Skip to content

Commit

Permalink
Tried to activate COMPDAT for PYACTION, but some cells are missing in…
Browse files Browse the repository at this point in the history
… the completedcells of the ScheduleGrid...
  • Loading branch information
lisajulia committed May 10, 2024
1 parent 5daf849 commit 4abbb1b
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 37 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions opm/input/eclipse/Schedule/Action/PyAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace Action {
bool PyAction::valid_keyword(const std::string& keyword) {
static std::unordered_set<std::string> pyaction_allowed_list = {
"BOX",
"COMPLUMP", "COMPDAT", //"COMPSEGS",
"FIELD",
"ENDBOX",
"GCONINJE", "GCONPROD",
Expand Down
21 changes: 19 additions & 2 deletions opm/input/eclipse/Schedule/CompletedCells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

#include <opm/input/eclipse/Schedule/CompletedCells.hpp>

#include <iostream>
bool Opm::CompletedCells::Cell::Props::operator==(const Props& other) const
{
return (this->active_index == other.active_index)
Expand Down Expand Up @@ -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<bool, Opm::CompletedCells::Cell&>
Expand Down
91 changes: 58 additions & 33 deletions opm/input/eclipse/Schedule/Schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,48 +1423,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<std::string, double> target_wellpi;
std::vector<std::string> 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<std::string, double> 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<std::string, double> target_wellpi;
// std::vector<std::string> 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<std::string, double> 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);
}


Expand Down
4 changes: 4 additions & 0 deletions opm/input/eclipse/Schedule/ScheduleGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <string>

#include <fmt/format.h>
#include <iostream>

Opm::ScheduleGrid::ScheduleGrid(const Opm::EclipseGrid& ecl_grid,
const Opm::FieldPropsManager& fpm,
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 4abbb1b

Please sign in to comment.