diff --git a/Src/Base/AMReX_MultiFab.H b/Src/Base/AMReX_MultiFab.H index b2fc9c80a1f..8ec62700cc1 100644 --- a/Src/Base/AMReX_MultiFab.H +++ b/Src/Base/AMReX_MultiFab.H @@ -486,6 +486,14 @@ public: int dstcomp, int numcomp, const IntVect& nghost); + + /** Create a deep copy of this MultiFab and its data. + * + * This uses the same arena and factory in the copy and copies + * all data. + */ + [[nodiscard]] MultiFab deepCopy () const; + /** * \brief Copy from src to dst including nghost ghost cells. * The two MultiFabs MUST have the same underlying BoxArray. diff --git a/Src/Base/AMReX_MultiFab.cpp b/Src/Base/AMReX_MultiFab.cpp index 15f9490b1c2..2a80123836b 100644 --- a/Src/Base/AMReX_MultiFab.cpp +++ b/Src/Base/AMReX_MultiFab.cpp @@ -167,6 +167,28 @@ MultiFab::Add (MultiFab& dst, const MultiFab& src, amrex::Add(dst, src, srccomp, dstcomp, numcomp, nghost); } +MultiFab +MultiFab::deepCopy () const +{ + MultiFab mf( + this->boxArray(), + this->DistributionMap(), + this->nComp(), + this->nGrowVect(), + MFInfo().SetArena(this->arena()), + this->Factory() + ); + MultiFab::Copy( + mf, + *this, + 0, + 0, + this->nComp(), + this->nGrowVect() + ); + return mf; +} + void MultiFab::Copy (MultiFab& dst, const MultiFab& src, int srccomp, int dstcomp, int numcomp, int nghost)