GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/discretization/cvfe/elementsolution.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 30 30 100.0%
Functions: 121 122 99.2%
Branches: 61 87 70.1%

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 CVFEDiscretization
10 * \brief The local element solution class for control-volume finite element methods
11 */
12 #ifndef DUMUX_CVFE_ELEMENT_SOLUTION_HH
13 #define DUMUX_CVFE_ELEMENT_SOLUTION_HH
14
15 #include <type_traits>
16 #include <dune/common/reservedvector.hh>
17 #include <dumux/discretization/method.hh>
18 #include <dumux/discretization/localdoftraits.hh>
19
20 namespace Dumux {
21
22 /*!
23 * \ingroup CVFEDiscretization
24 * \brief The element solution vector
25 */
26 template<class FVElementGeometry, class PV>
27 class CVFEElementSolution
28 {
29 using GridGeometry = typename FVElementGeometry::GridGeometry;
30 using GridView = typename GridGeometry::GridView;
31 using Element = typename GridView::template Codim<0>::Entity;
32
33 static constexpr int dim = GridView::dimension;
34
35 // Dofs are located at corners and in the element center
36 static constexpr int numCubeDofs = Detail::LocalDofTraits<
37 GridView, typename GridGeometry::DiscretizationMethod
38 >::numCubeElementDofs;
39
40 public:
41 //! export the primary variables type
42 using PrimaryVariables = PV;
43
44 //! Default constructor
45 9 CVFEElementSolution() = default;
46
47 //! Constructor with element and solution and grid geometry
48 template<class SolutionVector>
49 87763677 CVFEElementSolution(const Element& element, const SolutionVector& sol,
50 const GridGeometry& gridGeometry)
51 128722804 {
52
10/14
✓ Branch 2 taken 1782467 times.
✓ Branch 3 taken 24492 times.
✓ Branch 7 taken 34908 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 69700 times.
✗ Branch 11 not taken.
✓ Branch 5 taken 30156 times.
✓ Branch 6 taken 20 times.
✓ Branch 4 taken 12372 times.
✓ Branch 13 taken 12279 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 34 times.
✗ Branch 17 not taken.
✓ Branch 1 taken 346732 times.
87763577 update(element, sol, gridGeometry);
53 18790643 }
54
55 //! Constructor with element and elemVolVars and fvGeometry
56 template<class ElementVolumeVariables>
57 10542417 CVFEElementSolution(const Element& element, const ElementVolumeVariables& elemVolVars,
58 const FVElementGeometry& fvGeometry)
59 10542417 {
60
2/4
✓ Branch 0 taken 2522976 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1092264 times.
✗ Branch 3 not taken.
10542417 priVars_.resize(fvGeometry.numScv());
61
3/4
✓ Branch 0 taken 11890472 times.
✓ Branch 1 taken 4384440 times.
✓ Branch 2 taken 1092264 times.
✗ Branch 3 not taken.
19986807 for (const auto& scv : scvs(fvGeometry))
62 9444390 priVars_[scv.localDofIndex()] = elemVolVars[scv].priVars();
63 4124844 }
64
65 //! extract the element solution from the solution vector using a mapper
66 template<class SolutionVector>
67 131048045 void update(const Element& element, const SolutionVector& sol,
68 const GridGeometry& gridGeometry)
69 {
70 // TODO: this implementation only works if there is only one dof per codim/entity
71 // As local-global mappings are provided by the grid geometry
72 // this logic should maybe become part of the grid geometry.
73 131048045 const auto& localCoeff = gridGeometry.feCache().get(element.type()).localCoefficients();
74 131048045 priVars_.resize(localCoeff.size());
75
3/3
✓ Branch 0 taken 257963520 times.
✓ Branch 1 taken 136073444 times.
✓ Branch 2 taken 16132227 times.
597978675 for (int localDofIdx = 0; localDofIdx < localCoeff.size(); ++localDofIdx)
76 {
77 466930630 const auto& localKey = localCoeff.localKey(localDofIdx);
78 466930630 priVars_[localDofIdx] = sol[
79 466930630 gridGeometry.dofMapper().subIndex(
80 441242762 element, localKey.subEntity(), localKey.codim()
81 )
82 ];
83 }
84 131048045 }
85
86 //! extract the element solution from the solution vector using a local fv geometry
87 template<class SolutionVector>
88 void update(const Element& element, const SolutionVector& sol,
89 const FVElementGeometry& fvGeometry)
90 {
91 priVars_.resize(fvGeometry.numScv());
92 for (const auto& scv : scvs(fvGeometry))
93 priVars_[scv.localDofIndex()] = sol[scv.dofIndex()];
94 }
95
96 //! return the size of the element solution
97 13311096 std::size_t size() const
98
2/2
✓ Branch 0 taken 6655548 times.
✓ Branch 1 taken 6655548 times.
13311096 { return priVars_.size(); }
99
100 //! bracket operator const access
101 template<typename IndexType>
102 937145482 const PrimaryVariables& operator [](IndexType i) const
103
5/9
✓ Branch 3 taken 2595772 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 1 taken 11358321 times.
✓ Branch 2 taken 36120 times.
✓ Branch 7 taken 93600 times.
✗ Branch 8 not taken.
✓ Branch 0 taken 800797 times.
935063944 { return priVars_[i]; }
104
105 //! bracket operator access
106 template<typename IndexType>
107 306063456 PrimaryVariables& operator [](IndexType i)
108
14/20
✓ Branch 0 taken 226808 times.
✓ Branch 1 taken 4903336 times.
✓ Branch 4 taken 329856 times.
✓ Branch 5 taken 896160 times.
✓ Branch 8 taken 2592772 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 2125680 times.
✗ Branch 12 not taken.
✓ Branch 17 taken 117472 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 48304 times.
✗ Branch 21 not taken.
✓ Branch 2 taken 87059442 times.
✓ Branch 3 taken 782 times.
✓ Branch 7 taken 824256 times.
✓ Branch 6 taken 782 times.
✓ Branch 14 taken 1056 times.
✗ Branch 15 not taken.
✓ Branch 22 taken 2892000 times.
✗ Branch 23 not taken.
299965912 { return priVars_[i]; }
109
110 private:
111 Dune::ReservedVector<PrimaryVariables, numCubeDofs> priVars_;
112 };
113
114 //! Make an element solution for control-volume finite element schemes
115 template<class Element, class SolutionVector, class GridGeometry>
116
4/6
✓ Branch 2 taken 1688867 times.
✓ Branch 3 taken 24472 times.
✓ Branch 5 taken 30156 times.
✗ Branch 6 not taken.
✓ Branch 4 taken 12279 times.
✗ Branch 1 not taken.
86096101 auto elementSolution(const Element& element, const SolutionVector& sol, const GridGeometry& gg)
117 -> std::enable_if_t<DiscretizationMethods::isCVFE<typename GridGeometry::DiscretizationMethod>,
118 CVFEElementSolution<typename GridGeometry::LocalView,
119 std::decay_t<decltype(std::declval<SolutionVector>()[0])>>
120 >
121 {
122 using PrimaryVariables = std::decay_t<decltype(std::declval<SolutionVector>()[0])>;
123
11/15
✓ Branch 3 taken 1765757 times.
✓ Branch 4 taken 50459 times.
✓ Branch 6 taken 63389 times.
✗ Branch 7 not taken.
✓ Branch 2 taken 2393474 times.
✓ Branch 5 taken 1824138 times.
✓ Branch 1 taken 404370 times.
✓ Branch 9 taken 44820 times.
✗ Branch 10 not taken.
✓ Branch 8 taken 12640 times.
✓ Branch 11 taken 1794158 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 34 times.
✗ Branch 15 not taken.
✓ Branch 0 taken 534520 times.
88717933 return CVFEElementSolution<typename GridGeometry::LocalView, PrimaryVariables>(element, sol, gg);
124 }
125
126 //! Make an element solution for control-volume finite element schemes
127 template<class Element, class ElementVolumeVariables, class FVElementGeometry>
128
2/4
✓ Branch 0 taken 2522976 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1092264 times.
✗ Branch 3 not taken.
10525533 auto elementSolution(const Element& element, const ElementVolumeVariables& elemVolVars, const FVElementGeometry& gg)
129 -> std::enable_if_t<DiscretizationMethods::isCVFE<typename FVElementGeometry::GridGeometry::DiscretizationMethod>,
130 CVFEElementSolution<FVElementGeometry,
131 typename ElementVolumeVariables::VolumeVariables::PrimaryVariables>>
132 {
133 using PrimaryVariables = typename ElementVolumeVariables::VolumeVariables::PrimaryVariables;
134
5/6
✓ Branch 0 taken 2528731 times.
✓ Branch 1 taken 279356 times.
✓ Branch 2 taken 1092264 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5045952 times.
✓ Branch 5 taken 2522976 times.
15577239 return CVFEElementSolution<FVElementGeometry, PrimaryVariables>(element, elemVolVars, gg);
135 }
136
137 } // end namespace Dumux
138
139 #endif
140