From 2c68f12769d441b544f3061043bacd1053d9f017 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 11 Oct 2021 14:38:41 +0200 Subject: [PATCH] Load WellTestState from restart file --- ebos/eclgenericvanguard.cc | 14 ++++++++++++- ebos/eclgenericvanguard.hh | 20 +++++++++++++++++-- flow/flow_ebos_blackoil.cpp | 2 ++ flow/flow_ebos_blackoil.hpp | 2 ++ opm/simulators/flow/Main.hpp | 6 +++++- .../utils/ParallelSerialization.cpp | 5 ++++- .../utils/ParallelSerialization.hpp | 4 +++- opm/simulators/utils/readDeck.cpp | 14 +++++++++---- opm/simulators/utils/readDeck.hpp | 2 ++ opm/simulators/wells/BlackoilWellModel.hpp | 1 + .../wells/BlackoilWellModelGeneric.cpp | 3 +++ .../wells/BlackoilWellModelGeneric.hpp | 1 + 12 files changed, 64 insertions(+), 10 deletions(-) diff --git a/ebos/eclgenericvanguard.cc b/ebos/eclgenericvanguard.cc index bfee21ff7..33bcbb3bb 100644 --- a/ebos/eclgenericvanguard.cc +++ b/ebos/eclgenericvanguard.cc @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,7 @@ std::shared_ptr EclGenericVanguard::externalEclSchedule_; std::shared_ptr EclGenericVanguard::externalEclSummaryConfig_; std::unique_ptr EclGenericVanguard::externalUDQState_; std::unique_ptr EclGenericVanguard::externalActionState_; +std::unique_ptr EclGenericVanguard::externalWTestState_; std::unique_ptr EclGenericVanguard::comm_; EclGenericVanguard::EclGenericVanguard() @@ -135,6 +137,11 @@ void EclGenericVanguard::setExternalActionState(std::unique_ptr a externalActionState_ = std::move(actionState); } +void EclGenericVanguard::setExternalWTestState(std::unique_ptr wtestState) +{ + externalWTestState_ = std::move(wtestState); +} + std::string EclGenericVanguard::canonicalDeckPath(const std::string& caseName) { const auto fileExists = [](const filesystem::path& f) -> bool @@ -289,7 +296,7 @@ void EclGenericVanguard::init() parseContext_ = createParseContext(ignoredKeywords_, eclStrictParsing_); } - readDeck(EclGenericVanguard::comm(), fileName_, deck_, eclState_, eclSchedule_, udqState_, actionState_, + readDeck(EclGenericVanguard::comm(), fileName_, deck_, eclState_, eclSchedule_, udqState_, actionState_, wtestState_, eclSummaryConfig_, std::move(errorGuard), python, std::move(parseContext_), /* initFromRestart = */ false, /* checkDeck = */ enableExperiments_, outputInterval_); @@ -304,6 +311,11 @@ void EclGenericVanguard::init() else this->actionState_ = std::make_unique(); + if (EclGenericVanguard::externalWTestState_) + this->wtestState_ = std::move(EclGenericVanguard::externalWTestState_); + else + this->wtestState_ = std::make_unique(); + this->summaryState_ = std::make_unique( TimeService::from_time_t(this->eclSchedule_->getStartTime() )); // Initialize parallelWells with all local wells diff --git a/ebos/eclgenericvanguard.hh b/ebos/eclgenericvanguard.hh index 7f35f2672..3ba88f05e 100644 --- a/ebos/eclgenericvanguard.hh +++ b/ebos/eclgenericvanguard.hh @@ -28,7 +28,7 @@ #define EWOMS_ECL_GENERIC_VANGUARD_HH #include - +#include #include #include @@ -57,6 +57,7 @@ class Python; class SummaryConfig; class SummaryState; class UDQState; +class WellTestState; class EclGenericVanguard { public: @@ -152,6 +153,9 @@ public: static void setExternalUDQState(std::unique_ptr udqState); static void setExternalActionState(std::unique_ptr actionState); + static void setExternalWTestState(std::unique_ptr wtestState); + + /*! * \brief Return a reference to the parsed ECL deck. */ @@ -221,6 +225,11 @@ public: const UDQState& udqState() const { return *udqState_; } + WellTestState transferWTestState() { + return *this->wtestState_.release(); + } + + /*! * \brief Returns the name of the case. * @@ -304,6 +313,7 @@ protected: static bool externalDeckSet_; static std::unique_ptr externalUDQState_; static std::unique_ptr externalActionState_; + static std::unique_ptr externalWTestState_; static std::unique_ptr comm_; std::string caseName_; @@ -320,8 +330,14 @@ protected: bool enableExperiments_; std::unique_ptr summaryState_; - std::unique_ptr actionState_; std::unique_ptr udqState_; + std::unique_ptr actionState_; + + // Observe that this instance is handled differently from the other state + // variables, it will only be initialized for a restart run. While + // initializing a restarted run this instance is transferred to the WGState + // member in the well model. + std::unique_ptr wtestState_; // these attributes point either to the internal or to the external version of the // parser objects. diff --git a/flow/flow_ebos_blackoil.cpp b/flow/flow_ebos_blackoil.cpp index 3cbf55325..1a0cc6431 100644 --- a/flow/flow_ebos_blackoil.cpp +++ b/flow/flow_ebos_blackoil.cpp @@ -35,6 +35,7 @@ void flowEbosBlackoilSetDeck(double setupTime, std::shared_ptr deck, std::shared_ptr schedule, std::unique_ptr udqState, std::unique_ptr actionState, + std::unique_ptr wtestState, std::shared_ptr summaryConfig) { using TypeTag = Properties::TTag::EclFlowProblem; @@ -46,6 +47,7 @@ void flowEbosBlackoilSetDeck(double setupTime, std::shared_ptr deck, Vanguard::setExternalSchedule(std::move(schedule)); Vanguard::setExternalUDQState(std::move(udqState)); Vanguard::setExternalActionState(std::move(actionState)); + Vanguard::setExternalWTestState(std::move(wtestState)); Vanguard::setExternalSummaryConfig(std::move(summaryConfig)); } diff --git a/flow/flow_ebos_blackoil.hpp b/flow/flow_ebos_blackoil.hpp index df0f614d9..1b173ed65 100644 --- a/flow/flow_ebos_blackoil.hpp +++ b/flow/flow_ebos_blackoil.hpp @@ -27,6 +27,7 @@ template class FlowMainEbos; class Schedule; class SummaryConfig; class UDQState; +class WellTestState; namespace Action { class State; } @@ -37,6 +38,7 @@ void flowEbosBlackoilSetDeck(double setupTime, std::shared_ptr deck, std::shared_ptr schedule, std::unique_ptr udqState, std::unique_ptr actionState, + std::unique_ptr wtestState, std::shared_ptr summaryConfig); int flowEbosBlackoilMain(int argc, char** argv, bool outputCout, bool outputFiles); diff --git a/opm/simulators/flow/Main.hpp b/opm/simulators/flow/Main.hpp index 8d66e0028..22b281de1 100644 --- a/opm/simulators/flow/Main.hpp +++ b/opm/simulators/flow/Main.hpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -264,6 +265,7 @@ namespace Opm schedule_, std::move(udqState_), std::move(this->actionState_), + std::move(this->wtestState_), summaryConfig_); return flowEbosBlackoilMainInit( argc_, argv_, outputCout_, outputFiles_); @@ -457,7 +459,7 @@ namespace Opm if (output_param >= 0) outputInterval = output_param; - readDeck(EclGenericVanguard::comm(), deckFilename, deck_, eclipseState_, schedule_, udqState_, actionState_, + readDeck(EclGenericVanguard::comm(), deckFilename, deck_, eclipseState_, schedule_, udqState_, actionState_, wtestState_, summaryConfig_, nullptr, python, std::move(parseContext), init_from_restart_file, outputCout_, outputInterval); @@ -655,6 +657,7 @@ namespace Opm this->schedule_, std::move(this->udqState_), std::move(this->actionState_), + std::move(this->wtestState_), this->summaryConfig_); return flowEbosBlackoilMain(argc_, argv_, outputCout_, outputFiles_); @@ -670,6 +673,7 @@ namespace Opm char *saveArgs_[3]{nullptr}; std::unique_ptr udqState_{}; std::unique_ptr actionState_{}; + std::unique_ptr wtestState_{}; // These variables may be owned by both Python and the simulator std::shared_ptr deck_{}; diff --git a/opm/simulators/utils/ParallelSerialization.cpp b/opm/simulators/utils/ParallelSerialization.cpp index 5ad839d9f..1163a0c46 100644 --- a/opm/simulators/utils/ParallelSerialization.cpp +++ b/opm/simulators/utils/ParallelSerialization.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -44,7 +45,8 @@ namespace Opm { void eclStateBroadcast(Parallel::Communication comm, EclipseState& eclState, Schedule& schedule, SummaryConfig& summaryConfig, UDQState& udqState, - Action::State& actionState) + Action::State& actionState, + WellTestState& wtestState) { Opm::EclMpiSerializer ser(comm); ser.broadcast(eclState); @@ -52,6 +54,7 @@ void eclStateBroadcast(Parallel::Communication comm, EclipseState& eclState, Sch ser.broadcast(summaryConfig); ser.broadcast(udqState); ser.broadcast(actionState); + //ser.broadcast(wtestState); } void eclScheduleBroadcast(Parallel::Communication comm, Schedule& schedule) diff --git a/opm/simulators/utils/ParallelSerialization.hpp b/opm/simulators/utils/ParallelSerialization.hpp index 87b5c529f..5c24eddd3 100644 --- a/opm/simulators/utils/ParallelSerialization.hpp +++ b/opm/simulators/utils/ParallelSerialization.hpp @@ -27,6 +27,7 @@ class EclipseState; class Schedule; class SummaryConfig; class UDQState; +class WellTestState; namespace Action { class State; @@ -41,7 +42,8 @@ class State; void eclStateBroadcast(Parallel::Communication comm, EclipseState& eclState, Schedule& schedule, SummaryConfig& summaryConfig, UDQState& udqState, - Action::State& actionState); + Action::State& actionState, + WellTestState& wtestState); /// \brief Broadcasts an schedule from root node in parallel runs. void eclScheduleBroadcast(Parallel::Communication comm, Schedule& schedule); diff --git a/opm/simulators/utils/readDeck.cpp b/opm/simulators/utils/readDeck.cpp index a8a846a8a..6e04fa396 100644 --- a/opm/simulators/utils/readDeck.cpp +++ b/opm/simulators/utils/readDeck.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -117,6 +118,7 @@ namespace { std::shared_ptr& schedule, std::unique_ptr& udqState, std::unique_ptr& actionState, + std::unique_ptr& wtestState, Opm::ErrorGuard& errorGuard) { // Analytic aquifers must always be loaded from the restart file in @@ -167,6 +169,8 @@ namespace { actionState = std::make_unique(); actionState->load_rst((*schedule)[report_step].actions(), rst_state); + + wtestState = std::make_unique(schedule->runspec().start_time(), rst_state); } void createNonRestartDynamicObjects(const Opm::Deck& deck, @@ -236,6 +240,7 @@ namespace { std::shared_ptr& schedule, std::unique_ptr& udqState, std::unique_ptr& actionState, + std::unique_ptr& wtestState, std::shared_ptr& summaryConfig, std::shared_ptr python, const bool initFromRestart, @@ -265,13 +270,13 @@ namespace { loadObjectsFromRestart(*deck, parser, *parseContext, initFromRestart, outputInterval, *eclipseState, std::move(python), - schedule, udqState, actionState, + schedule, udqState, actionState, wtestState, errorGuard); } else { createNonRestartDynamicObjects(*deck, *eclipseState, *parseContext, std::move(python), - schedule, udqState, actionState, + schedule, udqState, actionState, errorGuard); } @@ -423,6 +428,7 @@ void Opm::readDeck(Opm::Parallel::Communication comm, std::shared_ptr& schedule, std::unique_ptr& udqState, std::unique_ptr& actionState, + std::unique_ptr& wtestState, std::shared_ptr& summaryConfig, std::unique_ptr errorGuard, std::shared_ptr python, @@ -441,7 +447,7 @@ void Opm::readDeck(Opm::Parallel::Communication comm, if (comm.rank() == 0) { // Always true when !HAVE_MPI try { readOnIORank(comm, deckFilename, parseContext.get(), deck, - eclipseState, schedule, udqState, actionState, + eclipseState, schedule, udqState, actionState, wtestState, summaryConfig, std::move(python), initFromRestart, checkDeck, outputInterval, *errorGuard); } @@ -469,7 +475,7 @@ void Opm::readDeck(Opm::Parallel::Communication comm, try { if (parseSuccess) { eclStateBroadcast(comm, *eclipseState, *schedule, - *summaryConfig, *udqState, *actionState); + *summaryConfig, *udqState, *actionState, *wtestState); } } catch (const std::exception& broadcast_error) { diff --git a/opm/simulators/utils/readDeck.hpp b/opm/simulators/utils/readDeck.hpp index b8bad1a2a..4cf9786b9 100644 --- a/opm/simulators/utils/readDeck.hpp +++ b/opm/simulators/utils/readDeck.hpp @@ -37,6 +37,7 @@ namespace Opm { class Schedule; class SummaryConfig; class UDQState; + class WellTestState; } // end namespace Opm namespace Opm { @@ -76,6 +77,7 @@ void readDeck(Parallel::Communication comm, std::shared_ptr& schedule, std::unique_ptr& udqState, std::unique_ptr& actionState, + std::unique_ptr& wtestState, std::shared_ptr& summaryConfig, std::unique_ptr errorGuard, std::shared_ptr python, diff --git a/opm/simulators/wells/BlackoilWellModel.hpp b/opm/simulators/wells/BlackoilWellModel.hpp index e3ffd3322..c1dc044f1 100644 --- a/opm/simulators/wells/BlackoilWellModel.hpp +++ b/opm/simulators/wells/BlackoilWellModel.hpp @@ -220,6 +220,7 @@ namespace Opm { void initFromRestartFile(const RestartValue& restartValues) { initFromRestartFile(restartValues, + this->ebosSimulator_.vanguard().transferWTestState(), UgGridHelpers::numCells(grid()), param_.use_multisegment_well_); } diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.cpp b/opm/simulators/wells/BlackoilWellModelGeneric.cpp index 3f5a67d43..4a92073f9 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.cpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.cpp @@ -255,6 +255,7 @@ loadRestartData(const data::Wells& rst_wells, void BlackoilWellModelGeneric:: initFromRestartFile(const RestartValue& restartValues, + WellTestState wtestState, const size_t numCells, bool handle_ms_well) { @@ -277,6 +278,8 @@ initFromRestartFile(const RestartValue& restartValues, loadRestartData(restartValues.wells, restartValues.grp_nwrk, phase_usage_, handle_ms_well, this->wellState()); } + + this->active_wgstate_.well_test_state = std::move(wtestState); this->commitWGState(); initial_step_ = false; } diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.hpp b/opm/simulators/wells/BlackoilWellModelGeneric.hpp index c2c1cd9c5..a510defbb 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.hpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.hpp @@ -135,6 +135,7 @@ public: WellState& well_state); void initFromRestartFile(const RestartValue& restartValues, + WellTestState wtestState, const size_t numCells, bool handle_ms_well);