1 #ifndef AMREX_ARRAY4_H_
2 #define AMREX_ARRAY4_H_
3 #include <AMReX_Config.H>
22 constexpr
CellData (T* a_p, Long a_stride,
int a_ncomp)
27 std::enable_if_t<std::is_const_v<U>,
int> = 0>
34 explicit operator bool() const noexcept {
return p !=
nullptr; }
40 std::enable_if_t<!std::is_void_v<U>,
int> = 0>
43 #if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
44 if (n < 0 || n >=
ncomp) {
50 ss <<
" " << n <<
" is out of bound: (0:" <<
ncomp-1 <<
")";
71 constexpr
Array4 () noexcept :
p(
nullptr) {}
73 template <
class U=T, std::enable_if_t<std::is_const_v<U>,
int> = 0>
75 constexpr
Array4 (
Array4<std::remove_const_t<T>>
const& rhs) noexcept
86 constexpr
Array4 (T* a_p,
Dim3 const& a_begin,
Dim3 const& a_end,
int a_ncomp) noexcept
98 <std::is_same_v<std::remove_const_t<T>,
99 std::remove_const_t<U>>,
int> = 0>
102 :
p((T*)(rhs.p+start_comp*rhs.nstride)),
108 ncomp(rhs.ncomp-start_comp)
113 <std::is_same_v<std::remove_const_t<T>,
114 std::remove_const_t<U>>,
int> = 0>
117 :
p((T*)(rhs.p+start_comp*rhs.nstride)),
127 explicit operator bool() const noexcept {
return p !=
nullptr; }
129 template <
class U=T, std::enable_if_t<!std::is_
void_v<U>,
int> = 0>
132 #if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
133 index_assert(i,j,k,0);
138 template <
class U=T, std::enable_if_t<!std::is_
void_v<U>,
int> = 0>
141 #if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
142 index_assert(i,j,k,n);
147 template <
class U=T, std::enable_if_t<!std::is_
void_v<U>,
int> = 0>
149 T*
ptr (
int i,
int j,
int k)
const noexcept {
150 #if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
151 index_assert(i,j,k,0);
156 template <
class U=T, std::enable_if_t<!std::is_
void_v<U>,
int> = 0>
158 T*
ptr (
int i,
int j,
int k,
int n)
const noexcept {
159 #if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
160 index_assert(i,j,k,0);
165 template <
class U=T, std::enable_if_t<!std::is_
void_v<U>,
int> = 0>
168 #if (AMREX_SPACEDIM == 1)
170 #elif (AMREX_SPACEDIM == 2)
177 template <
class U=T, std::enable_if_t<!std::is_
void_v<U>,
int> = 0>
180 #if (AMREX_SPACEDIM == 1)
182 #elif (AMREX_SPACEDIM == 2)
189 template <
class U=T, std::enable_if_t<!std::is_
void_v<U>,
int> = 0>
192 #if (AMREX_SPACEDIM == 1)
193 return this->
ptr(iv[0],0,0);
194 #elif (AMREX_SPACEDIM == 2)
195 return this->
ptr(iv[0],iv[1],0);
197 return this->
ptr(iv[0],iv[1],iv[2]);
201 template <
class U=T, std::enable_if_t<!std::is_
void_v<U>,
int> = 0>
204 #if (AMREX_SPACEDIM == 1)
205 return this->
ptr(iv[0],0,0,n);
206 #elif (AMREX_SPACEDIM == 2)
207 return this->
ptr(iv[0],iv[1],0,n);
209 return this->
ptr(iv[0],iv[1],iv[2],n);
213 template <
class U=T, std::enable_if_t<!std::is_
void_v<U>,
int> = 0>
216 return this->
operator()(cell.x,cell.y,cell.z);
219 template <
class U=T, std::enable_if_t<!std::is_
void_v<U>,
int> = 0>
222 return this->
operator()(cell.x,cell.y,cell.z,n);
225 template <
class U=T, std::enable_if_t<!std::is_
void_v<U>,
int> = 0>
228 return this->
ptr(cell.x,cell.y,cell.z);
231 template <
class U=T, std::enable_if_t<!std::is_
void_v<U>,
int> = 0>
233 T*
ptr (
Dim3 const& cell,
int n)
const noexcept {
234 return this->
ptr(cell.x,cell.y,cell.z,n);
243 std::size_t
size () const noexcept {
244 return this->nstride * this->
ncomp;
251 bool contains (
int i,
int j,
int k)
const noexcept {
264 return this->
contains(cell.x,cell.y,cell.z);
267 #if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
269 void index_assert (
int i,
int j,
int k,
int n)
const
271 if (i<begin.x || i>=
end.
x || j<begin.y || j>=
end.
y || k<begin.z || k>=
end.
z
272 || n < 0 || n >=
ncomp) {
280 std::stringstream ss;
281 ss << " (" << i << "," << j << "," << k << "," << n
282 << ") is out of bound ("
286 << "0:" <<
ncomp-1 << ")";
299 template <
class Tto,
class Tfrom>
303 return Array4<Tto>((Tto*)(a_in.p), a_in.begin, a_in.end, a_in.ncomp);
317 return Dim3{a.end.
x-1,a.end.y-1,a.end.z-1};
324 return Dim3{a.end.
x-a.begin.x,a.end.y-a.begin.y,a.end.z-a.begin.z};
327 template <
typename T>
336 template <
class A,
class Enable =
void>
struct HasMultiComp : std::false_type {};
347 template <
typename T>
360 template <class U=T, std::enable_if_t< amrex::HasMultiComp<U>::value,
int> = 0>
362 typename U::reference_type
367 template <class U=T, std::enable_if_t<!amrex::HasMultiComp<U>::value,
int> = 0>
374 template <
typename T>
375 [[nodiscard]] PolymorphicArray4<T>
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_RESTRICT
Definition: AMReX_Extension.H:37
#define AMREX_DEVICE_PRINTF(...)
Definition: AMReX_GpuPrint.H:21
#define AMREX_IF_ON_DEVICE(CODE)
Definition: AMReX_GpuQualifiers.H:56
#define AMREX_IF_ON_HOST(CODE)
Definition: AMReX_GpuQualifiers.H:58
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
#define AMREX_D_TERM(a, b, c)
Definition: AMReX_SPACE.H:129
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE Array4< Tto > ToArray4(Array4< Tfrom > const &a_in) noexcept
Definition: AMReX_Array4.H:301
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 ubound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:315
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 lbound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:308
PolymorphicArray4< T > makePolymorphic(Array4< T > const &a)
Definition: AMReX_Array4.H:376
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 length(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:322
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition: AMReX.cpp:225
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Definition: AMReX_AmrMesh.cpp:1236
Definition: AMReX_Array4.H:61
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * ptr(int i, int j, int k) const noexcept
Definition: AMReX_Array4.H:149
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * ptr(Dim3 const &cell) const noexcept
Definition: AMReX_Array4.H:227
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * ptr(IntVect const &iv, int n) const noexcept
Definition: AMReX_Array4.H:203
Long kstride
Definition: AMReX_Array4.H:64
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * ptr(Dim3 const &cell, int n) const noexcept
Definition: AMReX_Array4.H:233
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * ptr(int i, int j, int k, int n) const noexcept
Definition: AMReX_Array4.H:158
int ncomp
Definition: AMReX_Array4.H:68
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool contains(IntVect const &iv) const noexcept
Definition: AMReX_Array4.H:256
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * ptr(IntVect const &iv) const noexcept
Definition: AMReX_Array4.H:191
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nComp() const noexcept
Definition: AMReX_Array4.H:248
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::size_t size() const noexcept
Definition: AMReX_Array4.H:243
Dim3 begin
Definition: AMReX_Array4.H:66
constexpr AMREX_GPU_HOST_DEVICE Array4(Array4< U > const &rhs, int start_comp) noexcept
Definition: AMReX_Array4.H:101
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * dataPtr() const noexcept
Definition: AMReX_Array4.H:238
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool contains(Dim3 const &cell) const noexcept
Definition: AMReX_Array4.H:263
constexpr AMREX_GPU_HOST_DEVICE Array4() noexcept
Definition: AMReX_Array4.H:71
constexpr AMREX_GPU_HOST_DEVICE Array4(T *a_p, Dim3 const &a_begin, Dim3 const &a_end, int a_ncomp) noexcept
Definition: AMReX_Array4.H:86
Long jstride
Definition: AMReX_Array4.H:63
constexpr AMREX_GPU_HOST_DEVICE Array4(Array4< U > const &rhs, int start_comp, int num_comps) noexcept
Definition: AMReX_Array4.H:116
Dim3 end
Definition: AMReX_Array4.H:67
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE U & operator()(int i, int j, int k) const noexcept
Definition: AMReX_Array4.H:131
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE CellData< T > cellData(int i, int j, int k) const noexcept
Definition: AMReX_Array4.H:294
Long nstride
Definition: AMReX_Array4.H:65
T *AMREX_RESTRICT p
Definition: AMReX_Array4.H:62
constexpr AMREX_GPU_HOST_DEVICE Array4(Array4< std::remove_const_t< T >> const &rhs) noexcept
Definition: AMReX_Array4.H:75
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool contains(int i, int j, int k) const noexcept
Definition: AMReX_Array4.H:251
Definition: AMReX_Array4.H:16
int ncomp
Definition: AMReX_Array4.H:19
Long stride
Definition: AMReX_Array4.H:18
AMREX_GPU_HOST_DEVICE int nComp() const noexcept
Definition: AMReX_Array4.H:37
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE U & operator[](int n) const noexcept
Definition: AMReX_Array4.H:42
constexpr AMREX_GPU_HOST_DEVICE CellData(CellData< std::remove_const_t< T >> const &rhs) noexcept
Definition: AMReX_Array4.H:29
T *AMREX_RESTRICT p
Definition: AMReX_Array4.H:17
constexpr AMREX_GPU_HOST_DEVICE CellData(T *a_p, Long a_stride, int a_ncomp)
Definition: AMReX_Array4.H:22
Definition: AMReX_Dim3.H:12
int x
Definition: AMReX_Dim3.H:12
int z
Definition: AMReX_Dim3.H:12
int y
Definition: AMReX_Dim3.H:12
Definition: AMReX_Array4.H:336
Definition: AMReX_Array4.H:350
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE PolymorphicArray4(Array4< T > const &a)
Definition: AMReX_Array4.H:352