This example tests the refinement buffer option, which extends the refinement a given number of cells
1 #include "../src/cpp_macros.h"
6 program random_refinement
12 integer :: grid_size(NDIM)
13 real(dp) :: domain_size(NDIM)
14 logical :: periodic(NDIM) = .true.
16 integer,
parameter :: coord_type = af_xyz
18 integer,
parameter :: box_size = 8
20 type(ref_info_t) :: ref_info
21 character(len=100) :: fname
23 write(*,
'(A,I0,A)')
'program test_refinement_buffer_', ndim,
"d"
25 print *,
"Number of threads", af_get_max_threads()
27 call af_add_cc_variable(tree,
"phi", ix=i_phi)
29 call af_set_cc_methods(tree, 1, af_bc_dirichlet_zero, &
30 prolong=af_prolong_linear)
33 grid_size(:) = box_size
34 domain_size(:) = 1.0_dp
44 call af_adjust_refinement(tree, ref_routine, ref_info, ref_buffer=0)
45 if (ref_info%n_add == 0)
exit
48 call af_loop_box(tree, set_init_cond)
49 call af_gc_tree(tree, [i_phi])
52 call af_adjust_refinement(tree, ref_routine, ref_info, ref_buffer=iter)
54 call af_loop_box(tree, set_init_cond)
55 call af_gc_tree(tree, [i_phi])
57 write(fname,
"(A,I0)")
"output/test_refinement_buffer_" // dimname //
"_", iter
58 call af_write_silo(tree, trim(fname), n_cycle=iter)
64 subroutine ref_routine(box, cell_flags)
65 type(box_t),
intent(in) :: box
66 integer,
intent(out) :: cell_flags(DTIMES(box%n_cell))
73 rr = af_r_cc(box, [ijk])
74 if (norm2(rr - 0.5_dp) < 0.25_dp .and. box%lvl < 5)
then
75 cell_flags(ijk) = af_do_ref
77 cell_flags(ijk) = af_keep_ref
81 end subroutine ref_routine
84 subroutine set_init_cond(box)
85 type(box_t),
intent(inout) :: box
92 rr = af_r_cc(box, [ijk])
94 if (norm2(rr - 0.5_dp) < 0.25_dp)
then
95 box%cc(ijk, i_phi) = 1
97 box%cc(ijk, i_phi) = 0
101 end subroutine set_init_cond
103 end program random_refinement
Module which contains all Afivo modules, so that a user does not have to include them separately.