ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InitCustomPert_TurbulentInflow.H
Go to the documentation of this file.
1 
2  ParmParse pp("prob");
3 
4  Real rho_0 = one; pp.query("rho_0", rho_0);
5  Real T_0 = amrex::Real(300.0); pp.query("T_0", T_0);
6 
7  Real A_0 = one; pp.query("A_0", A_0);
8  Real KE_0 = amrex::Real(0.1); pp.query("KE_0", KE_0);
9 
10  Real KE_decay_height = -1; pp.query("KE_decay_height", KE_decay_height);
11  Real KE_decay_order = 1; pp.query("KE_decay_order", KE_decay_order);
12 
13  Real U_0 = zero; pp.query("U_0", U_0);
14  Real V_0 = zero; pp.query("V_0", V_0);
15  Real W_0 = zero; pp.query("W_0", W_0);
16 
17  // random initial perturbations (legacy code)
18  Real U_0_Pert_Mag = zero; pp.query("U_0_Pert_Mag", U_0_Pert_Mag);
19  Real V_0_Pert_Mag = zero; pp.query("V_0_Pert_Mag", V_0_Pert_Mag);
20  Real W_0_Pert_Mag = zero; pp.query("W_0_Pert_Mag", W_0_Pert_Mag);
21  Real T_0_Pert_Mag = zero; pp.query("T_0_Pert_Mag", T_0_Pert_Mag);
22  bool pert_rhotheta = true; pp.query("pert_rhotheta", pert_rhotheta);
23 
24  // divergence-free initial perturbations
25  Real pert_deltaU = zero; pp.query("pert_deltaU", pert_deltaU);
26  Real pert_deltaV = zero; pp.query("pert_deltaV", pert_deltaV);
27  Real pert_periods_U = amrex::Real(5.0); pp.query("pert_periods_U", pert_periods_U);
28  Real pert_periods_V = amrex::Real(5.0); pp.query("pert_periods_V", pert_periods_V);
29  Real pert_ref_height = amrex::Real(100.0); pp.query("pert_ref_height", pert_ref_height);
30 
31  const Real* prob_lo = geomdata.ProbLo();
32  const Real* prob_hi = geomdata.ProbHi();
33 
34  const bool use_eb = (sc.terrain_type == TerrainType::EB);
35  const int klo = geomdata.Domain().smallEnd(2);
36  if (KE_decay_height > 0 &&
37  state_pert.nComp() > RhoKE_comp) {
38  amrex::Print() << "Initial KE profile (order " << KE_decay_order
39  << ") will extend up to " << KE_decay_height
40  << std::endl;
41  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(klo == bx.smallEnd(2),
42  "Vertical decomposition with KE initialization is not allowed.");
43  }
44 
45  if (pert_ref_height > 0) {
46  if ((pert_deltaU != zero) || (pert_deltaV != zero)) {
47  amrex::Print() << "Adding divergence-free perturbations "
48  << pert_deltaU << " " << pert_deltaV
49  << std::endl;
50  }
51  if (U_0_Pert_Mag != zero) {
52  amrex::Print() << "Adding random x-velocity perturbations" << std::endl;
53  }
54  if (V_0_Pert_Mag != zero) {
55  amrex::Print() << "Adding random y-velocity perturbations" << std::endl;
56  }
57  if (T_0_Pert_Mag != zero) {
58  if (pert_rhotheta) {
59  amrex::Print() << "Adding random rho*theta perturbations" << std::endl;
60  } else {
61  amrex::Print() << "Adding random theta perturbations" << std::endl;
62  }
63  }
64  }
65 
66  ParallelForRNG(bx, [=,one_d=one] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept
67  {
68  const Real* dx = geomdata.CellSize();
69  const Real x = prob_lo[0] + (i + myhalf) * dx[0];
70  const Real y = prob_lo[1] + (j + myhalf) * dx[1];
71  const Real z = z_cc(i,j,k);
72 
73  // Define a point (xc,yc,zc) at the center of the domain
74  const Real xc = myhalf * (prob_lo[0] + prob_hi[0]);
75  const Real yc = myhalf * (prob_lo[1] + prob_hi[1]);
76  const Real zc = myhalf * (prob_lo[2] + prob_hi[2]);
77 
78  const Real r = std::sqrt((x-xc)*(x-xc) + (y-yc)*(y-yc) + (z-zc)*(z-zc));
79 
80  // Add temperature perturbations
81  if ((z <= pert_ref_height) && (T_0_Pert_Mag != zero)) {
82  Real rand_double = amrex::Random(engine); // Between zero and one
83  state_pert(i, j, k, RhoTheta_comp) = (rand_double*two - one_d)*T_0_Pert_Mag;
84  if (!pert_rhotheta) {
85  // we're perturbing theta, not rho*theta
86  state_pert(i, j, k, RhoTheta_comp) *= r_hse(i,j,k);
87  }
88  }
89 
90  // Set scalar = A_0*exp(-10r^2), where r is distance from center of domain
91  state_pert(i, j, k, RhoScalar_comp) = A_0 * std::exp(-amrex::Real(10.)*r*r);
92 
93  // Set an initial value for SGS KE
94  //
95  // KE_decay_height is a depth of turbulence above the ground, so the profile
96  // is a function of height above the terrain surface, not of absolute z. Over
97  // terrain higher than KE_decay_height the latter would clamp the decay factor
98  // to its floor at the ground -- exactly backwards. On a flat mesh with
99  // prob_lo[2] == 0 this reduces to the absolute height, since
100  // init_default_zphys ignores prob_lo[2]. Under EB, z_cc is already measured
101  // from the EB surface, so z_sfc is forced to zero there. Matches the surface
102  // height used by SurfaceLayer::init_tke_from_ustar.
103  if (state_pert.nComp() > RhoKE_comp) {
104  // Deardorff
105  state_pert(i, j, k, RhoKE_comp) = r_hse(i,j,k) * KE_0;
106  if (KE_decay_height > 0) {
107  // scale initial SGS kinetic energy with height
108  const Real z_sfc = (use_eb) ? zero :
109  fourth * ( z_nd(i ,j ,klo) + z_nd(i+1,j ,klo)
110  + z_nd(i ,j+1,klo) + z_nd(i+1,j+1,klo) );
111  const Real z_agl = z_cc(i,j,k) - z_sfc;
112  state_pert(i, j, k, RhoKE_comp) *= max(
113  std::pow(1 - min(z_agl/KE_decay_height,one_d), KE_decay_order),
114  amrex::Real(1e-12));
115  }
116  }
117  });
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:43
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:40
#define RhoKE_comp
Definition: ERF_IndexDefines.H:41
const Real zc
Definition: ERF_InitCustomPert_ABL.H:56
const Real yc
Definition: ERF_InitCustomPert_ABL.H:55
const Real xc
Definition: ERF_InitCustomPert_ABL.H:54
const Real dx
Definition: ERF_InitCustomPert_ABL.H:44
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_cloud_chamber_config.active, "Cloud Chamber: initializer reached without a parsed configuration")
const int klo
Definition: ERF_InitCustomPert_TurbulentInflow.H:35
Real W_0_Pert_Mag
Definition: ERF_InitCustomPert_TurbulentInflow.H:20
Real T_0_Pert_Mag
Definition: ERF_InitCustomPert_TurbulentInflow.H:21
Real pert_ref_height
Definition: ERF_InitCustomPert_TurbulentInflow.H:29
Real KE_0
Definition: ERF_InitCustomPert_TurbulentInflow.H:8
const Real * prob_lo
Definition: ERF_InitCustomPert_TurbulentInflow.H:31
Real rho_0
Definition: ERF_InitCustomPert_TurbulentInflow.H:4
ParmParse pp("prob")
Real U_0_Pert_Mag
Definition: ERF_InitCustomPert_TurbulentInflow.H:18
ParallelForRNG(bx, [=, one_d=one] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine &engine) noexcept { const Real *dx=geomdata.CellSize();const Real x=prob_lo[0]+(i+myhalf) *dx[0];const Real y=prob_lo[1]+(j+myhalf) *dx[1];const Real z=z_cc(i, j, k);const Real xc=myhalf *(prob_lo[0]+prob_hi[0]);const Real yc=myhalf *(prob_lo[1]+prob_hi[1]);const Real zc=myhalf *(prob_lo[2]+prob_hi[2]);const Real r=std::sqrt((x-xc) *(x-xc)+(y-yc) *(y-yc)+(z-zc) *(z-zc));if((z<=pert_ref_height) &&(T_0_Pert_Mag !=zero)) { Real rand_double=amrex::Random(engine);state_pert(i, j, k, RhoTheta_comp)=(rand_double *two - one_d) *T_0_Pert_Mag;if(!pert_rhotheta) { state_pert(i, j, k, RhoTheta_comp) *=r_hse(i, j, k);} } state_pert(i, j, k, RhoScalar_comp)=A_0 *std::exp(-amrex::Real(10.) *r *r);if(state_pert.nComp() > RhoKE_comp) { state_pert(i, j, k, RhoKE_comp)=r_hse(i, j, k) *KE_0;if(KE_decay_height > 0) { const Real z_sfc=(use_eb) ? zero :fourth *(z_nd(i, j, klo)+z_nd(i+1, j, klo)+z_nd(i, j+1, klo)+z_nd(i+1, j+1, klo));const Real z_agl=z_cc(i, j, k) - z_sfc;state_pert(i, j, k, RhoKE_comp) *=max(std::pow(1 - min(z_agl/KE_decay_height, one_d), KE_decay_order), amrex::Real(1e-12));} } })
Real pert_periods_V
Definition: ERF_InitCustomPert_TurbulentInflow.H:28
Real T_0
Definition: ERF_InitCustomPert_TurbulentInflow.H:5
Real pert_deltaV
Definition: ERF_InitCustomPert_TurbulentInflow.H:26
Real U_0
Definition: ERF_InitCustomPert_TurbulentInflow.H:13
Real KE_decay_order
Definition: ERF_InitCustomPert_TurbulentInflow.H:11
Real V_0
Definition: ERF_InitCustomPert_TurbulentInflow.H:14
Real pert_deltaU
Definition: ERF_InitCustomPert_TurbulentInflow.H:25
const Real * prob_hi
Definition: ERF_InitCustomPert_TurbulentInflow.H:32
Real pert_periods_U
Definition: ERF_InitCustomPert_TurbulentInflow.H:27
Real KE_decay_height
Definition: ERF_InitCustomPert_TurbulentInflow.H:10
bool pert_rhotheta
Definition: ERF_InitCustomPert_TurbulentInflow.H:22
Real W_0
Definition: ERF_InitCustomPert_TurbulentInflow.H:15
Real A_0
Definition: ERF_InitCustomPert_TurbulentInflow.H:7
Real V_0_Pert_Mag
Definition: ERF_InitCustomPert_TurbulentInflow.H:19
const bool use_eb
Definition: ERF_InitCustomPert_TurbulentInflow.H:34
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:31
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:30
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:35
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:29
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:34
amrex::Real Real
Definition: ERF_ShocInterface.H:19