ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
FloodCoupler Class Reference

#include <ERF_FloodCoupler.H>

Collaboration diagram for FloodCoupler:

Public Member Functions

 FloodCoupler (const FloodCouplingParams &params, std::unique_ptr< FloodEngine > engine)
 
void initialize (const ERF &erf, int lev, const amrex::MultiFab *z_phys_nd_atm)
 Check the configuration, build the flood grid and set the engine up. More...
 
void set_flood_grid (int lev, const FloodGrid &fg, const amrex::BoxArray &ba_atm, const amrex::DistributionMapping &dm_atm, const amrex::Geometry &geom_atm)
 Lay the coupling out on a flood grid: what initialize() does after its start-up checks and before it sets the engine up. More...
 
void set_precip_reference (const SurfacePrecipAccumulationSources &precip_sources)
 Take the current surface precipitation accumulation as the reference the next step's precipitation is measured from. More...
 
void advance (double time, double dt, const amrex::MultiFab &xvel, const amrex::MultiFab &yvel, const amrex::MultiFab &z_phys_cc, const SurfacePrecipAccumulationSources &precip_sources)
 Advance the flood one step of its level. More...
 
void write_checkpoint (const std::string &checkpointname) const
 Write the flood to a checkpoint: the engine's state (FloodEngine::write_checkpoint), then the flood grid's level, ratio and region in checkpointname/Level_<lev>/FloodGrid, and the precipitation reference in Level_<lev>/FloodPrecipRef, or in Level_<lev>/FloodPrecipRefIce for a scheme whose cloud ice counts as frozen (SurfacePrecipAccumulationSources::rest_is_frozen) More...
 
std::string checkpoint_mismatch (int chk_lev, int chk_ratio, const amrex::Box &chk_region) const
 Why a checkpoint's flood state does not belong to this run's flood grid, or an empty string when it does. More...
 
void read_checkpoint (const std::string &restart_chkfile, int step)
 Restore the engine's state on a restart. More...
 
const std::vector< std::string > & plot_var_names () const
 Flood fields the ERF plotfile can carry (FloodEngine::plot_var_names(), read at construction). More...
 
void fill_plot_var (const std::string &name, amrex::MultiFab &dst, int dcomp, int lev) const
 Fill component dcomp of an ERF plotfile MultiFab of level lev with the flood field name. More...
 
int level () const
 The level the flood grid refines (erf.flood.anchor_level, resolved at initialize). More...
 
const FloodCouplingParams & params () const
 The coupling inputs. More...
 
FloodEngine & engine ()
 The flood engine. More...
 
const FloodEngine & engine () const
 
const FloodGrid & flood_grid () const
 The flood grid. More...
 
double fields_time () const
 The time the engine's fields belong to [s], in ERF's double time. More...
 
void set_fields_time (double t)
 Set fields_time() to t [s] (ERF only: start-up, restart, end of a coarser step). More...
 

Private Member Functions

std::string precip_ref_name () const
 

Private Attributes

FloodCouplingParams m_params
 
std::unique_ptr< FloodEngine > m_engine
 
FloodGrid m_fg
 
int m_lev = 0
 
bool m_grid_set = false
 
amrex::Geometry m_geom_atm
 geometry of the flood grid's level More...
 
amrex::BoxArray m_ba_cols
 the k = 0 slab of each box of the level More...
 
