include/pops/coupling/system/amr_system_coupler.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
|
amr_system_coupler.hpp
Go to the documentation of this file.
10#include <pops/numerics/elliptic/interface/elliptic_problem.hpp> // field_postprocess, FieldPostProcess
13#include <pops/numerics/time/amr/reflux/amr_reflux_mf.hpp> // AmrLevelMP, advance_amr, mf_average_down_mb
55// step). Single source of truth on the GRID that all blocks share: per level the BoxArray (the boxes
57// (= ba.size()). Today this information is implicit, scattered across each AmrLevelMP (U.box_array() /
59// replace EquationBlock / AmrLevelMP and introduces NO block abstraction (the wide AmrBlock of the
60// design is a LATER step, and only if needed). The layout of a stack of levels is read via from_levels.
98// DistributionMapping (rank per box), same dx/dy (bit-for-bit). Returns true if everything matches.
99// dx/dy are the level spacings, identical by construction if the boxes are; we compare them anyway to
108// LAYOUT CONSISTENCY guard between blocks (point 1 of the capstone). The aux is SHARED per level: all
110// levels[k].aux = &aux_[k] and the advance read an inconsistent grid (silent out-of-bound access).
112// levels, then per level BoxArray (boxes AND order), DistributionMapping and dx/dy. Throws a clear
113// error at the FIRST discrepancy (block and level located). A single block matches itself trivially ->
395 // block with an extra field, the width stays 3 -> allocation strictly bit-identical to history.
406 // Populates the aux B_z component (index kAuxBaseComps) of the shared channel of EACH level from
410 // AMR engine does not touch the aux). Each level has ITS geometry: level k = geom_.refine(1 << k),
415 // without periodicity ambiguity on a patch domain). No-op if the aux width <= kAuxBaseComps (no
476// Poisson + aux per level) AND advances (step, reflux, subcycling). Splitting into two classes is
AmrCouplerMP: MULTI-PATCH E x B AMR coupler (coarse Poisson -> aux = grad phi -> fine injection -> co...
Umbrella for the AMR MultiFab stack: includes the numerics/time sub-headers in dependency order (flux...
Helpers shared by the three couplers (single-block Coupler, SystemAssembler, AmrSystemCoupler) for th...
Box2D: the integer index space of a 2D cell-centered Cartesian grid.
BoxArray: the set of boxes tiling a level (disjoint, covering).
std::vector< AmrLevelMP > & levels(std::size_t b)
Definition amr_system_coupler.hpp:232
void step(Real dt, ImplicitAdvance &&implicit_advance)
Advances the system by one macro-step dt.
Definition amr_system_coupler.hpp:280
void solve_fields()
Solves the fields: average_down per block, coarse system Poisson (RHS = Sum_s q_s n_s),...
Definition amr_system_coupler.hpp:242
void coupled_source_step(CoupledSource &&src, Real dt)
Definition amr_system_coupler.hpp:342
const MultiFab & coarse(std::size_t b) const
Definition amr_system_coupler.hpp:234
void set_bz(std::function< Real(Real, Real)> bz)
Definition amr_system_coupler.hpp:217
void step(Real dt)
Overload for a FULLY explicit system (static_assert if an implicit/IMEX block goes through it).
Definition amr_system_coupler.hpp:328
AmrSystemCoupler(System system, const Geometry &geom, const BoxArray &ba_coarse, const BCRec &bcPhi, RhsAssembler rhs_assembler, std::vector< std::vector< AmrLevelMP > > block_levels, Periodicity base_per=Periodicity{true, true}, bool replicated_coarse=true, PoissonCadence cadence=PoissonCadence::OncePerStep, std::function< bool(Real, Real)> active={}, std::function< Real(Real, Real)> bz={})
Definition amr_system_coupler.hpp:158
const std::vector< Box2D > & boxes() const
View on the underlying vector (element-by-element equality = same boxes AND same order).
Definition box_array.hpp:46
Owning MPI rank of each box, indexed by GLOBAL box index (parallel to a BoxArray).
Definition distribution_mapping.hpp:19
const std::vector< int > & ranks() const
View on the rank vector (element-by-element equality = same assignment).
Definition distribution_mapping.hpp:39
ConstArray4 const_array() const
READ handle (POD device-copyable) over this Fab. Valid as long as the Fab lives.
Definition fab2d.hpp:96
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
const Box2D & box(int li) const
VALID box of local fab li.
Definition multifab.hpp:71
int local_size() const
Number of fabs OWNED by this rank (bound on local indices).
Definition multifab.hpp:65
Coupled multi-species system, composed at runtime from generic bricks.
Definition system.hpp:89
Parallel seam: minimal MPI abstraction (rank/size + collectives) with serial fallback.
Concept: C is a valid coupling source for System if System is a CoupledSystem and if C exposes apply(...
Definition coupled_source.hpp:24
Definition elliptic_solver.hpp:30
CoupledSourceFor / NoCoupledSource: contract of an inter-species COUPLING source.
CoupledSystem: heterogeneous collection of equation blocks (multi-species, multi-scheme).
DistributionMapping: maps each box (by global index) to its owning MPI rank.
DESCRIPTIVE types of the elliptic stage: EllipticProblem (problem definition) and FieldPostProcess (f...
Elliptic (Poisson) RIGHT-HAND-SIDE assemblers: single-model and N-species.
EllipticSolver concept: common contract for elliptic solvers at the MultiFab level (solve D phi = f),...
fill_boundary: INTRA-level halo exchange (fills ghosts from neighbors).
for_each_cell and reductions: the parallelism SEAM over the cells of a Box2D; sync_host / sync_device...
GeometricMG: in-house geometric multigrid (V-cycle) for the elliptic operator, Gauss-Seidel smoother ...
Geometry: index-space (Box2D) <-> Cartesian physical-space mapping; PolarGeometry: SIBLING for a glob...
Implicit / IMEX block step as a named CONTRACT.
MultiFab: a field DISTRIBUTED over a level (equivalent of AMReX's MultiFab).
void coupler_inject_aux_mb(const MultiFab &parent, MultiFab &child, bool replicated_parent=true)
Definition amr_coupler_mp.hpp:60
constexpr bool amr_always_false_v
Definition amr_system_coupler.hpp:95
void fill_bz_box(Fab2D &f, const Box2D &box, const Geometry &g, const Bz &bz)
Writes B_z(x, y) at component kAuxBaseComps on box box of fab f, sampling bz at the cell centers of g...
Definition aux_fill.hpp:42
void same_layout_or_throw(const std::vector< std::vector< AmrLevelMP > > &block_levels)
Definition amr_system_coupler.hpp:115
bool same_level_layout(const BoxArray &a_ba, const DistributionMapping &a_dm, Real a_dx, Real a_dy, const BoxArray &b_ba, const DistributionMapping &b_dm, Real b_dx, Real b_dy)
Definition amr_system_coupler.hpp:101
BCRec derive_aux_bc(const BCRec &b)
Aux-channel BC derived from the potential phi BC: a periodic BC stays periodic, any other becomes Foe...
Definition aux_fill.hpp:27
Definition amr_hierarchy.hpp:29
Real for_each_cell_reduce_sum(const Box2D &b, F f)
SUM reduction of f(i, j) over box b.
Definition for_each.hpp:199
void mf_average_down_mb(const MultiFab &Uf, MultiFab &Uc)
Definition amr_subcycling.hpp:305
void backward_euler_source(const Model &model, const MultiFab &aux, MultiFab &U, Real dt, const NewtonOptions &opts, const ImplicitMask< Model::n_vars > &mask={}, NewtonReport *report=nullptr)
Definition implicit_stepper.hpp:486
@ Implicit
@ Explicit
constexpr int kAmrRefRatio
The native AMR refinement ratio between two consecutive levels.
Definition refinement_ratio.hpp:30
void field_postprocess(const MultiFab &phi, MultiFab &out, Real cx, Real cy, FieldPostProcess spec)
Definition elliptic_problem.hpp:104
PoissonCadence
Re-solve frequency of the Poisson on AMR: OncePerStep (phi solved once per macro-step,...
Definition amr_system_coupler.hpp:52
@ PerSubstep
@ OncePerStep
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
PHYSICAL boundary conditions at the domain edge (BCType, BCRec, fill_physical_bc, fill_ghosts).
Single source of truth for the native AMR refinement ratio.
Minimal scheduler for coupled systems: advance_subcycled reads each block's time policy (traits block...
Single source of truth on the GRID shared by all blocks: per level the BoxArray (boxes AND order),...
Definition amr_system_coupler.hpp:64
int nlev() const
Number of levels (= ba.size()).
Definition amr_system_coupler.hpp:70
std::vector< DistributionMapping > dm
Definition amr_system_coupler.hpp:66
static AmrHierarchyLayout from_levels(const std::vector< AmrLevelMP > &levels)
Extracts the layout (BoxArray + DistributionMapping + dx/dy per level) from the level stack of ONE bl...
Definition amr_system_coupler.hpp:76
Default implicit callback for AmrSystemCoupler::step: backward-Euler (Newton) on the model source,...
Definition amr_system_coupler.hpp:455
void operator()(Coupler &coupler, Block &block, Levels &levels, Real dt) const
Definition amr_system_coupler.hpp:459
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
Definition elliptic_problem.hpp:73
Cartesian geometry of a level: index domain + physical bounds [xlo, xhi] x [ylo, yhi].
Definition geometry.hpp:20
POPS_HD Real dy() const
Grid spacing in y (= (yhi - ylo) / domain.ny()). POPS_HD.
Definition geometry.hpp:33
POPS_HD Real dx() const
Grid spacing in x (= (xhi - xlo) / domain.nx()). POPS_HD.
Definition geometry.hpp:31
Geometry refine(int r) const
Geometry refined by ratio r: SAME physical extent, refined index domain (dx -> dx/r).
Definition geometry.hpp:40
Per-direction periodicity: halo wrapping in x and/or y during the exchange (false = open edge,...
Definition fill_boundary.hpp:37
SourceFreeModel<M>: adapter that cancels the source of M (explicit IMEX half-step).
Definition state_access.hpp:50
Base scalar types and the POPS_HD macro (host+device portability).
Generated by