BlackoilWellModel: move runWellPIScaling to generic class

This commit is contained in:
Arne Morten Kvarving
2021-06-07 15:01:10 +02:00
parent 7219f09fdc
commit 0ef68b452a
4 changed files with 93 additions and 90 deletions

View File

@@ -125,7 +125,7 @@ namespace Opm {
BlackoilWellModel(Simulator& ebosSimulator);
void init();
void initWellContainer();
void initWellContainer() override;
/////////////
// <eWoms auxiliary module stuff>
@@ -279,7 +279,7 @@ namespace Opm {
const SummaryState& summaryState);
// create the well container
void createWellContainer(const int time_step);
void createWellContainer(const int time_step) override;
WellInterfacePtr
createWellPointer(const int wellID,
@@ -301,8 +301,6 @@ namespace Opm {
std::vector<double> depth_{};
bool alternative_well_rate_init_{};
std::optional<int> last_run_wellpi_{};
std::unique_ptr<RateConverterType> rateConverter_{};
SimulatorReportSingle last_report_{};
@@ -348,8 +346,8 @@ namespace Opm {
const std::vector<double>& wellPerfEfficiencyFactors() const;
void calculateProductivityIndexValuesShutWells(const int reportStepIdx, DeferredLogger& deferred_logger);
void calculateProductivityIndexValues(DeferredLogger& deferred_logger);
void calculateProductivityIndexValuesShutWells(const int reportStepIdx, DeferredLogger& deferred_logger) override;
void calculateProductivityIndexValues(DeferredLogger& deferred_logger) override;
void calculateProductivityIndexValues(const WellInterface<TypeTag>* wellPtr,
DeferredLogger& deferred_logger);
@@ -375,8 +373,6 @@ namespace Opm {
const int pvtreg,
std::vector<double>& resv_coeff) override;
void runWellPIScaling(const int timeStepIdx, DeferredLogger& local_deferredLogger);
void computeWellTemperature();
private:

View File

@@ -45,7 +45,7 @@
namespace Opm {
BlackoilWellModelGeneric::
BlackoilWellModelGeneric(const Schedule& schedule,
BlackoilWellModelGeneric(Schedule& schedule,
const SummaryState& summaryState,
const EclipseState& eclState,
const PhaseUsage& phase_usage,
@@ -1764,4 +1764,78 @@ updateWellPotentials(const int reportStepIdx,
}
void
BlackoilWellModelGeneric::
runWellPIScaling(const int timeStepIdx,
DeferredLogger& local_deferredLogger)
{
if (this->last_run_wellpi_.has_value() && (*this->last_run_wellpi_ == timeStepIdx)) {
// We've already run WELPI scaling for this report step. Most
// common for the very first report step. Don't redo WELPI scaling.
return;
}
auto hasWellPIEvent = [this, timeStepIdx](const int well_index) -> bool
{
return this->schedule()[timeStepIdx].wellgroup_events()
.hasEvent(this->wells_ecl_[well_index].name(),
ScheduleEvents::Events::WELL_PRODUCTIVITY_INDEX);
};
auto updateEclWell = [this, timeStepIdx](const int well_index) -> void
{
const auto& schedule = this->schedule();
const auto& wname = this->wells_ecl_[well_index].name();
this->wells_ecl_[well_index] = schedule.getWell(wname, timeStepIdx);
const auto& well = this->wells_ecl_[well_index];
auto& pd = this->well_perf_data_[well_index];
auto pdIter = pd.begin();
for (const auto& conn : well.getConnections()) {
if (conn.state() != Connection::State::SHUT) {
pdIter->connection_transmissibility_factor = conn.CF();
++pdIter;
}
}
this->wellState().resetConnectionTransFactors(well_index, pd);
this->prod_index_calc_[well_index].reInit(well);
};
auto rescaleWellPI =
[this, timeStepIdx](const int well_index,
const double newWellPI) -> void
{
const auto& wname = this->wells_ecl_[well_index].name();
schedule_.applyWellProdIndexScaling(wname, timeStepIdx, newWellPI);
};
// Minimal well setup to compute PI/II values
{
auto saved_previous_wgstate = this->prevWGState();
this->commitWGState();
this->createWellContainer(timeStepIdx);
this->inferLocalShutWells();
this->initWellContainer();
this->calculateProductivityIndexValues(local_deferredLogger);
this->calculateProductivityIndexValuesShutWells(timeStepIdx, local_deferredLogger);
this->commitWGState(std::move(saved_previous_wgstate));
}
const auto nw = this->numLocalWells();
for (auto wellID = 0*nw; wellID < nw; ++wellID) {
if (hasWellPIEvent(wellID)) {
rescaleWellPI(wellID, this->wellPI(wellID));
updateEclWell(wellID);
}
}
this->last_run_wellpi_ = timeStepIdx;
}
}

View File

@@ -73,7 +73,7 @@ public:
using GLiftProdWells = std::map<std::string,const WellInterfaceGeneric*>;
using GLiftWellStateMap = std::map<std::string,std::unique_ptr<GasLiftWellState>>;
BlackoilWellModelGeneric(const Schedule& schedule,
BlackoilWellModelGeneric(Schedule& schedule,
const SummaryState& summaryState,
const EclipseState& eclState,
const PhaseUsage& phase_usage,
@@ -353,8 +353,18 @@ protected:
const SummaryConfig& summaryConfig,
DeferredLogger& deferred_logger);
// create the well container
virtual void createWellContainer(const int time_step) = 0;
virtual void initWellContainer() = 0;
const Schedule& schedule_;
virtual void calculateProductivityIndexValuesShutWells(const int reportStepIdx,
DeferredLogger& deferred_logger) = 0;
virtual void calculateProductivityIndexValues(DeferredLogger& deferred_logger) = 0;
void runWellPIScaling(const int timeStepIdx,
DeferredLogger& local_deferredLogger);
Schedule& schedule_;
const SummaryState& summaryState_;
const EclipseState& eclState_;
const Comm& comm_;
@@ -365,6 +375,8 @@ protected:
bool initial_step_{};
bool report_step_starts_{};
std::optional<int> last_run_wellpi_{};
std::vector<Well> wells_ecl_;
std::vector<std::vector<PerforationData>> well_perf_data_;
std::function<bool(const Well&)> not_on_process_{};

View File

@@ -1496,85 +1496,6 @@ namespace Opm {
}
template<typename TypeTag>
void
BlackoilWellModel<TypeTag>::
runWellPIScaling(const int timeStepIdx, DeferredLogger& local_deferredLogger)
{
if (this->last_run_wellpi_.has_value() && (*this->last_run_wellpi_ == timeStepIdx)) {
// We've already run WELPI scaling for this report step. Most
// common for the very first report step. Don't redo WELPI scaling.
return;
}
auto hasWellPIEvent = [this, timeStepIdx](const int well_index) -> bool
{
return this->schedule()[timeStepIdx].wellgroup_events()
.hasEvent(this->wells_ecl_[well_index].name(),
ScheduleEvents::Events::WELL_PRODUCTIVITY_INDEX);
};
auto updateEclWell = [this, timeStepIdx](const int well_index) -> void
{
const auto& schedule = this->schedule();
const auto& wname = this->wells_ecl_[well_index].name();
this->wells_ecl_[well_index] = schedule.getWell(wname, timeStepIdx);
const auto& well = this->wells_ecl_[well_index];
auto& pd = this->well_perf_data_[well_index];
auto pdIter = pd.begin();
for (const auto& conn : well.getConnections()) {
if (conn.state() != Connection::State::SHUT) {
pdIter->connection_transmissibility_factor = conn.CF();
++pdIter;
}
}
this->wellState().resetConnectionTransFactors(well_index, pd);
this->prod_index_calc_[well_index].reInit(well);
};
auto rescaleWellPI =
[this, timeStepIdx](const int well_index,
const double newWellPI) -> void
{
const auto& wname = this->wells_ecl_[well_index].name();
auto& schedule = this->ebosSimulator_.vanguard().schedule(); // Mutable
schedule.applyWellProdIndexScaling(wname, timeStepIdx, newWellPI);
};
// Minimal well setup to compute PI/II values
{
auto saved_previous_wgstate = this->prevWGState();
this->commitWGState();
this->createWellContainer(timeStepIdx);
this->inferLocalShutWells();
this->initWellContainer();
this->calculateProductivityIndexValues(local_deferredLogger);
this->calculateProductivityIndexValuesShutWells(timeStepIdx, local_deferredLogger);
this->commitWGState(std::move(saved_previous_wgstate));
}
const auto nw = this->numLocalWells();
for (auto wellID = 0*nw; wellID < nw; ++wellID) {
if (hasWellPIEvent(wellID)) {
rescaleWellPI(wellID, this->wellPI(wellID));
updateEclWell(wellID);
}
}
this->last_run_wellpi_ = timeStepIdx;
}
template <typename TypeTag>
void
BlackoilWellModel<TypeTag>::