27 #ifndef OPM_BLACK_OIL_FLUID_SYSTEM_HPP
28 #define OPM_BLACK_OIL_FLUID_SYSTEM_HPP
45 #include <opm/input/eclipse/EclipseState/EclipseState.hpp>
46 #include <opm/input/eclipse/EclipseState/Tables/FlatTable.hpp>
47 #include <opm/input/eclipse/EclipseState/Tables/TableManager.hpp>
62 template <class FluidSystem, class FluidState, class LhsEval>
63 LhsEval getRs_(typename std::enable_if<!HasMember_Rs<FluidState>::value, const FluidState&>::type fluidState,
67 decay<LhsEval>(fluidState.massFraction(FluidSystem::oilPhaseIdx, FluidSystem::gasCompIdx));
68 return FluidSystem::convertXoGToRs(XoG, regionIdx);
71 template <
class Flu
idSystem,
class Flu
idState,
class LhsEval>
72 auto getRs_(
typename std::enable_if<HasMember_Rs<FluidState>::value,
const FluidState&>::type fluidState,
74 -> decltype(decay<LhsEval>(fluidState.Rs()))
75 {
return decay<LhsEval>(fluidState.Rs()); }
77 template <
class Flu
idSystem,
class Flu
idState,
class LhsEval>
78 LhsEval getRv_(
typename std::enable_if<!HasMember_Rv<FluidState>::value,
const FluidState&>::type fluidState,
82 decay<LhsEval>(fluidState.massFraction(FluidSystem::gasPhaseIdx, FluidSystem::oilCompIdx));
83 return FluidSystem::convertXgOToRv(XgO, regionIdx);
86 template <
class Flu
idSystem,
class Flu
idState,
class LhsEval>
87 auto getRv_(
typename std::enable_if<HasMember_Rv<FluidState>::value,
const FluidState&>::type fluidState,
89 -> decltype(decay<LhsEval>(fluidState.Rv()))
90 {
return decay<LhsEval>(fluidState.Rv()); }
92 template <
class Flu
idSystem,
class Flu
idState,
class LhsEval>
93 LhsEval getRvw_(
typename std::enable_if<!HasMember_Rvw<FluidState>::value,
const FluidState&>::type fluidState,
97 decay<LhsEval>(fluidState.massFraction(FluidSystem::gasPhaseIdx, FluidSystem::waterCompIdx));
98 return FluidSystem::convertXgWToRvw(XgW, regionIdx);
101 template <
class Flu
idSystem,
class Flu
idState,
class LhsEval>
102 auto getRvw_(
typename std::enable_if<HasMember_Rvw<FluidState>::value,
const FluidState&>::type fluidState,
104 -> decltype(decay<LhsEval>(fluidState.Rvw()))
105 {
return decay<LhsEval>(fluidState.Rvw()); }
107 template <
class Flu
idSystem,
class Flu
idState,
class LhsEval>
108 LhsEval getSaltConcentration_(
typename std::enable_if<!HasMember_saltConcentration<FluidState>::value,
109 const FluidState&>::type,
113 template <
class Flu
idSystem,
class Flu
idState,
class LhsEval>
114 auto getSaltConcentration_(
typename std::enable_if<HasMember_saltConcentration<FluidState>::value,
const FluidState&>::type fluidState,
116 -> decltype(decay<LhsEval>(fluidState.saltConcentration()))
117 {
return decay<LhsEval>(fluidState.saltConcentration()); }
119 template <
class Flu
idSystem,
class Flu
idState,
class LhsEval>
120 LhsEval getSaltSaturation_(
typename std::enable_if<!HasMember_saltSaturation<FluidState>::value,
121 const FluidState&>::type,
125 template <
class Flu
idSystem,
class Flu
idState,
class LhsEval>
126 auto getSaltSaturation_(
typename std::enable_if<HasMember_saltSaturation<FluidState>::value,
const FluidState&>::type fluidState,
128 -> decltype(decay<LhsEval>(fluidState.saltSaturation()))
129 {
return decay<LhsEval>(fluidState.saltSaturation()); }
139 template <
class Scalar,
class IndexTraits = BlackOilDefaultIndexTraits>
150 template <
class EvaluationT>
153 typedef EvaluationT Evaluation;
158 maxOilSat_ = maxOilSat;
159 regionIdx_ = regionIdx;
169 template <
class OtherCache>
172 regionIdx_ = other.regionIndex();
173 maxOilSat_ = other.maxOilSat();
184 {
return regionIdx_; }
194 { regionIdx_ = val; }
196 const Evaluation& maxOilSat()
const
197 {
return maxOilSat_; }
199 void setMaxOilSat(
const Evaluation& val)
200 { maxOilSat_ = val; }
203 Evaluation maxOilSat_;
214 static void initFromState(
const EclipseState& eclState,
const Schedule& schedule)
216 size_t numRegions = eclState.runspec().tabdims().getNumPVTTables();
219 numActivePhases_ = 0;
220 std::fill_n(&phaseIsActive_[0],
numPhases,
false);
223 if (eclState.runspec().phases().active(Phase::OIL)) {
228 if (eclState.runspec().phases().active(Phase::GAS)) {
233 if (eclState.runspec().phases().active(Phase::WATER)) {
247 assert(numActivePhases_ >= 1 && numActivePhases_ <= 3);
254 gasPvt_ = std::make_shared<GasPvt>();
255 gasPvt_->initFromState(eclState, schedule);
259 oilPvt_ = std::make_shared<OilPvt>();
260 oilPvt_->initFromState(eclState, schedule);
264 waterPvt_ = std::make_shared<WaterPvt>();
265 waterPvt_->initFromState(eclState, schedule);
269 for (
unsigned regionIdx = 0; regionIdx <
numRegions; ++regionIdx) {
283 if (eclState.runspec().co2Storage()) {
284 for (
unsigned regionIdx = 0; regionIdx <
numRegions; ++regionIdx) {
292 const auto& diffCoeffTables = eclState.getTableManager().getDiffusionCoefficientTable();
293 if(!diffCoeffTables.empty()) {
296 diffusionCoefficients_.resize(
numRegions,{0,0,0,0,0,0,0,0,0});
298 for (
unsigned regionIdx = 0; regionIdx <
numRegions; ++regionIdx) {
299 const auto& diffCoeffTable = diffCoeffTables[regionIdx];
300 molarMass_[regionIdx][
oilCompIdx] = diffCoeffTable.oil_mw;
301 molarMass_[regionIdx][
gasCompIdx] = diffCoeffTable.gas_mw;
306 if(diffCoeffTable.gas_in_oil_cross_phase > 0 || diffCoeffTable.oil_in_oil_cross_phase > 0) {
307 throw std::runtime_error(
"Cross phase diffusion is set in the deck, but not implemented in Flow. "
308 "Please default DIFFC item 7 and item 8 or set it to zero.");
326 isInitialized_ =
false;
328 enableDissolvedGas_ =
true;
329 enableVaporizedOil_ =
false;
330 enableVaporizedWater_ =
false;
331 enableDiffusion_ =
false;
342 std::fill_n(&phaseIsActive_[0],
numPhases,
true);
344 resizeArrays_(numPvtRegions);
354 { enableDissolvedGas_ = yesno; }
363 { enableVaporizedOil_ = yesno; }
372 { enableVaporizedWater_ = yesno; }
380 { enableDiffusion_ = yesno; }
387 { gasPvt_ = pvtObj; }
393 { oilPvt_ = pvtObj; }
399 { waterPvt_ = pvtObj; }
413 referenceDensity_[regionIdx][
oilPhaseIdx] = rhoOil;
415 referenceDensity_[regionIdx][
gasPhaseIdx] = rhoGas;
426 for (
unsigned regionIdx = 0; regionIdx <
numRegions; ++ regionIdx) {
448 int activePhaseIdx = 0;
449 for (
unsigned phaseIdx = 0; phaseIdx <
numPhases; ++phaseIdx) {
451 canonicalToActivePhaseIdx_[phaseIdx] = activePhaseIdx;
452 activeToCanonicalPhaseIdx_[activePhaseIdx] = phaseIdx;
456 isInitialized_ =
true;
459 static bool isInitialized()
460 {
return isInitialized_; }
494 throw std::logic_error(
"Phase index " + std::to_string(phaseIdx) +
" is unknown");
520 static unsigned char numActivePhases_;
521 static std::array<bool,numPhases> phaseIsActive_;
526 {
return numActivePhases_; }
532 return phaseIsActive_[phaseIdx];
547 throw std::logic_error(
"Phase index " + std::to_string(phaseIdx) +
" is unknown");
556 throw std::logic_error(
"The water phase does not have any solutes in the black oil model!");
563 throw std::logic_error(
"Phase index " + std::to_string(phaseIdx) +
" is unknown");
579 throw std::logic_error(
"Component index " + std::to_string(compIdx) +
" is unknown");
585 {
return molarMass_[regionIdx][compIdx]; }
613 {
return molarMass_.size(); }
622 {
return enableDissolvedGas_; }
631 {
return enableVaporizedOil_; }
640 {
return enableVaporizedWater_; }
648 {
return enableDiffusion_; }
656 {
return referenceDensity_[regionIdx][phaseIdx]; }
662 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar,
class ParamCacheEval = LhsEval>
663 static LhsEval
density(
const FluidState& fluidState,
666 {
return density<FluidState, LhsEval>(fluidState, phaseIdx, paramCache.
regionIndex()); }
669 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar,
class ParamCacheEval = LhsEval>
675 return fugacityCoefficient<FluidState, LhsEval>(fluidState,
682 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar,
class ParamCacheEval = LhsEval>
686 {
return viscosity<FluidState, LhsEval>(fluidState, phaseIdx, paramCache.
regionIndex()); }
689 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar,
class ParamCacheEval = LhsEval>
690 static LhsEval
enthalpy(
const FluidState& fluidState,
693 {
return enthalpy<FluidState, LhsEval>(fluidState, phaseIdx, paramCache.
regionIndex()); }
700 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
701 static LhsEval
density(
const FluidState& fluidState,
708 const LhsEval& p = decay<LhsEval>(fluidState.pressure(phaseIdx));
709 const LhsEval& T = decay<LhsEval>(fluidState.temperature(phaseIdx));
710 const LhsEval& saltConcentration = BlackOil::template getSaltConcentration_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
716 const LhsEval& Rs = BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
717 const LhsEval& bo = oilPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rs);
725 const LhsEval Rs(0.0);
726 const auto& bo = oilPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rs);
734 const LhsEval& Rv = BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
735 const LhsEval& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv);
744 const LhsEval& Rvw = BlackOil::template getRvw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
745 const LhsEval& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rvw);
753 const LhsEval Rv(0.0);
754 const auto& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv);
761 * waterPvt_->inverseFormationVolumeFactor(regionIdx, T, p, saltConcentration);
764 throw std::logic_error(
"Unhandled phase index "+std::to_string(phaseIdx));
774 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
782 const auto& p = fluidState.pressure(phaseIdx);
783 const auto& T = fluidState.temperature(phaseIdx);
789 const LhsEval& Rs = saturatedDissolutionFactor<FluidState, LhsEval>(fluidState,
oilPhaseIdx, regionIdx);
790 const LhsEval& bo = oilPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rs);
798 const LhsEval Rs(0.0);
799 const LhsEval& bo = oilPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rs);
806 const LhsEval& Rv = saturatedDissolutionFactor<FluidState, LhsEval>(fluidState,
gasPhaseIdx, regionIdx);
807 const LhsEval& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv);
816 const LhsEval& Rvw = saturatedVaporizationFactor<FluidState, LhsEval>(fluidState,
gasPhaseIdx, regionIdx);
817 const LhsEval& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rvw);
825 const LhsEval Rv(0.0);
826 const LhsEval& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv);
835 *inverseFormationVolumeFactor<FluidState, LhsEval>(fluidState,
waterPhaseIdx, regionIdx);
838 throw std::logic_error(
"Unhandled phase index "+std::to_string(phaseIdx));
849 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
857 const auto& p = decay<LhsEval>(fluidState.pressure(phaseIdx));
858 const auto& T = decay<LhsEval>(fluidState.temperature(phaseIdx));
859 const auto& saltConcentration = decay<LhsEval>(fluidState.saltConcentration());
864 const auto& Rs = BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
866 && Rs >= (1.0 - 1e-10)*oilPvt_->saturatedGasDissolutionFactor(regionIdx, scalarValue(T), scalarValue(p)))
868 return oilPvt_->saturatedInverseFormationVolumeFactor(regionIdx, T, p);
870 return oilPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rs);
874 const LhsEval Rs(0.0);
875 return oilPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rs);
879 const auto& Rv = BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
881 && Rv >= (1.0 - 1e-10)*gasPvt_->saturatedOilVaporizationFactor(regionIdx, scalarValue(T), scalarValue(p)))
883 return gasPvt_->saturatedInverseFormationVolumeFactor(regionIdx, T, p);
885 return gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv);
889 const LhsEval Rv(0.0);
890 return gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv);
893 return waterPvt_->inverseFormationVolumeFactor(regionIdx, T, p, saltConcentration);
894 default:
throw std::logic_error(
"Unhandled phase index "+std::to_string(phaseIdx));
905 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
913 const auto& p = decay<LhsEval>(fluidState.pressure(phaseIdx));
914 const auto& T = decay<LhsEval>(fluidState.temperature(phaseIdx));
915 const auto& saltConcentration = decay<LhsEval>(fluidState.saltConcentration());
918 case oilPhaseIdx:
return oilPvt_->saturatedInverseFormationVolumeFactor(regionIdx, T, p);
919 case gasPhaseIdx:
return gasPvt_->saturatedInverseFormationVolumeFactor(regionIdx, T, p);
920 case waterPhaseIdx:
return waterPvt_->inverseFormationVolumeFactor(regionIdx, T, p, saltConcentration);
921 default:
throw std::logic_error(
"Unhandled phase index "+std::to_string(phaseIdx));
926 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
936 const auto& p = decay<LhsEval>(fluidState.pressure(phaseIdx));
937 const auto& T = decay<LhsEval>(fluidState.temperature(phaseIdx));
942 const LhsEval phi_oO = 20e3/p;
945 const Scalar phi_gG = 1.0;
949 const LhsEval phi_wW = 30e3/p;
967 const auto& R_vSat = gasPvt_->saturatedOilVaporizationFactor(regionIdx, T, p);
971 const auto& R_sSat = oilPvt_->saturatedGasDissolutionFactor(regionIdx, T, p);
974 const auto& x_oOSat = 1.0 - x_oGSat;
976 const auto& p_o = decay<LhsEval>(fluidState.pressure(
oilPhaseIdx));
977 const auto& p_g = decay<LhsEval>(fluidState.pressure(
gasPhaseIdx));
979 return phi_oO*p_o*x_oOSat / (p_g*x_gOSat);
987 throw std::logic_error(
"Invalid component index "+std::to_string(compIdx));
1003 const auto& R_vSat = gasPvt_->saturatedOilVaporizationFactor(regionIdx, T, p);
1006 const auto& x_gGSat = 1.0 - x_gOSat;
1008 const auto& R_sSat = oilPvt_->saturatedGasDissolutionFactor(regionIdx, T, p);
1012 const auto& p_o = decay<LhsEval>(fluidState.pressure(
oilPhaseIdx));
1013 const auto& p_g = decay<LhsEval>(fluidState.pressure(
gasPhaseIdx));
1015 return phi_gG*p_g*x_gGSat / (p_o*x_oGSat);
1022 throw std::logic_error(
"Invalid component index "+std::to_string(compIdx));
1037 throw std::logic_error(
"Invalid component index "+std::to_string(compIdx));
1041 throw std::logic_error(
"Invalid phase index "+std::to_string(phaseIdx));
1044 throw std::logic_error(
"Unhandled phase or component index");
1048 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
1056 const LhsEval& p = decay<LhsEval>(fluidState.pressure(phaseIdx));
1057 const LhsEval& T = decay<LhsEval>(fluidState.temperature(phaseIdx));
1058 const LhsEval& saltConcentration = BlackOil::template getSaltConcentration_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
1063 const auto& Rs = BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
1065 && Rs >= (1.0 - 1e-10)*oilPvt_->saturatedGasDissolutionFactor(regionIdx, scalarValue(T), scalarValue(p)))
1067 return oilPvt_->saturatedViscosity(regionIdx, T, p);
1069 return oilPvt_->viscosity(regionIdx, T, p, Rs);
1073 const LhsEval Rs(0.0);
1074 return oilPvt_->viscosity(regionIdx, T, p, Rs);
1079 const auto& Rv = BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
1081 && Rv >= (1.0 - 1e-10)*gasPvt_->saturatedOilVaporizationFactor(regionIdx, scalarValue(T), scalarValue(p)))
1083 return gasPvt_->saturatedViscosity(regionIdx, T, p);
1085 return gasPvt_->viscosity(regionIdx, T, p, Rv);
1089 const LhsEval Rv(0.0);
1090 return gasPvt_->viscosity(regionIdx, T, p, Rv);
1096 return waterPvt_->viscosity(regionIdx, T, p, saltConcentration);
1099 throw std::logic_error(
"Unhandled phase index "+std::to_string(phaseIdx));
1103 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
1111 const auto& p = decay<LhsEval>(fluidState.pressure(phaseIdx));
1112 const auto& T = decay<LhsEval>(fluidState.temperature(phaseIdx));
1117 oilPvt_->internalEnergy(regionIdx, T, p, BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx))
1118 + p/density<FluidState, LhsEval>(fluidState, phaseIdx, regionIdx);
1122 gasPvt_->internalEnergy(regionIdx, T, p, BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx))
1123 + p/density<FluidState, LhsEval>(fluidState, phaseIdx, regionIdx);
1127 waterPvt_->internalEnergy(regionIdx, T, p)
1128 + p/density<FluidState, LhsEval>(fluidState, phaseIdx, regionIdx);
1130 default:
throw std::logic_error(
"Unhandled phase index "+std::to_string(phaseIdx));
1133 throw std::logic_error(
"Unhandled phase index "+std::to_string(phaseIdx));
1142 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
1150 const auto& p = decay<LhsEval>(fluidState.pressure(phaseIdx));
1151 const auto& T = decay<LhsEval>(fluidState.temperature(phaseIdx));
1155 case gasPhaseIdx:
return gasPvt_->saturatedWaterVaporizationFactor(regionIdx, T, p);
1157 default:
throw std::logic_error(
"Unhandled phase index "+std::to_string(phaseIdx));
1167 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
1171 const LhsEval& maxOilSaturation)
1176 const auto& p = decay<LhsEval>(fluidState.pressure(phaseIdx));
1177 const auto& T = decay<LhsEval>(fluidState.temperature(phaseIdx));
1178 const auto& So = decay<LhsEval>(fluidState.saturation(
oilPhaseIdx));
1181 case oilPhaseIdx:
return oilPvt_->saturatedGasDissolutionFactor(regionIdx, T, p, So, maxOilSaturation);
1182 case gasPhaseIdx:
return gasPvt_->saturatedOilVaporizationFactor(regionIdx, T, p, So, maxOilSaturation);
1184 default:
throw std::logic_error(
"Unhandled phase index "+std::to_string(phaseIdx));
1196 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
1204 const auto& p = decay<LhsEval>(fluidState.pressure(phaseIdx));
1205 const auto& T = decay<LhsEval>(fluidState.temperature(phaseIdx));
1208 case oilPhaseIdx:
return oilPvt_->saturatedGasDissolutionFactor(regionIdx, T, p);
1209 case gasPhaseIdx:
return gasPvt_->saturatedOilVaporizationFactor(regionIdx, T, p);
1211 default:
throw std::logic_error(
"Unhandled phase index "+std::to_string(phaseIdx));
1218 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
1229 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
1246 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
1254 const auto& T = decay<LhsEval>(fluidState.temperature(phaseIdx));
1257 case oilPhaseIdx:
return oilPvt_->saturationPressure(regionIdx, T, BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
1258 case gasPhaseIdx:
return gasPvt_->saturationPressure(regionIdx, T, BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
1260 default:
throw std::logic_error(
"Unhandled phase index "+std::to_string(phaseIdx));
1271 template <
class LhsEval>
1277 return XoG/(1.0 - XoG)*(rho_oRef/rho_gRef);
1284 template <
class LhsEval>
1290 return XgO/(1.0 - XgO)*(rho_gRef/rho_oRef);
1297 template <
class LhsEval>
1303 return XgW/(1.0 - XgW)*(rho_gRef/rho_wRef);
1311 template <
class LhsEval>
1317 const LhsEval& rho_oG = Rs*rho_gRef;
1318 return rho_oG/(rho_oRef + rho_oG);
1325 template <
class LhsEval>
1331 const LhsEval& rho_gO = Rv*rho_oRef;
1332 return rho_gO/(rho_gRef + rho_gO);
1339 template <
class LhsEval>
1345 const LhsEval& rho_gW = Rvw*rho_wRef;
1346 return rho_gW/(rho_gRef + rho_gW);
1352 template <
class LhsEval>
1358 return XoG*MO / (MG*(1 - XoG) + XoG*MO);
1364 template <
class LhsEval>
1370 return xoG*MG / (xoG*(MG - MO) + MO);
1376 template <
class LhsEval>
1382 return XgO*MG / (MO*(1 - XgO) + XgO*MG);
1388 template <
class LhsEval>
1394 return xgO*MO / (xgO*(MO - MG) + MG);
1405 {
return *gasPvt_; }
1415 {
return *oilPvt_; }
1425 {
return *waterPvt_; }
1433 {
return reservoirTemperature_; }
1441 { reservoirTemperature_ = value; }
1443 static short activeToCanonicalPhaseIdx(
unsigned activePhaseIdx) {
1445 return activeToCanonicalPhaseIdx_[activePhaseIdx];
1448 static short canonicalToActivePhaseIdx(
unsigned phaseIdx) {
1451 return canonicalToActivePhaseIdx_[phaseIdx];
1456 {
return diffusionCoefficients_[regionIdx][
numPhases*compIdx + phaseIdx]; }
1460 { diffusionCoefficients_[regionIdx][
numPhases*compIdx + phaseIdx] = coefficient ; }
1465 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar,
class ParamCacheEval = LhsEval>
1476 if(!diffusionCoefficients_.empty()) {
1480 const auto& p = decay<LhsEval>(fluidState.pressure(phaseIdx));
1481 const auto& T = decay<LhsEval>(fluidState.temperature(phaseIdx));
1487 default:
throw std::logic_error(
"Unhandled phase index "+std::to_string(phaseIdx));
1498 static Scalar reservoirTemperature_;
1500 static std::shared_ptr<GasPvt> gasPvt_;
1501 static std::shared_ptr<OilPvt> oilPvt_;
1502 static std::shared_ptr<WaterPvt> waterPvt_;
1504 static bool enableDissolvedGas_;
1505 static bool enableVaporizedOil_;
1506 static bool enableVaporizedWater_;
1507 static bool enableDiffusion_;
1512 static std::vector<std::array<
Scalar, 3> > referenceDensity_;
1513 static std::vector<std::array<
Scalar, 3> > molarMass_;
1514 static std::vector<std::array<
Scalar, 3 * 3> > diffusionCoefficients_;
1516 static std::array<short, numPhases> activeToCanonicalPhaseIdx_;
1517 static std::array<short, numPhases> canonicalToActivePhaseIdx_;
1519 static bool isInitialized_;
1522 template <
class Scalar,
class IndexTraits>
1523 unsigned char BlackOilFluidSystem<Scalar, IndexTraits>::numActivePhases_;
1525 template <
class Scalar,
class IndexTraits>
1526 std::array<bool, BlackOilFluidSystem<Scalar, IndexTraits>::numPhases> BlackOilFluidSystem<Scalar, IndexTraits>::phaseIsActive_;
1528 template <
class Scalar,
class IndexTraits>
1529 std::array<short, BlackOilFluidSystem<Scalar, IndexTraits>::numPhases> BlackOilFluidSystem<Scalar, IndexTraits>::activeToCanonicalPhaseIdx_;
1531 template <
class Scalar,
class IndexTraits>
1532 std::array<short, BlackOilFluidSystem<Scalar, IndexTraits>::numPhases> BlackOilFluidSystem<Scalar, IndexTraits>::canonicalToActivePhaseIdx_;
1534 template <
class Scalar,
class IndexTraits>
1538 template <
class Scalar,
class IndexTraits>
1542 template <
class Scalar,
class IndexTraits>
1544 BlackOilFluidSystem<Scalar, IndexTraits>::reservoirTemperature_;
1546 template <
class Scalar,
class IndexTraits>
1547 bool BlackOilFluidSystem<Scalar, IndexTraits>::enableDissolvedGas_;
1549 template <
class Scalar,
class IndexTraits>
1550 bool BlackOilFluidSystem<Scalar, IndexTraits>::enableVaporizedOil_;
1552 template <
class Scalar,
class IndexTraits>
1553 bool BlackOilFluidSystem<Scalar, IndexTraits>::enableVaporizedWater_;
1555 template <
class Scalar,
class IndexTraits>
1556 bool BlackOilFluidSystem<Scalar, IndexTraits>::enableDiffusion_;
1558 template <
class Scalar,
class IndexTraits>
1559 std::shared_ptr<OilPvtMultiplexer<Scalar> >
1560 BlackOilFluidSystem<Scalar, IndexTraits>::oilPvt_;
1562 template <
class Scalar,
class IndexTraits>
1563 std::shared_ptr<GasPvtMultiplexer<Scalar> >
1564 BlackOilFluidSystem<Scalar, IndexTraits>::gasPvt_;
1566 template <
class Scalar,
class IndexTraits>
1567 std::shared_ptr<WaterPvtMultiplexer<Scalar> >
1568 BlackOilFluidSystem<Scalar, IndexTraits>::waterPvt_;
1570 template <
class Scalar,
class IndexTraits>
1571 std::vector<std::array<Scalar, 3> >
1572 BlackOilFluidSystem<Scalar, IndexTraits>::referenceDensity_;
1574 template <
class Scalar,
class IndexTraits>
1575 std::vector<std::array<Scalar, 3> >
1576 BlackOilFluidSystem<Scalar, IndexTraits>::molarMass_;
1578 template <
class Scalar,
class IndexTraits>
1579 std::vector<std::array<Scalar, 9> >
1580 BlackOilFluidSystem<Scalar, IndexTraits>::diffusionCoefficients_;
1582 template <
class Scalar,
class IndexTraits>
1583 bool BlackOilFluidSystem<Scalar, IndexTraits>::isInitialized_ =
false;
The base class for all fluid systems.
This class represents the Pressure-Volume-Temperature relations of the liquid phase for a CO2-Brine s...
A central place for various physical constants occuring in some equations.
Provides the opm-material specific exception classes.
This class represents the Pressure-Volume-Temperature relations of the gas phase in the black-oil mod...
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
This class represents the Pressure-Volume-Temperature relations of the oil phase in the black-oil mod...
Some templates to wrap the valgrind client request macros.
This class represents the Pressure-Volume-Temperature relations of the water phase in the black-oil m...
The base class for all fluid systems.
Definition: BaseFluidSystem.hpp:44
Scalar Scalar
The type used for scalar quantities.
Definition: BaseFluidSystem.hpp:49
A fluid system which uses the black-oil model assumptions to calculate termodynamically meaningful qu...
Definition: BlackOilFluidSystem.hpp:141
static unsigned numActivePhases()
Returns the number of active fluid phases (i.e., usually three)
Definition: BlackOilFluidSystem.hpp:525
static Scalar diffusionCoefficient(unsigned compIdx, unsigned phaseIdx, unsigned regionIdx=0)
Calculate the binary molecular diffusion coefficient for a component in a fluid phase [mol^2 * s / (k...
Definition: BlackOilFluidSystem.hpp:1455
static void setReferenceDensities(Scalar rhoOil, Scalar rhoWater, Scalar rhoGas, unsigned regionIdx)
Initialize the values of the reference densities.
Definition: BlackOilFluidSystem.hpp:408
static LhsEval convertXoGToRs(const LhsEval &XoG, unsigned regionIdx)
Convert the mass fraction of the gas component in the oil phase to the corresponding gas dissolution ...
Definition: BlackOilFluidSystem.hpp:1272
static LhsEval convertRsToXoG(const LhsEval &Rs, unsigned regionIdx)
Convert a gas dissolution factor to the the corresponding mass fraction of the gas component in the o...
Definition: BlackOilFluidSystem.hpp:1312
static void initEnd()
Finish initializing the black oil fluid system.
Definition: BlackOilFluidSystem.hpp:422
static LhsEval convertRvwToXgW(const LhsEval &Rvw, unsigned regionIdx)
Convert an water vaporization factor to the corresponding mass fraction of the water component in the...
Definition: BlackOilFluidSystem.hpp:1340
static constexpr unsigned soluteComponentIndex(unsigned phaseIdx)
returns the index of "secondary" component of a phase (solute)
Definition: BlackOilFluidSystem.hpp:552
static LhsEval saturatedInverseFormationVolumeFactor(const FluidState &fluidState, unsigned phaseIdx, unsigned regionIdx)
Returns the formation volume factor of a "saturated" fluid phase.
Definition: BlackOilFluidSystem.hpp:906
static LhsEval convertXoGToxoG(const LhsEval &XoG, unsigned regionIdx)
Convert a gas mass fraction in the oil phase the corresponding mole fraction.
Definition: BlackOilFluidSystem.hpp:1353
static LhsEval viscosity(const FluidState &fluidState, unsigned phaseIdx, unsigned regionIdx)
Calculate the dynamic viscosity of a fluid phase [Pa*s].
Definition: BlackOilFluidSystem.hpp:1049
static const unsigned oilPhaseIdx
Index of the oil phase.
Definition: BlackOilFluidSystem.hpp:472
static Scalar reservoirTemperature(unsigned=0)
Set the temperature of the reservoir.
Definition: BlackOilFluidSystem.hpp:1432
static void setEnableDiffusion(bool yesno)
Specify whether the fluid system should consider diffusion.
Definition: BlackOilFluidSystem.hpp:379
static const unsigned waterPhaseIdx
Index of the water phase.
Definition: BlackOilFluidSystem.hpp:470
static LhsEval bubblePointPressure(const FluidState &fluidState, unsigned regionIdx)
Returns the bubble point pressure $P_b$ using the current Rs.
Definition: BlackOilFluidSystem.hpp:1219
static LhsEval density(const FluidState &fluidState, unsigned phaseIdx, unsigned regionIdx)
Calculate the density [kg/m^3] of a fluid phase.
Definition: BlackOilFluidSystem.hpp:701
static LhsEval saturatedDensity(const FluidState &fluidState, unsigned phaseIdx, unsigned regionIdx)
Compute the density of a saturated fluid phase.
Definition: BlackOilFluidSystem.hpp:775
static LhsEval viscosity(const FluidState &fluidState, const ParameterCache< ParamCacheEval > ¶mCache, unsigned phaseIdx)
Calculate the dynamic viscosity of a fluid phase [Pa*s].
Definition: BlackOilFluidSystem.hpp:683
static bool isIdealMixture(unsigned)
Returns true if and only if a fluid phase is assumed to be an ideal mixture.
Definition: BlackOilFluidSystem.hpp:588
static bool enableVaporizedWater()
Returns whether the fluid system should consider that the water component can dissolve in the gas pha...
Definition: BlackOilFluidSystem.hpp:639
static const unsigned numComponents
Number of chemical species in the fluid system.
Definition: BlackOilFluidSystem.hpp:510
static const char * componentName(unsigned compIdx)
Return the human readable name of a component.
Definition: BlackOilFluidSystem.hpp:568
static const GasPvt & gasPvt()
Return a reference to the low-level object which calculates the gas phase quantities.
Definition: BlackOilFluidSystem.hpp:1404
static constexpr unsigned solventComponentIndex(unsigned phaseIdx)
returns the index of "primary" component of a phase (solvent)
Definition: BlackOilFluidSystem.hpp:536
static void setWaterPvt(std::shared_ptr< WaterPvt > pvtObj)
Set the pressure-volume-saturation (PVT) relations for the water phase.
Definition: BlackOilFluidSystem.hpp:398
static void setReservoirTemperature(Scalar value)
Return the temperature of the reservoir.
Definition: BlackOilFluidSystem.hpp:1440
static LhsEval saturatedDissolutionFactor(const FluidState &fluidState, unsigned phaseIdx, unsigned regionIdx, const LhsEval &maxOilSaturation)
Returns the dissolution factor of a saturated fluid phase.
Definition: BlackOilFluidSystem.hpp:1168
static size_t numRegions()
Returns the number of PVT regions which are considered.
Definition: BlackOilFluidSystem.hpp:612
static LhsEval enthalpy(const FluidState &fluidState, unsigned phaseIdx, unsigned regionIdx)
Given a phase's composition, temperature, pressure and density, calculate its specific enthalpy [J/kg...
Definition: BlackOilFluidSystem.hpp:1104
static bool isLiquid(unsigned phaseIdx)
Return whether a phase is liquid.
Definition: BlackOilFluidSystem.hpp:499
static LhsEval enthalpy(const FluidState &fluidState, const ParameterCache< ParamCacheEval > ¶mCache, unsigned phaseIdx)
Given a phase's composition, temperature, pressure and density, calculate its specific enthalpy [J/kg...
Definition: BlackOilFluidSystem.hpp:690
static LhsEval fugacityCoefficient(const FluidState &fluidState, unsigned phaseIdx, unsigned compIdx, unsigned regionIdx)
Calculate the fugacity coefficient [Pa] of an individual component in a fluid phase.
Definition: BlackOilFluidSystem.hpp:927
static LhsEval convertxoGToXoG(const LhsEval &xoG, unsigned regionIdx)
Convert a gas mole fraction in the oil phase the corresponding mass fraction.
Definition: BlackOilFluidSystem.hpp:1365
static Scalar molarMass(unsigned compIdx, unsigned regionIdx=0)
Return the molar mass of a component in [kg/mol].
Definition: BlackOilFluidSystem.hpp:584
static LhsEval saturatedDissolutionFactor(const FluidState &fluidState, unsigned phaseIdx, unsigned regionIdx)
Returns the dissolution factor of a saturated fluid phase.
Definition: BlackOilFluidSystem.hpp:1197
static LhsEval dewPointPressure(const FluidState &fluidState, unsigned regionIdx)
Returns the dew point pressure $P_d$ using the current Rv.
Definition: BlackOilFluidSystem.hpp:1230
static LhsEval saturationPressure(const FluidState &fluidState, unsigned phaseIdx, unsigned regionIdx)
Returns the saturation pressure of a given phase [Pa] depending on its composition.
Definition: BlackOilFluidSystem.hpp:1247
static LhsEval convertXgOToxgO(const LhsEval &XgO, unsigned regionIdx)
Convert a oil mass fraction in the gas phase the corresponding mole fraction.
Definition: BlackOilFluidSystem.hpp:1377
static LhsEval diffusionCoefficient(const FluidState &fluidState, const ParameterCache< ParamCacheEval > ¶mCache, unsigned phaseIdx, unsigned compIdx)
Calculate the binary molecular diffusion coefficient for a component in a fluid phase [mol^2 * s / (k...
Definition: BlackOilFluidSystem.hpp:1466
static LhsEval saturatedVaporizationFactor(const FluidState &fluidState, unsigned phaseIdx, unsigned regionIdx)
Returns the water vaporization factor of saturated phase.
Definition: BlackOilFluidSystem.hpp:1143
static bool enableDissolvedGas()
Returns whether the fluid system should consider that the gas component can dissolve in the oil phase...
Definition: BlackOilFluidSystem.hpp:621
static Scalar referenceDensity(unsigned phaseIdx, unsigned regionIdx)
Returns the density of a fluid phase at surface pressure [kg/m^3].
Definition: BlackOilFluidSystem.hpp:655
static Scalar surfaceTemperature
The temperature at the surface.
Definition: BlackOilFluidSystem.hpp:480
static void setOilPvt(std::shared_ptr< OilPvt > pvtObj)
Set the pressure-volume-saturation (PVT) relations for the oil phase.
Definition: BlackOilFluidSystem.hpp:392
static LhsEval convertxgOToXgO(const LhsEval &xgO, unsigned regionIdx)
Convert a oil mole fraction in the gas phase the corresponding mass fraction.
Definition: BlackOilFluidSystem.hpp:1389
static LhsEval inverseFormationVolumeFactor(const FluidState &fluidState, unsigned phaseIdx, unsigned regionIdx)
Returns the formation volume factor of an "undersaturated" fluid phase.
Definition: BlackOilFluidSystem.hpp:850
static void setEnableDissolvedGas(bool yesno)
Specify whether the fluid system should consider that the gas component can dissolve in the oil phase...
Definition: BlackOilFluidSystem.hpp:353
static const char * phaseName(unsigned phaseIdx)
Return the human readable name of a fluid phase.
Definition: BlackOilFluidSystem.hpp:483
static const unsigned numPhases
Number of fluid phases in the fluid system.
Definition: BlackOilFluidSystem.hpp:467
static LhsEval convertXgOToRv(const LhsEval &XgO, unsigned regionIdx)
Convert the mass fraction of the oil component in the gas phase to the corresponding oil vaporization...
Definition: BlackOilFluidSystem.hpp:1285
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: BlackOilFluidSystem.hpp:670
static const unsigned gasPhaseIdx
Index of the gas phase.
Definition: BlackOilFluidSystem.hpp:474
static LhsEval density(const FluidState &fluidState, const ParameterCache< ParamCacheEval > ¶mCache, unsigned phaseIdx)
Calculate the density [kg/m^3] of a fluid phase.
Definition: BlackOilFluidSystem.hpp:663
static LhsEval convertRvToXgO(const LhsEval &Rv, unsigned regionIdx)
Convert an oil vaporization factor to the corresponding mass fraction of the oil component in the gas...
Definition: BlackOilFluidSystem.hpp:1326
static bool enableVaporizedOil()
Returns whether the fluid system should consider that the oil component can dissolve in the gas phase...
Definition: BlackOilFluidSystem.hpp:630
static bool isIdealGas(unsigned)
Returns true if and only if a fluid phase is assumed to be an ideal gas.
Definition: BlackOilFluidSystem.hpp:600
static unsigned phaseIsActive(unsigned phaseIdx)
Returns whether a fluid phase is active.
Definition: BlackOilFluidSystem.hpp:529
static Scalar surfacePressure
The pressure at the surface.
Definition: BlackOilFluidSystem.hpp:477
static const WaterPvt & waterPvt()
Return a reference to the low-level object which calculates the water phase quantities.
Definition: BlackOilFluidSystem.hpp:1424
static void setEnableVaporizedWater(bool yesno)
Specify whether the fluid system should consider that the water component can dissolve in the gas pha...
Definition: BlackOilFluidSystem.hpp:371
static void initBegin(size_t numPvtRegions)
Begin the initialization of the black oil fluid system.
Definition: BlackOilFluidSystem.hpp:324
static bool enableDiffusion()
Returns whether the fluid system should consider diffusion.
Definition: BlackOilFluidSystem.hpp:647
static LhsEval convertXgWToRvw(const LhsEval &XgW, unsigned regionIdx)
Convert the mass fraction of the water component in the gas phase to the corresponding water vaporiza...
Definition: BlackOilFluidSystem.hpp:1298
static const unsigned gasCompIdx
Index of the gas component.
Definition: BlackOilFluidSystem.hpp:517
static const unsigned oilCompIdx
Index of the oil component.
Definition: BlackOilFluidSystem.hpp:513
static void setEnableVaporizedOil(bool yesno)
Specify whether the fluid system should consider that the oil component can dissolve in the gas phase...
Definition: BlackOilFluidSystem.hpp:362
static const unsigned waterCompIdx
Index of the water component.
Definition: BlackOilFluidSystem.hpp:515
static void setDiffusionCoefficient(Scalar coefficient, unsigned compIdx, unsigned phaseIdx, unsigned regionIdx=0)
Definition: BlackOilFluidSystem.hpp:1459
static const OilPvt & oilPvt()
Return a reference to the low-level object which calculates the oil phase quantities.
Definition: BlackOilFluidSystem.hpp:1414
static bool isCompressible(unsigned)
Returns true if and only if a fluid phase is assumed to be compressible.
Definition: BlackOilFluidSystem.hpp:596
static void setGasPvt(std::shared_ptr< GasPvt > pvtObj)
Set the pressure-volume-saturation (PVT) relations for the gas phase.
Definition: BlackOilFluidSystem.hpp:386
static Scalar molarMass()
The molar mass in of the component.
Definition: Brine.hpp:80
static Scalar molarMass()
The mass in [kg] of one mole of CO2.
Definition: CO2.hpp:66
A central place for various physical constants occuring in some equations.
Definition: Constants.hpp:41
This class represents the Pressure-Volume-Temperature relations of the gas phase in the black-oil mod...
Definition: GasPvtMultiplexer.hpp:93
Evaluation diffusionCoefficient(const Evaluation &temperature, const Evaluation &pressure, unsigned compIdx) const
Calculate the binary molecular diffusion coefficient for a component in a fluid phase [mol^2 * s / (k...
Definition: GasPvtMultiplexer.hpp:302
A parameter cache which does nothing.
Definition: NullParameterCache.hpp:40
This class represents the Pressure-Volume-Temperature relations of the oil phase in the black-oil mod...
Definition: OilPvtMultiplexer.hpp:96
Evaluation diffusionCoefficient(const Evaluation &temperature, const Evaluation &pressure, unsigned compIdx) const
Calculate the binary molecular diffusion coefficient for a component in a fluid phase [mol^2 * s / (k...
Definition: OilPvtMultiplexer.hpp:271
This class represents the Pressure-Volume-Temperature relations of the water phase in the black-oil m...
Definition: WaterPvtMultiplexer.hpp:75
The type of the fluid system's parameter cache.
Definition: BlackOilFluidSystem.hpp:152
void assignPersistentData(const OtherCache &other)
Copy the data which is not dependent on the type of the Scalars from another parameter cache.
Definition: BlackOilFluidSystem.hpp:170
void setRegionIndex(unsigned val)
Set the index of the region which should be used to determine the thermodynamic properties.
Definition: BlackOilFluidSystem.hpp:193
unsigned regionIndex() const
Return the index of the region which should be used to determine the thermodynamic properties.
Definition: BlackOilFluidSystem.hpp:183