ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InitCustomPert_ScalarAdvDiff.H
Go to the documentation of this file.
1 
2  // On a mesh other than ConstantDz, heights come from z_cc 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  const Real phys_z_lo = phys_zlo(geomdata, lev);
6  const Real phys_z_hi = phys_zhi(geomdata, lev);
7 
8  ParmParse pp("prob");
9  Real rho_0 = one; pp.query("rho_0", rho_0);
10  Real A_0 = one; pp.query("A_0", A_0);
11  Real B_0 = zero; pp.query("B_0", B_0);
12  Real rad_0 = zero; pp.query("rad_0", rad_0);
13 
14  // Location of "center" of scalar (multiplies domain length)
15  Real xc_frac = myhalf; pp.query("xc_frac", xc_frac);
16  Real yc_frac = myhalf; pp.query("yc_frac", yc_frac);
17  Real zc_frac = myhalf; pp.query("zc_frac", zc_frac);
18 
19  int prob_type = -1; pp.query("prob_type", prob_type);
20 
21  // If nonzero, theta is perturbed with the same profile as the scalar: rho theta += theta_pert_amp * (rho scalar).
22  // Used to test that two-way coupling conserves (rho theta)
23  Real theta_pert_amp = zero; pp.query("theta_pert_amp", theta_pert_amp);
24 
25  // prob_type 11, 12 and 13 divide by the radius
26  if (prob_type == 11 || prob_type == 12 || prob_type == 13) {
28  "prob.rad_0 must be > 0 for prob.prob_type = 11, 12 and 13");
29  }
30  ParallelFor(bx, [=,one_d=one] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
31  {
32  // Geometry
33  const Real* prob_lo = geomdata.ProbLo();
34  const Real* prob_hi = geomdata.ProbHi();
35  const Real* dx = geomdata.CellSize();
36  const Real x = prob_lo[0] + (i + myhalf) * dx[0];
37  const Real y = prob_lo[1] + (j + myhalf) * dx[1];
38  const Real z = use_z_phys ? z_cc(i,j,k) : prob_lo[2] + (k + myhalf) * dx[2];
39 
40  // Define a point (xc,yc,zc) at the given fractions of the domain extent
41  const Real xc = prob_lo[0] + xc_frac * (prob_hi[0] - prob_lo[0]);
42  const Real yc = prob_lo[1] + yc_frac * (prob_hi[1] - prob_lo[1]);
43  const Real zc = phys_z_lo + zc_frac * (phys_z_hi - phys_z_lo);
44 
45  // Define ellipse parameters
46  const Real r0 = rad_0 * (prob_hi[0] - prob_lo[0]);
47 
48  const Real r3d = std::sqrt((x-xc)*(x-xc) + (y-yc)*(y-yc) + (z-zc)*(z-zc));
49  const Real r2d_xy = std::sqrt((x-xc)*(x-xc) + (y-yc)*(y-yc));
50  const Real r2d_xz = std::sqrt((x-xc)*(x-xc) + (z-zc)*(z-zc));
51 
52  if (prob_type == 10)
53  {
54  // Set scalar = A_0*std::exp(-10r^2), where r is distance from center of domain,
55  // + B_0*std::sin(x)
56  state_pert(i, j, k, RhoScalar_comp) = A_0 * std::exp(-amrex::Real(10.)*r3d*r3d) + B_0*std::sin(x);
57 
58  } else if (prob_type == 11) {
59  state_pert(i, j, k, RhoScalar_comp) = A_0 * fourth * (one_d + std::cos(PI * std::min(r2d_xy, r0) / r0));
60  } else if (prob_type == 12) {
61  state_pert(i, j, k, RhoScalar_comp) = A_0 * fourth * (one_d + std::cos(PI * std::min(r2d_xz, r0) / r0));
62  } else if (prob_type == 13) {
63  const Real r0_z = rad_0 * (phys_z_hi - phys_z_lo);
64  //ellipse for mapfac shear validation
65  //
66  // NOTE: unlike r2d_xy and r2d_xz above, this radius is already normalized by the
67  // semi-axes, so it is dimensionless and equals one *on* the ellipse. We
68  // therefore clip it at one rather than at a length -- dividing it by r0_z
69  // would scale the blob as 1/r0_z instead of giving the intended ellipse.
70  // With r0_z = r0 this reduces exactly to prob_type 12.
71  //
72  const Real r2d_xz_ell = std::sqrt((x-xc)*(x-xc)/(r0*r0) + (z-zc)*(z-zc)/(r0_z*r0_z));
73  state_pert(i, j, k, RhoScalar_comp) = A_0 * fourth * (one_d + std::cos(PI * std::min(r2d_xz_ell, one_d)));
74  } else if (prob_type == 14) {
75  state_pert(i, j, k, RhoScalar_comp) = std::cos(PI*x);
76  } else {
77  // Set scalar = A_0 in a ball of radius r0 and 0 elsewhere
78  if (r3d < r0) {
79  state_pert(i, j, k, RhoScalar_comp) = A_0;
80  } else {
81  state_pert(i, j, k, RhoScalar_comp) = zero;
82  }
83  }
84 
85  state_pert(i, j, k, RhoScalar_comp) *= rho_0;
86  state_pert(i, j, k, RhoTheta_comp) += theta_pert_amp * state_pert(i, j, k, RhoScalar_comp);
87  });
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:57
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:54
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
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
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_z_phys
Definition: ERF_InitCustomPert_ScalarAdvDiff.H:4
ParallelFor(bx, [=, one_d=one] AMREX_GPU_DEVICE(int i, int j, int k) 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+myhalf) *dx[0];const Real y=prob_lo[1]+(j+myhalf) *dx[1];const Real z=use_z_phys ? z_cc(i, j, k) :prob_lo[2]+(k+myhalf) *dx[2];const Real xc=prob_lo[0]+xc_frac *(prob_hi[0] - prob_lo[0]);const Real yc=prob_lo[1]+yc_frac *(prob_hi[1] - prob_lo[1]);const Real zc=phys_z_lo+zc_frac *(phys_z_hi - phys_z_lo);const Real r0=rad_0 *(prob_hi[0] - prob_lo[0]);const Real r3d=std::sqrt((x-xc) *(x-xc)+(y-yc) *(y-yc)+(z-zc) *(z-zc));const Real r2d_xy=std::sqrt((x-xc) *(x-xc)+(y-yc) *(y-yc));const Real r2d_xz=std::sqrt((x-xc) *(x-xc)+(z-zc) *(z-zc));if(prob_type==10) { state_pert(i, j, k, RhoScalar_comp)=A_0 *std::exp(-amrex::Real(10.) *r3d *r3d)+B_0 *std::sin(x);} else if(prob_type==11) { state_pert(i, j, k, RhoScalar_comp)=A_0 *fourth *(one_d+std::cos(PI *std::min(r2d_xy, r0)/r0));} else if(prob_type==12) { state_pert(i, j, k, RhoScalar_comp)=A_0 *fourth *(one_d+std::cos(PI *std::min(r2d_xz, r0)/r0));} else if(prob_type==13) { const Real r0_z=rad_0 *(phys_z_hi - phys_z_lo);const Real r2d_xz_ell=std::sqrt((x-xc) *(x-xc)/(r0 *r0)+(z-zc) *(z-zc)/(r0_z *r0_z));state_pert(i, j, k, RhoScalar_comp)=A_0 *fourth *(one_d+std::cos(PI *std::min(r2d_xz_ell, one_d)));} else if(prob_type==14) { state_pert(i, j, k, RhoScalar_comp)=std::cos(PI *x);} else { if(r3d< r0) { state_pert(i, j, k, RhoScalar_comp)=A_0;} else { state_pert(i, j, k, RhoScalar_comp)=zero;} } state_pert(i, j, k, RhoScalar_comp) *=rho_0;state_pert(i, j, k, RhoTheta_comp)+=theta_pert_amp *state_pert(i, j, k, RhoScalar_comp);})
Real B_0
Definition: ERF_InitCustomPert_ScalarAdvDiff.H:11
Real zc_frac
Definition: ERF_InitCustomPert_ScalarAdvDiff.H:17
Real xc_frac
Definition: ERF_InitCustomPert_ScalarAdvDiff.H:15
Real rho_0
Definition: ERF_InitCustomPert_ScalarAdvDiff.H:9
const Real phys_z_hi
Definition: ERF_InitCustomPert_ScalarAdvDiff.H:6
ParmParse pp("prob")
Real yc_frac
Definition: ERF_InitCustomPert_ScalarAdvDiff.H:16
int prob_type
Definition: ERF_InitCustomPert_ScalarAdvDiff.H:19
Real A_0
Definition: ERF_InitCustomPert_ScalarAdvDiff.H:10
Real rad_0
Definition: ERF_InitCustomPert_ScalarAdvDiff.H:12
Real theta_pert_amp
Definition: ERF_InitCustomPert_ScalarAdvDiff.H:23
const Real phys_z_lo
Definition: ERF_InitCustomPert_ScalarAdvDiff.H:5
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:42
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
real(kind=kind_phys), parameter, private r0
Definition: ERF_module_mp_wdm6.F90:75