5 program boundary_conditions_2d
10 integer,
parameter :: box_size = 8
11 integer,
parameter :: n_boxes_base = 1
12 integer,
parameter :: n_iterations = 20
13 integer,
parameter :: i_phi = 1
17 integer :: ix_list(2, n_boxes_base)
19 character(len=100) :: fname
21 print *,
"Running boundary_conditions_2d" 22 print *,
"Number of threads", af_get_max_threads()
25 dr = 1.0_dp / box_size
37 ix_list(:, 1) = [1, 1]
40 call a2_set_base(tree, 1, ix_list)
41 call a2_print_info(tree)
43 do iter = 1, n_iterations
46 call a2_loop_box(tree, set_phi_zero)
49 call a2_loop_box(tree, average_phi)
52 call a2_gc_tree(tree, i_phi, a2_gc_interp, boundary_method)
54 write(fname,
"(A,I0)")
"boundary_conditions_2d_", iter
55 call a2_write_vtk(tree, trim(fname), dir=
"output")
61 subroutine set_phi_zero(box)
62 type(box2_t),
intent(inout) :: box
64 box%cc(:, :, i_phi) = 0.0_dp
65 end subroutine set_phi_zero
67 subroutine average_phi(box)
68 type(box2_t),
intent(inout) :: box
70 real(dp) :: tmp(box%n_cell, box%n_cell)
74 do j = 1, nc;
do i = 1, nc
75 tmp(i, j) = 0.25_dp * ( &
76 box%cc(i+1, j, i_phi) + &
77 box%cc(i-1, j, i_phi) + &
78 box%cc(i, j+1, i_phi) + &
79 box%cc(i, j-1, i_phi))
82 box%cc(1:nc, 1:nc, i_phi) = tmp(:, :)
83 end subroutine average_phi
86 subroutine boundary_method(box, nb, iv, bc_type)
87 type(box2_t),
intent(inout) :: box
88 integer,
intent(in) :: nb
89 integer,
intent(in) :: iv
90 integer,
intent(out) :: bc_type
98 bc_type = af_bc_dirichlet
99 box%cc(0, 1:nc, iv) = 1.0_dp
100 case (a2_neighb_highx)
101 bc_type = af_bc_neumann
102 box%cc(nc+1, 1:nc, iv) = 0.0_dp
103 case (a2_neighb_lowy)
104 bc_type = af_bc_dirichlet
105 box%cc(1:nc, 0, iv) = 1.0_dp
106 case (a2_neighb_highy)
107 bc_type = af_bc_neumann
108 box%cc(1:nc, nc+1, iv) = 0.0_dp
111 end subroutine boundary_method
114 end program boundary_conditions_2d