From 9304542dbe1a13a9b8668f3ac6bf74ec1611e691 Mon Sep 17 00:00:00 2001 From: Kai Bao Date: Wed, 29 Mar 2023 14:33:05 +0200 Subject: [PATCH] combining wellIsStopped and wellUnderZeroRateTaget for better readability. --- .../wells/MultisegmentWellAssemble.cpp | 2 +- .../wells/MultisegmentWellPrimaryVariables.cpp | 12 ++++++------ .../wells/MultisegmentWellPrimaryVariables.hpp | 6 +++--- opm/simulators/wells/MultisegmentWell_impl.hpp | 10 +++++----- opm/simulators/wells/StandardWell.hpp | 4 ++-- opm/simulators/wells/StandardWellAssemble.cpp | 2 +- opm/simulators/wells/StandardWellEval.cpp | 4 ++-- opm/simulators/wells/StandardWellEval.hpp | 2 +- .../wells/StandardWellPrimaryVariables.cpp | 8 ++++---- .../wells/StandardWellPrimaryVariables.hpp | 4 ++-- opm/simulators/wells/StandardWell_impl.hpp | 18 +++++++++--------- opm/simulators/wells/WellBhpThpCalculator.cpp | 4 ++-- opm/simulators/wells/WellBhpThpCalculator.hpp | 2 +- opm/simulators/wells/WellInterfaceGeneric.cpp | 13 +++++++++---- opm/simulators/wells/WellInterfaceGeneric.hpp | 6 ++++-- opm/simulators/wells/WellInterface_impl.hpp | 2 +- 16 files changed, 53 insertions(+), 46 deletions(-) diff --git a/opm/simulators/wells/MultisegmentWellAssemble.cpp b/opm/simulators/wells/MultisegmentWellAssemble.cpp index 1655e4256..e37eabf51 100644 --- a/opm/simulators/wells/MultisegmentWellAssemble.cpp +++ b/opm/simulators/wells/MultisegmentWellAssemble.cpp @@ -116,7 +116,7 @@ assembleControlEq(const WellState& well_state, return rates; }; - if (well_.wellUnderZeroRateControl(summaryState, well_state)) { + if (well_.stopppedOrZeroRateTarget(summaryState, well_state)) { control_eq = primary_variables.getWQTotal(); } else if (well_.isInjector() ) { // Find scaling factor to get injection rate, diff --git a/opm/simulators/wells/MultisegmentWellPrimaryVariables.cpp b/opm/simulators/wells/MultisegmentWellPrimaryVariables.cpp index 368101606..01136cbd7 100644 --- a/opm/simulators/wells/MultisegmentWellPrimaryVariables.cpp +++ b/opm/simulators/wells/MultisegmentWellPrimaryVariables.cpp @@ -64,7 +64,7 @@ init() template void MultisegmentWellPrimaryVariables:: -update(const WellState& well_state, const bool zero_rate_target) +update(const WellState& well_state, const bool stop_or_zero_rate_target) { static constexpr int Water = BlackoilPhases::Aqua; static constexpr int Gas = BlackoilPhases::Vapour; @@ -104,7 +104,7 @@ update(const WellState& well_state, const bool zero_rate_target) } } value_[seg][WQTotal] = total_seg_rate; - if (zero_rate_target && seg == 0) { + if (stop_or_zero_rate_target && seg == 0) { value_[seg][WQTotal] = 0; } if (std::abs(total_seg_rate) > 0.) { @@ -155,7 +155,7 @@ void MultisegmentWellPrimaryVariables:: updateNewton(const BVectorWell& dwells, const double relaxation_factor, const double dFLimit, - const bool zero_rate_target, + const bool stop_or_zero_rate_target, const double max_pressure_change) { const std::vector> old_primary_variables = value_; @@ -198,7 +198,7 @@ updateNewton(const BVectorWell& dwells, } } - if (zero_rate_target) { + if (stop_or_zero_rate_target) { value_[0][WQTotal] = 0.; } } @@ -207,7 +207,7 @@ template void MultisegmentWellPrimaryVariables:: copyToWellState(const MultisegmentWellGeneric& mswell, const double rho, - const bool zero_rate_target, + const bool stop_or_zero_rate_target, WellState& well_state, DeferredLogger& deferred_logger) const { @@ -394,7 +394,7 @@ copyToWellState(const MultisegmentWellGeneric& mswell, } WellBhpThpCalculator(well_) - .updateThp(rho, zero_rate_target, [this]() { return well_.wellEcl().alq_value(); }, + .updateThp(rho, stop_or_zero_rate_target, [this]() { return well_.wellEcl().alq_value(); }, {FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx), FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx), FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)}, diff --git a/opm/simulators/wells/MultisegmentWellPrimaryVariables.hpp b/opm/simulators/wells/MultisegmentWellPrimaryVariables.hpp index 4d5630617..dde7a3f9a 100644 --- a/opm/simulators/wells/MultisegmentWellPrimaryVariables.hpp +++ b/opm/simulators/wells/MultisegmentWellPrimaryVariables.hpp @@ -88,19 +88,19 @@ public: void init(); //! \brief Copy values from well state. - void update(const WellState& well_state, const bool zero_rate_target); + void update(const WellState& well_state, const bool stop_or_zero_rate_target); //! \brief Update values from newton update vector. void updateNewton(const BVectorWell& dwells, const double relaxation_factor, const double DFLimit, - const bool zero_rate_target, + const bool stop_or_zero_rate_target, const double max_pressure_change); //! \brief Copy values to well state. void copyToWellState(const MultisegmentWellGeneric& mswell, const double rho, - const bool zero_rate_target, + const bool stop_or_zero_rate_target, WellState& well_state, DeferredLogger& deferred_logger) const; diff --git a/opm/simulators/wells/MultisegmentWell_impl.hpp b/opm/simulators/wells/MultisegmentWell_impl.hpp index 9491bff20..53aae50ab 100644 --- a/opm/simulators/wells/MultisegmentWell_impl.hpp +++ b/opm/simulators/wells/MultisegmentWell_impl.hpp @@ -152,8 +152,8 @@ namespace Opm const WellState& well_state, DeferredLogger& /* deferred_logger */) { - const bool zero_rate_target = this->wellUnderZeroRateControl(summary_state, well_state); - this->primary_variables_.update(well_state, zero_rate_target); + const bool stop_or_zero_rate_target = this->stopppedOrZeroRateTarget(summary_state, well_state); + this->primary_variables_.update(well_state, stop_or_zero_rate_target); } @@ -615,14 +615,14 @@ namespace Opm const double dFLimit = this->param_.dwell_fraction_max_; const double max_pressure_change = this->param_.max_pressure_change_ms_wells_; - const bool zero_rate_target = this->wellUnderZeroRateControl(summary_state, well_state); + const bool stop_or_zero_rate_target = this->stopppedOrZeroRateTarget(summary_state, well_state); this->primary_variables_.updateNewton(dwells, relaxation_factor, dFLimit, - zero_rate_target, + stop_or_zero_rate_target, max_pressure_change); - this->primary_variables_.copyToWellState(*this, getRefDensity(), zero_rate_target, + this->primary_variables_.copyToWellState(*this, getRefDensity(), stop_or_zero_rate_target, well_state, deferred_logger); Base::calculateReservoirRates(well_state.well(this->index_of_well_)); } diff --git a/opm/simulators/wells/StandardWell.hpp b/opm/simulators/wells/StandardWell.hpp index ba7d3829d..df3fdcb15 100644 --- a/opm/simulators/wells/StandardWell.hpp +++ b/opm/simulators/wells/StandardWell.hpp @@ -365,10 +365,10 @@ namespace Opm DeferredLogger& deferred_logger) const; void updatePrimaryVariablesNewton(const BVectorWell& dwells, - const bool zero_rate_target, + const bool stop_or_zero_rate_target, DeferredLogger& deferred_logger); - void updateWellStateFromPrimaryVariables(const bool zero_rate_target, + void updateWellStateFromPrimaryVariables(const bool stop_or_zero_rate_target, WellState& well_state, DeferredLogger& deferred_logger) const; diff --git a/opm/simulators/wells/StandardWellAssemble.cpp b/opm/simulators/wells/StandardWellAssemble.cpp index bb5e76dba..45e2f4fd7 100644 --- a/opm/simulators/wells/StandardWellAssemble.cpp +++ b/opm/simulators/wells/StandardWellAssemble.cpp @@ -116,7 +116,7 @@ assembleControlEq(const WellState& well_state, return rates; }; - if (well_.wellUnderZeroRateControl(summaryState, well_state)) { + if (well_.stopppedOrZeroRateTarget(summaryState, well_state)) { control_eq = primary_variables.eval(PrimaryVariables::WQTotal); } else if (well_.isInjector()) { // Find injection rate. diff --git a/opm/simulators/wells/StandardWellEval.cpp b/opm/simulators/wells/StandardWellEval.cpp index da13a574a..18e8d5933 100644 --- a/opm/simulators/wells/StandardWellEval.cpp +++ b/opm/simulators/wells/StandardWellEval.cpp @@ -71,7 +71,7 @@ extendEval(const Eval& in) const template void StandardWellEval:: -updateWellStateFromPrimaryVariables(const bool zero_rate_target, +updateWellStateFromPrimaryVariables(const bool stop_or_zero_rate_target, WellState& well_state, DeferredLogger& deferred_logger) const { @@ -79,7 +79,7 @@ updateWellStateFromPrimaryVariables(const bool zero_rate_target, WellBhpThpCalculator(baseif_). updateThp(connections_.rho(), - zero_rate_target, + stop_or_zero_rate_target, [this,&well_state]() { return this->baseif_.getALQ(well_state); }, {FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx), FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx), diff --git a/opm/simulators/wells/StandardWellEval.hpp b/opm/simulators/wells/StandardWellEval.hpp index ff0c960de..ecd6b0e3f 100644 --- a/opm/simulators/wells/StandardWellEval.hpp +++ b/opm/simulators/wells/StandardWellEval.hpp @@ -92,7 +92,7 @@ protected: const int num_cells, const bool has_polymermw); - void updateWellStateFromPrimaryVariables(const bool zero_rate_target, + void updateWellStateFromPrimaryVariables(const bool stop_or_zero_rate_target, WellState& well_state, DeferredLogger& deferred_logger) const; diff --git a/opm/simulators/wells/StandardWellPrimaryVariables.cpp b/opm/simulators/wells/StandardWellPrimaryVariables.cpp index 82858d956..462341d2e 100644 --- a/opm/simulators/wells/StandardWellPrimaryVariables.cpp +++ b/opm/simulators/wells/StandardWellPrimaryVariables.cpp @@ -122,7 +122,7 @@ resize(const int numWellEq) template void StandardWellPrimaryVariables:: update(const WellState& well_state, - const bool zero_rate_target, + const bool stop_or_zero_rate_target, DeferredLogger& deferred_logger) { static constexpr int Water = BlackoilPhases::Aqua; @@ -160,7 +160,7 @@ update(const WellState& well_state, } } else { value_[WQTotal] = total_well_rate; - if (zero_rate_target) { + if (stop_or_zero_rate_target) { value_[WQTotal] = 0.; } } @@ -245,7 +245,7 @@ updatePolyMW(const WellState& well_state) template void StandardWellPrimaryVariables:: updateNewton(const BVectorWell& dwells, - const bool zero_rate_target, + const bool stop_or_zero_rate_target, [[maybe_unused]] const double dFLimit, const double dBHPLimit) { @@ -281,7 +281,7 @@ updateNewton(const BVectorWell& dwells, // updating the total rates Q_t value_[WQTotal] = value_[WQTotal] - dwells[0][WQTotal] * relaxation_factor_rate; - if (zero_rate_target) { + if (stop_or_zero_rate_target) { value_[WQTotal] = 0.; } // TODO: here, we make sure it is zero for zero rated wells diff --git a/opm/simulators/wells/StandardWellPrimaryVariables.hpp b/opm/simulators/wells/StandardWellPrimaryVariables.hpp index aecf29a4b..05e3b04d5 100644 --- a/opm/simulators/wells/StandardWellPrimaryVariables.hpp +++ b/opm/simulators/wells/StandardWellPrimaryVariables.hpp @@ -102,7 +102,7 @@ public: //! \brief Copy values from well state. void update(const WellState& well_state, - const bool zero_rate_target, + const bool stop_or_zero_rate_target, DeferredLogger& deferred_logger); //! \brief Copy polymer molecular weigt values from well state. @@ -110,7 +110,7 @@ public: //! \brief Update values from newton update vector. void updateNewton(const BVectorWell& dwells, - const bool zero_rate_target, + const bool stop_or_zero_rate_target, const double dFLimit, const double dBHPLimit); diff --git a/opm/simulators/wells/StandardWell_impl.hpp b/opm/simulators/wells/StandardWell_impl.hpp index aaef3656a..757c9393d 100644 --- a/opm/simulators/wells/StandardWell_impl.hpp +++ b/opm/simulators/wells/StandardWell_impl.hpp @@ -1000,10 +1000,10 @@ namespace Opm { if (!this->isOperableAndSolvable() && !this->wellIsStopped()) return; - const bool zero_rate_target = this->wellUnderZeroRateControl(summary_state, well_state); - updatePrimaryVariablesNewton(dwells, zero_rate_target, deferred_logger); + const bool stop_or_zero_rate_target = this->stopppedOrZeroRateTarget(summary_state, well_state); + updatePrimaryVariablesNewton(dwells, stop_or_zero_rate_target, deferred_logger); - updateWellStateFromPrimaryVariables(zero_rate_target, well_state, deferred_logger); + updateWellStateFromPrimaryVariables(stop_or_zero_rate_target, well_state, deferred_logger); Base::calculateReservoirRates(well_state.well(this->index_of_well_)); } @@ -1015,12 +1015,12 @@ namespace Opm void StandardWell:: updatePrimaryVariablesNewton(const BVectorWell& dwells, - const bool zero_rate_target, + const bool stop_or_zero_rate_target, DeferredLogger& deferred_logger) { const double dFLimit = this->param_.dwell_fraction_max_; const double dBHPLimit = this->param_.dbhp_max_rel_; - this->primary_variables_.updateNewton(dwells, zero_rate_target, dFLimit, dBHPLimit); + this->primary_variables_.updateNewton(dwells, stop_or_zero_rate_target, dFLimit, dBHPLimit); // for the water velocity and skin pressure if constexpr (Base::has_polymermw) { @@ -1037,11 +1037,11 @@ namespace Opm template void StandardWell:: - updateWellStateFromPrimaryVariables(const bool zero_rate_target, + updateWellStateFromPrimaryVariables(const bool stop_or_zero_rate_target, WellState& well_state, DeferredLogger& deferred_logger) const { - this->StdWellEval::updateWellStateFromPrimaryVariables(zero_rate_target, well_state, deferred_logger); + this->StdWellEval::updateWellStateFromPrimaryVariables(stop_or_zero_rate_target, well_state, deferred_logger); // other primary variables related to polymer injectivity study if constexpr (Base::has_polymermw) { @@ -1984,8 +1984,8 @@ namespace Opm { if (!this->isOperableAndSolvable() && !this->wellIsStopped()) return; - const bool zero_rate_target = this->wellUnderZeroRateControl(summary_state, well_state); - this->primary_variables_.update(well_state, zero_rate_target, deferred_logger); + const bool stop_or_zero_rate_target = this->stopppedOrZeroRateTarget(summary_state, well_state); + this->primary_variables_.update(well_state, stop_or_zero_rate_target, deferred_logger); // other primary variables related to polymer injection if constexpr (Base::has_polymermw) { diff --git a/opm/simulators/wells/WellBhpThpCalculator.cpp b/opm/simulators/wells/WellBhpThpCalculator.cpp index 7cc184eeb..03b0e1c18 100644 --- a/opm/simulators/wells/WellBhpThpCalculator.cpp +++ b/opm/simulators/wells/WellBhpThpCalculator.cpp @@ -224,7 +224,7 @@ computeBhpAtThpLimitInj(const std::function(const double)>& } void WellBhpThpCalculator::updateThp(const double rho, - const bool zero_rate_target, + const bool stop_or_zero_rate_target, const std::function& alq_value, const std::array& active, WellState& well_state, @@ -236,7 +236,7 @@ void WellBhpThpCalculator::updateThp(const double rho, auto& ws = well_state.well(well_.indexOfWell()); // When there is no vaild VFP table provided, we set the thp to be zero. - if (!well_.isVFPActive(deferred_logger) || well_.wellIsStopped() || zero_rate_target) { + if (!well_.isVFPActive(deferred_logger) || stop_or_zero_rate_target) { ws.thp = 0; return; } diff --git a/opm/simulators/wells/WellBhpThpCalculator.hpp b/opm/simulators/wells/WellBhpThpCalculator.hpp index 651ab2f55..6f03125eb 100644 --- a/opm/simulators/wells/WellBhpThpCalculator.hpp +++ b/opm/simulators/wells/WellBhpThpCalculator.hpp @@ -82,7 +82,7 @@ public: //! \brief Update THP. void updateThp(const double rho, - const bool zero_rate_target, + const bool stop_or_zero_rate_target, const std::function& alq_value, const std::array& active, WellState& well_state, diff --git a/opm/simulators/wells/WellInterfaceGeneric.cpp b/opm/simulators/wells/WellInterfaceGeneric.cpp index 3a2290103..710aad7ac 100644 --- a/opm/simulators/wells/WellInterfaceGeneric.cpp +++ b/opm/simulators/wells/WellInterfaceGeneric.cpp @@ -452,11 +452,9 @@ bool WellInterfaceGeneric::isPressureControlled(const WellState& well_state) con -bool WellInterfaceGeneric::wellUnderZeroRateControl(const SummaryState& summary_state, - const WellState& well_state) const +bool WellInterfaceGeneric::wellUnderZeroRateTarget(const SummaryState& summary_state, + const WellState& well_state) const { - if (this->wellIsStopped()) return true; - if (this->isProducer()) { // producers const auto prod_controls = this->well_ecl_.productionControls(summary_state); const auto prod_mode = well_state.well(this->indexOfWell()).production_cmode; @@ -468,6 +466,13 @@ bool WellInterfaceGeneric::wellUnderZeroRateControl(const SummaryState& summary_ } } +bool WellInterfaceGeneric::stopppedOrZeroRateTarget(const SummaryState& summary_state, + const WellState& well_state) const +{ + return (this->wellIsStopped() || this->wellUnderZeroRateTarget(summary_state, well_state)); + +} + double WellInterfaceGeneric::wmicrobes_() const { auto injectorType = this->well_ecl_.injectorType(); diff --git a/opm/simulators/wells/WellInterfaceGeneric.hpp b/opm/simulators/wells/WellInterfaceGeneric.hpp index 785299d41..674e50fff 100644 --- a/opm/simulators/wells/WellInterfaceGeneric.hpp +++ b/opm/simulators/wells/WellInterfaceGeneric.hpp @@ -195,9 +195,8 @@ public: bool isPressureControlled(const WellState& well_state) const; - bool wellUnderZeroRateControl(const SummaryState& summary_state, + bool stopppedOrZeroRateTarget(const SummaryState& summary_state, const WellState& well_state) const; - protected: bool getAllowCrossFlow() const; @@ -212,6 +211,9 @@ protected: int polymerInjTable_() const; int polymerWaterTable_() const; + bool wellUnderZeroRateTarget(const SummaryState& summary_state, + const WellState& well_state) const; + // definition of the struct OperabilityStatus struct OperabilityStatus { bool isOperableAndSolvable() const { diff --git a/opm/simulators/wells/WellInterface_impl.hpp b/opm/simulators/wells/WellInterface_impl.hpp index 53fb8d96f..dc9af269f 100644 --- a/opm/simulators/wells/WellInterface_impl.hpp +++ b/opm/simulators/wells/WellInterface_impl.hpp @@ -185,7 +185,7 @@ namespace Opm DeferredLogger& deferred_logger) /* const */ { const auto& summary_state = ebos_simulator.vanguard().summaryState(); - if (this->wellUnderZeroRateControl(summary_state, well_state)) { + if (this->stopppedOrZeroRateTarget(summary_state, well_state)) { return false; }