ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_LengthScaleCellSize.H
Go to the documentation of this file.
1 #ifndef ERF_LENGTH_SCALE_CELL_SIZE_H_
2 #define ERF_LENGTH_SCALE_CELL_SIZE_H_
3 
4 #include <AMReX_Array.H>
5 #include <AMReX_Box.H>
6 #include <AMReX_Geometry.H>
7 #include <AMReX_REAL.H>
8 
9 /**
10  * Cell sizes for formulas that use a lateral cell size as a length scale rather than to
11  * divide a difference: LES filter widths, scale-aware parameterizations, drag rates and
12  * per-area densities.
13  *
14  * On a domain with one cell in y and more than one in x (an x-z run), dy is arbitrary, so
15  * dx is used in its place; likewise dy replaces dx on a domain with one cell in x. The
16  * formula then keeps its 3-D form, as if the unresolved direction had the spacing of the
17  * resolved one. A single column (one cell in both) keeps the dx and dy of the inputs as
18  * its nominal column size.
19  *
20  * The level's own domain decides: a lateral direction with one cell is not refined
21  * (amr.ref_ratio_vect = r 1 r), so it has one cell on every level, and the spacing copied
22  * is that of the level.
23  *
24  * @param[in] geom geometry of the level
25  * @return dx, dy and dz with the substitution above
26  */
27 inline amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>
28 LengthScaleCellSize (const amrex::Geometry& geom)
29 {
30  amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> dx = geom.CellSizeArray();
31  const amrex::Box& domain = geom.Domain();
32  const int nx = domain.length(0);
33  const int ny = domain.length(1);
34  if (ny == 1 && nx > 1) {
35  dx[1] = dx[0];
36  } else if (nx == 1 && ny > 1) {
37  dx[0] = dx[1];
38  }
39  return dx;
40 }
41 
42 /**
43  * Inverse of LengthScaleCellSize.
44  *
45  * @param[in] geom geometry of the level
46  * @return 1/dx, 1/dy and 1/dz with the substitution of LengthScaleCellSize
47  */
48 inline amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>
49 LengthScaleInvCellSize (const amrex::Geometry& geom)
50 {
51  amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> dxinv = geom.InvCellSizeArray();
52  const amrex::Box& domain = geom.Domain();
53  const int nx = domain.length(0);
54  const int ny = domain.length(1);
55  if (ny == 1 && nx > 1) {
56  dxinv[1] = dxinv[0];
57  } else if (nx == 1 && ny > 1) {
58  dxinv[0] = dxinv[1];
59  }
60  return dxinv;
61 }
62 
63 #endif
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
const int nx
Definition: ERF_InitCustomPertVels_CloudChamber.H:14
const int ny
Definition: ERF_InitCustomPertVels_CloudChamber.H:15
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > LengthScaleCellSize(const amrex::Geometry &geom)
Definition: ERF_LengthScaleCellSize.H:28
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > LengthScaleInvCellSize(const amrex::Geometry &geom)
Definition: ERF_LengthScaleCellSize.H:49