181 const auto element = *problem_.gridView().template begin<0>();
182 FluidState fluidState;
183 fluidState.setPressure(wPhaseIdx, problem_.referencePressure(element));
184 fluidState.setPressure(nPhaseIdx, problem_.referencePressure(element));
185 fluidState.setTemperature(problem_.temperature(element));
186 fluidState.setSaturation(wPhaseIdx, 1.);
187 fluidState.setSaturation(nPhaseIdx, 0.);
188 density_[wPhaseIdx] = FluidSystem::density(fluidState, wPhaseIdx);
189 density_[nPhaseIdx] = FluidSystem::density(fluidState, nPhaseIdx);
190 viscosity_[wPhaseIdx] = FluidSystem::viscosity(fluidState, wPhaseIdx);
191 viscosity_[nPhaseIdx] = FluidSystem::viscosity(fluidState, nPhaseIdx);
195 lstiff_.initialize();
254 int size = problem_.gridView().size(0);
255 ScalarSolutionType *potential = writer.allocateManagedBuffer(size);
256 ScalarSolutionType *pressure = 0;
257 ScalarSolutionType *pressureSecond = 0;
258 ScalarSolutionType *potentialSecond = 0;
259 Dune::BlockVector < DimVector > *velocityWetting = 0;
260 Dune::BlockVector < DimVector > *velocityNonwetting = 0;
262 if (vtkOutputLevel_ > 0)
264 pressure = writer.allocateManagedBuffer(size);
265 pressureSecond = writer.allocateManagedBuffer(size);
266 potentialSecond = writer.allocateManagedBuffer(size);
267 velocityWetting = writer.template allocateManagedBuffer<Scalar, dim>(size);
268 velocityNonwetting = writer.template allocateManagedBuffer<Scalar, dim>(size);
272 for (
const auto& element : elements(problem_.gridView()))
274 int eIdxGlobal = problem_.variables().index(element);
275 CellData& cellData = problem_.variables().cellData(eIdxGlobal);
277 if (pressureType == pw)
279 (*potential)[eIdxGlobal] = cellData.potential(wPhaseIdx);
282 if (pressureType == pn)
284 (*potential)[eIdxGlobal] = cellData.potential(nPhaseIdx);
287 if (vtkOutputLevel_ > 0)
290 if (pressureType == pw)
292 (*pressure)[eIdxGlobal] = cellData.pressure(wPhaseIdx);
293 (*potentialSecond)[eIdxGlobal] = cellData.potential(nPhaseIdx);
294 (*pressureSecond)[eIdxGlobal] = cellData.pressure(nPhaseIdx);
297 if (pressureType == pn)
299 (*pressure)[eIdxGlobal] = cellData.pressure(nPhaseIdx);
300 (*potentialSecond)[eIdxGlobal] = cellData.potential(wPhaseIdx);
301 (*pressureSecond)[eIdxGlobal] = cellData.pressure(wPhaseIdx);
304 const typename Element::Geometry& geometry = element.geometry();
307 using ReferenceElements = Dune::ReferenceElements<Scalar, dim>;
308 const auto refElement = ReferenceElements::general(geometry.type());
310 const int numberOfFaces=refElement.size(1);
311 std::vector<Scalar> fluxW(numberOfFaces,0);
312 std::vector<Scalar> fluxNw(numberOfFaces,0);
315 for (
const auto& intersection :
intersections(problem_.gridView(), element))
317 int isIndex = intersection.indexInInside();
319 fluxW[isIndex] += intersection.geometry().volume()
320 * (intersection.centerUnitOuterNormal() * cellData.fluxData().velocity(wPhaseIdx, isIndex));
321 fluxNw[isIndex] += intersection.geometry().volume()
322 * (intersection.centerUnitOuterNormal() * cellData.fluxData().velocity(nPhaseIdx, isIndex));
327 Dune::FieldVector<Scalar, dim> refVelocity;
329 if (refElement.type().isSimplex()) {
330 for (
int dimIdx = 0; dimIdx < dim; dimIdx++)
332 refVelocity[dimIdx] = -fluxW[dim - 1 - dimIdx];
333 for (
int fIdx = 0; fIdx < dim + 1; fIdx++)
335 refVelocity[dimIdx] += fluxW[fIdx]/(dim + 1);
340 else if (refElement.type().isCube()){
341 for (
int i = 0; i < dim; i++)
342 refVelocity[i] = 0.5 * (fluxW[2*i + 1] - fluxW[2*i]);
346 DUNE_THROW(Dune::NotImplemented,
"velocity output for prism/pyramid not implemented");
349 const DimVector& localPos = refElement.position(0, 0);
352 const JacobianTransposed jacobianT = geometry.jacobianTransposed(localPos);
355 DimVector elementVelocity(0);
356 jacobianT.umtv(refVelocity, elementVelocity);
357 elementVelocity /= geometry.integrationElement(localPos);
359 (*velocityWetting)[eIdxGlobal] = elementVelocity;
364 if (refElement.type().isSimplex()) {
365 for (
int dimIdx = 0; dimIdx < dim; dimIdx++)
367 refVelocity[dimIdx] = -fluxNw[dim - 1 - dimIdx];
368 for (
int fIdx = 0; fIdx < dim + 1; fIdx++)
370 refVelocity[dimIdx] += fluxNw[fIdx]/(dim + 1);
375 else if (refElement.type().isCube()){
376 for (
int i = 0; i < dim; i++)
377 refVelocity[i] = 0.5 * (fluxNw[2*i + 1] - fluxNw[2*i]);
381 DUNE_THROW(Dune::NotImplemented,
"velocity output for prism/pyramid not implemented");
386 jacobianT.umtv(refVelocity, elementVelocity);
387 elementVelocity /= geometry.integrationElement(localPos);
389 (*velocityNonwetting)[eIdxGlobal] = elementVelocity;
393 if (pressureType == pw)
395 writer.attachCellData(*potential,
"wetting potential");
398 if (pressureType == pn)
400 writer.attachCellData(*potential,
"nonwetting potential");
403 if (vtkOutputLevel_ > 0)
405 if (pressureType == pw)
407 writer.attachCellData(*pressure,
"wetting pressure");
408 writer.attachCellData(*pressureSecond,
"nonwetting pressure");
409 writer.attachCellData(*potentialSecond,
"nonwetting potential");
412 if (pressureType == pn)
414 writer.attachCellData(*pressure,
"nonwetting pressure");
415 writer.attachCellData(*pressureSecond,
"wetting pressure");
416 writer.attachCellData(*potentialSecond,
"wetting potential");
419 writer.attachCellData(*velocityWetting,
"wetting-velocity", dim);
420 writer.attachCellData(*velocityNonwetting,
"non-wetting-velocity", dim);