5 program photon_absorption_2d
10 integer,
parameter :: box_size = 8
11 integer,
parameter :: i_phi = 1
12 integer,
parameter :: n_photons = 1000
13 real(dp),
parameter :: domain_len = 1.0_dp
14 real(dp),
parameter :: r_min(2) = -0.5_dp * domain_len
15 real(dp),
parameter :: dr = domain_len / box_size
16 real(dp),
allocatable :: coord_t0(:, :), coord_t1(:, :)
19 type(ref_info_t) :: refine_info
20 integer :: n, id, ix_list(2, 1)
21 integer :: count_rate, t_start, t_end
22 real(dp) :: sum_density
24 print *,
"Running photon_absorption_2d" 25 print *,
"Number of threads", af_get_max_threads()
41 call a2_set_base(tree, 1, ix_list)
43 call a2_set_cc_methods(tree, i_phi, a2_bc_neumann_zero, a2_gc_interp)
46 call a2_loop_box(tree, set_opaque_cells)
47 call a2_adjust_refinement(tree, refine_routine, refine_info, 0)
48 if (refine_info%n_add == 0)
exit 52 allocate(coord_t0(2, n_photons))
53 allocate(coord_t1(2, n_photons))
55 call random_number(coord_t0(:, :))
56 call random_number(coord_t1(:, :))
58 coord_t0 = (coord_t0 - 0.5_dp) * domain_len
59 coord_t1 = (coord_t1 - 0.5_dp) * domain_len
61 call system_clock(t_start, count_rate)
63 call system_clock(t_end, count_rate)
64 call a2_write_silo(tree,
"photon_absorption_2d_0", 1, 0.0_dp, dir=
"output")
68 subroutine set_opaque_cells(box)
69 type(box2_t),
intent(inout) :: box
75 do j = 0, nc+1;
do i = 0, nc+1
76 rr = a2_r_cc(box, [i, j])
79 if (norm2(rr) < 0.25_dp)
then 80 box%cc(i, j, i_phi) = 2.0_dp
82 box%cc(i, j, i_phi) = 1.0_dp
86 end subroutine set_opaque_cells
88 subroutine refine_routine(box, cell_flags)
89 type(box2_t),
intent(in) :: box
90 integer,
intent(out) :: cell_flags(box%n_cell, box%n_cell)
92 if (all(box%r_min < 0.0_dp) .and. box%lvl <= 5)
then 93 cell_flags(:, :) = af_do_ref
95 cell_flags(:, :) = af_keep_ref
97 end subroutine refine_routine
99 end program photon_absorption_2d
Module which contains all Afivo modules, so that a user does not have to include them separately...