ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_BaseStateParams.H
Go to the documentation of this file.
1 /**
2  * \file ERF_BaseStateParams.H
3  */
4 #ifndef ERF_BASE_STATE_PARAMS_H_
5 #define ERF_BASE_STATE_PARAMS_H_
6 
7 #include <cmath>
8 
9 #include <AMReX_REAL.H>
10 #include <AMReX_Print.H>
11 
12 #include <ERF_Constants.H>
13 
14 /**
15  * Parameters defining the WRF reference (base) state, along with the layer
16  * interface heights derived from them.
17  *
18  * The base state is piecewise in log-pressure:
19  * (1) troposphere T = T00 + TLP * ln(p/P00) p > P_iso
20  * (2) isothermal layer T = TISO P_STRAT < p <= P_iso
21  * (3) stratosphere T = TISO + TLP_STRAT * ln(p/P_STRAT) p <= P_STRAT
22  * Each piece inverts to p(z) in closed form under dp/dz = -rho g, so the two
23  * interface heights are precomputed once and the inversion branches on z.
24  *
25  * Because the resulting profile is a pure function of height, it can be
26  * evaluated on any subset of a column -- it does not require a box that spans
27  * the domain in the vertical.
28  *
29  * NOTE: The defaults are the WRF namelist defaults for base_temp, base_pres,
30  * base_lapse, iso_temp, base_lapse_strat and base_pres_strat. metgrid
31  * files do not carry these parameters at all; wrfinput files usually do,
32  * and are read by read_base_state_params_from_wrfinput.
33  */
35 {
42 
43  // Derived by set_layer_interfaces()
47  bool use_strat = false;
48 
49  // Whether set_layer_interfaces() has been called, so that consumers can
50  // catch an un-initialized profile rather than silently using z_iso = 0.
51  bool is_set = false;
52 
53  //
54  // Compute the layer interfaces and report them.
55  //
56  // NOTE: This must be called from outside of any MFIter (and outside of any
57  // OpenMP parallel region) so the diagnostics are emitted exactly once
58  // rather than once per box per thread.
59  //
61  {
62  // The troposphere inverts p(z) as sqrt((T00/TLP)^2 - 2*g*z/(TLP*R_d)), which
63  // folds 1/TLP inside the square root and so discards the sign of TLP. A
64  // non-positive lapse parameter, or an isothermal temperature at or above the
65  // surface temperature, would silently select the wrong root instead of failing.
67  "Base state TLP must be positive");
69  "Base state TISO must be less than T00");
70 
71  const amrex::Real x_iso = (TISO - T00) / TLP;
72  P_iso = P00 * std::exp(x_iso);
73  z_iso = -(R_d/CONST_GRAV) * (T00*x_iso + myhalf*TLP*x_iso*x_iso);
74 
75  // The upper stratospheric layer is optional (P_STRAT == 0 or TLP_STRAT == 0
76  // disables it) and is only meaningful if it begins above the isothermal layer,
77  // i.e. if P_STRAT is below the pressure at which the isothermal layer starts.
78  const bool want_strat = ((P_STRAT > zero) && (TLP_STRAT != zero));
79  use_strat = (want_strat && (P_STRAT < P_iso));
81  : z_iso;
82 
83  // A configured stratospheric layer that lies at or below the isothermal
84  // transition cannot be represented, so say so rather than dropping it quietly.
85  if (want_strat && !use_strat) {
86  amrex::Print() << "WARNING: the base stratospheric layer is being ignored: P_STRAT = "
87  << P_STRAT << " Pa is not below the pressure at the base of the "
88  << "isothermal layer, P_iso = " << P_iso << " Pa.\n";
89  amrex::Print() << " TLP_STRAT = " << TLP_STRAT << " will have no effect and "
90  << "the atmosphere above z_iso will be isothermal at TISO = "
91  << TISO << " K.\n";
92  }
93 
94  amrex::Print() << "Base state layer interfaces: z_iso = " << z_iso << " m";
95  if (use_strat) amrex::Print() << ", z_strat = " << z_strat << " m";
96  amrex::Print() << "\n";
97 
98  is_set = true;
99  }
100 
101  //
102  // True if this holds the same six defining parameters as bsp. Used to warn when
103  // a nested wrfinput file disagrees with its parent: the levels of an AMR hierarchy
104  // must share one reference profile, or their base states cannot be consistent
105  // across the coarse/fine interface.
106  //
107  bool same_params_as (const BaseStateParams& bsp) const
108  {
109  return (T00 == bsp.T00 ) && (P00 == bsp.P00 ) &&
110  (TLP == bsp.TLP ) && (TISO == bsp.TISO) &&
111  (TLP_STRAT == bsp.TLP_STRAT) && (P_STRAT == bsp.P_STRAT);
112  }
113 };
114 
115 #endif
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
constexpr amrex::Real p_0
Definition: ERF_Constants.H:61
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:64
constexpr amrex::Real R_d
Definition: ERF_Constants.H:47
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_cloud_chamber_config.active, "Cloud Chamber: initializer reached without a parsed configuration")
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Definition: ERF_BaseStateParams.H:35
bool is_set
Definition: ERF_BaseStateParams.H:51
void set_layer_interfaces()
Definition: ERF_BaseStateParams.H:60
amrex::Real T00
Definition: ERF_BaseStateParams.H:36
amrex::Real z_strat
Definition: ERF_BaseStateParams.H:46
amrex::Real P00
Definition: ERF_BaseStateParams.H:37
amrex::Real z_iso
Definition: ERF_BaseStateParams.H:45
amrex::Real P_iso
Definition: ERF_BaseStateParams.H:44
amrex::Real TLP
Definition: ERF_BaseStateParams.H:38
amrex::Real P_STRAT
Definition: ERF_BaseStateParams.H:41
bool use_strat
Definition: ERF_BaseStateParams.H:47
amrex::Real TLP_STRAT
Definition: ERF_BaseStateParams.H:40
bool same_params_as(const BaseStateParams &bsp) const
Definition: ERF_BaseStateParams.H:107
amrex::Real TISO
Definition: ERF_BaseStateParams.H:39