23#ifndef DUMUX_FVMPFALPRESSUREVELOCITY2P_ADAPTIVE_HH
24#define DUMUX_FVMPFALPRESSUREVELOCITY2P_ADAPTIVE_HH
26#include <dune/common/float_cmp.hh>
54 dim = GridView::dimension, dimWorld = GridView::dimensionworld
57 using Indices =
typename GET_PROP_TYPE(TypeTag, ModelTraits)::Indices;
61 pw = Indices::pressureW,
62 pn = Indices::pressureNw,
63 sw = Indices::saturationW,
64 sn = Indices::saturationNw,
65 wPhaseIdx = Indices::wPhaseIdx,
66 nPhaseIdx = Indices::nPhaseIdx,
67 pressureIdx = Indices::pressureIdx,
68 saturationIdx = Indices::saturationIdx,
69 pressEqIdx = Indices::pressureEqIdx,
70 satEqIdx = Indices::satEqIdx,
75 using FluidSystem =
typename GET_PROP_TYPE(TypeTag, FluidSystem);
76 using FluidState =
typename GET_PROP_TYPE(TypeTag, FluidState);
78 using BoundaryTypes =
typename GET_PROP_TYPE(TypeTag, BoundaryTypes);
79 using SolutionTypes =
typename GET_PROP(TypeTag, SolutionTypes);
80 using PrimaryVariables =
typename SolutionTypes::PrimaryVariables;
81 using SpatialParams =
typename GET_PROP_TYPE(TypeTag, SpatialParams);
82 using MaterialLaw =
typename SpatialParams::MaterialLaw;
85 using Intersection =
typename GridView::Intersection;
87 using Element =
typename GridView::template Codim<0>::Entity;
89 using GlobalPosition =
typename Element::Geometry::GlobalCoordinate;
90 using DimMatrix = Dune::FieldMatrix<Scalar, dim, dim>;
91 using DimVector = Dune::FieldVector<Scalar, dim>;
100 ParentType(problem), problem_(problem), velocity_(problem)
102 density_[wPhaseIdx] = 0.;
103 density_[nPhaseIdx] = 0.;
104 viscosity_[wPhaseIdx] = 0.;
105 viscosity_[nPhaseIdx] = 0.;
107 calcVelocityInTransport_ = getParam<bool>(
"MPFA.CalcVelocityInTransport");
134 const auto element = *problem_.gridView().template begin<0>();
135 FluidState fluidState;
136 fluidState.setPressure(wPhaseIdx, problem_.referencePressure(element));
137 fluidState.setPressure(nPhaseIdx, problem_.referencePressure(element));
138 fluidState.setTemperature(problem_.temperature(element));
139 fluidState.setSaturation(wPhaseIdx, 1.);
140 fluidState.setSaturation(nPhaseIdx, 0.);
147 velocity_.initialize();
175 return calcVelocityInTransport_;
188 template<
class MultiWriter>
192 velocity_.addOutputVtkFields(writer);
199 Scalar density_[numPhases];
200 Scalar viscosity_[numPhases];
201 bool calcVelocityInTransport_;
204 static const int pressureType_ =
GET_PROP_VALUE(TypeTag, PressureFormulation);
215template<
class TypeTag>
219 for (
const auto& vertex : vertices(problem_.gridView()))
221 int vIdxGlobal = problem_.variables().index(vertex);
223 InteractionVolume& interactionVolume = this->interactionVolumes_.interactionVolume(vIdxGlobal);
226 if (interactionVolume.isInnerVolume())
230 for (
int i = 0; i < 8; i++)
232 eIdxGlobal[i] = problem_.variables().index(interactionVolume.getSubVolumeElement(i));
236 CellData & cellData1 = problem_.variables().cellData(eIdxGlobal[0]);
237 CellData & cellData2 = problem_.variables().cellData(eIdxGlobal[1]);
238 CellData & cellData3 = problem_.variables().cellData(eIdxGlobal[2]);
239 CellData & cellData4 = problem_.variables().cellData(eIdxGlobal[3]);
240 CellData & cellData5 = problem_.variables().cellData(eIdxGlobal[4]);
241 CellData & cellData6 = problem_.variables().cellData(eIdxGlobal[5]);
242 CellData & cellData7 = problem_.variables().cellData(eIdxGlobal[6]);
243 CellData & cellData8 = problem_.variables().cellData(eIdxGlobal[7]);
245 if (!interactionVolume.isHangingNodeVolume())
247 velocity_.calculateInnerInteractionVolumeVelocity(interactionVolume,
248 cellData1, cellData2, cellData3, cellData4,
249 cellData5, cellData6, cellData7, cellData8,
250 this->interactionVolumes_, this->transmissibilityCalculator_);
254 velocity_.calculateHangingNodeInteractionVolumeVelocity(interactionVolume,
255 cellData1, cellData2, cellData3, cellData4,
256 cellData5, cellData6, cellData7, cellData8);
262 for (
int elemIdx = 0; elemIdx < 8; elemIdx++)
264 if (!interactionVolume.hasSubVolumeElement(elemIdx))
268 bool isOutside =
false;
269 for (
int fIdx = 0; fIdx < dim; fIdx++)
271 int intVolFaceIdx = interactionVolume.getFaceIndexFromSubVolume(elemIdx, fIdx);
272 if (interactionVolume.isOutsideFace(intVolFaceIdx))
284 int eIdxGlobal = problem_.variables().index(interactionVolume.getSubVolumeElement(elemIdx));
286 CellData& cellData = problem_.variables().cellData(eIdxGlobal);
288 velocity_.calculateBoundaryInteractionVolumeVelocity(interactionVolume, cellData, elemIdx);
305template<
class TypeTag>
308 auto elementI = intersection.inside();
309 auto elementJ = intersection.outside();
311 int levelI = elementI.level();
312 int levelJ = elementJ.level();
314 int eIdxGlobalI = problem_.variables().index(elementI);
315 int eIdxGlobalJ = problem_.variables().index(elementJ);
317 CellData& cellDataJ = problem_.variables().cellData(eIdxGlobalJ);
319 int indexInInside = intersection.indexInInside();
320 int indexInOutside = intersection.indexInOutside();
322 Dune::FieldVector<CellData, 8> cellDataTemp;
324 if (levelI != levelJ)
327 cellData.fluxData().setVelocity(wPhaseIdx, indexInInside, vel);
328 cellData.fluxData().setVelocity(nPhaseIdx, indexInInside, vel);
329 cellData.fluxData().setUpwindPotential(wPhaseIdx, indexInInside, 0);
330 cellData.fluxData().setUpwindPotential(nPhaseIdx, indexInInside, 0);
332 cellDataJ.fluxData().setVelocity(wPhaseIdx, indexInOutside, vel);
333 cellDataJ.fluxData().setVelocity(nPhaseIdx, indexInOutside, vel);
334 cellDataJ.fluxData().setUpwindPotential(wPhaseIdx, indexInOutside, 0);
335 cellDataJ.fluxData().setUpwindPotential(nPhaseIdx, indexInOutside, 0);
338 std::set<int> vIdxGlobal;
340 if (levelI >= levelJ)
342 vIdxGlobal = this->interactionVolumes_.faceVerticeIndices(eIdxGlobalI, indexInInside);
346 vIdxGlobal = this->interactionVolumes_.faceVerticeIndices(eIdxGlobalJ, indexInOutside);
349 std::set<int>::iterator itEnd = vIdxGlobal.end();
351 for (std::set<int>::iterator vIdxIt = vIdxGlobal.begin(); vIdxIt != itEnd; ++vIdxIt)
353 InteractionVolume& interactionVolume = this->interactionVolumes_.interactionVolume(*vIdxIt);
355 if (interactionVolume.isInnerVolume())
358 std::vector<std::pair<int,int> > localMpfaElemIdx(0);
361 for (
int i = 0; i < 8; i++)
363 auto elem = interactionVolume.getSubVolumeElement(i);
365 if (interactionVolume.isHangingNodeVolume())
367 if (elem == elementI)
369 for (
int j = 0; j < 3; j++)
371 for (
int k = 0; k < 8; k++)
373 if (interactionVolume.getSubVolumeElement(k) == elementJ &&
374 IndexTranslator::getFaceIndexFromSubVolume(i,j)
375 == IndexTranslator::getFaceIndexFromElements(i,k))
377 std::pair<int,int> localIdx = std::make_pair(i, k);
378 localMpfaElemIdx.push_back(localIdx);
386 if (localMpfaElemIdx.size() != 1)
387 localMpfaElemIdx.resize(1);
389 if (elem == elementI)
390 localMpfaElemIdx[0].first = i;
391 else if (elem == elementJ)
392 localMpfaElemIdx[0].second = i;
395 eIdxGlobal[i] = problem_.variables().index(elem);
396 cellDataTemp[i] = problem_.variables().cellData(eIdxGlobal[i]);
399 int size = localMpfaElemIdx.size();
404 for (
int i = 0; i < size; i++)
406 int mpfaFaceIdx = IndexTranslator::getFaceIndexFromElements(localMpfaElemIdx[i].first, localMpfaElemIdx[i].second);
408 if (!interactionVolume.isHangingNodeVolume())
410 velocity_.calculateInnerInteractionVolumeVelocity(interactionVolume,
411 cellDataTemp[0], cellDataTemp[1], cellDataTemp[2], cellDataTemp[3],
412 cellDataTemp[4], cellDataTemp[5], cellDataTemp[6], cellDataTemp[7],
413 this->interactionVolumes_, this->transmissibilityCalculator_, mpfaFaceIdx);
417 velocity_.calculateHangingNodeInteractionVolumeVelocity(interactionVolume,
418 cellDataTemp[0], cellDataTemp[1], cellDataTemp[2], cellDataTemp[3],
419 cellDataTemp[4], cellDataTemp[5], cellDataTemp[6], cellDataTemp[7], mpfaFaceIdx);
422 if (levelI >= levelJ)
424 cellData.fluxData().setVelocity(wPhaseIdx, indexInInside,
425 cellDataTemp[localMpfaElemIdx[i].first].fluxData().velocity(wPhaseIdx, indexInInside));
426 cellData.fluxData().setVelocity(nPhaseIdx, indexInInside,
427 cellDataTemp[localMpfaElemIdx[i].first].fluxData().velocity(nPhaseIdx, indexInInside));
428 cellData.fluxData().setUpwindPotential(wPhaseIdx, indexInInside,
429 cellDataTemp[localMpfaElemIdx[i].first].fluxData().upwindPotential(wPhaseIdx, indexInInside));
430 cellData.fluxData().setUpwindPotential(nPhaseIdx, indexInInside,
431 cellDataTemp[localMpfaElemIdx[i].first].fluxData().upwindPotential(nPhaseIdx, indexInInside));
433 if (levelJ >= levelI)
435 cellDataJ.fluxData().setVelocity(wPhaseIdx, indexInOutside,
436 cellDataTemp[localMpfaElemIdx[i].second].fluxData().velocity(wPhaseIdx, indexInOutside));
437 cellDataJ.fluxData().setVelocity(nPhaseIdx, indexInOutside,
438 cellDataTemp[localMpfaElemIdx[i].second].fluxData().velocity(nPhaseIdx, indexInOutside));
439 cellDataJ.fluxData().setUpwindPotential(wPhaseIdx, indexInOutside,
440 cellDataTemp[localMpfaElemIdx[i].second].fluxData().upwindPotential(wPhaseIdx, indexInOutside));
441 cellDataJ.fluxData().setUpwindPotential(nPhaseIdx, indexInOutside,
442 cellDataTemp[localMpfaElemIdx[i].second].fluxData().upwindPotential(nPhaseIdx, indexInOutside));
447 for (
int j = 0; j < 8; j++)
449 cellDataTemp[j] = problem_.variables().cellData(eIdxGlobal[j]);
456 if (levelI == levelJ)
458 cellData.fluxData().setVelocityMarker(indexInInside);
459 cellDataJ.fluxData().setVelocityMarker(indexInOutside);
461 else if (levelI > levelJ)
463 cellDataJ.fluxData().setVelocity(wPhaseIdx, indexInOutside, cellData.fluxData().velocity(wPhaseIdx, indexInInside));
464 cellDataJ.fluxData().setVelocity(nPhaseIdx, indexInOutside, cellData.fluxData().velocity(nPhaseIdx, indexInInside));
465 cellDataJ.fluxData().setUpwindPotential(wPhaseIdx, indexInOutside, -1*cellData.fluxData().upwindPotential(wPhaseIdx, indexInInside));
466 cellDataJ.fluxData().setUpwindPotential(nPhaseIdx, indexInOutside, -1*cellData.fluxData().upwindPotential(nPhaseIdx, indexInInside));
468 else if (levelJ > levelI)
470 cellData.fluxData().setVelocity(wPhaseIdx, indexInInside, cellDataJ.fluxData().velocity(wPhaseIdx, indexInOutside));
471 cellData.fluxData().setVelocity(nPhaseIdx, indexInInside, cellDataJ.fluxData().velocity(nPhaseIdx, indexInOutside));
472 cellData.fluxData().setUpwindPotential(wPhaseIdx, indexInInside, -1*cellDataJ.fluxData().upwindPotential(wPhaseIdx, indexInOutside));
473 cellData.fluxData().setUpwindPotential(nPhaseIdx, indexInInside, -1*cellDataJ.fluxData().upwindPotential(nPhaseIdx, indexInOutside));
485template<
class TypeTag>
488 auto element = intersection.inside();
491 int isIndex = intersection.indexInInside();
494 const Dune::FieldVector<Scalar, dim>& unitOuterNormal = intersection.centerUnitOuterNormal();
496 BoundaryTypes bcType;
498 problem_.boundaryTypes(bcType, intersection);
499 PrimaryVariables boundValues(0.0);
501 if (bcType.isDirichlet(pressEqIdx))
503 problem_.dirichlet(boundValues, intersection);
506 const GlobalPosition& globalPosI = element.geometry().center();
509 const GlobalPosition& globalPosJ = intersection.geometry().center();
512 Scalar lambdaWI = cellData.mobility(wPhaseIdx);
513 Scalar lambdaNwI = cellData.mobility(nPhaseIdx);
516 Scalar pcI = cellData.capillaryPressure();
519 GlobalPosition distVec = globalPosJ - globalPosI;
522 Scalar dist = distVec.two_norm();
526 DimMatrix meanPermeability(0);
528 problem_.spatialParams().meanK(meanPermeability, problem_.spatialParams().intrinsicPermeability(element));
535 if (bcType.isDirichlet(satEqIdx))
537 switch (saturationType_)
541 satW = boundValues[saturationIdx];
546 satW = 1 - boundValues[saturationIdx];
553 satW = cellData.saturation(wPhaseIdx);
556 Scalar pressBound = boundValues[pressureIdx];
557 Scalar pcBound = MaterialLaw::pc(problem_.spatialParams().materialLawParams(element), satW);
560 Scalar pressWBound = 0;
561 Scalar pressNwBound = 0;
562 if (pressureType_ == pw)
564 pressWBound = pressBound;
565 pressNwBound = pressBound + pcBound;
567 else if (pressureType_ == pn)
569 pressWBound = pressBound - pcBound;
570 pressNwBound = pressBound;
573 Scalar lambdaWBound = MaterialLaw::krw(problem_.spatialParams().materialLawParams(element), satW)
574 / viscosity_[wPhaseIdx];
575 Scalar lambdaNwBound = MaterialLaw::krn(problem_.spatialParams().materialLawParams(element), satW)
576 / viscosity_[nPhaseIdx];
578 Scalar potentialDiffW = cellData.fluxData().upwindPotential(wPhaseIdx, isIndex);
579 Scalar potentialDiffNw = cellData.fluxData().upwindPotential(nPhaseIdx, isIndex);
582 potentialDiffW = (cellData.pressure(wPhaseIdx) - pressWBound);
583 potentialDiffNw = (cellData.pressure(nPhaseIdx) - pressNwBound);
585 potentialDiffW += density_[wPhaseIdx] * (distVec * problem_.gravity());
586 potentialDiffNw += density_[nPhaseIdx] * (distVec * problem_.gravity());
589 cellData.fluxData().setUpwindPotential(wPhaseIdx, isIndex, potentialDiffW);
590 cellData.fluxData().setUpwindPotential(nPhaseIdx, isIndex, potentialDiffNw);
593 Scalar lambdaW = (potentialDiffW > 0.) ? lambdaWI : lambdaWBound;
594 lambdaW = (Dune::FloatCmp::eq<Scalar, Dune::FloatCmp::absolute>(potentialDiffW, 0.0, 1.0e-30)) ? 0.5 * (lambdaWI + lambdaWBound) : lambdaW;
595 Scalar lambdaNw = (potentialDiffNw > 0.) ? lambdaNwI : lambdaNwBound;
596 lambdaNw = (Dune::FloatCmp::eq<Scalar, Dune::FloatCmp::absolute>(potentialDiffNw, 0.0, 1.0e-30)) ? 0.5 * (lambdaNwI + lambdaNwBound) : lambdaNw;
602 Dune::FieldVector<Scalar, dimWorld> velocityW(unitOuterNormal);
603 Dune::FieldVector<Scalar, dimWorld> velocityNw(unitOuterNormal);
607 Scalar areaScaling = (unitOuterNormal * distVec);
609 Scalar gravityTermW = (problem_.gravity() * distVec) * density_[wPhaseIdx] * areaScaling;
610 Scalar gravityTermNw = (problem_.gravity() * distVec) * density_[nPhaseIdx] * areaScaling;
613 switch (pressureType_)
617 velocityW *= lambdaW * scalarPerm * ((cellData.pressure(wPhaseIdx) - pressBound) / dist + gravityTermW);
618 velocityNw *= lambdaNw * scalarPerm * ((cellData.pressure(wPhaseIdx) - pressBound) / dist + gravityTermNw)
619 + 0.5 * (lambdaNwI + lambdaNwBound) * scalarPerm * (pcI - pcBound) / dist;
624 velocityW *= lambdaW * scalarPerm * ((cellData.pressure(nPhaseIdx) - pressBound) / dist + gravityTermW)
625 - 0.5 * (lambdaWI + lambdaWBound) * scalarPerm * (pcI - pcBound) / dist;
626 velocityNw *= lambdaNw * scalarPerm * ((cellData.pressure(nPhaseIdx) - pressBound) / dist + gravityTermNw);
632 cellData.fluxData().setVelocity(wPhaseIdx, isIndex, velocityW);
633 cellData.fluxData().setVelocity(nPhaseIdx, isIndex, velocityNw);
634 cellData.fluxData().setVelocityMarker(isIndex);
638 else if (bcType.isNeumann(pressEqIdx))
640 problem_.neumann(boundValues, intersection);
642 Dune::FieldVector<Scalar, dimWorld> velocityW(unitOuterNormal);
643 Dune::FieldVector<Scalar, dimWorld> velocityNw(unitOuterNormal);
645 velocityW *= boundValues[wPhaseIdx];
646 velocityNw *= boundValues[nPhaseIdx];
648 velocityW /= density_[wPhaseIdx];
649 velocityNw /= density_[nPhaseIdx];
652 cellData.fluxData().setUpwindPotential(wPhaseIdx, isIndex, boundValues[wPhaseIdx]);
653 cellData.fluxData().setUpwindPotential(nPhaseIdx, isIndex, boundValues[nPhaseIdx]);
655 cellData.fluxData().setVelocity(wPhaseIdx, isIndex, velocityW);
656 cellData.fluxData().setVelocity(nPhaseIdx, isIndex, velocityNw);
657 cellData.fluxData().setVelocityMarker(isIndex);
661 DUNE_THROW(Dune::NotImplemented,
"No valid boundary condition type defined for pressure equation!");
#define GET_PROP_VALUE(TypeTag, PropTagName)
Definition: propertysystemmacros.hh:282
#define GET_PROP(TypeTag, PropTagName)
Definition: propertysystemmacros.hh:281
#define GET_PROP_TYPE(TypeTag, PropTagName)
Definition: propertysystemmacros.hh:283
3-d finite Volume-MPFAL implementation of a two-phase pressure equation on h-adaptive grids
3-d velocity calculation on adaptive grids using a 3-d MPFA L-method.
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
Property tag SaturationFormulation
The formulation of the saturation model.
Definition: porousmediumflow/2p/sequential/properties.hh:53
Property tag NumPhases
Number of phases in the system.
Definition: porousmediumflow/sequential/properties.hh:69
Property tag MPFAInteractionVolume
Type of the data container for one interaction volume.
Definition: porousmediumflow/sequential/cellcentered/mpfa/properties.hh:96
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
void storePressureSolution()
Globally stores the pressure solution.
Definition: 3dpressure.hh:206
void addOutputVtkFields(MultiWriter &writer)
Adds pressure output to the output file.
Definition: 3dpressure.hh:385
typename GET_PROP_TYPE(TypeTag, MPFAInteractionVolume) InteractionVolume
Type for storing interaction volume information.
Definition: 3dpressure.hh:155
void updateMaterialLaws()
constitutive functions are initialized and stored in the variables object
Definition: 3dpressure.hh:2481
3-d finite volume MPFA L-method discretization of a two-phase flow pressure equation of the sequentia...
Definition: 3dpressureadaptive.hh:78
void update()
updates the pressure field (analog to update function in IMPET)
Definition: 3dpressureadaptive.hh:195
Class for the calculation of 3d velocities from the pressure solution of an IMPES scheme using a grid...
Definition: 3dpressurevelocityadaptive.hh:46
void calculateVelocity()
Calculates the velocities at a cell-cell interfaces for the entire simulation grid.
Definition: 3dpressurevelocityadaptive.hh:216
FvMpfaL3dPressureVelocity2pAdaptive(Problem &problem)
Constructs a FvMpfaL3dPressureVelocity2pAdaptive object.
Definition: 3dpressurevelocityadaptive.hh:99
void updateVelocity()
Function for updating the velocity field if iterations are necessary in the transport solution.
Definition: 3dpressurevelocityadaptive.hh:117
void calculateVelocityOnBoundary(const Intersection &intersection, CellData &cellData)
Calculates the velocity at a boundary.
Definition: 3dpressurevelocityadaptive.hh:486
bool calculateVelocityInTransport()
Indicates if velocity is reconstructed in the pressure step or in the transport step.
Definition: 3dpressurevelocityadaptive.hh:173
void initialize(bool solveTwice=true)
Initializes pressure and velocity.
Definition: 3dpressurevelocityadaptive.hh:132
void addOutputVtkFields(MultiWriter &writer)
Adds velocity output to the output file.
Definition: 3dpressurevelocityadaptive.hh:189
void update()
Pressure and velocity update.
Definition: 3dpressurevelocityadaptive.hh:160
Class for calculating 3-d velocities from cell-wise constant pressure values.
Definition: 3dvelocityadaptive.hh:54
The finite volume base class for the solution of a pressure equation.
Definition: sequential/cellcentered/pressure.hh:48
void initialize()
Initialize pressure model.
Definition: sequential/cellcentered/pressure.hh:212