5 program particles_to_grid_2d
10 integer,
parameter :: box_size = 8
11 integer,
parameter :: i_phi = 1
12 integer,
parameter :: n_particles = 10*1000*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 :: coordinates(:, :), weights(:)
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 particles_to_grid_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_adjust_refinement(tree, refine_routine, refine_info, 0)
47 if (refine_info%n_add == 0)
exit 50 allocate(coordinates(2, n_particles))
51 allocate(weights(n_particles))
53 call random_number(coordinates(:, :))
57 coordinates(:, n) = (coordinates(:, n) - 0.5_dp) * domain_len
61 call system_clock(t_start, count_rate)
62 call a2_particles_to_grid(tree, i_phi, coordinates, weights, n_particles, 0)
63 call system_clock(t_end, count_rate)
64 call a2_write_silo(tree,
"particles_to_grid_2d_0", 1, 0.0_dp, dir=
"output")
65 call a2_tree_sum_cc(tree, i_phi, sum_density)
66 print *,
"zeroth order: ", (t_end-t_start) /
real(count_rate, dp),
" seconds" 67 print *,
"integrated density: ", sum_density
69 call a2_tree_clear_cc(tree, i_phi)
71 call system_clock(t_start, count_rate)
72 call a2_particles_to_grid(tree, i_phi, coordinates, weights, n_particles, 1)
73 call system_clock(t_end, count_rate)
74 call a2_write_silo(tree,
"particles_to_grid_2d_1", 1, 0.0_dp, dir=
"output")
75 call a2_tree_sum_cc(tree, i_phi, sum_density)
76 print *,
"first order: ", (t_end-t_start) /
real(count_rate, dp),
" seconds" 77 print *,
"integrated density: ", sum_density
81 subroutine refine_routine(box, cell_flags)
82 type(box2_t),
intent(in) :: box
83 integer,
intent(out) :: cell_flags(box%n_cell, box%n_cell)
85 if (all(box%r_min < 0.0_dp) .and. box%lvl <= 5)
then 86 cell_flags(:, :) = af_do_ref
88 cell_flags(:, :) = af_keep_ref
90 end subroutine refine_routine
92 end program particles_to_grid_2d
Module which contains all Afivo modules, so that a user does not have to include them separately...