28#ifndef OPM_BLACK_OIL_FLUID_STATE_HH
29#define OPM_BLACK_OIL_FLUID_STATE_HH
31#include <opm/material/fluidsystems/BlackOilFluidSystem.hpp>
41template <class FluidState>
42unsigned getPvtRegionIndex_(typename std::enable_if<HasMember_pvtRegionIndex<FluidState>::value,
43 const FluidState&>::type fluidState)
44{
return fluidState.pvtRegionIndex(); }
46template <
class Flu
idState>
47unsigned getPvtRegionIndex_(
typename std::enable_if<!HasMember_pvtRegionIndex<FluidState>::value,
48 const FluidState&>::type)
53template <class FluidSystem, class FluidState, class LhsEval>
54auto getInvB_(typename std::enable_if<HasMember_invB<FluidState>::value,
55 const FluidState&>::type fluidState,
58 -> decltype(decay<LhsEval>(fluidState.invB(phaseIdx)))
59{
return decay<LhsEval>(fluidState.invB(phaseIdx)); }
61template <
class Flu
idSystem,
class Flu
idState,
class LhsEval>
62LhsEval getInvB_(
typename std::enable_if<!HasMember_invB<FluidState>::value,
63 const FluidState&>::type fluidState,
65 unsigned pvtRegionIdx)
67 const auto& rho = fluidState.density(phaseIdx);
68 const auto& Xsolvent =
69 fluidState.massFraction(phaseIdx, FluidSystem::solventComponentIndex(phaseIdx));
73 *decay<LhsEval>(Xsolvent)
74 /FluidSystem::referenceDensity(phaseIdx, pvtRegionIdx);
79template <class FluidState>
80auto getSaltConcentration_(typename std::enable_if<HasMember_saltConcentration<FluidState>::value,
81 const FluidState&>::type fluidState)
82{
return fluidState.saltConcentration(); }
84template <
class Flu
idState>
85auto getSaltConcentration_(
typename std::enable_if<!HasMember_saltConcentration<FluidState>::value,
86 const FluidState&>::type)
91template <class FluidState>
92auto getSaltSaturation_(typename std::enable_if<HasMember_saltSaturation<FluidState>::value,
93 const FluidState&>::type fluidState)
94{
return fluidState.saltSaturation(); }
97template <
class Flu
idState>
98auto getSaltSaturation_(
typename std::enable_if<!HasMember_saltSaturation<FluidState>::value,
99 const FluidState&>::type)
109template <
class ScalarT,
111 bool enableTemperature =
false,
112 bool enableEnergy =
false,
113 bool enableDissolution =
true,
114 bool enableVapwat =
false,
115 bool enableBrine =
false,
116 bool enableSaltPrecipitation =
false,
117 bool enableDissolutionInWater =
false,
118 unsigned numStoragePhases = FluidSystem::numPhases>
121 enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
122 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
123 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
125 enum { waterCompIdx = FluidSystem::waterCompIdx };
126 enum { gasCompIdx = FluidSystem::gasCompIdx };
127 enum { oilCompIdx = FluidSystem::oilCompIdx };
130 using Scalar = ScalarT;
131 enum { numPhases = FluidSystem::numPhases };
132 enum { numComponents = FluidSystem::numComponents };
145 Valgrind::CheckDefined(pvtRegionIdx_);
147 for (
unsigned storagePhaseIdx = 0; storagePhaseIdx < numStoragePhases; ++ storagePhaseIdx) {
148 Valgrind::CheckDefined(saturation_[storagePhaseIdx]);
149 Valgrind::CheckDefined(pressure_[storagePhaseIdx]);
150 Valgrind::CheckDefined(density_[storagePhaseIdx]);
151 Valgrind::CheckDefined(invB_[storagePhaseIdx]);
153 if constexpr (enableEnergy)
154 Valgrind::CheckDefined((*enthalpy_)[storagePhaseIdx]);
157 if constexpr (enableDissolution) {
158 Valgrind::CheckDefined(*Rs_);
159 Valgrind::CheckDefined(*Rv_);
162 if constexpr (enableVapwat) {
163 Valgrind::CheckDefined(*Rvw_);
166 if constexpr (enableDissolutionInWater) {
167 Valgrind::CheckDefined(*Rsw_);
170 if constexpr (enableBrine) {
171 Valgrind::CheckDefined(*saltConcentration_);
174 if constexpr (enableSaltPrecipitation) {
175 Valgrind::CheckDefined(*saltSaturation_);
178 if constexpr (enableTemperature || enableEnergy)
179 Valgrind::CheckDefined(*temperature_);
187 template <
class Flu
idState>
190 if constexpr (enableTemperature || enableEnergy)
193 unsigned pvtRegionIdx = getPvtRegionIndex_<FluidState>(fs);
196 if constexpr (enableDissolution) {
197 setRs(BlackOil::getRs_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
198 setRv(BlackOil::getRv_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
200 if constexpr (enableVapwat) {
201 setRvw(BlackOil::getRvw_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
203 if constexpr (enableDissolutionInWater) {
204 setRsw(BlackOil::getRsw_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
206 if constexpr (enableBrine){
207 setSaltConcentration(BlackOil::getSaltConcentration_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
209 if constexpr (enableSaltPrecipitation){
210 setSaltSaturation(BlackOil::getSaltSaturation_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
212 for (
unsigned storagePhaseIdx = 0; storagePhaseIdx < numStoragePhases; ++storagePhaseIdx) {
213 unsigned phaseIdx = storageToCanonicalPhaseIndex_(storagePhaseIdx);
218 if constexpr (enableEnergy)
221 setInvB(phaseIdx, getInvB_<FluidSystem, FluidState, Scalar>(fs, phaseIdx, pvtRegionIdx));
232 { pvtRegionIdx_ =
static_cast<unsigned short>(newPvtRegionIdx); }
238 { pressure_[canonicalToStoragePhaseIndex_(phaseIdx)] = p; }
244 { saturation_[canonicalToStoragePhaseIndex_(phaseIdx)] = S; }
249 void setPc(
unsigned phaseIdx,
const Scalar&
pc)
250 { pc_[canonicalToStoragePhaseIndex_(phaseIdx)] =
pc; }
257 totalSaturation_ = value;
268 assert(enableTemperature || enableEnergy);
270 (*temperature_) = value;
281 assert(enableTemperature || enableEnergy);
283 (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx)] = value;
289 void setInvB(
unsigned phaseIdx,
const Scalar& b)
290 { invB_[canonicalToStoragePhaseIndex_(phaseIdx)] = b; }
296 { density_[canonicalToStoragePhaseIndex_(phaseIdx)] = rho; }
334 { *saltConcentration_ = newSaltConcentration; }
340 { *saltSaturation_ = newSaltSaturation; }
346 {
return pressure_[canonicalToStoragePhaseIndex_(phaseIdx)]; }
352 {
return saturation_[canonicalToStoragePhaseIndex_(phaseIdx)]; }
357 const Scalar&
pc(
unsigned phaseIdx)
const
358 {
return pc_[canonicalToStoragePhaseIndex_(phaseIdx)]; }
365 return totalSaturation_;
373 if constexpr (enableTemperature || enableEnergy) {
374 return *temperature_;
376 return FluidSystem::reservoirTemperature(pvtRegionIdx_);
386 const Scalar&
invB(
unsigned phaseIdx)
const
387 {
return invB_[canonicalToStoragePhaseIndex_(phaseIdx)]; }
398 if constexpr (enableDissolution) {
414 if constexpr (!enableDissolution) {
430 if constexpr (enableVapwat) {
446 if constexpr (enableDissolutionInWater) {
458 if constexpr (enableBrine) {
459 return *saltConcentration_;
470 if constexpr (enableSaltPrecipitation) {
471 return *saltSaturation_;
482 {
return pvtRegionIdx_; }
488 {
return density_[canonicalToStoragePhaseIndex_(phaseIdx)]; }
497 {
return (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx)]; }
506 {
auto energy = (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx)];
507 if(!FluidSystem::enthalpyEqualEnergy()){
522 const auto& rho =
density(phaseIdx);
524 if (phaseIdx == waterPhaseIdx)
525 return rho/FluidSystem::molarMass(waterCompIdx, pvtRegionIdx_);
528 rho*(
moleFraction(phaseIdx, gasCompIdx)/FluidSystem::molarMass(gasCompIdx, pvtRegionIdx_)
529 +
moleFraction(phaseIdx, oilCompIdx)/FluidSystem::molarMass(oilCompIdx, pvtRegionIdx_));
545 {
return FluidSystem::viscosity(*
this, phaseIdx, pvtRegionIdx_); }
554 if (compIdx == waterCompIdx)
559 if (compIdx == waterCompIdx)
561 else if (compIdx == oilCompIdx)
562 return 1.0 - FluidSystem::convertRsToXoG(
Rs(), pvtRegionIdx_);
564 assert(compIdx == gasCompIdx);
565 return FluidSystem::convertRsToXoG(
Rs(), pvtRegionIdx_);
570 if (compIdx == waterCompIdx)
572 else if (compIdx == oilCompIdx)
573 return FluidSystem::convertRvToXgO(
Rv(), pvtRegionIdx_);
575 assert(compIdx == gasCompIdx);
576 return 1.0 - FluidSystem::convertRvToXgO(
Rv(), pvtRegionIdx_);
581 throw std::logic_error(
"Invalid phase or component index!");
591 if (compIdx == waterCompIdx)
596 if (compIdx == waterCompIdx)
598 else if (compIdx == oilCompIdx)
599 return 1.0 - FluidSystem::convertXoGToxoG(FluidSystem::convertRsToXoG(
Rs(), pvtRegionIdx_),
602 assert(compIdx == gasCompIdx);
603 return FluidSystem::convertXoGToxoG(FluidSystem::convertRsToXoG(
Rs(), pvtRegionIdx_),
609 if (compIdx == waterCompIdx)
611 else if (compIdx == oilCompIdx)
612 return FluidSystem::convertXgOToxgO(FluidSystem::convertRvToXgO(
Rv(), pvtRegionIdx_),
615 assert(compIdx == gasCompIdx);
616 return 1.0 - FluidSystem::convertXgOToxgO(FluidSystem::convertRvToXgO(
Rv(), pvtRegionIdx_),
622 throw std::logic_error(
"Invalid phase or component index!");
628 Scalar
molarity(
unsigned phaseIdx,
unsigned compIdx)
const
637 for (
unsigned compIdx = 0; compIdx < numComponents; ++ compIdx)
638 result += FluidSystem::molarMass(compIdx, pvtRegionIdx_)*
moleFraction(phaseIdx, compIdx);
646 {
return FluidSystem::fugacityCoefficient(*
this, phaseIdx, compIdx, pvtRegionIdx_); }
651 Scalar
fugacity(
unsigned phaseIdx,
unsigned compIdx)
const
660 static unsigned storageToCanonicalPhaseIndex_(
unsigned storagePhaseIdx)
662 if constexpr (numStoragePhases == 3)
663 return storagePhaseIdx;
665 return FluidSystem::activeToCanonicalPhaseIdx(storagePhaseIdx);
668 static unsigned canonicalToStoragePhaseIndex_(
unsigned canonicalPhaseIdx)
670 if constexpr (numStoragePhases == 3)
671 return canonicalPhaseIdx;
673 return FluidSystem::canonicalToActivePhaseIdx(canonicalPhaseIdx);
676 ConditionalStorage<enableTemperature || enableEnergy, Scalar> temperature_{};
677 ConditionalStorage<enableEnergy, std::array<Scalar, numStoragePhases> > enthalpy_{};
678 Scalar totalSaturation_{};
679 std::array<Scalar, numStoragePhases> pressure_{};
680 std::array<Scalar, numStoragePhases> pc_{};
681 std::array<Scalar, numStoragePhases> saturation_{};
682 std::array<Scalar, numStoragePhases> invB_{};
683 std::array<Scalar, numStoragePhases> density_{};
684 ConditionalStorage<enableDissolution,Scalar> Rs_{};
685 ConditionalStorage<enableDissolution, Scalar> Rv_{};
686 ConditionalStorage<enableVapwat,Scalar> Rvw_{};
687 ConditionalStorage<enableDissolutionInWater,Scalar> Rsw_{};
688 ConditionalStorage<enableBrine, Scalar> saltConcentration_{};
689 ConditionalStorage<enableSaltPrecipitation, Scalar> saltSaturation_{};
691 unsigned short pvtRegionIdx_{};
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.
Implements a "tailor-made" fluid state class for the black-oil model.
Definition BlackOilFluidState.hpp:120
void setEnthalpy(unsigned phaseIdx, const Scalar &value)
Set the specific enthalpy [J/kg] of a given fluid phase.
Definition BlackOilFluidState.hpp:279
const Scalar & pressure(unsigned phaseIdx) const
Return the pressure of a fluid phase [Pa].
Definition BlackOilFluidState.hpp:345
Scalar temperature(unsigned) const
Return the temperature [K].
Definition BlackOilFluidState.hpp:371
void setTemperature(const Scalar &value)
Set the temperature [K].
Definition BlackOilFluidState.hpp:266
const Scalar & invB(unsigned phaseIdx) const
Return the inverse formation volume factor of a fluid phase [-].
Definition BlackOilFluidState.hpp:386
Scalar moleFraction(unsigned phaseIdx, unsigned compIdx) const
Return the mole fraction of a component in a fluid phase [-].
Definition BlackOilFluidState.hpp:587
void setSaltSaturation(const Scalar &newSaltSaturation)
Set the solid salt saturation.
Definition BlackOilFluidState.hpp:339
void setSaltConcentration(const Scalar &newSaltConcentration)
Set the salt concentration.
Definition BlackOilFluidState.hpp:333
void setRs(const Scalar &newRs)
Set the gas dissolution factor [m^3/m^3] of the oil phase.
Definition BlackOilFluidState.hpp:303
Scalar Rs() const
Return the gas dissolution factor of oil [m^3/m^3].
Definition BlackOilFluidState.hpp:396
Scalar saltSaturation() const
Return the saturation of solid salt.
Definition BlackOilFluidState.hpp:468
void setDensity(unsigned phaseIdx, const Scalar &rho)
\ brief Set the density of a fluid phase
Definition BlackOilFluidState.hpp:295
Scalar Rvw() const
Return the water vaporization factor of gas [m^3/m^3].
Definition BlackOilFluidState.hpp:428
void checkDefined() const
Make sure that all attributes are defined.
Definition BlackOilFluidState.hpp:142
Scalar averageMolarMass(unsigned phaseIdx) const
Return the partial molar density of a fluid phase [kg / mol].
Definition BlackOilFluidState.hpp:634
void setInvB(unsigned phaseIdx, const Scalar &b)
\ brief Set the inverse formation volume factor of a fluid phase
Definition BlackOilFluidState.hpp:289
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition BlackOilFluidState.hpp:188
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:628
Scalar internalEnergy(unsigned phaseIdx) const
Return the specific internal energy [J/kg] of a given fluid phase.
Definition BlackOilFluidState.hpp:505
void setSaturation(unsigned phaseIdx, const Scalar &S)
Set the saturation of a fluid phase [-].
Definition BlackOilFluidState.hpp:243
void setRv(const Scalar &newRv)
Set the oil vaporization factor [m^3/m^3] of the gas phase.
Definition BlackOilFluidState.hpp:311
void setPvtRegionIndex(unsigned newPvtRegionIdx)
Set the index of the fluid region.
Definition BlackOilFluidState.hpp:231
const Scalar & pc(unsigned phaseIdx) const
Return the capillary pressure of a fluid phase [-].
Definition BlackOilFluidState.hpp:357
Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
Return the fugacity of a component in a fluid phase [Pa].
Definition BlackOilFluidState.hpp:651
void setTotalSaturation(const Scalar &value)
Set the total saturation used for sequential methods.
Definition BlackOilFluidState.hpp:255
Scalar molarDensity(unsigned phaseIdx) const
Return the molar density of a fluid phase [mol/m^3].
Definition BlackOilFluidState.hpp:520
void setPressure(unsigned phaseIdx, const Scalar &p)
Set the pressure of a fluid phase [-].
Definition BlackOilFluidState.hpp:237
unsigned short pvtRegionIndex() const
Return the PVT region where the current fluid state is assumed to be part of.
Definition BlackOilFluidState.hpp:481
Scalar Rv() const
Return the oil vaporization factor of gas [m^3/m^3].
Definition BlackOilFluidState.hpp:412
Scalar massFraction(unsigned phaseIdx, unsigned compIdx) const
Return the mass fraction of a component in a fluid phase [-].
Definition BlackOilFluidState.hpp:550
void setPc(unsigned phaseIdx, const Scalar &pc)
Set the capillary pressure of a fluid phase [-].
Definition BlackOilFluidState.hpp:249
const Scalar & totalSaturation() const
Return the total saturation needed for sequential.
Definition BlackOilFluidState.hpp:363
const Scalar & saturation(unsigned phaseIdx) const
Return the saturation of a fluid phase [-].
Definition BlackOilFluidState.hpp:351
Scalar fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
Return the fugacity coefficient of a component in a fluid phase [-].
Definition BlackOilFluidState.hpp:645
Scalar saltConcentration() const
Return the concentration of salt in water.
Definition BlackOilFluidState.hpp:456
const Scalar & enthalpy(unsigned phaseIdx) const
Return the specific enthalpy [J/kg] of a given fluid phase.
Definition BlackOilFluidState.hpp:496
Scalar molarVolume(unsigned phaseIdx) const
Return the molar volume of a fluid phase [m^3/mol].
Definition BlackOilFluidState.hpp:538
Scalar Rsw() const
Return the gas dissolution factor of water [m^3/m^3].
Definition BlackOilFluidState.hpp:444
Scalar density(unsigned phaseIdx) const
Return the density [kg/m^3] of a given fluid phase.
Definition BlackOilFluidState.hpp:487
void setRsw(const Scalar &newRsw)
Set the gas dissolution factor [m^3/m^3] of the water phase.
Definition BlackOilFluidState.hpp:327
Scalar viscosity(unsigned phaseIdx) const
Return the dynamic viscosity of a fluid phase [Pa s].
Definition BlackOilFluidState.hpp:544
void setRvw(const Scalar &newRvw)
Set the water vaporization factor [m^3/m^3] of the gas phase.
Definition BlackOilFluidState.hpp:319
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30