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

#include <ERF_FireCoupler.H>

Collaboration diagram for FireCoupler:

Public Member Functions

 FireCoupler (const FireCouplingParams &params, std::unique_ptr< FireEngine > engine)
 
void initialize (const ERF &erf, int lev, const SurfaceLayer *surface_layer, const amrex::MultiFab *z_phys_nd_atm)
 Check the configuration, build the fire grid and set the engine up. More...
 
void set_fire_grid (int lev, const FireGrid &fg, const amrex::BoxArray &ba_atm, const amrex::DistributionMapping &dm_atm, const amrex::Geometry &geom_atm)
 Lay the coupling out on a fire grid: what initialize() does after its start-up checks and before it sets the engine up. More...
 
void advance (double time, double dt, const amrex::MultiFab &S_old, const amrex::MultiFab &xvel_old, const amrex::MultiFab &yvel_old, const amrex::MultiFab &xvel_new, const amrex::MultiFab &yvel_new, const amrex::MultiFab &z_phys_cc, const amrex::BoxArray &ba2d, const amrex::Geometry &geom, const SurfacePrecipAccumulationSources &precip_sources)
 Advance the fire one step of its level and refill the lagged fluxes. More...
 
void add_sources (amrex::MultiFab &cc_source, const amrex::MultiFab &S_old, const amrex::MultiFab &z_phys_cc, const amrex::MultiFab *z_phys_nd, const amrex::Geometry &geom, bool has_moisture, int step)
 Inject the lagged fire heat, vapor and smoke into the cell sources. More...
 
void write_checkpoint (const std::string &checkpointname) const
 Write the fire to a checkpoint: the engine's state (FireEngine::write_checkpoint), then the coupling's lagged fluxes (FireQAtmPrev and FireQLatAtmPrev) under checkpointname/Level_<lev>/. More...
 
std::string checkpoint_mismatch (int chk_lev, const amrex::Box &chk_region) const
 Why a checkpoint's lagged fluxes do not belong to this run's fire grid, or an empty string when they do. More...
 
void read_checkpoint (const std::string &restart_chkfile, int max_level, int step)
 Restore the engine's state, then the lagged fluxes, on a restart. More...
 
const std::vector< std::string > & plot_var_names () const
 
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 fire field name. More...
 
int level () const
 The level the fire grid refines (erf.fire.anchor_level, resolved at initialize). More...
 
const FireCouplingParams & params () const
 The coupling inputs. More...
 
FireEngine & engine ()
 The fire engine. More...
 
const FireEngine & engine () const
 
const FireGrid & fire_grid () const
 The fire 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...
 
const amrex::MultiFab * get_Q_atm_prev () const
 Sensible heat flux [W/m2] of the previous fire step on the atmospheric columns of the fire grid's level, with 5 ghost columns (for a reader that samples a halo around each tile, such as a boundary-layer scheme taking the fire's heat into its mixing); zero outside the fire region. Allocated at initialize, so never null afterwards. More...
 
const amrex::MultiFab * get_Q_lat_atm_prev () const
 Latent heat flux [W/m2] of the previous fire step, laid out as get_Q_atm_prev(). More...
 

Private Member Functions

void update_flux_buffer (const amrex::Geometry &geom_atm)
 Average the engine's fluxes onto the atmospheric columns for the next step. More...
 

Private Attributes

FireCouplingParams m_params
 
std::unique_ptr< FireEngine > m_engine
 
FireGrid m_fg
 
int m_lev = 0
 
amrex::Geometry m_geom_atm
 geometry of the fire grid's level More...
 
double m_fields_time = 0.0
 the time the engine's fields belong to (fields_time()) More...
 
std::unique_ptr< amrex::MultiFab > m_Q_atm_prev
 sensible [W/m2] More...
 
std::unique_ptr< amrex::MultiFab > m_Q_lat_atm_prev
 latent [W/m2] More...
 
std::vector< std::string > m_plot_var_names
 FireEngine::plot_var_names(), read at construction. More...
 

Constructor & Destructor Documentation

◆ FireCoupler()

