1 #include "cpp_macros.h"
11 public :: af_restrict_to_box
12 public :: af_restrict_to_boxes
13 public :: af_restrict_tree
14 public :: af_restrict_box
15 public :: af_restrict_ref_boundary
22 subroutine af_restrict_to_box(boxes, id, ivs)
23 type(
box_t),
intent(inout) :: boxes(:)
24 integer,
intent(in) :: id
25 integer,
intent(in) :: ivs(:)
26 integer :: nc, i_c, c_id
29 do i_c = 1, af_num_children
30 c_id = boxes(id)%children(i_c)
31 if (c_id == af_no_box) cycle
32 call af_restrict_box(boxes(c_id), boxes(id), ivs)
34 end subroutine af_restrict_to_box
37 subroutine af_restrict_to_boxes(boxes, ids, ivs)
38 type(
box_t),
intent(inout) :: boxes(:)
39 integer,
intent(in) :: ids(:)
40 integer,
intent(in) :: ivs(:)
45 call af_restrict_to_box(boxes, ids(i), ivs)
48 end subroutine af_restrict_to_boxes
51 subroutine af_restrict_tree(tree, ivs)
52 type(
af_t),
intent(inout) :: tree
53 integer,
intent(in) :: ivs(:)
56 if (.not. tree%ready) stop
"Tree not ready"
57 do lvl = tree%highest_lvl-1, 1, -1
58 call af_restrict_to_boxes(tree%boxes, tree%lvls(lvl)%parents, ivs)
60 end subroutine af_restrict_tree
63 subroutine af_restrict_box(box_c, box_p, ivs, use_geometry)
64 type(
box_t),
intent(in) :: box_c
65 type(
box_t),
intent(inout) :: box_p
66 integer,
intent(in) :: ivs(:)
67 logical,
intent(in),
optional :: use_geometry
68 integer :: ijk, ijk_(c), ijk_(f), n, iv
69 integer :: hnc, ix_offset(ndim)
75 hnc = ishft(box_c%n_cell, -1)
76 ix_offset = af_get_child_offset(box_c)
78 if (
present(use_geometry))
then
79 use_geom = use_geometry
88 i_c = ix_offset(1) + i
90 box_p%cc(i_c, iv) = 0.5_dp * &
91 sum(box_c%cc(i_f:i_f+1, iv))
94 if (box_p%coord_t == af_cyl .and. use_geom)
then
96 j_c = ix_offset(2) + j
99 i_c = ix_offset(1) + i
102 call af_cyl_child_weights(box_p, i_c, w1, w2)
103 box_p%cc(i_c, j_c, iv) = 0.25_dp * (&
104 w1 * sum(box_c%cc(i_f, j_f:j_f+1, iv)) + &
105 w2 * sum(box_c%cc(i_f+1, j_f:j_f+1, iv)))
110 j_c = ix_offset(2) + j
113 i_c = ix_offset(1) + i
115 box_p%cc(i_c, j_c, iv) = 0.25_dp * &
116 sum(box_c%cc(i_f:i_f+1, j_f:j_f+1, iv))
122 k_c = ix_offset(3) + k
125 j_c = ix_offset(2) + j
128 i_c = ix_offset(1) + i
130 box_p%cc(i_c, j_c, k_c, iv) = 0.125_dp * &
131 sum(box_c%cc(i_f:i_f+1, j_f:j_f+1, k_f:k_f+1, iv))
137 end subroutine af_restrict_box
141 subroutine af_restrict_ref_boundary(tree, ivs)
142 type(
af_t),
intent(inout) :: tree
143 integer,
intent(in) :: ivs(:)
144 integer :: lvl, i, id, p_id
147 do lvl = 1, tree%highest_lvl
149 do i = 1,
size(tree%lvls(lvl)%leaves)
150 id = tree%lvls(lvl)%leaves(i)
151 p_id = tree%boxes(id)%parent
154 if (p_id > af_no_box .and. &
155 any(tree%boxes(id)%neighbors == af_no_box))
then
156 call af_restrict_box(tree%boxes(id), tree%boxes(p_id), ivs)
162 end subroutine af_restrict_ref_boundary
This module contains routines for restriction: going from fine to coarse variables.
This module contains the basic types and constants that are used in the NDIM-dimensional version of A...
Type which stores all the boxes and levels, as well as some information about the number of boxes,...
The basic building block of afivo: a box with cell-centered and face centered data,...