Namespace mgrid
Classes
| Type | Name |
|---|---|
| struct | Axis One grid axis: point count, spacing, and periodicity, with the index arithmetic every stencil / sweep / transfer needs. A bounded axis uses one-sided stencils at its ends and never wraps; a periodic axis has no ends (index arithmetic is mod n ). |
| class | BoundaryConditions Container for boundary conditions on all four edges of a domain. |
| struct | BoundaryLengthError Exception thrown when boundary condition arrays have mismatched lengths. |
| struct | BoundaryPoint Boundary condition point (type and value). |
| struct | Deriv Ten finite-difference partials at a point: dx, dxu, dz, dzu, dxx, dxxu, dzz, dzzu, dxz, dxzu. |
| class | FDArray 2-D scalar field on a finite-difference grid: FDBase geometry plus an owningField2D of element values. |
| class | FDBase |
| struct | FDVecArray A 2-component vector field on a finite-difference grid. |
| class | Field2D |
| struct | InvalidBoundaryCondition Exception thrown when an invalid boundary condition is supplied. |
| class | LinearMultigrid Linear full-multigrid (FMG) solver. |
| class | MultigridBase Abstract base class for the multigrid solvers. |
| struct | MultigridError Base exception for multigrid solver errors. |
| class | NcWriter Incremental writer for a gridded solution file (netCDF-4). |
| class | NonlinearMultigrid Nonlinear full-approximation-scheme (FAS) multigrid solver. |
| struct | Settings Multigrid solver settings. |
| class | Stack Grid-level hierarchy for a multigrid solve. |
Public Types
| Type | Name |
|---|---|
| enum | AxisKind Whether a grid axis has physical boundaries or wraps periodically. |
| typedef std::vector< BoundaryPoint > | Boundary Vector of boundary condition points. |
| enum | BoundaryFlag Domain boundary edges. |
| enum | ConditionType Boundary condition type. |
| enum | CycleType Multigrid cycle type. |
| typedef int | Level Multigrid level (integer index). |
Public Attributes
| Type | Name |
|---|---|
| std::array< BoundaryFlag, 4 > | allBoundaryFlags = /* multi line expression */Array of all four boundary flags: [left, right, top, bottom]. |
| BoundaryPoint | periodicCondition = {.conditionType = periodic, .value = 0.0}A boundary point on a periodic edge (the value field is unused). |
| BoundaryPoint | zeroDirichletCondition = {.conditionType = dirichlet, .value = 0.0}Zero-Dirichlet boundary condition (zero value). |
| BoundaryPoint | zeroNeumannCondition = {.conditionType = neumann, .value = 0.0}Zero-Neumann boundary condition (zero normal derivative). |
Public Functions
| Type | Name |
|---|---|
| void | apply (Field2D & f, F fn) Maps every element through fn in place. |
| Field2D | dot (const FDVecArray & a, const FDVecArray & b) Computes the component-wise dot product of two vector fields. |
| void | for_each_index (const Field2D & f, F fn) Invokes fn once per index pair, in row-major order. |
| double | frobenius_norm (const Field2D & f) Root-mean-square element magnitude. |
| void | injection_operator (FDArray & coarse, const FDArray & fine) Straight-injection restriction: coarse(ic, jc) = fine(2*ic, 2*jc) . |
| void | interpolation_operator (const FDArray & coarse, FDArray & fine) Bilinear interpolation: transfers coarse onto the next finer gridfine . |
| const char * | library_version () noexcept Returns the library version string, e.g. "2.0.0". |
| void | project_out_constant (Field2D & f) Subtract the arithmetic mean of all elements, projecting out the constant null-space component. |
| void | red_black_sweep (const Field2D & f, F fn) Visits the interior points in red-then-black checkerboard order. |
| void | red_black_sweep (const Field2D & f, F fn, const Axis & ax, const Axis & az) Red-then-black checkerboard sweep with explicit per-axis bounds. |
| void | restriction_operator (FDArray & coarse, const FDArray & fine) Full-weighting restriction: transfers fine onto the next coarser gridcoarse . |
| double | sum_of_squares (const Field2D & f) Sum of the squares of every element, \(\sum_{i,j} f_{ij}^2\) . |
Public Types Documentation
enum AxisKind
Whether a grid axis has physical boundaries or wraps periodically.
enum mgrid::AxisKind {
bounded,
periodic
};
typedef Boundary
Vector of boundary condition points.
using mgrid::Boundary = std::vector<BoundaryPoint>;
enum BoundaryFlag
Domain boundary edges.
enum mgrid::BoundaryFlag {
leftBoundary,
rightBoundary,
topBoundary,
bottomBoundary
};
enum ConditionType
Boundary condition type.
enum mgrid::ConditionType {
dirichlet,
neumann,
periodic
};
enum CycleType
Multigrid cycle type.
enum mgrid::CycleType {
vCycle = 1,
wCycle = 2,
threeCycle = 3
};
typedef Level
Multigrid level (integer index).
using mgrid::Level = int;
Public Attributes Documentation
variable allBoundaryFlags
Array of all four boundary flags: [left, right, top, bottom].
std::array<BoundaryFlag, 4> mgrid::allBoundaryFlags;
variable periodicCondition
A boundary point on a periodic edge (the value field is unused).
BoundaryPoint mgrid::periodicCondition;
variable zeroDirichletCondition
Zero-Dirichlet boundary condition (zero value).
BoundaryPoint mgrid::zeroDirichletCondition;
variable zeroNeumannCondition
Zero-Neumann boundary condition (zero normal derivative).
BoundaryPoint mgrid::zeroNeumannCondition;
Public Functions Documentation
function apply
Maps every element through fn in place.
template<class F>
void mgrid::apply (
Field2D & f,
F fn
)
Parameters:
ffield to transformfncallabledouble(double)giving each element's new value
function dot
Computes the component-wise dot product of two vector fields.
Field2D mgrid::dot (
const FDVecArray & a,
const FDVecArray & b
)
Parameters:
afirst vector fieldbsecond vector field; must have the same shape asa
Returns:
a new Field2D containing a.first(i,j)*b.first(i,j) + a.second(i,j)*b.second(i,j) at each point
function for_each_index
Invokes fn once per index pair, in row-major order.
template<class F>
void mgrid::for_each_index (
const Field2D & f,
F fn
)
Parameters:
ffield whose shape bounds the iterationfncallable(int i, int j)
function frobenius_norm
Root-mean-square element magnitude.
inline double mgrid::frobenius_norm (
const Field2D & f
)
Parameters:
ffield to reduce
Returns:
sqrt(sum_of_squares(f) / f.size())
function injection_operator
Straight-injection restriction: coarse(ic, jc) = fine(2*ic, 2*jc) .
void mgrid::injection_operator (
FDArray & coarse,
const FDArray & fine
)
Parameters:
coarsedestination grid on the coarser level, overwrittenfinesource grid on the finer level, read only
Note:
Every coarse node (boundary nodes included) copies the collocated fine node's value with no averaging. This is the restriction the full-approximation scheme uses for the solution transfer: full weighting would smooth the restricted solution and shift the FAS fixed point away from the fine discrete solution. The residual / right-hand-side transfers still use restriction_operator.
function interpolation_operator
Bilinear interpolation: transfers coarse onto the next finer gridfine .
void mgrid::interpolation_operator (
const FDArray & coarse,
FDArray & fine
)
Parameters:
coarsesource grid on the coarser level, read only (coarse-first argument order)finedestination grid on the finer level, overwritten with the interpolated field
Note:
Each coarse node (ic, jc) is injected onto the collocated even-even fine node (2*ic, 2*jc). The remaining fine nodes are then filled from those injected values: a node on an even row or even column is the 0.5 average of its two axial even-even neighbours, and an odd-row/odd-column node is the 0.25 average of its four diagonal even-even neighbours. A linear field is reproduced exactly. On a periodic fine axis (taken from fine.x_axis() / fine.z_axis()) the last odd node is filled too and the "next" even-even neighbour wraps mod n; a bounded axis is byte-identical to before.
function library_version
Returns the library version string, e.g. "2.0.0".
const char * mgrid::library_version () noexcept
function project_out_constant
Subtract the arithmetic mean of all elements, projecting out the constant null-space component.
inline void mgrid::project_out_constant (
Field2D & f
)
Parameters:
ffield modified in place; afterwardssum(f) == 0to rounding
Note:
Used by fully-periodic solvers, whose discrete operator has a constant null space, to pin the otherwise-undetermined additive constant each sweep.
function red_black_sweep
Visits the interior points in red-then-black checkerboard order.
template<class F>
void mgrid::red_black_sweep (
const Field2D & f,
F fn
)
Parameters:
ffield whose interior (all but the outermost row/column) is sweptfncallable(int i, int j)
Note:
All "red" points ((i + j) even) are visited before any "black" point ((i + j) odd).
function red_black_sweep
Red-then-black checkerboard sweep with explicit per-axis bounds.
template<class F>
void mgrid::red_black_sweep (
const Field2D & f,
F fn,
const Axis & ax,
const Axis & az
)
Parameters:
ffield being swept (only its shape is used;fndoes the updates)fncallable(int i, int j)invoked once per swept pointaxx-axis (rows) providing the sweep bounds viaAxis::lo()/hi()azz-axis (columns) providing the sweep bounds viaAxis::lo()/hi()
Note:
A periodic axis visits [0, n); a bounded axis visits [1, n-1). All "red" points ((i + j) even) are visited before any "black" point ((i + j) odd).
function restriction_operator
Full-weighting restriction: transfers fine onto the next coarser gridcoarse .
void mgrid::restriction_operator (
FDArray & coarse,
const FDArray & fine
)
Parameters:
coarsedestination grid, overwritten with the restricted field (coarse-first argument order)finesource grid on the finer level, read only
Note:
Each coarse node (ic, jc) collects from the fine node (2*ic, 2*jc) and its neighbours with the full-weighting stencil weights 4 (centre), 2 (axial neighbours) and 1 (diagonal neighbours), accumulated as a single num / den sum whose divisor is the weight total that actually contributed. On a bounded axis a neighbour that would step outside the grid is dropped, so the divisor is 16 in the interior (4 + 2*4 + 1*4), 12 along an edge (4 + 2*3 + 1*2) and 9 at a corner (4 + 2*2 + 1*1). On a periodic axis (taken from fine.x_axis() / fine.z_axis()) no neighbour is ever dropped: the index wraps mod n and the divisor stays 16. A constant field is reproduced exactly in every case.
function sum_of_squares
Sum of the squares of every element, \(\sum_{i,j} f_{ij}^2\) .
inline double mgrid::sum_of_squares (
const Field2D & f
)
Parameters:
ffield to reduce
Returns:
the sum of squared elements
The documentation for this class was generated from the following file include/multigrid/boundary_conditions.hpp