FireCoupler::FireCoupler ( const FireCouplingParams &  params,
std::unique_ptr< FireEngine >  engine 
)
Parameters
[in]paramsThe coupling inputs (FireCouplingParams::read())
[in]engineThe fire engine erf.fire.engine selects
72  : m_params(params), m_engine(std::move(engine))
73 {
74  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_engine != nullptr, "[FIRE] FireCoupler needs a fire engine");
75  m_plot_var_names = m_engine->plot_var_names();
76  if (!m_plot_var_names.empty()) {
77  amrex::Print() << "[FIRE] " << m_engine->name()
78  << ": the following additional variables are available to plot:\n";
79  for (const auto& n : m_plot_var_names) { amrex::Print() << " " << n << "\n"; }
80  }
81 }
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
const FireCouplingParams & params() const
The coupling inputs.
Definition: ERF_FireCoupler.H:197
std::unique_ptr< FireEngine > m_engine
Definition: ERF_FireCoupler.H:235
FireCouplingParams m_params
Definition: ERF_FireCoupler.H:234
FireEngine & engine()
The fire engine.
Definition: ERF_FireCoupler.H:200
std::vector< std::string > m_plot_var_names
FireEngine::plot_var_names(), read at construction.
Definition: ERF_FireCoupler.H:250
Here is the call graph for this function:

Member Function Documentation

◆ add_sources()

void FireCoupler::add_sources ( amrex::MultiFab &  cc_source,
const amrex::MultiFab &  S_old,
const amrex::MultiFab &  z_phys_cc,
const amrex::MultiFab *  z_phys_nd,
const amrex::Geometry &  geom,
bool  has_moisture,
int  step 
)

Inject the lagged fire heat, vapor and smoke into the cell sources.

Called from the slow right-hand side at every Runge-Kutta stage on the fire grid's level, after make_sources has rebuilt cc_source. The lagged fluxes are fixed over the step, so every stage receives the same tendency (erf.fire.source_mode decides whether it replaces or adds to the theta and vapor sources). Heat and vapor only with lagged or synchronous coupling; smoke with erf.fire.smoke_enable.

Parameters
[in,out]cc_sourceCell-centered sources of the level
[in]S_oldConserved state at the start of the step (density)
[in]z_phys_ccCell-center height [m]
[in]z_phys_ndNodal height [m] (ERF always passes it): the cell thickness and roof datum of the heat, and the smoke cell's thickness
[in]geomGeometry of the level
[in]has_moistureThe vapor source exists
[in]stepStep of the level, for the debug output
291 {
292  // Heat and vapor, with the WRF-Fire profile (ERF_FireAtmCoupling.H)
294  if (m_params.fire_debug) {
295  amrex::Print() << "[FIRE DEBUG] Applying fire coupling to atmosphere (coupling_type="
296  << m_params.coupling_type << ", feedback=" << m_params.fire_atm_feedback
297  << ", max_Q_prev=" << m_Q_atm_prev->max(0) << " W/m2)" << std::endl;
298  }
299 
300  const MultiFab* Q_lat_ptr = (m_params.inject_latent && has_moisture)
301  ? m_Q_lat_atm_prev.get() : nullptr;
302 
303  // Pass fire_debug so apply_fire_tendency_to_cc_source prints tendency diagnostics.
304  // With fire_debug=true you will see per-RK-stage output:
305  // [FIRE COUPLING] Q_atm_max=... alfg=...
306  // [FIRE COUPLING] RhoTheta tendency sum=... max=... expected_surface_max=...
308  cc_source,
309  *m_Q_atm_prev,
310  Q_lat_ptr,
311  z_phys_cc,
312  z_phys_nd,
313  S_old,
314  geom,
317  has_moisture,
319  m_params.source_mode == "add",
320  m_engine->heat_open_fraction_atm(),
321  m_engine->roof_height_atm(),
326  }
327 
328  // The smoke tracer, after the heat: proportional to the fuel burnt, which
329  // the engine's heat per kilogram recovers from the lagged sensible flux
331  inject_smoke_from_fire(
332  cc_source,
333  *m_Q_atm_prev,
334  z_phys_nd,
335  geom,
337  m_engine->smoke_heat_per_kg(),
338  RhoSmoke_comp,
340  step);
341  }
342 }
void apply_fire_tendency_to_cc_source(amrex::MultiFab &cc_source, const amrex::MultiFab &Q_atm, const amrex::MultiFab *Q_lat_atm, const amrex::MultiFab &z_phys_cc, const amrex::MultiFab *z_phys_nd, const amrex::MultiFab &S_old, const amrex::Geometry &geom_atm, amrex::Real alfg, amrex::Real feedback, bool has_moisture, bool fire_debug=false, bool additive=false, const amrex::MultiFab *open_frac_atm=nullptr, const amrex::MultiFab *roof_h_atm=nullptr, bool use_open_weights=false, bool density_factor=false, bool exner_factor=false, bool bottom_cell=false)
Definition: ERF_FireAtmCoupling.H:176
std::unique_ptr< amrex::MultiFab > m_Q_lat_atm_prev
latent [W/m2]
Definition: ERF_FireCoupler.H:248
std::unique_ptr< amrex::MultiFab > m_Q_atm_prev
sensible [W/m2]
Definition: ERF_FireCoupler.H:247
bool heat_in_bottom_cell() const
Definition: ERF_FireCouplingParams.H:62
bool fire_debug
erf.fire.fire_debug: debug output of the coupling
Definition: ERF_FireCouplingParams.H:55
bool heat_tendency_exner
erf.fire.heat_tendency_exner: Exner factor of the theta tendency
Definition: ERF_FireCouplingParams.H:46
bool inject_latent
erf.fire.inject_latent: inject the engine's latent flux as vapor
Definition: ERF_FireCouplingParams.H:35
bool heat_tendency_density
erf.fire.heat_tendency_density: density factor of the theta tendency
Definition: ERF_FireCouplingParams.H:44
bool heat_open_fraction
erf.fire.heat_open_fraction: place the heat by the engine's open fraction
Definition: ERF_FireCouplingParams.H:42
bool smoke_enable
erf.fire.smoke_enable: inject the smoke tracer
Definition: ERF_FireCouplingParams.H:51
amrex::Real smoke_emission_factor
erf.fire.smoke_emission_factor: kg smoke per kg fuel burned [-]
Definition: ERF_FireCouplingParams.H:53
bool injects_flux() const
Heat (and vapor) reach the atmosphere: lagged and synchronous coupling.
Definition: ERF_FireCouplingParams.H:61
std::string source_mode
erf.fire.source_mode: overwrite or add to the theta and vapor sources
Definition: ERF_FireCouplingParams.H:37
std::string coupling_type
erf.fire.coupling_type: passive, lagged or synchronous
Definition: ERF_FireCouplingParams.H:29
amrex::Real heat_flux_alfg
erf.fire.heat_flux_alfg: e-folding height of the injected heat [m]
Definition: ERF_FireCouplingParams.H:31
amrex::Real fire_atm_feedback
erf.fire.fire_atm_feedback: multiplier on the injected fluxes
Definition: ERF_FireCouplingParams.H:33
Here is the call graph for this function:

