Afivo
0.3
|
This module contains the geometric multigrid routines that come with Afivo. More...
Functions/Subroutines | |
subroutine, public | mg_init (tree, mg) |
Check multigrid options or set them to default. More... | |
subroutine, public | mg_destroy (mg) |
subroutine, public | mg_use (tree, mg) |
Make sure box tags and operators are set. More... | |
subroutine | done_with_mg (tree) |
To be called at the end of a multigrid solve. More... | |
subroutine, public | mg_fas_fmg (tree, mg, set_residual, have_guess) |
Perform FAS-FMG cycle (full approximation scheme, full multigrid). Note that this routine needs valid ghost cells (for i_phi) on input, and gives back valid ghost cells on output. More... | |
subroutine, public | mg_fas_vcycle (tree, mg, set_residual, highest_lvl, standalone) |
Perform FAS V-cycle (full approximation scheme). Note that this routine needs valid ghost cells (for i_phi) on input, and gives back valid ghost cells on output. More... | |
subroutine | solve_coarse_grid (tree, mg) |
subroutine, public | mg_sides_rb (boxes, id, nb, iv) |
Fill ghost cells near refinement boundaries which preserves diffusive fluxes. More... | |
subroutine | mg_sides_rb_extrap (boxes, id, nb, iv) |
Fill ghost cells near refinement boundaries which preserves diffusive fluxes. This routine does not do interpolation of coarse grid values. Basically, we extrapolate from the fine cells to a corner point, and then take the average between this corner point and a coarse neighbor to fill ghost cells for the fine cells. More... | |
subroutine | correct_children (boxes, ids, mg) |
subroutine | gsrb_boxes (tree, lvl, mg, type_cycle) |
subroutine | update_coarse (tree, lvl, mg) |
subroutine | set_coarse_phi_rhs (tree, lvl, mg) |
This routine performs the same as update_coarse, but it ignores the tmp variable. More... | |
subroutine | init_phi_rhs (tree, mg) |
Set the initial guess for phi and restrict the rhs. More... | |
subroutine | residual_box (box, mg) |
subroutine | mg_auto_gsrb (box, redblack_cntr, mg) |
Based on the box type, apply a Gauss-Seidel relaxation scheme. More... | |
subroutine | mg_store_operator_stencil (box, mg, ix) |
Store operator stencil for a box. More... | |
subroutine | mg_store_prolongation_stencil (tree, id, mg) |
Store prolongation stencil for a box. More... | |
subroutine | mg_auto_op (box, i_out, mg) |
Based on the box type, apply the approriate operator. More... | |
subroutine | mg_auto_rstr (box_c, box_p, iv, mg) |
Restriction operator. More... | |
subroutine | mg_auto_rb (boxes, id, nb, iv, op_mask) |
Set ghost cells near refinement boundaries. More... | |
subroutine | mg_auto_corr (box_p, box_c, mg) |
Based on the box type, correct the solution of the children. More... | |
subroutine | get_possible_lsf_root_mask (box, nc, dmax, mg, root_mask) |
Check where the level-set function could have a root by computing the numerical gradient. More... | |
subroutine | store_lsf_distance_matrix (box, nc, mg, boundary) |
Check if the level set function could have zeros, and store distances for the neighboring cells. More... | |
subroutine, public | mg_set_box_tag (tree, id, mg, new_lsf, new_eps) |
Set tag (box type) for a box in the tree. More... | |
subroutine, public | mg_set_operators_lvl (tree, mg, lvl) |
subroutine, public | mg_update_operator_stencil (tree, mg, new_lsf, new_eps) |
Update stencil for an operator, because (part of) the coefficients have changed. More... | |
subroutine, public | mg_set_operators_tree (tree, mg) |
subroutine | mg_box_rstr_lpl (box_c, box_p, iv, mg) |
Restriction of child box (box_c) to its parent (box_p) More... | |
subroutine | mg_box_lpl_stencil (box, mg, ix) |
Store the matrix stencil for each cell of the box. The order of the stencil is (i, j), (i-1, j), (i+1, j), (i, j-1), (i, j+1) (e.g., -4, 1, 1, 1, 1) More... | |
subroutine | mg_box_prolong_linear_stencil (box, box_p, mg, ix) |
Store linear prolongation stencil for standard Laplacian. More... | |
subroutine | mg_box_prolong_sparse_stencil (box, box_p, mg, ix) |
Store sparse linear prolongation stencil for standard Laplacian. More... | |
subroutine | mg_box_prolong_eps_stencil (box, box_p, mg, ix) |
Store prolongation stencil for standard Laplacian with variable coefficient that can jump at cell faces. More... | |
subroutine | mg_box_prolong_lsf_stencil (box, box_p, mg, ix) |
Store prolongation stencil for standard Laplacian with level set function for internal boundaries. More... | |
subroutine | mg_box_lpld_stencil (box, mg, ix) |
Store the matrix stencil for each cell of the box. The order of the stencil is (i, j), (i-1, j), (i+1, j), (i, j-1), (i, j+1) (e.g., -4, 1, 1, 1, 1) More... | |
subroutine | mg_box_lpld_lsf_stencil (box, mg, ix) |
Store stencil for a box with variable coefficient and level set function. More... | |
real(dp) function, public | mg_lsf_dist_linear (a, b, mg) |
Compute distance to boundary starting at point a going to point b, in the range from [0, 1], with 1 meaning there is no boundary. More... | |
real(dp) function, public | mg_lsf_dist_gss (a, b, mg) |
Find root of f in the interval [a, b]. If f(a) and f(b) have different signs, apply bisection directly. Else, first find the (assumed to be) unique local minimum/maximum to determine a bracket. Return relative location of root, or 1 if there is no root. More... | |
real(dp) function, dimension(ndim) | bisection (f, in_a, in_b, tol, max_iter) |
Simple bisection. More... | |
real(dp) function, dimension(ndim, 2) | gss (f, in_a, in_b, minimization, tol, find_bracket) |
Golden-section search on a line between a and b. Given a function f with a single local minimum/maximum in the interval [a,b], gss returns a subset interval [c,d] that contains the minimum/maximum with d-c <= tol. Adapted from https://en.wikipedia.org/wiki/Golden-section_search. More... | |
subroutine | mg_box_lsf_stencil (box, mg, ix) |
Store the matrix stencil for each cell of the box. The order of the stencil is (i, j), (i-1, j), (i+1, j), (i, j-1), (i, j+1) (e.g., -4, 1, 1, 1, 1) More... | |
subroutine, public | mg_compute_phi_gradient (tree, mg, i_fc, fac, i_norm) |
Compute the gradient of the potential and store in face-centered variables. More... | |
subroutine, public | mg_box_lpl_gradient (tree, id, mg, i_fc, fac) |
Compute the gradient of the potential. More... | |
subroutine, public | mg_compute_field_norm (tree, i_fc, i_norm) |
Compute norm of face-centered variable. More... | |
subroutine, public | mg_box_field_norm (tree, id, i_fc, i_norm) |
subroutine | mg_box_lpllsf_gradient (tree, id, mg, i_fc, fac) |
Compute the gradient of the potential with a level set function and store in face-centered variables. The gradients are computed from the positive side of the level set function. More... | |
subroutine | check_coarse_representation_lsf (tree, mg) |
This method checks whether the level set function is properly defined on the coarse grid. More... | |
real(dp) function, dimension(ndim) | numerical_gradient (f, r) |
Get amplitude of numerical gradient of level set function. More... | |
This module contains the geometric multigrid routines that come with Afivo.
subroutine, public m_af_multigrid::mg_init | ( | type(af_t), intent(inout) | tree, |
type(mg_t), intent(inout) | mg | ||
) |
Check multigrid options or set them to default.
[in,out] | tree | Tree to do multigrid on |
[in,out] | mg | Multigrid options |
Definition at line 43 of file m_af_multigrid.f90.
subroutine, public m_af_multigrid::mg_destroy | ( | type(mg_t), intent(inout) | mg | ) |
[in,out] | mg | Multigrid options |
Definition at line 111 of file m_af_multigrid.f90.
subroutine, public m_af_multigrid::mg_use | ( | type(af_t), intent(inout) | tree, |
type(mg_t), intent(in), target | mg | ||
) |
Make sure box tags and operators are set.
[in] | mg | Multigrid options |
Definition at line 118 of file m_af_multigrid.f90.
|
private |
To be called at the end of a multigrid solve.
Definition at line 129 of file m_af_multigrid.f90.
subroutine, public m_af_multigrid::mg_fas_fmg | ( | type(af_t), intent(inout) | tree, |
type(mg_t), intent(inout) | mg, | ||
logical, intent(in) | set_residual, | ||
logical, intent(in) | have_guess | ||
) |
Perform FAS-FMG cycle (full approximation scheme, full multigrid). Note that this routine needs valid ghost cells (for i_phi) on input, and gives back valid ghost cells on output.
[in,out] | tree | Tree to do multigrid on |
[in,out] | mg | Multigrid options |
[in] | set_residual | If true, store residual in i_tmp |
[in] | have_guess | If false, start from phi = 0 |
Definition at line 137 of file m_af_multigrid.f90.
subroutine, public m_af_multigrid::mg_fas_vcycle | ( | type(af_t), intent(inout) | tree, |
type(mg_t), intent(in) | mg, | ||
logical, intent(in) | set_residual, | ||
integer, intent(in), optional | highest_lvl, | ||
logical, intent(in), optional | standalone | ||
) |
Perform FAS V-cycle (full approximation scheme). Note that this routine needs valid ghost cells (for i_phi) on input, and gives back valid ghost cells on output.
[in,out] | tree | Tree to do multigrid on |
[in] | mg | Multigrid options |
[in] | set_residual | If true, store residual in i_tmp |
[in] | highest_lvl | Maximum level for V-cycle |
[in] | standalone | False if called by other cycle |
Definition at line 185 of file m_af_multigrid.f90.
subroutine m_af_multigrid::solve_coarse_grid | ( | type(af_t), intent(inout) | tree, |
type(mg_t), intent(in) | mg | ||
) |
[in,out] | tree | Tree to do multigrid on |
[in] | mg | Multigrid options |
Definition at line 266 of file m_af_multigrid.f90.
subroutine, public m_af_multigrid::mg_sides_rb | ( | type(box_t), dimension(:), intent(inout) | boxes, |
integer, intent(in) | id, | ||
integer, intent(in) | nb, | ||
integer, intent(in) | iv | ||
) |
Fill ghost cells near refinement boundaries which preserves diffusive fluxes.
[in,out] | boxes | List of all boxes |
[in] | id | Id of box |
[in] | nb | Ghost cell direction |
[in] | iv | Ghost cell variable |
Definition at line 294 of file m_af_multigrid.f90.
|
private |
Fill ghost cells near refinement boundaries which preserves diffusive fluxes. This routine does not do interpolation of coarse grid values. Basically, we extrapolate from the fine cells to a corner point, and then take the average between this corner point and a coarse neighbor to fill ghost cells for the fine cells.
[in,out] | boxes | List of all boxes |
[in] | id | Id of box |
[in] | nb | Ghost cell direction |
[in] | iv | Ghost cell variable |
Definition at line 468 of file m_af_multigrid.f90.
|
private |
[in,out] | boxes | List of all boxes |
[in] | ids | Operate on these boxes |
[in] | mg | Multigrid options |
Definition at line 624 of file m_af_multigrid.f90.
|
private |
[in,out] | tree | Tree containing full grid |
[in] | mg | Multigrid options |
[in] | lvl | Operate on this refinement level |
[in] | type_cycle | Type of cycle to perform |
Definition at line 648 of file m_af_multigrid.f90.
|
private |
[in,out] | tree | Tree containing full grid |
[in] | lvl | Update coarse values at lvl-1 |
[in] | mg | Multigrid options |
Definition at line 691 of file m_af_multigrid.f90.
subroutine m_af_multigrid::set_coarse_phi_rhs | ( | type(af_t), intent(inout) | tree, |
integer, intent(in) | lvl, | ||
type(mg_t), intent(in) | mg | ||
) |
This routine performs the same as update_coarse, but it ignores the tmp variable.
[in,out] | tree | Tree containing full grid |
[in] | lvl | Update coarse values at lvl-1 |
[in] | mg | Multigrid options |
Definition at line 742 of file m_af_multigrid.f90.
subroutine m_af_multigrid::init_phi_rhs | ( | type(af_t), intent(inout) | tree, |
type(mg_t), intent(in) | mg | ||
) |
Set the initial guess for phi and restrict the rhs.
[in,out] | tree | Full grid |
[in] | mg | Multigrid options |
Definition at line 779 of file m_af_multigrid.f90.
subroutine m_af_multigrid::residual_box | ( | type(box_t), intent(inout) | box, |
type(mg_t), intent(in) | mg | ||
) |
[in,out] | box | Operate on this box |
[in] | mg | Multigrid options |
Definition at line 801 of file m_af_multigrid.f90.
|
private |
Based on the box type, apply a Gauss-Seidel relaxation scheme.
[in,out] | box | Box to operate on |
[in] | redblack_cntr | Iteration count |
[in] | mg | Multigrid options |
Definition at line 813 of file m_af_multigrid.f90.
|
private |
Store operator stencil for a box.
[in,out] | ix | Index of the stencil. If equal to af_stencil_none, store a new stencil |
Definition at line 823 of file m_af_multigrid.f90.
|
private |
Store prolongation stencil for a box.
[in] | id | Id of box |
Definition at line 862 of file m_af_multigrid.f90.
|
private |
Based on the box type, apply the approriate operator.
[in,out] | box | Operate on this box |
[in] | i_out | Index of output variable |
[in] | mg | Multigrid options |
Definition at line 906 of file m_af_multigrid.f90.
|
private |
Restriction operator.
[in] | box_c | Child box |
[in,out] | box_p | Parent box |
[in] | iv | Index of variable |
[in] | mg | Multigrid options |
Definition at line 915 of file m_af_multigrid.f90.
|
private |
Set ghost cells near refinement boundaries.
[in,out] | boxes | List of all boxes |
[in] | id | Id of box |
[in] | nb | Ghost cell direction |
[in] | iv | Ghost cell variable |
[in] | op_mask | Operator mask |
Definition at line 926 of file m_af_multigrid.f90.
|
private |
Based on the box type, correct the solution of the children.
[in,out] | box_c | Child box |
[in] | box_p | Parent box |
[in] | mg | Multigrid options |
Definition at line 943 of file m_af_multigrid.f90.
|
private |
Check where the level-set function could have a root by computing the numerical gradient.
[in] | box | Box to operate on |
[in] | dmax | Maximal distance to consider |
[in] | nc | Box size |
[in] | mg | Multigrid options |
[out] | root_mask | Whether there could be a root |
Definition at line 954 of file m_af_multigrid.f90.
|
private |
Check if the level set function could have zeros, and store distances for the neighboring cells.
[in,out] | box | Box to operate on |
[in] | nc | Box size |
[in] | mg | Multigrid options |
[out] | boundary | Whether a boundary is found |
Definition at line 977 of file m_af_multigrid.f90.
subroutine, public m_af_multigrid::mg_set_box_tag | ( | type(af_t), intent(inout) | tree, |
integer, intent(in) | id, | ||
type(mg_t), intent(in) | mg, | ||
logical, intent(in) | new_lsf, | ||
logical, intent(in) | new_eps | ||
) |
Set tag (box type) for a box in the tree.
[in] | new_lsf | Whether the lsf has changed |
[in] | new_eps | Whether epsilon has changed |
Definition at line 1100 of file m_af_multigrid.f90.
subroutine, public m_af_multigrid::mg_set_operators_lvl | ( | type(af_t), intent(inout) | tree, |
type(mg_t), intent(in) | mg, | ||
integer, intent(in) | lvl | ||
) |
Definition at line 1147 of file m_af_multigrid.f90.
subroutine, public m_af_multigrid::mg_update_operator_stencil | ( | type(af_t), intent(inout) | tree, |
type(mg_t), intent(inout) | mg, | ||
logical, intent(in) | new_lsf, | ||
logical, intent(in) | new_eps | ||
) |
Update stencil for an operator, because (part of) the coefficients have changed.
[in] | new_lsf | Whether the lsf has changed |
[in] | new_eps | Whether epsilon has changed |
Definition at line 1188 of file m_af_multigrid.f90.
subroutine, public m_af_multigrid::mg_set_operators_tree | ( | type(af_t), intent(inout) | tree, |
type(mg_t), intent(in) | mg | ||
) |
Definition at line 1216 of file m_af_multigrid.f90.
|
private |
Restriction of child box (box_c) to its parent (box_p)
[in] | box_c | Child box to restrict |
[in,out] | box_p | Parent box to restrict to |
[in] | iv | Variable to restrict |
[in] | mg | Multigrid options |
Definition at line 1227 of file m_af_multigrid.f90.
subroutine m_af_multigrid::mg_box_lpl_stencil | ( | type(box_t), intent(inout) | box, |
type(mg_t), intent(in) | mg, | ||
integer, intent(in) | ix | ||
) |
Store the matrix stencil for each cell of the box. The order of the stencil is (i, j), (i-1, j), (i+1, j), (i, j-1), (i, j+1) (e.g., -4, 1, 1, 1, 1)
[in] | ix | Stencil index |
Definition at line 1246 of file m_af_multigrid.f90.
|
private |
Store linear prolongation stencil for standard Laplacian.
[in,out] | box | Current box |
[in] | box_p | Parent box |
[in] | ix | Stencil index |
Definition at line 1267 of file m_af_multigrid.f90.
|
private |
Store sparse linear prolongation stencil for standard Laplacian.
[in,out] | box | Current box |
[in] | box_p | Parent box |
[in] | ix | Stencil index |
Definition at line 1287 of file m_af_multigrid.f90.
|
private |
Store prolongation stencil for standard Laplacian with variable coefficient that can jump at cell faces.
[in,out] | box | Current box |
[in] | box_p | Parent box |
[in] | ix | Stencil index |
Definition at line 1308 of file m_af_multigrid.f90.
|
private |
Store prolongation stencil for standard Laplacian with level set function for internal boundaries.
[in,out] | box | Current box |
[in] | box_p | Parent box |
[in] | ix | Stencil index |
Definition at line 1392 of file m_af_multigrid.f90.
|
private |
Store the matrix stencil for each cell of the box. The order of the stencil is (i, j), (i-1, j), (i+1, j), (i, j-1), (i, j+1) (e.g., -4, 1, 1, 1, 1)
[in] | ix | Index of the stencil |
Definition at line 1493 of file m_af_multigrid.f90.
|
private |
Store stencil for a box with variable coefficient and level set function.
[in] | ix | Index of the stencil |
Definition at line 1535 of file m_af_multigrid.f90.
real(dp) function, public m_af_multigrid::mg_lsf_dist_linear | ( | real(dp), dimension(ndim), intent(in) | a, |
real(dp), dimension(ndim), intent(in) | b, | ||
type(mg_t), intent(in) | mg | ||
) |
Compute distance to boundary starting at point a going to point b, in the range from [0, 1], with 1 meaning there is no boundary.
[in] | a | Start point |
[in] | b | End point |
Definition at line 1627 of file m_af_multigrid.f90.
real(dp) function, public m_af_multigrid::mg_lsf_dist_gss | ( | real(dp), dimension(ndim), intent(in) | a, |
real(dp), dimension(ndim), intent(in) | b, | ||
type(mg_t), intent(in) | mg | ||
) |
Find root of f in the interval [a, b]. If f(a) and f(b) have different signs, apply bisection directly. Else, first find the (assumed to be) unique local minimum/maximum to determine a bracket. Return relative location of root, or 1 if there is no root.
[in] | a | Start point |
[in] | b | End point |
Definition at line 1649 of file m_af_multigrid.f90.
|
private |
Simple bisection.
Definition at line 1687 of file m_af_multigrid.f90.
|
private |
Golden-section search on a line between a and b. Given a function f with a single local minimum/maximum in the interval [a,b], gss returns a subset interval [c,d] that contains the minimum/maximum with d-c <= tol. Adapted from https://en.wikipedia.org/wiki/Golden-section_search.
f | Function to minimize/maximize | |
[in] | in_a | Start coordinate |
[in] | in_b | End coordinate |
[in] | minimization | Whether to perform minimization or maximization |
[in] | tol | Absolute tolerance |
[in] | find_bracket | Whether to search for a bracket |
Definition at line 1714 of file m_af_multigrid.f90.
|
private |
Store the matrix stencil for each cell of the box. The order of the stencil is (i, j), (i-1, j), (i+1, j), (i, j-1), (i, j+1) (e.g., -4, 1, 1, 1, 1)
[in] | ix | Index of stencil |
Definition at line 1782 of file m_af_multigrid.f90.
subroutine, public m_af_multigrid::mg_compute_phi_gradient | ( | type(af_t), intent(inout) | tree, |
type(mg_t), intent(in) | mg, | ||
integer, intent(in) | i_fc, | ||
real(dp), intent(in) | fac, | ||
integer, intent(in), optional | i_norm | ||
) |
Compute the gradient of the potential and store in face-centered variables.
[in] | i_fc | Face-centered indices |
[in] | fac | Multiply with this factor |
[in] | i_norm | If present, store norm in this cell-centered variable |
Definition at line 1857 of file m_af_multigrid.f90.
subroutine, public m_af_multigrid::mg_box_lpl_gradient | ( | type(af_t), intent(inout) | tree, |
integer, intent(in) | id, | ||
type(mg_t), intent(in) | mg, | ||
integer, intent(in) | i_fc, | ||
real(dp), intent(in) | fac | ||
) |
Compute the gradient of the potential.
[in] | i_fc | Face-centered indices |
[in] | fac | Multiply with this factor |
Definition at line 1902 of file m_af_multigrid.f90.
subroutine, public m_af_multigrid::mg_compute_field_norm | ( | type(af_t), intent(inout) | tree, |
integer, intent(in) | i_fc, | ||
integer, intent(in) | i_norm | ||
) |
Compute norm of face-centered variable.
[in] | i_fc | Index of face-centered variable |
[in] | i_norm | Index of cell-centered variable |
Definition at line 1997 of file m_af_multigrid.f90.
subroutine, public m_af_multigrid::mg_box_field_norm | ( | type(af_t), intent(inout) | tree, |
integer, intent(in) | id, | ||
integer, intent(in) | i_fc, | ||
integer, intent(in) | i_norm | ||
) |
[in] | i_fc | Face-centered indices |
[in] | i_norm | Store norm in this cell-centered variable |
Definition at line 2015 of file m_af_multigrid.f90.
|
private |
Compute the gradient of the potential with a level set function and store in face-centered variables. The gradients are computed from the positive side of the level set function.
[in] | i_fc | Face-centered indices |
[in] | fac | Multiply with this factor |
Definition at line 2050 of file m_af_multigrid.f90.
|
private |
This method checks whether the level set function is properly defined on the coarse grid.
Definition at line 2144 of file m_af_multigrid.f90.
|
private |
Get amplitude of numerical gradient of level set function.
Definition at line 2164 of file m_af_multigrid.f90.