ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SLM.H
Go to the documentation of this file.
1 #ifndef ERF_SLM_H
2 #define ERF_SLM_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_SLM {
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 SLM : public NullSurf {
27 
28  using FabPtr = std::shared_ptr<amrex::MultiFab>;
29 
30 public:
31  // Constructor
32  SLM () {}
33 
34  // Destructor
35  virtual ~SLM () = 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->AdvanceSLM();
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  AdvanceSLM ();
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 < SLM::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 < SLM::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 SLM::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 < SLM::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_SLM::NumVars> lsm_fab_vars;
139 
140  // flux array for conjugate transfer
141  amrex::Array<FabPtr, LsmVar_SLM::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 = 400.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_NullSurf.H:8
Definition: ERF_SLM.H:26
void ComputeTsurf()
Definition: ERF_SLM.cpp:63
amrex::MultiFab * Lsm_Flux_Ptr(const int &varIdx) override
Definition: ERF_SLM.H:85
SLM()
Definition: ERF_SLM.H:32
int khi_lsm
Definition: ERF_SLM.H:129
virtual ~SLM()=default
void Advance(const amrex::Real &dt) override
Definition: ERF_SLM.H:54
amrex::Array< FabPtr, LsmVar_SLM::NumVars > lsm_fab_flux
Definition: ERF_SLM.H:141
amrex::Real m_cp_soil
Definition: ERF_SLM.H:152
std::string Lsm_VarName(const int &varIdx) override
Definition: ERF_SLM.H:102
amrex::Vector< std::string > LsmVarName
Definition: ERF_SLM.H:117
amrex::Real m_dt
Definition: ERF_SLM.H:126
int m_lsm_size
Definition: ERF_SLM.H:111
amrex::Real m_d_soil
Definition: ERF_SLM.H:161
amrex::Real m_dz_lsm
Definition: ERF_SLM.H:149
amrex::Array< FabPtr, LsmVar_SLM::NumVars > lsm_fab_vars
Definition: ERF_SLM.H:138
amrex::Geometry m_geom
Definition: ERF_SLM.H:120
amrex::Geometry Lsm_Geom() override
Definition: ERF_SLM.H:94
amrex::MultiFab * Lsm_Data_Ptr(const int &varIdx) override
Definition: ERF_SLM.H:76
amrex::Real m_k_soil
Definition: ERF_SLM.H:155
void Define(SolverChoice &) override
Definition: ERF_SLM.H:39
void ComputeFluxes()
Definition: ERF_SLM.cpp:82
std::shared_ptr< amrex::MultiFab > FabPtr
Definition: ERF_SLM.H:28
void AdvanceSLM()
Definition: ERF_SLM.cpp:107
amrex::Geometry m_lsm_geom
Definition: ERF_SLM.H:123
int m_nz_lsm
Definition: ERF_SLM.H:146
int Lsm_Data_Size() override
Definition: ERF_SLM.H:98
amrex::Vector< int > LsmVarMap
Definition: ERF_SLM.H:114
amrex::Real m_theta_dir
Definition: ERF_SLM.H:158
void Init(const amrex::MultiFab &cons_in, const amrex::Geometry &geom, const amrex::Real &dt) override
Definition: ERF_SLM.cpp:7
Definition: ERF_SLM.H:17
@ NumVars
Definition: ERF_SLM.H:21
@ theta
Definition: ERF_SLM.H:20
Definition: ERF_DataStruct.H:82