From 9fe58cb528b4a5270947afcd72e1c55923548d3c Mon Sep 17 00:00:00 2001 From: Lisa Julia Nebel Date: Fri, 10 May 2024 09:57:37 +0200 Subject: [PATCH] Tried to activate COMPDAT for PYACTION, but some cells are missing in the completedcells of the ScheduleGrid... --- CMakeLists.txt | 4 +- .../eclipse/Schedule/Action/PyAction.cpp | 2 +- opm/input/eclipse/Schedule/CompletedCells.cpp | 21 ++++- opm/input/eclipse/Schedule/Schedule.cpp | 91 ++++++++++++------- opm/input/eclipse/Schedule/ScheduleGrid.cpp | 4 + 5 files changed, 84 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 504b107ebed..eb21a62b7d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,9 +8,9 @@ set(OPM_MACROS_ROOT ${PROJECT_SOURCE_DIR}) option(ENABLE_ECL_INPUT "Enable eclipse input support?" ON) option(ENABLE_ECL_OUTPUT "Enable eclipse output support?" ON) option(ENABLE_MOCKSIM "Build the mock simulator for io testing" ON) -option(OPM_ENABLE_PYTHON "Enable python bindings?" OFF) +option(OPM_ENABLE_PYTHON "Enable python bindings?" ON) option(OPM_INSTALL_PYTHON "Install python bindings?" ON) -option(OPM_ENABLE_EMBEDDED_PYTHON "Enable embedded python?" OFF) +option(OPM_ENABLE_EMBEDDED_PYTHON "Enable embedded python?" ON) # Output implies input if(ENABLE_ECL_OUTPUT) diff --git a/opm/input/eclipse/Schedule/Action/PyAction.cpp b/opm/input/eclipse/Schedule/Action/PyAction.cpp index 2dd9bc0455c..2ebde5b3c27 100644 --- a/opm/input/eclipse/Schedule/Action/PyAction.cpp +++ b/opm/input/eclipse/Schedule/Action/PyAction.cpp @@ -40,7 +40,7 @@ namespace Action { bool PyAction::valid_keyword(const std::string& keyword) { static std::unordered_set pyaction_allowed_list = { "BOX", - "COMPSEGS", + "COMPDAT", "COMPLUMP", "COMPSEGS", "FIELD", "ENDBOX", "EXIT", "GCONINJE", "GCONPROD", "GCONSUMP","GRUPTREE", diff --git a/opm/input/eclipse/Schedule/CompletedCells.cpp b/opm/input/eclipse/Schedule/CompletedCells.cpp index b157dbe4090..aadd96cd299 100644 --- a/opm/input/eclipse/Schedule/CompletedCells.cpp +++ b/opm/input/eclipse/Schedule/CompletedCells.cpp @@ -18,7 +18,7 @@ */ #include - +#include bool Opm::CompletedCells::Cell::Props::operator==(const Props& other) const { return (this->active_index == other.active_index) @@ -83,7 +83,24 @@ Opm::CompletedCells::CompletedCells(const Opm::GridDims& dims_) const Opm::CompletedCells::Cell& Opm::CompletedCells::get(std::size_t i, std::size_t j, std::size_t k) const { - return this->cells.at(this->dims.getGlobalIndex(i, j, k)); + std::cout << "looping over cells" << std::endl; + for (auto& cell : this->cells) { + std::cout << cell.first << ", (i,j,k) = (" << cell.second.i << ", " << cell.second.j << ", " << cell.second.k << ")" << std::endl; + } + try { + std::cout << "this->dims.getGlobalIndex(" << i << ", " << j << ", " << k << ") = " << this->dims.getGlobalIndex(i, j, k) << std::endl; + } catch (std::exception& e) { + std::cout << "this->dims.getGlobalIndex(" << i << ", " << j << ", " << k << ") not found " << std::endl; + std::cout << e.what() << std::endl; + } + try { + return this->cells.at(this->dims.getGlobalIndex(i, j, k)); + } catch (std::exception& e) { + std::cout << e.what() << std::endl; + Opm::CompletedCells::Cell cell; + return cell; + } + } std::pair diff --git a/opm/input/eclipse/Schedule/Schedule.cpp b/opm/input/eclipse/Schedule/Schedule.cpp index 416d6e1f542..7926bf135c0 100644 --- a/opm/input/eclipse/Schedule/Schedule.cpp +++ b/opm/input/eclipse/Schedule/Schedule.cpp @@ -1434,48 +1434,73 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen } else if (reportStep >= this->m_sched_deck.size()) { throw std::invalid_argument("Insert keyword for report step " + std::to_string(reportStep) + " requested, this exceeds the total number of report steps, being " + std::to_string(this->m_sched_deck.size() -1) + "."); } + ParseContext parseContext; ErrorGuard errors; - ScheduleGrid grid(this->completed_cells); - SimulatorUpdate sim_update; - 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]; - std::unordered_map wpimult_global_factor; + + std::time_t start_time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::from_time_t(0)); + Opm::Action::ActionX action("insertkwaction", 1, 0.0, start_time); for (auto& keyword : keywords) { if (Action::PyAction::valid_keyword(keyword->name())) { - input_block.push_back(*keyword); - this->handleKeyword(reportStep, - input_block, - *keyword, - parseContext, - errors, - grid, - matching_wells, - /*actionx_mode=*/false, - &sim_update, - &target_wellpi, - wpimult_global_factor); + action.addKeyword(*keyword); } else { const std::string msg_fmt = fmt::format("The keyword {} is not supported for inserting it from Python into a simulation", keyword->name()); parseContext.handleError(ParseContext::PYACTION_ILLEGAL_KEYWORD, msg_fmt, keyword->location(), errors); } } - this->applyGlobalWPIMULT(wpimult_global_factor); - 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, - prefix); - } - this->simUpdateFromPython->append(sim_update); + SimulatorUpdate delta = this->applyAction(reportStep, action, {} /*matching_wells*/, {}/*target_wellpi*/); + this->simUpdateFromPython->append(delta); + +// ScheduleGrid grid(this->completed_cells); +// SimulatorUpdate sim_update; +// 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]; +// std::unordered_map wpimult_global_factor; +// for (auto& keyword : keywords) { +// if (Action::PyAction::valid_keyword(keyword->name())) { +// input_block.push_back(*keyword); +// this->handleKeyword(reportStep, +// input_block, +// *keyword, +// parseContext, +// errors, +// grid, +// matching_wells, +// /*actionx_mode=*/false, +// &sim_update, +// &target_wellpi, +// wpimult_global_factor); +// } else { +// const std::string msg_fmt = fmt::format("The keyword {} is not supported for inserting it from Python into a simulation", keyword->name()); +// parseContext.handleError(ParseContext::PYACTION_ILLEGAL_KEYWORD, msg_fmt, keyword->location(), errors); +// } +// } +// this->applyGlobalWPIMULT(wpimult_global_factor); +// this->end_report(reportStep); +// if (! sim_update.affected_wells.empty()) { +// this->snapshots.back().events() +// .addEvent(ScheduleEvents::ACTIONX_WELL_EVENT); +// +// auto& wgEvents = this->snapshots.back().wellgroup_events(); +// +// for (const auto& well: sim_update.affected_wells) { +// wgEvents.addEvent(well, ScheduleEvents::ACTIONX_WELL_EVENT); +// } +// } +// if (reportStep < this->m_sched_deck.size() - 1) { +// iterateScheduleSection( +// reportStep + 1, +// this->m_sched_deck.size(), +// parseContext, +// errors, +// grid, +// &target_wellpi, +// prefix); +// } +// this->simUpdateFromPython->append(sim_update); } diff --git a/opm/input/eclipse/Schedule/ScheduleGrid.cpp b/opm/input/eclipse/Schedule/ScheduleGrid.cpp index 8bee8878738..4d3b41d5154 100644 --- a/opm/input/eclipse/Schedule/ScheduleGrid.cpp +++ b/opm/input/eclipse/Schedule/ScheduleGrid.cpp @@ -28,6 +28,7 @@ #include #include +#include Opm::ScheduleGrid::ScheduleGrid(const Opm::EclipseGrid& ecl_grid, const Opm::FieldPropsManager& fpm, @@ -66,7 +67,10 @@ namespace { const Opm::CompletedCells::Cell& Opm::ScheduleGrid::get_cell(std::size_t i, std::size_t j, std::size_t k) const { + std::cout << "In ScheduleGrid::get_cell" << std::endl; + if (this->grid == nullptr) { + std::cout << " no EclipseGrid set!" << std::endl; return this->cells.get(i, j, k); }