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

Functions

amrex::Periodicity lateral_periodicity (const amrex::Geometry &geom)
 
void fill_unread_ghosts (amrex::MultiFab &dst, int dcomp, int ncomp, const amrex::IntVect &ng_filled, const amrex::IntVect &ng_dst, const amrex::Periodicity &period)
 
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

◆ fill_unread_ghosts()

void erf_checkpoint::fill_unread_ghosts ( amrex::MultiFab &  dst,
int  dcomp,
int  ncomp,
const amrex::IntVect &  ng_filled,
const amrex::IntVect &  ng_dst,
const amrex::Periodicity &  period 
)
inline

Fill the ghost layers of dst between ng_filled and ng_dst, which a checkpoint written with fewer ghost cells (for example before a change of advection scheme) could not supply.

Every such cell first takes the value of the nearest cell within ng_filled of its own valid box, so that none is left undefined: outside the domain that is the outermost layer the file did hold. FillBoundary then gives the cells that lie over another box's valid region, or its periodic image, the value from there.

42 {
43  if (ng_filled.allGE(ng_dst)) { return; }
44 
45  for (amrex::MFIter mfi(dst); mfi.isValid(); ++mfi) {
46  const amrex::Box& vbx = mfi.validbox();
47  const amrex::Box gbx = amrex::grow(vbx, ng_dst);
48  const amrex::Box fbx = amrex::grow(vbx, ng_filled);
49  const amrex::Dim3 flo = amrex::lbound(fbx);
50  const amrex::Dim3 fhi = amrex::ubound(fbx);
51  const amrex::Array4<amrex::Real>& a = dst.array(mfi);
52  amrex::ParallelFor(gbx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
53  {
54  const int ii = amrex::Clamp(i, flo.x, fhi.x);
55  const int jj = amrex::Clamp(j, flo.y, fhi.y);
56  const int kk = amrex::Clamp(k, flo.z, fhi.z);
57  if (ii != i || jj != j || kk != k) {
58  a(i,j,k,dcomp+n) = a(ii,jj,kk,dcomp+n);
59  }
60  });
61  }
62 
63  dst.FillBoundary(dcomp, ncomp, ng_dst, period);
64 }
GpuArray< Real, AMREX_SPACEDIM > period
Definition: ERF_ActuatorSpreading.cpp:131
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})

Referenced by read_checkpoint_multifab().

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

◆ 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.

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

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.

167 {
168  amrex::MultiFab tmp(ba, dm, 1, 0);
169  read_checkpoint_multifab(tmp, mf_name, 0, 0, 1, amrex::IntVect(0), false, period);
170  dst = amrex::cast<amrex::iMultiFab>(tmp);
171 }
@ 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:92

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. If the file holds fewer ghost cells than that, the layers it cannot supply are filled by fill_unread_ghosts rather than left undefined.

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
98 {
99  //
100  // Undefined on purpose: VisMF::Read defines it on the BoxArray the file records, which is
101  // the decomposition the checkpoint was written with and need not be this run's.
102  //
103  amrex::MultiFab src;
104  amrex::VisMF::Read(src, mf_name);
105 
106  //
107  // A file written with fewer ghost cells than the destination holds cannot fill more than
108  // it has, and the destination cannot take more than it holds.
109  //
110  const amrex::IntVect ng_dst = amrex::min(dst_ghosts, dst.nGrowVect());
111 
112  //
113  // The overwhelmingly common case: this level's grids ARE the grids the checkpoint was
114  // written on, so nothing has to move between boxes. Copy box to box, exactly as the
115  // reader did before the grids could differ, so that an ordinary restart stays
116  // byte-for-byte what it always was -- no periodic images, and no overlapping sources to
117  // be ambiguous about.
118  //
119  // The distribution still has to be matched: VisMF::Read gives the MultiFab it defines a
120  // DistributionMapping of its own, which is not this run's even when the BoxArray is.
121  // Redistribute is the box-to-box move for exactly that case.
122  //
123  if (src.boxArray() == dst.boxArray())
124  {
125  const amrex::IntVect ng_copy = src_ghosts ? amrex::min(ng_dst, src.nGrowVect())
126  : amrex::IntVect(0);
127 
128  if (src.DistributionMap() == dst.DistributionMap()) {
129  amrex::MultiFab::Copy(dst, src, scomp, dcomp, ncomp, ng_copy);
130  } else {
131  amrex::MultiFab aligned(src.boxArray(), dst.DistributionMap(), src.nComp(), src.nGrowVect());
132  aligned.Redistribute(src, 0, 0, src.nComp(), src.nGrowVect());
133  amrex::MultiFab::Copy(dst, aligned, scomp, dcomp, ncomp, ng_copy);
134  }
135  if (src_ghosts) { fill_unread_ghosts(dst, dcomp, ncomp, ng_copy, ng_dst, period); }
136  return;
137  }
138 
139  if (src_ghosts) {
140  //
141  // Two passes. The first offers the file's halo so that destination ghost cells OUTSIDE
142  // the domain -- which no valid cell can reach -- get the values the checkpoint recorded
143  // for them. But a file's halo is not guaranteed to agree with its valid data, and
144  // offering it alone would let a stale ghost cell land in a valid cell through a box
145  // overlap or a periodic image, with no ordering guarantee between overlapping sources.
146  // So the second pass copies the valid cells on top, and they win wherever they reach.
147  //
148  const amrex::IntVect ng_src = amrex::min(ng_dst, src.nGrowVect());
149  dst.ParallelCopy(src, scomp, dcomp, ncomp, ng_src, ng_dst, period);
150  dst.ParallelCopy(src, scomp, dcomp, ncomp, amrex::IntVect(0), ng_dst, period);
151  fill_unread_ghosts(dst, dcomp, ncomp, ng_src, ng_dst, period);
152  } else {
153  dst.ParallelCopy(src, scomp, dcomp, ncomp, amrex::IntVect(0), ng_dst, period);
154  }
155 }
Definition: ERF_ConsoleIO.cpp:17
void fill_unread_ghosts(amrex::MultiFab &dst, int dcomp, int ncomp, const amrex::IntVect &ng_filled, const amrex::IntVect &ng_dst, const amrex::Periodicity &period)
Definition: ERF_ReadCheckpointMF.H:39

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

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