3#include <AMReX_Config.H>
23 template <
class T, std::
size_t N>
32 template <
class T,
unsigned int N>
44#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
56#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
66 const T*
data () const noexcept {
return arr; }
79 static constexpr unsigned int size () noexcept {
return N; }
86 const T*
begin () const noexcept {
return arr; }
93 const T*
end () const noexcept {
return arr + N; }
116 void fill (
const T& value )
noexcept
117 {
for (
unsigned int i = 0; i < N; ++i) {
arr[i] = value; } }
123 constexpr T
sum () const noexcept
126 for (
unsigned int i = 0; i < N; ++i) { s +=
arr[i]; }
137 for (
unsigned int i = 0; i < N; ++i) { p *=
arr[i]; }
144 for (
unsigned int i = 0; i < N; ++i) {
150#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
151#if defined(AMREX_USE_HIP)
156 static void index_assert (
int i)
158 if (i < 0 ||
static_cast<unsigned int>(i) >= N) {
165 std::stringstream ss;
166 ss << " (" << i << ") is out of bound (0:" << N-1 <<")";
191 template <
class T,
int XLO,
int XHI>
199 static constexpr unsigned int size () noexcept {
return (XHI-XLO+1); }
206 static constexpr int lo () noexcept {
return XLO; }
212 static constexpr int hi () noexcept {
return XHI; }
219 static constexpr unsigned int len () noexcept {
return (XHI-XLO+1); }
226 const T*
begin () const noexcept {
return arr; }
233 const T*
end () const noexcept {
return arr + XHI-XLO+1; }
240 T*
begin () noexcept {
return arr; }
247 T*
end () noexcept {
return arr + XHI-XLO+1; }
254 const T& operator() (
int i)
const noexcept {
255#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
266 T& operator() (
int i)
noexcept {
267#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
277 constexpr T
sum () const noexcept
280 for (
int i = XLO; i <= XHI; ++i) { s += arr[i-XLO]; }
291 for (
int i = 0; i < (XHI-XLO+1); ++i) {
296#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
297#if defined(AMREX_USE_HIP)
302 static void index_assert (
int i)
304 if (i<XLO || i>XHI) {
311 std::stringstream ss;
312 ss << " (" << i << ") is out of bound ("
313 << XLO << ":" << XHI << ")";
314 amrex::Abort(ss.str());
338 template <
class T,
int XLO,
int XHI,
int YLO,
int YHI,
339 Order ORDER = Order::F>
347 static constexpr unsigned int size() noexcept {
return (XHI-XLO+1)*(YHI-YLO+1); }
355 static constexpr int xlo () noexcept {
return XLO; }
362 static constexpr int xhi () noexcept {
return XHI; }
370 static constexpr unsigned int xlen () noexcept {
return (XHI-XLO+1); }
378 static constexpr int ylo () noexcept {
return YLO; }
385 static constexpr int yhi () noexcept {
return YHI; }
393 static constexpr unsigned int ylen () noexcept {
return (YHI-YLO+1); }
400 const T*
begin () const noexcept {
return arr; }
407 const T*
end () const noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1); }
414 T*
begin () noexcept {
return arr; }
421 T*
end () noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1); }
429 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::F,
int> = 0>
431 const T& operator() (
int i,
int j)
const noexcept {
432#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
435 return arr[i+j*(XHI-XLO+1)-(YLO*(XHI-XLO+1)+XLO)];
444 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::F,
int> = 0>
446 T& operator() (
int i,
int j)
noexcept {
447#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
450 return arr[i+j*(XHI-XLO+1)-(YLO*(XHI-XLO+1)+XLO)];
459 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::C,
int> = 0>
461 const T& operator() (
int i,
int j)
const noexcept {
462#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
465 return arr[j+i*(YHI-YLO+1)-(XLO*(YHI-YLO+1)+YLO)];
474 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::C,
int> = 0>
476 T& operator() (
int i,
int j)
noexcept {
477#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
480 return arr[j+i*(YHI-YLO+1)-(XLO*(YHI-YLO+1)+YLO)];
488 constexpr T
sum () const noexcept
491 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1); ++i) {
526 constexpr T
sum (
int axis,
int loc)
const noexcept
531 for (
int i = XLO; i <= XHI; ++i) {
532 s += this->operator()(i,j);
534 }
else if (axis == 1) {
536 for (
int j = YLO; j <= YHI; ++j) {
537 s += this->operator()(i,j);
551 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1); ++i) {
587 constexpr T
product (
int axis,
int loc)
const noexcept
592 for (
int i = XLO; i <= XHI; ++i) {
593 p *= this->operator()(i,j);
595 }
else if (axis == 1) {
597 for (
int j = YLO; j <= YHI; ++j) {
598 p *= this->operator()(i,j);
603#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
604#if defined(AMREX_USE_HIP)
609 static void index_assert (
int i,
int j)
611 if (i<XLO || i>XHI || j<YLO || j>YHI) {
614 i, j, XLO, XHI, YLO, YHI);
618 std::stringstream ss;
619 ss << " (" << i << "," << j
620 << ") is out of bound ("
621 << XLO << ":" << XHI << ","
622 << YLO << ":" << YHI << ")";
623 amrex::Abort(ss.str());
628 T arr[(XHI-XLO+1)*(YHI-YLO+1)];
645 template <
class T,
int XLO,
int XHI,
int YLO,
int YHI,
int ZLO,
int ZHI,
646 Order ORDER=Order::F>
654 static constexpr unsigned int size () noexcept {
return (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); }
662 static constexpr int xlo () noexcept {
return XLO; }
669 static constexpr int xhi () noexcept {
return XHI; }
676 static constexpr unsigned int xlen () noexcept {
return (XHI-XLO+1); }
684 static constexpr int ylo () noexcept {
return YLO; }
691 static constexpr int yhi () noexcept {
return YHI; }
699 static constexpr unsigned int ylen () noexcept {
return (YHI-YLO+1); }
707 static constexpr int zlo () noexcept {
return ZLO; }
714 static constexpr int zhi () noexcept {
return ZHI; }
721 static constexpr unsigned int zlen () noexcept {
return (ZHI-ZLO+1); }
728 const T*
begin () const noexcept {
return arr; }
735 const T*
end () const noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); }
742 T*
begin () noexcept {
return arr; }
749 T*
end () noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); }
757 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::F,
int> = 0>
759 const T& operator() (
int i,
int j,
int k)
const noexcept {
760#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
761 index_assert(i, j, k);
763 return arr[i+j*(XHI-XLO+1)+k*((XHI-XLO+1)*(YHI-YLO+1))
764 -(ZLO*((XHI-XLO+1)*(YHI-YLO+1))+YLO*(XHI-XLO+1)+XLO)];
773 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::F,
int> = 0>
775 T& operator() (
int i,
int j,
int k)
noexcept {
776#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
777 index_assert(i, j, k);
779 return arr[i+j*(XHI-XLO+1)+k*((XHI-XLO+1)*(YHI-YLO+1))
780 -(ZLO*((XHI-XLO+1)*(YHI-YLO+1))+YLO*(XHI-XLO+1)+XLO)];
789 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::C,
int> = 0>
791 const T& operator() (
int i,
int j,
int k)
const noexcept {
792#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
793 index_assert(i, j, k);
795 return arr[k+j*(ZHI-ZLO+1)+i*((ZHI-ZLO+1)*(YHI-YLO+1))
796 -(XLO*((ZHI-ZLO+1)*(YHI-YLO+1))+YLO*(ZHI-ZLO+1)+ZLO)];
805 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::C,
int> = 0>
807 T& operator() (
int i,
int j,
int k)
noexcept {
808#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
809 index_assert(i, j, k);
811 return arr[k+j*(ZHI-ZLO+1)+i*((ZHI-ZLO+1)*(YHI-YLO+1))
812 -(XLO*((ZHI-ZLO+1)*(YHI-YLO+1))+YLO*(ZHI-ZLO+1)+ZLO)];
820 constexpr T
sum () const noexcept
823 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); ++i) {
864 constexpr T
sum (
int axis,
int loc0,
int loc1)
const noexcept
870 for (
int i = XLO; i <= XHI; ++i) {
871 s += this->operator()(i,j,k);
873 }
else if (axis == 1) {
876 for (
int j = YLO; j <= YHI; ++j) {
877 s += this->operator()(i,j,k);
879 }
else if (axis == 2) {
882 for (
int k = ZLO; k <= ZHI; ++k) {
883 s += this->operator()(i,j,k);
897 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); ++i) {
939 constexpr T
product (
const int axis,
const int loc0,
const int loc1)
const noexcept
945 for (
int i = XLO; i <= XHI; ++i) {
946 p *= this->operator()(i,j,k);
948 }
else if (axis == 1) {
951 for (
int j = YLO; j <= YHI; ++j) {
952 p *= this->operator()(i,j,k);
954 }
else if (axis == 2) {
957 for (
int k = ZLO; k <= ZHI; ++k) {
958 p *= this->operator()(i,j,k);
964#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
965#if defined(AMREX_USE_HIP)
970 static void index_assert (
int i,
int j,
int k)
972 if (i<XLO || i>XHI || j<YLO || j>YHI || k<ZLO || k>ZHI) {
975 i, j, k, XLO, XHI, YLO, YHI, ZLO, ZHI);
979 std::stringstream ss;
980 ss << " (" << i << "," << j << "," << k
981 << ") is out of bound ("
982 << XLO << ":" << XHI << ","
983 << YLO << ":" << YHI << ","
984 << ZLO << ":" << ZHI << ")";
985 amrex::Abort(ss.str());
991 T arr[(XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1)];
997 template <
class T,
typename =
typename T::FABType>
998 std::array<T*,AMREX_SPACEDIM>
GetArrOfPtrs (std::array<T,AMREX_SPACEDIM>& a)
noexcept
1000 return {{
AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
1004 std::array<T*,AMREX_SPACEDIM>
GetArrOfPtrs (
const std::array<std::unique_ptr<T>,AMREX_SPACEDIM>& a)
noexcept
1010 std::array<T const*,AMREX_SPACEDIM>
GetArrOfConstPtrs (
const std::array<T,AMREX_SPACEDIM>& a)
noexcept
1012 return {{
AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
1016 std::array<T const*,AMREX_SPACEDIM>
GetArrOfConstPtrs (
const std::array<T*,AMREX_SPACEDIM>& a)
noexcept
1022 std::array<T const*,AMREX_SPACEDIM>
GetArrOfConstPtrs (
const std::array<std::unique_ptr<T>,AMREX_SPACEDIM>& a)
noexcept
1033#if (AMREX_SPACEDIM == 1)
1034 return XDim3{a[0], 0., 0.};
1035#elif (AMREX_SPACEDIM == 2)
1036 return XDim3{a[0], a[1], 0.};
1038 return XDim3{a[0], a[1], a[2]};
#define AMREX_NO_INLINE
Definition AMReX_Extension.H:136
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#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_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Definition AMReX_Amr.cpp:49
Array< int, 3 > IntArray
Definition AMReX_Array.H:27
std::array< T const *, 3 > GetArrOfConstPtrs(const std::array< T, 3 > &a) noexcept
Definition AMReX_Array.H:1010
Order
Definition AMReX_Order.H:7
__host__ __device__ constexpr GpuTupleElement< I, GpuTuple< Ts... > >::type & get(GpuTuple< Ts... > &tup) noexcept
Definition AMReX_Tuple.H:179
XDim3 makeXDim3(const Array< Real, 3 > &a) noexcept
Definition AMReX_Array.H:1031
std::array< T *, 3 > GetArrOfPtrs(std::array< T, 3 > &a) noexcept
Definition AMReX_Array.H:998
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:35
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:230
Array< Real, 3 > RealArray
Definition AMReX_Array.H:26
std::array< T, N > Array
Definition AMReX_Array.H:24
Definition AMReX_Array.H:193
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:199
__host__ static __device__ constexpr int hi() noexcept
Definition AMReX_Array.H:212
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:233
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:226
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:247
__host__ static __device__ constexpr unsigned int len() noexcept
Definition AMReX_Array.H:219
__host__ static __device__ constexpr int lo() noexcept
Definition AMReX_Array.H:206
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:277
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:240
__host__ __device__ constexpr T product() const noexcept
Definition AMReX_Array.H:288
Definition AMReX_Array.H:341
__host__ static __device__ constexpr unsigned int ylen() noexcept
Definition AMReX_Array.H:393
__host__ static __device__ constexpr int yhi() noexcept
Definition AMReX_Array.H:385
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:421
__host__ __device__ constexpr T sum(int axis, int loc) const noexcept
Definition AMReX_Array.H:526
__host__ static __device__ constexpr unsigned int xlen() noexcept
Definition AMReX_Array.H:370
__host__ static __device__ constexpr int xlo() noexcept
Definition AMReX_Array.H:355
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:400
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:488
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:414
__host__ static __device__ constexpr int ylo() noexcept
Definition AMReX_Array.H:378
__host__ __device__ constexpr T product(int axis, int loc) const noexcept
Definition AMReX_Array.H:587
__host__ __device__ constexpr T product() const noexcept
Definition AMReX_Array.H:548
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:407
__host__ static __device__ constexpr int xhi() noexcept
Definition AMReX_Array.H:362
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:347
Definition AMReX_Array.H:648
__host__ static __device__ constexpr int xlo() noexcept
Definition AMReX_Array.H:662
__host__ static __device__ constexpr int zhi() noexcept
Definition AMReX_Array.H:714
__host__ __device__ constexpr T product(const int axis, const int loc0, const int loc1) const noexcept
Definition AMReX_Array.H:939
__host__ static __device__ constexpr unsigned int xlen() noexcept
Definition AMReX_Array.H:676
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:820
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:728
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:749
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:742
__host__ __device__ constexpr T product() const noexcept
Definition AMReX_Array.H:894
__host__ __device__ constexpr T sum(int axis, int loc0, int loc1) const noexcept
Definition AMReX_Array.H:864
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:654
__host__ static __device__ constexpr int xhi() noexcept
Definition AMReX_Array.H:669
__host__ static __device__ constexpr unsigned int ylen() noexcept
Definition AMReX_Array.H:699
__host__ static __device__ constexpr int zlo() noexcept
Definition AMReX_Array.H:707
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:735
__host__ static __device__ constexpr int yhi() noexcept
Definition AMReX_Array.H:691
__host__ static __device__ constexpr int ylo() noexcept
Definition AMReX_Array.H:684
__host__ static __device__ constexpr unsigned int zlen() noexcept
Definition AMReX_Array.H:721
Definition AMReX_Array.H:34
T & reference_type
Definition AMReX_Array.H:36
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:123
T value_type
Definition AMReX_Array.H:35
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:93
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:107
__host__ __device__ const T * data() const noexcept
Definition AMReX_Array.H:66
T arr[amrex::max(N, 1U)]
Definition AMReX_Array.H:172
__host__ __device__ void fill(const T &value) noexcept
Definition AMReX_Array.H:116
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:100
__host__ __device__ T product() const noexcept
Definition AMReX_Array.H:134
__host__ __device__ T * data() noexcept
Definition AMReX_Array.H:72
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:86
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:79
__host__ __device__ const T & operator[](int i) const noexcept
Definition AMReX_Array.H:43
__host__ __device__ GpuArray< T, N > & operator+=(GpuArray< T, N > const &a) noexcept
Definition AMReX_Array.H:142
Definition AMReX_Dim3.H:13