amrex::DistributionMapping m_dm_cols
 their owners (the level's) More...
 
double m_fields_time = 0.0
 
std::unique_ptr< amrex::MultiFab > m_precip_prev
 
bool m_precip_rest_frozen = false
 The sources' rest_is_frozen at set_precip_reference(): which split the reference holds. More...
 
std::vector< std::string > m_plot_var_names
 

Constructor & Destructor Documentation

◆ FloodCoupler()

FloodCoupler::FloodCoupler ( const FloodCouplingParams &  params,
std::unique_ptr< FloodEngine >  engine 
)
Parameters
[in]paramsThe coupling inputs (FloodCouplingParams::read())
[in]engineThe flood engine erf.flood.engine selects

Aborts when the engine lists a plot field whose name does not start with "flood_" or lists a name twice.

48  : m_params(params), m_engine(std::move(engine))
49 {
50  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_engine != nullptr, "[FLOOD] FloodCoupler needs a flood engine");
51  m_plot_var_names = m_engine->plot_var_names();
52  std::set<std::string> seen;
53  for (const auto& n : m_plot_var_names) {
54  if (n.size() <= 6 || n.compare(0, 6, "flood_") != 0) {
55  amrex::Abort(std::string("[FLOOD] flood engine \"") + m_engine->name() + "\" lists the plot field \""
56  + n + "\"; every flood plot field name must start with \"flood_\" and continue after it");
57  }
58  if (!seen.insert(n).second) {
59  amrex::Abort(std::string("[FLOOD] flood engine \"") + m_engine->name() + "\" lists the plot field \""
60  + n + "\" twice");
61  }
62  }
63  if (!m_plot_var_names.empty()) {
64  amrex::Print() << "[FLOOD] " << m_engine->name()
65  << ": the following additional variables are available to plot:\n";
66  for (const auto& n : m_plot_var_names) { amrex::Print() << " " << n << "\n"; }
67  }
68 }
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
std::vector< std::string > m_plot_var_names
Definition: ERF_FloodCoupler.H:201
const FloodCouplingParams & params() const
The coupling inputs.
Definition: ERF_FloodCoupler.H:160
std::unique_ptr< FloodEngine > m_engine
Definition: ERF_FloodCoupler.H:182
FloodEngine & engine()
The flood engine.
Definition: ERF_FloodCoupler.H:163
FloodCouplingParams m_params
Definition: ERF_FloodCoupler.H:181
Here is the call graph for this function:

Member Function Documentation

◆ advance()

void FloodCoupler::advance ( double  time,
double  dt,
const amrex::MultiFab &  xvel,
const amrex::MultiFab &  yvel,
const amrex::MultiFab &  z_phys_cc,
const SurfacePrecipAccumulationSources &  precip_sources 
)

Advance the flood one step of its level.

Called from ERF::Advance() once per step of the flood grid's level, after that level's dycore and microphysics.

