GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/io/grid/gridmanager_yasp.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 113 132 85.6%
Functions: 29 38 76.3%
Branches: 183 470 38.9%

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 Grid manager specialization for YaspGrid
11 */
12 #ifndef DUMUX_IO_GRID_MANAGER_YASP_HH
13 #define DUMUX_IO_GRID_MANAGER_YASP_HH
14
15 #include <dune/common/math.hh>
16
17 #include <dune/grid/yaspgrid.hh>
18 #include <dune/grid/io/file/dgfparser/dgfyasp.hh>
19
20 #ifndef DUMUX_IO_GRID_MANAGER_BASE_HH
21 #include <dumux/io/grid/gridmanager_base.hh>
22 #endif
23
24 #include <dumux/common/gridcapabilities.hh>
25
26 namespace Dumux {
27
28 /*!
29 * \ingroup InputOutput
30 * \brief Provides a grid manager for YaspGrids
31 * from information in the input file
32 *
33 * All keys are expected to be in group GridParameterGroup.
34 * The following keys are recognized:
35 * - File : a DGF file to load the coarse grid from
36 * - LowerLeft : lower left corner of the domain (only for EquidistantOffsetCoordinates, otherwise 0-origin)
37 * - UpperRight : upper right corner of the domain
38 * - Cells : the number of cells in each direction
39 * - Periodic : true or false for each direction
40 * - Overlap : overlap size in cells
41 * - Partitioning : a non-standard load-balancing, number of processors per direction
42 * - KeepPyhsicalOverlap : whether to keep the physical overlap
43 * in physical size or in number of cells upon refinement
44 * - Refinement : the number of global refines to apply initially.
45 *
46 */
47 template<class Coordinates, int dim>
48
3/5
✓ Branch 1 taken 29 times.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
577 class GridManager<Dune::YaspGrid<dim, Coordinates>>
49 : public GridManagerBase<Dune::YaspGrid<dim, Coordinates>>
50 {
51 using ct = typename Dune::YaspGrid<dim, Coordinates>::ctype;
52 using GlobalPosition = Dune::FieldVector<ct, dim>;
53 public:
54 using Grid = typename Dune::YaspGrid<dim, Coordinates>;
55 using ParentType = GridManagerBase<Grid>;
56
57 /*!
58 * \brief Make the grid. This is implemented by specializations of this method.
59 */
60 378 void init(const std::string& modelParamGroup = "")
61 {
62 // First try to create it from a DGF file in GridParameterGroup.File
63
6/14
✓ Branch 1 taken 316 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 316 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 316 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 316 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 316 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 316 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
1134 if (hasParamInGroup(modelParamGroup, "Grid.File"))
64 {
65 ParentType::makeGridFromDgfFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"));
66 postProcessing_(modelParamGroup);
67 return;
68 }
69
70 // Then look for the necessary keys to construct from the input file
71
6/14
✓ Branch 1 taken 316 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 316 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 316 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 316 times.
✓ Branch 11 taken 316 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 316 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
1134 else if (hasParamInGroup(modelParamGroup, "Grid.UpperRight"))
72 {
73 // get the upper right corner coordinates
74 378 const auto upperRight = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.UpperRight");
75
76 // number of cells in each direction
77 378 std::array<int, dim> cells; cells.fill(1);
78 378 cells = getParamFromGroup<std::array<int, dim>>(modelParamGroup, "Grid.Cells", cells);
79
80 // \todo TODO periodic boundaries with yasp (the periodicity concept of yasp grid is currently not supported, use dune-spgrid)
81 // const auto periodic = getParamFromGroup<std::bitset<dim>>(modelParamGroup, "Grid.Periodic", std::bitset<dim>{});
82 378 const std::bitset<dim> periodic;
83
84 // get the overlap
85 378 const int overlap = getParamFromGroup<int>(modelParamGroup, "Grid.Overlap", 1);
86
87 if constexpr (std::is_same_v<Dune::EquidistantCoordinates<ct, dim>, Coordinates>)
88 255 init(upperRight, cells, modelParamGroup, overlap, periodic);
89 else
90 {
91 246 const auto lowerLeft = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.LowerLeft", GlobalPosition(0.0));
92 123 init(lowerLeft, upperRight, cells, modelParamGroup, overlap, periodic);
93 }
94 }
95
96 // Didn't find a way to construct the grid
97 else
98 {
99 const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup + ".";
100 DUNE_THROW(ParameterException, "Please supply one of the parameters "
101 << prefix + "Grid.UpperRight"
102 << ", or a grid file in " << prefix + "Grid.File");
103
104 }
105 }
106
107 /*!
108 * \brief Make the grid using input data not read from the input file.
109 * \note Use this function for EquidistantCoordinates where lowerLeft is always zero.
110 */
111 226 void init(const GlobalPosition& upperRight,
112 const std::array<int, dim>& cells,
113 const std::string& modelParamGroup = "",
114 const int overlap = 1,
115 const std::bitset<dim> periodic = std::bitset<dim>{})
116 {
117 static_assert(std::is_same_v<Dune::EquidistantCoordinates<ct, dim>, Coordinates>,
118 "Use init function taking lowerLeft as argument when working with EquidistantOffsetCoordinates");
119
120
6/14
✓ Branch 1 taken 222 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 222 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 222 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 222 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 222 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 222 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
1130 if (!hasParamInGroup(modelParamGroup, "Grid.Partitioning"))
121 {
122 // construct using default load balancing
123
3/8
✓ Branch 2 taken 222 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 222 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 222 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
226 ParentType::gridPtr() = std::make_unique<Grid>(upperRight, cells, periodic, overlap);
124 }
125 else
126 {
127 // construct using user defined partitioning
128 const auto partitioning = getParamFromGroup<std::array<int, dim>>(modelParamGroup, "Grid.Partitioning");
129 Dune::Yasp::FixedSizePartitioning<dim> lb(partitioning);
130 ParentType::gridPtr() = std::make_unique<Grid>(upperRight, cells, periodic, overlap, typename Grid::Communication(), &lb);
131 }
132
133 226 postProcessing_(modelParamGroup);
134 226 }
135
136 /*!
137 * \brief Make the grid using input data not read from the input file.
138 * \note Use this function for EquidistantOffsetCoordinates.
139 */
140 96 void init(const GlobalPosition& lowerLeft,
141 const GlobalPosition& upperRight,
142 const std::array<int, dim>& cells,
143 const std::string& modelParamGroup = "",
144 const int overlap = 1,
145 const std::bitset<dim> periodic = std::bitset<dim>{})
146 {
147 static_assert(std::is_same_v<Dune::EquidistantOffsetCoordinates<ct, dim>, Coordinates>,
148 "LowerLeft can only be specified with EquidistantOffsetCoordinates");
149
150
6/14
✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 96 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 96 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 96 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 96 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 96 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
480 if (!hasParamInGroup(modelParamGroup, "Grid.Partitioning"))
151 {
152 // construct using default load balancing
153
3/8
✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 96 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 96 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
96 ParentType::gridPtr() = std::make_unique<Grid>(lowerLeft, upperRight, cells, periodic, overlap);
154 }
155 else
156 {
157 // construct using user defined partitioning
158 const auto partitioning = getParamFromGroup<std::array<int, dim>>(modelParamGroup, "Grid.Partitioning");
159 Dune::Yasp::FixedSizePartitioning<dim> lb(partitioning);
160 ParentType::gridPtr() = std::make_unique<Grid>(lowerLeft, upperRight, cells, periodic, overlap, typename Grid::Communication(), &lb);
161 }
162
163 96 postProcessing_(modelParamGroup);
164 96 }
165
166 private:
167
168 /*!
169 * \brief Postprocessing for YaspGrid
170 */
171 380 void postProcessing_(const std::string& modelParamGroup)
172 {
173 // Check if should refine the grid
174 380 const bool keepPhysicalOverlap = getParamFromGroup<bool>(modelParamGroup, "Grid.KeepPhysicalOverlap", true);
175 380 ParentType::grid().refineOptions(keepPhysicalOverlap);
176 380 ParentType::maybeRefineGrid(modelParamGroup);
177 380 ParentType::loadBalance();
178 380 }
179 };
180
181 /*!
182 * \ingroup InputOutput
183 * \brief Provides a grid manager for YaspGrids with different zones and grading
184 *
185 * All keys are expected to be in group GridParameterGroup.
186 * The following keys are recognized:
187 * - Positions0 : position array for x-coordinate
188 * - Positions1 : position array for y-coordinate
189 * - Positions2 : position array for z-coordinate
190 * - Cells0 : number of cells array for x-coordinate
191 * - Cells1 : number of cells array for y-coordinate
192 * - Cells2 : number of cells array for z-coordinate
193 * - Grading0 : grading factor array for x-coordinate
194 * - Grading1 : grading factor array for y-coordinate
195 * - Grading2 : grading factor array for z-coordinate
196 * - Verbosity : whether the grid construction should output to standard out
197 * - Periodic : true or false for each direction
198 * - Overlap : overlap size in cells
199 * - Partitioning : a non-standard load-balancing, number of processors per direction
200 * - KeepPyhsicalOverlap : whether to keep the physical overlap
201 * in physical size or in number of cells upon refinement
202 * - Refinement : the number of global refines to apply initially.
203 *
204 * The grading factor \f$ g \f$ specifies the ratio between the next and the current cell size:
205 * \f$ g = \frac{h_{i+1}}{h_i} \f$.
206 * Negative grading factors are converted to
207 * \f$ g = -\frac{1}{g_\textrm{negative}} \f$
208 * to avoid issues with imprecise fraction numbers.
209 */
210 template<class ctype, int dim>
211
4/7
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 13 taken 8 times.
✗ Branch 14 not taken.
167 class GridManager<Dune::YaspGrid<dim, Dune::TensorProductCoordinates<ctype, dim> >>
212 : public GridManagerBase<Dune::YaspGrid<dim, Dune::TensorProductCoordinates<ctype, dim> > >
213 {
214 public:
215 using Grid = typename Dune::YaspGrid<dim, Dune::TensorProductCoordinates<ctype, dim> >;
216 using ParentType = GridManagerBase<Grid>;
217
218 /*!
219 * \brief Make the grid. This is implemented by specializations of this method.
220 */
221 67 void init(const std::string& modelParamGroup = "")
222 {
223 // Only construction from the input file is possible
224 // Look for the necessary keys to construct from the input file
225 // The positions
226 67 std::array<std::vector<ctype>, dim> positions;
227
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 123 times.
190 for (int i = 0; i < dim; ++i)
228
6/18
✓ Branch 1 taken 123 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 123 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 123 times.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 123 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 123 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 123 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
369 positions[i] = getParamFromGroup<std::vector<ctype>>(modelParamGroup, "Grid.Positions" + std::to_string(i));
229
230 // the number of cells (has a default)
231 67 std::array<std::vector<int>, dim> cells;
232
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 123 times.
190 for (int i = 0; i < dim; ++i)
233 {
234
4/8
✓ Branch 1 taken 123 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 123 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 123 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 123 times.
✗ Branch 11 not taken.
492 cells[i].resize(positions[i].size()-1, 1.0);
235
7/18
✓ Branch 1 taken 123 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 123 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 123 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 123 times.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 123 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 123 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 123 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
492 cells[i] = getParamFromGroup<std::vector<int>>(modelParamGroup, "Grid.Cells" + std::to_string(i), cells[i]);
236 }
237
238 // grading factor (has a default)
239 67 std::array<std::vector<ctype>, dim> grading;
240
2/2
✓ Branch 0 taken 123 times.
✓ Branch 1 taken 67 times.
190 for (int i = 0; i < dim; ++i)
241 {
242
4/8
✓ Branch 1 taken 123 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 123 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 123 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 123 times.
✗ Branch 11 not taken.
492 grading[i].resize(positions[i].size()-1, 1.0);
243
7/18
✓ Branch 1 taken 123 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 123 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 123 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 123 times.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 123 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 123 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 123 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
492 grading[i] = getParamFromGroup<std::vector<ctype>>(modelParamGroup, "Grid.Grading" + std::to_string(i), grading[i]);
244 }
245
246 // call the generic function
247
1/2
✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
67 init(positions, cells, grading, modelParamGroup);
248 67 }
249
250 /*!
251 * \brief Make the grid using input data not read from the input file.
252 */
253 97 void init(const std::array<std::vector<ctype>, dim>& positions,
254 const std::array<std::vector<int>, dim>& cells,
255 const std::array<std::vector<ctype>, dim>& grading,
256 const std::string& modelParamGroup = "")
257 {
258 // Additional parameters (they have a default)
259 97 const int overlap = getParamFromGroup<int>(modelParamGroup, "Grid.Overlap", 1);
260 97 const bool verbose = getParamFromGroup<bool>(modelParamGroup, "Grid.Verbosity", false);
261 // \todo TODO periodic boundaries with yasp (the periodicity concept of yasp grid is currently not supported, use dune-spgrid)
262 // const auto periodic = getParamFromGroup<std::bitset<dim>>(modelParamGroup, "Grid.Periodic", std::bitset<dim>{});
263 97 const std::bitset<dim> periodic;
264
265 // Some sanity checks
266
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 87 times.
291 for (unsigned int dimIdx = 0; dimIdx < dim; ++dimIdx)
267 {
268
5/10
✗ Branch 0 not taken.
✓ Branch 1 taken 172 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 172 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 172 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 172 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 172 times.
970 if (cells[dimIdx].size() + 1 != positions[dimIdx].size())
269 {
270 DUNE_THROW(Dune::RangeError, "Make sure to specify correct \"Cells\" and \"Positions\" arrays");
271 }
272
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 172 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 172 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 172 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 172 times.
776 if (grading[dimIdx].size() + 1 != positions[dimIdx].size())
273 {
274 DUNE_THROW(Dune::RangeError, "Make sure to specify correct \"Grading\" and \"Positions\" arrays");
275 }
276 ctype temp = std::numeric_limits<ctype>::lowest();
277
4/4
✓ Branch 0 taken 359 times.
✓ Branch 1 taken 183 times.
✓ Branch 2 taken 359 times.
✓ Branch 3 taken 183 times.
1216 for (unsigned int posIdx = 0; posIdx < positions[dimIdx].size(); ++posIdx)
278 {
279
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 370 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 370 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 370 times.
1242 if (temp > positions[dimIdx][posIdx])
280 {
281 DUNE_THROW(Dune::RangeError, "Make sure to specify a monotone increasing \"Positions\" array");
282 }
283 828 temp = positions[dimIdx][posIdx];
284 }
285 }
286
287 97 const auto globalPositions = computeGlobalPositions_(positions, cells, grading, verbose);
288
289 // make the grid
290
6/14
✓ Branch 1 taken 87 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 87 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 87 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 87 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 87 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 87 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
485 if (!hasParamInGroup(modelParamGroup, "Grid.Partitioning"))
291 {
292 // construct using default load balancing
293
4/12
✓ Branch 1 taken 87 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 87 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 87 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 87 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
97 ParentType::gridPtr() = std::make_shared<Grid>(globalPositions, periodic, overlap);
294 }
295 else
296 {
297 // construct using user defined partitioning
298 const auto partitioning = getParamFromGroup<std::array<int, dim>>(modelParamGroup, "Grid.Partitioning");
299 Dune::Yasp::FixedSizePartitioning<dim> lb(partitioning);
300 ParentType::gridPtr() = std::make_shared<Grid>(globalPositions, periodic, overlap, typename Grid::Communication(), &lb);
301 }
302
303
1/2
✓ Branch 1 taken 87 times.
✗ Branch 2 not taken.
97 postProcessing_(modelParamGroup);
304 97 }
305
306 private:
307 /*!
308 * \brief Postprocessing for YaspGrid
309 */
310 97 void postProcessing_(const std::string& modelParamGroup)
311 {
312 // Check if should refine the grid
313 97 const bool keepPhysicalOverlap = getParamFromGroup<bool>(modelParamGroup, "Grid.KeepPhysicalOverlap", true);
314 97 ParentType::grid().refineOptions(keepPhysicalOverlap);
315 97 ParentType::maybeRefineGrid(modelParamGroup);
316 97 ParentType::loadBalance();
317 97 }
318
319 //! Compute the global position tensor grid from the given positions, cells, and grading factors
320 std::array<std::vector<ctype>, dim>
321 87 computeGlobalPositions_(const std::array<std::vector<ctype>, dim>& positions,
322 const std::array<std::vector<int>, dim>& cells,
323 const std::array<std::vector<ctype>, dim>& grading,
324 bool verbose = false)
325 {
326 87 std::array<std::vector<ctype>, dim> globalPositions;
327 using std::pow;
328 using Dune::power;
329
2/2
✓ Branch 0 taken 150 times.
✓ Branch 1 taken 77 times.
259 for (int dimIdx = 0; dimIdx < dim; dimIdx++)
330 {
331
6/6
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 150 times.
✓ Branch 2 taken 176 times.
✓ Branch 3 taken 150 times.
✓ Branch 4 taken 176 times.
✓ Branch 5 taken 150 times.
1110 for (int zoneIdx = 0; zoneIdx < cells[dimIdx].size(); ++zoneIdx)
332 {
333
4/4
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 101 times.
✓ Branch 2 taken 75 times.
✓ Branch 3 taken 101 times.
396 ctype lower = positions[dimIdx][zoneIdx];
334
4/4
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 101 times.
✓ Branch 2 taken 75 times.
✓ Branch 3 taken 101 times.
396 ctype upper = positions[dimIdx][zoneIdx+1];
335
4/4
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 101 times.
✓ Branch 2 taken 75 times.
✓ Branch 3 taken 101 times.
396 int numCells = cells[dimIdx][zoneIdx];
336
4/4
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 101 times.
✓ Branch 2 taken 75 times.
✓ Branch 3 taken 101 times.
396 ctype gradingFactor = grading[dimIdx][zoneIdx];
337 198 ctype length = upper - lower;
338 198 ctype height = 1.0;
339 198 bool increasingCellSize = false;
340
341
2/2
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 101 times.
198 if (verbose)
342 {
343 75 std::cout << "dim " << dimIdx
344
2/4
✓ Branch 1 taken 75 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 75 times.
✗ Branch 6 not taken.
150 << " lower " << lower
345
1/2
✓ Branch 2 taken 75 times.
✗ Branch 3 not taken.
150 << " upper " << upper
346 75 << " numCells " << numCells
347
2/4
✓ Branch 1 taken 75 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 75 times.
✗ Branch 6 not taken.
150 << " grading " << gradingFactor;
348 }
349
350
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 148 times.
198 if (gradingFactor > 1.0)
351 {
352 28 increasingCellSize = true;
353 }
354
355 // take absolute values and reverse cell size increment to achieve
356 // reverse behavior for negative values
357
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 154 times.
198 if (gradingFactor < 0.0)
358 {
359 using std::abs;
360
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 17 times.
22 gradingFactor = abs(gradingFactor);
361
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 17 times.
22 if (gradingFactor < 1.0)
362 {
363 5 increasingCellSize = true;
364 }
365 }
366
367 // if the grading factor is exactly 1.0 do equal spacing
368
4/4
✓ Branch 0 taken 166 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 121 times.
✓ Branch 3 taken 45 times.
198 if (gradingFactor > 1.0 - 1e-7 && gradingFactor < 1.0 + 1e-7)
369 {
370 143 height = 1.0 / numCells;
371
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 85 times.
143 if (verbose)
372 {
373
2/4
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 36 times.
✗ Branch 6 not taken.
72 std::cout << " -> h " << height * length << std::endl;
374 }
375 }
376 // if grading factor is not 1.0, do power law spacing
377 else
378 {
379 55 height = (1.0 - gradingFactor) / (1.0 - power(gradingFactor, numCells));
380
381
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 16 times.
55 if (verbose)
382 {
383
1/2
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
78 std::cout << " -> grading_eff " << gradingFactor
384
2/4
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 39 times.
✗ Branch 6 not taken.
117 << " h_min " << height * power(gradingFactor, 0) * length
385
1/2
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
117 << " h_max " << height * power(gradingFactor, numCells-1) * length
386
1/2
✓ Branch 1 taken 39 times.
✗ Branch 2 not taken.
39 << std::endl;
387 }
388 }
389
390
2/4
✓ Branch 1 taken 176 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 176 times.
✗ Branch 4 not taken.
594 std::vector<ctype> localPositions;
391
1/2
✓ Branch 1 taken 176 times.
✗ Branch 2 not taken.
198 localPositions.push_back(0);
392
2/2
✓ Branch 0 taken 9889 times.
✓ Branch 1 taken 176 times.
10153 for (int i = 0; i < numCells-1; i++)
393 {
394 9955 ctype hI = height;
395
4/4
✓ Branch 0 taken 9340 times.
✓ Branch 1 taken 549 times.
✓ Branch 2 taken 5220 times.
✓ Branch 3 taken 4120 times.
9955 if (!(gradingFactor < 1.0 + 1e-7 && gradingFactor > 1.0 - 1e-7))
396 {
397
2/2
✓ Branch 0 taken 4414 times.
✓ Branch 1 taken 1355 times.
5769 if (increasingCellSize)
398 {
399 8828 hI *= power(gradingFactor, i);
400 }
401 else
402 {
403 2710 hI *= power(gradingFactor, numCells-i-1);
404 }
405 }
406
2/6
✓ Branch 1 taken 9889 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9889 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
19910 localPositions.push_back(localPositions[i] + hI);
407 }
408
409
4/4
✓ Branch 0 taken 10065 times.
✓ Branch 1 taken 176 times.
✓ Branch 2 taken 10065 times.
✓ Branch 3 taken 176 times.
20702 for (int i = 0; i < localPositions.size(); i++)
410 {
411 10153 localPositions[i] *= length;
412 10153 localPositions[i] += lower;
413 }
414
415
4/4
✓ Branch 0 taken 10065 times.
✓ Branch 1 taken 176 times.
✓ Branch 2 taken 10065 times.
✓ Branch 3 taken 176 times.
10549 for (unsigned int i = 0; i < localPositions.size(); ++i)
416 {
417
3/6
✓ Branch 1 taken 10065 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10065 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 10065 times.
✗ Branch 8 not taken.
30459 globalPositions[dimIdx].push_back(localPositions[i]);
418 }
419 }
420
4/8
✓ Branch 1 taken 150 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 150 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 150 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 150 times.
✗ Branch 11 not taken.
688 globalPositions[dimIdx].push_back(positions[dimIdx].back());
421 }
422
423 87 return globalPositions;
424 }
425 };
426
427 namespace Grid::Capabilities {
428
429 // To the best of our knowledge YaspGrid is view thread-safe
430 // This specialization can be removed after we depend on Dune release 2.9 and this is guaranteed by YaspGrid itself
431 template<class Coordinates, int dim>
432 struct MultithreadingSupported<Dune::YaspGrid<dim, Coordinates>>
433 {
434 template<class GV>
435 static bool eval(const GV& gv) // default is independent of the grid view
436 { return true; }
437 };
438
439 } // end namespace Grid::Capabilities
440
441 } // end namespace Dumux
442
443 #endif
444