28#ifndef OPM_BLACK_OIL_FLUID_STATE_HH
29#define OPM_BLACK_OIL_FLUID_STATE_HH
33#include <opm/common/utility/gpuDecorators.hpp>
34#include <opm/material/fluidsystems/BlackOilFluidSystem.hpp>
44template <class FluidState>
45OPM_HOST_DEVICE
unsigned getPvtRegionIndex_(typename std::enable_if<HasMember_pvtRegionIndex<FluidState>::value,
46 const FluidState&>::type fluidState)
47{
return fluidState.pvtRegionIndex(); }
49template <
class Flu
idState>
50OPM_HOST_DEVICE
unsigned getPvtRegionIndex_(
typename std::enable_if<!HasMember_pvtRegionIndex<FluidState>::value,
51 const FluidState&>::type)
56template <class FluidSystem, class FluidState, class LhsEval>
58auto getInvB_(typename std::enable_if<HasMember_invB<FluidState>::value,
59 const FluidState&>::type fluidState,
62 [[maybe_unused]] const FluidSystem& fluidSystem = FluidSystem{})
63 ->
decltype(decay<LhsEval>(fluidState.invB(phaseIdx)))
64{
return decay<LhsEval>(fluidState.invB(phaseIdx)); }
66template <
class Flu
idSystem,
class Flu
idState,
class LhsEval>
68LhsEval getInvB_(
typename std::enable_if<!HasMember_invB<FluidState>::value,
69 const FluidState&>::type fluidState,
71 unsigned pvtRegionIdx,
72 const FluidSystem& fluidSystem = FluidSystem{})
74 const auto& rho = fluidState.density(phaseIdx);
75 const auto& Xsolvent =
76 fluidState.massFraction(phaseIdx, fluidSystem.solventComponentIndex(phaseIdx));
80 *decay<LhsEval>(Xsolvent)
81 /fluidSystem.referenceDensity(phaseIdx, pvtRegionIdx);
86template <class FluidState>
87OPM_HOST_DEVICE auto getSaltConcentration_(typename std::enable_if<HasMember_saltConcentration<FluidState>::value,
88 const FluidState&>::type fluidState)
89{
return fluidState.saltConcentration(); }
91template <
class Flu
idState>
92OPM_HOST_DEVICE
auto getSaltConcentration_(
typename std::enable_if<!HasMember_saltConcentration<FluidState>::value,
93 const FluidState&>::type)
98template <class FluidState>
99OPM_HOST_DEVICE auto getSaltSaturation_(typename std::enable_if<HasMember_saltSaturation<FluidState>::value,
100 const FluidState&>::type fluidState)
101{
return fluidState.saltSaturation(); }
104template <
class Flu
idState>
105OPM_HOST_DEVICE
auto getSaltSaturation_(
typename std::enable_if<!HasMember_saltSaturation<FluidState>::value,
106 const FluidState&>::type)
116template <
class ScalarT,
118 bool enableTemperature =
false,
119 bool enableEnergy =
false,
120 bool enableDissolution =
true,
121 bool enableVapwat =
false,
122 bool enableBrine =
false,
123 bool enableSaltPrecipitation =
false,
124 bool enableDissolutionInWater =
false,
125 unsigned numStoragePhases = FluidSystemT::numPhases>
129 using FluidSystem = FluidSystemT;
130 using Scalar = ScalarT;
132 static constexpr int waterPhaseIdx = FluidSystem::waterPhaseIdx;
133 static constexpr int gasPhaseIdx = FluidSystem::gasPhaseIdx;
134 static constexpr int oilPhaseIdx = FluidSystem::oilPhaseIdx;
136 static constexpr int waterCompIdx = FluidSystem::waterCompIdx;
137 static constexpr int gasCompIdx = FluidSystem::gasCompIdx;
138 static constexpr int oilCompIdx = FluidSystem::oilCompIdx;
140 static constexpr int numPhases = FluidSystem::numPhases;
141 static constexpr int numComponents = FluidSystem::numComponents;
143 static constexpr bool fluidSystemIsStatic = std::is_empty_v<FluidSystem>;
152 if constexpr (fluidSystemIsStatic) {
164 static_assert(fluidSystemIsStatic);
180 for (
unsigned storagePhaseIdx = 0; storagePhaseIdx < numStoragePhases; ++ storagePhaseIdx) {
186 if constexpr (enableEnergy)
190 if constexpr (enableDissolution) {
195 if constexpr (enableVapwat) {
199 if constexpr (enableDissolutionInWater) {
203 if constexpr (enableBrine) {
207 if constexpr (enableSaltPrecipitation) {
211 if constexpr (enableTemperature || enableEnergy)
220 template <
class Flu
idState>
221 OPM_HOST_DEVICE
void assign(
const FluidState& fs)
223 if constexpr (enableTemperature || enableEnergy)
226 unsigned pvtRegionIdx = getPvtRegionIndex_<FluidState>(fs);
229 if constexpr (enableDissolution) {
230 setRs(BlackOil::getRs_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
231 setRv(BlackOil::getRv_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
233 if constexpr (enableVapwat) {
234 setRvw(BlackOil::getRvw_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
236 if constexpr (enableDissolutionInWater) {
237 setRsw(BlackOil::getRsw_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
239 if constexpr (enableBrine){
242 if constexpr (enableSaltPrecipitation){
243 setSaltSaturation(BlackOil::getSaltSaturation_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
245 for (
unsigned storagePhaseIdx = 0; storagePhaseIdx < numStoragePhases; ++storagePhaseIdx) {
246 unsigned phaseIdx = storageToCanonicalPhaseIndex_(storagePhaseIdx,
fluidSystem());
251 if constexpr (enableEnergy)
254 setInvB(phaseIdx, getInvB_<FluidSystem, FluidState, Scalar>(fs, phaseIdx, pvtRegionIdx,
fluidSystem()));
265 { pvtRegionIdx_ =
static_cast<unsigned short>(newPvtRegionIdx); }
270 OPM_HOST_DEVICE
void setPressure(
unsigned phaseIdx,
const Scalar& p)
271 { pressure_[canonicalToStoragePhaseIndex_(phaseIdx,
fluidSystem())] = p; }
277 { saturation_[canonicalToStoragePhaseIndex_(phaseIdx,
fluidSystem())] = S; }
284 totalSaturation_ = value;
295 assert(enableTemperature || enableEnergy);
297 (*temperature_) = value;
306 OPM_HOST_DEVICE
void setEnthalpy(
unsigned phaseIdx,
const Scalar& value)
308 assert(enableTemperature || enableEnergy);
310 (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx,
fluidSystem())] = value;
316 OPM_HOST_DEVICE
void setInvB(
unsigned phaseIdx,
const Scalar& b)
317 { invB_[canonicalToStoragePhaseIndex_(phaseIdx,
fluidSystem())] = b; }
322 OPM_HOST_DEVICE
void setDensity(
unsigned phaseIdx,
const Scalar& rho)
323 { density_[canonicalToStoragePhaseIndex_(phaseIdx,
fluidSystem())] = rho; }
330 OPM_HOST_DEVICE
void setRs(
const Scalar& newRs)
338 OPM_HOST_DEVICE
void setRv(
const Scalar& newRv)
346 OPM_HOST_DEVICE
void setRvw(
const Scalar& newRvw)
354 OPM_HOST_DEVICE
void setRsw(
const Scalar& newRsw)
361 { *saltConcentration_ = newSaltConcentration; }
367 { *saltSaturation_ = newSaltSaturation; }
372 OPM_HOST_DEVICE
const Scalar&
pressure(
unsigned phaseIdx)
const
373 {
return pressure_[canonicalToStoragePhaseIndex_(phaseIdx,
fluidSystem())]; }
378 OPM_HOST_DEVICE
const Scalar&
saturation(
unsigned phaseIdx)
const
379 {
return saturation_[canonicalToStoragePhaseIndex_(phaseIdx,
fluidSystem())]; }
386 return totalSaturation_;
394 if constexpr (enableTemperature || enableEnergy) {
395 return *temperature_;
397 return fluidSystem().reservoirTemperature(pvtRegionIdx_);
407 OPM_HOST_DEVICE
const Scalar&
invB(
unsigned phaseIdx)
const
408 {
return invB_[canonicalToStoragePhaseIndex_(phaseIdx,
fluidSystem())]; }
417 OPM_HOST_DEVICE Scalar
Rs()
const
419 if constexpr (enableDissolution) {
433 OPM_HOST_DEVICE Scalar
Rv()
const
435 if constexpr (!enableDissolution) {
449 OPM_HOST_DEVICE Scalar
Rvw()
const
451 if constexpr (enableVapwat) {
465 OPM_HOST_DEVICE Scalar
Rsw()
const
467 if constexpr (enableDissolutionInWater) {
479 if constexpr (enableBrine) {
480 return *saltConcentration_;
491 if constexpr (enableSaltPrecipitation) {
492 return *saltSaturation_;
503 {
return pvtRegionIdx_; }
508 OPM_HOST_DEVICE Scalar
density(
unsigned phaseIdx)
const
509 {
return density_[canonicalToStoragePhaseIndex_(phaseIdx,
fluidSystem())]; }
517 OPM_HOST_DEVICE
const Scalar&
enthalpy(
unsigned phaseIdx)
const
518 {
return (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx,
fluidSystem())]; }
527 {
auto energy = (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx,
fluidSystem())];
543 const auto& rho =
density(phaseIdx);
545 if (phaseIdx == waterPhaseIdx)
546 return rho/
fluidSystem().molarMass(waterCompIdx, pvtRegionIdx_);
565 OPM_HOST_DEVICE Scalar
viscosity(
unsigned phaseIdx)
const
566 {
return fluidSystem().viscosity(*
this, phaseIdx, pvtRegionIdx_); }
571 OPM_HOST_DEVICE Scalar
massFraction(
unsigned phaseIdx,
unsigned compIdx)
const
575 if (compIdx == waterCompIdx)
580 if (compIdx == waterCompIdx)
582 else if (compIdx == oilCompIdx)
583 return 1.0 -
fluidSystem().convertRsToXoG(
Rs(), pvtRegionIdx_);
585 assert(compIdx == gasCompIdx);
591 if (compIdx == waterCompIdx)
593 else if (compIdx == oilCompIdx)
596 assert(compIdx == gasCompIdx);
597 return 1.0 -
fluidSystem().convertRvToXgO(
Rv(), pvtRegionIdx_);
602 OPM_THROW(std::logic_error,
"Invalid phase or component index!");
608 OPM_HOST_DEVICE Scalar
moleFraction(
unsigned phaseIdx,
unsigned compIdx)
const
612 if (compIdx == waterCompIdx)
617 if (compIdx == waterCompIdx)
619 else if (compIdx == oilCompIdx)
623 assert(compIdx == gasCompIdx);
630 if (compIdx == waterCompIdx)
632 else if (compIdx == oilCompIdx)
636 assert(compIdx == gasCompIdx);
643 OPM_THROW(std::logic_error,
"Invalid phase or component index!");
649 OPM_HOST_DEVICE Scalar
molarity(
unsigned phaseIdx,
unsigned compIdx)
const
658 for (
unsigned compIdx = 0; compIdx < numComponents; ++ compIdx)
667 {
return fluidSystem().fugacityCoefficient(*
this, phaseIdx, compIdx, pvtRegionIdx_); }
672 OPM_HOST_DEVICE Scalar
fugacity(
unsigned phaseIdx,
unsigned compIdx)
const
701 if constexpr (fluidSystemIsStatic) {
702 static FluidSystem instance;
705 return **fluidSystemPtr_;
710 OPM_HOST_DEVICE
static unsigned storageToCanonicalPhaseIndex_(
unsigned storagePhaseIdx,
const FluidSystem&
fluidSystem)
712 if constexpr (numStoragePhases == 3)
713 return storagePhaseIdx;
715 return fluidSystem.activeToCanonicalPhaseIdx(storagePhaseIdx);
718 OPM_HOST_DEVICE
static unsigned canonicalToStoragePhaseIndex_(
unsigned canonicalPhaseIdx,
const FluidSystem&
fluidSystem)
720 if constexpr (numStoragePhases == 3)
721 return canonicalPhaseIdx;
723 return fluidSystem.canonicalToActivePhaseIdx(canonicalPhaseIdx);
726 ConditionalStorage<enableTemperature || enableEnergy, Scalar> temperature_{};
727 ConditionalStorage<enableEnergy, std::array<Scalar, numStoragePhases> > enthalpy_{};
728 Scalar totalSaturation_{};
729 std::array<Scalar, numStoragePhases> pressure_{};
730 std::array<Scalar, numStoragePhases> saturation_{};
731 std::array<Scalar, numStoragePhases> invB_{};
732 std::array<Scalar, numStoragePhases> density_{};
733 ConditionalStorage<enableDissolution,Scalar> Rs_{};
734 ConditionalStorage<enableDissolution, Scalar> Rv_{};
735 ConditionalStorage<enableVapwat,Scalar> Rvw_{};
736 ConditionalStorage<enableDissolutionInWater,Scalar> Rsw_{};
737 ConditionalStorage<enableBrine, Scalar> saltConcentration_{};
738 ConditionalStorage<enableSaltPrecipitation, Scalar> saltSaturation_{};
740 unsigned short pvtRegionIdx_{};
744 ConditionalStorage<!fluidSystemIsStatic, FluidSystem const*> fluidSystemPtr_;
A simple class which only stores a given member attribute if a boolean condition is true.
This macro generates a class HasMember_${MEMBER_NAME} which can be used for template specialization.
#define OPM_GENERATE_HAS_MEMBER(MEMBER_NAME,...)
This macro generates a class HasMember_${MEMBER_NAME} which can be used for template specialization.
Definition HasMemberGeneratorMacros.hpp:49
Some templates to wrap the valgrind client request macros.
OPM_HOST_DEVICE bool CheckDefined(const T &value)
Make valgrind complain if any of the memory occupied by an object is undefined.
Definition Valgrind.hpp:76
OPM_HOST_DEVICE void setRvw(const Scalar &newRvw)
Set the water vaporization factor [m^3/m^3] of the gas phase.
Definition BlackOilFluidState.hpp:346
OPM_HOST_DEVICE void setSaltSaturation(const Scalar &newSaltSaturation)
Set the solid salt saturation.
Definition BlackOilFluidState.hpp:366
OPM_HOST_DEVICE const Scalar & invB(unsigned phaseIdx) const
Return the inverse formation volume factor of a fluid phase [-].
Definition BlackOilFluidState.hpp:407
OPM_HOST_DEVICE void setRs(const Scalar &newRs)
Set the gas dissolution factor [m^3/m^3] of the oil phase.
Definition BlackOilFluidState.hpp:330
OPM_HOST_DEVICE Scalar molarity(unsigned phaseIdx, unsigned compIdx) const
Return the partial molar density of a component in a fluid phase [mol / m^3].
Definition BlackOilFluidState.hpp:649
OPM_HOST_DEVICE BlackOilFluidState()
Construct a fluid state object.
Definition BlackOilFluidState.hpp:162
OPM_HOST_DEVICE void setSaltConcentration(const Scalar &newSaltConcentration)
Set the salt concentration.
Definition BlackOilFluidState.hpp:360
OPM_HOST_DEVICE Scalar fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
Return the fugacity coefficient of a component in a fluid phase [-].
Definition BlackOilFluidState.hpp:666
OPM_HOST_DEVICE Scalar Rv() const
Return the oil vaporization factor of gas [m^3/m^3].
Definition BlackOilFluidState.hpp:433
OPM_HOST_DEVICE Scalar density(unsigned phaseIdx) const
Return the density [kg/m^3] of a given fluid phase.
Definition BlackOilFluidState.hpp:508
OPM_HOST_DEVICE void setInvB(unsigned phaseIdx, const Scalar &b)
\ brief Set the inverse formation volume factor of a fluid phase
Definition BlackOilFluidState.hpp:316
OPM_HOST_DEVICE const Scalar & enthalpy(unsigned phaseIdx) const
Return the specific enthalpy [J/kg] of a given fluid phase.
Definition BlackOilFluidState.hpp:517
OPM_HOST_DEVICE void setSaturation(unsigned phaseIdx, const Scalar &S)
Set the saturation of a fluid phase [-].
Definition BlackOilFluidState.hpp:276
OPM_HOST_DEVICE void setTotalSaturation(const Scalar &value)
Set the total saturation used for sequential methods.
Definition BlackOilFluidState.hpp:282
OPM_HOST_DEVICE Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
Return the fugacity of a component in a fluid phase [Pa].
Definition BlackOilFluidState.hpp:672
OPM_HOST_DEVICE const Scalar & totalSaturation() const
Return the total saturation needed for sequential.
Definition BlackOilFluidState.hpp:384
OPM_HOST_DEVICE Scalar averageMolarMass(unsigned phaseIdx) const
Return the partial molar density of a fluid phase [kg / mol].
Definition BlackOilFluidState.hpp:655
OPM_HOST_DEVICE void setDensity(unsigned phaseIdx, const Scalar &rho)
\ brief Set the density of a fluid phase
Definition BlackOilFluidState.hpp:322
void checkDefined() const
Make sure that all attributes are defined.
Definition BlackOilFluidState.hpp:175
OPM_HOST_DEVICE Scalar Rs() const
Return the gas dissolution factor of oil [m^3/m^3].
Definition BlackOilFluidState.hpp:417
OPM_HOST_DEVICE Scalar temperature(unsigned) const
Return the temperature [K].
Definition BlackOilFluidState.hpp:392
OPM_HOST_DEVICE BlackOilFluidState(const FluidSystem &fluidSystem)
Construct a fluid state object.
Definition BlackOilFluidState.hpp:150
OPM_HOST_DEVICE void setRv(const Scalar &newRv)
Set the oil vaporization factor [m^3/m^3] of the gas phase.
Definition BlackOilFluidState.hpp:338
OPM_HOST_DEVICE Scalar molarDensity(unsigned phaseIdx) const
Return the molar density of a fluid phase [mol/m^3].
Definition BlackOilFluidState.hpp:541
OPM_HOST_DEVICE void setPvtRegionIndex(unsigned newPvtRegionIdx)
Set the index of the fluid region.
Definition BlackOilFluidState.hpp:264
OPM_HOST_DEVICE void setPressure(unsigned phaseIdx, const Scalar &p)
Set the pressure of a fluid phase [-].
Definition BlackOilFluidState.hpp:270
OPM_HOST_DEVICE const Scalar & pressure(unsigned phaseIdx) const
Return the pressure of a fluid phase [Pa].
Definition BlackOilFluidState.hpp:372
OPM_HOST_DEVICE void setRsw(const Scalar &newRsw)
Set the gas dissolution factor [m^3/m^3] of the water phase.
Definition BlackOilFluidState.hpp:354
OPM_HOST_DEVICE void setTemperature(const Scalar &value)
Set the temperature [K].
Definition BlackOilFluidState.hpp:293
OPM_HOST_DEVICE Scalar saltSaturation() const
Return the saturation of solid salt.
Definition BlackOilFluidState.hpp:489
OPM_HOST_DEVICE Scalar internalEnergy(unsigned phaseIdx) const
Return the specific internal energy [J/kg] of a given fluid phase.
Definition BlackOilFluidState.hpp:526
OPM_HOST_DEVICE Scalar Rsw() const
Return the gas dissolution factor of water [m^3/m^3].
Definition BlackOilFluidState.hpp:465
OPM_HOST_DEVICE void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition BlackOilFluidState.hpp:221
OPM_HOST_DEVICE Scalar Rvw() const
Return the water vaporization factor of gas [m^3/m^3].
Definition BlackOilFluidState.hpp:449
OPM_HOST_DEVICE const FluidSystem & fluidSystem() const
Return the fluid system used by this fluid state.
Definition BlackOilFluidState.hpp:699
bool phaseIsActive(int phaseIdx) const
Return if a phase is active (via the FluidSystem).
Definition BlackOilFluidState.hpp:687
OPM_HOST_DEVICE void setEnthalpy(unsigned phaseIdx, const Scalar &value)
Set the specific enthalpy [J/kg] of a given fluid phase.
Definition BlackOilFluidState.hpp:306
OPM_HOST_DEVICE const Scalar & saturation(unsigned phaseIdx) const
Return the saturation of a fluid phase [-].
Definition BlackOilFluidState.hpp:378
OPM_HOST_DEVICE Scalar saltConcentration() const
Return the concentration of salt in water.
Definition BlackOilFluidState.hpp:477
OPM_HOST_DEVICE Scalar molarVolume(unsigned phaseIdx) const
Return the molar volume of a fluid phase [m^3/mol].
Definition BlackOilFluidState.hpp:559
OPM_HOST_DEVICE unsigned short pvtRegionIndex() const
Return the PVT region where the current fluid state is assumed to be part of.
Definition BlackOilFluidState.hpp:502
OPM_HOST_DEVICE Scalar massFraction(unsigned phaseIdx, unsigned compIdx) const
Return the mass fraction of a component in a fluid phase [-].
Definition BlackOilFluidState.hpp:571
OPM_HOST_DEVICE Scalar moleFraction(unsigned phaseIdx, unsigned compIdx) const
Return the mole fraction of a component in a fluid phase [-].
Definition BlackOilFluidState.hpp:608
OPM_HOST_DEVICE Scalar viscosity(unsigned phaseIdx) const
Return the dynamic viscosity of a fluid phase [Pa s].
Definition BlackOilFluidState.hpp:565
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30