include/pops/coupling/amr/amr_level_storage.hpp Source FileΒΆ

adc_cpp: include/pops/coupling/amr/amr_level_storage.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_level_storage.hpp
Go to the documentation of this file.
1
11
12#pragma once
13
14#include <pops/core/state/state.hpp> // kAuxBaseComps: default aux width (base phi/grad channel)
18
19#include <utility>
20#include <vector>
21
22namespace pops {
23
27template <class Level>
29 public:
32 AmrLevelStack(const Box2D& dom, std::vector<Level> levels, int aux_ncomp = kAuxBaseComps)
33 : dom_(dom), L_(std::move(levels)), aux_ncomp_(aux_ncomp) {
34 nlev_ = static_cast<int>(L_.size());
35 aux_.resize(nlev_); // stable addresses: aux_ is no longer resized
36 for (int k = 0; k < nlev_; ++k) {
37 aux_[k] = MultiFab(L_[k].U.box_array(), L_[k].U.dmap(), aux_ncomp_, 1);
38 L_[k].aux = &aux_[k];
39 }
40 }
41
42 std::vector<Level>& levels() { return L_; }
43 const std::vector<Level>& levels() const { return L_; }
44 MultiFab& coarse() { return L_[0].U; }
45 const MultiFab& coarse() const { return L_[0].U; }
46 const Box2D& domain() const { return dom_; }
47 int nlev() const { return nlev_; }
48
49 std::vector<Level>& L() { return L_; }
50 std::vector<MultiFab>& aux() { return aux_; }
51 MultiFab& aux(int k) { return aux_[k]; }
52 const MultiFab& aux(int k) const { return aux_[k]; }
53
54 // aux channel width (components), as sized at the ctor.
55 int aux_ncomp() const { return aux_ncomp_; }
56
57 // In-place realloc of aux_[k] on the current box of L_[k].U + rewiring of the
58 // pointer. Keeps the aux channel width (aux_ncomp_); default 3 -> bit-identical
59 // to the original inline block (same MultiFab(..., 3, 1)).
60 void reattach_aux(int k) {
61 aux_[k] = MultiFab(L_[k].U.box_array(), L_[k].U.dmap(), aux_ncomp_, 1);
62 L_[k].aux = &aux_[k];
63 }
64
65 private:
66 Box2D dom_;
67 std::vector<Level> L_;
68 std::vector<MultiFab> aux_;
69 int nlev_ = 0;
70 int aux_ncomp_ = kAuxBaseComps; // aux channel width (default: base contract)
71};
72
73} // namespace pops
Box2D: the integer index space of a 2D cell-centered Cartesian grid.
Owns the AMR level stack and the parallel aux stack.
Definition amr_level_storage.hpp:28
std::vector< Level > & levels()
Definition amr_level_storage.hpp:42
void reattach_aux(int k)
Definition amr_level_storage.hpp:60
AmrLevelStack(const Box2D &dom, std::vector< Level > levels, int aux_ncomp=kAuxBaseComps)
Builds the stack: takes ownership of levels, allocates an aux (aux_ncomp components,...
Definition amr_level_storage.hpp:32
const std::vector< Level > & levels() const
Definition amr_level_storage.hpp:43
MultiFab & aux(int k)
Definition amr_level_storage.hpp:51
const MultiFab & aux(int k) const
Definition amr_level_storage.hpp:52
MultiFab & coarse()
Definition amr_level_storage.hpp:44
const Box2D & domain() const
Definition amr_level_storage.hpp:46
std::vector< MultiFab > & aux()
Definition amr_level_storage.hpp:50
const MultiFab & coarse() const
Definition amr_level_storage.hpp:45
int nlev() const
Definition amr_level_storage.hpp:47
std::vector< Level > & L()
Definition amr_level_storage.hpp:49
int aux_ncomp() const
Definition amr_level_storage.hpp:55
Field distributed over a level: decomposition (BoxArray) + distribution (DistributionMapping) + ncomp...
Definition multifab.hpp:33
MultiFab: a field DISTRIBUTED over a level (equivalent of AMReX's MultiFab).
Definition amr_hierarchy.hpp:29
constexpr int kAuxBaseComps
Definition state.hpp:147
Pointwise types of the physics layer: StateVec<N> (conserved state) and Aux (auxiliary fields from th...
2D integer index space, cell-centered.
Definition box2d.hpp:37
Base scalar types and the POPS_HD macro (host+device portability).