Afivo  0.3
photon_absorption_2d.f90
1 
5 program photon_absorption_2d
6  use m_a2_all
7 
8  implicit none
9 
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(:, :)
17 
18  type(a2_t) :: tree
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
23 
24  print *, "Running photon_absorption_2d"
25  print *, "Number of threads", af_get_max_threads()
26 
27  ! Initialize tree
28  call a2_init(tree, & ! Tree to initialize
29  box_size, & ! A box contains box_size**DIM cells
30  n_var_cell=1, & ! Number of cell-centered variables
31  n_var_face=0, & ! Number of face-centered variables
32  dr=dr, & ! Distance between cells on base level
33  cc_names=["phi"], & ! Variable names
34  r_min=r_min)
35 
36  ! Set up geometry
37  id = 1
38  ix_list(:, id) = 1 ! Set index of box
39 
40  ! Create the base mesh, using the box indices and their neighbor information
41  call a2_set_base(tree, 1, ix_list)
42 
43  call a2_set_cc_methods(tree, i_phi, a2_bc_neumann_zero, a2_gc_interp)
44 
45  do
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
49  end do
50 
51  ! Get photon start and end position in domain
52  allocate(coord_t0(2, n_photons))
53  allocate(coord_t1(2, n_photons))
54 
55  call random_number(coord_t0(:, :))
56  call random_number(coord_t1(:, :))
57 
58  coord_t0 = (coord_t0 - 0.5_dp) * domain_len
59  coord_t1 = (coord_t1 - 0.5_dp) * domain_len
60 
61  call system_clock(t_start, count_rate)
62 
63  call system_clock(t_end, count_rate)
64  call a2_write_silo(tree, "photon_absorption_2d_0", 1, 0.0_dp, dir="output")
65 
66 contains
67 
68  subroutine set_opaque_cells(box)
69  type(box2_t), intent(inout) :: box
70  integer :: i, j, nc
71  real(dp) :: rr(2)
72 
73  nc = box%n_cell
74 
75  do j = 0, nc+1; do i = 0, nc+1
76  rr = a2_r_cc(box, [i, j])
77 
78  ! Change phi to a 'high' value in part of the domain
79  if (norm2(rr) < 0.25_dp) then
80  box%cc(i, j, i_phi) = 2.0_dp
81  else
82  box%cc(i, j, i_phi) = 1.0_dp
83  end if
84  end do; end do
85 
86  end subroutine set_opaque_cells
87 
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)
91 
92  if (all(box%r_min < 0.0_dp) .and. box%lvl <= 5) then
93  cell_flags(:, :) = af_do_ref
94  else
95  cell_flags(:, :) = af_keep_ref
96  end if
97  end subroutine refine_routine
98 
99 end program photon_absorption_2d
Module which contains all Afivo modules, so that a user does not have to include them separately...
Definition: m_a2_all.f90:4