ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InitCustomPertVels_TurbulentInflow.H
Go to the documentation of this file.
1  ParmParse pp_for_pert_vels("prob");
2 
3  Real rho_0 = 1.0; pp_for_pert_vels.query("rho_0", rho_0);
4  Real T_0 = 300.0; pp_for_pert_vels.query("T_0", T_0);
5 
6  Real A_0 = 1.0; pp_for_pert_vels.query("A_0", A_0);
7  Real KE_0 = 0.1; pp_for_pert_vels.query("KE_0", KE_0);
8 
9  Real KE_decay_height = -1; pp_for_pert_vels.query("KE_decay_height", KE_decay_height);
10  Real KE_decay_order = 1; pp_for_pert_vels.query("KE_decay_order", KE_decay_order);
11 
12  Real U_0 = 0.0; pp_for_pert_vels.query("U_0", U_0);
13  Real V_0 = 0.0; pp_for_pert_vels.query("V_0", V_0);
14  Real W_0 = 0.0; pp_for_pert_vels.query("W_0", W_0);
15 
16  // random initial perturbations (legacy code)
17  Real U_0_Pert_Mag = 0.0; pp_for_pert_vels.query("U_0_Pert_Mag", U_0_Pert_Mag);
18  Real V_0_Pert_Mag = 0.0; pp_for_pert_vels.query("V_0_Pert_Mag", V_0_Pert_Mag);
19  Real W_0_Pert_Mag = 0.0; pp_for_pert_vels.query("W_0_Pert_Mag", W_0_Pert_Mag);
20  Real T_0_Pert_Mag = 0.0; pp_for_pert_vels.query("T_0_Pert_Mag", T_0_Pert_Mag);
21  bool pert_rhotheta = true; pp_for_pert_vels.query("pert_rhotheta", pert_rhotheta);
22 
23  // divergence-free initial perturbations
24  Real pert_deltaU = 0.0; pp_for_pert_vels.query("pert_deltaU", pert_deltaU);
25  Real pert_deltaV = 0.0; pp_for_pert_vels.query("pert_deltaV", pert_deltaV);
26  Real pert_periods_U = 5.0; pp_for_pert_vels.query("pert_periods_U", pert_periods_U);
27  Real pert_periods_V = 5.0; pp_for_pert_vels.query("pert_periods_V", pert_periods_V);
28  Real pert_ref_height = 100.0; pp_for_pert_vels.query("pert_ref_height", pert_ref_height);
29 
30  const Real* prob_lo = geomdata.ProbLo();
31  const Real* prob_hi = geomdata.ProbHi();
32 
33  // helper vars
34  Real aval = pert_periods_U * 2.0 * PI / (prob_hi[1] - prob_lo[1]);
35  Real bval = pert_periods_V * 2.0 * PI / (prob_hi[0] - prob_lo[0]);
36  Real ufac = pert_deltaU * std::exp(0.5) / pert_ref_height;
37  Real vfac = pert_deltaV * std::exp(0.5) / pert_ref_height;
38 
39  const bool use_terrain = (SolverChoice::terrain_type != TerrainType::None);
40 
41  // Set the x-velocity
42  ParallelForRNG(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept
43  {
44  const Real* prob_lo = geomdata.ProbLo();
45  const Real* dx = geomdata.CellSize();
46  const Real y = prob_lo[1] + (j + 0.5) * dx[1];
47  const Real z = use_terrain ? 0.25*( z_nd(i,j ,k) + z_nd(i,j ,k+1)
48  + z_nd(i,j+1,k) + z_nd(i,j+1,k+1) )
49  : prob_lo[2] + (k + 0.5) * dx[2];
50 
51  // Set the x-velocity
52  x_vel_pert(i, j, k) = U_0;
53  if ((z <= pert_ref_height) && (U_0_Pert_Mag != 0.0))
54  {
55  Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
56  Real x_vel_prime = (rand_double*2.0 - 1.0)*U_0_Pert_Mag;
57  x_vel_pert(i, j, k) += x_vel_prime;
58  }
59  if (pert_deltaU != 0.0)
60  {
61  const Real yl = y - prob_lo[1];
62  const Real zl = z / pert_ref_height;
63  const Real damp = std::exp(-0.5 * zl * zl);
64  x_vel_pert(i, j, k) += ufac * damp * z * std::cos(aval * yl);
65  }
66  });
67 
68  // Set the y-velocity
69  ParallelForRNG(ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept {
70  const Real* prob_lo = geomdata.ProbLo();
71  const Real* dx = geomdata.CellSize();
72  const Real x = prob_lo[0] + (i + 0.5) * dx[0];
73  const Real z = use_terrain ? 0.25*( z_nd(i ,j,k) + z_nd(i ,j,k+1)
74  + z_nd(i+1,j,k) + z_nd(i+1,j,k+1) )
75  : prob_lo[2] + (k + 0.5) * dx[2];
76 
77  // Set the y-velocity
78  y_vel_pert(i, j, k) = V_0;
79  if ((z <= pert_ref_height) && (V_0_Pert_Mag != 0.0))
80  {
81  Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
82  Real y_vel_prime = (rand_double*2.0 - 1.0)*V_0_Pert_Mag;
83  y_vel_pert(i, j, k) += y_vel_prime;
84  }
85  if (pert_deltaV != 0.0)
86  {
87  const Real xl = x - prob_lo[0];
88  const Real zl = z / pert_ref_height;
89  const Real damp = std::exp(-0.5 * zl * zl);
90  y_vel_pert(i, j, k) += vfac * damp * z * std::cos(bval * xl);
91  }
92  });
93 
94  // Set the z-velocity
95  ParallelForRNG(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept {
96  const int dom_lo_z = geomdata.Domain().smallEnd()[2];
97  const int dom_hi_z = geomdata.Domain().bigEnd()[2];
98 
99  // Set the z-velocity
100  if (k == dom_lo_z || k == dom_hi_z+1)
101  {
102  z_vel_pert(i, j, k) = 0.0;
103  }
104  else if (W_0_Pert_Mag != 0.0)
105  {
106  Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
107  Real z_vel_prime = (rand_double*2.0 - 1.0)*W_0_Pert_Mag;
108  z_vel_pert(i, j, k) = W_0 + z_vel_prime;
109  }
110  });
constexpr amrex::Real PI
Definition: ERF_Constants.H:6
const auto dx
Definition: ERF_InitCustomPertVels_ParticleTests.H:15
const bool use_terrain
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:39
Real bval
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:35
Real aval
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:34
Real W_0_Pert_Mag
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:19
Real T_0_Pert_Mag
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:20
Real pert_ref_height
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:28
Real KE_0
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:7
const Real * prob_lo
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:30
Real rho_0
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:3
ParmParse pp_for_pert_vels("prob")
Real U_0_Pert_Mag
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:17
Real pert_periods_V
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:27
Real vfac
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:37
Real T_0
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:4
Real pert_deltaV
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:25
Real U_0
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:12
Real ufac
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:36
Real KE_decay_order
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:10
Real V_0
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:13
Real pert_deltaU
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:24
const Real * prob_hi
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:31
Real pert_periods_U
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:26
Real KE_decay_height
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:9
bool pert_rhotheta
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:21
Real W_0
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:14
Real A_0
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:6
Real V_0_Pert_Mag
Definition: ERF_InitCustomPertVels_TurbulentInflow.H:18
ParallelForRNG(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine &engine) noexcept { const Real *prob_lo=geomdata.ProbLo();const Real *dx=geomdata.CellSize();const Real y=prob_lo[1]+(j+0.5) *dx[1];const Real z=use_terrain ? 0.25 *(z_nd(i, j, k)+z_nd(i, j, k+1)+z_nd(i, j+1, k)+z_nd(i, j+1, k+1)) :prob_lo[2]+(k+0.5) *dx[2];x_vel_pert(i, j, k)=U_0;if((z<=pert_ref_height) &&(U_0_Pert_Mag !=0.0)) { Real rand_double=amrex::Random(engine);Real x_vel_prime=(rand_double *2.0 - 1.0) *U_0_Pert_Mag;x_vel_pert(i, j, k)+=x_vel_prime;} if(pert_deltaU !=0.0) { const Real yl=y - prob_lo[1];const Real zl=z/pert_ref_height;const Real damp=std::exp(-0.5 *zl *zl);x_vel_pert(i, j, k)+=ufac *damp *z *std::cos(aval *yl);} })
const Box zbx
Definition: ERF_SetupDiff.H:9
const Box xbx
Definition: ERF_SetupDiff.H:7
const Box ybx
Definition: ERF_SetupDiff.H:8
amrex::Real Real
Definition: ERF_ShocInterface.H:19
static TerrainType terrain_type
Definition: ERF_DataStruct.H:1056