28#ifndef EWOMS_DISPERSION_MODULE_HH
29#define EWOMS_DISPERSION_MODULE_HH
33#include <opm/material/common/Valgrind.hpp>
35#include <dune/common/fvector.hh>
47template <
class TypeTag,
bool enableDispersion>
50template <
class TypeTag,
bool enableDispersion>
56template <
class TypeTag>
64 enum { numPhases = FluidSystem::numPhases };
70 static void initFromState(
const EclipseState&)
79 template <
class Context>
86 template<
class Flu
idState,
class Scalar>
98template <
class TypeTag>
113 enum { numPhases = FluidSystem::numPhases };
114 enum { numComponents = FluidSystem::numComponents };
115 enum { conti0EqIdx = Indices::conti0EqIdx };
116 enum { enableDispersion = getPropValue<TypeTag, Properties::EnableDispersion>() };
118 using Toolbox = MathToolbox<Evaluation>;
123 static void initFromState(
const EclipseState& eclState)
125 if (!eclState.getSimulationConfig().rock_config().dispersion()) {
129 if (eclState.getSimulationConfig().hasVAPWAT() || eclState.getSimulationConfig().hasVAPOIL()) {
130 OpmLog::warning(
"Dispersion is activated in combination with VAPWAT/VAPOIL. \n"
131 "Water/oil is still allowed to vaporize, but dispersion in the "
132 "gas phase is ignored.");
140 template <
class Context>
142 unsigned spaceIdx,
unsigned timeIdx)
145 if (!context.simulator().vanguard().eclState().getSimulationConfig().rock_config().dispersion()) {
148 const auto& extQuants = context.extensiveQuantities(spaceIdx, timeIdx);
149 const auto& fluidStateI = context.intensiveQuantities(extQuants.interiorIndex(), timeIdx).fluidState();
150 const auto& fluidStateJ = context.intensiveQuantities(extQuants.exteriorIndex(), timeIdx).fluidState();
151 const auto& dispersivity = extQuants.dispersivity();
152 const auto& normVelocityAvg = extQuants.normVelocityAvg();
153 addDispersiveFlux(flux, fluidStateI, fluidStateJ, dispersivity, normVelocityAvg);
176 template<
class Flu
idState,
class Scalar>
178 const FluidState& fluidStateI,
179 const FluidState& fluidStateJ,
180 const Evaluation& dispersivity,
181 const Scalar& normVelocityAvg)
183 unsigned pvtRegionIndex = fluidStateI.pvtRegionIndex();
184 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
185 if (!FluidSystem::phaseIsActive(phaseIdx)) {
190 if (!FluidSystem::enableDissolvedGasInWater() && FluidSystem::waterPhaseIdx == phaseIdx) {
197 if (FluidSystem::gasPhaseIdx == phaseIdx) {
202 if ((!FluidSystem::enableVaporizedWater() && !FluidSystem::enableVaporizedOil()) && FluidSystem::gasPhaseIdx == phaseIdx) {
207 Evaluation bAvg = fluidStateI.invB(phaseIdx);
208 bAvg += Toolbox::value(fluidStateJ.invB(phaseIdx));
211 Evaluation convFactor = 1.0;
212 Evaluation diffR = 0.0;
213 if (FluidSystem::enableDissolvedGas() && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx) && phaseIdx == FluidSystem::oilPhaseIdx) {
214 Evaluation rsAvg = (fluidStateI.Rs() + Toolbox::value(fluidStateJ.Rs())) / 2;
215 convFactor = 1.0 / (toMassFractionGasOil(pvtRegionIndex) + rsAvg);
216 diffR = fluidStateI.Rs() - Toolbox::value(fluidStateJ.Rs());
218 if (FluidSystem::enableVaporizedOil() && FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && phaseIdx == FluidSystem::gasPhaseIdx) {
219 Evaluation rvAvg = (fluidStateI.Rv() + Toolbox::value(fluidStateJ.Rv())) / 2;
220 convFactor = toMassFractionGasOil(pvtRegionIndex) / (1.0 + rvAvg*toMassFractionGasOil(pvtRegionIndex));
221 diffR = fluidStateI.Rv() - Toolbox::value(fluidStateJ.Rv());
223 if (FluidSystem::enableDissolvedGasInWater() && phaseIdx == FluidSystem::waterPhaseIdx) {
224 Evaluation rsAvg = (fluidStateI.Rsw() + Toolbox::value(fluidStateJ.Rsw())) / 2;
225 convFactor = 1.0 / (toMassFractionGasWater(pvtRegionIndex) + rsAvg);
226 diffR = fluidStateI.Rsw() - Toolbox::value(fluidStateJ.Rsw());
228 if (FluidSystem::enableVaporizedWater() && phaseIdx == FluidSystem::gasPhaseIdx) {
229 Evaluation rvAvg = (fluidStateI.Rvw() + Toolbox::value(fluidStateJ.Rvw())) / 2;
230 convFactor = toMassFractionGasWater(pvtRegionIndex)/ (1.0 + rvAvg*toMassFractionGasWater(pvtRegionIndex));
231 diffR = fluidStateI.Rvw() - Toolbox::value(fluidStateJ.Rvw());
235 unsigned solventCompIdx = FluidSystem::solventComponentIndex(phaseIdx);
236 unsigned activeSolventCompIdx = Indices::canonicalToActiveComponentIndex(solventCompIdx);
237 flux[conti0EqIdx + activeSolventCompIdx] +=
239 * normVelocityAvg[phaseIdx]
245 unsigned soluteCompIdx = FluidSystem::soluteComponentIndex(phaseIdx);
246 unsigned activeSoluteCompIdx = Indices::canonicalToActiveComponentIndex(soluteCompIdx);
247 flux[conti0EqIdx + activeSoluteCompIdx] +=
249 * normVelocityAvg[phaseIdx]
258 static Scalar toMassFractionGasOil (
unsigned regionIdx) {
259 Scalar rhoO = FluidSystem::referenceDensity(FluidSystem::oilPhaseIdx, regionIdx);
260 Scalar rhoG = FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, regionIdx);
263 static Scalar toMassFractionGasWater (
unsigned regionIdx) {
264 Scalar rhoW = FluidSystem::referenceDensity(FluidSystem::waterPhaseIdx, regionIdx);
265 Scalar rhoG = FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, regionIdx);
277template <
class TypeTag,
bool enableDispersion>
283template <
class TypeTag>
296 throw std::logic_error(
"Method normVelocityCell() "
297 "does not make sense if dispersion is disabled");
305 template<
class ElementContext>
315template <
class TypeTag>
324 enum { numPhases = FluidSystem::numPhases };
325 enum { numComponents = FluidSystem::numComponents };
326 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
327 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
328 enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
329 enum { gasCompIdx = FluidSystem::gasCompIdx };
330 enum { oilCompIdx = FluidSystem::oilCompIdx };
331 enum { waterCompIdx = FluidSystem::waterCompIdx };
332 enum { conti0EqIdx = Indices::conti0EqIdx };
333 enum { enableDispersion = getPropValue<TypeTag, Properties::EnableDispersion>() };
342 return normVelocityCell_[phaseIdx];
355 template<
class ElementContext>
356 void update_(
const ElementContext& elemCtx,
unsigned dofIdx,
unsigned timeIdx)
359 if (!elemCtx.simulator().vanguard().eclState().getSimulationConfig().rock_config().dispersion()) {
362 const auto& problem = elemCtx.simulator().problem();
363 if (problem.model().linearizer().getVelocityInfo().empty()) {
366 const std::array<int, 3> phaseIdxs = { gasPhaseIdx, oilPhaseIdx, waterPhaseIdx };
367 const std::array<int, 3> compIdxs = { gasCompIdx, oilCompIdx, waterCompIdx };
368 const auto& velocityInf = problem.model().linearizer().getVelocityInfo();
369 unsigned globalDofIdx = elemCtx.globalSpaceIndex(dofIdx, timeIdx);
370 auto velocityInfos = velocityInf[globalDofIdx];
371 for (
unsigned i = 0; i < phaseIdxs.size(); ++i) {
372 normVelocityCell_[i] = 0;
374 for (
auto& velocityInfo : velocityInfos) {
375 for (
unsigned i = 0; i < phaseIdxs.size(); ++i) {
376 if (FluidSystem::phaseIsActive(phaseIdxs[i])) {
377 normVelocityCell_[phaseIdxs[i]] = max( normVelocityCell_[phaseIdxs[i]],
378 std::abs( velocityInfo.velocity[conti0EqIdx
379 + Indices::canonicalToActiveComponentIndex(compIdxs[i])] ));
386 Scalar normVelocityCell_[numPhases];
395template <
class TypeTag,
bool enableDispersion>
396class BlackOilDispersionExtensiveQuantities;
401template <
class TypeTag>
410 enum { numPhases = FluidSystem::numPhases };
422 template <
class Context,
class Flu
idState>
433 const IntensiveQuantities&,
434 const IntensiveQuantities&)
443 throw std::logic_error(
"The method dispersivity() does not "
444 "make sense if dispersion is disabled.");
456 throw std::logic_error(
"The method normVelocityAvg() "
457 "does not make sense if dispersion is disabled.");
465template <
class TypeTag>
473 using Toolbox = MathToolbox<Evaluation>;
476 enum { dimWorld = GridView::dimensionworld };
477 enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
478 enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
480 using DimVector = Dune::FieldVector<Scalar, dimWorld>;
481 using DimEvalVector = Dune::FieldVector<Evaluation, dimWorld>;
485 const IntensiveQuantities& intQuantsInside,
486 const IntensiveQuantities& intQuantsOutside)
488 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
489 if (!FluidSystem::phaseIsActive(phaseIdx)) {
493 if (!FluidSystem::enableDissolvedGasInWater() && FluidSystem::waterPhaseIdx == phaseIdx) {
497 if ((!FluidSystem::enableVaporizedWater() && !FluidSystem::enableVaporizedOil()) && FluidSystem::gasPhaseIdx == phaseIdx) {
502 normVelocityAvg[phaseIdx] = 0.5 *
503 ( intQuantsInside.normVelocityCell(phaseIdx) +
504 intQuantsOutside.normVelocityCell(phaseIdx) );
505 Valgrind::CheckDefined(normVelocityAvg[phaseIdx]);
509 template <
class Context,
class Flu
idState>
515 throw std::runtime_error(
"Not implemented: Dispersion across boundary not implemented for blackoil");
526 {
return dispersivity_; }
536 {
return normVelocityAvg_[phaseIdx]; }
539 return normVelocityAvg_;
543 Scalar dispersivity_;
544 ScalarArray normVelocityAvg_;
Definition: blackoildispersionmodule.hh:403
void updateBoundary_(const Context &, unsigned, unsigned, const FluidState &)
Definition: blackoildispersionmodule.hh:423
void update_(const ElementContext &, unsigned, unsigned)
Update the quantities required to calculate the dispersive fluxes.
Definition: blackoildispersionmodule.hh:417
const Scalar & dispersivity() const
The dispersivity the face.
Definition: blackoildispersionmodule.hh:441
Scalar[numPhases] ScalarArray
Definition: blackoildispersionmodule.hh:430
static void update(ScalarArray &, const IntensiveQuantities &, const IntensiveQuantities &)
Definition: blackoildispersionmodule.hh:432
const Scalar & normVelocityAvg(unsigned) const
The effective filter velocity coefficient in a fluid phase at the face's integration point.
Definition: blackoildispersionmodule.hh:454
Provides the quantities required to calculate dispersive mass fluxes.
Definition: blackoildispersionmodule.hh:467
static void update(ScalarArray &normVelocityAvg, const IntensiveQuantities &intQuantsInside, const IntensiveQuantities &intQuantsOutside)
Definition: blackoildispersionmodule.hh:484
const Scalar & dispersivity() const
The dispersivity of the face.
Definition: blackoildispersionmodule.hh:525
Scalar[numPhases] ScalarArray
Definition: blackoildispersionmodule.hh:483
void updateBoundary_(const Context &, unsigned, unsigned, const FluidState &)
Definition: blackoildispersionmodule.hh:510
const auto & normVelocityAvg() const
Definition: blackoildispersionmodule.hh:538
const Scalar & normVelocityAvg(unsigned phaseIdx) const
The effective velocity coefficient in a fluid phase at the face's integration point.
Definition: blackoildispersionmodule.hh:535
Provides the quantities required to calculate dispersive mass fluxes.
Definition: blackoildispersionmodule.hh:51
Scalar normVelocityCell(unsigned, unsigned) const
Returns the max. norm of the filter velocity of the cell.
Definition: blackoildispersionmodule.hh:294
void update_(ElementContext &, unsigned, unsigned)
Update the quantities required to calculate dispersive fluxes.
Definition: blackoildispersionmodule.hh:306
void update_(const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx)
Update the quantities required to calculate dispersive mass fluxes. This considers the linear disperi...
Definition: blackoildispersionmodule.hh:356
Scalar normVelocityCell(unsigned phaseIdx) const
Returns the max. norm of the filter velocity of the cell.
Definition: blackoildispersionmodule.hh:339
Provides the volumetric quantities required for the calculation of dispersive fluxes.
Definition: blackoildispersionmodule.hh:278
static void addDispersiveFlux(RateVector &, const Context &, unsigned, unsigned)
Adds the dispersive flux to the flux vector over a flux integration point.
Definition: blackoildispersionmodule.hh:80
static void addDispersiveFlux(RateVector &, const FluidState &, const FluidState &, const Evaluation &, const Scalar &)
Definition: blackoildispersionmodule.hh:87
static void addDispersiveFlux(RateVector &flux, const FluidState &fluidStateI, const FluidState &fluidStateJ, const Evaluation &dispersivity, const Scalar &normVelocityAvg)
Adds the mass flux due to dispersion to the flux vector over the integration point....
Definition: blackoildispersionmodule.hh:177
static void addDispersiveFlux(RateVector &flux, const Context &context, unsigned spaceIdx, unsigned timeIdx)
Adds the mass flux due to dispersion to the flux vector over the flux integration point.
Definition: blackoildispersionmodule.hh:141
Provides the auxiliary methods required for consideration of the dispersion equation.
Definition: blackoildispersionmodule.hh:48
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