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 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 | 18 | CVFEElementSolution() = default; | |
46 | |||
47 | //! Constructor with element and solution and grid geometry | ||
48 | template<class SolutionVector> | ||
49 | 16785451 | CVFEElementSolution(const Element& element, const SolutionVector& sol, | |
50 | const GridGeometry& gridGeometry) | ||
51 | 149425237 | { | |
52 |
11/15✓ Branch 1 taken 346742 times.
✓ Branch 2 taken 1234412 times.
✓ Branch 3 taken 1840 times.
✓ Branch 4 taken 12372 times.
✓ Branch 5 taken 30156 times.
✓ Branch 6 taken 66 times.
✓ Branch 7 taken 34358 times.
✓ Branch 8 taken 38500 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 31200 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 12279 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 34 times.
✗ Branch 17 not taken.
|
83565444 | update(element, sol, gridGeometry); |
53 | 16785451 | } | |
54 | |||
55 | //! Constructor with element and elemVolVars and fvGeometry | ||
56 | template<class ElementVolumeVariables> | ||
57 | 4096074 | CVFEElementSolution(const Element& element, const ElementVolumeVariables& elemVolVars, | |
58 | const FVElementGeometry& fvGeometry) | ||
59 | 16988760 | { | |
60 |
2/4✓ Branch 0 taken 2522976 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1092264 times.
✗ Branch 3 not taken.
|
14914971 | priVars_.resize(fvGeometry.numScv()); |
61 |
8/8✓ Branch 0 taken 8204036 times.
✓ Branch 1 taken 4079190 times.
✓ Branch 2 taken 10727012 times.
✓ Branch 3 taken 4079190 times.
✓ Branch 4 taken 1105920 times.
✓ Branch 5 taken 276480 times.
✓ Branch 6 taken 2198184 times.
✓ Branch 7 taken 276480 times.
|
36243294 | for (const auto& scv : scvs(fvGeometry)) |
62 | 28160550 | priVars_[scv.localDofIndex()] = elemVolVars[scv].priVars(); | |
63 | 4096074 | } | |
64 | |||
65 | //! extract the element solution from the solution vector using a mapper | ||
66 | template<class SolutionVector> | ||
67 | 124231070 | 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 | 303919195 | const auto& localCoeff = gridGeometry.feCache().get(element.type()).localCoefficients(); | |
74 | 124231070 | priVars_.resize(localCoeff.size()); | |
75 |
4/4✓ Branch 0 taken 247649813 times.
✓ Branch 1 taken 131715624 times.
✓ Branch 2 taken 263521223 times.
✓ Branch 3 taken 68259574 times.
|
892377134 | for (int localDofIdx = 0; localDofIdx < localCoeff.size(); ++localDofIdx) |
76 | { | ||
77 | 445962349 | const auto& localKey = localCoeff.localKey(localDofIdx); | |
78 | 891924698 | priVars_[localDofIdx] = sol[ | |
79 | 891924698 | gridGeometry.dofMapper().subIndex( | |
80 | element, localKey.subEntity(), localKey.codim() | ||
81 | ) | ||
82 | ]; | ||
83 | } | ||
84 | 124231070 | } | |
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 | std::size_t size() const | ||
98 | ✗ | { return priVars_.size(); } | |
99 | |||
100 | //! bracket operator const access | ||
101 | template<typename IndexType> | ||
102 | const PrimaryVariables& operator [](IndexType i) const | ||
103 |
9/38✓ Branch 0 taken 800797 times.
✓ Branch 1 taken 11228361 times.
✓ Branch 2 taken 800797 times.
✓ Branch 3 taken 9738623 times.
✓ Branch 4 taken 1489738 times.
✓ Branch 5 taken 2720572 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 2720572 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 93600 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✓ Branch 26 taken 93600 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
|
1774602118 | { return priVars_[i]; } |
104 | |||
105 | //! bracket operator access | ||
106 | template<typename IndexType> | ||
107 | PrimaryVariables& operator [](IndexType i) | ||
108 |
31/45✓ Branch 2 taken 226808 times.
✓ Branch 3 taken 90175380 times.
✓ Branch 4 taken 226808 times.
✓ Branch 5 taken 4903382 times.
✓ Branch 6 taken 85601900 times.
✓ Branch 7 taken 874560 times.
✓ Branch 8 taken 329902 times.
✓ Branch 9 taken 896160 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 126 times.
✓ Branch 12 taken 21600 times.
✓ Branch 13 taken 781328 times.
✓ Branch 14 taken 46 times.
✓ Branch 15 taken 2327916 times.
✓ Branch 16 taken 781248 times.
✓ Branch 17 taken 54872 times.
✓ Branch 18 taken 2327916 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 54872 times.
✓ Branch 21 taken 99056 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 99056 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 2042736 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 2042736 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1056 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1056 times.
✗ Branch 37 not taken.
✓ Branch 39 taken 118528 times.
✗ Branch 40 not taken.
✓ Branch 42 taken 118528 times.
✗ Branch 43 not taken.
✓ Branch 45 taken 17472 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 17472 times.
✓ Branch 49 taken 2892000 times.
✗ Branch 50 not taken.
✓ Branch 51 taken 48304 times.
✓ Branch 52 taken 2892000 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 48304 times.
✗ Branch 55 not taken.
|
603571448 | { 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 | 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 |
15/22✓ Branch 1 taken 10 times.
✓ Branch 2 taken 5737 times.
✓ Branch 3 taken 2812730 times.
✓ Branch 4 taken 10607 times.
✓ Branch 5 taken 1788366 times.
✓ Branch 6 taken 1171022 times.
✓ Branch 7 taken 12279 times.
✓ Branch 8 taken 77116 times.
✓ Branch 9 taken 66 times.
✓ Branch 10 taken 12279 times.
✓ Branch 11 taken 1894014 times.
✓ Branch 12 taken 66 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 61356 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 42 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 22 taken 34 times.
✗ Branch 23 not taken.
|
120521159 | 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 | ✗ | 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 |
4/8✓ Branch 0 taken 2522976 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2522976 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1092264 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1092264 times.
✗ Branch 7 not taken.
|
14417253 | return CVFEElementSolution<FVElementGeometry, PrimaryVariables>(element, elemVolVars, gg); |
135 | } | ||
136 | |||
137 | } // end namespace Dumux | ||
138 | |||
139 | #endif | ||
140 |