1 #ifndef AMREX_BASEFAB_H_
2 #define AMREX_BASEFAB_H_
3 #include <AMReX_Config.H>
33 #include <type_traits>
50 #pragma omp threadprivate(private_total_bytes_allocated_in_fabs)
51 #pragma omp threadprivate(private_total_bytes_allocated_in_fabs_hwm)
52 #pragma omp threadprivate(private_total_cells_allocated_in_fabs)
53 #pragma omp threadprivate(private_total_cells_allocated_in_fabs_hwm)
68 explicit SrcComp (
int ai) noexcept : i(ai) {}
93 std::enable_if_t<std::is_arithmetic_v<T>>
98 std::enable_if_t<std::is_trivially_default_constructible_v<T>
99 && !std::is_arithmetic_v<T>>
102 for (Long i = 0; i < n; ++i) {
107 template <
typename T>
108 std::enable_if_t<!std::is_trivially_default_constructible_v<T>>
117 template <
typename T>
118 std::enable_if_t<std::is_trivially_destructible_v<T>>
122 template <
typename T>
123 std::enable_if_t<!std::is_trivially_destructible_v<T>>
199 bool shared = false,
Arena* ar =
nullptr);
228 #if defined(AMREX_USE_GPU)
229 template <RunOn run_on>
231 template <RunOn run_on=RunOn::Host>
253 template <
class U=T, std::enable_if_t<std::is_trivially_destructible_v<U>,
int> = 0>
266 [[nodiscard]] std::
size_t nBytes () const noexcept {
return this->
truesize*
sizeof(T); }
273 [[nodiscard]] std::size_t
nBytes (
const Box& bx,
int ncomps)
const noexcept
274 {
return bx.numPts() *
sizeof(T) * ncomps; }
277 [[nodiscard]]
int nComp () const noexcept {
return this->
nvar; }
280 [[nodiscard]]
const int*
nCompPtr() const noexcept {
281 return &(this->
nvar);
291 [[nodiscard]]
const Box&
box () const noexcept {
return this->
domain; }
352 [[nodiscard]] T*
dataPtr (
int n = 0) noexcept {
361 [[nodiscard]]
const T*
dataPtr (
int n = 0) const noexcept {
457 void getVal (T* data,
const IntVect& pos,
int N,
int numcomp)
const noexcept;
461 #if defined(AMREX_USE_GPU)
462 template <
RunOn run_on,
466 class U=T, std::enable_if_t<std::is_same_v<U,float> || std::is_same_v<U,double>,
int> FOO = 0>
475 #if defined(AMREX_USE_GPU)
476 template <RunOn run_on>
478 template <RunOn run_on=RunOn::Host>
480 void setVal (T
const& x,
const Box& bx,
int dcomp,
int ncomp) noexcept;
482 #if defined(AMREX_USE_GPU)
483 template <RunOn run_on>
485 template <RunOn run_on=RunOn::Host>
487 void setVal (T
const& x,
const Box& bx,
int N = 0) noexcept;
489 #if defined(AMREX_USE_GPU)
490 template <RunOn run_on>
492 template <RunOn run_on=RunOn::Host>
494 void setVal (T
const& x,
int N) noexcept;
496 #if defined(AMREX_USE_GPU)
497 template <RunOn run_on>
499 template <RunOn run_on=RunOn::Host>
508 #if defined(AMREX_USE_GPU)
509 template <RunOn run_on>
511 template <RunOn run_on=RunOn::Host>
531 #if defined(AMREX_USE_GPU)
532 template <RunOn run_on>
534 template <RunOn run_on=RunOn::Host>
537 const Box& destbox,
int destcomp,
int numcomp) noexcept;
545 #if defined(AMREX_USE_GPU)
546 template <RunOn run_on>
548 template <RunOn run_on=RunOn::Host>
551 int numcomp = 1) noexcept;
558 #if defined(AMREX_USE_GPU)
559 template <RunOn run_on>
561 template <RunOn run_on=RunOn::Host>
566 #if defined(AMREX_USE_GPU)
567 template <RunOn run_on>
569 template <RunOn run_on=RunOn::Host>
572 int numcomp,
void* dst)
const noexcept;
575 #if defined(AMREX_USE_GPU)
576 template <RunOn run_on,
typename BUF = T>
578 template <RunOn run_on=RunOn::Host,
typename BUF = T>
581 int numcomp,
const void* src) noexcept;
584 #if defined(AMREX_USE_GPU)
585 template <RunOn run_on,
typename BUF = T>
587 template <RunOn run_on=RunOn::Host,
typename BUF = T>
590 int numcomp,
const void* src) noexcept;
617 #if defined(AMREX_USE_GPU)
618 template <RunOn run_on>
620 template <RunOn run_on=RunOn::Host>
630 #if defined(AMREX_USE_GPU)
631 template <RunOn run_on>
633 template <RunOn run_on=RunOn::Host>
635 [[nodiscard]] Real
norm (
int p,
int scomp = 0,
int numcomp = 1) const noexcept;
638 #if defined(AMREX_USE_GPU)
639 template <RunOn run_on>
641 template <RunOn run_on=RunOn::Host>
643 [[nodiscard]] Real
norm (
const Box& subbox,
int p,
int scomp = 0,
int numcomp = 1) const noexcept;
645 #if defined(AMREX_USE_GPU)
646 template <RunOn run_on>
648 template <RunOn run_on=RunOn::Host>
652 #if defined(AMREX_USE_GPU)
653 template <RunOn run_on>
655 template <RunOn run_on=RunOn::Host>
657 void abs (
int comp,
int numcomp=1) noexcept;
661 #if defined(AMREX_USE_GPU)
662 template <RunOn run_on>
664 template <RunOn run_on=RunOn::Host>
666 void abs (
const Box& subbox,
int comp = 0,
int numcomp=1) noexcept;
670 #if defined(AMREX_USE_GPU)
671 template <RunOn run_on>
673 template <RunOn run_on=RunOn::Host>
675 [[nodiscard]] T
min (
int comp = 0) const noexcept;
679 #if defined(AMREX_USE_GPU)
680 template <RunOn run_on>
682 template <RunOn run_on=RunOn::Host>
684 [[nodiscard]] T
min (
const Box& subbox,
int comp = 0) const noexcept;
688 #if defined(AMREX_USE_GPU)
689 template <RunOn run_on>
691 template <RunOn run_on=RunOn::Host>
693 [[nodiscard]] T
max (
int comp = 0) const noexcept;
697 #if defined(AMREX_USE_GPU)
698 template <RunOn run_on>
700 template <RunOn run_on=RunOn::Host>
702 [[nodiscard]] T
max (
const Box& subbox,
int comp = 0) const noexcept;
706 #if defined(AMREX_USE_GPU)
707 template <RunOn run_on>
709 template <RunOn run_on=RunOn::Host>
711 [[nodiscard]] std::pair<T,T>
minmax (
int comp = 0) const noexcept;
715 #if defined(AMREX_USE_GPU)
716 template <RunOn run_on>
718 template <RunOn run_on=RunOn::Host>
720 [[nodiscard]] std::pair<T,T>
minmax (
const Box& subbox,
int comp = 0) const noexcept;
724 #if defined(AMREX_USE_GPU)
725 template <RunOn run_on>
727 template <RunOn run_on=RunOn::Host>
729 [[nodiscard]] T
maxabs (
int comp = 0) const noexcept;
733 #if defined(AMREX_USE_GPU)
734 template <RunOn run_on>
736 template <RunOn run_on=RunOn::Host>
738 [[nodiscard]] T
maxabs (
const Box& subbox,
int comp = 0) const noexcept;
743 #if defined(AMREX_USE_GPU)
744 template <RunOn run_on>
746 template <RunOn run_on=RunOn::Host>
753 #if defined(AMREX_USE_GPU)
754 template <RunOn run_on>
756 template <RunOn run_on=RunOn::Host>
763 #if defined(AMREX_USE_GPU)
764 template <RunOn run_on>
766 template <RunOn run_on=RunOn::Host>
773 #if defined(AMREX_USE_GPU)
774 template <RunOn run_on>
776 template <RunOn run_on=RunOn::Host>
783 #if defined(AMREX_USE_GPU)
784 template <RunOn run_on>
786 template <RunOn run_on=RunOn::Host>
793 #if defined(AMREX_USE_GPU)
794 template <RunOn run_on>
796 template <RunOn run_on=RunOn::Host>
803 #if defined(AMREX_USE_GPU)
804 template <RunOn run_on>
806 template <RunOn run_on=RunOn::Host>
816 #if defined(AMREX_USE_GPU)
817 template <RunOn run_on>
819 template <RunOn run_on=RunOn::Host>
823 #if defined(AMREX_USE_GPU)
824 template <RunOn run_on>
826 template <RunOn run_on=RunOn::Host>
831 #if defined(AMREX_USE_GPU)
832 template <RunOn run_on>
834 template <RunOn run_on=RunOn::Host>
838 #if defined(AMREX_USE_GPU)
839 template <RunOn run_on>
841 template <RunOn run_on=RunOn::Host>
845 #if defined(AMREX_USE_GPU)
846 template <RunOn run_on>
848 template <RunOn run_on=RunOn::Host>
853 #if defined(AMREX_USE_GPU)
854 template <RunOn run_on>
856 template <RunOn run_on=RunOn::Host>
858 [[nodiscard]] T
sum (
int comp,
int numcomp = 1) const noexcept;
860 #if defined(AMREX_USE_GPU)
861 template <RunOn run_on>
863 template <RunOn run_on=RunOn::Host>
865 [[nodiscard]] T
sum (
const Box& subbox,
int comp,
int numcomp = 1) const noexcept;
868 #if defined(AMREX_USE_GPU)
869 template <RunOn run_on>
871 template <RunOn run_on=RunOn::Host>
875 #if defined(AMREX_USE_GPU)
876 template <RunOn run_on>
878 template <RunOn run_on=RunOn::Host>
883 #if defined(AMREX_USE_GPU)
884 template <RunOn run_on>
886 template <RunOn run_on=RunOn::Host>
890 #if defined(AMREX_USE_GPU)
891 template <RunOn run_on>
893 template <RunOn run_on=RunOn::Host>
898 #if defined(AMREX_USE_GPU)
899 template <RunOn run_on>
901 template <RunOn run_on=RunOn::Host>
906 #if defined(AMREX_USE_GPU)
907 template <RunOn run_on>
909 template <RunOn run_on=RunOn::Host>
918 #if defined(AMREX_USE_GPU)
919 template <RunOn run_on>
921 template <RunOn run_on=RunOn::Host>
929 #if defined(AMREX_USE_GPU)
930 template <RunOn run_on>
932 template <RunOn run_on=RunOn::Host>
939 #if defined(AMREX_USE_GPU)
940 template <RunOn run_on>
942 template <RunOn run_on=RunOn::Host>
945 int srccomp,
int destcomp,
int numcomp=1) noexcept;
948 #if defined(AMREX_USE_GPU)
949 template <RunOn run_on>
951 template <RunOn run_on=RunOn::Host>
960 #if defined(AMREX_USE_GPU)
961 template <RunOn run_on>
963 template <RunOn run_on=RunOn::Host>
971 #if defined(AMREX_USE_GPU)
972 template <RunOn run_on>
974 template <RunOn run_on=RunOn::Host>
977 int numcomp=1) noexcept;
982 #if defined(AMREX_USE_GPU)
983 template <RunOn run_on>
985 template <RunOn run_on=RunOn::Host>
988 int srccomp,
int destcomp,
int numcomp=1) noexcept;
995 #if defined(AMREX_USE_GPU)
996 template <RunOn run_on>
998 template <RunOn run_on=RunOn::Host>
1001 int srccomp,
int destcomp,
int numcomp) noexcept;
1004 #if defined(AMREX_USE_GPU)
1005 template <RunOn run_on>
1007 template <RunOn run_on=RunOn::Host>
1010 int srccomp,
int destcomp,
int numcomp=1) noexcept;
1012 #if defined(AMREX_USE_GPU)
1013 template <RunOn run_on>
1015 template <RunOn run_on=RunOn::Host>
1020 #if defined(AMREX_USE_GPU)
1021 template <RunOn run_on>
1023 template <RunOn run_on=RunOn::Host>
1026 int srccomp,
int destcomp,
int numcomp=1) noexcept;
1029 #if defined(AMREX_USE_GPU)
1030 template <RunOn run_on>
1032 template <RunOn run_on=RunOn::Host>
1043 #if defined(AMREX_USE_GPU)
1044 template <RunOn run_on>
1046 template <RunOn run_on=RunOn::Host>
1054 #if defined(AMREX_USE_GPU)
1055 template <RunOn run_on>
1057 template <RunOn run_on=RunOn::Host>
1060 int numcomp=1) noexcept;
1065 #if defined(AMREX_USE_GPU)
1066 template <RunOn run_on>
1068 template <RunOn run_on=RunOn::Host>
1071 int srccomp,
int destcomp,
int numcomp=1) noexcept;
1074 #if defined(AMREX_USE_GPU)
1075 template <RunOn run_on>
1077 template <RunOn run_on=RunOn::Host>
1083 #if defined(AMREX_USE_GPU)
1084 template <RunOn run_on>
1086 template <RunOn run_on=RunOn::Host>
1095 #if defined(AMREX_USE_GPU)
1096 template <RunOn run_on>
1098 template <RunOn run_on=RunOn::Host>
1107 #if defined(AMREX_USE_GPU)
1108 template <RunOn run_on>
1110 template <RunOn run_on=RunOn::Host>
1113 int numcomp=1) noexcept;
1119 #if defined(AMREX_USE_GPU)
1120 template <RunOn run_on>
1122 template <RunOn run_on=RunOn::Host>
1125 int srccomp,
int destcomp,
int numcomp=1) noexcept;
1128 #if defined(AMREX_USE_GPU)
1129 template <RunOn run_on>
1131 template <RunOn run_on=RunOn::Host>
1136 #if defined(AMREX_USE_GPU)
1137 template <RunOn run_on>
1139 template <RunOn run_on=RunOn::Host>
1149 #if defined(AMREX_USE_GPU)
1150 template <RunOn run_on>
1152 template <RunOn run_on=RunOn::Host>
1160 #if defined(AMREX_USE_GPU)
1161 template <RunOn run_on>
1163 template <RunOn run_on=RunOn::Host>
1166 int numcomp=1) noexcept;
1171 #if defined(AMREX_USE_GPU)
1172 template <RunOn run_on>
1174 template <RunOn run_on=RunOn::Host>
1177 int srccomp,
int destcomp,
int numcomp=1) noexcept;
1181 #if defined(AMREX_USE_GPU)
1182 template <RunOn run_on>
1184 template <RunOn run_on=RunOn::Host>
1195 #if defined(AMREX_USE_GPU)
1196 template <RunOn run_on>
1198 template <RunOn run_on=RunOn::Host>
1208 #if defined(AMREX_USE_GPU)
1209 template <RunOn run_on>
1211 template <RunOn run_on=RunOn::Host>
1214 int numcomp=1) noexcept;
1221 #if defined(AMREX_USE_GPU)
1222 template <RunOn run_on>
1224 template <RunOn run_on=RunOn::Host>
1227 int srccomp,
int destcomp,
int numcomp=1) noexcept;
1239 #if defined(AMREX_USE_GPU)
1240 template <RunOn run_on>
1242 template <RunOn run_on=RunOn::Host>
1246 Real t1, Real t2, Real t,
1247 const Box& b,
int comp,
int numcomp = 1) noexcept;
1250 #if defined(AMREX_USE_GPU)
1251 template <RunOn run_on>
1253 template <RunOn run_on=RunOn::Host>
1257 Real t1, Real t2, Real t,
1258 const Box& b,
int comp,
int numcomp = 1) noexcept;
1269 #if defined(AMREX_USE_GPU)
1270 template <RunOn run_on>
1272 template <RunOn run_on=RunOn::Host>
1276 Real alpha, Real beta,
const Box& b,
1277 int comp,
int numcomp = 1) noexcept;
1280 #if defined(AMREX_USE_GPU)
1281 template <RunOn run_on>
1283 template <RunOn run_on=RunOn::Host>
1286 int numcomp = 1) const noexcept;
1288 #if defined(AMREX_USE_GPU)
1289 template <RunOn run_on>
1291 template <RunOn run_on=RunOn::Host>
1295 int numcomp)
const noexcept;
1305 #if defined(AMREX_USE_GPU)
1306 template <RunOn run_on>
1308 template <RunOn run_on=RunOn::Host>
1313 #if defined(AMREX_USE_GPU)
1314 template <RunOn run_on>
1316 template <RunOn run_on=RunOn::Host>
1320 #if defined(AMREX_USE_GPU)
1321 template <RunOn run_on>
1323 template <RunOn run_on=RunOn::Host>
1328 #if defined(AMREX_USE_GPU)
1329 template <RunOn run_on>
1331 template <RunOn run_on=RunOn::Host>
1335 #if defined(AMREX_USE_GPU)
1336 template <RunOn run_on>
1338 template <RunOn run_on=RunOn::Host>
1343 #if defined(AMREX_USE_GPU)
1344 template <RunOn run_on>
1346 template <RunOn run_on=RunOn::Host>
1351 #if defined(AMREX_USE_GPU)
1352 template <RunOn run_on>
1354 template <RunOn run_on=RunOn::Host>
1363 #if defined(AMREX_USE_GPU)
1364 template <RunOn run_on>
1366 template <RunOn run_on=RunOn::Host>
1371 #if defined(AMREX_USE_GPU)
1372 template <RunOn run_on>
1374 template <RunOn run_on=RunOn::Host>
1379 #if defined(AMREX_USE_GPU)
1380 template <RunOn run_on>
1382 template <RunOn run_on=RunOn::Host>
1386 #if defined(AMREX_USE_GPU)
1387 template <RunOn run_on>
1389 template <RunOn run_on=RunOn::Host>
1394 #if defined(AMREX_USE_GPU)
1395 template <RunOn run_on>
1397 template <RunOn run_on=RunOn::Host>
1405 #if defined(AMREX_USE_GPU)
1406 template <RunOn run_on>
1408 template <RunOn run_on=RunOn::Host>
1412 #if defined(AMREX_USE_GPU)
1413 template <RunOn run_on>
1415 template <RunOn run_on=RunOn::Host>
1420 #if defined(AMREX_USE_GPU)
1421 template <RunOn run_on>
1423 template <RunOn run_on=RunOn::Host>
1428 #if defined(AMREX_USE_GPU)
1429 template <RunOn run_on>
1431 template <RunOn run_on=RunOn::Host>
1435 #if defined(AMREX_USE_GPU)
1436 template <RunOn run_on>
1438 template <RunOn run_on=RunOn::Host>
1443 #if defined(AMREX_USE_GPU)
1444 template <RunOn run_on>
1446 template <RunOn run_on=RunOn::Host>
1454 #if defined(AMREX_USE_GPU)
1455 template <RunOn run_on>
1457 template <RunOn run_on=RunOn::Host>
1461 #if defined(AMREX_USE_GPU)
1462 template <RunOn run_on>
1464 template <RunOn run_on=RunOn::Host>
1469 #if defined(AMREX_USE_GPU)
1470 template <RunOn run_on>
1472 template <RunOn run_on=RunOn::Host>
1477 #if defined(AMREX_USE_GPU)
1478 template <RunOn run_on>
1480 template <RunOn run_on=RunOn::Host>
1484 #if defined(AMREX_USE_GPU)
1485 template <RunOn run_on>
1487 template <RunOn run_on=RunOn::Host>
1492 #if defined(AMREX_USE_GPU)
1493 template <RunOn run_on>
1495 template <RunOn run_on=RunOn::Host>
1503 #if defined(AMREX_USE_GPU)
1504 template <RunOn run_on>
1506 template <RunOn run_on=RunOn::Host>
1510 #if defined(AMREX_USE_GPU)
1511 template <RunOn run_on>
1513 template <RunOn run_on=RunOn::Host>
1518 #if defined(AMREX_USE_GPU)
1519 template <RunOn run_on>
1521 template <RunOn run_on=RunOn::Host>
1526 #if defined(AMREX_USE_GPU)
1527 template <RunOn run_on>
1529 template <RunOn run_on=RunOn::Host>
1533 #if defined(AMREX_USE_GPU)
1534 template <RunOn run_on>
1536 template <RunOn run_on=RunOn::Host>
1541 #if defined(AMREX_USE_GPU)
1542 template <RunOn run_on>
1544 template <RunOn run_on=RunOn::Host>
1552 #if defined(AMREX_USE_GPU)
1553 template <RunOn run_on>
1555 template <RunOn run_on=RunOn::Host>
1559 #if defined(AMREX_USE_GPU)
1560 template <RunOn run_on>
1562 template <RunOn run_on=RunOn::Host>
1567 #if defined(AMREX_USE_GPU)
1568 template <RunOn run_on>
1570 template <RunOn run_on=RunOn::Host>
1575 #if defined(AMREX_USE_GPU)
1576 template <RunOn run_on>
1578 template <RunOn run_on=RunOn::Host>
1582 #if defined(AMREX_USE_GPU)
1583 template <RunOn run_on>
1585 template <RunOn run_on=RunOn::Host>
1590 #if defined(AMREX_USE_GPU)
1591 template <RunOn run_on>
1593 template <RunOn run_on=RunOn::Host>
1597 #if defined(AMREX_USE_GPU)
1598 template <RunOn run_on>
1600 template <RunOn run_on=RunOn::Host>
1605 #if defined(AMREX_USE_GPU)
1606 template <RunOn run_on>
1608 template <RunOn run_on=RunOn::Host>
1613 #if defined(AMREX_USE_GPU)
1614 template <RunOn run_on>
1616 template <RunOn run_on=RunOn::Host>
1621 #if defined(AMREX_USE_GPU)
1622 template <RunOn run_on>
1624 template <RunOn run_on=RunOn::Host>
1626 [[nodiscard]] T
dot (
const Box& bx,
int destcomp,
int numcomp)
const noexcept;
1629 #if defined(AMREX_USE_GPU)
1630 template <RunOn run_on>
1632 template <RunOn run_on=RunOn::Host>
1637 #if defined(AMREX_USE_GPU)
1638 template <RunOn run_on>
1640 template <RunOn run_on=RunOn::Host>
1655 #ifdef AMREX_USE_GPU
1670 return this->dptr + (this->domain.index(p)+n*this->domain.numPts());
1683 return this->dptr + (this->domain.index(p)+n*this->domain.numPts());
1690 #ifdef AMREX_USE_GPU
1692 #if defined(AMREX_USE_SYCL)
1697 #elif defined(AMREX_USE_CUDA) && !defined(_WIN32)
1699 std::size_t s =
sizeof(T)*this->nvar*this->domain.numPts();
1704 #elif defined(AMREX_USE_HIP)
1715 #ifdef AMREX_USE_GPU
1717 #if defined(AMREX_USE_SYCL)
1718 std::size_t s =
sizeof(T)*this->nvar*this->domain.numPts();
1719 auto& q = Gpu::Device::streamQueue();
1720 q.submit([&] (sycl::handler& h) { h.prefetch(this->dptr, s); });
1721 #elif defined(AMREX_USE_CUDA) && !defined(_WIN32)
1723 std::size_t s =
sizeof(T)*this->nvar*this->domain.numPts();
1728 #elif defined(AMREX_USE_HIP)
1745 return this->dptr[this->domain.index(p)+n*this->domain.numPts()];
1756 return this->dptr[this->domain.index(p)];
1769 return this->dptr[this->domain.index(p)+n*this->domain.numPts()];
1780 return this->dptr[this->domain.index(p)];
1788 int numcomp)
const noexcept
1790 const int loc = this->domain.index(pos);
1791 const Long sz = this->domain.numPts();
1796 for (
int k = 0; k < numcomp; k++) {
1797 data[k] = this->dptr[loc+(n+k)*sz];
1804 const IntVect& pos)
const noexcept
1806 getVal(data,pos,0,this->nvar);
1821 this->domain.shift(
idir,n_cell);
1829 this->domain.shiftHalf(v);
1837 this->domain.shiftHalf(
idir,n_cell);
1842 template <
RunOn run_on,
class U,
1843 std::enable_if_t<std::is_same_v<U,float> || std::is_same_v<U,double>,
int> FOO>
1847 amrex::fill_snan<run_on>(this->dptr, this->truesize);
1851 template <RunOn run_on>
1859 template <RunOn run_on>
1867 template <RunOn run_on>
1875 template <RunOn run_on>
1883 template <RunOn run_on>
1886 const Box& destbox,
int destcomp,
int numcomp) noexcept
1893 AMREX_ASSERT(destcomp >= 0 && destcomp+numcomp <= this->nvar);
1899 const Dim3 offset{slo.x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
1910 template <RunOn run_on>
1918 template <RunOn run_on>
1932 if (this->nvar == 0) {
return; }
1935 this->truesize = this->nvar*this->domain.numPts();
1936 this->ptr_owner =
true;
1937 this->dptr =
static_cast<T*
>(this->alloc(this->truesize*
sizeof(T)));
1938 #ifdef AMREX_USE_GPU
1946 if constexpr (std::is_same_v<T,float> || std::is_same_v<T,double>) {
1948 #ifdef AMREX_USE_GPU
1950 this->
template fill_snan<RunOn::Device>();
1955 this->
template fill_snan<RunOn::Host>();
1975 :
DataAllocator{ar}, domain(bx), nvar(n), shared_memory(shared)
1983 dptr(const_cast<T*>(rhs.dataPtr(scomp))),
1984 domain(rhs.domain), nvar(ncomp),
1985 truesize(ncomp*rhs.domain.numPts())
1990 this->
dptr =
nullptr;
1992 this->copy<RunOn::Device>(rhs, this->
domain, scomp, this->
domain, 0, ncomp);
2002 : dptr(p), domain(bx), nvar(ncomp), truesize(bx.numPts()*ncomp)
2008 : dptr(const_cast<T*>(p)), domain(bx), nvar(ncomp), truesize(bx.numPts()*ncomp)
2017 nvar(a.ncomp), truesize(a.ncomp*a.nstride)
2025 nvar(a.ncomp), truesize(a.ncomp*a.nstride)
2030 : dptr(
const_cast<T*
>(a.p)),
2033 nvar(a.ncomp), truesize(a.ncomp*a.nstride)
2038 : dptr(
const_cast<T*
>(a.p)),
2041 nvar(a.ncomp), truesize(a.ncomp*a.nstride)
2053 dptr(rhs.dptr), domain(rhs.domain),
2054 nvar(rhs.nvar), truesize(rhs.truesize),
2055 ptr_owner(rhs.ptr_owner), shared_memory(rhs.shared_memory)
2056 #ifdef AMREX_USE_GPU
2057 , alloc_stream(rhs.alloc_stream)
2061 rhs.ptr_owner =
false;
2070 DataAllocator::operator=(rhs);
2072 domain = rhs.domain;
2074 truesize = rhs.truesize;
2075 ptr_owner = rhs.ptr_owner;
2076 shared_memory = rhs.shared_memory;
2077 #ifdef AMREX_USE_GPU
2078 alloc_stream = rhs.alloc_stream;
2082 rhs.ptr_owner =
false;
2088 template <RunOn run_on>
2103 if (ar ==
nullptr) {
2112 else if (this->dptr ==
nullptr || !this->ptr_owner)
2114 if (this->shared_memory) {
2115 amrex::Abort(
"BaseFab::resize: BaseFab in shared memory cannot increase size");
2118 this->dptr =
nullptr;
2121 else if (this->nvar*this->domain.numPts() > this->truesize
2122 #ifdef AMREX_USE_GPU
2123 || (arena()->isStreamOrderedArena() && alloc_stream !=
Gpu::gpuStream())
2127 if (this->shared_memory) {
2128 amrex::Abort(
"BaseFab::resize: BaseFab in shared memory cannot increase size");
2138 template <
class U, std::enable_if_t<std::is_trivially_destructible_v<U>,
int>>
2144 o = this->ptr_owner;
2145 this->ptr_owner =
false;
2146 if (o && this->dptr) {
2147 if (this->nvar > 1) {
2156 return Elixir((o ? this->dptr :
nullptr), this->arena());
2168 if (this->ptr_owner)
2170 if (this->shared_memory)
2172 amrex::Abort(
"BaseFab::clear: BaseFab cannot be owner of shared memory");
2177 #ifdef AMREX_USE_GPU
2181 this->
free(this->dptr);
2182 #ifdef AMREX_USE_GPU
2186 if (this->nvar > 1) {
2193 this->dptr =
nullptr;
2199 std::unique_ptr<T,DataDeleter>
2202 std::unique_ptr<T,DataDeleter>
r(
nullptr,
DataDeleter{this->arena()});
2203 if (this->dptr && this->ptr_owner) {
2204 r.reset(this->dptr);
2205 this->ptr_owner =
false;
2206 if (this->nvar > 1) {
2216 template <RunOn run_on>
2221 void* dst)
const noexcept
2232 d(i,j,k,n) = s(i,j,k,n+srccomp);
2234 return sizeof(T)*d.
size();
2243 template <RunOn run_on,
typename BUF>
2248 const void* src) noexcept
2260 d(i,j,k,n+dstcomp) =
static_cast<T
>(s(i,j,k,n));
2262 return sizeof(BUF)*s.
size();
2271 template <RunOn run_on,
typename BUF>
2276 const void* src) noexcept
2288 d(i,j,k,n+dstcomp) +=
static_cast<T
>(s(i,j,k,n));
2290 return sizeof(BUF)*s.
size();
2299 template <RunOn run_on>
2307 template <RunOn run_on>
2311 this->abs<run_on>(this->domain,0,this->nvar);
2315 template <RunOn run_on>
2319 this->abs<run_on>(this->domain,comp,numcomp);
2323 template <RunOn run_on>
2330 a(i,j,k,n+comp) =
std::abs(a(i,j,k,n+comp));
2335 template <RunOn run_on>
2338 int scomp,
int ncomp)
const noexcept
2340 BL_ASSERT(this->domain.contains(subbox));
2341 BL_ASSERT(scomp >= 0 && scomp + ncomp <= this->nvar);
2346 #ifdef AMREX_USE_GPU
2351 reduce_op.
eval(subbox, reduce_data,
2356 for (
int n = 0; n < ncomp; ++n) {
2362 ReduceTuple hv = reduce_data.
value(reduce_op);
2363 r = amrex::get<0>(hv);
2370 Real t =
static_cast<Real
>(
std::abs(a(i,j,k,n+scomp)));
2379 template <RunOn run_on>
2383 return norm<run_on>(this->domain,p,comp,numcomp);
2387 template <RunOn run_on>
2391 BL_ASSERT(this->domain.contains(subbox));
2392 BL_ASSERT(comp >= 0 && comp + numcomp <= this->nvar);
2396 #ifdef AMREX_USE_GPU
2402 reduce_op.
eval(subbox, reduce_data,
2406 for (
int n = 0; n < numcomp; ++n) {
2411 ReduceTuple hv = reduce_data.
value(reduce_op);
2412 nrm = amrex::get<0>(hv);
2413 }
else if (p == 1) {
2417 reduce_op.
eval(subbox, reduce_data,
2421 for (
int n = 0; n < numcomp; ++n) {
2422 t +=
static_cast<Real
>(
std::abs(a(i,j,k,n+comp)));
2426 ReduceTuple hv = reduce_data.
value(reduce_op);
2427 nrm = amrex::get<0>(hv);
2428 }
else if (p == 2) {
2432 reduce_op.
eval(subbox, reduce_data,
2436 for (
int n = 0; n < numcomp; ++n) {
2437 t +=
static_cast<Real
>(a(i,j,k,n+comp)*a(i,j,k,n+comp));
2441 ReduceTuple hv = reduce_data.
value(reduce_op);
2442 nrm = amrex::get<0>(hv);
2450 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n) noexcept
2452 Real t =
static_cast<Real
>(
std::abs(a(i,j,k,n+comp)));
2455 }
else if (p == 1) {
2456 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n) noexcept
2460 }
else if (p == 2) {
2461 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n) noexcept
2463 nrm += a(i,j,k,n+comp)*a(i,j,k,n+comp);
2474 template <RunOn run_on>
2478 return this->min<run_on>(this->domain,comp);
2482 template <RunOn run_on>
2487 #ifdef AMREX_USE_GPU
2491 using ReduceTuple =
typename decltype(reduce_data)::Type;
2492 reduce_op.
eval(subbox, reduce_data,
2495 return { a(i,j,k) };
2497 ReduceTuple hv = reduce_data.
value(reduce_op);
2498 return amrex::get<0>(hv);
2512 template <RunOn run_on>
2516 return this->max<run_on>(this->domain,comp);
2520 template <RunOn run_on>
2525 #ifdef AMREX_USE_GPU
2529 using ReduceTuple =
typename decltype(reduce_data)::Type;
2530 reduce_op.
eval(subbox, reduce_data,
2533 return { a(i,j,k) };
2535 ReduceTuple hv = reduce_data.
value(reduce_op);
2536 return amrex::get<0>(hv);
2540 T
r = std::numeric_limits<T>::lowest();
2550 template <RunOn run_on>
2554 return this->minmax<run_on>(this->domain,comp);
2558 template <RunOn run_on>
2563 #ifdef AMREX_USE_GPU
2567 using ReduceTuple =
typename decltype(reduce_data)::Type;
2568 reduce_op.
eval(subbox, reduce_data,
2571 auto const x = a(i,j,k);
2574 ReduceTuple hv = reduce_data.
value(reduce_op);
2575 return std::make_pair(amrex::get<0>(hv), amrex::get<1>(hv));
2579 T rmax = std::numeric_limits<T>::lowest();
2583 auto const x = a(i,j,k);
2587 return std::make_pair(rmin,rmax);
2592 template <RunOn run_on>
2596 return this->maxabs<run_on>(this->domain,comp);
2600 template <RunOn run_on>
2605 #ifdef AMREX_USE_GPU
2609 using ReduceTuple =
typename decltype(reduce_data)::Type;
2610 reduce_op.
eval(subbox, reduce_data,
2615 ReduceTuple hv = reduce_data.
value(reduce_op);
2616 return amrex::get<0>(hv);
2631 template <RunOn run_on>
2636 #ifdef AMREX_USE_GPU
2639 std::numeric_limits<int>::lowest(),
2640 std::numeric_limits<int>::lowest())};
2647 if ((*flag == 0) && (a(i,j,k) == value)) {
2670 template <RunOn run_on>
2674 return this->minIndex<run_on>(this->domain,comp);
2678 template <RunOn run_on>
2682 T min_val = this->min<run_on>(subbox, comp);
2683 return this->indexFromValue<run_on>(subbox, comp, min_val);
2687 template <RunOn run_on>
2691 min_val = this->min<run_on>(subbox, comp);
2692 min_idx = this->indexFromValue<run_on>(subbox, comp, min_val);
2696 template <RunOn run_on>
2700 return this->maxIndex<run_on>(this->domain,comp);
2704 template <RunOn run_on>
2708 T max_val = this->max<run_on>(subbox, comp);
2709 return this->indexFromValue<run_on>(subbox, comp, max_val);
2713 template <RunOn run_on>
2717 max_val = this->max<run_on>(subbox, comp);
2718 max_idx = this->indexFromValue<run_on>(subbox, comp, max_val);
2722 template <RunOn run_on>
2726 mask.resize(this->domain,1);
2730 #ifdef AMREX_USE_GPU
2734 using ReduceTuple =
typename decltype(reduce_data)::Type;
2735 reduce_op.
eval(this->domain, reduce_data,
2739 if (a(i,j,k) < val) {
2748 ReduceTuple hv = reduce_data.
value(reduce_op);
2749 cnt = amrex::get<0>(hv);
2755 if (a(i,j,k) < val) {
2768 template <RunOn run_on>
2772 mask.resize(this->domain,1);
2776 #ifdef AMREX_USE_GPU
2780 using ReduceTuple =
typename decltype(reduce_data)::Type;
2781 reduce_op.
eval(this->domain, reduce_data,
2785 if (a(i,j,k) <= val) {
2794 ReduceTuple hv = reduce_data.
value(reduce_op);
2795 cnt = amrex::get<0>(hv);
2801 if (a(i,j,k) <= val) {
2814 template <RunOn run_on>
2818 mask.resize(this->domain,1);
2822 #ifdef AMREX_USE_GPU
2826 using ReduceTuple =
typename decltype(reduce_data)::Type;
2827 reduce_op.
eval(this->domain, reduce_data,
2831 if (a(i,j,k) == val) {
2840 ReduceTuple hv = reduce_data.
value(reduce_op);
2841 cnt = amrex::get<0>(hv);
2847 if (a(i,j,k) == val) {
2860 template <RunOn run_on>
2864 mask.resize(this->domain,1);
2868 #ifdef AMREX_USE_GPU
2872 using ReduceTuple =
typename decltype(reduce_data)::Type;
2873 reduce_op.
eval(this->domain, reduce_data,
2877 if (a(i,j,k) > val) {
2886 ReduceTuple hv = reduce_data.
value(reduce_op);
2887 cnt = amrex::get<0>(hv);
2893 if (a(i,j,k) > val) {
2906 template <RunOn run_on>
2910 mask.resize(this->domain,1);
2914 #ifdef AMREX_USE_GPU
2918 using ReduceTuple =
typename decltype(reduce_data)::Type;
2919 reduce_op.
eval(this->domain, reduce_data,
2923 if (a(i,j,k) >= val) {
2932 ReduceTuple hv = reduce_data.
value(reduce_op);
2933 cnt = amrex::get<0>(hv);
2939 if (a(i,j,k) >= val) {
2952 template <RunOn run_on>
2956 Box ovlp(this->domain);
2958 return ovlp.
ok() ? this->atomicAdd<run_on>(
x,ovlp,ovlp,0,0,this->nvar) : *
this;
2962 template <RunOn run_on>
2965 int srccomp,
int destcomp,
int numcomp) noexcept
2972 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
2979 const Dim3 offset{slo.x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2989 template <RunOn run_on>
2993 Box ovlp(this->domain);
2995 return ovlp.
ok() ? saxpy<run_on>(a,
x,ovlp,ovlp,0,0,this->nvar) : *
this;
2999 template <RunOn run_on>
3002 const Box& srcbox,
const Box& destbox,
3003 int srccomp,
int destcomp,
int numcomp) noexcept
3010 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
3017 const Dim3 offset{slo.x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3020 d(i,j,k,n+destcomp) = s(i+
offset.x,j+
offset.y,k+
offset.z,n+srccomp) + a*d(i,j,k,n+destcomp);
3027 template <RunOn run_on>
3035 BL_ASSERT( comp1 >= 0 && comp1+numcomp <= src1.nComp());
3036 BL_ASSERT( comp2 >= 0 && comp2+numcomp <= src2.nComp());
3044 d(i,j,k,n+destcomp) += s1(i,j,k,n+comp1) * s2(i,j,k,n+comp2);
3051 template <RunOn run_on>
3055 Real alpha, Real beta,
const Box& b,
3056 int comp,
int numcomp) noexcept
3076 const Dim3 off1{slo1.
x-dlo.x,slo1.y-dlo.y,slo1.z-dlo.z};
3077 const Dim3 off2{slo2.
x-dlo.x,slo2.y-dlo.y,slo2.z-dlo.z};
3081 d(i,j,k,n+comp) = alpha*s1(i+off1.x,j+off1.y,k+off1.z,n+comp1)
3082 + beta*s2(i+off2.x,j+off2.y,k+off2.z,n+comp2);
3088 template <RunOn run_on>
3092 int numcomp)
const noexcept
3105 const Dim3 offset{ylo.x-xlo.x,ylo.y-xlo.y,ylo.z-xlo.z};
3109 #ifdef AMREX_USE_GPU
3113 using ReduceTuple =
typename decltype(reduce_data)::Type;
3114 reduce_op.
eval(xbx, reduce_data,
3118 for (
int n = 0; n < numcomp; ++n) {
3123 ReduceTuple hv = reduce_data.
value(reduce_op);
3124 r = amrex::get<0>(hv);
3138 template <RunOn run_on>
3142 int numcomp)
const noexcept
3155 const Dim3 offset{ylo.x-xlo.x,ylo.y-xlo.y,ylo.z-xlo.z};
3161 #ifdef AMREX_USE_GPU
3165 using ReduceTuple =
typename decltype(reduce_data)::Type;
3166 reduce_op.
eval(xbx, reduce_data,
3169 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
3171 for (
int n = 0; n < numcomp; ++n) {
3176 ReduceTuple hv = reduce_data.
value(reduce_op);
3177 r = amrex::get<0>(hv);
3183 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
3192 template <RunOn run_on>
3200 template <RunOn run_on>
3208 template <RunOn run_on>
3212 return this->negate<run_on>(this->domain,
DestComp{comp},
NumComps{numcomp});
3216 template <RunOn run_on>
3224 template <RunOn run_on>
3228 return this->invert<run_on>(
r, this->domain,
DestComp{comp},
NumComps{numcomp});
3232 template <RunOn run_on>
3240 template <RunOn run_on>
3248 template <RunOn run_on>
3256 template <RunOn run_on>
3264 template <RunOn run_on>
3268 Box ovlp(this->domain);
3270 return ovlp.
ok() ? this->atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
3274 template <RunOn run_on>
3277 int numcomp) noexcept
3283 template <RunOn run_on>
3286 int numcomp) noexcept
3288 Box ovlp(this->domain);
3291 return ovlp.
ok() ? this->atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
3295 template <RunOn run_on>
3298 int srccomp,
int destcomp,
int numcomp) noexcept
3311 const Dim3 offset{slo.x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3321 template <RunOn run_on>
3324 int srccomp,
int destcomp,
int numcomp) noexcept
3337 const Dim3 offset{slo.x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3340 T* p = d.
ptr(i,j,k,n+destcomp);
3348 template <RunOn run_on>
3351 int srccomp,
int destcomp,
int numcomp) noexcept
3353 #if defined(AMREX_USE_OMP) && (AMREX_SPACEDIM > 1)
3354 #if defined(AMREX_USE_GPU)
3370 Dim3 const offset{slo.x-dlo.x, slo.y-dlo.y, slo.z-dlo.z};
3386 for (
int ip = 0; ip < nplanes; ++ip) {
3391 int planes_left = nplanes;
3392 while (planes_left > 0) {
3394 auto const m = mm + plo;
3395 auto* lock = OpenMP::get_lock(m);
3396 if (omp_test_lock(lock))
3400 if (planedim == 1) {
3408 for (
int n = 0; n < numcomp; ++n) {
3409 for (
int k = lo.z; k <= hi.z; ++k) {
3410 for (
int j = lo.y; j <= hi.y; ++j) {
3411 auto *
pdst = d.
ptr(dlo.x,j ,k ,n+destcomp);
3414 for (
int ii = 0; ii < len.x; ++ii) {
3415 pdst[ii] += psrc[ii];
3423 omp_unset_lock(lock);
3424 if (planes_left == 0) {
break; }
3428 for (
int ip = 0; ip < nplanes; ++ip) {
3429 int new_mm = (mm+ip) % nplanes;
3430 if ( !
mask[new_mm] ) {
3441 #if defined(AMREX_USE_GPU)
3443 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
3447 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
3452 template <RunOn run_on>
3460 template <RunOn run_on>
3468 template <RunOn run_on>
3471 int srccomp,
int destcomp,
int numcomp) noexcept
3484 const Dim3 offset{slo.x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3494 template <RunOn run_on>
3502 template <RunOn run_on>
3510 template <RunOn run_on>
3518 template <RunOn run_on>
3526 template <RunOn run_on>
3529 int srccomp,
int destcomp,
int numcomp) noexcept
3542 const Dim3 offset{slo.x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3552 template <RunOn run_on>
3556 return this->divide<run_on>(
r, this->domain,
DestComp{comp},
NumComps{numcomp});
3560 template <RunOn run_on>
3568 template <RunOn run_on>
3576 template <RunOn run_on>
3584 template <RunOn run_on>
3587 int srccomp,
int destcomp,
int numcomp) noexcept
3600 const Dim3 offset{slo.x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3610 template <RunOn run_on>
3614 Box ovlp(this->domain);
3616 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,0,0,this->nvar) : *
this;
3620 template <RunOn run_on>
3624 Box ovlp(this->domain);
3626 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
3630 template <RunOn run_on>
3633 int numcomp) noexcept
3635 Box ovlp(this->domain);
3638 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
3642 template <RunOn run_on>
3645 int srccomp,
int destcomp,
int numcomp) noexcept
3658 const Dim3 offset{slo.x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3662 d(i,j,k,n+destcomp) /= s(i+offset.x,j+offset.y,k+offset.z,n+srccomp);
3680 template <RunOn run_on>
3684 Real t1, Real t2, Real t,
3685 const Box& b,
int comp,
int numcomp) noexcept
3688 return copy<run_on>(f1,b1,comp1,
b,comp,numcomp);
3690 return copy<run_on>(f2,b2,comp2,
b,comp,numcomp);
3692 Real alpha = (t2-t)/(t2-t1);
3693 Real beta = (t-t1)/(t2-t1);
3694 return linComb<run_on>(f1,b1,comp1,f2,b2,comp2,alpha,beta,
b,comp,numcomp);
3699 template <RunOn run_on>
3703 Real t1, Real t2, Real t,
3704 const Box& b,
int comp,
int numcomp) noexcept
3707 return copy<run_on>(f1,
b,comp1,
b,comp,numcomp);
3709 return copy<run_on>(f2,
b,comp2,
b,comp,numcomp);
3711 Real alpha = (t2-t)/(t2-t1);
3712 Real beta = (t-t1)/(t2-t1);
3713 return linComb<run_on>(f1,
b,comp1,f2,
b,comp2,alpha,beta,
b,comp,numcomp);
3722 template <RunOn run_on>
3726 this->setVal<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3730 template <RunOn run_on>
3734 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3738 a(i,j,k,n+dcomp.i) = x;
3743 template <RunOn run_on>
3751 template <RunOn run_on>
3755 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3760 if (m(i,j,k)) { a(i,j,k,n+dcomp.i) = val; }
3765 template <RunOn run_on>
3773 template <RunOn run_on>
3777 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3782 if (!m(i,j,k)) { a(i,j,k,n+dcomp.i) = val; }
3787 template <RunOn run_on>
3791 #ifdef AMREX_USE_GPU
3797 for (
int n = dcomp.i; n < ncomp.n+dcomp.i; ++n) {
3806 for (
auto const&
b : b_lst) {
3807 this->setVal<RunOn::Host>(
x,
b, dcomp, ncomp);
3813 template <RunOn run_on>
3822 template <RunOn run_on>
3829 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3837 d(i,j,k,n+dcomp.i) = s(i,j,k,n+scomp.i);
3844 template <RunOn run_on>
3848 return this->plus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3852 template <RunOn run_on>
3856 return this->plus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3860 template <RunOn run_on>
3864 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3869 a(i,j,k,n+dcomp.i) += val;
3876 template <RunOn run_on>
3884 template <RunOn run_on>
3892 template <RunOn run_on>
3899 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3907 d(i,j,k,n+dcomp.i) += s(i,j,k,n+scomp.i);
3914 template <RunOn run_on>
3918 return this->minus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3922 template <RunOn run_on>
3926 return this->minus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3930 template <RunOn run_on>
3934 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3939 a(i,j,k,n+dcomp.i) -= val;
3946 template <RunOn run_on>
3954 template <RunOn run_on>
3962 template <RunOn run_on>
3969 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3977 d(i,j,k,n+dcomp.i) -= s(i,j,k,n+scomp.i);
3984 template <RunOn run_on>
3988 return this->mult<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3992 template <RunOn run_on>
3996 return this->mult<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
4000 template <RunOn run_on>
4004 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
4009 a(i,j,k,n+dcomp.i) *= val;
4016 template <RunOn run_on>
4024 template <RunOn run_on>
4032 template <RunOn run_on>
4039 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
4047 d(i,j,k,n+dcomp.i) *= s(i,j,k,n+scomp.i);
4054 template <RunOn run_on>
4058 return this->divide<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
4062 template <RunOn run_on>
4066 return this->divide<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
4070 template <RunOn run_on>
4074 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
4079 a(i,j,k,n+dcomp.i) /= val;
4086 template <RunOn run_on>
4094 template <RunOn run_on>
4102 template <RunOn run_on>
4109 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
4117 d(i,j,k,n+dcomp.i) /= s(i,j,k,n+scomp.i);
4124 template <RunOn run_on>
4128 return this->negate<run_on>(this->domain,
DestComp{0},
NumComps{this->nvar});
4132 template <RunOn run_on>
4136 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
4141 a(i,j,k,n+dcomp.i) = -a(i,j,k,n+dcomp.i);
4148 template <RunOn run_on>
4152 return this->invert<run_on>(
r, this->domain,
DestComp{0},
NumComps{this->nvar});
4156 template <RunOn run_on>
4160 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
4165 a(i,j,k,n+dcomp.i) = r / a(i,j,k,n+dcomp.i);
4172 template <RunOn run_on>
4176 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
4180 #ifdef AMREX_USE_GPU
4184 using ReduceTuple =
typename decltype(reduce_data)::Type;
4185 reduce_op.
eval(bx, reduce_data,
4189 for (
int n = 0; n < ncomp.n; ++n) {
4190 t += a(i,j,k,n+dcomp.i);
4194 ReduceTuple hv = reduce_data.
value(reduce_op);
4195 r = amrex::get<0>(hv);
4201 r += a(i,j,k,n+dcomp.i);
4209 template <RunOn run_on>
4215 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
4220 #ifdef AMREX_USE_GPU
4224 using ReduceTuple =
typename decltype(reduce_data)::Type;
4225 reduce_op.
eval(bx, reduce_data,
4229 for (
int n = 0; n < ncomp.n; ++n) {
4230 t += d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
4234 ReduceTuple hv = reduce_data.
value(reduce_op);
4235 r = amrex::get<0>(hv);
4241 r += d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
4249 template <RunOn run_on>
4258 template <RunOn run_on>
4262 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
4266 #ifdef AMREX_USE_GPU
4270 using ReduceTuple =
typename decltype(reduce_data)::Type;
4271 reduce_op.
eval(bx, reduce_data,
4275 for (
int n = 0; n < ncomp.n; ++n) {
4276 t += a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
4280 ReduceTuple hv = reduce_data.
value(reduce_op);
4281 r = amrex::get<0>(hv);
4287 r += a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
4295 template <RunOn run_on>
4303 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
4309 #ifdef AMREX_USE_GPU
4313 using ReduceTuple =
typename decltype(reduce_data)::Type;
4314 reduce_op.
eval(bx, reduce_data,
4318 T mi =
static_cast<T
>(
static_cast<int>(
static_cast<bool>(m(i,j,k))));
4319 for (
int n = 0; n < ncomp.n; ++n) {
4320 t += d(i,j,k,n+dcomp.i)*s(i,j,k,n+scomp.i)*mi;
4324 ReduceTuple hv = reduce_data.
value(reduce_op);
4325 r = amrex::get<0>(hv);
4331 int mi = static_cast<int>(static_cast<bool>(m(i,j,k)));
4332 r += d(i,j,k,n+dcomp.i)*s(i,j,k,n+scomp.i)*mi;
#define BL_ASSERT(EX)
Definition: AMReX_BLassert.H:39
#define AMREX_ASSERT(EX)
Definition: AMReX_BLassert.H:38
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_CUDA_SAFE_CALL(call)
Definition: AMReX_GpuError.H:73
#define AMREX_HOST_DEVICE_FOR_1D(...)
Definition: AMReX_GpuLaunch.nolint.H:49
#define AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(where_to_run, box, nc, i, j, k, n, block)
Definition: AMReX_GpuLaunch.nolint.H:89
#define AMREX_GPU_DEVICE
Definition: AMReX_GpuQualifiers.H:18
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
int idir
Definition: AMReX_HypreMLABecLap.cpp:1093
Array4< int const > offset
Definition: AMReX_HypreMLABecLap.cpp:1089
Real * pdst
Definition: AMReX_HypreMLABecLap.cpp:1090
Array4< int const > mask
Definition: AMReX_InterpFaceRegister.cpp:93
#define AMREX_LOOP_3D(bx, i, j, k, block)
Definition: AMReX_Loop.nolint.H:4
#define AMREX_LOOP_4D(bx, ncomp, i, j, k, n, block)
Definition: AMReX_Loop.nolint.H:16
void amrex_mempool_free(void *p)
Definition: AMReX_MemPool.cpp:80
void * amrex_mempool_alloc(size_t nbytes)
Definition: AMReX_MemPool.cpp:74
#define AMREX_D_TERM(a, b, c)
Definition: AMReX_SPACE.H:129
#define AMREX_D_DECL(a, b, c)
Definition: AMReX_SPACE.H:104
A virtual base class for objects that manage their own dynamic memory allocation.
Definition: AMReX_Arena.H:100
A FortranArrayBox(FAB)-like object.
Definition: AMReX_BaseFab.H:183
int maskGE(BaseFab< int > &mask, T const &val, int comp=0) const noexcept
Same as above except mark cells with value greater than or equal to val.
Definition: AMReX_BaseFab.H:2908
BaseFab< T > & saxpy(T a, const BaseFab< T > &x, const Box &srcbox, const Box &destbox, int srccomp, int destcomp, int numcomp=1) noexcept
FAB SAXPY (y[i] <- y[i] + a * x[i]), in place.
Definition: AMReX_BaseFab.H:2964
BaseFab< T > & copy(const BaseFab< T > &src, Box bx, SrcComp scomp, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx does not intersect with src fab.
Definition: AMReX_BaseFab.H:3824
T sum(int comp, int numcomp=1) const noexcept
Returns sum of given component of FAB state vector.
Definition: AMReX_BaseFab.H:3194
gpuStream_t alloc_stream
Definition: AMReX_BaseFab.H:1656
Real norminfmask(const Box &subbox, const BaseFab< int > &mask, int scomp=0, int ncomp=1) const noexcept
Definition: AMReX_BaseFab.H:2337
BaseFab< T > & divide(T const &val) noexcept
Scalar division on the whole domain and all components.
Definition: AMReX_BaseFab.H:4056
BaseFab< T > & atomicAdd(const BaseFab< T > &src, int srccomp, int destcomp, int numcomp=1) noexcept
Atomically add src components (srccomp:srccomp+numcomp-1) to this FABs components (destcomp:destcomp+...
Definition: AMReX_BaseFab.H:3266
std::pair< T, T > minmax(const Box &subbox, int comp=0) const noexcept
Definition: AMReX_BaseFab.H:2560
BaseFab< T > & minus(const BaseFab< T > &src, Box bx, SrcComp scomp, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx does not intersect with src fab.
Definition: AMReX_BaseFab.H:3964
BaseFab< T > & lockAdd(const BaseFab< T > &src, const Box &srcbox, const Box &destbox, int srccomp, int destcomp, int numcomp) noexcept
Atomically add srcbox region of src FAB to destbox region of this FAB. The srcbox and destbox must be...
Definition: AMReX_BaseFab.H:3350
std::size_t copyToMem(const Box &srcbox, int srccomp, int numcomp, void *dst) const noexcept
Copy from the srcbox of this Fab to raw memory and return the number of bytes copied.
Definition: AMReX_BaseFab.H:2218
std::size_t addFromMem(const Box &dstbox, int dstcomp, int numcomp, const void *src) noexcept
Add from raw memory to the dstbox of this Fab and return the number of bytes copied.
Definition: AMReX_BaseFab.H:2273
BaseFab< T > & divide(const BaseFab< T > &src, int srccomp, int destcomp, int numcomp=1) noexcept
This FAB is numerator, src FAB is denominator divide src components (srccomp:srccomp+numcomp-1) into ...
Definition: AMReX_BaseFab.H:3570
AMREX_FORCE_INLINE Array4< T const > const_array() const noexcept
Definition: AMReX_BaseFab.H:415
std::size_t nBytesOwned() const noexcept
Definition: AMReX_BaseFab.H:268
BaseFab< T > & copy(const BaseFab< T > &src) noexcept
Definition: AMReX_BaseFab.H:3815
BaseFab< T > & addproduct(const Box &destbox, int destcomp, int numcomp, const BaseFab< T > &src1, int comp1, const BaseFab< T > &src2, int comp2) noexcept
y[i] <- y[i] + x1[i] * x2[i])
Definition: AMReX_BaseFab.H:3029
BaseFab< T > & minus(T const &val) noexcept
Scalar subtraction on the whole domain and all components.
Definition: AMReX_BaseFab.H:3916
BaseFab< T > & copy(const BaseFab< T > &src, int srccomp, int destcomp, int numcomp=1) noexcept
As above, except the destination Box and the source Box are taken to be the entire domain of the dest...
Definition: AMReX_BaseFab.H:1920
BaseFab< T > & negate(const Box &b, int comp=0, int numcomp=1) noexcept
Negate BaseFab, most general.
Definition: AMReX_BaseFab.H:3218
int maskLT(BaseFab< int > &mask, T const &val, int comp=0) const noexcept
Compute mask array with value of 1 in cells where BaseFab has value less than val,...
Definition: AMReX_BaseFab.H:2724
BaseFab< T > & plus(T const &val) noexcept
Scalar addition on the whole domain and all components.
Definition: AMReX_BaseFab.H:3846
BaseFab< T > & plus(T const &r, int comp, int numcomp=1) noexcept
As above, except on entire domain.
Definition: AMReX_BaseFab.H:3242
BaseFab< T > & mult(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition: AMReX_BaseFab.H:4002
BaseFab< T > & mult(const BaseFab< T > &src, Box bx, SrcComp scomp, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx does not intersect with src fab.
Definition: AMReX_BaseFab.H:4034
std::size_t nBytes(const Box &bx, int ncomps) const noexcept
Returns bytes used in the Box for those components.
Definition: AMReX_BaseFab.H:273
void setPtr(T *p, Long sz) noexcept
Definition: AMReX_BaseFab.H:373
BaseFab< T > & linComb(const BaseFab< T > &f1, const Box &b1, int comp1, const BaseFab< T > &f2, const Box &b2, int comp2, Real alpha, Real beta, const Box &b, int comp, int numcomp=1) noexcept
Linear combination. Result is alpha*f1 + beta*f2. Data is taken from b1 region of f1,...
Definition: AMReX_BaseFab.H:3053
void define()
Allocates memory for the BaseFab<T>.
Definition: AMReX_BaseFab.H:1927
BaseFab< T > & operator*=(T const &val) noexcept
Definition: AMReX_BaseFab.H:3994
void resize(const Box &b, int N=1, Arena *ar=nullptr)
This function resizes a BaseFab so it covers the Box b with N components.
Definition: AMReX_BaseFab.H:2098
BaseFab< T > & divide(T const &r, const Box &b, int comp=0, int numcomp=1) noexcept
As above except specify sub-box.
Definition: AMReX_BaseFab.H:3562
BaseFab< T > & mult(T const &r, int comp, int numcomp=1) noexcept
Scalar multiplication, except control which components are multiplied.
Definition: AMReX_BaseFab.H:3496
BaseFab< T > & invert(T const &r, const Box &bx, DestComp dcomp, NumComps ncomp) noexcept
Definition: AMReX_BaseFab.H:4158
BaseFab< T > & atomicAdd(const BaseFab< T > &x) noexcept
Atomic FAB addition (a[i] <- a[i] + b[i]).
Definition: AMReX_BaseFab.H:2954
int maskEQ(BaseFab< int > &mask, T const &val, int comp=0) const noexcept
Same as above except mark cells with value equal to val.
Definition: AMReX_BaseFab.H:2816
bool contains(const BaseFab< T > &fab) const noexcept
Returns true if the domain of fab is totally contained within the domain of this BaseFab.
Definition: AMReX_BaseFab.H:332
bool isAllocated() const noexcept
Returns true if the data for the FAB has been allocated.
Definition: AMReX_BaseFab.H:433
std::unique_ptr< T, DataDeleter > release() noexcept
Release ownership of memory.
Definition: AMReX_BaseFab.H:2200
void setVal(T const &x, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition: AMReX_BaseFab.H:3732
BaseFab< T > & protected_divide(const BaseFab< T > &src, int srccomp, int destcomp, int numcomp=1) noexcept
Divide wherever "src" is "true" or "non-zero". This FAB is numerator, src FAB is denominator divide s...
Definition: AMReX_BaseFab.H:3622
BaseFab< T > & operator-=(T const &val) noexcept
Definition: AMReX_BaseFab.H:3924
void setValIf(T const &val, Box const &bx, const BaseFab< int > &mask, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition: AMReX_BaseFab.H:3753
IntVect indexFromValue(const Box &subbox, int comp, T const &value) const noexcept
Definition: AMReX_BaseFab.H:2633
BaseFab< T > & mult(const BaseFab< T > &src) noexcept
Definition: AMReX_BaseFab.H:4018
bool shared_memory
Is the memory allocated in shared memory?
Definition: AMReX_BaseFab.H:1654
BaseFab< T > & minus(const BaseFab< T > &src, const Box &srcbox, const Box &destbox, int srccomp, int destcomp, int numcomp=1) noexcept
Subtract srcbox region of src FAB from destbox region of this FAB. srcbox and destbox must be same si...
Definition: AMReX_BaseFab.H:3470
void abs(const Box &subbox, int comp=0, int numcomp=1) noexcept
Calculate abs() on subbox for given component range.
Definition: AMReX_BaseFab.H:2325
int maskLE(BaseFab< int > &mask, T const &val, int comp=0) const noexcept
Same as above except mark cells with value less than or equal to val.
Definition: AMReX_BaseFab.H:2770
void setValIf(T const &val, const BaseFab< int > &mask) noexcept
Definition: AMReX_BaseFab.H:3745
Real norm(const Box &subbox, int p, int scomp=0, int numcomp=1) const noexcept
Same as above except only on given subbox.
Definition: AMReX_BaseFab.H:2389
const int * loVect() const noexcept
Returns the lower corner of the domain.
Definition: AMReX_BaseFab.H:316
BaseFab< T > & plus(const BaseFab< T > &src, Box bx, SrcComp scomp, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx does not intersect with src fab.
Definition: AMReX_BaseFab.H:3894
AMREX_FORCE_INLINE Array4< T const > array(int start_comp, int num_comps) const noexcept
Definition: AMReX_BaseFab.H:391
void setValIfNot(T const &val, const BaseFab< int > &mask) noexcept
Definition: AMReX_BaseFab.H:3767
AMREX_FORCE_INLINE Array4< T > array() noexcept
Definition: AMReX_BaseFab.H:397
BaseFab< T > & xpay(T a, const BaseFab< T > &x, const Box &srcbox, const Box &destbox, int srccomp, int destcomp, int numcomp=1) noexcept
FAB XPAY (y[i] <- x[i] + a * y[i])
Definition: AMReX_BaseFab.H:3001
std::size_t nBytes() const noexcept
Returns how many bytes used.
Definition: AMReX_BaseFab.H:266
T * dataPtr(int n=0) noexcept
Returns a pointer to an object of type T that is the value of the Nth component associated with the c...
Definition: AMReX_BaseFab.H:352
AMREX_FORCE_INLINE Array4< T const > array(int start_comp) const noexcept
Definition: AMReX_BaseFab.H:385
std::size_t copyFromMem(const Box &dstbox, int dstcomp, int numcomp, const void *src) noexcept
Copy from raw memory to the dstbox of this Fab and return the number of bytes copied.
Definition: AMReX_BaseFab.H:2245
BaseFab< T > & negate() noexcept
on the whole domain and all components
Definition: AMReX_BaseFab.H:4126
BaseFab< T > & minus(const BaseFab< T > &src) noexcept
Definition: AMReX_BaseFab.H:3948
BaseFab< T > & linInterp(const BaseFab< T > &f1, int comp1, const BaseFab< T > &f2, int comp2, Real t1, Real t2, Real t, const Box &b, int comp, int numcomp=1) noexcept
Version of linInterp() in which b, b1, & b2 are the same.
Definition: AMReX_BaseFab.H:3701
BaseFab< T > & copy(const BaseFab< T > &src, const Box &destbox) noexcept
As above, except that the destination Box is specified, but the source Box is taken to the equal to t...
Definition: AMReX_BaseFab.H:1912
T maxabs(const Box &subbox, int comp=0) const noexcept
Definition: AMReX_BaseFab.H:2602
T min(const Box &subbox, int comp=0) const noexcept
Definition: AMReX_BaseFab.H:2484
BaseFab< T > & minus(const BaseFab< T > &src, int srccomp, int destcomp, int numcomp=1) noexcept
Subtract src components (srccomp:srccomp+numcomp-1) to this FABs components (destcomp:destcomp+numcom...
Definition: AMReX_BaseFab.H:3454
T dot(const BaseFab< T > &src, const Box &bx, SrcComp scomp, DestComp dcomp, NumComps ncomp) const noexcept
Dot product of two Fabs.
Definition: AMReX_BaseFab.H:4211
T value_type
Definition: AMReX_BaseFab.H:188
void SetBoxType(const IndexType &typ) noexcept
Change the Box type without change the length.
Definition: AMReX_BaseFab.H:1298
BaseFab< T > & mult(const BaseFab< T > &src, int srccomp, int destcomp, int numcomp=1) noexcept
Multiply src components (srccomp:srccomp+numcomp-1) with this FABs components (destcomp:destcomp+numc...
Definition: AMReX_BaseFab.H:3512
BaseFab< T > & divide(const BaseFab< T > &src, const Box &subbox, int srccomp, int destcomp, int numcomp=1) noexcept
Same as above except division is restricted to intersection of subbox and src FAB....
Definition: AMReX_BaseFab.H:3578
AMREX_FORCE_INLINE Array4< T const > array() const noexcept
Definition: AMReX_BaseFab.H:379
T sum(const Box &bx, DestComp dcomp, NumComps ncomp) const noexcept
Sum.
Definition: AMReX_BaseFab.H:4174
T maxabs(int comp=0) const noexcept
Definition: AMReX_BaseFab.H:2594
BaseFab< T > & mult(T const &r, const Box &b, int comp=0, int numcomp=1) noexcept
As above, except specify sub-box.
Definition: AMReX_BaseFab.H:3504
BaseFab< T > & operator+=(T const &val) noexcept
Definition: AMReX_BaseFab.H:3854
void setComplement(T const &x, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
setVal on the complement of bx in the fab's domain
Definition: AMReX_BaseFab.H:3789
T dot(const Box &bx, DestComp dcomp, NumComps ncomp) const noexcept
Dot product.
Definition: AMReX_BaseFab.H:4260
BaseFab< T > & mult(const BaseFab< T > &src, const Box &srcbox, const Box &destbox, int srccomp, int destcomp, int numcomp=1) noexcept
Multiply srcbox region of src FAB with destbox region of this FAB. The srcbox and destbox must be sam...
Definition: AMReX_BaseFab.H:3528
BaseFab< T > & minus(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition: AMReX_BaseFab.H:3932
BaseFab< T > & divide(const BaseFab< T > &src, const Box &srcbox, const Box &destbox, int srccomp, int destcomp, int numcomp=1) noexcept
destbox region of this FAB is numerator. srcbox regions of src FAB is denominator....
Definition: AMReX_BaseFab.H:3586
Long truesize
nvar*numpts that was allocated on heap.
Definition: AMReX_BaseFab.H:1652
void setVal(T const &val) noexcept
Set value on the whole domain and all components.
Definition: AMReX_BaseFab.H:3724
T dotmask(const BaseFab< T > &src, const Box &bx, const BaseFab< int > &mask, SrcComp scomp, DestComp dcomp, NumComps ncomp) const noexcept
Dot product of two Fabs with mask.
Definition: AMReX_BaseFab.H:4297
IntVect minIndex(const Box &subbox, int comp=0) const noexcept
Definition: AMReX_BaseFab.H:2680
BaseFab< T > & saxpy(T a, const BaseFab< T > &x) noexcept
FAB SAXPY (y[i] <- y[i] + a * x[i]), in place. All components.
Definition: AMReX_BaseFab.H:2991
Box domain
My index space.
Definition: AMReX_BaseFab.H:1650
BaseFab< T > & plus(const BaseFab< T > &src, const Box &srcbox, const Box &destbox, int srccomp, int destcomp, int numcomp=1) noexcept
Add srcbox region of src FAB to destbox region of this FAB. The srcbox and destbox must be same size.
Definition: AMReX_BaseFab.H:3297
bool contains(const Box &bx) const noexcept
Returns true if bx is totally contained within the domain of this BaseFab.
Definition: AMReX_BaseFab.H:341
T * dptr
The data pointer.
Definition: AMReX_BaseFab.H:1649
BaseFab< T > & shift(const IntVect &v) noexcept
Perform shifts upon the domain of the BaseFab. They are completely analogous to the corresponding Box...
Definition: AMReX_BaseFab.H:1811
T max(const Box &subbox, int comp=0) const noexcept
Definition: AMReX_BaseFab.H:2522
const T * dataPtr(int n=0) const noexcept
Same as above except works on const FABs.
Definition: AMReX_BaseFab.H:361
BaseFab< T > & divide(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition: AMReX_BaseFab.H:4072
AMREX_FORCE_INLINE Array4< T > array(int start_comp) noexcept
Definition: AMReX_BaseFab.H:403
T max(int comp=0) const noexcept
Definition: AMReX_BaseFab.H:2514
BaseFab< T > & copy(const BaseFab< T > &src, const Box &srcbox, int srccomp, const Box &destbox, int destcomp, int numcomp) noexcept
The copy functions copy the contents of one BaseFab into another. The destination BaseFab is always t...
Definition: AMReX_BaseFab.H:1885
BaseFab< T > & mult(const BaseFab< T > &src, const Box &subbox, int srccomp, int destcomp, int numcomp=1) noexcept
Same as above except multiplication is restricted to intersection of subbox and src FAB....
Definition: AMReX_BaseFab.H:3520
int nvar
Number components.
Definition: AMReX_BaseFab.H:1651
BaseFab< T > & operator=(const BaseFab< T > &rhs)=delete
BaseFab< T > & protected_divide(const BaseFab< T > &src, const Box &subbox, int srccomp, int destcomp, int numcomp=1) noexcept
Divide wherever "src" is "true" or "non-zero". Same as above except division is restricted to interse...
Definition: AMReX_BaseFab.H:3632
T dot(const Box &xbx, int xcomp, const BaseFab< T > &y, const Box &ybx, int ycomp, int numcomp=1) const noexcept
Dot product of x (i.e.,this) and y.
Definition: AMReX_BaseFab.H:3090
BaseFab< T > & shiftHalf(const IntVect &v) noexcept
Perform shifts upon the domain of the BaseFab. They are completely analogous to the corresponding Box...
Definition: AMReX_BaseFab.H:1827
BaseFab< T > & divide(T const &r, int comp, int numcomp=1) noexcept
As above except specify which components.
Definition: AMReX_BaseFab.H:3554
Real norm(int p, int scomp=0, int numcomp=1) const noexcept
Compute the Lp-norm of this FAB using components (scomp : scomp+ncomp-1). p < 0 -> ERROR p = 0 -> inf...
Definition: AMReX_BaseFab.H:2381
BaseFab< T > & atomicAdd(const BaseFab< T > &src, const Box &subbox, int srccomp, int destcomp, int numcomp=1) noexcept
Same as above except addition is restricted to intersection of subbox and src FAB....
Definition: AMReX_BaseFab.H:3285
const Box & box() const noexcept
Returns the domain (box) where the array is defined.
Definition: AMReX_BaseFab.H:291
AMREX_FORCE_INLINE Array4< T const > const_array(int start_comp, int num_comps) const noexcept
Definition: AMReX_BaseFab.H:427
BaseFab< T > & minus(const BaseFab< T > &src, const Box &subbox, int srccomp, int destcomp, int numcomp=1) noexcept
Same as above except subtraction is restricted to intersection of subbox and src FAB....
Definition: AMReX_BaseFab.H:3462
const int * nCompPtr() const noexcept
for calls to fortran.
Definition: AMReX_BaseFab.H:280
BaseFab< T > & plus(const BaseFab< T > &src, const Box &subbox, int srccomp, int destcomp, int numcomp=1) noexcept
Same as above except addition is restricted to intersection of subbox and src FAB....
Definition: AMReX_BaseFab.H:3276
BaseFab< T > & operator/=(T const &val) noexcept
Definition: AMReX_BaseFab.H:4064
std::pair< T, T > minmax(int comp=0) const noexcept
Definition: AMReX_BaseFab.H:2552
BaseFab< T > & negate(const Box &bx, DestComp dcomp, NumComps ncomp) noexcept
Definition: AMReX_BaseFab.H:4134
void fill_snan() noexcept
Definition: AMReX_BaseFab.H:1845
void setVal(T const &x, const Box &bx, int dcomp, int ncomp) noexcept
The setVal functions set sub-regions in the BaseFab to a constant value. This most general form speci...
Definition: AMReX_BaseFab.H:1869
const IntVect & smallEnd() const noexcept
Returns the lower corner of the domain See class Box for analogue.
Definition: AMReX_BaseFab.H:303
BaseFab< T > & protected_divide(const BaseFab< T > &src, const Box &srcbox, const Box &destbox, int srccomp, int destcomp, int numcomp=1) noexcept
Definition: AMReX_BaseFab.H:3644
T dot(const Box &bx, int destcomp, int numcomp) const noexcept
Int wrapper for dot.
Definition: AMReX_BaseFab.H:4251
Long size() const noexcept
Returns the total number of points of all components.
Definition: AMReX_BaseFab.H:288
BaseFab< T > & plus(T const &r, const Box &b, int comp=0, int numcomp=1) noexcept
Scalar addition (a[i] <- a[i] + r), most general.
Definition: AMReX_BaseFab.H:3250
void maxIndex(const Box &subbox, Real &max_value, IntVect &max_idx, int comp=0) const noexcept
Definition: AMReX_BaseFab.H:2715
void getVal(T *data, const IntVect &pos, int N, int numcomp) const noexcept
This function puts numcomp component values, starting at component N, from position pos in the domain...
Definition: AMReX_BaseFab.H:1785
const int * hiVect() const noexcept
Returns the upper corner of the domain.
Definition: AMReX_BaseFab.H:326
Elixir elixir() noexcept
Definition: AMReX_BaseFab.H:2140
Long numPts() const noexcept
Returns the number of points.
Definition: AMReX_BaseFab.H:285
IntVect maxIndex(const Box &subbox, int comp=0) const noexcept
Definition: AMReX_BaseFab.H:2706
void setValIfNot(T const &val, Box const &bx, const BaseFab< int > &mask, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition: AMReX_BaseFab.H:3775
BaseFab< T > & mult(T const &val) noexcept
Scalar multiplication on the whole domain and all components.
Definition: AMReX_BaseFab.H:3986
BaseFab< T > & divide(const BaseFab< T > &src, Box bx, SrcComp scomp, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx does not intersect with src fab.
Definition: AMReX_BaseFab.H:4104
void setValIfNot(T const &val, const Box &bx, const BaseFab< int > &mask, int nstart, int num) noexcept
Definition: AMReX_BaseFab.H:1877
BaseFab< T > & shiftHalf(int dir, int n_cell) noexcept
Perform shifts upon the domain of the BaseFab. They are completely analogous to the corresponding Box...
Definition: AMReX_BaseFab.H:1835
void setVal(T const &x, const Box &bx, int N=0) noexcept
Same as above, except the number of modified components is one. N is the component to be modified.
Definition: AMReX_BaseFab.H:1853
void prefetchToDevice() const noexcept
Definition: AMReX_BaseFab.H:1713
const IntVect & bigEnd() const noexcept
Returns the upper corner of the domain. See class Box for analogue.
Definition: AMReX_BaseFab.H:306
bool ptr_owner
Owner of T*?
Definition: AMReX_BaseFab.H:1653
BaseFab< T > & negate(int comp, int numcomp=1) noexcept
As above, except on entire domain.
Definition: AMReX_BaseFab.H:3210
virtual ~BaseFab() noexcept
The destructor deletes the array memory.
Definition: AMReX_BaseFab.H:2045
void setVal(T const &x, int N) noexcept
Same as above, except the sub-box defaults to the entire domain.
Definition: AMReX_BaseFab.H:1861
AMREX_FORCE_INLINE Array4< T > array(int start_comp, int num_comps) noexcept
Definition: AMReX_BaseFab.H:409
BaseFab< T > & shift(int idir, int n_cell) noexcept
Perform shifts upon the domain of the BaseFab. They are completely analogous to the corresponding Box...
Definition: AMReX_BaseFab.H:1819
IntVect length() const noexcept
Returns a pointer to an array of SPACEDIM integers giving the length of the domain in each direction.
Definition: AMReX_BaseFab.H:297
BaseFab< T > & invert(T const &r, int comp, int numcomp=1) noexcept
As above except on entire domain.
Definition: AMReX_BaseFab.H:3226
T & operator()(const IntVect &p, int N) noexcept
Returns a reference to the Nth component value defined at position p in the domain....
Definition: AMReX_BaseFab.H:1738
IntVect maxIndex(int comp=0) const noexcept
Definition: AMReX_BaseFab.H:2698
BaseFab< T > & protected_divide(const BaseFab< T > &src) noexcept
Divide wherever "src" is "true" or "non-zero".
Definition: AMReX_BaseFab.H:3612
friend class BaseFab
Definition: AMReX_BaseFab.H:186
BaseFab< T > & invert(T const &r, const Box &b, int comp=0, int numcomp=1) noexcept
Most general version, specify subbox and which components.
Definition: AMReX_BaseFab.H:3234
BaseFab< T > & invert(T const &r) noexcept
Fab <- Fab/r on the whole domain and all components.
Definition: AMReX_BaseFab.H:4150
T sum(const Box &subbox, int comp, int numcomp=1) const noexcept
Compute sum of given component of FAB state vector in given subbox.
Definition: AMReX_BaseFab.H:3202
int nComp() const noexcept
Returns the number of components.
Definition: AMReX_BaseFab.H:277
int maskGT(BaseFab< int > &mask, T const &val, int comp=0) const noexcept
Same as above except mark cells with value greater than val.
Definition: AMReX_BaseFab.H:2862
T dotmask(const BaseFab< int > &mask, const Box &xbx, int xcomp, const BaseFab< T > &y, const Box &ybx, int ycomp, int numcomp) const noexcept
Definition: AMReX_BaseFab.H:3140
void clear() noexcept
The function returns the BaseFab to the invalid state. The memory is freed.
Definition: AMReX_BaseFab.H:2161
AMREX_FORCE_INLINE Array4< T const > const_array(int start_comp) const noexcept
Definition: AMReX_BaseFab.H:421
BaseFab< T > & plus(const BaseFab< T > &src) noexcept
Definition: AMReX_BaseFab.H:3878
void abs(int comp, int numcomp=1) noexcept
Same as above except only for components (comp: comp+numcomp-1)
Definition: AMReX_BaseFab.H:2317
BaseFab() noexcept=default
Construct an empty BaseFab, which must be resized (see BaseFab::resize) before use.
BaseFab< T > & divide(const BaseFab< T > &src) noexcept
Definition: AMReX_BaseFab.H:4088
void prefetchToHost() const noexcept
Definition: AMReX_BaseFab.H:1688
T min(int comp=0) const noexcept
Definition: AMReX_BaseFab.H:2476
void setComplement(T const &x, const Box &b, int ns, int num) noexcept
This function is analogous to the fourth form of setVal above, except that instead of setting values ...
Definition: AMReX_BaseFab.H:2301
BaseFab< T > & linInterp(const BaseFab< T > &f1, const Box &b1, int comp1, const BaseFab< T > &f2, const Box &b2, int comp2, Real t1, Real t2, Real t, const Box &b, int comp, int numcomp=1) noexcept
Linear interpolation / extrapolation. Result is (t2-t)/(t2-t1)*f1 + (t-t1)/(t2-t1)*f2 Data is taken f...
Definition: AMReX_BaseFab.H:3682
IntVect minIndex(int comp=0) const noexcept
Definition: AMReX_BaseFab.H:2672
void minIndex(const Box &subbox, Real &min_val, IntVect &min_idx, int comp=0) const noexcept
Definition: AMReX_BaseFab.H:2689
T * dataPtr(const IntVect &p, int n=0) noexcept
Definition: AMReX_BaseFab.H:1663
BaseFab< T > & plus(const BaseFab< T > &src, int srccomp, int destcomp, int numcomp=1) noexcept
Add src components (srccomp:srccomp+numcomp-1) to this FABs components (destcomp:destcomp+numcomp-1) ...
Definition: AMReX_BaseFab.H:3258
void abs() noexcept
Compute absolute value for all components of this FAB.
Definition: AMReX_BaseFab.H:2309
void getVal(T *data, const IntVect &pos) const noexcept
Same as above, except that starts at component 0 and copies all comps.
Definition: AMReX_BaseFab.H:1803
BaseFab< T > & atomicAdd(const BaseFab< T > &src, const Box &srcbox, const Box &destbox, int srccomp, int destcomp, int numcomp=1) noexcept
Atomically add srcbox region of src FAB to destbox region of this FAB. The srcbox and destbox must be...
Definition: AMReX_BaseFab.H:3323
BaseFab< T > & plus(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition: AMReX_BaseFab.H:3862
A class for managing a List of Boxes that share a common IndexType. This class implements operations ...
Definition: AMReX_BoxList.H:52
AMREX_GPU_HOST_DEVICE const IntVectND< dim > & smallEnd() const &noexcept
Get the smallend of the BoxND.
Definition: AMReX_Box.H:105
AMREX_GPU_HOST_DEVICE const int * hiVect() const &noexcept
Returns a constant pointer the array of high end coordinates. Useful for calls to FORTRAN.
Definition: AMReX_Box.H:183
AMREX_GPU_HOST_DEVICE const IntVectND< dim > & bigEnd() const &noexcept
Get the bigend.
Definition: AMReX_Box.H:116
AMREX_GPU_HOST_DEVICE IntVectND< dim > length() const noexcept
Return the length of the BoxND.
Definition: AMReX_Box.H:146
AMREX_GPU_HOST_DEVICE BoxND & setType(const IndexTypeND< dim > &t) noexcept
Set indexing type.
Definition: AMReX_Box.H:492
AMREX_GPU_HOST_DEVICE const int * loVect() const &noexcept
Returns a constant pointer the array of low end coordinates. Useful for calls to FORTRAN.
Definition: AMReX_Box.H:178
AMREX_GPU_HOST_DEVICE bool ok() const noexcept
Checks if it is a proper BoxND (including a valid type).
Definition: AMReX_Box.H:200
AMREX_GPU_HOST_DEVICE bool sameSize(const BoxND &b) const noexcept
Returns true is Boxes same size, ie translates of each other,. It is an error if they have different ...
Definition: AMReX_Box.H:279
AMREX_GPU_HOST_DEVICE Long numPts() const noexcept
Returns the number of points contained in the BoxND.
Definition: AMReX_Box.H:346
AMREX_GPU_HOST_DEVICE bool contains(const IntVectND< dim > &p) const noexcept
Returns true if argument is contained within BoxND.
Definition: AMReX_Box.H:204
Definition: AMReX_Tuple.H:93
static gpuStream_t setStream(gpuStream_t s) noexcept
Definition: AMReX_GpuDevice.cpp:615
static gpuStream_t gpuStream() noexcept
Definition: AMReX_GpuDevice.H:60
static int deviceId() noexcept
Definition: AMReX_GpuDevice.cpp:568
static int devicePropMajor() noexcept
Definition: AMReX_GpuDevice.H:142
Definition: AMReX_GpuElixir.H:13
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE IntVectND< dim > TheMinVector() noexcept
Definition: AMReX_IntVect.H:720
Definition: AMReX_PODVector.H:246
T * data() noexcept
Definition: AMReX_PODVector.H:593
Definition: AMReX_Reduce.H:249
Type value()
Definition: AMReX_Reduce.H:281
Definition: AMReX_Reduce.H:364
std::enable_if_t< IsFabArray< MF >::value > eval(MF const &mf, IntVect const &nghost, D &reduce_data, F &&f)
Definition: AMReX_Reduce.H:441
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T Exch(T *address, T val) noexcept
Definition: AMReX_GpuAtomic.H:485
bool isManaged(void const *p) noexcept
Definition: AMReX_GpuUtility.H:48
void copy(HostToDevice, InIter begin, InIter end, OutIter result) noexcept
A host-to-device copy routine. Note this is just a wrapper around memcpy, so it assumes contiguous st...
Definition: AMReX_GpuContainers.H:121
void streamSynchronize() noexcept
Definition: AMReX_GpuDevice.H:237
void dtoh_memcpy_async(void *p_h, const void *p_d, const std::size_t sz) noexcept
Definition: AMReX_GpuDevice.H:265
bool inLaunchRegion() noexcept
Definition: AMReX_GpuControl.H:86
bool notInLaunchRegion() noexcept
Definition: AMReX_GpuControl.H:87
void htod_memcpy_async(void *p_d, const void *p_h, const std::size_t sz) noexcept
Definition: AMReX_GpuDevice.H:251
gpuStream_t gpuStream() noexcept
Definition: AMReX_GpuDevice.H:218
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void Add(T *const sum, T const value) noexcept
Definition: AMReX_GpuAtomic.H:619
@ max
Definition: AMReX_ParallelReduce.H:17
@ sum
Definition: AMReX_ParallelReduce.H:19
Definition: AMReX_Amr.cpp:49
std::atomic< Long > atomic_total_bytes_allocated_in_fabs_hwm
Definition: AMReX_BaseFab.cpp:14
std::enable_if_t< std::is_integral_v< T > > ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition: AMReX_CTOParallelForImpl.H:200
MakeType
Definition: AMReX_MakeType.H:7
@ make_deep_copy
Definition: AMReX_MakeType.H:7
@ make_alias
Definition: AMReX_MakeType.H:7
int nComp(FabArrayBase const &fa)
Long private_total_cells_allocated_in_fabs_hwm
high-water-mark over a given interval
Definition: AMReX_BaseFab.cpp:20
AMREX_ATTRIBUTE_FLATTEN_FOR void LoopOnCpu(Dim3 lo, Dim3 hi, F const &f) noexcept
Definition: AMReX_Loop.H:355
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Array4< T > makeArray4(T *p, Box const &bx, int ncomp) noexcept
Definition: AMReX_BaseFab.H:87
RunOn
Definition: AMReX_GpuControl.H:69
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & max(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:35
std::enable_if_t< std::is_trivially_destructible_v< T > > placementDelete(T *const, Long)
Definition: AMReX_BaseFab.H:119
cudaStream_t gpuStream_t
Definition: AMReX_GpuControl.H:77
Long private_total_cells_allocated_in_fabs
total cells at any given time
Definition: AMReX_BaseFab.cpp:19
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & min(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:21
bool InitSNaN() noexcept
Definition: AMReX.cpp:168
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T abs(const GpuComplex< T > &a_z) noexcept
Return the absolute value of a complex number.
Definition: AMReX_GpuComplex.H:356
Long TotalBytesAllocatedInFabs() noexcept
Definition: AMReX_BaseFab.cpp:64
Long private_total_bytes_allocated_in_fabs_hwm
high-water-mark over a given interval
Definition: AMReX_BaseFab.cpp:18
void BaseFab_Initialize()
Definition: AMReX_BaseFab.cpp:28
void BaseFab_Finalize()
Definition: AMReX_BaseFab.cpp:57
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 end(BoxND< dim > const &box) noexcept
Definition: AMReX_Box.H:1890
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 ubound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:315
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 lbound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:308
void ResetTotalBytesAllocatedInFabsHWM() noexcept
Definition: AMReX_BaseFab.cpp:132
BoxList boxDiff(const Box &b1in, const Box &b2)
Returns BoxList defining the compliment of b2 in b1in.
IntVectND< AMREX_SPACEDIM > IntVect
Definition: AMReX_BaseFwd.H:30
Long TotalBytesAllocatedInFabsHWM() noexcept
Definition: AMReX_BaseFab.cpp:81
std::atomic< Long > atomic_total_bytes_allocated_in_fabs
Definition: AMReX_BaseFab.cpp:13
Long TotalCellsAllocatedInFabsHWM() noexcept
Definition: AMReX_BaseFab.cpp:115
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::enable_if_t< std::is_floating_point_v< T >, bool > almostEqual(T x, T y, int ulp=2)
Definition: AMReX_Algorithm.H:93
Long TotalCellsAllocatedInFabs() noexcept
Definition: AMReX_BaseFab.cpp:98
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition: AMReX.cpp:219
std::atomic< Long > atomic_total_cells_allocated_in_fabs
Definition: AMReX_BaseFab.cpp:15
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 length(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:322
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 begin(BoxND< dim > const &box) noexcept
Definition: AMReX_Box.H:1881
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition: AMReX.cpp:225
std::enable_if_t< std::is_arithmetic_v< T > > placementNew(T *const, Long)
Definition: AMReX_BaseFab.H:94
Long private_total_bytes_allocated_in_fabs
total bytes at any given time
Definition: AMReX_BaseFab.cpp:17
std::atomic< Long > atomic_total_cells_allocated_in_fabs_hwm
Definition: AMReX_BaseFab.cpp:16
void update_fab_stats(Long n, Long s, size_t szt) noexcept
Definition: AMReX_BaseFab.cpp:144
std::array< T, N > Array
Definition: AMReX_Array.H:24
Definition: AMReX_Array4.H:61
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * ptr(int i, int j, int k) const noexcept
Definition: AMReX_Array4.H:149
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::size_t size() const noexcept
Definition: AMReX_Array4.H:243
Definition: AMReX_DataAllocator.H:9
Arena * arena() const noexcept
Definition: AMReX_DataAllocator.H:24
void * alloc(std::size_t sz) const noexcept
Definition: AMReX_DataAllocator.H:16
Definition: AMReX_DataAllocator.H:29
Definition: AMReX_BaseFab.H:72
int i
Definition: AMReX_BaseFab.H:75
AMREX_GPU_HOST_DEVICE DestComp(int ai) noexcept
Definition: AMReX_BaseFab.H:74
Definition: AMReX_Dim3.H:12
int x
Definition: AMReX_Dim3.H:12
Definition: AMReX_BaseFab.H:78
int n
Definition: AMReX_BaseFab.H:81
AMREX_GPU_HOST_DEVICE NumComps(int an) noexcept
Definition: AMReX_BaseFab.H:80
Definition: AMReX_BaseFab.H:66
AMREX_GPU_HOST_DEVICE SrcComp(int ai) noexcept
Definition: AMReX_BaseFab.H:68
int i
Definition: AMReX_BaseFab.H:69