Parameters
[in]timeStart of the step [s]
[in]dtStep of the level [s], ERF's double dt[lev]: fields_time() becomes time + dt, the time ERF assigns to the level
[in]xvel,yvelFace velocities after the dycore [m/s]
[in]z_phys_ccCell-center height of the level [m]
[in]precip_sourcesThe microphysics surface precipitation accumulators of the level
123 {
124  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_grid_set, "[FLOOD] FloodCoupler: set_flood_grid() before advance()");
125  // ERF keeps its time and step in double; the engine takes the time in
126  // double too (a float clock drifts on long runs) and the step in Real
127  const double time = time_d;
128  const Real dt = static_cast<Real>(dt_d);
129 
130  // This step's precipitation: the accumulation now less the one at the end
131  // of the previous step (or at start-up), which then rolls forward
132  std::unique_ptr<MultiFab> precip;
133  if (m_engine->wants_surface_precip()) {
135  "[FLOOD] FloodCoupler: set_precip_reference() before the first advance() of an engine that reads the precipitation");
136  precip = std::make_unique<MultiFab>(m_ba_cols, m_dm_cols, 2, 0);
137  surface_precip_liquid_frozen_accum_k0(*precip, precip_sources, m_geom_atm.Domain().smallEnd(2));
138  for (MFIter mfi(*precip); mfi.isValid(); ++mfi) {
139  const auto now = precip->array(mfi);
140  const auto prev = m_precip_prev->array(mfi);
141  ParallelFor(mfi.validbox(), 2, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
142  {
143  const Real a = now(i, j, k, n);
144  now(i, j, k, n) = a - prev(i, j, k, n);
145  prev(i, j, k, n) = a;
146  });
147  }
148  }
149 
150  const FloodForcing forcing{time, dt, xvel, yvel, z_phys_cc, precip.get()};
151  m_engine->advance(forcing);
152  // time + dt[lev] in double, as ERF::timeStep sets t_new[lev]
153  m_fields_time = time_d + dt_d;
154 }
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);})
void surface_precip_liquid_frozen_accum_k0(amrex::MultiFab &accum_2d, const SurfacePrecipAccumulationSources &sources, int klo)
The Liquid accumulation in component 0 and the Frozen one in component 1 of accum_2d (two components)...
Definition: ERF_SurfacePrecipitation.H:220
amrex::Geometry m_geom_atm
geometry of the flood grid's level
Definition: ERF_FloodCoupler.H:186
amrex::BoxArray m_ba_cols
the k = 0 slab of each box of the level
Definition: ERF_FloodCoupler.H:187
amrex::DistributionMapping m_dm_cols
their owners (the level's)
Definition: ERF_FloodCoupler.H:188
double m_fields_time
Definition: ERF_FloodCoupler.H:189
bool m_grid_set
Definition: ERF_FloodCoupler.H:185
std::unique_ptr< amrex::MultiFab > m_precip_prev
Definition: ERF_FloodCoupler.H:193
@ precip
Definition: ERF_SLM.H:135
@ xvel
Definition: ERF_IndexDefines.H:232
@ yvel
Definition: ERF_IndexDefines.H:233
The atmospheric state a flood engine reads for one step.
Definition: ERF_FloodEngine.H:62
Here is the call graph for this function:

◆ checkpoint_mismatch()

std::string FloodCoupler::checkpoint_mismatch ( int  chk_lev,
int  chk_ratio,
const amrex::Box &  chk_region 
) const

Why a checkpoint's flood state does not belong to this run's flood grid, or an empty string when it does.

Parameters
[in]chk_levThe level the checkpoint's flood grid refines
[in]chk_ratioIts grid ratio
[in]chk_regionThe atmospheric columns it covers
216 {
217  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_grid_set, "[FLOOD] FloodCoupler: set_flood_grid() before the checkpoint");
218  const Box run_region = m_ba_cols.minimalBox();
219  Box chk2 = chk_region;
220  chk2.setSmall(2, run_region.smallEnd(2));
221  chk2.setBig(2, run_region.bigEnd(2));
222  if (chk_lev == m_lev && chk_ratio == m_fg.C && chk2 == run_region) { return {}; }
223  std::ostringstream msg;
224  msg << "holds flood state on level " << chk_lev << " with erf.flood.grid_ratio = " << chk_ratio
225  << " over the columns " << chk2 << ", but this run's flood grid is on level " << m_lev
226  << " with erf.flood.grid_ratio = " << m_fg.C << " over the columns " << run_region
227  << ". Restart with the erf.flood.anchor_level, erf.flood.grid_ratio and the refinement the"
228  " checkpoint was written with.";
229  return msg.str();
230 }
FloodGrid m_fg
Definition: ERF_FloodCoupler.H:183
int m_lev
Definition: ERF_FloodCoupler.H:184
int C
Definition: ERF_SurfaceGrid.H:38

Referenced by read_checkpoint().

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

◆ engine() [1/2]

FloodEngine& FloodCoupler::engine ( )
inline

The flood engine.

163 { return *m_engine; }

◆ engine() [2/2]

const FloodEngine& FloodCoupler::engine ( ) const
inline
164 { return *m_engine; }

◆ fields_time()

double FloodCoupler::fields_time ( ) const
inline

The time the engine's fields belong to [s], in ERF's double time.

ERF sets it at start-up and on a restart, advance() to the end of the step, and ERF again to the coarser level's time once the finer levels' substeps have reached it.

176 { return m_fields_time; }

◆ fill_plot_var()

void FloodCoupler::fill_plot_var ( const std::string &  name,
amrex::MultiFab &  dst,
int  dcomp,
int  lev 
) const

Fill component dcomp of an ERF plotfile MultiFab of level lev with the flood field name.

On the flood grid's level, the k = 0 cell of each column holds the mean of the engine's field over the flood cells under it; every other cell, every other level and a field the engine returns as nullptr hold zero.

