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);
191 const unsigned inIdx = extQuants.interiorIndex();
193 flux[contiZfracEqIdx] = 0.0;
195 const unsigned upIdxGas =
static_cast<unsigned>(extQuants.upstreamIndex(gasPhaseIdx));
196 const auto& upGas = elemCtx.intensiveQuantities(upIdxGas, timeIdx);
197 if (upIdxGas == inIdx) {
198 addExtboFluxes_<Evaluation>(
199 flux, gasPhaseIdx, extQuants.volumeFlux(gasPhaseIdx), upGas);
201 addExtboFluxes_<Scalar>(flux, gasPhaseIdx, extQuants.volumeFlux(gasPhaseIdx), upGas);
204 if (FluidSystem::enableDissolvedGas()) {
205 const unsigned upIdxOil =
static_cast<unsigned>(extQuants.upstreamIndex(oilPhaseIdx));
206 const auto& upOil = elemCtx.intensiveQuantities(upIdxOil, timeIdx);
207 if (upIdxOil == inIdx) {
208 addExtboFluxes_<Evaluation>(
209 flux, oilPhaseIdx, extQuants.volumeFlux(oilPhaseIdx), upOil);
211 addExtboFluxes_<Scalar>(
212 flux, oilPhaseIdx, extQuants.volumeFlux(oilPhaseIdx), upOil);
228 template <
class UpEval>
230 const unsigned phaseIdx,
231 const Evaluation& volumeFlux,
232 const IntensiveQuantities& up)
234 if constexpr (blackoilConserveSurfaceVolume) {
235 const auto& fs = up.fluidState();
236 if (phaseIdx == gasPhaseIdx) {
237 flux[contiZfracEqIdx] += volumeFlux
238 * decay<UpEval>(up.yVolume())
239 * decay<UpEval>(fs.invB(gasPhaseIdx));
240 }
else if (phaseIdx == oilPhaseIdx && FluidSystem::enableDissolvedGas()) {
242 flux[contiZfracEqIdx] += volumeFlux
243 * decay<UpEval>(up.xVolume())
244 * decay<UpEval>(fs.Rs())
245 * decay<UpEval>(fs.invB(oilPhaseIdx));
248 throw std::runtime_error(
249 "Only component conservation in terms of surface volumes is implemented. ");
259 priVars[zFractionIdx] = zFraction;
266 const PrimaryVariables& oldPv,
267 const EqVector& delta)
270 newPv[zFractionIdx] = oldPv[zFractionIdx] - delta[zFractionIdx];
282 return static_cast<Scalar
>(0.0);
291 return std::abs(Toolbox::scalarValue(resid[contiZfracEqIdx]));
294 template <
class DofEntity>
295 static void serializeEntity(
const Model& model, std::ostream& outstream,
const DofEntity& dof)
297 const unsigned dofIdx = model.dofMapper().index(dof);
299 const PrimaryVariables& priVars = model.solution(0)[dofIdx];
300 outstream << priVars[zFractionIdx];
303 template <
class DofEntity>
306 const unsigned dofIdx = model.dofMapper().index(dof);
308 PrimaryVariables& priVars0 = model.solution(0)[dofIdx];
309 PrimaryVariables& priVars1 = model.solution(1)[dofIdx];
311 instream >> priVars0[zFractionIdx];
314 priVars1 = priVars0[zFractionIdx];
317 template <
typename Value>
318 static Value
xVolume(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
319 {
return params_.X_[pvtRegionIdx].eval(z, pressure,
true); }
321 template <
typename Value>
322 static Value
yVolume(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
323 {
return params_.Y_[pvtRegionIdx].eval(z, pressure,
true); }
325 template <
typename Value>
326 static Value
pbubRs(
unsigned pvtRegionIdx,
const Value& z,
const Value& rs)
327 {
return params_.PBUB_RS_[pvtRegionIdx].eval(z, rs,
true); }
329 template <
typename Value>
330 static Value
pbubRv(
unsigned pvtRegionIdx,
const Value& z,
const Value& rv)
331 {
return params_.PBUB_RV_[pvtRegionIdx].eval(z, rv,
true); }
333 template <
typename Value>
334 static Value
oilViscosity(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
335 {
return params_.VISCO_[pvtRegionIdx].eval(z, pressure,
true); }
337 template <
typename Value>
338 static Value
gasViscosity(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
339 {
return params_.VISCG_[pvtRegionIdx].eval(z, pressure,
true); }
341 template <
typename Value>
342 static Value
bo(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
343 {
return params_.BO_[pvtRegionIdx].eval(z, pressure,
true); }
345 template <
typename Value>
346 static Value
bg(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
347 {
return params_.BG_[pvtRegionIdx].eval(z, pressure,
true); }
349 template <
typename Value>
350 static Value
rs(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
351 {
return params_.RS_[pvtRegionIdx].eval(z, pressure,
true); }
353 template <
typename Value>
354 static Value
rv(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z)
355 {
return params_.RV_[pvtRegionIdx].eval(z, pressure,
true); }
358 {
return params_.zReferenceDensity_[regionIdx]; }
360 static Scalar
zLim(
unsigned regionIdx)
361 {
return params_.zLim_[regionIdx]; }
363 template <
typename Value>
364 static Value
oilCmp(
unsigned pvtRegionIdx,
const Value& z)
365 {
return params_.oilCmp_[pvtRegionIdx].eval(z,
true); }
367 template <
typename Value>
368 static Value
gasCmp(
unsigned pvtRegionIdx,
const Value& z)
369 {
return params_.gasCmp_[pvtRegionIdx].eval(z,
true); }
375template <
class TypeTag>
376BlackOilExtboParams<typename BlackOilExtboModule<TypeTag, true>::Scalar>
377BlackOilExtboModule<TypeTag, true>::params_;
386template <
class TypeTag>
400 static constexpr unsigned zFractionIdx = Indices::zFractionIdx;
401 static constexpr int oilPhaseIdx = FluidSystem::oilPhaseIdx;
402 static constexpr int gasPhaseIdx = FluidSystem::gasPhaseIdx;
414 zFractionUpdate_(elemCtx.primaryVars(dofIdx, timeIdx), timeIdx);
425 const unsigned pvtRegionIdx = priVars.pvtRegionIndex();
426 const auto& fs = asImp_().fluidState_;
428 zFraction_ = priVars.makeEvaluation(zFractionIdx, timeIdx);
430 oilViscosity_ = ExtboModule::oilViscosity(pvtRegionIdx, fs.pressure(oilPhaseIdx), zFraction_);
431 gasViscosity_ = ExtboModule::gasViscosity(pvtRegionIdx, fs.pressure(gasPhaseIdx), zFraction_);
433 bo_ = ExtboModule::bo(pvtRegionIdx, fs.pressure(oilPhaseIdx), zFraction_);
434 bg_ = ExtboModule::bg(pvtRegionIdx, fs.pressure(gasPhaseIdx), zFraction_);
436 bz_ = ExtboModule::bg(pvtRegionIdx, fs.pressure(oilPhaseIdx), Evaluation{0.99});
438 if (FluidSystem::enableDissolvedGas()) {
439 rs_ = ExtboModule::rs(pvtRegionIdx, fs.pressure(oilPhaseIdx), zFraction_);
445 if (FluidSystem::enableVaporizedOil()) {
446 rv_ = ExtboModule::rv(pvtRegionIdx, fs.pressure(gasPhaseIdx), zFraction_);
452 xVolume_ = ExtboModule::xVolume(pvtRegionIdx, fs.pressure(oilPhaseIdx), zFraction_);
453 yVolume_ = ExtboModule::yVolume(pvtRegionIdx, fs.pressure(oilPhaseIdx), zFraction_);
455 Evaluation pbub = fs.pressure(oilPhaseIdx);
457 if (priVars.primaryVarsMeaningWater() == PrimaryVariables::WaterMeaning::Sw) {
458 static const Scalar thresholdWaterFilledCell = 1.0 - 1e-6;
459 Scalar sw = priVars.makeEvaluation(Indices::waterSwitchIdx, timeIdx).value();
460 if (sw >= thresholdWaterFilledCell) {
465 if (priVars.primaryVarsMeaningGas() == PrimaryVariables::GasMeaning::Rs) {
466 rs_ = priVars.makeEvaluation(Indices::compositionSwitchIdx, timeIdx);
467 const Evaluation zLim = ExtboModule::zLim(pvtRegionIdx);
468 if (zFraction_ > zLim) {
469 pbub = ExtboModule::pbubRs(pvtRegionIdx, zLim, rs_);
471 pbub = ExtboModule::pbubRs(pvtRegionIdx, zFraction_, rs_);
473 bo_ = ExtboModule::bo(pvtRegionIdx, pbub, zFraction_) +
474 ExtboModule::oilCmp(pvtRegionIdx, zFraction_) * (fs.pressure(oilPhaseIdx) - pbub);
476 xVolume_ = ExtboModule::xVolume(pvtRegionIdx, pbub, zFraction_);
479 if (priVars.primaryVarsMeaningGas() == PrimaryVariables::GasMeaning::Rv) {
480 rv_ = priVars.makeEvaluation(Indices::compositionSwitchIdx, timeIdx);
481 const Evaluation rvsat = ExtboModule::rv(pvtRegionIdx, pbub, zFraction_);
482 bg_ = ExtboModule::bg(pvtRegionIdx, pbub, zFraction_) +
483 ExtboModule::gasCmp(pvtRegionIdx, zFraction_) * (rv_ - rvsat);
485 yVolume_ = ExtboModule::yVolume(pvtRegionIdx, pbub, zFraction_);
496 const auto& iq = asImp_();
497 auto& fs = asImp_().fluidState_;
499 const unsigned pvtRegionIdx = iq.pvtRegionIndex();
500 zRefDensity_ = ExtboModule::referenceDensity(pvtRegionIdx);
502 fs.setInvB(oilPhaseIdx, 1.0 / bo_);
503 fs.setInvB(gasPhaseIdx, 1.0 / bg_);
505 fs.setDensity(oilPhaseIdx,
506 fs.invB(oilPhaseIdx) *
507 (FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx) +
508 (1.0 - xVolume_) * fs.Rs() * FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx) +
509 xVolume_ * fs.Rs() * zRefDensity_));
510 fs.setDensity(gasPhaseIdx,
511 fs.invB(gasPhaseIdx) *
512 (FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx) *
513 (1.0 - yVolume_) + yVolume_* zRefDensity_ +
514 FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx) * fs.Rv()));
518 {
return zFraction_; }
527 {
return oilViscosity_; }
530 {
return gasViscosity_; }
532 const Evaluation&
bo()
const
535 const Evaluation&
bg()
const
538 const Evaluation&
rs()
const
541 const Evaluation&
rv()
const
545 {
return 1.0 / bz_; }
548 {
return zRefDensity_; }
552 {
return *
static_cast<Implementation*
>(
this); }
583template <
class TypeTag>
588 Implementation& asImp_()
589 {
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:410
Evaluation xVolume_
Definition: blackoilextbomodules.hh:560
Evaluation bo_
Definition: blackoilextbomodules.hh:566
void zPvtUpdate_()
Re-compute face densities to account for zFraction dependency.
Definition: blackoilextbomodules.hh:494
const Evaluation & oilViscosity() const
Definition: blackoilextbomodules.hh:526
const Evaluation & xVolume() const
Definition: blackoilextbomodules.hh:520
const Evaluation & zFraction() const
Definition: blackoilextbomodules.hh:517
Scalar zRefDensity_
Definition: blackoilextbomodules.hh:573
void zFractionUpdate_(const PrimaryVariables &priVars, unsigned timeIdx)
Compute extended pvt properties from table lookups.
Definition: blackoilextbomodules.hh:422
const Evaluation & gasViscosity() const
Definition: blackoilextbomodules.hh:529
const Evaluation & yVolume() const
Definition: blackoilextbomodules.hh:523
Evaluation oilViscosity_
Definition: blackoilextbomodules.hh:564
const Evaluation & rv() const
Definition: blackoilextbomodules.hh:541
Evaluation bg_
Definition: blackoilextbomodules.hh:567
Evaluation bz_
Definition: blackoilextbomodules.hh:572
const Evaluation & bg() const
Definition: blackoilextbomodules.hh:535
Evaluation yVolume_
Definition: blackoilextbomodules.hh:561
Evaluation gasViscosity_
Definition: blackoilextbomodules.hh:565
Scalar zRefDensity() const
Definition: blackoilextbomodules.hh:547
const Evaluation & rs() const
Definition: blackoilextbomodules.hh:538
const Evaluation zPureInvFormationVolumeFactor() const
Definition: blackoilextbomodules.hh:544
Evaluation rs_
Definition: blackoilextbomodules.hh:568
const Evaluation & bo() const
Definition: blackoilextbomodules.hh:532
Implementation & asImp_()
Definition: blackoilextbomodules.hh:551
Evaluation rv_
Definition: blackoilextbomodules.hh:569
Evaluation zFraction_
Definition: blackoilextbomodules.hh:557
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:288
static Value rs(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:350
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:256
static bool eqApplies(unsigned eqIdx)
Definition: blackoilextbomodules.hh:129
static Value xVolume(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:318
static Value pbubRv(unsigned pvtRegionIdx, const Value &z, const Value &rv)
Definition: blackoilextbomodules.hh:330
static Scalar primaryVarWeight(unsigned pvIdx)
Definition: blackoilextbomodules.hh:121
static Value rv(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:354
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:338
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:265
static void serializeEntity(const Model &model, std::ostream &outstream, const DofEntity &dof)
Definition: blackoilextbomodules.hh:295
static Scalar referenceDensity(unsigned regionIdx)
Definition: blackoilextbomodules.hh:357
static void addExtboFluxes_(RateVector &flux, const unsigned phaseIdx, const Evaluation &volumeFlux, const IntensiveQuantities &up)
Add the z-component flux carried by one phase over a face.
Definition: blackoilextbomodules.hh:229
static Value yVolume(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:322
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:346
static Scalar computeUpdateError(const PrimaryVariables &, const EqVector &)
Return how much a Newton-Raphson update is considered an error.
Definition: blackoilextbomodules.hh:276
static Value gasCmp(unsigned pvtRegionIdx, const Value &z)
Definition: blackoilextbomodules.hh:368
static void deserializeEntity(Model &model, std::istream &instream, const DofEntity &dof)
Definition: blackoilextbomodules.hh:304
static std::string eqName(unsigned eqIdx)
Definition: blackoilextbomodules.hh:134
static Value oilViscosity(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:334
static Value pbubRs(unsigned pvtRegionIdx, const Value &z, const Value &rs)
Definition: blackoilextbomodules.hh:326
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:342
static Scalar zLim(unsigned regionIdx)
Definition: blackoilextbomodules.hh:360
static Value oilCmp(unsigned pvtRegionIdx, const Value &z)
Definition: blackoilextbomodules.hh:364
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:48