32#ifndef EWOMS_BLACK_OIL_EXTBO_MODULE_HH
33#define EWOMS_BLACK_OIL_EXTBO_MODULE_HH
35#include <dune/common/fvector.hh>
37#include <opm/common/utility/gpuDecorators.hpp>
63template <
class TypeTag>
64class BlackOilExtboModule<TypeTag, true>
78 using Toolbox = MathToolbox<Evaluation>;
80 static constexpr unsigned zFractionIdx = Indices::zFractionIdx;
81 static constexpr unsigned contiZfracEqIdx = Indices::contiZfracEqIdx;
82 static constexpr bool enableExtbo =
true;
83 static constexpr unsigned numEq = getPropValue<TypeTag, Properties::NumEq>();
84 static constexpr unsigned gasPhaseIdx = FluidSystem::gasPhaseIdx;
85 static constexpr unsigned oilPhaseIdx = FluidSystem::oilPhaseIdx;
86 static constexpr bool blackoilConserveSurfaceVolume =
87 getPropValue<TypeTag, Properties::BlackoilConserveSurfaceVolume>();
111 return pvIdx == zFractionIdx;
116 assert(primaryVarApplies(pvIdx));
123 assert(primaryVarApplies(pvIdx));
126 return static_cast<Scalar
>(1.0);
131 return eqIdx == contiZfracEqIdx;
134 static std::string
eqName([[maybe_unused]]
unsigned eqIdx)
136 assert(eqApplies(eqIdx));
138 return "conti^solvent";
141 static Scalar
eqWeight([[maybe_unused]]
unsigned eqIdx)
143 assert(eqApplies(eqIdx));
146 return static_cast<Scalar
>(1.0);
149 template <
class StorageType>
151 const IntensiveQuantities& intQuants)
153 using LhsEval =
typename StorageType::value_type;
155 if constexpr (blackoilConserveSurfaceVolume) {
156 storage[contiZfracEqIdx] =
157 Toolbox::template decay<LhsEval>(intQuants.porosity()) *
158 Toolbox::template decay<LhsEval>(intQuants.yVolume()) *
159 Toolbox::template decay<LhsEval>(intQuants.fluidState().saturation(gasPhaseIdx)) *
160 Toolbox::template decay<LhsEval>(intQuants.fluidState().invB(gasPhaseIdx));
161 if (FluidSystem::enableDissolvedGas()) {
162 storage[contiZfracEqIdx] +=
163 Toolbox::template decay<LhsEval>(intQuants.porosity()) *
164 Toolbox::template decay<LhsEval>(intQuants.xVolume()) *
165 Toolbox::template decay<LhsEval>(intQuants.fluidState().Rs()) *
166 Toolbox::template decay<LhsEval>(intQuants.fluidState().saturation(oilPhaseIdx)) *
167 Toolbox::template decay<LhsEval>(intQuants.fluidState().invB(oilPhaseIdx));
172 const Scalar regWghtFactor = 1.0e-6;
173 storage[contiZfracEqIdx] +=
174 regWghtFactor* (1.0 - Toolbox::template decay<LhsEval>(intQuants.zFraction())) +
175 regWghtFactor*Toolbox::template decay<LhsEval>(intQuants.porosity()) *
176 Toolbox::template decay<LhsEval>(intQuants.fluidState().saturation(gasPhaseIdx)) *
177 Toolbox::template decay<LhsEval>(intQuants.fluidState().invB(gasPhaseIdx));
178 storage[contiZfracEqIdx - 1] += regWghtFactor*Toolbox::template decay<LhsEval>(intQuants.zFraction());
181 OPM_THROW(std::runtime_error,
"Only component conservation in terms of surface volumes is implemented. ");
186 const ElementContext& elemCtx,
190 const auto& extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
192 if constexpr (blackoilConserveSurfaceVolume) {
193 const unsigned inIdx = extQuants.interiorIndex();
195 const unsigned upIdxGas =
static_cast<unsigned>(extQuants.upstreamIndex(gasPhaseIdx));
196 const auto& upGas = elemCtx.intensiveQuantities(upIdxGas, timeIdx);
197 const auto& fsGas = upGas.fluidState();
198 if (upIdxGas == inIdx) {
199 flux[contiZfracEqIdx] =
200 extQuants.volumeFlux(gasPhaseIdx) *
202 fsGas.invB(gasPhaseIdx);
205 flux[contiZfracEqIdx] =
206 extQuants.volumeFlux(gasPhaseIdx) *
207 decay<Scalar>(upGas.yVolume()) *
208 decay<Scalar>(fsGas.invB(gasPhaseIdx));
210 if (FluidSystem::enableDissolvedGas()) {
211 const unsigned upIdxOil =
static_cast<unsigned>(extQuants.upstreamIndex(oilPhaseIdx));
212 const auto& upOil = elemCtx.intensiveQuantities(upIdxOil, timeIdx);
213 const auto& fsOil = upOil.fluidState();
214 if (upIdxOil == inIdx) {
215 flux[contiZfracEqIdx] +=
216 extQuants.volumeFlux(oilPhaseIdx) *
219 fsOil.invB(oilPhaseIdx);
222 flux[contiZfracEqIdx] +=
223 extQuants.volumeFlux(oilPhaseIdx) *
224 decay<Scalar>(upOil.xVolume()) *
225 decay<Scalar>(fsOil.Rs()) *
226 decay<Scalar>(fsOil.invB(oilPhaseIdx));
231 throw std::runtime_error(
"Only component conservation in terms of surface volumes is implemented. ");
241 priVars[zFractionIdx] = zFraction;
248 const PrimaryVariables& oldPv,
249 const EqVector& delta)
252 newPv[zFractionIdx] = oldPv[zFractionIdx] - delta[zFractionIdx];
264 return static_cast<Scalar
>(0.0);
273 return std::abs(Toolbox::scalarValue(resid[contiZfracEqIdx]));
276 template <
class DofEntity>
277 static void serializeEntity(
const Model& model, std::ostream& outstream,
const DofEntity& dof)
279 const unsigned dofIdx = model.dofMapper().index(dof);
281 const PrimaryVariables& priVars = model.solution(0)[dofIdx];
282 outstream << priVars[zFractionIdx];
285 template <
class DofEntity>
288 const unsigned dofIdx = model.dofMapper().index(dof);
290 PrimaryVariables& priVars0 = model.solution(0)[dofIdx];
291 PrimaryVariables& priVars1 = model.solution(1)[dofIdx];
293 instream >> priVars0[zFractionIdx];
296 priVars1 = priVars0[zFractionIdx];
299 template <
typename Value>
300 static Value
xVolume(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
301 {
return params_.X_[pvtRegionIdx].eval(z, pressure,
true); }
303 template <
typename Value>
304 static Value
yVolume(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
305 {
return params_.Y_[pvtRegionIdx].eval(z, pressure,
true); }
307 template <
typename Value>
308 static Value
pbubRs(
unsigned pvtRegionIdx,
const Value& z,
const Value& rs)
309 {
return params_.PBUB_RS_[pvtRegionIdx].eval(z, rs,
true); }
311 template <
typename Value>
312 static Value
pbubRv(
unsigned pvtRegionIdx,
const Value& z,
const Value& rv)
313 {
return params_.PBUB_RV_[pvtRegionIdx].eval(z, rv,
true); }
315 template <
typename Value>
316 static Value
oilViscosity(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
317 {
return params_.VISCO_[pvtRegionIdx].eval(z, pressure,
true); }
319 template <
typename Value>
320 static Value
gasViscosity(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
321 {
return params_.VISCG_[pvtRegionIdx].eval(z, pressure,
true); }
323 template <
typename Value>
324 static Value
bo(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
325 {
return params_.BO_[pvtRegionIdx].eval(z, pressure,
true); }
327 template <
typename Value>
328 static Value
bg(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
329 {
return params_.BG_[pvtRegionIdx].eval(z, pressure,
true); }
331 template <
typename Value>
332 static Value
rs(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
333 {
return params_.RS_[pvtRegionIdx].eval(z, pressure,
true); }
335 template <
typename Value>
336 static Value
rv(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
337 {
return params_.RV_[pvtRegionIdx].eval(z, pressure,
true); }
340 {
return params_.zReferenceDensity_[regionIdx]; }
342 static Scalar
zLim(
unsigned regionIdx)
343 {
return params_.zLim_[regionIdx]; }
345 template <
typename Value>
346 static Value
oilCmp(
unsigned pvtRegionIdx,
const Value& z)
347 {
return params_.oilCmp_[pvtRegionIdx].eval(z,
true); }
349 template <
typename Value>
350 static Value
gasCmp(
unsigned pvtRegionIdx,
const Value& z)
351 {
return params_.gasCmp_[pvtRegionIdx].eval(z,
true); }
357template <
class TypeTag>
358BlackOilExtboParams<typename BlackOilExtboModule<TypeTag, true>::Scalar>
359BlackOilExtboModule<TypeTag, true>::params_;
368template <
class TypeTag>
382 static constexpr unsigned zFractionIdx = Indices::zFractionIdx;
383 static constexpr int oilPhaseIdx = FluidSystem::oilPhaseIdx;
384 static constexpr int gasPhaseIdx = FluidSystem::gasPhaseIdx;
396 zFractionUpdate_(elemCtx.primaryVars(dofIdx, timeIdx), timeIdx);
407 const unsigned pvtRegionIdx = priVars.pvtRegionIndex();
408 const auto& fs = asImp_().fluidState_;
410 zFraction_ = priVars.makeEvaluation(zFractionIdx, timeIdx);
412 oilViscosity_ = ExtboModule::oilViscosity(pvtRegionIdx, fs.pressure(oilPhaseIdx), zFraction_);
413 gasViscosity_ = ExtboModule::gasViscosity(pvtRegionIdx, fs.pressure(gasPhaseIdx), zFraction_);
415 bo_ = ExtboModule::bo(pvtRegionIdx, fs.pressure(oilPhaseIdx), zFraction_);
416 bg_ = ExtboModule::bg(pvtRegionIdx, fs.pressure(gasPhaseIdx), zFraction_);
418 bz_ = ExtboModule::bg(pvtRegionIdx, fs.pressure(oilPhaseIdx), Evaluation{0.99});
420 if (FluidSystem::enableDissolvedGas()) {
421 rs_ = ExtboModule::rs(pvtRegionIdx, fs.pressure(oilPhaseIdx), zFraction_);
427 if (FluidSystem::enableVaporizedOil()) {
428 rv_ = ExtboModule::rv(pvtRegionIdx, fs.pressure(gasPhaseIdx), zFraction_);
434 xVolume_ = ExtboModule::xVolume(pvtRegionIdx, fs.pressure(oilPhaseIdx), zFraction_);
435 yVolume_ = ExtboModule::yVolume(pvtRegionIdx, fs.pressure(oilPhaseIdx), zFraction_);
437 Evaluation pbub = fs.pressure(oilPhaseIdx);
439 if (priVars.primaryVarsMeaningWater() == PrimaryVariables::WaterMeaning::Sw) {
440 static const Scalar thresholdWaterFilledCell = 1.0 - 1e-6;
441 Scalar sw = priVars.makeEvaluation(Indices::waterSwitchIdx, timeIdx).value();
442 if (sw >= thresholdWaterFilledCell) {
447 if (priVars.primaryVarsMeaningGas() == PrimaryVariables::GasMeaning::Rs) {
448 rs_ = priVars.makeEvaluation(Indices::compositionSwitchIdx, timeIdx);
449 const Evaluation zLim = ExtboModule::zLim(pvtRegionIdx);
450 if (zFraction_ > zLim) {
451 pbub = ExtboModule::pbubRs(pvtRegionIdx, zLim, rs_);
453 pbub = ExtboModule::pbubRs(pvtRegionIdx, zFraction_, rs_);
455 bo_ = ExtboModule::bo(pvtRegionIdx, pbub, zFraction_) +
456 ExtboModule::oilCmp(pvtRegionIdx, zFraction_) * (fs.pressure(oilPhaseIdx) - pbub);
458 xVolume_ = ExtboModule::xVolume(pvtRegionIdx, pbub, zFraction_);
461 if (priVars.primaryVarsMeaningGas() == PrimaryVariables::GasMeaning::Rv) {
462 rv_ = priVars.makeEvaluation(Indices::compositionSwitchIdx, timeIdx);
463 const Evaluation rvsat = ExtboModule::rv(pvtRegionIdx, pbub, zFraction_);
464 bg_ = ExtboModule::bg(pvtRegionIdx, pbub, zFraction_) +
465 ExtboModule::gasCmp(pvtRegionIdx, zFraction_) * (rv_ - rvsat);
467 yVolume_ = ExtboModule::yVolume(pvtRegionIdx, pbub, zFraction_);
478 const auto& iq = asImp_();
479 auto& fs = asImp_().fluidState_;
481 const unsigned pvtRegionIdx = iq.pvtRegionIndex();
482 zRefDensity_ = ExtboModule::referenceDensity(pvtRegionIdx);
484 fs.setInvB(oilPhaseIdx, 1.0 / bo_);
485 fs.setInvB(gasPhaseIdx, 1.0 / bg_);
487 fs.setDensity(oilPhaseIdx,
488 fs.invB(oilPhaseIdx) *
489 (FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx) +
490 (1.0 - xVolume_) * fs.Rs() * FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx) +
491 xVolume_ * fs.Rs() * zRefDensity_));
492 fs.setDensity(gasPhaseIdx,
493 fs.invB(gasPhaseIdx) *
494 (FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx) *
495 (1.0 - yVolume_) + yVolume_* zRefDensity_ +
496 FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx) * fs.Rv()));
500 {
return zFraction_; }
509 {
return oilViscosity_; }
512 {
return gasViscosity_; }
514 const Evaluation&
bo()
const
517 const Evaluation&
bg()
const
520 const Evaluation&
rs()
const
523 const Evaluation&
rv()
const
527 {
return 1.0 / bz_; }
530 {
return zRefDensity_; }
534 {
return *
static_cast<Implementation*
>(
this); }
565template <
class TypeTag>
570 Implementation& asImp_()
571 {
return *
static_cast<Implementation*
>(
this); }
Defines a type tags and some fundamental properties all models.
Contains the parameters required to extend the black-oil model by solvent component....
Contains classes extending the black-oil model. \detail This file holds dummy definitions,...
Declares the properties required by the black oil model.
Provides the solvent specific extensive quantities to the generic black-oil module's extensive quanti...
void zFractionUpdate_(const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx)
Compute extended pvt properties from table lookups.
Definition: blackoilextbomodules.hh:392
Evaluation xVolume_
Definition: blackoilextbomodules.hh:542
Evaluation bo_
Definition: blackoilextbomodules.hh:548
void zPvtUpdate_()
Re-compute face densities to account for zFraction dependency.
Definition: blackoilextbomodules.hh:476
const Evaluation & oilViscosity() const
Definition: blackoilextbomodules.hh:508
const Evaluation & xVolume() const
Definition: blackoilextbomodules.hh:502
const Evaluation & zFraction() const
Definition: blackoilextbomodules.hh:499
Scalar zRefDensity_
Definition: blackoilextbomodules.hh:555
void zFractionUpdate_(const PrimaryVariables &priVars, unsigned timeIdx)
Compute extended pvt properties from table lookups.
Definition: blackoilextbomodules.hh:404
const Evaluation & gasViscosity() const
Definition: blackoilextbomodules.hh:511
const Evaluation & yVolume() const
Definition: blackoilextbomodules.hh:505
Evaluation oilViscosity_
Definition: blackoilextbomodules.hh:546
const Evaluation & rv() const
Definition: blackoilextbomodules.hh:523
Evaluation bg_
Definition: blackoilextbomodules.hh:549
Evaluation bz_
Definition: blackoilextbomodules.hh:554
const Evaluation & bg() const
Definition: blackoilextbomodules.hh:517
Evaluation yVolume_
Definition: blackoilextbomodules.hh:543
Evaluation gasViscosity_
Definition: blackoilextbomodules.hh:547
Scalar zRefDensity() const
Definition: blackoilextbomodules.hh:529
const Evaluation & rs() const
Definition: blackoilextbomodules.hh:520
const Evaluation zPureInvFormationVolumeFactor() const
Definition: blackoilextbomodules.hh:526
Evaluation rs_
Definition: blackoilextbomodules.hh:550
const Evaluation & bo() const
Definition: blackoilextbomodules.hh:514
Implementation & asImp_()
Definition: blackoilextbomodules.hh:533
Evaluation rv_
Definition: blackoilextbomodules.hh:551
Evaluation zFraction_
Definition: blackoilextbomodules.hh:539
Provides the volumetric quantities required for the equations needed by the solvents extension of the...
Contains the high level supplements required to extend the black oil model.
Definition: blackoilextbomodules.hh:65
static Scalar computeResidualError(const EqVector &resid)
Return how much a residual is considered an error.
Definition: blackoilextbomodules.hh:270
static Value rs(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:332
static Scalar eqWeight(unsigned eqIdx)
Definition: blackoilextbomodules.hh:141
static void assignPrimaryVars(PrimaryVariables &priVars, Scalar zFraction)
Assign the solvent specific primary variables to a PrimaryVariables object.
Definition: blackoilextbomodules.hh:238
static bool eqApplies(unsigned eqIdx)
Definition: blackoilextbomodules.hh:129
static Value xVolume(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:300
static Value pbubRv(unsigned pvtRegionIdx, const Value &z, const Value &rv)
Definition: blackoilextbomodules.hh:312
static Scalar primaryVarWeight(unsigned pvIdx)
Definition: blackoilextbomodules.hh:121
static Value rv(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:336
static void computeFlux(RateVector &flux, const ElementContext &elemCtx, unsigned scvfIdx, unsigned timeIdx)
Definition: blackoilextbomodules.hh:185
static Value gasViscosity(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:320
static void updatePrimaryVars(PrimaryVariables &newPv, const PrimaryVariables &oldPv, const EqVector &delta)
Do a Newton-Raphson update the primary variables of the solvents.
Definition: blackoilextbomodules.hh:247
static void serializeEntity(const Model &model, std::ostream &outstream, const DofEntity &dof)
Definition: blackoilextbomodules.hh:277
static Scalar referenceDensity(unsigned regionIdx)
Definition: blackoilextbomodules.hh:339
static Value yVolume(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:304
static void registerOutputModules(Model &, Simulator &)
Register all solvent specific VTK and ECL output modules.
Definition: blackoilextbomodules.hh:105
static void setParams(BlackOilExtboParams< Scalar > &¶ms)
Set parameters.
Definition: blackoilextbomodules.hh:91
static void registerParameters()
Register all run-time parameters for the black-oil solvent module.
Definition: blackoilextbomodules.hh:99
static bool primaryVarApplies(unsigned pvIdx)
Definition: blackoilextbomodules.hh:109
static std::string primaryVarName(unsigned pvIdx)
Definition: blackoilextbomodules.hh:114
static Value bg(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:328
static Scalar computeUpdateError(const PrimaryVariables &, const EqVector &)
Return how much a Newton-Raphson update is considered an error.
Definition: blackoilextbomodules.hh:258
static Value gasCmp(unsigned pvtRegionIdx, const Value &z)
Definition: blackoilextbomodules.hh:350
static void deserializeEntity(Model &model, std::istream &instream, const DofEntity &dof)
Definition: blackoilextbomodules.hh:286
static std::string eqName(unsigned eqIdx)
Definition: blackoilextbomodules.hh:134
static Value oilViscosity(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:316
static Value pbubRs(unsigned pvtRegionIdx, const Value &z, const Value &rs)
Definition: blackoilextbomodules.hh:308
static OPM_HOST_DEVICE void addStorage(StorageType &storage, const IntensiveQuantities &intQuants)
Definition: blackoilextbomodules.hh:150
static Value bo(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:324
static Scalar zLim(unsigned regionIdx)
Definition: blackoilextbomodules.hh:342
static Value oilCmp(unsigned pvtRegionIdx, const Value &z)
Definition: blackoilextbomodules.hh:346
Declare the properties used by the infrastructure code of the finite volume discretizations.
Definition: blackoilbioeffectsmodules.hh:45
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233
Struct holding the parameters for the BlackoilExtboModule class.
Definition: blackoilextboparams.hpp:47