ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_Kessler.H
Go to the documentation of this file.
1 /*
2  * Implementation 1-moment microphysics model
3  * NOTE: this model is based on the Kessler code, and the Klemp's paper
4  * 1): Joseph, Klemp, the simulation of three-dimensional convective storm dynamics,
5  * Journal of the atmospheric sciences, vol35, p1070
6  * 2): Marat Khairoutdinov and David Randall, cloud resolving modeling of the ARM summer 1997 IOP:
7  * model formulation, results, unvertainties, and sensitivities, Journal of the atmospheric sciences, vol60, p607
8  */
9 #ifndef ERF_Kessler_H
10 #define ERF_Kessler_H
11 
12 #include <string>
13 #include <vector>
14 #include <memory>
15 
16 #include <AMReX_FArrayBox.H>
17 #include <AMReX_Geometry.H>
18 #include <AMReX_TableData.H>
19 #include <AMReX_MultiFabUtil.H>
20 
21 #include "ERF_Constants.H"
22 #include "ERF_Microphysics_Utils.H"
23 #include "ERF_IndexDefines.H"
24 #include "ERF_DataStruct.H"
25 #include "ERF_NullMoist.H"
26 
27 namespace MicVar_Kess {
28  enum {
29  // independent variables
30  rho=0, // density
31  theta, // liquid/ice water potential temperature
32  tabs, // temperature
33  pres, // pressure
34  // non-precipitating vars
35  qt, // total cloud
36  qv, // cloud vapor
37  qcl, // cloud water
38  // precipitating vars
39  qp, // total precip
40  // derived vars
42  NumVars
43  };
44 }
45 
46 class Kessler : public NullMoist {
47 
48  using FabPtr = std::shared_ptr<amrex::MultiFab>;
49 
50 public:
51  // constructor
52  Kessler () {}
53 
54  // destructor
55  virtual ~Kessler () = default;
56 
57  // cloud physics
58  void AdvanceKessler (const SolverChoice &solverChoice);
59 
60  // Set up for first time
61  void
62  Define (SolverChoice& sc) override
63  {
64  docloud = sc.do_cloud;
65  doprecip = sc.do_precip;
66  m_fac_cond = lcond / sc.c_p;
67  m_fac_fus = lfus / sc.c_p;
68  m_fac_sub = lsub / sc.c_p;
69  m_gOcp = CONST_GRAV / sc.c_p;
70  m_axis = sc.ave_plane;
71  }
72 
73  // init
74  void
75  Init (const amrex::MultiFab& cons_in,
76  const amrex::BoxArray& grids,
77  const amrex::Geometry& geom,
78  const amrex::Real& dt_advance,
79  std::unique_ptr<amrex::MultiFab>& z_phys_nd,
80  std::unique_ptr<amrex::MultiFab>& detJ_cc) override;
81 
82  // Copy state into micro vars
83  void
84  Copy_State_to_Micro (const amrex::MultiFab& cons_in) override;
85 
86  // Copy state into micro vars
87  void
88  Copy_Micro_to_State (amrex::MultiFab& cons_in) override;
89 
90  // update micro vars
91  void
92  Update_Micro_Vars (amrex::MultiFab& cons_in) override
93  {
94  this->Copy_State_to_Micro(cons_in);
95  }
96 
97  // update state vars
98  void
99  Update_State_Vars (amrex::MultiFab& cons_in) override
100  {
101  this->Copy_Micro_to_State(cons_in);
102  }
103 
104  // wrapper to advance micro vars
105  void
106  Advance (const amrex::Real& dt_advance,
107  const SolverChoice& solverChoice) override
108  {
109  dt = dt_advance;
110 
111  this->AdvanceKessler(solverChoice);
112  }
113 
114  amrex::MultiFab*
115  Qmoist_Ptr (const int& varIdx) override
116  {
117  AMREX_ALWAYS_ASSERT(varIdx < m_qmoist_size);
118  return mic_fab_vars[MicVarMap[varIdx]].get();
119  }
120 
121  int
122  Qmoist_Size () override { return Kessler::m_qmoist_size; }
123 
124  int
125  Qstate_Size () override { return Kessler::m_qstate_size; }
126 
127  void
129  std::vector<int>& a_idx,
130  std::vector<std::string>& a_names) const override
131  {
132  a_idx.clear();
133  a_names.clear();
134  if (a_sc.moisture_type == MoistureType::Kessler) {
135  a_idx.push_back(4); a_names.push_back("RainAccum");
136  }
137  }
138 
139 private:
140  // Number of qmoist variables (qt, qv, qcl, qp)
141  int m_qmoist_size = 5;
142 
143  // Number of qstate variables
144  int m_qstate_size = 3;
145 
146  // MicVar map (Qmoist indices -> MicVar enum)
147  amrex::Vector<int> MicVarMap;
148 
149  // geometry
150  amrex::Geometry m_geom;
151 
152  // valid boxes on which to evolve the solution
153  amrex::BoxArray m_gtoe;
154 
155  // timestep
156  amrex::Real dt;
157 
158  // number of vertical levels
159  int nlev, zlo, zhi;
160 
161  // plane average axis
162  int m_axis;
163 
164  // model options
166 
167  // constants
168  amrex::Real m_fac_cond;
169  amrex::Real m_fac_fus;
170  amrex::Real m_fac_sub;
171  amrex::Real m_gOcp;
172 
173  // Pointer to terrain data
174  amrex::MultiFab* m_z_phys_nd;
175  amrex::MultiFab* m_detJ_cc;
176 
177  // independent variables
178  amrex::Array<FabPtr, MicVar_Kess::NumVars> mic_fab_vars;
179 };
180 #endif
constexpr amrex::Real lfus
Definition: ERF_Constants.H:67
constexpr amrex::Real lsub
Definition: ERF_Constants.H:68
constexpr amrex::Real lcond
Definition: ERF_Constants.H:66
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:21
Definition: ERF_Kessler.H:46
int zlo
Definition: ERF_Kessler.H:159
void Update_Micro_Vars(amrex::MultiFab &cons_in) override
Definition: ERF_Kessler.H:92
amrex::MultiFab * Qmoist_Ptr(const int &varIdx) override
Definition: ERF_Kessler.H:115
amrex::Vector< int > MicVarMap
Definition: ERF_Kessler.H:147
void Copy_State_to_Micro(const amrex::MultiFab &cons_in) override
Definition: ERF_Init_Kessler.cpp:64
int Qstate_Size() override
Definition: ERF_Kessler.H:125
bool doprecip
Definition: ERF_Kessler.H:165
amrex::Real m_fac_sub
Definition: ERF_Kessler.H:170
int Qmoist_Size() override
Definition: ERF_Kessler.H:122
virtual ~Kessler()=default
amrex::Geometry m_geom
Definition: ERF_Kessler.H:150
Kessler()
Definition: ERF_Kessler.H:52
amrex::MultiFab * m_detJ_cc
Definition: ERF_Kessler.H:175
void Define(SolverChoice &sc) override
Definition: ERF_Kessler.H:62
bool docloud
Definition: ERF_Kessler.H:165
amrex::Real m_fac_cond
Definition: ERF_Kessler.H:168
void Copy_Micro_to_State(amrex::MultiFab &cons_in) override
Definition: ERF_Update_Kessler.cpp:14
amrex::Real dt
Definition: ERF_Kessler.H:156
int zhi
Definition: ERF_Kessler.H:159
int nlev
Definition: ERF_Kessler.H:159
amrex::Array< FabPtr, MicVar_Kess::NumVars > mic_fab_vars
Definition: ERF_Kessler.H:178
amrex::Real m_gOcp
Definition: ERF_Kessler.H:171
amrex::MultiFab * m_z_phys_nd
Definition: ERF_Kessler.H:174
void Init(const amrex::MultiFab &cons_in, const amrex::BoxArray &grids, const amrex::Geometry &geom, const amrex::Real &dt_advance, std::unique_ptr< amrex::MultiFab > &z_phys_nd, std::unique_ptr< amrex::MultiFab > &detJ_cc) override
Definition: ERF_Init_Kessler.cpp:22
void AdvanceKessler(const SolverChoice &solverChoice)
Definition: ERF_Kessler.cpp:11
amrex::Real m_fac_fus
Definition: ERF_Kessler.H:169
int m_qstate_size
Definition: ERF_Kessler.H:144
std::shared_ptr< amrex::MultiFab > FabPtr
Definition: ERF_Kessler.H:48
void Advance(const amrex::Real &dt_advance, const SolverChoice &solverChoice) override
Definition: ERF_Kessler.H:106
void Update_State_Vars(amrex::MultiFab &cons_in) override
Definition: ERF_Kessler.H:99
amrex::BoxArray m_gtoe
Definition: ERF_Kessler.H:153
int m_qmoist_size
Definition: ERF_Kessler.H:141
void Qmoist_Restart_Vars(const SolverChoice &a_sc, std::vector< int > &a_idx, std::vector< std::string > &a_names) const override
Definition: ERF_Kessler.H:128
int m_axis
Definition: ERF_Kessler.H:162
Definition: ERF_NullMoist.H:8
Definition: ERF_Kessler.H:27
@ qp
Definition: ERF_Kessler.H:39
@ qcl
Definition: ERF_Kessler.H:37
@ tabs
Definition: ERF_Kessler.H:32
@ pres
Definition: ERF_Kessler.H:33
@ rho
Definition: ERF_Kessler.H:30
@ theta
Definition: ERF_Kessler.H:31
@ qt
Definition: ERF_Kessler.H:35
@ rain_accum
Definition: ERF_Kessler.H:41
@ NumVars
Definition: ERF_Kessler.H:42
@ qv
Definition: ERF_Kessler.H:36
Definition: ERF_DataStruct.H:78
amrex::Real c_p
Definition: ERF_DataStruct.H:580
bool do_precip
Definition: ERF_DataStruct.H:641
MoistureType moisture_type
Definition: ERF_DataStruct.H:627
bool do_cloud
Definition: ERF_DataStruct.H:640
int ave_plane
Definition: ERF_DataStruct.H:638