GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/discretization/cellcentered/mpfa/dualgridindexset.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 51 51 100.0%
Functions: 50 50 100.0%
Branches: 43 63 68.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-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 CCMpfaDiscretization
10 * \brief Class for the index sets of the dual grid in mpfa schemes.
11 */
12 #ifndef DUMUX_DISCRETIZATION_MPFA_DUALGRID_INDEX_SET_HH
13 #define DUMUX_DISCRETIZATION_MPFA_DUALGRID_INDEX_SET_HH
14
15 #include <cassert>
16 #include <vector>
17 #include <algorithm>
18
19 #include <dune/common/reservedvector.hh>
20 #include <dumux/common/indextraits.hh>
21
22 namespace Dumux {
23
24 /*!
25 * \ingroup CCMpfaDiscretization
26 * \brief Default traits to be used in conjunction
27 * with the dual grid nodal index set.
28 *
29 * \tparam GV The grid view type
30 */
31 template<class GV>
32 struct NodalIndexSetDefaultTraits
33 {
34 using GridView = GV;
35 using GridIndexType = typename IndexTraits<GV>::GridIndex;
36 using LocalIndexType = typename IndexTraits<GV>::LocalIndex;
37
38 //! per default, we use dynamic data containers (iv size unknown)
39 template< class T > using NodalScvDataStorage = std::vector< T >;
40 template< class T > using NodalScvfDataStorage = std::vector< T >;
41
42 //! store data on neighbors of scvfs in static containers if possible
43 template< class T >
44 using ScvfNeighborDataStorage = typename std::conditional_t< (int(GV::dimension)<int(GV::dimensionworld)),
45 std::vector< T >,
46 Dune::ReservedVector< T, 2 > >;
47 };
48
49 /*!
50 * \ingroup CCMpfaDiscretization
51 * \brief Nodal index set for mpfa schemes, constructed
52 * around grid vertices.
53 *
54 * \tparam T The traits class to be used
55 */
56 template< class T >
57 class CCMpfaDualGridNodalIndexSet
58 {
59 using LI = typename T::LocalIndexType;
60 using GI = typename T::GridIndexType;
61
62 using DimIndexVector = Dune::ReservedVector<LI, T::GridView::dimension>;
63 using ScvfIndicesInScvStorage = typename T::template NodalScvDataStorage< DimIndexVector >;
64
65 public:
66 //! Export the traits type
67 using Traits = T;
68
69 //! Export the index types used
70 using LocalIndexType = LI;
71 using GridIndexType = GI;
72
73 //! Export the stencil types used
74 using NodalGridStencilType = typename T::template NodalScvDataStorage< GI >;
75 using NodalLocalStencilType = typename T::template NodalScvDataStorage< LI >;
76 using NodalGridScvfStencilType = typename T::template NodalScvfDataStorage< GI >;
77
78 //! Data structure to store the neighboring scv indices of an scvf (grid/local indices)
79 using ScvfNeighborLocalIndexSet = typename T::template ScvfNeighborDataStorage< LI >;
80
81 //! Constructor
82 79024 CCMpfaDualGridNodalIndexSet() : numBoundaryScvfs_(0) {}
83
84 //! Inserts data for a given scvf
85 template<typename SubControlVolumeFace>
86
1/2
✓ Branch 1 taken 247564 times.
✗ Branch 2 not taken.
247564 void insert(const SubControlVolumeFace& scvf)
87 {
88
1/2
✓ Branch 1 taken 247564 times.
✗ Branch 2 not taken.
247564 insert(scvf.index(), scvf.insideScvIdx(), scvf.boundary());
89 247564 }
90
91 //! Inserts scvf data
92 630616 void insert(const GridIndexType scvfIdx,
93 const GridIndexType insideScvIdx,
94 const bool boundary)
95 {
96 // this should always be called only once per scvf
97
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 630616 times.
1261232 assert(std::count(scvfIndices_.begin(), scvfIndices_.end(), scvfIdx ) == 0 && "scvf already inserted!");
98
99 // the local index of the scvf data about to be inserted
100
2/2
✓ Branch 0 taken 16372 times.
✓ Branch 1 taken 614244 times.
630616 const LocalIndexType curScvfLocalIdx = scvfIndices_.size();
101
102 // if scvf is on boundary, increase counter
103
2/2
✓ Branch 0 taken 16372 times.
✓ Branch 1 taken 614244 times.
630616 if (boundary) numBoundaryScvfs_++;
104
105 // insert data on the new scv
106 630616 scvfIndices_.push_back(scvfIdx);
107 630616 scvfIsOnBoundary_.push_back(boundary);
108
109 // if entry for the inside scv exists append data, create otherwise
110
2/2
✓ Branch 0 taken 317272 times.
✓ Branch 1 taken 313344 times.
630616 auto it = std::find( scvIndices_.begin(), scvIndices_.end(), insideScvIdx );
111
2/2
✓ Branch 0 taken 317272 times.
✓ Branch 1 taken 313344 times.
630616 if (it != scvIndices_.end())
112 {
113 317272 const auto scvIdxLocal = std::distance(scvIndices_.begin(), it);
114 317272 scvfInsideScvIndices_.push_back(scvIdxLocal);
115 317272 localScvfIndicesInScv_[scvIdxLocal].push_back(curScvfLocalIdx);
116 }
117 else
118 {
119 313344 scvfInsideScvIndices_.push_back(scvIndices_.size());
120 313344 localScvfIndicesInScv_.push_back({curScvfLocalIdx});
121 313344 scvIndices_.push_back(insideScvIdx);
122 }
123 630616 }
124
125 //! returns the number of scvs around the node
126 953955092 std::size_t numScvs() const
127
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8674446 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 34944 times.
8709390 { return scvIndices_.size(); }
128
129 //! returns the number of scvfs around the node
130 76248222 std::size_t numScvfs() const
131
4/8
✓ Branch 1 taken 79024 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2044908 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 8637789 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 24336 times.
10786057 { return scvfIndices_.size(); }
132
133 //! returns the number of boundary scvfs around the node
134 950086104 std::size_t numBoundaryScvfs() const
135
12/12
✓ Branch 0 taken 523076684 times.
✓ Branch 1 taken 17693374 times.
✓ Branch 2 taken 3240834 times.
✓ Branch 3 taken 16407894 times.
✓ Branch 4 taken 34694150 times.
✓ Branch 5 taken 3390674 times.
✓ Branch 6 taken 154356630 times.
✓ Branch 7 taken 49767578 times.
✓ Branch 8 taken 4589736 times.
✓ Branch 9 taken 4369414 times.
✓ Branch 10 taken 31091712 times.
✓ Branch 11 taken 1899784 times.
950086104 { return numBoundaryScvfs_; }
136
137 //! returns the grid scv indices connected to this dual grid node
138 8715534 const NodalGridStencilType& gridScvIndices() const
139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4639837 times.
9342254 { return scvIndices_; }
140
141 //! returns the grid scvf indices connected to this dual grid node
142 const NodalGridScvfStencilType& gridScvfIndices() const
143
2/2
✓ Branch 0 taken 6410274 times.
✓ Branch 1 taken 59820846 times.
71937952 { return scvfIndices_; }
144
145 //! returns whether or not the i-th scvf is on a domain boundary
146 323350 bool scvfIsOnBoundary(unsigned int i) const
147 {
148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 323350 times.
323350 assert(i < numScvfs());
149 323350 return scvfIsOnBoundary_[i];
150 }
151
152 //! returns the grid scv idx of the i-th scv
153 GridIndexType gridScvIndex(unsigned int i) const
154 {
155 assert(i < numScvs());
156 return scvIndices_[i];
157 }
158
159 //! returns the index of the i-th scvf
160 64508199 GridIndexType gridScvfIndex(unsigned int i) const
161 {
162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64508199 times.
64508199 assert(i < numScvfs());
163 64508199 return scvfIndices_[i];
164 }
165
166 //! returns the grid index of the j-th scvf embedded in the i-th scv
167 120437944 GridIndexType gridScvfIndex(unsigned int i, unsigned int j) const
168 {
169
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 120437944 times.
120437944 assert(i < numScvs());
170
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 120437944 times.
120437944 assert(j < localScvfIndicesInScv_[i].size());
171 120437944 return scvfIndices_[ localScvfIndicesInScv_[i][j] ];
172 }
173
174 //! returns the node-local index of the j-th scvf embedded in the i-th scv
175 824807758 LocalIndexType localScvfIndex(unsigned int i, unsigned int j) const
176 {
177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824807758 times.
824807758 assert(i < numScvs());
178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824807758 times.
824807758 assert(j < localScvfIndicesInScv_[i].size());
179 824807758 return localScvfIndicesInScv_[i][j];
180 }
181
182 //! returns the node-local index of the inside scv of the i-th scvf
183 630616 LocalIndexType insideScvLocalIndex(unsigned int i) const
184 {
185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 630616 times.
630616 assert(i < numScvfs());
186 630616 return scvfInsideScvIndices_[i];
187 }
188
189 private:
190 NodalGridStencilType scvIndices_; //!< The indices of the scvs around a dual grid node
191 ScvfIndicesInScvStorage localScvfIndicesInScv_; //!< Maps to each scv a list of scvf indices embedded in it
192
193 std::size_t numBoundaryScvfs_; //!< stores how many boundary scvfs are embedded in this dual grid node
194 NodalGridScvfStencilType scvfIndices_; //!< the indices of the scvfs around a dual grid node
195 typename T::template NodalScvfDataStorage< bool > scvfIsOnBoundary_; //!< Maps to each scvf a boolean to indicate if it is on the boundary
196 typename T::template NodalScvfDataStorage< LI > scvfInsideScvIndices_; //!< The inside local scv index for each scvf
197 };
198
199 /*!
200 * \ingroup CCMpfaDiscretization
201 * \brief Class for the index sets of the dual grid in mpfa schemes.
202 *
203 * \tparam NI The type used for the nodal index sets.
204 */
205 template< class NI >
206 150 class CCMpfaDualGridIndexSet
207 {
208 public:
209 using NodalIndexSet = NI;
210 using GridIndexType = typename NodalIndexSet::GridIndexType;
211
212 //! Default constructor should not be used
213 CCMpfaDualGridIndexSet() = delete;
214
215 //! Constructor taking a grid view
216 template< class GridView >
217 50 CCMpfaDualGridIndexSet(const GridView& gridView)
218 50 : nodalIndexSets_(gridView.size(GridView::dimension))
219 50 {}
220
221 //! Access with an scvf
222 template< class SubControlVolumeFace >
223 const NodalIndexSet& operator[] (const SubControlVolumeFace& scvf) const
224 { return nodalIndexSets_[scvf.vertexIndex()]; }
225
226 template< class SubControlVolumeFace >
227 NodalIndexSet& operator[] (const SubControlVolumeFace& scvf)
228 { return nodalIndexSets_[scvf.vertexIndex()]; }
229
230 //! Access with an index
231 const NodalIndexSet& operator[] (GridIndexType i) const
232 { return nodalIndexSets_[i]; }
233
234 709640 NodalIndexSet& operator[] (GridIndexType i)
235
4/7
✓ Branch 1 taken 53055 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 53055 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 419736 times.
✗ Branch 8 not taken.
✓ Branch 3 taken 210880 times.
788664 { return nodalIndexSets_[i]; }
236
237 private:
238 std::vector<NodalIndexSet> nodalIndexSets_;
239 };
240
241 } // end namespace Dumux
242
243 #endif
244