32#ifndef EWOMS_BLACK_OIL_EXTBO_MODULE_HH
33#define EWOMS_BLACK_OIL_EXTBO_MODULE_HH
44#include <dune/common/fvector.hh>
57template <class TypeTag, bool enableExtboV = getPropValue<TypeTag, Properties::EnableExtbo>()>
73 using Toolbox = MathToolbox<Evaluation>;
78 static constexpr unsigned zFractionIdx = Indices::zFractionIdx;
79 static constexpr unsigned contiZfracEqIdx = Indices::contiZfracEqIdx;
80 static constexpr unsigned enableExtbo = enableExtboV;
81 static constexpr unsigned numEq = getPropValue<TypeTag, Properties::NumEq>();
82 static constexpr unsigned numPhases = FluidSystem::numPhases;
83 static constexpr unsigned gasPhaseIdx = FluidSystem::gasPhaseIdx;
84 static constexpr unsigned oilPhaseIdx = FluidSystem::oilPhaseIdx;
85 static constexpr unsigned waterPhaseIdx = FluidSystem::waterPhaseIdx;
86 static constexpr bool blackoilConserveSurfaceVolume = getPropValue<TypeTag, Properties::BlackoilConserveSurfaceVolume>();
112 if constexpr (enableExtbo)
113 return pvIdx == zFractionIdx;
130 return static_cast<Scalar
>(1.0);
135 if constexpr (enableExtbo)
136 return eqIdx == contiZfracEqIdx;
141 static std::string
eqName([[maybe_unused]]
unsigned eqIdx)
145 return "conti^solvent";
148 static Scalar
eqWeight([[maybe_unused]]
unsigned eqIdx)
153 return static_cast<Scalar
>(1.0);
156 template <
class LhsEval>
157 static void addStorage(Dune::FieldVector<LhsEval, numEq>& storage,
158 const IntensiveQuantities& intQuants)
160 if constexpr (enableExtbo) {
161 if constexpr (blackoilConserveSurfaceVolume) {
162 storage[contiZfracEqIdx] =
163 Toolbox::template decay<LhsEval>(intQuants.porosity())
164 * Toolbox::template decay<LhsEval>(intQuants.yVolume())
165 * Toolbox::template decay<LhsEval>(intQuants.fluidState().saturation(gasPhaseIdx))
166 * Toolbox::template decay<LhsEval>(intQuants.fluidState().invB(gasPhaseIdx));
167 if (FluidSystem::enableDissolvedGas()) {
168 storage[contiZfracEqIdx] +=
169 Toolbox::template decay<LhsEval>(intQuants.porosity())
170 * Toolbox::template decay<LhsEval>(intQuants.xVolume())
171 * Toolbox::template decay<LhsEval>(intQuants.fluidState().Rs())
172 * Toolbox::template decay<LhsEval>(intQuants.fluidState().saturation(oilPhaseIdx))
173 * Toolbox::template decay<LhsEval>(intQuants.fluidState().invB(oilPhaseIdx));
178 const Scalar regWghtFactor = 1.0e-6;
179 storage[contiZfracEqIdx] += regWghtFactor*(1.0-Toolbox::template decay<LhsEval>(intQuants.zFraction()))
180 + regWghtFactor*Toolbox::template decay<LhsEval>(intQuants.porosity())
181 * Toolbox::template decay<LhsEval>(intQuants.fluidState().saturation(gasPhaseIdx))
182 * Toolbox::template decay<LhsEval>(intQuants.fluidState().invB(gasPhaseIdx));
183 storage[contiZfracEqIdx-1] += regWghtFactor*Toolbox::template decay<LhsEval>(intQuants.zFraction());
186 throw std::runtime_error(
"Only component conservation in terms of surface volumes is implemented. ");
192 [[maybe_unused]]
const ElementContext& elemCtx,
193 [[maybe_unused]]
unsigned scvfIdx,
194 [[maybe_unused]]
unsigned timeIdx)
197 if constexpr (enableExtbo) {
198 const auto& extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
200 if constexpr (blackoilConserveSurfaceVolume) {
201 unsigned inIdx = extQuants.interiorIndex();
203 unsigned upIdxGas =
static_cast<unsigned>(extQuants.upstreamIndex(gasPhaseIdx));
204 const auto& upGas = elemCtx.intensiveQuantities(upIdxGas, timeIdx);
205 const auto& fsGas = upGas.fluidState();
206 if (upIdxGas == inIdx) {
207 flux[contiZfracEqIdx] =
208 extQuants.volumeFlux(gasPhaseIdx)
210 * fsGas.invB(gasPhaseIdx);
213 flux[contiZfracEqIdx] =
214 extQuants.volumeFlux(gasPhaseIdx)
215 * (decay<Scalar>(upGas.yVolume()))
216 * decay<Scalar>(fsGas.invB(gasPhaseIdx));
218 if (FluidSystem::enableDissolvedGas()) {
219 unsigned upIdxOil =
static_cast<unsigned>(extQuants.upstreamIndex(oilPhaseIdx));
220 const auto& upOil = elemCtx.intensiveQuantities(upIdxOil, timeIdx);
221 const auto& fsOil = upOil.fluidState();
222 if (upIdxOil == inIdx) {
223 flux[contiZfracEqIdx] +=
224 extQuants.volumeFlux(oilPhaseIdx)
227 * fsOil.invB(oilPhaseIdx);
230 flux[contiZfracEqIdx] +=
231 extQuants.volumeFlux(oilPhaseIdx)
232 * decay<Scalar>(upOil.xVolume())
233 * decay<Scalar>(fsOil.Rs())
234 * decay<Scalar>(fsOil.invB(oilPhaseIdx));
239 throw std::runtime_error(
"Only component conservation in terms of surface volumes is implemented. ");
250 if constexpr (enableExtbo)
251 priVars[zFractionIdx] = zFraction;
258 const PrimaryVariables& oldPv,
259 const EqVector& delta)
261 if constexpr (enableExtbo)
263 newPv[zFractionIdx] = oldPv[zFractionIdx] - delta[zFractionIdx];
275 return static_cast<Scalar
>(0.0);
284 return std::abs(Toolbox::scalarValue(resid[contiZfracEqIdx]));
287 template <
class DofEntity>
288 static void serializeEntity(
const Model& model, std::ostream& outstream,
const DofEntity& dof)
290 if constexpr (enableExtbo) {
291 unsigned dofIdx = model.dofMapper().index(dof);
293 const PrimaryVariables& priVars = model.solution(0)[dofIdx];
294 outstream << priVars[zFractionIdx];
298 template <
class DofEntity>
301 if constexpr (enableExtbo) {
302 unsigned dofIdx = model.dofMapper().index(dof);
304 PrimaryVariables& priVars0 = model.solution(0)[dofIdx];
305 PrimaryVariables& priVars1 = model.solution(1)[dofIdx];
307 instream >> priVars0[zFractionIdx];
310 priVars1 = priVars0[zFractionIdx];
314 template <
typename Value>
315 static Value
xVolume(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z) {
316 return params_.X_[pvtRegionIdx].eval(z, pressure,
true);
319 template <
typename Value>
320 static Value
yVolume(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z) {
321 return params_.Y_[pvtRegionIdx].eval(z, pressure,
true);
324 template <
typename Value>
325 static Value
pbubRs(
unsigned pvtRegionIdx,
const Value& z,
const Value&
rs) {
326 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);
334 template <
typename Value>
335 static Value
oilViscosity(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z) {
336 return params_.VISCO_[pvtRegionIdx].eval(z, pressure,
true);
339 template <
typename Value>
340 static Value
gasViscosity(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z) {
341 return params_.VISCG_[pvtRegionIdx].eval(z, pressure,
true);
344 template <
typename Value>
345 static Value
bo(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z) {
346 return params_.BO_[pvtRegionIdx].eval(z, pressure,
true);
349 template <
typename Value>
350 static Value
bg(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z) {
351 return params_.BG_[pvtRegionIdx].eval(z, pressure,
true);
354 template <
typename Value>
355 static Value
rs(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z) {
356 return params_.RS_[pvtRegionIdx].eval(z, pressure,
true);
359 template <
typename Value>
360 static Value
rv(
unsigned pvtRegionIdx,
const Value& pressure,
const Value& z) {
361 return params_.RV_[pvtRegionIdx].eval(z, pressure,
true);
365 return params_.zReferenceDensity_[regionIdx];
368 static Scalar
zLim(
unsigned regionIdx) {
369 return params_.zLim_[regionIdx];
372 template <
typename Value>
373 static Value
oilCmp(
unsigned pvtRegionIdx,
const Value& z) {
374 return params_.oilCmp_[pvtRegionIdx].eval(z,
true);
377 template <
typename Value>
378 static Value
gasCmp(
unsigned pvtRegionIdx,
const Value& z) {
379 return params_.gasCmp_[pvtRegionIdx].eval(z,
true);
386template <
class TypeTag,
bool enableExtboV>
387BlackOilExtboParams<typename BlackOilExtboModule<TypeTag, enableExtboV>::Scalar>
388BlackOilExtboModule<TypeTag, enableExtboV>::params_;
397template <class TypeTag, bool enableExtboV = getPropValue<TypeTag, Properties::EnableExtbo>()>
412 enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
413 static constexpr int zFractionIdx = Indices::zFractionIdx;
414 static constexpr int oilPhaseIdx = FluidSystem::oilPhaseIdx;
415 static constexpr int gasPhaseIdx = FluidSystem::gasPhaseIdx;
416 static constexpr int waterPhaseIdx = FluidSystem::waterPhaseIdx;
417 static constexpr double cutOff = 1e-12;
430 const PrimaryVariables& priVars = elemCtx.primaryVars(dofIdx, timeIdx);
431 unsigned pvtRegionIdx = priVars.pvtRegionIndex();
432 auto& fs =
asImp_().fluidState_;
434 zFraction_ = priVars.makeEvaluation(zFractionIdx, timeIdx);
444 if (FluidSystem::enableDissolvedGas())
449 if (FluidSystem::enableVaporizedOil())
457 Evaluation pbub = fs.pressure(oilPhaseIdx);
459 if (priVars.primaryVarsMeaningWater() == PrimaryVariables::WaterMeaning::Sw) {
460 static const Scalar thresholdWaterFilledCell = 1.0 - 1e-6;
461 Scalar sw = priVars.makeEvaluation(Indices::waterSwitchIdx, timeIdx).value();
462 if (sw >= thresholdWaterFilledCell)
466 if (priVars.primaryVarsMeaningGas() == PrimaryVariables::GasMeaning::Rs) {
467 rs_ = priVars.makeEvaluation(Indices::compositionSwitchIdx, timeIdx);
479 if (priVars.primaryVarsMeaningGas() == PrimaryVariables::GasMeaning::Rv) {
480 rv_ = priVars.makeEvaluation(Indices::compositionSwitchIdx, timeIdx);
495 const auto& iq =
asImp_();
496 auto& fs =
asImp_().fluidState_;
498 unsigned pvtRegionIdx = iq.pvtRegionIndex();
501 fs.setInvB(oilPhaseIdx, 1.0/
bo_);
502 fs.setInvB(gasPhaseIdx, 1.0/
bg_);
504 fs.setDensity(oilPhaseIdx,
506 *(FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx)
507 + (1.0-
xVolume_)*fs.Rs()*FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx)
509 fs.setDensity(gasPhaseIdx,
512 + FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx)*fs.Rv()));
530 const Evaluation&
bo()
const
533 const Evaluation&
bg()
const
536 const Evaluation&
rs()
const
539 const Evaluation&
rv()
const
553 {
return *
static_cast<Implementation*
>(
this); }
577template <
class TypeTag>
595 {
throw std::runtime_error(
"xVolume() called but extbo is disabled"); }
598 {
throw std::runtime_error(
"yVolume() called but extbo is disabled"); }
601 {
throw std::runtime_error(
"oilViscosity() called but extbo is disabled"); }
604 {
throw std::runtime_error(
"gasViscosity() called but extbo is disabled"); }
606 const Evaluation&
rs()
const
607 {
throw std::runtime_error(
"rs() called but extbo is disabled"); }
609 const Evaluation&
rv()
const
610 {
throw std::runtime_error(
"rv() called but extbo is disabled"); }
613 {
throw std::runtime_error(
"zPureInvFormationVolumeFactor() called but extbo is disabled"); }
616 {
throw std::runtime_error(
"zFraction() called but extbo is disabled"); }
619 {
throw std::runtime_error(
"zInverseFormationVolumeFactor() called but extbo is disabled"); }
622 {
throw std::runtime_error(
"zRefDensity() called but extbo is disabled"); }
632template <class TypeTag, bool enableExtboV = getPropValue<TypeTag, Properties::EnableExtbo>()>
645 using Toolbox = MathToolbox<Evaluation>;
647 static constexpr unsigned gasPhaseIdx = FluidSystem::gasPhaseIdx;
648 static constexpr int dimWorld = GridView::dimensionworld;
650 typedef Dune::FieldVector<Scalar, dimWorld> DimVector;
651 typedef Dune::FieldVector<Evaluation, dimWorld> DimEvalVector;
656 Implementation& asImp_()
657 {
return *
static_cast<Implementation*
>(
this); }
661template <
class TypeTag>
Defines a type tags and some fundamental properties all models.
Contains the parameters required to extend the black-oil model by solvent component....
Declares the properties required by the black oil model.
Provides the solvent specific extensive quantities to the generic black-oil module's extensive quanti...
Definition: blackoilextbomodules.hh:634
const Scalar & zRefDensity() const
Definition: blackoilextbomodules.hh:621
const Evaluation & xVolume() const
Definition: blackoilextbomodules.hh:594
const Evaluation & rs() const
Definition: blackoilextbomodules.hh:606
const Evaluation & zInverseFormationVolumeFactor() const
Definition: blackoilextbomodules.hh:618
const Evaluation & zPureInvFormationVolumeFactor() const
Definition: blackoilextbomodules.hh:612
const Evaluation & oilViscosity() const
Definition: blackoilextbomodules.hh:600
void zFractionUpdate_(const ElementContext &, unsigned, unsigned)
Definition: blackoilextbomodules.hh:589
const Evaluation & zFraction() const
Definition: blackoilextbomodules.hh:615
void zPvtUpdate_()
Definition: blackoilextbomodules.hh:586
const Evaluation & rv() const
Definition: blackoilextbomodules.hh:609
const Evaluation & gasViscosity() const
Definition: blackoilextbomodules.hh:603
const Evaluation & yVolume() const
Definition: blackoilextbomodules.hh:597
Provides the volumetric quantities required for the equations needed by the solvents extension of the...
Definition: blackoilextbomodules.hh:399
const Evaluation & rv() const
Definition: blackoilextbomodules.hh:539
Evaluation zFraction_
Definition: blackoilextbomodules.hh:558
const Evaluation & oilViscosity() const
Definition: blackoilextbomodules.hh:524
const Evaluation & zFraction() const
Definition: blackoilextbomodules.hh:515
const Evaluation & bo() const
Definition: blackoilextbomodules.hh:530
void zFractionUpdate_(const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx)
Compute extended pvt properties from table lookups.
Definition: blackoilextbomodules.hh:426
Scalar zRefDensity_
Definition: blackoilextbomodules.hh:574
void zPvtUpdate_()
Re-compute face densities to account for zFraction dependency.
Definition: blackoilextbomodules.hh:493
const Evaluation & yVolume() const
Definition: blackoilextbomodules.hh:521
Evaluation gasViscosity_
Definition: blackoilextbomodules.hh:566
Evaluation bg_
Definition: blackoilextbomodules.hh:568
Evaluation rs_
Definition: blackoilextbomodules.hh:569
const Evaluation & gasViscosity() const
Definition: blackoilextbomodules.hh:527
const Evaluation & rs() const
Definition: blackoilextbomodules.hh:536
Implementation & asImp_()
Definition: blackoilextbomodules.hh:552
Evaluation rv_
Definition: blackoilextbomodules.hh:570
const Evaluation & bg() const
Definition: blackoilextbomodules.hh:533
const Evaluation zPureInvFormationVolumeFactor() const
Definition: blackoilextbomodules.hh:542
const Scalar & zRefDensity() const
Definition: blackoilextbomodules.hh:545
Evaluation bo_
Definition: blackoilextbomodules.hh:567
Evaluation bz_
Definition: blackoilextbomodules.hh:573
Evaluation yVolume_
Definition: blackoilextbomodules.hh:562
Evaluation xVolume_
Definition: blackoilextbomodules.hh:561
Evaluation oilViscosity_
Definition: blackoilextbomodules.hh:565
const Evaluation & xVolume() const
Definition: blackoilextbomodules.hh:518
Contains the high level supplements required to extend the black oil model.
Definition: blackoilextbomodules.hh:59
static void addStorage(Dune::FieldVector< LhsEval, numEq > &storage, const IntensiveQuantities &intQuants)
Definition: blackoilextbomodules.hh:157
static bool primaryVarApplies(unsigned pvIdx)
Definition: blackoilextbomodules.hh:110
static Scalar zLim(unsigned regionIdx)
Definition: blackoilextbomodules.hh:368
static Scalar computeResidualError(const EqVector &resid)
Return how much a residual is considered an error.
Definition: blackoilextbomodules.hh:281
static Value yVolume(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:257
static Value gasViscosity(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:340
static std::string eqName(unsigned eqIdx)
Definition: blackoilextbomodules.hh:141
static bool eqApplies(unsigned eqIdx)
Definition: blackoilextbomodules.hh:133
static Value pbubRv(unsigned pvtRegionIdx, const Value &z, const Value &rv)
Definition: blackoilextbomodules.hh:330
static Scalar primaryVarWeight(unsigned pvIdx)
Definition: blackoilextbomodules.hh:125
static Value rs(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:355
static void registerOutputModules(Model &, Simulator &)
Register all solvent specific VTK and ECL output modules.
Definition: blackoilextbomodules.hh:105
static Scalar computeUpdateError(const PrimaryVariables &, const EqVector &)
Return how much a Newton-Raphson update is considered an error.
Definition: blackoilextbomodules.hh:269
static Value xVolume(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:315
static void serializeEntity(const Model &model, std::ostream &outstream, const DofEntity &dof)
Definition: blackoilextbomodules.hh:288
static void computeFlux(RateVector &flux, const ElementContext &elemCtx, unsigned scvfIdx, unsigned timeIdx)
Definition: blackoilextbomodules.hh:191
static void registerParameters()
Register all run-time parameters for the black-oil solvent module.
Definition: blackoilextbomodules.hh:98
static void deserializeEntity(Model &model, std::istream &instream, const DofEntity &dof)
Definition: blackoilextbomodules.hh:299
static std::string primaryVarName(unsigned pvIdx)
Definition: blackoilextbomodules.hh:118
static Value rv(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:360
static void setParams(BlackOilExtboParams< Scalar > &¶ms)
Set parameters.
Definition: blackoilextbomodules.hh:90
static Value pbubRs(unsigned pvtRegionIdx, const Value &z, const Value &rs)
Definition: blackoilextbomodules.hh:325
static Value oilCmp(unsigned pvtRegionIdx, const Value &z)
Definition: blackoilextbomodules.hh:373
static Scalar referenceDensity(unsigned regionIdx)
Definition: blackoilextbomodules.hh:364
static Value bg(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:350
static Value oilViscosity(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:335
static void assignPrimaryVars(PrimaryVariables &priVars, Scalar zFraction)
Assign the solvent specific primary variables to a PrimaryVariables object.
Definition: blackoilextbomodules.hh:247
static Scalar eqWeight(unsigned eqIdx)
Definition: blackoilextbomodules.hh:148
static Value bo(unsigned pvtRegionIdx, const Value &pressure, const Value &z)
Definition: blackoilextbomodules.hh:345
static Value gasCmp(unsigned pvtRegionIdx, const Value &z)
Definition: blackoilextbomodules.hh:378
Declare the properties used by the infrastructure code of the finite volume discretizations.
Definition: blackoilboundaryratevector.hh:37
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:235
Struct holding the parameters for the BlackoilExtboModule class.
Definition: blackoilextboparams.hpp:49
UniformXTabulated2DFunction< Scalar > Tabulated2DFunction
Definition: blackoilextboparams.hpp:51
Tabulated1DFunction< Scalar > TabulatedFunction
Definition: blackoilextboparams.hpp:50