ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InitCustomPertVels_ScalarAdvDiff.H
Go to the documentation of this file.
1 
2  // On a mesh other than ConstantDz, heights come from z_nd and the vertical levels,
3  // not from geomdata's prob_lo[2], prob_hi[2] and CellSize(2)
4  const bool use_z_phys = use_physical_z();
5 
6  amrex::Gpu::streamSynchronize();
7  ParmParse pp_for_pert_vels("prob");
8  Real U_0 = zero; pp_for_pert_vels.query("U_0", U_0);
9  Real V_0 = zero; pp_for_pert_vels.query("V_0", V_0);
10  Real W_0 = zero; pp_for_pert_vels.query("W_0", W_0);
11 
12  Real z0 = amrex::Real(0.1); pp_for_pert_vels.query("z0", z0);
13  Real zRef = amrex::Real(80.0); pp_for_pert_vels.query("zRef", zRef);
14  Real uRef = zero; pp_for_pert_vels.query("uRef", uRef);
15 
16  int prob_type = -1; pp_for_pert_vels.query("prob_type", prob_type);
17 
18  // An optional smooth test flow added to the velocity above, divergence-free in the
19  // continuum and varying in all three directions: the x-z roll of the streamfunction
20  // psi = A (Lx / 2 pi) sin(2 pi x / Lx) sin(pi z / H), whose w vanishes at the bottom and
21  // top, and the horizontal shears A sin(2 pi y / Ly) in u and A sin(2 pi x / Lx) in v
22  // (periodic in x and y). The initial projection makes it discretely divergence-free.
23  Real test_amp = zero; pp_for_pert_vels.query("test_flow_amp", test_amp);
24  const Real tf_xlo = geomdata.ProbLo()[0], tf_ylo = geomdata.ProbLo()[1];
25  const Real tf_Lx = geomdata.ProbHi()[0] - tf_xlo;
26  const Real tf_Ly = geomdata.ProbHi()[1] - tf_ylo;
27  const Real tf_zlo = geomdata.ProbLo()[2];
28  const Real tf_H = geomdata.ProbHi()[2] - tf_zlo;
29  const Real tf_kx = Real(2.0) * PI / tf_Lx;
30  const Real tf_ky = Real(2.0) * PI / tf_Ly;
31  const Real tf_kz = PI / tf_H;
32 
33  // Set the x-velocity
34  ParallelFor(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
35  {
36  const Real* prob_lo = geomdata.ProbLo();
37  const Real* dx = geomdata.CellSize();
38  const Real z = use_z_phys ? erf_prob_heights::z_xface(i,j,k,z_nd) : prob_lo[2] + (k + myhalf) * dx[2];
39 
40  // Set the x-velocity
41  if (uRef != zero) {
42  x_vel_pert(i, j, k) = U_0 + uRef *
43  std::log((z + z0)/z0) / std::log((zRef +z0)/z0);
44  } else {
45  x_vel_pert(i, j, k) = U_0;
46  }
47  if (test_amp != zero) {
48  const Real x = prob_lo[0] + i * dx[0];
49  const Real y = prob_lo[1] + (j + myhalf) * dx[1];
50  x_vel_pert(i, j, k) += test_amp * (tf_kz / tf_kx) * std::sin(tf_kx * (x - tf_xlo))
51  * std::cos(tf_kz * (z - tf_zlo))
52  + test_amp * std::sin(tf_ky * (y - tf_ylo));
53  }
54  });
55 
56  // Set the y-velocity
57  ParallelFor(ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
58  {
59  y_vel_pert(i, j, k) = V_0;
60  if (test_amp != zero) {
61  const Real* prob_lo = geomdata.ProbLo();
62  const Real* dx = geomdata.CellSize();
63  const Real x = prob_lo[0] + (i + myhalf) * dx[0];
64  y_vel_pert(i, j, k) += test_amp * std::sin(tf_kx * (x - tf_xlo));
65  }
66  });
67 
68  // Set the z-velocity
69  ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
70  {
71  z_vel_pert(i, j, k) = W_0;
72  if (test_amp != zero) {
73  const Real* prob_lo = geomdata.ProbLo();
74  const Real* dx = geomdata.CellSize();
75  const Real x = prob_lo[0] + (i + myhalf) * dx[0];
76  const Real z = use_z_phys ? erf_prob_heights::z_zface(i,j,k,z_nd) : prob_lo[2] + k * dx[2];
77  z_vel_pert(i, j, k) -= test_amp * std::cos(tf_kx * (x - tf_xlo)) * std::sin(tf_kz * (z - tf_zlo));
78  }
79  });
ParallelFor(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { const Real *prob_lo=geomdata.ProbLo();const Real *dx=geomdata.CellSize();const Real z=use_z_phys ? erf_prob_heights::z_xface(i, j, k, z_nd) :prob_lo[2]+(k+myhalf) *dx[2];if(uRef !=zero) { x_vel_pert(i, j, k)=U_0+uRef *std::log((z+z0)/z0)/std::log((zRef+z0)/z0);} else { x_vel_pert(i, j, k)=U_0;} if(test_amp !=zero) { const Real x=prob_lo[0]+i *dx[0];const Real y=prob_lo[1]+(j+myhalf) *dx[1];x_vel_pert(i, j, k)+=test_amp *(tf_kz/tf_kx) *std::sin(tf_kx *(x - tf_xlo)) *std::cos(tf_kz *(z - tf_zlo))+test_amp *std::sin(tf_ky *(y - tf_ylo));} })
const bool use_z_phys
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:4
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:12
const Real tf_ylo
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:24
ParmParse pp_for_pert_vels("prob")
const Real tf_ky
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:30
Real U_0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:8
const Real tf_Lx
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:25
Real V_0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:9
const Real tf_kx
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:29
const Real tf_zlo
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:27
Real uRef
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:14
Real zRef
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:13
int prob_type
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:16
Real W_0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:10
Real test_amp
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:23
const Real tf_Ly
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:26
const Real tf_H
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:28
const Real tf_xlo
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:24
const Real tf_kz
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:31
const Real dx
Definition: ERF_InitCustomPert_ABL.H:44
const GpuArray< Real, AMREX_SPACEDIM > prob_lo
Definition: ERF_InitCustomPert_CloudChamber.H:33
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
constexpr amrex::Real PI
Definition: ERF_NumericalConstants.H:46
amrex::Real Real
Definition: ERF_ShocInterface.H:19
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real z_zface(int i, int j, int k, amrex::Array4< amrex::Real const > const &z_nd) noexcept
Height of the centre of z-face (i,j,k)
Definition: ERF_ProbHeights.H:39
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real z_xface(int i, int j, int k, amrex::Array4< amrex::Real const > const &z_nd) noexcept
Height of the centre of x-face (i,j,k)
Definition: ERF_ProbHeights.H:21