Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_Box.H
Go to the documentation of this file.
1
2#ifndef AMREX_BOX_H_
3#define AMREX_BOX_H_
4#include <AMReX_Config.H>
5
6#include <AMReX_Algorithm.H>
7#include <AMReX_ArrayLim.H>
8#include <AMReX_BoxIterator.H>
9#include <AMReX_ccse-mpi.H>
10#include <AMReX_IntVect.H>
11#include <AMReX_IndexType.H>
12#include <AMReX_Orientation.H>
13#include <AMReX_SPACE.H>
14#include <AMReX_Array.H>
15#include <AMReX_Array4.H>
16#include <AMReX_Vector.H>
17#include <AMReX_GpuQualifiers.H>
18#include <AMReX_GpuControl.H>
19#include <AMReX_Math.H>
20
21#include <iosfwd>
22
28namespace amrex
29{
30template<int dim>
31class BoxND;
33using Box = BoxND<AMREX_SPACEDIM>;
34class BoxCommHelper;
35template<int dim>
36class BoxIteratorND;
37
52template<int dim>
53class BoxND
54{
56 friend class BoxCommHelper;
57
58public:
59 // DO NOT CHANGE THIS BEHAVIOR!
64 constexpr BoxND () noexcept
65 : smallend(1),
66 bigend(0)
67 {}
68
71 constexpr BoxND (const IntVectND<dim>& small, const IntVectND<dim>& big) noexcept
72 : smallend(small),
73 bigend(big)
74 {}
75
82 BoxND (const IntVectND<dim>& small, const int* vec_len) noexcept
83 : smallend(small),
84 bigend(small + IntVectND<dim>(vec_len) - 1)
85 {}
86
95 BoxND (const IntVectND<dim>& small, const IntVectND<dim>& big, const IntVectND<dim>& typ) noexcept
96 : smallend(small),
97 bigend(big),
98 btype(typ)
99 {
100 BL_ASSERT(typ.allGE(0) && typ.allLE(1));
101 }
102
105 BoxND (const IntVectND<dim>& small, const IntVectND<dim>& big, IndexTypeND<dim> t) noexcept
106 : smallend(small),
107 bigend(big),
108 btype(t)
109 {}
110
112 template <typename T>
113 requires ( 1<=dim && dim<=3 )
115 explicit BoxND (Array4<T> const& a) noexcept
116 : smallend(IntVectShrink<dim>(a.begin)),
117 bigend(IntVectShrink<dim>(a.end) - 1)
118 {}
119
120 // dtor, copy-ctor, copy-op=, move-ctor, and move-op= are compiler generated.
121
123 [[nodiscard]] AMREX_GPU_HOST_DEVICE
124 const IntVectND<dim>& smallEnd () const& noexcept { return smallend; }
125
127 [[nodiscard]] const IntVectND<dim>& smallEnd () && = delete;
129
131 [[nodiscard]] AMREX_GPU_HOST_DEVICE
132 int smallEnd (int dir) const& noexcept { return smallend[dir]; }
133
135 [[nodiscard]] AMREX_GPU_HOST_DEVICE
136 const IntVectND<dim>& bigEnd () const& noexcept { return bigend; }
137
139 [[nodiscard]] const IntVectND<dim>& bigEnd () && = delete;
141
143 [[nodiscard]] AMREX_GPU_HOST_DEVICE
144 int bigEnd (int dir) const noexcept { return bigend[dir]; }
145
147 [[nodiscard]] AMREX_GPU_HOST_DEVICE
148 IndexTypeND<dim> ixType () const noexcept { return btype; }
149
151 [[nodiscard]] AMREX_GPU_HOST_DEVICE
152 IntVectND<dim> type () const noexcept { return btype.ixType(); }
153
155 [[nodiscard]] AMREX_GPU_HOST_DEVICE
156 IndexType::CellIndex type (int dir) const noexcept { return btype.ixType(dir); }
157
159 [[nodiscard]] AMREX_GPU_HOST_DEVICE
160 IntVectND<dim> size () const noexcept
161 {
162 return bigend - smallend + 1;
163 }
164
166 [[nodiscard]] AMREX_GPU_HOST_DEVICE
167 IntVectND<dim> length () const noexcept
168 {
169 return bigend - smallend + 1;
170 }
171
173 [[nodiscard]] AMREX_GPU_HOST_DEVICE
174 int length (int dir) const noexcept { return bigend[dir] - smallend[dir] + 1; }
175
177 [[nodiscard]] AMREX_GPU_HOST_DEVICE
178 GpuArray<int,3> length3d () const noexcept
179 requires (1 <= dim && dim <= 3)
180 {
181 Dim3 len3d = length().dim3(1);
182 return {{len3d.x, len3d.y, len3d.z}};
183 }
184
186 [[nodiscard]] AMREX_GPU_HOST_DEVICE
187 GpuArray<int,3> loVect3d () const noexcept
188 requires (1 <= dim && dim <= 3)
189 {
190 Dim3 lo3d = smallend.dim3(0);
191 return {{lo3d.x, lo3d.y, lo3d.z}};
192 }
193
195 [[nodiscard]] AMREX_GPU_HOST_DEVICE
196 GpuArray<int,3> hiVect3d () const noexcept
197 requires (1 <= dim && dim <= 3)
198 {
199 Dim3 hi3d = bigend.dim3(0);
200 return {{hi3d.x, hi3d.y, hi3d.z}};
201 }
202
204 [[nodiscard]] AMREX_GPU_HOST_DEVICE
205 const int* loVect () const& noexcept { return smallend.getVect(); }
207 const int* loVect () && = delete;
209 [[nodiscard]] AMREX_GPU_HOST_DEVICE
210 const int* hiVect () const& noexcept { return bigend.getVect(); }
212 const int* hiVect () && = delete;
213
215 [[nodiscard]] AMREX_GPU_HOST_DEVICE
216 int operator[] (Orientation face) const noexcept {
217 const int dir = face.coordDir();
218 return face.isLow() ? smallend[dir] : bigend[dir];
219 }
220
222 [[nodiscard]] AMREX_GPU_HOST_DEVICE
223 bool isEmpty () const noexcept { return !ok(); }
224
228 [[nodiscard]] AMREX_GPU_HOST_DEVICE
229 bool ok () const noexcept { return bigend.allGE(smallend) && btype.ok(); }
230
232 [[nodiscard]] AMREX_GPU_HOST_DEVICE
233 bool contains (const IntVectND<dim>& p) const noexcept {
234 return p.allGE(smallend) && p.allLE(bigend);
235 }
236
238 [[nodiscard]] AMREX_GPU_HOST_DEVICE
239 bool contains (const Dim3& p) const noexcept
240 requires (1 <= dim && dim <= 3)
241 {
242 IntVectND<dim> piv{p};
243 return contains(piv);
244 }
245
247 [[nodiscard]] AMREX_GPU_HOST_DEVICE
248 bool contains (int i, int j, int k) const noexcept
249 requires (1 <= dim && dim <= 3)
250 {
251 Dim3 p3d{.x = i, .y = j, .z = k};
252 return contains(p3d);
253 }
254
258 [[nodiscard]] AMREX_GPU_HOST_DEVICE
259 bool contains (const BoxND& b) const noexcept
260 {
262 return b.smallend.allGE(smallend) && b.bigend.allLE(bigend);
263 }
264
266 [[nodiscard]] AMREX_GPU_HOST_DEVICE
267 bool strictly_contains (const IntVectND<dim>& p) const noexcept {
268 return p.allGT(smallend) && p.allLT(bigend);
269 }
270
275 [[nodiscard]] AMREX_GPU_HOST_DEVICE
276 bool strictly_contains (const BoxND& b) const noexcept
277 {
279 return b.smallend.allGT(smallend) && b.bigend.allLT(bigend);
280 }
281
283 [[nodiscard]] AMREX_GPU_HOST_DEVICE
284 bool strictly_contains (const Dim3& p) const noexcept
285 requires (1 <= dim && dim <= 3)
286 {
287 IntVectND<dim> piv{p};
288 return strictly_contains(piv);
289 }
290
292 [[nodiscard]] AMREX_GPU_HOST_DEVICE
293 bool strictly_contains (int i, int j, int k) const noexcept
294 requires (1 <= dim && dim <= 3)
295 {
296 Dim3 p3d{.x = i, .y = j, .z = k};
297 return strictly_contains(p3d);
298 }
299
304 [[nodiscard]] AMREX_GPU_HOST_DEVICE
305 bool intersects (const BoxND& b) const noexcept { BoxND isect(*this); isect &= b; return isect.ok(); }
306
311 [[nodiscard]] AMREX_GPU_HOST_DEVICE
312 bool sameSize (const BoxND& b) const noexcept {
314 return length() == b.length();
315 }
316
318 [[nodiscard]] AMREX_GPU_HOST_DEVICE
319 bool sameType (const BoxND &b) const noexcept { return btype == b.btype; }
320
322 [[nodiscard]] AMREX_GPU_HOST_DEVICE
323 bool operator== (const BoxND& b) const noexcept { return smallend == b.smallend && bigend == b.bigend && b.btype == btype; }
324
326 [[nodiscard]] AMREX_GPU_HOST_DEVICE
327 bool operator!= (const BoxND& b) const noexcept { return !operator==(b); }
328
330 [[nodiscard]] AMREX_GPU_HOST_DEVICE
331 bool operator< (const BoxND& rhs) const noexcept
332 {
333 return btype < rhs.btype ||
334 ((btype == rhs.btype) &&
335 ( (smallend < rhs.smallend) ||
336 ((smallend == rhs.smallend) && (bigend < rhs.bigend)) ));
337 }
339 [[nodiscard]] AMREX_GPU_HOST_DEVICE
340 bool operator <= (const BoxND& rhs) const noexcept {
341 return !(rhs < *this);
342 }
344 [[nodiscard]] AMREX_GPU_HOST_DEVICE
345 bool operator> (const BoxND& rhs) const noexcept {
346 return rhs < *this;
347 }
349 [[nodiscard]] AMREX_GPU_HOST_DEVICE
350 bool operator>= (const BoxND& rhs) const noexcept {
351 return !(*this < rhs);
352 }
353
355 [[nodiscard]] AMREX_GPU_HOST_DEVICE
356 bool cellCentered () const noexcept { return !btype.any(); }
357
360 void checkOverflow () const {
361 if (ok()) {
362 for (int i = 0; i < dim; ++i) {
363 auto lo = static_cast<Long>(smallend[i]);
364 auto hi = static_cast<Long>(bigend[i]);
365 Long len = hi - lo + 1;
366 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(len>=0 && len<std::numeric_limits<int>::max(),
367 "Overflow when computing length of box");
368 }
369 auto num_pts = static_cast<Long>(length(0));
370 for (int i = 1; i < dim; ++i) {
371 auto len = static_cast<Long>(length(i));
372 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(num_pts == 0 || len == 0 ||
373 num_pts <= std::numeric_limits<Long>::max() / len,
374 "Overflow when computing numPts of box");
375 num_pts *= len;
376 }
377 }
378 }
380
384 [[nodiscard]] AMREX_GPU_HOST_DEVICE
385 Long numPts () const noexcept {
386#if defined(AMREX_DEBUG) || defined(AMREX_USE_ASSERTION)
387 AMREX_IF_ON_HOST((checkOverflow();))
388#endif
389 if (ok()) {
390 auto num_pts = static_cast<Long>(length(0));
391 for (int i = 1; i < dim; ++i) {
392 num_pts *= static_cast<Long>(length(i));
393 }
394 return num_pts;
395 } else {
396 return Long(0);
397 }
398 }
399
404 [[nodiscard]] AMREX_GPU_HOST_DEVICE
405 double d_numPts () const noexcept {
406 if (ok()) {
407 auto num_pts = static_cast<double>(length(0));
408 for (int i = 1; i < dim; ++i) {
409 num_pts *= static_cast<double>(length(i));
410 }
411 return num_pts;
412 } else {
413 return 0.0;
414 }
415 }
416
422 [[nodiscard]] AMREX_GPU_HOST_DEVICE
423 Long volume () const noexcept {
424 if (ok()) {
425 auto num_pts = static_cast<Long>(length(0)-btype[0]);
426 for (int i = 1; i < dim; ++i) {
427 num_pts *= static_cast<Long>(length(i)-btype[i]);
428 }
429 return num_pts;
430 } else {
431 return Long(0);
432 }
433 }
434
439 [[nodiscard]] AMREX_GPU_HOST_DEVICE
440 int longside (int& dir) const noexcept {
441 int maxlen = length(0);
442 dir = 0;
443 for (int i = 1; i < dim; i++)
444 {
445 if (length(i) > maxlen)
446 {
447 maxlen = length(i);
448 dir = i;
449 }
450 }
451 return maxlen;
452 }
453
455 [[nodiscard]] AMREX_GPU_HOST_DEVICE
456 int longside () const noexcept {
457 int ignore = 0;
458 return longside(ignore);
459 }
460
465 [[nodiscard]] AMREX_GPU_HOST_DEVICE
466 int shortside (int& dir) const noexcept {
467 int minlen = length(0);
468 dir = 0;
469 for (int i = 1; i < dim; i++)
470 {
471 if (length(i) < minlen)
472 {
473 minlen = length(i);
474 dir = i;
475 }
476 }
477 return minlen;
478 }
479
481 [[nodiscard]] AMREX_GPU_HOST_DEVICE
482 int shortside () const noexcept {
483 int ignore = 0;
484 return shortside(ignore);
485 }
486
492 [[nodiscard]] AMREX_GPU_HOST_DEVICE
493 Long index (const IntVectND<dim>& v) const noexcept;
494
496 [[nodiscard]] AMREX_GPU_HOST_DEVICE
498
502 template <int N=dim>
503 requires (1 <= N && N <= 3)
504 [[nodiscard]] AMREX_GPU_HOST_DEVICE
506
508 BoxND& setSmall (const IntVectND<dim>& sm) noexcept { smallend = sm; return *this; }
509
512 BoxND& setSmall (int dir, int sm_index) noexcept { smallend.setVal(dir,sm_index); return *this; }
513
516 BoxND& setBig (const IntVectND<dim>& bg) noexcept { bigend = bg; return *this; }
517
520 BoxND& setBig (int dir, int bg_index) noexcept { bigend.setVal(dir,bg_index); return *this; }
521
528 BoxND& setRange (int dir,
529 int sm_index,
530 int n_cells = 1) noexcept;
531
534 BoxND& setType (const IndexTypeND<dim>& t) noexcept { btype = t; return *this; }
535
538 BoxND& shift (int dir, int nzones) noexcept { smallend.shift(dir,nzones); bigend.shift(dir,nzones); return *this; }
539
542 BoxND& shift (const IntVectND<dim>& iv) noexcept { smallend.shift(iv); bigend.shift(iv); return *this; }
543
554 BoxND& shiftHalf (int dir, int num_halfs) noexcept;
555
558 BoxND& shiftHalf (const IntVectND<dim>& iv) noexcept;
559
569
578 BoxND& convert (const IntVectND<dim>& typ) noexcept;
579
583
586 BoxND& surroundingNodes (int dir) noexcept;
587
590 BoxND& surroundingNodes (Direction d) noexcept { return surroundingNodes(static_cast<int>(d)); }
591
594 BoxND& enclosedCells () noexcept;
595
598 BoxND& enclosedCells (int dir) noexcept;
599
602 BoxND& enclosedCells (Direction d) noexcept { return enclosedCells(static_cast<int>(d)); }
603
609 BoxND operator& (const BoxND& rhs) const noexcept { BoxND lhs(*this); lhs &= rhs; return lhs; }
610
613 BoxND& operator&= (const BoxND& rhs) noexcept
614 {
615 BL_ASSERT(sameType(rhs));
616 smallend.max(rhs.smallend);
617 bigend.min(rhs.bigend);
618 return *this;
619 }
620
627 BoxND& minBox (const BoxND& b) noexcept {
628 // BoxArray may call this with not ok boxes. BL_ASSERT(b.ok() && ok());
630 smallend.min(b.smallend);
631 bigend.max(b.bigend);
632 return *this;
633 }
634
637 BoxND& operator+= (const IntVectND<dim>& v) noexcept { smallend += v; bigend += v; return *this; }
638
641 BoxND operator+ (const IntVectND<dim>& v) const noexcept { BoxND r(*this); r += v; return r; }
642
645 BoxND& operator-= (const IntVectND<dim>& v) noexcept { smallend -= v; bigend -= v; return *this; }
646
649 BoxND operator- (const IntVectND<dim>& v) const noexcept { BoxND r(*this); r -= v; return r; }
650
664 BoxND chop (int dir, int chop_pnt) noexcept;
665
668 BoxND& grow (int i) noexcept { smallend.diagShift(-i); bigend.diagShift(i); return *this; }
669
672 BoxND& grow (const IntVectND<dim>& v) noexcept { smallend -= v; bigend += v; return *this;}
673
678 BoxND& grow (int idir, int n_cell) noexcept { smallend.shift(idir, -n_cell); bigend.shift(idir, n_cell); return *this; }
679
684 BoxND& grow (Direction d, int n_cell) noexcept { return grow(static_cast<int>(d), n_cell); }
685
690 BoxND& growLo (int idir, int n_cell = 1) noexcept { smallend.shift(idir, -n_cell); return *this; }
691
696 BoxND& growLo (Direction d, int n_cell = 1) noexcept { return growLo(static_cast<int>(d), n_cell); }
697
702 BoxND& growHi (int idir, int n_cell = 1) noexcept { bigend.shift(idir,n_cell); return *this; }
703
708 BoxND& growHi (Direction d, int n_cell = 1) noexcept { return growHi(static_cast<int>(d), n_cell); }
709
712 BoxND& grow (Orientation face, int n_cell = 1) noexcept {
713 int idir = face.coordDir();
714 if (face.isLow()) {
715 smallend.shift(idir, -n_cell);
716 } else {
717 bigend.shift(idir,n_cell);
718 }
719 return *this;
720 }
721
730 BoxND& refine (int ref_ratio) noexcept {
731 return this->refine(IntVectND<dim>(ref_ratio));
732 }
733
742 BoxND& refine (const IntVectND<dim>& ref_ratio) noexcept;
743
754 BoxND& coarsen (int ref_ratio) noexcept {
755 return this->coarsen(IntVectND<dim>(ref_ratio));
756 }
757
768 BoxND& coarsen (const IntVectND<dim>& ref_ratio) noexcept;
769
775 void next (IntVectND<dim> &) const noexcept;
776
786
787 [[nodiscard]] AMREX_GPU_HOST_DEVICE
788 bool isSquare() const noexcept;
789
801 [[nodiscard]] AMREX_GPU_HOST_DEVICE
802 bool coarsenable (const IntVectND<dim>& refrat, const IntVectND<dim>& min_width) const noexcept
803 {
804 if (!size().allGE(refrat*min_width)) {
805 return false;
806 } else {
807 BoxND testBox = *this;
808 testBox.coarsen(refrat);
809 testBox.refine (refrat);
810 return (*this == testBox);
811 }
812 }
813
825 [[nodiscard]] AMREX_GPU_HOST_DEVICE
826 bool coarsenable (int refrat, int min_width=1) const noexcept {
827 return coarsenable(IntVectND<dim>(refrat), IntVectND<dim>(min_width));
828 }
829
841 [[nodiscard]] AMREX_GPU_HOST_DEVICE
842 bool coarsenable (const IntVectND<dim>& refrat, int min_width=1) const noexcept
843 {
844 return coarsenable(refrat, IntVectND<dim>(min_width));
845 }
846
849 void normalize () noexcept
850 {
851 for (int idim=0; idim < dim; ++idim) {
852 if (this->length(idim) == 0) {
853 this->growHi(idim,1);
854 }
855 }
856 }
857
860 BoxND& makeSlab (int direction, int slab_index) noexcept
861 {
862 smallend[direction] = slab_index;
863 bigend[direction] = slab_index;
864 return *this;
865 }
866
878 [[nodiscard]] BoxIteratorND<dim> iterator () const noexcept {
879 return BoxIteratorND<dim>{*this};
880 }
881
883 static constexpr std::size_t ndims () noexcept {
884 return static_cast<std::size_t>(dim);
885 }
886
888 static constexpr int indims () noexcept {
889 return dim;
890 }
891
896 template<int new_dim>
898 BoxND<new_dim> shrink () const noexcept {
899 static_assert(new_dim <= dim);
900 auto lo = smallend.template shrink<new_dim>();
901 auto hi = bigend.template shrink<new_dim>();
902 auto typ = btype.template shrink<new_dim>();
903 return BoxND<new_dim>(lo, hi, typ);
904 }
905
911 template<int new_dim>
913 BoxND<new_dim> expand () const noexcept {
914 static_assert(new_dim >= dim);
915 auto lo = smallend.template expand<new_dim>(0);
916 auto hi = bigend.template expand<new_dim>(0);
917 auto typ = btype.template expand<new_dim>(IndexType::CellIndex::CELL);
918 return BoxND<new_dim>(lo, hi, typ);
919 }
920
925 template<int new_dim>
927 BoxND<new_dim> resize () const noexcept {
928 if constexpr (new_dim > dim) {
929 return expand<new_dim>();
930 } else {
931 return shrink<new_dim>();
932 }
933 }
934
935private:
936 IntVectND<dim> smallend;
937 IntVectND<dim> bigend;
938 IndexTypeND<dim> btype;
939};
940
941template<int dim>
944BoxND<dim>&
945BoxND<dim>::refine (const IntVectND<dim>& ref_ratio) noexcept
946{
947 if (ref_ratio != 1) {
948 IntVectND<dim> shft(1);
949 shft -= btype.ixType();
950 smallend *= ref_ratio;
951 bigend += shft;
952 bigend *= ref_ratio;
953 bigend -= shft;
954 }
955 return *this;
956}
957
958template<int dim>
962BoxND<dim>::coarsen (const IntVectND<dim>& ref_ratio) noexcept
963{
964 if (ref_ratio != 1)
965 {
966 smallend.coarsen(ref_ratio);
967
968 if (btype.any())
969 {
970 IntVectND<dim> off(0);
971 for (int dir = 0; dir < dim; dir++)
972 {
973 if (btype[dir]) {
974 if (bigend[dir]%ref_ratio[dir]) {
975 off.setVal(dir,1);
976 }
977 }
978 }
979 bigend.coarsen(ref_ratio);
980 bigend += off;
981 }
982 else
983 {
984 bigend.coarsen(ref_ratio);
985 }
986 }
987
988 return *this;
989}
990
991template<int dim>
996{
997 BL_ASSERT(typ.allGE(0) && typ.allLE(1));
998 IntVectND<dim> shft(typ - btype.ixType());
999 bigend += shft;
1000 btype = IndexTypeND<dim>(typ);
1001 return *this;
1002}
1003
1004template<int dim>
1009{
1010 for (int dir = 0; dir < dim; dir++)
1011 {
1012 const auto typ = t[dir];
1013 const auto bitval = btype[dir];
1014 const int off = typ - bitval;
1015 bigend.shift(dir,off);
1016 btype.setType(dir, static_cast<IndexType::CellIndex>(typ));
1017 }
1018 return *this;
1019}
1020
1021template<int dim>
1026{
1027 if (!(btype[dir]))
1028 {
1029 bigend.shift(dir,1);
1030 //
1031 // Set dir'th bit to 1 = IndexType::NODE.
1032 //
1033 btype.set(dir);
1034 }
1035 return *this;
1036}
1037
1038template<int dim>
1043{
1044 for (int i = 0; i < dim; ++i) {
1045 if ((btype[i] == 0)) {
1046 bigend.shift(i,1);
1047 }
1048 }
1049 btype.setall();
1050 return *this;
1051}
1052
1053template<int dim>
1058{
1059 if (btype[dir])
1060 {
1061 bigend.shift(dir,-1);
1062 //
1063 // Set dir'th bit to 0 = IndexType::CELL.
1064 //
1065 btype.unset(dir);
1066 }
1067 return *this;
1068}
1069
1070template<int dim>
1075{
1076 for (int i = 0 ; i < dim; ++i) {
1077 if (btype[i]) {
1078 bigend.shift(i,-1);
1079 }
1080 }
1081 btype.clear();
1082 return *this;
1083}
1084
1085template<int dim>
1088Long
1089BoxND<dim>::index (const IntVectND<dim>& v) const noexcept
1090{
1091 IntVectND<dim> vz = v - smallend;
1092 Long result = vz[0];
1093 Long mult = length(0);
1094 for (int i = 1 ; i < dim; ++i) {
1095 result += mult * vz[i];
1096 mult *= length(i);
1097 }
1098 return result;
1099}
1100
1101template<int dim>
1106{
1107 IntVectND<dim> result = smallend;
1108
1109 if constexpr (dim > 1) {
1110 GpuArray<Long, dim-1> mult{};
1111 mult[0] = length(0);
1112 for (int i = 1 ; i < dim-1; ++i) {
1113 mult[i] = mult[i-1] * length(i);
1114 }
1115 for (int i = dim-1 ; i > 0; --i) {
1116 Long idx = offset / mult[i-1];
1117 offset -= idx * mult[i-1];
1118 result[i] += static_cast<int>(idx);
1119 }
1120 }
1121
1122 result[0] += static_cast<int>(offset);
1123
1124 return result;
1125}
1126
1127template<int dim>
1128template <int N>
1129requires (1 <= N && N <= 3)
1134{
1135 Dim3 iv3d = atOffset(offset).dim3(0);
1136 return {{iv3d.x, iv3d.y, iv3d.z}};
1137}
1138
1139template<int dim>
1144 int sm_index,
1145 int n_cells) noexcept
1146{
1147 smallend.setVal(dir,sm_index);
1148 bigend.setVal(dir,sm_index+n_cells-1);
1149 return *this;
1150}
1151
1152template<int dim>
1155void
1156BoxND<dim>::next (IntVectND<dim>& p) const noexcept // NOLINT(readability-convert-member-functions-to-static)
1157{
1158 BL_ASSERT(contains(p));
1159
1160 ++p[0];
1161
1162 for (int i = 0 ; i < dim-1; ++i) {
1163 if (p[i] > bigend[i]) {
1164 p[i] = smallend[i];
1165 ++p[i+1];
1166 } else {
1167 break;
1168 }
1169 }
1170}
1171
1172template<int dim>
1175bool
1176BoxND<dim>::isSquare () const noexcept // NOLINT(readability-convert-member-functions-to-static)
1177{
1178 if constexpr (dim == 1) {
1179 return false; // can't build a square in 1-D
1180 } else {
1181 bool is_square = true;
1182 const IntVectND<dim>& sz = this->size();
1183 for (int i = 0 ; i < dim-1; ++i) {
1184 is_square = is_square && (sz[i] == sz[i+1]);
1185 }
1186 return is_square;
1187 }
1188}
1189
1190//
1191// Modified BoxND is low end, returned BoxND is high end.
1192// If CELL: chop_pnt included in high end.
1193// If NODE: chop_pnt included in both Boxes.
1194//
1195
1196template<int dim>
1198inline
1200BoxND<dim>::chop (int dir, int chop_pnt) noexcept
1201{
1202 //
1203 // Define new high end BoxND including chop_pnt.
1204 //
1205 IntVectND<dim> sm(smallend);
1206 IntVectND<dim> bg(bigend);
1207 sm.setVal(dir,chop_pnt);
1208 if (btype[dir])
1209 {
1210 //
1211 // NODE centered BoxND.
1212 //
1213 BL_ASSERT(chop_pnt > smallend[dir] && chop_pnt < bigend[dir]);
1214 //
1215 // Shrink original BoxND to just contain chop_pnt.
1216 //
1217 bigend.setVal(dir,chop_pnt);
1218 }
1219 else
1220 {
1221 //
1222 // CELL centered BoxND.
1223 //
1224 BL_ASSERT(chop_pnt > smallend[dir] && chop_pnt <= bigend[dir]);
1225 //
1226 // Shrink original BoxND to one below chop_pnt.
1227 //
1228 bigend.setVal(dir,chop_pnt-1);
1229 }
1230 return BoxND<dim>(sm,bg,btype);
1231}
1232
1233template<int dim>
1235inline
1237BoxND<dim>::shiftHalf (int dir, int num_halfs) noexcept
1238{
1239 const int nbit = (num_halfs<0 ? -num_halfs : num_halfs)%2;
1240 int nshift = num_halfs/2;
1241 //
1242 // Toggle btyp bit if num_halfs is odd.
1243 //
1244 const unsigned int bit_dir = btype[dir];
1245 if (nbit) {
1246 btype.flip(dir);
1247 }
1248 if (num_halfs < 0) {
1249 nshift -= (bit_dir ? nbit : 0);
1250 } else {
1251 nshift += (bit_dir ? 0 : nbit);
1252 }
1253 smallend.shift(dir,nshift);
1254 bigend.shift(dir,nshift);
1255 return *this;
1256}
1257
1258template<int dim>
1260inline
1263{
1264 for (int i = 0; i < dim; i++) {
1265 shiftHalf(i,iv[i]);
1266 }
1267 return *this;
1268}
1269
1271class BoxCommHelper
1272{
1273public:
1274
1275 explicit BoxCommHelper (const Box& bx, int* p_ = nullptr);
1276
1277 [[nodiscard]] int* data () const& noexcept { return p; }
1278 int* data () && = delete;
1279
1280 [[nodiscard]] Box make_box () const noexcept {
1281 return Box(IntVect(p), IntVect(p+AMREX_SPACEDIM), IntVect(p+2*AMREX_SPACEDIM));
1282 }
1283
1284 [[nodiscard]] static int size () noexcept { return 3*AMREX_SPACEDIM; }
1285
1286private:
1287 int* p;
1288 std::vector<int> v;
1289};
1291
1292class BoxConverter { // NOLINT
1293public:
1294 virtual Box doit (const Box& fine) const = 0; // NOLINT
1295 virtual BoxConverter* clone () const = 0; // NOLINT
1296 virtual ~BoxConverter () = default;
1297};
1298
1310void AllGatherBoxes (Vector<Box>& bxs, int n_extra_reserve=0);
1311
1322template<int dim>
1323[[nodiscard]]
1326BoxND<dim> grow (const BoxND<dim>& b, int i) noexcept
1327{
1328 BoxND<dim> result = b;
1329 result.grow(i);
1330 return result;
1331}
1332
1340template<int dim>
1341[[nodiscard]]
1344BoxND<dim> grow (const BoxND<dim>& b, const IntVectND<dim>& v) noexcept
1345{
1346 BoxND<dim> result = b;
1347 result.grow(v);
1348 return result;
1349}
1350
1359template<int dim>
1360[[nodiscard]]
1363BoxND<dim> grow (const BoxND<dim>& b, int idir, int n_cell) noexcept
1364{
1365 BoxND<dim> result = b;
1366 result.grow(idir, n_cell);
1367 return result;
1368}
1369
1374template<int dim>
1375[[nodiscard]]
1378BoxND<dim> grow (const BoxND<dim>& b, Direction d, int n_cell) noexcept
1379{
1380 return grow(b, static_cast<int>(d), n_cell);
1381}
1382
1394template<int dim>
1395[[nodiscard]]
1398BoxND<dim> growLo (const BoxND<dim>& b, int idir, int n_cell) noexcept
1399{
1400 BoxND<dim> result = b;
1401 result.growLo(idir, n_cell);
1402 return result;
1403}
1404
1409template<int dim>
1410[[nodiscard]]
1413BoxND<dim> growLo (const BoxND<dim>& b, Direction d, int n_cell) noexcept
1414{
1415 return growLo(b, static_cast<int>(d), n_cell);
1416}
1417
1429template<int dim>
1430[[nodiscard]]
1433BoxND<dim> growHi (const BoxND<dim>& b, int idir, int n_cell) noexcept
1434{
1435 BoxND<dim> result = b;
1436 result.growHi(idir, n_cell);
1437 return result;
1438}
1439
1444template<int dim>
1445[[nodiscard]]
1448BoxND<dim> growHi (const BoxND<dim>& b, Direction d, int n_cell) noexcept
1449{
1450 return growHi(b, static_cast<int>(d), n_cell);
1451}
1452
1465template<int dim>
1466[[nodiscard]]
1469BoxND<dim> coarsen (const BoxND<dim>& b, int ref_ratio) noexcept
1470{
1471 BoxND<dim> result = b;
1472 result.coarsen(IntVectND<dim>(ref_ratio));
1473 return result;
1474}
1475
1483template<int dim>
1484[[nodiscard]]
1487BoxND<dim> coarsen (const BoxND<dim>& b, const IntVectND<dim>& ref_ratio) noexcept
1488{
1489 BoxND<dim> result = b;
1490 result.coarsen(ref_ratio);
1491 return result;
1492}
1493
1506template<int dim>
1507[[nodiscard]]
1510BoxND<dim> refine (const BoxND<dim>& b, int ref_ratio) noexcept
1511{
1512 BoxND<dim> result = b;
1513 result.refine(IntVectND<dim>(ref_ratio));
1514 return result;
1515}
1516
1524template<int dim>
1525[[nodiscard]]
1528BoxND<dim> refine (const BoxND<dim>& b, const IntVectND<dim>& ref_ratio) noexcept
1529{
1530 BoxND<dim> result = b;
1531 result.refine(ref_ratio);
1532 return result;
1533}
1534
1544template<int dim>
1545[[nodiscard]]
1548BoxND<dim> shift (const BoxND<dim>& b, int dir, int nzones) noexcept
1549{
1550 BoxND<dim> result = b;
1551 result.shift(dir, nzones);
1552 return result;
1553}
1554
1562template<int dim>
1563[[nodiscard]]
1566BoxND<dim> shift (const BoxND<dim>& b, const IntVectND<dim>& nzones) noexcept
1567{
1568 BoxND<dim> result = b;
1569 result.shift(nzones);
1570 return result;
1571}
1572
1578template<int dim>
1579[[nodiscard]]
1582BoxND<dim> surroundingNodes (const BoxND<dim>& b, int dir) noexcept
1583{
1584 BoxND<dim> bx(b);
1585 bx.surroundingNodes(dir);
1586 return bx;
1587}
1588
1593template<int dim>
1594[[nodiscard]]
1598{
1599 return surroundingNodes(b, static_cast<int>(d));
1600}
1601
1607template<int dim>
1608[[nodiscard]]
1612{
1613 BoxND<dim> bx(b);
1614 bx.surroundingNodes();
1615 return bx;
1616}
1617
1626template<int dim>
1627[[nodiscard]]
1630BoxND<dim> convert (const BoxND<dim>& b, const IntVectND<dim>& typ) noexcept
1631{
1632 BoxND<dim> bx(b);
1633 bx.convert(typ);
1634 return bx;
1635}
1636
1644template<int dim>
1645[[nodiscard]]
1648BoxND<dim> convert (const BoxND<dim>& b, const IndexTypeND<dim>& typ) noexcept
1649{
1650 BoxND<dim> bx(b);
1651 bx.convert(typ);
1652 return bx;
1653}
1654
1660template<int dim>
1661[[nodiscard]]
1664BoxND<dim> enclosedCells (const BoxND<dim>& b, int dir) noexcept
1665{
1666 BoxND<dim> bx(b);
1667 bx.enclosedCells(dir);
1668 return bx;
1669}
1670
1675template<int dim>
1676[[nodiscard]]
1680{
1681 return enclosedCells(b, static_cast<int>(d));
1682}
1683
1689template<int dim>
1690[[nodiscard]]
1694{
1695 BoxND<dim> bx(b);
1696 bx.enclosedCells();
1697 return bx;
1698}
1699
1711template<int dim>
1712[[nodiscard]]
1715BoxND<dim> bdryLo (const BoxND<dim>& b, int dir, int len=1) noexcept
1716{
1717 IntVectND<dim> low(b.smallEnd());
1718 IntVectND<dim> hi(b.bigEnd());
1719 int sm = low[dir];
1720 low.setVal(dir,sm-len+1);
1721 hi.setVal(dir,sm);
1722 //
1723 // set dir'th bit to 1 = IndexType::NODE.
1724 //
1725 IndexTypeND<dim> typ(b.ixType());
1726 typ.set(dir);
1727 return BoxND<dim>(low,hi,typ);
1728}
1729
1741template<int dim>
1742[[nodiscard]]
1745BoxND<dim> bdryHi (const BoxND<dim>& b, int dir, int len=1) noexcept
1746{
1747 IntVectND<dim> low(b.smallEnd());
1748 IntVectND<dim> hi(b.bigEnd());
1749 auto const bitval = b.type()[dir];
1750 int bg = hi[dir] + 1 - bitval%2;
1751 low.setVal(dir,bg);
1752 hi.setVal(dir,bg+len-1);
1753 //
1754 // Set dir'th bit to 1 = IndexType::NODE.
1755 //
1756 IndexTypeND<dim> typ(b.ixType());
1757 typ.set(dir);
1758 return BoxND<dim>(low,hi,typ);
1759}
1760
1772template<int dim>
1773[[nodiscard]]
1776BoxND<dim> bdryNode (const BoxND<dim>& b, Orientation face, int len=1) noexcept
1777{
1778 int dir = face.coordDir();
1779 IntVectND<dim> low(b.smallEnd());
1780 IntVectND<dim> hi(b.bigEnd());
1781 if (face.isLow())
1782 {
1783 int sm = low[dir];
1784 low.setVal(dir,sm-len+1);
1785 hi.setVal(dir,sm);
1786 }
1787 else
1788 {
1789 int bitval = b.type()[dir];
1790 int bg = hi[dir] + 1 - bitval%2;
1791 low.setVal(dir,bg);
1792 hi.setVal(dir,bg+len-1);
1793 }
1794 //
1795 // Set dir'th bit to 1 = IndexType::NODE.
1796 //
1797 IndexTypeND<dim> typ(b.ixType());
1798 typ.set(dir);
1799 return BoxND<dim>(low,hi,typ);
1800}
1801
1813template<int dim>
1814[[nodiscard]]
1817BoxND<dim> adjCellLo (const BoxND<dim>& b, int dir, int len=1) noexcept
1818{
1819 BL_ASSERT(len > 0);
1820 IntVectND<dim> low(b.smallEnd());
1821 IntVectND<dim> hi(b.bigEnd());
1822 int sm = low[dir];
1823 low.setVal(dir,sm - len);
1824 hi.setVal(dir,sm - 1);
1825 //
1826 // Set dir'th bit to 0 = IndexType::CELL.
1827 //
1828 IndexTypeND<dim> typ(b.ixType());
1829 typ.unset(dir);
1830 return BoxND<dim>(low,hi,typ);
1831}
1832
1844template<int dim>
1845[[nodiscard]]
1848BoxND<dim> adjCellHi (const BoxND<dim>& b, int dir, int len=1) noexcept
1849{
1850 BL_ASSERT(len > 0);
1851 IntVectND<dim> low(b.smallEnd());
1852 IntVectND<dim> hi(b.bigEnd());
1853 int bitval = b.type()[dir];
1854 int bg = hi[dir] + 1 - bitval%2;
1855 low.setVal(dir,bg);
1856 hi.setVal(dir,bg + len - 1);
1857 //
1858 // Set dir'th bit to 0 = IndexType::CELL.
1859 //
1860 IndexTypeND<dim> typ(b.ixType());
1861 typ.unset(dir);
1862 return BoxND<dim>(low,hi,typ);
1863}
1864
1876template<int dim>
1877[[nodiscard]]
1880BoxND<dim> adjCell (const BoxND<dim>& b, Orientation face, int len=1) noexcept
1881{
1882 BL_ASSERT(len > 0);
1883 IntVectND<dim> low(b.smallEnd());
1884 IntVectND<dim> hi(b.bigEnd());
1885 int dir = face.coordDir();
1886 if (face.isLow())
1887 {
1888 int sm = low[dir];
1889 low.setVal(dir,sm - len);
1890 hi.setVal(dir,sm - 1);
1891 }
1892 else
1893 {
1894 int bitval = b.type()[dir];
1895 int bg = hi[dir] + 1 - bitval%2;
1896 low.setVal(dir,bg);
1897 hi.setVal(dir,bg + len - 1);
1898 }
1899 //
1900 // Set dir'th bit to 0 = IndexType::CELL.
1901 //
1902 IndexTypeND<dim> typ(b.ixType());
1903 typ.unset(dir);
1904 return BoxND<dim>(low,hi,typ);
1905}
1906
1917template<int dim>
1918[[nodiscard]]
1921BoxND<dim> minBox (const BoxND<dim>& b1, const BoxND<dim>& b2) noexcept
1922{
1923 BoxND<dim> result = b1;
1924 result.minBox(b2);
1925 return result;
1926}
1927
1929namespace detail {
1930 std::ostream& box_write (std::ostream& os, const int * smallend, const int * bigend,
1931 const int * type, int dim);
1932 std::istream& box_read (std::istream& is, int * smallend, int * bigend, int * type, int dim);
1933
1934 template<std::size_t...Ns, class T, class U>
1936 auto BoxSplit_imp (std::index_sequence<Ns...>,
1937 const T& lo, const T& hi, const U& typ) noexcept {
1938 return makeTuple(BoxND(get<Ns>(lo), get<Ns>(hi), get<Ns>(typ))...);
1939 }
1940}
1942
1950template<int dim>
1951std::ostream& operator<< (std::ostream& os, const BoxND<dim>& bx)
1952{
1953 IntVectND<dim> type = bx.type();
1954 return detail::box_write(os, bx.smallEnd().begin(), bx.bigEnd().begin(), type.begin(), dim);
1955}
1956
1964template<int dim>
1965std::istream& operator>> (std::istream& is, BoxND<dim>& bx) {
1966 IntVectND<dim> small;
1967 IntVectND<dim> big;
1968 IntVectND<dim> type;
1969 detail::box_read(is, small.begin(), big.begin(), type.begin(), dim);
1970 bx = BoxND<dim>{small, big, type};
1971 return is;
1972}
1973
1983template<int d, int...dims>
1986constexpr BoxND<detail::get_sum<d, dims...>()>
1987BoxCat (const BoxND<d>& bx, const BoxND<dims>&...boxes) noexcept {
1988 auto lo = IntVectCat(bx.smallEnd(), boxes.smallEnd()...);
1989 auto hi = IntVectCat(bx.bigEnd(), boxes.bigEnd()...);
1990 auto typ = IndexTypeCat(bx.ixType(), boxes.ixType()...);
1991 return BoxND<detail::get_sum<d, dims...>()>{lo, hi, typ};
1992}
1993
2000template<int d, int...dims>
2003constexpr GpuTuple<BoxND<d>, BoxND<dims>...>
2004BoxSplit (const BoxND<detail::get_sum<d, dims...>()>& bx) noexcept {
2005 auto lo = IntVectSplit<d, dims...>(bx.smallEnd());
2006 auto hi = IntVectSplit<d, dims...>(bx.bigEnd());
2007 auto typ = IndexTypeSplit<d, dims...>(bx.ixType());
2008 return detail::BoxSplit_imp(std::make_index_sequence<1 + sizeof...(dims)>(), lo, hi, typ);
2009}
2010
2017template<int new_dim, int old_dim>
2020constexpr BoxND<new_dim>
2021BoxShrink (const BoxND<old_dim>& bx) noexcept {
2022 return bx.template shrink<new_dim>();
2023}
2024
2033template<int new_dim, int old_dim>
2036constexpr BoxND<new_dim>
2037BoxExpand (const BoxND<old_dim>& bx) noexcept {
2038 return bx.template expand<new_dim>();
2039}
2040
2047template<int new_dim, int old_dim>
2050constexpr BoxND<new_dim>
2051BoxResize (const BoxND<old_dim>& bx) noexcept {
2052 return bx.template resize<new_dim>();
2053}
2054
2061template<int dim>
2062[[nodiscard]]
2066{
2067 return box.smallEnd();
2068}
2069
2076template<int dim>
2077[[nodiscard]]
2081{
2082 return box.bigEnd();
2083}
2084
2091template<int dim>
2092[[nodiscard]]
2096{
2097 return box.smallEnd();
2098}
2099
2108template<int dim>
2109[[nodiscard]]
2112IntVectND<dim> end_iv (BoxND<dim> const& box) noexcept
2113{
2114 return box.bigEnd() + 1;
2115}
2116
2123template<int dim>
2124[[nodiscard]]
2128{
2129 return box.bigEnd() - box.smallEnd() + 1;
2130}
2131
2139template<int dim>
2140[[nodiscard]]
2143IntVectND<dim> max_lbound_iv (BoxND<dim> const& b1, BoxND<dim> const& b2) noexcept
2144{
2145 return max(b1.smallEnd(), b2.smallEnd());
2146}
2147
2155template<int dim>
2156[[nodiscard]]
2160{
2161 return max(b1.smallEnd(), lo);
2162}
2163
2171template<int dim>
2172[[nodiscard]]
2175IntVectND<dim> min_ubound_iv (BoxND<dim> const& b1, BoxND<dim> const& b2) noexcept
2176{
2177 return min(b1.bigEnd(), b2.bigEnd());
2178}
2179
2187template<int dim>
2188[[nodiscard]]
2192{
2193 return min(b1.bigEnd(), hi);
2194}
2195
2202template<int dim>
2203requires ( 1<=dim && dim<=3 )
2204[[nodiscard]]
2207Dim3 lbound (BoxND<dim> const& box) noexcept
2208{
2209 return box.smallEnd().dim3();
2210}
2211
2218template<int dim>
2219requires ( 1<=dim && dim<=3 )
2220[[nodiscard]]
2223Dim3 ubound (BoxND<dim> const& box) noexcept
2224{
2225 return box.bigEnd().dim3();
2226}
2227
2234template<int dim>
2235requires ( 1<=dim && dim<=3 )
2236[[nodiscard]]
2239Dim3 begin (BoxND<dim> const& box) noexcept
2240{
2241 return box.smallEnd().dim3();
2242}
2243
2252template<int dim>
2253requires ( 1<=dim && dim<=3 )
2254[[nodiscard]]
2257Dim3 end (BoxND<dim> const& box) noexcept
2258{
2259 return (box.bigEnd() + 1).dim3(1);
2260}
2261
2268template<int dim>
2269requires ( 1<=dim && dim<=3 )
2270[[nodiscard]]
2273Dim3 length (BoxND<dim> const& box) noexcept
2274{
2275 return (box.bigEnd() - box.smallEnd() + 1).dim3(1);
2276}
2277
2285template<int dim>
2286requires ( 1<=dim && dim<=3 )
2287[[nodiscard]]
2290Dim3 max_lbound (BoxND<dim> const& b1, BoxND<dim> const& b2) noexcept
2291{
2292 return max(b1.smallEnd(), b2.smallEnd()).dim3();
2293}
2294
2302template<int dim>
2303requires ( 1<=dim && dim<=3 )
2304[[nodiscard]]
2307Dim3 max_lbound (BoxND<dim> const& b1, Dim3 const& lo) noexcept
2308{
2309 return max(b1.smallEnd(), IntVectND<dim>(lo)).dim3();
2310}
2311
2319template<int dim>
2320requires ( 1<=dim && dim<=3 )
2321[[nodiscard]]
2324Dim3 min_ubound (BoxND<dim> const& b1, BoxND<dim> const& b2) noexcept
2325{
2326 return min(b1.bigEnd(), b2.bigEnd()).dim3();
2327}
2328
2336template<int dim>
2337requires ( 1<=dim && dim<=3 )
2338[[nodiscard]]
2341Dim3 min_ubound (BoxND<dim> const& b1, Dim3 const& hi) noexcept
2342{
2343 return min(b1.bigEnd(), IntVectND<dim>(hi)).dim3();
2344}
2345
2346template<int dim>
2347[[nodiscard]]
2350{
2351 return b1;
2352}
2353
2365template<int dim>
2366[[nodiscard]]
2368BoxND<dim> getIndexBounds (BoxND<dim> const& b1, BoxND<dim> const& b2) noexcept
2369{
2370 BoxND<dim> b = b1;
2371 b.setType(b2.ixType());
2372 b.minBox(b2);
2373 return b;
2374}
2375
2388template <class T, class ... Ts>
2389[[nodiscard]]
2391auto getIndexBounds (T const& b1, T const& b2, Ts const& ... b3) noexcept
2392{
2393 return getIndexBounds(getIndexBounds(b1,b2),b3...);
2394}
2395
2404template<int dim>
2405[[nodiscard]]
2408IntVectND<dim> getCell (BoxND<dim> const* boxes, int nboxes, Long icell) noexcept
2409{
2410 int ibox;
2411 Long ncells_subtotal = 0;
2412 Long offset = 0;
2413 for (ibox = 0; ibox < nboxes; ++ibox) {
2414 const Long n = boxes[ibox].numPts();
2415 ncells_subtotal += n;
2416 if (icell < ncells_subtotal) {
2417 offset = icell - (ncells_subtotal - n);
2418 break;
2419 }
2420 }
2421 return boxes[ibox].atOffset(offset);
2422}
2423
2432template<int dim>
2433[[nodiscard]]
2436BoxND<dim> makeSlab (BoxND<dim> const& b, int direction, int slab_index) noexcept
2437{
2438 BoxND<dim> r = b;
2439 r.makeSlab(direction,slab_index);
2440 return r;
2441}
2442
2453template<int dim=AMREX_SPACEDIM>
2454requires ( 1<=dim && dim<=3 )
2455[[nodiscard]]
2459{
2460 Dim3 p3d{.x = i, .y = j, .z = k};
2461 IntVectND<dim> vect{p3d};
2462 return BoxND<dim>{vect, vect, typ};
2463}
2464
2473template<int dim>
2474[[nodiscard]]
2478{
2479 return BoxND<dim>{vect, vect, typ};
2480}
2481
2492template<int dim>
2494{
2495 std::uint64_t npts;
2498
2500 : npts(box.numPts()),
2501 lo (box.smallEnd())
2502 {
2503 std::uint64_t mult = 1;
2504 for (int i=0; i<dim-1; ++i) {
2505 mult *= box.length(i);
2506 fdm[i] = Math::FastDivmodU64(mult);
2507 }
2508 }
2509
2517 IntVectND<dim> intVect (std::uint64_t icell) const
2518 {
2519 IntVectND<dim> retval = lo;
2520
2521 for (int i=dim-1; i>0; --i) {
2522 std::uint64_t quotient, remainder;
2523 fdm[i-1](quotient, remainder, icell);
2524 retval[i] += quotient;
2525 icell = remainder;
2526 }
2527
2528 retval[0] += icell;
2529
2530 return retval;
2531 }
2532
2540 Dim3 operator()(std::uint64_t icell) const
2541 requires (1 <= dim && dim <= 3)
2542 {
2543 return intVect(icell).dim3();
2544 }
2545
2552 std::uint64_t numPts () const { return npts; }
2553};
2554
2558template<>
2560{
2561 std::uint64_t npts;
2562
2563 int lo;
2564
2571 : npts(box.numPts()),
2572 lo(box.smallEnd(0))
2573 {}
2574
2582 IntVectND<1> intVect (std::uint64_t icell) const
2583 {
2584 return IntVectND<1>{int(icell)+lo};
2585 }
2586
2594 Dim3 operator() (std::uint64_t icell) const
2595 {
2596 return Dim3{.x = int(icell)+lo, .y = 0, .z = 0};
2597 }
2598
2605 std::uint64_t numPts () const { return npts; }
2606};
2607
2609
2610}
2611
2612#endif /*AMREX_BOX_H*/
General-purpose algorithm utilities available on both host and device.
Lightweight non-owning multidimensional array accessors for GPU and CPU.
Fixed-size array types for use on GPU and CPU.
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:49
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
Iterator over all IntVects in a Box.
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:124
#define AMREX_IF_ON_HOST(CODE)
Definition AMReX_GpuQualifiers.H:58
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
int idir
Definition AMReX_HypreMLABecLap.cpp:1133
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1129
Array4< Real > fine
Definition AMReX_InterpFaceRegister.cpp:90
Definition AMReX_Box.H:1292
virtual Box doit(const Box &fine) const =0
virtual ~BoxConverter()=default
virtual BoxConverter * clone() const =0
Iterator over all IntVects in a Box.
Definition AMReX_BoxIterator.H:59
A Rectangular Domain on an Integer Lattice.
Definition AMReX_Box.H:54
__host__ __device__ const int * hiVect() &&=delete
__host__ __device__ BoxND & grow(const IntVectND< dim > &v) noexcept
Grow in each direction by the supplied amount (negative shrinks).
Definition AMReX_Box.H:672
__host__ __device__ GpuArray< int, 3 > loVect3d() const noexcept
Return low-end coordinates padded to 3D (missing dims default to 0).
Definition AMReX_Box.H:187
__host__ __device__ constexpr BoxND(const IntVectND< dim > &small, const IntVectND< dim > &big) noexcept
Construct a cell-centered box spanning small through big.
Definition AMReX_Box.H:71
__host__ __device__ bool operator<=(const BoxND &rhs) const noexcept
Return true if this box is <= rhs in the lexicographic ordering.
Definition AMReX_Box.H:340
__host__ __device__ BoxND & grow(int i) noexcept
Grow in all directions by i cells (negative shrinks).
Definition AMReX_Box.H:668
__host__ __device__ GpuArray< int, 3 > length3d() const noexcept
Return lengths padded to 3D (missing dims default to 1).
Definition AMReX_Box.H:178
__host__ __device__ const IntVectND< dim > & bigEnd() const &noexcept
Return the inclusive upper bound of the box.
Definition AMReX_Box.H:136
__host__ __device__ const int * hiVect() const &noexcept
Return a pointer to the high-end coordinates (useful for Fortran calls).
Definition AMReX_Box.H:210
__host__ __device__ BoxND & operator&=(const BoxND &rhs) noexcept
Intersect this BoxND with its argument. The Boxes MUST be of the same type.
Definition AMReX_Box.H:613
__host__ __device__ bool isEmpty() const noexcept
Checks if it is an empty BoxND.
Definition AMReX_Box.H:223
__host__ __device__ BoxND(const IntVectND< dim > &small, const IntVectND< dim > &big, IndexTypeND< dim > t) noexcept
Construct a box with the given index type descriptor.
Definition AMReX_Box.H:105
__host__ static __device__ constexpr int indims() noexcept
Definition AMReX_Box.H:888
__host__ __device__ int bigEnd(int dir) const noexcept
Return the inclusive upper bound in the given direction.
Definition AMReX_Box.H:144
__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:927
__host__ __device__ BoxND & operator-=(const IntVectND< dim > &v) noexcept
Shift BoxND (relative) by given IntVectND<dim>.
Definition AMReX_Box.H:645
__host__ __device__ BoxND & surroundingNodes(Direction d) noexcept
Convert to NODE type in given direction.
Definition AMReX_Box.H:590
__host__ __device__ BoxND & makeSlab(int direction, int slab_index) noexcept
Collapse the box to a single slab at coordinate slab_index along direction.
Definition AMReX_Box.H:860
__host__ __device__ BoxND & setBig(const IntVectND< dim > &bg) noexcept
Redefine the big end of the BoxND.
Definition AMReX_Box.H:516
__host__ __device__ int shortside() const noexcept
Return length of shortest side. Ignores type.
Definition AMReX_Box.H:482
__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:627
__host__ __device__ Long volume() const noexcept
Return the volume, in indexing space, of region enclosed by this BoxND. This is identical to numPts()...
Definition AMReX_Box.H:423
__host__ __device__ BoxND & shift(const IntVectND< dim > &iv) noexcept
Equivalent to b.shift(0,iv[0]).shift(1,iv[1]) ....
Definition AMReX_Box.H:542
__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:913
__host__ __device__ bool isSquare() const noexcept
Definition AMReX_Box.H:1176
__host__ __device__ bool contains(const Dim3 &p) const noexcept
Return true if argument is contained within BoxND.
Definition AMReX_Box.H:239
__host__ __device__ bool cellCentered() const noexcept
Return true if BoxND is cell-centered in all indexing directions.
Definition AMReX_Box.H:356
__host__ __device__ BoxND(const IntVectND< dim > &small, const int *vec_len) noexcept
Construct a box with lower corner small and lengths vec_len.
Definition AMReX_Box.H:82
__host__ __device__ bool coarsenable(int refrat, int min_width=1) const noexcept
Return whether this Box is coarsenable.
Definition AMReX_Box.H:826
__host__ __device__ BoxND & operator+=(const IntVectND< dim > &v) noexcept
Shift BoxND (relative) by given IntVectND<dim>.
Definition AMReX_Box.H:637
__host__ __device__ const int * loVect() &&=delete
__host__ __device__ Long numPts() const noexcept
Return the number of points contained in the BoxND.
Definition AMReX_Box.H:385
__host__ __device__ bool operator>=(const BoxND &rhs) const noexcept
Return true if this box is >= rhs in the lexicographic ordering.
Definition AMReX_Box.H:350
__host__ __device__ bool sameType(const BoxND &b) const noexcept
Return true if Boxes have same type.
Definition AMReX_Box.H:319
__host__ __device__ bool operator!=(const BoxND &b) const noexcept
Return true if Boxes differ (including type).
Definition AMReX_Box.H:327
__host__ __device__ BoxND & setBig(int dir, int bg_index) noexcept
Redefine the big end of the BoxND.
Definition AMReX_Box.H:520
__host__ __device__ BoxND operator-(const IntVectND< dim > &v) const noexcept
Shift BoxND (relative) by given IntVectND<dim>.
Definition AMReX_Box.H:649
__host__ __device__ BoxND & refine(const IntVectND< dim > &ref_ratio) noexcept
Refine BoxND by given (positive) refinement ratio. NOTE: if type(dir) = CELL centered: lo <- lo*ratio...
Definition AMReX_Box.H:945
__host__ __device__ bool sameSize(const BoxND &b) const noexcept
Return true is Boxes same size, ie translates of each other,. It is an error if they have different t...
Definition AMReX_Box.H:312
__host__ __device__ IntVectND< dim > length() const noexcept
Return the length of the BoxND.
Definition AMReX_Box.H:167
__host__ __device__ GpuArray< int, 3 > hiVect3d() const noexcept
Return high-end coordinates padded to 3D (missing dims default to 0).
Definition AMReX_Box.H:196
__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:1008
__host__ __device__ bool contains(const IntVectND< dim > &p) const noexcept
Return true if argument is contained within BoxND.
Definition AMReX_Box.H:233
__host__ __device__ int shortside(int &dir) const noexcept
Return length of shortest side. dir is modified to give direction with shortest side: 0....
Definition AMReX_Box.H:466
__host__ __device__ IntVectND< dim > size() const noexcept
Return the length of the BoxND.
Definition AMReX_Box.H:160
__host__ __device__ int operator[](Orientation face) const noexcept
Return the coordinate normal to the given face.
Definition AMReX_Box.H:216
__host__ __device__ bool strictly_contains(const Dim3 &p) const noexcept
Return true if argument is strictly contained within BoxND.
Definition AMReX_Box.H:284
__host__ __device__ BoxND & shift(int dir, int nzones) noexcept
Shift this BoxND nzones indexing positions in coordinate direction dir.
Definition AMReX_Box.H:538
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:878
__host__ static __device__ constexpr std::size_t ndims() noexcept
Definition AMReX_Box.H:883
__host__ __device__ bool coarsenable(const IntVectND< dim > &refrat, const IntVectND< dim > &min_width) const noexcept
Return whether this Box is coarsenable.
Definition AMReX_Box.H:802
__host__ __device__ BoxND & setSmall(int dir, int sm_index) noexcept
Redefine the small end of the BoxND.
Definition AMReX_Box.H:512
__host__ __device__ double d_numPts() const noexcept
Return the number of points contained in the BoxND. This is intended for use only in diagnostic messa...
Definition AMReX_Box.H:405
__host__ __device__ IntVectND< dim > atOffset(Long offset) const noexcept
Given the offset, compute IntVectND<dim>
Definition AMReX_Box.H:1105
__host__ __device__ BoxND operator+(const IntVectND< dim > &v) const noexcept
Shift BoxND (relative) by given IntVectND<dim>.
Definition AMReX_Box.H:641
__host__ __device__ BoxND & grow(int idir, int n_cell) noexcept
Grow on both ends in direction idir by n_cell cells (negative shrinks).
Definition AMReX_Box.H:678
__host__ __device__ const int * loVect() const &noexcept
Return a pointer to the low-end coordinates (useful for Fortran calls).
Definition AMReX_Box.H:205
__host__ __device__ BoxND & growLo(int idir, int n_cell=1) noexcept
Grow on the low end by n_cell cells in direction idir (negative shrinks).
Definition AMReX_Box.H:690
__host__ __device__ bool contains(const BoxND &b) const noexcept
Return true if argument is contained within BoxND. It is an error if the Boxes have different types.
Definition AMReX_Box.H:259
__host__ __device__ int longside(int &dir) const noexcept
Return length of longest side. dir is modified to give direction with longest side: 0....
Definition AMReX_Box.H:440
__host__ __device__ IndexTypeND< dim > ixType() const noexcept
Return the indexing type.
Definition AMReX_Box.H:148
__host__ __device__ BoxND & growHi(int idir, int n_cell=1) noexcept
Grow on the high end by n_cell cells in direction idir (negative shrinks).
Definition AMReX_Box.H:702
__host__ __device__ bool strictly_contains(const IntVectND< dim > &p) const noexcept
Return true if argument is strictly contained within BoxND.
Definition AMReX_Box.H:267
__host__ __device__ IntVectND< dim > type() const noexcept
Return the indexing type.
Definition AMReX_Box.H:152
__host__ __device__ BoxND & growHi(Direction d, int n_cell=1) noexcept
Grow on the high end by n_cell cells in direction d (negative shrinks).
Definition AMReX_Box.H:708
__host__ __device__ BoxND & growLo(Direction d, int n_cell=1) noexcept
Grow on the low end by n_cell cells in direction d (negative shrinks).
Definition AMReX_Box.H:696
__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:754
__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:730
__host__ __device__ BoxND & setRange(int dir, int sm_index, int n_cells=1) noexcept
Set the entire range in a given direction, starting at sm_index with length n_cells....
Definition AMReX_Box.H:1143
__host__ __device__ bool strictly_contains(int i, int j, int k) const noexcept
Return true if argument is strictly contained within BoxND.
Definition AMReX_Box.H:293
__host__ __device__ Long index(const IntVectND< dim > &v) const noexcept
Return offset of point from smallend; i.e. index(smallend) -> 0, bigend would return numPts()-1....
Definition AMReX_Box.H:1089
__host__ __device__ bool contains(int i, int j, int k) const noexcept
Return true if argument is contained within BoxND.
Definition AMReX_Box.H:248
__host__ __device__ BoxND & setType(const IndexTypeND< dim > &t) noexcept
Set indexing type.
Definition AMReX_Box.H:534
__host__ __device__ BoxND & grow(Direction d, int n_cell) noexcept
Grow on both ends in direction d by n_cell cells (negative shrinks).
Definition AMReX_Box.H:684
__host__ __device__ int longside() const noexcept
Return length of longest side. Ignores type.
Definition AMReX_Box.H:456
__host__ __device__ constexpr BoxND() noexcept
Default constructor creates an invalid box (use ok() to test).
Definition AMReX_Box.H:64
__host__ __device__ BoxND & enclosedCells() noexcept
Convert to CELL type in all directions.
Definition AMReX_Box.H:1074
__host__ __device__ GpuArray< int, 3 > atOffset3d(Long offset) const noexcept
Definition AMReX_Box.H:1133
__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:1156
__host__ __device__ void normalize() noexcept
Ensure each dimension has at least one cell or node by expanding empty directions.
Definition AMReX_Box.H:849
__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:898
__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:962
__host__ __device__ BoxND & shiftHalf(int dir, int num_halfs) noexcept
This member shifts the BoxND by "half" indices, thereby converting the BoxND from type CELL to NODE a...
Definition AMReX_Box.H:1237
__host__ __device__ bool operator==(const BoxND &b) const noexcept
Return true if Boxes are identical (including type).
Definition AMReX_Box.H:323
__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:783
__host__ __device__ int smallEnd(int dir) const &noexcept
Return the inclusive lower bound in the given direction.
Definition AMReX_Box.H:132
__host__ __device__ BoxND & convert(const IntVectND< dim > &typ) noexcept
Convert the BoxND from the current type into the argument type. This may change the BoxND coordinates...
Definition AMReX_Box.H:995
__host__ __device__ BoxND & shiftHalf(const IntVectND< dim > &iv) noexcept
Equivalent to b.shiftHalf(0,iv[0]).shiftHalf(1,iv[1]) ...
Definition AMReX_Box.H:1262
__host__ __device__ bool coarsenable(const IntVectND< dim > &refrat, int min_width=1) const noexcept
Return whether this Box is coarsenable.
Definition AMReX_Box.H:842
__host__ __device__ BoxND & enclosedCells(Direction d) noexcept
Convert to CELL type in given Direction d.
Definition AMReX_Box.H:602
__host__ __device__ bool operator<(const BoxND &rhs) const noexcept
Lexicographic ordering (type, then lower, then upper corners).
Definition AMReX_Box.H:331
__host__ __device__ bool intersects(const BoxND &b) const noexcept
Return true if Boxes have non-null intersections. It is an error if the Boxes have different types.
Definition AMReX_Box.H:305
__host__ __device__ IndexType::CellIndex type(int dir) const noexcept
Return the indexing type in the specified direction.
Definition AMReX_Box.H:156
__host__ __device__ BoxND chop(int dir, int chop_pnt) noexcept
Chop the BoxND at chop_pnt in the dir direction return one BoxND and modify the object BoxND....
Definition AMReX_Box.H:1200
__host__ __device__ bool ok() const noexcept
Return true if high bounds are >= low bounds and the index type is valid.
Definition AMReX_Box.H:229
__host__ __device__ int length(int dir) const noexcept
Return the length of the BoxND in given direction.
Definition AMReX_Box.H:174
friend class BoxCommHelper
Definition AMReX_Box.H:56
__host__ __device__ BoxND & surroundingNodes() noexcept
Convert to NODE type in all directions.
Definition AMReX_Box.H:1042
__host__ __device__ BoxND & grow(Orientation face, int n_cell=1) noexcept
Grow in the direction of the given face.
Definition AMReX_Box.H:712
__host__ __device__ BoxND operator&(const BoxND &rhs) const noexcept
Return BoxND that is intersection of this BoxND and argument. The Boxes MUST be of same type.
Definition AMReX_Box.H:609
__host__ __device__ BoxND(const IntVectND< dim > &small, const IntVectND< dim > &big, const IntVectND< dim > &typ) noexcept
Construct a box with explicit nodal/cell flags per direction.
Definition AMReX_Box.H:95
__host__ __device__ const IntVectND< dim > & smallEnd() const &noexcept
Return the inclusive lower bound of the box.
Definition AMReX_Box.H:124
__host__ __device__ bool operator>(const BoxND &rhs) const noexcept
Return true if this box is > rhs in the lexicographic ordering.
Definition AMReX_Box.H:345
__host__ __device__ BoxND & setSmall(const IntVectND< dim > &sm) noexcept
Definition AMReX_Box.H:508
__host__ __device__ bool strictly_contains(const BoxND &b) const noexcept
Return true if argument is strictly contained within BoxND. It is an error if the Boxes have differen...
Definition AMReX_Box.H:276
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:70
__host__ __device__ void unset(int dir) noexcept
Set IndexTypeND to be CELL based in direction dir.
Definition AMReX_IndexType.H:73
An Integer Vector in dim-Dimensional Space.
Definition AMReX_IntVect.H:149
__host__ __device__ IntVectND & setVal(int i, int val) noexcept
Set i'th coordinate of IntVectND to val.
Definition AMReX_IntVect.H:373
__host__ __device__ constexpr int * begin() noexcept
Returns a pointer to the first element of the IntVectND.
Definition AMReX_IntVect.H:357
__host__ __device__ IntVectND< dim > & coarsen(const IntVectND< dim > &p) noexcept
Modify IntVectND<dim> by component-wise integer projection.
Definition AMReX_IntVect.H:941
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:29
amrex_long Long
Definition AMReX_INT.H:30
__host__ __device__ Dim3 ubound(Array4< T > const &a) noexcept
Return the inclusive upper bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1364
__host__ __device__ Dim3 length(Array4< T > const &a) noexcept
Return the spatial extents of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1378
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Return the inclusive lower bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1350
__host__ __device__ BoxND< dim > adjCellHi(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the BoxND of length len adjacent to b on the high end along coordinate direction dir.
Definition AMReX_Box.H:1848
__host__ __device__ BoxND< dim > makeSingleCellBox(int i, int j, int k, IndexTypeND< dim > typ=IndexTypeND< dim >::TheCellType())
Create a single-cell box at coordinates (i,j,k).
Definition AMReX_Box.H:2458
__host__ __device__ BoxND< dim > convert(const BoxND< dim > &b, const IntVectND< dim > &typ) noexcept
Return a copy of b converted to the nodal flags typ.
Definition AMReX_Box.H:1630
__host__ __device__ BoxND< dim > adjCellLo(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the BoxND of length len adjacent to b on the low end along coordinate direction dir.
Definition AMReX_Box.H:1817
__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:1582
__host__ __device__ BoxND< dim > bdryLo(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the BoxND of length len on the low boundary of b along coordinate direction dir.
Definition AMReX_Box.H:1715
__host__ __device__ BoxND< dim > minBox(const BoxND< dim > &b1, const BoxND< dim > &b2) noexcept
Return the minimal BoxND containing both b1 and b2.
Definition AMReX_Box.H:1921
__host__ __device__ BoxND< dim > coarsen(const BoxND< dim > &b, int ref_ratio) noexcept
Return a copy of b coarsened by the isotropic ratio ref_ratio.
Definition AMReX_Box.H:1469
__host__ __device__ BoxND< dim > adjCell(const BoxND< dim > &b, Orientation face, int len=1) noexcept
Similar to adjCellLo and adjCellHi except that it operates on the given face of BoxND b.
Definition AMReX_Box.H:1880
__host__ __device__ BoxND< dim > shift(const BoxND< dim > &b, int dir, int nzones) noexcept
Return a copy of b shifted by nzones cells in direction dir.
Definition AMReX_Box.H:1548
__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:1664
__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 BoxND b.
Definition AMReX_Box.H:1776
__host__ __device__ BoxND< dim > growLo(const BoxND< dim > &b, int idir, int n_cell) noexcept
Return a copy of b with the low end grown by n_cell cells in direction idir.
Definition AMReX_Box.H:1398
__host__ __device__ BoxND< dim > grow(const BoxND< dim > &b, int i) noexcept
Return a copy of b grown uniformly by i cells in every direction.
Definition AMReX_Box.H:1326
__host__ __device__ BoxND< dim > refine(const BoxND< dim > &b, int ref_ratio) noexcept
Return a copy of b refined by the isotropic ratio ref_ratio.
Definition AMReX_Box.H:1510
__host__ __device__ BoxND< dim > bdryHi(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the BoxND of length len on the high boundary of b along coordinate direction dir.
Definition AMReX_Box.H:1745
__host__ __device__ BoxND< dim > growHi(const BoxND< dim > &b, int idir, int n_cell) noexcept
Return a copy of b with the high end grown by n_cell cells in direction idir.
Definition AMReX_Box.H:1433
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:31
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:53
int MPI_Datatype
Definition AMReX_ccse-mpi.H:53
Definition AMReX_Amr.cpp:50
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Stream helper; forwards to the friend declared inside AmrMesh.
Definition AMReX_AmrMesh.cpp:1306
__host__ __device__ BoxND< dim > makeSlab(BoxND< dim > const &b, int direction, int slab_index) noexcept
Return a copy of b collapsed to a slab perpendicular to direction.
Definition AMReX_Box.H:2436
__host__ __device__ constexpr GpuTuple< detail::tuple_decay_t< Ts >... > makeTuple(Ts &&... args)
Definition AMReX_Tuple.H:269
__host__ __device__ IntVectND< dim > end_iv(BoxND< dim > const &box) noexcept
Return the iterator end IntVectND for box.
Definition AMReX_Box.H:2112
__host__ __device__ Dim3 begin(BoxND< dim > const &box) noexcept
Return the iterator begin coordinate of box as Dim3.
Definition AMReX_Box.H:2239
__host__ __device__ IntVectND< dim > lbound_iv(BoxND< dim > const &box) noexcept
Return the inclusive lower corner of box as an IntVectND.
Definition AMReX_Box.H:2065
__host__ __device__ Dim3 min_ubound(BoxND< dim > const &b1, BoxND< dim > const &b2) noexcept
Return the Dim3 minimum of the upper corners of two boxes.
Definition AMReX_Box.H:2324
__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:1288
__host__ __device__ IntVectND< dim > min_ubound_iv(BoxND< dim > const &b1, BoxND< dim > const &b2) noexcept
Return the component-wise minimum of the upper corners of two boxes.
Definition AMReX_Box.H:2175
void AllGatherBoxes(Vector< Box > &bxs, int n_extra_reserve)
Gather boxes from all MPI ranks into bxs.
Definition AMReX_Box.cpp:124
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
__host__ __device__ constexpr BoxND< new_dim > BoxResize(const BoxND< old_dim > &bx) noexcept
Resize bx to new_dim directions via shrink or expand.
Definition AMReX_Box.H:2051
__host__ __device__ Dim3 max_lbound(BoxND< dim > const &b1, BoxND< dim > const &b2) noexcept
Return the Dim3 maximum of the lower corners of two boxes.
Definition AMReX_Box.H:2290
__host__ __device__ IntVectND< dim > begin_iv(BoxND< dim > const &box) noexcept
Return the iterator begin IntVectND for box.
Definition AMReX_Box.H:2095
__host__ __device__ constexpr BoxND< new_dim > BoxShrink(const BoxND< old_dim > &bx) noexcept
Shrink bx to its first new_dim directions.
Definition AMReX_Box.H:2021
__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:293
__host__ __device__ IntVectND< dim > length_iv(BoxND< dim > const &box) noexcept
Return the side lengths of box as an IntVectND.
Definition AMReX_Box.H:2127
Direction
Definition AMReX_Orientation.H:14
__host__ __device__ constexpr BoxND< detail::get_sum< d, dims... >()> BoxCat(const BoxND< d > &bx, const BoxND< dims > &...boxes) noexcept
Concatenate boxes along their dimensions.
Definition AMReX_Box.H:1987
__host__ __device__ IntVectND< dim > ubound_iv(BoxND< dim > const &box) noexcept
Return the inclusive upper corner of box as an IntVectND.
Definition AMReX_Box.H:2080
__host__ __device__ constexpr BoxND< new_dim > BoxExpand(const BoxND< old_dim > &bx) noexcept
Expand bx to new_dim directions, padding with zeros.
Definition AMReX_Box.H:2037
__host__ __device__ IntVectND< dim > getCell(BoxND< dim > const *boxes, int nboxes, Long icell) noexcept
Return the point coordinate corresponding to the flattened index icell.
Definition AMReX_Box.H:2408
const int[]
Definition AMReX_BLProfiler.cpp:1664
std::istream & operator>>(std::istream &is, BoxND< dim > &bx)
Read a BoxND from is.
Definition AMReX_Box.H:1965
__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:1272
__host__ __device__ Dim3 end(BoxND< dim > const &box) noexcept
Return the iterator end coordinate of box as Dim3.
Definition AMReX_Box.H:2257
BoxND< dim > getIndexBounds(BoxND< dim > const &b1) noexcept
Definition AMReX_Box.H:2349
__host__ __device__ constexpr GpuTuple< BoxND< d >, BoxND< dims >... > BoxSplit(const BoxND< detail::get_sum< d, dims... >()> &bx) noexcept
Split bx into boxes whose dimensions match the template arguments.
Definition AMReX_Box.H:2004
__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:313
__host__ __device__ IntVectND< dim > max_lbound_iv(BoxND< dim > const &b1, BoxND< dim > const &b2) noexcept
Return the component-wise maximum of the lower corners of two boxes.
Definition AMReX_Box.H:2143
A multidimensional array accessor.
Definition AMReX_Array4.H:288
IntVectND< N > end
Exclusive upper bounds.
Definition AMReX_Array4.H:302
IntVectND< N > begin
Inclusive lower bounds.
Definition AMReX_Array4.H:301
BoxIndexerND(BoxND< 1 > const &box)
Construct the 1D indexer; no fast divisors are needed because only one axis exists.
Definition AMReX_Box.H:2570
std::uint64_t npts
Definition AMReX_Box.H:2561
__host__ __device__ std::uint64_t numPts() const
Return the number of points covered by the indexed box.
Definition AMReX_Box.H:2605
__host__ __device__ IntVectND< 1 > intVect(std::uint64_t icell) const
Convert flattened point index icell to the 1D coordinate.
Definition AMReX_Box.H:2582
int lo
Definition AMReX_Box.H:2563
Utility that maps flattened point indices back to IntVectND coordinates.
Definition AMReX_Box.H:2494
__host__ __device__ IntVectND< dim > intVect(std::uint64_t icell) const
Convert flattened point index icell to its IntVectND coordinate.
Definition AMReX_Box.H:2517
BoxIndexerND(BoxND< dim > const &box)
Definition AMReX_Box.H:2499
IntVectND< dim > lo
Definition AMReX_Box.H:2497
__host__ __device__ std::uint64_t numPts() const
Return the number of points covered by the indexed box.
Definition AMReX_Box.H:2552
Math::FastDivmodU64 fdm[dim-1]
Definition AMReX_Box.H:2496
__host__ __device__ Dim3 operator()(std::uint64_t icell) const
Functor returning the coordinate padded to Dim3.
Definition AMReX_Box.H:2540
std::uint64_t npts
Definition AMReX_Box.H:2495
CellIndex
The cell index type: one of CELL or NODE.
Definition AMReX_IndexType.H:21
@ CELL
Definition AMReX_IndexType.H:21
A simple struct holding 3 int values for a 3D index.
Definition AMReX_Dim3.H:24
int x
Definition AMReX_Dim3.H:24
int z
Definition AMReX_Dim3.H:24
int y
Definition AMReX_Dim3.H:24
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:52
Definition AMReX_Math.H:493