Skip to content

Commit

Permalink
added total net heating in history output (SN)
Browse files Browse the repository at this point in the history
  • Loading branch information
mari2895 committed Mar 11, 2024
1 parent 691f6c1 commit 039fdf5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/analysis/history.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Real ReduceInGain(MeshData<Real> *md, const std::string &varname, int idx = 0) {
std::is_same<Reducer_t, Kokkos::Sum<Real, HostExecSpace>>::value ||
std::is_same<Reducer_t, Kokkos::Sum<Real, DevExecSpace>>::value ||
std::is_same<Reducer_t, Kokkos::Sum<Real, Kokkos::DefaultExecutionSpace>>::value;
auto geom = Geometry::GetCoordinateSystem(md);

parthenon::par_reduce(
parthenon::LoopPatternMDRange(), "Phoebus History for " + varname, DevExecSpace(),
Expand All @@ -120,10 +121,12 @@ Real ReduceInGain(MeshData<Real> *md, const std::string &varname, int idx = 0) {
// join is a Kokkos construct
// that automatically does the
// reduction operation locally
Real gdet = geom.DetGamma(CellLocation::Cent, 0, k, j, i);
bool is_netheat = (pack(b, iheat, k, j, i) - pack(b, icool, k, j, i) > 0);
const auto &coords = pack.GetCoords(b);
const Real vol = volume_weighting ? coords.CellVolume(k, j, i) : 1.0;
reducer.join(lresult, pack(b, ivar.first + idx, k, j, i) * vol * is_netheat);
reducer.join(lresult,
pack(b, ivar.first + idx, k, j, i) * gdet * vol * is_netheat);
},
reducer);
return result;
Expand Down
12 changes: 10 additions & 2 deletions src/fluid/fluid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {
// Reductions
// By default compute integrated value of scalar conserved vars
auto HstSum = parthenon::UserHistoryOperation::sum;
auto HstMax = parthenon::UserHistoryOperation::max;
using History::ReduceInGain;
using History::ReduceOneVar;
using parthenon::HistoryOutputVar;
Expand All @@ -322,17 +323,24 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {
auto ReduceEn = [](MeshData<Real> *md) {
return ReduceOneVar<Kokkos::Sum<Real>>(md, fluid_cons::energy::name(), 0);
};
auto CentralDensitySN = [](MeshData<Real> *md) {
auto MaxDensitySN = [](MeshData<Real> *md) {
History::ReduceCentralDensitySN(md);
return ReduceOneVar<Kokkos::Max<Real>>(md, diag::central_density::name(), 0);
};
auto Mgain = [](MeshData<Real> *md) {
return ReduceInGain<Kokkos::Sum<Real, HostExecSpace>>(md, fluid_prim::density::name(),
0);
};
auto Qgain = [](MeshData<Real> *md) {
return ReduceInGain<Kokkos::Sum<Real, HostExecSpace>>(
md, internal_variables::GcovHeat::name(), 0) -
ReduceInGain<Kokkos::Sum<Real, HostExecSpace>>(
md, internal_variables::GcovCool::name(), 0);
};

hst_vars.emplace_back(HistoryOutputVar(HstSum, CentralDensitySN, "central density SN"));
hst_vars.emplace_back(HistoryOutputVar(HstMax, MaxDensitySN, "maximum density SN"));
hst_vars.emplace_back(HistoryOutputVar(HstSum, Mgain, "Mgain"));
hst_vars.emplace_back(HistoryOutputVar(HstSum, Qgain, "total net heat"));
hst_vars.emplace_back(HistoryOutputVar(HstSum, ReduceMass, "total baryon number"));
hst_vars.emplace_back(HistoryOutputVar(HstSum, ReduceEn, "total conserved energy tau"));

Expand Down

0 comments on commit 039fdf5

Please sign in to comment.