Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function returning all well production indices to be handed over to a pyaction call #5254

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 47 additions & 0 deletions opm/simulators/flow/ActionHandler.cpp
Expand Up @@ -42,6 +42,7 @@
#include <opm/simulators/wells/BlackoilWellModelGeneric.hpp>
#include <opm/simulators/utils/ParallelSerialization.hpp>

#include <iostream>
#include <chrono>
#include <cstddef>
#include <ctime>
Expand Down Expand Up @@ -143,6 +144,10 @@ void ActionHandler::applyActions(const int reportStep,

bool commit_wellstate = false;
for (const auto& pyaction : actions.pending_python(actionState_)) {
//if (!schedule_.wellPIPointer) {
//auto wellPIAll = this->fetchWellPIAll(reportStep); //todo: do this nicer!
//schedule_.wellPIPointer = std::make_shared<std::unordered_map<std::string, double>>(std::move(wellPIAll));
//}
auto sim_update = schedule_.runPyAction(reportStep, *pyaction, actionState_,
ecl_state_, summaryState_);
this->applySimulatorUpdate(reportStep, sim_update, commit_wellstate, transUp);
Expand Down Expand Up @@ -207,6 +212,47 @@ void ActionHandler::applySimulatorUpdate(const int report_step,
}
}

std::unordered_map<std::string, double>
ActionHandler::fetchWellPIAll(const int reportStep) const
{
std::vector<Well> allWells = schedule_.getWells(reportStep);
const auto num_wells = schedule_[reportStep].well_order().size();
std::vector<double> wellpi_vector(num_wells);
for (const auto& well : allWells) {
wellpi_vector[well.seqIndex()] = this->wellModel_.wellPI(well.name());
}

if (comm_.size() > 1) {
std::vector<double> wellpi_buffer(num_wells * comm_.size());
comm_.gather( wellpi_vector.data(), wellpi_buffer.data(), num_wells, 0 );
if (comm_.rank() == 0) {
for (int rank=1; rank < comm_.size(); rank++) {
for (std::size_t well_index=0; well_index < num_wells; well_index++) {
const auto global_index = rank*num_wells + well_index;
const auto value = wellpi_buffer[global_index];
if (value != 0)
wellpi_vector[well_index] = value;
}
}
}
comm_.broadcast(wellpi_vector.data(), wellpi_vector.size(), 0);
}

std::unordered_map<std::string, double> wellpi;
for (const auto& well : allWells) {
wellpi[well.name()] = wellpi_vector[ well.seqIndex() ];
std::cout << "------------------------------------------------------- At Report Step: " << reportStep << ": Well " << well.name() << " has productivity/injectivity of " << wellpi[well.name()] << std::endl;
}
/*if (reportStep > 0) {
std::cout << " wellpi_from_inside ------------------------------------------------------- At Report Step: " << reportStep << ": Try to get schedule_.snapshots[reportStep-1].target_wellpi" << std::endl;
auto wellpi_from_inside = schedule_.snapshots[reportStep-1].target_wellpi;
for (const auto& wellpi_from_inside_entry : wellpi_from_inside) {
std::cout << " wellpi_from_inside ------------------------------------------------------- At Report Step: " << reportStep << ": Well " << wellpi_from_inside_entry.first << " has productivity/injectivity of " << wellpi_from_inside_entry.second << std::endl;
}
}*/
return wellpi;
}

std::unordered_map<std::string, double>
ActionHandler::fetchWellPI(const int reportStep,
const Action::ActionX& action,
Expand Down Expand Up @@ -249,6 +295,7 @@ ActionHandler::fetchWellPI(const int reportStep,
for (const auto& wname : wellpi_wells) {
const auto& well = schedule_.getWell( wname, reportStep );
wellpi[wname] = wellpi_vector[ well.seqIndex() ];
std::cout << "------------------------------------------------------- At Report Step: " << reportStep << ": Well " << wname << " has productivity/injectivity of " << wellpi[wname] << std::endl;
}
return wellpi;
}
Expand Down
3 changes: 3 additions & 0 deletions opm/simulators/flow/ActionHandler.hpp
Expand Up @@ -84,6 +84,9 @@ class ActionHandler
const Action::ActionX& action,
const std::vector<std::string>& matching_wells) const;

std::unordered_map<std::string, double>
fetchWellPIAll(int reportStep) const;

EclipseState& ecl_state_;
Schedule& schedule_;
Action::State& actionState_;
Expand Down