From 3789855545c6ce8c8493971d67af4b5cf50d9c6e Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Mon, 25 Mar 2024 14:21:35 -0700 Subject: [PATCH] `MultiFab::copy()` Create a copy of this MultiFab, using the same Arena. --- Src/Base/AMReX_MultiFab.H | 6 ++++++ Src/Base/AMReX_MultiFab.cpp | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Src/Base/AMReX_MultiFab.H b/Src/Base/AMReX_MultiFab.H index b2fc9c80a1f..005a3dd154a 100644 --- a/Src/Base/AMReX_MultiFab.H +++ b/Src/Base/AMReX_MultiFab.H @@ -486,6 +486,12 @@ public: int dstcomp, int numcomp, const IntVect& nghost); + + + /** Create a copy of this MultiFab, using the same Arena. + */ + MultiFab copy (); + /** * \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..072cbf074c5 100644 --- a/Src/Base/AMReX_MultiFab.cpp +++ b/Src/Base/AMReX_MultiFab.cpp @@ -167,6 +167,27 @@ MultiFab::Add (MultiFab& dst, const MultiFab& src, amrex::Add(dst, src, srccomp, dstcomp, numcomp, nghost); } +MultiFab +MultiFab::copy () +{ + auto mf = MultiFab( + this->boxArray(), + this->DistributionMap(), + this->nComp(), + this->nGrowVect(), + MFInfo().SetArena(this->arena()) + ); + 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)