Block-Structured AMR Software Framework
AMReX_RealBox.H
Go to the documentation of this file.
1 
2 #ifndef AMREX_RealBox_H_
3 #define AMREX_RealBox_H_
4 #include <AMReX_Config.H>
5 
6 #include <AMReX_Array.H>
7 #include <AMReX_Vector.H>
8 #include <AMReX_REAL.H>
9 #include <AMReX_Box.H>
10 #include <AMReX_RealVect.H>
11 #include <AMReX_SPACE.H>
12 
13 #include <iosfwd>
14 #include <array>
15 
16 namespace amrex {
17 
19 
20 class RealBox
21 {
22 public:
24  constexpr RealBox () noexcept = default;
25 
28  RealBox (const Real* a_lo, const Real* a_hi) noexcept
29  : xlo{AMREX_D_DECL(a_lo[0],a_lo[1],a_lo[2])}, xhi{AMREX_D_DECL(a_hi[0],a_hi[1],a_hi[2])} {}
30 
31  RealBox (const std::array<Real,AMREX_SPACEDIM>& a_lo,
32  const std::array<Real,AMREX_SPACEDIM>& a_hi) noexcept;
33 
38  RealBox (const Box& bx, const Real* dx, const Real* base) noexcept;
41  RealBox (AMREX_D_DECL(Real x0, Real y0, Real z0),
42  AMREX_D_DECL(Real x1, Real y1, Real z1)) noexcept
43  : xlo{AMREX_D_DECL(x0,y0,z0)}, xhi{AMREX_D_DECL(x1,y1,z1)} {}
45  [[nodiscard]] AMREX_GPU_HOST_DEVICE
46  const Real* lo () const& noexcept { return xlo; }
48  const Real* lo () && = delete;
50  [[nodiscard]] AMREX_GPU_HOST_DEVICE
51  const Real* hi () const& noexcept { return xhi; }
53  const Real* hi () && = delete;
55  [[nodiscard]] AMREX_GPU_HOST_DEVICE
56  Real lo (int dir) const noexcept { return xlo[dir]; }
58  [[nodiscard]] AMREX_GPU_HOST_DEVICE
59  Real hi (int dir) const noexcept { return xhi[dir]; }
61  [[nodiscard]] AMREX_GPU_HOST_DEVICE
62  Real length (int dir) const noexcept { return xhi[dir]-xlo[dir]; }
64  void setLo (const Real* a_lo) noexcept { AMREX_D_EXPR(xlo[0] = a_lo[0], xlo[1] = a_lo[1], xlo[2] = a_lo[2]); }
66  void setLo (const Vector<Real>& a_lo) noexcept { AMREX_D_EXPR(xlo[0] = a_lo[0], xlo[1] = a_lo[1], xlo[2] = a_lo[2]); }
68  void setLo (const RealVect& a_lo) noexcept { AMREX_D_EXPR(xlo[0] = a_lo[0], xlo[1] = a_lo[1], xlo[2] = a_lo[2]); }
70  void setLo (int dir, Real a_lo) noexcept { BL_ASSERT(dir >= 0 && dir < AMREX_SPACEDIM); xlo[dir] = a_lo; }
72  void setHi (const Real* a_hi) noexcept { AMREX_D_EXPR(xhi[0] = a_hi[0], xhi[1] = a_hi[1], xhi[2] = a_hi[2]); }
74  void setHi (const Vector<Real>& a_hi) noexcept { AMREX_D_EXPR(xhi[0] = a_hi[0], xhi[1] = a_hi[1], xhi[2] = a_hi[2]); }
76  void setHi (const RealVect& a_hi) noexcept { AMREX_D_EXPR(xhi[0] = a_hi[0], xhi[1] = a_hi[1], xhi[2] = a_hi[2]); }
78  void setHi (int dir, Real a_hi) noexcept { BL_ASSERT(dir >= 0 && dir < AMREX_SPACEDIM); xhi[dir] = a_hi; }
80  [[nodiscard]] AMREX_GPU_HOST_DEVICE
81  bool ok () const noexcept {
82  return (length(0) >= 0.0)
83 #if (AMREX_SPACEDIM > 1)
84  && (length(1) >= 0.0)
85 #endif
86 #if (AMREX_SPACEDIM > 2)
87  && (length(2) >= 0.0)
88 #endif
89  ;
90  }
91 
94  [[nodiscard]] AMREX_GPU_HOST_DEVICE
95  Real volume () const noexcept {
96  if (ok()) { return AMREX_D_TERM(length(0), *length(1), *length(2)); }
97  return 0.0;
98  }
99 
101  [[nodiscard]] AMREX_GPU_HOST_DEVICE
102  bool contains (const Real* point,
103  Real eps = 0.0) const noexcept {
104  return AMREX_D_TERM((xlo[0]-eps < point[0]) && (point[0] < xhi[0]+eps),
105  && (xlo[1]-eps < point[1]) && (point[1] < xhi[1]+eps),
106  && (xlo[2]-eps < point[2]) && (point[2] < xhi[2]+eps));
107  }
108 
110  [[nodiscard]] AMREX_GPU_HOST_DEVICE
111  bool contains (XDim3 point, Real eps = 0.0) const noexcept {
112  return AMREX_D_TERM((xlo[0]-eps < point.x) && (point.x < xhi[0]+eps),
113  && (xlo[1]-eps < point.y) && (point.y < xhi[1]+eps),
114  && (xlo[2]-eps < point.z) && (point.z < xhi[2]+eps));
115  }
116 
118  [[nodiscard]] AMREX_GPU_HOST_DEVICE
119  bool contains (const RealVect& rv,
120  Real eps=0.0) const noexcept { return contains(rv.dataPtr(), eps); }
121 
123  [[nodiscard]] AMREX_GPU_HOST_DEVICE
124  bool contains (const RealBox& rb,
125  Real eps = 0.0) const noexcept {
126  return contains(rb.xlo, eps) && contains(rb.xhi, eps);
127  }
128 
130  [[nodiscard]] AMREX_GPU_HOST_DEVICE
131  bool intersects (const RealBox& bx) const noexcept {
132  return ! (AMREX_D_TERM((xlo[0] > bx.xhi[0]) || (xhi[0] < bx.xlo[0]),
133  || (xlo[1] > bx.xhi[1]) || (xhi[1] < bx.xlo[1]),
134  || (xlo[2] > bx.xhi[2]) || (xhi[2] < bx.xlo[2])));
135  }
136 
137 private:
138  //
139  // The data.
140  //
141  Real xlo[AMREX_SPACEDIM] = {AMREX_D_DECL(Real(0.),Real(0.),Real(0.))};
142  Real xhi[AMREX_SPACEDIM] = {AMREX_D_DECL(Real(-1.),Real(-1.),Real(-1.))};
143 };
144 
145 //
147 std::ostream& operator<< (std::ostream&, const RealBox&);
148 //
150 std::istream& operator>> (std::istream&, RealBox&);
151 
153 bool AlmostEqual (const RealBox& box1,
154  const RealBox& box2,
155  Real eps = 0.0) noexcept;
156 
157 }
158 
159 #endif /*_RealBox_H_*/
#define BL_ASSERT(EX)
Definition: AMReX_BLassert.H:39
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
#define AMREX_D_EXPR(a, b, c)
Definition: AMReX_SPACE.H:81
#define AMREX_D_TERM(a, b, c)
Definition: AMReX_SPACE.H:129
#define AMREX_D_DECL(a, b, c)
Definition: AMReX_SPACE.H:104
A Box with real dimensions. A RealBox is OK iff volume >= 0.
Definition: AMReX_RealBox.H:21
AMREX_GPU_HOST_DEVICE RealBox(AMREX_D_DECL(Real x0, Real y0, Real z0), AMREX_D_DECL(Real x1, Real y1, Real z1)) noexcept
Explicit dimension specific constructors.
Definition: AMReX_RealBox.H:41
void setLo(int dir, Real a_lo) noexcept
Sets lo side in specified direction.
Definition: AMReX_RealBox.H:70
AMREX_GPU_HOST_DEVICE Real volume() const noexcept
Definition: AMReX_RealBox.H:95
constexpr RealBox() noexcept=default
The default constructor. Builds invalid RealBox.
AMREX_GPU_HOST_DEVICE bool ok() const noexcept
Is the RealBox OK; i.e. does it have non-negative volume?
Definition: AMReX_RealBox.H:81
void setLo(const Real *a_lo) noexcept
Sets lo side.
Definition: AMReX_RealBox.H:64
AMREX_GPU_HOST_DEVICE const Real * hi() &&=delete
void setHi(const Vector< Real > &a_hi) noexcept
Sets hi side.
Definition: AMReX_RealBox.H:74
void setHi(int dir, Real a_hi) noexcept
Sets hi side in specified direction.
Definition: AMReX_RealBox.H:78
AMREX_GPU_HOST_DEVICE bool contains(const Real *point, Real eps=0.0) const noexcept
Is the specified point contained in the RealBox?
Definition: AMReX_RealBox.H:102
AMREX_GPU_HOST_DEVICE bool contains(XDim3 point, Real eps=0.0) const noexcept
Is the specified point contained in the RealBox?
Definition: AMReX_RealBox.H:111
AMREX_GPU_HOST_DEVICE const Real * hi() const &noexcept
Returns hide side.
Definition: AMReX_RealBox.H:51
AMREX_GPU_HOST_DEVICE Real hi(int dir) const noexcept
Returns hi side in specified direction.
Definition: AMReX_RealBox.H:59
AMREX_GPU_HOST_DEVICE bool contains(const RealVect &rv, Real eps=0.0) const noexcept
Is the specified RealVect contained in this RealBox?
Definition: AMReX_RealBox.H:119
AMREX_GPU_HOST_DEVICE bool intersects(const RealBox &bx) const noexcept
Does the specified RealBox intersect with this RealBox?
Definition: AMReX_RealBox.H:131
void setHi(const RealVect &a_hi) noexcept
Sets hi side.
Definition: AMReX_RealBox.H:76
void setLo(const RealVect &a_lo) noexcept
Sets lo side.
Definition: AMReX_RealBox.H:68
void setLo(const Vector< Real > &a_lo) noexcept
Sets lo side.
Definition: AMReX_RealBox.H:66
AMREX_GPU_HOST_DEVICE const Real * lo() const &noexcept
Returns lo side.
Definition: AMReX_RealBox.H:46
void setHi(const Real *a_hi) noexcept
Sets hi side.
Definition: AMReX_RealBox.H:72
Real xlo[AMREX_SPACEDIM]
Definition: AMReX_RealBox.H:141
AMREX_GPU_HOST_DEVICE Real lo(int dir) const noexcept
Returns length in specified direction.
Definition: AMReX_RealBox.H:56
AMREX_GPU_HOST_DEVICE bool contains(const RealBox &rb, Real eps=0.0) const noexcept
Is the specified RealBox contained in this RealBox?
Definition: AMReX_RealBox.H:124
AMREX_GPU_HOST_DEVICE Real length(int dir) const noexcept
Returns length in specified direction.
Definition: AMReX_RealBox.H:62
AMREX_GPU_HOST_DEVICE const Real * lo() &&=delete
Real xhi[AMREX_SPACEDIM]
Definition: AMReX_RealBox.H:142
A Real vector in SpaceDim-dimensional space.
Definition: AMReX_RealVect.H:32
AMREX_GPU_HOST_DEVICE const Real * dataPtr() const noexcept
Definition: AMReX_RealVect.H:488
constexpr double eps
Definition: AMReX_MLNodeLap_K.H:19
Definition: AMReX_Amr.cpp:49
BoxND< AMREX_SPACEDIM > Box
Definition: AMReX_BaseFwd.H:27
bool AlmostEqual(const RealBox &box1, const RealBox &box2, Real eps) noexcept
Check for equality of real boxes within a certain tolerance.
Definition: AMReX_RealBox.cpp:84
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Definition: AMReX_AmrMesh.cpp:1236
std::istream & operator>>(std::istream &is, BoxND< dim > &bx)
Read from istream.
Definition: AMReX_Box.H:1700
Definition: AMReX_Dim3.H:13
Real x
Definition: AMReX_Dim3.H:13
Real z
Definition: AMReX_Dim3.H:13
Real y
Definition: AMReX_Dim3.H:13