diff --git a/msim/src/msim.cpp b/msim/src/msim.cpp index 30d599b7b..c2f2a78a7 100644 --- a/msim/src/msim.cpp +++ b/msim/src/msim.cpp @@ -75,7 +75,7 @@ UDAValue msim::uda_val() { void msim::post_step(Schedule& schedule, Action::State& action_state, SummaryState& st, data::Solution& /* sol */, data::Wells& /* well_data */, data::GroupAndNetworkValues& /* grp_nwrk_data */, size_t report_step) { - const auto& actions = schedule.actions(report_step); + const auto& actions = schedule[report_step].actions(); if (actions.empty()) return; diff --git a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp index 2eebc3dd7..780a591e6 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp @@ -43,7 +43,6 @@ #include #include #include -#include #include #include #include @@ -95,7 +94,6 @@ namespace Opm { - class Actions; class Deck; class DeckKeyword; class DeckRecord; @@ -281,7 +279,6 @@ namespace Opm const UDQActive& udqActive(std::size_t timeStep) const; const UDQConfig& getUDQConfig(std::size_t timeStep) const; std::vector udqConfigList() const; - const Action::Actions& actions(std::size_t timeStep) const; void evalAction(const SummaryState& summary_state, std::size_t timeStep); GTNode groupTree(std::size_t report_step) const; @@ -315,6 +312,7 @@ namespace Opm std::shared_ptr python() const; + const ScheduleState& back() const; const ScheduleState& operator[](std::size_t index) const; std::vector::const_iterator begin() const; std::vector::const_iterator end() const; @@ -345,7 +343,6 @@ namespace Opm udq_config.serializeOp(serializer); udq_active.serializeOp(serializer); guide_rate_config.serializeOp(serializer); - m_actions.serializeOp(serializer); m_glo.serializeOp(serializer); rft_config.serializeOp(serializer); restart_config.serializeOp(serializer); @@ -367,7 +364,6 @@ namespace Opm DynamicState> udq_config; DynamicState> udq_active; DynamicState> guide_rate_config; - DynamicState> m_actions; DynamicState> m_glo; RFTConfig rft_config; RestartConfig restart_config; @@ -408,7 +404,7 @@ namespace Opm ErrorGuard& errors, const EclipseGrid& grid, const FieldPropsManager& fp); - void addACTIONX(const Action::ActionX& action, std::size_t currentStep); + void addACTIONX(const Action::ActionX& action); void addGroupToGroup( const std::string& parent_group, const std::string& child_group, std::size_t timeStep); void addGroupToGroup( const std::string& parent_group, const Group& child_group, std::size_t timeStep); void addGroup(const std::string& groupName , std::size_t timeStep); @@ -496,7 +492,7 @@ namespace Opm bool handleNormalKeyword(const HandlerContext& handlerContext, const ParseContext& parseContext, ErrorGuard& errors); // Keyword Handlers - void handlePYACTION(const DeckKeyword&, std::size_t currentStep); + void handlePYACTION(const DeckKeyword&); void handleGCONPROD(const DeckKeyword& keyword, std::size_t current_step, const ParseContext& parseContext, ErrorGuard& errors); void handleGCONINJE(const DeckKeyword& keyword, std::size_t current_step, const ParseContext& parseContext, ErrorGuard& errors); void handleGLIFTOPT(const DeckKeyword& keyword, std::size_t report_step, const ParseContext& parseContext, ErrorGuard& errors); diff --git a/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp b/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp index aa74d4397..eaaccf8d5 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp @@ -39,6 +39,7 @@ #include #include #include +#include namespace Opm { @@ -126,6 +127,9 @@ namespace Opm { const VFPInjTable& vfpinj(int table_id) const; void vfpinj(VFPInjTable vfpinj); + const Action::Actions& actions() const; + void actions(Action::Actions actions); + template void serializeOp(Serializer& serializer) { serializer(m_start_time); @@ -147,6 +151,7 @@ namespace Opm { serializer(m_rptconfig); serializer.map(m_vfpprod); serializer.map(m_vfpinj); + serializer(m_actions); } @@ -169,6 +174,7 @@ namespace Opm { std::shared_ptr m_wlist_manager; std::shared_ptr m_network; std::shared_ptr m_rptconfig; + std::shared_ptr m_actions; std::map> m_vfpprod; std::map> m_vfpinj; }; diff --git a/src/opm/output/eclipse/AggregateActionxData.cpp b/src/opm/output/eclipse/AggregateActionxData.cpp index 95e7bea09..0e31e1fc1 100644 --- a/src/opm/output/eclipse/AggregateActionxData.cpp +++ b/src/opm/output/eclipse/AggregateActionxData.cpp @@ -687,7 +687,7 @@ captureDeclaredActionxData( const Opm::Schedule& sched, const std::vector& actDims, const std::size_t simStep) { - const auto& acts = sched.actions(simStep); + const auto& acts = sched[simStep].actions(); std::size_t act_ind = 0; for (auto actx_it = acts.begin(); actx_it < acts.end(); actx_it++) { { diff --git a/src/opm/output/eclipse/AggregateWellData.cpp b/src/opm/output/eclipse/AggregateWellData.cpp index ce002a078..b56e83305 100644 --- a/src/opm/output/eclipse/AggregateWellData.cpp +++ b/src/opm/output/eclipse/AggregateWellData.cpp @@ -926,7 +926,7 @@ namespace { std::vector> act_res_stat(const Opm::Schedule& sched, const Opm::Action::State& action_state, const Opm::SummaryState& smry, const std::size_t sim_step) { std::vector> results; - const auto& acts = sched.actions(sim_step); + const auto& acts = sched[sim_step].actions(); Opm::Action::Context context(smry, sched[sim_step].wlist_manager()); auto sim_time = sched.simTime(sim_step); for (const auto& action : acts.pending(action_state, sim_time)) { diff --git a/src/opm/output/eclipse/CreateActionxDims.cpp b/src/opm/output/eclipse/CreateActionxDims.cpp index 7a61ad8d2..f0ec5b096 100755 --- a/src/opm/output/eclipse/CreateActionxDims.cpp +++ b/src/opm/output/eclipse/CreateActionxDims.cpp @@ -121,7 +121,7 @@ createActionxDims( const Runspec& rspec, const Schedule& sched, const std::size_t simStep) { - const auto& acts = sched.actions(simStep); + const auto& acts = sched[simStep].actions(); std::vector actDims(9); //No of Actionx keywords diff --git a/src/opm/output/eclipse/CreateInteHead.cpp b/src/opm/output/eclipse/CreateInteHead.cpp index a90135cb6..56a9795c6 100755 --- a/src/opm/output/eclipse/CreateInteHead.cpp +++ b/src/opm/output/eclipse/CreateInteHead.cpp @@ -477,7 +477,7 @@ createInteHead(const EclipseState& es, const auto ngmax = (report_step == 0) ? 0 : numGroupsInField(sched, lookup_step); - const auto& acts = sched.actions(lookup_step); + const auto& acts = sched[lookup_step].actions(); const auto& rspec = es.runspec(); const auto& tdim = es.getTableManager(); const auto& rdim = tdim.getRegdims(); diff --git a/src/opm/output/eclipse/Summary.cpp b/src/opm/output/eclipse/Summary.cpp index 3058b28ee..70e00be34 100644 --- a/src/opm/output/eclipse/Summary.cpp +++ b/src/opm/output/eclipse/Summary.cpp @@ -3209,7 +3209,7 @@ void Opm::out::Summary::SummaryImplementation::configureUDQ(const SummaryConfig& for (const auto& udq_ptr : sched.udqConfigList()) udq_ptr->required_summary(summary_keys); - for (const auto& action : sched.actions(sched.size() - 1)) + for (const auto& action : sched.back().actions()) action.required_summary(summary_keys); for (const auto& key : summary_keys) { diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp index 435598037..90451675f 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp @@ -116,7 +116,6 @@ namespace { 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_actions(this->m_timeMap, std::make_shared()), m_glo(this->m_timeMap, std::make_shared()), rft_config(this->m_timeMap), restart_config(m_timeMap, deck, parseContext, errors) @@ -256,7 +255,6 @@ namespace { 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.m_actions = {{std::make_shared(Action::Actions::serializeObject())}, 1}; result.rft_config = RFTConfig::serializeObject(); result.restart_config = RestartConfig::serializeObject(); result.snapshots = { ScheduleState::serializeObject() }; @@ -312,7 +310,7 @@ namespace { rftProperties.push_back( std::make_pair( &keyword , currentStep )); else if (keyword.name() == "PYACTION") - handlePYACTION(keyword, currentStep); + handlePYACTION(keyword); } namespace { @@ -466,7 +464,7 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e parseContext.handleError( ParseContext::ACTIONX_ILLEGAL_KEYWORD, msg_fmt, action_keyword.location(), errors); } } - this->addACTIONX(action, report_step); + this->addACTIONX(action); keyword_index++; continue; } @@ -498,13 +496,13 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e } } - void Schedule::addACTIONX(const Action::ActionX& action, std::size_t currentStep) { - auto new_actions = std::make_shared( this->actions(currentStep) ); - new_actions->add(action); - this->m_actions.update(currentStep, new_actions); + void Schedule::addACTIONX(const Action::ActionX& action) { + auto new_actions = Action::Actions( this->snapshots.back().actions() ); + new_actions.add( action ); + this->snapshots.back().actions( std::move(new_actions) ); } - void Schedule::handlePYACTION(const DeckKeyword& keyword, std::size_t currentStep) { + void Schedule::handlePYACTION(const DeckKeyword& keyword) { if (!this->m_static.m_python_handle->enabled()) { //Must have a real Python instance here - to ensure that IMPORT works const auto& loc = keyword.location(); @@ -522,9 +520,9 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e module = this->m_static.m_input_path + "/" + module_arg; Action::PyAction pyaction(this->m_static.m_python_handle, name, run_count, module); - auto new_actions = std::make_shared( this->actions(currentStep) ); - new_actions->add(pyaction); - this->m_actions.update(currentStep, new_actions); + auto new_actions = Action::Actions( this->snapshots.back().actions() ); + new_actions.add(pyaction); + this->snapshots.back().actions( std::move(new_actions) ); } void Schedule::applyEXIT(const DeckKeyword& keyword, std::size_t report_step) { @@ -1356,11 +1354,6 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e } - const Action::Actions& Schedule::actions(std::size_t timeStep) const { - const auto& ptr = this->m_actions.get(timeStep); - return *ptr; - } - void Schedule::applyAction(std::size_t reportStep, const Action::ActionX& action, const Action::Result& result) { ParseContext parseContext; ErrorGuard errors; @@ -1497,7 +1490,6 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e compareDynState(this->udq_config, data.udq_config) && compareDynState(this->udq_active, data.udq_active) && compareDynState(this->guide_rate_config, data.guide_rate_config) && - compareDynState(this->m_actions, data.m_actions) && rft_config == data.rft_config && this->restart_config == data.restart_config && this->snapshots == data.snapshots; @@ -1874,6 +1866,10 @@ bool Schedule::cmp(const Schedule& sched1, const Schedule& sched2, std::size_t r return (count == 0); } +const ScheduleState& Schedule::back() const { + return this->snapshots.back(); +} + const ScheduleState& Schedule::operator[](std::size_t index) const { return this->snapshots.at(index); } @@ -1902,7 +1898,7 @@ void Schedule::create_first(const std::chrono::system_clock::time_point& start_t sched_state.wlist_manager( WListManager() ); sched_state.network( Network::ExtNetwork() ); sched_state.rpt_config( RPTConfig() ); - + sched_state.actions( Action::Actions() ); 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 465b1a9eb..459b401b3 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.cpp @@ -159,7 +159,6 @@ bool ScheduleState::operator==(const ScheduleState& other) const { ++it2; } - return true; }; @@ -204,7 +203,7 @@ ScheduleState ScheduleState::serializeObject() { ts.m_vfpprod.emplace( std::make_pair(78, std::make_shared(VFPProdTable::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() ); return ts; } @@ -337,4 +336,13 @@ void ScheduleState::vfpinj(VFPInjTable vfpinj) { int table_id = vfpinj.getTableNum(); this->m_vfpinj[table_id] = std::make_shared( std::move(vfpinj) ); } + +const Action::Actions& ScheduleState::actions() const { + return *this->m_actions; +} + +void ScheduleState::actions(Action::Actions actions) { + this->m_actions = std::make_shared( std::move(actions) ); +} + } diff --git a/tests/parser/ACTIONX.cpp b/tests/parser/ACTIONX.cpp index 30afa353d..b706b0ba7 100644 --- a/tests/parser/ACTIONX.cpp +++ b/tests/parser/ACTIONX.cpp @@ -764,10 +764,10 @@ TSTEP Runspec runspec (deck); Schedule sched(deck, grid1, fp, runspec, python); - const auto& actions0 = sched.actions(0); + const auto& actions0 = sched[0].actions(); BOOST_CHECK_EQUAL(actions0.size(), 0U); - const auto& actions1 = sched.actions(1); + const auto& actions1 = sched[1].actions(); BOOST_CHECK_EQUAL(actions1.size(), 1U); @@ -804,7 +804,7 @@ TSTEP /*****************************************************************/ - const auto& actions2 = sched.actions(2); + const auto& actions2 = sched[2].actions(); BOOST_CHECK_EQUAL(actions2.size(), 2U); const auto& actB = actions2.get("B"); @@ -920,8 +920,8 @@ ENDACTIO Runspec runspec (deck); Schedule sched(deck, grid1, fp, runspec, python); - const auto& action1 = sched.actions(1).get("A"); - const auto& action2 = sched.actions(2).get("A"); + const auto& action1 = sched[1].actions().get("A"); + const auto& action2 = sched[2].actions().get("A"); BOOST_CHECK(action1.id() != action2.id()); @@ -976,7 +976,7 @@ TSTEP auto unit_system = UnitSystem::newMETRIC(); const auto st = SummaryState{ std::chrono::system_clock::now() }; Schedule sched = make_schedule(deck_string); - const auto& action1 = sched.actions(0).get("A"); + const auto& action1 = sched[0].actions().get("A"); { const auto& group = sched.getGroup("G1", 0); const auto& prod = group.productionControls(st); @@ -1040,7 +1040,7 @@ TSTEP Opm::UnitSystem unitSystem = UnitSystem( UnitSystem::UnitType::UNIT_TYPE_METRIC ); auto sched = make_schedule(input); - const auto& action1 = sched.actions(0).get("A"); + const auto& action1 = sched[0].actions().get("A"); { const auto& glo = sched.glo(0); BOOST_CHECK(!glo.has_group("PLAT-A")); @@ -1096,7 +1096,7 @@ TSTEP const auto st = SummaryState{ std::chrono::system_clock::now() }; Schedule sched = make_schedule(deck_string); - const auto& action1 = sched.actions(0).get("A"); + const auto& action1 = sched[0].actions().get("A"); { const auto& well = sched.getWell("PROD1", 0); BOOST_CHECK_EQUAL( well.getWellPIScalingFactor(1.0), 1.0); @@ -1138,7 +1138,7 @@ ENDACTIO Opm::WListManager wlm; Opm::Action::Context context(st, wlm); - const auto& config = sched.actions(0); + const auto& config = sched[0].actions(); const Opm::Action::ActionX& action = config.get("ACT1"); /*