ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InitCustomPertVels_ABL.H
Go to the documentation of this file.
1 
2  ParmParse pp_prob("prob");
3 
5  int fix_random_seed = 0;
6  long random_seed = -1;
7  {
8  amrex::ParmParse pp_erf("erf");
9  pp_erf.query("deterministic_ic_pert", deterministic_ic_pert);
10  pp_erf.query("fix_random_seed", fix_random_seed);
11  pp_erf.query("random_seed", random_seed);
12  }
13  const std::uint64_t ic_pert_seed = fix_random_seed
14  ? std::uint64_t(1024)
15  : ((random_seed >= 0) ? static_cast<std::uint64_t>(random_seed) : std::uint64_t(0));
16  constexpr int x_velocity_hash_comp = 1;
17  constexpr int y_velocity_hash_comp = 2;
18  constexpr int z_velocity_hash_comp = 3;
19 
20  Real U_0 = zero; pp_prob.query("U_0", U_0);
21  Real V_0 = zero; pp_prob.query("V_0", V_0);
22  Real W_0 = zero; pp_prob.query("W_0", W_0);
23 
24  // random initial perturbations (legacy code)
25  Real U_0_Pert_Mag = zero; pp_prob.query("U_0_Pert_Mag", U_0_Pert_Mag);
26  Real V_0_Pert_Mag = zero; pp_prob.query("V_0_Pert_Mag", V_0_Pert_Mag);
27  Real W_0_Pert_Mag = zero; pp_prob.query("W_0_Pert_Mag", W_0_Pert_Mag);
28 
29  // divergence-free initial perturbations
30  Real pert_deltaU = zero; pp_prob.query("pert_deltaU", pert_deltaU);
31  Real pert_deltaV = zero; pp_prob.query("pert_deltaV", pert_deltaV);
32  Real pert_periods_U = amrex::Real(5.0); pp_prob.query("pert_periods_U", pert_periods_U);
33  Real pert_periods_V = amrex::Real(5.0); pp_prob.query("pert_periods_V", pert_periods_V);
34  Real pert_ref_height = amrex::Real(100.0); pp_prob.query("pert_ref_height", pert_ref_height);
35 
36  auto problo = geomdata.ProbLo();
37  auto probhi = geomdata.ProbHi();
38 
39  Real aval = pert_periods_U * two * PI / (probhi[1] - problo[1]);
40  Real bval = pert_periods_V * two * PI / (probhi[0] - problo[0]);
43 
44  if (pert_ref_height > 0) {
45  if ((pert_deltaU != zero) || (pert_deltaV != zero)) {
46  amrex::Print() << "Adding divergence-free perturbations "
47  << pert_deltaU << " " << pert_deltaV
48  << std::endl;
49  }
50  if (U_0_Pert_Mag != zero) {
51  amrex::Print() << "Adding random x-velocity perturbations" << std::endl;
52  }
53  if (V_0_Pert_Mag != zero) {
54  amrex::Print() << "Adding random y-velocity perturbations" << std::endl;
55  }
56  }
57 
58  // Set the x-velocity
59  ParallelForRNG(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept {
60  const Real* prob_lo = geomdata.ProbLo();
61  const Real* dx = geomdata.CellSize();
62  const Real y = prob_lo[1] + (j + myhalf) * dx[1];
63  const Real z = (z_nd) ? fourth*( z_nd(i,j ,k) + z_nd(i,j ,k+1)
64  + z_nd(i,j+1,k) + z_nd(i,j+1,k+1) )
65  : prob_lo[2] + (k + myhalf) * dx[2];
66 
67  // Set the x-velocity
68  x_vel_pert(i, j, k) = U_0;
69  if ((z <= pert_ref_height) && (U_0_Pert_Mag != zero))
70  {
71  Real rand_double;
73  rand_double = erf_hash_rng::hash_uniform(
74  i, j, k, x_velocity_hash_comp, lev, ic_pert_seed);
75  } else {
76  rand_double = amrex::Random(engine); // Between zero and one
77  }
78  Real x_vel_prime = (rand_double*two - one)*U_0_Pert_Mag;
79  x_vel_pert(i, j, k) += x_vel_prime;
80  }
81  if (pert_deltaU != zero)
82  {
83  const amrex::Real yl = y - prob_lo[1];
84  const amrex::Real zl = z / pert_ref_height;
85  const amrex::Real damp = std::exp(-myhalf * zl * zl);
86  x_vel_pert(i, j, k) += ufac * damp * z * std::cos(aval * yl);
87  }
88  });
89 
90  // Set the y-velocity
91  ParallelForRNG(ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept
92  {
93  const Real* prob_lo = geomdata.ProbLo();
94  const Real* dx = geomdata.CellSize();
95  const Real x = prob_lo[0] + (i + myhalf) * dx[0];
96  const Real z = (z_nd) ? fourth*( z_nd(i ,j,k) + z_nd(i ,j,k+1)
97  + z_nd(i+1,j,k) + z_nd(i+1,j,k+1) )
98  : prob_lo[2] + (k + myhalf) * dx[2];
99 
100  // Set the y-velocity
101  y_vel_pert(i, j, k) = V_0;
102  if ((z <= pert_ref_height) && (V_0_Pert_Mag != zero))
103  {
104  Real rand_double;
105  if (deterministic_ic_pert) {
106  rand_double = erf_hash_rng::hash_uniform(
107  i, j, k, y_velocity_hash_comp, lev, ic_pert_seed);
108  } else {
109  rand_double = amrex::Random(engine); // Between zero and one
110  }
111  Real y_vel_prime = (rand_double*two - one)*V_0_Pert_Mag;
112  y_vel_pert(i, j, k) += y_vel_prime;
113  }
114  if (pert_deltaV != zero)
115  {
116  const amrex::Real xl = x - prob_lo[0];
117  const amrex::Real zl = z / pert_ref_height;
118  const amrex::Real damp = std::exp(-myhalf * zl * zl);
119  y_vel_pert(i, j, k) += vfac * damp * z * std::cos(bval * xl);
120  }
121  });
122 
123  // Set the z-velocity
124  ParallelForRNG(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept
125  {
126  const int dom_lo_z = geomdata.Domain().smallEnd()[2];
127  const int dom_hi_z = geomdata.Domain().bigEnd()[2];
128 
129  // Set the z-velocity
130  if (k == dom_lo_z || k == dom_hi_z+1)
131  {
132  z_vel_pert(i, j, k) = zero;
133  }
134  else
135  {
136  z_vel_pert(i, j, k) = W_0;
137  if (W_0_Pert_Mag != zero)
138  {
139  Real rand_double;
140  if (deterministic_ic_pert) {
141  rand_double = erf_hash_rng::hash_uniform(
142  i, j, k, z_velocity_hash_comp, lev, ic_pert_seed);
143  } else {
144  rand_double = amrex::Random(engine); // Between zero and one
145  }
146  Real z_vel_prime = (rand_double*two - one)*W_0_Pert_Mag;
147  z_vel_pert(i, j, k) += z_vel_prime;
148  }
149  }
150  });
constexpr amrex::Real two
Definition: ERF_Constants.H:10
constexpr amrex::Real one
Definition: ERF_Constants.H:9
constexpr amrex::Real fourth
Definition: ERF_Constants.H:14
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
constexpr amrex::Real PI
Definition: ERF_Constants.H:42
Real bval
Definition: ERF_InitCustomPertVels_ABL.H:40
Real aval
Definition: ERF_InitCustomPertVels_ABL.H:39
Real W_0_Pert_Mag
Definition: ERF_InitCustomPertVels_ABL.H:27
int deterministic_ic_pert
Definition: ERF_InitCustomPertVels_ABL.H:4
Real pert_ref_height
Definition: ERF_InitCustomPertVels_ABL.H:34
constexpr int y_velocity_hash_comp
Definition: ERF_InitCustomPertVels_ABL.H:17
auto probhi
Definition: ERF_InitCustomPertVels_ABL.H:37
constexpr int x_velocity_hash_comp
Definition: ERF_InitCustomPertVels_ABL.H:16
ParmParse pp_prob("prob")
Real U_0_Pert_Mag
Definition: ERF_InitCustomPertVels_ABL.H:25
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+myhalf) *dx[1];const Real z=(z_nd) ? fourth *(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+myhalf) *dx[2];x_vel_pert(i, j, k)=U_0;if((z<=pert_ref_height) &&(U_0_Pert_Mag !=zero)) { Real rand_double;if(deterministic_ic_pert) { rand_double=erf_hash_rng::hash_uniform(i, j, k, x_velocity_hash_comp, lev, ic_pert_seed);} else { rand_double=amrex::Random(engine);} Real x_vel_prime=(rand_double *two - one) *U_0_Pert_Mag;x_vel_pert(i, j, k)+=x_vel_prime;} if(pert_deltaU !=zero) { const amrex::Real yl=y - prob_lo[1];const amrex::Real zl=z/pert_ref_height;const amrex::Real damp=std::exp(-myhalf *zl *zl);x_vel_pert(i, j, k)+=ufac *damp *z *std::cos(aval *yl);} })
Real pert_periods_V
Definition: ERF_InitCustomPertVels_ABL.H:33
Real vfac
Definition: ERF_InitCustomPertVels_ABL.H:42
long random_seed
Definition: ERF_InitCustomPertVels_ABL.H:6
Real pert_deltaV
Definition: ERF_InitCustomPertVels_ABL.H:31
Real U_0
Definition: ERF_InitCustomPertVels_ABL.H:20
const std::uint64_t ic_pert_seed
Definition: ERF_InitCustomPertVels_ABL.H:13
Real ufac
Definition: ERF_InitCustomPertVels_ABL.H:41
Real V_0
Definition: ERF_InitCustomPertVels_ABL.H:21
Real pert_deltaU
Definition: ERF_InitCustomPertVels_ABL.H:30
Real pert_periods_U
Definition: ERF_InitCustomPertVels_ABL.H:32
Real W_0
Definition: ERF_InitCustomPertVels_ABL.H:22
int fix_random_seed
Definition: ERF_InitCustomPertVels_ABL.H:5
constexpr int z_velocity_hash_comp
Definition: ERF_InitCustomPertVels_ABL.H:18
Real V_0_Pert_Mag
Definition: ERF_InitCustomPertVels_ABL.H:26
auto problo
Definition: ERF_InitCustomPertVels_ABL.H:36
const Real dx
Definition: ERF_InitCustomPert_ABL.H:44
const GpuArray< Real, AMREX_SPACEDIM > prob_lo
Definition: ERF_InitCustomPert_CloudChamber.H:33
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ xl
Definition: ERF_WSM6.H:235
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real hash_uniform(int i, int j, int k, int comp, int lev, std::uint64_t seed) noexcept
Definition: ERF_HashRNG.H:68