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
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,
71 numPhases = getPropValue<TypeTag, Properties::NumPhases>()
80 using PrimaryVariables =
typename SolutionTypes::PrimaryVariables;
84 using Intersection =
typename GridView::Intersection;
86 using Element =
typename GridView::template Codim<0>::Entity;
88 using GlobalPosition =
typename Element::Geometry::GlobalCoordinate;
89 using DimMatrix = Dune::FieldMatrix<Scalar, dim, dim>;
90 using DimVector = Dune::FieldVector<Scalar, dim>;
99 ParentType(problem), problem_(problem), velocity_(problem)
101 density_[wPhaseIdx] = 0.;
102 density_[nPhaseIdx] = 0.;
103 viscosity_[wPhaseIdx] = 0.;
104 viscosity_[nPhaseIdx] = 0.;
106 calcVelocityInTransport_ = getParam<bool>(
"MPFA.CalcVelocityInTransport");
133 const auto element = *problem_.gridView().template begin<0>();
134 FluidState fluidState;
135 fluidState.setPressure(wPhaseIdx, problem_.referencePressure(element));
136 fluidState.setPressure(nPhaseIdx, problem_.referencePressure(element));
137 fluidState.setTemperature(problem_.temperature(element));
138 fluidState.setSaturation(wPhaseIdx, 1.);
139 fluidState.setSaturation(nPhaseIdx, 0.);
146 velocity_.initialize();
174 return calcVelocityInTransport_;
187 template<
class MultiWriter>
191 velocity_.addOutputVtkFields(writer);
198 Scalar density_[numPhases];
199 Scalar viscosity_[numPhases];
200 bool calcVelocityInTransport_;
203 static const int pressureType_ = getPropValue<TypeTag, Properties::PressureFormulation>();
205 static const int saturationType_ = getPropValue<TypeTag, Properties::SaturationFormulation>();
214template<
class TypeTag>
218 for (
const auto& vertex : vertices(problem_.gridView()))
220 int vIdxGlobal = problem_.variables().index(vertex);
222 InteractionVolume& interactionVolume = this->interactionVolumes_.interactionVolume(vIdxGlobal);
225 if (interactionVolume.isInnerVolume())
229 for (
int i = 0; i < 8; i++)
231 eIdxGlobal[i] = problem_.variables().index(interactionVolume.getSubVolumeElement(i));
235 CellData & cellData1 = problem_.variables().cellData(eIdxGlobal[0]);
236 CellData & cellData2 = problem_.variables().cellData(eIdxGlobal[1]);
237 CellData & cellData3 = problem_.variables().cellData(eIdxGlobal[2]);
238 CellData & cellData4 = problem_.variables().cellData(eIdxGlobal[3]);
239 CellData & cellData5 = problem_.variables().cellData(eIdxGlobal[4]);
240 CellData & cellData6 = problem_.variables().cellData(eIdxGlobal[5]);
241 CellData & cellData7 = problem_.variables().cellData(eIdxGlobal[6]);
242 CellData & cellData8 = problem_.variables().cellData(eIdxGlobal[7]);
244 if (!interactionVolume.isHangingNodeVolume())
246 velocity_.calculateInnerInteractionVolumeVelocity(interactionVolume,
247 cellData1, cellData2, cellData3, cellData4,
248 cellData5, cellData6, cellData7, cellData8,
249 this->interactionVolumes_, this->transmissibilityCalculator_);
253 velocity_.calculateHangingNodeInteractionVolumeVelocity(interactionVolume,
254 cellData1, cellData2, cellData3, cellData4,
255 cellData5, cellData6, cellData7, cellData8);
261 for (
int elemIdx = 0; elemIdx < 8; elemIdx++)
263 if (!interactionVolume.hasSubVolumeElement(elemIdx))
267 bool isOutside =
false;
268 for (
int fIdx = 0; fIdx < dim; fIdx++)
270 int intVolFaceIdx = interactionVolume.getFaceIndexFromSubVolume(elemIdx, fIdx);
271 if (interactionVolume.isOutsideFace(intVolFaceIdx))
283 int eIdxGlobal = problem_.variables().index(interactionVolume.getSubVolumeElement(elemIdx));
285 CellData& cellData = problem_.variables().cellData(eIdxGlobal);
287 velocity_.calculateBoundaryInteractionVolumeVelocity(interactionVolume, cellData, elemIdx);
304template<
class TypeTag>
307 auto elementI = intersection.inside();
308 auto elementJ = intersection.outside();
310 int levelI = elementI.level();
311 int levelJ = elementJ.level();
313 int eIdxGlobalI = problem_.variables().index(elementI);
314 int eIdxGlobalJ = problem_.variables().index(elementJ);
316 CellData& cellDataJ = problem_.variables().cellData(eIdxGlobalJ);
318 int indexInInside = intersection.indexInInside();
319 int indexInOutside = intersection.indexInOutside();
321 Dune::FieldVector<CellData, 8> cellDataTemp;
323 if (levelI != levelJ)
326 cellData.fluxData().setVelocity(wPhaseIdx, indexInInside, vel);
327 cellData.fluxData().setVelocity(nPhaseIdx, indexInInside, vel);
328 cellData.fluxData().setUpwindPotential(wPhaseIdx, indexInInside, 0);
329 cellData.fluxData().setUpwindPotential(nPhaseIdx, indexInInside, 0);
331 cellDataJ.fluxData().setVelocity(wPhaseIdx, indexInOutside, vel);
332 cellDataJ.fluxData().setVelocity(nPhaseIdx, indexInOutside, vel);
333 cellDataJ.fluxData().setUpwindPotential(wPhaseIdx, indexInOutside, 0);
334 cellDataJ.fluxData().setUpwindPotential(nPhaseIdx, indexInOutside, 0);
337 std::set<int> vIdxGlobal;
339 if (levelI >= levelJ)
341 vIdxGlobal = this->interactionVolumes_.faceVerticeIndices(eIdxGlobalI, indexInInside);
345 vIdxGlobal = this->interactionVolumes_.faceVerticeIndices(eIdxGlobalJ, indexInOutside);
348 std::set<int>::iterator itEnd = vIdxGlobal.end();
350 for (std::set<int>::iterator vIdxIt = vIdxGlobal.begin(); vIdxIt != itEnd; ++vIdxIt)
352 InteractionVolume& interactionVolume = this->interactionVolumes_.interactionVolume(*vIdxIt);
354 if (interactionVolume.isInnerVolume())
357 std::vector<std::pair<int,int> > localMpfaElemIdx(0);
360 for (
int i = 0; i < 8; i++)
362 auto elem = interactionVolume.getSubVolumeElement(i);
364 if (interactionVolume.isHangingNodeVolume())
366 if (elem == elementI)
368 for (
int j = 0; j < 3; j++)
370 for (
int k = 0; k < 8; k++)
372 if (interactionVolume.getSubVolumeElement(k) == elementJ &&
373 IndexTranslator::getFaceIndexFromSubVolume(i,j)
374 == IndexTranslator::getFaceIndexFromElements(i,k))
376 std::pair<int,int> localIdx = std::make_pair(i, k);
377 localMpfaElemIdx.push_back(localIdx);
385 if (localMpfaElemIdx.size() != 1)
386 localMpfaElemIdx.resize(1);
388 if (elem == elementI)
389 localMpfaElemIdx[0].first = i;
390 else if (elem == elementJ)
391 localMpfaElemIdx[0].second = i;
394 eIdxGlobal[i] = problem_.variables().index(elem);
395 cellDataTemp[i] = problem_.variables().cellData(eIdxGlobal[i]);
398 int size = localMpfaElemIdx.size();
403 for (
int i = 0; i < size; i++)
405 int mpfaFaceIdx = IndexTranslator::getFaceIndexFromElements(localMpfaElemIdx[i].first, localMpfaElemIdx[i].second);
407 if (!interactionVolume.isHangingNodeVolume())
409 velocity_.calculateInnerInteractionVolumeVelocity(interactionVolume,
410 cellDataTemp[0], cellDataTemp[1], cellDataTemp[2], cellDataTemp[3],
411 cellDataTemp[4], cellDataTemp[5], cellDataTemp[6], cellDataTemp[7],
412 this->interactionVolumes_, this->transmissibilityCalculator_, mpfaFaceIdx);
416 velocity_.calculateHangingNodeInteractionVolumeVelocity(interactionVolume,
417 cellDataTemp[0], cellDataTemp[1], cellDataTemp[2], cellDataTemp[3],
418 cellDataTemp[4], cellDataTemp[5], cellDataTemp[6], cellDataTemp[7], mpfaFaceIdx);
421 if (levelI >= levelJ)
423 cellData.fluxData().setVelocity(wPhaseIdx, indexInInside,
424 cellDataTemp[localMpfaElemIdx[i].first].fluxData().velocity(wPhaseIdx, indexInInside));
425 cellData.fluxData().setVelocity(nPhaseIdx, indexInInside,
426 cellDataTemp[localMpfaElemIdx[i].first].fluxData().velocity(nPhaseIdx, indexInInside));
427 cellData.fluxData().setUpwindPotential(wPhaseIdx, indexInInside,
428 cellDataTemp[localMpfaElemIdx[i].first].fluxData().upwindPotential(wPhaseIdx, indexInInside));
429 cellData.fluxData().setUpwindPotential(nPhaseIdx, indexInInside,
430 cellDataTemp[localMpfaElemIdx[i].first].fluxData().upwindPotential(nPhaseIdx, indexInInside));
432 if (levelJ >= levelI)
434 cellDataJ.fluxData().setVelocity(wPhaseIdx, indexInOutside,
435 cellDataTemp[localMpfaElemIdx[i].second].fluxData().velocity(wPhaseIdx, indexInOutside));
436 cellDataJ.fluxData().setVelocity(nPhaseIdx, indexInOutside,
437 cellDataTemp[localMpfaElemIdx[i].second].fluxData().velocity(nPhaseIdx, indexInOutside));
438 cellDataJ.fluxData().setUpwindPotential(wPhaseIdx, indexInOutside,
439 cellDataTemp[localMpfaElemIdx[i].second].fluxData().upwindPotential(wPhaseIdx, indexInOutside));
440 cellDataJ.fluxData().setUpwindPotential(nPhaseIdx, indexInOutside,
441 cellDataTemp[localMpfaElemIdx[i].second].fluxData().upwindPotential(nPhaseIdx, indexInOutside));
446 for (
int j = 0; j < 8; j++)
448 cellDataTemp[j] = problem_.variables().cellData(eIdxGlobal[j]);
455 if (levelI == levelJ)
457 cellData.fluxData().setVelocityMarker(indexInInside);
458 cellDataJ.fluxData().setVelocityMarker(indexInOutside);
460 else if (levelI > levelJ)
462 cellDataJ.fluxData().setVelocity(wPhaseIdx, indexInOutside, cellData.fluxData().velocity(wPhaseIdx, indexInInside));
463 cellDataJ.fluxData().setVelocity(nPhaseIdx, indexInOutside, cellData.fluxData().velocity(nPhaseIdx, indexInInside));
464 cellDataJ.fluxData().setUpwindPotential(wPhaseIdx, indexInOutside, -1*cellData.fluxData().upwindPotential(wPhaseIdx, indexInInside));
465 cellDataJ.fluxData().setUpwindPotential(nPhaseIdx, indexInOutside, -1*cellData.fluxData().upwindPotential(nPhaseIdx, indexInInside));
467 else if (levelJ > levelI)
469 cellData.fluxData().setVelocity(wPhaseIdx, indexInInside, cellDataJ.fluxData().velocity(wPhaseIdx, indexInOutside));
470 cellData.fluxData().setVelocity(nPhaseIdx, indexInInside, cellDataJ.fluxData().velocity(nPhaseIdx, indexInOutside));
471 cellData.fluxData().setUpwindPotential(wPhaseIdx, indexInInside, -1*cellDataJ.fluxData().upwindPotential(wPhaseIdx, indexInOutside));
472 cellData.fluxData().setUpwindPotential(nPhaseIdx, indexInInside, -1*cellDataJ.fluxData().upwindPotential(nPhaseIdx, indexInOutside));
484template<
class TypeTag>
487 auto element = intersection.inside();
490 int isIndex = intersection.indexInInside();
493 const Dune::FieldVector<Scalar, dim>& unitOuterNormal = intersection.centerUnitOuterNormal();
495 BoundaryTypes bcType;
497 problem_.boundaryTypes(bcType, intersection);
498 PrimaryVariables boundValues(0.0);
500 if (bcType.isDirichlet(pressEqIdx))
502 problem_.dirichlet(boundValues, intersection);
505 const GlobalPosition& globalPosI = element.geometry().center();
508 const GlobalPosition& globalPosJ = intersection.geometry().center();
511 Scalar lambdaWI = cellData.mobility(wPhaseIdx);
512 Scalar lambdaNwI = cellData.mobility(nPhaseIdx);
515 Scalar pcI = cellData.capillaryPressure();
518 GlobalPosition distVec = globalPosJ - globalPosI;
521 Scalar dist = distVec.two_norm();
525 DimMatrix meanPermeability(0);
527 problem_.spatialParams().meanK(meanPermeability, problem_.spatialParams().intrinsicPermeability(element));
534 if (bcType.isDirichlet(satEqIdx))
536 switch (saturationType_)
540 satW = boundValues[saturationIdx];
545 satW = 1 - boundValues[saturationIdx];
552 satW = cellData.saturation(wPhaseIdx);
555 const Scalar pressBound = boundValues[pressureIdx];
557 const auto fluidMatrixInteraction = problem_.spatialParams().fluidMatrixInteractionAtPos(element.geometry().center());
558 const Scalar pcBound = fluidMatrixInteraction.pc(satW);
561 Scalar pressWBound = 0;
562 Scalar pressNwBound = 0;
563 if (pressureType_ == pw)
565 pressWBound = pressBound;
566 pressNwBound = pressBound + pcBound;
568 else if (pressureType_ == pn)
570 pressWBound = pressBound - pcBound;
571 pressNwBound = pressBound;
574 const Scalar lambdaWBound = fluidMatrixInteraction.krw(satW) / viscosity_[wPhaseIdx];
575 const Scalar lambdaNwBound = fluidMatrixInteraction.krn(satW) / viscosity_[nPhaseIdx];
577 Scalar potentialDiffW = cellData.fluxData().upwindPotential(wPhaseIdx, isIndex);
578 Scalar potentialDiffNw = cellData.fluxData().upwindPotential(nPhaseIdx, isIndex);
581 potentialDiffW = (cellData.pressure(wPhaseIdx) - pressWBound);
582 potentialDiffNw = (cellData.pressure(nPhaseIdx) - pressNwBound);
584 potentialDiffW += density_[wPhaseIdx] * (distVec * problem_.gravity());
585 potentialDiffNw += density_[nPhaseIdx] * (distVec * problem_.gravity());
588 cellData.fluxData().setUpwindPotential(wPhaseIdx, isIndex, potentialDiffW);
589 cellData.fluxData().setUpwindPotential(nPhaseIdx, isIndex, potentialDiffNw);
592 Scalar lambdaW = (potentialDiffW > 0.) ? lambdaWI : lambdaWBound;
593 lambdaW = (Dune::FloatCmp::eq<Scalar, Dune::FloatCmp::absolute>(potentialDiffW, 0.0, 1.0e-30)) ? 0.5 * (lambdaWI + lambdaWBound) : lambdaW;
594 Scalar lambdaNw = (potentialDiffNw > 0.) ? lambdaNwI : lambdaNwBound;
595 lambdaNw = (Dune::FloatCmp::eq<Scalar, Dune::FloatCmp::absolute>(potentialDiffNw, 0.0, 1.0e-30)) ? 0.5 * (lambdaNwI + lambdaNwBound) : lambdaNw;
601 Dune::FieldVector<Scalar, dimWorld> velocityW(unitOuterNormal);
602 Dune::FieldVector<Scalar, dimWorld> velocityNw(unitOuterNormal);
606 Scalar areaScaling = (unitOuterNormal * distVec);
608 Scalar gravityTermW = (problem_.gravity() * distVec) * density_[wPhaseIdx] * areaScaling;
609 Scalar gravityTermNw = (problem_.gravity() * distVec) * density_[nPhaseIdx] * areaScaling;
612 switch (pressureType_)
616 velocityW *= lambdaW * scalarPerm * ((cellData.pressure(wPhaseIdx) - pressBound) / dist + gravityTermW);
617 velocityNw *= lambdaNw * scalarPerm * ((cellData.pressure(wPhaseIdx) - pressBound) / dist + gravityTermNw)
618 + 0.5 * (lambdaNwI + lambdaNwBound) * scalarPerm * (pcI - pcBound) / dist;
623 velocityW *= lambdaW * scalarPerm * ((cellData.pressure(nPhaseIdx) - pressBound) / dist + gravityTermW)
624 - 0.5 * (lambdaWI + lambdaWBound) * scalarPerm * (pcI - pcBound) / dist;
625 velocityNw *= lambdaNw * scalarPerm * ((cellData.pressure(nPhaseIdx) - pressBound) / dist + gravityTermNw);
631 cellData.fluxData().setVelocity(wPhaseIdx, isIndex, velocityW);
632 cellData.fluxData().setVelocity(nPhaseIdx, isIndex, velocityNw);
633 cellData.fluxData().setVelocityMarker(isIndex);
637 else if (bcType.isNeumann(pressEqIdx))
639 problem_.neumann(boundValues, intersection);
641 Dune::FieldVector<Scalar, dimWorld> velocityW(unitOuterNormal);
642 Dune::FieldVector<Scalar, dimWorld> velocityNw(unitOuterNormal);
644 velocityW *= boundValues[wPhaseIdx];
645 velocityNw *= boundValues[nPhaseIdx];
647 velocityW /= density_[wPhaseIdx];
648 velocityNw /= density_[nPhaseIdx];
651 cellData.fluxData().setUpwindPotential(wPhaseIdx, isIndex, boundValues[wPhaseIdx]);
652 cellData.fluxData().setUpwindPotential(nPhaseIdx, isIndex, boundValues[nPhaseIdx]);
654 cellData.fluxData().setVelocity(wPhaseIdx, isIndex, velocityW);
655 cellData.fluxData().setVelocity(nPhaseIdx, isIndex, velocityNw);
656 cellData.fluxData().setVelocityMarker(isIndex);
660 DUNE_THROW(Dune::NotImplemented,
"No valid boundary condition type defined for pressure equation!");
3-d velocity calculation on adaptive grids using a 3-d MPFA L-method.
3-d finite Volume-MPFAL implementation of a two-phase pressure equation on h-adaptive grids
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type GetProp
get the type of a property
Definition: propertysystem.hh:141
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:150
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
GetPropType< TypeTag, Properties::MPFAInteractionVolume > InteractionVolume
Type for storing interaction volume information.
Definition: 3dpressure.hh:154
void storePressureSolution()
Globally stores the pressure solution.
Definition: 3dpressure.hh:205
void addOutputVtkFields(MultiWriter &writer)
Adds pressure output to the output file.
Definition: 3dpressure.hh:384
void updateMaterialLaws()
constitutive functions are initialized and stored in the variables object
Definition: 3dpressure.hh:2478
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:194
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:215
FvMpfaL3dPressureVelocity2pAdaptive(Problem &problem)
Constructs a FvMpfaL3dPressureVelocity2pAdaptive object.
Definition: 3dpressurevelocityadaptive.hh:98
void updateVelocity()
Function for updating the velocity field if iterations are necessary in the transport solution.
Definition: 3dpressurevelocityadaptive.hh:116
void calculateVelocityOnBoundary(const Intersection &intersection, CellData &cellData)
Calculates the velocity at a boundary.
Definition: 3dpressurevelocityadaptive.hh:485
bool calculateVelocityInTransport()
Indicates if velocity is reconstructed in the pressure step or in the transport step.
Definition: 3dpressurevelocityadaptive.hh:172
void initialize(bool solveTwice=true)
Initializes pressure and velocity.
Definition: 3dpressurevelocityadaptive.hh:131
void addOutputVtkFields(MultiWriter &writer)
Adds velocity output to the output file.
Definition: 3dpressurevelocityadaptive.hh:188
void update()
Pressure and velocity update.
Definition: 3dpressurevelocityadaptive.hh:159
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:49
void initialize()
Initialize pressure model.
Definition: sequential/cellcentered/pressure.hh:213