GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/assembly/coloring.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 78 79 98.7%
Functions: 256 277 92.4%
Branches: 292 391 74.7%

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 Assembly
10 * \brief Coloring schemes for shared-memory-parallel assembly
11 */
12 #ifndef DUMUX_ASSEMBLY_COLORING_HH
13 #define DUMUX_ASSEMBLY_COLORING_HH
14
15 #include <vector>
16 #include <deque>
17 #include <iostream>
18 #include <tuple>
19 #include <algorithm>
20
21 #include <dune/common/timer.hh>
22 #include <dune/common/exceptions.hh>
23
24 #include <dumux/io/format.hh>
25 #include <dumux/discretization/method.hh>
26
27 #ifndef DOXYGEN // hide from doxygen
28 namespace Dumux::Detail {
29
30 //! Compute a map from dof indices to element indices (helper data for coloring algorithm)
31 template <class GridGeometry>
32 std::vector<std::vector<std::size_t>>
33 452 computeConnectedElements(const GridGeometry& gg)
34 {
35
1/2
✓ Branch 1 taken 283 times.
✗ Branch 2 not taken.
482 std::vector<std::vector<std::size_t>> connectedElements;
36
37 if constexpr (GridGeometry::discMethod == DiscretizationMethods::cctpfa)
38 {
39
4/7
✓ Branch 1 taken 149 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 47 times.
✓ Branch 4 taken 149 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 149 times.
✗ Branch 8 not taken.
490 connectedElements.resize(gg.gridView().size(0));
40
1/2
✓ Branch 1 taken 158 times.
✗ Branch 2 not taken.
243 const auto& eMapper = gg.elementMapper();
41
16/17
✓ Branch 1 taken 158 times.
✓ Branch 2 taken 49047 times.
✓ Branch 3 taken 34 times.
✓ Branch 4 taken 49201 times.
✓ Branch 5 taken 38 times.
✓ Branch 6 taken 1250138 times.
✓ Branch 7 taken 5516 times.
✓ Branch 8 taken 17638 times.
✓ Branch 9 taken 13 times.
✓ Branch 10 taken 17 times.
✓ Branch 11 taken 17638 times.
✓ Branch 12 taken 61276 times.
✓ Branch 13 taken 17 times.
✓ Branch 14 taken 61276 times.
✓ Branch 15 taken 17 times.
✓ Branch 17 taken 61276 times.
✗ Branch 18 not taken.
4617306 for (const auto& element : elements(gg.gridView()))
42 {
43
1/2
✓ Branch 1 taken 84400 times.
✗ Branch 2 not taken.
2308404 const auto eIdx = eMapper.index(element);
44
17/22
✓ Branch 1 taken 97557 times.
✓ Branch 2 taken 1262772 times.
✓ Branch 3 taken 6909064 times.
✓ Branch 4 taken 219157 times.
✓ Branch 5 taken 42860 times.
✓ Branch 6 taken 20 times.
✓ Branch 7 taken 139238 times.
✓ Branch 8 taken 372794 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 17638 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 99988 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 291407 times.
✓ Branch 15 taken 1468 times.
✓ Branch 17 taken 47086 times.
✓ Branch 18 taken 17638 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 139900 times.
✓ Branch 21 taken 3726 times.
✓ Branch 23 taken 82350 times.
✗ Branch 24 not taken.
20622408 for (const auto& intersection : intersections(gg.gridView(), element))
45
4/4
✓ Branch 0 taken 6842164 times.
✓ Branch 1 taken 438368 times.
✓ Branch 2 taken 127999 times.
✓ Branch 3 taken 5194 times.
13108701 if (intersection.neighbor())
46
6/10
✓ Branch 1 taken 333104 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6803150 times.
✓ Branch 4 taken 333104 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6803150 times.
✓ Branch 7 taken 333104 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 333104 times.
✗ Branch 11 not taken.
24910612 connectedElements[eMapper.index(intersection.outside())].push_back(eIdx);
47 }
48 }
49
50 else if constexpr (GridGeometry::discMethod == DiscretizationMethods::box
51 || GridGeometry::discMethod == DiscretizationMethods::pq1bubble)
52 {
53 static constexpr int dim = GridGeometry::GridView::dimension;
54
4/7
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 52 times.
✓ Branch 4 taken 114 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 114 times.
✗ Branch 8 not taken.
345 connectedElements.resize(gg.gridView().size(dim));
55
1/2
✓ Branch 1 taken 138 times.
✗ Branch 2 not taken.
172 const auto& vMapper = gg.vertexMapper();
56
17/19
✓ Branch 1 taken 138 times.
✓ Branch 2 taken 52448 times.
✓ Branch 3 taken 27 times.
✓ Branch 4 taken 52585 times.
✓ Branch 5 taken 28 times.
✓ Branch 6 taken 146931 times.
✓ Branch 7 taken 40 times.
✓ Branch 8 taken 27777 times.
✓ Branch 9 taken 25 times.
✓ Branch 10 taken 15 times.
✓ Branch 11 taken 27777 times.
✓ Branch 12 taken 33708 times.
✓ Branch 13 taken 15 times.
✓ Branch 14 taken 61485 times.
✓ Branch 15 taken 15 times.
✓ Branch 17 taken 33708 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 33708 times.
✗ Branch 21 not taken.
485443 for (const auto& element : elements(gg.gridView()))
57 {
58
2/4
✓ Branch 1 taken 61485 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 61485 times.
✗ Branch 5 not taken.
326407 const auto eIdx = gg.elementMapper().index(element);
59
4/4
✓ Branch 1 taken 948266 times.
✓ Branch 2 taken 201503 times.
✓ Branch 3 taken 896781 times.
✓ Branch 4 taken 222988 times.
2101855 for (int i = 0; i < element.subEntities(dim); i++)
60
3/6
✓ Branch 1 taken 926781 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 926781 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 926781 times.
✗ Branch 8 not taken.
1083325 connectedElements[vMapper.subIndex(element, i, dim)].push_back(eIdx);
61 }
62 }
63
64 else if constexpr (
65 GridGeometry::discMethod == DiscretizationMethods::fcstaggered
66 || GridGeometry::discMethod == DiscretizationMethods::ccmpfa
67 )
68 {
69 // for MPFA-O schemes the assembly of each element residual touches all vertex neighbors
70 // for face-centered staggered it is all codim-2 neighbors (vertex neighbors in 2D, edge neighbors in 3D)
71 // but we use vertex neighbors also in 3D for simplicity
72
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
54 std::vector<std::vector<std::size_t>> vToElements;
73 static constexpr int dim = GridGeometry::GridView::dimension;
74
4/7
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
74 vToElements.resize(gg.gridView().size(dim));
75
1/2
✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
37 const auto& vMapper = gg.vertexMapper();
76
17/19
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 6978 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 7012 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 23785 times.
✓ Branch 7 taken 17 times.
✓ Branch 8 taken 14484 times.
✓ Branch 9 taken 14 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 14484 times.
✓ Branch 12 taken 12782 times.
✓ Branch 13 taken 3 times.
✓ Branch 14 taken 27266 times.
✓ Branch 15 taken 3 times.
✓ Branch 17 taken 12782 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 12782 times.
✗ Branch 21 not taken.
78456 for (const auto& element : elements(gg.gridView()))
77 {
78
2/4
✓ Branch 1 taken 27266 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 27266 times.
✗ Branch 5 not taken.
70794 const auto eIdx = gg.elementMapper().index(element);
79
4/4
✓ Branch 1 taken 194400 times.
✓ Branch 2 taken 16262 times.
✓ Branch 3 taken 167134 times.
✓ Branch 4 taken 43528 times.
268732 for (int i = 0; i < element.subEntities(dim); i++)
80
3/6
✓ Branch 1 taken 167134 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 167134 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 167134 times.
✗ Branch 8 not taken.
167134 vToElements[vMapper.subIndex(element, i, dim)].push_back(eIdx);
81 }
82
83
4/7
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
74 connectedElements.resize(gg.gridView().size(0));
84
16/17
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 6978 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 7012 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 23785 times.
✓ Branch 7 taken 17 times.
✓ Branch 8 taken 14484 times.
✓ Branch 9 taken 14 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 14484 times.
✓ Branch 12 taken 12782 times.
✓ Branch 13 taken 3 times.
✓ Branch 14 taken 12782 times.
✓ Branch 15 taken 3 times.
✓ Branch 17 taken 12782 times.
✗ Branch 18 not taken.
87156 for (const auto& element : elements(gg.gridView()))
85 {
86
2/4
✓ Branch 1 taken 27266 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 27266 times.
✗ Branch 5 not taken.
70794 const auto eIdx = gg.elementMapper().index(element);
87
4/4
✓ Branch 1 taken 194400 times.
✓ Branch 2 taken 16262 times.
✓ Branch 3 taken 167134 times.
✓ Branch 4 taken 43528 times.
268732 for (int i = 0; i < element.subEntities(dim); i++)
88 {
89
2/4
✓ Branch 1 taken 167134 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 167134 times.
✗ Branch 5 not taken.
167134 const auto& e = vToElements[vMapper.subIndex(element, i, dim)];
90
6/12
✓ Branch 1 taken 167134 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 167134 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 167134 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 167134 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 167134 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 167134 times.
✗ Branch 17 not taken.
1002804 connectedElements[eIdx].insert(connectedElements[eIdx].end(), e.begin(), e.end());
91 }
92
93 // make unique
94 174112 std::sort(connectedElements[eIdx].begin(), connectedElements[eIdx].end());
95
1/2
✓ Branch 4 taken 27266 times.
✗ Branch 5 not taken.
87056 connectedElements[eIdx].erase(
96 130584 std::unique(connectedElements[eIdx].begin(), connectedElements[eIdx].end()),
97 43528 connectedElements[eIdx].end()
98 );
99 }
100 }
101
102 // nothing has to be precomputed here as only immediate face neighbors are connected
103 else if constexpr (GridGeometry::discMethod == DiscretizationMethods::fcdiamond)
104 return connectedElements;
105
106 else
107 DUNE_THROW(Dune::NotImplemented,
108 "Missing coloring scheme implementation for this discretization method"
109 );
110
111 452 return connectedElements;
112 }
113
114 /*!
115 * \brief Compute the colors of neighboring nodes in the dependency graph
116 *
117 * Neighboring nodes are those elements that manipulate the
118 * same data structures (e.g. system matrix, volvars, flux cache) in the same places
119 *
120 * \param gridGeometry the grid geometry
121 * \param element the element we want to color
122 * \param colors a vector of current colors for each element (not assigned: -1)
123 * \param connectedElements a map from implementation-defined indices to element indices
124 * \param neighborColors a vector to add the colors of neighbor nodes to
125 */
126 template<class GridGeometry, class ConnectedElements>
127 2640108 void addNeighborColors(const GridGeometry& gg,
128 const typename GridGeometry::LocalView::Element& element,
129 const std::vector<int>& colors,
130 const ConnectedElements& connectedElements,
131 std::vector<int>& neighborColors)
132 {
133 if constexpr (
134 GridGeometry::discMethod == DiscretizationMethods::cctpfa
135 || GridGeometry::discMethod == DiscretizationMethods::ccmpfa
136 || GridGeometry::discMethod == DiscretizationMethods::fcstaggered
137 )
138 {
139 // we modify neighbor elements during the assembly
140 // check who else modifies these neighbor elements
141 2351932 const auto& eMapper = gg.elementMapper();
142
13/15
✓ Branch 2 taken 1272056 times.
✓ Branch 3 taken 6978322 times.
✓ Branch 4 taken 599562 times.
✓ Branch 5 taken 30420 times.
✓ Branch 6 taken 32122 times.
✓ Branch 7 taken 121600 times.
✓ Branch 8 taken 172408 times.
✓ Branch 9 taken 66484 times.
✓ Branch 10 taken 299339 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 68586 times.
✓ Branch 13 taken 134516 times.
✓ Branch 14 taken 5770 times.
✓ Branch 16 taken 140286 times.
✗ Branch 17 not taken.
18991154 for (const auto& intersection : intersections(gg.gridView(), element))
143 {
144
4/4
✓ Branch 0 taken 6955191 times.
✓ Branch 1 taken 492665 times.
✓ Branch 2 taken 205453 times.
✓ Branch 3 taken 7872 times.
13356157 if (intersection.neighbor())
145 {
146 // direct face neighbors
147
2/4
✓ Branch 1 taken 439748 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 439748 times.
✗ Branch 5 not taken.
25092216 const auto nIdx = eMapper.index(intersection.outside());
148
2/4
✓ Branch 1 taken 494792 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 494792 times.
✗ Branch 5 not taken.
25660772 neighborColors.push_back(colors[nIdx]);
149
150 // neighbor-neighbors
151
12/12
✓ Branch 0 taken 25144 times.
✓ Branch 1 taken 439748 times.
✓ Branch 2 taken 38447682 times.
✓ Branch 3 taken 6870858 times.
✓ Branch 4 taken 38850846 times.
✓ Branch 5 taken 6859418 times.
✓ Branch 6 taken 865116 times.
✓ Branch 7 taken 134516 times.
✓ Branch 8 taken 2293965 times.
✓ Branch 9 taken 428308 times.
✓ Branch 10 taken 1428849 times.
✓ Branch 11 taken 293792 times.
98789569 for (const auto nnIdx : connectedElements[eMapper.index(intersection.outside())])
152
2/4
✓ Branch 1 taken 2701415 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2701415 times.
✗ Branch 5 not taken.
147244402 neighborColors.push_back(colors[nnIdx]);
153 }
154 }
155 }
156
157 else if constexpr (GridGeometry::discMethod == DiscretizationMethods::box
158 || GridGeometry::discMethod == DiscretizationMethods::pq1bubble)
159 {
160 // we modify the vertex dofs of our element during the assembly
161 // check who else modifies these vertex dofs
162 256698 const auto& vMapper = gg.vertexMapper();
163 static constexpr int dim = GridGeometry::GridView::dimension;
164 // direct vertex neighbors
165
4/4
✓ Branch 0 taken 638184 times.
✓ Branch 1 taken 450100 times.
✓ Branch 2 taken 709669 times.
✓ Branch 3 taken 161503 times.
1340023 for (int i = 0; i < element.subEntities(dim); i++)
166
4/4
✓ Branch 1 taken 5337873 times.
✓ Branch 2 taken 926781 times.
✓ Branch 3 taken 5337873 times.
✓ Branch 4 taken 926781 times.
8088898 for (auto eIdx : connectedElements[vMapper.subIndex(element, i, dim)])
167 14011146 neighborColors.push_back(colors[eIdx]);
168 }
169
170 else if constexpr (GridGeometry::discMethod == DiscretizationMethods::fcdiamond)
171 {
172 // we modify neighbor faces during the assembly
173 // check who else modifies these neighbor elements
174 31478 const auto& eMapper = gg.elementMapper();
175
9/14
✓ Branch 2 taken 21100 times.
✓ Branch 3 taken 84500 times.
✓ Branch 4 taken 42956 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 100 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 500 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 32678 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 360 times.
✓ Branch 14 taken 40 times.
✓ Branch 16 taken 400 times.
✗ Branch 17 not taken.
224350 for (const auto& intersection : intersections(gg.gridView(), element))
176
4/4
✓ Branch 0 taken 83970 times.
✓ Branch 1 taken 32868 times.
✓ Branch 2 taken 1000 times.
✓ Branch 3 taken 40 times.
117878 if (intersection.neighbor())
177
4/8
✓ Branch 1 taken 32398 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 32398 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 32398 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 32398 times.
✗ Branch 11 not taken.
198038 neighborColors.push_back(colors[eMapper.index(intersection.outside())]);
178 }
179
180 else
181 DUNE_THROW(Dune::NotImplemented,
182 "Missing coloring scheme implementation for this discretization method"
183 );
184 2640108 }
185
186 /*!
187 * \brief Find the smallest color (integer >= 0) _not_ present in the given list of colors
188 * \param colors list of colors which are already taken
189 * \param notAssigned container to store which colors are not yet taken (is resized as required)
190 */
191 1935801 int smallestAvailableColor(const std::vector<int>& colors,
192 std::vector<bool>& colorUsed)
193 {
194 1935801 const int numColors = colors.size();
195 1935801 colorUsed.assign(numColors, false);
196
197 // The worst case for e.g. numColors=3 is colors={0, 1, 2}
198 // in which case we return 3 as smallest available color
199 // That means, we only track candidates in the (half-open) interval [0, numColors)
200 // Mark candidate colors which are present in colors
201
2/2
✓ Branch 0 taken 58377215 times.
✓ Branch 1 taken 1935801 times.
60313016 for (int i = 0; i < numColors; i++)
202
6/6
✓ Branch 0 taken 24871084 times.
✓ Branch 1 taken 33506131 times.
✓ Branch 2 taken 24871084 times.
✓ Branch 3 taken 33506131 times.
✓ Branch 4 taken 24862331 times.
✓ Branch 5 taken 8753 times.
116754430 if (colors[i] >= 0 && colors[i] < numColors)
203 74586993 colorUsed[colors[i]] = true;
204
205 // return smallest color not in colors
206
2/2
✓ Branch 0 taken 7869078 times.
✓ Branch 1 taken 450 times.
7869528 for (int i = 0; i < numColors; i++)
207
6/6
✓ Branch 0 taken 1935351 times.
✓ Branch 1 taken 5933727 times.
✓ Branch 2 taken 1935351 times.
✓ Branch 3 taken 5933727 times.
✓ Branch 4 taken 1935351 times.
✓ Branch 5 taken 5933727 times.
23607234 if (!colorUsed[i])
208 1935351 return i;
209
210 return numColors;
211 }
212
213 } // end namespace Dumux::Detail
214 #endif // DOXYGEN
215
216 namespace Dumux {
217
218 /*!
219 * \brief Compute iterable lists of element seeds partitioned by color
220 *
221 * Splits up the elements of a grid view into partitions such that
222 * all elements in one partition do not modify global data structures
223 * at the same place during assembly. This is used to allow for
224 * lock-free thread-parallel (shared memory) assembly routines.
225 *
226 * Implements a simply greedy graph coloring algorithm:
227 * For each node (element), assign the smallest available color
228 * not used by any of the neighboring nodes (element with conflicting memory access)
229 * The greedy algorithm doesn't necessarily return the smallest
230 * possible number of colors (that's a hard problem) but is fast
231 *
232 * Returns a struct with access to the colors of each element (member colors)
233 * and vector of element seed sets of the same color (member sets)
234 *
235 * \param gg the grid geometry
236 * \param verbosity the verbosity level
237 */
238 template<class GridGeometry>
239 362 auto computeColoring(const GridGeometry& gg, int verbosity = 1)
240 {
241 362 Dune::Timer timer;
242
243 using ElementSeed = typename GridGeometry::GridView::Grid::template Codim<0>::EntitySeed;
244 struct Coloring
245 {
246 using Sets = std::deque<std::vector<ElementSeed>>;
247 using Colors = std::vector<int>;
248
249
2/4
✓ Branch 2 taken 362 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 362 times.
✗ Branch 6 not taken.
362 Coloring(std::size_t size) : sets{}, colors(size, -1) {}
250
251 Sets sets;
252 Colors colors;
253 };
254
255 729 Coloring coloring(gg.gridView().size(0));
256
257 // pre-reserve some memory for helper arrays to avoid reallocation
258
2/6
✓ Branch 1 taken 362 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 362 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
724 std::vector<int> neighborColors; neighborColors.reserve(30);
259
3/6
✓ Branch 1 taken 362 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 362 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 362 times.
✗ Branch 7 not taken.
1086 std::vector<bool> colorUsed; colorUsed.reserve(30);
260
261 // dof to element map to speed up neighbor search
262
1/2
✓ Branch 1 taken 362 times.
✗ Branch 2 not taken.
724 const auto connectedElements = Detail::computeConnectedElements(gg);
263
264
17/19
✓ Branch 1 taken 319 times.
✓ Branch 2 taken 100519 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 100833 times.
✓ Branch 5 taken 43 times.
✓ Branch 6 taken 548238 times.
✓ Branch 7 taken 134 times.
✓ Branch 8 taken 487716 times.
✓ Branch 9 taken 275 times.
✓ Branch 10 taken 56793 times.
✓ Branch 11 taken 52 times.
✓ Branch 12 taken 109820 times.
✓ Branch 13 taken 56845 times.
✓ Branch 14 taken 109820 times.
✓ Branch 15 taken 44 times.
✓ Branch 17 taken 109820 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 109820 times.
✗ Branch 21 not taken.
1170550 for (const auto& element : elements(gg.gridView()))
265 {
266 // compute neighbor colors based on discretization-dependent stencil
267
2/2
✓ Branch 0 taken 697911 times.
✓ Branch 1 taken 362 times.
698273 neighborColors.clear();
268
1/2
✓ Branch 1 taken 698273 times.
✗ Branch 2 not taken.
698273 Detail::addNeighborColors(gg, element, coloring.colors, connectedElements, neighborColors);
269
270 // find smallest color (positive integer) not in neighborColors
271
1/2
✓ Branch 1 taken 698273 times.
✗ Branch 2 not taken.
698273 const auto color = Detail::smallestAvailableColor(neighborColors, colorUsed);
272
273 // assign color to element
274
8/8
✓ Branch 0 taken 3708 times.
✓ Branch 1 taken 166664 times.
✓ Branch 2 taken 530087 times.
✓ Branch 3 taken 1565 times.
✓ Branch 4 taken 170329 times.
✓ Branch 5 taken 43 times.
✓ Branch 6 taken 165968 times.
✓ Branch 7 taken 653 times.
1400297 coloring.colors[gg.elementMapper().index(element)] = color;
275
276 // add element to the set of elements with the same color
277
4/4
✓ Branch 0 taken 696055 times.
✓ Branch 1 taken 2218 times.
✓ Branch 2 taken 696055 times.
✓ Branch 3 taken 2218 times.
1396546 if (color < coloring.sets.size())
278
5/6
✓ Branch 1 taken 1566 times.
✓ Branch 2 taken 654123 times.
✓ Branch 3 taken 40366 times.
✓ Branch 4 taken 109482 times.
✓ Branch 5 taken 546207 times.
✗ Branch 6 not taken.
805537 coloring.sets[color].push_back(element.seed());
279 else
280
13/16
✗ Branch 0 not taken.
✓ Branch 1 taken 2184 times.
✓ Branch 2 taken 34 times.
✓ Branch 3 taken 338 times.
✓ Branch 4 taken 1846 times.
✓ Branch 5 taken 34 times.
✓ Branch 6 taken 338 times.
✓ Branch 7 taken 1846 times.
✓ Branch 8 taken 34 times.
✓ Branch 9 taken 338 times.
✓ Branch 10 taken 1846 times.
✓ Branch 11 taken 34 times.
✓ Branch 12 taken 338 times.
✓ Branch 13 taken 1846 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
6586 coloring.sets.push_back(std::vector<ElementSeed>{ element.seed() });
281 }
282
283
1/2
✓ Branch 0 taken 362 times.
✗ Branch 1 not taken.
362 if (verbosity > 0)
284
6/13
✓ Branch 1 taken 267 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 95 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 267 times.
✓ Branch 6 taken 95 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 362 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 267 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
729 std::cout << Fmt::format("Colored {} elements with {} colors in {} seconds.\n",
285
2/4
✓ Branch 2 taken 267 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 267 times.
✗ Branch 6 not taken.
362 gg.gridView().size(0), coloring.sets.size(), timer.elapsed());
286
287 362 return coloring;
288 }
289
290 //! Traits specifying if a given discretization tag supports coloring
291 template<class DiscretizationMethod>
292 struct SupportsColoring : public std::false_type {};
293
294 template<> struct SupportsColoring<DiscretizationMethods::CCTpfa> : public std::true_type {};
295 template<> struct SupportsColoring<DiscretizationMethods::CCMpfa> : public std::true_type {};
296 template<> struct SupportsColoring<DiscretizationMethods::Box> : public std::true_type {};
297 template<> struct SupportsColoring<DiscretizationMethods::FCStaggered> : public std::true_type {};
298 template<> struct SupportsColoring<DiscretizationMethods::FCDiamond> : public std::true_type {};
299 template<> struct SupportsColoring<DiscretizationMethods::PQ1Bubble> : public std::true_type {};
300
301 } // end namespace Dumux
302
303 #endif
304