From 4fcb1e9d37830eb45dfdcabdfd869b075fd2f5ee Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 19 Oct 2022 09:55:14 +0200 Subject: [PATCH] changed: move calculateThpFromBhp to WellBhpThpCalculator --- opm/simulators/wells/MultisegmentWellEval.cpp | 7 ++- .../wells/MultisegmentWellGeneric.cpp | 41 ---------------- .../wells/MultisegmentWellGeneric.hpp | 5 -- .../wells/MultisegmentWell_impl.hpp | 6 ++- opm/simulators/wells/StandardWellEval.cpp | 10 ++-- opm/simulators/wells/StandardWellGeneric.cpp | 42 ---------------- opm/simulators/wells/StandardWellGeneric.hpp | 5 -- opm/simulators/wells/StandardWell_impl.hpp | 6 ++- opm/simulators/wells/WellBhpThpCalculator.cpp | 48 +++++++++++++++++++ opm/simulators/wells/WellBhpThpCalculator.hpp | 8 ++++ 10 files changed, 78 insertions(+), 100 deletions(-) diff --git a/opm/simulators/wells/MultisegmentWellEval.cpp b/opm/simulators/wells/MultisegmentWellEval.cpp index 82a96b1c7..697277b18 100644 --- a/opm/simulators/wells/MultisegmentWellEval.cpp +++ b/opm/simulators/wells/MultisegmentWellEval.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -1306,7 +1307,11 @@ updateThp(WellState& well_state, rates[ Gas ] = ws.surface_rates[pu.phase_pos[ Gas ] ]; } - ws.thp = this->calculateThpFromBhp(rates, ws.bhp, rho, deferred_logger); + ws.thp = WellBhpThpCalculator(baseif_).calculateThpFromBhp(rates, + ws.bhp, + rho, + baseif_.wellEcl().alq_value(), + deferred_logger); } template diff --git a/opm/simulators/wells/MultisegmentWellGeneric.cpp b/opm/simulators/wells/MultisegmentWellGeneric.cpp index c7333e6e7..e0d2d99f0 100644 --- a/opm/simulators/wells/MultisegmentWellGeneric.cpp +++ b/opm/simulators/wells/MultisegmentWellGeneric.cpp @@ -178,47 +178,6 @@ segmentNumberToIndex(const int segment_number) const return segmentSet().segmentNumberToIndex(segment_number); } -template -double -MultisegmentWellGeneric:: -calculateThpFromBhp(const std::vector& rates, - const double bhp, - const double rho, - DeferredLogger& deferred_logger) const -{ - assert(int(rates.size()) == 3); // the vfp related only supports three phases now. - - static constexpr int Water = BlackoilPhases::Aqua; - static constexpr int Oil = BlackoilPhases::Liquid; - static constexpr int Gas = BlackoilPhases::Vapour; - - const double aqua = rates[Water]; - const double liquid = rates[Oil]; - const double vapour = rates[Gas]; - - double thp = 0.0; - if (baseif_.isInjector()) { - const int table_id = baseif_.wellEcl().vfp_table_number(); - const double vfp_ref_depth = baseif_.vfpProperties()->getInj()->getTable(table_id).getDatumDepth(); - const double dp = wellhelpers::computeHydrostaticCorrection(baseif_.refDepth(), vfp_ref_depth, rho, baseif_.gravity()); - - thp = baseif_.vfpProperties()->getInj()->thp(table_id, aqua, liquid, vapour, bhp + dp); - } - else if (baseif_.isProducer()) { - const int table_id = baseif_.wellEcl().vfp_table_number(); - const double alq = baseif_.wellEcl().alq_value(); - const double vfp_ref_depth = baseif_.vfpProperties()->getProd()->getTable(table_id).getDatumDepth(); - const double dp = wellhelpers::computeHydrostaticCorrection(baseif_.refDepth(), vfp_ref_depth, rho, baseif_.gravity()); - - thp = baseif_.vfpProperties()->getProd()->thp(table_id, aqua, liquid, vapour, bhp + dp, alq); - } - else { - OPM_DEFLOG_THROW(std::logic_error, "Expected INJECTOR or PRODUCER well", deferred_logger); - } - - return thp; -} - template void MultisegmentWellGeneric:: diff --git a/opm/simulators/wells/MultisegmentWellGeneric.hpp b/opm/simulators/wells/MultisegmentWellGeneric.hpp index 9c8d2b47e..b8e3dd4a7 100644 --- a/opm/simulators/wells/MultisegmentWellGeneric.hpp +++ b/opm/simulators/wells/MultisegmentWellGeneric.hpp @@ -60,11 +60,6 @@ protected: /// number of segments for this well int numberOfSegments() const; - double calculateThpFromBhp(const std::vector& rates, - const double bhp, - const double rho, - DeferredLogger& deferred_logger) const; - std::optional computeBhpAtThpLimitInj(const std::function(const double)>& frates, const SummaryState& summary_state, const double rho, diff --git a/opm/simulators/wells/MultisegmentWell_impl.hpp b/opm/simulators/wells/MultisegmentWell_impl.hpp index 5eb29d940..ce501c1ed 100644 --- a/opm/simulators/wells/MultisegmentWell_impl.hpp +++ b/opm/simulators/wells/MultisegmentWell_impl.hpp @@ -1269,7 +1269,11 @@ namespace Opm std::vector well_rates_bhp_limit; computeWellRatesWithBhp(ebos_simulator, bhp_limit, well_rates_bhp_limit, deferred_logger); - const double thp = this->calculateThpFromBhp(well_rates_bhp_limit, bhp_limit, getRefDensity(), deferred_logger); + const double thp = WellBhpThpCalculator(*this).calculateThpFromBhp(well_rates_bhp_limit, + bhp_limit, + this->getRefDensity(), + this->wellEcl().alq_value(), + deferred_logger); const double thp_limit = this->getTHPConstraint(summaryState); if ( (this->isProducer() && thp < thp_limit) || (this->isInjector() && thp > thp_limit) ) { this->operability_status_.obey_thp_limit_under_bhp_limit = false; diff --git a/opm/simulators/wells/StandardWellEval.cpp b/opm/simulators/wells/StandardWellEval.cpp index d21537b04..4f016d43d 100644 --- a/opm/simulators/wells/StandardWellEval.cpp +++ b/opm/simulators/wells/StandardWellEval.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -595,10 +596,11 @@ updateThp(WellState& well_state, rates[ Gas ] = ws.surface_rates[pu.phase_pos[ Gas ] ]; } - ws.thp = this->calculateThpFromBhp(well_state, - rates, - ws.bhp, - deferred_logger); + ws.thp = WellBhpThpCalculator(this->baseif_).calculateThpFromBhp(rates, + ws.bhp, + this->getRho(), + this->baseif_.getALQ(well_state), + deferred_logger); } template diff --git a/opm/simulators/wells/StandardWellGeneric.cpp b/opm/simulators/wells/StandardWellGeneric.cpp index 7159a6438..b780ca1ed 100644 --- a/opm/simulators/wells/StandardWellGeneric.cpp +++ b/opm/simulators/wells/StandardWellGeneric.cpp @@ -112,48 +112,6 @@ relaxationFactorFraction(const double old_value, return relaxation_factor; } -template -double -StandardWellGeneric:: -calculateThpFromBhp(const WellState &well_state, - const std::vector& rates, - const double bhp, - DeferredLogger& deferred_logger) const -{ - assert(int(rates.size()) == 3); // the vfp related only supports three phases now. - - static constexpr int Water = BlackoilPhases::Aqua; - static constexpr int Oil = BlackoilPhases::Liquid; - static constexpr int Gas = BlackoilPhases::Vapour; - - const double aqua = rates[Water]; - const double liquid = rates[Oil]; - const double vapour = rates[Gas]; - - // pick the density in the top layer - double thp = 0.0; - if (baseif_.isInjector()) { - const int table_id = baseif_.wellEcl().vfp_table_number(); - const double vfp_ref_depth = baseif_.vfpProperties()->getInj()->getTable(table_id).getDatumDepth(); - const double dp = wellhelpers::computeHydrostaticCorrection(baseif_.refDepth(), vfp_ref_depth, getRho(), baseif_.gravity()); - - thp = baseif_.vfpProperties()->getInj()->thp(table_id, aqua, liquid, vapour, bhp + dp); - } - else if (baseif_.isProducer()) { - const int table_id = baseif_.wellEcl().vfp_table_number(); - const double alq = baseif_.getALQ(well_state); - const double vfp_ref_depth = baseif_.vfpProperties()->getProd()->getTable(table_id).getDatumDepth(); - const double dp = wellhelpers::computeHydrostaticCorrection(baseif_.refDepth(), vfp_ref_depth, getRho(), baseif_.gravity()); - - thp = baseif_.vfpProperties()->getProd()->thp(table_id, aqua, liquid, vapour, bhp + dp, alq); - } - else { - OPM_DEFLOG_THROW(std::logic_error, "Expected INJECTOR or PRODUCER well", deferred_logger); - } - - return thp; -} - template void StandardWellGeneric:: diff --git a/opm/simulators/wells/StandardWellGeneric.hpp b/opm/simulators/wells/StandardWellGeneric.hpp index e55c988c6..839b3e050 100644 --- a/opm/simulators/wells/StandardWellGeneric.hpp +++ b/opm/simulators/wells/StandardWellGeneric.hpp @@ -79,11 +79,6 @@ protected: static double relaxationFactorFraction(const double old_value, const double dx); - double calculateThpFromBhp(const WellState& well_state, - const std::vector& rates, - const double bhp, - DeferredLogger& deferred_logger) const; - void computeConnectionPressureDelta(); std::optional computeBhpAtThpLimitInj(const std::function(const double)>& frates, diff --git a/opm/simulators/wells/StandardWell_impl.hpp b/opm/simulators/wells/StandardWell_impl.hpp index d72311a0a..4a0f7da59 100644 --- a/opm/simulators/wells/StandardWell_impl.hpp +++ b/opm/simulators/wells/StandardWell_impl.hpp @@ -1136,7 +1136,11 @@ namespace Opm computeWellRatesWithBhp(ebos_simulator, bhp_limit, well_rates_bhp_limit, deferred_logger); this->adaptRatesForVFP(well_rates_bhp_limit); - const double thp = this->calculateThpFromBhp(well_state, well_rates_bhp_limit, bhp_limit, deferred_logger); + const double thp = WellBhpThpCalculator(*this).calculateThpFromBhp(well_rates_bhp_limit, + bhp_limit, + this->getRho(), + this->getALQ(well_state), + deferred_logger); const double thp_limit = this->getTHPConstraint(summaryState); if ( (this->isProducer() && thp < thp_limit) || (this->isInjector() && thp > thp_limit) ) { this->operability_status_.obey_thp_limit_under_bhp_limit = false; diff --git a/opm/simulators/wells/WellBhpThpCalculator.cpp b/opm/simulators/wells/WellBhpThpCalculator.cpp index ba9cdc71a..56ad605df 100644 --- a/opm/simulators/wells/WellBhpThpCalculator.cpp +++ b/opm/simulators/wells/WellBhpThpCalculator.cpp @@ -22,10 +22,19 @@ #include #include +#include + +#include #include +#include + +#include +#include #include +#include + namespace Opm { @@ -80,4 +89,43 @@ double WellBhpThpCalculator::mostStrictBhpFromBhpLimits(const SummaryState& summ return 0.0; } +double WellBhpThpCalculator::calculateThpFromBhp(const std::vector& rates, + const double bhp, + const double rho, + const double alq, + DeferredLogger& deferred_logger) const +{ + assert(int(rates.size()) == 3); // the vfp related only supports three phases now. + + static constexpr int Water = BlackoilPhases::Aqua; + static constexpr int Oil = BlackoilPhases::Liquid; + static constexpr int Gas = BlackoilPhases::Vapour; + + const double aqua = rates[Water]; + const double liquid = rates[Oil]; + const double vapour = rates[Gas]; + + // pick the density in the top layer + double thp = 0.0; + if (well_.isInjector()) { + const int table_id = well_.wellEcl().vfp_table_number(); + const double vfp_ref_depth = well_.vfpProperties()->getInj()->getTable(table_id).getDatumDepth(); + const double dp = wellhelpers::computeHydrostaticCorrection(well_.refDepth(), vfp_ref_depth, rho, well_.gravity()); + + thp = well_.vfpProperties()->getInj()->thp(table_id, aqua, liquid, vapour, bhp + dp); + } + else if (well_.isProducer()) { + const int table_id = well_.wellEcl().vfp_table_number(); + const double vfp_ref_depth = well_.vfpProperties()->getProd()->getTable(table_id).getDatumDepth(); + const double dp = wellhelpers::computeHydrostaticCorrection(well_.refDepth(), vfp_ref_depth, rho, well_.gravity()); + + thp = well_.vfpProperties()->getProd()->thp(table_id, aqua, liquid, vapour, bhp + dp, alq); + } + else { + OPM_DEFLOG_THROW(std::logic_error, "Expected INJECTOR or PRODUCER well", deferred_logger); + } + + return thp; +} + } // namespace Opm diff --git a/opm/simulators/wells/WellBhpThpCalculator.hpp b/opm/simulators/wells/WellBhpThpCalculator.hpp index ba7af9e2d..975e151cf 100644 --- a/opm/simulators/wells/WellBhpThpCalculator.hpp +++ b/opm/simulators/wells/WellBhpThpCalculator.hpp @@ -32,6 +32,7 @@ namespace Opm { +class DeferredLogger; class SummaryState; class WellInterfaceGeneric; @@ -50,6 +51,13 @@ public: //! \brief Obtain the most strict BHP from BHP limits. double mostStrictBhpFromBhpLimits(const SummaryState& summaryState) const; + //! \brief Calculates THP from BHP. + double calculateThpFromBhp(const std::vector& rates, + const double bhp, + const double rho, + const double alq, + DeferredLogger& deferred_logger) const; + private: const WellInterfaceGeneric& well_; //!< Reference to well interface };