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
27
28namespace amrex
29{
30template<int dim>
31class BoxND;
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 }
338
339 [[nodiscard]] AMREX_GPU_HOST_DEVICE
340 bool operator <= (const BoxND& rhs) const noexcept {
341 return !(rhs < *this);
342 }
343
344 [[nodiscard]] AMREX_GPU_HOST_DEVICE
345 bool operator> (const BoxND& rhs) const noexcept {
346 return rhs < *this;
347 }
348
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
497 IntVectND<dim> atOffset (Long offset) const noexcept;
498
502 template <int N=dim>
503 requires (1 <= N && N <= 3)
504 [[nodiscard]] AMREX_GPU_HOST_DEVICE
505 GpuArray<int,3> atOffset3d (Long offset) const noexcept;
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>
1105BoxND<dim>::atOffset (Long offset) const noexcept
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)
1133BoxND<dim>::atOffset3d (Long offset) const noexcept
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{
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
1297 [[nodiscard]] virtual bool equals (const BoxConverter& other) const = 0;
1298 virtual ~BoxConverter () = default;
1299};
1300
1312void AllGatherBoxes (Vector<Box>& bxs, int n_extra_reserve=0);
1313
1324template<int dim>
1325[[nodiscard]]
1328BoxND<dim> grow (const BoxND<dim>& b, int i) noexcept
1329{
1330 BoxND<dim> result = b;
1331 result.grow(i);
1332 return result;
1333}
1334
1342template<int dim>
1343[[nodiscard]]
1346BoxND<dim> grow (const BoxND<dim>& b, const IntVectND<dim>& v) noexcept
1347{
1348 BoxND<dim> result = b;
1349 result.grow(v);
1350 return result;
1351}
1352
1361template<int dim>
1362[[nodiscard]]
1365BoxND<dim> grow (const BoxND<dim>& b, int idir, int n_cell) noexcept
1366{
1367 BoxND<dim> result = b;
1368 result.grow(idir, n_cell);
1369 return result;
1370}
1371
1376template<int dim>
1377[[nodiscard]]
1380BoxND<dim> grow (const BoxND<dim>& b, Direction d, int n_cell) noexcept
1381{
1382 return grow(b, static_cast<int>(d), n_cell);
1383}
1384
1396template<int dim>
1397[[nodiscard]]
1400BoxND<dim> growLo (const BoxND<dim>& b, int idir, int n_cell) noexcept
1401{
1402 BoxND<dim> result = b;
1403 result.growLo(idir, n_cell);
1404 return result;
1405}
1406
1411template<int dim>
1412[[nodiscard]]
1415BoxND<dim> growLo (const BoxND<dim>& b, Direction d, int n_cell) noexcept
1416{
1417 return growLo(b, static_cast<int>(d), n_cell);
1418}
1419
1431template<int dim>
1432[[nodiscard]]
1435BoxND<dim> growHi (const BoxND<dim>& b, int idir, int n_cell) noexcept
1436{
1437 BoxND<dim> result = b;
1438 result.growHi(idir, n_cell);
1439 return result;
1440}
1441
1446template<int dim>
1447[[nodiscard]]
1450BoxND<dim> growHi (const BoxND<dim>& b, Direction d, int n_cell) noexcept
1451{
1452 return growHi(b, static_cast<int>(d), n_cell);
1453}
1454
1467template<int dim>
1468[[nodiscard]]
1471BoxND<dim> coarsen (const BoxND<dim>& b, int ref_ratio) noexcept
1472{
1473 BoxND<dim> result = b;
1474 result.coarsen(IntVectND<dim>(ref_ratio));
1475 return result;
1476}
1477
1485template<int dim>
1486[[nodiscard]]
1489BoxND<dim> coarsen (const BoxND<dim>& b, const IntVectND<dim>& ref_ratio) noexcept
1490{
1491 BoxND<dim> result = b;
1492 result.coarsen(ref_ratio);
1493 return result;
1494}
1495
1508template<int dim>
1509[[nodiscard]]
1512BoxND<dim> refine (const BoxND<dim>& b, int ref_ratio) noexcept
1513{
1514 BoxND<dim> result = b;
1515 result.refine(IntVectND<dim>(ref_ratio));
1516 return result;
1517}
1518
1526template<int dim>
1527[[nodiscard]]
1530BoxND<dim> refine (const BoxND<dim>& b, const IntVectND<dim>& ref_ratio) noexcept
1531{
1532 BoxND<dim> result = b;
1533 result.refine(ref_ratio);
1534 return result;
1535}
1536
1546template<int dim>
1547[[nodiscard]]
1550BoxND<dim> shift (const BoxND<dim>& b, int dir, int nzones) noexcept
1551{
1552 BoxND<dim> result = b;
1553 result.shift(dir, nzones);
1554 return result;
1555}
1556
1564template<int dim>
1565[[nodiscard]]
1568BoxND<dim> shift (const BoxND<dim>& b, const IntVectND<dim>& nzones) noexcept
1569{
1570 BoxND<dim> result = b;
1571 result.shift(nzones);
1572 return result;
1573}
1574
1580template<int dim>
1581[[nodiscard]]
1584BoxND<dim> surroundingNodes (const BoxND<dim>& b, int dir) noexcept
1585{
1586 BoxND<dim> bx(b);
1587 bx.surroundingNodes(dir);
1588 return bx;
1589}
1590
1595template<int dim>
1596[[nodiscard]]
1600{
1601 return surroundingNodes(b, static_cast<int>(d));
1602}
1603
1609template<int dim>
1610[[nodiscard]]
1614{
1615 BoxND<dim> bx(b);
1616 bx.surroundingNodes();
1617 return bx;
1618}
1619
1628template<int dim>
1629[[nodiscard]]
1632BoxND<dim> convert (const BoxND<dim>& b, const IntVectND<dim>& typ) noexcept
1633{
1634 BoxND<dim> bx(b);
1635 bx.convert(typ);
1636 return bx;
1637}
1638
1646template<int dim>
1647[[nodiscard]]
1650BoxND<dim> convert (const BoxND<dim>& b, const IndexTypeND<dim>& typ) noexcept
1651{
1652 BoxND<dim> bx(b);
1653 bx.convert(typ);
1654 return bx;
1655}
1656
1662template<int dim>
1663[[nodiscard]]
1666BoxND<dim> enclosedCells (const BoxND<dim>& b, int dir) noexcept
1667{
1668 BoxND<dim> bx(b);
1669 bx.enclosedCells(dir);
1670 return bx;
1671}
1672
1677template<int dim>
1678[[nodiscard]]
1682{
1683 return enclosedCells(b, static_cast<int>(d));
1684}
1685
1691template<int dim>
1692[[nodiscard]]
1696{
1697 BoxND<dim> bx(b);
1698 bx.enclosedCells();
1699 return bx;
1700}
1701
1713template<int dim>
1714[[nodiscard]]
1717BoxND<dim> bdryLo (const BoxND<dim>& b, int dir, int len=1) noexcept
1718{
1719 IntVectND<dim> low(b.smallEnd());
1720 IntVectND<dim> hi(b.bigEnd());
1721 int sm = low[dir];
1722 low.setVal(dir,sm-len+1);
1723 hi.setVal(dir,sm);
1724 //
1725 // set dir'th bit to 1 = IndexType::NODE.
1726 //
1727 IndexTypeND<dim> typ(b.ixType());
1728 typ.set(dir);
1729 return BoxND<dim>(low,hi,typ);
1730}
1731
1743template<int dim>
1744[[nodiscard]]
1747BoxND<dim> bdryHi (const BoxND<dim>& b, int dir, int len=1) noexcept
1748{
1749 IntVectND<dim> low(b.smallEnd());
1750 IntVectND<dim> hi(b.bigEnd());
1751 auto const bitval = b.type()[dir];
1752 int bg = hi[dir] + 1 - bitval%2;
1753 low.setVal(dir,bg);
1754 hi.setVal(dir,bg+len-1);
1755 //
1756 // Set dir'th bit to 1 = IndexType::NODE.
1757 //
1758 IndexTypeND<dim> typ(b.ixType());
1759 typ.set(dir);
1760 return BoxND<dim>(low,hi,typ);
1761}
1762
1774template<int dim>
1775[[nodiscard]]
1778BoxND<dim> bdryNode (const BoxND<dim>& b, Orientation face, int len=1) noexcept
1779{
1780 int dir = face.coordDir();
1781 IntVectND<dim> low(b.smallEnd());
1782 IntVectND<dim> hi(b.bigEnd());
1783 if (face.isLow())
1784 {
1785 int sm = low[dir];
1786 low.setVal(dir,sm-len+1);
1787 hi.setVal(dir,sm);
1788 }
1789 else
1790 {
1791 int bitval = b.type()[dir];
1792 int bg = hi[dir] + 1 - bitval%2;
1793 low.setVal(dir,bg);
1794 hi.setVal(dir,bg+len-1);
1795 }
1796 //
1797 // Set dir'th bit to 1 = IndexType::NODE.
1798 //
1799 IndexTypeND<dim> typ(b.ixType());
1800 typ.set(dir);
1801 return BoxND<dim>(low,hi,typ);
1802}
1803
1815template<int dim>
1816[[nodiscard]]
1819BoxND<dim> adjCellLo (const BoxND<dim>& b, int dir, int len=1) noexcept
1820{
1821 BL_ASSERT(len > 0);
1822 IntVectND<dim> low(b.smallEnd());
1823 IntVectND<dim> hi(b.bigEnd());
1824 int sm = low[dir];
1825 low.setVal(dir,sm - len);
1826 hi.setVal(dir,sm - 1);
1827 //
1828 // Set dir'th bit to 0 = IndexType::CELL.
1829 //
1830 IndexTypeND<dim> typ(b.ixType());
1831 typ.unset(dir);
1832 return BoxND<dim>(low,hi,typ);
1833}
1834
1846template<int dim>
1847[[nodiscard]]
1850BoxND<dim> adjCellHi (const BoxND<dim>& b, int dir, int len=1) noexcept
1851{
1852 BL_ASSERT(len > 0);
1853 IntVectND<dim> low(b.smallEnd());
1854 IntVectND<dim> hi(b.bigEnd());
1855 int bitval = b.type()[dir];
1856 int bg = hi[dir] + 1 - bitval%2;
1857 low.setVal(dir,bg);
1858 hi.setVal(dir,bg + len - 1);
1859 //
1860 // Set dir'th bit to 0 = IndexType::CELL.
1861 //
1862 IndexTypeND<dim> typ(b.ixType());
1863 typ.unset(dir);
1864 return BoxND<dim>(low,hi,typ);
1865}
1866
1878template<int dim>
1879[[nodiscard]]
1882BoxND<dim> adjCell (const BoxND<dim>& b, Orientation face, int len=1) noexcept
1883{
1884 BL_ASSERT(len > 0);
1885 IntVectND<dim> low(b.smallEnd());
1886 IntVectND<dim> hi(b.bigEnd());
1887 int dir = face.coordDir();
1888 if (face.isLow())
1889 {
1890 int sm = low[dir];
1891 low.setVal(dir,sm - len);
1892 hi.setVal(dir,sm - 1);
1893 }
1894 else
1895 {
1896 int bitval = b.type()[dir];
1897 int bg = hi[dir] + 1 - bitval%2;
1898 low.setVal(dir,bg);
1899 hi.setVal(dir,bg + len - 1);
1900 }
1901 //
1902 // Set dir'th bit to 0 = IndexType::CELL.
1903 //
1904 IndexTypeND<dim> typ(b.ixType());
1905 typ.unset(dir);
1906 return BoxND<dim>(low,hi,typ);
1907}
1908
1919template<int dim>
1920[[nodiscard]]
1923BoxND<dim> minBox (const BoxND<dim>& b1, const BoxND<dim>& b2) noexcept
1924{
1925 BoxND<dim> result = b1;
1926 result.minBox(b2);
1927 return result;
1928}
1929
1931namespace detail {
1932 std::ostream& box_write (std::ostream& os, const int * smallend, const int * bigend,
1933 const int * type, int dim);
1934 std::istream& box_read (std::istream& is, int * smallend, int * bigend, int * type, int dim);
1935
1936 template<std::size_t...Ns, class T, class U>
1938 auto BoxSplit_imp (std::index_sequence<Ns...>,
1939 const T& lo, const T& hi, const U& typ) noexcept {
1940 return makeTuple(BoxND(get<Ns>(lo), get<Ns>(hi), get<Ns>(typ))...);
1941 }
1942}
1944
1952template<int dim>
1953std::ostream& operator<< (std::ostream& os, const BoxND<dim>& bx)
1954{
1955 IntVectND<dim> type = bx.type();
1956 return detail::box_write(os, bx.smallEnd().begin(), bx.bigEnd().begin(), type.begin(), dim);
1957}
1958
1966template<int dim>
1967std::istream& operator>> (std::istream& is, BoxND<dim>& bx) {
1968 IntVectND<dim> small;
1969 IntVectND<dim> big;
1970 IntVectND<dim> type;
1971 detail::box_read(is, small.begin(), big.begin(), type.begin(), dim);
1972 bx = BoxND<dim>{small, big, type};
1973 return is;
1974}
1975
1985template<int d, int...dims>
1988constexpr BoxND<detail::get_sum<d, dims...>()>
1989BoxCat (const BoxND<d>& bx, const BoxND<dims>&...boxes) noexcept {
1990 auto lo = IntVectCat(bx.smallEnd(), boxes.smallEnd()...);
1991 auto hi = IntVectCat(bx.bigEnd(), boxes.bigEnd()...);
1992 auto typ = IndexTypeCat(bx.ixType(), boxes.ixType()...);
1993 return BoxND<detail::get_sum<d, dims...>()>{lo, hi, typ};
1994}
1995
2002template<int d, int...dims>
2005constexpr GpuTuple<BoxND<d>, BoxND<dims>...>
2006BoxSplit (const BoxND<detail::get_sum<d, dims...>()>& bx) noexcept {
2007 auto lo = IntVectSplit<d, dims...>(bx.smallEnd());
2008 auto hi = IntVectSplit<d, dims...>(bx.bigEnd());
2009 auto typ = IndexTypeSplit<d, dims...>(bx.ixType());
2010 return detail::BoxSplit_imp(std::make_index_sequence<1 + sizeof...(dims)>(), lo, hi, typ);
2011}
2012
2019template<int new_dim, int old_dim>
2022constexpr BoxND<new_dim>
2023BoxShrink (const BoxND<old_dim>& bx) noexcept {
2024 return bx.template shrink<new_dim>();
2025}
2026
2035template<int new_dim, int old_dim>
2038constexpr BoxND<new_dim>
2039BoxExpand (const BoxND<old_dim>& bx) noexcept {
2040 return bx.template expand<new_dim>();
2041}
2042
2049template<int new_dim, int old_dim>
2052constexpr BoxND<new_dim>
2053BoxResize (const BoxND<old_dim>& bx) noexcept {
2054 return bx.template resize<new_dim>();
2055}
2056
2063template<int dim>
2064[[nodiscard]]
2068{
2069 return box.smallEnd();
2070}
2071
2078template<int dim>
2079[[nodiscard]]
2083{
2084 return box.bigEnd();
2085}
2086
2093template<int dim>
2094[[nodiscard]]
2098{
2099 return box.smallEnd();
2100}
2101
2110template<int dim>
2111[[nodiscard]]
2114IntVectND<dim> end_iv (BoxND<dim> const& box) noexcept
2115{
2116 return box.bigEnd() + 1;
2117}
2118
2125template<int dim>
2126[[nodiscard]]
2130{
2131 return box.bigEnd() - box.smallEnd() + 1;
2132}
2133
2141template<int dim>
2142[[nodiscard]]
2145IntVectND<dim> max_lbound_iv (BoxND<dim> const& b1, BoxND<dim> const& b2) noexcept
2146{
2147 return max(b1.smallEnd(), b2.smallEnd());
2148}
2149
2157template<int dim>
2158[[nodiscard]]
2162{
2163 return max(b1.smallEnd(), lo);
2164}
2165
2173template<int dim>
2174[[nodiscard]]
2177IntVectND<dim> min_ubound_iv (BoxND<dim> const& b1, BoxND<dim> const& b2) noexcept
2178{
2179 return min(b1.bigEnd(), b2.bigEnd());
2180}
2181
2189template<int dim>
2190[[nodiscard]]
2194{
2195 return min(b1.bigEnd(), hi);
2196}
2197
2204template<int dim>
2205requires ( 1<=dim && dim<=3 )
2206[[nodiscard]]
2209Dim3 lbound (BoxND<dim> const& box) noexcept
2210{
2211 return box.smallEnd().dim3();
2212}
2213
2220template<int dim>
2221requires ( 1<=dim && dim<=3 )
2222[[nodiscard]]
2225Dim3 ubound (BoxND<dim> const& box) noexcept
2226{
2227 return box.bigEnd().dim3();
2228}
2229
2236template<int dim>
2237requires ( 1<=dim && dim<=3 )
2238[[nodiscard]]
2241Dim3 begin (BoxND<dim> const& box) noexcept
2242{
2243 return box.smallEnd().dim3();
2244}
2245
2254template<int dim>
2255requires ( 1<=dim && dim<=3 )
2256[[nodiscard]]
2259Dim3 end (BoxND<dim> const& box) noexcept
2260{
2261 return (box.bigEnd() + 1).dim3(1);
2262}
2263
2270template<int dim>
2271requires ( 1<=dim && dim<=3 )
2272[[nodiscard]]
2275Dim3 length (BoxND<dim> const& box) noexcept
2276{
2277 return (box.bigEnd() - box.smallEnd() + 1).dim3(1);
2278}
2279
2287template<int dim>
2288requires ( 1<=dim && dim<=3 )
2289[[nodiscard]]
2292Dim3 max_lbound (BoxND<dim> const& b1, BoxND<dim> const& b2) noexcept
2293{
2294 return max(b1.smallEnd(), b2.smallEnd()).dim3();
2295}
2296
2304template<int dim>
2305requires ( 1<=dim && dim<=3 )
2306[[nodiscard]]
2309Dim3 max_lbound (BoxND<dim> const& b1, Dim3 const& lo) noexcept
2310{
2311 return max(b1.smallEnd(), IntVectND<dim>(lo)).dim3();
2312}
2313
2321template<int dim>
2322requires ( 1<=dim && dim<=3 )
2323[[nodiscard]]
2326Dim3 min_ubound (BoxND<dim> const& b1, BoxND<dim> const& b2) noexcept
2327{
2328 return min(b1.bigEnd(), b2.bigEnd()).dim3();
2329}
2330
2338template<int dim>
2339requires ( 1<=dim && dim<=3 )
2340[[nodiscard]]
2343Dim3 min_ubound (BoxND<dim> const& b1, Dim3 const& hi) noexcept
2344{
2345 return min(b1.bigEnd(), IntVectND<dim>(hi)).dim3();
2346}
2347
2348template<int dim>
2349[[nodiscard]]
2352{
2353 return b1;
2354}
2355
2367template<int dim>
2368[[nodiscard]]
2370BoxND<dim> getIndexBounds (BoxND<dim> const& b1, BoxND<dim> const& b2) noexcept
2371{
2372 BoxND<dim> b = b1;
2373 b.setType(b2.ixType());
2374 b.minBox(b2);
2375 return b;
2376}
2377
2390template <class T, class ... Ts>
2391[[nodiscard]]
2393auto getIndexBounds (T const& b1, T const& b2, Ts const& ... b3) noexcept
2394{
2395 return getIndexBounds(getIndexBounds(b1,b2),b3...);
2396}
2397
2406template<int dim>
2407[[nodiscard]]
2410IntVectND<dim> getCell (BoxND<dim> const* boxes, int nboxes, Long icell) noexcept
2411{
2412 int ibox;
2413 Long ncells_subtotal = 0;
2414 Long offset = 0;
2415 for (ibox = 0; ibox < nboxes; ++ibox) {
2416 const Long n = boxes[ibox].numPts();
2417 ncells_subtotal += n;
2418 if (icell < ncells_subtotal) {
2419 offset = icell - (ncells_subtotal - n);
2420 break;
2421 }
2422 }
2423 return boxes[ibox].atOffset(offset);
2424}
2425
2434template<int dim>
2435[[nodiscard]]
2438BoxND<dim> makeSlab (BoxND<dim> const& b, int direction, int slab_index) noexcept
2439{
2440 BoxND<dim> r = b;
2441 r.makeSlab(direction,slab_index);
2442 return r;
2443}
2444
2455template<int dim=AMREX_SPACEDIM>
2456requires ( 1<=dim && dim<=3 )
2457[[nodiscard]]
2461{
2462 Dim3 p3d{.x = i, .y = j, .z = k};
2463 IntVectND<dim> vect{p3d};
2464 return BoxND<dim>{vect, vect, typ};
2465}
2466
2475template<int dim>
2476[[nodiscard]]
2480{
2481 return BoxND<dim>{vect, vect, typ};
2482}
2483
2494template<int dim>
2496{
2497 std::uint64_t npts;
2500
2502 : npts(box.numPts()),
2503 lo (box.smallEnd())
2504 {
2505 std::uint64_t mult = 1;
2506 for (int i=0; i<dim-1; ++i) {
2507 mult *= box.length(i);
2508 fdm[i] = Math::FastDivmodU64(mult);
2509 }
2510 }
2511
2519 IntVectND<dim> intVect (std::uint64_t icell) const
2520 {
2521 IntVectND<dim> retval = lo;
2522
2523 for (int i=dim-1; i>0; --i) {
2524 std::uint64_t quotient, remainder;
2525 fdm[i-1](quotient, remainder, icell);
2526 retval[i] += quotient;
2527 icell = remainder;
2528 }
2529
2530 retval[0] += icell;
2531
2532 return retval;
2533 }
2534
2542 Dim3 operator()(std::uint64_t icell) const
2543 requires (1 <= dim && dim <= 3)
2544 {
2545 return intVect(icell).dim3();
2546 }
2547
2554 std::uint64_t numPts () const { return npts; }
2555};
2556
2560template<>
2562{
2563 std::uint64_t npts;
2564
2566
2573 : npts(box.numPts()),
2574 lo(box.smallEnd(0))
2575 {}
2576
2584 IntVectND<1> intVect (std::uint64_t icell) const
2585 {
2586 return IntVectND<1>{int(icell)+lo[0]};
2587 }
2588
2596 Dim3 operator() (std::uint64_t icell) const
2597 {
2598 return Dim3{.x = int(icell)+lo[0], .y = 0, .z = 0};
2599 }
2600
2607 std::uint64_t numPts () const { return npts; }
2608};
2609
2611
2613namespace detail {
2614// The points of bx whose index equals offset modulo stride: lower corner is
2615// the first such point, lengths are the numbers of such points.
2617Box strided_box (Box const& bx, IntVect const& stride, IntVect const& offset)
2618{
2619 IntVect lo, hi;
2620 for (int d = 0; d < AMREX_SPACEDIM; ++d) {
2621 const int s = stride[d];
2622 lo[d] = bx.smallEnd(d) + ((offset[d]-bx.smallEnd(d))%s + s) % s;
2623 hi[d] = lo[d] + (bx.bigEnd(d)-lo[d]+s)/s - 1;
2624 }
2625 return Box(lo, hi);
2626}
2627}
2629
2630}
2631
2632#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
while parser_exe_t p
Definition AMReX_Parser_Exe_Body.H:33
Definition AMReX_Box.H:1292
virtual bool equals(const BoxConverter &other) const =0
Equal only if both produce the same box for every input.
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
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
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
__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__ static __device__ constexpr IndexTypeND< dim > TheCellType() noexcept
This static member function returns an IndexTypeND object of value IndexTypeND::CELL....
Definition AMReX_IndexType.H:150
__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__ static __device__ constexpr IntVectND< dim > TheZeroVector() noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:771
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:1365
__host__ __device__ Dim3 length(Array4< T > const &a) noexcept
Return the spatial extents of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1379
ArrayND< T, 4, true > Array4
Convenient alias for a 4D ArrayND with three spatial dimensions plus a component dimension.
Definition AMReX_Array4.H:1340
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Return the inclusive lower bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1351
__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:1850
__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:2460
__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:1632
__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:1819
__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:1584
__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:1717
__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:1923
__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:1471
__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:1882
__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:1550
__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:1666
__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:1778
__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:1400
__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:1328
__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:1512
__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:1747
__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:1435
__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:54
int MPI_Datatype
Definition AMReX_ccse-mpi.H:53
Definition AMReX_Amr.cpp:50
__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:2438
__host__ __device__ constexpr GpuTuple< detail::tuple_decay_t< Ts >... > makeTuple(Ts &&... args)
Definition AMReX_Tuple.H:275
__host__ __device__ IntVectND< dim > end_iv(BoxND< dim > const &box) noexcept
Return the iterator end IntVectND for box.
Definition AMReX_Box.H:2114
__host__ __device__ Dim3 begin(BoxND< dim > const &box) noexcept
Return the iterator begin coordinate of box as Dim3.
Definition AMReX_Box.H:2241
__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:2067
__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:2326
__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:1314
__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:2177
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:2053
__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:2292
__host__ __device__ IntVectND< dim > begin_iv(BoxND< dim > const &box) noexcept
Return the iterator begin IntVectND for box.
Definition AMReX_Box.H:2097
__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:2023
__host__ __device__ constexpr IntVectND< new_dim > IntVectShrink(const IntVectND< old_dim > &iv) noexcept
Returns a new IntVectND of size new_dim and assigns the first new_dim values of iv to it.
Definition AMReX_IntVect.H:1329
__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
IndexTypeND(const IntVectND< dim > &) -> IndexTypeND< dim >
__host__ __device__ IntVectND< dim > length_iv(BoxND< dim > const &box) noexcept
Return the side lengths of box as an IntVectND.
Definition AMReX_Box.H:2129
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:1989
__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:2082
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
__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:2039
__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:2410
BoxIndexerND< 3 > BoxIndexer
Definition AMReX_Box.H:2610
const int[]
Definition AMReX_BLProfiler.cpp:1665
std::istream & operator>>(std::istream &is, BoxND< dim > &bx)
Read a BoxND from is.
Definition AMReX_Box.H:1967
__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:1298
__host__ __device__ Dim3 end(BoxND< dim > const &box) noexcept
Return the iterator end coordinate of box as Dim3.
Definition AMReX_Box.H:2259
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Stream helper; forwards to the friend declared inside AmrMesh.
Definition AMReX_AmrMesh.cpp:1372
BoxND< dim > getIndexBounds(BoxND< dim > const &b1) noexcept
Definition AMReX_Box.H:2351
__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:2006
__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__ constexpr int get(IntVectND< dim > const &iv) noexcept
Get the Idx-th element of IntVectND<dim>.
Definition AMReX_IntVect.H:1360
__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:2145
IntVectND< N > end
Exclusive upper bounds.
Definition AMReX_Array4.H:303
IntVectND< N > begin
Inclusive lower bounds.
Definition AMReX_Array4.H:302
BoxIndexerND(BoxND< 1 > const &box)
Construct the 1D indexer; no fast divisors are needed because only one axis exists.
Definition AMReX_Box.H:2572
std::uint64_t npts
Definition AMReX_Box.H:2563
__host__ __device__ std::uint64_t numPts() const
Return the number of points covered by the indexed box.
Definition AMReX_Box.H:2607
__host__ __device__ IntVectND< 1 > intVect(std::uint64_t icell) const
Convert flattened point index icell to the 1D coordinate.
Definition AMReX_Box.H:2584
IntVectND< 1 > lo
Definition AMReX_Box.H:2565
Utility that maps flattened point indices back to IntVectND coordinates.
Definition AMReX_Box.H:2496
__host__ __device__ IntVectND< dim > intVect(std::uint64_t icell) const
Convert flattened point index icell to its IntVectND coordinate.
Definition AMReX_Box.H:2519
BoxIndexerND(BoxND< dim > const &box)
Definition AMReX_Box.H:2501
IntVectND< dim > lo
Definition AMReX_Box.H:2499
__host__ __device__ std::uint64_t numPts() const
Definition AMReX_Box.H:2554
Math::FastDivmodU64 fdm[dim-1]
Definition AMReX_Box.H:2498
__host__ __device__ Dim3 operator()(std::uint64_t icell) const
Functor returning the coordinate padded to Dim3.
Definition AMReX_Box.H:2542
std::uint64_t npts
Definition AMReX_Box.H:2497
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:641