From 2f6623993ab40134024ead8234962a5c9159091c Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Mon, 22 May 2023 11:10:02 +0200 Subject: [PATCH] StandardWell: move connectionRateFoam to Connections class --- opm/simulators/wells/StandardWell.hpp | 4 -- .../wells/StandardWellConnections.cpp | 44 ++++++++++++++++- .../wells/StandardWellConnections.hpp | 6 +++ opm/simulators/wells/StandardWell_impl.hpp | 47 ++++--------------- 4 files changed, 57 insertions(+), 44 deletions(-) diff --git a/opm/simulators/wells/StandardWell.hpp b/opm/simulators/wells/StandardWell.hpp index b3b7c9598..5052eda59 100644 --- a/opm/simulators/wells/StandardWell.hpp +++ b/opm/simulators/wells/StandardWell.hpp @@ -443,10 +443,6 @@ namespace Opm const IntensiveQuantities& intQuants, DeferredLogger& deferred_logger) const; - Eval connectionRateFoam(const std::vector& cq_s, - const IntensiveQuantities& intQuants, - DeferredLogger& deferred_logger) const; - std::tuple connectionRatesMICP(const std::vector& cq_s, const IntensiveQuantities& intQuants) const; diff --git a/opm/simulators/wells/StandardWellConnections.cpp b/opm/simulators/wells/StandardWellConnections.cpp index 0e436f144..8e4e7e076 100644 --- a/opm/simulators/wells/StandardWellConnections.cpp +++ b/opm/simulators/wells/StandardWellConnections.cpp @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include #include @@ -539,8 +539,48 @@ connectionRateBrine(double& rate, return well_.restrictEval(cq_s_sm); } +template +typename StandardWellConnections::Eval +StandardWellConnections:: +connectionRateFoam(const std::vector& cq_s, + const std::variant& foamConcentration, + const Phase transportPhase, + DeferredLogger& deferred_logger) const +{ + // TODO: the application of well efficiency factor has not been tested with an example yet + auto getFoamTransportIdx = [&deferred_logger,transportPhase] { + switch (transportPhase) { + case Phase::WATER: { + return Indices::canonicalToActiveComponentIndex(FluidSystem::waterCompIdx); + } + case Phase::GAS: { + return Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx); + } + case Phase::SOLVENT: { + if constexpr (Indices::enableSolvent) + return static_cast(Indices::contiSolventEqIdx); + else + OPM_DEFLOG_THROW(std::runtime_error, "Foam transport phase is SOLVENT but SOLVENT is not activated.", deferred_logger); + } + default: { + OPM_DEFLOG_THROW(std::runtime_error, "Foam transport phase must be GAS/WATER/SOLVENT.", deferred_logger); + } + } + }; + + EvalWell cq_s_foam = cq_s[getFoamTransportIdx()] * well_.wellEfficiencyFactor();; + if (well_.isInjector()) { + cq_s_foam *= std::get(foamConcentration); + } else { + cq_s_foam *= std::get(foamConcentration); + } + + return well_.restrictEval(cq_s_foam); +} + #define INSTANCE(...) \ -template class StandardWellConnections,__VA_ARGS__,double>; +template class StandardWellConnections, \ + __VA_ARGS__,double>; // One phase INSTANCE(BlackOilOnePhaseIndices<0u,0u,0u,0u,false,false,0u,1u,0u>) diff --git a/opm/simulators/wells/StandardWellConnections.hpp b/opm/simulators/wells/StandardWellConnections.hpp index 2d4d3b9ec..878db2971 100644 --- a/opm/simulators/wells/StandardWellConnections.hpp +++ b/opm/simulators/wells/StandardWellConnections.hpp @@ -33,6 +33,7 @@ namespace Opm { class DeferredLogger; +enum class Phase; template class WellInterfaceIndices; class WellState; @@ -87,6 +88,11 @@ public: const std::vector& cq_s, const std::variant& saltConcentration) const; + Eval connectionRateFoam(const std::vector& cq_s, + const std::variant& foamConcentration, + const Phase transportPhase, + DeferredLogger& deferred_logger) const; + private: void computePressureDelta(); diff --git a/opm/simulators/wells/StandardWell_impl.hpp b/opm/simulators/wells/StandardWell_impl.hpp index d64225c41..6aeccbe58 100644 --- a/opm/simulators/wells/StandardWell_impl.hpp +++ b/opm/simulators/wells/StandardWell_impl.hpp @@ -537,8 +537,16 @@ namespace Opm } if constexpr (has_foam) { + std::variant foamConcentration; + if (this->isInjector()) { + foamConcentration = this->wfoam(); + } else { + foamConcentration = this->extendEval(intQuants.foamConcentration()); + } connectionRates[perf][Indices::contiFoamEqIdx] = - connectionRateFoam(cq_s, intQuants, deferred_logger); + this->connections_.connectionRateFoam(cq_s, foamConcentration, + FoamModule::transportPhase(), + deferred_logger); } if constexpr (has_zFraction) { @@ -2225,43 +2233,6 @@ namespace Opm } - template - typename StandardWell::Eval - StandardWell:: - connectionRateFoam(const std::vector& cq_s, - const IntensiveQuantities& intQuants, - DeferredLogger& deferred_logger) const - { - // TODO: the application of well efficiency factor has not been tested with an example yet - auto getFoamTransportIdx = [&deferred_logger] { - switch (FoamModule::transportPhase()) { - case Phase::WATER: { - return Indices::canonicalToActiveComponentIndex(FluidSystem::waterCompIdx); - } - case Phase::GAS: { - return Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx); - } - case Phase::SOLVENT: { - if constexpr (has_solvent) - return static_cast(Indices::contiSolventEqIdx); - else - OPM_DEFLOG_THROW(std::runtime_error, "Foam transport phase is SOLVENT but SOLVENT is not activated.", deferred_logger); - } - default: { - OPM_DEFLOG_THROW(std::runtime_error, "Foam transport phase must be GAS/WATER/SOLVENT.", deferred_logger); - } - } - }; - EvalWell cq_s_foam = cq_s[getFoamTransportIdx()] * this->well_efficiency_factor_; - if (this->isInjector()) { - cq_s_foam *= this->wfoam(); - } else { - cq_s_foam *= this->extendEval(intQuants.foamConcentration()); - } - return Base::restrictEval(cq_s_foam); - } - - template std::tuple::Eval, typename StandardWell::Eval,