From c8209c39a79e87ac6d15c7551f8a862f37d1bf58 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 12 Feb 2025 15:07:36 +0100 Subject: [PATCH] move CompositionalContainer member into OutputCompositionalModule --- .../flow/CompositionalContainer.cpp | 22 +++++--------- .../flow/CompositionalContainer.hpp | 3 +- .../flow/GenericOutputBlackoilModule.cpp | 30 +++++-------------- .../flow/GenericOutputBlackoilModule.hpp | 11 +++---- .../flow/OutputCompositionalModule.hpp | 28 ++++++++++++----- 5 files changed, 41 insertions(+), 53 deletions(-) diff --git a/opm/simulators/flow/CompositionalContainer.cpp b/opm/simulators/flow/CompositionalContainer.cpp index 8f5034b0c..28135641d 100644 --- a/opm/simulators/flow/CompositionalContainer.cpp +++ b/opm/simulators/flow/CompositionalContainer.cpp @@ -23,8 +23,6 @@ #include #include -#include -#include #include #include @@ -42,8 +40,8 @@ allocate(const unsigned bufferSize, std::map& rstKeywords) { if (auto& zmf = rstKeywords["ZMF"]; zmf > 0) { - zmf = 0; this->allocated_ = true; + zmf = 0; for (int i = 0; i < numComponents; ++i) { moleFractions_[i].resize(bufferSize, 0.0); } @@ -112,7 +110,8 @@ assignOilFractions(const unsigned globalDofIdx, template void CompositionalContainer:: -outputRestart(data::Solution& sol) +outputRestart(data::Solution& sol, + ScalarBuffer& oil_saturation) { using DataEntry = std::tuple&>; @@ -158,6 +157,10 @@ outputRestart(data::Solution& sol) } } + if (!oil_saturation.empty()) { + entries.emplace_back("SOIL", UnitSystem::measure::identity, oil_saturation); + } + std::for_each(entries.begin(), entries.end(), [&doInsert](auto& array) { doInsert(array, data::TargetType::RESTART_SOLUTION); }); @@ -165,17 +168,6 @@ outputRestart(data::Solution& sol) this->allocated_ = false; } -template using FS = BlackOilFluidSystem; - -#define INSTANTIATE_TYPE(T) \ - template class CompositionalContainer>; - -INSTANTIATE_TYPE(double) - -#if FLOW_INSTANTIATE_FLOAT -INSTANTIATE_TYPE(float) -#endif - #define INSTANTIATE_COMP(NUM) \ template using FS##NUM = GenericOilGasFluidSystem; \ template class CompositionalContainer>; diff --git a/opm/simulators/flow/CompositionalContainer.hpp b/opm/simulators/flow/CompositionalContainer.hpp index f2b2a2a2f..67a9ca4f9 100644 --- a/opm/simulators/flow/CompositionalContainer.hpp +++ b/opm/simulators/flow/CompositionalContainer.hpp @@ -64,7 +64,8 @@ public: void assignOilFractions(const unsigned globalDofIdx, const AssignFunction& fractions); - void outputRestart(data::Solution& sol); + void outputRestart(data::Solution& sol, + ScalarBuffer& oil_saturation); bool allocated() const { return allocated_; } diff --git a/opm/simulators/flow/GenericOutputBlackoilModule.cpp b/opm/simulators/flow/GenericOutputBlackoilModule.cpp index 405d70887..1d4a19fb3 100644 --- a/opm/simulators/flow/GenericOutputBlackoilModule.cpp +++ b/opm/simulators/flow/GenericOutputBlackoilModule.cpp @@ -104,8 +104,7 @@ GenericOutputBlackoilModule(const EclipseState& eclState, bool enableBrine, bool enableSaltPrecipitation, bool enableExtbo, - bool enableMICP, - bool isCompositional) + bool enableMICP) : eclState_(eclState) , schedule_(schedule) , summaryState_(summaryState) @@ -124,7 +123,6 @@ GenericOutputBlackoilModule(const EclipseState& eclState, , enableSaltPrecipitation_(enableSaltPrecipitation) , enableExtbo_(enableExtbo) , enableMICP_(enableMICP) - , isCompositional_(isCompositional) , local_data_valid_(false) { const auto& fp = eclState_.fieldProps(); @@ -527,10 +525,6 @@ assignToSolution(data::Solution& sol) DataEntry{"TMULT_RC", UnitSystem::measure::identity, rockCompTransMultiplier_}, }; - if (this->isCompositional_) { - this->compC_.outputRestart(sol); - } - for (auto& array : baseSolutionVector) { doInsert(array, data::TargetType::RESTART_SOLUTION); } @@ -574,15 +568,6 @@ assignToSolution(data::Solution& sol) data::TargetType::RESTART_SOLUTION); } - if (this->isCompositional_ && FluidSystem::phaseIsActive(oilPhaseIdx) && - ! this->saturation_[oilPhaseIdx].empty()) - { - sol.insert("SOIL", UnitSystem::measure::identity, - std::move(this->saturation_[oilPhaseIdx]), - data::TargetType::RESTART_SOLUTION); - } - - if ((eclState_.runspec().co2Storage() || eclState_.runspec().h2Storage()) && !rsw_.empty()) { auto mfrac = std::vector(this->rsw_.size(), 0.0); @@ -806,10 +791,14 @@ doAllocBuffers(const unsigned bufferSize, const bool enableWettingHysteresis, const unsigned numTracers, const std::vector& enableSolTracers, - const unsigned numOutputNnc) + const unsigned numOutputNnc, + std::map rstKeywords) { + if (rstKeywords.empty()) { + rstKeywords = schedule_.rst_keywords(reportStepNum); + } + // Output RESTART_OPM_EXTENDED only when explicitly requested by user. - std::map rstKeywords = schedule_.rst_keywords(reportStepNum); for (auto& [keyword, should_write] : rstKeywords) { if (this->isOutputCreationDirective_(keyword)) { // 'BASIC', 'FREQ' and similar. Don't attempt to create @@ -1265,11 +1254,6 @@ doAllocBuffers(const unsigned bufferSize, overburdenPressure_.resize(bufferSize, 0.0); } - if (this->isCompositional_) { - this->compC_.allocate(bufferSize, rstKeywords); - } - - //Warn for any unhandled keyword if (log) { for (auto& keyValue: rstKeywords) { diff --git a/opm/simulators/flow/GenericOutputBlackoilModule.hpp b/opm/simulators/flow/GenericOutputBlackoilModule.hpp index 0a7b0a11b..5c570803e 100644 --- a/opm/simulators/flow/GenericOutputBlackoilModule.hpp +++ b/opm/simulators/flow/GenericOutputBlackoilModule.hpp @@ -32,7 +32,6 @@ #include #include -#include #include #include #include @@ -320,8 +319,7 @@ protected: bool enableBrine, bool enableSaltPrecipitation, bool enableExtbo, - bool enableMICP, - bool isCompositional = false); + bool enableMICP); void doAllocBuffers(unsigned bufferSize, unsigned reportStepNum, @@ -330,11 +328,12 @@ protected: const bool isRestart, const bool vapparsActive = false, const bool enablePCHysteresis = false, - const bool enableNonWettingHysteresis =false, + const bool enableNonWettingHysteresis = false, const bool enableWettingHysteresis = false, unsigned numTracers = 0, const std::vector& enableSolTracers = {}, - unsigned numOutputNnc = 0); + unsigned numOutputNnc = 0, + std::map rstKeywords = {}); void makeRegionSum(Inplace& inplace, const std::string& region_name, @@ -391,7 +390,6 @@ protected: bool enableSaltPrecipitation_{false}; bool enableExtbo_{false}; bool enableMICP_{false}; - bool isCompositional_{false}; bool forceDisableFipOutput_{false}; bool forceDisableFipresvOutput_{false}; @@ -469,7 +467,6 @@ protected: std::array viscosity_; std::array relativePermeability_; - CompositionalContainer compC_; std::vector freeTracerConcentrations_; std::vector solTracerConcentrations_; diff --git a/opm/simulators/flow/OutputCompositionalModule.hpp b/opm/simulators/flow/OutputCompositionalModule.hpp index a4fdd6ccb..34b161164 100644 --- a/opm/simulators/flow/OutputCompositionalModule.hpp +++ b/opm/simulators/flow/OutputCompositionalModule.hpp @@ -45,6 +45,7 @@ #include #include +#include #include #include @@ -105,8 +106,7 @@ public: getPropValue(), getPropValue(), getPropValue(), - getPropValue(), - true) + getPropValue()) , simulator_(simulator) { for (auto& region_pair : this->regions_) { @@ -158,11 +158,24 @@ public: return; } - this->doAllocBuffers(bufferSize, - reportStepNum, - substep, - log, - isRestart); + auto rstKeywords = this->schedule_.rst_keywords(reportStepNum); + this->compC_.allocate(bufferSize, rstKeywords); + + this->doAllocBuffers(bufferSize, reportStepNum, substep, log, isRestart, + /* vapparsActive =*/ false, + /* enablePCHysteresis = */ false, + /* enableNonWettingHysteresis =*/ false, + /* enableWettingHysteresis =*/ false, + /* numTracers = */ 0, + /* enableSoltracers =*/ {}, + /* numOutputNnc =*/ 0, + std::move(rstKeywords)); + } + + void assignToSolution(data::Solution& sol) + { + this->compC_.outputRestart(sol, this->saturation_[oilPhaseIdx]); + BaseType::assignToSolution(sol); } /*! @@ -336,6 +349,7 @@ private: } const Simulator& simulator_; + CompositionalContainer compC_; }; } // namespace Opm