22#ifndef DUMUX_FVMPFAO2DPRESSURE2P_HH
23#define DUMUX_FVMPFAO2DPRESSURE2P_HH
67template<
class TypeTag>
75 dim = GridView::dimension, dimWorld = GridView::dimensionworld
91 using PrimaryVariables =
typename SolutionTypes::PrimaryVariables;
92 using ScalarSolutionType =
typename SolutionTypes::ScalarSolution;
98 pw = Indices::pressureW,
99 pn = Indices::pressureNw,
100 sw = Indices::saturationW,
101 sn = Indices::saturationNw
105 wPhaseIdx = Indices::wPhaseIdx,
106 nPhaseIdx = Indices::nPhaseIdx,
107 pressureIdx = Indices::pressureIdx,
108 saturationIdx = Indices::saturationIdx,
109 pressEqIdx = Indices::pressureEqIdx,
110 satEqIdx = Indices::satEqIdx,
111 numPhases = getPropValue<TypeTag, Properties::NumPhases>()
118 dirichletDirichlet = 1,
119 dirichletNeumann = 2,
123 using Element =
typename GridView::Traits::template Codim<0>::Entity;
124 using IntersectionIterator =
typename GridView::IntersectionIterator;
125 using Intersection =
typename GridView::Intersection;
127 using LocalPosition = Dune::FieldVector<Scalar, dim>;
128 using GlobalPosition =
typename Element::Geometry::GlobalCoordinate;
129 using GravityVector = Dune::FieldVector<Scalar, dimWorld>;
130 using DimMatrix = Dune::FieldMatrix<Scalar, dim, dim>;
132 using DimVector = Dune::FieldVector<Scalar, dim>;
136 using GlobalInteractionVolumeVector = std::vector<InteractionVolume>;
137 using InnerBoundaryVolumeFaces = std::vector<Dune::FieldVector<bool, 2*dim> >;
140 Intersection getNextIntersection_(
const Element&,
const IntersectionIterator&);
144 void initializeMatrix();
146 void storeInteractionVolumeInfo();
168 storeInteractionVolumeInfo();
180 const auto element = *problem_.gridView().template begin<0>();
181 FluidState fluidState;
182 fluidState.setPressure(wPhaseIdx, problem_.referencePressure(element));
183 fluidState.setPressure(nPhaseIdx, problem_.referencePressure(element));
184 fluidState.setTemperature(problem_.temperature(element));
185 fluidState.setSaturation(wPhaseIdx, 1.);
186 fluidState.setSaturation(nPhaseIdx, 0.);
197 storeInteractionVolumeInfo();
216 timeStep_ = problem_.timeManager().timeStepSize();
218 int size = problem_.gridView().size(0);
219 for (
int i = 0; i < size; i++)
223 switch (saturationType_)
226 sat = problem_.variables().cellData(i).saturation(wPhaseIdx);
229 sat = problem_.variables().cellData(i).saturation(nPhaseIdx);
234 maxError_ = max(maxError_, (sat - 1.0) / timeStep_);
238 maxError_ = max(maxError_, (-sat) / timeStep_);
256 for (
const auto& element : elements(problem_.gridView()))
269 int eIdxGlobal = problem_.variables().index(element);
270 CellData& cellData = problem_.variables().cellData(eIdxGlobal);
272 switch (pressureType_)
276 Scalar potW = this->
pressure()[eIdxGlobal];
278 Scalar gravityDiff = (problem_.bBoxMax() - element.geometry().center()) * gravity_;
279 Scalar potPc = cellData.capillaryPressure()
280 + gravityDiff * (density_[nPhaseIdx] - density_[wPhaseIdx]);
282 cellData.setPotential(wPhaseIdx, potW);
283 cellData.setPotential(nPhaseIdx, potW + potPc);
285 Scalar pressW = potW - gravityDiff * density_[wPhaseIdx];
287 cellData.setPressure(wPhaseIdx, pressW);
288 cellData.setPressure(nPhaseIdx, pressW + cellData.capillaryPressure());
294 Scalar potNw = this->
pressure()[eIdxGlobal];
296 Scalar gravityDiff = (problem_.bBoxMax() - element.geometry().center()) * gravity_;
297 Scalar potPc = cellData.capillaryPressure()
298 + gravityDiff * (density_[nPhaseIdx] - density_[wPhaseIdx]);
300 cellData.setPotential(nPhaseIdx, potNw);
301 cellData.setPotential(wPhaseIdx, potNw - potPc);
303 Scalar pressNw = potNw - gravityDiff * density_[nPhaseIdx];
305 cellData.setPressure(wPhaseIdx, pressNw - cellData.capillaryPressure());
306 cellData.setPressure(nPhaseIdx, pressNw);
312 cellData.fluxData().resetVelocity();
325 template<
class MultiWriter>
328 int size = problem_.gridView().size(0);
329 ScalarSolutionType *potential = writer.allocateManagedBuffer(size);
333 if (pressureType_ == pw)
335 writer.attachCellData(*potential,
"wetting potential");
338 if (pressureType_ == pn)
340 writer.attachCellData(*potential,
"nonwetting potential");
343 if (vtkOutputLevel_ > 0)
345 ScalarSolutionType *
pressure = writer.allocateManagedBuffer(size);
346 ScalarSolutionType *pressureSecond = writer.allocateManagedBuffer(size);
347 ScalarSolutionType *potentialSecond = writer.allocateManagedBuffer(size);
348 ScalarSolutionType *pc = writer.allocateManagedBuffer(size);
350 for (
const auto& element : elements(problem_.gridView()))
352 int idx = problem_.variables().index(element);
353 CellData& cellData = problem_.variables().cellData(idx);
355 (*pc)[idx] = cellData.capillaryPressure();
357 if (pressureType_ == pw)
359 (*pressure)[idx] = cellData.pressure(wPhaseIdx);
360 (*potentialSecond)[idx] = cellData.potential(nPhaseIdx);
361 (*pressureSecond)[idx] = cellData.pressure(nPhaseIdx);
364 if (pressureType_ == pn)
366 (*pressure)[idx] = cellData.pressure(nPhaseIdx);
367 (*potentialSecond)[idx] = cellData.potential(wPhaseIdx);
368 (*pressureSecond)[idx] = cellData.pressure(wPhaseIdx);
372 if (pressureType_ == pw)
374 writer.attachCellData(*
pressure,
"wetting pressure");
375 writer.attachCellData(*pressureSecond,
"nonwetting pressure");
376 writer.attachCellData(*potentialSecond,
"nonwetting potential");
379 if (pressureType_ == pn)
381 writer.attachCellData(*
pressure,
"nonwetting pressure");
382 writer.attachCellData(*pressureSecond,
"wetting pressure");
383 writer.attachCellData(*potentialSecond,
"wetting potential");
386 writer.attachCellData(*pc,
"capillary pressure");
397 ParentType(problem), problem_(problem), gravity_(problem.gravity()), maxError_(
400 if (pressureType_ != pw && pressureType_ != pn)
402 DUNE_THROW(Dune::NotImplemented,
"Pressure type not supported!");
404 if (saturationType_ != sw && saturationType_ != sn)
406 DUNE_THROW(Dune::NotImplemented,
"Saturation type not supported!");
408 if (getPropValue<TypeTag, Properties::EnableCompressibility>())
410 DUNE_THROW(Dune::NotImplemented,
"Compressibility not supported!");
414 DUNE_THROW(Dune::NotImplemented,
"Dimension not supported!");
417 ErrorTermFactor_ = getParam<Scalar>(
"Impet.ErrorTermFactor");
418 ErrorTermLowerBound_ = getParam<Scalar>(
"Impet.ErrorTermLowerBound");
419 ErrorTermUpperBound_ = getParam<Scalar>(
"Impet.ErrorTermUpperBound");
421 density_[wPhaseIdx] = 0.;
422 density_[nPhaseIdx] = 0.;
423 viscosity_[wPhaseIdx] = 0.;
424 viscosity_[nPhaseIdx] = 0.;
426 vtkOutputLevel_ = getParam<int>(
"Vtk.OutputLevel");
448 Scalar evaluateErrorTerm_(CellData& cellData)
453 switch (saturationType_)
456 sat = cellData.saturation(wPhaseIdx);
459 sat = cellData.saturation(nPhaseIdx);
463 Scalar error = (sat > 1.0) ? sat - 1.0 : 0.0;
471 Scalar errorAbs = abs(error);
473 if ((errorAbs * timeStep_ > 1e-6) && (errorAbs > ErrorTermLowerBound_ * maxError_)
474 && (!problem_.timeManager().willBeFinished()))
476 return ErrorTermFactor_ * error;
486 const GravityVector& gravity_;
490 Scalar ErrorTermFactor_;
491 Scalar ErrorTermLowerBound_;
492 Scalar ErrorTermUpperBound_;
494 Scalar density_[numPhases];
495 Scalar viscosity_[numPhases];
499 static constexpr Scalar threshold_ = 1e-15;
501 static const int pressureType_ = getPropValue<TypeTag, Properties::PressureFormulation>();
503 static const int saturationType_ = getPropValue<TypeTag, Properties::SaturationFormulation>();
505 static const int velocityType_ = getPropValue<TypeTag, Properties::VelocityFormulation>();
509template<
class TypeTag>
510typename FvMpfaO2dPressure2p<TypeTag>::Intersection
512 const IntersectionIterator& isIt)
514 auto isItBegin = problem_.gridView().ibegin(element);
515 const auto isEndIt = problem_.gridView().iend(element);
517 auto tempIsIt = isIt;
518 auto nextIsIt = ++tempIsIt;
521 switch (getPropValue<TypeTag, Properties::GridImplementation>())
524 case GridTypeIndices::yaspGrid:
526 if (nextIsIt == isEndIt)
528 nextIsIt = isItBegin;
532 nextIsIt = ++tempIsIt;
534 if (nextIsIt == isEndIt)
536 auto tempIsItBegin = isItBegin;
537 nextIsIt = ++tempIsItBegin;
544 case GridTypeIndices::aluGrid:
545 case GridTypeIndices::ugGrid:
547 if (nextIsIt == isEndIt)
548 nextIsIt = isItBegin;
554 DUNE_THROW(Dune::NotImplemented,
"GridType can not be used with MPFAO implementation!");
563template<
class TypeTag>
564void FvMpfaO2dPressure2p<TypeTag>::initializeMatrix()
567 for (
const auto& element : elements(problem_.gridView()))
570 int eIdxGlobalI = problem_.variables().index(element);
576 const auto isEndIt = problem_.gridView().iend(element);
577 for (
auto isIt = problem_.gridView().ibegin(element); isIt != isEndIt; ++isIt)
579 const auto& intersection = *isIt;
580 auto nextIntersection = getNextIntersection_(element, isIt);
582 if (intersection.neighbor())
586 if (intersection.neighbor() && nextIntersection.neighbor())
588 for (
const auto& innerIntersection
589 : intersections(problem_.gridView(), intersection.outside()))
590 for (
const auto& innerNextIntersection
591 : intersections(problem_.gridView(), nextIntersection.outside()))
593 if (innerIntersection.neighbor() && innerNextIntersection.neighbor())
595 if (innerIntersection.outside() == innerNextIntersection.outside()
596 && innerIntersection.outside() != intersection.inside())
606 this->A_.setrowsize(eIdxGlobalI, rowSize);
611 this->A_.endrowsizes();
614 for (
const auto& element : elements(problem_.gridView()))
617 int eIdxGlobalI = problem_.variables().index(element);
620 this->A_.addindex(eIdxGlobalI, eIdxGlobalI);
623 const auto isEndIt = problem_.gridView().iend(element);
624 for (
auto isIt = problem_.gridView().ibegin(element); isIt != isEndIt; ++isIt)
626 const auto& intersection = *isIt;
627 auto nextIntersection = getNextIntersection_(element, isIt);
629 if (intersection.neighbor())
632 int eIdxGlobalJ = problem_.variables().index(intersection.outside());
636 this->A_.addindex(eIdxGlobalI, eIdxGlobalJ);
639 if (intersection.neighbor() && nextIntersection.neighbor())
641 for (
const auto& innerIntersection
642 : intersections(problem_.gridView(), intersection.outside()))
643 for (
const auto& innerNextIntersection
644 : intersections(problem_.gridView(), nextIntersection.outside()))
646 if (innerIntersection.neighbor() && innerNextIntersection.neighbor())
648 auto innerOutside = innerIntersection.outside();
650 if (innerOutside == innerNextIntersection.outside()
651 && innerOutside != intersection.inside())
653 int eIdxGlobalJ = problem_.variables().index(innerOutside);
655 this->A_.addindex(eIdxGlobalI, eIdxGlobalJ);
664 this->A_.endindices();
692template<
class TypeTag>
693void FvMpfaO2dPressure2p<TypeTag>::storeInteractionVolumeInfo()
705 BoundaryTypes bcType;
708 for (
const auto& element : elements(problem_.gridView()))
712 int eIdxGlobal1 = problem_.variables().index(element);
714 const GlobalPosition& globalPos1 = element.geometry().center();
717 DimMatrix K1(problem_.spatialParams().intrinsicPermeability(element));
719 const auto isIt12End = problem_.gridView().iend(element);
720 for (
auto isIt12 = problem_.gridView().ibegin(element); isIt12 != isIt12End; ++isIt12)
722 const auto& intersection12 = *isIt12;
723 auto intersection14 = getNextIntersection_(element, isIt12);
725 int indexInInside12 = intersection12.indexInInside();
726 int indexInInside14 = intersection14.indexInInside();
731 const auto refElement = referenceElement(element);
733 GlobalPosition corner1234(0);
735 int globalVertIdx1234 = 0;
738 for (
int i = 0; i < intersection12.geometry().corners(); ++i)
740 bool finished =
false;
742 const GlobalPosition& isIt12corner = intersection12.geometry().corner(i);
744 int localVertIdx12corner = refElement.subEntity(indexInInside12, dim - 1, i, dim);
746 int globalVertIdx12corner = problem_.variables().index(element.template subEntity<dim>(localVertIdx12corner));
748 for (
int j = 0; j < intersection14.geometry().corners(); ++j)
750 int localVertIdx14corner = refElement.subEntity(indexInInside14, dim - 1, j, dim);
752 int globalVertIdx14corner = problem_.variables().index(element.template subEntity<dim>(localVertIdx14corner));
754 if (globalVertIdx12corner == globalVertIdx14corner)
756 corner1234 = isIt12corner;
758 globalVertIdx1234 = globalVertIdx12corner;
771 if (interactionVolumes_[globalVertIdx1234].isStored())
777 interactionVolumes_[globalVertIdx1234].setStored();
782 interactionVolumes_[globalVertIdx1234].setSubVolumeElement(element, 0);
783 interactionVolumes_[globalVertIdx1234].setIndexOnElement(intersection12.indexInInside(), 0, 0);
784 interactionVolumes_[globalVertIdx1234].setIndexOnElement(intersection14.indexInInside(), 0, 1);
787 const GlobalPosition& globalPosFace12 = intersection12.geometry().center();
790 Scalar faceVol12 = intersection12.geometry().volume() / 2.0;
793 DimVector unitOuterNormal12 = intersection12.centerUnitOuterNormal();
796 const GlobalPosition& globalPosFace41 = intersection14.geometry().center();
799 Scalar faceVol41 = intersection14.geometry().volume() / 2.0;
802 DimVector unitOuterNormal14 = intersection14.centerUnitOuterNormal();
806 R.mv(globalPos1 - globalPosFace12, nu14);
809 R.mv(globalPosFace41 - globalPos1, nu12);
811 interactionVolumes_[globalVertIdx1234].setPermTimesNu(nu12, K1, 0, 0);
812 interactionVolumes_[globalVertIdx1234].setPermTimesNu(nu14, K1, 0, 1);
813 interactionVolumes_[globalVertIdx1234].setNormal(unitOuterNormal12, 0, 0);
814 interactionVolumes_[globalVertIdx1234].setNormal(unitOuterNormal14, 0, 1);
815 interactionVolumes_[globalVertIdx1234].setFaceArea(faceVol12, 0, 0);
816 interactionVolumes_[globalVertIdx1234].setFaceArea(faceVol41, 0, 1);
822 interactionVolumes_[globalVertIdx1234].setDF(abs(nu14 * Rnu12), 0);
825 if (intersection12.neighbor())
828 auto element2 = intersection12.outside();
830 int eIdxGlobal2 = problem_.variables().index(element2);
833 interactionVolumes_[globalVertIdx1234].setSubVolumeElement(element2, 1);
834 interactionVolumes_[globalVertIdx1234].setIndexOnElement(intersection12.indexInOutside(), 1, 1);
836 interactionVolumes_[globalVertIdx1234].setNormal(unitOuterNormal12, 1, 1);
837 interactionVolumes_[globalVertIdx1234].setFaceArea(faceVol12, 1, 1);
840 const GlobalPosition& globalPos2 = element2.geometry().center();
843 DimMatrix K2(problem_.spatialParams().intrinsicPermeability(element2));
846 if (intersection14.neighbor())
850 auto element4 = intersection14.outside();
853 interactionVolumes_[globalVertIdx1234].setSubVolumeElement(element4, 3);
854 interactionVolumes_[globalVertIdx1234].setIndexOnElement(intersection14.indexInOutside(), 3, 0);
856 interactionVolumes_[globalVertIdx1234].setNormal(unitOuterNormal14, 3, 0);
857 interactionVolumes_[globalVertIdx1234].setFaceArea(faceVol41, 3, 0);
862 const GlobalPosition& globalPos4 = element4.geometry().center();
865 DimMatrix K4(problem_.spatialParams().intrinsicPermeability(element4));
868 GlobalPosition globalPos3(0);
870 GlobalPosition globalPosFace23(0);
871 GlobalPosition globalPosFace34(0);
873 for (
const auto& intersection2
874 : intersections(problem_.gridView(), element2))
876 bool finished =
false;
878 for (
const auto& intersection4
879 : intersections(problem_.gridView(), element4))
881 if (intersection2.neighbor() && intersection4.neighbor())
883 auto element32 = intersection2.outside();
884 auto element34 = intersection4.outside();
887 if (element32 == element34 && element32 != element)
890 interactionVolumes_[globalVertIdx1234].setSubVolumeElement(element32, 2);
892 interactionVolumes_[globalVertIdx1234].setIndexOnElement(intersection2.indexInInside(), 1,
894 interactionVolumes_[globalVertIdx1234].setIndexOnElement(intersection2.indexInOutside(), 2,
896 interactionVolumes_[globalVertIdx1234].setIndexOnElement(intersection4.indexInInside(), 3,
898 interactionVolumes_[globalVertIdx1234].setIndexOnElement(intersection4.indexInOutside(), 2,
902 globalPos3 = element32.geometry().center();
904 globalPosFace23 = intersection2.geometry().center();
905 globalPosFace34 = intersection4.geometry().center();
907 Scalar faceVol23 = intersection2.geometry().volume() / 2.0;
908 Scalar faceVol34 = intersection4.geometry().volume() / 2.0;
911 DimVector unitOuterNormal23 = intersection2.centerUnitOuterNormal();
913 DimVector unitOuterNormal43 = intersection4.centerUnitOuterNormal();
915 interactionVolumes_[globalVertIdx1234].setNormal(unitOuterNormal23, 1, 0);
916 interactionVolumes_[globalVertIdx1234].setNormal(unitOuterNormal23, 2, 1);
917 interactionVolumes_[globalVertIdx1234].setNormal(unitOuterNormal43, 2, 0);
918 interactionVolumes_[globalVertIdx1234].setNormal(unitOuterNormal43, 3, 1);
919 interactionVolumes_[globalVertIdx1234].setFaceArea(faceVol23, 1, 0);
920 interactionVolumes_[globalVertIdx1234].setFaceArea(faceVol23, 2, 1);
921 interactionVolumes_[globalVertIdx1234].setFaceArea(faceVol34, 2, 0);
922 interactionVolumes_[globalVertIdx1234].setFaceArea(faceVol34, 3, 1);
926 problem_.spatialParams().intrinsicPermeability(element32));
930 R.umv(globalPosFace12 - globalPos2, nu23);
933 R.umv(globalPosFace23 - globalPos2, nu21);
936 R.umv(globalPosFace34 - globalPos3, nu32);
939 R.umv(globalPos3 - globalPosFace23, nu34);
942 R.umv(globalPos4 - globalPosFace34, nu41);
945 R.umv(globalPos4 - globalPosFace41, nu43);
947 interactionVolumes_[globalVertIdx1234].setPermTimesNu(nu23, K2, 1, 0);
948 interactionVolumes_[globalVertIdx1234].setPermTimesNu(nu21, K2, 1, 1);
949 interactionVolumes_[globalVertIdx1234].setPermTimesNu(nu34, K3, 2, 0);
950 interactionVolumes_[globalVertIdx1234].setPermTimesNu(nu32, K3, 2, 1);
951 interactionVolumes_[globalVertIdx1234].setPermTimesNu(nu41, K4, 3, 0);
952 interactionVolumes_[globalVertIdx1234].setPermTimesNu(nu43, K4, 3, 1);
957 interactionVolumes_[globalVertIdx1234].setDF(abs(nu23 * Rnu21), 1);
961 interactionVolumes_[globalVertIdx1234].setDF(abs(nu32 * Rnu34), 2);
965 interactionVolumes_[globalVertIdx1234].setDF(abs(nu41 * Rnu43), 3);
983 problem_.boundaryTypes(bcType, intersection14);
984 PrimaryVariables boundValues(0.0);
986 interactionVolumes_[globalVertIdx1234].setBoundary(bcType, 3);
987 if (bcType.isNeumann(pressEqIdx))
989 problem_.neumann(boundValues, intersection14);
990 boundValues *= faceVol41;
991 interactionVolumes_[globalVertIdx1234].setNeumannCondition(boundValues, 3);
993 if (bcType.hasDirichlet())
995 problem_.dirichlet(boundValues, intersection14);
996 interactionVolumes_[globalVertIdx1234].setDirichletCondition(boundValues, 3);
1003 GlobalPosition globalPosFace23(0);
1006 Scalar faceVol23 = 0;
1009 DimVector unitOuterNormal23(0);
1011 bool finished =
false;
1013 for (
const auto& intersection2
1014 : intersections(problem_.gridView(), element2))
1016 if (intersection2.boundary())
1018 for (
int i = 0; i < intersection2.geometry().corners(); ++i)
1020 int localVertIdx2corner = refElement.subEntity(intersection2.indexInInside(), dim - 1, i,
1023 int globalVertIdx2corner = problem_.variables().index(element2.template subEntity<dim>(localVertIdx2corner));
1025 if (globalVertIdx2corner == globalVertIdx1234)
1027 interactionVolumes_[globalVertIdx1234].setIndexOnElement(intersection2.indexInInside(), 1,
1030 globalPosFace23 = intersection2.geometry().center();
1032 faceVol23 = intersection2.geometry().volume() / 2.0;
1034 unitOuterNormal23 = intersection2.centerUnitOuterNormal();
1036 interactionVolumes_[globalVertIdx1234].setNormal(unitOuterNormal23, 1, 0);
1037 interactionVolumes_[globalVertIdx1234].setFaceArea(faceVol23, 1, 0);
1039 problem_.boundaryTypes(bcType, intersection2);
1042 interactionVolumes_[globalVertIdx1234].setBoundary(bcType, 1);
1043 if (bcType.isNeumann(pressEqIdx))
1045 problem_.neumann(boundValues, intersection2);
1046 boundValues *= faceVol23;
1047 interactionVolumes_[globalVertIdx1234].setNeumannCondition(boundValues, 1);
1049 if (bcType.hasDirichlet())
1051 problem_.dirichlet(boundValues, intersection2);
1052 interactionVolumes_[globalVertIdx1234].setDirichletCondition(boundValues, 1);
1055 interactionVolumes_[globalVertIdx1234].setOutsideFace(2);
1057 innerBoundaryVolumeFaces_[eIdxGlobal1][intersection12.indexInInside()] =
true;
1058 innerBoundaryVolumeFaces_[eIdxGlobal2][intersection12.indexInOutside()] =
true;
1062 R.umv(globalPosFace12 - globalPos2, nu23);
1065 R.umv(globalPosFace23 - globalPos2, nu21);
1067 interactionVolumes_[globalVertIdx1234].setPermTimesNu(nu23, K2, 1, 0);
1068 interactionVolumes_[globalVertIdx1234].setPermTimesNu(nu21, K2, 1, 1);
1073 interactionVolumes_[globalVertIdx1234].setDF(abs(nu23 * Rnu21), 1);
1089 Dune::NotImplemented,
1090 "fvmpfao2pfaboundpressure2p.hh, l. 997: boundary shape not available as interaction volume shape");
1098 problem_.boundaryTypes(bcType, *isIt12);
1099 PrimaryVariables boundValues(0.0);
1101 interactionVolumes_[globalVertIdx1234].setBoundary(bcType, 0);
1102 if (bcType.isNeumann(pressEqIdx))
1104 problem_.neumann(boundValues, *isIt12);
1105 boundValues *= faceVol12;
1106 interactionVolumes_[globalVertIdx1234].setNeumannCondition(boundValues, 0);
1108 if (bcType.hasDirichlet())
1110 problem_.dirichlet(boundValues, *isIt12);
1111 interactionVolumes_[globalVertIdx1234].setDirichletCondition(boundValues, 0);
1115 if (intersection14.boundary())
1117 problem_.boundaryTypes(bcType, intersection14);
1120 interactionVolumes_[globalVertIdx1234].setBoundary(bcType, 3);
1121 if (bcType.isNeumann(pressEqIdx))
1123 problem_.neumann(boundValues, intersection14);
1124 boundValues *= faceVol41;
1125 interactionVolumes_[globalVertIdx1234].setNeumannCondition(boundValues, 3);
1127 if (bcType.hasDirichlet())
1129 problem_.dirichlet(boundValues, intersection14);
1130 interactionVolumes_[globalVertIdx1234].setDirichletCondition(boundValues, 3);
1133 interactionVolumes_[globalVertIdx1234].setOutsideFace(1);
1134 interactionVolumes_[globalVertIdx1234].setOutsideFace(2);
1142 auto element4 = intersection14.outside();
1143 interactionVolumes_[globalVertIdx1234].setIndexOnElement(intersection14.indexInOutside(), 3, 0);
1146 interactionVolumes_[globalVertIdx1234].setSubVolumeElement(element4, 3);
1148 interactionVolumes_[globalVertIdx1234].setNormal(unitOuterNormal14, 3, 0);
1149 interactionVolumes_[globalVertIdx1234].setFaceArea(faceVol41, 3, 0);
1152 const GlobalPosition& globalPos4 = element4.geometry().center();
1154 int eIdxGlobal4 = problem_.variables().index(element4);
1156 bool finished =
false;
1159 for (
const auto& intersection4
1160 : intersections(problem_.gridView(), element4))
1162 if (intersection4.boundary())
1164 for (
int i = 0; i < intersection4.geometry().corners(); ++i)
1166 int localVertIdx4corner = refElement.subEntity(intersection4.indexInInside(), dim - 1, i,
1169 int globalVertIdx4corner = problem_.variables().index(element4.template subEntity<dim>(localVertIdx4corner));
1171 if (globalVertIdx4corner == globalVertIdx1234)
1173 interactionVolumes_[globalVertIdx1234].setIndexOnElement(intersection4.indexInInside(), 3,
1176 const GlobalPosition& globalPosFace34 = intersection4.geometry().center();
1178 Scalar faceVol34 = intersection4.geometry().volume() / 2.0;
1180 DimVector unitOuterNormal43 = intersection4.centerUnitOuterNormal();
1182 interactionVolumes_[globalVertIdx1234].setNormal(unitOuterNormal43, 3, 1);
1183 interactionVolumes_[globalVertIdx1234].setFaceArea(faceVol34, 3, 1);
1185 problem_.boundaryTypes(bcType, intersection4);
1188 interactionVolumes_[globalVertIdx1234].setBoundary(bcType, 2);
1189 if (bcType.isNeumann(pressEqIdx))
1191 problem_.neumann(boundValues, intersection4);
1192 boundValues *= faceVol34;
1193 interactionVolumes_[globalVertIdx1234].setNeumannCondition(boundValues, 2);
1195 if (bcType.hasDirichlet())
1197 problem_.dirichlet(boundValues, intersection4);
1198 interactionVolumes_[globalVertIdx1234].setDirichletCondition(boundValues, 2);
1201 interactionVolumes_[globalVertIdx1234].setOutsideFace(1);
1203 innerBoundaryVolumeFaces_[eIdxGlobal1][intersection14.indexInInside()] =
true;
1204 innerBoundaryVolumeFaces_[eIdxGlobal4][intersection14.indexInOutside()] =
true;
1208 problem_.spatialParams().intrinsicPermeability(element4));
1212 R.umv(globalPos4 - globalPosFace34, nu41);
1215 R.umv(globalPos4 - globalPosFace41, nu43);
1217 interactionVolumes_[globalVertIdx1234].setPermTimesNu(nu41, K4, 3, 0);
1218 interactionVolumes_[globalVertIdx1234].setPermTimesNu(nu43, K4, 3, 1);
1223 interactionVolumes_[globalVertIdx1234].setDF(abs(nu41 * Rnu43), 3);
1239 Dune::NotImplemented,
1240 "fvmpfao2pfaboundpressure2p.hh, l. 1164: boundary shape not available as interaction volume shape");
1253template<
class TypeTag>
1254void FvMpfaO2dPressure2p<TypeTag>::assemble()
1261 for (
const auto& vertex : vertices(problem_.gridView()))
1263 int vIdxGlobal = problem_.variables().index(vertex);
1265 InteractionVolume& interactionVolume = interactionVolumes_[vIdxGlobal];
1267 if (interactionVolume.isInnerVolume())
1270 auto element1 = interactionVolume.getSubVolumeElement(0);
1271 auto element2 = interactionVolume.getSubVolumeElement(1);
1272 auto element3 = interactionVolume.getSubVolumeElement(2);
1273 auto element4 = interactionVolume.getSubVolumeElement(3);
1276 const GlobalPosition& globalPos1 = element1.geometry().center();
1277 const GlobalPosition& globalPos2 = element2.geometry().center();
1278 const GlobalPosition& globalPos3 = element3.geometry().center();
1279 const GlobalPosition& globalPos4 = element4.geometry().center();
1282 Scalar volume1 = element1.geometry().volume();
1283 Scalar volume2 = element2.geometry().volume();
1284 Scalar volume3 = element3.geometry().volume();
1285 Scalar volume4 = element4.geometry().volume();
1288 int eIdxGlobal1 = problem_.variables().index(element1);
1289 int eIdxGlobal2 = problem_.variables().index(element2);
1290 int eIdxGlobal3 = problem_.variables().index(element3);
1291 int eIdxGlobal4 = problem_.variables().index(element4);
1294 CellData& cellData1 = problem_.variables().cellData(eIdxGlobal1);
1295 CellData& cellData2 = problem_.variables().cellData(eIdxGlobal2);
1296 CellData& cellData3 = problem_.variables().cellData(eIdxGlobal3);
1297 CellData& cellData4 = problem_.variables().cellData(eIdxGlobal4);
1300 PrimaryVariables source(0.0);
1301 problem_.source(source, element1);
1302 this->f_[eIdxGlobal1] += volume1 / (4.0)
1303 * (source[wPhaseIdx] / density_[wPhaseIdx] + source[nPhaseIdx] / density_[nPhaseIdx]);
1304 problem_.source(source, element2);
1305 this->f_[eIdxGlobal2] += volume2 / (4.0)
1306 * (source[wPhaseIdx] / density_[wPhaseIdx] + source[nPhaseIdx] / density_[nPhaseIdx]);
1307 problem_.source(source, element3);
1308 this->f_[eIdxGlobal3] += volume3 / (4.0)
1309 * (source[wPhaseIdx] / density_[wPhaseIdx] + source[nPhaseIdx] / density_[nPhaseIdx]);
1310 problem_.source(source, element4);
1311 this->f_[eIdxGlobal4] += volume4 / (4.0)
1312 * (source[wPhaseIdx] / density_[wPhaseIdx] + source[nPhaseIdx] / density_[nPhaseIdx]);
1314 this->f_[eIdxGlobal1] += evaluateErrorTerm_(cellData1) * volume1 / (4.0);
1315 this->f_[eIdxGlobal2] += evaluateErrorTerm_(cellData2) * volume2 / (4.0);
1316 this->f_[eIdxGlobal3] += evaluateErrorTerm_(cellData3) * volume3 / (4.0);
1317 this->f_[eIdxGlobal4] += evaluateErrorTerm_(cellData4) * volume4 / (4.0);
1320 Dune::FieldVector<Scalar, numPhases> lambda1(cellData1.mobility(wPhaseIdx));
1321 lambda1[nPhaseIdx] = cellData1.mobility(nPhaseIdx);
1324 Scalar lambdaTotal1 = lambda1[wPhaseIdx] + lambda1[nPhaseIdx];
1327 Dune::FieldVector<Scalar, numPhases> lambda2(cellData2.mobility(wPhaseIdx));
1328 lambda2[nPhaseIdx] = cellData2.mobility(nPhaseIdx);
1331 Scalar lambdaTotal2 = lambda2[wPhaseIdx] + lambda2[nPhaseIdx];
1334 Dune::FieldVector<Scalar, numPhases> lambda3(cellData3.mobility(wPhaseIdx));
1335 lambda3[nPhaseIdx] = cellData3.mobility(nPhaseIdx);
1338 Scalar lambdaTotal3 = lambda3[wPhaseIdx] + lambda3[nPhaseIdx];
1341 Dune::FieldVector<Scalar, numPhases> lambda4(cellData4.mobility(wPhaseIdx));
1342 lambda4[nPhaseIdx] = cellData4.mobility(nPhaseIdx);
1345 Scalar lambdaTotal4 = lambda4[wPhaseIdx] + lambda4[nPhaseIdx];
1347 Scalar gn12nu14 = interactionVolume.getNtkrkNu_df(lambdaTotal1, 0, 0, 1);
1348 Scalar gn12nu12 = interactionVolume.getNtkrkNu_df(lambdaTotal1, 0, 0, 0);
1349 Scalar gn14nu14 = interactionVolume.getNtkrkNu_df(lambdaTotal1, 0, 1, 1);
1350 Scalar gn14nu12 = interactionVolume.getNtkrkNu_df(lambdaTotal1, 0, 1, 0);
1351 Scalar gn12nu23 = interactionVolume.getNtkrkNu_df(lambdaTotal2, 1, 1, 0);
1352 Scalar gn12nu21 = interactionVolume.getNtkrkNu_df(lambdaTotal2, 1, 1, 1);
1353 Scalar gn23nu23 = interactionVolume.getNtkrkNu_df(lambdaTotal2, 1, 0, 0);
1354 Scalar gn23nu21 = interactionVolume.getNtkrkNu_df(lambdaTotal2, 1, 0, 1);
1355 Scalar gn43nu32 = interactionVolume.getNtkrkNu_df(lambdaTotal3, 2, 0, 1);
1356 Scalar gn43nu34 = interactionVolume.getNtkrkNu_df(lambdaTotal3, 2, 0, 0);
1357 Scalar gn23nu32 = interactionVolume.getNtkrkNu_df(lambdaTotal3, 2, 1, 1);
1358 Scalar gn23nu34 = interactionVolume.getNtkrkNu_df(lambdaTotal3, 2, 1, 0);
1359 Scalar gn43nu41 = interactionVolume.getNtkrkNu_df(lambdaTotal4, 3, 1, 0);
1360 Scalar gn43nu43 = interactionVolume.getNtkrkNu_df(lambdaTotal4, 3, 1, 1);
1361 Scalar gn14nu41 = interactionVolume.getNtkrkNu_df(lambdaTotal4, 3, 0, 0);
1362 Scalar gn14nu43 = interactionVolume.getNtkrkNu_df(lambdaTotal4, 3, 0, 1);
1365 Dune::FieldMatrix<Scalar, 2 * dim, 2 * dim> C(0), F(0), A(0), B(0);
1368 C[0][0] = -gn12nu12;
1369 C[0][3] = -gn12nu14;
1371 C[1][1] = -gn23nu23;
1374 C[3][2] = -gn14nu43;
1377 F[0][0] = gn12nu12 + gn12nu14;
1378 F[1][1] = -gn23nu21 + gn23nu23;
1379 F[2][2] = -gn43nu34 - gn43nu32;
1380 F[3][3] = gn14nu43 - gn14nu41;
1382 A[0][0] = gn12nu12 + gn12nu21;
1383 A[0][1] = -gn12nu23;
1385 A[1][0] = -gn23nu21;
1386 A[1][1] = gn23nu23 + gn23nu32;
1388 A[2][1] = -gn43nu32;
1389 A[2][2] = -gn43nu34 - gn43nu43;
1391 A[3][0] = -gn14nu12;
1393 A[3][3] = -gn14nu41 - gn14nu14;
1395 B[0][0] = gn12nu12 + gn12nu14;
1396 B[0][1] = gn12nu21 - gn12nu23;
1397 B[1][1] = -gn23nu21 + gn23nu23;
1398 B[1][2] = gn23nu34 + gn23nu32;
1399 B[2][2] = -gn43nu34 - gn43nu32;
1400 B[2][3] = -gn43nu43 + gn43nu41;
1401 B[3][0] = -gn14nu12 - gn14nu14;
1402 B[3][3] = gn14nu43 - gn14nu41;
1406 F += C.rightmultiply(B.leftmultiply(A));
1407 Dune::FieldMatrix<Scalar, 2 * dim, 2 * dim> T(F);
1412 this->A_[eIdxGlobal1][eIdxGlobal1] += T[0][0] + T[3][0];
1413 this->A_[eIdxGlobal1][eIdxGlobal2] += T[0][1] + T[3][1];
1414 this->A_[eIdxGlobal1][eIdxGlobal3] += T[0][2] + T[3][2];
1415 this->A_[eIdxGlobal1][eIdxGlobal4] += T[0][3] + T[3][3];
1417 this->A_[eIdxGlobal2][eIdxGlobal1] += -T[0][0] + T[1][0];
1418 this->A_[eIdxGlobal2][eIdxGlobal2] += -T[0][1] + T[1][1];
1419 this->A_[eIdxGlobal2][eIdxGlobal3] += -T[0][2] + T[1][2];
1420 this->A_[eIdxGlobal2][eIdxGlobal4] += -T[0][3] + T[1][3];
1422 this->A_[eIdxGlobal3][eIdxGlobal1] -= T[1][0] + T[2][0];
1423 this->A_[eIdxGlobal3][eIdxGlobal2] -= T[1][1] + T[2][1];
1424 this->A_[eIdxGlobal3][eIdxGlobal3] -= T[1][2] + T[2][2];
1425 this->A_[eIdxGlobal3][eIdxGlobal4] -= T[1][3] + T[2][3];
1427 this->A_[eIdxGlobal4][eIdxGlobal1] += T[2][0] - T[3][0];
1428 this->A_[eIdxGlobal4][eIdxGlobal2] += T[2][1] - T[3][1];
1429 this->A_[eIdxGlobal4][eIdxGlobal3] += T[2][2] - T[3][2];
1430 this->A_[eIdxGlobal4][eIdxGlobal4] += T[2][3] - T[3][3];
1432 if (innerBoundaryVolumeFaces_[eIdxGlobal1][interactionVolume.getIndexOnElement(0, 0)])
1434 this->A_[eIdxGlobal1][eIdxGlobal1] += T[0][0];
1435 this->A_[eIdxGlobal1][eIdxGlobal2] += T[0][1];
1436 this->A_[eIdxGlobal1][eIdxGlobal3] += T[0][2];
1437 this->A_[eIdxGlobal1][eIdxGlobal4] += T[0][3];
1439 if (innerBoundaryVolumeFaces_[eIdxGlobal1][interactionVolume.getIndexOnElement(0, 1)])
1441 this->A_[eIdxGlobal1][eIdxGlobal1] += T[3][0];
1442 this->A_[eIdxGlobal1][eIdxGlobal2] += T[3][1];
1443 this->A_[eIdxGlobal1][eIdxGlobal3] += T[3][2];
1444 this->A_[eIdxGlobal1][eIdxGlobal4] += T[3][3];
1447 if (innerBoundaryVolumeFaces_[eIdxGlobal2][interactionVolume.getIndexOnElement(1, 0)])
1449 this->A_[eIdxGlobal2][eIdxGlobal1] += T[1][0];
1450 this->A_[eIdxGlobal2][eIdxGlobal2] += T[1][1];
1451 this->A_[eIdxGlobal2][eIdxGlobal3] += T[1][2];
1452 this->A_[eIdxGlobal2][eIdxGlobal4] += T[1][3];
1454 if (innerBoundaryVolumeFaces_[eIdxGlobal2][interactionVolume.getIndexOnElement(1, 1)])
1456 this->A_[eIdxGlobal2][eIdxGlobal1] += -T[0][0];
1457 this->A_[eIdxGlobal2][eIdxGlobal2] += -T[0][1];
1458 this->A_[eIdxGlobal2][eIdxGlobal3] += -T[0][2];
1459 this->A_[eIdxGlobal2][eIdxGlobal4] += -T[0][3];
1461 if (innerBoundaryVolumeFaces_[eIdxGlobal3][interactionVolume.getIndexOnElement(2, 0)])
1463 this->A_[eIdxGlobal3][eIdxGlobal1] -= T[2][0];
1464 this->A_[eIdxGlobal3][eIdxGlobal2] -= T[2][1];
1465 this->A_[eIdxGlobal3][eIdxGlobal3] -= T[2][2];
1466 this->A_[eIdxGlobal3][eIdxGlobal4] -= T[2][3];
1468 if (innerBoundaryVolumeFaces_[eIdxGlobal3][interactionVolume.getIndexOnElement(2, 1)])
1470 this->A_[eIdxGlobal3][eIdxGlobal1] -= T[1][0];
1471 this->A_[eIdxGlobal3][eIdxGlobal2] -= T[1][1];
1472 this->A_[eIdxGlobal3][eIdxGlobal3] -= T[1][2];
1473 this->A_[eIdxGlobal3][eIdxGlobal4] -= T[1][3];
1475 if (innerBoundaryVolumeFaces_[eIdxGlobal4][interactionVolume.getIndexOnElement(3, 0)])
1477 this->A_[eIdxGlobal4][eIdxGlobal1] += -T[3][0];
1478 this->A_[eIdxGlobal4][eIdxGlobal2] += -T[3][1];
1479 this->A_[eIdxGlobal4][eIdxGlobal3] += -T[3][2];
1480 this->A_[eIdxGlobal4][eIdxGlobal4] += -T[3][3];
1482 if (innerBoundaryVolumeFaces_[eIdxGlobal4][interactionVolume.getIndexOnElement(3, 1)])
1484 this->A_[eIdxGlobal4][eIdxGlobal1] += T[2][0];
1485 this->A_[eIdxGlobal4][eIdxGlobal2] += T[2][1];
1486 this->A_[eIdxGlobal4][eIdxGlobal3] += T[2][2];
1487 this->A_[eIdxGlobal4][eIdxGlobal4] += T[2][3];
1492 Dune::FieldVector<Scalar, 2 * dim> pc(0);
1493 pc[0] = cellData1.capillaryPressure();
1494 pc[1] = cellData2.capillaryPressure();
1495 pc[2] = cellData3.capillaryPressure();
1496 pc[3] = cellData4.capillaryPressure();
1498 Dune::FieldVector<Scalar, 2 * dim> gravityDiff(0);
1502 gravityDiff[0] = (problem_.bBoxMax() - globalPos1) * gravity_ * (density_[nPhaseIdx] - density_[wPhaseIdx]);
1503 gravityDiff[1] = (problem_.bBoxMax() - globalPos2) * gravity_ * (density_[nPhaseIdx] - density_[wPhaseIdx]);
1504 gravityDiff[2] = (problem_.bBoxMax() - globalPos3) * gravity_ * (density_[nPhaseIdx] - density_[wPhaseIdx]);
1505 gravityDiff[3] = (problem_.bBoxMax() - globalPos4) * gravity_ * (density_[nPhaseIdx] - density_[wPhaseIdx]);
1509 if (pc[0] == 0 && pc[1] == 0 && pc[2] == 0 && pc[3] == 0)
1514 Dune::FieldVector<Scalar, 2 * dim> pcFlux(0);
1520 Scalar pcPotential12 = pcFlux[0];
1521 Scalar pcPotential14 = pcFlux[3];
1522 Scalar pcPotential32 = -pcFlux[1];
1523 Scalar pcPotential34 = -pcFlux[2];
1528 Dune::FieldVector<Scalar, numPhases> lambda12Upw(0.0);
1529 lambda12Upw[wPhaseIdx] = (pcPotential12 >= 0) ? lambda1[wPhaseIdx] : lambda2[wPhaseIdx];
1530 lambda12Upw[nPhaseIdx] = (pcPotential12 >= 0) ? lambda1[nPhaseIdx] : lambda2[nPhaseIdx];
1533 Dune::FieldVector<Scalar, numPhases> lambda14Upw(0.0);
1534 lambda14Upw[wPhaseIdx] = (pcPotential14 >= 0) ? lambda1[wPhaseIdx] : lambda4[wPhaseIdx];
1535 lambda14Upw[nPhaseIdx] = (pcPotential14 >= 0) ? lambda1[nPhaseIdx] : lambda4[nPhaseIdx];
1538 Dune::FieldVector<Scalar, numPhases> lambda32Upw(0.0);
1539 lambda32Upw[wPhaseIdx] = (pcPotential32 >= 0) ? lambda3[wPhaseIdx] : lambda2[wPhaseIdx];
1540 lambda32Upw[nPhaseIdx] = (pcPotential32 >= 0) ? lambda3[nPhaseIdx] : lambda2[nPhaseIdx];
1543 Dune::FieldVector<Scalar, numPhases> lambda34Upw(0.0);
1544 lambda34Upw[wPhaseIdx] = (pcPotential34 >= 0) ? lambda3[wPhaseIdx] : lambda4[wPhaseIdx];
1545 lambda34Upw[nPhaseIdx] = (pcPotential34 >= 0) ? lambda3[nPhaseIdx] : lambda4[nPhaseIdx];
1547 for (
int i = 0; i < numPhases; i++)
1549 Scalar lambdaT12 = lambda12Upw[wPhaseIdx] + lambda12Upw[nPhaseIdx];
1550 Scalar lambdaT14 = lambda14Upw[wPhaseIdx] + lambda14Upw[nPhaseIdx];
1551 Scalar lambdaT32 = lambda32Upw[wPhaseIdx] + lambda32Upw[nPhaseIdx];
1552 Scalar lambdaT34 = lambda34Upw[wPhaseIdx] + lambda34Upw[nPhaseIdx];
1553 Scalar fracFlow12 = (lambdaT12 > threshold_) ? lambda12Upw[i] / (lambdaT12) : 0.0;
1554 Scalar fracFlow14 = (lambdaT14 > threshold_) ? lambda14Upw[i] / (lambdaT14) : 0.0;
1555 Scalar fracFlow32 = (lambdaT32 > threshold_) ? lambda32Upw[i] / (lambdaT32) : 0.0;
1556 Scalar fracFlow34 = (lambdaT34 > threshold_) ? lambda34Upw[i] / (lambdaT34) : 0.0;
1558 Dune::FieldVector<Scalar, 2 * dim> pcFluxReal(pcFlux);
1560 pcFluxReal[0] *= fracFlow12;
1561 pcFluxReal[1] *= fracFlow32;
1562 pcFluxReal[2] *= fracFlow34;
1563 pcFluxReal[3] *= fracFlow14;
1569 switch (pressureType_)
1576 this->f_[eIdxGlobal1] -= (pcFluxReal[0] + pcFluxReal[3]);
1577 this->f_[eIdxGlobal2] -= (pcFluxReal[1] - pcFluxReal[0]);
1578 this->f_[eIdxGlobal3] -= (-pcFluxReal[2] - pcFluxReal[1]);
1579 this->f_[eIdxGlobal4] -= (-pcFluxReal[3] + pcFluxReal[2]);
1581 if (innerBoundaryVolumeFaces_[eIdxGlobal1][interactionVolume.getIndexOnElement(0, 0)])
1583 this->f_[eIdxGlobal1] -= pcFluxReal[0];
1585 if (innerBoundaryVolumeFaces_[eIdxGlobal1][interactionVolume.getIndexOnElement(0, 1)])
1587 this->f_[eIdxGlobal1] -= pcFluxReal[3];
1589 if (innerBoundaryVolumeFaces_[eIdxGlobal2][interactionVolume.getIndexOnElement(1, 0)])
1591 this->f_[eIdxGlobal2] -= pcFluxReal[1];
1593 if (innerBoundaryVolumeFaces_[eIdxGlobal2][interactionVolume.getIndexOnElement(1, 1)])
1595 this->f_[eIdxGlobal2] += pcFluxReal[0];
1597 if (innerBoundaryVolumeFaces_[eIdxGlobal3][interactionVolume.getIndexOnElement(2, 0)])
1599 this->f_[eIdxGlobal3] += pcFluxReal[2];
1601 if (innerBoundaryVolumeFaces_[eIdxGlobal3][interactionVolume.getIndexOnElement(2, 1)])
1603 this->f_[eIdxGlobal3] += pcFluxReal[1];
1605 if (innerBoundaryVolumeFaces_[eIdxGlobal4][interactionVolume.getIndexOnElement(3, 0)])
1607 this->f_[eIdxGlobal4] += pcFluxReal[3];
1609 if (innerBoundaryVolumeFaces_[eIdxGlobal4][interactionVolume.getIndexOnElement(3, 1)])
1611 this->f_[eIdxGlobal4] -= pcFluxReal[2];
1621 this->f_[eIdxGlobal1] += (pcFluxReal[0] + pcFluxReal[1]);
1622 this->f_[eIdxGlobal2] += (pcFluxReal[1] - pcFluxReal[0]);
1623 this->f_[eIdxGlobal3] += (-pcFluxReal[2] - pcFluxReal[1]);
1624 this->f_[eIdxGlobal4] += (-pcFluxReal[3] + pcFluxReal[2]);
1626 if (innerBoundaryVolumeFaces_[eIdxGlobal1][interactionVolume.getIndexOnElement(0, 0)])
1628 this->f_[eIdxGlobal1] += pcFluxReal[0];
1630 if (innerBoundaryVolumeFaces_[eIdxGlobal1][interactionVolume.getIndexOnElement(0, 1)])
1632 this->f_[eIdxGlobal1] += pcFluxReal[3];
1634 if (innerBoundaryVolumeFaces_[eIdxGlobal2][interactionVolume.getIndexOnElement(1, 0)])
1636 this->f_[eIdxGlobal2] += pcFluxReal[1];
1638 if (innerBoundaryVolumeFaces_[eIdxGlobal2][interactionVolume.getIndexOnElement(1, 1)])
1640 this->f_[eIdxGlobal2] -= pcFluxReal[0];
1642 if (innerBoundaryVolumeFaces_[eIdxGlobal3][interactionVolume.getIndexOnElement(2, 0)])
1644 this->f_[eIdxGlobal3] -= pcFluxReal[2];
1646 if (innerBoundaryVolumeFaces_[eIdxGlobal3][interactionVolume.getIndexOnElement(2, 1)])
1648 this->f_[eIdxGlobal3] -= pcFluxReal[1];
1650 if (innerBoundaryVolumeFaces_[eIdxGlobal4][interactionVolume.getIndexOnElement(3, 0)])
1652 this->f_[eIdxGlobal4] -= pcFluxReal[3];
1654 if (innerBoundaryVolumeFaces_[eIdxGlobal4][interactionVolume.getIndexOnElement(3, 1)])
1656 this->f_[eIdxGlobal4] += pcFluxReal[2];
1668 for (
int elemIdx = 0; elemIdx < 2 * dim; elemIdx++)
1670 bool isOutside =
false;
1671 for (
int fIdx = 0; fIdx < dim; fIdx++)
1673 int intVolFaceIdx = interactionVolume.getFaceIndexFromSubVolume(elemIdx, fIdx);
1674 if (interactionVolume.isOutsideFace(intVolFaceIdx))
1685 auto element = interactionVolume.getSubVolumeElement(elemIdx);
1688 const GlobalPosition& globalPos = element.geometry().center();
1691 Scalar volume = element.geometry().volume();
1694 int eIdxGlobal = problem_.variables().index(element);
1697 CellData& cellData = problem_.variables().cellData(eIdxGlobal);
1700 DimMatrix
permeability(problem_.spatialParams().intrinsicPermeability(element));
1703 PrimaryVariables source(0);
1704 problem_.source(source, element);
1705 this->f_[eIdxGlobal] += volume / (4.0)
1706 * (source[wPhaseIdx] / density_[wPhaseIdx] + source[nPhaseIdx] / density_[nPhaseIdx]);
1708 this->f_[eIdxGlobal] += evaluateErrorTerm_(cellData) * volume / (4.0);
1711 Dune::FieldVector<Scalar, numPhases> lambda(cellData.mobility(wPhaseIdx));
1712 lambda[nPhaseIdx] = cellData.mobility(nPhaseIdx);
1714 Scalar pc = cellData.capillaryPressure();
1716 Scalar gravityDiff = (problem_.bBoxMax() - globalPos) * gravity_
1717 * (density_[nPhaseIdx] - density_[wPhaseIdx]);
1721 for (
int fIdx = 0; fIdx < dim; fIdx++)
1723 int intVolFaceIdx = interactionVolume.getFaceIndexFromSubVolume(elemIdx, fIdx);
1725 if (interactionVolume.isBoundaryFace(intVolFaceIdx))
1728 if (interactionVolume.getBoundaryType(intVolFaceIdx).isDirichlet(pressEqIdx))
1730 int boundaryFaceIdx = interactionVolume.getIndexOnElement(elemIdx, fIdx);
1732 const auto refElement = referenceElement(element);
1734 const LocalPosition& localPos = refElement.position(boundaryFaceIdx, 1);
1736 const GlobalPosition& globalPosFace = element.geometry().global(localPos);
1738 DimVector distVec(globalPosFace - globalPos);
1739 Scalar dist = distVec.two_norm();
1740 DimVector unitDistVec(distVec);
1741 unitDistVec /= dist;
1743 Scalar faceArea = interactionVolume.getFaceArea(elemIdx, fIdx);
1746 Scalar satWBound = cellData.saturation(wPhaseIdx);
1748 if (interactionVolume.getBoundaryType(intVolFaceIdx).isDirichlet(satEqIdx))
1750 Scalar satBound = interactionVolume.getDirichletValues(intVolFaceIdx)[saturationIdx];
1751 switch (saturationType_)
1755 satWBound = satBound;
1760 satWBound = 1 - satBound;
1770 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem_.spatialParams(), element);
1772 Scalar pcBound = fluidMatrixInteraction.pc(satWBound);
1774 Scalar gravityDiffBound = (problem_.bBoxMax() - globalPosFace) * gravity_
1775 * (density_[nPhaseIdx] - density_[wPhaseIdx]);
1777 pcBound += gravityDiffBound;
1779 Dune::FieldVector<Scalar, numPhases> lambdaBound(fluidMatrixInteraction.krw(satWBound));
1780 lambdaBound[nPhaseIdx] = fluidMatrixInteraction.krn(satWBound);
1781 lambdaBound[wPhaseIdx] /= viscosity_[wPhaseIdx];
1782 lambdaBound[nPhaseIdx] /= viscosity_[nPhaseIdx];
1784 Scalar potentialBound = interactionVolume.getDirichletValues(intVolFaceIdx)[pressureIdx];
1785 Scalar gdeltaZ = (problem_.bBoxMax()-globalPosFace) * gravity_;
1788 Scalar potentialDiffW = 0;
1789 Scalar potentialDiffNw = 0;
1790 switch (pressureType_)
1794 potentialBound += density_[wPhaseIdx]*gdeltaZ;
1795 potentialDiffW = (cellData.potential(wPhaseIdx) - potentialBound) / dist;
1796 potentialDiffNw = (cellData.potential(nPhaseIdx) - potentialBound - pcBound) / dist;
1801 potentialBound += density_[nPhaseIdx]*gdeltaZ;
1802 potentialDiffW = (cellData.potential(wPhaseIdx) - potentialBound + pcBound) / dist;
1803 potentialDiffNw = (cellData.potential(nPhaseIdx) - potentialBound) / dist;
1808 Scalar lambdaTotal = (potentialDiffW >= 0.) ? lambda[wPhaseIdx] : lambdaBound[wPhaseIdx];
1809 lambdaTotal += (potentialDiffNw >= 0.) ? lambda[nPhaseIdx] : lambdaBound[nPhaseIdx];
1811 DimVector permTimesNormal(0);
1815 Scalar entry = lambdaTotal * (unitDistVec * permTimesNormal) / dist * faceArea;
1820 switch (pressureType_)
1825 DimVector pcGradient = unitDistVec;
1826 pcGradient *= (pc - pcBound) / dist;
1829 pcFlux = 0.5 * (lambda[nPhaseIdx] + lambdaBound[nPhaseIdx])
1830 * (permTimesNormal * pcGradient) * faceArea;
1837 DimVector pcGradient = unitDistVec;
1838 pcGradient *= (pc - pcBound) / dist;
1841 pcFlux = 0.5 * (lambda[wPhaseIdx] + lambdaBound[wPhaseIdx])
1842 * (permTimesNormal * pcGradient) * faceArea;
1850 this->A_[eIdxGlobal][eIdxGlobal] += entry;
1851 this->f_[eIdxGlobal] += entry * potentialBound;
1853 if (pc == 0 && pcBound == 0)
1858 for (
int i = 0; i < numPhases; i++)
1860 switch (pressureType_)
1867 this->f_[eIdxGlobal] -= pcFlux;
1876 this->f_[eIdxGlobal] += pcFlux;
1884 else if (interactionVolume.getBoundaryType(intVolFaceIdx).isNeumann(pressEqIdx))
1886 Scalar J = interactionVolume.getNeumannValues(intVolFaceIdx)[wPhaseIdx]
1887 / density_[wPhaseIdx];
1888 J += interactionVolume.getNeumannValues(intVolFaceIdx)[nPhaseIdx] / density_[nPhaseIdx];
1889 this->f_[eIdxGlobal] -= J;
1893 std::cout <<
"interactionVolume.getBoundaryType(intVolFaceIdx).isNeumann(pressEqIdx)"
1894 << interactionVolume.getBoundaryType(intVolFaceIdx).isNeumann(pressEqIdx) <<
"\n";
1895 DUNE_THROW(Dune::NotImplemented,
1896 "No valid boundary condition type defined for pressure equation!");
1907 if (problem_.gridView().comm().size() > 1)
1910 for (
const auto& element : elements(problem_.gridView()))
1912 if (element.partitionType() == Dune::InteriorEntity)
1916 int eIdxGlobalI = problem_.variables().index(element);
1918 this->A_[eIdxGlobalI] = 0.0;
1919 this->A_[eIdxGlobalI][eIdxGlobalI] = 1.0;
1920 this->f_[eIdxGlobalI] = this->
pressure()[eIdxGlobalI];
1933template<
class TypeTag>
1937 for (
const auto& element : elements(problem_.gridView()))
1939 int eIdxGlobal = problem_.variables().index(element);
1941 CellData& cellData = problem_.variables().cellData(eIdxGlobal);
1943 const Scalar satW = cellData.saturation(wPhaseIdx);
1948 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem_.spatialParams(), element);
1950 const Scalar pc = fluidMatrixInteraction.pc(satW);
1952 cellData.setCapillaryPressure(pc);
1955 const Scalar mobilityW = fluidMatrixInteraction.krw(satW) / viscosity_[wPhaseIdx];
1956 const Scalar mobilityNw = fluidMatrixInteraction.krn(satW) / viscosity_[nPhaseIdx];
1959 cellData.setMobility(wPhaseIdx, mobilityW);
1960 cellData.setMobility(nPhaseIdx, mobilityNw);
1963 cellData.setFracFlowFunc(wPhaseIdx, mobilityW / (mobilityW + mobilityNw));
1964 cellData.setFracFlowFunc(nPhaseIdx, mobilityNw / (mobilityW + mobilityNw));
Class including the information of an interaction volume of a MPFA O-method that does not change with...
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 pressure(int phaseIdx) noexcept
I/O name of pressure for multiphase systems.
Definition: name.hh:34
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:65
Finite volume MPFA O-method discretization of a two-phase flow pressure equation of the sequential IM...
Definition: omethod/2dpressure.hh:69
void updateMaterialLaws()
Constitutive functions are initialized and stored in the variables object.
Definition: omethod/2dpressure.hh:1934
GlobalInteractionVolumeVector interactionVolumes_
Definition: omethod/2dpressure.hh:482
void storePressureSolution(const Element &element)
Stores the pressure solution of a cell.
Definition: omethod/2dpressure.hh:267
InnerBoundaryVolumeFaces innerBoundaryVolumeFaces_
Definition: omethod/2dpressure.hh:483
void updateInteractionVolumeInfo()
Updates interaction volumes.
Definition: omethod/2dpressure.hh:160
void addOutputVtkFields(MultiWriter &writer)
Adds pressure output to the output file.
Definition: omethod/2dpressure.hh:326
void update()
Pressure update.
Definition: omethod/2dpressure.hh:212
void initialize()
Initializes the pressure model.
Definition: omethod/2dpressure.hh:176
void storePressureSolution()
Globally stores the pressure solution.
Definition: omethod/2dpressure.hh:253
FvMpfaO2dPressure2p(Problem &problem)
Constructs a FvMpfaO2dPressure2p object.
Definition: omethod/2dpressure.hh:396
Class including the information of an interaction volume of a MPFA O-method that does not change with...
Definition: ointeractionvolume.hh:38
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
PressureSolution & pressure()
Returns the vector containing the pressure solution.
Definition: sequential/cellcentered/pressure.hh:120
void solve()
Solves the global system of equations to get the spatial distribution of the pressure.
Definition: sequential/cellcentered/pressure.hh:527
Specifies the properties for immiscible 2p diffusion/pressure models.
Properties for a MPFA method.
Finite Volume Diffusion Model.