158 {
159  dst.setVal(0.0_rt, dcomp, 1, 0);
160  if (lev != m_lev || !m_grid_set) { return; }
161  const MultiFab* field = m_engine->plot_var(name);
162  if (!field) { return; }
163 
164  MultiFab col(m_ba_cols, m_dm_cols, 1, 0);
165  coarsen_flood_to_atm(col, *field, m_fg);
166 
167  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(flood_same_columns(dst.boxArray(), col.boxArray()) &&
168  dst.DistributionMap() == col.DistributionMap(),
169  "[FLOOD] fill_plot_var: the plotfile MultiFab is not on the flood grid's level");
170  const int k0 = m_geom_atm.Domain().smallEnd(2);
171  for (MFIter mfi(dst); mfi.isValid(); ++mfi) {
172  Box bx = mfi.validbox();
173  if (bx.smallEnd(2) > k0) { continue; }
174  bx.setSmall(2, k0);
175  bx.setBig(2, k0);
176  const auto d = dst.array(mfi);
177  const auto c = col.const_array(mfi);
178  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
179  {
180  d(i, j, k, dcomp) = c(i, j, k);
181  });
182  }
183 }
bool flood_same_columns(const amrex::BoxArray &a, const amrex::BoxArray &b)
surface_same_columns: box n of a and box n of b cover the same columns.
Definition: ERF_FloodGrid.H:62
void coarsen_flood_to_atm(amrex::MultiFab &atm_out, const amrex::MultiFab &flood, const FloodGrid &fg)
Definition: ERF_FloodGrid.H:100
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
Here is the call graph for this function:

◆ flood_grid()

const FloodGrid& FloodCoupler::flood_grid ( ) const
inline

The flood grid.

167 { return m_fg; }

◆ initialize()

void FloodCoupler::initialize ( const ERF &  erf,
int  lev,
const amrex::MultiFab *  z_phys_nd_atm 
)

Check the configuration, build the flood grid and set the engine up.

Called once from ERF::InitData_post(), on a fresh start and on a restart alike. Runs the coupling's checks (verify_flood_prerequisites), then the engine's, builds the flood grid on level lev and initializes the engine.

Parameters
[in]erfERF instance (public AmrCore accessors only)
[in]levThe level the flood grid refines (flood_anchor_level)
[in]z_phys_nd_atmNodal height of level lev [m]
72 {
73  // The ERF configuration a flood grid needs, then the engine's own inputs
75  m_engine->verify_prerequisites(erf, lev);
76 
77  FloodGrid fg = create_flood_grid(erf.boxArray(lev), erf.DistributionMap(lev),
78  erf.Geom(lev), m_params.grid_ratio);
79  fg.lev = lev;
80  report_flood_region(erf, lev, fg);
81  set_flood_grid(lev, fg, erf.boxArray(lev), erf.DistributionMap(lev), erf.Geom(lev));
82 
83  m_engine->initialize(erf, lev, m_fg, z_phys_nd_atm);
84 }
FloodGrid create_flood_grid(const BoxArray &ba_atm, const DistributionMapping &dm_atm, const Geometry &geom_atm, int C)
Definition: ERF_FloodGrid.cpp:6
void verify_flood_prerequisites(const ERF &erf, int lev)
Verify the ERF configuration the flood coupling needs.
Definition: ERF_FloodPrerequisites.cpp:21
void set_flood_grid(int lev, const FloodGrid &fg, const amrex::BoxArray &ba_atm, const amrex::DistributionMapping &dm_atm, const amrex::Geometry &geom_atm)
Lay the coupling out on a flood grid: what initialize() does after its start-up checks and before it ...
Definition: ERF_FloodCoupler.cpp:87
@ fg
Definition: ERF_AdvanceMorrison.cpp:111
int grid_ratio
erf.flood.grid_ratio: flood cells per atmospheric cell in x and y
Definition: ERF_FloodCouplingParams.H:27
2D horizontal flood grid
Definition: ERF_FloodGrid.H:42
Here is the call graph for this function:

◆ level()

int FloodCoupler::level ( ) const
inline

The level the flood grid refines (erf.flood.anchor_level, resolved at initialize).

157 { return m_lev; }

◆ params()

const FloodCouplingParams& FloodCoupler::params ( ) const
inline

The coupling inputs.

160 { return m_params; }

◆ plot_var_names()

const std::vector<std::string>& FloodCoupler::plot_var_names ( ) const
inline

