Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow zero components MultiFab and BaseFab #2873

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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