ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_BndryPlaneIndex.H
Go to the documentation of this file.
1 #ifndef ERF_BNDRY_PLANE_INDEX_H
2 #define ERF_BNDRY_PLANE_INDEX_H
3 
4 #include <cmath>
5 
6 #include <AMReX_Extension.H>
7 #include <AMReX_GpuQualifiers.H>
8 #include <AMReX_REAL.H>
9 
10 /**
11  * The index along a boundary plane that fills the ghost cell at index i: inside the domain, i
12  * itself; outside it, the periodic image when the direction is periodic, so that a ghost cell
13  * beside the inflow face holds what the plane holds at the periodic image (as the interior cells
14  * across the seam do); else the nearest cell of the plane. A plane holds the domain's cells only
15  * along its face, so its ghost cells in the other directions come from here.
16  */
17 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
18 int bndry_plane_index (int i, int lo, int hi, bool periodic) noexcept
19 {
20  if (i >= lo && i <= hi) { return i; }
21  if (periodic) {
22  const int n = hi - lo + 1;
23  const int r = (i - lo) % n;
24  return lo + ((r < 0) ? r + n : r);
25  }
26  return (i < lo) ? lo : hi;
27 }
28 
29 /**
30  * Where a fine index sits among the level-0 plane indices along one tangential direction:
31  * the two plane indices to blend and the weight on the second. The plane holds cell-centered
32  * values in every direction (the writer averages the face velocities to cell centers), so a
33  * cell-centered index and a nodal (face) index are both located by their positions relative
34  * to the plane's cell centers. At level 0 (ratio 1) a cell-centered index is the plane cell
35  * itself with zero weight on its neighbor, and node j is the average of plane cells j - 1
36  * and j, the two cells it separates. Both indices are brought into the plane's extent, which
37  * is the level-0 domain: along a periodic direction they take the periodic image, as the
38  * interior cells across the seam do (bndry_plane_index); otherwise they are clamped.
39  */
40 struct PlaneIndex { int lo; int hi; amrex::Real w; };
41 
42 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
43 PlaneIndex plane_index (int i, int ratio, bool nodal, int plo, int phi, bool periodic) noexcept
44 {
45  using amrex::Real;
46  const Real x = (nodal ? Real(i) : Real(i) + Real(0.5)) / Real(ratio) - Real(0.5);
47  const int i0 = static_cast<int>(std::floor(x));
48  const Real w = x - Real(i0);
49  return { bndry_plane_index(i0 , plo, phi, periodic),
50  bndry_plane_index(i0+1, plo, phi, periodic), w };
51 }
52 
53 #endif
GpuArray< Real, AMREX_SPACEDIM > plo
Definition: ERF_ActuatorSpreading.cpp:131
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int bndry_plane_index(int i, int lo, int hi, bool periodic) noexcept
Definition: ERF_BndryPlaneIndex.H:18
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE PlaneIndex plane_index(int i, int ratio, bool nodal, int plo, int phi, bool periodic) noexcept
Definition: ERF_BndryPlaneIndex.H:43
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real phi(amrex::Real d, amrex::Real z0, amrex::Real psi) noexcept
Definition: ERF_ImmersedWallCell.H:176
Definition: ERF_BndryPlaneIndex.H:40
amrex::Real w
Definition: ERF_BndryPlaneIndex.H:40
int lo
Definition: ERF_BndryPlaneIndex.H:40
int hi
Definition: ERF_BndryPlaneIndex.H:40