ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_LagrangianMicrophysics.H
Go to the documentation of this file.
1 /*! @file ERF_LagrangianMicrophysics.H
2  * \brief Contains the Lagrangian microphysics class
3  */
4 
5 #ifndef ERF_LAGRANGIANMICROPHYSICS_H
6 #define ERF_LAGRANGIANMICROPHYSICS_H
7 
8 #ifdef ERF_USE_PARTICLES
9 
10 #include <utility>
11 #include <string>
12 
14 #include "ERF_SuperDropletsMoist.H"
15 #include "ERF_Microphysics.H"
16 
17 /* forward declaration */
18 class ERFPC;
19 
20 /*! \brief Eulerian microphysics interface
21  *
22  * One key difference from #EulerianMicrophysics is that only the base AMR
23  * level has the moisture model. Thus, for higher AMR levels, the microphysics
24  * interface need not do anything. The number of conserved state variables for
25  * moisture (RhoQ1, RhoQ2, ...) are the same for all AMR levels; however, for
26  * levels other than the base, they just contain and evolve zeros. */
27 class LagrangianMicrophysics : public Microphysics {
28 
29 public:
30 
31  /*! \brief Null constructor */
32  LagrangianMicrophysics () { }
33 
34  /*! \brief default destructor */
35  ~LagrangianMicrophysics () = default;
36 
37  /*! \brief Constructor: create the moisture model */
38  LagrangianMicrophysics (const int& /* nlev */, /*!< Number of AMR levels */
39  const MoistureType& a_model_type /*!< moisture model */ )
40  {
41  AMREX_ASSERT( Microphysics::modelType(a_model_type) == MoistureModelType::Lagrangian );
42  if (a_model_type == MoistureType::SuperDroplets) {
43  SetModel<SuperDropletsMoist>();
44  amrex::Print() << "Super-Droplets moisture model!\n";
45  } else {
46  amrex::Abort("Unknown Lagrangian moisture model!") ;
47  }
48  }
49 
50  /*! \brief Define the moisture model */
51  void Define (const int& lev, /*!< AMR level */
52  SolverChoice& sc /*!< Solver choice object */) override
53  {
54  if (lev > 0) return;
55  m_moist_model->Define(sc);
56  }
57 
58  /*! \brief Initialize the moisture model */
59  void Init (const int& lev, /*!< AMR level */
60  const amrex::MultiFab& cons_in, /*!< Conserved state variables */
61  const amrex::BoxArray& grids, /*!< Grids */
62  const amrex::Geometry& geom, /*!< Geometry */
63  const amrex::Real& dt_advance, /*!< Time step */
64  std::unique_ptr<amrex::MultiFab>& z_phys_nd,/*< Nodal z heights */
65  std::unique_ptr<amrex::MultiFab>& detJ_cc /*< CC Jacobian determinants */) override
66  {
67  if (lev > 0) return;
68  m_moist_model->Init(cons_in, grids, geom, dt_advance,
69  z_phys_nd, detJ_cc);
70  }
71 
72  /*! \brief finish initializations steps that require flow variables */
73  void FinishInit (const int& lev, /*!< AMR level */
74  amrex::MultiFab& cons_in, /*!< Conserved state variable */
75  const amrex::Vector<std::unique_ptr<amrex::MultiFab>>& z_phys_nd /*!< terrain */) override
76  {
77  if (lev > 0) return;
78  m_moist_model->FinishInit( lev, cons_in, z_phys_nd );
79  }
80 
81  /*! \brief Advance the moisture model for one time step */
82  void Advance (const int& lev, /*!< AMR level */
83  const amrex::Real& dt_advance, /*!< Time step */
84  const int& iter, /*!< iteration number */
85  const amrex::Real& time, /*!< current time */
86  const SolverChoice& /*solverChoice*/, /*!< Solver choice object */
87  amrex::Vector<amrex::Vector<amrex::MultiFab>>& a_vars, /*!< Dycore state variables */
88  const amrex::Vector<std::unique_ptr<amrex::MultiFab>>& a_z/*!< terrain */,
89  const amrex::GpuArray<ERF_BC, AMREX_SPACEDIM*2>& a_phys_bc_types ) override
90  {
91  if (lev > 0) return;
92  m_moist_model->Advance(dt_advance, iter, time, a_vars, a_z, a_phys_bc_types);
93  }
94 
95  /*! \brief update microphysics variables from ERF state variables */
96  void Update_Micro_Vars_Lev (const int& lev, /*! AMR level */
97  amrex::MultiFab& cons_in /*!< Conserved state variables */) override
98  {
99  if (lev > 0) return;
100  m_moist_model->Update_Micro_Vars(cons_in);
101  }
102 
103  /*! \brief update ERF state variables from microphysics variables */
104  void Update_State_Vars_Lev (const int& lev, /*!< AMR level */
105  amrex::MultiFab& cons_in, /*!< Conserved state variables */
106  const amrex::MultiFab& z_phys_nd /*!< Nodal terrain heights */) override
107  {
108  if (lev > 0) return;
109  m_moist_model->Update_State_Vars(cons_in, z_phys_nd);
110  }
111 
112  /*! \brief get pointer to a moisture variable */
113  amrex::MultiFab* Get_Qmoist_Ptr (const int& lev, /*!< AMR level */
114  const int& varIdx /*!< moisture variable index */) override
115  {
116  return (lev > 0 ? nullptr : m_moist_model->Qmoist_Ptr(varIdx));
117  }
118 
119  /*! \brief get the number of moisture model variables */
120  int Get_Qmoist_Size (const int& a_lev /*!< AMR level */) override
121  {
122  return (a_lev > 0 ? 0 : m_moist_model->Qmoist_Size());
123  }
124 
125  /*! \brief get the number of microphysics conserved moist (water-related) state variables */
126  int Get_Qstate_Moist_Size () override
127  {
128  return m_moist_model->Qstate_Moist_Size();
129  }
130 
131  /*! \brief get the number of microphysics conserved non-moist (non-water, i.e., other vapor/condensed species) state variables */
132  int Get_Qstate_NonMoist_Size () override
133  {
134  return m_moist_model->Qstate_NonMoist_Size();
135  }
136 
137  /*! \brief initialize particles in particle container */
138  inline void initParticles ( std::unique_ptr<amrex::MultiFab>& z_phys_nd /*!< Nodal z heights */ )
139  {
140  m_moist_model->InitParticles(z_phys_nd);
141  }
142 
143  /*! \brief restart particles in particle container */
144  inline void restartParticles ( amrex::ParGDBBase* a_gdb, const std::string& a_fname)
145  {
146  m_moist_model->RestartParticles(a_gdb, a_fname);
147  }
148 
149  /*! \brief get the particle container from the moisture model */
150  inline ERFPC* getParticleContainer () const
151  {
152  return m_moist_model->getParticleContainer();
153  }
154 
155  /*! \brief get the name of the moisture model's particle container */
156  inline const std::string& getName () const
157  {
158  return m_moist_model->getName();
159  }
160 
161  /*! \brief get the indices and names of moisture model variables for restart
162  at a given level */
163  void Get_Qmoist_Restart_Vars ( const int a_lev, /*!< level */
164  const SolverChoice& a_sc, /*!< Solver choice object */
165  std::vector<int>& a_idx, /*!< indices */
166  std::vector<std::string>& a_names /*!< names */ ) const override
167  {
168  if (a_lev == 0) {
169  m_moist_model->Qmoist_Restart_Vars( a_sc, a_idx, a_names );
170  } else {
171  a_idx.clear();
172  a_names.clear();
173  }
174  }
175 
176  /*! \brief Returns a list of additional plot variable names */
177  virtual void GetPlotVarNames (amrex::Vector<std::string>& a_vec) const override
178  {
179  m_moist_model->GetPlotVarNames(a_vec);
180  }
181 
182  /*! \brief Fills in a MultiFab for plotting */
183  virtual void GetPlotVar (const std::string& a_name,
184  amrex::MultiFab& a_mf,
185  const int a_lev) const override
186  {
187  if (a_lev > 0) {
188  a_mf.setVal(0.0);
189  return;
190  }
191  m_moist_model->GetPlotVar(a_name, a_mf);
192  }
193 
194  /*! \brief Populates dz_min in micro model for precipitation */
195  virtual void Set_dzmin (const int /*a_lev*/,
196  const amrex::Real dz_min) const override
197  {
198  m_moist_model->Set_dzmin(dz_min);
199  }
200 
201  /*! \brief Populates real_width in micro model for box limiting */
202  virtual void Set_RealWidth (const int /*a_lev*/,
203  const int real_width) const override
204  {
205  m_moist_model->Set_RealWidth(real_width);
206  }
207 
208 protected:
209 
210  /*! \brief Create and set the specified moisture model */
211  template<class NewMoistModel>
212  void SetModel ()
213  {
214  m_moist_model = std::make_unique<NewMoistModel>();
215  }
216 
217  std::unique_ptr<NullMoistLagrangian> m_moist_model; /*!< moisture model */
218 };
219 
220 #endif
221 #endif
Contains the base class for microphysics.
Contains the Lagrangian moisture model base class.
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Base class for microphysics interface.
Definition: ERF_Microphysics.H:14
virtual int Get_Qmoist_Size(const int &)=0
get the number of moisture model variables
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 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 Update_Micro_Vars_Lev(const int &, amrex::MultiFab &)=0
update microphysics variables from ERF state variables
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
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:99
virtual void FinishInit(const int &, amrex::MultiFab &, const amrex::Vector< std::unique_ptr< amrex::MultiFab >> &)=0
finish initializations steps that require flow variables
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
virtual void Set_RealWidth(const int lev, const int real_width) const =0
Define the nudging+set width for real BCs.
Definition: ERF_DataStruct.H:130