26 #ifndef OPM_GENERIC_OIL_GAS_WATER_FLUIDSYSTEM_HPP 27 #define OPM_GENERIC_OIL_GAS_WATER_FLUIDSYSTEM_HPP 29 #include <opm/common/OpmLog/OpmLog.hpp> 31 #include <opm/input/eclipse/EclipseState/EclipseState.hpp> 32 #include <opm/input/eclipse/Schedule/Schedule.hpp> 34 #include <opm/material/eos/CubicEOS.hpp> 45 #include <string_view> 46 #include <type_traits> 48 #include <fmt/format.h> 60 template<
class Scalar,
int NumComp,
bool enableWater>
62 :
public BaseFluidSystem<Scalar, GenericOilGasWaterFluidSystem<Scalar, NumComp, enableWater> > {
65 static constexpr
bool waterEnabled = enableWater;
66 static constexpr
int numPhases = enableWater ? 3 : 2;
67 static constexpr
int numComponents = NumComp;
68 static constexpr
int numMisciblePhases = 2;
71 static constexpr
int numMiscibleComponents = NumComp;
73 static constexpr
int oilPhaseIdx = 0;
74 static constexpr
int gasPhaseIdx = 1;
75 static constexpr
int waterPhaseIdx = 2;
77 static constexpr
int waterCompIdx = -1;
78 static constexpr
int oilCompIdx = 0;
79 static constexpr
int gasCompIdx = 1;
80 static constexpr
int compositionSwitchIdx = -1;
82 template <
class ValueType>
99 molar_mass(molar_mass_),
100 critic_temp(critic_temp_),
101 critic_pres(critic_pres_),
102 critic_vol(critic_vol_),
103 acentric_factor(acentric_factor_)
107 static bool phaseIsActive(
unsigned phaseIdx)
109 if constexpr (enableWater) {
110 assert(phaseIdx < numPhases);
114 if (phaseIdx == waterPhaseIdx)
116 assert(phaseIdx < numPhases);
121 template<
typename Param>
122 static void addComponent(
const Param& param)
125 if (component_param_.size() < numComponents) {
126 component_param_.push_back(param);
129 const std::string msg = fmt::format(
"The fluid system has reached its maximum capacity of {} components," 130 "the component '{}' will not be added.", NumComp, param.name);
142 const auto& comp_config = eclState.compositionalConfig();
145 const std::size_t num_comps = comp_config.numComps();
147 assert(num_comps == NumComp);
148 const auto& names = comp_config.compName();
149 const auto& eos_props = comp_config.eosProps(0);
151 using CompParm =
typename FluidSystem::ComponentParam;
152 for (std::size_t c = 0; c < num_comps; ++c) {
154 FluidSystem::addComponent(CompParm{names[c],
155 static_cast<Scalar>(eos_props.molecular_weights[c]),
156 static_cast<Scalar>(eos_props.critical_temperature[c]),
157 static_cast<Scalar>(eos_props.critical_pressure[c]),
158 static_cast<Scalar>(eos_props.critical_volume[c] * 1.e3),
159 static_cast<Scalar>(eos_props.acentric_factors[c])});
162 const auto& bic = eos_props.binary_interaction_coefficient;
163 if constexpr (std::is_same_v<Scalar, double>) {
164 interaction_coefficients_ = bic;
166 interaction_coefficients_.resize(bic.size());
167 std::ranges::copy(bic, interaction_coefficients_.begin());
170 const auto& lbc = comp_config.lbcCoefficients();
171 std::ranges::copy(lbc, lbc_coefficients_.begin());
174 waterPvt_->initFromState(eclState, schedule);
180 waterPvt_ = std::make_shared<WaterPvt>();
181 component_param_.reserve(numComponents);
188 { waterPvt_ = std::move(pvtObj); }
197 assert(isConsistent());
198 assert(compIdx < numComponents);
200 return component_param_[compIdx].acentric_factor;
209 assert(isConsistent());
210 assert(compIdx < numComponents);
212 return component_param_[compIdx].critic_temp;
221 assert(isConsistent());
222 assert(compIdx < numComponents);
224 return component_param_[compIdx].critic_pres;
233 assert(isConsistent());
234 assert(compIdx < numComponents);
236 return component_param_[compIdx].critic_vol;
242 assert(isConsistent());
243 assert(compIdx < numComponents);
245 return component_param_[compIdx].molar_mass;
255 {
return lbc_coefficients_; }
263 assert(isConsistent());
264 assert(comp1Idx < numComponents);
265 assert(comp2Idx < numComponents);
266 if (interaction_coefficients_.empty() || comp2Idx == comp1Idx) {
270 const auto [column, row] = std::minmax(comp1Idx, comp2Idx);
271 const unsigned index = (row * (row - 1) / 2 + column);
272 return interaction_coefficients_[index];
278 static const std::string_view name[] = {
"o",
282 assert(phaseIdx < numPhases);
283 return name[phaseIdx];
289 assert(isConsistent());
290 assert(compIdx < numComponents);
292 return component_param_[compIdx].name;
298 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::ValueType,
class ParamCacheEval = LhsEval>
299 static LhsEval
density(
const FluidState& fluidState,
303 assert(isConsistent());
304 assert(phaseIdx < numPhases);
306 if (phaseIdx == oilPhaseIdx || phaseIdx == gasPhaseIdx) {
307 return decay<LhsEval>(fluidState.averageMolarMass(phaseIdx) / paramCache.
molarVolume(phaseIdx));
310 const LhsEval& p = decay<LhsEval>(fluidState.pressure(phaseIdx));
311 const LhsEval& T = decay<LhsEval>(fluidState.temperature(phaseIdx));
312 const Scalar& rho_w_ref = waterPvt_->waterReferenceDensity(0);
313 const LhsEval& bw = waterPvt_->inverseFormationVolumeFactor(0, T, p, LhsEval(0.0), LhsEval(0.0));
314 return rho_w_ref * bw;
321 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::ValueType,
class ParamCacheEval = LhsEval>
326 assert(isConsistent());
327 assert(phaseIdx < numPhases);
329 if (phaseIdx == oilPhaseIdx || phaseIdx == gasPhaseIdx) {
331 return decay<LhsEval>(ViscosityModel::LBC(fluidState, paramCache, phaseIdx));
334 const LhsEval& p = decay<LhsEval>(fluidState.pressure(phaseIdx));
335 const LhsEval& T = decay<LhsEval>(fluidState.temperature(phaseIdx));
336 return waterPvt_->viscosity(0, T, p, LhsEval(0.0), LhsEval(0.0));
341 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::ValueType,
class ParamCacheEval = LhsEval>
347 if (waterEnabled && phaseIdx == static_cast<unsigned int>(waterPhaseIdx))
350 assert(isConsistent());
351 assert(phaseIdx < numPhases);
352 assert(compIdx < numComponents);
354 return decay<LhsEval>(CubicEOS::computeFugacityCoefficient(fluidState, paramCache, phaseIdx, compIdx));
361 assert(phaseIdx < numPhases);
369 assert(phaseIdx < numPhases);
377 assert(phaseIdx < numPhases);
379 return (phaseIdx == oilPhaseIdx);
385 assert(phaseIdx < numPhases);
387 return (phaseIdx == gasPhaseIdx);
391 template <
class LhsEval>
392 static LhsEval convertXwGToxwG(
const LhsEval&,
unsigned)
394 assert(
false &&
"convertXwGToxwG not implemented for GenericOilGasWaterFluidSystem!");
397 template <
class LhsEval>
398 static LhsEval convertXoGToxoG(
const LhsEval&,
unsigned)
400 assert(
false &&
"convertXoGToxoG not implemented for GenericOilGasWaterFluidSystem!");
404 template <
class LhsEval>
405 static LhsEval convertxoGToXoG(
const LhsEval&,
unsigned)
407 assert(
false &&
"convertxoGToXoG not implemented for GenericOilGasWaterFluidSystem!");
411 template <
class LhsEval>
412 static LhsEval convertXgOToxgO(
const LhsEval&,
unsigned)
414 assert(
false &&
"convertXgOToxgO not implemented for GenericOilGasWaterFluidSystem!");
418 template <
class LhsEval>
419 static LhsEval convertRswToXwG(
const LhsEval&,
unsigned)
421 assert(
false &&
"convertRswToXwG not implemented for GenericOilGasWaterFluidSystem!");
425 template <
class LhsEval>
426 static LhsEval convertRvwToXgW(
const LhsEval&,
unsigned)
428 assert(
false &&
"convertRvwToXgW not implemented for GenericOilGasWaterFluidSystem!");
432 template <
class LhsEval>
433 static LhsEval convertXgWToxgW(
const LhsEval&,
unsigned)
435 assert(
false &&
"convertXgWToxgW not implemented for GenericOilGasWaterFluidSystem!");
439 static bool enableDissolvedGas()
444 static bool enableDissolvedGasInWater()
449 static bool enableVaporizedWater()
454 static bool enableVaporizedOil()
460 static bool isConsistent() {
461 return component_param_.size() == NumComp;
464 static std::vector<ComponentParam> component_param_;
465 static std::vector<Scalar> interaction_coefficients_;
466 static std::array<Scalar, 5> lbc_coefficients_;
467 static std::shared_ptr<WaterPvt> waterPvt_;
470 static std::string printComponentParams() {
471 std::string result =
"Components Information:\n";
472 for (
const auto& param : component_param_) {
473 result += fmt::format(
"Name: {}\n", param.name);
474 result += fmt::format(
"Molar Mass: {} g/mol\n", param.molar_mass);
475 result += fmt::format(
"Critical Temperature: {} K\n", param.critic_temp);
476 result += fmt::format(
"Critical Pressure: {} Pascal\n", param.critic_pres);
477 result += fmt::format(
"Critical Volume: {} m^3/kmol\n", param.critic_vol);
478 result += fmt::format(
"Acentric Factor: {}\n", param.acentric_factor);
479 result +=
"---------------------------------\n";
485 template <
class Scalar,
int NumComp,
bool enableWater>
486 std::vector<typename GenericOilGasWaterFluidSystem<Scalar, NumComp, enableWater>::ComponentParam>
487 GenericOilGasWaterFluidSystem<Scalar, NumComp, enableWater>::component_param_;
489 template <
class Scalar,
int NumComp,
bool enableWater>
491 GenericOilGasWaterFluidSystem<Scalar, NumComp, enableWater>::interaction_coefficients_;
493 template <
class Scalar,
int NumComp,
bool enableWater>
494 std::array<Scalar, 5>
495 GenericOilGasWaterFluidSystem<Scalar, NumComp, enableWater>::lbc_coefficients_ =
496 ViscosityModel::defaultLBCCoefficients();
498 template <
class Scalar,
int NumComp,
bool enableWater>
499 std::shared_ptr<WaterPvtMultiplexer<Scalar> >
500 GenericOilGasWaterFluidSystem<Scalar, NumComp, enableWater>::waterPvt_;
503 #endif // OPM_GENERIC_OIL_GAS_WATER_FLUIDSYSTEM_HPP static Scalar criticalTemperature(unsigned compIdx)
Critical temperature of a component [K].
Definition: GenericOilGasWaterFluidSystem.hpp:207
static Scalar criticalVolume(unsigned compIdx)
Critical volume of a component [m3].
Definition: GenericOilGasWaterFluidSystem.hpp:231
Specifies the parameter cache used by the SPE-5 fluid system.
Definition: PTFlashParameterCache.hpp:49
static void initFromState(const EclipseState &eclState, const Schedule &schedule)
Initialize the fluid system using an ECL deck object.
Definition: GenericOilGasWaterFluidSystem.hpp:139
Definition: Schedule.hpp:102
Definition: ViscosityModels.hpp:42
static Scalar molarMass(unsigned compIdx)
Return the molar mass of a component in [kg/mol].
Definition: GenericOilGasWaterFluidSystem.hpp:240
static LhsEval density(const FluidState &fluidState, const ParameterCache< ParamCacheEval > ¶mCache, unsigned phaseIdx)
Calculate the density [kg/m^3] of a fluid phase.
Definition: GenericOilGasWaterFluidSystem.hpp:299
This class represents the Pressure-Volume-Temperature relations of the water phase in the black-oil m...
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Scalar molarVolume(unsigned phaseIdx) const
Returns the molar volume of a phase [m^3/mol].
Definition: PTFlashParameterCache.hpp:283
Definition: CubicEOS.hpp:33
static LhsEval fugacityCoefficient(const FluidState &fluidState, const ParameterCache< ParamCacheEval > ¶mCache, unsigned phaseIdx, unsigned compIdx)
Calculate the fugacity coefficient [Pa] of an individual component in a fluid phase.
Definition: GenericOilGasWaterFluidSystem.hpp:342
A two phase system that can contain NumComp components.
Definition: GenericOilGasWaterFluidSystem.hpp:61
Definition: EclipseState.hpp:66
static bool isIdealMixture([[maybe_unused]] unsigned phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal mixture.
Definition: GenericOilGasWaterFluidSystem.hpp:367
static const std::array< Scalar, 5 > & lbcCoefficients()
Coefficients for the Lorentz-Bray-Clark viscosity correlation.
Definition: GenericOilGasWaterFluidSystem.hpp:254
static LhsEval viscosity(const FluidState &fluidState, const ParameterCache< ParamCacheEval > ¶mCache, unsigned phaseIdx)
Calculate the dynamic viscosity of a fluid phase [Pa*s].
Definition: GenericOilGasWaterFluidSystem.hpp:322
static Scalar criticalPressure(unsigned compIdx)
Critical pressure of a component [Pa].
Definition: GenericOilGasWaterFluidSystem.hpp:219
This class represents the Pressure-Volume-Temperature relations of the water phase in the black-oil m...
Definition: ConstantCompressibilityBrinePvt.hpp:39
The base class for all fluid systems.
Definition: BaseFluidSystem.hpp:42
static std::string_view phaseName(unsigned phaseIdx)
Return the human readable name of a fluid phase.
Definition: GenericOilGasWaterFluidSystem.hpp:276
static bool isLiquid(unsigned phaseIdx)
Return whether a phase is liquid.
Definition: GenericOilGasWaterFluidSystem.hpp:375
static bool isCompressible([[maybe_unused]] unsigned phaseIdx)
Returns true if and only if a fluid phase is assumed to be compressible.
Definition: GenericOilGasWaterFluidSystem.hpp:359
static Scalar acentricFactor(unsigned compIdx)
The acentric factor of a component [].
Definition: GenericOilGasWaterFluidSystem.hpp:195
static bool isIdealGas(unsigned phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal gas.
Definition: GenericOilGasWaterFluidSystem.hpp:383
Scalar Scalar
The type used for scalar quantities.
Definition: BaseFluidSystem.hpp:48
static Scalar interactionCoefficient(unsigned comp1Idx, unsigned comp2Idx)
Returns the interaction coefficient for two components.
Definition: GenericOilGasWaterFluidSystem.hpp:261
Definition: GenericOilGasWaterFluidSystem.hpp:88
static std::string_view componentName(unsigned compIdx)
Return the human readable name of a component.
Definition: GenericOilGasWaterFluidSystem.hpp:287
Specifies the parameter cache used by the SPE-5 fluid system.
static void setWaterPvt(std::shared_ptr< WaterPvt > pvtObj)
Set the pressure-volume-saturation (PVT) relations for the water phase.
Definition: GenericOilGasWaterFluidSystem.hpp:187
The base class for all fluid systems.