◆ advance()

void FireCoupler::advance ( double  time,
double  dt,
const amrex::MultiFab &  S_old,
const amrex::MultiFab &  xvel_old,
const amrex::MultiFab &  yvel_old,
const amrex::MultiFab &  xvel_new,
const amrex::MultiFab &  yvel_new,
const amrex::MultiFab &  z_phys_cc,
const amrex::BoxArray &  ba2d,
const amrex::Geometry &  geom,
const SurfacePrecipAccumulationSources &  precip_sources 
)

Advance the fire one step of its level and refill the lagged fluxes.

Called from ERF::Advance() once per step of the fire grid's level, after that level's dycore. The air temperature and humidity at k = 0 come from the state before the dycore; the wind from before the dycore (passive and lagged coupling) or after it (synchronous).

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]S_oldConserved state before the dycore
[in]xvel_old,yvel_oldFace velocities before the dycore [m/s]
[in]xvel_new,yvel_newFace velocities after the dycore [m/s]
[in]z_phys_ccCell-center height of the level [m]
[in]ba2dThe level's boxes coarsened to one cell in z
[in]geomGeometry of the level
[in]precip_sourcesThe microphysics surface precipitation accumulators of the level
145 {
146  // ERF keeps its time and step in double. The engine gets the time in
147  // double too, as the flood engine does (in single precision a float time
148  // stops resolving a 0.5 s step after about 48 days), and the step in Real
149  const double time = time_d;
150  const Real dt = static_cast<Real>(dt_d);
151 
152  // Air temperature and RH at k=0 (an engine may drive a fuel moisture
153  // model with them), derived from the pre-dycore state. This is used in both lagged and synchronous
154  // modes: the moisture ODE uses time-averaged T, and the change in T from
155  // fire heating within one atmospheric step is small relative to the
156  // moisture time lag. The temperature is theta * Exner(p) (the moisture
157  // curves, Balbi's T_a and the threshold ignition take an air
158  // temperature); the plain k = 0 potential temperature used here before
159  // was 14-16 K too warm at 840 hPa.
160  MultiFab T_atm_k0(ba2d, S_old.DistributionMap(), 1, 0);
161  compute_t_from_conservative(T_atm_k0, S_old);
162  MultiFab RH_atm_k0(ba2d, S_old.DistributionMap(), 1, 0);
163  compute_rh_from_conservative(RH_atm_k0, S_old, geom);
164 
165  // Surface precipitation accumulation of every column after this step's
166  // microphysics, for an engine that takes the rain per column
167  // (FireEngine::wants_surface_precip); the engine differences it against the
168  // accumulation it saw at its previous step.
169  std::unique_ptr<MultiFab> precip_accum_k0;
170  if (m_engine->wants_surface_precip()) {
171  precip_accum_k0 = std::make_unique<MultiFab>(ba2d, S_old.DistributionMap(), 1, 0);
172  fire_surface_precip_accum_k0(*precip_accum_k0, precip_sources, geom.Domain().smallEnd(2));
173  }
174 
175  // In passive and lagged modes, fire uses pre-dycore wind (vars_old).
176  // In synchronous mode, fire uses post-dycore wind (vars_new) so that
177  // the fire spread rate at step n+1 reflects the atmospheric momentum
178  // response to fire heating from step n.
179  const bool post_dycore = m_params.is_synchronous();
180  if (m_params.fire_debug) {
181  const char* mode = m_params.is_synchronous() ? "SYNCHRONOUS coupling with POST-dycore"
182  : m_params.is_lagged() ? "LAGGED coupling with PRE-dycore"
183  : "PASSIVE coupling with PRE-dycore";
184  amrex::Print() << "[FIRE DEBUG] Fire advance using " << mode << " wind at t="
185  << time << ", dt=" << dt << std::endl;
186  }
187  const FireForcing forcing{time, dt,
188  post_dycore ? xvel_new : xvel_old,
189  post_dycore ? yvel_new : yvel_old,
190  z_phys_cc, T_atm_k0, RH_atm_k0, precip_accum_k0.get()};
191  m_engine->advance(forcing);
192  // time + dt[lev] in double, as ERF::timeStep sets t_new[lev]
193  m_fields_time = time_d + dt_d;
194  if (m_params.fire_debug) {
195  const Real area = m_engine->burned_area(); // every rank: it may reduce over the fire grid
196  if (area >= 0.0_rt) {
197  amrex::Print() << "[FIRE DEBUG] Burned area at t=" << time + dt << ": " << area << " m2" << std::endl;
198  }
199  }
200 
201  // Store the fire flux of this step for injection at the next step via the
202  // Runge-Kutta source term (add_sources). This applies in both lagged and
203  // synchronous modes; in passive mode the buffer keeps its zero unless the
204  // smoke tracer needs it.
205  update_flux_buffer(geom);
206 }
void fire_surface_precip_accum_k0(amrex::MultiFab &accum_2d, const SurfacePrecipAccumulationSources &sources, int klo)
Total liquid-water-equivalent surface precipitation accumulation [kg/m2] of every column: surface_pre...
Definition: ERF_FirePrecip.H:56
void compute_t_from_conservative(amrex::MultiFab &T_out, const amrex::MultiFab &S_atm)
Air temperature [K] at k = 0 from the conserved state.
Definition: ERF_FireUtils.H:117
void compute_rh_from_conservative(amrex::MultiFab &RH_out, const amrex::MultiFab &S_atm, const amrex::Geometry &)
Compute relative humidity from conserved atmospheric variables at k=0.
Definition: ERF_FireUtils.H:37
void update_flux_buffer(const amrex::Geometry &geom_atm)
Average the engine's fluxes onto the atmospheric columns for the next step.
Definition: ERF_FireCoupler.cpp:241
double m_fields_time
the time the engine's fields belong to (fields_time())
Definition: ERF_FireCoupler.H:239
bool is_lagged() const
Definition: ERF_FireCouplingParams.H:58
bool is_synchronous() const
Definition: ERF_FireCouplingParams.H:59
The atmospheric state a fire engine reads at the start of its step.
Definition: ERF_FireEngine.H:67
Here is the call graph for this function:

