22#ifndef DUMUX_MPFAL2DPRESSUREVELOCITY2P_HH
23#define DUMUX_MPFAL2DPRESSUREVELOCITY2P_HH
25#include <dune/common/float_cmp.hh>
55 dim = GridView::dimension, dimWorld = GridView::dimensionworld
63 using PrimaryVariables =
typename SolutionTypes::PrimaryVariables;
72 using IndexSet =
typename GridView::IndexSet;
73 using Intersection =
typename GridView::Intersection;
79 pw = Indices::pressureW,
80 pn = Indices::pressureNw,
81 sw = Indices::saturationW,
82 sn = Indices::saturationNw,
83 wPhaseIdx = Indices::wPhaseIdx,
84 nPhaseIdx = Indices::nPhaseIdx,
85 pressureIdx = Indices::pressureIdx,
86 saturationIdx = Indices::saturationIdx,
87 pressEqIdx = Indices::pressureEqIdx,
88 satEqIdx = Indices::satEqIdx,
89 numPhases = getPropValue<TypeTag, Properties::NumPhases>()
92 using Element =
typename GridView::template Codim<0>::Entity;
94 using GlobalPosition =
typename Element::Geometry::GlobalCoordinate;
95 using DimMatrix = Dune::FieldMatrix<Scalar, dim, dim>;
104 ParentType(problem), problem_(problem), velocity_(problem)
106 density_[wPhaseIdx] = 0.;
107 density_[nPhaseIdx] = 0.;
108 viscosity_[wPhaseIdx] = 0.;
109 viscosity_[nPhaseIdx] = 0.;
111 calcVelocityInTransport_ = getParam<bool>(
"MPFA.CalcVelocityInTransport");
139 const auto element = *problem_.gridView().template begin<0>();
140 FluidState fluidState;
141 fluidState.setPressure(wPhaseIdx, problem_.referencePressure(element));
142 fluidState.setPressure(nPhaseIdx, problem_.referencePressure(element));
143 fluidState.setTemperature(problem_.temperature(element));
144 fluidState.setSaturation(wPhaseIdx, 1.);
145 fluidState.setSaturation(nPhaseIdx, 0.);
152 velocity_.initialize();
178 return calcVelocityInTransport_;
191 template<
class MultiWriter>
195 velocity_.addOutputVtkFields(writer);
202 Scalar density_[numPhases];
203 Scalar viscosity_[numPhases];
204 bool calcVelocityInTransport_;
207 static const int pressureType_ = getPropValue<TypeTag, Properties::PressureFormulation>();
209 static const int saturationType_ = getPropValue<TypeTag, Properties::SaturationFormulation>();
219template<
class TypeTag>
223 for (
const auto& vertex : vertices(problem_.gridView()))
225 int vIdxGlobal = problem_.variables().index(vertex);
237 int eIdxGlobal1 = problem_.variables().index(element1);
238 int eIdxGlobal2 = problem_.variables().index(element2);
239 int eIdxGlobal3 = problem_.variables().index(element3);
240 int eIdxGlobal4 = problem_.variables().index(element4);
243 CellData& cellData1 = problem_.variables().cellData(eIdxGlobal1);
244 CellData& cellData2 = problem_.variables().cellData(eIdxGlobal2);
245 CellData& cellData3 = problem_.variables().cellData(eIdxGlobal3);
246 CellData& cellData4 = problem_.variables().cellData(eIdxGlobal4);
248 velocity_.calculateInnerInteractionVolumeVelocity(interactionVolume, cellData1, cellData2,
249 cellData3, cellData4, this->innerBoundaryVolumeFaces_);
255 for (
int elemIdx = 0; elemIdx < 2 * dim; elemIdx++)
257 bool isOutside =
false;
258 for (
int fIdx = 0; fIdx < dim; fIdx++)
272 int eIdxGlobal = problem_.variables().index(interactionVolume.
getSubVolumeElement(elemIdx));
274 CellData& cellData = problem_.variables().cellData(eIdxGlobal);
276 velocity_.calculateBoundaryInteractionVolumeVelocity(interactionVolume, cellData, elemIdx);
295template<
class TypeTag>
298 int numVertices = intersection.geometry().corners();
300 auto elementI = intersection.inside();
301 auto elementJ = intersection.outside();
303 int eIdxGlobalI = problem_.variables().index(elementI);
304 int eIdxGlobalJ = problem_.variables().index(elementJ);
306 CellData& cellDataJ = problem_.variables().cellData(eIdxGlobalJ);
308 const auto refElement = referenceElement(elementI);
310 int indexInInside = intersection.indexInInside();
311 int indexInOutside = intersection.indexInOutside();
313 Dune::FieldVector<CellData, 4> cellDataTemp;
315 for (
int vIdx = 0; vIdx < numVertices; vIdx++)
317 int localVertIdx = refElement.subEntity(indexInInside, dim - 1, vIdx, dim);
319 int vIdxGlobal = problem_.variables().index(elementI.template subEntity<dim>(localVertIdx));
333 eIdxGlobal[0] = problem_.variables().index(element1);
334 eIdxGlobal[1] = problem_.variables().index(element2);
335 eIdxGlobal[2] = problem_.variables().index(element3);
336 eIdxGlobal[3] = problem_.variables().index(element4);
339 cellDataTemp[0] = problem_.variables().cellData(eIdxGlobal[0]);
340 cellDataTemp[1] = problem_.variables().cellData(eIdxGlobal[1]);
341 cellDataTemp[2] = problem_.variables().cellData(eIdxGlobal[2]);
342 cellDataTemp[3] = problem_.variables().cellData(eIdxGlobal[3]);
344 velocity_.calculateInnerInteractionVolumeVelocity(interactionVolume, cellDataTemp[0], cellDataTemp[1],
345 cellDataTemp[2], cellDataTemp[3], this->innerBoundaryVolumeFaces_);
347 for (
int i = 0; i < 4; i++)
349 if (eIdxGlobal[i] == eIdxGlobalI)
351 cellData.fluxData().setVelocity(wPhaseIdx, indexInInside,
352 cellDataTemp[i].fluxData().velocity(wPhaseIdx, indexInInside));
353 cellData.fluxData().setVelocity(nPhaseIdx, indexInInside,
354 cellDataTemp[i].fluxData().velocity(nPhaseIdx, indexInInside));
355 cellData.fluxData().setUpwindPotential(wPhaseIdx, indexInInside,
356 cellDataTemp[i].fluxData().upwindPotential(wPhaseIdx, indexInInside));
357 cellData.fluxData().setUpwindPotential(nPhaseIdx, indexInInside,
358 cellDataTemp[i].fluxData().upwindPotential(nPhaseIdx, indexInInside));
360 else if (eIdxGlobal[i] == eIdxGlobalJ)
362 cellDataJ.fluxData().setVelocity(wPhaseIdx, indexInOutside,
363 cellDataTemp[i].fluxData().velocity(wPhaseIdx, indexInOutside));
364 cellDataJ.fluxData().setVelocity(nPhaseIdx, indexInOutside,
365 cellDataTemp[i].fluxData().velocity(nPhaseIdx, indexInOutside));
366 cellDataJ.fluxData().setUpwindPotential(wPhaseIdx, indexInOutside,
367 cellDataTemp[i].fluxData().upwindPotential(wPhaseIdx, indexInOutside));
368 cellDataJ.fluxData().setUpwindPotential(nPhaseIdx, indexInOutside,
369 cellDataTemp[i].fluxData().upwindPotential(nPhaseIdx, indexInOutside));
374 cellData.fluxData().setVelocityMarker(indexInInside);
375 cellDataJ.fluxData().setVelocityMarker(indexInOutside);
386template<
class TypeTag>
389 auto element = intersection.inside();
392 int isIndex = intersection.indexInInside();
395 const Dune::FieldVector<Scalar, dim>& unitOuterNormal = intersection.centerUnitOuterNormal();
397 BoundaryTypes bcType;
399 problem_.boundaryTypes(bcType, intersection);
400 PrimaryVariables boundValues(0.0);
402 if (bcType.isDirichlet(pressEqIdx))
404 problem_.dirichlet(boundValues, intersection);
407 const GlobalPosition& globalPosI = element.geometry().center();
410 const GlobalPosition& globalPosJ = intersection.geometry().center();
413 Scalar lambdaWI = cellData.mobility(wPhaseIdx);
414 Scalar lambdaNwI = cellData.mobility(nPhaseIdx);
417 Scalar pcI = cellData.capillaryPressure();
420 GlobalPosition distVec = globalPosJ - globalPosI;
423 Scalar dist = distVec.two_norm();
427 DimMatrix meanPermeability(0);
429 problem_.spatialParams().meanK(meanPermeability, problem_.spatialParams().intrinsicPermeability(element));
436 if (bcType.isDirichlet(satEqIdx))
438 switch (saturationType_)
442 satW = boundValues[saturationIdx];
447 satW = 1 - boundValues[saturationIdx];
454 satW = cellData.saturation(wPhaseIdx);
457 const Scalar pressBound = boundValues[pressureIdx];
462 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem_.spatialParams(), element);
464 const Scalar pcBound = fluidMatrixInteraction.pc(satW);
467 Scalar pressWBound = 0;
468 Scalar pressNwBound = 0;
469 if (pressureType_ == pw)
471 pressWBound = pressBound;
472 pressNwBound = pressBound + pcBound;
474 else if (pressureType_ == pn)
476 pressWBound = pressBound - pcBound;
477 pressNwBound = pressBound;
480 const Scalar lambdaWBound = fluidMatrixInteraction.krw(satW) / viscosity_[wPhaseIdx];
481 const Scalar lambdaNwBound = fluidMatrixInteraction.krn(satW) / viscosity_[nPhaseIdx];
483 Scalar potentialDiffW = cellData.fluxData().upwindPotential(wPhaseIdx, isIndex);
484 Scalar potentialDiffNw = cellData.fluxData().upwindPotential(nPhaseIdx, isIndex);
487 potentialDiffW = (cellData.pressure(wPhaseIdx) - pressWBound);
488 potentialDiffNw = (cellData.pressure(nPhaseIdx) - pressNwBound);
490 potentialDiffW += density_[wPhaseIdx] * (distVec * problem_.gravity());
491 potentialDiffNw += density_[nPhaseIdx] * (distVec * problem_.gravity());
494 cellData.fluxData().setUpwindPotential(wPhaseIdx, isIndex, potentialDiffW);
495 cellData.fluxData().setUpwindPotential(nPhaseIdx, isIndex, potentialDiffNw);
498 Scalar lambdaW = (potentialDiffW > 0.) ? lambdaWI : lambdaWBound;
499 lambdaW = (Dune::FloatCmp::eq<Scalar, Dune::FloatCmp::absolute>(potentialDiffW, 0.0, 1.0e-30)) ? 0.5 * (lambdaWI + lambdaWBound) : lambdaW;
500 Scalar lambdaNw = (potentialDiffNw > 0.) ? lambdaNwI : lambdaNwBound;
501 lambdaNw = (Dune::FloatCmp::eq<Scalar, Dune::FloatCmp::absolute>(potentialDiffNw, 0.0, 1.0e-30)) ? 0.5 * (lambdaNwI + lambdaNwBound) : lambdaNw;
507 Dune::FieldVector<Scalar, dimWorld> velocityW(unitOuterNormal);
508 Dune::FieldVector<Scalar, dimWorld> velocityNw(unitOuterNormal);
512 Scalar areaScaling = (unitOuterNormal * distVec);
514 Scalar gravityTermW = (problem_.gravity() * distVec) * density_[wPhaseIdx] * areaScaling;
515 Scalar gravityTermNw = (problem_.gravity() * distVec) * density_[nPhaseIdx] * areaScaling;
518 switch (pressureType_)
522 velocityW *= lambdaW * scalarPerm * ((cellData.pressure(wPhaseIdx) - pressBound) / dist + gravityTermW);
523 velocityNw *= lambdaNw * scalarPerm * ((cellData.pressure(wPhaseIdx) - pressBound) / dist + gravityTermNw)
524 + 0.5 * (lambdaNwI + lambdaNwBound) * scalarPerm * (pcI - pcBound) / dist;
529 velocityW *= lambdaW * scalarPerm * ((cellData.pressure(nPhaseIdx) - pressBound) / dist + gravityTermW)
530 - 0.5 * (lambdaWI + lambdaWBound) * scalarPerm * (pcI - pcBound) / dist;
531 velocityNw *= lambdaNw * scalarPerm * ((cellData.pressure(nPhaseIdx) - pressBound) / dist + gravityTermNw);
537 cellData.fluxData().setVelocity(wPhaseIdx, isIndex, velocityW);
538 cellData.fluxData().setVelocity(nPhaseIdx, isIndex, velocityNw);
539 cellData.fluxData().setVelocityMarker(isIndex);
543 else if (bcType.isNeumann(pressEqIdx))
545 problem_.neumann(boundValues, intersection);
547 Dune::FieldVector<Scalar, dimWorld> velocityW(unitOuterNormal);
548 Dune::FieldVector<Scalar, dimWorld> velocityNw(unitOuterNormal);
550 velocityW *= boundValues[wPhaseIdx];
551 velocityNw *= boundValues[nPhaseIdx];
553 velocityW /= density_[wPhaseIdx];
554 velocityNw /= density_[nPhaseIdx];
557 cellData.fluxData().setUpwindPotential(wPhaseIdx, isIndex, boundValues[wPhaseIdx]);
558 cellData.fluxData().setUpwindPotential(nPhaseIdx, isIndex, boundValues[nPhaseIdx]);
560 cellData.fluxData().setVelocity(wPhaseIdx, isIndex, velocityW);
561 cellData.fluxData().setVelocity(nPhaseIdx, isIndex, velocityNw);
562 cellData.fluxData().setVelocityMarker(isIndex);
566 DUNE_THROW(Dune::NotImplemented,
"No valid boundary condition type defined for pressure equation!");
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type GetProp
get the type of a property (equivalent to old macro GET_PROP(...))
Definition: propertysystem.hh:140
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:149
std::string viscosity(int phaseIdx) noexcept
I/O name of viscosity for multiphase systems.
Definition: name.hh:74
std::string permeability() noexcept
I/O name of permeability.
Definition: name.hh:143
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:65
Finite volume MPFA L-method discretization of a two-phase flow pressure equation of the sequential IM...
Definition: lmethod/2dpressure.hh:74
void update()
Pressure update.
Definition: lmethod/2dpressure.hh:290
void initialize()
Initializes the pressure model.
Definition: lmethod/2dpressure.hh:193
FVMPFALInteractionVolume< TypeTag > InteractionVolume
Type of the interaction volume objects.
Definition: lmethod/2dpressure.hh:150
void storePressureSolution()
Globally stores the pressure solution.
Definition: lmethod/2dpressure.hh:227
void addOutputVtkFields(MultiWriter &writer)
Adds pressure output to the output file.
Definition: lmethod/2dpressure.hh:339
void updateMaterialLaws()
constitutive functions are initialized and stored in the variables object
Definition: lmethod/2dpressure.hh:1834
Class for the calculation of velocities from the pressure solution of an IMPES scheme using a MPFA L-...
Definition: lmethod/2dpressurevelocity.hh:48
void updateVelocity()
Function for updating the velocity field if iterations are necessary in the transport solution.
Definition: lmethod/2dpressurevelocity.hh:122
void calculateVelocityOnBoundary(const Intersection &intersection, CellData &cellData)
Calculates the velocity at a boundary.
Definition: lmethod/2dpressurevelocity.hh:387
FvMpfaL2dPressureVelocity2p(Problem &problem)
Constructs a FvMpfaL2dPressureVelocity2p object.
Definition: lmethod/2dpressurevelocity.hh:103
void initialize()
Initializes pressure and velocity.
Definition: lmethod/2dpressurevelocity.hh:137
void addOutputVtkFields(MultiWriter &writer)
Adds velocity output to the output file.
Definition: lmethod/2dpressurevelocity.hh:192
bool calculateVelocityInTransport()
Indicates if velocity is reconstructed in the pressure step or in the transport step.
Definition: lmethod/2dpressurevelocity.hh:176
void calculateVelocity()
Calculates the velocities at all cell-cell interfaces.
Definition: lmethod/2dpressurevelocity.hh:220
void update()
Pressure and velocity update.
Definition: lmethod/2dpressurevelocity.hh:164
Class for calculating 2-d velocities from cell-wise constant pressure values.
Definition: lmethod/2dvelocity.hh:60
Class including the information of an interaction volume of a MPFA L-method that does not change with...
Definition: linteractionvolume.hh:41
bool isInnerVolume()
Returns true if the interaction volume is completely inside the model domain.
Definition: linteractionvolume.hh:316
Element getSubVolumeElement(int subVolumeIdx)
Get an element of the interaction volume.
Definition: linteractionvolume.hh:281
int getFaceIndexFromSubVolume(int subVolumeIdx, int subVolumeFaceIdx)
Map from local interaction volume numbering on element to numbering on interaction volume.
Definition: linteractionvolume.hh:270
bool isOutsideFace(int subVolumeFaceIdx)
Returns true if an interaction volume flux face is outside the model domain.
Definition: linteractionvolume.hh:301
The finite volume base class for the solution of a pressure equation.
Definition: sequential/cellcentered/pressure.hh:49
Finite volume MPFA O-method discretization of a two-phase pressure equation of the sequential IMPES m...
Velocity calculation using a 2-d MPFA O-method.