23#ifndef DUMUX_FVMPFALPRESSUREVELOCITY2P_ADAPTIVE_HH
24#define DUMUX_FVMPFALPRESSUREVELOCITY2P_ADAPTIVE_HH
26#include <dune/common/float_cmp.hh>
56 dim = GridView::dimension, dimWorld = GridView::dimensionworld
63 pw = Indices::pressureW,
64 pn = Indices::pressureNw,
65 sw = Indices::saturationW,
66 sn = Indices::saturationNw,
67 wPhaseIdx = Indices::wPhaseIdx,
68 nPhaseIdx = Indices::nPhaseIdx,
69 pressureIdx = Indices::pressureIdx,
70 saturationIdx = Indices::saturationIdx,
71 pressEqIdx = Indices::pressureEqIdx,
72 satEqIdx = Indices::satEqIdx,
73 numPhases = getPropValue<TypeTag, Properties::NumPhases>()
82 using PrimaryVariables =
typename SolutionTypes::PrimaryVariables;
86 using Intersection =
typename GridView::Intersection;
88 using Element =
typename GridView::template Codim<0>::Entity;
90 using GlobalPosition =
typename Element::Geometry::GlobalCoordinate;
91 using DimMatrix = Dune::FieldMatrix<Scalar, dim, dim>;
92 using DimVector = Dune::FieldVector<Scalar, dim>;
101 ParentType(problem), problem_(problem), velocity_(problem)
103 density_[wPhaseIdx] = 0.;
104 density_[nPhaseIdx] = 0.;
105 viscosity_[wPhaseIdx] = 0.;
106 viscosity_[nPhaseIdx] = 0.;
108 calcVelocityInTransport_ = getParam<bool>(
"MPFA.CalcVelocityInTransport");
135 const auto element = *problem_.gridView().template begin<0>();
136 FluidState fluidState;
137 fluidState.setPressure(wPhaseIdx, problem_.referencePressure(element));
138 fluidState.setPressure(nPhaseIdx, problem_.referencePressure(element));
139 fluidState.setTemperature(problem_.temperature(element));
140 fluidState.setSaturation(wPhaseIdx, 1.);
141 fluidState.setSaturation(nPhaseIdx, 0.);
148 velocity_.initialize();
176 return calcVelocityInTransport_;
189 template<
class MultiWriter>
193 velocity_.addOutputVtkFields(writer);
200 Scalar density_[numPhases];
201 Scalar viscosity_[numPhases];
202 bool calcVelocityInTransport_;
205 static const int pressureType_ = getPropValue<TypeTag, Properties::PressureFormulation>();
207 static const int saturationType_ = getPropValue<TypeTag, Properties::SaturationFormulation>();
216template<
class TypeTag>
220 for (
const auto& vertex : vertices(problem_.gridView()))
222 int vIdxGlobal = problem_.variables().index(vertex);
224 InteractionVolume& interactionVolume = this->interactionVolumes_.interactionVolume(vIdxGlobal);
227 if (interactionVolume.isInnerVolume())
231 for (
int i = 0; i < 8; i++)
233 eIdxGlobal[i] = problem_.variables().index(interactionVolume.getSubVolumeElement(i));
237 CellData & cellData1 = problem_.variables().cellData(eIdxGlobal[0]);
238 CellData & cellData2 = problem_.variables().cellData(eIdxGlobal[1]);
239 CellData & cellData3 = problem_.variables().cellData(eIdxGlobal[2]);
240 CellData & cellData4 = problem_.variables().cellData(eIdxGlobal[3]);
241 CellData & cellData5 = problem_.variables().cellData(eIdxGlobal[4]);
242 CellData & cellData6 = problem_.variables().cellData(eIdxGlobal[5]);
243 CellData & cellData7 = problem_.variables().cellData(eIdxGlobal[6]);
244 CellData & cellData8 = problem_.variables().cellData(eIdxGlobal[7]);
246 if (!interactionVolume.isHangingNodeVolume())
248 velocity_.calculateInnerInteractionVolumeVelocity(interactionVolume,
249 cellData1, cellData2, cellData3, cellData4,
250 cellData5, cellData6, cellData7, cellData8,
251 this->interactionVolumes_, this->transmissibilityCalculator_);
255 velocity_.calculateHangingNodeInteractionVolumeVelocity(interactionVolume,
256 cellData1, cellData2, cellData3, cellData4,
257 cellData5, cellData6, cellData7, cellData8);
263 for (
int elemIdx = 0; elemIdx < 8; elemIdx++)
265 if (!interactionVolume.hasSubVolumeElement(elemIdx))
269 bool isOutside =
false;
270 for (
int fIdx = 0; fIdx < dim; fIdx++)
272 int intVolFaceIdx = interactionVolume.getFaceIndexFromSubVolume(elemIdx, fIdx);
273 if (interactionVolume.isOutsideFace(intVolFaceIdx))
285 int eIdxGlobal = problem_.variables().index(interactionVolume.getSubVolumeElement(elemIdx));
287 CellData& cellData = problem_.variables().cellData(eIdxGlobal);
289 velocity_.calculateBoundaryInteractionVolumeVelocity(interactionVolume, cellData, elemIdx);
306template<
class TypeTag>
309 auto elementI = intersection.inside();
310 auto elementJ = intersection.outside();
312 int levelI = elementI.level();
313 int levelJ = elementJ.level();
315 int eIdxGlobalI = problem_.variables().index(elementI);
316 int eIdxGlobalJ = problem_.variables().index(elementJ);
318 CellData& cellDataJ = problem_.variables().cellData(eIdxGlobalJ);
320 int indexInInside = intersection.indexInInside();
321 int indexInOutside = intersection.indexInOutside();
323 Dune::FieldVector<CellData, 8> cellDataTemp;
325 if (levelI != levelJ)
328 cellData.fluxData().setVelocity(wPhaseIdx, indexInInside, vel);
329 cellData.fluxData().setVelocity(nPhaseIdx, indexInInside, vel);
330 cellData.fluxData().setUpwindPotential(wPhaseIdx, indexInInside, 0);
331 cellData.fluxData().setUpwindPotential(nPhaseIdx, indexInInside, 0);
333 cellDataJ.fluxData().setVelocity(wPhaseIdx, indexInOutside, vel);
334 cellDataJ.fluxData().setVelocity(nPhaseIdx, indexInOutside, vel);
335 cellDataJ.fluxData().setUpwindPotential(wPhaseIdx, indexInOutside, 0);
336 cellDataJ.fluxData().setUpwindPotential(nPhaseIdx, indexInOutside, 0);
339 std::set<int> vIdxGlobal;
341 if (levelI >= levelJ)
343 vIdxGlobal = this->interactionVolumes_.faceVerticeIndices(eIdxGlobalI, indexInInside);
347 vIdxGlobal = this->interactionVolumes_.faceVerticeIndices(eIdxGlobalJ, indexInOutside);
350 std::set<int>::iterator itEnd = vIdxGlobal.end();
352 for (std::set<int>::iterator vIdxIt = vIdxGlobal.begin(); vIdxIt != itEnd; ++vIdxIt)
354 InteractionVolume& interactionVolume = this->interactionVolumes_.interactionVolume(*vIdxIt);
356 if (interactionVolume.isInnerVolume())
359 std::vector<std::pair<int,int> > localMpfaElemIdx(0);
362 for (
int i = 0; i < 8; i++)
364 auto elem = interactionVolume.getSubVolumeElement(i);
366 if (interactionVolume.isHangingNodeVolume())
368 if (elem == elementI)
370 for (
int j = 0; j < 3; j++)
372 for (
int k = 0; k < 8; k++)
374 if (interactionVolume.getSubVolumeElement(k) == elementJ &&
375 IndexTranslator::getFaceIndexFromSubVolume(i,j)
376 == IndexTranslator::getFaceIndexFromElements(i,k))
378 std::pair<int,int> localIdx = std::make_pair(i, k);
379 localMpfaElemIdx.push_back(localIdx);
387 if (localMpfaElemIdx.size() != 1)
388 localMpfaElemIdx.resize(1);
390 if (elem == elementI)
391 localMpfaElemIdx[0].first = i;
392 else if (elem == elementJ)
393 localMpfaElemIdx[0].second = i;
396 eIdxGlobal[i] = problem_.variables().index(elem);
397 cellDataTemp[i] = problem_.variables().cellData(eIdxGlobal[i]);
400 int size = localMpfaElemIdx.size();
405 for (
int i = 0; i < size; i++)
407 int mpfaFaceIdx = IndexTranslator::getFaceIndexFromElements(localMpfaElemIdx[i].first, localMpfaElemIdx[i].second);
409 if (!interactionVolume.isHangingNodeVolume())
411 velocity_.calculateInnerInteractionVolumeVelocity(interactionVolume,
412 cellDataTemp[0], cellDataTemp[1], cellDataTemp[2], cellDataTemp[3],
413 cellDataTemp[4], cellDataTemp[5], cellDataTemp[6], cellDataTemp[7],
414 this->interactionVolumes_, this->transmissibilityCalculator_, mpfaFaceIdx);
418 velocity_.calculateHangingNodeInteractionVolumeVelocity(interactionVolume,
419 cellDataTemp[0], cellDataTemp[1], cellDataTemp[2], cellDataTemp[3],
420 cellDataTemp[4], cellDataTemp[5], cellDataTemp[6], cellDataTemp[7], mpfaFaceIdx);
423 if (levelI >= levelJ)
425 cellData.fluxData().setVelocity(wPhaseIdx, indexInInside,
426 cellDataTemp[localMpfaElemIdx[i].first].fluxData().velocity(wPhaseIdx, indexInInside));
427 cellData.fluxData().setVelocity(nPhaseIdx, indexInInside,
428 cellDataTemp[localMpfaElemIdx[i].first].fluxData().velocity(nPhaseIdx, indexInInside));
429 cellData.fluxData().setUpwindPotential(wPhaseIdx, indexInInside,
430 cellDataTemp[localMpfaElemIdx[i].first].fluxData().upwindPotential(wPhaseIdx, indexInInside));
431 cellData.fluxData().setUpwindPotential(nPhaseIdx, indexInInside,
432 cellDataTemp[localMpfaElemIdx[i].first].fluxData().upwindPotential(nPhaseIdx, indexInInside));
434 if (levelJ >= levelI)
436 cellDataJ.fluxData().setVelocity(wPhaseIdx, indexInOutside,
437 cellDataTemp[localMpfaElemIdx[i].second].fluxData().velocity(wPhaseIdx, indexInOutside));
438 cellDataJ.fluxData().setVelocity(nPhaseIdx, indexInOutside,
439 cellDataTemp[localMpfaElemIdx[i].second].fluxData().velocity(nPhaseIdx, indexInOutside));
440 cellDataJ.fluxData().setUpwindPotential(wPhaseIdx, indexInOutside,
441 cellDataTemp[localMpfaElemIdx[i].second].fluxData().upwindPotential(wPhaseIdx, indexInOutside));
442 cellDataJ.fluxData().setUpwindPotential(nPhaseIdx, indexInOutside,
443 cellDataTemp[localMpfaElemIdx[i].second].fluxData().upwindPotential(nPhaseIdx, indexInOutside));
448 for (
int j = 0; j < 8; j++)
450 cellDataTemp[j] = problem_.variables().cellData(eIdxGlobal[j]);
457 if (levelI == levelJ)
459 cellData.fluxData().setVelocityMarker(indexInInside);
460 cellDataJ.fluxData().setVelocityMarker(indexInOutside);
462 else if (levelI > levelJ)
464 cellDataJ.fluxData().setVelocity(wPhaseIdx, indexInOutside, cellData.fluxData().velocity(wPhaseIdx, indexInInside));
465 cellDataJ.fluxData().setVelocity(nPhaseIdx, indexInOutside, cellData.fluxData().velocity(nPhaseIdx, indexInInside));
466 cellDataJ.fluxData().setUpwindPotential(wPhaseIdx, indexInOutside, -1*cellData.fluxData().upwindPotential(wPhaseIdx, indexInInside));
467 cellDataJ.fluxData().setUpwindPotential(nPhaseIdx, indexInOutside, -1*cellData.fluxData().upwindPotential(nPhaseIdx, indexInInside));
469 else if (levelJ > levelI)
471 cellData.fluxData().setVelocity(wPhaseIdx, indexInInside, cellDataJ.fluxData().velocity(wPhaseIdx, indexInOutside));
472 cellData.fluxData().setVelocity(nPhaseIdx, indexInInside, cellDataJ.fluxData().velocity(nPhaseIdx, indexInOutside));
473 cellData.fluxData().setUpwindPotential(wPhaseIdx, indexInInside, -1*cellDataJ.fluxData().upwindPotential(wPhaseIdx, indexInOutside));
474 cellData.fluxData().setUpwindPotential(nPhaseIdx, indexInInside, -1*cellDataJ.fluxData().upwindPotential(nPhaseIdx, indexInOutside));
486template<
class TypeTag>
489 auto element = intersection.inside();
492 int isIndex = intersection.indexInInside();
495 const Dune::FieldVector<Scalar, dim>& unitOuterNormal = intersection.centerUnitOuterNormal();
497 BoundaryTypes bcType;
499 problem_.boundaryTypes(bcType, intersection);
500 PrimaryVariables boundValues(0.0);
502 if (bcType.isDirichlet(pressEqIdx))
504 problem_.dirichlet(boundValues, intersection);
507 const GlobalPosition& globalPosI = element.geometry().center();
510 const GlobalPosition& globalPosJ = intersection.geometry().center();
513 Scalar lambdaWI = cellData.mobility(wPhaseIdx);
514 Scalar lambdaNwI = cellData.mobility(nPhaseIdx);
517 Scalar pcI = cellData.capillaryPressure();
520 GlobalPosition distVec = globalPosJ - globalPosI;
523 Scalar dist = distVec.two_norm();
527 DimMatrix meanPermeability(0);
529 problem_.spatialParams().meanK(meanPermeability, problem_.spatialParams().intrinsicPermeability(element));
536 if (bcType.isDirichlet(satEqIdx))
538 switch (saturationType_)
542 satW = boundValues[saturationIdx];
547 satW = 1 - boundValues[saturationIdx];
554 satW = cellData.saturation(wPhaseIdx);
557 const Scalar pressBound = boundValues[pressureIdx];
562 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem_.spatialParams(), element);
564 const Scalar pcBound = fluidMatrixInteraction.pc(satW);
567 Scalar pressWBound = 0;
568 Scalar pressNwBound = 0;
569 if (pressureType_ == pw)
571 pressWBound = pressBound;
572 pressNwBound = pressBound + pcBound;
574 else if (pressureType_ == pn)
576 pressWBound = pressBound - pcBound;
577 pressNwBound = pressBound;
580 const Scalar lambdaWBound = fluidMatrixInteraction.krw(satW) / viscosity_[wPhaseIdx];
581 const Scalar lambdaNwBound = fluidMatrixInteraction.krn(satW) / viscosity_[nPhaseIdx];
583 Scalar potentialDiffW = cellData.fluxData().upwindPotential(wPhaseIdx, isIndex);
584 Scalar potentialDiffNw = cellData.fluxData().upwindPotential(nPhaseIdx, isIndex);
587 potentialDiffW = (cellData.pressure(wPhaseIdx) - pressWBound);
588 potentialDiffNw = (cellData.pressure(nPhaseIdx) - pressNwBound);
590 potentialDiffW += density_[wPhaseIdx] * (distVec * problem_.gravity());
591 potentialDiffNw += density_[nPhaseIdx] * (distVec * problem_.gravity());
594 cellData.fluxData().setUpwindPotential(wPhaseIdx, isIndex, potentialDiffW);
595 cellData.fluxData().setUpwindPotential(nPhaseIdx, isIndex, potentialDiffNw);
598 Scalar lambdaW = (potentialDiffW > 0.) ? lambdaWI : lambdaWBound;
599 lambdaW = (Dune::FloatCmp::eq<Scalar, Dune::FloatCmp::absolute>(potentialDiffW, 0.0, 1.0e-30)) ? 0.5 * (lambdaWI + lambdaWBound) : lambdaW;
600 Scalar lambdaNw = (potentialDiffNw > 0.) ? lambdaNwI : lambdaNwBound;
601 lambdaNw = (Dune::FloatCmp::eq<Scalar, Dune::FloatCmp::absolute>(potentialDiffNw, 0.0, 1.0e-30)) ? 0.5 * (lambdaNwI + lambdaNwBound) : lambdaNw;
607 Dune::FieldVector<Scalar, dimWorld> velocityW(unitOuterNormal);
608 Dune::FieldVector<Scalar, dimWorld> velocityNw(unitOuterNormal);
612 Scalar areaScaling = (unitOuterNormal * distVec);
614 Scalar gravityTermW = (problem_.gravity() * distVec) * density_[wPhaseIdx] * areaScaling;
615 Scalar gravityTermNw = (problem_.gravity() * distVec) * density_[nPhaseIdx] * areaScaling;
618 switch (pressureType_)
622 velocityW *= lambdaW * scalarPerm * ((cellData.pressure(wPhaseIdx) - pressBound) / dist + gravityTermW);
623 velocityNw *= lambdaNw * scalarPerm * ((cellData.pressure(wPhaseIdx) - pressBound) / dist + gravityTermNw)
624 + 0.5 * (lambdaNwI + lambdaNwBound) * scalarPerm * (pcI - pcBound) / dist;
629 velocityW *= lambdaW * scalarPerm * ((cellData.pressure(nPhaseIdx) - pressBound) / dist + gravityTermW)
630 - 0.5 * (lambdaWI + lambdaWBound) * scalarPerm * (pcI - pcBound) / dist;
631 velocityNw *= lambdaNw * scalarPerm * ((cellData.pressure(nPhaseIdx) - pressBound) / dist + gravityTermNw);
637 cellData.fluxData().setVelocity(wPhaseIdx, isIndex, velocityW);
638 cellData.fluxData().setVelocity(nPhaseIdx, isIndex, velocityNw);
639 cellData.fluxData().setVelocityMarker(isIndex);
643 else if (bcType.isNeumann(pressEqIdx))
645 problem_.neumann(boundValues, intersection);
647 Dune::FieldVector<Scalar, dimWorld> velocityW(unitOuterNormal);
648 Dune::FieldVector<Scalar, dimWorld> velocityNw(unitOuterNormal);
650 velocityW *= boundValues[wPhaseIdx];
651 velocityNw *= boundValues[nPhaseIdx];
653 velocityW /= density_[wPhaseIdx];
654 velocityNw /= density_[nPhaseIdx];
657 cellData.fluxData().setUpwindPotential(wPhaseIdx, isIndex, boundValues[wPhaseIdx]);
658 cellData.fluxData().setUpwindPotential(nPhaseIdx, isIndex, boundValues[nPhaseIdx]);
660 cellData.fluxData().setVelocity(wPhaseIdx, isIndex, velocityW);
661 cellData.fluxData().setVelocity(nPhaseIdx, isIndex, velocityNw);
662 cellData.fluxData().setVelocityMarker(isIndex);
666 DUNE_THROW(Dune::NotImplemented,
"No valid boundary condition type defined for pressure equation!");
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.
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
GetPropType< TypeTag, Properties::MPFAInteractionVolume > InteractionVolume
Type for storing interaction volume information.
Definition: 3dpressure.hh:156
void storePressureSolution()
Globally stores the pressure solution.
Definition: 3dpressure.hh:207
void addOutputVtkFields(MultiWriter &writer)
Adds pressure output to the output file.
Definition: 3dpressure.hh:386
void updateMaterialLaws()
constitutive functions are initialized and stored in the variables object
Definition: 3dpressure.hh:2484
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:48
void calculateVelocity()
Calculates the velocities at a cell-cell interfaces for the entire simulation grid.
Definition: 3dpressurevelocityadaptive.hh:217
FvMpfaL3dPressureVelocity2pAdaptive(Problem &problem)
Constructs a FvMpfaL3dPressureVelocity2pAdaptive object.
Definition: 3dpressurevelocityadaptive.hh:100
void updateVelocity()
Function for updating the velocity field if iterations are necessary in the transport solution.
Definition: 3dpressurevelocityadaptive.hh:118
void calculateVelocityOnBoundary(const Intersection &intersection, CellData &cellData)
Calculates the velocity at a boundary.
Definition: 3dpressurevelocityadaptive.hh:487
bool calculateVelocityInTransport()
Indicates if velocity is reconstructed in the pressure step or in the transport step.
Definition: 3dpressurevelocityadaptive.hh:174
void initialize(bool solveTwice=true)
Initializes pressure and velocity.
Definition: 3dpressurevelocityadaptive.hh:133
void addOutputVtkFields(MultiWriter &writer)
Adds velocity output to the output file.
Definition: 3dpressurevelocityadaptive.hh:190
void update()
Pressure and velocity update.
Definition: 3dpressurevelocityadaptive.hh:161
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