GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/test/multidomain/embedded/1d3d/1p_1p/l2norm.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 22 22 100.0%
Functions: 4 4 100.0%
Branches: 8 12 66.7%

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-FileCopyrightText: 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
3/4
✓ Branch 2 taken 931602 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 365 times.
✓ Branch 6 taken 19 times.
5588844 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
1/2
✓ Branch 1 taken 365 times.
✗ Branch 2 not taken.
1863166 const auto& quad = Dune::QuadratureRules<Scalar, GridView::dimension>::rule(geometry.type(), order);
44
2/2
✓ Branch 0 taken 931583 times.
✓ Branch 1 taken 931583 times.
3726332 for(auto&& qp : quad)
45 {
46
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
1863896 const auto globalPos = geometry.global(qp.position());
47
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
1863166 const Scalar pe = problem.exactSolution(globalPos);
48 1863166 const Scalar p = evalSolution(element, geometry, gg, elemSol, globalPos)[0];
49 3725602 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 2794422 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 931583 const auto& quad = Dune::QuadratureRules<Scalar, GridView::dimension>::rule(geometry.type(), order);
70 1863166 for (auto&& qp : quad)
71 1862801 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