diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index 7f50fe9dc..8c989c881 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -1323,12 +1323,13 @@ namespace Opm { { DeferredLogger local_deferredLogger; for (const auto& well : well_container_) { - const auto wasClosed = wellTestState.hasWellClosed(well->name()); + const auto& wname = well->name(); + const auto wasClosed = wellTestState.hasWellClosed(wname); - well->updateWellTestState(this->wellState(), simulationTime, /*writeMessageToOPMLog=*/ true, wellTestState, local_deferredLogger); + well->updateWellTestState(this->wellState().well(wname), simulationTime, /*writeMessageToOPMLog=*/ true, wellTestState, local_deferredLogger); - if (!wasClosed && wellTestState.hasWellClosed(well->name())) { - this->closed_this_step_.insert(well->name()); + if (!wasClosed && wellTestState.hasWellClosed(wname)) { + this->closed_this_step_.insert(wname); } } diff --git a/opm/simulators/wells/MultisegmentWell_impl.hpp b/opm/simulators/wells/MultisegmentWell_impl.hpp index 5f19edbc5..3b8946e66 100644 --- a/opm/simulators/wells/MultisegmentWell_impl.hpp +++ b/opm/simulators/wells/MultisegmentWell_impl.hpp @@ -588,7 +588,7 @@ namespace Opm max_pressure_change); this->updateWellStateFromPrimaryVariables(well_state, getRefDensity(), deferred_logger); - Base::calculateReservoirRates(well_state); + Base::calculateReservoirRates(well_state.well(this->index_of_well_)); } diff --git a/opm/simulators/wells/StandardWell_impl.hpp b/opm/simulators/wells/StandardWell_impl.hpp index 7863fdb73..6f5d43cb0 100644 --- a/opm/simulators/wells/StandardWell_impl.hpp +++ b/opm/simulators/wells/StandardWell_impl.hpp @@ -857,7 +857,7 @@ namespace Opm updatePrimaryVariablesNewton(dwells, well_state); updateWellStateFromPrimaryVariables(well_state, deferred_logger); - Base::calculateReservoirRates(well_state); + Base::calculateReservoirRates(well_state.well(this->index_of_well_)); } diff --git a/opm/simulators/wells/WellInterfaceFluidSystem.cpp b/opm/simulators/wells/WellInterfaceFluidSystem.cpp index ce7e24d2d..7dd048a08 100644 --- a/opm/simulators/wells/WellInterfaceFluidSystem.cpp +++ b/opm/simulators/wells/WellInterfaceFluidSystem.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -62,12 +63,11 @@ WellInterfaceFluidSystem(const Well& well, template void WellInterfaceFluidSystem:: -calculateReservoirRates(WellState& well_state) const +calculateReservoirRates(SingleWellState& ws) const { const int fipreg = 0; // not considering the region for now const int np = number_of_phases_; - auto& ws = well_state.well(this->index_of_well_); std::vector surface_rates(np, 0.0); for (int p = 0; p < np; ++p) { surface_rates[p] = ws.surface_rates[p]; @@ -82,13 +82,11 @@ calculateReservoirRates(WellState& well_state) const template Well::ProducerCMode WellInterfaceFluidSystem:: -activeProductionConstraint(const WellState& well_state, +activeProductionConstraint(const SingleWellState& ws, const SummaryState& summaryState) const { const PhaseUsage& pu = this->phaseUsage(); - const int well_index = this->index_of_well_; const auto controls = this->well_ecl_.productionControls(summaryState); - auto& ws = well_state.well(well_index); const auto currentControl = ws.production_cmode; if (controls.hasControl(Well::ProducerCMode::BHP) && currentControl != Well::ProducerCMode::BHP) { @@ -175,12 +173,10 @@ activeProductionConstraint(const WellState& well_state, template Well::InjectorCMode WellInterfaceFluidSystem:: -activeInjectionConstraint(const WellState& well_state, +activeInjectionConstraint(const SingleWellState& ws, const SummaryState& summaryState) const { const PhaseUsage& pu = this->phaseUsage(); - const int well_index = this->index_of_well_; - const auto& ws = well_state.well(well_index); const auto controls = this->well_ecl_.injectionControls(summaryState); const auto currentControl = ws.injection_cmode; @@ -252,13 +248,11 @@ activeInjectionConstraint(const WellState& well_state, template bool WellInterfaceFluidSystem:: -checkIndividualConstraints(WellState& well_state, +checkIndividualConstraints(SingleWellState& ws, const SummaryState& summaryState) const { - const int well_index = this->index_of_well_; - auto& ws = well_state.well(well_index); if (this->well_ecl_.isProducer()) { - auto new_cmode = this->activeProductionConstraint(well_state, summaryState); + auto new_cmode = this->activeProductionConstraint(ws, summaryState); if (new_cmode != ws.production_cmode) { ws.production_cmode = new_cmode; return true; @@ -266,7 +260,7 @@ checkIndividualConstraints(WellState& well_state, } if (this->well_ecl_.isInjector()) { - auto new_cmode = this->activeInjectionConstraint(well_state, summaryState); + auto new_cmode = this->activeInjectionConstraint(ws, summaryState); if (new_cmode != ws.injection_cmode) { ws.injection_cmode = new_cmode; return true; @@ -447,7 +441,7 @@ checkConstraints(WellState& well_state, const SummaryState& summaryState, DeferredLogger& deferred_logger) const { - const bool ind_broken = checkIndividualConstraints(well_state, summaryState); + const bool ind_broken = checkIndividualConstraints(well_state.well(this->index_of_well_), summaryState); if (ind_broken) { return true; } else { @@ -505,7 +499,7 @@ template void WellInterfaceFluidSystem:: checkMaxWaterCutLimit(const WellEconProductionLimits& econ_production_limits, - const WellState& well_state, + const SingleWellState& ws, RatioLimitCheckReport& report) const { assert(FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)); @@ -532,11 +526,11 @@ checkMaxWaterCutLimit(const WellEconProductionLimits& econ_production_limits, const double max_water_cut_limit = econ_production_limits.maxWaterCut(); assert(max_water_cut_limit > 0.); - const bool watercut_limit_violated = checkMaxRatioLimitWell(well_state, max_water_cut_limit, waterCut); + const bool watercut_limit_violated = checkMaxRatioLimitWell(ws, max_water_cut_limit, waterCut); if (watercut_limit_violated) { report.ratio_limit_violated = true; - checkMaxRatioLimitCompletions(well_state, max_water_cut_limit, waterCut, report); + checkMaxRatioLimitCompletions(ws, max_water_cut_limit, waterCut, report); } } @@ -544,7 +538,7 @@ template void WellInterfaceFluidSystem:: checkMaxGORLimit(const WellEconProductionLimits& econ_production_limits, - const WellState& well_state, + const SingleWellState& ws, RatioLimitCheckReport& report) const { assert(FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)); @@ -578,11 +572,11 @@ checkMaxGORLimit(const WellEconProductionLimits& econ_production_limits, const double max_gor_limit = econ_production_limits.maxGasOilRatio(); assert(max_gor_limit > 0.); - const bool gor_limit_violated = checkMaxRatioLimitWell(well_state, max_gor_limit, gor); + const bool gor_limit_violated = checkMaxRatioLimitWell(ws, max_gor_limit, gor); if (gor_limit_violated) { report.ratio_limit_violated = true; - checkMaxRatioLimitCompletions(well_state, max_gor_limit, gor, report); + checkMaxRatioLimitCompletions(ws, max_gor_limit, gor, report); } } @@ -590,7 +584,7 @@ template void WellInterfaceFluidSystem:: checkMaxWGRLimit(const WellEconProductionLimits& econ_production_limits, - const WellState& well_state, + const SingleWellState& ws, RatioLimitCheckReport& report) const { assert(FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)); @@ -624,11 +618,11 @@ checkMaxWGRLimit(const WellEconProductionLimits& econ_production_limits, const double max_wgr_limit = econ_production_limits.maxWaterGasRatio(); assert(max_wgr_limit > 0.); - const bool wgr_limit_violated = checkMaxRatioLimitWell(well_state, max_wgr_limit, wgr); + const bool wgr_limit_violated = checkMaxRatioLimitWell(ws, max_wgr_limit, wgr); if (wgr_limit_violated) { report.ratio_limit_violated = true; - checkMaxRatioLimitCompletions(well_state, max_wgr_limit, wgr, report); + checkMaxRatioLimitCompletions(ws, max_wgr_limit, wgr, report); } } @@ -636,7 +630,7 @@ template void WellInterfaceFluidSystem:: checkRatioEconLimits(const WellEconProductionLimits& econ_production_limits, - const WellState& well_state, + const SingleWellState& ws, RatioLimitCheckReport& report, DeferredLogger& deferred_logger) const { @@ -649,15 +643,15 @@ checkRatioEconLimits(const WellEconProductionLimits& econ_production_limits, // extent. if (econ_production_limits.onMaxWaterCut()) { - checkMaxWaterCutLimit(econ_production_limits, well_state, report); + checkMaxWaterCutLimit(econ_production_limits, ws, report); } if (econ_production_limits.onMaxGasOilRatio()) { - checkMaxGORLimit(econ_production_limits, well_state, report); + checkMaxGORLimit(econ_production_limits, ws, report); } if (econ_production_limits.onMaxWaterGasRatio()) { - checkMaxWGRLimit(econ_production_limits, well_state, report); + checkMaxWGRLimit(econ_production_limits, ws, report); } if (econ_production_limits.onMaxGasLiquidRatio()) { @@ -673,7 +667,7 @@ checkRatioEconLimits(const WellEconProductionLimits& econ_production_limits, template void WellInterfaceFluidSystem:: -updateWellTestStateEconomic(const WellState& well_state, +updateWellTestStateEconomic(const SingleWellState& ws, const double simulation_time, const bool write_message_to_opmlog, WellTestState& well_test_state, @@ -693,7 +687,6 @@ updateWellTestStateEconomic(const WellState& well_state, bool rate_limit_violated = false; const auto& quantity_limit = econ_production_limits.quantityLimit(); - const auto& ws = well_state.well(this->index_of_well_); if (econ_production_limits.onAnyRateLimit()) { if (quantity_limit == WellEconProductionLimits::QuantityLimit::POTN) rate_limit_violated = checkRateEconLimits(econ_production_limits, ws.well_potentials.data(), deferred_logger); @@ -738,7 +731,7 @@ updateWellTestStateEconomic(const WellState& well_state, // checking for ratio related limits, mostly all kinds of ratio. RatioLimitCheckReport ratio_report; - checkRatioEconLimits(econ_production_limits, well_state, ratio_report, deferred_logger); + checkRatioEconLimits(econ_production_limits, ws, ratio_report, deferred_logger); if (ratio_report.ratio_limit_violated) { const auto workover = econ_production_limits.workover(); @@ -812,7 +805,7 @@ updateWellTestStateEconomic(const WellState& well_state, template void WellInterfaceFluidSystem:: -updateWellTestState(const WellState& well_state, +updateWellTestState(const SingleWellState& ws, const double& simulationTime, const bool& writeMessageToOPMLog, WellTestState& wellTestState, @@ -831,10 +824,10 @@ updateWellTestState(const WellState& well_state, } // updating well test state based on physical (THP/BHP) limits. - updateWellTestStatePhysical(well_state, simulationTime, writeMessageToOPMLog, wellTestState, deferred_logger); + updateWellTestStatePhysical(ws, simulationTime, writeMessageToOPMLog, wellTestState, deferred_logger); // updating well test state based on Economic limits. - updateWellTestStateEconomic(well_state, simulationTime, writeMessageToOPMLog, wellTestState, deferred_logger); + updateWellTestStateEconomic(ws, simulationTime, writeMessageToOPMLog, wellTestState, deferred_logger); // TODO: well can be shut/closed due to other reasons } @@ -842,7 +835,7 @@ updateWellTestState(const WellState& well_state, template template void WellInterfaceFluidSystem:: -checkMaxRatioLimitCompletions(const WellState& well_state, +checkMaxRatioLimitCompletions(const SingleWellState& ws, const double max_ratio_limit, const RatioFunc& ratioFunc, RatioLimitCheckReport& report) const @@ -854,7 +847,6 @@ checkMaxRatioLimitCompletions(const WellState& well_state, double max_ratio_completion = 0; const int np = number_of_phases_; - const auto& ws = well_state.well(this->index_of_well_); const auto& perf_data = ws.perf_data; const auto& perf_phase_rates = perf_data.phase_rates; // look for the worst_offending_completion @@ -893,14 +885,13 @@ checkMaxRatioLimitCompletions(const WellState& well_state, template template bool WellInterfaceFluidSystem:: -checkMaxRatioLimitWell(const WellState& well_state, +checkMaxRatioLimitWell(const SingleWellState& ws, const double max_ratio_limit, const RatioFunc& ratioFunc) const { const int np = number_of_phases_; std::vector well_rates(np, 0.0); - const auto& ws = well_state.well(this->index_of_well_); for (int p = 0; p < np; ++p) { well_rates[p] = ws.surface_rates[p]; } diff --git a/opm/simulators/wells/WellInterfaceFluidSystem.hpp b/opm/simulators/wells/WellInterfaceFluidSystem.hpp index 024712899..5bc838207 100644 --- a/opm/simulators/wells/WellInterfaceFluidSystem.hpp +++ b/opm/simulators/wells/WellInterfaceFluidSystem.hpp @@ -40,6 +40,7 @@ class Group; class GroupState; class Schedule; class WellState; +class SingleWellState; template class WellInterfaceFluidSystem : public WellInterfaceGeneric { @@ -50,7 +51,7 @@ protected: static constexpr int INVALIDCOMPLETION = std::numeric_limits::max(); public: - void updateWellTestState(const WellState& well_state, + void updateWellTestState(const SingleWellState& ws, const double& simulationTime, const bool& writeMessageToOPMLog, WellTestState& wellTestState, @@ -79,15 +80,15 @@ protected: const std::vector& perf_data); // updating the voidage rates in well_state when requested - void calculateReservoirRates(WellState& well_state) const; + void calculateReservoirRates(SingleWellState& ws) const; - bool checkIndividualConstraints(WellState& well_state, + bool checkIndividualConstraints(SingleWellState& ws, const SummaryState& summaryState) const; - Well::InjectorCMode activeInjectionConstraint(const WellState& well_state, + Well::InjectorCMode activeInjectionConstraint(const SingleWellState& ws, const SummaryState& summaryState) const; - Well::ProducerCMode activeProductionConstraint(const WellState& well_state, + Well::ProducerCMode activeProductionConstraint(const SingleWellState& ws, const SummaryState& summaryState) const; std::pair checkGroupConstraintsInj(const Group& group, @@ -129,23 +130,23 @@ protected: }; void checkMaxWaterCutLimit(const WellEconProductionLimits& econ_production_limits, - const WellState& well_state, + const SingleWellState& ws, RatioLimitCheckReport& report) const; void checkMaxGORLimit(const WellEconProductionLimits& econ_production_limits, - const WellState& well_state, + const SingleWellState& ws, RatioLimitCheckReport& report) const; void checkMaxWGRLimit(const WellEconProductionLimits& econ_production_limits, - const WellState& well_state, + const SingleWellState& ws, RatioLimitCheckReport& report) const; void checkRatioEconLimits(const WellEconProductionLimits& econ_production_limits, - const WellState& well_state, + const SingleWellState& ws, RatioLimitCheckReport& report, DeferredLogger& deferred_logger) const; - void updateWellTestStateEconomic(const WellState& well_state, + void updateWellTestStateEconomic(const SingleWellState& ws, const double simulation_time, const bool write_message_to_opmlog, WellTestState& well_test_state, @@ -174,13 +175,13 @@ protected: private: template - void checkMaxRatioLimitCompletions(const WellState& well_state, + void checkMaxRatioLimitCompletions(const SingleWellState& ws, const double max_ratio_limit, const RatioFunc& ratioFunc, RatioLimitCheckReport& report) const; template - bool checkMaxRatioLimitWell(const WellState& well_state, + bool checkMaxRatioLimitWell(const SingleWellState& well_state, const double max_ratio_limit, const RatioFunc& ratioFunc) const; }; diff --git a/opm/simulators/wells/WellInterfaceGeneric.cpp b/opm/simulators/wells/WellInterfaceGeneric.cpp index b15001c3e..b1ed7e7cb 100644 --- a/opm/simulators/wells/WellInterfaceGeneric.cpp +++ b/opm/simulators/wells/WellInterfaceGeneric.cpp @@ -347,7 +347,7 @@ bool WellInterfaceGeneric::isVFPActive(DeferredLogger& deferred_logger) const } } -void WellInterfaceGeneric::updateWellTestStatePhysical(const WellState& /* well_state */, +void WellInterfaceGeneric::updateWellTestStatePhysical(const SingleWellState& /* well_state */, const double simulation_time, const bool write_message_to_opmlog, WellTestState& well_test_state, diff --git a/opm/simulators/wells/WellInterfaceGeneric.hpp b/opm/simulators/wells/WellInterfaceGeneric.hpp index c22033df9..a1368465c 100644 --- a/opm/simulators/wells/WellInterfaceGeneric.hpp +++ b/opm/simulators/wells/WellInterfaceGeneric.hpp @@ -43,6 +43,7 @@ class SummaryState; class VFPProperties; class WellTestState; class WellState; +class SingleWellState; class GroupState; class Group; class Schedule; @@ -171,7 +172,7 @@ public: protected: bool getAllowCrossFlow() const; double mostStrictBhpFromBhpLimits(const SummaryState& summaryState) const; - void updateWellTestStatePhysical(const WellState& well_state, + void updateWellTestStatePhysical(const SingleWellState& ws, const double simulation_time, const bool write_message_to_opmlog, WellTestState& well_test_state, diff --git a/opm/simulators/wells/WellInterface_impl.hpp b/opm/simulators/wells/WellInterface_impl.hpp index 68e8cce20..6f687fd2c 100644 --- a/opm/simulators/wells/WellInterface_impl.hpp +++ b/opm/simulators/wells/WellInterface_impl.hpp @@ -175,7 +175,7 @@ namespace Opm bool changed = false; if (iog == IndividualOrGroup::Individual) { - changed = this->checkIndividualConstraints(well_state, summaryState); + changed = this->checkIndividualConstraints(ws, summaryState); } else if (iog == IndividualOrGroup::Group) { changed = this->checkGroupConstraints(well_state, group_state, schedule, summaryState, deferred_logger); } else { @@ -273,7 +273,7 @@ namespace Opm for (int p = 0; p < np; ++p) { ws.well_potentials[p] = std::abs(potentials[p]); } - this->updateWellTestState(well_state_copy, simulation_time, /*writeMessageToOPMLog=*/ false, welltest_state_temp, deferred_logger); + this->updateWellTestState(well_state_copy.well(this->indexOfWell()), simulation_time, /*writeMessageToOPMLog=*/ false, welltest_state_temp, deferred_logger); this->closeCompletions(welltest_state_temp); // Stop testing if the well is closed or shut due to all completions shut