From e235bb5e937a55bba32446933f32972e4013a300 Mon Sep 17 00:00:00 2001 From: Lisa Julia Nebel Date: Tue, 2 Jul 2024 14:41:46 +0200 Subject: [PATCH 1/9] 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(); } From f3c514701b23b60b20c014344bf718df369febba Mon Sep 17 00:00:00 2001 From: Lisa Julia Nebel Date: Wed, 3 Jul 2024 08:55:50 +0200 Subject: [PATCH 2/9] Activate WPIMULT for Pyaction --- 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 5ee52e11013..d77bc948a8e 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", "WELPI", "WELTARG", "WGRUPCON", "WELSEGS", "WELSPECS", "WSEGVALV", "WTEST" + "WCONINJE", "WCONPROD", "WECON", "WEFAC", "WELOPEN", "WELPI", "WELTARG", "WGRUPCON", "WELSEGS", "WELSPECS", "WSEGVALV", "WPIMULT", "WTEST" }; return pyaction_allowed_list.find(keyword) != pyaction_allowed_list.end(); } From c861b8e9c8d9229bd8bea7d2eaf476f696a3e315 Mon Sep 17 00:00:00 2001 From: Lisa Julia Nebel Date: Tue, 2 Jul 2024 07:48:34 +0200 Subject: [PATCH 3/9] 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 | 8 ++++---- opm/input/eclipse/Schedule/Schedule.hpp | 2 +- opm/input/eclipse/Schedule/UDQ/UDQKeywordHandlers.cpp | 2 +- .../Schedule/Well/WellPropertiesKeywordHandlers.cpp | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/opm/input/eclipse/Schedule/HandlerContext.hpp b/opm/input/eclipse/Schedule/HandlerContext.hpp index 09725042a63..d71d257f1c1 100644 --- a/opm/input/eclipse/Schedule/HandlerContext.hpp +++ b/opm/input/eclipse/Schedule/HandlerContext.hpp @@ -61,7 +61,7 @@ class HandlerContext const ScheduleGrid& grid_, const std::size_t currentStep_, const Action::Result::MatchingEntities& matches_, - bool actionx_mode_, + bool welpi_action_mode_, const ParseContext& parseContext_, ErrorGuard& errors_, SimulatorUpdate* sim_update_, @@ -73,7 +73,7 @@ class HandlerContext , keyword(keyword_) , currentStep(currentStep_) , matches(matches_) - , actionx_mode(actionx_mode_) + , welpi_action_mode(welpi_action_mode_) , parseContext(parseContext_) , errors(errors_) , wpimult_global_factor(wpimult_global_factor_) @@ -166,7 +166,7 @@ class HandlerContext const DeckKeyword& keyword; const std::size_t currentStep; const Action::Result::MatchingEntities& matches; - 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 e2b98433469..e05cee7bcbc 100644 --- a/opm/input/eclipse/Schedule/Schedule.cpp +++ b/opm/input/eclipse/Schedule/Schedule.cpp @@ -393,7 +393,7 @@ namespace Opm { ErrorGuard& errors, const ScheduleGrid& grid, const Action::Result::MatchingEntities& matches, - const bool actionx_mode, + const bool welpi_action_mode, SimulatorUpdate* sim_update, const std::unordered_map* target_wellpi, std::unordered_map& wpimult_global_factor, @@ -401,7 +401,7 @@ namespace Opm { std::set* compsegs_wells) { HandlerContext handlerContext { *this, block, keyword, grid, currentStep, - matches, actionx_mode, + matches, welpi_action_mode, parseContext, errors, sim_update, target_wellpi, wpimult_global_factor, welsegs_wells, compsegs_wells}; @@ -1664,7 +1664,7 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen auto& input_block = this->m_sched_deck[reportStep]; ScheduleLogger logger(ScheduleLogger::select_stream(false, false), // will log to OpmLog::info prefix, this->m_sched_deck.location()); - + for (const auto& keyword : keywords) { const auto valid = Action::PyAction::valid_keyword(keyword->name()); @@ -1685,7 +1685,7 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen errors, grid, matches, - /* 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 e4f74271606..878292e20ec 100644 --- a/opm/input/eclipse/Schedule/Schedule.hpp +++ b/opm/input/eclipse/Schedule/Schedule.hpp @@ -474,7 +474,7 @@ namespace Opm { ErrorGuard& errors, const ScheduleGrid& grid, const Action::Result::MatchingEntities& matches, - 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/UDQ/UDQKeywordHandlers.cpp b/opm/input/eclipse/Schedule/UDQ/UDQKeywordHandlers.cpp index 911e84e5ed1..b74051e058b 100644 --- a/opm/input/eclipse/Schedule/UDQ/UDQKeywordHandlers.cpp +++ b/opm/input/eclipse/Schedule/UDQ/UDQKeywordHandlers.cpp @@ -42,7 +42,7 @@ namespace { { auto dynSelector = std::optional{}; - if (handlerContext.actionx_mode) { + if (handlerContext.welpi_action_mode) { dynSelector = Opm::UDQConfig::DynamicSelector{}; if (const auto dynWells = handlerContext.matches.wells(); diff --git a/opm/input/eclipse/Schedule/Well/WellPropertiesKeywordHandlers.cpp b/opm/input/eclipse/Schedule/Well/WellPropertiesKeywordHandlers.cpp index 450e38db4fe..151ae8c5462 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 491e6c78ced9e7d94a63c545a42e598ae7b23e09 Mon Sep 17 00:00:00 2001 From: Lisa Julia Nebel Date: Tue, 9 Jul 2024 13:21:41 +0200 Subject: [PATCH 4/9] Add welpi_action_mode as an attribute to the Schedule Object --- opm/input/eclipse/Schedule/Schedule.cpp | 2 ++ opm/input/eclipse/Schedule/Schedule.hpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/opm/input/eclipse/Schedule/Schedule.cpp b/opm/input/eclipse/Schedule/Schedule.cpp index e05cee7bcbc..ec5ac3c0085 100644 --- a/opm/input/eclipse/Schedule/Schedule.cpp +++ b/opm/input/eclipse/Schedule/Schedule.cpp @@ -363,6 +363,7 @@ namespace Opm { result.completed_cells = CompletedCells::serializationTestObject(); result.current_report_step = 0; result.m_lowActionParsingStrictness = false; + result.welpi_action_mode = false; result.simUpdateFromPython = std::make_shared(SimulatorUpdate::serializationTestObject()); return result; @@ -2102,6 +2103,7 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen && this->completed_cells == data.completed_cells && this->current_report_step == data.current_report_step && this->m_lowActionParsingStrictness == data.m_lowActionParsingStrictness + && this->welpi_action_mode == data.welpi_action_mode && simUpdateFromPythonIsEqual ; } diff --git a/opm/input/eclipse/Schedule/Schedule.hpp b/opm/input/eclipse/Schedule/Schedule.hpp index 878292e20ec..670e5247340 100644 --- a/opm/input/eclipse/Schedule/Schedule.hpp +++ b/opm/input/eclipse/Schedule/Schedule.hpp @@ -350,6 +350,7 @@ namespace Opm { serializer(this->m_treat_critical_as_non_critical); serializer(this->current_report_step); serializer(this->m_lowActionParsingStrictness); + serializer(this->welpi_action_mode); serializer(this->simUpdateFromPython); // If we are deserializing we need to setup the pointer to the @@ -412,6 +413,9 @@ namespace Opm { // end up on the same partition. std::unordered_map> possibleFutureConnections; + // 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 e95b3e2e6010aca151f8891838d4431545e5fed9 Mon Sep 17 00:00:00 2001 From: Lisa Julia Nebel Date: Tue, 9 Jul 2024 13:25:36 +0200 Subject: [PATCH 5/9] Use the welpi_action_mode of the Schedule Object in runPyAction This indicates that the 'handleWELPIRuntime' instead of 'handleWELPI' function should be used when inserting the keyword WELPI from a PyAction --- opm/input/eclipse/Schedule/Schedule.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/opm/input/eclipse/Schedule/Schedule.cpp b/opm/input/eclipse/Schedule/Schedule.cpp index ec5ac3c0085..92de5baa2f1 100644 --- a/opm/input/eclipse/Schedule/Schedule.cpp +++ b/opm/input/eclipse/Schedule/Schedule.cpp @@ -1686,7 +1686,7 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen errors, grid, matches, - /*welpi_action_mode=*/false, + this->welpi_action_mode, &sim_update, &target_wellpi, wpimult_global_factor); @@ -1983,6 +1983,9 @@ 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 keyword is handled differently when it's called during a running simulation (see functions handleWELPI and handleWELPIRuntime). + 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. @@ -1997,7 +2000,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 was executed, welpi_action_mode is set to false and the simUpdateFromPython is returned. + this->welpi_action_mode = false; return *(this->simUpdateFromPython); } From f3d1c1088e58b71470a72fa1870d2b2d200a2146 Mon Sep 17 00:00:00 2001 From: Lisa Julia Nebel Date: Tue, 9 Jul 2024 13:28:34 +0200 Subject: [PATCH 6/9] Remove the argument welpi_action_mode from the Schedule::handleKeyword function This is not needed anymore, since welpi_action_mode is an attribute of the Schedule. --- opm/input/eclipse/Schedule/Schedule.cpp | 12 +++++++----- opm/input/eclipse/Schedule/Schedule.hpp | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/opm/input/eclipse/Schedule/Schedule.cpp b/opm/input/eclipse/Schedule/Schedule.cpp index 92de5baa2f1..b71fbb2256c 100644 --- a/opm/input/eclipse/Schedule/Schedule.cpp +++ b/opm/input/eclipse/Schedule/Schedule.cpp @@ -394,7 +394,6 @@ namespace Opm { ErrorGuard& errors, const ScheduleGrid& grid, const Action::Result::MatchingEntities& matches, - const bool welpi_action_mode, SimulatorUpdate* sim_update, const std::unordered_map* target_wellpi, std::unordered_map& wpimult_global_factor, @@ -402,7 +401,7 @@ namespace Opm { std::set* compsegs_wells) { HandlerContext handlerContext { *this, block, keyword, grid, currentStep, - matches, welpi_action_mode, + matches, this->welpi_action_mode, parseContext, errors, sim_update, target_wellpi, wpimult_global_factor, welsegs_wells, compsegs_wells}; @@ -718,7 +717,6 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e errors, grid, matches, - /* actionx_mode = */ false, /* sim_update = */ nullptr, target_wellpi, wpimult_global_factor, @@ -1686,7 +1684,6 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen errors, grid, matches, - this->welpi_action_mode, &sim_update, &target_wellpi, wpimult_global_factor); @@ -1759,6 +1756,10 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen auto& input_block = this->m_sched_deck[reportStep]; std::unordered_map wpimult_global_factor; + + // Set welpi_action_mode to true, this is necessary for the keyword WELPI. + // This keyword is handled differently when it's called during a running simulation (see functions handleWELPI and handleWELPIRuntime). + this->welpi_action_mode = true; for (const auto& keyword : action) { input_block.push_back(keyword); @@ -1773,11 +1774,12 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen errors, grid, matches, - /* actionx_mode = */ true, &sim_update, &target_wellpi, wpimult_global_factor); } + // The whole ACTIONX was executed, welpi_action_mode is set to false. + this->welpi_action_mode = false; this->applyGlobalWPIMULT(wpimult_global_factor); diff --git a/opm/input/eclipse/Schedule/Schedule.hpp b/opm/input/eclipse/Schedule/Schedule.hpp index 670e5247340..dd989f67f9b 100644 --- a/opm/input/eclipse/Schedule/Schedule.hpp +++ b/opm/input/eclipse/Schedule/Schedule.hpp @@ -478,7 +478,6 @@ namespace Opm { ErrorGuard& errors, const ScheduleGrid& grid, const Action::Result::MatchingEntities& matches, - bool welpi_action_mode, SimulatorUpdate* sim_update, const std::unordered_map* target_wellpi, std::unordered_map& wpimult_global_factor, From a631ed1a044b0b0d6c19a2cfc64c4db1705d58ba Mon Sep 17 00:00:00 2001 From: Lisa Julia Nebel Date: Tue, 17 Dec 2024 18:16:57 +0100 Subject: [PATCH 7/9] Add setWellPI Map function to Schedule This is set in the ActionHandler. Use the wellPIMap when calling handleKeyword in the applyKeywords function. --- opm/input/eclipse/Schedule/Schedule.cpp | 16 ++++++++++++++-- opm/input/eclipse/Schedule/Schedule.hpp | 8 ++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/opm/input/eclipse/Schedule/Schedule.cpp b/opm/input/eclipse/Schedule/Schedule.cpp index b71fbb2256c..8d05a234af5 100644 --- a/opm/input/eclipse/Schedule/Schedule.cpp +++ b/opm/input/eclipse/Schedule/Schedule.cpp @@ -355,6 +355,7 @@ namespace Opm { result.m_treat_critical_as_non_critical = false; result.m_static = ScheduleStatic::serializationTestObject(); result.m_sched_deck = ScheduleDeck::serializationTestObject(); + result.m_wellPIMap = {{"WELL1", 1000}, {"WELL2", 2000}}; result.action_wgnames = Action::WGNames::serializationTestObject(); result.potential_wellopen_patterns = std::unordered_set {"W1"}; result.exit_status = EXIT_FAILURE; @@ -1653,7 +1654,6 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen ErrorGuard errors; ScheduleGrid grid(this->completed_cells); SimulatorUpdate sim_update; - std::unordered_map target_wellpi; std::unordered_map wpimult_global_factor; const auto matches = Action::Result{false}.matches(); const std::string prefix = "| "; // logger prefix string @@ -1685,7 +1685,7 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen grid, matches, &sim_update, - &target_wellpi, + &(this->m_wellPIMap), wpimult_global_factor); } else { @@ -2007,6 +2007,17 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen return *(this->simUpdateFromPython); } + template void Schedule::setWellPIMap(std::unordered_map); + template void Schedule::setWellPIMap(std::unordered_map); + + template + void Schedule::setWellPIMap(std::unordered_map wellPIMap) { + this->m_wellPIMap.clear(); + for (const auto& [key, value] : wellPIMap) { + this->m_wellPIMap[key] = static_cast(value); + } + } + void Schedule::applyWellProdIndexScaling(const std::string& well_name, const std::size_t reportStep, const double newWellPI) { if (reportStep >= this->snapshots.size()) return; @@ -2110,6 +2121,7 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen && this->current_report_step == data.current_report_step && this->m_lowActionParsingStrictness == data.m_lowActionParsingStrictness && this->welpi_action_mode == data.welpi_action_mode + && this->m_wellPIMap == data.m_wellPIMap && simUpdateFromPythonIsEqual ; } diff --git a/opm/input/eclipse/Schedule/Schedule.hpp b/opm/input/eclipse/Schedule/Schedule.hpp index dd989f67f9b..e3a97623a5d 100644 --- a/opm/input/eclipse/Schedule/Schedule.hpp +++ b/opm/input/eclipse/Schedule/Schedule.hpp @@ -310,6 +310,9 @@ namespace Opm { SimulatorUpdate modifyCompletions(const std::size_t reportStep, const std::map>& extraConns); + template + void setWellPIMap(std::unordered_map); + const GasLiftOpt& glo(std::size_t report_step) const; bool operator==(const Schedule& data) const; @@ -352,6 +355,7 @@ namespace Opm { serializer(this->m_lowActionParsingStrictness); serializer(this->welpi_action_mode); serializer(this->simUpdateFromPython); + serializer(this->m_wellPIMap); // If we are deserializing we need to setup the pointer to the // unit system since this is process specific. This is safe @@ -425,6 +429,10 @@ namespace Opm { // It is a shared_ptr, so a Schedule can be constructed using the copy constructor sharing the simUpdateFromPython. // The copy constructor is needed for creating a mocked simulator (msim). std::shared_ptr simUpdateFromPython{}; + // The wellPIMap is used when a PYACTION is executed for handling the keyword WELPI. + // It is a map containing wells and their production index. + // This map is set in the ActionHandler with the setWellPIMap function of the Schedule. + std::unordered_map m_wellPIMap; void load_rst(const RestartIO::RstState& rst, const TracerConfig& tracer_config, From 9b65c1c78980502d35c2f0cc7eb5dd9e8b5018aa Mon Sep 17 00:00:00 2001 From: Lisa Julia Nebel Date: Tue, 9 Jul 2024 17:03:59 +0200 Subject: [PATCH 8/9] Remove the target_wellpi argument from the handleKeyword and applyAction function Instead, use the wellPIMap of the Schedule Object --- msim/src/msim.cpp | 3 +-- opm/input/eclipse/Schedule/Schedule.cpp | 36 +++++-------------------- opm/input/eclipse/Schedule/Schedule.hpp | 9 +------ tests/parser/ACTIONX.cpp | 27 +++++++------------ 4 files changed, 18 insertions(+), 57 deletions(-) diff --git a/msim/src/msim.cpp b/msim/src/msim.cpp index 9c729dfeb07..9dffc742a31 100644 --- a/msim/src/msim.cpp +++ b/msim/src/msim.cpp @@ -141,8 +141,7 @@ void msim::post_step(data::Solution& /* sol */, for (const auto& action : actions.pending(this->action_state, std::chrono::system_clock::to_time_t(sim_time))) { const auto result = action->eval(context); if (result.conditionSatisfied()) { - this->schedule.applyAction(report_step, *action, result.matches(), - std::unordered_map{}); + this->schedule.applyAction(report_step, *action, result.matches()); } } diff --git a/opm/input/eclipse/Schedule/Schedule.cpp b/opm/input/eclipse/Schedule/Schedule.cpp index 8d05a234af5..9f9d4a42283 100644 --- a/opm/input/eclipse/Schedule/Schedule.cpp +++ b/opm/input/eclipse/Schedule/Schedule.cpp @@ -396,14 +396,13 @@ namespace Opm { const ScheduleGrid& grid, const Action::Result::MatchingEntities& matches, SimulatorUpdate* sim_update, - const std::unordered_map* target_wellpi, std::unordered_map& wpimult_global_factor, WelSegsSet* welsegs_wells, std::set* compsegs_wells) { HandlerContext handlerContext { *this, block, keyword, grid, currentStep, matches, this->welpi_action_mode, - parseContext, errors, sim_update, target_wellpi, + parseContext, errors, sim_update, &(this->m_wellPIMap), wpimult_global_factor, welsegs_wells, compsegs_wells}; if (!KeywordHandlers::getInstance().handleKeyword(handlerContext)) { @@ -719,7 +718,6 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e grid, matches, /* sim_update = */ nullptr, - target_wellpi, wpimult_global_factor, &welsegs_wells, &compsegs_wells); @@ -908,8 +906,7 @@ Defaulted grid coordinates is not allowed for COMPDAT as part of ACTIONX)" action_keyword.addRecord(std::move(deckRecord)); action.addKeyword(action_keyword); SimulatorUpdate delta = this->applyAction(report_step, action, - /* matches = */ Action::Result{false}.matches(), - std::unordered_map{}/*target_wellpi*/); + /* matches = */ Action::Result{false}.matches()); this->simUpdateFromPython->append(delta); } @@ -1685,8 +1682,7 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen grid, matches, &sim_update, - &(this->m_wellPIMap), - wpimult_global_factor); + wpimult_global_factor); } else { const std::string msg_fmt = @@ -1707,7 +1703,7 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen parseContext, errors, grid, - &target_wellpi, + &(this->m_wellPIMap), prefix, /* keepKeywords = */ true); } @@ -1716,26 +1712,10 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen } - SimulatorUpdate - Schedule::applyAction(const std::size_t reportStep, - const Action::ActionX& action, - const Action::Result::MatchingEntities& matches, - const std::unordered_map& target_wellpi) - { - std::unordered_map dtarget_wellpi; - for (const auto& w : target_wellpi) { - dtarget_wellpi.emplace(w.first, w.second); - } - - return this->applyAction(reportStep, action, matches, dtarget_wellpi); - } - - SimulatorUpdate Schedule::applyAction(std::size_t reportStep, const Action::ActionX& action, - const Action::Result::MatchingEntities& matches, - const std::unordered_map& target_wellpi) + const Action::Result::MatchingEntities& matches) { const std::string prefix = "| "; ParseContext parseContext; @@ -1775,7 +1755,6 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen grid, matches, &sim_update, - &target_wellpi, wpimult_global_factor); } // The whole ACTIONX was executed, welpi_action_mode is set to false. @@ -1800,7 +1779,7 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen const auto keepKeywords = true; const auto log_to_debug = true; this->iterateScheduleSection(reportStep + 1, this->m_sched_deck.size(), - parseContext, errors, grid, &target_wellpi, + parseContext, errors, grid, &(this->m_wellPIMap), prefix, keepKeywords, log_to_debug); } @@ -1913,8 +1892,7 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen } return this->applyAction(reportStep, actions[action_name], - Action::Result{true}.wells(well_names).matches(), - std::unordered_map{}); + Action::Result{true}.wells(well_names).matches()); } else { OpmLog::error(fmt::format("Tried to apply unknown action: '{}'", action_name)); diff --git a/opm/input/eclipse/Schedule/Schedule.hpp b/opm/input/eclipse/Schedule/Schedule.hpp index e3a97623a5d..22c80a54122 100644 --- a/opm/input/eclipse/Schedule/Schedule.hpp +++ b/opm/input/eclipse/Schedule/Schedule.hpp @@ -291,13 +291,7 @@ namespace Opm { // keywords have been applied. SimulatorUpdate applyAction(std::size_t reportStep, const Action::ActionX& action, - const Action::Result::MatchingEntities& matches, - const std::unordered_map& wellpi); - - SimulatorUpdate applyAction(std::size_t reportStep, - const Action::ActionX& action, - const Action::Result::MatchingEntities& matches, - const std::unordered_map& wellpi); + const Action::Result::MatchingEntities& matches); /* The runPyAction() will run the Python script in a PYACTION keyword. In the case of Schedule updates the recommended way of doing that from @@ -487,7 +481,6 @@ namespace Opm { const ScheduleGrid& grid, const Action::Result::MatchingEntities& matches, SimulatorUpdate* sim_update, - const std::unordered_map* target_wellpi, std::unordered_map& wpimult_global_factor, WelSegsSet* welsegs_wells = nullptr, std::set* compsegs_wells = nullptr); diff --git a/tests/parser/ACTIONX.cpp b/tests/parser/ACTIONX.cpp index a2ac88b003c..91466126bc9 100644 --- a/tests/parser/ACTIONX.cpp +++ b/tests/parser/ACTIONX.cpp @@ -224,8 +224,7 @@ TSTEP const auto action_result = Action::Result { true }; const auto& action1 = sched[0].actions.get()["ACTION"]; - auto sim_update = sched.applyAction(0, action1, action_result.matches(), - std::unordered_map{}); + auto sim_update = sched.applyAction(0, action1, action_result.matches()); const auto& affected_wells = sim_update.affected_wells; const std::vector expected_wells{"W0", "W1", "W3"}; @@ -295,8 +294,7 @@ COMPDAT Schedule sched = make_schedule(TRAILING_COMPDAT); const auto& action1 = sched[0].actions.get()["ACTION"]; - BOOST_CHECK_NO_THROW(sched.applyAction(0, action1, Action::Result{false}.matches(), - std::unordered_map{})); + BOOST_CHECK_NO_THROW(sched.applyAction(0, action1, Action::Result{false}.matches())); } BOOST_AUTO_TEST_CASE(EMPTY) @@ -1222,8 +1220,7 @@ END } const Action::Result action_result{true}; - sched.applyAction(0, action1, action_result.matches(), - std::unordered_map{}); + sched.applyAction(0, action1, action_result.matches()); { const auto& group = sched.getGroup("G1", 1); @@ -1349,8 +1346,7 @@ END { const Action::Result action_result(true); - const auto& sim_update = sched.applyAction(0, action1, action_result.matches(), - std::unordered_map{}); + const auto& sim_update = sched.applyAction(0, action1, action_result.matches()); BOOST_CHECK(sim_update.affected_wells.empty()); } @@ -1432,8 +1428,7 @@ END BOOST_CHECK(!sched.hasWell("PROD1")); Action::Result action_result(true); - sched.applyAction(0, action1, action_result.matches(), - std::unordered_map{}); + sched.applyAction(0, action1, action_result.matches()); const auto& well = sched.getWell("PROD1", 1); const auto& connections = well.getConnections(); @@ -1493,15 +1488,12 @@ END const auto CF0 = sched.getWell("PROD1", 0).getConnections()[0].CF(); const Action::Result action_result(true); - BOOST_CHECK_THROW(sched.applyAction(0, action1, action_result.matches(), - std::unordered_map{}), std::exception); + BOOST_CHECK_THROW(sched.applyAction(0, action1, action_result.matches()), std::exception); { const auto& well = sched.getWell("PROD1", 0); - const auto& sim_update = sched.applyAction(0, action1, action_result.matches(), - std::unordered_map { - { "PROD1", well.convertDeckPI(500) }, - }); + sched.setWellPIMap(std::unordered_map{{"PROD1", static_cast(well.convertDeckPI(500))}}); + const auto& sim_update = sched.applyAction(0, action1, action_result.matches()); BOOST_CHECK_EQUAL(sim_update.welpi_wells.count("PROD1"), 1); BOOST_CHECK_EQUAL(sim_update.welpi_wells.size(), 1); @@ -1574,8 +1566,7 @@ END const auto& action1 = sched[0].actions.get()["A"]; const Action::Result action_result(true); - auto sim_update = sched.applyAction(0, action1, action_result.matches(), - std::unordered_map{}); + auto sim_update = sched.applyAction(0, action1, action_result.matches()); BOOST_CHECK(sim_update.tran_update); BOOST_CHECK_EQUAL(sched[0].geo_keywords().size(), 3); From 16de16fe597a6a1acfad612fd22bb23e7025face Mon Sep 17 00:00:00 2001 From: Lisa Julia Nebel Date: Tue, 9 Jul 2024 18:15:39 +0200 Subject: [PATCH 9/9] Remove target_wellpi argument of iterateScheduleSection - this is not needed anymore now --- opm/input/eclipse/Schedule/Schedule.cpp | 11 ++++------- opm/input/eclipse/Schedule/Schedule.hpp | 1 - 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/opm/input/eclipse/Schedule/Schedule.cpp b/opm/input/eclipse/Schedule/Schedule.cpp index 9f9d4a42283..2e838eba1ac 100644 --- a/opm/input/eclipse/Schedule/Schedule.cpp +++ b/opm/input/eclipse/Schedule/Schedule.cpp @@ -168,12 +168,12 @@ namespace Opm { auto restart_step = this->m_static.rst_info.report_step; this->iterateScheduleSection(0, restart_step, parseContext, errors, - grid, nullptr, "", keepKeywords); + grid, "", keepKeywords); this->load_rst(*rst, *tracer_config, grid, fp); if (! this->restart_output.writeRestartFile(restart_step)) this->restart_output.addRestartOutput(restart_step); this->iterateScheduleSection(restart_step, this->m_sched_deck.size(), - parseContext, errors, grid, nullptr, "", keepKeywords); + parseContext, errors, grid, "", keepKeywords); // Events added during restart reading well be added to previous step, but need to be active at the // restart step to ensure well potentials and guide rates are available at the first step. const auto prev_step = std::max(static_cast(restart_step-1), 0); @@ -181,7 +181,7 @@ namespace Opm { this->snapshots[restart_step].update_events(this->snapshots[prev_step].events()); } else { this->iterateScheduleSection(0, this->m_sched_deck.size(), - parseContext, errors, grid, nullptr, "", keepKeywords); + parseContext, errors, grid, "", keepKeywords); } } catch (const OpmInputError& opm_error) { @@ -575,7 +575,6 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e const ParseContext& parseContext, ErrorGuard& errors, const ScheduleGrid& grid, - const std::unordered_map * target_wellpi, const std::string& prefix, const bool keepKeywords, const bool log_to_debug) @@ -1703,7 +1702,6 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen parseContext, errors, grid, - &(this->m_wellPIMap), prefix, /* keepKeywords = */ true); } @@ -1779,7 +1777,7 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen const auto keepKeywords = true; const auto log_to_debug = true; this->iterateScheduleSection(reportStep + 1, this->m_sched_deck.size(), - parseContext, errors, grid, &(this->m_wellPIMap), + parseContext, errors, grid, prefix, keepKeywords, log_to_debug); } @@ -1863,7 +1861,6 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen const auto log_to_debug = true; this->iterateScheduleSection(reportStep + 1, this->m_sched_deck.size(), parseContext, errors, grid, - /* target_wellpi = */ nullptr, prefix, keepKeywords, log_to_debug); } diff --git a/opm/input/eclipse/Schedule/Schedule.hpp b/opm/input/eclipse/Schedule/Schedule.hpp index 22c80a54122..5d18d38f500 100644 --- a/opm/input/eclipse/Schedule/Schedule.hpp +++ b/opm/input/eclipse/Schedule/Schedule.hpp @@ -458,7 +458,6 @@ namespace Opm { const ParseContext& parseContext, ErrorGuard& errors, const ScheduleGrid& grid, - const std::unordered_map * target_wellpi, const std::string& prefix, const bool keepKeywords, const bool log_to_debug = false);