Skip to content

Commit f7ab597

Browse files
committed
Add Amr::derive overloads for all levels
This allows the user to create a vector of MultiFabs (one per level) with the derived quantity computed on each level. The overloads match those in AmrLevel.
1 parent a7f0aed commit f7ab597

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

Src/Amr/AMReX_Amr.H

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ public:
222222
Real time,
223223
int lev,
224224
int ngrow);
225+
//! Compute derived data on all levels and store in the dcompth component of
226+
//! each Multifab in mf
227+
void derive (const std::string& name,
228+
Real time,
229+
const Vector<MultiFab*>& mf,
230+
int dcomp);
231+
//! Compute derived data on all levels and return as a vector of MultiFab pointers
232+
Vector<std::unique_ptr<MultiFab>> derive (const std::string& name,
233+
amrex::Real time,
234+
int ngrow);
225235
//! Name of the restart chkpoint file.
226236
const std::string& theRestartFile () const noexcept { return restart_chkfile; }
227237
//! Name of the restart plotfile.

Src/Amr/AMReX_Amr.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,46 @@ Amr::derive (const std::string& name,
205205
return amr_level[lev]->derive(name,time,ngrow);
206206
}
207207

208+
Vector<std::unique_ptr<MultiFab>>
209+
Amr::derive(const std::string& name,
210+
amrex::Real time,
211+
int ngrow)
212+
{
213+
BL_PROFILE("Amr::derive()");
214+
Vector<std::unique_ptr<MultiFab>> out;
215+
out.reserve(finest_level + 1);
216+
217+
for (int i = 0; i <= finest_level; ++i)
218+
{
219+
auto mf = amr_level[i]->derive(name,time,ngrow);
220+
out.push_back(std::move(mf));
221+
}
222+
223+
return out;
224+
}
225+
226+
void
227+
Amr::derive (const std::string& name,
228+
Real time,
229+
const Vector<MultiFab*>& mf,
230+
int dcomp)
231+
{
232+
BL_PROFILE("Amr::derive()");
233+
AMREX_ASSERT(mf.size() == static_cast<amrex::Long>(finest_level + 1));
234+
235+
for (int i = 0; i <= finest_level; ++i)
236+
{
237+
AMREX_ASSERT(mf[i] != nullptr);
238+
AMREX_ASSERT(mf[i]->ok());
239+
AMREX_ASSERT(mf[i]->nComp() > dcomp);
240+
}
241+
242+
for (int i = 0; i <= finestLevel(); ++i)
243+
{
244+
amr_level[i]->derive(name,time,*(mf[i]),dcomp);
245+
}
246+
}
247+
208248
Amr::Amr (LevelBld* a_levelbld)
209249
:
210250
levelbld(a_levelbld)

0 commit comments

Comments
 (0)