diff --git a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp index 536dbe6ce..3ad549554 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp @@ -301,6 +301,7 @@ namespace Opm for the schedule instances created by loading a restart file. */ static bool cmp(const Schedule& sched1, const Schedule& sched2, std::size_t report_step); + void applyKeywords(std::vector& keywords, std::size_t timeStep); template void serializeOp(Serializer& serializer) diff --git a/python/cxx/deck.cpp b/python/cxx/deck.cpp index 98348a95f..ea7330e90 100644 --- a/python/cxx/deck.cpp +++ b/python/cxx/deck.cpp @@ -45,7 +45,7 @@ namespace { void python::common::export_Deck(py::module &module) { - // Note: In the below class we std::shared_ptr as the holder type, see: + // Note: In the below class we use std::shared_ptr as the holder type, see: // // https://pybind11.readthedocs.io/en/stable/advanced/smart_ptrs.html // diff --git a/python/cxx/schedule.cpp b/python/cxx/schedule.cpp index a8914087a..c14070d8c 100644 --- a/python/cxx/schedule.cpp +++ b/python/cxx/schedule.cpp @@ -1,7 +1,9 @@ #include #include +#include #include +#include #include @@ -92,13 +94,38 @@ namespace { return sch[index]; } + void insert_keywords( + Schedule& sch, + const std::string& deck_string, + std::size_t index, + const UnitSystem& unit_system + ) + { + Parser parser; + std::string str {unit_system.deck_name() + "\n\n" + deck_string}; + auto deck = parser.parseString(str); + std::vector keywords; + for (auto &keyword : deck) { + keywords.push_back(&keyword); + } + sch.applyKeywords(keywords, index); + } + + void insert_keywords( + Schedule& sch, py::list& deck_keywords, std::size_t index) + { + Parser parser; + std::vector keywords; + for (py::handle item : deck_keywords) { + DeckKeyword &keyword = item.cast(); + keywords.push_back(&keyword); + } + sch.applyKeywords(keywords, index); + } } - - - void python::common::export_Schedule(py::module& module) { @@ -107,7 +134,7 @@ void python::common::export_Schedule(py::module& module) { .def("group", &get_group, ref_internal); - // Note: In the below class we std::shared_ptr as the holder type, see: + // Note: In the below class we use std::shared_ptr as the holder type, see: // // https://pybind11.readthedocs.io/en/stable/advanced/smart_ptrs.html // @@ -128,6 +155,14 @@ void python::common::export_Schedule(py::module& module) { .def( "get_wells", &Schedule::getWells) .def("well_names", py::overload_cast(&Schedule::wellNames, py::const_)) .def( "get_well", &get_well) + .def( "insert_keywords", + py::overload_cast(&insert_keywords), + py::arg("keywords"), py::arg("step")) + .def( "insert_keywords", + py::overload_cast< + Schedule&, const std::string&, std::size_t, const UnitSystem& + >(&insert_keywords), + py::arg("data"), py::arg("step"), py::arg("unit_system")) .def( "__contains__", &has_well ); } diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp index ab56730ee..649d37395 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp @@ -1273,6 +1273,45 @@ void Schedule::iterateScheduleSection(std::size_t load_start, std::size_t load_e return std::chrono::duration_cast(elapsed).count(); } + void Schedule::applyKeywords( + std::vector& keywords, std::size_t reportStep) { + ParseContext parseContext; + ErrorGuard errors; + ScheduleGrid grid(this->completed_cells); + std::unordered_set affected_wells; + std::unordered_map target_wellpi; + std::vector matching_wells; + const std::string prefix = "| "; /* logger prefix string */ + this->snapshots.resize(reportStep + 1); + auto& input_block = this->m_sched_deck[reportStep]; + for (auto keyword : keywords) { + input_block.push_back(*keyword); + this->handleKeyword(reportStep, + input_block, + *keyword, + parseContext, + errors, + grid, + /*FieldPropsManager *fp=*/nullptr, + matching_wells, + /*actionx_mode=*/false, + &affected_wells, + &target_wellpi); + } + this->end_report(reportStep); + if (reportStep < this->m_sched_deck.size() - 1) { + iterateScheduleSection( + reportStep + 1, + this->m_sched_deck.size(), + parseContext, + errors, + grid, + &target_wellpi, + /*FieldPropsManager *fp=*/nullptr, + prefix); + } + } + SimulatorUpdate Schedule::applyAction(std::size_t reportStep, const time_point&, const Action::ActionX& action, const Action::Result& result, const std::unordered_map& target_wellpi) { const std::string prefix = "| ";