ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InitCustomPert_SLM.H
Go to the documentation of this file.
1 
2  ParmParse pp("prob");
3 
4  Real A_0 = amrex::Real(1.0); pp.query("A_0", A_0);
5  Real KE_0 = amrex::Real(0.1); pp.query("KE_0", KE_0);
6 
7  // Random temperature perturbation amplitude and taper/cutoff height.
8  Real T_0_Pert_Mag = amrex::Real(0.0); pp.query("T_0_Pert_Mag", T_0_Pert_Mag);
9  Real qv_0_Pert_Mag = amrex::Real(0.0); pp.query("qv_0_Pert_Mag", qv_0_Pert_Mag);
10  Real pert_ref_height = amrex::Real(200.0); pp.query("pert_ref_height", pert_ref_height);
11  bool custom_TKE = false; pp.query("custom_TKE", custom_TKE);
12 
13  const bool use_moisture = (sc.moisture_type != MoistureType::None);
14  const bool use_terrain = (sc.terrain_type != TerrainType::None);
15  const bool const_rho = (sc.fixed_density[lev] == 1);
16  const Real rdOcp = sc.rdOcp;
17 
18  ParallelForRNG(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k,
19  const RandomEngine& engine) noexcept
20  {
21  const Real* prob_lo = geomdata.ProbLo();
22  const Real* prob_hi = geomdata.ProbHi();
23  const Real* dx = geomdata.CellSize();
24  const Real x = prob_lo[0] + (i + 0.5) * dx[0];
25  const Real y = prob_lo[1] + (j + 0.5) * dx[1];
26  const Real z = use_terrain ? z_cc(i, j, k) : prob_lo[2] + (k + 0.5) * dx[2];
27 
28  const Real xc = 0.5 * (prob_lo[0] + prob_hi[0]);
29  const Real yc = 0.5 * (prob_lo[1] + prob_hi[1]);
30  const Real zc = 0.5 * (prob_lo[2] + prob_hi[2]);
31  const Real r = std::sqrt((x-xc)*(x-xc) + (y-yc)*(y-yc) + (z-zc)*(z-zc));
32 
33  // Apply a random temperature perturbation that tapers linearly from
34  // T_0_Pert_Mag at the surface to zero at pert_ref_height.
35  if (pert_ref_height > 0.0 && z <= pert_ref_height &&
36  T_0_Pert_Mag != 0.0) {
37  const Real rhotheta = state(i,j,k,RhoTheta_comp);
38  const Real rho = state(i,j,k,Rho_comp);
39  const Real qv = state(i,j,k,RhoQ1_comp) / rho;
40  const Real Told = getTgivenRandRTh(rho, rhotheta, qv);
41  const Real P = getPgivenRTh(rhotheta, qv);
42 
43  const Real rand_double = amrex::Random(engine);
44  const Real Tnew = Told + T_0_Pert_Mag * (1.0 - 2.0 * rand_double)
45  * (1.0 - z / pert_ref_height);
46  const Real theta_new = getThgivenTandP(Tnew, P, rdOcp);
47  const Real rhonew = getRhogivenThetaPress(theta_new, P, rdOcp, qv);
48 
49  if (const_rho) {
50  state_pert(i, j, k, Rho_comp) = 0.0;
51  state_pert(i, j, k, RhoTheta_comp) =
52  r_hse(i, j, k) * (theta_new - (rhotheta / rho));
53  } else {
54  state_pert(i, j, k, Rho_comp) = rhonew - rho;
55  state_pert(i, j, k, RhoTheta_comp) = 0.0;
56  }
57  }
58 
59  state_pert(i, j, k, RhoScalar_comp) = A_0 * exp(-10.0*r*r);
60 
61  if (custom_TKE) {
62  state_pert(i, j, k, RhoKE_comp) =
63  (1.0 - z / prob_hi[2]) * r_hse(i,j,k);
64  } else {
65  state_pert(i, j, k, RhoKE_comp) = KE_0;
66  }
67 
68  if (use_moisture) {
69  state_pert(i, j, k, RhoQ1_comp) = 0.0;
70  state_pert(i, j, k, RhoQ2_comp) = 0.0;
71  if (z <= pert_ref_height && qv_0_Pert_Mag != 0.0) {
72  const Real rhoold = state(i,j,k,Rho_comp);
73  const Real rhonew = rhoold + state_pert(i,j,k,Rho_comp);
74  const Real qvold = state(i,j,k,RhoQ1_comp) / rhoold;
75  const Real rand_double = amrex::Random(engine);
76  const Real qvnew = qvold +
77  (2.0 * rand_double - 1.0) * qv_0_Pert_Mag;
78  state_pert(i, j, k, RhoQ1_comp) =
79  rhonew * qvnew - rhoold * qvold;
80  }
81  }
82  });
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getRhogivenThetaPress(const amrex::Real th, const amrex::Real p, const amrex::Real rdOcp, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:96
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getTgivenRandRTh(const amrex::Real rho, const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:46
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getThgivenTandP(const amrex::Real T, const amrex::Real P, const amrex::Real rdOcp)
Definition: ERF_EOS.H:18
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:81
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:46
#define Rho_comp
Definition: ERF_IndexDefines.H:42
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:43
#define RhoQ2_comp
Definition: ERF_IndexDefines.H:49
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:48
#define RhoKE_comp
Definition: ERF_IndexDefines.H:44
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
const GpuArray< Real, AMREX_SPACEDIM > prob_lo
Definition: ERF_InitCustomPert_CloudChamber.H:33
const amrex::Real * prob_hi
Definition: ERF_InitCustomPert_DataAssimilation_ISV.H:17
const bool use_terrain
Definition: ERF_InitCustomPert_SLM.H:14
const bool const_rho
Definition: ERF_InitCustomPert_SLM.H:15
Real T_0_Pert_Mag
Definition: ERF_InitCustomPert_SLM.H:8
Real pert_ref_height
Definition: ERF_InitCustomPert_SLM.H:10
const bool use_moisture
Definition: ERF_InitCustomPert_SLM.H:13
Real KE_0
Definition: ERF_InitCustomPert_SLM.H:5
const Real rdOcp
Definition: ERF_InitCustomPert_SLM.H:16
ParmParse pp("prob")
ParallelForRNG(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const RandomEngine &engine) noexcept { const Real *prob_lo=geomdata.ProbLo();const Real *prob_hi=geomdata.ProbHi();const Real *dx=geomdata.CellSize();const Real x=prob_lo[0]+(i+0.5) *dx[0];const Real y=prob_lo[1]+(j+0.5) *dx[1];const Real z=use_terrain ? z_cc(i, j, k) :prob_lo[2]+(k+0.5) *dx[2];const Real xc=0.5 *(prob_lo[0]+prob_hi[0]);const Real yc=0.5 *(prob_lo[1]+prob_hi[1]);const Real zc=0.5 *(prob_lo[2]+prob_hi[2]);const Real r=std::sqrt((x-xc) *(x-xc)+(y-yc) *(y-yc)+(z-zc) *(z-zc));if(pert_ref_height > 0.0 &&z<=pert_ref_height &&T_0_Pert_Mag !=0.0) { const Real rhotheta=state(i, j, k, RhoTheta_comp);const Real rho=state(i, j, k, Rho_comp);const Real qv=state(i, j, k, RhoQ1_comp)/rho;const Real Told=getTgivenRandRTh(rho, rhotheta, qv);const Real P=getPgivenRTh(rhotheta, qv);const Real rand_double=amrex::Random(engine);const Real Tnew=Told+T_0_Pert_Mag *(1.0 - 2.0 *rand_double) *(1.0 - z/pert_ref_height);const Real theta_new=getThgivenTandP(Tnew, P, rdOcp);const Real rhonew=getRhogivenThetaPress(theta_new, P, rdOcp, qv);if(const_rho) { state_pert(i, j, k, Rho_comp)=0.0;state_pert(i, j, k, RhoTheta_comp)=r_hse(i, j, k) *(theta_new -(rhotheta/rho));} else { state_pert(i, j, k, Rho_comp)=rhonew - rho;state_pert(i, j, k, RhoTheta_comp)=0.0;} } state_pert(i, j, k, RhoScalar_comp)=A_0 *exp(-10.0 *r *r);if(custom_TKE) { state_pert(i, j, k, RhoKE_comp)=(1.0 - z/prob_hi[2]) *r_hse(i, j, k);} else { state_pert(i, j, k, RhoKE_comp)=KE_0;} if(use_moisture) { state_pert(i, j, k, RhoQ1_comp)=0.0;state_pert(i, j, k, RhoQ2_comp)=0.0;if(z<=pert_ref_height &&qv_0_Pert_Mag !=0.0) { const Real rhoold=state(i, j, k, Rho_comp);const Real rhonew=rhoold+state_pert(i, j, k, Rho_comp);const Real qvold=state(i, j, k, RhoQ1_comp)/rhoold;const Real rand_double=amrex::Random(engine);const Real qvnew=qvold+(2.0 *rand_double - 1.0) *qv_0_Pert_Mag;state_pert(i, j, k, RhoQ1_comp)=rhonew *qvnew - rhoold *qvold;} } })
Real A_0
Definition: ERF_InitCustomPert_SLM.H:4
Real qv_0_Pert_Mag
Definition: ERF_InitCustomPert_SLM.H:9
bool custom_TKE
Definition: ERF_InitCustomPert_SLM.H:11
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ None
Definition: ERF_LSM_Types.H:6
@ P
Definition: ERF_IndexDefines.H:207
@ rho
Definition: ERF_Kessler.H:25
@ qv
Definition: ERF_Kessler.H:31