From 502e99a2ca506356c70fac983d224cee1ba71386 Mon Sep 17 00:00:00 2001 From: Philipp Grete Date: Mon, 16 Dec 2024 11:35:14 +0100 Subject: [PATCH] Add power measurement timings --- inputs/exacb_turbulence.in | 4 ++++ src/hydro/hydro.cpp | 13 +++++++++++++ src/hydro/hydro_driver.cpp | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/inputs/exacb_turbulence.in b/inputs/exacb_turbulence.in index a441161b..ad856774 100644 --- a/inputs/exacb_turbulence.in +++ b/inputs/exacb_turbulence.in @@ -5,6 +5,10 @@ reference = to be written, see https://gitlab.com/pgrete/kathena/wikis/turbulenc problem_id = turbulence + +cycle_start = 50 +cycle_end = 250 + cfl = 0.3 # The Courant, Friedrichs, & Lewy (CFL) Number nlim = __NLIM__ # cycle limit diff --git a/src/hydro/hydro.cpp b/src/hydro/hydro.cpp index 54a97b7f..18dd56b8 100644 --- a/src/hydro/hydro.cpp +++ b/src/hydro/hydro.cpp @@ -678,6 +678,19 @@ std::shared_ptr Initialize(ParameterInput *pin) { pkg->CheckRefinementBlock = Hydro::ProblemCheckRefinementBlock; } + // EXACB custom modifications for power measurements + if (pin->DoesBlockExist("exacb/power")) { + const auto start = pin->GetOrAddInteger("exacb/power", "cycle_start", 50); + const auto end = pin->GetOrAddInteger("exacb/power", "cycle_stop", 250); + PARTHENON_REQUIRE_THROWS(end > start, "Measuring backwards does not make sense."); + + const auto nlim = pin->GetInteger("parthenon/time", "nlim"); + PARTHENON_REQUIRE_THROWS(nlim < 0 || nlim >= end, "end must be within nlim"); + + pkg->AddParam("exacb/power/start", start); + pkg->AddParam("exacb/power/end", end); + } + if (ProblemInitPackageData != nullptr) { ProblemInitPackageData(pin, pkg.get()); } diff --git a/src/hydro/hydro_driver.cpp b/src/hydro/hydro_driver.cpp index 36bdce91..46a55b71 100644 --- a/src/hydro/hydro_driver.cpp +++ b/src/hydro/hydro_driver.cpp @@ -395,6 +395,25 @@ TaskCollection HydroDriver::MakeTaskCollection(BlockList_t &blocks, int stage) { const int num_partitions = pmesh->DefaultNumPartitions(); + // EXACB custom modifications for power measurements + if (stage == 1 && hydro_pkg->AllParams().hasKey("exacb/power/start")) { + const auto start = hydro_pkg->Param("exacb/power/start"); + const auto end = hydro_pkg->Param("exacb/power/end"); + std::ofstream outfile; + if (start == tm.ncycle) { + outfile.open("energy.times"); + outfile << "energy_start:"; + } + if (end == tm.ncycle) { + outfile.open("energy.times", std::ios_base::app); + outfile << "energy_stop:"; + } + outfile << std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()) + .count() + << std::endl; + } + // calculate agn triggering accretion rate if ((stage == 1) && hydro_pkg->AllParams().hasKey("agn_triggering_reduce_accretion_rate") &&