ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_DustModel.H
Go to the documentation of this file.
1 #ifndef ERF_DUST_MODEL_H
2 #define ERF_DUST_MODEL_H
3 
4 #include <AMReX_Geometry.H>
5 #include <AMReX_MultiFab.H>
6 #include <AMReX_REAL.H>
7 
8 #include <string>
9 
10 class ERF;
11 class SurfaceLayer;
12 struct ForceRestoreSoil;
13 #ifdef ERF_USE_FIRE
14 class FireEngine;
15 struct FireGrid;
16 #endif
17 
18 /**
19  * @file ERF_DustModel.H
20  * @brief The interface between ERF and a dust model
21  *
22  * A dust model emits dust from the ground into the dust scalars of the
23  * conserved state, settles and deposits it, and writes its own output. ERF
24  * owns the dust scalars: ERF_NUM_DUST_SCALARS (CMake; NUM_DUST_SCALARS in GNU
25  * make) of them, starting at RhoDust_comp (ERF_IndexDefines.H), advected and
26  * diffused like every passive scalar and zero at the start of a run. A model
27  * adds its tendencies to them in add_sources() and keeps everything else (its
28  * surface grid, its fields, its particles) itself.
29  *
30  * ERF itself contains no model. A model lives in its own directory outside ERF
31  * (DUST_HOME in GNU make, ERF_DUST_MODEL_DIRS in CMake) and registers itself
32  * with ERF_REGISTER_DUST_MODEL (ERF_DustModelRegistry.H). erf.dust.enable =
33  * true turns dust on; erf.dust.model names the model, and may be left out
34  * when one model is compiled in.
35  *
36  * ERF calls, in this order:
37  * - initialize() once, at the end of start-up (after the fire coupling's
38  * initialization), which on a restart also restores the model's state;
39  * - add_sources() at every Runge-Kutta stage of every level, right after
40  * ERF's own sources are built and before the fire coupling adds its fluxes;
41  * - advance() once per step of level 0, after the step;
42  * - write_output() at start-up (step 0, before the first plotfile), after
43  * each step and at the end of the run, each time before ERF writes a
44  * checkpoint, so a checkpoint records the model's output of that step as
45  * written;
46  * - write_checkpoint() each time ERF writes a checkpoint.
47  *
48  * Memory contract, as for fire engines (ERF_FireEngine.H): every MultiFab in
49  * DustInit, DustStep and the add_sources() arguments is an ordinary AMReX
50  * MultiFab in the default arena (device memory on a GPU build) and a
51  * temporary of the call; a model keeps no pointer to it.
52  */
53 
54 #ifdef ERF_USE_FIRE
55 /**
56  * @brief The fire, read-only, for a dust model that couples to it
57  *
58  * The engine's getters (level_set(), reference_wind(),
59  * reference_wind_height(), heat_release()) are what a dust model may read;
60  * an engine without one returns nullptr. The fields live on the fire grid.
61  */
62 struct DustFire
63 {
64  const FireEngine& engine; ///< The fire engine (erf.fire.engine)
65  const FireGrid& grid; ///< The fire grid: its layout and refinement factor C (erf.fire.grid_ratio)
66  double time; ///< The time the engine's fields belong to [s]
67 };
68 #endif
69 
70 /**
71  * @brief What a dust model reads when it is set up
72  */
73 struct DustInit
74 {
75  const ERF& erf; ///< ERF instance (public accessors only)
76  SurfaceLayer* surface_layer; ///< The bottom surface layer, or nullptr when zlo is not one
77  const amrex::MultiFab& z_phys_nd; ///< Nodal height [m] of level 0
78  const std::string& restart_chkfile; ///< The checkpoint the run restarts from; empty on a fresh start
79  int step; ///< Level 0's step: 0, or the step of the checkpoint
80  double time; ///< Level 0's time [s]: 0, or the time of the checkpoint
81 #ifdef ERF_USE_FIRE
82  const DustFire* fire; ///< The fire, when the run has one; nullptr otherwise
83 #endif
84 };
85 
86 /**
87  * @brief The state a dust model reads after each step of level 0
88  */
89 struct DustStep
90 {
91  int step; ///< The step just taken (0 for the first one)
92  double time; ///< Start of the step [s]
93  amrex::Real dt; ///< Step of level 0 [s]
94  const amrex::Geometry& geom; ///< Geometry of level 0
95  const amrex::MultiFab& cons; ///< Conserved state of level 0 at the end of the step
96  const amrex::MultiFab& xvel; ///< x-velocity on x-faces [m/s], end of the step
97  const amrex::MultiFab& yvel; ///< y-velocity on y-faces [m/s], end of the step
98  const amrex::MultiFab& zvel; ///< z-velocity on z-faces [m/s], end of the step
99  const amrex::MultiFab* z_phys_cc; ///< Cell-center height [m]; nullptr when ERF holds none
100  const amrex::MultiFab* surface_q1_flux; ///< Surface vapor flux of level 0 (the turbulence scheme's z flux of q1); nullptr when there is none
101  SurfaceLayer* surface_layer; ///< The bottom surface layer, or nullptr
102 #ifdef ERF_USE_FIRE
103  const DustFire* fire; ///< The fire, when the run has one; nullptr otherwise
104 #endif
105  /// The two-stream force-restore soil of level 0 (ERF_ForceRestoreHydrologyState.H),
106  /// read-only; nullptr when that state is not evolved (erf.radiation.seb_prognostic_enable).
107  /// Last, with a default, so that an initializer that predates it still compiles.
108  const ForceRestoreSoil* soil = nullptr;
109 };
110 
111 /**
112  * @brief A dust model behind ERF's dust coupling
113  */
115 {
116 public:
117  virtual ~DustModel () = default;
118 
119  /// Name of the model, as erf.dust.model selects it.
120  virtual const char* name () const = 0;
121 
122  /// Number of dust scalars the model fills, from RhoDust_comp on; at most
123  /// NSCALARS_DUST (ERF stops the run otherwise).
124  virtual int num_scalars () const { return 1; }
125 
126  /**
127  * @brief Set the model up, and on a restart restore its state
128  *
129  * Reads the model's inputs (erf.dust.*). On a restart
130  * (init.restart_chkfile not empty) the model reads back what its
131  * write_checkpoint() wrote there. After this call, on a fresh start, ERF
132  * zeroes the dust scalars on every level.
133  */
134  virtual void initialize (const DustInit& init) = 0;
135 
136  /**
137  * @brief Add the dust tendencies to the source of the conserved state
138  *
139  * @param[in] lev The level; a model that runs on level 0 only returns on the others
140  * @param[inout] cc_src Source of the conserved state [per second]; the model adds to
141  * the dust components only
142  * @param[in] state The conserved state of this Runge-Kutta stage
143  * @param[in] detJ_cc Cell Jacobian (1 on a mesh without terrain): a cell's height is detJ dz
144  * @param[in] geom Geometry of the level
145  * @param[in] dt The step of the stage's slow update [s]
146  */
147  virtual void add_sources (int lev, amrex::MultiFab& cc_src, const amrex::MultiFab& state,
148  const amrex::MultiFab& detJ_cc, const amrex::Geometry& geom,
149  amrex::Real dt) = 0;
150 
151  /// Advance the model's own state over the step of level 0 just taken.
152  virtual void advance (const DustStep& step) = 0;
153 
154  /// Write the model's output for step (0 at start-up); is_final at the end of the run.
155  virtual void write_output (int /*step*/, double /*time*/, bool /*is_final*/) {}
156 
157  /// Write the model's state into the checkpoint directory, for initialize() to restore.
158  virtual void write_checkpoint (const std::string& /*checkpointname*/) const {}
159 };
160 
161 #endif
A dust model behind ERF's dust coupling.
Definition: ERF_DustModel.H:115
virtual void add_sources(int lev, amrex::MultiFab &cc_src, const amrex::MultiFab &state, const amrex::MultiFab &detJ_cc, const amrex::Geometry &geom, amrex::Real dt)=0
Add the dust tendencies to the source of the conserved state.
virtual void write_output(int, double, bool)
Write the model's output for step (0 at start-up); is_final at the end of the run.
Definition: ERF_DustModel.H:155
virtual void write_checkpoint(const std::string &) const
Write the model's state into the checkpoint directory, for initialize() to restore.
Definition: ERF_DustModel.H:158
virtual int num_scalars() const
Definition: ERF_DustModel.H:124
virtual void initialize(const DustInit &init)=0
Set the model up, and on a restart restore its state.
virtual void advance(const DustStep &step)=0
Advance the model's own state over the step of level 0 just taken.
virtual const char * name() const =0
Name of the model, as erf.dust.model selects it.
virtual ~DustModel()=default
A fire engine behind the shared coupling layer.
Definition: ERF_FireEngine.H:132
Definition: ERF_SurfaceLayer.H:64
Definition: ERF_InterpolationUtils.H:15
What a dust model reads when it is set up.
Definition: ERF_DustModel.H:74
const amrex::MultiFab & z_phys_nd
Nodal height [m] of level 0.
Definition: ERF_DustModel.H:77
const ERF & erf
ERF instance (public accessors only)
Definition: ERF_DustModel.H:75
SurfaceLayer * surface_layer
The bottom surface layer, or nullptr when zlo is not one.
Definition: ERF_DustModel.H:76
int step
Level 0's step: 0, or the step of the checkpoint.
Definition: ERF_DustModel.H:79
double time
Level 0's time [s]: 0, or the time of the checkpoint.
Definition: ERF_DustModel.H:80
const std::string & restart_chkfile
The checkpoint the run restarts from; empty on a fresh start.
Definition: ERF_DustModel.H:78
The state a dust model reads after each step of level 0.
Definition: ERF_DustModel.H:90
double time
Start of the step [s].
Definition: ERF_DustModel.H:92
int step
The step just taken (0 for the first one)
Definition: ERF_DustModel.H:91
SurfaceLayer * surface_layer
The bottom surface layer, or nullptr.
Definition: ERF_DustModel.H:101
const amrex::MultiFab & xvel
x-velocity on x-faces [m/s], end of the step
Definition: ERF_DustModel.H:96
const amrex::Geometry & geom
Geometry of level 0.
Definition: ERF_DustModel.H:94
const amrex::MultiFab & zvel
z-velocity on z-faces [m/s], end of the step
Definition: ERF_DustModel.H:98
const amrex::MultiFab * surface_q1_flux
Surface vapor flux of level 0 (the turbulence scheme's z flux of q1); nullptr when there is none.
Definition: ERF_DustModel.H:100
const ForceRestoreSoil * soil
Definition: ERF_DustModel.H:108
const amrex::MultiFab & yvel
y-velocity on y-faces [m/s], end of the step
Definition: ERF_DustModel.H:97
const amrex::MultiFab & cons
Conserved state of level 0 at the end of the step.
Definition: ERF_DustModel.H:95
amrex::Real dt
Step of level 0 [s].
Definition: ERF_DustModel.H:93
const amrex::MultiFab * z_phys_cc
Cell-center height [m]; nullptr when ERF holds none.
Definition: ERF_DustModel.H:99
2D horizontal fire computational grid
Definition: ERF_FireGrid.H:42
The force-restore soil of one level, read-only, for a model that reads the ground (the dust coupling'...
Definition: ERF_ForceRestoreHydrologyState.H:24