From 9b4b8ea68692411f340c7df058893b5ef51d19bb Mon Sep 17 00:00:00 2001 From: Lisa Julia Nebel Date: Tue, 2 Jul 2024 07:48:34 +0200 Subject: [PATCH 1/3] Rename actionx_mode to welpi_action_mode since this flag is only for the WELPI keyword and not only for ActionX but also for Pyaction --- opm/input/eclipse/Schedule/HandlerContext.hpp | 6 +++--- opm/input/eclipse/Schedule/Schedule.cpp | 6 +++--- opm/input/eclipse/Schedule/Schedule.hpp | 2 +- .../eclipse/Schedule/Well/WellPropertiesKeywordHandlers.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/opm/input/eclipse/Schedule/HandlerContext.hpp b/opm/input/eclipse/Schedule/HandlerContext.hpp index 5605c43a77f..e369b103503 100644 --- a/opm/input/eclipse/Schedule/HandlerContext.hpp +++ b/opm/input/eclipse/Schedule/HandlerContext.hpp @@ -55,7 +55,7 @@ class HandlerContext const ScheduleGrid& grid_, const std::size_t currentStep_, const std::vector& matching_wells_, - bool actionx_mode_, + bool welpi_action_mode_, const ParseContext& parseContext_, ErrorGuard& errors_, SimulatorUpdate* sim_update_, @@ -67,7 +67,7 @@ class HandlerContext , keyword(keyword_) , currentStep(currentStep_) , matching_wells(matching_wells_) - , actionx_mode(actionx_mode_) + , welpi_action_mode(welpi_action_mode_) , parseContext(parseContext_) , errors(errors_) , wpimult_global_factor(wpimult_global_factor_) @@ -157,7 +157,7 @@ class HandlerContext const DeckKeyword& keyword; const std::size_t currentStep; const std::vector& matching_wells; - const bool actionx_mode; + const bool welpi_action_mode; const ParseContext& parseContext; ErrorGuard& errors; std::unordered_map& wpimult_global_factor; diff --git a/opm/input/eclipse/Schedule/Schedule.cpp b/opm/input/eclipse/Schedule/Schedule.cpp index 416d6e1f542..a89acf50a56 100644 --- a/opm/input/eclipse/Schedule/Schedule.cpp +++ b/opm/input/eclipse/Schedule/Schedule.cpp @@ -294,7 +294,7 @@ Schedule::Schedule(const Deck& deck, const EclipseState& es, const std::optional ErrorGuard& errors, const ScheduleGrid& grid, const std::vector& matching_wells, - bool actionx_mode, + bool welpi_action_mode, SimulatorUpdate* sim_update, const std::unordered_map* target_wellpi, std::unordered_map& wpimult_global_factor, @@ -302,7 +302,7 @@ Schedule::Schedule(const Deck& deck, const EclipseState& es, const std::optional std::set* compsegs_wells) { HandlerContext handlerContext { *this, block, keyword, grid, currentStep, - matching_wells, actionx_mode, + matching_wells, welpi_action_mode, parseContext, errors, sim_update, target_wellpi, wpimult_global_factor, welsegs_wells, compsegs_wells}; @@ -1454,7 +1454,7 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen errors, grid, matching_wells, - /*actionx_mode=*/false, + /*welpi_action_mode=*/false, &sim_update, &target_wellpi, wpimult_global_factor); diff --git a/opm/input/eclipse/Schedule/Schedule.hpp b/opm/input/eclipse/Schedule/Schedule.hpp index b2497046c71..b9e02e03922 100644 --- a/opm/input/eclipse/Schedule/Schedule.hpp +++ b/opm/input/eclipse/Schedule/Schedule.hpp @@ -531,7 +531,7 @@ namespace Opm ErrorGuard& errors, const ScheduleGrid& grid, const std::vector& matching_wells, - bool actionx_mode, + bool welpi_action_mode, SimulatorUpdate* sim_update, const std::unordered_map* target_wellpi, std::unordered_map& wpimult_global_factor, diff --git a/opm/input/eclipse/Schedule/Well/WellPropertiesKeywordHandlers.cpp b/opm/input/eclipse/Schedule/Well/WellPropertiesKeywordHandlers.cpp index 4529a68b323..e7c8c176993 100644 --- a/opm/input/eclipse/Schedule/Well/WellPropertiesKeywordHandlers.cpp +++ b/opm/input/eclipse/Schedule/Well/WellPropertiesKeywordHandlers.cpp @@ -192,7 +192,7 @@ void handleWELPIRuntime(HandlerContext& handlerContext) void handleWELPI(HandlerContext& handlerContext) { - if (handlerContext.actionx_mode) { + if (handlerContext.welpi_action_mode) { handleWELPIRuntime(handlerContext); return; } From 76a681ae9dcbea2d5a1c04420bb799d81d938be8 Mon Sep 17 00:00:00 2001 From: Lisa Julia Nebel Date: Tue, 2 Jul 2024 08:35:09 +0200 Subject: [PATCH 2/3] Use the welpi_action_mode of the Schedule for handling the WELPI keyword from a Pyaction --- opm/input/eclipse/Schedule/Schedule.cpp | 13 +++++++++++-- opm/input/eclipse/Schedule/Schedule.hpp | 7 +++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/opm/input/eclipse/Schedule/Schedule.cpp b/opm/input/eclipse/Schedule/Schedule.cpp index a89acf50a56..91331572aaa 100644 --- a/opm/input/eclipse/Schedule/Schedule.cpp +++ b/opm/input/eclipse/Schedule/Schedule.cpp @@ -265,6 +265,7 @@ Schedule::Schedule(const Deck& deck, const EclipseState& es, const std::optional result.completed_cells = CompletedCells::serializationTestObject(); result.current_report_step = 0; result.simUpdateFromPython = std::make_shared(SimulatorUpdate::serializationTestObject()); + result.wellPIPointer = nullptr; return result; } @@ -1439,6 +1440,11 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen ScheduleGrid grid(this->completed_cells); SimulatorUpdate sim_update; std::unordered_map target_wellpi; + // Get the well production indices from the simulation up until now + // and use in the calculation for the overall production indices. + if (this->wellPIPointer) { + target_wellpi = *(this->wellPIPointer); + } std::vector matching_wells; const std::string prefix = "| "; /* logger prefix string */ this->snapshots.resize(reportStep + 1); @@ -1454,7 +1460,7 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen errors, grid, matching_wells, - /*welpi_action_mode=*/false, + this->welpi_action_mode, &sim_update, &target_wellpi, wpimult_global_factor); @@ -1640,6 +1646,8 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen SimulatorUpdate Schedule::runPyAction(std::size_t reportStep, const Action::PyAction& pyaction, Action::State& action_state, EclipseState& ecl_state, SummaryState& summary_state) { + // Set welpi_action_mode to true, this is necessary for the keyword WELPI + this->welpi_action_mode = true; // Reset simUpdateFromPython, pyaction.run(...) will run through the PyAction script, the calls that trigger a simulator update will append this to simUpdateFromPython. this->simUpdateFromPython->reset(); // Set the current_report_step to the report step in which this PyAction was triggered. @@ -1654,7 +1662,8 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen auto result = pyaction.run(ecl_state, *this, reportStep, summary_state, apply_action_callback); action_state.add_run(pyaction, result); - // The whole pyaction script was executed, now the simUpdateFromPython is returned. + // The whole pyaction script was executed, welpi_action_mode is set to false and the simUpdateFromPython is returned. + this->welpi_action_mode = false; return *(this->simUpdateFromPython); } diff --git a/opm/input/eclipse/Schedule/Schedule.hpp b/opm/input/eclipse/Schedule/Schedule.hpp index b9e02e03922..acd1910bbc2 100644 --- a/opm/input/eclipse/Schedule/Schedule.hpp +++ b/opm/input/eclipse/Schedule/Schedule.hpp @@ -290,6 +290,7 @@ namespace Opm serializer(this->completed_cells); serializer(this->m_treat_critical_as_non_critical); serializer(this->current_report_step); + serializer(this->welpi_action_mode); serializer(this->simUpdateFromPython); this->template pack_unpack(serializer); @@ -453,6 +454,9 @@ namespace Opm friend std::ostream& operator<<(std::ostream& os, const Schedule& sched); void dump_deck(std::ostream& os) const; + // The wellPIPointer is used when a PYACTION is executed. It is filled from the ActionHandler is + // over, it is set to false again. This is needed for handling the keyword WELPI from a PYACTION. + std::shared_ptr> wellPIPointer = nullptr; private: friend class HandlerContext; @@ -470,6 +474,9 @@ namespace Opm WriteRestartFileEvents restart_output{}; CompletedCells completed_cells{}; + // The action mode is set to true when a PYACTION call is executed, when the PYACTION execution is + // over, it is set to false again. This is needed for handling the keyword WELPI from a PYACTION. + bool welpi_action_mode = false; // The current_report_step is set to the current report step when a PYACTION call is executed. // This is needed since the Schedule object does not know the current report step of the simulator and // we only allow PYACTIONS for the current and future report steps. From 49c238654e89e759ad9091c64fa12b73f8a0cd28 Mon Sep 17 00:00:00 2001 From: Lisa Julia Nebel Date: Tue, 2 Jul 2024 14:41:46 +0200 Subject: [PATCH 3/3] Add WELPI to PyAction Keywords --- opm/input/eclipse/Schedule/Action/PyAction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opm/input/eclipse/Schedule/Action/PyAction.cpp b/opm/input/eclipse/Schedule/Action/PyAction.cpp index 2dd9bc0455c..5ee52e11013 100644 --- a/opm/input/eclipse/Schedule/Action/PyAction.cpp +++ b/opm/input/eclipse/Schedule/Action/PyAction.cpp @@ -46,7 +46,7 @@ bool PyAction::valid_keyword(const std::string& keyword) { "GCONINJE", "GCONPROD", "GCONSUMP","GRUPTREE", "METRIC", "MULTX", "MULTX-", "MULTY", "MULTY-", "MULTZ", "MULTZ-", "NEXT", "NEXTSTEP", - "WCONINJE", "WCONPROD", "WECON", "WEFAC", "WELOPEN", "WELTARG", "WGRUPCON", "WELSEGS", "WELSPECS", "WSEGVALV", "WTEST" + "WCONINJE", "WCONPROD", "WECON", "WEFAC", "WELOPEN", "WELPI", "WELTARG", "WGRUPCON", "WELSEGS", "WELSPECS", "WSEGVALV", "WTEST" }; return pyaction_allowed_list.find(keyword) != pyaction_allowed_list.end(); }