ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
erf_checkpoint Namespace Reference

Functions

amrex::Periodicity lateral_periodicity (const amrex::Geometry &geom)
 
void read_checkpoint_multifab (amrex::MultiFab &dst, const std::string &mf_name, int scomp, int dcomp, int ncomp, const amrex::IntVect &dst_ghosts, bool src_ghosts, const amrex::Periodicity &period)
 
void read_checkpoint_imultifab (amrex::iMultiFab &dst, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm, const std::string &mf_name, const amrex::Periodicity &period)
 

Function Documentation

◆ lateral_periodicity()

amrex::Periodicity erf_checkpoint::lateral_periodicity ( const amrex::Geometry &  geom)
inline

The periodicity of geom in x and y only. For planar fields, and for the terrain heights, which are not periodic in z even when the domain is: in a domain periodic in z, the top node of a column is the image of the bottom one but its height is not.

21 {
22  const amrex::Box& dom = geom.Domain();
23  return amrex::Periodicity(amrex::IntVect(AMREX_D_DECL(geom.isPeriodic(0) ? dom.length(0) : 0,
24  geom.isPeriodic(1) ? dom.length(1) : 0,
25  0)));
26 }

Referenced by SLM::ReadCheckpoint(), and ERF::ReadCheckpointFile().

Here is the caller graph for this function:

◆ read_checkpoint_imultifab()

void erf_checkpoint::read_checkpoint_imultifab ( amrex::iMultiFab &  dst,
const amrex::BoxArray &  ba,
const amrex::DistributionMapping &  dm,
const std::string &  mf_name,
const amrex::Periodicity &  period 
)
inline

As read_checkpoint_multifab, for an integer field the checkpoint stores as a MultiFab, valid cells only. dst is (re)defined on ba/dm, which are the grids the run uses.

125 {
126  amrex::MultiFab tmp(ba, dm, 1, 0);
127  read_checkpoint_multifab(tmp, mf_name, 0, 0, 1, amrex::IntVect(0), false, period);
128  dst = amrex::cast<amrex::iMultiFab>(tmp);
129 }
@ tmp
Definition: ERF_AdvanceWSM6.cpp:116
void read_checkpoint_multifab(amrex::MultiFab &dst, const std::string &mf_name, int scomp, int dcomp, int ncomp, const amrex::IntVect &dst_ghosts, bool src_ghosts, const amrex::Periodicity &period)
Definition: ERF_ReadCheckpointMF.H:52

Referenced by SLM::ReadCheckpoint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_checkpoint_multifab()

void erf_checkpoint::read_checkpoint_multifab ( amrex::MultiFab &  dst,
const std::string &  mf_name,
int  scomp,
int  dcomp,
int  ncomp,
const amrex::IntVect &  dst_ghosts,
bool  src_ghosts,
const amrex::Periodicity &  period 
)
inline

Read one checkpoint MultiFab and deposit it into dst, which may live on different grids.

The source is read into an undefined MultiFab, which VisMF::Read then defines on the BoxArray recorded in the file, so no caller needs to know the checkpoint's grids – which is what lets a restart land a component's state on level-0 grids that moved (issue 4225).

Only the VALID cells of the source are offered by default: a file's ghost cells are not guaranteed to agree with its valid data, and ParallelCopy intersects the grown source with the grown destination without any ordering guarantee between overlapping sources, so offering them can land stale values in valid cells. Pass src_ghosts = true for a field whose halo the checkpoint carries and whose ordinary restart has always restored it; the valid cells are then laid over the top in a second pass, so they win wherever they reach.

Parameters
[in,out]dstdestination, on the grids the run uses
[in]mf_namethe checkpoint MultiFab, as for VisMF::Read
[in]scompfirst component of the source to read
[in]dcompfirst component of dst to fill
[in]ncompnumber of components
[in]dst_ghostsghost cells of dst to fill (capped at what dst holds)
[in]src_ghostsoffer the file's ghost cells as well as its valid cells
[in]periodperiodicity of the domain dst lives in
58 {
59  //
60  // Undefined on purpose: VisMF::Read defines it on the BoxArray the file records, which is
61  // the decomposition the checkpoint was written with and need not be this run's.
62  //
63  amrex::MultiFab src;
64  amrex::VisMF::Read(src, mf_name);
65 
66  //
67  // A file written with fewer ghost cells than the destination holds cannot fill more than
68  // it has, and the destination cannot take more than it holds.
69  //
70  const amrex::IntVect ng_dst = amrex::min(dst_ghosts, dst.nGrowVect());
71 
72  //
73  // The overwhelmingly common case: this level's grids ARE the grids the checkpoint was
74  // written on, so nothing has to move between boxes. Copy box to box, exactly as the
75  // reader did before the grids could differ, so that an ordinary restart stays
76  // byte-for-byte what it always was -- no periodic images, and no overlapping sources to
77  // be ambiguous about.
78  //
79  // The distribution still has to be matched: VisMF::Read gives the MultiFab it defines a
80  // DistributionMapping of its own, which is not this run's even when the BoxArray is.
81  // Redistribute is the box-to-box move for exactly that case.
82  //
83  if (src.boxArray() == dst.boxArray())
84  {
85  const amrex::IntVect ng_copy = src_ghosts ? amrex::min(ng_dst, src.nGrowVect())
86  : amrex::IntVect(0);
87 
88  if (src.DistributionMap() == dst.DistributionMap()) {
89  amrex::MultiFab::Copy(dst, src, scomp, dcomp, ncomp, ng_copy);
90  } else {
91  amrex::MultiFab aligned(src.boxArray(), dst.DistributionMap(), src.nComp(), src.nGrowVect());
92  aligned.Redistribute(src, 0, 0, src.nComp(), src.nGrowVect());
93  amrex::MultiFab::Copy(dst, aligned, scomp, dcomp, ncomp, ng_copy);
94  }
95  return;
96  }
97 
98  if (src_ghosts) {
99  //
100  // Two passes. The first offers the file's halo so that destination ghost cells OUTSIDE
101  // the domain -- which no valid cell can reach -- get the values the checkpoint recorded
102  // for them. But a file's halo is not guaranteed to agree with its valid data, and
103  // offering it alone would let a stale ghost cell land in a valid cell through a box
104  // overlap or a periodic image, with no ordering guarantee between overlapping sources.
105  // So the second pass copies the valid cells on top, and they win wherever they reach.
106  //
107  const amrex::IntVect ng_src = amrex::min(ng_dst, src.nGrowVect());
108  dst.ParallelCopy(src, scomp, dcomp, ncomp, ng_src, ng_dst, period);
109  dst.ParallelCopy(src, scomp, dcomp, ncomp, amrex::IntVect(0), ng_dst, period);
110  } else {
111  dst.ParallelCopy(src, scomp, dcomp, ncomp, amrex::IntVect(0), ng_dst, period);
112  }
113 }
Definition: ERF_ConsoleIO.cpp:17

Referenced by TwoStreamRadiation::read_checkpoint(), read_checkpoint_imultifab(), ERF::read_checkpoint_mf(), SLM::ReadCheckpoint(), and ERF::ReadCheckpointFile().

Here is the caller graph for this function: