ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_MYNNStruct.H
Go to the documentation of this file.
1 #ifndef ERF_MYNN_STRUCT_H_
2 #define ERF_MYNN_STRUCT_H_
3 
4 enum struct MYNNConfigType {
5  NN09 = 0, // Nakanishi & Niino 2009, J Met Soc Japan
6  CHEN2021 // Chen & Bryan 2021, JAS
7 };
8 
9 struct MYNNLevel25 {
10 
11  /*
12  * Calculate the stability functions that determine the eddy diffusivities
13  * of momentum, heat, KE, and (optionally) moisture.
14  */
15  AMREX_GPU_DEVICE
16  AMREX_FORCE_INLINE
17  void calc_stability_funcs(amrex::Real& SM,
18  amrex::Real& SH,
19  amrex::Real& SQ,
20  const amrex::Real GM,
21  const amrex::Real GH,
22  const amrex::Real alphac = 1.0) const
23  {
24  amrex::Real alphac2 = alphac * alphac;
25 
26  // Compute non-dimensional parameters (notation follows NN09)
27  amrex::Real Phi1 = 1.0 - alphac2*3.0*A2*B2*(1-C3)*GH;
28  amrex::Real Phi2 = 1.0 - alphac2*9.0*A1*A2*(1-C2)*GH;
29  amrex::Real Phi3 = Phi1 + alphac2*9.0*A2*A2*(1-C2)*(1-C5)*GH;
30  amrex::Real Phi4 = Phi1 - alphac2*12.0*A1*A2*(1-C2)*GH;
31  amrex::Real Phi5 = 6.0*alphac*A1*A1*GM;
32 
33  // Compute stability functions
34  amrex::Real D = Phi2*Phi4 + Phi5*Phi3;
35  SM = alphac * A1 * (Phi3 - 3*C1*Phi4) / D;
36  SH = alphac * A2 * (Phi2 + 3*C1*Phi5) / D;
37  SQ = 3.0 * SM; // revised in NN09
38  }
39 
40  // Closure coefficients (from Nakanishi & Niino 2009 [NN09])
41  amrex::Real A1 = 1.18;
42  amrex::Real A2 = 0.665;
43  amrex::Real B1 = 24.0;
44  amrex::Real B2 = 15.0;
45  amrex::Real C1 = 0.137;
46  amrex::Real C2 = 0.75;
47  amrex::Real C3 = 0.352;
48  amrex::Real C4 = 0.0;
49  amrex::Real C5 = 0.2;
50 
51  // Clipping (defaults from WRF v4.5.0 onward)
52  amrex::Real SMmin = 0.0;
53  amrex::Real SMmax = 1.0e34;
54  amrex::Real SHmin = 0.0;
55  amrex::Real SHmax = 4.0;
56 
58 
59  // Calculate eddy diffusivity for moisture variables
60  bool diffuse_moistvars = false;
61 };
62 
63 struct MYNNLevel2 {
64  void init_coeffs (amrex::Real A1_lvl25,
65  amrex::Real A2_lvl25,
66  amrex::Real B1,
67  amrex::Real B2,
68  amrex::Real C1,
69  amrex::Real C2,
70  amrex::Real C3,
71  amrex::Real /*C4*/,
72  amrex::Real C5)
73  {
74  A1 = A1_lvl25;
75  A2 = A2_lvl25;
76  gam2 = (2.0*A1*(3.0-2.0*C2) + B2*(1.0-C3)) / B1;
77  F1 = B1*(gam1-C1) + 2.0*A1*(3.0-2.0*C2) + 3.0*A2*(1.0-C2)*(1.0-C5);
78  F2 = B1*(gam1+gam2) - 3.0*A1*(1.0-C2);
79  Rf1 = B1*(gam1-C1) / F1;
80  Rf2 = B1*gam1 / F2;
81  Rfc = gam1 / (gam1 + gam2);
82  Ri1 = 0.5*A2*F2/(A1*F1);
83  Ri2 = 0.5*Rf1/Ri1;
84  Ri3 = (2.0*Rf2-Rf1)/Ri1;
85 
86  initialized = true;
87  }
88 
89  AMREX_GPU_DEVICE
90  AMREX_FORCE_INLINE
91  amrex::Real calc_Rf (const amrex::Real GM, const amrex::Real GH) const
92  {
93  AMREX_ASSERT(initialized);
94  amrex::Real Ri = -GH/(GM + eps);
95  return Ri1*(Ri + Ri2 - std::sqrt(Ri*Ri - Ri3*Ri + Ri2*Ri2));
96  }
97 
98  AMREX_GPU_DEVICE
99  AMREX_FORCE_INLINE
100  amrex::Real calc_SH (const amrex::Real Rf) const
101  {
102  AMREX_ASSERT(initialized);
103  return 3.0*A2*(gam1+gam2)*(Rfc-Rf)/(1.0-Rf);
104  }
105 
106  AMREX_GPU_DEVICE
107  AMREX_FORCE_INLINE
108  amrex::Real calc_SM(const amrex::Real Rf) const
109  {
110  AMREX_ASSERT(initialized);
111  return A1*F1/(A2*F2) * (Rf1-Rf) / (Rf2-Rf) * calc_SH(Rf);
112  }
113 
114  bool initialized{false};
115 
116  amrex::Real A1, A2; // from Level 2.5
117  amrex::Real F1, F2;
118  const amrex::Real gam1 = 0.235;
119  amrex::Real gam2;
120  amrex::Real Rf1, Rf2, Rfc;
121  amrex::Real Ri1, Ri2, Ri3;
122 
123  const amrex::Real eps = std::numeric_limits<amrex::Real>::epsilon();
124 };
125 #endif
MYNNConfigType
Definition: ERF_MYNNStruct.H:4
Definition: ERF_MYNNStruct.H:9
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void calc_stability_funcs(amrex::Real &SM, amrex::Real &SH, amrex::Real &SQ, const amrex::Real GM, const amrex::Real GH, const amrex::Real alphac=1.0) const
Definition: ERF_MYNNStruct.H:17
amrex::Real SMmax
Definition: ERF_MYNNStruct.H:53
amrex::Real SHmax
Definition: ERF_MYNNStruct.H:55
amrex::Real C4
Definition: ERF_MYNNStruct.H:48
amrex::Real C1
Definition: ERF_MYNNStruct.H:45
MYNNConfigType config
Definition: ERF_MYNNStruct.H:57
amrex::Real C3
Definition: ERF_MYNNStruct.H:47
amrex::Real C2
Definition: ERF_MYNNStruct.H:46
amrex::Real A2
Definition: ERF_MYNNStruct.H:42
amrex::Real SHmin
Definition: ERF_MYNNStruct.H:54
amrex::Real B1
Definition: ERF_MYNNStruct.H:43
amrex::Real B2
Definition: ERF_MYNNStruct.H:44
amrex::Real C5
Definition: ERF_MYNNStruct.H:49
amrex::Real SMmin
Definition: ERF_MYNNStruct.H:52
amrex::Real A1
Definition: ERF_MYNNStruct.H:41
bool diffuse_moistvars
Definition: ERF_MYNNStruct.H:60
Definition: ERF_MYNNStruct.H:63
amrex::Real A2
Definition: ERF_MYNNStruct.H:116
amrex::Real F2
Definition: ERF_MYNNStruct.H:117
amrex::Real Rf1
Definition: ERF_MYNNStruct.H:120
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real calc_Rf(const amrex::Real GM, const amrex::Real GH) const
Definition: ERF_MYNNStruct.H:91
amrex::Real Rf2
Definition: ERF_MYNNStruct.H:120
const amrex::Real eps
Definition: ERF_MYNNStruct.H:123
amrex::Real Ri3
Definition: ERF_MYNNStruct.H:121
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real calc_SM(const amrex::Real Rf) const
Definition: ERF_MYNNStruct.H:108
const amrex::Real gam1
Definition: ERF_MYNNStruct.H:118
amrex::Real Ri2
Definition: ERF_MYNNStruct.H:121
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real calc_SH(const amrex::Real Rf) const
Definition: ERF_MYNNStruct.H:100
amrex::Real F1
Definition: ERF_MYNNStruct.H:117
amrex::Real Ri1
Definition: ERF_MYNNStruct.H:121
void init_coeffs(amrex::Real A1_lvl25, amrex::Real A2_lvl25, amrex::Real B1, amrex::Real B2, amrex::Real C1, amrex::Real C2, amrex::Real C3, amrex::Real, amrex::Real C5)
Definition: ERF_MYNNStruct.H:64
amrex::Real A1
Definition: ERF_MYNNStruct.H:116
bool initialized
Definition: ERF_MYNNStruct.H:114
amrex::Real Rfc
Definition: ERF_MYNNStruct.H:120
amrex::Real gam2
Definition: ERF_MYNNStruct.H:119