28 #ifndef OPM_BLACK_OIL_FLUID_STATE_HH
29 #define OPM_BLACK_OIL_FLUID_STATE_HH
42 template <class FluidState>
43 unsigned getPvtRegionIndex_(typename std::enable_if<HasMember_pvtRegionIndex<FluidState>::value,
44 const FluidState&>::type fluidState)
45 {
return fluidState.pvtRegionIndex(); }
47 template <
class Flu
idState>
48 unsigned getPvtRegionIndex_(
typename std::enable_if<!HasMember_pvtRegionIndex<FluidState>::value,
49 const FluidState&>::type)
54 template <class FluidSystem, class FluidState, class LhsEval>
55 auto getInvB_(typename std::enable_if<HasMember_invB<FluidState>::value,
56 const FluidState&>::type fluidState,
59 -> decltype(decay<LhsEval>(fluidState.invB(phaseIdx)))
60 {
return decay<LhsEval>(fluidState.invB(phaseIdx)); }
62 template <
class Flu
idSystem,
class Flu
idState,
class LhsEval>
63 LhsEval getInvB_(
typename std::enable_if<!HasMember_invB<FluidState>::value,
64 const FluidState&>::type fluidState,
66 unsigned pvtRegionIdx)
68 const auto& rho = fluidState.density(phaseIdx);
69 const auto& Xsolvent =
70 fluidState.massFraction(phaseIdx, FluidSystem::solventComponentIndex(phaseIdx));
74 *decay<LhsEval>(Xsolvent)
75 /FluidSystem::referenceDensity(phaseIdx, pvtRegionIdx);
80 template <class FluidState>
81 auto getSaltConcentration_(typename std::enable_if<HasMember_saltConcentration<FluidState>::value,
82 const FluidState&>::type fluidState)
83 {
return fluidState.saltConcentration(); }
85 template <
class Flu
idState>
86 auto getSaltConcentration_(
typename std::enable_if<!HasMember_saltConcentration<FluidState>::value,
87 const FluidState&>::type)
92 template <class FluidState>
93 auto getSaltSaturation_(typename std::enable_if<HasMember_saltSaturation<FluidState>::value,
94 const FluidState&>::type fluidState)
95 {
return fluidState.saltSaturation(); }
98 template <
class Flu
idState>
99 auto getSaltSaturation_(
typename std::enable_if<!HasMember_saltSaturation<FluidState>::value,
100 const FluidState&>::type)
110 template <
class ScalarT,
112 bool enableTemperature =
false,
113 bool enableEnergy =
false,
114 bool enableDissolution =
true,
115 bool enableEvaporation =
false,
116 bool enableBrine =
false,
117 bool enableSaltPrecipitation =
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 typedef ScalarT Scalar;
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]);
154 Valgrind::CheckDefined((*enthalpy_)[storagePhaseIdx]);
157 if (enableDissolution) {
158 Valgrind::CheckDefined(*Rs_);
159 Valgrind::CheckDefined(*Rv_);
162 if (enableEvaporation) {
163 Valgrind::CheckDefined(*Rvw_);
167 Valgrind::CheckDefined(*saltConcentration_);
170 if (enableSaltPrecipitation) {
171 Valgrind::CheckDefined(*saltSaturation_);
174 if (enableTemperature || enableEnergy)
175 Valgrind::CheckDefined(*temperature_);
183 template <
class Flu
idState>
186 if (enableTemperature || enableEnergy)
189 unsigned pvtRegionIdx = getPvtRegionIndex_<FluidState>(fs);
192 if (enableDissolution) {
193 setRs(BlackOil::getRs_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
194 setRv(BlackOil::getRv_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
196 if (enableEvaporation) {
197 setRvw(BlackOil::getRvw_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
200 setSaltConcentration(BlackOil::getSaltConcentration_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
202 if (enableSaltPrecipitation){
203 setSaltSaturation(BlackOil::getSaltSaturation_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx));
205 for (
unsigned storagePhaseIdx = 0; storagePhaseIdx < numStoragePhases; ++storagePhaseIdx) {
206 unsigned phaseIdx = storageToCanonicalPhaseIndex_(storagePhaseIdx);
214 setInvB(phaseIdx, getInvB_<FluidSystem, FluidState, Scalar>(fs, phaseIdx, pvtRegionIdx));
225 { pvtRegionIdx_ =
static_cast<unsigned short>(newPvtRegionIdx); }
231 { pressure_[canonicalToStoragePhaseIndex_(phaseIdx)] = p; }
237 { saturation_[canonicalToStoragePhaseIndex_(phaseIdx)] = S; }
242 void setPc(
unsigned phaseIdx,
const Scalar&
pc)
243 { pc_[canonicalToStoragePhaseIndex_(phaseIdx)] =
pc; }
250 totalSaturation_ = value;
261 assert(enableTemperature || enableEnergy);
263 (*temperature_) = value;
274 assert(enableTemperature || enableEnergy);
276 (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx)] = value;
282 void setInvB(
unsigned phaseIdx,
const Scalar& b)
283 { invB_[canonicalToStoragePhaseIndex_(phaseIdx)] = b; }
289 { density_[canonicalToStoragePhaseIndex_(phaseIdx)] = rho; }
319 { *saltConcentration_ = newSaltConcentration; }
325 { *saltSaturation_ = newSaltSaturation; }
331 {
return pressure_[canonicalToStoragePhaseIndex_(phaseIdx)]; }
337 {
return saturation_[canonicalToStoragePhaseIndex_(phaseIdx)]; }
342 const Scalar&
pc(
unsigned phaseIdx)
const
343 {
return pc_[canonicalToStoragePhaseIndex_(phaseIdx)]; }
350 return totalSaturation_;
358 if (!enableTemperature && !enableEnergy) {
359 static Scalar tmp(FluidSystem::reservoirTemperature(pvtRegionIdx_));
363 return *temperature_;
372 const Scalar&
invB(
unsigned phaseIdx)
const
373 {
return invB_[canonicalToStoragePhaseIndex_(phaseIdx)]; }
382 const Scalar&
Rs()
const
384 if (!enableDissolution) {
385 static Scalar
null = 0.0;
399 const Scalar&
Rv()
const
401 if (!enableDissolution) {
402 static Scalar
null = 0.0;
418 if (!enableEvaporation) {
419 static Scalar
null = 0.0;
432 static Scalar
null = 0.0;
436 return *saltConcentration_;
444 if (!enableSaltPrecipitation) {
445 static Scalar
null = 0.0;
449 return *saltSaturation_;
461 {
return pvtRegionIdx_; }
467 {
return density_[canonicalToStoragePhaseIndex_(phaseIdx)]; }
476 {
return (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx)]; }
485 {
return (*enthalpy_)[canonicalToStoragePhaseIndex_(phaseIdx)] -
pressure(phaseIdx)/
density(phaseIdx); }
496 const auto& rho =
density(phaseIdx);
498 if (phaseIdx == waterPhaseIdx)
499 return rho/FluidSystem::molarMass(waterCompIdx, pvtRegionIdx_);
502 rho*(
moleFraction(phaseIdx, gasCompIdx)/FluidSystem::molarMass(gasCompIdx, pvtRegionIdx_)
503 +
moleFraction(phaseIdx, oilCompIdx)/FluidSystem::molarMass(oilCompIdx, pvtRegionIdx_));
519 {
return FluidSystem::viscosity(*
this, phaseIdx, pvtRegionIdx_); }
528 if (compIdx == waterCompIdx)
533 if (compIdx == waterCompIdx)
535 else if (compIdx == oilCompIdx)
536 return 1.0 - FluidSystem::convertRsToXoG(
Rs(), pvtRegionIdx_);
538 assert(compIdx == gasCompIdx);
539 return FluidSystem::convertRsToXoG(
Rs(), pvtRegionIdx_);
544 if (compIdx == waterCompIdx)
546 else if (compIdx == oilCompIdx)
547 return FluidSystem::convertRvToXgO(
Rv(), pvtRegionIdx_);
549 assert(compIdx == gasCompIdx);
550 return 1.0 - FluidSystem::convertRvToXgO(
Rv(), pvtRegionIdx_);
555 throw std::logic_error(
"Invalid phase or component index!");
565 if (compIdx == waterCompIdx)
570 if (compIdx == waterCompIdx)
572 else if (compIdx == oilCompIdx)
573 return 1.0 - FluidSystem::convertXoGToxoG(FluidSystem::convertRsToXoG(
Rs(), pvtRegionIdx_),
576 assert(compIdx == gasCompIdx);
577 return FluidSystem::convertXoGToxoG(FluidSystem::convertRsToXoG(
Rs(), pvtRegionIdx_),
583 if (compIdx == waterCompIdx)
585 else if (compIdx == oilCompIdx)
586 return FluidSystem::convertXgOToxgO(FluidSystem::convertRvToXgO(
Rv(), pvtRegionIdx_),
589 assert(compIdx == gasCompIdx);
590 return 1.0 - FluidSystem::convertXgOToxgO(FluidSystem::convertRvToXgO(
Rv(), pvtRegionIdx_),
596 throw std::logic_error(
"Invalid phase or component index!");
602 Scalar
molarity(
unsigned phaseIdx,
unsigned compIdx)
const
611 for (
unsigned compIdx = 0; compIdx < numComponents; ++ compIdx)
612 result += FluidSystem::molarMass(compIdx, pvtRegionIdx_)*
moleFraction(phaseIdx, compIdx);
620 {
return FluidSystem::fugacityCoefficient(*
this, phaseIdx, compIdx, pvtRegionIdx_); }
625 Scalar
fugacity(
unsigned phaseIdx,
unsigned compIdx)
const
634 static unsigned storageToCanonicalPhaseIndex_(
unsigned storagePhaseIdx)
636 if (numStoragePhases == 3)
637 return storagePhaseIdx;
639 return FluidSystem::activeToCanonicalPhaseIdx(storagePhaseIdx);
642 static unsigned canonicalToStoragePhaseIndex_(
unsigned canonicalPhaseIdx)
644 if (numStoragePhases == 3)
645 return canonicalPhaseIdx;
647 return FluidSystem::canonicalToActivePhaseIdx(canonicalPhaseIdx);
650 ConditionalStorage<enableTemperature || enableEnergy, Scalar> temperature_;
651 ConditionalStorage<enableEnergy, std::array<Scalar, numStoragePhases> > enthalpy_;
652 Scalar totalSaturation_;
653 std::array<Scalar, numStoragePhases> pressure_;
654 std::array<Scalar, numStoragePhases> pc_;
655 std::array<Scalar, numStoragePhases> saturation_;
656 std::array<Scalar, numStoragePhases> invB_;
657 std::array<Scalar, numStoragePhases> density_;
658 ConditionalStorage<enableDissolution,Scalar> Rs_;
659 ConditionalStorage<enableDissolution, Scalar> Rv_;
660 ConditionalStorage<enableEvaporation,Scalar> Rvw_;
661 ConditionalStorage<enableBrine, Scalar> saltConcentration_;
662 ConditionalStorage<enableSaltPrecipitation, Scalar> saltSaturation_;
663 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
Provides the OPM_UNUSED macro.
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 setTemperature(const Scalar &value)
Set the temperature [K].
Definition: BlackOilFluidState.hpp:259
const Scalar & Rv() const
Return the oil vaporization factor of gas [m^3/m^3].
Definition: BlackOilFluidState.hpp:399
void setSaltSaturation(const Scalar &newSaltSaturation)
Set the solid salt saturation.
Definition: BlackOilFluidState.hpp:324
void setPc(unsigned phaseIdx, const Scalar &pc)
Set the capillary pressure of a fluid phase [-].
Definition: BlackOilFluidState.hpp:242
const Scalar & Rvw() const
Return the water vaporization factor of gas [m^3/m^3].
Definition: BlackOilFluidState.hpp:416
unsigned short pvtRegionIndex() const
Return the PVT region where the current fluid state is assumed to be part of.
Definition: BlackOilFluidState.hpp:460
void setDensity(unsigned phaseIdx, const Scalar &rho)
\ brief Set the density of a fluid phase
Definition: BlackOilFluidState.hpp:288
const Scalar & invB(unsigned phaseIdx) const
Return the inverse formation volume factor of a fluid phase [-].
Definition: BlackOilFluidState.hpp:372
const Scalar & enthalpy(unsigned phaseIdx) const
Return the specific enthalpy [J/kg] of a given fluid phase.
Definition: BlackOilFluidState.hpp:475
void setRs(const Scalar &newRs)
Set the gas dissolution factor [m^3/m^3] of the oil phase.
Definition: BlackOilFluidState.hpp:296
Scalar fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
Return the fugacity coefficient of a component in a fluid phase [-].
Definition: BlackOilFluidState.hpp:619
void setSaturation(unsigned phaseIdx, const Scalar &S)
Set the saturation of a fluid phase [-].
Definition: BlackOilFluidState.hpp:236
void setInvB(unsigned phaseIdx, const Scalar &b)
\ brief Set the inverse formation volume factor of a fluid phase
Definition: BlackOilFluidState.hpp:282
Scalar averageMolarMass(unsigned phaseIdx) const
Return the partial molar density of a fluid phase [kg / mol].
Definition: BlackOilFluidState.hpp:608
const Scalar & pc(unsigned phaseIdx) const
Return the capillary pressure of a fluid phase [-].
Definition: BlackOilFluidState.hpp:342
void setRv(const Scalar &newRv)
Set the oil vaporization factor [m^3/m^3] of the gas phase.
Definition: BlackOilFluidState.hpp:304
const Scalar & saltSaturation() const
Return the saturation of solid salt.
Definition: BlackOilFluidState.hpp:442
void setPressure(unsigned phaseIdx, const Scalar &p)
Set the pressure of a fluid phase [-].
Definition: BlackOilFluidState.hpp:230
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: BlackOilFluidState.hpp:184
Scalar density(unsigned phaseIdx) const
Return the density [kg/m^3] of a given fluid phase.
Definition: BlackOilFluidState.hpp:466
void checkDefined() const
Make sure that all attributes are defined.
Definition: BlackOilFluidState.hpp:142
Scalar molarVolume(unsigned phaseIdx) const
Return the molar volume of a fluid phase [m^3/mol].
Definition: BlackOilFluidState.hpp:512
const Scalar & pressure(unsigned phaseIdx) const
Return the pressure of a fluid phase [Pa].
Definition: BlackOilFluidState.hpp:330
const Scalar & temperature(unsigned) const
Return the temperature [K].
Definition: BlackOilFluidState.hpp:356
const Scalar & saturation(unsigned phaseIdx) const
Return the saturation of a fluid phase [-].
Definition: BlackOilFluidState.hpp:336
Scalar molarDensity(unsigned phaseIdx) const
Return the molar density of a fluid phase [mol/m^3].
Definition: BlackOilFluidState.hpp:494
Scalar moleFraction(unsigned phaseIdx, unsigned compIdx) const
Return the mole fraction of a component in a fluid phase [-].
Definition: BlackOilFluidState.hpp:561
void setSaltConcentration(const Scalar &newSaltConcentration)
Set the salt concentration.
Definition: BlackOilFluidState.hpp:318
Scalar internalEnergy(unsigned phaseIdx) const
Return the specific internal energy [J/kg] of a given fluid phase.
Definition: BlackOilFluidState.hpp:484
const Scalar & totalSaturation() const
Return the total saturation needed for sequential.
Definition: BlackOilFluidState.hpp:348
Scalar viscosity(unsigned phaseIdx) const
Return the dynamic viscosity of a fluid phase [Pa s].
Definition: BlackOilFluidState.hpp:518
void setPvtRegionIndex(unsigned newPvtRegionIdx)
Set the index of the fluid region.
Definition: BlackOilFluidState.hpp:224
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:602
void setRvw(const Scalar &newRvw)
Set the water vaporization factor [m^3/m^3] of the gas phase.
Definition: BlackOilFluidState.hpp:312
Scalar massFraction(unsigned phaseIdx, unsigned compIdx) const
Return the mass fraction of a component in a fluid phase [-].
Definition: BlackOilFluidState.hpp:524
const Scalar & Rs() const
Return the gas dissulition factor of oil [m^3/m^3].
Definition: BlackOilFluidState.hpp:382
void setTotalSaturation(const Scalar &value)
Set the total saturation used for sequential methods.
Definition: BlackOilFluidState.hpp:248
const Scalar & saltConcentration() const
Return the concentration of salt in water.
Definition: BlackOilFluidState.hpp:429
Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
Return the fugacity of a component in a fluid phase [Pa].
Definition: BlackOilFluidState.hpp:625
void setEnthalpy(unsigned phaseIdx, const Scalar &value)
Set the specific enthalpy [J/kg] of a given fluid phase.
Definition: BlackOilFluidState.hpp:272