GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/common/reorderingdofmapper.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 32 34 94.1%
Functions: 3 5 60.0%
Branches: 138 382 36.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-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7
8 /*!
9 * \file
10 * \ingroup Core
11 * \brief An SCSG element mapper that sorts the indices in order to optimize the matrix sparsity pattern
12 * \note The reordering needs the SCOTCH library
13 */
14 #ifndef DUMUX_COMMON_REORDERING_DOF_MAPPER_HH
15 #define DUMUX_COMMON_REORDERING_DOF_MAPPER_HH
16
17 #if HAVE_PTSCOTCH
18
19 #include <dune/common/timer.hh>
20 #include <dune/grid/common/mapper.hh>
21
22 #include <dumux/linear/scotchbackend.hh>
23
24 namespace Dumux {
25
26 /*!
27 * \ingroup Core
28 * \brief An SCSG element mapper that sorts the indices in order to optimize the matrix sparsity pattern
29 * \note The reordering needs the SCOTCH library
30 */
31 template<class GridView>
32
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 class ReorderingDofMapper
33 : public Dune::Mapper<typename GridView::Grid, ReorderingDofMapper<GridView>, typename GridView::IndexSet::IndexType>
34 {
35 using Index = typename GridView::IndexSet::IndexType;
36 using ParentType = typename Dune::Mapper<typename GridView::Grid, ReorderingDofMapper<GridView>, Index>;
37 using Element = typename GridView::template Codim<0>::Entity;
38 public:
39
40 /*!
41 * \brief Construct mapper from grid and one of its index sets.
42 * \param gridView A Dune GridView object.
43 * \param layout a layout object (we just check whether it contains elements -> element mapper, else it's a vertex mapper)
44 */
45 template<class Layout>
46 13 ReorderingDofMapper (const GridView& gridView, Layout&& layout)
47 : gridView_(gridView)
48 26 , indexSet_(&gridView.indexSet())
49
5/14
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 13 times.
✓ Branch 7 taken 13 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 13 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
52 , codimension_(layout(indexSet_->types(0)[0], GridView::dimension) ? 0 : GridView::dimension)
50 {
51
1/2
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
13 update_();
52 13 }
53
54 /*!
55 * \brief Map entity to array index.
56 *
57 * \tparam EntityType
58 * \param e Reference to codim \a EntityType entity.
59 * \return An index in the range 0 ... Max number of entities in set - 1.
60 */
61 template<class EntityType>
62 Index index (const EntityType& e) const
63 {
64 // map the index using the permutation obtained from the reordering algorithm
65
62/143
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 10 taken 4032 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4032 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4032 times.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✓ Branch 25 taken 177251 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 177251 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 177251 times.
✗ Branch 32 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✓ Branch 37 taken 2016 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 2016 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 2016 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 4092 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 4092 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 5827 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 3751 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 3751 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 2016 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 11440 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 11440 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 11440 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 5486 times.
✗ Branch 74 not taken.
✓ Branch 76 taken 5486 times.
✗ Branch 77 not taken.
✓ Branch 79 taken 5486 times.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✓ Branch 82 taken 11440 times.
✗ Branch 83 not taken.
✓ Branch 84 taken 4092 times.
✓ Branch 85 taken 7348 times.
✓ Branch 86 taken 4092 times.
✓ Branch 88 taken 7348 times.
✗ Branch 89 not taken.
✓ Branch 90 taken 3714 times.
✓ Branch 91 taken 37 times.
✓ Branch 92 taken 3714 times.
✓ Branch 93 taken 37 times.
✓ Branch 94 taken 3714 times.
✓ Branch 95 taken 37 times.
✓ Branch 96 taken 13996 times.
✓ Branch 97 taken 13011 times.
✓ Branch 98 taken 13996 times.
✓ Branch 99 taken 13011 times.
✓ Branch 100 taken 13996 times.
✓ Branch 101 taken 13011 times.
✓ Branch 105 taken 1728 times.
✓ Branch 106 taken 7 times.
✓ Branch 107 taken 1728 times.
✓ Branch 108 taken 7 times.
✓ Branch 109 taken 1728 times.
✓ Branch 110 taken 7 times.
✗ Branch 120 not taken.
✓ Branch 121 taken 9722 times.
✗ Branch 122 not taken.
✓ Branch 123 taken 9722 times.
✗ Branch 124 not taken.
✓ Branch 125 taken 9722 times.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✗ Branch 132 not taken.
✗ Branch 133 not taken.
✗ Branch 134 not taken.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 137 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 140 not taken.
✗ Branch 141 not taken.
✓ Branch 142 taken 3470 times.
✗ Branch 143 not taken.
✓ Branch 144 taken 3470 times.
✗ Branch 145 not taken.
✓ Branch 146 taken 3470 times.
✗ Branch 153 not taken.
✗ Branch 154 not taken.
✗ Branch 155 not taken.
✗ Branch 156 not taken.
✗ Branch 157 not taken.
✗ Branch 158 not taken.
✓ Branch 172 taken 1735 times.
✗ Branch 173 not taken.
✓ Branch 175 taken 1735 times.
✗ Branch 176 not taken.
✓ Branch 178 taken 1735 times.
✗ Branch 179 not taken.
✗ Branch 186 not taken.
✗ Branch 187 not taken.
✗ Branch 188 not taken.
✗ Branch 189 not taken.
✗ Branch 190 not taken.
✗ Branch 191 not taken.
✓ Branch 193 taken 1735 times.
✗ Branch 194 not taken.
✓ Branch 196 taken 1735 times.
✗ Branch 197 not taken.
✓ Branch 199 taken 1735 times.
✗ Branch 200 not taken.
✗ Branch 204 not taken.
✓ Branch 205 taken 2873 times.
✗ Branch 206 not taken.
✓ Branch 207 taken 2873 times.
✗ Branch 208 not taken.
✓ Branch 209 taken 2873 times.
✓ Branch 214 taken 1735 times.
✗ Branch 215 not taken.
✓ Branch 217 taken 1735 times.
✗ Branch 218 not taken.
✓ Branch 220 taken 1735 times.
✗ Branch 221 not taken.
6500616 return static_cast<Index>(permutation_[indexSet_->index(e)]);
66 }
67
68 /** @brief Map subentity of codim 0 entity to array index.
69
70 \param e Reference to codim 0 entity.
71 \param i Number of subentity of e
72 \param codim Codimension of the subentity
73 \return An index in the range 0 ... Max number of entities in set - 1.
74 */
75 Index subIndex (const Element& e, int i, unsigned int codim) const
76 {
77
5/30
✓ Branch 1 taken 8088 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 4032 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 4032 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 30 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✓ Branch 41 taken 4032 times.
✗ Branch 42 not taken.
84662 return indexSet_->subIndex(e, i, codim);
78 }
79
80 /** @brief Return total number of entities in the entity set managed by the mapper.
81
82 This number can be used to allocate a vector of data elements associated with the
83 entities of the set. In the parallel case this number is per process (i.e. it
84 may be different in different processes).
85
86 \return Size of the entity set.
87 */
88 std::size_t size () const
89 {
90
21/122
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ 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 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✓ Branch 33 taken 24 times.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 37 taken 24 times.
✓ Branch 38 taken 101 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✓ Branch 41 taken 101 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 508 times.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✓ Branch 47 taken 508 times.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✓ Branch 56 taken 12 times.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✓ Branch 59 taken 12 times.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✓ Branch 66 taken 12 times.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✓ Branch 69 taken 12 times.
✗ Branch 70 not taken.
✓ Branch 71 taken 12 times.
✗ Branch 72 not taken.
✓ Branch 73 taken 12 times.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✓ Branch 76 taken 6 times.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✓ Branch 86 taken 6 times.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✓ Branch 90 taken 6 times.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✓ Branch 94 taken 6 times.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✓ Branch 98 taken 6 times.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 101 not taken.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✓ Branch 105 taken 6 times.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✓ Branch 108 taken 6 times.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✗ Branch 116 not taken.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
✗ Branch 120 not taken.
✓ Branch 121 taken 3 times.
✗ Branch 122 not taken.
✗ Branch 123 not taken.
✓ Branch 124 taken 3 times.
✗ Branch 125 not taken.
1416 return indexSet_->size(codimension_);
91 }
92
93 /** @brief Returns true if the entity is contained in the index set
94
95 \param e Reference to entity
96 \param result integer reference where corresponding index is stored if true
97 \return true if entity is in entity set of the mapper
98 */
99 template<class EntityType>
100 bool contains (const EntityType& e, Index& result) const
101 {
102 result = index(e);
103 return true;
104 }
105
106 /** @brief Returns true if the entity is contained in the index set
107
108 \param e Reference to codim 0 entity
109 \param i subentity number
110 \param cc subentity codim
111 \param result integer reference where corresponding index is stored if true
112 \return true if entity is in entity set of the mapper
113 */
114 bool contains (const Element& e, int i, int cc, Index& result) const
115 {
116 result = indexSet_->subIndex(e, i, cc);
117 return true;
118 }
119
120 /*!
121 * \brief Recalculates map after mesh adaptation
122 */
123 13 void update (const GridView& gridView)
124 {
125
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 gridView_ = gridView;
126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 indexSet_ = &gridView_.indexSet();
127 13 update_();
128 13 }
129
130 void update (GridView&& gridView)
131 {
132 gridView_ = std::move(gridView);
133 indexSet_ = &gridView_.indexSet();
134 update_();
135 }
136
137 private:
138 26 void update_()
139 {
140 // Compute scotch reordering
141 26 Dune::Timer watch;
142 // Create the graph as an adjacency list
143
4/6
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
78 std::vector<std::vector<Index>> graph(size());
144
145 // dofs on element centers (cell-centered methods)
146
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 12 times.
26 if (codimension_ == 0)
147 {
148
5/6
✓ Branch 1 taken 7502 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 7502 times.
✓ Branch 4 taken 14 times.
✓ Branch 6 taken 7502 times.
✗ Branch 7 not taken.
15018 for (const auto& element : elements(gridView_))
149 {
150
1/2
✓ Branch 1 taken 7502 times.
✗ Branch 2 not taken.
7502 auto eIdx = indexSet_->index(element);
151
5/8
✓ Branch 1 taken 7502 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 23346 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 15532 times.
✓ Branch 12 taken 312 times.
✓ Branch 14 taken 15844 times.
✗ Branch 15 not taken.
68886 for (const auto& intersection : intersections(gridView_, element))
152 {
153
4/4
✓ Branch 0 taken 15532 times.
✓ Branch 1 taken 312 times.
✓ Branch 2 taken 15532 times.
✓ Branch 3 taken 312 times.
31688 if (intersection.neighbor())
154
4/8
✓ Branch 1 taken 15532 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15532 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 15532 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 15532 times.
✗ Branch 11 not taken.
62128 graph[eIdx].push_back(indexSet_->index(intersection.outside()));
155 }
156 }
157 }
158 // dof on vertices (box method)
159 else
160 {
161
4/4
✓ Branch 1 taken 4032 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 4032 times.
✓ Branch 4 taken 12 times.
4044 for (const auto& element : elements(gridView_))
162 {
163 4032 auto eIdx = indexSet_->index(element);
164
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 12096 times.
✓ Branch 2 taken 8064 times.
✓ Branch 3 taken 4032 times.
24192 for (int vIdxLocal = 0; vIdxLocal < element.subEntities(codimension_); ++vIdxLocal)
165 {
166
1/2
✓ Branch 1 taken 8064 times.
✗ Branch 2 not taken.
8064 auto vIdxGlobal = indexSet_->subIndex(element, vIdxLocal, codimension_);
167
2/4
✓ Branch 1 taken 8064 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8064 times.
✗ Branch 5 not taken.
16128 graph[vIdxGlobal].push_back(eIdx);
168 }
169 }
170 }
171
172
2/4
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 26 times.
26 permutation_ = ScotchBackend<Index>::computeGPSReordering(graph);
173
3/5
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 26 times.
✗ Branch 6 not taken.
78 std::cout << "Scotch backend reordered index set of size " << size()
174
2/4
✓ Branch 3 taken 26 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 26 times.
✗ Branch 8 not taken.
78 << " in " << watch.elapsed() << " seconds." << std::endl;
175 26 }
176 // GridView is needed to keep the IndexSet valid
177 GridView gridView_;
178 const typename GridView::IndexSet* indexSet_;
179 const int codimension_;
180 // the map resulting from the reordering
181 std::vector<int> permutation_;
182 };
183
184 } // end namespace Dumux
185
186 #else
187
188 #warning "PTSCOTCH was not found on your system. Dumux::ReorderingDofMapper needs it to work -> fallback to MCMGMapper without reordering!"
189 #include <dune/grid/common/mcmgmapper.hh>
190 namespace Dumux {
191 template<class GridView>
192 using ReorderingDofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
193 } // end namespace Dumux
194
195 #endif // HAVE_PTSCOTCH
196 #endif
197