Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
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
11#include <AMReX.H>
12#include <AMReX_REAL.H>
13#include <AMReX_Array.H>
14#include <AMReX_Vector.H>
15#include <AMReX_Box.H>
16
17#include <limits>
18
19namespace amrex {
20
21class FArrayBox;
22
31{
32public:
33
35 enum CoordType { undef = -1, cartesian = 0, RZ = 1, SPHERICAL = 2 };
37 friend std::ostream& operator<< (std::ostream&, const CoordSys& );
38
40 friend std::istream& operator>> (std::istream&, CoordSys& );
41
43 [[nodiscard]] bool Ok () const noexcept { return ok; }
44
46 void SetCoord (CoordType coord) noexcept { c_sys = coord; }
47
49 [[nodiscard]] CoordType Coord () const noexcept { return c_sys; }
50
52 [[nodiscard]] int CoordInt () const noexcept { return static_cast<int>(c_sys); }
53
55 [[nodiscard]] bool IsSPHERICAL () const noexcept {
56 BL_ASSERT(c_sys != undef); return (c_sys == SPHERICAL);
57 }
58
60 [[nodiscard]] bool IsRZ () const noexcept {
61 BL_ASSERT(c_sys != undef); return (c_sys == RZ);
62 }
63
65 [[nodiscard]] bool IsCartesian () const noexcept {
66 BL_ASSERT(c_sys != undef); return (c_sys == cartesian);
67 }
68
70 void SetOffset (const Real* x_lo) noexcept;
71
73 [[nodiscard]] const Real* Offset () const noexcept { return offset; }
74
76 [[nodiscard]] Real Offset (int dir) const noexcept { return offset[dir]; }
77
79 [[nodiscard]] const Real* CellSize () const noexcept { BL_ASSERT(ok); return dx; }
80
82 [[nodiscard]] Real CellSize (int dir) const noexcept { BL_ASSERT(ok); return dx[dir]; }
83
85 [[nodiscard]] GpuArray<Real,AMREX_SPACEDIM> CellSizeArray () const noexcept {
87 return {{ AMREX_D_DECL(dx[0],dx[1],dx[2]) }};
88 }
89
91 [[nodiscard]] const Real* InvCellSize () const noexcept { BL_ASSERT(ok); return inv_dx; }
92
94 [[nodiscard]] Real InvCellSize (int dir) const noexcept { BL_ASSERT(ok); return inv_dx[dir]; }
95
97 [[nodiscard]] GpuArray<Real,AMREX_SPACEDIM> InvCellSizeArray () const noexcept {
99 return {{ AMREX_D_DECL(inv_dx[0],inv_dx[1],inv_dx[2]) }};
100 }
101
103 [[nodiscard]] Real CellCenter (int point, int dir) const noexcept
104 {
105 BL_ASSERT(ok); return offset[dir] + dx[dir]*((Real)0.5+ (Real)point);
106 }
107
113 void CellCenter (const IntVect& point, Vector<Real>& loc) const noexcept;
114
120 void CellCenter (const IntVect& point, Real* loc) const noexcept;
121
123 [[nodiscard]] Real LoEdge (int point, int dir) const noexcept
124 {
125 BL_ASSERT(ok); return offset[dir] + dx[dir]*static_cast<Real>(point);
126 }
127
129 [[nodiscard]] Real LoEdge (const IntVect& point, int dir) const noexcept
130 {
131 BL_ASSERT(ok); return offset[dir] + dx[dir]*static_cast<Real>(point[dir]);
132 }
133
135 [[nodiscard]] Real HiEdge (int point, int dir) const noexcept
136 {
137 BL_ASSERT(ok); return offset[dir] + dx[dir]*static_cast<Real>(point + 1);
138 }
139
141 [[nodiscard]] Real HiEdge (const IntVect& point, int dir) const noexcept
142 {
143 BL_ASSERT(ok); return offset[dir] + dx[dir]*static_cast<Real>(point[dir] + 1);
144 }
145
152 void LoFace (const IntVect& point, int dir, Vector<Real>& loc) const noexcept;
153
160 void LoFace (const IntVect& point, int dir, Real* loc) const noexcept;
161
168 void HiFace (const IntVect& point, int dir, Vector<Real>& loc) const noexcept;
169
176 void HiFace (const IntVect& point, int dir, Real* loc) const noexcept;
177
183 void LoNode (const IntVect& point, Vector<Real>& loc) const noexcept;
184
190 void LoNode (const IntVect& point, Real* loc) const noexcept;
191
197 void HiNode (const IntVect& point, Vector<Real>& loc) const noexcept;
198
204 void HiNode (const IntVect& point, Real* loc) const noexcept;
213 IntVect CellIndex (const Real* point) const noexcept;
220 IntVect LowerIndex (const Real* point) const noexcept;
227 IntVect UpperIndex (const Real* point) const noexcept;
235 void SetVolume (FArrayBox& a_volfab, const Box& region) const;
243 void GetVolume (FArrayBox& vol, const Box& region) const;
252 void SetDLogA (FArrayBox& a_dlogafab, const Box& region, int dir) const;
261 void GetDLogA (FArrayBox& dloga, const Box& region, int dir) const;
262
267 [[nodiscard]] Real Volume (const IntVect& point) const;
268
270 [[nodiscard]] Real Volume (const Real xlo[AMREX_SPACEDIM],
271 const Real xhi[AMREX_SPACEDIM]) const;
272
277 void SetFaceArea (FArrayBox& a_areafab, const Box& region, int dir) const;
278
283 void GetFaceArea (FArrayBox& area, const Box& region, int dir) const;
284
286 [[nodiscard]] Real AreaLo (const IntVect& point, int dir) const noexcept;
287
289 [[nodiscard]] Real AreaHi (const IntVect& point, int dir) const noexcept;
290
295 void GetEdgeLoc (Vector<Real>& loc, const Box& region, int dir) const;
296
301 void GetCellLoc (Vector<Real>& loc, const Box& region, int dir) const;
302
307 void GetEdgeVolCoord (Vector<Real>& vc, const Box& region, int dir) const;
308
313 void GetCellVolCoord (Vector<Real>& vc, const Box& region, int dir) const;
314
315protected:
316 // c_sys and offset used to be static
318 Real offset[AMREX_SPACEDIM];
319
320 Real dx[AMREX_SPACEDIM] = {AMREX_D_DECL(0.,0.,0.)};
321 Real inv_dx[AMREX_SPACEDIM]
322 = {AMREX_D_DECL(std::numeric_limits<Real>::max(),
323 std::numeric_limits<Real>::max(),
324 std::numeric_limits<Real>::max())};
325 bool ok = false;
326};
327
328}
329
330#endif /*_COORDSYS_H_*/
Runtime initialization/finalization helpers and global diagnostics.
Fixed-size array types for use on GPU and CPU.
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
Integer-lattice boxes and helpers for defining index-space regions.
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Coordinate system; provides mapping between physical space and index space.
Definition AMReX_CoordSys.H:31
friend std::ostream & operator<<(std::ostream &, const CoordSys &)
Nice ASCII output.
Definition AMReX_CoordSys.cpp:447
const Real * CellSize() const noexcept
Returns the cellsize for each coordinate direction.
Definition AMReX_CoordSys.H:79
const Real * Offset() const noexcept
Returns the offset.
Definition AMReX_CoordSys.H:73
bool Ok() const noexcept
Is ok?
Definition AMReX_CoordSys.H:43
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:304
GpuArray< Real, 3 > CellSizeArray() const noexcept
Returns the cell sizes as a GpuArray for use on host or device.
Definition AMReX_CoordSys.H:85
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:174
IntVect CellIndex(const Real *point) const noexcept
Returns cell-centered index of cell containing point.
Definition AMReX_CoordSys.cpp:135
void LoNode(const IntVect &point, Vector< Real > &loc) const noexcept
Return the location of the lower-left node of the cell.
Definition AMReX_CoordSys.cpp:107
void SetCoord(CoordType coord) noexcept
Set the CoordType.
Definition AMReX_CoordSys.H:46
CoordType Coord() const noexcept
Returns the CoordType.
Definition AMReX_CoordSys.H:49
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:258
int CoordInt() const noexcept
Returns the CoordType as an int.
Definition AMReX_CoordSys.H:52
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:323
Real InvCellSize(int dir) const noexcept
Returns the inverse cellsize for the specified coordinate direction.
Definition AMReX_CoordSys.H:94
bool IsCartesian() const noexcept
Is CoordType == cartesian?
Definition AMReX_CoordSys.H:65
Real offset[3]
Definition AMReX_CoordSys.H:318
Real CellCenter(int point, int dir) const noexcept
Returns location of cell center in specified direction.
Definition AMReX_CoordSys.H:103
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:385
friend std::istream & operator>>(std::istream &, CoordSys &)
Nice ASCII input.
Definition AMReX_CoordSys.cpp:467
Real HiEdge(const IntVect &point, int dir) const noexcept
Equivalent to HiEdge(point[dir], dir).
Definition AMReX_CoordSys.H:141
void HiNode(const IntVect &point, Vector< Real > &loc) const noexcept
Return the location of the upper-right node of the cell.
Definition AMReX_CoordSys.cpp:127
Real LoEdge(const IntVect &point, int dir) const noexcept
Equivalent to LoEdge(point[dir], dir).
Definition AMReX_CoordSys.H:129
Real inv_dx[3]
Definition AMReX_CoordSys.H:322
IntVect UpperIndex(const Real *point) const noexcept
Returns nodal index of upper right hand corner of cell containing this point.
Definition AMReX_CoordSys.cpp:161
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:182
Real AreaHi(const IntVect &point, int dir) const noexcept
Returns hi face area of given cell in direction dir.
Definition AMReX_CoordSys.cpp:582
CoordType c_sys
Definition AMReX_CoordSys.H:317
const Real * InvCellSize() const noexcept
Returns the inverse cellsize for each coordinate direction.
Definition AMReX_CoordSys.H:91
bool IsSPHERICAL() const noexcept
Is CoordType == SPHERICAL?
Definition AMReX_CoordSys.H:55
void HiFace(const IntVect &point, int dir, Vector< Real > &loc) const noexcept
Compute the physical location of the upper face in direction dir.
Definition AMReX_CoordSys.cpp:86
Real HiEdge(int point, int dir) const noexcept
Returns location of hi edge in specified direction.
Definition AMReX_CoordSys.H:135
Real dx[3]
Definition AMReX_CoordSys.H:320
Real Offset(int dir) const noexcept
Returns the offset for the specified coordinate direction.
Definition AMReX_CoordSys.H:76
Real LoEdge(int point, int dir) const noexcept
Returns location of lo edge in specified direction.
Definition AMReX_CoordSys.H:123
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:218
GpuArray< Real, 3 > InvCellSizeArray() const noexcept
Returns the inverse cell sizes as a GpuArray for use on host or device.
Definition AMReX_CoordSys.H:97
Real Volume(const IntVect &point) const
Return the physical volume of the specified cell.
Definition AMReX_CoordSys.cpp:495
void LoFace(const IntVect &point, int dir, Vector< Real > &loc) const noexcept
Compute the physical location of the lower face in direction dir.
Definition AMReX_CoordSys.cpp:63
bool ok
Definition AMReX_CoordSys.H:325
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:209
void SetOffset(const Real *x_lo) noexcept
Sets the offset for each coordinate direction.
Definition AMReX_CoordSys.cpp:21
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:285
IntVect LowerIndex(const Real *point) const noexcept
Returns nodal index of lower-left corner of cell containing this point.
Definition AMReX_CoordSys.cpp:148
Real AreaLo(const IntVect &point, int dir) const noexcept
Returns lo face area of given cell in direction dir.
Definition AMReX_CoordSys.cpp:528
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:247
CoordType
Coordinate system type: undefined, Cartesian, cylindrical (RZ), or spherical.
Definition AMReX_CoordSys.H:35
@ RZ
Definition AMReX_CoordSys.H:35
@ undef
Definition AMReX_CoordSys.H:35
@ cartesian
Definition AMReX_CoordSys.H:35
@ SPHERICAL
Definition AMReX_CoordSys.H:35
Real CellSize(int dir) const noexcept
Returns the cellsize for the specified coordinate direction.
Definition AMReX_CoordSys.H:82
bool IsRZ() const noexcept
Is CoordType == RZ?
Definition AMReX_CoordSys.H:60
A Fortran Array of REALs.
Definition AMReX_FArrayBox.H:237
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:79
Definition AMReX_Amr.cpp:50
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:52