ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InitZLevels.cpp File Reference
#include <ERF_TerrainMetrics.H>
#include <ERF_Utils.H>
#include <AMReX_ParmParse.H>
#include <ERF_Constants.H>
#include <ERF_Interpolation_1D.H>
#include <cmath>
Include dependency graph for ERF_InitZLevels.cpp:

Functions

void init_zlevels (Vector< Vector< Real >> &zlevels_stag, Vector< Vector< Real >> &stretched_dz_h, Vector< Gpu::DeviceVector< Real >> &stretched_dz_d, Vector< Geometry > const &geom, Vector< IntVect > const &ref_ratio, const Real grid_stretching_ratio, const Real zsurf, const Real dz0)
 

Function Documentation

◆ init_zlevels()

void init_zlevels ( Vector< Vector< Real >> &  zlevels_stag,
Vector< Vector< Real >> &  stretched_dz_h,
Vector< Gpu::DeviceVector< Real >> &  stretched_dz_d,
Vector< Geometry > const &  geom,
Vector< IntVect > const &  ref_ratio,
const Real  grid_stretching_ratio,
const Real  zsurf,
const Real  dz0 
)
19 {
20  int max_level = zlevels_stag.size()-1;
21 
22  for (int lev = 0; lev <= max_level; lev++)
23  {
24  auto dx = geom[lev].CellSizeArray();
25  const Box& domain = geom[lev].Domain();
26  int nz = domain.length(2);
27 
28  zlevels_stag[lev].resize(nz+1);
29 
30  stretched_dz_h[lev].resize(domain.length(2));
31 
32  if (grid_stretching_ratio == 0) {
33  // This is the default for z_levels
34  for (int k = 0; k < nz+1; k++)
35  {
36  zlevels_stag[lev][k] = k * dx[2];
37  }
38  for (int k = 0; k < nz; k++)
39  {
40  stretched_dz_h[lev][k] = dx[2];
41  }
42  } else if (lev == 0) {
43  // Create stretched grid based on initial dz and stretching ratio
44  zlevels_stag[lev][0] = zsurf;
45  Real dz = dz0;
46  Print() << "Stretched grid levels at level : " << lev << " is " << zsurf;
47  for (int k = 1; k < nz+1; k++)
48  {
49  stretched_dz_h[lev][k-1] = dz;
50  zlevels_stag[lev][k] = zlevels_stag[lev][k-1] + dz;
51  Print() << " " << zlevels_stag[lev][k];
52  dz *= grid_stretching_ratio;
53  }
54  Print() << std::endl;
55  } else if (lev > 0) {
56  int rr = ref_ratio[lev-1][2];
57  expand_and_interpolate_1d(zlevels_stag[lev], zlevels_stag[lev-1], rr, false);
58  for (int k = 0; k < nz; k++)
59  {
60  stretched_dz_h[lev][k] = (zlevels_stag[lev][k+1] - zlevels_stag[lev][k]);
61  }
62  }
63  }
64 
65  // Try reading in terrain_z_levels, which allows arbitrarily spaced grid
66  // levels to be specified and will take precedence over the
67  // grid_stretching_ratio parameter
68  ParmParse pp("erf");
69  int n_zlevels = pp.countval("terrain_z_levels");
70  if (n_zlevels > 0)
71  {
72  int nz = geom[0].Domain().length(2);
73  if (n_zlevels != nz+1) {
74  Print() << "You supplied " << n_zlevels << " staggered terrain_z_levels " << std::endl;
75  Print() << "but n_cell+1 in the z-direction is " << nz+1 << std::endl;
76  Abort("You must specify a z_level for every value of k");
77  }
78 
79  if (grid_stretching_ratio > 0) {
80  Print() << "Note: Found terrain_z_levels, ignoring grid_stretching_ratio" << std::endl;
81  }
82 
83  pp.getarr("terrain_z_levels", zlevels_stag[0], 0, nz+1);
84 
85  // These levels should range from 0 at the surface to the height of the
86  // top of model domain (see the coordinate surface height, zeta, in
87  // Klemp 2011)
88  AMREX_ALWAYS_ASSERT(zlevels_stag[0][0] == 0);
89 
90  for (int lev = 1; lev <= max_level; lev++) {
91  int rr = ref_ratio[lev-1][2];
92  expand_and_interpolate_1d(zlevels_stag[lev], zlevels_stag[lev-1], rr, false);
93  }
94 
95  for (int lev = 0; lev <= max_level; lev++) {
96  int nz_zlevs = zlevels_stag[lev].size();
97  for (int k = 0; k < nz_zlevs-1; k++)
98  {
99  stretched_dz_h[lev][k] = (zlevels_stag[lev][k+1] - zlevels_stag[lev][k]);
100  }
101  }
102  }
103 
104  for (int lev = 0; lev <= max_level; lev++) {
105  stretched_dz_d[lev].resize(stretched_dz_h[lev].size());
106  Gpu::copy(Gpu::hostToDevice, stretched_dz_h[lev].begin(), stretched_dz_h[lev].end(), stretched_dz_d[lev].begin());
107  }
108 }
AMREX_FORCE_INLINE void expand_and_interpolate_1d(amrex::Vector< amrex::Real > &znew, const amrex::Vector< amrex::Real > &zorig, int refine_fac, bool destag=false)
Definition: ERF_Interpolation_1D.H:85
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pp(amrex::Real y)
Definition: ERF_MicrophysicsUtils.H:233
amrex::Real Real
Definition: ERF_ShocInterface.H:19
real(c_double), private rr
Definition: ERF_module_mp_morr_two_moment.F90:224

Referenced by ERF::ERF_shared().

Here is the call graph for this function:
Here is the caller graph for this function: