38 error stop
"Multigrid module was compiled for different ndim"
44 if (
ndim == 3) error stop
"Multigrid does not support cylindrical 3D"
47 error stop
"Multigrid does not support your geometry"
51 error stop
"Multigrid requires all block_nx to be equal"
61 type(
mg_t),
intent(inout) :: mg
62 integer,
intent(in) :: iw
63 character(len=std_len) :: bnd_name(mg_num_neighbors)
66 do n = 1, mg_num_neighbors
70 mg%bc(n,
mg_iphi)%bc_value = 0.0_dp
73 mg%bc(n,
mg_iphi)%bc_value = 0.0_dp
76 mg%bc(n,
mg_iphi)%bc_value = 0.0_dp
80 write(*,*)
"mg_copy_boundary_conditions: unknown boundary type"
88 integer,
intent(in) :: n_coarsen
89 integer,
intent(in) :: n_refine
94 if (.not.
mg%is_allocated)
then
96 else if (n_coarsen + n_refine > 0)
then
106 integer,
intent(in) :: iw_from
107 integer,
intent(in) :: iw_to
108 logical,
intent(in),
optional :: restrict
109 logical,
intent(in),
optional :: restrict_gc
110 real(dp),
intent(in),
optional :: factor
112 type(state),
intent(in),
optional,
target :: state_from(max_blocks)
113 integer :: iigrid, igrid, id
114 integer :: nc, lvl, ilo^D, ihi^D
117 logical :: do_restrict, do_gc
119 if (.not.
mg%is_allocated) &
120 error stop
"mg_copy_to_tree: tree not allocated yet"
122 fac = 1.0_dp;
if (
present(factor)) fac = factor
123 do_restrict = .false.;
if (
present(restrict)) do_restrict = restrict
124 do_gc = .false.;
if (
present(restrict_gc)) do_gc = restrict_gc
129 do iigrid = 1, igridstail
130 igrid = igrids(iigrid);
133 lvl =
mg%boxes(id)%lvl
134 nc =
mg%box_size_lvl(lvl)
137 if (
present(state_from))
then
138 mg%boxes(id)%cc({0:nc+1}, iw_to) = &
139 fac * state_from(igrid)%w({ilo^d:ihi^d}, iw_from)
141 mg%boxes(id)%cc({0:nc+1}, iw_to) = fac * ps(igrid)%w({ilo^d:ihi^d}, iw_from)
145 if (do_restrict)
then
156 integer,
intent(in) :: iw_from
157 integer,
intent(in) :: iw_to
159 type(state),
intent(inout),
optional,
target :: state_to(max_blocks)
160 integer :: iigrid, igrid, id
164 if (.not.
mg%is_allocated) &
165 error stop
"mg_copy_from_tree: tree not allocated yet"
167 do iigrid = 1, igridstail
168 igrid = igrids(iigrid);
171 lvl =
mg%boxes(id)%lvl
172 nc =
mg%box_size_lvl(lvl)
174 if (
present(state_to))
then
175 state_to(igrid)%w(
ixm^t, iw_to) =
mg%boxes(id)%cc({1:nc}, iw_from)
177 ps(igrid)%w(
ixm^t, iw_to) =
mg%boxes(id)%cc({1:nc}, iw_from)
187 integer,
intent(in) :: iw_from
188 integer,
intent(in) :: iw_to
190 type(state),
intent(inout),
optional,
target :: state_to(max_blocks)
191 integer :: iigrid, igrid, id
192 integer :: nc, lvl, ilo^D, ihi^D
195 if (.not.
mg%is_allocated) &
196 error stop
"mg_copy_from_tree_gc: tree not allocated yet"
201 do iigrid = 1, igridstail
202 igrid = igrids(iigrid);
205 lvl =
mg%boxes(id)%lvl
206 nc =
mg%box_size_lvl(lvl)
208 if (
present(state_to))
then
209 state_to(igrid)%w({ilo^d:ihi^d}, iw_to) =
mg%boxes(id)%cc({0:nc+1}, iw_from)
211 ps(igrid)%w({ilo^d:ihi^d}, iw_to) =
mg%boxes(id)%cc({0:nc+1}, iw_from)
222 type(
mg_t),
intent(inout) :: mg
223 integer :: i, n, id, ix(ndim)
224 integer :: n_boxes_total, i_c, c_id, c_ix(ndim)
225 integer :: min_lvl, lvl
226 integer :: nb, nb_ix, nb_dim
228 type(
tree_node),
pointer :: pnode, pnode_ch
230 real(dp) :: dr_coarse
239 n_boxes_total = mg%n_boxes + n_finer
242 allocate(id_to_node(n_boxes_total))
245 do i = 1,
size(mg%lvls(1)%ids)
246 id = mg%lvls(1)%ids(i)
251 id_to_node(id)%node => pnode
252 mg%boxes(id)%rank = pnode%ipe
256 do lvl = 1, mg%highest_lvl
257 do i = 1,
size(mg%lvls(lvl)%ids)
258 id = mg%lvls(lvl)%ids(i)
259 pnode => id_to_node(id)%node
261 if (.not. pnode%leaf)
then
265 c_id = mg%boxes(id)%children(i_c)
267 pnode_ch => pnode%child({c_ix(^
d)})%node
268 id_to_node(c_id)%node => pnode_ch
270 mg%boxes(c_id)%rank = pnode_ch%ipe
277 if (lvl < mg%highest_lvl)
then
284 do lvl = 1, mg%highest_lvl
integer, parameter, public mg_iphi
Index of solution.
integer, parameter, public mg_bc_neumann
Value to indicate a Neumann boundary condition.
integer, parameter, public mg_cylindrical
Cylindrical coordinate system.
integer, parameter, public mg_num_children
subroutine, public mg_set_methods(mg)
subroutine, public mg_fill_ghost_cells(mg, iv)
Fill ghost cells at all grid levels.
subroutine, public mg_build_rectangle(mg, domain_size, box_size, dx, r_min, periodic, n_finer)
subroutine, public mg_comm_init(mg, comm)
Prolong from a parent to a child with index offset dix. This method could sometimes work better than ...
subroutine, public mg_restrict(mg, iv)
Restrict all levels.
subroutine, public mg_add_children(mg, id)
subroutine, public mg_set_refinement_boundaries(boxes, level)
Create a list of refinement boundaries (from the coarse side)
subroutine, public mg_set_next_level_ids(mg, lvl)
subroutine, public mg_set_neighbors_lvl(mg, lvl)
integer, parameter, public mg_bc_dirichlet
Value to indicate a Dirichlet boundary condition.
subroutine, public mg_allocate_storage(mg)
Allocate communication buffers and local boxes for a tree that has already been created.
integer, parameter, public mg_ndim
Problem dimension.
subroutine, public mg_deallocate_storage(mg)
Deallocate all allocatable arrays.
subroutine, public mg_set_leaves_parents(boxes, level)
Create a list of leaves and a list of parents for a level.
subroutine, public mg_load_balance_parents(mg)
Load balance the parents (non-leafs). Assign them to the rank that has most children.
integer, dimension(1, 2), parameter, public mg_child_dix
integer, parameter, public mg_bc_continuous
Value to indicate a continuous boundary condition.
Module with basic grid data structures.
integer, save nleafs
Number of leaf block.
type(tree_node_ptr), dimension(:^d &), allocatable, save tree_root
Pointers to the coarse grid.
integer, save nparents
Number of parent blocks.
type(tree_node_ptr), dimension(:,:), allocatable, save igrid_to_node
Array to go from an [igrid, ipe] index to a node pointer.
Module with geometry-related routines (e.g., divergence, curl)
integer, parameter cartesian
integer, parameter cylindrical
This module contains definitions of global parameters and variables and some generic functions/subrou...
integer domain_nx
number of cells for each dimension in level-one mesh
integer, parameter bc_asymm
integer, dimension(:, :), allocatable typeboundary
Array indicating the type of boundary condition per variable and per physical boundary.
integer, parameter ndim
Number of spatial dimensions for grid variables.
integer mype
The rank of the current MPI task.
integer block_nx
number of cells for each dimension in grid block excluding ghostcells
integer, dimension(:), allocatable, parameter d
integer ixm
the mesh range of a physical block without ghost cells
integer, parameter bc_periodic
logical, dimension(ndim) periodb
True for dimensions with periodic boundaries.
integer, parameter bc_cont
double precision, dimension(:,:), allocatable dx
integer, parameter bc_symm
Module to couple the octree-mg library to AMRVAC. This file uses the VACPP preprocessor,...
type(mg_t) mg
Data structure containing the multigrid tree.
subroutine mg_copy_boundary_conditions(mg, iw)
Set multigrid boundary conditions for the solution according to variable iw.
subroutine mg_update_refinement(n_coarsen, n_refine)
If the grid has changed, rebuild the full multigrid tree.
subroutine mg_copy_to_tree(iw_from, iw_to, restrict, restrict_gc, factor, state_from)
Copy a variable to the multigrid tree, including a layer of ghost cells.
procedure(after_new_tree), pointer mg_after_new_tree
If defined, this routine is called after a new multigrid tree is constructed.
subroutine mg_copy_from_tree_gc(iw_from, iw_to, state_to)
Copy from multigrid tree with one layer of ghost cells. Corner ghost cells are not used/set.
subroutine mg_tree_from_amrvac(mg)
Generate a multigrid tree that includes the amrvac tree, but also contains coarser grid levels....
subroutine mg_setup_multigrid()
Setup multigrid for usage.
subroutine mg_copy_from_tree(iw_from, iw_to, state_to)
Copy a variable from the multigrid tree.
The data structure that contains information about a tree node/grid block.