ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_MM5.H
Go to the documentation of this file.
1 #ifndef ERF_MM5_H
2 #define ERF_MM5_H
3 
4 #include <string>
5 #include <vector>
6 #include <memory>
7 
8 #include <AMReX_FArrayBox.H>
9 #include <AMReX_Geometry.H>
10 #include <AMReX_MultiFabUtil.H>
11 
12 #include <ERF_NullSurf.H>
13 #include <ERF_Constants.H>
14 #include <ERF_IndexDefines.H>
15 #include <ERF_DataStruct.H>
16 
17 namespace LsmVar_MM5 {
18  enum {
19  // independent variables
20  theta = 0,
21  NumVars
22  };
23 }
24 
25 /* See Chen & Dudhia (2001) https://doi.org/10.1175/1520-0493(2001)129<0569:CAALSH>2.0.CO;2 */
26 class MM5 : public NullSurf {
27 
28  using FabPtr = std::shared_ptr<amrex::MultiFab>;
29 
30 public:
31  // Constructor
32  MM5 () {}
33 
34  // Destructor
35  virtual ~MM5 () = default;
36 
37  // Set thermo and grid properties
38  void
39  Define (SolverChoice& /*sc*/) override
40  {
41  // NOTE: We should parse things from sc here,
42  // but they are hard coded because this
43  // is a demonstration for now.
44  }
45 
46  // Initialize data structures
47  void
48  Init (const amrex::MultiFab& cons_in,
49  const amrex::Geometry& geom,
50  const amrex::Real& dt) override;
51 
52  // Wrapper to do all the updating
53  void
54  Advance (const amrex::Real& dt) override
55  {
56  m_dt = dt;
57  this->ComputeFluxes();
58  this->AdvanceMM5();
59  this->ComputeTsurf();
60  }
61 
62  // Compute surface temperature
63  void
64  ComputeTsurf ();
65 
66  // Compute diffusive fluxes
67  void
68  ComputeFluxes ();
69 
70  // Advance the lsm state vars
71  void
72  AdvanceMM5 ();
73 
74  // Get state vars from lsm class
75  amrex::MultiFab*
76  Lsm_Data_Ptr (const int& varIdx) override
77  {
78  int lsmIdx = LsmVarMap[varIdx];
79  AMREX_ALWAYS_ASSERT(lsmIdx < MM5::m_lsm_size && lsmIdx>=0);
80  return lsm_fab_vars[lsmIdx].get();
81  }
82 
83  // Get flux vars from lsm class
84  amrex::MultiFab*
85  Lsm_Flux_Ptr (const int& varIdx) override
86  {
87  int lsmIdx = LsmVarMap[varIdx];
88  AMREX_ALWAYS_ASSERT(lsmIdx < MM5::m_lsm_size && lsmIdx>=0);
89  return lsm_fab_flux[lsmIdx].get();
90  }
91 
92  // Get lsm geometry
93  amrex::Geometry
94  Lsm_Geom ( ) override { return m_lsm_geom; }
95 
96  // Get number of vars lsm class contains
97  int
98  Lsm_Data_Size () override { return MM5::m_lsm_size; }
99 
100  // Get variable names
101  std::string
102  Lsm_VarName (const int& varIdx) override
103  {
104  int lsmIdx = LsmVarMap[varIdx];
105  AMREX_ALWAYS_ASSERT(lsmIdx < MM5::m_lsm_size && lsmIdx>=0);
106  return LsmVarName[lsmIdx];
107  }
108 
109 private:
110  // number of lsm variables (theta)
111  int m_lsm_size = 1;
112 
113  // LsmVar map (state indices -> LsmVar enum)
114  amrex::Vector<int> LsmVarMap;
115 
116  // Lsm varnames
117  amrex::Vector<std::string> LsmVarName;
118 
119  // geometry for atmosphere
120  amrex::Geometry m_geom;
121 
122  // geometry for lsm
123  amrex::Geometry m_lsm_geom;
124 
125  // timestep
126  amrex::Real m_dt;
127 
128  // domain klo-1 or lsm khi
129  int khi_lsm;
130 
131  // constants
132  // amrex::Real m_fac_cond;
133  // amrex::Real m_fac_fus;
134  // amrex::Real m_fac_sub;
135  // amrex::Real m_gOcp;
136 
137  // independent variables
138  amrex::Array<FabPtr, LsmVar_MM5::NumVars> lsm_fab_vars;
139 
140  // flux array for conjugate transfer
141  amrex::Array<FabPtr, LsmVar_MM5::NumVars> lsm_fab_flux;
142 
143  // Vars that should be parsed
144  // ==========================
145  // Number of grid points in z
146  int m_nz_lsm = 30;
147 
148  // Size of grid spacing in z
149  amrex::Real m_dz_lsm = 0.1; // 3 [m] below surface
150 
151  // Specific heat
152  amrex::Real m_cp_soil = 1.26e6; // [J/m^3 K]
153 
154  // Conductivity
155  amrex::Real m_k_soil = 0.2; // dry soil [W/m K]
156 
157  // Theta Dirichlet value at lowest point below surface
158  amrex::Real m_theta_dir = 300.0; // [K]
159 
160  // Thermal diffusivity
161  amrex::Real m_d_soil = m_k_soil / m_cp_soil; // [m^2/s]
162 };
163 #endif
Definition: ERF_MM5.H:26
void Init(const amrex::MultiFab &cons_in, const amrex::Geometry &geom, const amrex::Real &dt) override
Definition: ERF_MM5.cpp:7
amrex::Real m_cp_soil
Definition: ERF_MM5.H:152
void ComputeFluxes()
Definition: ERF_MM5.cpp:82
std::shared_ptr< amrex::MultiFab > FabPtr
Definition: ERF_MM5.H:28
MM5()
Definition: ERF_MM5.H:32
amrex::Array< FabPtr, LsmVar_MM5::NumVars > lsm_fab_vars
Definition: ERF_MM5.H:138
amrex::Real m_d_soil
Definition: ERF_MM5.H:161
void Advance(const amrex::Real &dt) override
Definition: ERF_MM5.H:54
int m_lsm_size
Definition: ERF_MM5.H:111
amrex::Real m_dt
Definition: ERF_MM5.H:126
amrex::Vector< int > LsmVarMap
Definition: ERF_MM5.H:114
void AdvanceMM5()
Definition: ERF_MM5.cpp:107
amrex::MultiFab * Lsm_Data_Ptr(const int &varIdx) override
Definition: ERF_MM5.H:76
amrex::Geometry m_lsm_geom
Definition: ERF_MM5.H:123
int khi_lsm
Definition: ERF_MM5.H:129
amrex::Array< FabPtr, LsmVar_MM5::NumVars > lsm_fab_flux
Definition: ERF_MM5.H:141
amrex::Real m_dz_lsm
Definition: ERF_MM5.H:149
amrex::MultiFab * Lsm_Flux_Ptr(const int &varIdx) override
Definition: ERF_MM5.H:85
amrex::Geometry m_geom
Definition: ERF_MM5.H:120
int m_nz_lsm
Definition: ERF_MM5.H:146
void ComputeTsurf()
Definition: ERF_MM5.cpp:63
virtual ~MM5()=default
amrex::Real m_theta_dir
Definition: ERF_MM5.H:158
amrex::Vector< std::string > LsmVarName
Definition: ERF_MM5.H:117
amrex::Geometry Lsm_Geom() override
Definition: ERF_MM5.H:94
int Lsm_Data_Size() override
Definition: ERF_MM5.H:98
amrex::Real m_k_soil
Definition: ERF_MM5.H:155
void Define(SolverChoice &) override
Definition: ERF_MM5.H:39
std::string Lsm_VarName(const int &varIdx) override
Definition: ERF_MM5.H:102
Definition: ERF_NullSurf.H:8
Definition: ERF_MM5.H:17
@ NumVars
Definition: ERF_MM5.H:21
@ theta
Definition: ERF_MM5.H:20
Definition: ERF_DataStruct.H:82