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 = 1.0; pp.query("rho_0", rho_0);
5  Real T_0 = 300.0; pp.query("T_0", T_0);
6 
7  Real A_0 = 1.0; pp.query("A_0", A_0);
8  Real KE_0 = 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 = 0.0; pp.query("U_0", U_0);
14  Real V_0 = 0.0; pp.query("V_0", V_0);
15  Real W_0 = 0.0; pp.query("W_0", W_0);
16 
17  // random initial perturbations (legacy code)
18  Real U_0_Pert_Mag = 0.0; pp.query("U_0_Pert_Mag", U_0_Pert_Mag);
19  Real V_0_Pert_Mag = 0.0; pp.query("V_0_Pert_Mag", V_0_Pert_Mag);
20  Real W_0_Pert_Mag = 0.0; pp.query("W_0_Pert_Mag", W_0_Pert_Mag);
21  Real T_0_Pert_Mag = 0.0; 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 = 0.0; pp.query("pert_deltaU", pert_deltaU);
26  Real pert_deltaV = 0.0; pp.query("pert_deltaV", pert_deltaV);
27  Real pert_periods_U = 5.0; pp.query("pert_periods_U", pert_periods_U);
28  Real pert_periods_V = 5.0; pp.query("pert_periods_V", pert_periods_V);
29  Real pert_ref_height = 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  if (KE_decay_height > 0) {
35  amrex::Print() << "Initial KE profile (order " << KE_decay_order
36  << ") will extend up to " << KE_decay_height
37  << std::endl;
38  }
39 
40  if (pert_ref_height > 0) {
41  if ((pert_deltaU != 0.0) || (pert_deltaV != 0.0)) {
42  amrex::Print() << "Adding divergence-free perturbations "
43  << pert_deltaU << " " << pert_deltaV
44  << std::endl;
45  }
46  if (U_0_Pert_Mag != 0.0) {
47  amrex::Print() << "Adding random x-velocity perturbations" << std::endl;
48  }
49  if (V_0_Pert_Mag != 0.0) {
50  amrex::Print() << "Adding random y-velocity perturbations" << std::endl;
51  }
52  if (T_0_Pert_Mag != 0.0) {
53  if (pert_rhotheta) {
54  amrex::Print() << "Adding random rho*theta perturbations" << std::endl;
55  } else {
56  amrex::Print() << "Adding random theta perturbations" << std::endl;
57  }
58  }
59  }
60 
61  ParallelForRNG(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept
62  {
63  const Real* dx = geomdata.CellSize();
64  const Real x = prob_lo[0] + (i + 0.5) * dx[0];
65  const Real y = prob_lo[1] + (j + 0.5) * dx[1];
66  const Real z = z_cc(i,j,k);
67 
68  // Define a point (xc,yc,zc) at the center of the domain
69  const Real xc = 0.5 * (prob_lo[0] + prob_hi[0]);
70  const Real yc = 0.5 * (prob_lo[1] + prob_hi[1]);
71  const Real zc = 0.5 * (prob_lo[2] + prob_hi[2]);
72 
73  const Real r = std::sqrt((x-xc)*(x-xc) + (y-yc)*(y-yc) + (z-zc)*(z-zc));
74 
75  // Add temperature perturbations
76  if ((z <= pert_ref_height) && (T_0_Pert_Mag != 0.0)) {
77  Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
78  state_pert(i, j, k, RhoTheta_comp) = (rand_double*2.0 - 1.0)*T_0_Pert_Mag;
79  if (!pert_rhotheta) {
80  // we're perturbing theta, not rho*theta
81  state_pert(i, j, k, RhoTheta_comp) *= r_hse(i,j,k);
82  }
83  }
84 
85  // Set scalar = A_0*exp(-10r^2), where r is distance from center of domain
86  state_pert(i, j, k, RhoScalar_comp) = A_0 * exp(-10.*r*r);
87 
88  // Set an initial value for SGS KE
89  if (state_pert.nComp() > RhoKE_comp) {
90  // Deardorff
91  state_pert(i, j, k, RhoKE_comp) = r_hse(i,j,k) * KE_0;
92  if (KE_decay_height > 0) {
93  // scale initial SGS kinetic energy with height
94  state_pert(i, j, k, RhoKE_comp) *= max(
95  std::pow(1 - min(z/KE_decay_height,1.0), KE_decay_order),
96  1e-12);
97  }
98  }
99  });
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:40
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define RhoKE_comp
Definition: ERF_IndexDefines.H:38
const auto dx
Definition: ERF_InitCustomPertVels_ParticleTests.H:15
amrex::Real yc
Definition: ERF_InitCustomPert_IsentropicVortex.H:20
amrex::Real xc
Definition: ERF_InitCustomPert_IsentropicVortex.H:19
ParallelForRNG(bx, [=] 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+0.5) *dx[0];const Real y=prob_lo[1]+(j+0.5) *dx[1];const Real z=z_cc(i, j, k);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((z<=pert_ref_height) &&(T_0_Pert_Mag !=0.0)) { Real rand_double=amrex::Random(engine);state_pert(i, j, k, RhoTheta_comp)=(rand_double *2.0 - 1.0) *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 *exp(-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) { state_pert(i, j, k, RhoKE_comp) *=max(std::pow(1 - min(z/KE_decay_height, 1.0), KE_decay_order), 1e-12);} } })
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
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
amrex::Real Real
Definition: ERF_ShocInterface.H:19