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 get scheme-native surface precipitation accumulators and their kg/m^2 conversion factors */
71  {
72  return {};
73  }
74 
75  /*! \brief The sedimentation face fluxes of the most recent Advance at a level, or null
76  * when the moisture model does not sediment there (see ERF_SedimentationFlux.H) */
77  virtual const SedimentationFlux* Get_Sed_Flux (const int& /*lev*/) const { return nullptr; }
78 
79  /*! \brief Hand the moisture model at a level the inflow through the top of its fine
80  * patches for the next Advance, or null (see ERF_SedimentationFlux.H) */
81  virtual void Set_Sed_Inflow (const int& /*lev*/, const amrex::MultiFab* /*inflow*/) { }
82 
83  /*! \brief get pointer to a moisture variable */
84  virtual amrex::MultiFab* Get_Qmoist_Ptr (const int&, const int&) = 0;
85 
86  /*! \brief get the number of moisture model variables */
87  virtual int Get_Qmoist_Size (const int&) = 0;
88 
89  /*! \brief get the number of microphysics conserved moist (water-related) state variables */
90  virtual int Get_Qstate_Moist_Size () = 0;
91 
92  /*! \brief get the number of microphysics conserved moist (water-related) state variables that are number concentrations */
93  virtual int Get_Qstate_Moist_NumConc_Size () = 0;
94 
95  /*! \brief get the number of microphysics conserved non-moist (non-water, i.e., other vapor/condensed species) state variables */
96  virtual int Get_Qstate_NonMoist_Size () = 0;
97 
98  /*! \brief Whether a Q-state offset is a projection rather than host-transported state. */
99  virtual bool Qstate_Is_Diagnostic (int /*q*/) const { return false; }
100 
101  /*! \brief get total number of conserved state variables */
102  inline int Get_Qstate_Size ()
103  {
105  }
106 
107  /*! \brief get the indices and names of moisture model variables for restart
108  at a given level */
109  virtual void Get_Qmoist_Restart_Vars (int,
110  const SolverChoice&,
111  std::vector<int>&,
112  std::vector<std::string>& ) const = 0;
113 
114  /*! \brief Returns a list of additional plot variable names */
115  virtual void GetPlotVarNames (amrex::Vector<std::string>& a_vec) const = 0;
116 
117  /*! \brief Fills in a MultiFab for plotting */
118  virtual void GetPlotVar (const std::string& a_name,
119  amrex::MultiFab& a_mf,
120  const int a_lev) const = 0;
121 
122  /*! \brief Import minimum dz at this level */
123  virtual void Set_dzmin (const int lev,
124  const amrex::Real dz_min) const = 0;
125 
126  /*! \brief Import ERF's land/water mask at this level.
127  *
128  * The mask is held by pointer, not copied, so a mask that is retagged after
129  * this call (e.g. buildings set to 2 in init_zphys) is picked up. Callers
130  * must re-issue this after any rebuild of lmask_lev, since init_stuff
131  * replaces the unique_ptr. */
132  virtual void Set_Lmask (const int lev,
133  amrex::iMultiFab* lmask) const = 0;
134 
135  /*! \brief query if a specified moisture model is Eulerian or Lagrangian */
136  static MoistureModelType modelType (const MoistureType a_moisture_type)
137  {
138  if ( (a_moisture_type == MoistureType::SAM)
139  || (a_moisture_type == MoistureType::SAM_NoIce)
140  || (a_moisture_type == MoistureType::SAM_NoPrecip_NoIce)
141  || (a_moisture_type == MoistureType::Morrison)
142  || (a_moisture_type == MoistureType::Morrison_NoIce)
143  || (a_moisture_type == MoistureType::WSM6)
144  || (a_moisture_type == MoistureType::WDM6)
145  || (a_moisture_type == MoistureType::Kessler)
146  || (a_moisture_type == MoistureType::Kessler_NoRain)
147  || (a_moisture_type == MoistureType::SatAdj)
148  || (a_moisture_type == MoistureType::MoistNoCondensation)
149  || (a_moisture_type == MoistureType::SBM)
150  || (a_moisture_type == MoistureType::None) ) {
151  return MoistureModelType::Eulerian;
152  } else if ( (a_moisture_type == MoistureType::SuperDroplets) ) {
153  return MoistureModelType::Lagrangian;
154  } else {
155  amrex::Abort("Dont know this moisture_type!") ;
156  return MoistureModelType::Undefined;
157  }
158  }
159 private:
160 
161 };
162 #endif
The sedimentation face fluxes a precipitating microphysics scheme records.
amrex::Real Real
Definition: ERF_ShocInterface.H:19
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 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 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:81
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:70
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:77
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:102
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:136
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:99
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:715
Definition: ERF_SurfacePrecipitation.H:34