28#ifndef OPM_BLACK_OIL_FLUID_STATE_HH
29#define OPM_BLACK_OIL_FLUID_STATE_HH
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 static Scalar tmp(FluidSystem::reservoirTemperature(pvtRegionIdx_));
387 const Scalar&
invB(
unsigned phaseIdx)
const
388 {
return invB_[canonicalToStoragePhaseIndex_(phaseIdx)]; }
397 const Scalar&
Rs()
const
399 if constexpr (enableDissolution) {
402 static Scalar null = 0.0;
414 const Scalar&
Rv()
const
416 if constexpr (!enableDissolution) {
417 static Scalar null = 0.0;
433 if constexpr (enableVapwat) {
436 static Scalar null = 0.0;
450 if constexpr (enableDissolutionInWater) {
453 static Scalar null = 0.0;
463 if constexpr (enableBrine) {
464 return *saltConcentration_;
466 static Scalar null = 0.0;
476 if constexpr (enableSaltPrecipitation) {
477 return *saltSaturation_;
479 static Scalar null = 0.0;
489 {
return pvtRegionIdx_; }
495 {
return density_[canonicalToStoragePhaseIndex_(phaseIdx)]; }
504 {
return (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx)]; }
513 {
return (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx)] -
pressure(phaseIdx)/
density(phaseIdx); }
524 const auto& rho =
density(phaseIdx);
526 if (phaseIdx == waterPhaseIdx)
527 return rho/FluidSystem::molarMass(waterCompIdx, pvtRegionIdx_);
530 rho*(
moleFraction(phaseIdx, gasCompIdx)/FluidSystem::molarMass(gasCompIdx, pvtRegionIdx_)
531 +
moleFraction(phaseIdx, oilCompIdx)/FluidSystem::molarMass(oilCompIdx, pvtRegionIdx_));
547 {
return FluidSystem::viscosity(*
this, phaseIdx, pvtRegionIdx_); }
556 if (compIdx == waterCompIdx)
561 if (compIdx == waterCompIdx)
563 else if (compIdx == oilCompIdx)
564 return 1.0 - FluidSystem::convertRsToXoG(
Rs(), pvtRegionIdx_);
566 assert(compIdx == gasCompIdx);
567 return FluidSystem::convertRsToXoG(
Rs(), pvtRegionIdx_);
572 if (compIdx == waterCompIdx)
574 else if (compIdx == oilCompIdx)
575 return FluidSystem::convertRvToXgO(
Rv(), pvtRegionIdx_);
577 assert(compIdx == gasCompIdx);
578 return 1.0 - FluidSystem::convertRvToXgO(
Rv(), pvtRegionIdx_);
583 throw std::logic_error(
"Invalid phase or component index!");
593 if (compIdx == waterCompIdx)
598 if (compIdx == waterCompIdx)
600 else if (compIdx == oilCompIdx)
601 return 1.0 - FluidSystem::convertXoGToxoG(FluidSystem::convertRsToXoG(
Rs(), pvtRegionIdx_),
604 assert(compIdx == gasCompIdx);
605 return FluidSystem::convertXoGToxoG(FluidSystem::convertRsToXoG(
Rs(), pvtRegionIdx_),
611 if (compIdx == waterCompIdx)
613 else if (compIdx == oilCompIdx)
614 return FluidSystem::convertXgOToxgO(FluidSystem::convertRvToXgO(
Rv(), pvtRegionIdx_),
617 assert(compIdx == gasCompIdx);
618 return 1.0 - FluidSystem::convertXgOToxgO(FluidSystem::convertRvToXgO(
Rv(), pvtRegionIdx_),
624 throw std::logic_error(
"Invalid phase or component index!");
630 Scalar
molarity(
unsigned phaseIdx,
unsigned compIdx)
const
639 for (
unsigned compIdx = 0; compIdx < numComponents; ++ compIdx)
640 result += FluidSystem::molarMass(compIdx, pvtRegionIdx_)*
moleFraction(phaseIdx, compIdx);
648 {
return FluidSystem::fugacityCoefficient(*
this, phaseIdx, compIdx, pvtRegionIdx_); }
653 Scalar
fugacity(
unsigned phaseIdx,
unsigned compIdx)
const
662 static unsigned storageToCanonicalPhaseIndex_(
unsigned storagePhaseIdx)
664 if constexpr (numStoragePhases == 3)
665 return storagePhaseIdx;
667 return FluidSystem::activeToCanonicalPhaseIdx(storagePhaseIdx);
670 static unsigned canonicalToStoragePhaseIndex_(
unsigned canonicalPhaseIdx)
672 if constexpr (numStoragePhases == 3)
673 return canonicalPhaseIdx;
675 return FluidSystem::canonicalToActivePhaseIdx(canonicalPhaseIdx);
678 ConditionalStorage<enableTemperature || enableEnergy, Scalar> temperature_;
679 ConditionalStorage<enableEnergy, std::array<Scalar, numStoragePhases> > enthalpy_;
680 Scalar totalSaturation_;
681 std::array<Scalar, numStoragePhases> pressure_;
682 std::array<Scalar, numStoragePhases> pc_;
683 std::array<Scalar, numStoragePhases> saturation_;
684 std::array<Scalar, numStoragePhases> invB_;
685 std::array<Scalar, numStoragePhases> density_;
686 ConditionalStorage<enableDissolution,Scalar> Rs_;
687 ConditionalStorage<enableDissolution, Scalar> Rv_;
688 ConditionalStorage<enableVapwat,Scalar> Rvw_;
689 ConditionalStorage<enableDissolutionInWater,Scalar> Rsw_;
690 ConditionalStorage<enableBrine, Scalar> saltConcentration_;
691 ConditionalStorage<enableSaltPrecipitation, Scalar> saltSaturation_;
692 unsigned short pvtRegionIdx_;
A fluid system which uses the black-oil model assumptions to calculate termodynamically meaningful qu...
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
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:387
Scalar moleFraction(unsigned phaseIdx, unsigned compIdx) const
Return the mole fraction of a component in a fluid phase [-].
Definition BlackOilFluidState.hpp:589
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
const Scalar & Rv() const
Return the oil vaporization factor of gas [m^3/m^3].
Definition BlackOilFluidState.hpp:414
void setDensity(unsigned phaseIdx, const Scalar &rho)
\ brief Set the density of a fluid phase
Definition BlackOilFluidState.hpp:295
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:636
void setInvB(unsigned phaseIdx, const Scalar &b)
\ brief Set the inverse formation volume factor of a fluid phase
Definition BlackOilFluidState.hpp:289
const Scalar & Rsw() const
Return the gas dissolution factor of water [m^3/m^3].
Definition BlackOilFluidState.hpp:448
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:630
Scalar internalEnergy(unsigned phaseIdx) const
Return the specific internal energy [J/kg] of a given fluid phase.
Definition BlackOilFluidState.hpp:512
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:653
void setTotalSaturation(const Scalar &value)
Set the total saturation used for sequential methods.
Definition BlackOilFluidState.hpp:255
const Scalar & saltConcentration() const
Return the concentration of salt in water.
Definition BlackOilFluidState.hpp:461
const Scalar & saltSaturation() const
Return the saturation of solid salt.
Definition BlackOilFluidState.hpp:474
const Scalar & temperature(unsigned) const
Return the temperature [K].
Definition BlackOilFluidState.hpp:371
Scalar molarDensity(unsigned phaseIdx) const
Return the molar density of a fluid phase [mol/m^3].
Definition BlackOilFluidState.hpp:522
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:488
Scalar massFraction(unsigned phaseIdx, unsigned compIdx) const
Return the mass fraction of a component in a fluid phase [-].
Definition BlackOilFluidState.hpp:552
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:647
const Scalar & enthalpy(unsigned phaseIdx) const
Return the specific enthalpy [J/kg] of a given fluid phase.
Definition BlackOilFluidState.hpp:503
Scalar molarVolume(unsigned phaseIdx) const
Return the molar volume of a fluid phase [m^3/mol].
Definition BlackOilFluidState.hpp:540
const Scalar & Rvw() const
Return the water vaporization factor of gas [m^3/m^3].
Definition BlackOilFluidState.hpp:431
const Scalar & Rs() const
Return the gas dissolution factor of oil [m^3/m^3].
Definition BlackOilFluidState.hpp:397
Scalar density(unsigned phaseIdx) const
Return the density [kg/m^3] of a given fluid phase.
Definition BlackOilFluidState.hpp:494
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:546
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