include/pops/numerics/elliptic/mg/geometric_mg.hpp Source FileΒΆ
|
adc_cpp 0.3.0
Model-free C++23 core for coupled hyperbolic-elliptic systems on adaptive (AMR) meshes, with MPI and GPU (Kokkos) backends
|
geometric_mg.hpp
Go to the documentation of this file.
43#include <chrono> // last_bottom_seconds(): self-time the coarsest (bottom) GS solve (Spec 5, ADC-479)
52// DIAGNOSTIC trace of the MG V-cycle (milestone #93). Active only if POPS_TRACE_SOLVE_FIELDS is set;
95 // levelset if it is not provided. cut_cell=false => historical staircase stencil (bit-identical).
108 // (solve_robust LOCALLY doubles nu1/nu2 if the embedded boundary makes the cycle diverge, then restores them.)
156 // exact layout that average_down/interpolate would have allocated internally: coarsen(L.ba, 2) on the
158 // prolongation (interpolate(C.phi, L.corr)) of the same level (uses disjoint in time -> a single
226 // --- PER-SOLVE PROFILING STATS (Spec 5 sec.13.11.1, ADC-479 criteria 42/43) -------------------
227 // Cached by the most recent solve(rel_tol, max_cycles, abs_tol) call (the no-argument concept-level
228 // solve() funnels through it). The System reads these back at the field_solve seam to populate the
229 // elliptic-solver native counters WITHOUT threading a profiler into the deep numerics: chrono-only
230 // here, no profiler / Kokkos dependency. Additive accessors -- no existing path reads them, the
234 // last_bottom_seconds(): wall-clock self-time of the coarsest-grid (bottom) Gauss-Seidel solves
300 // ADC-251: 0 ghost / no fill_ghosts is DELIBERATE (a reaction term is zeroth-order: kappa is never
360 // restriction to the coarse therefore only serves a possible MG residual on the full operator (the
391 // Kokkos::fence() before popRegion) around this V-cycle would let Nsight attribute the GPU time on
392 // ROMEO. It is intentionally NOT added here: it needs a Kokkos include in a header the profiling
393 // design keeps Kokkos-free (chrono only, last_bottom_seconds()), and the host build (Serial-only
394 // conda Kokkos) gains nothing. Add it at the System/ProgramContext seam if Nsight attribution is
405 // relative criterion unchanged. The floor avoids over-solving an ALREADY converged state (tiny r0,
406 // typical of an OFF-STEP solve on an unchanged state): early-exit without cycling if r0 is below abs_tol.
446 // OFF-STEP solves on an already-converged state exit without cycling (initial residual under the floor).
455 // warm start propagates the divergence from one step to the next), hence a nan in the field at high
512 // a DISTRIBUTED MULTI-BOX coarse: without it, norm_inf returns the LOCAL max (different per rank),
515 // MPI fluxes (MPI_ERR_TRUNCATE). Idempotent under replication (local max = global on each rank) and
530 // MG residual) thus reuses the same operator, without duplicating the eps/kappa/Axy field wiring.
531 // nullptr when the corresponding term is inactive (cf. the internal *_ptr). Additive: no existing
552 // restriction (average_down) and the prolongation (interpolate) of the level. The bottom leaves them empty
591 // (eps, eps_y, kappa, ...) designated by a pointer-to-MGLevel-member MGLevel::*, either SAMPLED
600 // MultiFab(L.ba, L.dm, 1, nghost) at each level, writes f(x_cell, y_cell) at the center, then ghosts
601 // (fill_ghosts with ebc) ONLY if do_fill. Body extracted word-for-word from set_epsilon(fn) etc.
621 // Copy comp 0 of the fine field (already discretized) onto the fine level then RESTRICTION (average_down,
624 // if do_fill. Body extracted word-for-word from set_epsilon(const MultiFab&) / set_reaction(const MultiFab&).
625 void restrict_and_fill(MultiFab MGLevel::* field, const MultiFab& fine, int nghost, bool do_fill,
654 // residual (poisson_residual) carries them. The GS smoother touches only the diagonal -> its diag stays
656 // convention. For symmetric-positive-definite A the V-cycle stays contractive; for strongly non-symmetric
666 // no profiler dependency here) and accumulate into the per-solve last_bottom_seconds_ (reset at
668 // sec.13.11.1, ADC-479). Host serial / per-rank; the device-fence for an exact GPU bottom time is
715 // PER-SOLVE PROFILING STATS (read back at the System field_solve seam, ADC-479 criteria 42/43).
716 // last_cycles_/last_residual_ are set by solve(); last_bottom_seconds_ is reset at the top of solve()
BoxArray: the set of boxes tiling a level (disjoint, covering).
Owning MPI rank of each box, indexed by GLOBAL box index (parallel to a BoxArray).
Definition distribution_mapping.hpp:19
ConstArray4 const_array() const
READ handle (POD device-copyable) over this Fab. Valid as long as the Fab lives.
Definition fab2d.hpp:96
Definition geometric_mg.hpp:79
int solve(Real rel_tol, int max_cycles, Real abs_tol=Real(0))
Definition geometric_mg.hpp:407
void set_epsilon(std::function< Real(Real, Real)> eps_fn)
Definition geometric_mg.hpp:249
void set_epsilon(const MultiFab &eps_fine)
Definition geometric_mg.hpp:260
void set_epsilon_anisotropic(const MultiFab &eps_x_fine, const MultiFab &eps_y_fine)
Definition geometric_mg.hpp:286
void set_reaction(std::function< Real(Real, Real)> kappa_fn)
Definition geometric_mg.hpp:304
void set_epsilon_anisotropic(std::function< Real(Real, Real)> eps_x_fn, std::function< Real(Real, Real)> eps_y_fn)
Definition geometric_mg.hpp:274
int solve_robust(Real rel_tol, int max_cycles)
Definition geometric_mg.hpp:471
GeometricMG(const Geometry &geom, const BoxArray &ba, const BCRec &bc, std::function< bool(Real, Real)> active={}, bool replicated=false, int min_coarse=2, int nu1=2, int nu2=2, int nbottom=50, bool cut_cell=false, std::function< Real(Real, Real)> levelset={})
Definition geometric_mg.hpp:109
void set_reaction(const MultiFab &kappa_fine)
Definition geometric_mg.hpp:314
void set_cross_terms(std::function< Real(Real, Real)> a_xy_fn, std::function< Real(Real, Real)> a_yx_fn)
Definition geometric_mg.hpp:329
void set_cross_terms(const MultiFab &a_xy_fine, const MultiFab &a_yx_fine)
Definition geometric_mg.hpp:363
double last_bottom_seconds() const
Definition geometric_mg.hpp:240
Field distributed over a level: decomposition (BoxArray) + distribution (DistributionMapping) + ncomp...
Definition multifab.hpp:33
Fab2D & fab(int li)
Local fab at index li (0 <= li < local_size()), for writing.
Definition multifab.hpp:67
Parallel seam: minimal MPI abstraction (rank/size + collectives) with serial fallback.
SHARED cut-fraction primitive (cut-cell / embedded boundary).
DistributionMapping: maps each box (by global index) to its owning MPI rank.
Geometry: index-space (Box2D) <-> Cartesian physical-space mapping; PolarGeometry: SIBLING for a glob...
MultiFab arithmetic (saxpy, lincomb, norm_inf, dot) over VALID cells.
MultiFab: a field DISTRIBUTED over a level (equivalent of AMReX's MultiFab).
POPS_HD CutFraction cut_fraction(const LevelSet &ls, Real xc, Real yc, Real dx, Real dy)
Computes the cut geometry of an ACTIVE cell (center (xc, yc) with ls < 0) from a level-set ls evaluat...
Definition cut_fraction.hpp:76
POPS_HD ShortleyWellerWeights shortley_weller(const CutFraction &cf)
Definition cut_fraction.hpp:102
Definition amr_hierarchy.hpp:29
void average_down(const MultiFab &fine, MultiFab &coarse, int r, MultiFab &cfine)
CONSERVATIVE average fine -> coarse (ratio r): coarse(I, J) = average of the r^2 fine cells of the bl...
Definition refinement.hpp:181
void for_each_cell(const Box2D &b, F f)
Applies f to EACH cell (i, j) of box b (bounds inclusive), via Kokkos::parallel_for (Serial / OpenMP ...
Definition for_each.hpp:138
void zero_conductor(MultiFab &phi, const MultiFab &mask)
Definition poisson_operator.hpp:410
BoxArray coarsen(const BoxArray &ba, int r)
Coarsens each box of the BoxArray by a ratio r (coarsen box by box, order preserved).
Definition refinement.hpp:39
void saxpy(MultiFab &y, Real a, const MultiFab &x)
y <- y + a x over ALL components of the valid cells. Identical layouts required.
Definition mf_arith.hpp:102
void interpolate(const MultiFab &coarse, MultiFab &fine, int r, MultiFab &cfine)
Interpolation coarse -> fine (ratio r) by piecewise-CONSTANT injection: each fine cell (including the...
Definition refinement.hpp:220
void gs_smooth(MultiFab &phi, const MultiFab &f, const Geometry &geom, const BCRec &bc, int nsweeps, const MultiFab *mask=nullptr, const MultiFab *coef=nullptr, const MultiFab *eps=nullptr, const MultiFab *kappa=nullptr, const MultiFab *eps_y=nullptr)
Definition poisson_operator.hpp:389
void poisson_residual(MultiFab &phi, const MultiFab &f, const Geometry &geom, const BCRec &bc, MultiFab &res, const MultiFab *mask=nullptr, const MultiFab *coef=nullptr, const MultiFab *eps=nullptr, const MultiFab *kappa=nullptr, const MultiFab *eps_y=nullptr, const MultiFab *a_xy=nullptr, const MultiFab *a_yx=nullptr)
Definition poisson_operator.hpp:271
BCType
Boundary condition type for a face: Periodic (handled by fill_boundary), Foextrap (zero gradient,...
Definition physical_bc.hpp:25
@ Foextrap
@ Periodic
void fill_ghosts(MultiFab &mf, const Box2D &domain, const BCRec &bc)
COMPLETE ghost filling: fill_boundary (interior + periodic, periodicity deduced from bc) THEN fill_ph...
Definition physical_bc.hpp:227
Real norm_inf(const MultiFab &mf, int comp=0)
Infinity norm max |f(.,.,comp)| over the valid cells (LOCAL, without MPI all_reduce).
Definition mf_arith.hpp:123
PHYSICAL boundary conditions at the domain edge (BCType, BCRec, fill_physical_bc, fill_ghosts).
Free functions of the elliptic operator: apply_laplacian (matvec), poisson_residual (residual),...
AMR inter-level transfer operators (integer ratio r) + parallel_copy.
WRITE POD handle (raw pointer + strides) over a Fab2D buffer, indexed by (i, j, c) IN GLOBAL INDICES ...
Definition fab2d.hpp:29
Boundary conditions for the FOUR faces of the domain (type + associated Dirichlet value).
Definition physical_bc.hpp:29
READ-only handle (const counterpart of Array4): same layout and same contract (POD device-copyable,...
Definition fab2d.hpp:44
Cartesian geometry of a level: index domain + physical bounds [xlo, xhi] x [ylo, yhi].
Definition geometry.hpp:20
POPS_HD Real x_cell(int i) const
Abscissa at the CENTER of cell index i (i = 0 -> xlo + dx/2; defined for negative i)....
Definition geometry.hpp:35
POPS_HD Real y_cell(int j) const
Ordinate at the CENTER of cell index j. POPS_HD.
Definition geometry.hpp:37
Definition geometric_mg.hpp:66
POPS_HD void operator()(int i, int j) const
Definition geometric_mg.hpp:69
Base scalar types and the POPS_HD macro (host+device portability).
Generated by