diff --git a/opm/simulators/wells/StandardWell.hpp b/opm/simulators/wells/StandardWell.hpp index 464bcaa63..9d70234a8 100644 --- a/opm/simulators/wells/StandardWell.hpp +++ b/opm/simulators/wells/StandardWell.hpp @@ -267,12 +267,13 @@ namespace Opm WellState& well_state, DeferredLogger& deferred_logger); - // calculate the properties for the well connections - // to calulate the pressure difference between well connections. using WellConnectionProps = typename StdWellEval::StdWellConnections::Properties; - void computePropertiesForWellConnectionPressures(const Simulator& simulator, - const WellState& well_state, - WellConnectionProps& props) const; + + // Compute connection level PVT properties needed to calulate the + // pressure difference between well connections. + WellConnectionProps + computePropertiesForWellConnectionPressures(const Simulator& simulator, + const WellState& well_state) const; void computeWellConnectionDensitesPressures(const Simulator& simulator, const WellState& well_state, diff --git a/opm/simulators/wells/StandardWellConnections.cpp b/opm/simulators/wells/StandardWellConnections.cpp index da844fde0..cf60a6cc3 100644 --- a/opm/simulators/wells/StandardWellConnections.cpp +++ b/opm/simulators/wells/StandardWellConnections.cpp @@ -420,15 +420,13 @@ initialiseConnectionMixture(const int num_comp, } template -void StandardWellConnections:: -computePropertiesForPressures(const WellState& well_state, - const std::function& getTemperature, - const std::function& getSaltConcentration, - const std::function& pvtRegionIdx, - const std::function& solventInverseFormationVolumeFactor, - const std::function& solventRefDensity, - Properties& props) const +typename StandardWellConnections::Properties +StandardWellConnections:: +computePropertiesForPressures(const WellState& well_state, + const PressurePropertyFunctions& prop_func) const { + auto props = Properties{}; + const int nperf = well_.numPerfs(); const PhaseUsage& pu = well_.phaseUsage(); @@ -466,9 +464,9 @@ computePropertiesForPressures(const WellState& well_state, const int cell_idx = well_.cells()[perf]; const Scalar p_avg = (perf_press[perf] + p_above[perf])/2; - const Scalar temperature = getTemperature(cell_idx, FluidSystem::oilPhaseIdx); - const Scalar saltConcentration = getSaltConcentration(cell_idx); - const int region_idx = pvtRegionIdx(cell_idx); + const Scalar temperature = prop_func.getTemperature(cell_idx, FluidSystem::oilPhaseIdx); + const Scalar saltConcentration = prop_func.getSaltConcentration(cell_idx); + const int region_idx = prop_func.pvtRegionIdx(cell_idx); if (waterPresent) { const unsigned waterCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::waterCompIdx); @@ -572,10 +570,15 @@ computePropertiesForPressures(const WellState& well_state, // We use cell values for solvent injector if constexpr (Indices::enableSolvent) { - props.b_perf[well_.numComponents() * perf + Indices::contiSolventEqIdx] = solventInverseFormationVolumeFactor(cell_idx); - props.surf_dens_perf[well_.numComponents() * perf + Indices::contiSolventEqIdx] = solventRefDensity(cell_idx); + props.b_perf[well_.numComponents() * perf + Indices::contiSolventEqIdx] = + prop_func.solventInverseFormationVolumeFactor(cell_idx); + + props.surf_dens_perf[well_.numComponents() * perf + Indices::contiSolventEqIdx] = + prop_func.solventRefDensity(cell_idx); } } + + return props; } template diff --git a/opm/simulators/wells/StandardWellConnections.hpp b/opm/simulators/wells/StandardWellConnections.hpp index 782afd41b..3404107af 100644 --- a/opm/simulators/wells/StandardWellConnections.hpp +++ b/opm/simulators/wells/StandardWellConnections.hpp @@ -57,13 +57,18 @@ public: std::vector surf_dens_perf{}; }; - void computePropertiesForPressures(const WellState& well_state, - const std::function& getTemperature, - const std::function& getSaltConcentration, - const std::function& pvtRegionIdx, - const std::function& solventInverseFormationVolumeFactor, - const std::function& solventRefDensity, - Properties& props) const; + struct PressurePropertyFunctions + { + std::function getTemperature{}; + std::function getSaltConcentration{}; + std::function pvtRegionIdx{}; + std::function solventInverseFormationVolumeFactor{}; + std::function solventRefDensity{}; + }; + + Properties + computePropertiesForPressures(const WellState& well_state, + const PressurePropertyFunctions& propFunc) const; //! \brief Compute connection properties (densities, pressure drop, ...) void computeProperties(const WellState& well_state, diff --git a/opm/simulators/wells/StandardWell_impl.hpp b/opm/simulators/wells/StandardWell_impl.hpp index e2ac8d826..465afd557 100644 --- a/opm/simulators/wells/StandardWell_impl.hpp +++ b/opm/simulators/wells/StandardWell_impl.hpp @@ -1133,45 +1133,50 @@ namespace Opm template - void + typename StandardWell::WellConnectionProps StandardWell:: - computePropertiesForWellConnectionPressures(const Simulator& simulator, - const WellState& well_state, - WellConnectionProps& props) const + computePropertiesForWellConnectionPressures(const Simulator& simulator, + const WellState& well_state) const { - std::function getTemperature = - [&simulator](int cell_idx, int phase_idx) - { - return simulator.model().intensiveQuantities(cell_idx, 0).fluidState().temperature(phase_idx).value(); - }; - std::function getSaltConcentration = - [&simulator](int cell_idx) - { - return simulator.model().intensiveQuantities(cell_idx, 0).fluidState().saltConcentration().value(); - }; - std::function getPvtRegionIdx = - [&simulator](int cell_idx) - { - return simulator.model().intensiveQuantities(cell_idx, 0).fluidState().pvtRegionIndex(); - }; - std::function getInvFac = - [&simulator](int cell_idx) - { - return simulator.model().intensiveQuantities(cell_idx, 0).solventInverseFormationVolumeFactor().value(); - }; - std::function getSolventDensity = - [&simulator](int cell_idx) - { - return simulator.model().intensiveQuantities(cell_idx, 0).solventRefDensity(); + auto prop_func = typename StdWellEval::StdWellConnections::PressurePropertyFunctions { + // getTemperature + [&model = simulator.model()](int cell_idx, int phase_idx) + { + return model.intensiveQuantities(cell_idx, /* time_idx = */ 0) + .fluidState().temperature(phase_idx).value(); + }, + + // getSaltConcentration + [&model = simulator.model()](int cell_idx) + { + return model.intensiveQuantities(cell_idx, /* time_idx = */ 0) + .fluidState().saltConcentration().value(); + }, + + // getPvtRegionIdx + [&model = simulator.model()](int cell_idx) + { + return model.intensiveQuantities(cell_idx, /* time_idx = */ 0) + .fluidState().pvtRegionIndex(); + } }; - this->connections_.computePropertiesForPressures(well_state, - getTemperature, - getSaltConcentration, - getPvtRegionIdx, - getInvFac, - getSolventDensity, - props); + if constexpr (Indices::enableSolvent) { + prop_func.solventInverseFormationVolumeFactor = + [&model = simulator.model()](int cell_idx) + { + return model.intensiveQuantities(cell_idx, /* time_idx = */ 0) + .solventInverseFormationVolumeFactor().value(); + }; + + prop_func.solventRefDensity = [&model = simulator.model()](int cell_idx) + { + return model.intensiveQuantities(cell_idx, /* time_idx = */ 0) + .solventRefDensity(); + }; + } + + return this->connections_.computePropertiesForPressures(well_state, prop_func); } @@ -1347,11 +1352,9 @@ namespace Opm const WellState& well_state, DeferredLogger& deferred_logger) { - // 1. Compute properties required by computePressureDelta(). - // Note that some of the complexity of this part is due to the function - // taking std::vector arguments, and not Eigen objects. - WellConnectionProps props; - computePropertiesForWellConnectionPressures(simulator, well_state, props); + const auto props = computePropertiesForWellConnectionPressures + (simulator, well_state); + computeWellConnectionDensitesPressures(simulator, well_state, props, deferred_logger); }