From 344972624a31462fffb603ecdbb432c90bdb6f84 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Fri, 15 Jan 2021 08:33:29 +0100 Subject: [PATCH] Use ScheduleState to manage UDQActive --- .../EclipseState/Schedule/Schedule.hpp | 5 ---- .../EclipseState/Schedule/ScheduleState.hpp | 6 +++++ src/opm/output/eclipse/AggregateUDQData.cpp | 2 +- src/opm/output/eclipse/CreateInteHead.cpp | 4 ++-- .../EclipseState/Schedule/KeywordHandlers.cpp | 24 +++++++++---------- .../EclipseState/Schedule/Schedule.cpp | 12 +--------- .../EclipseState/Schedule/ScheduleState.cpp | 10 ++++++++ tests/parser/UDQTests.cpp | 8 +++---- 8 files changed, 36 insertions(+), 35 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp index 780a591e6..b29345181 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp @@ -106,7 +106,6 @@ namespace Opm class TimeMap; class ErrorGuard; class UDQConfig; - class UDQActive; struct ScheduleStatic { @@ -276,7 +275,6 @@ namespace Opm std::vector getChildWells2(const std::string& group_name, std::size_t timeStep) const; Well::ProducerCMode getGlobalWhistctlMmode(std::size_t timestep) const; - const UDQActive& udqActive(std::size_t timeStep) const; const UDQConfig& getUDQConfig(std::size_t timeStep) const; std::vector udqConfigList() const; void evalAction(const SummaryState& summary_state, std::size_t timeStep); @@ -341,7 +339,6 @@ namespace Opm serializer.vector(splitGroups.first); serializer(splitGroups.second); udq_config.serializeOp(serializer); - udq_active.serializeOp(serializer); guide_rate_config.serializeOp(serializer); m_glo.serializeOp(serializer); rft_config.serializeOp(serializer); @@ -362,7 +359,6 @@ namespace Opm WellMap wells_static; GroupMap groups; DynamicState> udq_config; - DynamicState> udq_active; DynamicState> guide_rate_config; DynamicState> m_glo; RFTConfig rft_config; @@ -395,7 +391,6 @@ namespace Opm GTNode groupTree(const std::string& root_node, std::size_t report_step, std::size_t level, const std::optional& parent_name) const; void updateGroup(std::shared_ptr group, std::size_t reportStep); bool checkGroups(const ParseContext& parseContext, ErrorGuard& errors); - void updateUDQActive( std::size_t timeStep, std::shared_ptr udq ); bool updateWellStatus( const std::string& well, std::size_t reportStep, bool runtime, Well::Status status, std::optional = {}); void addWellToGroup( const std::string& group_name, const std::string& well_name , std::size_t timeStep); void iterateScheduleSection(std::size_t load_start, diff --git a/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp b/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp index eaaccf8d5..225efa1a6 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp @@ -40,6 +40,7 @@ #include #include #include +#include namespace Opm { @@ -130,6 +131,9 @@ namespace Opm { const Action::Actions& actions() const; void actions(Action::Actions actions); + const UDQActive& udq_active() const; + void udq_active(UDQActive udq_active); + template void serializeOp(Serializer& serializer) { serializer(m_start_time); @@ -152,6 +156,7 @@ namespace Opm { serializer.map(m_vfpprod); serializer.map(m_vfpinj); serializer(m_actions); + serializer(m_udq_active); } @@ -175,6 +180,7 @@ namespace Opm { std::shared_ptr m_network; std::shared_ptr m_rptconfig; std::shared_ptr m_actions; + std::shared_ptr m_udq_active; std::map> m_vfpprod; std::map> m_vfpinj; }; diff --git a/src/opm/output/eclipse/AggregateUDQData.cpp b/src/opm/output/eclipse/AggregateUDQData.cpp index b687de70b..ebb042147 100644 --- a/src/opm/output/eclipse/AggregateUDQData.cpp +++ b/src/opm/output/eclipse/AggregateUDQData.cpp @@ -811,7 +811,7 @@ captureDeclaredUDQData(const Opm::Schedule& sched, } - auto udq_active = sched.udqActive(simStep); + auto udq_active = sched[simStep].udq_active(); if (udq_active) { const auto& udq_records = udq_active.get_iuad(); int cnt_iuad = 0; diff --git a/src/opm/output/eclipse/CreateInteHead.cpp b/src/opm/output/eclipse/CreateInteHead.cpp index 56a9795c6..1efecd862 100755 --- a/src/opm/output/eclipse/CreateInteHead.cpp +++ b/src/opm/output/eclipse/CreateInteHead.cpp @@ -168,7 +168,7 @@ namespace { return 0; } - const auto& udqAct = sched.udqActive(simStep); + const auto& udqAct = sched[simStep].udq_active(); const auto& iuad = udqAct.get_iuad(); return std::count_if(iuad.begin(), iuad.end(), [](const Opm::UDQActive::Record rec) { @@ -184,7 +184,7 @@ namespace { return 0; } - const auto& udqAct = sched.udqActive(simStep); + const auto& udqAct = sched[simStep].udq_active(); const auto& iuap = udqAct.get_iuap(); return std::count_if(iuap.begin(), iuap.end(), [](const Opm::UDQActive::InputRecord rec) { diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp index 5c7370228..0813c1894 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp @@ -463,9 +463,9 @@ namespace { this->snapshots.back().events().addEvent(ScheduleEvents::GROUP_PRODUCTION_UPDATE); this->snapshots.back().wellgroup_events().addEvent( group_name, ScheduleEvents::GROUP_PRODUCTION_UPDATE); - auto udq = std::make_shared(this->udqActive(current_step)); - if (production.updateUDQActive(this->getUDQConfig(current_step), *udq)) - this->updateUDQActive(current_step, udq); + auto udq_active = UDQActive(this->snapshots.back().udq_active()); + if (production.updateUDQActive(this->getUDQConfig(current_step), udq_active)) + this->snapshots.back().udq_active( std::move(udq_active)); } } } @@ -966,9 +966,9 @@ namespace { this->updateWell(std::move(well2), handlerContext.currentStep); } - auto udq = std::make_shared(this->udqActive(handlerContext.currentStep)); - if (properties->updateUDQActive(this->getUDQConfig(handlerContext.currentStep), *udq)) - this->updateUDQActive(handlerContext.currentStep, udq); + auto udq_active = UDQActive( this->snapshots.back().udq_active() ); + if (properties->updateUDQActive(this->getUDQConfig(handlerContext.currentStep), udq_active)) + this->snapshots.back().udq_active( std::move(udq_active)); } } } @@ -1028,9 +1028,9 @@ namespace { } } - auto udq = std::make_shared(this->udqActive(handlerContext.currentStep)); - if (injection->updateUDQActive(this->getUDQConfig(handlerContext.currentStep), *udq)) - this->updateUDQActive(handlerContext.currentStep, udq); + auto udq_active = UDQActive(this->snapshots.back().udq_active()); + if (injection->updateUDQActive(this->getUDQConfig(handlerContext.currentStep), udq_active)) + this->snapshots.back().udq_active( std::move(udq_active) ); } } } @@ -1289,9 +1289,9 @@ namespace { if (cmode == Well::WELTARGCMode::GUID) update |= well2->updateWellGuideRate(new_arg.get()); - auto udq = std::make_shared(this->udqActive(handlerContext.currentStep)); - if (prop->updateUDQActive(this->getUDQConfig(handlerContext.currentStep), *udq)) - this->updateUDQActive(handlerContext.currentStep, udq); + auto udq_active = UDQActive(this->snapshots.back().udq_active()); + if (prop->updateUDQActive(this->getUDQConfig(handlerContext.currentStep), udq_active)) + this->snapshots.back().udq_active( std::move(udq_active)); } else { auto inj = std::make_shared(well2->getInjectionProperties()); inj->handleWELTARG(cmode, new_arg, SiFactorP); diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp index 90451675f..6fb1de6c7 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_sched_deck(deck, restart_info(rst) ), m_timeMap( deck , restart_info( rst )), udq_config(this->m_timeMap, std::make_shared(deck)), - udq_active(this->m_timeMap, std::make_shared()), guide_rate_config(this->m_timeMap, std::make_shared()), m_glo(this->m_timeMap, std::make_shared()), rft_config(this->m_timeMap), @@ -253,7 +252,6 @@ namespace { result.groups.insert({"test2", {{std::make_shared(Opm::Group::serializeObject())},1}}); result.udq_config = {{std::make_shared(UDQConfig::serializeObject())}, 1}; result.m_glo = {{std::make_shared(GasLiftOpt::serializeObject())}, 1}; - result.udq_active = {{std::make_shared(UDQActive::serializeObject())}, 1}; result.guide_rate_config = {{std::make_shared(GuideRateConfig::serializeObject())}, 1}; result.rft_config = RFTConfig::serializeObject(); result.restart_config = RestartConfig::serializeObject(); @@ -1307,14 +1305,6 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e } - const UDQActive& Schedule::udqActive(std::size_t timeStep) const { - return *this->udq_active[timeStep]; - } - - void Schedule::updateUDQActive( std::size_t timeStep, std::shared_ptr udq ) { - this->udq_active.update(timeStep, udq); - } - const UDQConfig& Schedule::getUDQConfig(std::size_t timeStep) const { const auto& ptr = this->udq_config.get(timeStep); return *ptr; @@ -1488,7 +1478,6 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e compareMap(this->groups, data.groups) && compareDynState(this->m_glo, data.m_glo) && compareDynState(this->udq_config, data.udq_config) && - compareDynState(this->udq_active, data.udq_active) && compareDynState(this->guide_rate_config, data.guide_rate_config) && rft_config == data.rft_config && this->restart_config == data.restart_config && @@ -1899,6 +1888,7 @@ void Schedule::create_first(const std::chrono::system_clock::time_point& start_t sched_state.network( Network::ExtNetwork() ); sched_state.rpt_config( RPTConfig() ); sched_state.actions( Action::Actions() ); + sched_state.udq_active( UDQActive() ); 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 459b401b3..6d0de1ca2 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.cpp @@ -182,6 +182,7 @@ bool ScheduleState::operator==(const ScheduleState& other) const { *this->m_gconsump == *other.m_gconsump && *this->m_wlist_manager == *other.m_wlist_manager && *this->m_rptconfig == *other.m_rptconfig && + *this->m_udq_active == *other.m_udq_active && this->m_nupcol == other.m_nupcol; } @@ -204,6 +205,7 @@ ScheduleState ScheduleState::serializeObject() { ts.m_vfpinj.emplace( std::make_pair(177, std::make_shared(VFPInjTable::serializeObject() ))); ts.m_vfpinj.emplace( std::make_pair(178, std::make_shared(VFPInjTable::serializeObject() ))); ts.m_actions = std::make_shared( Action::Actions::serializeObject() ); + ts.m_udq_active = std::make_shared( UDQActive::serializeObject() ); return ts; } @@ -345,4 +347,12 @@ void ScheduleState::actions(Action::Actions actions) { this->m_actions = std::make_shared( std::move(actions) ); } +const UDQActive& ScheduleState::udq_active() const { + return *this->m_udq_active; +} + +void ScheduleState::udq_active(UDQActive udq_active) { + this->m_udq_active = std::make_shared( std::move(udq_active) ); +} + } diff --git a/tests/parser/UDQTests.cpp b/tests/parser/UDQTests.cpp index f7b0cbc31..b42508b31 100644 --- a/tests/parser/UDQTests.cpp +++ b/tests/parser/UDQTests.cpp @@ -1515,7 +1515,7 @@ BOOST_AUTO_TEST_CASE(IntegrationTest) { #include "data/integration_tests/udq.data" auto schedule = make_schedule(deck_string); { - const auto& active = schedule.udqActive(1); + const auto& active = schedule[1].udq_active(); BOOST_CHECK_EQUAL(active.IUAD_size(), 6U); BOOST_CHECK(active[0].control == UDAControl::WCONPROD_ORAT); @@ -1595,7 +1595,7 @@ WCONPROD // First timestep { - const auto& udq_active = schedule.udqActive(0); + const auto& udq_active = schedule[0].udq_active(); BOOST_CHECK(udq_active); BOOST_CHECK_EQUAL(udq_active.IUAD_size(), 2U); @@ -1616,7 +1616,7 @@ WCONPROD // Second timestep // - The WUOPRU and WULPRU udq are still used in the same manner for the PROD1 well. // - The new UDQs WUXO and WUXL are now used for the PROD2 well. - const auto& udq_active = schedule.udqActive(1); + const auto& udq_active = schedule[1].udq_active(); BOOST_CHECK(udq_active); BOOST_CHECK_EQUAL(udq_active.IUAD_size(), 4U); @@ -1649,7 +1649,7 @@ WCONPROD // Third timestep // - The new UDQs WUXO and WUXL are now used for the PROD2 well. // - The PROD1 well does not use UDQ - const auto& udq_active = schedule.udqActive(2); + const auto& udq_active = schedule[2].udq_active(); BOOST_CHECK(udq_active); BOOST_CHECK_EQUAL(udq_active.IUAD_size(), 2U);