Skip to content

Commit

Permalink
Allow zero components MultiFab and BaseFab (AMReX-Codes#2873)
Browse files Browse the repository at this point in the history
This is useful for particle I/O that does not have any mesh data.  yt needs
a header file associated with a MultiFab.
  • Loading branch information
WeiqunZhang committed Jul 8, 2022
1 parent c849dd1 commit 7660c88
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Src/Base/AMReX_BaseFab.H
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,22 @@ public:
* order, with the component index coming last. In other words,
* dataPtr returns a pointer to all the Nth components.
*/
T* dataPtr (int n = 0) noexcept { AMREX_ASSERT(!(this->dptr == 0)); return &(this->dptr[n*this->domain.numPts()]); }
T* dataPtr (int n = 0) noexcept {
if (this->dptr) {
return &(this->dptr[n*this->domain.numPts()]);
} else {
return nullptr;
}
}

//! Same as above except works on const FABs.
const T* dataPtr (int n = 0) const noexcept { AMREX_ASSERT(!(this->dptr == 0)); return &(this->dptr[n*this->domain.numPts()]); }
const T* dataPtr (int n = 0) const noexcept {
if (this->dptr) {
return &(this->dptr[n*this->domain.numPts()]);
} else {
return nullptr;
}
}

T* dataPtr (const IntVect& iv, int n = 0) noexcept;

Expand Down Expand Up @@ -1882,9 +1894,9 @@ BaseFab<T>::define ()
{
AMREX_ASSERT(this->dptr == 0);
AMREX_ASSERT(this->domain.numPts() > 0);
AMREX_ASSERT(std::numeric_limits<Long>::max()/this->nvar > this->domain.numPts());
AMREX_ASSERT(this->nvar >= 0);
if (this->nvar == 0) return;
AMREX_ASSERT(std::numeric_limits<Long>::max()/this->nvar > this->domain.numPts());

this->truesize = this->nvar*this->domain.numPts();
this->ptr_owner = true;
Expand Down

0 comments on commit 7660c88

Please sign in to comment.