GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/test/multidomain/embedded/1d3d/1p_1p/l2norm.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 22 22 100.0%
Functions: 4 4 100.0%
Branches: 10 12 83.3%

Line Branch Exec Source
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 // SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 /*!
8 * \file
9 * \ingroup EmbeddedTests
10 * \brief Helper functions to compute L2-norm.
11 */
12
13 #ifndef DUMUX_TEST_L2_NORM_HH
14 #define DUMUX_TEST_L2_NORM_HH
15
16 #include <cmath>
17 #include <type_traits>
18 #include <dune/geometry/quadraturerules.hh>
19 #include <dumux/common/parameters.hh>
20 #include <dumux/discretization/elementsolution.hh>
21 #include <dumux/discretization/evalsolution.hh>
22
23 namespace Dumux {
24
25 template<class Scalar>
26 struct L2Norm
27 {
28 //! Calculate the L2-Norm of the solution and hmax of the grid
29 template<class Problem, class Solution>
30 76 static Scalar computeErrorNorm(const Problem &problem, const Solution& sol, int order)
31 {
32 // calculate the L2-Norm and hmax
33 76 Scalar norm = 0.0;
34
35 // iterate over all elements
36 76 const auto& gg = problem.gridGeometry();
37
4/4
✓ Branch 2 taken 931602 times.
✓ Branch 3 taken 19 times.
✓ Branch 4 taken 365 times.
✓ Branch 5 taken 19 times.
3725754 for (const auto& element : elements(gg.gridView()))
38 {
39 1863166 const auto geometry = element.geometry();
40 1863166 const auto elemSol = elementSolution(element, sol, gg);
41
42 using GridView = std::decay_t<decltype(gg.gridView())>;
43 3725602 const auto& quad = Dune::QuadratureRules<Scalar, GridView::dimension>::rule(geometry.type(), order);
44
4/4
✓ Branch 0 taken 931583 times.
✓ Branch 1 taken 931583 times.
✓ Branch 2 taken 931583 times.
✓ Branch 3 taken 931583 times.
9315830 for(auto&& qp : quad)
45 {
46 3726332 const auto globalPos = geometry.global(qp.position());
47
1/2
✓ Branch 1 taken 13718 times.
✗ Branch 2 not taken.
1863166 const Scalar pe = problem.exactSolution(globalPos);
48
1/2
✓ Branch 1 taken 13718 times.
✗ Branch 2 not taken.
1863166 const Scalar p = evalSolution(element, geometry, gg, elemSol, globalPos)[0];
49 5589498 norm += (p - pe)*(p - pe)*qp.weight()*geometry.integrationElement(qp.position());
50 }
51 }
52
53 76 return std::sqrt(norm);
54 }
55
56 template<class Problem>
57 38 static Scalar computeNormalization(const Problem &problem, int order)
58 {
59 // calculate the L2-Norm of the exact solution vector
60 38 Scalar norm = 0.0;
61
62 // iterate over all elements
63 38 const auto& gg = problem.gridGeometry();
64 1862877 for (const auto& element : elements(gg.gridView()))
65 {
66 931583 const auto geometry = element.geometry();
67 using GridView = std::decay_t<decltype(gg.gridView())>;
68
69 1862801 const auto& quad = Dune::QuadratureRules<Scalar, GridView::dimension>::rule(geometry.type(), order);
70 4657915 for (auto&& qp : quad)
71 2794749 norm += 1.0*qp.weight()*geometry.integrationElement(qp.position());
72 }
73
74 38 return norm;
75 }
76 };
77
78 } // end namespace Dumux
79
80 #endif
81