GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/discretization/facecentered/staggered/elementsolution.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 15 16 93.8%
Functions: 11 24 45.8%
Branches: 20 24 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 FaceCenteredStaggeredDiscretization
10 * \copydoc Dumux::FaceCenteredStaggeredElementSolution
11 */
12 #ifndef DUMUX_DISCRETIZATION_FACECENTERED_STAGGERED_ELEMENT_SOLUTION_HH
13 #define DUMUX_DISCRETIZATION_FACECENTERED_STAGGERED_ELEMENT_SOLUTION_HH
14
15 #include <type_traits>
16 #include <array>
17 #include <utility>
18
19 #include <dumux/common/indextraits.hh>
20 #include <dumux/discretization/method.hh>
21
22 namespace Dumux {
23
24 /*!
25 * \ingroup FaceCenteredStaggeredDiscretization
26 * \brief The global face variables class for staggered models
27 */
28 template<class FVElementGeometry, class PV>
29 class FaceCenteredStaggeredElementSolution
30 {
31 using GridGeometry = typename FVElementGeometry::GridGeometry;
32 using GridView = typename GridGeometry::GridView;
33 using Element = typename GridView::template Codim<0>::Entity;
34 using SmallLocalIndexType = typename IndexTraits<GridView>::SmallLocalIndex;
35
36 static constexpr auto numScvsPerElement = GridView::Grid::dimension * 2;
37
38 public:
39 //! export the primary variables type
40 using PrimaryVariables = PV;
41
42 FaceCenteredStaggeredElementSolution() = default;
43
44 //! Constructor with element, solution vector and grid geometry
45 template<class SolutionVector>
46 63909982 FaceCenteredStaggeredElementSolution(const Element& element,
47 const SolutionVector& sol,
48 const GridGeometry& gridGeometry)
49 63909982 {
50 126367252 const auto fvGeometry = localView(gridGeometry).bindElement(element);
51
52
5/5
✓ Branch 0 taken 5810848 times.
✓ Branch 1 taken 251937304 times.
✓ Branch 2 taken 62457270 times.
✓ Branch 3 taken 250484592 times.
✓ Branch 4 taken 62457270 times.
572142726 for (const auto& scv : scvs(fvGeometry))
53 768886320 priVars_[scv.indexInElement()] = sol[scv.dofIndex()];
54 63909982 }
55
56 //! Constructor with element, element volume variables and fv element geometry
57 template<class ElementVolumeVariables>
58 FaceCenteredStaggeredElementSolution(const Element& element,
59 const ElementVolumeVariables& elemVolVars,
60 const FVElementGeometry& fvGeometry)
61 {
62 for (const auto& scv : scvs(fvGeometry))
63 priVars_ = elemVolVars[scv].priVars();
64 }
65
66 //! Constructor with a primary variable object
67 FaceCenteredStaggeredElementSolution(PrimaryVariables&& priVars)
68 {
69 priVars_[0] = std::move(priVars);
70 for (int i = 1; i < priVars_.size(); ++i)
71 priVars_[i] = priVars_[0];
72 }
73
74 //! Constructor with a primary variable object
75 297094 FaceCenteredStaggeredElementSolution(const PrimaryVariables& priVars)
76 594188 {
77 297094 priVars_[0] = priVars;
78
6/6
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 120 times.
✓ Branch 2 taken 914802 times.
✓ Branch 3 taken 296934 times.
✓ Branch 4 taken 120 times.
✓ Branch 5 taken 40 times.
1212376 for (int i = 1; i < priVars_.size(); ++i)
79 2745846 priVars_[i] = priVars_[0];
80 }
81
82 //! extract the element solution from the solution vector using a mapper
83 template<class SolutionVector>
84 void update(const Element& element, const SolutionVector& sol,
85 const GridGeometry& gridGeometry)
86 {
87 const auto fvGeometry = localView(gridGeometry).bindElement(element);
88
89 for (const auto& scv : scvs(fvGeometry))
90 priVars_[scv.indexInElement()] = sol[scv.dofIndex()];
91 }
92
93 //! bracket operator const access
94 const PrimaryVariables& operator [](SmallLocalIndexType localScvIdx) const
95 {
96 145870172 return priVars_[localScvIdx];
97 }
98
99 //! bracket operator
100 PrimaryVariables& operator [](SmallLocalIndexType localScvIdx)
101 {
102
4/7
✓ Branch 3 taken 60499688 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 60499688 times.
✓ Branch 7 taken 29528 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 29528 times.
✗ Branch 11 not taken.
604476672 return priVars_[localScvIdx];
103 }
104
105 //! return the size of the element solution
106 static constexpr std::size_t size()
107 { return numScvsPerElement; }
108
109 private:
110 std::array<PrimaryVariables, numScvsPerElement> priVars_;
111 };
112
113 /*!
114 * \ingroup Discretization
115 * \brief Make an element solution for face-centered staggered schemes
116 */
117 template<class Element, class SolutionVector, class GridGeometry>
118 auto elementSolution(const Element& element, const SolutionVector& sol, const GridGeometry& gg)
119 -> std::enable_if_t<
120 GridGeometry::discMethod == DiscretizationMethods::fcstaggered,
121 FaceCenteredStaggeredElementSolution<
122 typename GridGeometry::LocalView,
123 std::decay_t<decltype(std::declval<SolutionVector>()[0])>
124 >
125 >
126
5/6
✓ Branch 1 taken 439641 times.
✓ Branch 2 taken 42047 times.
✓ Branch 3 taken 866800 times.
✓ Branch 4 taken 5304 times.
✓ Branch 5 taken 111104 times.
✗ Branch 6 not taken.
63909982 { return { element, sol, gg }; }
127
128 /*!
129 * \ingroup Discretization
130 * \brief Make an element solution for face-centered staggered schemes
131 */
132 template<class Element, class ElementVolumeVariables, class FVElementGeometry>
133 auto elementSolution(const Element& element, const ElementVolumeVariables& elemVolVars, const FVElementGeometry& gg)
134 -> std::enable_if_t<
135 FVElementGeometry::GridGeometry::discMethod == DiscretizationMethods::fcstaggered,
136 FaceCenteredStaggeredElementSolution<
137 FVElementGeometry,
138 typename ElementVolumeVariables::VolumeVariables::PrimaryVariables
139 >
140 >
141 { return { element, elemVolVars, gg }; }
142
143 /*!
144 * \ingroup Discretization
145 * \brief Make an element solution for face-centered staggered schemes
146 * \note This is e.g. used to construct an element solution at Dirichlet boundaries
147 */
148 template<class FVElementGeometry, class PrimaryVariables>
149 auto elementSolution(PrimaryVariables&& priVars)
150 -> std::enable_if_t<
151 FVElementGeometry::GridGeometry::discMethod == DiscretizationMethods::fcstaggered,
152 FaceCenteredStaggeredElementSolution<
153 FVElementGeometry,
154 std::decay_t<PrimaryVariables>
155 >
156 >
157 594188 { return { std::forward<PrimaryVariables>(priVars) }; }
158
159 } // end namespace Dumux
160
161 #endif
162