include/pops/coupling/amr/amr_coupler_mp.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_coupler_mp.hpp
Go to the documentation of this file.
8#include <pops/coupling/single/coupler.hpp> // detail::coupler_eval_rhs (f = model.elliptic_rhs(U))
9#include <pops/numerics/elliptic/mg/composite_fac_poisson.hpp> // COMPOSITE FAC 2-level Poisson solver (opt-in)
12#include <pops/numerics/time/amr/reflux/amr_reflux_mf.hpp> // AmrLevelMP, amr_step_multilevel_multipatch, mf_*_mb
28#include <map> // named_aux_: model-named aux fields (comp -> coarse field), re-applied by compute_aux
138// AND distributed multi-box, GLOBAL indices (i,j)), only the per-cell write differs -- here we copy
139// the ncomp components positionally (no density/momentum/energy wiring; the caller already provides
140// the conservative, e.g. [rho, rho*u, rho*v]). gamma omitted (no energy derived). Index computed
166// boxes are disjoint -> the cross-rank sum reconstructs the field exactly). Replicated mono-box:
167// a single fab covers everything, the buffer is already complete, all_reduce would be the identity
185// Poisson solve) into a GLOBAL n*n row-major field, MULTI-BOX and DISTRIBUTION-AWARE. aux(0) shares
186// EXACTLY the layout of the coarse U (same BoxArray + DistributionMapping, cf. amr_level_storage:
189// sum), avoided in replicated mono-box (field already complete). PRECONDITION: update()/compute_aux
190// has run at least once (otherwise aux(0) is 0). Strict counterpart of coupler_read_coarse for phi.
191inline std::vector<double> coupler_read_coarse_phi(const MultiFab& aux0, int n, bool replicated) {
207// MULTI-BOX and DISTRIBUTION-AWARE. Makes the hierarchy consistent before the first sync_down (the
212inline void coupler_inject_coarse_to_fine_mb(const MultiFab& Uc, MultiFab& Uf, bool replicated) {
232 const BoxArray ccoarse = coarsen(Uf.box_array(), kAmrRefRatio); // coarse footprint (valid cells)
249// Builds the coarse level (BoxArray + DistributionMapping) of the AmrSystem path according to the
251// - replicated (distribute=false, DEFAULT): mono-box covering the domain, dmap = my_rank() everywhere
254// - distributed (distribute=true): multi-box BoxArray::from_domain(dom, max_grid) spread round-robin
257inline std::pair<BoxArray, DistributionMapping> coupler_make_coarse_layout(int n, bool distribute,
295 // superior. mg_ receives the same flag (otherwise, under replicated MPI, the coarse would fall on
296 // the single rank 0 and compute_aux would read a phi absent elsewhere). In serial, both coincide.
297 AmrCouplerMP(const Model& model, const Geometry& geom, const BoxArray& ba_coarse, const BCRec& bc,
331 // ----------------------------------------------------------------------------------------------
333 // CONSERVATIVE STATE per level (all components) + the phi (multigrid warm-start), and can IMPOSE
335 // accessors loop over local_size() + device_fence(), WITHOUT MPI gather (the facade rejects np>1
337 // ----------------------------------------------------------------------------------------------
389 // Reads the potential phi of level @p k, flat nf*nf row-major field (nf = n << k), zeros outside patches.
392 // aux(k) component 0 (informational; recomputed at update). It is mg_.phi() level 0 that makes the
393 // restart BIT-IDENTICAL (the 1st post-restart solve starts from the same guess as the continuous run).
412 // multigrid restart is BIT-IDENTICAL (the 1st post-restart solve starts from the same guess). Level
432 // above fill the GLOBAL buffer from the LOCAL fabs only (zeros where this rank owns no box); these
433 // add an all_reduce_sum_inplace so EACH rank holds the complete field (AMR reflux pattern, comm.hpp;
434 // MIRROR of System::state_global / gather_global). COLLECTIVE: all ranks MUST call them. Mono-rank
435 // the reduce is the identity -> bit-identical to level_state / level_potential. The base distributed
449 // fine_boxes BoxArray (instead of Berger-Rigoutsos clustering on tags), via the SAME mechanism as
450 // regrid (regrid_field_on_layout: parent interp + fine carry-over), then reattaches the level-1 aux.
451 // The rebuilt valid content is OVERWRITTEN afterwards by set_level_state (restore as-is): here we
489 // COMPOSITE path (opt-in): the fine patch TRULY refines the elliptic. Supported scope = 2 levels,
490 // ONE mono-box fine patch, replicated coarse (Phase 2). Otherwise Option A below (bit-identical).
500 // aux = (phi, grad phi) per LOCAL coarse fab: covers the replicated mono-box (1 fab) as well as
515 // model-NAMED aux (ADC-291): re-apply the static named fields onto the coarse valid cells BEFORE
516 // fill_boundary (ghosts) and the injection (lines below), so they reach every level and survive a
521 apply_named_aux_bc(); // ADC-369: per-field halo override on the coarse physical ghosts (after the
636 // ADC-291 NOTE: unlike compute_aux (Option A), this opt-in composite-FAC path does NOT re-apply
637 // named aux onto the fine level (it derives each level's aux from the FAC phi, with no coarse->fine
638 // aux injection). The coarse named comp survives (the grad writes touch only comps 0..2), but a
639 // fine-level model reading extra_field(k) would read 0. set_composite_poisson is C++-only and not
640 // facade-reachable, so named aux cannot hit this path today; carrying named aux to the composite
650 // f = elliptic_rhs(U) PER LEVEL: the fine has its OWN refined right-hand side (not an injection).
655 // level-0 aux (coarse): phi + grad from phi_coarse (same centered stencils as the Option A path).
675 replicated_coarse_; // level 0 replicated (true) or distributed multi-box (false, de-replication)
677 // current fine patch (rebuilt if the patch changes after regrid). Default OFF -> Option A bit-identical.
683 // (n*n row-major). STATIC user fields re-applied by compute_aux each update (so they persist across
686 // Per-field aux HALO policy (ADC-369): component -> uniform boundary policy, applied to the coarse aux
691 // SystemFieldSolver::apply_named_aux_one and AmrRuntime::apply_named_aux: per local fab (MPI-safe),
692 // valid cells only, global flat index j*nx+i. compute_aux runs the coarse->fine injection right
711 // Per-field aux HALO override (ADC-369) on the COARSE aux, AFTER the shared fill. Overrides only each
712 // declared component's physical-face ghosts; aux_halo_override(mg_.bc(), policy) keeps periodic faces
Diagnostics extracted from the AMR couplers: mass and max drift speed (responsibility c).
AmrLevelStack: AMR hierarchy storage (levels + aux) extracted from the couplers.
Umbrella for the AMR MultiFab stack: includes the numerics/time sub-headers in dependency order (flux...
amr_regrid_finest: Berger-Rigoutsos regrid of the finest level (responsibility b).
Box2D: the integer index space of a 2D cell-centered Cartesian grid.
BoxArray: the set of boxes tiling a level (disjoint, covering).
std::vector< double > level_potential(int k)
Definition amr_coupler_mp.hpp:394
void set_level_state(int k, const std::vector< double > &s)
Definition amr_coupler_mp.hpp:368
void set_composite_poisson(bool v)
OPT-IN: replaces the Option A AMR Poisson (coarse solve + piecewise-constant gradient injection) with...
Definition amr_coupler_mp.hpp:482
void set_named_aux_bc(int comp, AuxHaloPolicy policy)
Registers a per-field aux HALO policy (ADC-369) for the named component comp.
Definition amr_coupler_mp.hpp:327
bool composite_poisson() const
Definition amr_coupler_mp.hpp:483
void set_hierarchy(const std::vector< Box2D > &fine_boxes)
Definition amr_coupler_mp.hpp:454
std::vector< double > level_potential_global(int k)
Definition amr_coupler_mp.hpp:442
AmrCouplerMP(const Model &model, const Geometry &geom, const BoxArray &ba_coarse, const BCRec &bc, std::vector< AmrLevelMP > levels, std::function< bool(Real, Real)> active={}, bool replicated_coarse=true)
Definition amr_coupler_mp.hpp:297
void step(Real dt, bool recon_prim=false, bool imex=false, const NewtonOptions &nopts={}, AmrTimeMethod tmethod=AmrTimeMethod::kEuler, Real pos_floor=Real(0))
Advances the hierarchy by one step dt: update() then advance_amr (Berger-Oliger subcycling + reflux +...
Definition amr_coupler_mp.hpp:556
void set_level_potential(int k, const std::vector< double > &p)
Definition amr_coupler_mp.hpp:414
void advance_transport(Real dt, bool recon_prim=false, Real pos_floor=Real(0))
TRANSPORT-ONLY ADVANCE (hyperbolic), WITHOUT update() or source.
Definition amr_coupler_mp.hpp:573
void set_named_aux(int comp, std::vector< Real > field)
Registers a model-NAMED aux field (ADC-291) at shared-channel component comp (>= kAuxNamedBase),...
Definition amr_coupler_mp.hpp:319
std::vector< double > level_state(int k)
Definition amr_coupler_mp.hpp:343
Real max_wave_speed()
Max wave speed on the coarse level via model.max_wave_speed.
Definition amr_coupler_mp.hpp:612
void regrid(Crit crit, int grow=2, int margin=2)
Definition amr_coupler_mp.hpp:583
void update()
Updates the hierarchy before a step: sync_down (fine -> coarse) then compute_aux (coarse Poisson + gr...
Definition amr_coupler_mp.hpp:532
std::vector< double > level_state_global(int k)
Definition amr_coupler_mp.hpp:437
static BoxArray from_domain(const Box2D &domain, int max_grid_size)
Tile the domain into tiles of at most max_grid_size per direction, distributed evenly.
Definition box_array.hpp:30
Owning MPI rank of each box, indexed by GLOBAL box index (parallel to a BoxArray).
Definition distribution_mapping.hpp:19
const Box2D & grown_box() const
Grown box (valid + ng ghosts) = actual memory footprint.
Definition fab2d.hpp:76
ConstArray4 const_array() const
READ handle (POD device-copyable) over this Fab. Valid as long as the Fab lives.
Definition fab2d.hpp:96
Array4 array()
WRITE handle (POD device-copyable) over this Fab. Valid as long as the Fab lives.
Definition fab2d.hpp:91
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 DistributionMapping & dmap() const
GLOBAL distribution (owner rank per box).
Definition multifab.hpp:58
const BoxArray & box_array() const
GLOBAL decomposition of the level (all boxes, all ranks).
Definition multifab.hpp:56
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
Parallel seam: minimal MPI abstraction (rank/size + collectives) with serial fallback.
CompositeFacPoisson: 2-level AMR COMPOSITE elliptic solver (Fast Adaptive Composite,...
Definition elliptic_solver.hpp:30
Coupler: single-block hyperbolic-elliptic coupler (Poisson -> aux -> advance loop).
DistributionMapping: maps each box (by global index) to its owning MPI rank.
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...
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
std::vector< double > coupler_read_coarse(const MultiFab &U, int n, bool replicated)
Definition amr_coupler_mp.hpp:169
std::pair< BoxArray, DistributionMapping > coupler_make_coarse_layout(int n, bool distribute, int max_grid)
Definition amr_coupler_mp.hpp:257
void coupler_eval_rhs(const MultiFab &state, MultiFab &rhs, const Model &model)
Assemble the single-model elliptic RHS: rhs = model.elliptic_rhs(U) on valid cells (delegated to Sing...
Definition coupler.hpp:53
std::vector< double > coupler_read_coarse_phi(const MultiFab &aux0, int n, bool replicated)
Definition amr_coupler_mp.hpp:191
void coupler_write_coarse(MultiFab &U, const std::vector< double > &rho, int n, int ncomp, double gamma)
Definition amr_coupler_mp.hpp:112
void coupler_grad_phi(const MultiFab &phi, MultiFab &aux, Real cx, Real cy)
Set aux = (phi, d phi/dx, d phi/dy) by centered differences (factors cx, cy = 1/(2 dx),...
Definition coupler.hpp:64
void coupler_inject_coarse_to_fine_mb(const MultiFab &Uc, MultiFab &Uf, bool replicated)
Definition amr_coupler_mp.hpp:212
void coupler_write_coarse_state(MultiFab &U, const std::vector< double > &state, int n, int ncomp)
Definition amr_coupler_mp.hpp:143
Definition amr_hierarchy.hpp:29
void mf_average_down_mb(const MultiFab &Uf, MultiFab &Uc)
Definition amr_subcycling.hpp:305
BCRec aux_halo_override(const BCRec &shared, const AuxHaloPolicy &p)
Builds the effective override BCRec for a per-field aux halo: starts from the SHARED aux BC shared (s...
Definition physical_bc.hpp:204
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
BoxArray coarsen_grown(const BoxArray &ba, int ngrow, int r)
Definition amr_subcycling.hpp:241
POPS_HD constexpr int aux_comps()
Width of the aux channel a model CONSUMES.
Definition physical_model.hpp:67
void device_fence()
Device barrier: waits for in-flight kernels to finish before a HOST access to unified memory.
Definition kokkos_env.hpp:43
void fill_boundary(MultiFab &mf, const Box2D &domain, Periodicity per={})
BLOCKING halo exchange: begin then end immediately (no overlap).
Definition fill_boundary.hpp:333
Real amr_max_drift_speed_mb(const MultiFab &aux0, Real B0)
LOCAL max drift speed: max of |grad phi| / B0 (aux comp 1, 2 = grad phi) over the valid cells,...
Definition amr_diagnostics.hpp:48
Real amr_mass_mb(const MultiFab &coarse, Real dx, Real dy)
LOCAL mass: sum of u(.,.,0) * dx * dy over the valid cells of ALL local fabs, WITHOUT MPI reduction (...
Definition amr_diagnostics.hpp:33
void fill_physical_bc(MultiFab &mf, const Box2D &domain, const BCRec &bc)
Fills the physical-face ghosts of ALL components per bc (historical entry point, bit-identical).
Definition physical_bc.hpp:176
@ kEuler
constexpr int kAmrRefRatio
The native AMR refinement ratio between two consecutive levels.
Definition refinement_ratio.hpp:30
void amr_regrid_finest(std::vector< AmrLevelMP > &L, std::vector< MultiFab > &aux, const Box2D &dom, Crit crit, int grow, int margin, int aux_ncomp=kAuxBaseComps, bool coarse_replicated=true)
Regrid the finest level (L.back()) by Berger-Rigoutsos on the criterion crit applied to the parent: r...
Definition amr_regrid_coupler.hpp:151
void parallel_copy(MultiFab &dst, const MultiFab &src)
Copies the valid regions that OVERLAP from src to dst (same indices, no shift).
Definition refinement.hpp:50
POPS_HD int coarsen_index(int a, int r)
Index of the coarse cell containing the fine cell a (FLOOR division by r, handles a < 0).
Definition refinement.hpp:34
MultiFab regrid_field_on_layout(const BoxArray &fb, const DistributionMapping &dmap, const MultiFab &par, const MultiFab &old, int pk, int ngf, bool coarse_replicated=true)
Rebuild ONE fine MultiFab on the IMPOSED layout fb / dmap (the same one for all blocks in multi-block...
Definition amr_regrid_coupler.hpp:86
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).
AMR inter-level transfer operators (integer ratio r) + parallel_copy.
Single source of truth for the native AMR refinement ratio.
WRITE POD handle (raw pointer + strides) over a Fab2D buffer, indexed by (i, j, c) IN GLOBAL INDICES ...
Definition fab2d.hpp:29
Per-field aux halo policy (ADC-369): a UNIFORM boundary policy for ONE model-named aux component,...
Definition physical_bc.hpp:195
POINTWISE auxiliary fields shared with the physics: single coupling channel.
Definition state.hpp:123
Boundary conditions for the FOUR faces of the domain (type + associated Dirichlet value).
Definition physical_bc.hpp:29
static Box2D from_extents(int nx, int ny)
Box [0, nx-1] x [0, ny-1] covering nx*ny cells from the index origin.
Definition box2d.hpp:42
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 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
Options of the local Newton of the implicit source (backward-Euler).
Definition implicit_stepper.hpp:114
Per-direction periodicity: halo wrapping in x and/or y during the exchange (false = open edge,...
Definition fill_boundary.hpp:37
Base scalar types and the POPS_HD macro (host+device portability).
Generated by