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 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 | 24 | : dgfGrid_(grid) | |
64 | 24 | , isDgfData_(true) | |
65 |
1/2✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
|
24 | , paramGroup_(paramGroup) |
66 |
2/4✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
|
48 | , 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 | 37 | GridData(std::shared_ptr<Grid> grid, const std::string& paramGroup) | |
73 | 37 | : factoryGrid_(grid) | |
74 | 37 | , isDgfData_(false) | |
75 |
2/4✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 25 times.
✗ Branch 6 not taken.
|
111 | , paramGroup_(paramGroup) |
76 | { | ||
77 |
1/2✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
|
37 | numSubregions_ = getParamFromGroup<std::size_t>(paramGroup_, "Grid.NumSubregions", 0); |
78 |
1/2✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
|
37 | setParameterIndices_(); |
79 |
1/2✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
|
37 | parametersForGeneratedGrid_ = std::make_unique<ParametersForGeneratedGrid>(gridView_(), paramGroup); |
80 | 37 | } | |
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 | 447053 | const std::vector<double>& parameters(const Vertex& vertex) const | |
87 | { | ||
88 |
4/4✓ Branch 0 taken 122460 times.
✓ Branch 1 taken 320509 times.
✓ Branch 2 taken 121958 times.
✓ Branch 3 taken 502 times.
|
447053 | if (isDgfData_ && !useCopiedDgfData_) |
89 | 122080 | return dgfGrid_.parameters(vertex); | |
90 | else | ||
91 | { | ||
92 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 321011 times.
|
324973 | 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 | 320744 | const std::vector<double>& parameters(const Element& element) const | |
101 | { | ||
102 |
4/4✓ Branch 0 taken 212580 times.
✓ Branch 1 taken 106484 times.
✓ Branch 2 taken 211982 times.
✓ Branch 3 taken 598 times.
|
320744 | if (isDgfData_ && !useCopiedDgfData_) |
103 | { | ||
104 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 211982 times.
|
212098 | 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 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 107082 times.
|
108646 | 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 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 32 times.
|
63 | std::vector<SmallLocalIndex> getCoordinationNumbers() const |
140 | { | ||
141 |
2/2✓ Branch 2 taken 15 times.
✓ Branch 3 taken 32 times.
|
63 | std::vector<SmallLocalIndex> coordinationNumbers(gridView_().size(dim), 0); |
142 | |||
143 |
2/2✓ Branch 2 taken 78303 times.
✓ Branch 3 taken 47 times.
|
157993 | for (const auto &element : elements(gridView_())) |
144 | { | ||
145 |
2/2✓ Branch 0 taken 156606 times.
✓ Branch 1 taken 78303 times.
|
236895 | for (SmallLocalIndex vIdxLocal = 0; vIdxLocal < 2; ++vIdxLocal) |
146 | { | ||
147 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 156606 times.
|
157930 | const auto vIdxGlobal = gridView_().indexSet().subIndex(element, vIdxLocal, dim); |
148 | 157930 | coordinationNumbers[vIdxGlobal] += 1; | |
149 | } | ||
150 | } | ||
151 | |||
152 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
|
63 | 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 | 63 | return coordinationNumbers; | |
156 | ✗ | } | |
157 | |||
158 | /*! | ||
159 | * \brief Assign parameters for generically created grids | ||
160 | */ | ||
161 | 37 | void assignParameters() | |
162 | { | ||
163 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
37 | if (isDgfData_) |
164 | ✗ | DUNE_THROW(Dune::InvalidStateException, "Assigning parameter not possible for dgf gids"); | |
165 | |||
166 | 37 | const auto numVertexParams = vertexParameterNames_.size(); | |
167 | 37 | const auto numElementParams = elementParameterNames_.size(); | |
168 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
|
37 | vertexParameters_ = makeParamContainer_(*factoryGrid_, numVertexParams, 1/*codim*/); |
169 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
|
37 | elementParameters_ = makeParamContainer_(*factoryGrid_, numElementParams, 0/*codim*/); |
170 | |||
171 | 199019 | auto setParamHelper = [&](const auto& entity, const std::string& param, const Scalar value) | |
172 | { | ||
173 |
27/90✓ Branch 1 taken 16627 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 16627 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 32947 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 32947 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 43423 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 5188 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 11564 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 138 times.
✗ Branch 47 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✓ Branch 55 taken 138 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 138 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 138 times.
✗ Branch 62 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✓ Branch 82 taken 138 times.
✗ Branch 83 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✓ Branch 88 taken 138 times.
✗ Branch 89 not taken.
✓ Branch 91 taken 194 times.
✗ Branch 92 not taken.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✓ Branch 100 taken 194 times.
✗ Branch 101 not taken.
✓ Branch 103 taken 278 times.
✗ Branch 104 not taken.
✓ Branch 106 taken 278 times.
✗ Branch 107 not taken.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 112 not taken.
✗ Branch 113 not taken.
✗ Branch 115 not taken.
✗ Branch 116 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
✗ Branch 121 not taken.
✗ Branch 122 not taken.
✗ Branch 124 not taken.
✗ Branch 125 not taken.
✓ Branch 127 taken 278 times.
✗ Branch 128 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✓ Branch 133 taken 194 times.
✗ Branch 134 not taken.
|
198995 | setParameter_(entity, param, value); |
174 | }; | ||
175 | |||
176 | 293686 | auto getParamHelper = [&](const auto& entity, const std::string& param) | |
177 | { | ||
178 |
24/54✓ Branch 1 taken 10476 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 43385 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 43423 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 45048 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 45029 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 43615 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 43615 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 19 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 16587 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 40 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 138 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 138 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 69 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 not taken.
✗ Branch 50 not taken.
✓ Branch 52 taken 138 times.
✗ Branch 53 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✓ Branch 58 taken 278 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 278 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 243 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 243 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 243 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 243 times.
✗ Branch 74 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✓ Branch 79 taken 194 times.
✗ Branch 80 not taken.
|
293649 | return getParameter(entity, param); |
179 | }; | ||
180 | |||
181 | 37 | parametersForGeneratedGrid_->assignParameters(setParamHelper, getParamHelper, numSubregions_); | |
182 | 37 | } | |
183 | |||
184 | 8 | void resizeParameterContainers() | |
185 | { | ||
186 | // resize the parameters | ||
187 |
2/4✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
|
8 | vertexParameters_->resize(); |
188 |
2/4✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
|
8 | 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 | 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 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
8 | vertexParameters_ = makeParamContainer_(*dgfGrid_, numVertexParams, 1); |
204 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
|
8 | elementParameters_ = makeParamContainer_(*dgfGrid_, numElementParams, 0); |
205 | |||
206 |
2/2✓ Branch 2 taken 208 times.
✓ Branch 3 taken 4 times.
|
840 | 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 |
2/2✓ Branch 2 taken 186 times.
✓ Branch 3 taken 4 times.
|
752 | 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 | 837153 | 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 | 837153 | if (static_cast<bool>(parameterIndex_.count(paramName))) | |
227 | 837153 | 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 | 42 | 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 28 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.
|
42 | { return paramGroup_; } |
250 | |||
251 | /*! | ||
252 | * \brief Return if a given element parameter is provided by the grid | ||
253 | */ | ||
254 | 73 | bool gridHasElementParameter(const std::string& param) const | |
255 | { | ||
256 |
10/14✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 69 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 69 times.
✓ Branch 12 taken 23 times.
✓ Branch 13 taken 46 times.
|
281 | return std::any_of(elementParameterNames_.begin(), elementParameterNames_.end(), [¶m]( const auto& i ){ return (i == param); }); |
257 | } | ||
258 | |||
259 | /*! | ||
260 | * \brief Return if a given vertex parameter is provided by the grid | ||
261 | */ | ||
262 | 25 | bool gridHasVertexParameter(const std::string& param) const | |
263 | { | ||
264 |
8/14✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 11 taken 11 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 11 times.
|
71 | return std::any_of(vertexParameterNames_.begin(), vertexParameterNames_.end(), [¶m]( 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 | 402329 | Scalar getParameter(const Vertex& vertex, const std::string& param) const | |
277 | 402329 | { 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 | 14 | const std::vector<std::string>& vertexParameterNames() const | |
290 | 20 | { return vertexParameterNames_; } | |
291 | |||
292 | /*! | ||
293 | * \brief Returns the names of the element parameters | ||
294 | */ | ||
295 | 14 | 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 | 148230 | void setParameter_(const Element& element, const std::string& param, const Scalar value) | |
301 | 148230 | { (*elementParameters_)[element][parameterIndex(param)] = value; } | |
302 | |||
303 | 53243 | void setParameter_(const Vertex& vertex, const std::string& param, const Scalar value) | |
304 | 53243 | { (*vertexParameters_)[vertex][parameterIndex(param)] = value; } | |
305 | |||
306 | 61 | void setParameterIndices_() | |
307 | { | ||
308 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 18 times.
|
61 | if (!isDgfData_) |
309 | { | ||
310 |
4/8✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 25 times.
✓ Branch 8 taken 75 times.
✓ Branch 9 taken 25 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
185 | vertexParameterNames_ = StringVector{"PoreInscribedRadius", "PoreVolume", "PoreLabel"}; |
311 |
4/8✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 25 times.
✓ Branch 8 taken 75 times.
✓ Branch 9 taken 25 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
185 | elementParameterNames_ = StringVector{"ThroatInscribedRadius", "ThroatLength", "ThroatLabel"}; |
312 | 37 | if (numSubregions_ > 0) | |
313 | { | ||
314 | 2 | vertexParameterNames_.push_back("PoreRegionId"); | |
315 | 2 | elementParameterNames_.push_back("ThroatRegionId"); | |
316 | } | ||
317 | } | ||
318 | else // DGF grid data | ||
319 | { | ||
320 | // treat vertex parameter names | ||
321 |
1/2✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
|
24 | vertexParameterNames_ = dgfFileParameterNames_("Vertex"); |
322 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
24 | if (vertexParameterNames_.empty()) |
323 |
0/20✗ 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 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
|
24 | DUNE_THROW(Dune::InvalidStateException, "No vertex parameter names specified in dgf file. Set '% Vertex parameters: Param1 Param2 ...'"); |
324 | |||
325 | // treat element parameter names | ||
326 |
1/2✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
|
24 | elementParameterNames_ = dgfFileParameterNames_("Element"); |
327 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
24 | 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 |
1/2✗ Branch 1 not taken.
✓ Branch 2 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 |
1/2✓ Branch 1 taken 18 times.
✗ Branch 2 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 |
2/2✓ Branch 0 taken 121 times.
✓ Branch 1 taken 43 times.
|
236 | for (int i = 0; i < vertexParameterNames_.size(); ++i) |
341 | { | ||
342 | 175 | std::cout << vertexParameterNames_[i] << " is vertex parameter " << i << std::endl; | |
343 | 175 | parameterIndex_[vertexParameterNames_[i]] = i; | |
344 | } | ||
345 | |||
346 |
2/2✓ Branch 0 taken 136 times.
✓ Branch 1 taken 43 times.
|
251 | for (int i = 0; i < elementParameterNames_.size(); ++i) |
347 | { | ||
348 | 190 | std::cout << elementParameterNames_[i] << " is element parameter " << i << std::endl; | |
349 | 190 | parameterIndex_[elementParameterNames_[i]] = i; | |
350 | } | ||
351 | 172 | } | |
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 | 90 | auto makeParamContainer_(const Grid& grid, int numParams, int codim) const | |
361 | { | ||
362 |
1/2✓ Branch 2 taken 58 times.
✗ Branch 3 not taken.
|
90 | auto parameters = std::make_unique<PersistentParameterContainer>(grid, codim); |
363 |
2/6✓ Branch 1 taken 58 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 58 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
90 | (*parameters).resize(); |
364 |
2/2✓ Branch 0 taken 61192 times.
✓ Branch 1 taken 58 times.
|
62502 | for (auto&& v : (*parameters)) |
365 |
1/2✓ Branch 1 taken 61192 times.
✗ Branch 2 not taken.
|
62412 | v.resize(numParams); |
366 | 90 | return parameters; | |
367 | ✗ | } | |
368 | |||
369 | 48 | StringVector dgfFileParameterNames_(const std::string& entity) const | |
370 | { | ||
371 | 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.
|
96 | std::ifstream gridFile(getParamFromGroup<std::string>(paramGroup_, "Grid.File")); |
374 |
3/4✓ Branch 1 taken 21286 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21250 times.
✓ Branch 4 taken 36 times.
|
22398 | for (std::string line; std::getline(gridFile, line); ) |
375 | { | ||
376 | // handle Windows file endings (if any) | ||
377 | 22302 | line.erase( std::remove(line.begin(), line.end(), '\r'), line.end() ); | |
378 | |||
379 | // extract parameter names | ||
380 |
3/4✓ Branch 1 taken 21250 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 21214 times.
|
22302 | if (line.find(entity + " parameters:", 0) != std::string::npos) |
381 | { | ||
382 |
2/4✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 36 times.
✗ Branch 5 not taken.
|
96 | std::istringstream iss(line.substr(line.find(":")+1, std::string::npos)); |
383 |
3/4✓ Branch 1 taken 177 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 141 times.
✓ Branch 4 taken 36 times.
|
285 | for (std::string item; std::getline(iss, item, ' '); ) |
384 |
2/2✓ Branch 0 taken 105 times.
✓ Branch 1 taken 36 times.
|
189 | if (!item.empty()) |
385 |
1/2✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
|
141 | paramNames.push_back(item); |
386 | 48 | } | |
387 | } | ||
388 | 48 | } | |
389 | 48 | return paramNames; | |
390 | ✗ | } | |
391 | |||
392 | /*! | ||
393 | * \brief Return the gridView this grid geometry object lives on | ||
394 | */ | ||
395 | 156777 | const GridView gridView_() const | |
396 |
32/48✓ 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 13 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 13 times.
✓ Branch 13 taken 20 times.
✓ Branch 14 taken 13 times.
✓ Branch 15 taken 20 times.
✓ Branch 16 taken 2482 times.
✓ Branch 17 taken 152808 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 2 times.
✗ Branch 26 not taken.
✓ Branch 27 taken 2 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 76 times.
✓ Branch 32 taken 2 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 2 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 2 times.
✓ Branch 37 taken 8 times.
✓ Branch 38 taken 2 times.
✓ Branch 39 taken 8 times.
✓ Branch 40 taken 140 times.
✓ Branch 41 taken 556 times.
✓ Branch 44 taken 2 times.
✗ Branch 45 not taken.
✓ Branch 46 taken 2 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 2 times.
✓ Branch 49 taken 2 times.
✓ Branch 50 taken 2 times.
✓ Branch 51 taken 2 times.
✓ Branch 52 taken 276 times.
✓ Branch 53 taken 276 times.
|
156773 | { 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 |