20#ifndef DUMUX_BENCHMARKRESULT_HH
21#define DUMUX_BENCHMARKRESULT_HH
70 template<
class Gr
idView,
class Problem>
72 Problem& problem,
bool consecutiveNumbering =
false)
74 using Grid =
typename GridView::Grid;
75 using Scalar =
typename Grid::ctype;
76 enum {dim=Grid::dimension};
77 using Element =
typename Grid::template Codim<0>::Entity;
78 using Geometry =
typename Element::Geometry;
79 using JacobianInverseTransposed =
typename Geometry::JacobianInverseTransposed;
96 Scalar denominator = 0;
97 double numeratorGrad = 0;
98 double denominatorGrad = 0;
99 double numeratorFlux = 0;
100 double denominatorFlux = 0;
101 for (
const auto& element : elements(gridView))
104 const Geometry& geometry = element.geometry();
105 Dune::GeometryType geomType = geometry.type();
106 using ReferenceElements = Dune::ReferenceElements<Scalar, dim>;
107 const Dune::FieldVector<Scalar,dim>& local = ReferenceElements::general(geomType).position(0, 0);
108 Dune::FieldVector<Scalar,dim> globalPos = geometry.global(local);
110 Scalar volume = geometry.volume();
112 int elemIdx = problem.variables().index(element);
114 Scalar approxPressure = problem.variables().cellData(elemIdx).globalPressure();
115 Scalar exactPressure = problem.exact(globalPos);
117 numerator += volume*(approxPressure - exactPressure)*(approxPressure - exactPressure);
118 denominator += volume*exactPressure*exactPressure;
126 typename Problem::PrimaryVariables sourceVec;
127 problem.source(sourceVec, element);
128 sumf += volume*sourceVec[0];
131 Dune::FieldMatrix<double,dim,dim> K = problem.spatialParams().intrinsicPermeability(element);
134 Dune::FieldVector<Scalar,2*dim> fluxVector;
135 Dune::FieldVector<Scalar,dim> exactGradient;
136 for (
const auto& intersection :
intersections(gridView, element))
139 int fIdx = intersection.indexInInside();
141 if (consecutiveNumbering)
146 Dune::FieldVector<double,dim> faceGlobal = intersection.geometry().center();
147 double faceVol = intersection.geometry().volume();
150 Dune::FieldVector<double,dim> unitOuterNormal = intersection.centerUnitOuterNormal();
153 exactGradient = problem.exactGrad(faceGlobal);
156 Dune::FieldVector<double,dim> KGrad(0);
157 K.umv(exactGradient, KGrad);
160 double exactFlux = KGrad*unitOuterNormal;
163 double approximateFlux = problem.variables().cellData(elemIdx).fluxData().velocityTotal(isIdx)*unitOuterNormal;
166 double fluxDiff = exactFlux + approximateFlux;
172 numeratorFlux += volume*fluxDiff*fluxDiff;
173 denominatorFlux += volume*exactFlux*exactFlux;
176 exactFlux *= faceVol;
177 approximateFlux *= faceVol;
178 fluxVector[fIdx] = approximateFlux;
180 if (!intersection.neighbor()) {
181 if (abs(faceGlobal[1]) < 1e-6) {
182 fluy0 += approximateFlux;
185 else if (abs(faceGlobal[1] - 1.0) < 1e-6) {
186 fluy1 += approximateFlux;
189 else if (faceGlobal[0] < 1e-6) {
190 flux0 += approximateFlux;
193 else if (abs(faceGlobal[0] - 1.0) < 1e-6) {
194 flux1 += approximateFlux;
202 Dune::FieldVector<Scalar, dim> refVelocity;
204 if (geometry.type().isSimplex()) {
205 for (
int dimIdx = 0; dimIdx < dim; dimIdx++)
207 refVelocity[dimIdx] = -fluxVector[dim - 1 - dimIdx];
208 for (
int fIdx = 0; fIdx < dim + 1; fIdx++)
210 refVelocity[dimIdx] += fluxVector[fIdx]/(dim + 1);
215 else if (geometry.type().isCube()){
216 for (
int i = 0; i < dim; i++)
217 refVelocity[i] = 0.5 * (fluxVector[2*i + 1] - fluxVector[2*i]);
221 DUNE_THROW(Dune::NotImplemented,
"velocity output for prism/pyramid not implemented");
225 const JacobianInverseTransposed& jacobianInv = geometry.jacobianInverseTransposed(local);
226 JacobianInverseTransposed jacobianT(jacobianInv);
230 Dune::FieldVector<Scalar,dim> elementVelocity(0);
231 jacobianT.umtv(refVelocity, elementVelocity);
232 elementVelocity /= geometry.integrationElement(local);
235 Dune::FieldVector<Scalar,dim> approximateGradient;
236 K.solve(approximateGradient, elementVelocity);
239 exactGradient = problem.exactGrad(globalPos);
242 Dune::FieldVector<Scalar,dim> gradDiff(exactGradient);
243 gradDiff += approximateGradient;
246 ener1 += volume*(approximateGradient*elementVelocity);
248 numeratorGrad += volume*(gradDiff*gradDiff);
249 denominatorGrad += volume*(exactGradient*exactGradient);
255 ergrad = sqrt(numeratorGrad/denominatorGrad);
256 ervell2 = sqrt(numeratorFlux/denominatorFlux);
Base class for definition of an sequential diffusion (pressure) or transport problem.
Dune::IteratorRange< typename MultiDomainGlue< DomainGridView, TargetGridView, DomainMapper, TargetMapper >::Intersections::const_iterator > intersections(const MultiDomainGlue< DomainGridView, TargetGridView, DomainMapper, TargetMapper > &glue)
Range generator to iterate with range-based for loops over all intersections as follows: for (const a...
Definition: glue.hh:62
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
Calculate errors for the diffusion test problem.
Definition: resultevaluation.hh:38
double ener1
Definition: resultevaluation.hh:60
double relativeL2Error
Definition: resultevaluation.hh:40
double fluy0
Definition: resultevaluation.hh:47
double uMin
Definition: resultevaluation.hh:43
double exactflux1
Definition: resultevaluation.hh:52
double errfly0
Definition: resultevaluation.hh:57
double ervell2
Definition: resultevaluation.hh:42
double sumf
Definition: resultevaluation.hh:49
void evaluate(const GridView &gridView, Problem &problem, bool consecutiveNumbering=false)
Calculate errors for the diffusion test problem.
Definition: resultevaluation.hh:71
double flux0
Definition: resultevaluation.hh:45
double erflm
Definition: resultevaluation.hh:59
double fluy1
Definition: resultevaluation.hh:48
double ergrad
Definition: resultevaluation.hh:41
double errfly1
Definition: resultevaluation.hh:58
double errflx0
Definition: resultevaluation.hh:55
double exactflux0
Definition: resultevaluation.hh:51
double sumflux
Definition: resultevaluation.hh:50
double errflx1
Definition: resultevaluation.hh:56
double exactfluy1
Definition: resultevaluation.hh:54
double uMax
Definition: resultevaluation.hh:44
double flux1
Definition: resultevaluation.hh:46
double exactfluy0
Definition: resultevaluation.hh:53