From c20417d69b456d0a616a49c162302b66c8ea2310 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Tue, 12 Jan 2021 13:30:06 +0100 Subject: [PATCH] Handle well test configuration with ScheduleState --- .../EclipseState/Schedule/Schedule.hpp | 3 -- .../EclipseState/Schedule/ScheduleState.hpp | 6 ++++ .../EclipseState/Schedule/KeywordHandlers.cpp | 9 +++--- .../EclipseState/Schedule/Schedule.cpp | 12 ++----- .../EclipseState/Schedule/ScheduleState.cpp | 32 ++++++++++++------- tests/parser/ScheduleTests.cpp | 8 ++--- 6 files changed, 38 insertions(+), 32 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp index fdd0a5c42..1afffd53d 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp @@ -236,7 +236,6 @@ namespace Opm Well::ProducerCMode getGlobalWhistctlMmode(std::size_t timestep) const; const UDQActive& udqActive(std::size_t timeStep) const; - const WellTestConfig& wtestConfig(std::size_t timestep) const; const GConSale& gConSale(std::size_t timestep) const; const GConSump& gConSump(std::size_t timestep) const; const WListManager& getWListManager(std::size_t timeStep) const; @@ -318,7 +317,6 @@ namespace Opm auto splitvfpinj = splitDynMap(vfpinj_tables); serializer.vector(splitvfpinj.first); serializer(splitvfpinj.second); - wtest_config.serializeOp(serializer); wlist_manager.serializeOp(serializer); udq_config.serializeOp(serializer); udq_active.serializeOp(serializer); @@ -353,7 +351,6 @@ namespace Opm VFPProdMap vfpprod_tables; VFPInjMap vfpinj_tables; MessageLimits m_deck_message_limits; - DynamicState> wtest_config; DynamicState> wlist_manager; DynamicState> udq_config; DynamicState> udq_active; diff --git a/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp b/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp index 16593d67c..29b0164ce 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp @@ -42,6 +42,7 @@ namespace Opm { is handled by the Schedule instance owning the ScheduleState instance. */ + class WellTestConfig; class ScheduleState { public: @@ -92,6 +93,9 @@ namespace Opm { Well::ProducerCMode whistctl() const; void whistctl(Well::ProducerCMode whistctl); + const WellTestConfig& wtest_config() const; + void wtest_config(WellTestConfig wtest_config); + template void serializeOp(Serializer& serializer) { serializer(m_start_time); @@ -105,6 +109,7 @@ namespace Opm { serializer.vector(m_geo_keywords); m_message_limits.serializeOp(serializer); serializer(m_whistctl_mode); + serializer(m_wtest_config); } private: @@ -120,6 +125,7 @@ namespace Opm { std::vector m_geo_keywords; MessageLimits m_message_limits; Well::ProducerCMode m_whistctl_mode = Well::ProducerCMode::CMODE_UNDEFINED; + std::shared_ptr m_wtest_config; }; } diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp index f7778bb47..e5ed939be 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp @@ -1772,8 +1772,7 @@ namespace { } void Schedule::handleWTEST(const HandlerContext& handlerContext, const ParseContext& parseContext, ErrorGuard& errors) { - const auto& current = *this->wtest_config.get(handlerContext.currentStep); - std::shared_ptr new_config(new WellTestConfig(current)); + auto new_config = this->snapshots.back().wtest_config(); for (const auto& record : handlerContext.keyword) { const std::string& wellNamePattern = record.getItem("WELL").getTrimmedString(0); const auto well_names = wellNames(wellNamePattern, handlerContext.currentStep); @@ -1787,12 +1786,12 @@ namespace { for (const auto& well_name : well_names) { if (reasons.empty()) - new_config->drop_well(well_name); + new_config.drop_well(well_name); else - new_config->add_well(well_name, reasons, test_interval, num_test, startup_time, handlerContext.currentStep); + new_config.add_well(well_name, reasons, test_interval, num_test, startup_time, handlerContext.currentStep); } } - this->wtest_config.update(handlerContext.currentStep, new_config); + this->snapshots.back().wtest_config( std::move(new_config) ); } void Schedule::handleWTRACER(const HandlerContext& handlerContext, const ParseContext& parseContext, ErrorGuard& errors) { diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp index 698bc6857..87464bb38 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp @@ -114,7 +114,6 @@ namespace { m_timeMap( deck , restart_info( rst )), m_runspec( runspec ), m_deck_message_limits( MessageLimits(deck) ), - wtest_config(this->m_timeMap, std::make_shared() ), wlist_manager( this->m_timeMap, std::make_shared()), udq_config(this->m_timeMap, std::make_shared(deck)), udq_active(this->m_timeMap, std::make_shared()), @@ -265,7 +264,6 @@ namespace { result.m_runspec = Runspec::serializeObject(); result.vfpprod_tables = {{1, {{std::make_shared(VFPProdTable::serializeObject())}, 1}}}; result.vfpinj_tables = {{2, {{std::make_shared(VFPInjTable::serializeObject())}, 1}}}; - result.wtest_config = {{std::make_shared(WellTestConfig::serializeObject())}, 1}; result.wlist_manager = {{std::make_shared(WListManager::serializeObject())}, 1}; result.udq_config = {{std::make_shared(UDQConfig::serializeObject())}, 1}; result.m_network = {{std::make_shared(Network::ExtNetwork::serializeObject())}, 1}; @@ -1461,11 +1459,6 @@ void Schedule::iterateScheduleSection(std::optional load_offset, this->udq_active.update(timeStep, udq); } - const WellTestConfig& Schedule::wtestConfig(std::size_t timeStep) const { - const auto& ptr = this->wtest_config.get(timeStep); - return *ptr; - } - const GConSale& Schedule::gConSale(std::size_t timeStep) const { const auto& ptr = this->gconsale.get(timeStep); return *ptr; @@ -1668,7 +1661,6 @@ void Schedule::iterateScheduleSection(std::optional load_offset, compareMap(this->vfpinj_tables, data.vfpinj_tables) && compareDynState(this->m_network, data.m_network) && compareDynState(this->m_glo, data.m_glo) && - compareDynState(this->wtest_config, data.wtest_config) && compareDynState(this->wlist_manager, data.wlist_manager) && compareDynState(this->udq_config, data.udq_config) && compareDynState(this->udq_active, data.udq_active) && @@ -1679,7 +1671,8 @@ void Schedule::iterateScheduleSection(std::optional load_offset, compareDynState(this->rpt_config, data.rpt_config) && rft_config == data.rft_config && this->restart_config == data.restart_config && - this->unit_system == data.unit_system; + this->unit_system == data.unit_system && + this->snapshots == data.snapshots; } @@ -2091,6 +2084,7 @@ void Schedule::create_first(const std::chrono::system_clock::time_point& start_t sched_state.nupcol( this->m_runspec.nupcol() ); sched_state.oilvap( OilVaporizationProperties( this->m_runspec.tabdims().getNumPVTTables() )); sched_state.message_limits( this->m_deck_message_limits ); + sched_state.wtest_config( WellTestConfig() ); this->addGroup("FIELD", 0); } diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.cpp index 8884c195c..d91071721 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.cpp @@ -18,6 +18,7 @@ */ #include +#include namespace Opm { @@ -138,17 +139,17 @@ void ScheduleState::whistctl(Well::ProducerCMode whistctl) { } bool ScheduleState::operator==(const ScheduleState& other) const { - return - this->m_start_time == other.m_start_time && - this->m_oilvap == other.m_oilvap && - this->m_tuning == other.m_tuning && - this->m_end_time == other.m_end_time && - this->m_events == other.m_events && - this->m_wellgroup_events == other.m_wellgroup_events && - this->m_geo_keywords == other.m_geo_keywords && - this->m_message_limits == other.m_message_limits && - this->m_whistctl_mode == other.m_whistctl_mode && - this->m_nupcol == other.m_nupcol; + return this->m_start_time == other.m_start_time && + this->m_oilvap == other.m_oilvap && + this->m_tuning == other.m_tuning && + this->m_end_time == other.m_end_time && + this->m_events == other.m_events && + this->m_wellgroup_events == other.m_wellgroup_events && + this->m_geo_keywords == other.m_geo_keywords && + this->m_message_limits == other.m_message_limits && + this->m_whistctl_mode == other.m_whistctl_mode && + *this->m_wtest_config == *other.m_wtest_config && + this->m_nupcol == other.m_nupcol; } ScheduleState ScheduleState::serializeObject() { @@ -160,6 +161,7 @@ ScheduleState ScheduleState::serializeObject() { ts.oilvap( Opm::OilVaporizationProperties::serializeObject() ); ts.m_message_limits = MessageLimits::serializeObject(); ts.m_whistctl_mode = Well::ProducerCMode::THP; + ts.m_wtest_config = std::make_shared( WellTestConfig::serializeObject() ); return ts; } @@ -199,4 +201,12 @@ const WellGroupEvents& ScheduleState::wellgroup_events() const { return this->m_wellgroup_events; } +const WellTestConfig& ScheduleState::wtest_config() const { + return *this->m_wtest_config; +} + +void ScheduleState::wtest_config(WellTestConfig wtest_config) { + this->m_wtest_config = std::make_shared( std::move(wtest_config) ); +} + } diff --git a/tests/parser/ScheduleTests.cpp b/tests/parser/ScheduleTests.cpp index be78c1b61..5f200140b 100644 --- a/tests/parser/ScheduleTests.cpp +++ b/tests/parser/ScheduleTests.cpp @@ -2894,12 +2894,12 @@ WCONINJH BOOST_CHECK_CLOSE( 0.0 * 1e5, pro1.THPH, 1e-5 ); { - const auto& wtest_config = schedule.wtestConfig(0); + const auto& wtest_config = schedule[0].wtest_config(); BOOST_CHECK_EQUAL(wtest_config.size(), 0U); } { - const auto& wtest_config = schedule.wtestConfig(1); + const auto& wtest_config = schedule[1].wtest_config(); BOOST_CHECK_EQUAL(wtest_config.size(), 0U); } } @@ -3197,12 +3197,12 @@ TSTEP BOOST_AUTO_TEST_CASE(WTEST_CONFIG) { const auto& schedule = make_schedule(createDeckWTEST()); - const auto& wtest_config1 = schedule.wtestConfig(0); + const auto& wtest_config1 = schedule[0].wtest_config(); BOOST_CHECK_EQUAL(wtest_config1.size(), 2U); BOOST_CHECK(wtest_config1.has("ALLOW")); BOOST_CHECK(!wtest_config1.has("BAN")); - const auto& wtest_config2 = schedule.wtestConfig(1); + const auto& wtest_config2 = schedule[1].wtest_config(); BOOST_CHECK_EQUAL(wtest_config2.size(), 3U); BOOST_CHECK(!wtest_config2.has("ALLOW")); BOOST_CHECK(wtest_config2.has("BAN"));