52 dim = GridView::dimension, dimWorld = GridView::dimensionworld
60 using PrimaryVariables =
typename SolutionTypes::PrimaryVariables;
67 using Vertex =
typename GridView::Traits::template Codim<dim>::Entity;
68 using Intersection =
typename GridView::Intersection;
75 wPhaseIdx = Indices::wPhaseIdx,
76 nPhaseIdx = Indices::nPhaseIdx,
77 pw = Indices::pressureW,
78 pn = Indices::pressureNw,
79 vw = Indices::velocityW,
80 vn = Indices::velocityNw,
81 sw = Indices::saturationW,
82 sn = Indices::saturationNw,
83 pressureIdx = Indices::pressureIdx,
84 saturationIdx = Indices::saturationIdx,
85 pressEqIdx = Indices::pressureEqIdx,
86 satEqIdx = Indices::satEqIdx,
90 using Element =
typename GridView::template Codim<0>::Entity;
92 using GlobalPosition =
typename Element::Geometry::GlobalCoordinate;
93 using DimMatrix = Dune::FieldMatrix<Scalar, dim, dim>;
102 ParentType(problem), problem_(problem), velocity_(problem)
104 density_[wPhaseIdx] = 0.;
105 density_[nPhaseIdx] = 0.;
106 viscosity_[wPhaseIdx] = 0.;
107 viscosity_[nPhaseIdx] = 0.;
109 calcVelocityInTransport_ =
getParam<bool>(
"MPFA.CalcVelocityInTransport");
137 const auto element = *problem_.gridView().template begin<0>();
138 FluidState fluidState;
139 fluidState.setPressure(wPhaseIdx, problem_.referencePressure(element));
140 fluidState.setPressure(nPhaseIdx, problem_.referencePressure(element));
141 fluidState.setTemperature(problem_.temperature(element));
142 fluidState.setSaturation(wPhaseIdx, 1.);
143 fluidState.setSaturation(nPhaseIdx, 0.);
144 density_[wPhaseIdx] = FluidSystem::density(fluidState, wPhaseIdx);
145 density_[nPhaseIdx] = FluidSystem::density(fluidState, nPhaseIdx);
146 viscosity_[wPhaseIdx] = FluidSystem::viscosity(fluidState, wPhaseIdx);
147 viscosity_[nPhaseIdx] = FluidSystem::viscosity(fluidState, nPhaseIdx);
150 velocity_.initialize();
176 return calcVelocityInTransport_;
189 template<
class MultiWriter>
193 velocity_.addOutputVtkFields(writer);
204 Scalar density_[numPhases];
205 Scalar viscosity_[numPhases];
206 bool calcVelocityInTransport_;
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, cellData3,
254 for (
int elemIdx = 0; elemIdx < 2 * dim; elemIdx++)
256 bool isOutside =
false;
257 for (
int fIdx = 0; fIdx < dim; fIdx++)
271 int eIdxGlobal = problem_.variables().index(interactionVolume.
getSubVolumeElement(elemIdx));
273 CellData& cellData = problem_.variables().cellData(eIdxGlobal);
275 velocity_.calculateBoundaryInteractionVolumeVelocity(interactionVolume, cellData, elemIdx);
295 int numVertices = intersection.geometry().corners();
297 auto elementI = intersection.inside();
298 auto elementJ = intersection.outside();
300 int eIdxGlobalI = problem_.variables().index(elementI);
301 int eIdxGlobalJ = problem_.variables().index(elementJ);
303 CellData& cellDataJ = problem_.variables().cellData(eIdxGlobalJ);
305 const auto refElement = referenceElement(elementI);
307 int indexInInside = intersection.indexInInside();
308 int indexInOutside = intersection.indexInOutside();
310 Dune::FieldVector<CellData, 4> cellDataTemp;
312 for (
int vIdx = 0; vIdx < numVertices; vIdx++)
314 int localVertIdx = refElement.subEntity(indexInInside, dim - 1, vIdx, dim);
316 int vIdxGlobal = problem_.variables().index(elementI.template subEntity<dim>(localVertIdx));
330 eIdxGlobal[0] = problem_.variables().index(element1);
331 eIdxGlobal[1] = problem_.variables().index(element2);
332 eIdxGlobal[2] = problem_.variables().index(element3);
333 eIdxGlobal[3] = problem_.variables().index(element4);
336 cellDataTemp[0] = problem_.variables().cellData(eIdxGlobal[0]);
337 cellDataTemp[1] = problem_.variables().cellData(eIdxGlobal[1]);
338 cellDataTemp[2] = problem_.variables().cellData(eIdxGlobal[2]);
339 cellDataTemp[3] = problem_.variables().cellData(eIdxGlobal[3]);
341 velocity_.calculateInnerInteractionVolumeVelocity(interactionVolume, cellDataTemp[0], cellDataTemp[1],
344 for (
int i = 0; i < 4; i++)
346 if (eIdxGlobal[i] == eIdxGlobalI)
348 cellData.fluxData().setVelocity(wPhaseIdx, indexInInside,
349 cellDataTemp[i].fluxData().
velocity(wPhaseIdx, indexInInside));
350 cellData.fluxData().setVelocity(nPhaseIdx, indexInInside,
351 cellDataTemp[i].fluxData().
velocity(nPhaseIdx, indexInInside));
352 cellData.fluxData().setUpwindPotential(wPhaseIdx, indexInInside,
353 cellDataTemp[i].fluxData().upwindPotential(wPhaseIdx, indexInInside));
354 cellData.fluxData().setUpwindPotential(nPhaseIdx, indexInInside,
355 cellDataTemp[i].fluxData().upwindPotential(nPhaseIdx, indexInInside));
357 else if (eIdxGlobal[i] == eIdxGlobalJ)
359 cellDataJ.fluxData().setVelocity(wPhaseIdx, indexInOutside,
360 cellDataTemp[i].fluxData().
velocity(wPhaseIdx, indexInOutside));
361 cellDataJ.fluxData().setVelocity(nPhaseIdx, indexInOutside,
362 cellDataTemp[i].fluxData().
velocity(nPhaseIdx, indexInOutside));
363 cellDataJ.fluxData().setUpwindPotential(wPhaseIdx, indexInOutside,
364 cellDataTemp[i].fluxData().upwindPotential(wPhaseIdx, indexInOutside));
365 cellDataJ.fluxData().setUpwindPotential(nPhaseIdx, indexInOutside,
366 cellDataTemp[i].fluxData().upwindPotential(nPhaseIdx, indexInOutside));
373 cellData.fluxData().setVelocityMarker(indexInInside);
374 cellDataJ.fluxData().setVelocityMarker(indexInOutside);
388 auto element = intersection.inside();
391 int isIndex = intersection.indexInInside();
394 const Dune::FieldVector<Scalar, dim>& unitOuterNormal = intersection.centerUnitOuterNormal();
396 BoundaryTypes bcType;
398 problem_.boundaryTypes(bcType, intersection);
399 PrimaryVariables boundValues(0.0);
401 if (bcType.isDirichlet(pressEqIdx))
403 problem_.dirichlet(boundValues, intersection);
406 const GlobalPosition& globalPosI = element.geometry().center();
409 const GlobalPosition& globalPosJ = intersection.geometry().center();
412 Scalar lambdaWI = cellData.mobility(wPhaseIdx);
413 Scalar lambdaNwI = cellData.mobility(nPhaseIdx);
416 Scalar pcI = cellData.capillaryPressure();
419 GlobalPosition distVec = globalPosJ - globalPosI;
422 Scalar dist = distVec.two_norm();
426 DimMatrix meanPermeability(0);
428 problem_.spatialParams().meanK(meanPermeability, problem_.spatialParams().intrinsicPermeability(element));
430 Dune::FieldVector<Scalar, dim> permeability(0);
431 meanPermeability.mv(unitOuterNormal, permeability);
435 if (bcType.isDirichlet(satEqIdx))
437 switch (saturationType_)
441 satW = boundValues[saturationIdx];
446 satW = 1 - boundValues[saturationIdx];
453 satW = cellData.saturation(wPhaseIdx);
456 const Scalar pressBound = boundValues[pressureIdx];
458 const auto fluidMatrixInteraction = problem_.spatialParams().fluidMatrixInteractionAtPos(element.geometry().center());
459 const Scalar pcBound = fluidMatrixInteraction.pc(satW);
462 Scalar pressWBound = 0;
463 Scalar pressNwBound = 0;
464 if (pressureType_ == pw)
466 pressWBound = pressBound;
467 pressNwBound = pressBound + pcBound;
469 else if (pressureType_ == pn)
471 pressWBound = pressBound - pcBound;
472 pressNwBound = pressBound;
475 const Scalar lambdaWBound = fluidMatrixInteraction.krw(satW) / viscosity_[wPhaseIdx];
476 const Scalar lambdaNwBound = fluidMatrixInteraction.krn(satW) / viscosity_[nPhaseIdx];
478 Scalar potentialDiffW = cellData.fluxData().upwindPotential(wPhaseIdx, isIndex);
479 Scalar potentialDiffNw = cellData.fluxData().upwindPotential(nPhaseIdx, isIndex);
482 potentialDiffW = (cellData.pressure(wPhaseIdx) - pressWBound);
483 potentialDiffNw = (cellData.pressure(nPhaseIdx) - pressNwBound);
485 potentialDiffW += density_[wPhaseIdx] * (distVec * problem_.gravity());
486 potentialDiffNw += density_[nPhaseIdx] * (distVec * problem_.gravity());
489 cellData.fluxData().setUpwindPotential(wPhaseIdx, isIndex, potentialDiffW);
490 cellData.fluxData().setUpwindPotential(nPhaseIdx, isIndex, potentialDiffNw);
493 Scalar lambdaW = (potentialDiffW > 0.) ? lambdaWI : lambdaWBound;
494 lambdaW = (Dune::FloatCmp::eq<Scalar, Dune::FloatCmp::absolute>(potentialDiffW, 0.0, 1.0e-30)) ? 0.5 * (lambdaWI + lambdaWBound) : lambdaW;
495 Scalar lambdaNw = (potentialDiffNw > 0.) ? lambdaNwI : lambdaNwBound;
496 lambdaNw = (Dune::FloatCmp::eq<Scalar, Dune::FloatCmp::absolute>(potentialDiffNw, 0.0, 1.0e-30)) ? 0.5 * (lambdaNwI + lambdaNwBound) : lambdaNw;
499 Scalar scalarPerm = permeability.two_norm();
502 Dune::FieldVector<Scalar, dimWorld> velocityW(unitOuterNormal);
503 Dune::FieldVector<Scalar, dimWorld> velocityNw(unitOuterNormal);
507 Scalar areaScaling = (unitOuterNormal * distVec);
510 Scalar gravityTermW = (problem_.gravity() * distVec) * density_[wPhaseIdx] * areaScaling;
511 Scalar gravityTermNw = (problem_.gravity() * distVec) * density_[nPhaseIdx] * areaScaling;
514 switch (pressureType_)
518 velocityW *= lambdaW * scalarPerm * ((cellData.pressure(wPhaseIdx) - pressBound) / dist + gravityTermW);
519 velocityNw *= lambdaNw * scalarPerm * ((cellData.pressure(wPhaseIdx) - pressBound) / dist + gravityTermNw)
520 + 0.5 * (lambdaNwI + lambdaNwBound) * scalarPerm * (pcI - pcBound) / dist;
525 velocityW *= lambdaW * scalarPerm * ((cellData.pressure(nPhaseIdx) - pressBound) / dist + gravityTermW)
526 - 0.5 * (lambdaWI + lambdaWBound) * scalarPerm * (pcI - pcBound) / dist;
527 velocityNw *= lambdaNw * scalarPerm * ((cellData.pressure(nPhaseIdx) - pressBound) / dist + gravityTermNw);
533 cellData.fluxData().setVelocity(wPhaseIdx, isIndex, velocityW);
534 cellData.fluxData().setVelocity(nPhaseIdx, isIndex, velocityNw);
535 cellData.fluxData().setVelocityMarker(isIndex);
539 else if (bcType.isNeumann(pressEqIdx))
541 problem_.neumann(boundValues, intersection);
543 Dune::FieldVector<Scalar, dimWorld> velocityW(unitOuterNormal);
544 Dune::FieldVector<Scalar, dimWorld> velocityNw(unitOuterNormal);
546 velocityW *= boundValues[wPhaseIdx];
547 velocityNw *= boundValues[nPhaseIdx];
549 velocityW /= density_[wPhaseIdx];
550 velocityNw /= density_[nPhaseIdx];
553 cellData.fluxData().setUpwindPotential(wPhaseIdx, isIndex, boundValues[wPhaseIdx]);
554 cellData.fluxData().setUpwindPotential(nPhaseIdx, isIndex, boundValues[nPhaseIdx]);
556 cellData.fluxData().setVelocity(wPhaseIdx, isIndex, velocityW);
557 cellData.fluxData().setVelocity(nPhaseIdx, isIndex, velocityNw);
558 cellData.fluxData().setVelocityMarker(isIndex);
562 DUNE_THROW(Dune::NotImplemented,
"No valid boundary condition type defined for pressure equation!");