From 71079ce737bdd1c8b7fbde15537969b56e7df80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Wed, 9 Oct 2024 13:37:41 +0200 Subject: [PATCH] Initialise Fluid-in-Place Balance Sheets at Restart Commit 6ba9dc086 (PR #5626) moved the balance sheet report output logic ahead of the timestep. As a consequence, the output module's 'inplace_' and 'initialInplace_' data members must be fully initialised the first time we call 'writeReports()' if the run requests balance sheet output. This commit initialises those objects by calling calc_inplace() from EclWriter<>::endRestart(). Doing so restores the behaviour from before PR #5626. Note, however, that using this value for 'initialInplace_' is incorrect as the simulator then, in a restarted run, will calculate recovery factors based on the fluid distribution at the restart time instead of at the start of the base run. Nevertheless this is, as alluded to earlier, how the simulator has always performed. The behaviour is just a little more explicit now. --- opm/simulators/flow/EclWriter.hpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/opm/simulators/flow/EclWriter.hpp b/opm/simulators/flow/EclWriter.hpp index d49127838..9cea8f0b3 100644 --- a/opm/simulators/flow/EclWriter.hpp +++ b/opm/simulators/flow/EclWriter.hpp @@ -637,7 +637,29 @@ public: } void endRestart() - {} + { + // We need these objects to satisfy the interface requirements of + // member function calc_inplace(), but the objects are otherwise + // unused and intentionally so. + auto miscSummaryData = std::map{}; + auto regionData = std::map>{}; + + // Note: calc_inplace() *also* assigns the output module's + // "initialInplace_" data member. This is, semantically speaking, + // very wrong, as the run's intial volumes then correspond to the + // volumes at the restart time instead of the start of the base run. + // Nevertheless, this is how Flow has "always" done it. + // + // See GenericOutputBlackoilModule::accumulateRegionSums() for + // additional comments. + auto inplace = this->outputModule_ + ->calc_inplace(miscSummaryData, regionData, + this->simulator_.gridView().comm()); + + if (this->collectOnIORank_.isIORank()) { + this->inplace_ = std::move(inplace); + } + } const OutputBlackOilModule& outputModule() const { return *outputModule_; }