GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/io/grid/gmshgriddatahandle.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 46 59 78.0%
Functions: 14 223 6.3%
Branches: 72 156 46.2%

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 InputOutput
10 * \brief A data handle for commucating grid data for gmsh grids
11 */
12 #ifndef DUMUX_GMSH_GRID_DATA_HANDLE_HH
13 #define DUMUX_GMSH_GRID_DATA_HANDLE_HH
14
15 #include <memory>
16 #include <algorithm>
17 #include <map>
18
19 #include <dune/common/parallel/communication.hh>
20 #include <dune/geometry/dimension.hh>
21 #include <dune/grid/common/partitionset.hh>
22 #include <dune/grid/common/datahandleif.hh>
23
24 // UGGrid specific includes
25 #if HAVE_DUNE_UGGRID
26 #include <dune/grid/uggrid.hh>
27 #endif
28
29 namespace Dumux {
30
31 /*!
32 * \ingroup InputOutput
33 * \brief A data handle for commucating grid data for gmsh grids
34 */
35 template<class Grid, class GridFactory, class Data>
36 struct GmshGridDataHandle : public Dune::CommDataHandleIF<GmshGridDataHandle<Grid, GridFactory, Data>, typename Data::value_type>
37 {
38 using GridView = typename Grid::LevelGridView;
39
40 4 GmshGridDataHandle(const Grid& grid, const GridFactory& gridFactory, Data& elementMarkers, Data& boundaryMarkers, Data& faceMarkers)
41 : gridView_(grid.levelGridView(0))
42 , idSet_(grid.localIdSet())
43 , elementMarkers_(elementMarkers)
44 , boundaryMarkers_(boundaryMarkers)
45
3/7
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
12 , faceMarkers_(faceMarkers)
46 {
47
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 const auto& indexSet = gridView_.indexSet();
48
49
8/14
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 7946 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 7946 times.
✓ Branch 12 taken 4 times.
✓ Branch 14 taken 7946 times.
✗ Branch 15 not taken.
15896 for (const auto& element : elements(gridView_, Dune::Partitions::interior))
50
6/14
✓ Branch 1 taken 7946 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 7946 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 7946 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 7946 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 7946 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 7946 times.
✗ Branch 17 not taken.
7946 std::swap(elementMarkers_[gridFactory.insertionIndex(element)], data_[idSet_.id(element)]);
51
52
5/10
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 13502 times.
13510 for (const auto& face : entities(gridView_, Dune::Codim<1>()))
53
5/11
✓ Branch 1 taken 13502 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 13502 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 13502 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 13502 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 13502 times.
✗ Branch 15 not taken.
13502 std::swap(faceMarkers_[indexSet.index(face)], data_[idSet_.id(face)]);
54 4 }
55
56 4 ~GmshGridDataHandle()
57 {
58 4 const auto& indexSet = gridView_.indexSet();
59
60 8 elementMarkers_.resize(indexSet.size(0));
61
4/6
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8852 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 8852 times.
✓ Branch 6 taken 4 times.
17708 for (const auto& element : elements(gridView_))
62 8852 std::swap(elementMarkers_[indexSet.index(element)], data_[idSet_.id(element)]);
63
64 8 faceMarkers_.resize(indexSet.size(1));
65
2/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 16489 times.
16497 for (const auto& face : entities(gridView_, Dune::Codim<1>()))
66 16489 std::swap(faceMarkers_[indexSet.index(face)], data_[idSet_.id(face)]);
67
68
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 boundaryMarkers_.resize(gridView_.grid().numBoundarySegments(), 0);
69
5/9
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 8852 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 8852 times.
✓ Branch 9 taken 4 times.
17708 for (const auto& element : elements(gridView_.grid().leafGridView()))
70 {
71
2/12
✗ Branch 0 not taken.
✓ Branch 1 taken 8852 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 35824 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
80500 for (const auto& intersection : intersections(gridView_.grid().leafGridView(), element))
72 {
73
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 938 times.
✓ Branch 2 taken 26034 times.
✗ Branch 3 not taken.
26972 if (intersection.boundary())
74 {
75
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
938 const auto marker = faceMarkers_[indexSet.index(element.template subEntity<1>(intersection.indexInInside()))];
76 938 boundaryMarkers_[intersection.boundarySegmentIndex()] = marker;
77 }
78 }
79 }
80 4 }
81
82 Dune::CommDataHandleIF<GmshGridDataHandle<Grid, GridFactory, Data>, typename Data::value_type>& interface()
83 { return *this; }
84
85 bool contains (int dim, int codim) const
86 24 { return codim == 0 || codim == 1; }
87
88 //! returns true if size per entity of given dim and codim is a constant
89 bool fixedSize(int dim, int codim) const
90 { return true; }
91
92 template<class EntityType>
93 std::size_t size (const EntityType& e) const
94 { return 1; }
95
96 template<class MessageBufferImp, class EntityType>
97 42704 void gather (MessageBufferImp& buff, const EntityType& e) const
98 42704 { buff.write(data_[idSet_.id(e)]); }
99
100 template<class MessageBufferImp, class EntityType>
101 void scatter (MessageBufferImp& buff, const EntityType& e, std::size_t n)
102 { buff.read(data_[idSet_.id(e)]); }
103
104 private:
105 using IdSet = typename Grid::LocalIdSet;
106
107 const GridView gridView_;
108 const IdSet &idSet_;
109 Data& elementMarkers_;
110 Data& boundaryMarkers_;
111 Data& faceMarkers_;
112 mutable std::map< typename IdSet::IdType, typename Data::value_type> data_;
113 };
114
115 #if HAVE_DUNE_UGGRID
116
117 /*!
118 * \ingroup InputOutput
119 * \brief A data handle for commucating grid data for gmsh grids (specialization for UGGrid)
120 */
121 template<class GridFactory, class Data, int dimgrid>
122 struct GmshGridDataHandle<Dune::UGGrid<dimgrid>, GridFactory, Data>
123 : public Dune::CommDataHandleIF<GmshGridDataHandle<Dune::UGGrid<dimgrid>, GridFactory, Data>, typename Data::value_type>
124 {
125 using Grid = Dune::UGGrid<dimgrid>;
126 using GridView = typename Grid::LevelGridView;
127
128 4 GmshGridDataHandle(const Grid& grid, const GridFactory& gridFactory, Data& elementMarkers, Data& boundaryMarkers)
129 : gridView_(grid.levelGridView(0))
130 , idSet_(grid.localIdSet())
131 , elementMarkers_(elementMarkers)
132
3/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
12 , boundaryMarkers_(boundaryMarkers)
133 {
134
5/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7946 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 7946 times.
✓ Branch 6 taken 4 times.
15896 for (const auto& element : elements(gridView_, Dune::Partitions::interior))
135
5/10
✓ Branch 2 taken 7946 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 7946 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 7946 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 7946 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 7946 times.
✗ Branch 15 not taken.
7946 std::swap(elementMarkers_[gridFactory.insertionIndex(element)], data_[idSet_.id(element)]);
136
137 // Depending on the Dune version, the boundary markers are present on
138 // all processes (<= 2.6) or on the root process only (>= 2.7). Try to
139 // handle this in a flexible way: determine if the minimum size over
140 // all processes of the boundary markers vector is zero. If yes, assume
141 // that the root process contains all markers and broadcast them.
142
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 auto bmSizeMin = boundaryMarkers_.size();
143
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 Dune::MPIHelper::getCommunication().min(&bmSizeMin, 1);
144
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (bmSizeMin == 0)
145 {
146
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 auto bmSize = boundaryMarkers_.size();
147
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 Dune::MPIHelper::getCommunication().broadcast(&bmSize, 1, 0);
148
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 boundaryMarkers_.resize(bmSize);
149
3/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
4 Dune::MPIHelper::getCommunication().broadcast(&boundaryMarkers_.front(), bmSize, 0);
150 }
151 4 }
152
153 4 ~GmshGridDataHandle()
154 {
155 4 const auto& indexSet = gridView_.indexSet();
156 4 elementMarkers_.resize(indexSet.size(0));
157
4/4
✓ Branch 1 taken 8265 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 8265 times.
✓ Branch 4 taken 4 times.
16534 for (const auto& element : elements(gridView_))
158 8265 std::swap(elementMarkers_[indexSet.index(element)], data_[idSet_.id(element)]);
159 4 }
160
161 Dune::CommDataHandleIF<GmshGridDataHandle<Grid, GridFactory, Data>, typename Data::value_type>& interface()
162 { return *this; }
163
164 bool contains (int dim, int codim) const
165 { return codim == 0 || codim == 1; }
166
167 //! returns true if size per entity of given dim and codim is a constant
168 bool fixedSize(int dim, int codim) const
169 { return true; }
170
171 template<class EntityType>
172 std::size_t size (const EntityType& e) const
173 { return 1; }
174
175 template<class MessageBufferImp, class EntityType>
176 15892 void gather (MessageBufferImp& buff, const EntityType& e) const
177 15892 { buff.write(data_[idSet_.id(e)]); }
178
179 template<class MessageBufferImp, class EntityType>
180 void scatter (MessageBufferImp& buff, const EntityType& e, std::size_t n)
181 { buff.read(data_[idSet_.id(e)]); }
182
183 private:
184 using IdSet = typename Grid::LocalIdSet;
185
186 const GridView gridView_;
187 const IdSet &idSet_;
188 Data& elementMarkers_;
189 Data& boundaryMarkers_;
190 mutable std::map< typename IdSet::IdType, typename Data::value_type> data_;
191 };
192
193 #endif // HAVE_DUNE_UGGRID
194
195 } // namespace Dumux
196
197 #endif
198