4#include <AMReX_Config.H>
28using Box = BoxND<AMREX_SPACEDIM>;
100 template <
typename T,
int Tdim=dim, std::enable_if_t<( 1<=Tdim && Tdim<=3 ),
int> = 0>
101 AMREX_GPU_HOST_DEVICE
102 explicit BoxND (Array4<T> const& a) noexcept
104 bigend(IntVectND<dim>(a.end) - 1)
110 [[nodiscard]] AMREX_GPU_HOST_DEVICE
111 const IntVectND<dim>& smallEnd () const& noexcept { return smallend; }
114 [[nodiscard]] const IntVectND<dim>& smallEnd () && = delete;
118 [[nodiscard]] AMREX_GPU_HOST_DEVICE
119 int smallEnd (
int dir) const& noexcept { return smallend[dir]; }
122 [[nodiscard]] AMREX_GPU_HOST_DEVICE
123 const IntVectND<dim>& bigEnd () const& noexcept { return bigend; }
126 [[nodiscard]] const IntVectND<dim>& bigEnd () && = delete;
130 [[nodiscard]] AMREX_GPU_HOST_DEVICE
131 int bigEnd (
int dir) const noexcept { return bigend[dir]; }
134 [[nodiscard]] AMREX_GPU_HOST_DEVICE
135 IndexTypeND<dim> ixType () const noexcept { return btype; }
138 [[nodiscard]] AMREX_GPU_HOST_DEVICE
139 IntVectND<dim> type () const noexcept { return btype.ixType(); }
142 [[nodiscard]] AMREX_GPU_HOST_DEVICE
143 IndexType::CellIndex type (
int dir) const noexcept { return btype.ixType(dir); }
146 [[nodiscard]] AMREX_GPU_HOST_DEVICE
147 IntVectND<dim> size () const noexcept
149 return bigend - smallend + 1;
153 [[nodiscard]] AMREX_GPU_HOST_DEVICE
154 IntVectND<dim> length () const noexcept
156 return bigend - smallend + 1;
160 [[nodiscard]] AMREX_GPU_HOST_DEVICE
161 int length (
int dir) const noexcept { return bigend[dir] - smallend[dir] + 1; }
163 template <
int N=dim, std::enable_if_t<( 1<=N && N<=3 ),
int> = 0>
164 [[nodiscard]] AMREX_GPU_HOST_DEVICE
165 GpuArray<
int,3> length3d () const noexcept {
166 Dim3 len3d = length().dim3(1);
167 return {{len3d.x, len3d.y, len3d.z}};
170 template <
int N=dim, std::enable_if_t<( 1<=N && N<=3 ),
int> = 0>
171 [[nodiscard]] AMREX_GPU_HOST_DEVICE
172 GpuArray<
int,3> loVect3d () const noexcept {
173 Dim3 lo3d = smallend.dim3(0);
174 return {{lo3d.x, lo3d.y, lo3d.z}};
177 template <
int N=dim, std::enable_if_t<( 1<=N && N<=3 ),
int> = 0>
178 [[nodiscard]] AMREX_GPU_HOST_DEVICE
179 GpuArray<
int,3> hiVect3d () const noexcept {
180 Dim3 hi3d = bigend.dim3(0);
181 return {{hi3d.x, hi3d.y, hi3d.z}};
185 [[nodiscard]] AMREX_GPU_HOST_DEVICE
186 const
int* loVect () const& noexcept { return smallend.getVect(); }
187 AMREX_GPU_HOST_DEVICE
188 const
int* loVect () && = delete;
190 [[nodiscard]] AMREX_GPU_HOST_DEVICE
191 const
int* hiVect () const& noexcept { return bigend.getVect(); }
192 AMREX_GPU_HOST_DEVICE
193 const
int* hiVect () && = delete;
196 [[nodiscard]] AMREX_GPU_HOST_DEVICE
197 int operator[] (Orientation face) const noexcept {
198 const
int dir = face.coordDir();
199 return face.isLow() ? smallend[dir] : bigend[dir];
203 [[nodiscard]] AMREX_GPU_HOST_DEVICE
204 bool isEmpty () const noexcept { return !ok(); }
207 [[nodiscard]] AMREX_GPU_HOST_DEVICE
208 bool ok () const noexcept { return bigend.allGE(smallend) && btype.ok(); }
211 [[nodiscard]] AMREX_GPU_HOST_DEVICE
212 bool contains (const IntVectND<dim>& p) const noexcept {
213 return p.allGE(smallend) && p.allLE(bigend);
217 template <
int N=dim, std::enable_if_t<( 1<=N && N<=3 ),
int> = 0>
218 [[nodiscard]] AMREX_GPU_HOST_DEVICE
219 bool contains (const Dim3& p) const noexcept {
220 IntVectND<dim> piv{p};
221 return contains(piv);
225 template <
int N=dim, std::enable_if_t<( 1<=N && N<=3 ),
int> = 0>
226 [[nodiscard]] AMREX_GPU_HOST_DEVICE
227 bool contains (
int i,
int j,
int k) const noexcept {
229 return contains(p3d);
235 [[nodiscard]] AMREX_GPU_HOST_DEVICE
236 bool contains (const BoxND& b) const noexcept
238 BL_ASSERT(sameType(b));
239 return b.smallend.allGE(smallend) && b.bigend.allLE(bigend);
243 [[nodiscard]] AMREX_GPU_HOST_DEVICE
244 bool strictly_contains (const IntVectND<dim>& p) const noexcept {
245 return p.allGT(smallend) && p.allLT(bigend);
252 [[nodiscard]] AMREX_GPU_HOST_DEVICE
253 bool strictly_contains (const BoxND& b) const noexcept
255 BL_ASSERT(sameType(b));
256 return b.smallend.allGT(smallend) && b.bigend.allLT(bigend);
260 template <
int N=dim, std::enable_if_t<( 1<=N && N<=3 ),
int> = 0>
261 [[nodiscard]] AMREX_GPU_HOST_DEVICE
262 bool strictly_contains (const Dim3& p) const noexcept {
263 IntVectND<dim> piv{p};
264 return strictly_contains(piv);
268 template <
int N=dim, std::enable_if_t<( 1<=N && N<=3 ),
int> = 0>
269 [[nodiscard]] AMREX_GPU_HOST_DEVICE
270 bool strictly_contains (
int i,
int j,
int k) const noexcept {
272 return strictly_contains(p3d);
279 [[nodiscard]] AMREX_GPU_HOST_DEVICE
280 bool intersects (const BoxND& b) const noexcept { BoxND isect(*this); isect &= b; return isect.ok(); }
286 [[nodiscard]] AMREX_GPU_HOST_DEVICE
287 bool sameSize (const BoxND& b) const noexcept {
288 BL_ASSERT(sameType(b));
289 return length() == b.length();
293 [[nodiscard]] AMREX_GPU_HOST_DEVICE
294 bool sameType (const BoxND &b) const noexcept { return btype == b.btype; }
297 [[nodiscard]] AMREX_GPU_HOST_DEVICE
298 bool operator== (const BoxND& b) const noexcept { return smallend == b.smallend && bigend == b.bigend && b.btype == btype; }
301 [[nodiscard]] AMREX_GPU_HOST_DEVICE
302 bool operator!= (const BoxND& b) const noexcept { return !operator==(b); }
304 [[nodiscard]] AMREX_GPU_HOST_DEVICE
305 bool operator< (const BoxND& rhs) const noexcept
307 return btype < rhs.btype ||
308 ((btype == rhs.btype) &&
309 ( (smallend < rhs.smallend) ||
310 ((smallend == rhs.smallend) && (bigend < rhs.bigend)) ));
312 [[nodiscard]] AMREX_GPU_HOST_DEVICE
313 bool operator <= (const BoxND& rhs) const noexcept {
314 return !(rhs < *this);
316 [[nodiscard]] AMREX_GPU_HOST_DEVICE
317 bool operator> (const BoxND& rhs) const noexcept {
320 [[nodiscard]] AMREX_GPU_HOST_DEVICE
321 bool operator>= (const BoxND& rhs) const noexcept {
322 return !(*this < rhs);
326 [[nodiscard]] AMREX_GPU_HOST_DEVICE
327 bool cellCentered () const noexcept { return !btype.any(); }
331 void checkOverflow () const noexcept {
333 for (
int i = 0; i < dim; ++i) {
334 auto lo = static_cast<Long>(smallend[i]);
335 auto hi = static_cast<Long>(bigend[i]);
336 Long len = hi - lo + 1;
337 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(len>=0 && len<std::numeric_limits<
int>::max(),
338 "Overflow when computing length of box");
340 auto num_pts = static_cast<Long>(length(0));
341 for (
int i = 1; i < dim; ++i) {
342 auto len = static_cast<Long>(length(i));
343 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(num_pts == 0 || len == 0 ||
344 num_pts <= std::numeric_limits<Long>::max() / len,
345 "Overflow when computing numPts of box");
355 [[nodiscard]] AMREX_GPU_HOST_DEVICE
356 Long numPts () const noexcept {
357#if defined(AMREX_DEBUG) || defined(AMREX_USE_ASSERTION)
358 AMREX_IF_ON_HOST((checkOverflow();))
361 auto num_pts = static_cast<Long>(length(0));
362 for (
int i = 1; i < dim; ++i) {
363 num_pts *= static_cast<Long>(length(i));
375 [[nodiscard]] AMREX_GPU_HOST_DEVICE
376 double d_numPts () const noexcept {
378 auto num_pts = static_cast<
double>(length(0));
379 for (
int i = 1; i < dim; ++i) {
380 num_pts *= static_cast<
double>(length(i));
393 [[nodiscard]] AMREX_GPU_HOST_DEVICE
394 Long volume () const noexcept {
396 auto num_pts = static_cast<Long>(length(0)-btype[0]);
397 for (
int i = 1; i < dim; ++i) {
398 num_pts *= static_cast<Long>(length(i)-btype[i]);
410 [[nodiscard]] AMREX_GPU_HOST_DEVICE
411 int longs
ide (
int& dir) const noexcept {
412 int maxlen = length(0);
414 for (
int i = 1; i < dim; i++)
416 if (length(i) > maxlen)
426 [[nodiscard]] AMREX_GPU_HOST_DEVICE
427 int longs
ide () const noexcept {
429 return
longs
ide(ignore);
436 [[nodiscard]] AMREX_GPU_HOST_DEVICE
437 int shorts
ide (
int& dir) const noexcept {
438 int minlen = length(0);
440 for (
int i = 1; i < dim; i++)
442 if (length(i) < minlen)
452 [[nodiscard]] AMREX_GPU_HOST_DEVICE
453 int shorts
ide () const noexcept {
455 return
shorts
ide(ignore);
463 [[nodiscard]] AMREX_GPU_HOST_DEVICE
464 Long index (const IntVectND<dim>& v) const noexcept;
467 [[nodiscard]] AMREX_GPU_HOST_DEVICE
468 IntVectND<dim> atOffset (Long offset) const noexcept;
473 template <
int N=dim, std::enable_if_t<( 1<=N && N<=3 ),
int> = 0>
474 [[nodiscard]] AMREX_GPU_HOST_DEVICE
475 GpuArray<
int,3> atOffset3d (Long offset) const noexcept;
478 AMREX_GPU_HOST_DEVICE
479 BoxND& setSmall (const IntVectND<dim>& sm) noexcept { smallend = sm; return *this; }
482 AMREX_GPU_HOST_DEVICE
483 BoxND& setSmall (
int dir,
int sm_index) noexcept { smallend.setVal(dir,sm_index); return *this; }
486 AMREX_GPU_HOST_DEVICE
487 BoxND& setBig (const IntVectND<dim>& bg) noexcept { bigend = bg; return *this; }
490 AMREX_GPU_HOST_DEVICE
491 BoxND& setBig (
int dir,
int bg_index) noexcept { bigend.setVal(dir,bg_index); return *this; }
498 AMREX_GPU_HOST_DEVICE
499 BoxND& setRange (
int dir,
501 int n_cells = 1) noexcept;
504 AMREX_GPU_HOST_DEVICE
505 BoxND& setType (const IndexTypeND<dim>& t) noexcept { btype = t; return *this; }
508 AMREX_GPU_HOST_DEVICE
509 BoxND& shift (
int dir,
int nzones) noexcept { smallend.shift(dir,nzones); bigend.shift(dir,nzones); return *this; }
512 AMREX_GPU_HOST_DEVICE
513 BoxND& shift (const IntVectND<dim>& iv) noexcept { smallend.shift(iv); bigend.shift(iv); return *this; }
524 AMREX_GPU_HOST_DEVICE
525 BoxND& shiftHalf (
int dir,
int num_halfs) noexcept;
528 AMREX_GPU_HOST_DEVICE
529 BoxND& shiftHalf (const IntVectND<dim>& iv) noexcept;
538 AMREX_GPU_HOST_DEVICE
539 BoxND& convert (IndexTypeND<dim> typ) noexcept;
548 AMREX_GPU_HOST_DEVICE
549 BoxND& convert (const IntVectND<dim>& typ) noexcept;
552 AMREX_GPU_HOST_DEVICE
553 BoxND& surroundingNodes () noexcept;
556 AMREX_GPU_HOST_DEVICE
557 BoxND& surroundingNodes (
int dir) noexcept;
559 AMREX_GPU_HOST_DEVICE
560 BoxND& surroundingNodes (Direction d) noexcept { return surroundingNodes(static_cast<
int>(d)); }
563 AMREX_GPU_HOST_DEVICE
564 BoxND& enclosedCells () noexcept;
567 AMREX_GPU_HOST_DEVICE
568 BoxND& enclosedCells (
int dir) noexcept;
571 AMREX_GPU_HOST_DEVICE
572 BoxND& enclosedCells (Direction d) noexcept { return enclosedCells(static_cast<
int>(d)); }
578 AMREX_GPU_HOST_DEVICE
579 BoxND operator& (const BoxND& rhs) const noexcept { BoxND lhs(*this); lhs &= rhs; return lhs; }
582 AMREX_GPU_HOST_DEVICE
583 BoxND& operator&= (const BoxND& rhs) noexcept
585 BL_ASSERT(sameType(rhs));
586 smallend.max(rhs.smallend);
587 bigend.min(rhs.bigend);
596 AMREX_GPU_HOST_DEVICE
597 BoxND& minBox (const BoxND& b) noexcept {
599 BL_ASSERT(sameType(b));
600 smallend.min(b.smallend);
601 bigend.max(b.bigend);
606 AMREX_GPU_HOST_DEVICE
607 BoxND& operator+= (const IntVectND<dim>& v) noexcept { smallend += v; bigend += v; return *this; }
610 AMREX_GPU_HOST_DEVICE
611 BoxND operator+ (const IntVectND<dim>& v) const noexcept { BoxND r(*this); r += v; return r; }
614 AMREX_GPU_HOST_DEVICE
615 BoxND& operator-= (const IntVectND<dim>& v) noexcept { smallend -= v; bigend -= v; return *this; }
618 AMREX_GPU_HOST_DEVICE
619 BoxND operator- (const IntVectND<dim>& v) const noexcept { BoxND r(*this); r -= v; return r; }
633 AMREX_GPU_HOST_DEVICE
634 BoxND chop (
int dir,
int chop_pnt) noexcept;
640 AMREX_GPU_HOST_DEVICE
641 BoxND& grow (
int i) noexcept { smallend.diagShift(-i); bigend.diagShift(i); return *this; }
644 AMREX_GPU_HOST_DEVICE
645 BoxND& grow (const IntVectND<dim>& v) noexcept { smallend -= v; bigend += v; return *this;}
651 AMREX_GPU_HOST_DEVICE
652 BoxND& grow (
int idir,
int n_cell) noexcept { smallend.shift(
idir, -n_cell); bigend.shift(
idir, n_cell); return *this; }
654 AMREX_GPU_HOST_DEVICE
655 BoxND& grow (Direction d,
int n_cell) noexcept { return grow(static_cast<
int>(d), n_cell); }
661 AMREX_GPU_HOST_DEVICE
662 BoxND& growLo (
int idir,
int n_cell = 1) noexcept { smallend.shift(
idir, -n_cell); return *this; }
664 AMREX_GPU_HOST_DEVICE
665 BoxND& growLo (Direction d,
int n_cell = 1) noexcept { return growLo(static_cast<
int>(d), n_cell); }
672 AMREX_GPU_HOST_DEVICE
673 BoxND& growHi (
int idir,
int n_cell = 1) noexcept { bigend.shift(
idir,n_cell); return *this; }
675 AMREX_GPU_HOST_DEVICE
676 BoxND& growHi (Direction d,
int n_cell = 1) noexcept { return growHi(static_cast<
int>(d), n_cell); }
679 AMREX_GPU_HOST_DEVICE
680 BoxND& grow (Orientation face,
int n_cell = 1) noexcept {
681 int idir = face.coordDir();
683 smallend.shift(
idir, -n_cell);
685 bigend.shift(
idir,n_cell);
697 AMREX_GPU_HOST_DEVICE
698 BoxND& refine (
int ref_ratio) noexcept {
699 return this->refine(IntVectND<dim>(ref_ratio));
709 AMREX_GPU_HOST_DEVICE
710 BoxND& refine (const IntVectND<dim>& ref_ratio) noexcept;
721 AMREX_GPU_HOST_DEVICE
722 BoxND& coarsen (
int ref_ratio) noexcept {
772 if (!size().allGE(refrat*min_width)) {
775 BoxND testBox = *
this;
778 return (*
this == testBox);
818 for (
int idim=0; idim < dim; ++idim) {
819 if (this->
length(idim) == 0) {
828 smallend[direction] = slab_index;
829 bigend[direction] = slab_index;
849 static constexpr std::size_t
ndims () noexcept {
850 return static_cast<std::size_t
>(dim);
854 static constexpr int indims () noexcept {
862 template<
int new_dim>
865 static_assert(new_dim <= dim);
866 auto lo = smallend.template shrink<new_dim>();
867 auto hi = bigend.template shrink<new_dim>();
868 auto typ = btype.template shrink<new_dim>();
877 template<
int new_dim>
880 static_assert(new_dim >= dim);
881 auto lo = smallend.template expand<new_dim>(0);
882 auto hi = bigend.template expand<new_dim>(0);
891 template<
int new_dim>
894 if constexpr (new_dim > dim) {
895 return expand<new_dim>();
897 return shrink<new_dim>();
913 if (ref_ratio != 1) {
915 shft -= btype.ixType();
916 smallend *= ref_ratio;
937 for (
int dir = 0; dir < dim; dir++)
940 if (bigend[dir]%ref_ratio[dir]) {
976 for (
int dir = 0; dir < dim; dir++)
978 const auto typ = t[dir];
979 const auto bitval = btype[dir];
980 const int off = typ - bitval;
981 bigend.
shift(dir,off);
1010 for (
int i = 0; i < dim; ++i) {
1011 if ((btype[i] == 0)) {
1027 bigend.
shift(dir,-1);
1042 for (
int i = 0 ; i < dim; ++i) {
1058 Long result = vz[0];
1060 for (
int i = 1 ; i < dim; ++i) {
1061 result += mult * vz[i];
1075 if constexpr (dim > 1) {
1078 for (
int i = 1 ; i < dim-1; ++i) {
1079 mult[i] = mult[i-1] *
length(i);
1081 for (
int i = dim-1 ; i > 0; --i) {
1083 offset -= idx * mult[i-1];
1084 result[i] +=
static_cast<int>(idx);
1088 result[0] +=
static_cast<int>(
offset);
1094template <
int N, std::enable_if_t<( 1<=N && N<=3 ),
int>>
1095AMREX_GPU_HOST_DEVICE
1098BoxND<dim>::atOffset3d (Long offset) const noexcept
1100 Dim3 iv3d = atOffset(offset).dim3(0);
1101 return {{iv3d.x, iv3d.y, iv3d.z}};
1110 int n_cells)
noexcept
1112 smallend.setVal(dir,sm_index);
1113 bigend.setVal(dir,sm_index+n_cells-1);
1127 for (
int i = 0 ; i < dim-1; ++i) {
1128 if (p[i] > bigend[i]) {
1143 if constexpr (dim == 1) {
1146 bool is_square =
true;
1148 for (
int i = 0 ; i < dim-1; ++i) {
1149 is_square = is_square && (sz[i] == sz[i+1]);
1178 BL_ASSERT(chop_pnt > smallend[dir] && chop_pnt < bigend[dir]);
1182 bigend.setVal(dir,chop_pnt);
1189 BL_ASSERT(chop_pnt > smallend[dir] && chop_pnt <= bigend[dir]);
1193 bigend.setVal(dir,chop_pnt-1);
1204 const int nbit = (num_halfs<0 ? -num_halfs : num_halfs)%2;
1205 int nshift = num_halfs/2;
1209 const unsigned int bit_dir = btype[dir];
1213 if (num_halfs < 0) {
1214 nshift -= (bit_dir ? nbit : 0);
1216 nshift += (bit_dir ? 0 : nbit);
1218 smallend.
shift(dir,nshift);
1219 bigend.
shift(dir,nshift);
1229 for (
int i = 0; i < dim; i++) {
1240 explicit BoxCommHelper (
const Box& bx,
int* p_ =
nullptr);
1242 [[nodiscard]]
int* data () const& noexcept {
return p; }
1243 int* data () && =
delete;
1245 [[nodiscard]] Box make_box () const noexcept {
1246 return Box(IntVect(p), IntVect(p+AMREX_SPACEDIM), IntVect(p+2*AMREX_SPACEDIM));
1249 [[nodiscard]]
static int size () noexcept {
return 3*AMREX_SPACEDIM; }
1347 return grow(b,
static_cast<int>(d), n_cell);
1367 return growLo(b,
static_cast<int>(d), n_cell);
1387 return growHi(b,
static_cast<int>(d), n_cell);
1486 result.
refine(ref_ratio);
1498 result.
shift(dir, nzones);
1509 result.
shift(nzones);
1630 low.
setVal(dir,sm-len+1);
1652 auto const bitval = b.
type()[dir];
1653 int bg = hi[dir] + 1 - bitval%2;
1680 low.
setVal(dir,sm-len+1);
1685 int bitval = b.
type()[dir];
1686 int bg = hi[dir] + 1 - bitval%2;
1720 low.
setVal(dir,sm - len);
1740 int bitval = b.
type()[dir];
1741 int bg = hi[dir] + 1 - bitval%2;
1743 hi.
setVal(dir,bg + len - 1);
1766 low.
setVal(dir,sm - len);
1771 int bitval = b.
type()[dir];
1772 int bg = hi[dir] + 1 - bitval%2;
1774 hi.
setVal(dir,bg + len - 1);
1802 std::ostream& box_write (std::ostream& os,
const int * smallend,
const int * bigend,
1803 const int * type,
int dim);
1804 std::istream& box_read (std::istream& is,
int * smallend,
int * bigend,
int * type,
int dim);
1806 template<std::size_t...Ns,
class T,
class U>
1808 auto BoxSplit_imp (std::index_sequence<Ns...>,
1809 const T& lo,
const T& hi,
const U& typ)
noexcept {
1810 return makeTuple(BoxND(get<Ns>(lo), get<Ns>(hi), get<Ns>(typ))...);
1820 return detail::box_write(os, bx.
smallEnd().begin(), bx.
bigEnd().begin(), type.
begin(), dim);
1838template<
int d,
int...dims>
1841constexpr BoxND<detail::get_sum<d, dims...>()>
1846 return BoxND<detail::get_sum<d, dims...>()>{lo, hi, typ};
1853template<
int d,
int...dims>
1856constexpr GpuTuple<BoxND<d>, BoxND<dims>...>
1861 return detail::BoxSplit_imp(std::make_index_sequence<1 +
sizeof...(dims)>(), lo, hi, typ);
1868template<
int new_dim,
int old_dim>
1871constexpr BoxND<new_dim>
1873 return bx.template shrink<new_dim>();
1881template<
int new_dim,
int old_dim>
1884constexpr BoxND<new_dim>
1886 return bx.template expand<new_dim>();
1893template<
int new_dim,
int old_dim>
1896constexpr BoxND<new_dim>
1898 return bx.template resize<new_dim>();
1907 return box.smallEnd();
1916 return box.bigEnd();
1925 return box.smallEnd();
1934 return box.bigEnd() + 1;
1943 return box.bigEnd() - box.smallEnd() + 1;
1953 return max(b1.smallEnd(), b2.smallEnd());
1962 return max(b1.smallEnd(), lo);
1972 return min(b1.bigEnd(), b2.bigEnd());
1981 return min(b1.bigEnd(), hi);
1984template<
int dim, std::enable_if_t<( 1<=dim && dim<=3 ),
int> = 0>
1986AMREX_GPU_HOST_DEVICE
1988Dim3 lbound (BoxND<dim> const& box) noexcept
1990 return box.smallEnd().dim3();
1993template<
int dim, std::enable_if_t<( 1<=dim && dim<=3 ),
int> = 0>
1995AMREX_GPU_HOST_DEVICE
1997Dim3 ubound (BoxND<dim> const& box) noexcept
1999 return box.bigEnd().dim3();
2002template<
int dim, std::enable_if_t<( 1<=dim && dim<=3 ),
int> = 0>
2004AMREX_GPU_HOST_DEVICE
2006Dim3 begin (BoxND<dim> const& box) noexcept
2008 return box.smallEnd().dim3();
2011template<
int dim, std::enable_if_t<( 1<=dim && dim<=3 ),
int> = 0>
2013AMREX_GPU_HOST_DEVICE
2015Dim3 end (BoxND<dim> const& box) noexcept
2017 return (box.bigEnd() + 1).dim3(1);
2020template<
int dim, std::enable_if_t<( 1<=dim && dim<=3 ),
int> = 0>
2022AMREX_GPU_HOST_DEVICE
2024Dim3 length (BoxND<dim> const& box) noexcept
2026 return (box.bigEnd() - box.smallEnd() + 1).dim3(1);
2030template<
int dim, std::enable_if_t<( 1<=dim && dim<=3 ),
int> = 0>
2032AMREX_GPU_HOST_DEVICE
2034Dim3 max_lbound (BoxND<dim> const& b1, BoxND<dim> const& b2) noexcept
2036 return max(b1.smallEnd(), b2.smallEnd()).dim3();
2039template<
int dim, std::enable_if_t<( 1<=dim && dim<=3 ),
int> = 0>
2041AMREX_GPU_HOST_DEVICE
2043Dim3 max_lbound (BoxND<dim> const& b1, Dim3 const& lo) noexcept
2045 return max(b1.smallEnd(), IntVectND<dim>(lo)).dim3();
2049template<
int dim, std::enable_if_t<( 1<=dim && dim<=3 ),
int> = 0>
2051AMREX_GPU_HOST_DEVICE
2053Dim3 min_ubound (BoxND<dim> const& b1, BoxND<dim> const& b2) noexcept
2055 return min(b1.bigEnd(), b2.bigEnd()).dim3();
2058template<
int dim, std::enable_if_t<( 1<=dim && dim<=3 ),
int> = 0>
2060AMREX_GPU_HOST_DEVICE
2062Dim3 min_ubound (BoxND<dim> const& b1, Dim3 const& hi) noexcept
2064 return min(b1.bigEnd(), IntVectND<dim>(hi)).dim3();
2090template <
class T,
class ... Ts>
2106 Long ncells_subtotal = 0;
2108 for (ibox = 0; ibox < nboxes; ++ibox) {
2110 ncells_subtotal += n;
2111 if (icell < ncells_subtotal) {
2112 offset = icell - (ncells_subtotal - n);
2130template<
int dim=AMREX_SPACEDIM, std::enable_if_t<( 1<=dim && dim<=3 ),
int> = 0>
2132AMREX_GPU_HOST_DEVICE
2134BoxND<dim> makeSingleCellBox (
int i,
int j,
int k, IndexTypeND<dim> typ = IndexTypeND<dim>::TheCellType())
2137 IntVectND<dim> vect{p3d};
2138 return BoxND<dim>{vect, vect, typ};
2158 : npts(box.numPts()),
2161 std::uint64_t mult = 1;
2162 for (
int i=0; i<dim-1; ++i) {
2173 for (
int i=dim-1; i>0; --i) {
2174 std::uint64_t quotient, remainder;
2175 fdm[i-1](quotient, remainder, icell);
2176 retval[i] += quotient;
2185 template <
int N=dim, std::enable_if_t<( 1<=N && N<=3 ),
int> = 0>
2186 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
2187 Dim3 operator() (std::u
int64_t icell) const
2189 return
intVect(icell).dim3();
2192 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
2193 std::u
int64_t numPts () const { return npts; }
2204 : npts(box.numPts()),
2215 Dim3 operator() (std::uint64_t icell)
const
2217 return {int(icell)+lo, 0, 0};
2221 std::uint64_t
numPts ()
const {
return npts; }
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
int idir
Definition AMReX_HypreMLABecLap.cpp:1093
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1089
Array4< Real > fine
Definition AMReX_InterpFaceRegister.cpp:90
Definition AMReX_Box.H:1257
virtual Box doit(const Box &fine) const =0
virtual ~BoxConverter()=default
virtual BoxConverter * clone() const =0
iterates through the IntVects of a Box
Definition AMReX_BoxIterator.H:51
A Rectangular Domain on an Integer Lattice.
Definition AMReX_Box.H:49
IntVectND< dim > smallend
Definition AMReX_Box.H:902
__host__ __device__ constexpr BoxND(const IntVectND< dim > &small, const IntVectND< dim > &big) noexcept
Construct cell-centered type BoxND.
Definition AMReX_Box.H:67
__host__ __device__ BoxND & grow(int i) noexcept
Definition AMReX_Box.H:641
__host__ __device__ const IntVectND< dim > & bigEnd() const &noexcept
Return the inclusive upper bound of the box.
Definition AMReX_Box.H:123
IndexTypeND< dim > btype
Definition AMReX_Box.H:904
__host__ __device__ BoxND(const IntVectND< dim > &small, const IntVectND< dim > &big, IndexTypeND< dim > t) noexcept
Construct dimension specific Boxes.
Definition AMReX_Box.H:94
__host__ static __device__ constexpr int indims() noexcept
Definition AMReX_Box.H:854
__host__ __device__ BoxND< new_dim > resize() const noexcept
Return a new BoxND of size new_dim by either shrinking or expanding this BoxND.
Definition AMReX_Box.H:893
__host__ __device__ BoxND & makeSlab(int direction, int slab_index) noexcept
Definition AMReX_Box.H:826
__host__ __device__ BoxND & minBox(const BoxND &b) noexcept
Modify BoxND to that of the minimum BoxND containing both the original BoxND and the argument....
Definition AMReX_Box.H:597
__host__ __device__ BoxND< new_dim > expand() const noexcept
Return a new BoxND of size new_dim and assigns all values of this BoxND to it and (small=0,...
Definition AMReX_Box.H:879
__host__ __device__ bool isSquare() const noexcept
Definition AMReX_Box.H:1141
__host__ __device__ BoxND(const IntVectND< dim > &small, const int *vec_len) noexcept
Construct BoxND with specified lengths.
Definition AMReX_Box.H:74
__host__ __device__ bool coarsenable(int refrat, int min_width=1) const noexcept
Return whether this Box is coarsenable.
Definition AMReX_Box.H:794
__host__ __device__ Long numPts() const noexcept
Return the number of points contained in the BoxND.
Definition AMReX_Box.H:356
__host__ __device__ IntVectND< dim > length() const noexcept
Return the length of the BoxND.
Definition AMReX_Box.H:154
__host__ __device__ BoxND & convert(IndexTypeND< dim > typ) noexcept
Convert the BoxND from the current type into the argument type. This may change the BoxND coordinates...
Definition AMReX_Box.H:974
__host__ __device__ BoxND & shift(int dir, int nzones) noexcept
Shift this BoxND nzones indexing positions in coordinate direction dir.
Definition AMReX_Box.H:509
BoxIteratorND< dim > iterator() const noexcept
Return a BoxIteratorND that can be used to loop over the IntVects contained by the BoxND.
Definition AMReX_Box.H:844
__host__ static __device__ constexpr std::size_t ndims() noexcept
Definition AMReX_Box.H:849
IntVectND< dim > bigend
Definition AMReX_Box.H:903
__host__ __device__ IntVectND< dim > atOffset(Long offset) const noexcept
Given the offset, compute IntVectND<dim>
Definition AMReX_Box.H:1071
__host__ __device__ BoxND & growLo(int idir, int n_cell=1) noexcept
Grow the BoxND on the low end by n_cell cells in direction idir. NOTE: n_cell negative shrinks the Bo...
Definition AMReX_Box.H:662
__host__ __device__ IndexTypeND< dim > ixType() const noexcept
Return the indexing type.
Definition AMReX_Box.H:135
__host__ __device__ BoxND & growHi(int idir, int n_cell=1) noexcept
Grow the BoxND on the high end by n_cell cells in direction idir. NOTE: n_cell negative shrinks the B...
Definition AMReX_Box.H:673
__host__ __device__ IntVectND< dim > type() const noexcept
Return the indexing type.
Definition AMReX_Box.H:139
__host__ __device__ BoxND & coarsen(int ref_ratio) noexcept
Coarsen BoxND by given (positive) refinement ratio. NOTE: if type(dir) = CELL centered: lo <- lo/rati...
Definition AMReX_Box.H:722
__host__ __device__ BoxND & refine(int ref_ratio) noexcept
Refine BoxND by given (positive) refinement ratio. NOTE: if type(dir) = CELL centered: lo <- lo*ratio...
Definition AMReX_Box.H:698
__host__ __device__ BoxND & setType(const IndexTypeND< dim > &t) noexcept
Set indexing type.
Definition AMReX_Box.H:505
__host__ __device__ constexpr BoxND() noexcept
Definition AMReX_Box.H:60
__host__ __device__ BoxND & enclosedCells() noexcept
Convert to CELL type in all directions.
Definition AMReX_Box.H:1040
__host__ __device__ void next(IntVectND< dim > &) const noexcept
Step through the rectangle. It is a runtime error to give a point not inside rectangle....
Definition AMReX_Box.H:1121
__host__ __device__ void normalize() noexcept
Definition AMReX_Box.H:816
__host__ __device__ BoxND< new_dim > shrink() const noexcept
Return a new BoxND of dimension new_dim and assigns the first new_dim dimension of this BoxND to it.
Definition AMReX_Box.H:864
__host__ __device__ BoxND & coarsen(const IntVectND< dim > &ref_ratio) noexcept
Coarsen BoxND by given (positive) refinement ratio. NOTE: if type(dir) = CELL centered: lo <- lo/rati...
Definition AMReX_Box.H:928
__host__ static __device__ BoxND TheUnitBox() noexcept
This static member function returns a constant reference to an object of type BoxND representing the ...
Definition AMReX_Box.H:751
__host__ __device__ bool coarsenable(const IntVectND< dim > &refrat, int min_width=1) const noexcept
Return whether this Box is coarsenable.
Definition AMReX_Box.H:810
friend class BoxCommHelper
Definition AMReX_Box.H:51
__host__ __device__ BoxND & surroundingNodes() noexcept
Convert to NODE type in all directions.
Definition AMReX_Box.H:1008
__host__ __device__ BoxND(const IntVectND< dim > &small, const IntVectND< dim > &big, const IntVectND< dim > &typ) noexcept
Construct BoxND with given type. small and big are expected to be consistent with given type.
Definition AMReX_Box.H:84
__host__ __device__ const IntVectND< dim > & smallEnd() const &noexcept
Return the inclusive lower bound of the box.
Definition AMReX_Box.H:111
Cell-Based or Node-Based Indices.
Definition AMReX_IndexType.H:36
__host__ __device__ void set(int dir) noexcept
Set IndexTypeND to be NODE based in direction dir.
Definition AMReX_IndexType.H:72
__host__ __device__ void unset(int dir) noexcept
Set IndexTypeND to be CELL based in direction dir.
Definition AMReX_IndexType.H:75
An Integer Vector in dim-Dimensional Space.
Definition AMReX_IntVect.H:57
__host__ __device__ IntVectND & setVal(int i, int val) noexcept
Set i'th coordinate of IntVectND to val.
Definition AMReX_IntVect.H:282
__host__ __device__ constexpr int * begin() noexcept
Returns a pointer to the first element of the IntVectND.
Definition AMReX_IntVect.H:266
__host__ __device__ IntVectND< dim > & coarsen(const IntVectND< dim > &p) noexcept
Modify IntVectND<dim> by component-wise integer projection.
Definition AMReX_IntVect.H:854
Encapsulation of the Orientation of the Faces of a Box.
Definition AMReX_Orientation.H:29
__host__ __device__ bool isLow() const noexcept
Returns true if Orientation is low.
Definition AMReX_Orientation.H:89
__host__ __device__ int coordDir() const noexcept
Returns the coordinate direction.
Definition AMReX_Orientation.H:83
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:28
amrex_long Long
Definition AMReX_INT.H:30
__host__ __device__ BoxND< dim > coarsen(const BoxND< dim > &b, int ref_ratio) noexcept
Coarsen BoxND by given (positive) coarsening ratio.
Definition AMReX_Box.H:1409
__host__ __device__ BoxND< dim > grow(const BoxND< dim > &b, int i) noexcept
Grow BoxND in all directions by given amount.
Definition AMReX_Box.H:1280
__host__ __device__ BoxND< dim > refine(const BoxND< dim > &b, int ref_ratio) noexcept
Definition AMReX_Box.H:1459
int MPI_Datatype
Definition AMReX_ccse-mpi.H:53
Definition AMReX_Amr.cpp:49
__host__ __device__ BoxND< dim > adjCellHi(const BoxND< dim > &b, int dir, int len=1) noexcept
Similar to adjCellLo but builds an adjacent BoxND on the high end.
Definition AMReX_Box.H:1735
__host__ __device__ BoxND< dim > convert(const BoxND< dim > &b, const IntVectND< dim > &typ) noexcept
Return a BoxND with different type.
Definition AMReX_Box.H:1558
__host__ __device__ BoxND< dim > makeSlab(BoxND< dim > const &b, int direction, int slab_index) noexcept
Definition AMReX_Box.H:2123
__host__ __device__ BoxND< dim > adjCellLo(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the cell centered BoxND of length len adjacent to b on the low end along the coordinate direct...
Definition AMReX_Box.H:1714
__host__ __device__ BoxND< dim > surroundingNodes(const BoxND< dim > &b, int dir) noexcept
Return a BoxND with NODE based coordinates in direction dir that encloses BoxND b....
Definition AMReX_Box.H:1522
__host__ __device__ Dim3 length(Array4< T > const &a) noexcept
Definition AMReX_Array4.H:326
__host__ __device__ IntVectND< dim > end_iv(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:1932
__host__ __device__ IntVectND< dim > lbound_iv(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:1905
__host__ __device__ BoxND< dim > bdryLo(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the edge-centered BoxND (in direction dir) defining the low side of BoxND b.
Definition AMReX_Box.H:1625
__host__ __device__ constexpr GpuTuple< IntVectND< d >, IntVectND< dims >... > IntVectSplit(const IntVectND< detail::get_sum< d, dims... >()> &v) noexcept
Returns a tuple of IntVectND obtained by splitting the input IntVectND according to the dimensions sp...
Definition AMReX_IntVect.H:1187
__host__ __device__ IntVectND< dim > min_ubound_iv(BoxND< dim > const &b1, BoxND< dim > const &b2) noexcept
Definition AMReX_Box.H:1970
__host__ __device__ BoxND< dim > minBox(const BoxND< dim > &b1, const BoxND< dim > &b2) noexcept
Modify BoxND to that of the minimum BoxND containing both the original BoxND and the argument....
Definition AMReX_Box.H:1793
__host__ __device__ BoxND< dim > makeSingleCellBox(int i, int j, int k, IndexTypeND< dim > typ=IndexTypeND< dim >::TheCellType())
Definition AMReX_Box.H:2134
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:27
__host__ __device__ constexpr BoxND< new_dim > BoxResize(const BoxND< old_dim > &bx) noexcept
Return a new BoxND of size new_dim by either shrinking or expanding this BoxND.
Definition AMReX_Box.H:1897
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:21
__host__ __device__ BoxND< dim > adjCell(const BoxND< dim > &b, Orientation face, int len=1) noexcept
Similar to adjCellLo and adjCellHi; operates on given face.
Definition AMReX_Box.H:1757
__host__ __device__ IntVectND< dim > begin_iv(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:1923
__host__ __device__ BoxND< dim > shift(const BoxND< dim > &b, int dir, int nzones) noexcept
Return a BoxND with indices shifted by nzones in dir direction.
Definition AMReX_Box.H:1495
__host__ __device__ constexpr BoxND< new_dim > BoxShrink(const BoxND< old_dim > &bx) noexcept
Return a new BoxND of dimension new_dim and assigns the first new_dim dimension of this BoxND to it.
Definition AMReX_Box.H:1872
__host__ __device__ BoxND< dim > enclosedCells(const BoxND< dim > &b, int dir) noexcept
Return a BoxND with CELL based coordinates in direction dir that is enclosed by b....
Definition AMReX_Box.H:1586
__host__ __device__ constexpr IndexTypeND< detail::get_sum< d, dims... >()> IndexTypeCat(const IndexTypeND< d > &v, const IndexTypeND< dims > &...vects) noexcept
Returns a IndexTypeND obtained by concatenating the input IndexTypeNDs. The dimension of the return v...
Definition AMReX_IndexType.H:297
__host__ __device__ IntVectND< dim > length_iv(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:1941
Direction
Definition AMReX_Orientation.H:14
__host__ __device__ BoxND< dim > bdryNode(const BoxND< dim > &b, Orientation face, int len=1) noexcept
Similar to bdryLo and bdryHi except that it operates on the given face of box b.
Definition AMReX_Box.H:1672
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:35
__host__ __device__ BoxND< dim > growLo(const BoxND< dim > &b, int idir, int n_cell) noexcept
Definition AMReX_Box.H:1354
__host__ __device__ IntVectND< dim > ubound_iv(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:1914
__host__ __device__ constexpr BoxND< new_dim > BoxExpand(const BoxND< old_dim > &bx) noexcept
Return a new BoxND of size new_dim and assigns all values of this BoxND to it and (small=0,...
Definition AMReX_Box.H:1885
__host__ __device__ IntVectND< dim > getCell(BoxND< dim > const *boxes, int nboxes, Long icell) noexcept
Definition AMReX_Box.H:2103
void AllGatherBoxes(Vector< Box > &bxs, int n_extra_reserve)
Definition AMReX_Box.cpp:124
__host__ __device__ constexpr IntVectND< detail::get_sum< d, dims... >()> IntVectCat(const IntVectND< d > &v, const IntVectND< dims > &...vects) noexcept
Returns a IntVectND obtained by concatenating the input IntVectNDs. The dimension of the return value...
Definition AMReX_IntVect.H:1171
__host__ __device__ BoxND< dim > bdryHi(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the edge-centered BoxND (in direction dir) defining the high side of BoxND b.
Definition AMReX_Box.H:1648
__host__ __device__ BoxND< dim > growHi(const BoxND< dim > &b, int idir, int n_cell) noexcept
Definition AMReX_Box.H:1374
BoxND< dim > getIndexBounds(BoxND< dim > const &b1) noexcept
Definition AMReX_Box.H:2074
__host__ __device__ constexpr GpuTuple< BoxND< d >, BoxND< dims >... > BoxSplit(const BoxND< detail::get_sum< d, dims... >()> &bx) noexcept
Return a tuple of BoxNDs obtained by splitting the input BoxND according to the dimensions specified ...
Definition AMReX_Box.H:1857
__host__ __device__ constexpr GpuTuple< IndexTypeND< d >, IndexTypeND< dims >... > IndexTypeSplit(const IndexTypeND< detail::get_sum< d, dims... >()> &v) noexcept
Returns a tuple of IndexTypeND obtained by splitting the input IndexTypeND according to the dimension...
Definition AMReX_IndexType.H:317
__host__ __device__ IntVectND< dim > max_lbound_iv(BoxND< dim > const &b1, BoxND< dim > const &b2) noexcept
Definition AMReX_Box.H:1951
BoxIndexerND(BoxND< 1 > const &box)
Definition AMReX_Box.H:2203
std::uint64_t npts
Definition AMReX_Box.H:2199
__host__ __device__ std::uint64_t numPts() const
Definition AMReX_Box.H:2221
__host__ __device__ IntVectND< 1 > intVect(std::uint64_t icell) const
Definition AMReX_Box.H:2209
int lo
Definition AMReX_Box.H:2201
Definition AMReX_Box.H:2152
__host__ __device__ IntVectND< dim > intVect(std::uint64_t icell) const
Definition AMReX_Box.H:2169
BoxIndexerND(BoxND< dim > const &box)
Definition AMReX_Box.H:2157
IntVectND< dim > lo
Definition AMReX_Box.H:2155
std::uint64_t npts
Definition AMReX_Box.H:2153
CellIndex
The cell index type: one of CELL or NODE.
Definition AMReX_IndexType.H:21
@ CELL
Definition AMReX_IndexType.H:21
Definition AMReX_Dim3.H:12
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:40
Definition AMReX_Math.H:438
static MPI_Datatype type()