Generate Property Object Directly

This commit switches computePropertiesForPressures() to return a
Properties object directly instead of populating an object
constructed in the caller.  There is just a single call site for
this function so there's no benefit to using an out parameter here.
While here, also collect the property callbacks into a structure to
simplify the function signature.  This also enables not filling in
the solvent properties unless solvent is active in the run.  Update
caller accordingly.
This commit is contained in:
Bård Skaflestad 2024-07-12 17:51:29 +02:00
parent 6f2ee80e41
commit 586d8e2ddc
4 changed files with 77 additions and 65 deletions

View File

@ -267,12 +267,13 @@ namespace Opm
WellState<Scalar>& 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<Scalar>& 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<Scalar>& well_state) const;
void computeWellConnectionDensitesPressures(const Simulator& simulator,
const WellState<Scalar>& well_state,

View File

@ -420,15 +420,13 @@ initialiseConnectionMixture(const int num_comp,
}
template<class FluidSystem, class Indices>
void StandardWellConnections<FluidSystem,Indices>::
typename StandardWellConnections<FluidSystem, Indices>::Properties
StandardWellConnections<FluidSystem,Indices>::
computePropertiesForPressures(const WellState<Scalar>& well_state,
const std::function<Scalar(int,int)>& getTemperature,
const std::function<Scalar(int)>& getSaltConcentration,
const std::function<int(int)>& pvtRegionIdx,
const std::function<Scalar(int)>& solventInverseFormationVolumeFactor,
const std::function<Scalar(int)>& solventRefDensity,
Properties& props) const
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<Scalar>& 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<Scalar>& 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 <class FluidSystem, class Indices>

View File

@ -57,13 +57,18 @@ public:
std::vector<Scalar> surf_dens_perf{};
};
void computePropertiesForPressures(const WellState<Scalar>& well_state,
const std::function<Scalar(int,int)>& getTemperature,
const std::function<Scalar(int)>& getSaltConcentration,
const std::function<int(int)>& pvtRegionIdx,
const std::function<Scalar(int)>& solventInverseFormationVolumeFactor,
const std::function<Scalar(int)>& solventRefDensity,
Properties& props) const;
struct PressurePropertyFunctions
{
std::function<Scalar(int,int)> getTemperature{};
std::function<Scalar(int)> getSaltConcentration{};
std::function<int(int)> pvtRegionIdx{};
std::function<Scalar(int)> solventInverseFormationVolumeFactor{};
std::function<Scalar(int)> solventRefDensity{};
};
Properties
computePropertiesForPressures(const WellState<Scalar>& well_state,
const PressurePropertyFunctions& propFunc) const;
//! \brief Compute connection properties (densities, pressure drop, ...)
void computeProperties(const WellState<Scalar>& well_state,

View File

@ -1133,45 +1133,50 @@ namespace Opm
template<typename TypeTag>
void
typename StandardWell<TypeTag>::WellConnectionProps
StandardWell<TypeTag>::
computePropertiesForWellConnectionPressures(const Simulator& simulator,
const WellState<Scalar>& well_state,
WellConnectionProps& props) const
const WellState<Scalar>& well_state) const
{
std::function<Scalar(int,int)> getTemperature =
[&simulator](int cell_idx, int phase_idx)
auto prop_func = typename StdWellEval::StdWellConnections::PressurePropertyFunctions {
// getTemperature
[&model = simulator.model()](int cell_idx, int phase_idx)
{
return simulator.model().intensiveQuantities(cell_idx, 0).fluidState().temperature(phase_idx).value();
};
std::function<Scalar(int)> getSaltConcentration =
[&simulator](int cell_idx)
return model.intensiveQuantities(cell_idx, /* time_idx = */ 0)
.fluidState().temperature(phase_idx).value();
},
// getSaltConcentration
[&model = simulator.model()](int cell_idx)
{
return simulator.model().intensiveQuantities(cell_idx, 0).fluidState().saltConcentration().value();
};
std::function<int(int)> getPvtRegionIdx =
[&simulator](int cell_idx)
return model.intensiveQuantities(cell_idx, /* time_idx = */ 0)
.fluidState().saltConcentration().value();
},
// getPvtRegionIdx
[&model = simulator.model()](int cell_idx)
{
return simulator.model().intensiveQuantities(cell_idx, 0).fluidState().pvtRegionIndex();
};
std::function<Scalar(int)> getInvFac =
[&simulator](int cell_idx)
{
return simulator.model().intensiveQuantities(cell_idx, 0).solventInverseFormationVolumeFactor().value();
};
std::function<Scalar(int)> getSolventDensity =
[&simulator](int cell_idx)
{
return simulator.model().intensiveQuantities(cell_idx, 0).solventRefDensity();
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<Scalar>& 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<Scalar> 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);
}