Flood fields the ERF plotfile can carry (FloodEngine::plot_var_names(), read at construction).

144 { return m_plot_var_names; }

◆ precip_ref_name()

std::string FloodCoupler::precip_ref_name ( ) const
inlineprivate

The checkpoint name of the reference. Before the cloud ice of WSM6 and WDM6 counted as frozen, their reference had it in the liquid part, under FloodPrecipRef.

199 { return m_precip_rest_frozen ? "FloodPrecipRefIce" : "FloodPrecipRef"; }
bool m_precip_rest_frozen
The sources' rest_is_frozen at set_precip_reference(): which split the reference holds.
Definition: ERF_FloodCoupler.H:195

Referenced by read_checkpoint(), and write_checkpoint().

Here is the caller graph for this function:

◆ read_checkpoint()

void FloodCoupler::read_checkpoint ( const std::string &  restart_chkfile,
int  step 
)

Restore the engine's state on a restart.

A checkpoint written with a flood engine holds Level_<lev>/FloodGrid: the coupler aborts when it names another level, ratio or region than this run, and otherwise calls FloodEngine::read_checkpoint. A checkpoint without it (an atmosphere-only spin-up) leaves the engine in its initial state, said once.

Parameters
[in]restart_chkfileThe checkpoint directory
[in]stepThe step count of the flood grid's level at the checkpoint
234 {
235  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_grid_set, "[FLOOD] FloodCoupler: set_flood_grid() before the checkpoint");
236  // The flood grid record: found and read on the I/O rank and broadcast, so
237  // every rank takes the same branch. Every level the checkpoint holds is
238  // searched, not only those of this run's amr.max_level, so a restart onto
239  // fewer levels stops on the mismatch instead of starting the engine empty.
240  // found, lev, C, ilo, jlo, ihi, jhi, has this run's precipitation reference,
241  // has a FloodPrecipRef where this run writes FloodPrecipRefIce
242  Vector<int> rec(9, -1);
243  const std::string ref_name = precip_ref_name();
244  if (ParallelDescriptor::IOProcessor()) {
245  for (int l = 0; amrex::FileExists(restart_chkfile + "/Level_" + std::to_string(l)); ++l) {
246  const std::string f = restart_chkfile + "/Level_" + std::to_string(l) + "/FloodGrid";
247  if (!amrex::FileExists(f)) { continue; }
248  std::ifstream is(f);
249  rec[0] = 1;
250  is >> rec[1] >> rec[2] >> rec[3] >> rec[4] >> rec[5] >> rec[6];
251  if (!is) { rec[0] = 0; } // unreadable record
252  const std::string lev_dir = restart_chkfile + "/Level_" + std::to_string(l);
253  rec[7] = amrex::FileExists(lev_dir + "/" + ref_name + "_H") ? 1 : 0;
254  rec[8] = (ref_name != "FloodPrecipRef" && amrex::FileExists(lev_dir + "/FloodPrecipRef_H")) ? 1 : 0;
255  break;
256  }
257  }
258  ParallelDescriptor::Bcast(rec.data(), rec.size(), ParallelDescriptor::IOProcessorNumber());
259  if (rec[0] == 0) {
260  amrex::Abort("[FLOOD] The checkpoint " + restart_chkfile + " has a FloodGrid record that cannot be read");
261  }
262  if (rec[0] < 0) {
263  amrex::Print() << "[FLOOD] The checkpoint holds no flood state; the flood engine "
264  << m_engine->name() << " starts from its initial state.\n";
265  return;
266  }
267  const Box chk_region(IntVect(rec[3], rec[4], 0), IntVect(rec[5], rec[6], 0));
268  if (const std::string why = checkpoint_mismatch(rec[1], rec[2], chk_region); !why.empty()) {
269  amrex::Abort("[FLOOD] The checkpoint " + restart_chkfile + " " + why);
270  }
271  m_engine->read_checkpoint(restart_chkfile, step);
272  // The reference the flood last read, which can differ from the restored
273  // accumulators under a finer level (write_checkpoint)
274  if (rec[7] == 0 && rec[8] == 1 && m_precip_prev) {
275  // A reference written with the cloud ice in the liquid part: the one taken
276  // from the restored accumulators (set_precip_reference) is kept. Without a
277  // finer level those accumulators are what the flood last read; under one,
278  // the finer level's last correction is not handed to the engine.
279  amrex::Print() << "[FLOOD] The checkpoint holds FloodPrecipRef, written before the cloud ice of"
280  " WSM6 and WDM6 counted as frozen; the flood ignores it and takes its reference"
281  " from the restored accumulators, so a correction pending from a finer level"
282  " at the checkpoint is not carried over.\n";
283  }
284  if (rec[7] == 1 && m_precip_prev) {
285  MultiFab ref;
286  VisMF::Read(ref, restart_chkfile + "/Level_" + std::to_string(m_lev) + "/" + ref_name);
287  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(ref.nComp() == m_precip_prev->nComp(),
288  "[FLOOD] The checkpoint's " + ref_name + " has the wrong number of components");
289  m_precip_prev->ParallelCopy(ref, 0, 0, ref.nComp());
290  }
291 }
std::string precip_ref_name() const
Definition: ERF_FloodCoupler.H:199
std::string checkpoint_mismatch(int chk_lev, int chk_ratio, const amrex::Box &chk_region) const
Why a checkpoint's flood state does not belong to this run's flood grid, or an empty string when it d...
Definition: ERF_FloodCoupler.cpp:215
Here is the call graph for this function:

