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)
152 static void index_assert (
int i)
154 if (i < 0 ||
static_cast<unsigned int>(i) >= N) {
161 std::stringstream ss;
162 ss << " (" << i << ") is out of bound (0:" << N-1 <<")";
187 template <
class T,
int XLO,
int XHI>
195 static constexpr unsigned int size () noexcept {
return (XHI-XLO+1); }
202 static constexpr int lo () noexcept {
return XLO; }
208 static constexpr int hi () noexcept {
return XHI; }
215 static constexpr unsigned int len () noexcept {
return (XHI-XLO+1); }
222 const T*
begin () const noexcept {
return arr; }
229 const T*
end () const noexcept {
return arr + XHI-XLO+1; }
236 T*
begin () noexcept {
return arr; }
243 T*
end () noexcept {
return arr + XHI-XLO+1; }
250 const T& operator() (
int i)
const noexcept {
251#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
262 T& operator() (
int i)
noexcept {
263#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
273 constexpr T
sum () const noexcept
276 for (
int i = XLO; i <= XHI; ++i) { s += arr[i-XLO]; }
287 for (
int i = 0; i < (XHI-XLO+1); ++i) {
292#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
294 static void index_assert (
int i)
296 if (i<XLO || i>XHI) {
303 std::stringstream ss;
304 ss << " (" << i << ") is out of bound ("
305 << XLO << ":" << XHI << ")";
306 amrex::Abort(ss.str());
330 template <
class T,
int XLO,
int XHI,
int YLO,
int YHI,
331 Order ORDER = Order::F>
339 static constexpr unsigned int size() noexcept {
return (XHI-XLO+1)*(YHI-YLO+1); }
347 static constexpr int xlo () noexcept {
return XLO; }
354 static constexpr int xhi () noexcept {
return XHI; }
362 static constexpr unsigned int xlen () noexcept {
return (XHI-XLO+1); }
370 static constexpr int ylo () noexcept {
return YLO; }
377 static constexpr int yhi () noexcept {
return YHI; }
385 static constexpr unsigned int ylen () noexcept {
return (YHI-YLO+1); }
392 const T*
begin () const noexcept {
return arr; }
399 const T*
end () const noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1); }
406 T*
begin () noexcept {
return arr; }
413 T*
end () noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1); }
421 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::F,
int> = 0>
423 const T& operator() (
int i,
int j)
const noexcept {
424#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
427 return arr[i+j*(XHI-XLO+1)-(YLO*(XHI-XLO+1)+XLO)];
436 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::F,
int> = 0>
438 T& operator() (
int i,
int j)
noexcept {
439#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
442 return arr[i+j*(XHI-XLO+1)-(YLO*(XHI-XLO+1)+XLO)];
451 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::C,
int> = 0>
453 const T& operator() (
int i,
int j)
const noexcept {
454#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
457 return arr[j+i*(YHI-YLO+1)-(XLO*(YHI-YLO+1)+YLO)];
466 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::C,
int> = 0>
468 T& operator() (
int i,
int j)
noexcept {
469#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
472 return arr[j+i*(YHI-YLO+1)-(XLO*(YHI-YLO+1)+YLO)];
480 constexpr T
sum () const noexcept
483 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1); ++i) {
514 constexpr T
sum (
int axis,
int loc)
const noexcept
519 for (
int i = XLO; i <= XHI; ++i) {
520 s += this->operator()(i,j);
522 }
else if (axis == 1) {
524 for (
int j = YLO; j <= YHI; ++j) {
525 s += this->operator()(i,j);
539 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1); ++i) {
571 constexpr T
product (
int axis,
int loc)
const noexcept
576 for (
int i = XLO; i <= XHI; ++i) {
577 p *= this->operator()(i,j);
579 }
else if (axis == 1) {
581 for (
int j = YLO; j <= YHI; ++j) {
582 p *= this->operator()(i,j);
587#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
589 static void index_assert (
int i,
int j)
591 if (i<XLO || i>XHI || j<YLO || j>YHI) {
594 i, j, XLO, XHI, YLO, YHI);
598 std::stringstream ss;
599 ss << " (" << i << "," << j
600 << ") is out of bound ("
601 << XLO << ":" << XHI << ","
602 << YLO << ":" << YHI << ")";
603 amrex::Abort(ss.str());
608 T arr[(XHI-XLO+1)*(YHI-YLO+1)];
625 template <
class T,
int XLO,
int XHI,
int YLO,
int YHI,
int ZLO,
int ZHI,
626 Order ORDER=Order::F>
634 static constexpr unsigned int size () noexcept {
return (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); }
642 static constexpr int xlo () noexcept {
return XLO; }
649 static constexpr int xhi () noexcept {
return XHI; }
656 static constexpr unsigned int xlen () noexcept {
return (XHI-XLO+1); }
664 static constexpr int ylo () noexcept {
return YLO; }
671 static constexpr int yhi () noexcept {
return YHI; }
679 static constexpr unsigned int ylen () noexcept {
return (YHI-YLO+1); }
687 static constexpr int zlo () noexcept {
return ZLO; }
694 static constexpr int zhi () noexcept {
return ZHI; }
701 static constexpr unsigned int zlen () noexcept {
return (ZHI-ZLO+1); }
708 const T*
begin () const noexcept {
return arr; }
715 const T*
end () const noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); }
722 T*
begin () noexcept {
return arr; }
729 T*
end () noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); }
737 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::F,
int> = 0>
739 const T& operator() (
int i,
int j,
int k)
const noexcept {
740#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
741 index_assert(i, j, k);
743 return arr[i+j*(XHI-XLO+1)+k*((XHI-XLO+1)*(YHI-YLO+1))
744 -(ZLO*((XHI-XLO+1)*(YHI-YLO+1))+YLO*(XHI-XLO+1)+XLO)];
753 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::F,
int> = 0>
755 T& operator() (
int i,
int j,
int k)
noexcept {
756#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
757 index_assert(i, j, k);
759 return arr[i+j*(XHI-XLO+1)+k*((XHI-XLO+1)*(YHI-YLO+1))
760 -(ZLO*((XHI-XLO+1)*(YHI-YLO+1))+YLO*(XHI-XLO+1)+XLO)];
769 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::C,
int> = 0>
771 const T& operator() (
int i,
int j,
int k)
const noexcept {
772#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
773 index_assert(i, j, k);
775 return arr[k+j*(ZHI-ZLO+1)+i*((ZHI-ZLO+1)*(YHI-YLO+1))
776 -(XLO*((ZHI-ZLO+1)*(YHI-YLO+1))+YLO*(ZHI-ZLO+1)+ZLO)];
785 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::C,
int> = 0>
787 T& operator() (
int i,
int j,
int k)
noexcept {
788#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
789 index_assert(i, j, k);
791 return arr[k+j*(ZHI-ZLO+1)+i*((ZHI-ZLO+1)*(YHI-YLO+1))
792 -(XLO*((ZHI-ZLO+1)*(YHI-YLO+1))+YLO*(ZHI-ZLO+1)+ZLO)];
800 constexpr T
sum () const noexcept
803 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); ++i) {
840 constexpr T
sum (
int axis,
int loc0,
int loc1)
const noexcept
846 for (
int i = XLO; i <= XHI; ++i) {
847 s += this->operator()(i,j,k);
849 }
else if (axis == 1) {
852 for (
int j = YLO; j <= YHI; ++j) {
853 s += this->operator()(i,j,k);
855 }
else if (axis == 2) {
858 for (
int k = ZLO; k <= ZHI; ++k) {
859 s += this->operator()(i,j,k);
873 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); ++i) {
911 constexpr T
product (
const int axis,
const int loc0,
const int loc1)
const noexcept
917 for (
int i = XLO; i <= XHI; ++i) {
918 p *= this->operator()(i,j,k);
920 }
else if (axis == 1) {
923 for (
int j = YLO; j <= YHI; ++j) {
924 p *= this->operator()(i,j,k);
926 }
else if (axis == 2) {
929 for (
int k = ZLO; k <= ZHI; ++k) {
930 p *= this->operator()(i,j,k);
936#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
938 static void index_assert (
int i,
int j,
int k)
940 if (i<XLO || i>XHI || j<YLO || j>YHI || k<ZLO || k>ZHI) {
943 i, j, k, XLO, XHI, YLO, YHI, ZLO, ZHI);
947 std::stringstream ss;
948 ss << " (" << i << "," << j << "," << k
949 << ") is out of bound ("
950 << XLO << ":" << XHI << ","
951 << YLO << ":" << YHI << ","
952 << ZLO << ":" << ZHI << ")";
953 amrex::Abort(ss.str());
959 T arr[(XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1)];
965 template <
class T,
typename =
typename T::FABType>
966 std::array<T*,AMREX_SPACEDIM>
GetArrOfPtrs (std::array<T,AMREX_SPACEDIM>& a)
noexcept
968 return {{
AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
972 std::array<T*,AMREX_SPACEDIM>
GetArrOfPtrs (
const std::array<std::unique_ptr<T>,AMREX_SPACEDIM>& a)
noexcept
978 std::array<T const*,AMREX_SPACEDIM>
GetArrOfConstPtrs (
const std::array<T,AMREX_SPACEDIM>& a)
noexcept
980 return {{
AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
984 std::array<T const*,AMREX_SPACEDIM>
GetArrOfConstPtrs (
const std::array<T*,AMREX_SPACEDIM>& a)
noexcept
990 std::array<T const*,AMREX_SPACEDIM>
GetArrOfConstPtrs (
const std::array<std::unique_ptr<T>,AMREX_SPACEDIM>& a)
noexcept
1001#if (AMREX_SPACEDIM == 1)
1002 return XDim3{a[0], 0., 0.};
1003#elif (AMREX_SPACEDIM == 2)
1004 return XDim3{a[0], a[1], 0.};
1006 return XDim3{a[0], a[1], a[2]};
#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:104
Definition AMReX_Amr.cpp:49
Order
Definition AMReX_SmallMatrix.H:19
Array< int, AMREX_SPACEDIM > IntArray
Definition AMReX_Array.H:27
XDim3 makeXDim3(const Array< Real, AMREX_SPACEDIM > &a) noexcept
Definition AMReX_Array.H:999
AMREX_GPU_HOST_DEVICE constexpr GpuTupleElement< I, GpuTuple< Ts... > >::type & get(GpuTuple< Ts... > &tup) noexcept
Definition AMReX_Tuple.H:179
Array< Real, AMREX_SPACEDIM > RealArray
Definition AMReX_Array.H:26
std::array< T *, AMREX_SPACEDIM > GetArrOfPtrs(std::array< T, AMREX_SPACEDIM > &a) noexcept
Definition AMReX_Array.H:966
std::array< T const *, AMREX_SPACEDIM > GetArrOfConstPtrs(const std::array< T, AMREX_SPACEDIM > &a) noexcept
Definition AMReX_Array.H:978
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE 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
std::array< T, N > Array
Definition AMReX_Array.H:24
Definition AMReX_Array.H:189
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * end() noexcept
Definition AMReX_Array.H:243
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr T product() const noexcept
Definition AMReX_Array.H:284
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr int lo() noexcept
Definition AMReX_Array.H:202
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr unsigned int size() noexcept
Definition AMReX_Array.H:195
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr int hi() noexcept
Definition AMReX_Array.H:208
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * begin() const noexcept
Definition AMReX_Array.H:222
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * begin() noexcept
Definition AMReX_Array.H:236
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr T sum() const noexcept
Definition AMReX_Array.H:273
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * end() const noexcept
Definition AMReX_Array.H:229
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr unsigned int len() noexcept
Definition AMReX_Array.H:215
Definition AMReX_Array.H:333
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr int xlo() noexcept
Definition AMReX_Array.H:347
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr T sum(int axis, int loc) const noexcept
Definition AMReX_Array.H:514
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr int yhi() noexcept
Definition AMReX_Array.H:377
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr unsigned int xlen() noexcept
Definition AMReX_Array.H:362
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr T sum() const noexcept
Definition AMReX_Array.H:480
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr T product() const noexcept
Definition AMReX_Array.H:536
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr T product(int axis, int loc) const noexcept
Definition AMReX_Array.H:571
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * begin() noexcept
Definition AMReX_Array.H:406
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * end() noexcept
Definition AMReX_Array.H:413
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr int xhi() noexcept
Definition AMReX_Array.H:354
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * end() const noexcept
Definition AMReX_Array.H:399
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr int ylo() noexcept
Definition AMReX_Array.H:370
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr unsigned int ylen() noexcept
Definition AMReX_Array.H:385
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * begin() const noexcept
Definition AMReX_Array.H:392
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr unsigned int size() noexcept
Definition AMReX_Array.H:339
Definition AMReX_Array.H:628
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr unsigned int size() noexcept
Definition AMReX_Array.H:634
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr int xlo() noexcept
Definition AMReX_Array.H:642
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr unsigned int ylen() noexcept
Definition AMReX_Array.H:679
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr int yhi() noexcept
Definition AMReX_Array.H:671
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr unsigned int xlen() noexcept
Definition AMReX_Array.H:656
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr T product(const int axis, const int loc0, const int loc1) const noexcept
Definition AMReX_Array.H:911
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr T sum(int axis, int loc0, int loc1) const noexcept
Definition AMReX_Array.H:840
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * end() noexcept
Definition AMReX_Array.H:729
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr unsigned int zlen() noexcept
Definition AMReX_Array.H:701
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr int xhi() noexcept
Definition AMReX_Array.H:649
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * begin() noexcept
Definition AMReX_Array.H:722
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr int zlo() noexcept
Definition AMReX_Array.H:687
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * end() const noexcept
Definition AMReX_Array.H:715
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr int zhi() noexcept
Definition AMReX_Array.H:694
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * begin() const noexcept
Definition AMReX_Array.H:708
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr int ylo() noexcept
Definition AMReX_Array.H:664
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr T sum() const noexcept
Definition AMReX_Array.H:800
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr T product() const noexcept
Definition AMReX_Array.H:870
Definition AMReX_Array.H:34
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * end() const noexcept
Definition AMReX_Array.H:93
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * data() noexcept
Definition AMReX_Array.H:72
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * data() const noexcept
Definition AMReX_Array.H:66
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T product() const noexcept
Definition AMReX_Array.H:134
T & reference_type
Definition AMReX_Array.H:36
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * end() noexcept
Definition AMReX_Array.H:107
T value_type
Definition AMReX_Array.H:35
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & operator[](int i) const noexcept
Definition AMReX_Array.H:43
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * begin() noexcept
Definition AMReX_Array.H:100
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * begin() const noexcept
Definition AMReX_Array.H:86
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void fill(const T &value) noexcept
Definition AMReX_Array.H:116
T arr[amrex::max(N, 1U)]
Definition AMReX_Array.H:168
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuArray< T, N > & operator+=(GpuArray< T, N > const &a) noexcept
Definition AMReX_Array.H:142
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE constexpr unsigned int size() noexcept
Definition AMReX_Array.H:79
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr T sum() const noexcept
Definition AMReX_Array.H:123
Definition AMReX_Dim3.H:13