3#include <AMReX_Config.H>
25 template <
class T, std::
size_t N>
39 template <
class T,
unsigned int N>
51#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
63#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
73 const T*
data () const noexcept {
return arr; }
86 static constexpr unsigned int size () noexcept {
return N; }
93 const T*
begin () const noexcept {
return arr; }
100 const T*
end () const noexcept {
return arr + N; }
123 void fill (
const T& value )
noexcept
124 {
for (
unsigned int i = 0; i < N; ++i) {
arr[i] = value; } }
130 constexpr T
sum () const noexcept
133 for (
unsigned int i = 0; i < N; ++i) { s +=
arr[i]; }
144 for (
unsigned int i = 0; i < N; ++i) { p *=
arr[i]; }
151 for (
unsigned int i = 0; i < N; ++i) {
157#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
158#if defined(AMREX_USE_HIP)
163 static void index_assert (
int i)
165 if (i < 0 ||
static_cast<unsigned int>(i) >= N) {
172 std::stringstream ss;
173 ss << " (" << i << ") is out of bound (0:" << N-1 <<")";
198 template <
class T,
int XLO,
int XHI>
206 static constexpr unsigned int size () noexcept {
return (XHI-XLO+1); }
213 static constexpr int lo () noexcept {
return XLO; }
219 static constexpr int hi () noexcept {
return XHI; }
226 static constexpr unsigned int len () noexcept {
return (XHI-XLO+1); }
233 const T*
begin () const noexcept {
return arr; }
240 const T*
end () const noexcept {
return arr + XHI-XLO+1; }
247 T*
begin () noexcept {
return arr; }
254 T*
end () noexcept {
return arr + XHI-XLO+1; }
261 const T& operator() (
int i)
const noexcept {
262#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
273 T& operator() (
int i)
noexcept {
274#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
284 constexpr T
sum () const noexcept
287 for (
int i = XLO; i <= XHI; ++i) { s += arr[i-XLO]; }
298 for (
int i = 0; i < (XHI-XLO+1); ++i) {
303#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
304#if defined(AMREX_USE_HIP)
309 static void index_assert (
int i)
311 if (i<XLO || i>XHI) {
318 std::stringstream ss;
319 ss << " (" << i << ") is out of bound ("
320 << XLO << ":" << XHI << ")";
321 amrex::Abort(ss.str());
345 template <
class T,
int XLO,
int XHI,
int YLO,
int YHI,
346 Order ORDER = Order::F>
354 static constexpr unsigned int size() noexcept {
return (XHI-XLO+1)*(YHI-YLO+1); }
362 static constexpr int xlo () noexcept {
return XLO; }
369 static constexpr int xhi () noexcept {
return XHI; }
377 static constexpr unsigned int xlen () noexcept {
return (XHI-XLO+1); }
385 static constexpr int ylo () noexcept {
return YLO; }
392 static constexpr int yhi () noexcept {
return YHI; }
400 static constexpr unsigned int ylen () noexcept {
return (YHI-YLO+1); }
407 const T*
begin () const noexcept {
return arr; }
414 const T*
end () const noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1); }
421 T*
begin () noexcept {
return arr; }
428 T*
end () noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1); }
436 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::F,
int> = 0>
438 const T& operator() (
int i,
int j)
const 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::F,
int> = 0>
453 T& operator() (
int i,
int j)
noexcept {
454#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
457 return arr[i+j*(XHI-XLO+1)-(YLO*(XHI-XLO+1)+XLO)];
466 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::C,
int> = 0>
468 const T& operator() (
int i,
int j)
const noexcept {
469#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
472 return arr[j+i*(YHI-YLO+1)-(XLO*(YHI-YLO+1)+YLO)];
481 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::C,
int> = 0>
483 T& operator() (
int i,
int j)
noexcept {
484#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
487 return arr[j+i*(YHI-YLO+1)-(XLO*(YHI-YLO+1)+YLO)];
495 constexpr T
sum () const noexcept
498 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1); ++i) {
533 constexpr T
sum (
int axis,
int loc)
const noexcept
538 for (
int i = XLO; i <= XHI; ++i) {
539 s += this->operator()(i,j);
541 }
else if (axis == 1) {
543 for (
int j = YLO; j <= YHI; ++j) {
544 s += this->operator()(i,j);
558 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1); ++i) {
594 constexpr T
product (
int axis,
int loc)
const noexcept
599 for (
int i = XLO; i <= XHI; ++i) {
600 p *= this->operator()(i,j);
602 }
else if (axis == 1) {
604 for (
int j = YLO; j <= YHI; ++j) {
605 p *= this->operator()(i,j);
610#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
611#if defined(AMREX_USE_HIP)
616 static void index_assert (
int i,
int j)
618 if (i<XLO || i>XHI || j<YLO || j>YHI) {
621 i, j, XLO, XHI, YLO, YHI);
625 std::stringstream ss;
626 ss << " (" << i << "," << j
627 << ") is out of bound ("
628 << XLO << ":" << XHI << ","
629 << YLO << ":" << YHI << ")";
630 amrex::Abort(ss.str());
635 T arr[(XHI-XLO+1)*(YHI-YLO+1)];
652 template <
class T,
int XLO,
int XHI,
int YLO,
int YHI,
int ZLO,
int ZHI,
653 Order ORDER=Order::F>
661 static constexpr unsigned int size () noexcept {
return (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); }
669 static constexpr int xlo () noexcept {
return XLO; }
676 static constexpr int xhi () noexcept {
return XHI; }
683 static constexpr unsigned int xlen () noexcept {
return (XHI-XLO+1); }
691 static constexpr int ylo () noexcept {
return YLO; }
698 static constexpr int yhi () noexcept {
return YHI; }
706 static constexpr unsigned int ylen () noexcept {
return (YHI-YLO+1); }
714 static constexpr int zlo () noexcept {
return ZLO; }
721 static constexpr int zhi () noexcept {
return ZHI; }
728 static constexpr unsigned int zlen () noexcept {
return (ZHI-ZLO+1); }
735 const T*
begin () const noexcept {
return arr; }
742 const T*
end () const noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); }
749 T*
begin () noexcept {
return arr; }
756 T*
end () noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); }
764 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::F,
int> = 0>
766 const T& operator() (
int i,
int j,
int k)
const noexcept {
767#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
768 index_assert(i, j, k);
770 return arr[i+j*(XHI-XLO+1)+k*((XHI-XLO+1)*(YHI-YLO+1))
771 -(ZLO*((XHI-XLO+1)*(YHI-YLO+1))+YLO*(XHI-XLO+1)+XLO)];
780 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::F,
int> = 0>
782 T& operator() (
int i,
int j,
int k)
noexcept {
783#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
784 index_assert(i, j, k);
786 return arr[i+j*(XHI-XLO+1)+k*((XHI-XLO+1)*(YHI-YLO+1))
787 -(ZLO*((XHI-XLO+1)*(YHI-YLO+1))+YLO*(XHI-XLO+1)+XLO)];
796 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::C,
int> = 0>
798 const T& operator() (
int i,
int j,
int k)
const noexcept {
799#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
800 index_assert(i, j, k);
802 return arr[k+j*(ZHI-ZLO+1)+i*((ZHI-ZLO+1)*(YHI-YLO+1))
803 -(XLO*((ZHI-ZLO+1)*(YHI-YLO+1))+YLO*(ZHI-ZLO+1)+ZLO)];
812 template <Order Ord=ORDER, std::enable_if_t<Ord==Order::C,
int> = 0>
814 T& operator() (
int i,
int j,
int k)
noexcept {
815#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
816 index_assert(i, j, k);
818 return arr[k+j*(ZHI-ZLO+1)+i*((ZHI-ZLO+1)*(YHI-YLO+1))
819 -(XLO*((ZHI-ZLO+1)*(YHI-YLO+1))+YLO*(ZHI-ZLO+1)+ZLO)];
827 constexpr T
sum () const noexcept
830 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); ++i) {
871 constexpr T
sum (
int axis,
int loc0,
int loc1)
const noexcept
877 for (
int i = XLO; i <= XHI; ++i) {
878 s += this->operator()(i,j,k);
880 }
else if (axis == 1) {
883 for (
int j = YLO; j <= YHI; ++j) {
884 s += this->operator()(i,j,k);
886 }
else if (axis == 2) {
889 for (
int k = ZLO; k <= ZHI; ++k) {
890 s += this->operator()(i,j,k);
904 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); ++i) {
946 constexpr T
product (
const int axis,
const int loc0,
const int loc1)
const noexcept
952 for (
int i = XLO; i <= XHI; ++i) {
953 p *= this->operator()(i,j,k);
955 }
else if (axis == 1) {
958 for (
int j = YLO; j <= YHI; ++j) {
959 p *= this->operator()(i,j,k);
961 }
else if (axis == 2) {
964 for (
int k = ZLO; k <= ZHI; ++k) {
965 p *= this->operator()(i,j,k);
971#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
972#if defined(AMREX_USE_HIP)
977 static void index_assert (
int i,
int j,
int k)
979 if (i<XLO || i>XHI || j<YLO || j>YHI || k<ZLO || k>ZHI) {
982 i, j, k, XLO, XHI, YLO, YHI, ZLO, ZHI);
986 std::stringstream ss;
987 ss << " (" << i << "," << j << "," << k
988 << ") is out of bound ("
989 << XLO << ":" << XHI << ","
990 << YLO << ":" << YHI << ","
991 << ZLO << ":" << ZHI << ")";
992 amrex::Abort(ss.str());
998 T arr[(XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1)];
1004 template <
class T,
typename =
typename T::FABType>
1005 std::array<T*,AMREX_SPACEDIM>
GetArrOfPtrs (std::array<T,AMREX_SPACEDIM>& a)
noexcept
1007 return {{
AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
1011 std::array<T*,AMREX_SPACEDIM>
GetArrOfPtrs (
const std::array<std::unique_ptr<T>,AMREX_SPACEDIM>& a)
noexcept
1017 std::array<T const*,AMREX_SPACEDIM>
GetArrOfConstPtrs (
const std::array<T,AMREX_SPACEDIM>& a)
noexcept
1019 return {{
AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
1023 std::array<T const*,AMREX_SPACEDIM>
GetArrOfConstPtrs (
const std::array<T*,AMREX_SPACEDIM>& a)
noexcept
1029 std::array<T const*,AMREX_SPACEDIM>
GetArrOfConstPtrs (
const std::array<std::unique_ptr<T>,AMREX_SPACEDIM>& a)
noexcept
1040#if (AMREX_SPACEDIM == 1)
1041 return XDim3{a[0], 0., 0.};
1042#elif (AMREX_SPACEDIM == 2)
1043 return XDim3{a[0], a[1], 0.};
1045 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
std::array< T, N > Array
Definition AMReX_Array.H:26
Definition AMReX_Amr.cpp:49
Array< int, 3 > IntArray
Definition AMReX_Array.H:29
std::array< T const *, 3 > GetArrOfConstPtrs(const std::array< T, 3 > &a) noexcept
Definition AMReX_Array.H:1017
Order
Definition AMReX_Order.H:7
XDim3 makeXDim3(const Array< Real, 3 > &a) noexcept
Definition AMReX_Array.H:1038
std::array< T *, 3 > GetArrOfPtrs(std::array< T, 3 > &a) noexcept
Definition AMReX_Array.H:1005
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:44
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:28
__host__ __device__ constexpr int get(IntVectND< dim > const &iv) noexcept
Get I'th element of IntVectND<dim>
Definition AMReX_IntVect.H:1230
Definition AMReX_Array.H:200
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:206
__host__ static __device__ constexpr int hi() noexcept
Definition AMReX_Array.H:219
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:240
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:233
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:254
__host__ static __device__ constexpr unsigned int len() noexcept
Definition AMReX_Array.H:226
__host__ static __device__ constexpr int lo() noexcept
Definition AMReX_Array.H:213
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:284
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:247
__host__ __device__ constexpr T product() const noexcept
Definition AMReX_Array.H:295
Definition AMReX_Array.H:348
__host__ static __device__ constexpr unsigned int ylen() noexcept
Definition AMReX_Array.H:400
__host__ static __device__ constexpr int yhi() noexcept
Definition AMReX_Array.H:392
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:428
__host__ __device__ constexpr T sum(int axis, int loc) const noexcept
Definition AMReX_Array.H:533
__host__ static __device__ constexpr unsigned int xlen() noexcept
Definition AMReX_Array.H:377
__host__ static __device__ constexpr int xlo() noexcept
Definition AMReX_Array.H:362
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:407
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:495
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:421
__host__ static __device__ constexpr int ylo() noexcept
Definition AMReX_Array.H:385
__host__ __device__ constexpr T product(int axis, int loc) const noexcept
Definition AMReX_Array.H:594
__host__ __device__ constexpr T product() const noexcept
Definition AMReX_Array.H:555
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:414
__host__ static __device__ constexpr int xhi() noexcept
Definition AMReX_Array.H:369
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:354
Definition AMReX_Array.H:655
__host__ static __device__ constexpr int xlo() noexcept
Definition AMReX_Array.H:669
__host__ static __device__ constexpr int zhi() noexcept
Definition AMReX_Array.H:721
__host__ __device__ constexpr T product(const int axis, const int loc0, const int loc1) const noexcept
Definition AMReX_Array.H:946
__host__ static __device__ constexpr unsigned int xlen() noexcept
Definition AMReX_Array.H:683
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:827
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:735
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:756
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:749
__host__ __device__ constexpr T product() const noexcept
Definition AMReX_Array.H:901
__host__ __device__ constexpr T sum(int axis, int loc0, int loc1) const noexcept
Definition AMReX_Array.H:871
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:661
__host__ static __device__ constexpr int xhi() noexcept
Definition AMReX_Array.H:676
__host__ static __device__ constexpr unsigned int ylen() noexcept
Definition AMReX_Array.H:706
__host__ static __device__ constexpr int zlo() noexcept
Definition AMReX_Array.H:714
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:742
__host__ static __device__ constexpr int yhi() noexcept
Definition AMReX_Array.H:698
__host__ static __device__ constexpr int ylo() noexcept
Definition AMReX_Array.H:691
__host__ static __device__ constexpr unsigned int zlen() noexcept
Definition AMReX_Array.H:728
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:41
T & reference_type
Definition AMReX_Array.H:43
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:130
T value_type
Definition AMReX_Array.H:42
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:100
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:114
__host__ __device__ const T * data() const noexcept
Definition AMReX_Array.H:73
T arr[amrex::max(N, 1U)]
Definition AMReX_Array.H:179
__host__ __device__ void fill(const T &value) noexcept
Definition AMReX_Array.H:123
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:107
__host__ __device__ T product() const noexcept
Definition AMReX_Array.H:141
__host__ __device__ T * data() noexcept
Definition AMReX_Array.H:79
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:93
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:86
__host__ __device__ const T & operator[](int i) const noexcept
Definition AMReX_Array.H:50
__host__ __device__ GpuArray< T, N > & operator+=(GpuArray< T, N > const &a) noexcept
Definition AMReX_Array.H:149
Definition AMReX_Dim3.H:13