◆ set_fields_time()

void FloodCoupler::set_fields_time ( double  t)
inline

Set fields_time() to t [s] (ERF only: start-up, restart, end of a coarser step).

178 { m_fields_time = t; }
@ t
Definition: ERF_WSM6.H:295

◆ set_flood_grid()

void FloodCoupler::set_flood_grid ( int  lev,
const FloodGrid &  fg,
const amrex::BoxArray &  ba_atm,
const amrex::DistributionMapping &  dm_atm,
const amrex::Geometry &  geom_atm 
)

Lay the coupling out on a flood grid: what initialize() does after its start-up checks and before it sets the engine up.

Takes the flood grid and the k = 0 slabs of ba_atm. Public so that a test can drive the coupling with an engine of its own without an ERF object.

Parameters
[in]levThe level the flood grid refines
[in]fgThe flood grid (create_flood_grid)
[in]ba_atmThe level's boxes, each spanning the level's height
[in]dm_atmTheir owners
[in]geom_atmThe level's geometry
91 {
92  m_lev = lev;
93  m_fg = fg;
94  m_geom_atm = geom_atm;
95  const int klo = geom_atm.Domain().smallEnd(2);
96  BoxList bl;
97  for (int n = 0; n < ba_atm.size(); ++n) {
98  Box b = ba_atm[n];
99  b.setSmall(2, klo);
100  b.setBig(2, klo);
101  bl.push_back(b);
102  }
103  m_ba_cols = BoxArray(std::move(bl));
104  m_dm_cols = dm_atm;
105  m_grid_set = true;
106  m_precip_prev.reset();
107 }
const int klo
Definition: ERF_InitCustomPert_KE.H:9

Referenced by initialize().

Here is the caller graph for this function:

◆ set_precip_reference()

void FloodCoupler::set_precip_reference ( const SurfacePrecipAccumulationSources &  precip_sources)

Take the current surface precipitation accumulation as the reference the next step's precipitation is measured from.

Called once at start-up, after initialize(), when the engine reads the precipitation (FloodEngine::wants_surface_precip). On a fresh start the accumulators are zero; on a restart they hold the checkpoint's values, so the first restarted step hands the engine the same precipitation as the straight run.

Parameters
[in]precip_sourcesThe microphysics surface precipitation accumulators of the level
111 {
112  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_grid_set, "[FLOOD] FloodCoupler: set_flood_grid() before set_precip_reference()");
113  m_precip_prev = std::make_unique<MultiFab>(m_ba_cols, m_dm_cols, 2, 0);
114  m_precip_rest_frozen = precip_sources.rest_is_frozen;
115  surface_precip_liquid_frozen_accum_k0(*m_precip_prev, precip_sources, m_geom_atm.Domain().smallEnd(2));
116 }
bool rest_is_frozen
Definition: ERF_SurfacePrecipitation.H:46
Here is the call graph for this function:

