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

add computeVolumeIntegral function #597

Merged
merged 1 commit into from
Apr 8, 2024
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
29 changes: 29 additions & 0 deletions src/simulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ template <typename problem_t> class AMRSimulation : public amrex::AmrCore

template <typename ReduceOp, typename F> auto computePlaneProjection(F const &user_f, int dir) const -> amrex::BaseFab<amrex::Real>;

// compute volume integrals
template <typename F> auto computeVolumeIntegral(F const &user_f) -> amrex::Real;

// I/O functions
[[nodiscard]] auto PlotFileName(int lev) const -> std::string;
[[nodiscard]] auto CustomPlotFileName(const char *base, int lev) const -> std::string;
Expand Down Expand Up @@ -1958,6 +1961,32 @@ template <typename problem_t> void AMRSimulation<problem_t>::AverageDownTo(int c
}
}

template <typename problem_t> template <typename F> auto AMRSimulation<problem_t>::computeVolumeIntegral(F const &user_f) -> amrex::Real
{
// compute integral of user_f(i, j, k, state) along the given axis.
const BL_PROFILE("AMRSimulation::computeVolumeIntegral()");

// allocate temporary multifabs
amrex::Vector<amrex::MultiFab> q;
q.resize(finest_level + 1);
for (int lev = 0; lev <= finest_level; ++lev) {
q[lev].define(boxArray(lev), DistributionMap(lev), 1, 0);
}

// evaluate user_f on all levels
// (note: it is not necessary to average down)
for (int lev = 0; lev <= finest_level; ++lev) {
auto const &state = state_new_cc_[lev].const_arrays();
auto const &result = q[lev].arrays();
amrex::ParallelFor(q[lev], [=] AMREX_GPU_DEVICE(int bx, int i, int j, int k) { result[bx](i, j, k) = user_f(i, j, k, state[bx]); });
}
amrex::Gpu::streamSynchronize();

// call amrex::volumeWeightedSum
const amrex::Real result = amrex::volumeWeightedSum(amrex::GetVecOfConstPtrs(q), 0, geom, ref_ratio);
return result;
}

#ifdef AMREX_PARTICLES
template <typename problem_t> void AMRSimulation<problem_t>::InitParticles()
{
Expand Down