Block-Structured AMR Software Framework
 
Loading...
Searching...
No Matches
AMReX_IntVect.H
Go to the documentation of this file.
1#ifndef AMREX_INTVECT_H_
2#define AMREX_INTVECT_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_INT.H>
6#include <AMReX_SPACE.H>
7#include <AMReX_Array.H>
8#include <AMReX_Vector.H>
9#include <AMReX_Dim3.H>
10#include <AMReX_BLassert.H>
11#include <AMReX_Extension.H>
12#include <AMReX_GpuQualifiers.H>
13#include <AMReX_Math.H>
14#include <AMReX_Tuple.H>
15#include <AMReX_TypeTraits.H>
16
17#include <iosfwd>
18#include <cstdlib>
19#include <cmath>
20#include <limits>
21#include <climits>
22#include <algorithm>
23
24namespace amrex {
25
27int coarsen (int i, int ratio) noexcept
28{
29 switch (ratio) {
30 case 1: return i;
31 case 2: return (i<0) ? -std::abs(i+1)/2 -1 : i/2;
32 case 4: return (i<0) ? -std::abs(i+1)/4 -1 : i/4;
33 default: return (i<0) ? -std::abs(i+1)/ratio-1 : i/ratio;
34 }
35}
36
37template <int ratio>
39int coarsen (int i) noexcept
40{
41 return (i<0) ? -std::abs(i+1)/ratio-1 : i/ratio;
42}
43
55template<int dim>
57{
58public:
59 static_assert(dim >= 1, "The number of dimensions of IntVectND must be positive");
60
62 struct shift_hasher {
63 std::size_t operator()(const IntVectND<dim>& vec) const noexcept
64 {
65 static constexpr unsigned shift1 = sizeof(size_t)>=8 ? 20 : 10;
66 static constexpr unsigned shift2 = sizeof(size_t)>=8 ? 40 : 20;
67 if constexpr (dim == 1) {
70 return static_cast<std::size_t>(vec[0]);
71 } else if constexpr (dim == 2) {
73 return static_cast<std::size_t>(vec[0]) ^
74 (static_cast<std::size_t>(vec[1]) << shift1);
75 } else if constexpr (dim == 3) {
76 return static_cast<std::size_t>(vec[0]) ^
77 (static_cast<std::size_t>(vec[1]) << shift1) ^
78 (static_cast<std::size_t>(vec[2]) << shift2);
79 } else {
80 std::size_t seed = dim;
81 // hash function from
82 // https://stackoverflow.com/questions/20511347/a-good-hash-function-for-a-vector
83 for (int i=0; i<dim; ++i) {
84 auto x = static_cast<unsigned int>(vec[i]);
85 x = ((x >> 16) ^ x) * 0x45d9f3b;
86 x = ((x >> 16) ^ x) * 0x45d9f3b;
87 x = (x >> 16) ^ x;
88 seed ^= x + 0x9e3779b9 + (seed << 6) + (seed >> 2);
89 }
90 return seed;
91 }
92 }
93 };
94
96
98
101 constexpr IntVectND () noexcept {} // cannot use = default due to Clang bug // NOLINT
102
108 template <class...Args,
109 std::enable_if_t<
110 (sizeof...(Args)+2 == dim) &&
111 IsConvertible_v<int, Args...>,
112 int> = 0>
114 constexpr IntVectND (int i, int j, Args...ks) noexcept : vect{i, j, static_cast<int>(ks)...} {}
115
120 explicit constexpr IntVectND (int s) noexcept {
121 for (int i=0; i<dim; ++i) {
122 vect[i] = s;
123 }
124 }
125
131 explicit IntVectND (const int* a) noexcept {
132 for (int i=0; i<dim; ++i) {
133 vect[i] = a[i];
134 }
135 }
136
142 explicit IntVectND (const Vector<int>& a) noexcept {
143 BL_ASSERT(a.size() == dim);
144 for (int i=0; i<dim; ++i) {
145 vect[i] = a[i];
146 }
147 }
148
152 explicit IntVectND (const Array<int,dim>& a) noexcept {
153 for (int i=0; i<dim; ++i) {
154 vect[i] = a[i];
155 }
156 }
157
158 template <int N=dim, std::enable_if_t<( 1<=N && N<=3 ), int> = 0>
159 explicit constexpr IntVectND (Dim3 const& a) noexcept {
160 vect[0] = a.x;
161 if constexpr (dim >= 2) {
162 vect[1] = a.y;
163 }
164 if constexpr (dim == 3) {
165 vect[2] = a.z;
166 }
167 }
168
169 // dtor, copy-ctor, copy-op=, move-ctor, and move-op= are compiler generated.
170
171 template <int N=dim, std::enable_if_t<( 1<=N && N<=3 ), int> = 0>
172 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
173 Dim3 dim3 () const noexcept {
174 if constexpr (dim == 1) {
175 return Dim3{vect[0],0,0};
176 } else if constexpr (dim == 2) {
177 return Dim3{vect[0],vect[1],0};
178 } else {
179 return Dim3{vect[0],vect[1],vect[2]};
180 }
181 }
182
183 template <int N=dim, std::enable_if_t<( 1<=N && N<=3 ), int> = 0>
184 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
185 Dim3 dim3 ([[maybe_unused]] int fill_extra) const noexcept {
186 if constexpr (dim == 1) {
187 return Dim3{vect[0],fill_extra,fill_extra};
188 } else if constexpr (dim == 2) {
189 return Dim3{vect[0],vect[1],fill_extra};
190 } else {
191 return Dim3{vect[0],vect[1],vect[2]};
192 }
193 }
194
195 template< typename T = int >
198 toArray () const noexcept {
199 Array<T, dim> ret {};
200 for (int i=0; i<dim; ++i) {
201 ret[i] = T(vect[i]);
202 }
203 return ret;
204 }
205
207
211 int sum () const noexcept
212 {
213 int retval = vect[0];
214 for (int i=1; i<dim; ++i) {
215 retval += vect[i];
216 }
217 return retval;
218 }
219
222 int max () const noexcept
223 {
224 int retval = vect[0];
225 for (int i=1; i<dim; ++i) {
226 retval = retval > vect[i] ? retval : vect[i];
227 }
228 return retval;
229 }
230
233 int min () const noexcept
234 {
235 int retval = vect[0];
236 for (int i=1; i<dim; ++i) {
237 retval = retval < vect[i] ? retval : vect[i];
238 }
239 return retval;
240 }
241
242 //return coordinate with largest value
244 int maxDir(bool a_doAbsValue) const noexcept;
245
247 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr
248 int& operator[] (int i) noexcept { BL_ASSERT(i>=0 && i < dim); return vect[i]; }
249
251 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr
252 const int& operator[] (int i) const noexcept { BL_ASSERT(i>=0 && i < dim); return vect[i]; }
253
255 template<std::size_t i>
256 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr
257 int& get () noexcept {static_assert(0<=i && i<dim); return vect[i];}
258
260 template<std::size_t i>
261 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr
262 const int& get () const noexcept {static_assert(0<=i && i<dim); return vect[i];}
263
265 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr
266 int* begin () noexcept { return &vect[0]; }
267
269 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr
270 const int* begin () const noexcept { return &vect[0]; }
271
273 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr
274 int* end () noexcept { return &vect[dim]; }
275
277 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr
278 const int* end () const noexcept { return &vect[dim]; }
279
282 IntVectND& setVal (int i, int val) noexcept
283 {
284 BL_ASSERT(i>=0 && i<dim); vect[i] = val; return *this;
285 }
286
292 const int* getVect () const& noexcept { return vect; }
294 int* getVect () & noexcept { return vect; }
296 int* getVect () && = delete;
297
300 bool operator== (int val) const noexcept
301 {
302 bool retval = vect[0] == val;
303 for (int i=1; i<dim; ++i) {
304 retval = retval && vect[i] == val;
305 }
306 return retval;
307 }
308
311 bool operator!= (int val) const noexcept
312 {
313 bool retval = vect[0] != val;
314 for (int i=1; i<dim; ++i) {
315 retval = retval || vect[i] != val;
316 }
317 return retval;
318 }
319
322 bool operator== (const IntVectND<dim>& rhs) const noexcept
323 {
324 bool retval = vect[0] == rhs[0];
325 for (int i=1; i<dim; ++i) {
326 retval = retval && vect[i] == rhs[i];
327 }
328 return retval;
329 }
332 bool operator!= (const IntVectND<dim>& rhs) const noexcept
333 {
334 bool retval = vect[0] != rhs[0];
335 for (int i=1; i<dim; ++i) {
336 retval = retval || vect[i] != rhs[i];
337 }
338 return retval;
339 }
342 bool operator< (const IntVectND<dim>& rhs) const noexcept
343 {
344 for (int i=dim-1; i>=0; --i) {
345 if (vect[i] < rhs[i]) {
346 return true;
347 } else if (vect[i] > rhs[i]) {
348 return false;
349 }
350 }
351 return false;
352 }
355 bool operator<= (const IntVectND<dim>& rhs) const noexcept
356 {
357 return !(rhs < *this);
358 }
361 bool operator> (const IntVectND<dim>& rhs) const noexcept
362 {
363 return rhs < *this;
364 }
367 bool operator>= (const IntVectND<dim>& rhs) const noexcept
368 {
369 return !(*this < rhs);
370 }
376 bool allLT (const IntVectND<dim>& rhs) const noexcept
377 {
378 bool retval = vect[0] < rhs[0];
379 for (int i=1; i<dim; ++i) {
380 retval = retval && vect[i] < rhs[i];
381 }
382 return retval;
383 }
388 bool allLT (int rhs) const noexcept
389 {
390 bool retval = vect[0] < rhs;
391 for (int i=1; i<dim; ++i) {
392 retval = retval && vect[i] < rhs;
393 }
394 return retval;
395 }
401 bool allLE (const IntVectND<dim>& rhs) const noexcept
402 {
403 bool retval = vect[0] <= rhs[0];
404 for (int i=1; i<dim; ++i) {
405 retval = retval && vect[i] <= rhs[i];
406 }
407 return retval;
408 }
413 bool allLE (int rhs) const noexcept
414 {
415 bool retval = vect[0] <= rhs;
416 for (int i=1; i<dim; ++i) {
417 retval = retval && vect[i] <= rhs;
418 }
419 return retval;
420 }
426 bool allGT (const IntVectND<dim>& rhs) const noexcept
427 {
428 bool retval = vect[0] > rhs[0];
429 for (int i=1; i<dim; ++i) {
430 retval = retval && vect[i] > rhs[i];
431 }
432 return retval;
433 }
438 bool allGT (int rhs) const noexcept
439 {
440 bool retval = vect[0] > rhs;
441 for (int i=1; i<dim; ++i) {
442 retval = retval && vect[i] > rhs;
443 }
444 return retval;
445 }
451 bool allGE (const IntVectND<dim>& rhs) const noexcept
452 {
453 bool retval = vect[0] >= rhs[0];
454 for (int i=1; i<dim; ++i) {
455 retval = retval && vect[i] >= rhs[i];
456 }
457 return retval;
458 }
463 bool allGE (int rhs) const noexcept
464 {
465 bool retval = vect[0] >= rhs;
466 for (int i=1; i<dim; ++i) {
467 retval = retval && vect[i] >= rhs;
468 }
469 return retval;
470 }
473 IntVectND<dim> operator+ () const noexcept { return *this; }
476 IntVectND<dim> operator- () const noexcept {
477 IntVectND<dim> retval(0);
478 for (int i=0; i<dim; ++i) {
479 retval[i] = -vect[i];
480 }
481 return retval;
482 }
486 {
487 for (int i=0; i<dim; ++i) {
488 vect[i] += s;
489 }
490 return *this;
491 }
495 {
496 for (int i=0; i<dim; ++i) {
497 vect[i] += p[i];
498 }
499 return *this;
500 }
504 {
505 for (int i=0; i<dim; ++i) {
506 vect[i] *= s;
507 }
508 return *this;
509 }
513 {
514 for (int i=0; i<dim; ++i) {
515 vect[i] *= p[i];
516 }
517 return *this;
518 }
522 {
523 for (int i=0; i<dim; ++i) {
524 vect[i] /= s;
525 }
526 return *this;
527 }
531 {
532 for (int i=0; i<dim; ++i) {
533 vect[i] /= p[i];
534 }
535 return *this;
536 }
540 {
541 for (int i=0; i<dim; ++i) {
542 vect[i] -= s;
543 }
544 return *this;
545 }
549 {
550 for (int i=0; i<dim; ++i) {
551 vect[i] -= p[i];
552 }
553 return *this;
554 }
557 IntVectND<dim> operator+ (const IntVectND<dim>& p) const noexcept
558 {
559 IntVectND<dim> retval = *this;
560 return retval += p;
561 }
564 IntVectND<dim> operator+ (int s) const noexcept
565 {
566 IntVectND<dim> retval = *this;
567 return retval += s;
568 }
571 IntVectND<dim> operator- (const IntVectND<dim>& p) const noexcept
572 {
573 IntVectND<dim> retval = *this;
574 return retval -= p;
575 }
578 IntVectND<dim> operator- (int s) const noexcept
579 {
580 IntVectND<dim> retval = *this;
581 return retval -= s;
582 }
585 IntVectND<dim> operator* (const IntVectND<dim>& p) const noexcept
586 {
587 IntVectND<dim> retval = *this;
588 return retval *= p;
589 }
592 IntVectND<dim> operator* (int s) const noexcept
593 {
594 IntVectND<dim> retval = *this;
595 return retval *= s;
596 }
599 IntVectND<dim> operator/ (const IntVectND<dim>& p) const noexcept
600 {
601 IntVectND<dim> retval = *this;
602 return retval /= p;
603 }
606 IntVectND<dim> operator/ (int s) const noexcept
607 {
608 IntVectND<dim> retval = *this;
609 return retval /= s;
610 }
613 IntVectND<dim>& min (const IntVectND<dim>& p) noexcept
614 {
615 for (int i=0; i<dim; ++i) {
616 vect[i] = (vect[i] < p.vect[i] ? vect[i] : p.vect[i]);
617 }
618 return *this;
619 }
622 IntVectND<dim>& max (const IntVectND<dim>& p) noexcept
623 {
624 for (int i=0; i<dim; ++i) {
625 vect[i] = (vect[i] > p.vect[i] ? vect[i] : p.vect[i]);
626 }
627 return *this;
628 }
631 IntVectND<dim>& scale (int s) noexcept {
632 for (int i=0; i<dim; ++i) {
633 vect[i] *= s;
634 }
635 return *this;
636 }
642 IntVectND<dim>& reflect (int ref_ix, int idir) noexcept
643 {
644 BL_ASSERT(idir >= 0 && idir < dim);
645 vect[idir] = -vect[idir] + 2*ref_ix;
646 return *this;
647 }
650 IntVectND<dim>& shift (int coord, int s) noexcept
651 {
652 BL_ASSERT(coord >= 0 && coord < dim); vect[coord] += s; return *this;
653 }
656 IntVectND<dim>& shift (const IntVectND<dim>& iv) noexcept { *this += iv; return *this; }
659 IntVectND<dim>& diagShift (int s) noexcept
660 {
661 for (int i=0; i<dim; ++i) {
662 vect[i] += s;
663 }
664 return *this;
665 }
671 IntVectND<dim>& coarsen (int p) noexcept;
672
680 static constexpr IntVectND<dim> TheZeroVector () noexcept {
681 return IntVectND<dim>(0);
682 }
690 static constexpr IntVectND<dim> TheUnitVector () noexcept {
691 return IntVectND<dim>(1);
692 }
699 static constexpr IntVectND<dim> TheDimensionVector (int d) noexcept {
700 IntVectND<dim> retval(0);
701 retval[d] = 1;
702 return retval;
703 }
710 static constexpr IntVectND<dim> TheNodeVector () noexcept {
711 return IntVectND<dim>(1);
712 }
719 static constexpr IntVectND<dim> TheCellVector () noexcept {
720 return IntVectND<dim>(0);
721 }
722
724 static constexpr IntVectND<dim> TheMaxVector () noexcept {
725 return IntVectND<dim>(std::numeric_limits<int>::max());
726 }
728 static constexpr IntVectND<dim> TheMinVector () noexcept {
729 return IntVectND<dim>(std::numeric_limits<int>::lowest());
730 }
731
733 static constexpr std::size_t size () noexcept {
734 return static_cast<std::size_t>(dim);
735 }
736
738 static constexpr int isize () noexcept {
739 return dim;
740 }
741
742 using value_type = int;
743
748 template<int new_dim>
750 IntVectND<new_dim> shrink () const noexcept {
751 static_assert(new_dim <= dim);
752 return IntVectND<new_dim>(this->begin());
753 }
754
759 template<int new_dim>
761 IntVectND<new_dim> expand (int fill_extra=0) const noexcept {
762 static_assert(new_dim >= dim);
763 IntVectND<new_dim> retval(fill_extra);
764 for (int i=0; i<dim; ++i) {
765 retval[i] = vect[i];
766 }
767 return retval;
768 }
769
774 template<int new_dim>
776 IntVectND<new_dim> resize (int fill_extra=0) const noexcept {
777 if constexpr (new_dim > dim) {
778 return expand<new_dim>(fill_extra);
779 } else {
780 return shrink<new_dim>();
781 }
782 }
783
787 static const IntVectND<dim> Zero;
788
792 static const IntVectND<dim> Unit;
793
794private:
795
796 int vect[dim] = {};
797};
798
799template <int dim>
800inline constexpr const IntVectND<dim> IntVectND<dim>::Zero{0};
801
802template <int dim>
803inline constexpr const IntVectND<dim> IntVectND<dim>::Unit{1};
804
805// Template deduction guide for IntVectND
806template<std::size_t dim>
807AMREX_GPU_HOST_DEVICE // __device__ for HIP
809
810// Template deduction guide for IntVectND
811template <class...Args,
812 std::enable_if_t<
813 IsConvertible_v<int, Args...>,
814 int> = 0>
815AMREX_GPU_HOST_DEVICE // __device__ for HIP
816IntVectND(int, int, Args...) -> IntVectND<sizeof...(Args)+2>;
817
821
822template<int dim>
827{
828 BL_ASSERT(s > 0);
829 switch (s) {
830 case 1:
831 break;
832 case 2:
833 for (int i=0; i<dim; ++i) {
834 vect[i] = (vect[i]<0) ? -std::abs(vect[i]+1)/2-1 : vect[i]/2;
835 }
836 break;
837 case 4:
838 for (int i=0; i<dim; ++i) {
839 vect[i] = (vect[i]<0) ? -std::abs(vect[i]+1)/4-1 : vect[i]/4;
840 }
841 break;
842 default:
843 for (int i=0; i<dim; ++i) {
844 vect[i] = (vect[i]<0) ? -std::abs(vect[i]+1)/s-1 : vect[i]/s;
845 }
846 }
847 return *this;
848}
849
850template<int dim>
855{
856 BL_ASSERT(p.allGT(0));
857 for (int i=0; i<dim; ++i) {
858 vect[i] = amrex::coarsen(vect[i], p.vect[i]);
859 }
860 return *this;
861}
862
863template<int dim>
866int
867IntVectND<dim>::maxDir(bool a_doAbsValue) const noexcept
868{
869 int retval = 0;
870 if(a_doAbsValue)
871 {
872 int maxval = std::abs((*this)[0]);
873 for(int idir = 1; idir < dim; idir++)
874 {
875 int curval = std::abs((*this)[idir]);
876 if(curval > maxval)
877 {
878 maxval = curval;
879 retval = idir;
880 }
881 }
882 }
883 else
884 {
885 int maxval = (*this)[0];
886 for(int idir = 1; idir < dim; idir++)
887 {
888 int curval = (*this)[idir];
889 if(curval > maxval)
890 {
891 maxval = curval;
892 retval = idir;
893 }
894 }
895 }
896 return retval;
897}
898
900template<int dim>
903IntVectND<dim> operator+ (int s, const IntVectND<dim>& p) noexcept
904{
905 IntVectND<dim> retval = p;
906 for (int i=0; i<dim; ++i) {
907 retval[i] = s + retval[i];
908 }
909 return retval;
910}
911
913template<int dim>
917IntVectND<dim> operator- (int s, const IntVectND<dim>& p) noexcept
918{
919 IntVectND<dim> retval = p;
920 for (int i=0; i<dim; ++i) {
921 retval[i] = s - retval[i];
922 }
923 return retval;
924}
925
927template<int dim>
930IntVectND<dim> operator* (int s, const IntVectND<dim>& p) noexcept
931{
932 IntVectND<dim> retval = p;
933 for (int i=0; i<dim; ++i) {
934 retval[i] = s * retval[i];
935 }
936 return retval;
937}
938
943template<int dim>
946IntVectND<dim>
947min (const IntVectND<dim>& p1, const IntVectND<dim>& p2) noexcept
948{
949 IntVectND<dim> p(p1);
950 p.min(p2);
951 return p;
952}
953
954template<int dim>
957IntVectND<dim>
958elemwiseMin (const IntVectND<dim>& p1, const IntVectND<dim>& p2) noexcept
959{
960 IntVectND<dim> p(p1);
961 p.min(p2);
962 return p;
963}
964
969template<int dim>
972IntVectND<dim>
973max (const IntVectND<dim>& p1, const IntVectND<dim>& p2) noexcept
974{
975 IntVectND<dim> p(p1);
976 p.max(p2);
977 return p;
978}
979
980template<int dim>
983IntVectND<dim>
984elemwiseMax (const IntVectND<dim>& p1, const IntVectND<dim>& p2) noexcept
985{
986 IntVectND<dim> p(p1);
987 p.max(p2);
988 return p;
989}
990
996template<int dim = AMREX_SPACEDIM>
999IntVectND<dim>
1000BASISV (int dir) noexcept
1001{
1002 BL_ASSERT(dir >= 0 && dir < dim);
1003 IntVectND<dim> tmp(0);
1004 tmp[dir] = 1;
1005 return tmp;
1006}
1007
1012template<int dim>
1015IntVectND<dim>
1016scale (const IntVectND<dim>& p, int s) noexcept
1017{
1018 return IntVectND<dim>(p).scale(s);
1019}
1020
1026template<int dim>
1029IntVectND<dim>
1030reflect (const IntVectND<dim>& a, int ref_ix, int idir) noexcept
1031{
1032 return IntVectND<dim>(a).reflect(ref_ix, idir);
1033}
1034
1039template<int dim>
1042IntVectND<dim>
1043diagShift (const IntVectND<dim>& p, int s) noexcept
1044{
1045 return p + s;
1046}
1047
1052template<int dim>
1055IntVectND<dim>
1056coarsen (const IntVectND<dim>& p, int s) noexcept
1057{
1058 BL_ASSERT(s > 0);
1059 IntVectND<dim> v = p;
1060 v.coarsen(s);
1061 return v;
1062}
1063
1068template<int dim>
1071IntVectND<dim>
1072coarsen (const IntVectND<dim>& p1, const IntVectND<dim>& p2) noexcept
1073{
1074 IntVectND<dim> v = p1;
1075 v.coarsen(p2);
1076 return v;
1077}
1078
1079template<int dim, std::enable_if_t<( 1<=dim && dim<=3 ), int> = 0>
1080AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1081Dim3 refine (Dim3 const& coarse, IntVectND<dim> const& ratio) noexcept
1082{
1083 if constexpr (dim == 1) {
1084 return Dim3{coarse.x*ratio[0], coarse.y, coarse.z};
1085 } else if constexpr (dim == 2) {
1086 return Dim3{coarse.x*ratio[0], coarse.y*ratio[1], coarse.z};
1087 } else {
1088 return Dim3{coarse.x*ratio[0], coarse.y*ratio[1], coarse.z*ratio[2]};
1089 }
1090}
1091
1092template<int dim, std::enable_if_t<( 1<=dim && dim<=3 ), int> = 0>
1093AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1094Dim3 coarsen (Dim3 const& fine, IntVectND<dim> const& ratio) noexcept
1095{
1096 if constexpr (dim == 1) {
1097 return Dim3{amrex::coarsen(fine.x, ratio[0]),
1098 fine.y,
1099 fine.z};
1100 } else if constexpr (dim == 2) {
1101 return Dim3{amrex::coarsen(fine.x, ratio[0]),
1102 amrex::coarsen(fine.y, ratio[1]),
1103 fine.z};
1104 } else {
1105 return Dim3{amrex::coarsen(fine.x, ratio[0]),
1106 amrex::coarsen(fine.y, ratio[1]),
1107 amrex::coarsen(fine.z, ratio[2])};
1108 }
1109}
1110
1112namespace detail {
1113 std::ostream& int_vector_write (std::ostream& os, const int* iv, int dim);
1114 std::istream& int_vector_read (std::istream& is, int* iv, int dim);
1115
1116 template<int dim>
1118 void IntVectCat_imp (int*& dst, const IntVectND<dim>& src) noexcept {
1119 for (int i=0; i<dim; ++i) {
1120 dst[i] = src[i];
1121 }
1122 dst += dim;
1123 }
1124
1125 template<int dim>
1127 void IntVectSplit_imp2 (IntVectND<dim>& dst, const int*& src) noexcept {
1128 for (int i=0; i<dim; ++i) {
1129 dst[i] = src[i];
1130 }
1131 src += dim;
1132 }
1133
1134 template<class T, std::size_t...Ns>
1136 T IntVectSplit_imp (T& retval, std::index_sequence<Ns...>, const int * src) noexcept {
1137 (IntVectSplit_imp2(amrex::get<Ns>(retval), src), ...);
1138 return retval;
1139 }
1140
1141 template<int...dims>
1143 int get_sum () {
1144 return (0 + ... + dims);
1145 }
1146}
1148
1149template<int dim>
1150std::ostream&
1151operator<< (std::ostream& os, const IntVectND<dim>& iv)
1152{
1153 return detail::int_vector_write(os, iv.begin(), dim);
1154}
1155
1156template<int dim>
1157std::istream&
1158operator>> (std::istream& is, IntVectND<dim>& iv)
1159{
1160 return detail::int_vector_read(is, iv.begin(), dim);
1161}
1162
1167template<int d, int...dims>
1170constexpr IntVectND<detail::get_sum<d, dims...>()>
1171IntVectCat (const IntVectND<d>& v, const IntVectND<dims>&...vects) noexcept {
1172 IntVectND<detail::get_sum<d, dims...>()> retval (0);
1173 int* dst = retval.begin();
1174 detail::IntVectCat_imp(dst, v);
1175 (detail::IntVectCat_imp(dst, vects), ...);
1176 return retval;
1177}
1178
1183template<int d, int...dims>
1186constexpr GpuTuple<IntVectND<d>, IntVectND<dims>...>
1187IntVectSplit (const IntVectND<detail::get_sum<d, dims...>()>& v) noexcept {
1189 return detail::IntVectSplit_imp(retval,
1190 std::make_index_sequence<1 + sizeof...(dims)>(),
1191 v.begin());
1192}
1193
1198template<int new_dim, int old_dim>
1201constexpr IntVectND<new_dim>
1202IntVectShrink (const IntVectND<old_dim>& iv) noexcept {
1203 return iv.template shrink<new_dim>();
1204}
1205
1210template<int new_dim, int old_dim>
1213constexpr IntVectND<new_dim>
1214IntVectExpand (const IntVectND<old_dim>& iv, int fill_extra=0) noexcept {
1215 return iv.template expand<new_dim>(fill_extra);
1216}
1217
1222template<int new_dim, int old_dim>
1225constexpr IntVectND<new_dim>
1226IntVectResize (const IntVectND<old_dim>& iv, int fill_extra=0) noexcept {
1227 return iv.template resize<new_dim>(fill_extra);
1228}
1229
1230} // namespace amrex
1231
1232// Spcialize std::tuple_size for IntVectND. Used by structured bindings.
1233template<int dim>
1234struct std::tuple_size<amrex::IntVectND<dim>> {
1235 static constexpr std::size_t value = dim;
1236};
1237
1238// Spcialize std::tuple_element for IntVectND. Used by structured bindings.
1239template<std::size_t s, int dim>
1240struct std::tuple_element<s, amrex::IntVectND<dim>> {
1241 using type = int;
1242};
1243
1244#endif /*AMREX_INTVECT_H*/
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
int idir
Definition AMReX_HypreMLABecLap.cpp:1093
GPU-compatible tuple.
Definition AMReX_Tuple.H:98
An Integer Vector in dim-Dimensional Space.
Definition AMReX_IntVect.H:57
__host__ __device__ IntVectND(const int *a) noexcept
Construct an IntVectND setting the coordinates to the corresponding values in the integer array a.
Definition AMReX_IntVect.H:131
__host__ __device__ bool operator<=(const IntVectND< dim > &rhs) const noexcept
Return true if this is lexicographically less than or equal to rhs.
Definition AMReX_IntVect.H:355
IntVectND(const Array< int, dim > &a) noexcept
Construct an IntVectND from an Array<int,dim>.
Definition AMReX_IntVect.H:152
__host__ __device__ IntVectND< dim > & reflect(int ref_ix, int idir) noexcept
Modify IntVectND by reflecting it in the plane defined by the index ref_ix and with normal in the dir...
Definition AMReX_IntVect.H:642
__host__ __device__ int * getVect() &noexcept
Definition AMReX_IntVect.H:294
__host__ __device__ bool allLT(int rhs) const noexcept
Returns true if this is less than argument for all components.
Definition AMReX_IntVect.H:388
__host__ __device__ constexpr int & operator[](int i) noexcept
Returns a reference to the i'th coordinate of the IntVectND.
Definition AMReX_IntVect.H:248
__host__ __device__ int sum() const noexcept
Definition AMReX_IntVect.H:211
__host__ __device__ IntVectND< dim > & shift(const IntVectND< dim > &iv) noexcept
Equivalent to shift(0,iv[0]).shift(1,iv[1]) ...
Definition AMReX_IntVect.H:656
__host__ __device__ IntVectND< dim > & min(const IntVectND< dim > &p) noexcept
Modifies IntVectND by taking component-wise min with argument.
Definition AMReX_IntVect.H:613
__host__ __device__ bool operator!=(int val) const noexcept
Returns true if any component is not equal to the argument val.
Definition AMReX_IntVect.H:311
__host__ __device__ bool operator>=(const IntVectND< dim > &rhs) const noexcept
Return true if this is lexicographically greater than or equal to rhs.
Definition AMReX_IntVect.H:367
__host__ __device__ bool allGT(int rhs) const noexcept
Returns true if this is greater than argument for all components.
Definition AMReX_IntVect.H:438
int value_type
Definition AMReX_IntVect.H:742
__host__ __device__ IntVectND< dim > & operator-=(int s) noexcept
Modifies IntVectND by subtraction of a scalar to each component.
Definition AMReX_IntVect.H:539
__host__ __device__ constexpr int & get() noexcept
Returns a reference to the i'th coordinate of the IntVectND. Used by structured bindings.
Definition AMReX_IntVect.H:257
__host__ __device__ IntVectND< dim > & operator/=(int s) noexcept
Modifies IntVectND by division by a scalar to each component.
Definition AMReX_IntVect.H:521
__host__ __device__ IntVectND< dim > operator+() const noexcept
Unary plus – for completeness.
Definition AMReX_IntVect.H:473
__host__ __device__ IntVectND< dim > & diagShift(int s) noexcept
Modify IntVectND by adding s to each coordinate.
Definition AMReX_IntVect.H:659
__host__ __device__ bool allGE(const IntVectND< dim > &rhs) const noexcept
Returns true if this is greater than or equal to argument for all components. NOTE: This is NOT a str...
Definition AMReX_IntVect.H:451
__host__ __device__ int * getVect() &&=delete
__host__ static __device__ constexpr IntVectND< dim > TheMaxVector() noexcept
Definition AMReX_IntVect.H:724
__host__ static __device__ constexpr std::size_t size() noexcept
Definition AMReX_IntVect.H:733
__host__ __device__ IntVectND & setVal(int i, int val) noexcept
Set i'th coordinate of IntVectND to val.
Definition AMReX_IntVect.H:282
IntVectND(const Vector< int > &a) noexcept
Construct an IntVectND from an Vector<int>. It is an error if the Vector<int> doesn't have the same d...
Definition AMReX_IntVect.H:142
__host__ __device__ IntVectND< dim > & operator+=(int s) noexcept
Modifies IntVectND by addition of a scalar to each component.
Definition AMReX_IntVect.H:485
__host__ __device__ bool operator==(int val) const noexcept
Returns true if all components are equal to the argument val.
Definition AMReX_IntVect.H:300
__host__ __device__ constexpr int * begin() noexcept
Returns a pointer to the first element of the IntVectND.
Definition AMReX_IntVect.H:266
__host__ __device__ IntVectND< dim > & coarsen(const IntVectND< dim > &p) noexcept
Modify IntVectND<dim> by component-wise integer projection.
Definition AMReX_IntVect.H:854
__host__ static __device__ constexpr IntVectND< dim > TheUnitVector() noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:690
__host__ __device__ IntVectND< new_dim > expand(int fill_extra=0) const noexcept
Returns a new IntVectND of size new_dim and assigns all values of this IntVectND to it and fill_extra...
Definition AMReX_IntVect.H:761
__host__ __device__ bool allGT(const IntVectND< dim > &rhs) const noexcept
Returns true if this is greater than argument for all components. NOTE: This is NOT a strict weak ord...
Definition AMReX_IntVect.H:426
__host__ __device__ bool allLT(const IntVectND< dim > &rhs) const noexcept
Returns true if this is less than argument for all components. NOTE: This is NOT a strict weak orderi...
Definition AMReX_IntVect.H:376
__host__ __device__ IntVectND< dim > & shift(int coord, int s) noexcept
Modify IntVectND by adding s to given coordinate.
Definition AMReX_IntVect.H:650
__host__ __device__ int maxDir(bool a_doAbsValue) const noexcept
Definition AMReX_IntVect.H:867
__host__ __device__ const int * getVect() const &noexcept
Returns a const pointer to an array of coordinates of the IntVectND. Useful for arguments to FORTRAN ...
Definition AMReX_IntVect.H:292
__host__ __device__ int min() const noexcept
minimum (no absolute values) value
Definition AMReX_IntVect.H:233
static const IntVectND< dim > Unit
Definition AMReX_IntVect.H:792
__host__ __device__ int max() const noexcept
maximum (no absolute values) value
Definition AMReX_IntVect.H:222
__host__ __device__ constexpr const int * begin() const noexcept
Returns a pointer to the first element of the IntVectND.
Definition AMReX_IntVect.H:270
__host__ __device__ bool allLE(int rhs) const noexcept
Returns true if this is less than or equal to argument for all components.
Definition AMReX_IntVect.H:413
__host__ __device__ IntVectND< dim > operator*(const IntVectND< dim > &p) const noexcept
Returns component-wise product of IntVectND and argument.
Definition AMReX_IntVect.H:585
__host__ static __device__ constexpr IntVectND< dim > TheCellVector() noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:719
__host__ __device__ constexpr IntVectND(int i, int j, Args...ks) noexcept
Construct an IntVectND given the specific values for its coordinates. The inputs for this constructor...
Definition AMReX_IntVect.H:114
__host__ __device__ bool operator<(const IntVectND< dim > &rhs) const noexcept
Return true if this is lexicographically less than rhs.
Definition AMReX_IntVect.H:342
__host__ __device__ bool allGE(int rhs) const noexcept
Returns true if this is greater than or equal to argument for all components.
Definition AMReX_IntVect.H:463
__host__ __device__ IntVectND< dim > & operator*=(int s) noexcept
Modifies IntVectND by multiplication of a scalar to each component.
Definition AMReX_IntVect.H:503
__host__ __device__ IntVectND< dim > operator/(const IntVectND< dim > &p) const noexcept
Returns component-wise division of IntVectND by argument.
Definition AMReX_IntVect.H:599
__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:680
__host__ __device__ IntVectND< dim > & scale(int s) noexcept
Modify IntVectND by multiplying each coordinate by s.
Definition AMReX_IntVect.H:631
__host__ __device__ IntVectND< dim > & coarsen(int p) noexcept
Modify IntVectND<dim> by component-wise integer projection.
Definition AMReX_IntVect.H:826
__host__ static __device__ constexpr IntVectND< dim > TheNodeVector() noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:710
static const IntVectND< dim > Zero
Definition AMReX_IntVect.H:787
__host__ __device__ Array< T, dim > toArray() const noexcept
Definition AMReX_IntVect.H:198
__host__ __device__ IntVectND< new_dim > shrink() const noexcept
Returns a new IntVectND of size new_dim and assigns the first new_dim values of this IntVectND to it.
Definition AMReX_IntVect.H:750
__host__ __device__ constexpr int * end() noexcept
Returns a pointer to the (last+1) element of the IntVectND.
Definition AMReX_IntVect.H:274
__host__ static __device__ constexpr int isize() noexcept
Definition AMReX_IntVect.H:738
__host__ __device__ IntVectND< dim > & max(const IntVectND< dim > &p) noexcept
Modifies IntVectND by taking component-wise max with argument.
Definition AMReX_IntVect.H:622
__host__ __device__ constexpr IntVectND(int s) noexcept
Construct an IntVectND whose components are all the same.
Definition AMReX_IntVect.H:120
__host__ __device__ constexpr const int * end() const noexcept
Returns a pointer to the (last+1) element of the IntVectND.
Definition AMReX_IntVect.H:278
__host__ __device__ bool operator>(const IntVectND< dim > &rhs) const noexcept
Return true if this is lexicographically greater than rhs.
Definition AMReX_IntVect.H:361
__host__ __device__ IntVectND< new_dim > resize(int fill_extra=0) const noexcept
Returns a new IntVectND of size new_dim by either shrinking or expanding this IntVectND.
Definition AMReX_IntVect.H:776
__host__ __device__ constexpr const int & get() const noexcept
Returns a reference to the i'th coordinate of the IntVectND. Used by structured bindings.
Definition AMReX_IntVect.H:262
constexpr IntVectND() noexcept
Construct an IntVectND whose components are all zero.
Definition AMReX_IntVect.H:101
__host__ __device__ bool allLE(const IntVectND< dim > &rhs) const noexcept
Returns true if this is less than or equal to argument for all components. NOTE: This is NOT a strict...
Definition AMReX_IntVect.H:401
int vect[dim]
Definition AMReX_IntVect.H:796
__host__ static __device__ constexpr IntVectND< dim > TheMinVector() noexcept
Definition AMReX_IntVect.H:728
__host__ __device__ IntVectND< dim > operator-() const noexcept
Unary Minus – negates all components.
Definition AMReX_IntVect.H:476
__host__ static __device__ constexpr IntVectND< dim > TheDimensionVector(int d) noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:699
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:28
__host__ __device__ BoxND< dim > coarsen(const BoxND< dim > &b, int ref_ratio) noexcept
Coarsen BoxND by given (positive) coarsening ratio.
Definition AMReX_Box.H:1409
std::array< T, N > Array
Definition AMReX_Array.H:25
Definition AMReX_Amr.cpp:49
__host__ __device__ void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:138
__host__ __device__ constexpr IntVectND< new_dim > IntVectResize(const IntVectND< old_dim > &iv, int fill_extra=0) noexcept
Returns a new IntVectND of size new_dim by either shrinking or expanding iv.
Definition AMReX_IntVect.H:1226
__host__ __device__ constexpr GpuTuple< IntVectND< d >, IntVectND< dims >... > IntVectSplit(const IntVectND< detail::get_sum< d, dims... >()> &v) noexcept
Returns a tuple of IntVectND obtained by splitting the input IntVectND according to the dimensions sp...
Definition AMReX_IntVect.H:1187
__host__ __device__ IntVectND< dim > BASISV(int dir) noexcept
Returns a basis vector in the given coordinate direction; eg. IntVectND<3> BASISV<3>(1) == (0,...
Definition AMReX_IntVect.H:1000
__host__ __device__ constexpr T elemwiseMax(T const &a, T const &b) noexcept
Definition AMReX_Algorithm.H:62
__host__ __device__ GpuComplex< T > operator*(const GpuComplex< T > &a_x, const GpuComplex< U > &a_y) noexcept
Multiply two complex numbers.
Definition AMReX_GpuComplex.H:257
__host__ __device__ IntVectND< dim > reflect(const IntVectND< dim > &a, int ref_ix, int idir) noexcept
Returns an IntVectND that is the reflection of input in the plane which passes through ref_ix and nor...
Definition AMReX_IntVect.H:1030
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:21
constexpr bool IsConvertible_v
Definition AMReX_TypeTraits.H:276
__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:1202
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:35
__host__ __device__ IntVectND< dim > diagShift(const IntVectND< dim > &p, int s) noexcept
Returns IntVectND obtained by adding s to each of the components of this IntVectND.
Definition AMReX_IntVect.H:1043
__host__ __device__ constexpr IntVectND< new_dim > IntVectExpand(const IntVectND< old_dim > &iv, int fill_extra=0) noexcept
Returns a new IntVectND of size new_dim and assigns all values of iv to it and fill_extra to the rema...
Definition AMReX_IntVect.H:1214
__host__ __device__ XDim3 operator-(XDim3 const &a, XDim3 const &b)
Definition AMReX_Dim3.H:34
__host__ __device__ XDim3 operator+(XDim3 const &a, XDim3 const &b)
Definition AMReX_Dim3.H:28
__host__ __device__ constexpr T elemwiseMin(T const &a, T const &b) noexcept
Definition AMReX_Algorithm.H:49
__host__ __device__ IntVectND< dim > scale(const IntVectND< dim > &p, int s) noexcept
Returns a IntVectND obtained by multiplying each of the components of this IntVectND by s.
Definition AMReX_IntVect.H:1016
Hash function for IntVectND.
Definition AMReX_IntVect.H:62
std::size_t operator()(const IntVectND< dim > &vec) const noexcept
Definition AMReX_IntVect.H:63
int type
Definition AMReX_IntVect.H:1241