Block-Structured AMR Software Framework
AMReX_CoordSys.H
Go to the documentation of this file.
1 
2 #ifndef AMREX_COORDSYS_H_
3 #define AMREX_COORDSYS_H_
4 #include <AMReX_Config.H>
5 
6 #include <AMReX.H>
7 #include <AMReX_REAL.H>
8 #include <AMReX_Array.H>
9 #include <AMReX_Vector.H>
10 #include <AMReX_Box.H>
11 
12 #include <limits>
13 
14 namespace amrex {
15 
16 class FArrayBox;
17 
23 class CoordSys
24 {
25 public:
26 
27  enum CoordType { undef = -1, cartesian = 0, RZ = 1, SPHERICAL = 2 };
29  friend std::ostream& operator<< (std::ostream&, const CoordSys& );
30 
32  friend std::istream& operator>> (std::istream&, CoordSys& );
33 
35  [[nodiscard]] bool Ok () const noexcept { return ok; }
36 
38  void SetCoord (CoordType coord) noexcept { c_sys = coord; }
39 
41  [[nodiscard]] CoordType Coord () const noexcept { return c_sys; }
42 
44  [[nodiscard]] int CoordInt () const noexcept { return static_cast<int>(c_sys); }
45 
47  [[nodiscard]] bool IsSPHERICAL () const noexcept {
48  BL_ASSERT(c_sys != undef); return (c_sys == SPHERICAL);
49  }
50 
52  [[nodiscard]] bool IsRZ () const noexcept {
53  BL_ASSERT(c_sys != undef); return (c_sys == RZ);
54  }
55 
57  [[nodiscard]] bool IsCartesian () const noexcept {
58  BL_ASSERT(c_sys != undef); return (c_sys == cartesian);
59  }
60 
62  void SetOffset (const Real* x_lo) noexcept;
63 
65  [[nodiscard]] const Real* Offset () const noexcept { return offset; }
66 
68  [[nodiscard]] Real Offset (int dir) const noexcept { return offset[dir]; }
69 
71  [[nodiscard]] const Real* CellSize () const noexcept { BL_ASSERT(ok); return dx; }
72 
74  [[nodiscard]] Real CellSize (int dir) const noexcept { BL_ASSERT(ok); return dx[dir]; }
75 
76  [[nodiscard]] GpuArray<Real,AMREX_SPACEDIM> CellSizeArray () const noexcept {
77  BL_ASSERT(ok);
78  return {{ AMREX_D_DECL(dx[0],dx[1],dx[2]) }};
79  }
80 
82  [[nodiscard]] const Real* InvCellSize () const noexcept { BL_ASSERT(ok); return inv_dx; }
83 
85  [[nodiscard]] Real InvCellSize (int dir) const noexcept { BL_ASSERT(ok); return inv_dx[dir]; }
86 
87  [[nodiscard]] GpuArray<Real,AMREX_SPACEDIM> InvCellSizeArray () const noexcept {
88  BL_ASSERT(ok);
89  return {{ AMREX_D_DECL(inv_dx[0],inv_dx[1],inv_dx[2]) }};
90  }
91 
93  [[nodiscard]] Real CellCenter (int point, int dir) const noexcept
94  {
95  BL_ASSERT(ok); return offset[dir] + dx[dir]*((Real)0.5+ (Real)point);
96  }
97 
99  void CellCenter (const IntVect& point, Vector<Real>& loc) const noexcept;
100 
102  void CellCenter (const IntVect& point, Real* loc) const noexcept;
103 
105  [[nodiscard]] Real LoEdge (int point, int dir) const noexcept
106  {
107  BL_ASSERT(ok); return offset[dir] + dx[dir]*static_cast<Real>(point);
108  }
109 
111  [[nodiscard]] Real LoEdge (const IntVect& point, int dir) const noexcept
112  {
113  BL_ASSERT(ok); return offset[dir] + dx[dir]*static_cast<Real>(point[dir]);
114  }
115 
117  [[nodiscard]] Real HiEdge (int point, int dir) const noexcept
118  {
119  BL_ASSERT(ok); return offset[dir] + dx[dir]*static_cast<Real>(point + 1);
120  }
121 
123  [[nodiscard]] Real HiEdge (const IntVect& point, int dir) const noexcept
124  {
125  BL_ASSERT(ok); return offset[dir] + dx[dir]*static_cast<Real>(point[dir] + 1);
126  }
127 
129  void LoFace (const IntVect& point, int dir, Vector<Real>& loc) const noexcept;
130 
132  void LoFace (const IntVect& point, int dir, Real* loc) const noexcept;
133 
135  void HiFace (const IntVect& point, int dir, Vector<Real>& loc) const noexcept;
136 
138  void HiFace (const IntVect& point, int dir, Real* loc) const noexcept;
139 
141  void LoNode (const IntVect& point, Vector<Real>& loc) const noexcept;
142 
144  void LoNode (const IntVect& point, Real* loc) const noexcept;
145 
147  void HiNode (const IntVect& point, Vector<Real>& loc) const noexcept;
148 
150  void HiNode (const IntVect& point, Real* loc) const noexcept;
156  IntVect CellIndex (const Real* point) const noexcept;
161  IntVect LowerIndex (const Real* point) const noexcept;
166  IntVect UpperIndex (const Real* point) const noexcept;
171  void SetVolume (FArrayBox& a_volfab, const Box& region) const;
176  void GetVolume (FArrayBox& vol, const Box& region) const;
181  void SetDLogA (FArrayBox& a_dlogafab, const Box& region, int dir) const;
186  void GetDLogA (FArrayBox& dloga, const Box& region, int dir) const;
187 
189  [[nodiscard]] Real Volume (const IntVect& point) const;
190 
192  [[nodiscard]] Real Volume (const Real xlo[AMREX_SPACEDIM],
193  const Real xhi[AMREX_SPACEDIM]) const;
194 
199  void SetFaceArea (FArrayBox& a_areafab, const Box& region, int dir) const;
200 
205  void GetFaceArea (FArrayBox& area, const Box& region, int dir) const;
206 
208  [[nodiscard]] Real AreaLo (const IntVect& point, int dir) const noexcept;
209 
211  [[nodiscard]] Real AreaHi (const IntVect& point, int dir) const noexcept;
212 
217  void GetEdgeLoc (Vector<Real>& loc, const Box& region, int dir) const;
218 
223  void GetCellLoc (Vector<Real>& loc, const Box& region, int dir) const;
224 
229  void GetEdgeVolCoord (Vector<Real>& vc, const Box& region, int dir) const;
230 
235  void GetCellVolCoord (Vector<Real>& vc, const Box& region, int dir) const;
236 
237 protected:
238  // c_sys and offset used to be static
240  Real offset[AMREX_SPACEDIM];
241 
242  Real dx[AMREX_SPACEDIM] = {AMREX_D_DECL(0.,0.,0.)};
243  Real inv_dx[AMREX_SPACEDIM]
244  = {AMREX_D_DECL(std::numeric_limits<Real>::infinity(),
245  std::numeric_limits<Real>::infinity(),
246  std::numeric_limits<Real>::infinity())};
247  bool ok = false;
248 };
249 
250 }
251 
252 #endif /*_COORDSYS_H_*/
#define BL_ASSERT(EX)
Definition: AMReX_BLassert.H:39
#define AMREX_D_DECL(a, b, c)
Definition: AMReX_SPACE.H:104
Coordinate System.
Definition: AMReX_CoordSys.H:24
Real inv_dx[AMREX_SPACEDIM]
Definition: AMReX_CoordSys.H:244
bool Ok() const noexcept
Is ok?
Definition: AMReX_CoordSys.H:35
Real dx[AMREX_SPACEDIM]
Definition: AMReX_CoordSys.H:242
void GetCellLoc(Vector< Real > &loc, const Box &region, int dir) const
Return array of physical locations of cell centers in the resize()d input array.
Definition: AMReX_CoordSys.cpp:303
friend std::istream & operator>>(std::istream &, CoordSys &)
Nice ASCII input.
Definition: AMReX_CoordSys.cpp:466
void GetVolume(FArrayBox &vol, const Box &region) const
Compute cell volumes in given region and place them into resize()d input FAB.
Definition: AMReX_CoordSys.cpp:173
IntVect CellIndex(const Real *point) const noexcept
Returns cell centered index of cell containing point. This may return undesired results if point is o...
Definition: AMReX_CoordSys.cpp:134
void LoNode(const IntVect &point, Vector< Real > &loc) const noexcept
Return location of lower left hand corner.
Definition: AMReX_CoordSys.cpp:106
void SetCoord(CoordType coord) noexcept
Set the CoordType.
Definition: AMReX_CoordSys.H:38
CoordType Coord() const noexcept
Returns the CoordType.
Definition: AMReX_CoordSys.H:41
void SetFaceArea(FArrayBox &a_areafab, const Box &region, int dir) const
Compute area of cell faces in given region and given index direction and return the result in input F...
Definition: AMReX_CoordSys.cpp:257
int CoordInt() const noexcept
Returns the CoordType as an int.
Definition: AMReX_CoordSys.H:44
void GetEdgeVolCoord(Vector< Real > &vc, const Box &region, int dir) const
Return array of volume coordinates at cell edges for region in given direction.
Definition: AMReX_CoordSys.cpp:322
Real InvCellSize(int dir) const noexcept
Returns the inverse cellsize for the specified coordinate direction.
Definition: AMReX_CoordSys.H:85
friend std::ostream & operator<<(std::ostream &, const CoordSys &)
Nice ASCII output.
Definition: AMReX_CoordSys.cpp:446
bool IsCartesian() const noexcept
Is CoordType == cartesian?
Definition: AMReX_CoordSys.H:57
Real CellCenter(int point, int dir) const noexcept
Returns location of cell center in specified direction.
Definition: AMReX_CoordSys.H:93
void GetCellVolCoord(Vector< Real > &vc, const Box &region, int dir) const
Return array of volume coordinates at cell centers for region in given direction.
Definition: AMReX_CoordSys.cpp:384
Real HiEdge(const IntVect &point, int dir) const noexcept
Equivalent to HiEdge(point[dir], dir).
Definition: AMReX_CoordSys.H:123
void HiNode(const IntVect &point, Vector< Real > &loc) const noexcept
Return location of upper right hand corner.
Definition: AMReX_CoordSys.cpp:126
Real LoEdge(const IntVect &point, int dir) const noexcept
Equivalent to LoEdge(point[dir], dir).
Definition: AMReX_CoordSys.H:111
IntVect UpperIndex(const Real *point) const noexcept
Returns node centered index of upper right hand corner of cell containing this point.
Definition: AMReX_CoordSys.cpp:160
void SetVolume(FArrayBox &a_volfab, const Box &region) const
Compute cell volumes in given region and place them into input FAB.
Definition: AMReX_CoordSys.cpp:181
Real AreaHi(const IntVect &point, int dir) const noexcept
Returns hi face area of given cell in direction dir.
Definition: AMReX_CoordSys.cpp:581
CoordType c_sys
Definition: AMReX_CoordSys.H:239
bool IsSPHERICAL() const noexcept
Is CoordType == SPHERICAL?
Definition: AMReX_CoordSys.H:47
Real offset[AMREX_SPACEDIM]
Definition: AMReX_CoordSys.H:240
void HiFace(const IntVect &point, int dir, Vector< Real > &loc) const noexcept
Sets location of hi face into loc.
Definition: AMReX_CoordSys.cpp:85
const Real * Offset() const noexcept
Returns the offset.
Definition: AMReX_CoordSys.H:65
Real HiEdge(int point, int dir) const noexcept
Returns location of hi edge in specified direction.
Definition: AMReX_CoordSys.H:117
GpuArray< Real, AMREX_SPACEDIM > CellSizeArray() const noexcept
Definition: AMReX_CoordSys.H:76
Real Offset(int dir) const noexcept
Returns the offset for the specified coordinate direction.
Definition: AMReX_CoordSys.H:68
Real LoEdge(int point, int dir) const noexcept
Returns location of lo edge in specified direction.
Definition: AMReX_CoordSys.H:105
void SetDLogA(FArrayBox &a_dlogafab, const Box &region, int dir) const
Compute d(log(A))/dr at cell centers in given region and place them into input FAB.
Definition: AMReX_CoordSys.cpp:217
Real Volume(const IntVect &point) const
Return the volume of the specified cell.
Definition: AMReX_CoordSys.cpp:494
void LoFace(const IntVect &point, int dir, Vector< Real > &loc) const noexcept
Sets location of lo face into loc.
Definition: AMReX_CoordSys.cpp:62
bool ok
Definition: AMReX_CoordSys.H:247
const Real * InvCellSize() const noexcept
Returns the inverse cellsize for each coordinate direction.
Definition: AMReX_CoordSys.H:82
GpuArray< Real, AMREX_SPACEDIM > InvCellSizeArray() const noexcept
Definition: AMReX_CoordSys.H:87
void GetDLogA(FArrayBox &dloga, const Box &region, int dir) const
Compute d(log(A))/dr at cell centers in given region and return the results in the resize()d input FA...
Definition: AMReX_CoordSys.cpp:208
const Real * CellSize() const noexcept
Returns the cellsize for each coordinate direction.
Definition: AMReX_CoordSys.H:71
void SetOffset(const Real *x_lo) noexcept
Sets the offset for each coordinate direction.
Definition: AMReX_CoordSys.cpp:20
void GetEdgeLoc(Vector< Real > &loc, const Box &region, int dir) const
Return array of physical locations of cell edges in the resize()d input array.
Definition: AMReX_CoordSys.cpp:284
IntVect LowerIndex(const Real *point) const noexcept
Returns node centered index of lower left hand corner of cell containing this point.
Definition: AMReX_CoordSys.cpp:147
Real AreaLo(const IntVect &point, int dir) const noexcept
Returns lo face area of given cell in direction dir.
Definition: AMReX_CoordSys.cpp:527
void GetFaceArea(FArrayBox &area, const Box &region, int dir) const
Compute area of cell faces in given region and given index direction and return the result in resize(...
Definition: AMReX_CoordSys.cpp:246
CoordType
Definition: AMReX_CoordSys.H:27
@ RZ
Definition: AMReX_CoordSys.H:27
@ undef
Definition: AMReX_CoordSys.H:27
@ cartesian
Definition: AMReX_CoordSys.H:27
@ SPHERICAL
Definition: AMReX_CoordSys.H:27
Real CellSize(int dir) const noexcept
Returns the cellsize for the specified coordinate direction.
Definition: AMReX_CoordSys.H:74
bool IsRZ() const noexcept
Is CoordType == RZ?
Definition: AMReX_CoordSys.H:52
A Fortran Array of REALs.
Definition: AMReX_FArrayBox.H:229
Definition: AMReX_Amr.cpp:49