5 program boundary_conditions_3d
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(3, n_boxes_base)
19 character(len=100) :: fname
21 print *,
"Running boundary_conditions_3d" 22 print *,
"Number of threads", af_get_max_threads()
25 dr = 1.0_dp / box_size
37 ix_list(:, 1) = [1, 1, 1]
40 call a3_set_base(tree, 1, ix_list)
41 call a3_print_info(tree)
43 do iter = 1, n_iterations
46 call a3_loop_box(tree, set_phi_zero)
49 call a3_loop_box(tree, average_phi)
52 call a3_gc_tree(tree, i_phi, a3_gc_interp, boundary_method)
54 write(fname,
"(A,I0)")
"boundary_conditions_3d_", iter
55 call a3_write_vtk(tree, trim(fname), dir=
"output")
61 subroutine set_phi_zero(box)
62 type(box3_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(box3_t),
intent(inout) :: box
69 integer :: i, j, k, nc
70 real(dp) :: tmp(box%n_cell, box%n_cell, box%n_cell)
74 do k = 1, nc;
do j = 1, nc;
do i = 1, nc
75 tmp(i, j, k) = 1/6.0_dp * ( &
76 box%cc(i+1, j, k, i_phi) + &
77 box%cc(i-1, j, k, i_phi) + &
78 box%cc(i, j+1, k, i_phi) + &
79 box%cc(i, j-1, k, i_phi) + &
80 box%cc(i, j, k+1, i_phi) + &
81 box%cc(i, j, k-1, i_phi))
82 end do; end do; end do
84 box%cc(1:nc, 1:nc, 1:nc, i_phi) = tmp(:, :, :)
85 end subroutine average_phi
88 subroutine boundary_method(box, nb, iv, bc_type)
89 type(box3_t),
intent(inout) :: box
90 integer,
intent(in) :: nb
91 integer,
intent(in) :: iv
92 integer,
intent(out) :: bc_type
100 bc_type = af_bc_dirichlet
101 box%cc(0, 1:nc, 1:nc, iv) = 1.0_dp
102 case (a3_neighb_highx)
103 bc_type = af_bc_neumann
104 box%cc(nc+1, 1:nc, 1:nc, iv) = 0.0_dp
105 case (a3_neighb_lowy)
106 bc_type = af_bc_dirichlet
107 box%cc(1:nc, 0, 1:nc, iv) = 1.0_dp
108 case (a3_neighb_highy)
109 bc_type = af_bc_neumann
110 box%cc(1:nc, nc+1, 1:nc, iv) = 0.0_dp
111 case (a3_neighb_lowz)
112 bc_type = af_bc_neumann
113 box%cc(1:nc, 1:nc, 0, iv) = 0.0_dp
114 case (a3_neighb_highz)
115 bc_type = af_bc_neumann
116 box%cc(1:nc, 1:nc, nc+1, iv) = 0.0_dp
119 end subroutine boundary_method
122 end program boundary_conditions_3d
Module which contains all Afivo modules, so that a user does not have to include them separately...