◆ checkpoint_mismatch()

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

Why a checkpoint's lagged fluxes do not belong to this run's fire grid, or an empty string when they do.

Parameters
[in]chk_levThe level the checkpoint holds them on
[in]chk_regionThe columns they cover (minimal box of their boxes)
363 {
364  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_Q_atm_prev, "[FIRE] FireCoupler: set_fire_grid() before the checkpoint");
365  // The fluxes cover the columns of the level's boxes, which form the fire
366  // region (verify_fire_prerequisites, check 7b)
367  const Box run_region = m_Q_atm_prev->boxArray().minimalBox();
368  if (chk_lev == m_lev && chk_region == run_region) { return {}; }
369  std::ostringstream msg;
370  msg << "holds the lagged fire fluxes on level " << chk_lev << " over the columns " << chk_region
371  << ", but this run's fire grid covers the columns " << run_region << " of level " << m_lev
372  << ". Restart with the erf.fire.anchor_level and the refinement the checkpoint was written with.";
373  return msg.str();
374 }
int m_lev
Definition: ERF_FireCoupler.H:237

Referenced by read_checkpoint().

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

◆ engine() [1/2]

FireEngine& FireCoupler::engine ( )
inline

The fire engine.

200 { return *m_engine; }

◆ engine() [2/2]

