ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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  amrex::Print() <<" IN Z LEVELS " << std::endl;
21  int max_level = zlevels_stag.size()-1;
22 
23  for (int lev = 0; lev <= max_level; lev++)
24  {
25  auto dx = geom[lev].CellSizeArray();
26  const Box& domain = geom[lev].Domain();
27  int nz = domain.length(2)+1; // staggered
28 
29  zlevels_stag[lev].resize(nz);
30 
31  stretched_dz_h[lev].resize(domain.length(2));
32 
33  if (grid_stretching_ratio == 0) {
34  // This is the default for z_levels
35  for (int k = 0; k < nz; k++)
36  {
37  zlevels_stag[lev][k] = k * dx[2];
38  }
39  for (int k = 0; k < nz-1; k++)
40  {
41  stretched_dz_h[lev][k] = dx[2];
42  }
43  } else if (lev == 0) {
44  // Create stretched grid based on initial dz and stretching ratio
45  zlevels_stag[lev][0] = zsurf;
46  Real dz = dz0;
47  stretched_dz_h[lev][0] = dz0;
48  Print() << "Stretched grid levels at level : " << lev << " is " << zsurf;
49  for (int k = 1; k < nz; k++)
50  {
51  zlevels_stag[lev][k] = zlevels_stag[lev][k-1] + dz;
52  if (k < nz-1) {
53  stretched_dz_h[lev][k] = dz;
54  }
55  Print() << " " << zlevels_stag[lev][k];
56  dz *= grid_stretching_ratio;
57  }
58  Print() << std::endl;
59  } else if (lev > 0) {
60  int rr = ref_ratio[lev-1][2];
61  expand_and_interpolate_1d(zlevels_stag[lev], zlevels_stag[lev-1], rr, false);
62  for (int k = 0; k < nz-1; k++)
63  {
64  stretched_dz_h[lev][k] = (zlevels_stag[lev][k+1] - zlevels_stag[lev][k]);
65  }
66  }
67  }
68 
69  // Try reading in terrain_z_levels, which allows arbitrarily spaced grid
70  // levels to be specified and will take precedence over the
71  // grid_stretching_ratio parameter
72  ParmParse pp("erf");
73  int n_zlevels = pp.countval("terrain_z_levels");
74  if (n_zlevels > 0)
75  {
76  int nz = geom[0].Domain().length(2)+1; // staggered
77  if (n_zlevels != nz) {
78  Print() << "You supplied " << n_zlevels << " staggered terrain_z_levels " << std::endl;
79  Print() << "but n_cell+1 in the z-direction is " << nz << std::endl;
80  Abort("You must specify a z_level for every value of k");
81  }
82 
83  if (grid_stretching_ratio > 0) {
84  Print() << "Note: Found terrain_z_levels, ignoring grid_stretching_ratio" << std::endl;
85  }
86 
87  pp.getarr("terrain_z_levels", zlevels_stag[0], 0, nz);
88 
89  // These levels should range from 0 at the surface to the height of the
90  // top of model domain (see the coordinate surface height, zeta, in
91  // Klemp 2011)
92  AMREX_ALWAYS_ASSERT(zlevels_stag[0][0] == 0);
93 
94  for (int lev = 1; lev <= max_level; lev++) {
95  int rr = ref_ratio[lev-1][2];
96  expand_and_interpolate_1d(zlevels_stag[lev], zlevels_stag[lev-1], rr, false);
97  }
98 
99  for (int lev = 0; lev <= max_level; lev++) {
100  int nz_zlevs = zlevels_stag[lev].size();
101  for (int k = 0; k < nz_zlevs-1; k++)
102  {
103  stretched_dz_h[lev][k] = (zlevels_stag[lev][k+1] - zlevels_stag[lev][k]);
104  }
105  }
106  }
107 
108  for (int lev = 0; lev <= max_level; lev++) {
109  stretched_dz_d[lev].resize(stretched_dz_h[lev].size());
110  Gpu::copy(Gpu::hostToDevice, stretched_dz_h[lev].begin(), stretched_dz_h[lev].end(), stretched_dz_d[lev].begin());
111  }
112 }
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:219

Referenced by ERF::ERF_shared().

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