6 program poisson_neumann_3d
12 integer,
parameter :: box_size = 8
13 integer,
parameter :: n_boxes_base = 1
14 integer,
parameter :: n_iterations = 10
15 integer,
parameter :: n_var_cell = 4
16 integer,
parameter :: i_phi = 1
17 integer,
parameter :: i_rhs = 2
18 integer,
parameter :: i_tmp = 3
19 integer,
parameter :: i_err = 4
22 type(ref_info_t) :: refine_info
24 integer :: ix_list(3, n_boxes_base)
26 character(len=100) :: fname
28 integer :: count_rate,t_start,t_end
30 print *,
"Running poisson_neumann_3d" 31 print *,
"Number of threads", af_get_max_threads()
34 dr = 1.0_dp / box_size
43 cc_names=[
"phi",
"rhs",
"tmp",
"err"])
47 ix_list(:, 1) = [1, 1, 1]
50 call a3_set_base(tree, 1, ix_list)
52 call system_clock(t_start, count_rate)
55 call a3_loop_box(tree, set_initial_condition)
61 call a3_adjust_refinement(tree, refine_routine, refine_info, 0)
64 if (refine_info%n_add == 0)
exit 66 call system_clock(t_end, count_rate)
68 write(*,
"(A,Es10.3,A)")
" Wall-clock time generating AMR grid: ", &
69 (t_end-t_start) /
real(count_rate,dp),
" seconds" 71 call a3_print_info(tree)
78 mg%sides_bc => sides_bc
85 print *,
"Multigrid iteration | max residual | max error" 86 call system_clock(t_start, count_rate)
88 do mg_iter = 1, n_iterations
89 call mg3_fas_fmg(tree, mg, set_residual=.true., have_guess=(mg_iter>1))
92 call a3_loop_box(tree, set_error)
94 write(fname,
"(A,I0)")
"poisson_neumann_3d_", mg_iter
95 call a3_write_silo(tree, trim(fname), dir=
"output")
97 call system_clock(t_end, count_rate)
99 write(*,
"(A,I0,A,E10.3,A)") &
100 " Wall-clock time after ", n_iterations, &
101 " iterations: ", (t_end-t_start) /
real(count_rate, dp), &
107 subroutine refine_routine(box, cell_flags)
108 type(box3_t),
intent(in) :: box
109 integer,
intent(out) :: cell_flags(box%n_cell, box%n_cell, box%n_cell)
112 if (box%lvl <= 4 .and. all(box%r_min < 0.25_dp))
then 113 cell_flags(:, :, :) = af_do_ref
115 cell_flags(:, :, :) = af_keep_ref
117 end subroutine refine_routine
120 subroutine set_initial_condition(box)
121 type(box3_t),
intent(inout) :: box
123 box%cc(:, :, :, i_rhs) = 0.0_dp
124 end subroutine set_initial_condition
127 subroutine set_error(box)
128 type(box3_t),
intent(inout) :: box
129 integer :: i, j, k, nc
133 do k = 1, nc;
do j = 1, nc;
do i = 1, nc
134 rr = a3_r_cc(box, [i, j, k])
135 box%cc(i, j, k, i_err) = box%cc(i, j, k, i_phi) - rr(1)
136 end do; end do; end do
137 end subroutine set_error
141 subroutine sides_bc(box, nb, iv, bc_type)
142 type(box3_t),
intent(inout) :: box
143 integer,
intent(in) :: nb
144 integer,
intent(in) :: iv
145 integer,
intent(out) :: bc_type
152 case (a3_neighb_lowx)
153 call a3_bc_dirichlet_zero(box, nb, iv, bc_type)
154 case (a3_neighb_highx)
155 bc_type = af_bc_dirichlet
156 box%cc(nc+1, 1:nc, 1:nc, iv) = 1
158 call a3_bc_neumann_zero(box, nb, iv, bc_type)
160 end subroutine sides_bc
Module which contains all Afivo modules, so that a user does not have to include them separately...
This module can be used to construct solutions consisting of one or more Gaussians.