const FireEngine& FireCoupler::engine ( ) const
inline
201 { return *m_engine; }

◆ fields_time()

double FireCoupler::fields_time ( ) const
inline

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

ERF sets it to the fire level's time at start-up and on a restart (set_fields_time), advance() to the end of the step, and ERF again to the coarser level's time once the finer levels' substeps have reached it, so that it equals the time ERF assigns to the level and carries no round-off from summing substeps.

215 { return m_fields_time; }

◆ fill_plot_var()

void FireCoupler::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 fire field name.

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

Parameters
[in]nameOne of plot_var_names()
[out]dstCell-centered MultiFab on the boxes of level lev
[in]dcompComponent of dst to fill
[in]levThe level dst belongs to
210 {
211  dst.setVal(0.0_rt, dcomp, 1, 0);
212  if (lev != m_lev || !m_Q_atm_prev) { return; }
213  const MultiFab* fire_field = m_engine->plot_var(name);
214  if (!fire_field) { return; }
215 
216  // The column means, on the k = 0 slabs the lagged fluxes use
217  MultiFab col(m_Q_atm_prev->boxArray(), m_Q_atm_prev->DistributionMap(), 1, 0);
218  col.setVal(0.0_rt);
219  coarsen_fire_flux_to_atm(col, *fire_field, m_geom_atm, m_fg);
220 
221  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(surface_same_columns(dst.boxArray(), col.boxArray()) &&
222  dst.DistributionMap() == col.DistributionMap(),
223  "[FIRE] fill_plot_var: the plotfile MultiFab is not on the fire grid's level");
224  const int k0 = m_geom_atm.Domain().smallEnd(2);
225  for (MFIter mfi(dst); mfi.isValid(); ++mfi) {
226  Box bx = mfi.validbox();
227  if (bx.smallEnd(2) > k0) { continue; }
228  bx.setSmall(2, k0);
229  bx.setBig(2, k0);
230  const auto d = dst.array(mfi);
231  const auto c = col.const_array(mfi);
232  const int kc = col.boxArray()[mfi.index()].smallEnd(2);
233  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
234  {
235  d(i, j, k, dcomp) = c(i, j, kc);
236  });
237  }
238 }
void coarsen_fire_flux_to_atm(amrex::MultiFab &Q_atm_out, const amrex::MultiFab &Q_fire, const amrex::Geometry &, const FireGrid &fg)
Definition: ERF_FireAtmCoupling.H:118
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);})
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
bool surface_same_columns(const amrex::BoxArray &a, const amrex::BoxArray &b)
Definition: ERF_SurfaceGrid.H:79
FireGrid m_fg
Definition: ERF_FireCoupler.H:236
amrex::Geometry m_geom_atm
geometry of the fire grid's level
Definition: ERF_FireCoupler.H:238
Here is the call graph for this function:

◆ fire_grid()

const FireGrid& FireCoupler::fire_grid ( ) const
inline

The fire grid.

204 { return m_fg; }

◆ get_Q_atm_prev()

const amrex::MultiFab* FireCoupler::get_Q_atm_prev ( ) const
inline

Sensible heat flux [W/m2] of the previous fire step on the atmospheric columns of the fire grid's level, with 5 ghost columns (for a reader that samples a halo around each tile, such as a boundary-layer scheme taking the fire's heat into its mixing); zero outside the fire region. Allocated at initialize, so never null afterwards.

226 { return m_Q_atm_prev.get(); }

◆ get_Q_lat_atm_prev()

const amrex::MultiFab* FireCoupler::get_Q_lat_atm_prev ( ) const
inline

Latent heat flux [W/m2] of the previous fire step, laid out as get_Q_atm_prev().

228 { return m_Q_lat_atm_prev.get(); }

◆ initialize()

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

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

Called once from ERF::InitData_post() after every surface layer exists. Runs the coupling's checks (verify_fire_prerequisites), then the engine's, builds the fire grid on level lev, allocates the lagged flux buffers (zero) and initializes the engine.

