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  /**
16  * Get the coordinate index for the selected direction.
17  *
18  * @param i x-index
19  * @param j y-index
20  * @param k z-index
21  * @return The index corresponding to the selected direction
22  */
23  [[nodiscard]] int getIndx (int i, int j, int k) const;
24 };
25 
26 /**
27  * Specialization of DirectionSelector for the x-direction.
28  */
29 template <>
31 {
32  [[nodiscard]] AMREX_GPU_HOST_DEVICE static int getIndx (int i, int, int) { return i; }
33 };
34 
35 /**
36  * Specialization of DirectionSelector for the y-direction.
37  */
38 template <>
40 {
41  [[nodiscard]] AMREX_GPU_HOST_DEVICE static int getIndx (int, int j, int) { return j; }
42 };
43 
44 /**
45  * Specialization of DirectionSelector for the z-direction.
46  */
47 template <>
49 {
50  [[nodiscard]] AMREX_GPU_HOST_DEVICE static int getIndx (int, int, int k) { return k; }
51 };
52 
56 
57 /**
58  * Given a box, return a 2D box perpendicular to the selected axis.
59  * For example, if we're using ZDir, return a box covering the x-y plane.
60  * The IntVect is used to set the constant index in the parallel direction.
61  *
62  * @param[in] bx Initial box for computing of perpendicular box
63  * @param[in] iv IntVect defining the perpendicular direction
64  */
65 
66 template <typename IndexSelector>
67 AMREX_GPU_HOST_DEVICE amrex::Box
68 PerpendicularBox (const amrex::Box& bx, const amrex::IntVect& iv)
69 {
70  amrex::IntVect plane_lo, plane_hi;
71 
72  if (std::is_same<IndexSelector, XDir>::value) {
73  plane_lo = {iv[0], bx.smallEnd(1), bx.smallEnd(2)};
74  plane_hi = {iv[0], bx.bigEnd(1) , bx.bigEnd(2) };
75  } else if (std::is_same<IndexSelector, YDir>::value) {
76  plane_lo = {bx.smallEnd(0), iv[1], bx.smallEnd(2)};
77  plane_hi = {bx.bigEnd(0) , iv[1], bx.bigEnd(2) };
78  } else {
79  plane_lo = {bx.smallEnd(0), bx.smallEnd(1), iv[2]};
80  plane_hi = {bx.bigEnd(0) , bx.bigEnd(1) , iv[2]};
81  }
82 
83  amrex::Box pbx(plane_lo, plane_hi, bx.type());
84 
85  return pbx;
86 }
87 
88 /**
89  * Given a box, return a 1D box parallel to the selected axis.
90  * For example, if we're using ZDir, return a box covering the z axis.
91  * The IntVect is used to set the constant indices in the perpendicular
92  * direction.
93  *
94  * @param[in] bx Initial box for computing of perpendicular box
95  * @param[in] iv IntVect defining the perpendicular direction
96  */
97 
98 template <typename IndexSelector>
99 AMREX_GPU_HOST_DEVICE amrex::Box
100 ParallelBox (const amrex::Box& bx, const amrex::IntVect& iv)
101 {
102  amrex::IntVect line_lo, line_hi;
103 
104  if (std::is_same<IndexSelector, XDir>::value) {
105  line_lo = {bx.smallEnd(0), iv[1], iv[2]};
106  line_hi = {bx.bigEnd(0), iv[1], iv[2]};
107  } else if (std::is_same<IndexSelector, YDir>::value) {
108  line_lo = {iv[0], bx.smallEnd(1), iv[2]};
109  line_hi = {iv[0], bx.bigEnd(1), iv[2]};
110  } else {
111  line_lo = {iv[0], iv[1], bx.smallEnd(2)};
112  line_hi = {iv[0], iv[1], bx.bigEnd(2)};
113  }
114 
115  amrex::Box lbx(line_lo, line_hi, bx.type());
116 
117  return lbx;
118 }
119 
120 #endif /* ERF_DirectionSelector.H */
AMREX_GPU_HOST_DEVICE amrex::Box ParallelBox(const amrex::Box &bx, const amrex::IntVect &iv)
Definition: ERF_DirectionSelector.H:100
AMREX_GPU_HOST_DEVICE amrex::Box PerpendicularBox(const amrex::Box &bx, const amrex::IntVect &iv)
Definition: ERF_DirectionSelector.H:68
Definition: ERF_DirectionSelector.H:31
static AMREX_GPU_HOST_DEVICE int getIndx(int i, int, int)
Definition: ERF_DirectionSelector.H:32
Definition: ERF_DirectionSelector.H:40
static AMREX_GPU_HOST_DEVICE int getIndx(int, int j, int)
Definition: ERF_DirectionSelector.H:41
Definition: ERF_DirectionSelector.H:49
static AMREX_GPU_HOST_DEVICE int getIndx(int, int, int k)
Definition: ERF_DirectionSelector.H:50
Definition: ERF_DirectionSelector.H:14
int getIndx(int i, int j, int k) const