ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_DirectionSelector.H
Go to the documentation of this file.
1 
2 #ifndef ERF_DirectionSelector_H
3 #define ERF_DirectionSelector_H
4 
5 #include "AMReX_Box.H"
6 #include "AMReX_Gpu.H"
7 
8 /**
9  * Utility routines for selecting index based on direction input
10  */
11 
12 template <int Index>
14 {
15  [[nodiscard]] int getIndx (int i, int j, int k) const;
16 };
17 
18 template <>
20 {
21  [[nodiscard]] AMREX_GPU_HOST_DEVICE static int getIndx (int i, int, int) { return i; }
22 };
23 
24 template <>
26 {
27  [[nodiscard]] AMREX_GPU_HOST_DEVICE static int getIndx (int, int j, int) { return j; }
28 };
29 
30 template <>
32 {
33  [[nodiscard]] AMREX_GPU_HOST_DEVICE static int getIndx (int, int, int k) { return k; }
34 };
35 
39 
40 /**
41  * Given a box, return a 2D box perpendicular to the selected axis.
42  * For example, if we're using ZDir, return a box covering the x-y plane.
43  * The IntVect is used to set the constant index in the parallel direction.
44  *
45  * @param[in] bx Initial box for computing of perpendicular box
46  * @param[in] iv IntVect defining the perpendicular direction
47  */
48 
49 template <typename IndexSelector>
50 AMREX_GPU_HOST_DEVICE amrex::Box
51 PerpendicularBox (const amrex::Box& bx, const amrex::IntVect& iv)
52 {
53  amrex::IntVect plane_lo, plane_hi;
54 
55  if (std::is_same<IndexSelector, XDir>::value) {
56  plane_lo = {iv[0], bx.smallEnd(1), bx.smallEnd(2)};
57  plane_hi = {iv[0], bx.bigEnd(1), bx.bigEnd(2)};
58  } else if (std::is_same<IndexSelector, YDir>::value) {
59  plane_lo = {bx.smallEnd(0), iv[1], bx.smallEnd(2)};
60  plane_hi = {bx.bigEnd(0), iv[1], bx.bigEnd(2)};
61  } else {
62  plane_lo = {bx.smallEnd(0), bx.smallEnd(1), iv[2]};
63  plane_hi = {bx.bigEnd(0), bx.bigEnd(1), iv[2]};
64  }
65 
66  amrex::Box pbx(plane_lo, plane_hi, bx.type());
67 
68  return pbx;
69 }
70 
71 /**
72  * Given a box, return a 1D box parallel to the selected axis.
73  * For example, if we're using ZDir, return a box covering the z axis.
74  * The IntVect is used to set the constant indices in the perpendicular
75  * direction.
76  *
77  * @param[in] bx Initial box for computing of perpendicular box
78  * @param[in] iv IntVect defining the perpendicular direction
79  */
80 
81 template <typename IndexSelector>
82 AMREX_GPU_HOST_DEVICE amrex::Box
83 ParallelBox (const amrex::Box& bx, const amrex::IntVect& iv)
84 {
85  amrex::IntVect line_lo, line_hi;
86 
87  if (std::is_same<IndexSelector, XDir>::value) {
88  line_lo = {bx.smallEnd(0), iv[1], iv[2]};
89  line_hi = {bx.bigEnd(0), iv[1], iv[2]};
90  } else if (std::is_same<IndexSelector, YDir>::value) {
91  line_lo = {iv[0], bx.smallEnd(1), iv[2]};
92  line_hi = {iv[0], bx.bigEnd(1), iv[2]};
93  } else {
94  line_lo = {iv[0], iv[1], bx.smallEnd(2)};
95  line_hi = {iv[0], iv[1], bx.bigEnd(2)};
96  }
97 
98  amrex::Box lbx(line_lo, line_hi, bx.type());
99 
100  return lbx;
101 }
102 
103 #endif /* ERF_DirectionSelector.H */
AMREX_GPU_HOST_DEVICE amrex::Box ParallelBox(const amrex::Box &bx, const amrex::IntVect &iv)
Definition: ERF_DirectionSelector.H:83
AMREX_GPU_HOST_DEVICE amrex::Box PerpendicularBox(const amrex::Box &bx, const amrex::IntVect &iv)
Definition: ERF_DirectionSelector.H:51
Definition: ERF_DirectionSelector.H:20
static AMREX_GPU_HOST_DEVICE int getIndx(int i, int, int)
Definition: ERF_DirectionSelector.H:21
Definition: ERF_DirectionSelector.H:26
static AMREX_GPU_HOST_DEVICE int getIndx(int, int j, int)
Definition: ERF_DirectionSelector.H:27
Definition: ERF_DirectionSelector.H:32
static AMREX_GPU_HOST_DEVICE int getIndx(int, int, int k)
Definition: ERF_DirectionSelector.H:33
Definition: ERF_DirectionSelector.H:14
int getIndx(int i, int j, int k) const