Parameters
[in]erfERF instance (public AmrCore accessors only)
[in]levThe level the fire grid refines (fire_anchor_level)
[in]surface_layerThe bottom surface layer, or nullptr (aborts when the engine needs one, FireEngine::needs_surface_layer)
[in]z_phys_nd_atmNodal height of level lev [m] (ERF always passes it)
88 {
89  // The ERF configuration a fire grid needs, then the engine's own inputs
91  m_engine->needs_surface_layer());
92  m_engine->verify_prerequisites(erf, lev);
93 
94  FireGrid fg = create_fire_grid(erf.boxArray(lev), erf.DistributionMap(lev),
95  erf.Geom(lev), m_params.grid_ratio);
96  fg.lev = lev;
97  report_fire_region(erf, lev, fg);
98  set_fire_grid(lev, fg, erf.boxArray(lev), erf.DistributionMap(lev), erf.Geom(lev));
99 
100  m_engine->initialize(erf, lev, m_fg, surface_layer, z_phys_nd_atm);
101 
102  // erf.fire.heat_open_fraction places the heat by the open fraction the
103  // engine reports; without one the heat is placed as if every column were open
105  (!m_engine->heat_open_fraction_atm() || !m_engine->roof_height_atm())) {
106  amrex::Print() << "[FIRE] WARNING: erf.fire.heat_open_fraction = true, but the fire engine ("
107  << m_engine->name() << ") reports no open fraction;"
108  << " the heat is placed as if every column were open\n";
109  }
110 }
FireGrid create_fire_grid(const BoxArray &ba_atm, const DistributionMapping &dm_atm, const Geometry &geom_atm, int C)
Definition: ERF_FireGrid.cpp:6
void verify_fire_prerequisites(const ERF &erf, int lev, const SurfaceLayer *surface_layer, int grid_ratio, bool needs_surface_layer)
Verify the ERF configuration the fire coupling needs.
Definition: ERF_FirePrerequisites.cpp:64
@ surface_layer
void set_fire_grid(int lev, const FireGrid &fg, const amrex::BoxArray &ba_atm, const amrex::DistributionMapping &dm_atm, const amrex::Geometry &geom_atm)
Lay the coupling out on a fire grid: what initialize() does after its start-up checks and before it s...
Definition: ERF_FireCoupler.cpp:113
@ fg
Definition: ERF_AdvanceMorrison.cpp:111
int grid_ratio
erf.fire.grid_ratio: fire cells per atmospheric cell in x and y
Definition: ERF_FireCouplingParams.H:25
2D horizontal fire computational grid
Definition: ERF_FireGrid.H:42
Here is the call graph for this function:

◆ level()

int FireCoupler::level ( ) const
inline

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

194 { return m_lev; }

◆ params()

const FireCouplingParams& FireCoupler::params ( ) const
inline

The coupling inputs.

197 { return m_params; }

◆ plot_var_names()

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

Fire fields the ERF plotfile can carry (FireEngine::plot_var_names(), read at construction, before ERF reads erf.plot_vars_*).

175 { return m_plot_var_names; }

◆ read_checkpoint()

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

Restore the engine's state, then the lagged fluxes, on a restart.

Aborts when the checkpoint holds the lagged fluxes on another level or over another region than this run's fire grid. A checkpoint without them (no fire state, or written before they were checkpointed) leaves them at zero: the first restarted step injects no fire heat.