◆ write_checkpoint()

void FloodCoupler::write_checkpoint ( const std::string &  checkpointname) const

Write the flood to a checkpoint: the engine's state (FloodEngine::write_checkpoint), then the flood grid's level, ratio and region in checkpointname/Level_<lev>/FloodGrid, and the precipitation reference in Level_<lev>/FloodPrecipRef, or in Level_<lev>/FloodPrecipRefIce for a scheme whose cloud ice counts as frozen (SurfacePrecipAccumulationSources::rest_is_frozen)

187 {
188  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_grid_set, "[FLOOD] FloodCoupler: set_flood_grid() before the checkpoint");
189  // The engine's own state first
190  m_engine->write_checkpoint(checkpointname);
191 
192  // The flood grid the state belongs to, so a restart onto another one stops
193  if (ParallelDescriptor::IOProcessor()) {
194  const std::string dir = checkpointname + "/Level_" + std::to_string(m_lev);
195  if (!amrex::UtilCreateDirectory(dir, 0755)) { amrex::CreateDirectoryFailed(dir); }
196  const Box region = m_ba_cols.minimalBox();
197  std::ofstream os(dir + "/FloodGrid");
198  os << m_lev << " " << m_fg.C << " "
199  << region.smallEnd(0) << " " << region.smallEnd(1) << " "
200  << region.bigEnd(0) << " " << region.bigEnd(1) << "\n";
201  if (!os) { amrex::FileOpenFailed(dir + "/FloodGrid"); }
202  }
203  ParallelDescriptor::Barrier();
204 
205  // The precipitation reference: the accumulation the flood last read. Under
206  // a finer level ERF averages the accumulators down after the flood's step,
207  // and the next step hands that correction to the engine; saving the
208  // reference keeps the correction for the step after a restart.
209  if (m_precip_prev) {
210  VisMF::Write(*m_precip_prev, checkpointname + "/Level_" + std::to_string(m_lev) + "/" + precip_ref_name());
211  }
212 }
Here is the call graph for this function:

Member Data Documentation

◆ m_ba_cols

amrex::BoxArray FloodCoupler::m_ba_cols
private

the k = 0 slab of each box of the level

Referenced by advance(), checkpoint_mismatch(), fill_plot_var(), set_flood_grid(), set_precip_reference(), and write_checkpoint().

◆ m_dm_cols

amrex::DistributionMapping FloodCoupler::m_dm_cols
private

their owners (the level's)

Referenced by advance(), fill_plot_var(), set_flood_grid(), and set_precip_reference().

◆ m_engine

std::unique_ptr<FloodEngine> FloodCoupler::m_engine
private

◆ m_fg

◆ m_fields_time

double FloodCoupler::m_fields_time = 0.0
private

◆ m_geom_atm

amrex::Geometry FloodCoupler::m_geom_atm
private

geometry of the flood grid's level

Referenced by advance(), fill_plot_var(), set_flood_grid(), and set_precip_reference().

◆ m_grid_set

bool FloodCoupler::m_grid_set = false
private

◆ m_lev

int FloodCoupler::m_lev = 0
private

◆ m_params

FloodCouplingParams FloodCoupler::m_params
private

Referenced by initialize(), and params().

◆ m_plot_var_names

std::vector<std::string> FloodCoupler::m_plot_var_names
private

Referenced by FloodCoupler(), and plot_var_names().

◆ m_precip_prev

std::unique_ptr<amrex::MultiFab> FloodCoupler::m_precip_prev
private

Liquid (0) and frozen (1) accumulation [kg/m2] at the end of the last step, on m_ba_cols; null until set_precip_reference()

Referenced by advance(), read_checkpoint(), set_flood_grid(), set_precip_reference(), and write_checkpoint().

◆ m_precip_rest_frozen

bool FloodCoupler::m_precip_rest_frozen = false
private

The sources' rest_is_frozen at set_precip_reference(): which split the reference holds.

Referenced by precip_ref_name(), and set_precip_reference().


The documentation for this class was generated from the following files: