ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_Microphysics.H
Go to the documentation of this file.
1 /*! @file ERF_Microphysics.H
2  * \brief Contains the base class for microphysics
3  */
4 
5 #ifndef ERF_MICROPHYSICS_H
6 #define ERF_MICROPHYSICS_H
7 
8 #include <vector>
9 #include <string>
10 #include <AMReX_MultiFab.H>
11 #include <AMReX_iMultiFab.H>
12 #include "ERF_DataStruct.H"
13 #include "ERF_IndexDefines.H"
15 #include "ERF_SedimentationFlux.H"
16 
17 /*! \brief Base class for microphysics interface */
18 class Microphysics {
19 
20 public:
21 
22  /*! \brief Null constructor */
23  Microphysics () { }
24 
25  /*! \brief default destructor */
26  virtual ~Microphysics () = default;
27 
28  /*! \brief define the microphysics object */
29  virtual void Define (const int&, SolverChoice&) = 0;
30 
31  /*! \brief initialize the microphysics object */
32  virtual void Init (const int&,
33  const amrex::MultiFab&,
34  const amrex::BoxArray&,
35  const amrex::Geometry&,
36  const amrex::Real&,
37  std::unique_ptr<amrex::MultiFab>&,
38  std::unique_ptr<amrex::MultiFab>&) = 0;
39 
40  /*! \brief finish initializations steps that require flow variables */
41  virtual void FinishInit (const int&,
42  amrex::MultiFab&,
43  const amrex::Vector<std::unique_ptr<amrex::MultiFab>>& ) = 0;
44 
45  /*! \brief advance microphysics for one time step */
46  virtual void Advance (const int&,
47  const amrex::Real&,
48  const int&,
49  const amrex::Real&,
50  const SolverChoice&,
51  amrex::Vector<amrex::Vector<amrex::MultiFab>>&,
52  const amrex::Vector<std::unique_ptr<amrex::MultiFab>>&,
53  const amrex::GpuArray<ERF_BC, AMREX_SPACEDIM*2>& ) = 0;
54 
55  /*! \brief update microphysics variables from ERF state variables */
56  virtual void Update_Micro_Vars_Lev (const int&, amrex::MultiFab&,
57  const amrex::MultiFab* base_state = nullptr) = 0;
58 
59  /*! \brief update ERF state variables from microphysics variables */
60  virtual void Update_State_Vars_Lev (const int&, amrex::MultiFab&, const amrex::MultiFab&) = 0;
61 
62  /*! Refresh diagnostic Q projections after particle redistribution, without advancing sources. */
63  virtual void Update_Diagnostic_State_Lev (const int&, amrex::MultiFab&, const amrex::MultiFab&) {}
64 
65  /*! \brief average down moisture multifabs from finest_level to 0 (AMR coverage); no-op for non-Lagrangian models */
66  virtual void AverageDownMicroVars (const int /*finest_level*/) { }
67 
68  /*! \brief drop the fields of a level that a regrid removes; no-op for models without level fields of their own */
69  virtual void ClearLevel (const int /*lev*/) { }
70 
71  /*! \brief diagnostics of the state of all levels at a step (step, time, terrain, file name digits) */
72  virtual void Diagnostics (const int& /*step*/,
73  const amrex::Real& /*time*/,
74  const amrex::Vector<std::unique_ptr<amrex::MultiFab>>& /*z_phys_nd*/,
75  const int /*file_name_digits*/) { }
76 
77  /*! \brief get scheme-native surface precipitation accumulators and their kg/m^2 conversion factors */
80  {
81  return {};
82  }
83 
84  /*! \brief The sedimentation face fluxes of the most recent Advance at a level, or null
85  * when the moisture model does not sediment there (see ERF_SedimentationFlux.H) */
86  virtual const SedimentationFlux* Get_Sed_Flux (const int& /*lev*/) const { return nullptr; }
87 
88  /*! \brief Hand the moisture model at a level the inflow through the top of its fine
89  * patches for the next Advance, or null (see ERF_SedimentationFlux.H) */
90  virtual void Set_Sed_Inflow (const int& /*lev*/, const amrex::MultiFab* /*inflow*/) { }
91 
92  /*! \brief get pointer to a moisture variable */
93  virtual amrex::MultiFab* Get_Qmoist_Ptr (const int&, const int&) = 0;
94 
95  /*! \brief get the number of moisture model variables */
96  virtual int Get_Qmoist_Size (const int&) = 0;
97 
98  /*! \brief get the number of microphysics conserved moist (water-related) state variables */
99  virtual int Get_Qstate_Moist_Size () = 0;
100 
101  /*! \brief get the number of microphysics conserved moist (water-related) state variables that are number concentrations */
102  virtual int Get_Qstate_Moist_NumConc_Size () = 0;
103 
104  /*! \brief get the number of microphysics conserved non-moist (non-water, i.e., other vapor/condensed species) state variables */
105  virtual int Get_Qstate_NonMoist_Size () = 0;
106 
107  /*! \brief Whether a Q-state offset is a projection rather than host-transported state. */
108  virtual bool Qstate_Is_Diagnostic (int /*q*/) const { return false; }
109 
110  /*! \brief get total number of conserved state variables */
111  inline int Get_Qstate_Size ()
112  {
114  }
115 
116  /*! \brief get the indices and names of moisture model variables for restart
117  at a given level */
118  virtual void Get_Qmoist_Restart_Vars (int,
119  const SolverChoice&,
120  std::vector<int>&,
121  std::vector<std::string>& ) const = 0;
122 
123  /*! \brief Returns a list of additional plot variable names */
124  virtual void GetPlotVarNames (amrex::Vector<std::string>& a_vec) const = 0;
125 
126  /*! \brief Fills in a MultiFab for plotting */
127  virtual void GetPlotVar (const std::string& a_name,
128  amrex::MultiFab& a_mf,
129  const int a_lev) const = 0;
130 
131  /*! \brief Import minimum dz at this level */
132  virtual void Set_dzmin (const int lev,
133  const amrex::Real dz_min) const = 0;
134 
135  /*! \brief Import ERF's land/water mask at this level.
136  *
137  * The mask is held by pointer, not copied, so a mask that is retagged after
138  * this call (e.g. buildings set to 2 in init_zphys) is picked up. Callers
139  * must re-issue this after any rebuild of lmask_lev, since init_stuff
140  * replaces the unique_ptr. */
141  virtual void Set_Lmask (const int lev,
142  amrex::iMultiFab* lmask) const = 0;
143 
144  /*! \brief query if a specified moisture model is Eulerian or Lagrangian */
145  static MoistureModelType modelType (const MoistureType a_moisture_type)
146  {
147  if ( (a_moisture_type == MoistureType::SAM)
148  || (a_moisture_type == MoistureType::SAM_NoIce)
149  || (a_moisture_type == MoistureType::SAM_NoPrecip_NoIce)
150  || (a_moisture_type == MoistureType::Morrison)
151  || (a_moisture_type == MoistureType::Morrison_NoIce)
152  || (a_moisture_type == MoistureType::WSM6)
153  || (a_moisture_type == MoistureType::WDM6)
154  || (a_moisture_type == MoistureType::Kessler)
155  || (a_moisture_type == MoistureType::Kessler_NoRain)
156  || (a_moisture_type == MoistureType::SatAdj)
157  || (a_moisture_type == MoistureType::MoistNoCondensation)
158  || (a_moisture_type == MoistureType::SBM)
159  || (a_moisture_type == MoistureType::None) ) {
160  return MoistureModelType::Eulerian;
161  } else if ( (a_moisture_type == MoistureType::SuperDroplets) ) {
162  return MoistureModelType::Lagrangian;
163  } else {
164  amrex::Abort("Dont know this moisture_type!") ;
165  return MoistureModelType::Undefined;
166  }
167  }
168 private:
169 
170 };
171 #endif
The sedimentation face fluxes a precipitating microphysics scheme records.
Base class for microphysics interface.
Definition: ERF_Microphysics.H:18
virtual int Get_Qmoist_Size(const int &)=0
get the number of moisture model variables
virtual ~Microphysics()=default
default destructor
virtual void ClearLevel(const int)
drop the fields of a level that a regrid removes; no-op for models without level fields of their own
Definition: ERF_Microphysics.H:69
virtual int Get_Qstate_NonMoist_Size()=0
get the number of microphysics conserved non-moist (non-water, i.e., other vapor/condensed species) s...
virtual void Define(const int &, SolverChoice &)=0
define the microphysics object
virtual void AverageDownMicroVars(const int)
average down moisture multifabs from finest_level to 0 (AMR coverage); no-op for non-Lagrangian model...
Definition: ERF_Microphysics.H:66
virtual int Get_Qstate_Moist_NumConc_Size()=0
get the number of microphysics conserved moist (water-related) state variables that are number concen...
virtual void Init(const int &, const amrex::MultiFab &, const amrex::BoxArray &, const amrex::Geometry &, const amrex::Real &, std::unique_ptr< amrex::MultiFab > &, std::unique_ptr< amrex::MultiFab > &)=0
initialize the microphysics object
virtual int Get_Qstate_Moist_Size()=0
get the number of microphysics conserved moist (water-related) state variables
virtual void Diagnostics(const int &, const amrex::Real &, const amrex::Vector< std::unique_ptr< amrex::MultiFab >> &, const int)
diagnostics of the state of all levels at a step (step, time, terrain, file name digits)
Definition: ERF_Microphysics.H:72
virtual void Set_Sed_Inflow(const int &, const amrex::MultiFab *)
Hand the moisture model at a level the inflow through the top of its fine patches for the next Advanc...
Definition: ERF_Microphysics.H:90
Microphysics()
Null constructor.
Definition: ERF_Microphysics.H:23
virtual void Update_Micro_Vars_Lev(const int &, amrex::MultiFab &, const amrex::MultiFab *base_state=nullptr)=0
update microphysics variables from ERF state variables
virtual SurfacePrecipAccumulationSources Get_Surface_Precip_Accumulation_Ptrs(const int &) const
get scheme-native surface precipitation accumulators and their kg/m^2 conversion factors
Definition: ERF_Microphysics.H:79
virtual const SedimentationFlux * Get_Sed_Flux(const int &) const
The sedimentation face fluxes of the most recent Advance at a level, or null when the moisture model ...
Definition: ERF_Microphysics.H:86
virtual void Update_State_Vars_Lev(const int &, amrex::MultiFab &, const amrex::MultiFab &)=0
update ERF state variables from microphysics variables
virtual amrex::MultiFab * Get_Qmoist_Ptr(const int &, const int &)=0
get pointer to a moisture variable
virtual void GetPlotVarNames(amrex::Vector< std::string > &a_vec) const =0
Returns a list of additional plot variable names.
virtual void Get_Qmoist_Restart_Vars(int, const SolverChoice &, std::vector< int > &, std::vector< std::string > &) const =0
get the indices and names of moisture model variables for restart at a given level
int Get_Qstate_Size()
get total number of conserved state variables
Definition: ERF_Microphysics.H:111
virtual void Set_Lmask(const int lev, amrex::iMultiFab *lmask) const =0
Import ERF's land/water mask at this level.
virtual void Update_Diagnostic_State_Lev(const int &, amrex::MultiFab &, const amrex::MultiFab &)
Definition: ERF_Microphysics.H:63
virtual void Set_dzmin(const int lev, const amrex::Real dz_min) const =0
Import minimum dz at this level.
static MoistureModelType modelType(const MoistureType a_moisture_type)
query if a specified moisture model is Eulerian or Lagrangian
Definition: ERF_Microphysics.H:145
virtual void FinishInit(const int &, amrex::MultiFab &, const amrex::Vector< std::unique_ptr< amrex::MultiFab >> &)=0
finish initializations steps that require flow variables
virtual bool Qstate_Is_Diagnostic(int) const
Whether a Q-state offset is a projection rather than host-transported state.
Definition: ERF_Microphysics.H:108
virtual void GetPlotVar(const std::string &a_name, amrex::MultiFab &a_mf, const int a_lev) const =0
Fills in a MultiFab for plotting.
virtual void Advance(const int &, const amrex::Real &, const int &, const amrex::Real &, const SolverChoice &, amrex::Vector< amrex::Vector< amrex::MultiFab >> &, const amrex::Vector< std::unique_ptr< amrex::MultiFab >> &, const amrex::GpuArray< ERF_BC, AMREX_SPACEDIM *2 > &)=0
advance microphysics for one time step
@ None
Definition: ERF_LSM_Types.H:6
Definition: ERF_SedimentationFlux.H:38
Definition: ERF_DataStruct.H:743
Definition: ERF_SurfacePrecipitation.H:40