Parameters
[in]restart_chkfileThe checkpoint directory
[in]max_levelERF's max_level
[in]stepThe step count of the fire grid's level at the checkpoint
378 {
379  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_Q_atm_prev, "[FIRE] FireCoupler: set_fire_grid() before the checkpoint");
380  // Every level the checkpoint holds is searched, not only those of this
381  // run's amr.max_level, so a restart onto fewer levels stops on the
382  // mismatch instead of starting the fire without its state. The number of
383  // levels is found on the I/O rank and broadcast.
384  int chk_finest = -1;
385  if (ParallelDescriptor::IOProcessor()) {
386  while (amrex::FileExists(restart_chkfile + "/Level_" + std::to_string(chk_finest + 1))) { ++chk_finest; }
387  }
388  ParallelDescriptor::Bcast(&chk_finest, 1, ParallelDescriptor::IOProcessorNumber());
389  const int search_level = std::max(max_level, chk_finest);
390 
391  // The engine first: it may check, naming its own fields, that the
392  // checkpoint's fire grid sits on this level and region
393  m_engine->read_checkpoint(restart_chkfile, search_level, step);
394 
395  // The lagged fluxes, on the level of the fire grid. A checkpoint without them
396  // (written with no fire running): the buffers keep their zero, said once.
397  // Decided on the I/O rank and broadcast, so every rank takes the same branch
398  // into the collective reads below
399  int chk_lev = -1;
400  if (ParallelDescriptor::IOProcessor()) {
401  for (int l = 0; l <= search_level; ++l) {
402  if (amrex::FileExists(restart_chkfile + "/Level_" + std::to_string(l) + "/FireQAtmPrev_H")) {
403  chk_lev = l;
404  break;
405  }
406  }
407  }
408  ParallelDescriptor::Bcast(&chk_lev, 1, ParallelDescriptor::IOProcessorNumber());
409  if (chk_lev < 0) {
410  amrex::Print() << "[FIRE] Checkpoint has no lagged fire fluxes; the first restarted step injects none.\n";
411  return;
412  }
413  // Whatever the engine: the fluxes belong to this run's fire grid, on its
414  // level and over its region (an engine may have checked its own fields
415  // already; this check holds whatever the engine)
416  const Box chk_region = VisMF(MultiFabFileFullPrefix(chk_lev, restart_chkfile, "Level_", "FireQAtmPrev"))
417  .boxArray().minimalBox();
418  if (const std::string why = checkpoint_mismatch(chk_lev, chk_region); !why.empty()) {
419  amrex::Abort("[FIRE] The checkpoint " + restart_chkfile + " " + why);
420  }
421  for (const auto& [mf, name] : {std::pair<MultiFab*, const char*>{m_Q_atm_prev.get(), "FireQAtmPrev"},
422  std::pair<MultiFab*, const char*>{m_Q_lat_atm_prev.get(), "FireQLatAtmPrev"}}) {
423  if (mf == nullptr) { continue; }
424  // decided on one rank and broadcast, so every rank takes the same
425  // path into the collective read below
426  const std::string header = restart_chkfile + "/Level_" + std::to_string(m_lev) + "/" + name + "_H";
427  int has_field = 0;
428  if (ParallelDescriptor::IOProcessor()) { has_field = amrex::FileExists(header) ? 1 : 0; }
429  ParallelDescriptor::Bcast(&has_field, 1, ParallelDescriptor::IOProcessorNumber());
430  if (has_field == 0) {
431  amrex::Print() << "[FIRE] Checkpoint has no " << name << "; keeping the initialized values.\n";
432  continue;
433  }
434  VisMF::Read(*mf, MultiFabFileFullPrefix(m_lev, restart_chkfile, "Level_", name));
435  // VisMF restores the valid cells (a checkpoint may hold no ghost
436  // columns), so refill the ghosts the way update_flux_buffer() does.
438  }
439 }
void fire_fill_boundary(amrex::MultiFab &mf, const amrex::Geometry &geom)
Definition: ERF_FireGrid.H:73
std::string checkpoint_mismatch(int chk_lev, const amrex::Box &chk_region) const
Why a checkpoint's lagged fluxes do not belong to this run's fire grid, or an empty string when they ...
Definition: ERF_FireCoupler.cpp:362
Here is the call graph for this function:

◆ set_fields_time()

void FireCoupler::set_fields_time ( double  t)
inline

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

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

◆ set_fire_grid()

void FireCoupler::set_fire_grid ( int  lev,
const FireGrid &  fg,
const amrex::BoxArray &  ba_atm,
const amrex::DistributionMapping &  dm_atm,
const amrex::Geometry &  geom_atm 
)

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

Takes the fire grid and allocates the lagged flux buffers (zero) on the k = 0 slabs of ba_atm, with 5 ghost columns. Public so that a test can drive the coupling with an engine of its own without an ERF object (erf-model/FLARE: Tests/Unit/Fire/ERF_GTestFireCoupler.cpp).

Parameters
[in]levThe level the fire grid refines
[in]fgThe fire grid (create_fire_grid)
[in]ba_atmThe level's boxes
[in]dm_atmTheir owners
[in]geom_atmThe level's geometry
117 {
118  m_lev = lev;
119  m_fg = fg;
120  m_geom_atm = geom_atm;
121  const int nz = geom_atm.Domain().length(2);
122 
123  // The lagged fluxes live on the k = 0 slabs of the level's boxes, with the
124  // level's owners. Ghost columns for a reader that samples the fluxes in the
125  // halo around every tile: 5, the most ERF's state carries
126  // (ComputeGhostCells() + 1); update_flux_buffer() fills them.
127  BoxArray ba_atm_2d = ba_atm;
128  ba_atm_2d.coarsen(IntVect(1, 1, nz));
129  const IntVect ng_flux(5, 5, 0);
130  m_Q_atm_prev = std::make_unique<MultiFab>(ba_atm_2d, dm_atm, 1, ng_flux);
131  m_Q_lat_atm_prev = std::make_unique<MultiFab>(ba_atm_2d, dm_atm, 1, ng_flux);
132  m_Q_atm_prev->setVal(0.0_rt);
133  m_Q_lat_atm_prev->setVal(0.0_rt);
134 }

