3.1-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
l2norm.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
25#ifndef DUMUX_TEST_L2_NORM_HH
26#define DUMUX_TEST_L2_NORM_HH
27
28#include <cmath>
29#include <type_traits>
30#include <dune/geometry/quadraturerules.hh>
34
35namespace Dumux {
36
37template<class Scalar>
38struct L2Norm
39{
41 template<class Problem, class Solution>
42 static Scalar computeErrorNorm(const Problem &problem, const Solution& sol, int order)
43 {
44 // calculate the L2-Norm and hmax
45 Scalar norm = 0.0;
46
47 // iterate over all elements
48 const auto& gg = problem.gridGeometry();
49 for (const auto& element : elements(gg.gridView()))
50 {
51 const auto geometry = element.geometry();
52 const auto center = geometry.center();
53 const auto elemSol = elementSolution(element, sol, gg);
54
55 // maybe exclude some elements from the norm
56 static const bool excludeInnerBulk = getParam<bool>("Problem.NormExcludeInnerBulk");
57 static const Scalar radius = getParam<Scalar>("SpatialParams.Radius") + 0.01;
58 using GridView = std::decay_t<decltype(gg.gridView())>;
59 if (int(GridView::dimension) == 3 && excludeInnerBulk && std::sqrt(center[0]*center[0] + center[1]*center[1]) < radius)
60 continue;
61
62 const auto& quad = Dune::QuadratureRules<Scalar, GridView::dimension>::rule(geometry.type(), order);
63 for(auto&& qp : quad)
64 {
65 const auto globalPos = geometry.global(qp.position());
66 const Scalar pe = problem.exactSolution(globalPos);
67 const Scalar p = evalSolution(element, geometry, gg, elemSol, globalPos)[0];
68 norm += (p - pe)*(p - pe)*qp.weight()*geometry.integrationElement(qp.position());
69 }
70 }
71
72 return std::sqrt(norm);
73 }
74
75 template<class Problem>
76 static Scalar computeNormalization(const Problem &problem, int order)
77 {
78 // calculate the L2-Norm of the exact solution vector
79 Scalar norm = 0.0;
80
81 // iterate over all elements
82 const auto& gg = problem.gridGeometry();
83 for (const auto& element : elements(gg.gridView()))
84 {
85 const auto geometry = element.geometry();
86 const auto center = geometry.center();
87
88 // maybe exclude some elements from the norm
89 static const bool excludeInnerBulk = getParam<bool>("Problem.NormExcludeInnerBulk");
90 static const Scalar radius = getParam<Scalar>("SpatialParams.Radius") + 0.01;
91 using GridView = std::decay_t<decltype(gg.gridView())>;
92 if (int(GridView::dimension) == 3 && excludeInnerBulk && std::sqrt(center[0]*center[0] + center[1]*center[1]) < radius)
93 continue;
94
95 const auto& quad = Dune::QuadratureRules<Scalar, GridView::dimension>::rule(geometry.type(), order);
96 for(auto&& qp : quad)
97 {
98 const auto globalPos = geometry.global(qp.position());
99 const Scalar pe = problem.exactSolution(globalPos);
100 norm += pe*pe*qp.weight()*geometry.integrationElement(qp.position());
101 }
102 }
103
104 return std::sqrt(norm);
105 }
106};
107
108} // end namespace Dumux
109
110#endif
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
Element solution classes and factory functions.
free functions for the evaluation of primary variables inside elements.
PrimaryVariables evalSolution(const Element &element, const typename Element::Geometry &geometry, const typename FVElementGeometry::GridGeometry &gridGeometry, const BoxElementSolution< FVElementGeometry, PrimaryVariables > &elemSol, const typename Element::Geometry::GlobalCoordinate &globalPos, bool ignoreState=false)
Interpolates a given box element solution at a given global position. Uses the finite element cache o...
Definition: evalsolution.hh:95
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethod::box, BoxElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for box schemes.
Definition: box/elementsolution.hh:115
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
Definition: l2norm.hh:39
static Scalar computeErrorNorm(const Problem &problem, const Solution &sol, int order)
Calculate the L2-Norm of the solution and hmax of the grid.
Definition: l2norm.hh:42
static Scalar computeNormalization(const Problem &problem, int order)
Definition: l2norm.hh:76