Skip to content

Commit

Permalink
Add setWellPI Map function to Schedule
Browse files Browse the repository at this point in the history
This is set in the ActionHandler.
Use the wellPIMap when calling handleKeyword in the applyKeywords function.
  • Loading branch information
lisajulia committed Dec 18, 2024
1 parent 7636899 commit 34df271
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 14 additions & 2 deletions opm/input/eclipse/Schedule/Schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> {"W1"};
result.exit_status = EXIT_FAILURE;
Expand Down Expand Up @@ -1633,7 +1634,6 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen
ErrorGuard errors;
ScheduleGrid grid(this->completed_cells);
SimulatorUpdate sim_update;
std::unordered_map<std::string, double> target_wellpi;
std::unordered_map<std::string, double> wpimult_global_factor;
const auto matches = Action::Result{false}.matches();
const std::string prefix = "| "; // logger prefix string
Expand Down Expand Up @@ -1665,7 +1665,7 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen
grid,
matches,
&sim_update,
&target_wellpi,
&(this->m_wellPIMap),
wpimult_global_factor);
}
else {
Expand Down Expand Up @@ -1905,6 +1905,17 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen
return *(this->simUpdateFromPython);
}

template void Schedule::setWellPIMap<double>(std::unordered_map<std::string, double>);
template void Schedule::setWellPIMap<float>(std::unordered_map<std::string, float>);

template<typename Scalar>
void Schedule::setWellPIMap(std::unordered_map<std::string, Scalar> wellPIMap) {
this->m_wellPIMap.clear();
for (const auto& [key, value] : wellPIMap) {
this->m_wellPIMap[key] = static_cast<double>(value);
}
}

void Schedule::applyWellProdIndexScaling(const std::string& well_name, const std::size_t reportStep, const double newWellPI) {
if (reportStep >= this->snapshots.size())
return;
Expand Down Expand Up @@ -2002,6 +2013,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
;
}
Expand Down
7 changes: 7 additions & 0 deletions opm/input/eclipse/Schedule/Schedule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ namespace Opm {
*/
SimulatorUpdate runPyAction(std::size_t reportStep, const Action::PyAction& pyaction, Action::State& action_state, EclipseState& ecl_state, SummaryState& summary_state);

template<typename Scalar>
void setWellPIMap(std::unordered_map<std::string, Scalar>);

const GasLiftOpt& glo(std::size_t report_step) const;

Expand Down Expand Up @@ -349,6 +351,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
Expand Down Expand Up @@ -422,6 +425,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<SimulatorUpdate> 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<std::string, double> m_wellPIMap;

void load_rst(const RestartIO::RstState& rst,
const TracerConfig& tracer_config,
Expand Down

0 comments on commit 34df271

Please sign in to comment.