Referenced by initialize().

Here is the caller graph for this function:

◆ update_flux_buffer()

void FireCoupler::update_flux_buffer ( const amrex::Geometry &  geom_atm)
private

Average the engine's fluxes onto the atmospheric columns for the next step.

242 {
244  if (m_params.fire_debug) {
245  amrex::Print() << "[FIRE DEBUG] Skipping flux buffer update: coupling_type is passive (injects_flux=false) and smoke_enable=false" << std::endl;
246  }
247  return;
248  }
249 
250  if (!m_Q_atm_prev) { return; }
251  FireFluxes fluxes;
252  m_engine->fill_fluxes(fluxes);
253  if (fluxes.sensible) {
254  coarsen_fire_flux_to_atm(*m_Q_atm_prev, *fluxes.sensible, geom_atm, m_fg);
255  if (m_params.fire_debug) {
256  amrex::Print() << "[FIRE DEBUG] Sensible flux to the atmosphere: max " << m_Q_atm_prev->max(0)
257  << " W/m2" << fluxes.debug_note << std::endl;
258  }
259  } else {
260  // Clear the stale sensible flux without discarding independent latent
261  // feedback reported by the engine during this same step.
262  m_Q_atm_prev->setVal(0.0_rt);
263  }
264 
265  if (m_params.inject_latent && fluxes.latent) {
267  } else {
269  amrex::Print() << "[FIRE DEBUG] Skipping latent heat injection (inject_latent=false or the engine reports no latent flux)" << std::endl;
270  }
271  m_Q_lat_atm_prev->setVal(0.0_rt);
272  }
273 
274  // A reader may sample these fluxes in the halo columns around every tile;
275  // give them the neighboring box's value (and the edge column's
276  // outside a non-periodic face), so a column sees the same flux whichever box
277  // holds it. On a finer level the columns outside the refined region have no
278  // fire grid and keep the zero they were allocated with.
279  fire_fill_boundary(*m_Q_atm_prev, geom_atm);
281 }
The fluxes a fire engine hands to the atmosphere after its step.
Definition: ERF_FireEngine.H:99
const amrex::MultiFab * latent
Definition: ERF_FireEngine.H:101
std::string debug_note
Definition: ERF_FireEngine.H:104
const amrex::MultiFab * sensible
Sensible heat flux into the air [W/m2]; nullptr = none this step.
Definition: ERF_FireEngine.H:100

Referenced by advance().

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

◆ write_checkpoint()

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

Write the fire to a checkpoint: the engine's state (FireEngine::write_checkpoint), then the coupling's lagged fluxes (FireQAtmPrev and FireQLatAtmPrev) under checkpointname/Level_<lev>/.

346 {
347  // The engine's own state first, as read_checkpoint restores it
348  m_engine->write_checkpoint(checkpointname);
349 
350  // The lagged fluxes injected into the atmosphere on the next step. Without
351  // them the first step after a restart injects no fire heat at all.
352  if (m_Q_atm_prev) {
353  amrex::Print() << "Writing fire atmosphere flux buffer to checkpoint" << std::endl;
354  VisMF::Write(*m_Q_atm_prev, MultiFabFileFullPrefix(m_lev, checkpointname, "Level_", "FireQAtmPrev"));
355  }
356  if (m_Q_lat_atm_prev) {
357  VisMF::Write(*m_Q_lat_atm_prev, MultiFabFileFullPrefix(m_lev, checkpointname, "Level_", "FireQLatAtmPrev"));
358  }
359 }

Member Data Documentation

◆ m_engine

◆ m_fg

FireGrid FireCoupler::m_fg
private

◆ m_fields_time

double FireCoupler::m_fields_time = 0.0
private

the time the engine's fields belong to (fields_time())

Referenced by advance(), fields_time(), and set_fields_time().

◆ m_geom_atm

amrex::Geometry FireCoupler::m_geom_atm
private

geometry of the fire grid's level

Referenced by fill_plot_var(), read_checkpoint(), and set_fire_grid().

◆ m_lev

int FireCoupler::m_lev = 0
private

◆ m_params

FireCouplingParams FireCoupler::m_params
private

◆ m_plot_var_names

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

FireEngine::plot_var_names(), read at construction.

Referenced by FireCoupler(), and plot_var_names().

◆ m_Q_atm_prev

std::unique_ptr<amrex::MultiFab> FireCoupler::m_Q_atm_prev
private

◆ m_Q_lat_atm_prev

std::unique_ptr<amrex::MultiFab> FireCoupler::m_Q_lat_atm_prev
private

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