GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/io/grid/porenetwork/griddata.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 115 138 83.3%
Functions: 44 62 71.0%
Branches: 298 802 37.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 PoreNetworkModels
10 * \brief Class for grid data attached to dgf or gmsh grid files
11 */
12 #ifndef DUMUX_IO_PORENETWORKGRID_DATA_HH
13 #define DUMUX_IO_PORENETWORKGRID_DATA_HH
14
15 #include <algorithm>
16 #include <memory>
17 #include <string>
18 #include <type_traits>
19 #include <unordered_map>
20 #include <vector>
21 #include <fstream>
22
23 #include <dune/common/exceptions.hh>
24 #include <dune/grid/common/gridfactory.hh>
25 #include <dune/grid/common/mcmgmapper.hh>
26 #include <dune/grid/io/file/dgfparser/gridptr.hh>
27 #include <dune/grid/io/file/dgfparser/parser.hh>
28 #include <dune/grid/utility/persistentcontainer.hh>
29 #include <dune/geometry/axisalignedcubegeometry.hh>
30
31 #include <dumux/common/indextraits.hh>
32 #include <dumux/porenetwork/common/throatproperties.hh>
33
34 #include "parametersforgeneratedgrid.hh"
35
36 namespace Dumux::PoreNetwork {
37
38 /*!
39 * \ingroup PoreNetworkModels
40 * \brief Class for grid data attached to dgf or gmsh grid files
41 */
42 template <class Grid>
43 class GridData
44 {
45 static constexpr int dim = Grid::dimension;
46 static constexpr int dimWorld = Grid::dimensionworld;
47 using Intersection = typename Grid::LeafIntersection;
48 using Element = typename Grid::template Codim<0>::Entity;
49 using Vertex = typename Grid::template Codim<dim>::Entity;
50 using GridView = typename Grid::LeafGridView;
51 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
52 using SmallLocalIndex = typename IndexTraits<GridView>::SmallLocalIndex;
53 using StringVector = std::vector<std::string>;
54
55 using Scalar = typename Grid::ctype;
56 using PersistentParameterContainer = Dune::PersistentContainer<Grid, std::vector<typename Grid::ctype>>;
57 using ParametersForGeneratedGrid = Dumux::PoreNetwork::ParametersForGeneratedGrid<Grid, Scalar>;
58
59 public:
60
61 //! constructor for dgf grid data
62 24 GridData(Dune::GridPtr<Grid> grid, const std::string& paramGroup)
63 : dgfGrid_(grid)
64 , isDgfData_(true)
65 , paramGroup_(paramGroup)
66
8/26
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 18 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 18 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 18 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 18 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 18 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 18 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 18 times.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ 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.
24 , numSubregions_(0)
67 {
68
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
24 setParameterIndices_();
69 24 }
70
71 //! constructor for non-dgf grid data
72 33 GridData(std::shared_ptr<Grid> grid, const std::string& paramGroup)
73 : factoryGrid_(grid)
74 , isDgfData_(false)
75
7/24
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 21 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 21 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 21 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 21 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 21 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 21 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
33 , paramGroup_(paramGroup)
76 {
77
1/2
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
33 numSubregions_ = getParamFromGroup<std::size_t>(paramGroup_, "Grid.NumSubregions", 0);
78
1/2
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
33 setParameterIndices_();
79
3/6
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 21 times.
33 parametersForGeneratedGrid_ = std::make_unique<ParametersForGeneratedGrid>(gridView_(), paramGroup);
80 33 }
81
82 /*!
83 * \brief Call the parameters function of the DGF grid pointer if available for vertex data
84 * \note You can only pass vertices that exist on level 0!
85 */
86 447001 const std::vector<double>& parameters(const Vertex& vertex) const
87 {
88
4/4
✓ Branch 0 taken 122460 times.
✓ Branch 1 taken 320457 times.
✓ Branch 2 taken 121958 times.
✓ Branch 3 taken 502 times.
447001 if (isDgfData_ && !useCopiedDgfData_)
89 122080 return dgfGrid_.parameters(vertex);
90 else
91 {
92
2/4
✗ Branch 2 not taken.
✓ Branch 3 taken 320959 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 320959 times.
649842 assert(!(*vertexParameters_)[vertex].empty() && "No parameters available.");
93 return (*vertexParameters_)[vertex];
94 }
95 }
96
97 /*!
98 * \brief Call the parameters function of the DGF grid pointer if available for element data
99 */
100 320740 const std::vector<double>& parameters(const Element& element) const
101 {
102
4/4
✓ Branch 0 taken 212580 times.
✓ Branch 1 taken 106480 times.
✓ Branch 2 taken 211982 times.
✓ Branch 3 taken 598 times.
320740 if (isDgfData_ && !useCopiedDgfData_)
103 {
104
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 211982 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 211982 times.
424196 if (element.hasFather())
105 {
106 auto level0Element = element;
107 while(level0Element.hasFather())
108 level0Element = level0Element.father();
109
110 return dgfGrid_.parameters(level0Element);
111 }
112 else
113 {
114 212098 return dgfGrid_.parameters(element);
115 }
116 }
117 else
118 {
119
2/4
✗ Branch 2 not taken.
✓ Branch 3 taken 107078 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 107078 times.
217284 assert(!(*elementParameters_)[element].empty() && "No parameters available.");
120 return (*elementParameters_)[element];
121 }
122 }
123
124 /*!
125 * \brief Call the parameters function of the DGF grid pointer if available
126 */
127 template <class GridImp, class IntersectionImp>
128 const Dune::DGFBoundaryParameter::type& parameters(const Dune::Intersection<GridImp, IntersectionImp>& intersection) const
129 {
130 if (isDgfData_)
131 return dgfGrid_.parameters(intersection);
132 else
133 DUNE_THROW(Dune::InvalidStateException, "The parameters method is only available if the grid was constructed with a DGF file.");
134 }
135
136 /*!
137 * \brief Returns the coordination numbers for all pore bodies.
138 */
139 59 std::vector<SmallLocalIndex> getCoordinationNumbers() const
140 {
141
4/4
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 28 times.
✓ Branch 4 taken 15 times.
✓ Branch 5 taken 28 times.
118 std::vector<SmallLocalIndex> coordinationNumbers(gridView_().size(dim), 0);
142
143
4/4
✓ Branch 1 taken 78299 times.
✓ Branch 2 taken 43 times.
✓ Branch 3 taken 78299 times.
✓ Branch 4 taken 43 times.
79020 for (const auto &element : elements(gridView_()))
144 {
145
2/2
✓ Branch 0 taken 156598 times.
✓ Branch 1 taken 78299 times.
236883 for (SmallLocalIndex vIdxLocal = 0; vIdxLocal < 2; ++vIdxLocal)
146 {
147
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 156598 times.
✓ Branch 3 taken 156598 times.
✗ Branch 4 not taken.
157922 const auto vIdxGlobal = gridView_().indexSet().subIndex(element, vIdxLocal, dim);
148 315844 coordinationNumbers[vIdxGlobal] += 1;
149 }
150 }
151
152
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 43 times.
177 if (std::any_of(coordinationNumbers.begin(), coordinationNumbers.end(), [](auto i){ return i == 0; }))
153 DUNE_THROW(Dune::InvalidStateException, "One of the pores is not connected to another pore. SanitizeGrid will not help in this case. Check your grid file");
154
155 59 return coordinationNumbers;
156 }
157
158 /*!
159 * \brief Assign parameters for generically created grids
160 */
161 33 void assignParameters()
162 {
163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
33 if (isDgfData_)
164 DUNE_THROW(Dune::InvalidStateException, "Assigning parameter not possible for dgf gids");
165
166 33 const auto numVertexParams = vertexParameterNames_.size();
167 33 const auto numElementParams = elementParameterNames_.size();
168
2/4
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 21 times.
66 vertexParameters_ = makeParamContainer_(*factoryGrid_, numVertexParams, 1/*codim*/);
169
2/4
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 21 times.
66 elementParameters_ = makeParamContainer_(*factoryGrid_, numElementParams, 0/*codim*/);
170
171 33 auto setParamHelper = [&](const auto& entity, const std::string& param, const Scalar value)
172 {
173
27/90
✓ Branch 1 taken 16619 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1000 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 125 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 16619 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 32943 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 32943 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 10476 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 10476 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 10476 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 1625 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 1625 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 1625 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 43419 times.
✗ Branch 38 not taken.
✓ Branch 41 taken 5188 times.
✗ Branch 42 not taken.
✓ Branch 44 taken 11556 times.
✗ Branch 45 not taken.
✓ Branch 48 taken 138 times.
✗ Branch 49 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✓ Branch 57 taken 138 times.
✗ Branch 58 not taken.
✓ Branch 60 taken 138 times.
✗ Branch 61 not taken.
✓ Branch 63 taken 138 times.
✗ Branch 64 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✓ Branch 84 taken 138 times.
✗ Branch 85 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✓ Branch 91 taken 138 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 194 times.
✗ Branch 96 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✗ Branch 101 not taken.
✗ Branch 102 not taken.
✓ Branch 104 taken 194 times.
✗ Branch 105 not taken.
✓ Branch 107 taken 278 times.
✗ Branch 108 not taken.
✓ Branch 110 taken 278 times.
✗ Branch 111 not taken.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✗ Branch 116 not taken.
✗ Branch 117 not taken.
✗ Branch 119 not taken.
✗ Branch 120 not taken.
✗ Branch 122 not taken.
✗ Branch 123 not taken.
✗ Branch 125 not taken.
✗ Branch 126 not taken.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✓ Branch 131 taken 278 times.
✗ Branch 132 not taken.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✓ Branch 138 taken 194 times.
✗ Branch 139 not taken.
198959 setParameter_(entity, param, value);
174 };
175
176 33 auto getParamHelper = [&](const auto& entity, const std::string& param)
177 {
178
29/60
✓ Branch 1 taken 10476 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 43381 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 43381 times.
✓ Branch 9 taken 38 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 45006 times.
✓ Branch 12 taken 38 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 45006 times.
✓ Branch 15 taken 19 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 43592 times.
✓ Branch 18 taken 19 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 43592 times.
✓ Branch 21 taken 19 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 19 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 16579 times.
✗ Branch 28 not taken.
✓ Branch 31 taken 40 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 138 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 138 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 69 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 69 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 69 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 69 times.
✗ Branch 50 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✓ Branch 56 taken 138 times.
✗ Branch 57 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✓ Branch 63 taken 278 times.
✗ Branch 64 not taken.
✓ Branch 66 taken 278 times.
✗ Branch 67 not taken.
✓ Branch 69 taken 243 times.
✗ Branch 70 not taken.
✓ Branch 72 taken 243 times.
✗ Branch 73 not taken.
✓ Branch 75 taken 243 times.
✗ Branch 76 not taken.
✓ Branch 78 taken 243 times.
✗ Branch 79 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✓ Branch 85 taken 194 times.
✗ Branch 86 not taken.
293617 return getParameter(entity, param);
179 };
180
181 66 parametersForGeneratedGrid_->assignParameters(setParamHelper, getParamHelper, numSubregions_);
182 33 }
183
184 8 void resizeParameterContainers()
185 {
186 // resize the parameters
187
4/10
✓ 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.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
24 vertexParameters_->resize();
188
4/10
✓ 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.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
24 elementParameters_->resize();
189 8 vertexParameters_->shrinkToFit();
190 8 elementParameters_->shrinkToFit();
191 8 }
192
193 8 void copyDgfData()
194 {
195
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
8 if (!isDgfData_)
196 DUNE_THROW(Dune::InvalidStateException, "copying dgf data only works when a dgf grid is actually used");
197
198 8 useCopiedDgfData_ = true;
199
3/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
8 const auto someVertex = *(vertices(gridView_()).begin());
200 8 const auto someElement = *(elements(gridView_()).begin());
201 8 const auto numVertexParams = dgfGrid_.parameters(someVertex).size();
202 8 const auto numElementParams = dgfGrid_.parameters(someElement).size();
203
2/4
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
16 vertexParameters_ = makeParamContainer_(*dgfGrid_, numVertexParams, 1);
204
2/4
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
16 elementParameters_ = makeParamContainer_(*dgfGrid_, numElementParams, 0);
205
206
4/4
✓ Branch 1 taken 208 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 208 times.
✓ Branch 4 taken 4 times.
424 for (const auto& element : elements(gridView_()))
207 {
208
2/2
✓ Branch 0 taken 624 times.
✓ Branch 1 taken 208 times.
1664 for (int i = 0; i < numElementParams; ++i)
209 1248 (*elementParameters_)[element][i] = dgfGrid_.parameters(element)[i];
210 }
211
212
4/4
✓ Branch 1 taken 186 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 186 times.
✓ Branch 4 taken 4 times.
380 for (const auto& vertex : vertices(gridView_()))
213 {
214
2/2
✓ Branch 0 taken 558 times.
✓ Branch 1 taken 186 times.
1488 for (int i = 0; i < numVertexParams; ++i)
215 1116 (*vertexParameters_)[vertex][i] = dgfGrid_.parameters(vertex)[i];
216 }
217 8 }
218
219 /*!
220 * \brief Return the index for a given parameter name
221 */
222 837057 int parameterIndex(const std::string& paramName) const
223 {
224 // make sure the string is present in the map, throw a Dumux exception otherwise (and not a std one)
225 // the [] operator can't be used here due to const correctness
226
1/2
✓ Branch 1 taken 831975 times.
✗ Branch 2 not taken.
837057 if (static_cast<bool>(parameterIndex_.count(paramName)))
227 837057 return parameterIndex_.at(paramName);
228 else
229 {
230 std::stringstream list;
231 list << "List of parameter indices:\n";
232 for (const auto& entry : parameterIndex_)
233 list << entry.first << " " << entry.second << "\n";
234
235 std::string msg;
236 if (paramName.find("Throat") != std::string::npos)
237 msg = "Make sure to include it in the vector of parameter names as a comment in the DGF file: Element Parameters = ... " + paramName + " ...";
238 else if (paramName.find("Pore") != std::string::npos)
239 msg = "Make sure to include it in the vector of parameter names as a comment in the DGF file: Vertex Parameters = ... " + paramName + " ...";
240
241 DUNE_THROW(Dumux::ParameterException, paramName << " not set in the grid file. \n" << msg << "\n" << list.str());
242 }
243 }
244
245 /*!
246 * \brief Return the parameter group
247 */
248 const std::string& paramGroup() const
249
4/16
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 13 taken 24 times.
✗ Branch 14 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 5 times.
✗ Branch 21 not taken.
✓ Branch 24 taken 2 times.
✗ Branch 25 not taken.
38 { return paramGroup_; }
250
251 /*!
252 * \brief Return if a given element parameter is provided by the grid
253 */
254 bool gridHasElementParameter(const std::string& param) const
255 {
256
2/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 169 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
373 return std::any_of(elementParameterNames_.begin(), elementParameterNames_.end(), [&param]( const auto& i ){ return (i == param); });
257 }
258
259 /*!
260 * \brief Return if a given vertex parameter is provided by the grid
261 */
262 bool gridHasVertexParameter(const std::string& param) const
263 {
264
2/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
106 return std::any_of(vertexParameterNames_.begin(), vertexParameterNames_.end(), [&param]( const auto& i ){ return (i == param); });
265 }
266
267 /*!
268 * \brief Returns the value of an element parameter
269 */
270 223629 Scalar getParameter(const Element& element, const std::string& param) const
271 223629 { return parameters(element)[parameterIndex(param)]; }
272
273 /*!
274 * \brief Returns the value of an vertex parameter
275 */
276 402297 Scalar getParameter(const Vertex& vertex, const std::string& param) const
277 402297 { return parameters(vertex)[parameterIndex(param)]; }
278
279 /*!
280 * \brief Returns the pore label at a given position for a generic grid.
281 * This is needed by the grid creator in case not all parameters are initialized yet.
282 */
283 int poreLabelAtPosForGenericGrid(const GlobalPosition& pos) const
284 { return parametersForGeneratedGrid_->boundaryFaceMarkerAtPos(pos); }
285
286 /*!
287 * \brief Returns the names of the vertex parameters
288 */
289 const std::vector<std::string>& vertexParameterNames() const
290 20 { return vertexParameterNames_; }
291
292 /*!
293 * \brief Returns the names of the element parameters
294 */
295 const std::vector<std::string>& elementParameterNames() const
296
3/6
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
20 { return elementParameterNames_; }
297
298 private:
299
300 148218 void setParameter_(const Element& element, const std::string& param, const Scalar value)
301 296436 { (*elementParameters_)[element][parameterIndex(param)] = value; }
302
303 53219 void setParameter_(const Vertex& vertex, const std::string& param, const Scalar value)
304 106438 { (*vertexParameters_)[vertex][parameterIndex(param)] = value; }
305
306 57 void setParameterIndices_()
307 {
308
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 18 times.
57 if (!isDgfData_)
309 {
310
15/30
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 21 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 21 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 21 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 21 times.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 21 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 21 times.
✓ Branch 26 taken 63 times.
✓ Branch 27 taken 21 times.
✓ Branch 28 taken 21 times.
✓ Branch 29 taken 42 times.
✓ Branch 31 taken 21 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 21 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 21 times.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
165 vertexParameterNames_ = StringVector{"PoreInscribedRadius", "PoreVolume", "PoreLabel"};
311
18/30
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 21 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 21 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 21 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 21 times.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 21 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 21 times.
✓ Branch 26 taken 63 times.
✓ Branch 27 taken 21 times.
✓ Branch 28 taken 21 times.
✓ Branch 29 taken 42 times.
✓ Branch 30 taken 1 times.
✓ Branch 31 taken 20 times.
✓ Branch 32 taken 1 times.
✓ Branch 33 taken 20 times.
✓ Branch 34 taken 1 times.
✓ Branch 35 taken 20 times.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
165 elementParameterNames_ = StringVector{"ThroatInscribedRadius", "ThroatLength", "ThroatLabel"};
312
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 20 times.
33 if (numSubregions_ > 0)
313 {
314
5/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
2 vertexParameterNames_.push_back("PoreRegionId");
315
4/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
2 elementParameterNames_.push_back("ThroatRegionId");
316 }
317 }
318 else // DGF grid data
319 {
320 // treat vertex parameter names
321
5/12
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 18 times.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 18 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 18 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
48 vertexParameterNames_ = dgfFileParameterNames_("Vertex");
322
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
48 if (vertexParameterNames_.empty())
323 DUNE_THROW(Dune::InvalidStateException, "No vertex parameter names specified in dgf file. Set '% Vertex parameters: Param1 Param2 ...'");
324
325 // treat element parameter names
326
5/12
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 18 times.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 18 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 18 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
48 elementParameterNames_ = dgfFileParameterNames_("Element");
327
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
48 if (elementParameterNames_.empty())
328 DUNE_THROW(Dune::InvalidStateException, "No element parameter names specified in dgf file. Set '% Element parameters: Param1 Param2 ...'");
329
330 // make sure that the number of specified parameters matches with the dgf file
331
5/10
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 18 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 18 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 18 times.
24 if (const auto& someElement = *(elements(gridView_()).begin()); elementParameterNames_.size() != dgfGrid_.nofParameters(someElement))
332 DUNE_THROW(Dune::InvalidStateException, "Number of user-specified element parameters (" << elementParameterNames_.size()
333 << ") does not match number of element parameters in dgf file (" << dgfGrid_.nofParameters(someElement) << ")");
334
335
5/10
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 18 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 18 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 18 times.
✗ Branch 10 not taken.
24 if (const auto& someVertex = *(vertices(gridView_()).begin()); vertexParameterNames_.size() != dgfGrid_.nofParameters(someVertex))
336 DUNE_THROW(Dune::InvalidStateException, "Number of user-specified vertex parameters (" << vertexParameterNames_.size()
337 << ") does not match number of vertex parameters in dgf file (" << dgfGrid_.nofParameters(someVertex) << ")");
338 }
339
340
4/4
✓ Branch 0 taken 109 times.
✓ Branch 1 taken 39 times.
✓ Branch 2 taken 109 times.
✓ Branch 3 taken 39 times.
440 for (int i = 0; i < vertexParameterNames_.size(); ++i)
341 {
342 489 std::cout << vertexParameterNames_[i] << " is vertex parameter " << i << std::endl;
343 326 parameterIndex_[vertexParameterNames_[i]] = i;
344 }
345
346
4/4
✓ Branch 0 taken 124 times.
✓ Branch 1 taken 39 times.
✓ Branch 2 taken 124 times.
✓ Branch 3 taken 39 times.
470 for (int i = 0; i < elementParameterNames_.size(); ++i)
347 {
348 534 std::cout << elementParameterNames_[i] << " is element parameter " << i << std::endl;
349 356 parameterIndex_[elementParameterNames_[i]] = i;
350 }
351 57 }
352
353 /*!
354 * \brief Initializes and returns a container for vertex (codim dim) or element (codim 0) data
355 *
356 * \param grid The grid
357 * \param numParams The number of parameters
358 * \param codim The codimension
359 */
360 82 auto makeParamContainer_(const Grid& grid, int numParams, int codim) const
361 {
362 82 auto parameters = std::make_unique<PersistentParameterContainer>(grid, codim);
363
4/12
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 50 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 50 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 50 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
246 (*parameters).resize();
364
5/6
✓ Branch 0 taken 61180 times.
✓ Branch 1 taken 50 times.
✓ Branch 2 taken 61180 times.
✓ Branch 3 taken 50 times.
✓ Branch 5 taken 61180 times.
✗ Branch 6 not taken.
62728 for (auto&& v : (*parameters))
365
1/2
✓ Branch 1 taken 61180 times.
✗ Branch 2 not taken.
62400 v.resize(numParams);
366 82 return parameters;
367 }
368
369 48 StringVector dgfFileParameterNames_(const std::string& entity) const
370 {
371
1/2
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
48 StringVector paramNames;
372 {
373
2/4
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 36 times.
✗ Branch 5 not taken.
48 std::ifstream gridFile(getParamFromGroup<std::string>(paramGroup_, "Grid.File"));
374
6/8
✓ Branch 1 taken 21286 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21250 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 21250 times.
✓ Branch 6 taken 36 times.
✓ Branch 7 taken 36 times.
✗ Branch 8 not taken.
22446 for (std::string line; std::getline(gridFile, line); )
375 {
376 // handle Windows file endings (if any)
377 111510 line.erase( std::remove(line.begin(), line.end(), '\r'), line.end() );
378
379 // extract parameter names
380
4/6
✓ Branch 1 taken 21250 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 21250 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 21214 times.
✓ Branch 7 taken 36 times.
44604 if (line.find(entity + " parameters:", 0) != std::string::npos)
381 {
382
2/6
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 36 times.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
96 std::istringstream iss(line.substr(line.find(":")+1, std::string::npos));
383
6/10
✓ Branch 1 taken 177 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 141 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 141 times.
✓ Branch 6 taken 36 times.
✓ Branch 7 taken 36 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
333 for (std::string item; std::getline(iss, item, ' '); )
384
4/4
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 105 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 105 times.
378 if (!item.empty())
385
1/2
✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
141 paramNames.push_back(item);
386 }
387 }
388 }
389 48 return paramNames;
390 }
391
392 /*!
393 * \brief Return the gridView this grid geometry object lives on
394 */
395 const GridView gridView_() const
396
35/56
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 9 times.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 13 times.
✓ Branch 15 taken 16 times.
✓ Branch 16 taken 11 times.
✓ Branch 17 taken 24 times.
✓ Branch 18 taken 2482 times.
✓ Branch 19 taken 152792 times.
✗ 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 taken 2 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 2 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 76 times.
✓ Branch 34 taken 2 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 2 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 2 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 2 times.
✓ Branch 41 taken 8 times.
✓ Branch 42 taken 2 times.
✓ Branch 43 taken 8 times.
✓ Branch 44 taken 140 times.
✓ Branch 45 taken 556 times.
✓ Branch 48 taken 2 times.
✗ Branch 49 not taken.
✓ Branch 50 taken 2 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 2 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 2 times.
✓ Branch 55 taken 2 times.
✓ Branch 56 taken 2 times.
✓ Branch 57 taken 2 times.
✓ Branch 58 taken 276 times.
✓ Branch 59 taken 276 times.
156757 { return isDgfData_ ? dgfGrid_->leafGridView() : factoryGrid_->leafGridView(); }
397
398 // dgf grid data
399 Dune::GridPtr<Grid> dgfGrid_;
400
401 std::shared_ptr<Grid> factoryGrid_;
402
403 bool isDgfData_ = false;
404 bool useCopiedDgfData_ = false;
405 std::string paramGroup_;
406
407 std::unique_ptr<ParametersForGeneratedGrid> parametersForGeneratedGrid_;
408
409 std::vector<std::string> vertexParameterNames_;
410 std::vector<std::string> elementParameterNames_;
411
412 std::unique_ptr<PersistentParameterContainer> vertexParameters_;
413 std::unique_ptr<PersistentParameterContainer> elementParameters_;
414
415 std::size_t numSubregions_;
416
417 std::unordered_map<std::string, int> parameterIndex_;
418 };
419
420 } // namespace Dumux::PoreNetwork
421
422 #endif
423