version 3.10-dev
snappygridmanager.hh
Go to the documentation of this file.
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//
12#ifndef DUMUX_MULTIDOMAIN_BOUNDARY_FREEFLOW_PORENETWORK_SNAPPY_GRID_MANAGER_HH
13#define DUMUX_MULTIDOMAIN_BOUNDARY_FREEFLOW_PORENETWORK_SNAPPY_GRID_MANAGER_HH
14
15#include <bitset>
16#include <optional>
17#include <dune/common/float_cmp.hh>
18#include <dune/geometry/axisalignedcubegeometry.hh>
21
22namespace Dumux::PoreNetwork {
23
24namespace Detail {
29template<class GridView>
31{
32 using Scalar = typename GridView::ctype;
33 static constexpr auto dim = GridView::dimension;
34 static constexpr auto dimWorld = GridView::dimensionworld;
35 using GlobalPosition = Dune::FieldVector<Scalar, dimWorld>;
36 using Line = Dune::AxisAlignedCubeGeometry< Scalar, 1, dimWorld>;
37 using Plane = Dune::AxisAlignedCubeGeometry< Scalar, dimWorld-1, dimWorld>;
38
39public:
40
44 static unsigned int directionIndex(const GlobalPosition& vector)
45 {
46 const auto eps = 1e-8*vector.two_norm();
47 return std::find_if(vector.begin(), vector.end(), [eps](const auto& x) { return std::abs(x) > eps; } ) - vector.begin();
48 }
49
50 static auto couplingPlaneBoundingBox(const GlobalPosition& gridLowerLeft,
51 const GlobalPosition& gridUpperRight,
52 const GlobalPosition& couplingPlaneNormal,
53 const std::string& modelParamGroup)
54 {
55 const auto couplingPlaneNormalDirectionIndex = directionIndex(couplingPlaneNormal);
56
57 // get the spatial extent of the coupling plane
58 const auto couplingPlaneLowerLeft = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.CouplingPlaneLowerLeft", gridLowerLeft);
59 const auto couplingPlaneUpperRight = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.CouplingPlaneUpperRight",
60 [&]()
61 {
62 GlobalPosition tmp(gridUpperRight);
63 tmp[couplingPlaneNormalDirectionIndex] = gridLowerLeft[couplingPlaneNormalDirectionIndex];
64 return tmp;
65 }());
66 return std::make_pair(couplingPlaneLowerLeft, couplingPlaneUpperRight);
67 }
68
69 static Plane makeCouplingPlane(const GlobalPosition& gridLowerLeft,
70 const GlobalPosition& gridUpperRight,
71 const GlobalPosition& couplingPlaneNormal,
72 const std::string& modelParamGroup)
73 {
74 auto [couplingPlaneLowerLeft, couplingPlaneUpperRight] = couplingPlaneBoundingBox(gridLowerLeft, gridUpperRight, couplingPlaneNormal, modelParamGroup);
75 const auto couplingPlaneNormalDirectionIndex = directionIndex(couplingPlaneNormal);
76 auto inPlaneAxes = std::move(std::bitset<dimWorld>{}.set());
77 inPlaneAxes.set(couplingPlaneNormalDirectionIndex, false);
78 return Plane(std::move(couplingPlaneLowerLeft), std::move(couplingPlaneUpperRight), inPlaneAxes);
79 }
80
91 static std::array<std::optional<Line>, dim> makeAxisParallelLinesFromCouplingPlane(const GlobalPosition& gridLowerLeft,
92 const GlobalPosition& gridUpperRight,
93 const GlobalPosition& couplingPlaneNormal,
94 const std::string& modelParamGroup)
95 {
96 const auto couplingPlaneNormalDirectionIndex = directionIndex(couplingPlaneNormal);
97
98 // get the spatial extent of the coupling plane
99 auto [a, b] = couplingPlaneBoundingBox(gridLowerLeft, gridUpperRight, couplingPlaneNormal, modelParamGroup);
100 // structured bindings cannot be captured by a lambda, therefore we introduce the helper variables a and b here
101 const auto& couplingPlaneLowerLeft = a;
102 const auto& couplingPlaneUpperRight = b;
103
104 // Create an array of lines. The entry for dim == couplingPlaneNormalDirectionIndex remains empty
105 std::array<std::optional<Line>, dim> lines;
106 for (int i = 0; i < dim; ++i)
107 {
108 if (i == couplingPlaneNormalDirectionIndex)
109 continue;
110
111 lines[i] = [&]()
112 {
113 GlobalPosition tmp(couplingPlaneLowerLeft);
114 tmp[i] = couplingPlaneUpperRight[i];
115 auto axis = std::bitset<dimWorld>();
116 axis.set(i, true);
117 return Line(couplingPlaneLowerLeft, tmp, axis);
118 }();
119 }
120
121 return lines;
122 }
123
134 template<class LowDimGridView, class LowDimGridData>
135 static auto getPointsOnLine(const Dune::FieldVector<Scalar, 3>& bulkGridLowerLeft,
136 const Dune::FieldVector<Scalar, 3>& bulkGridUpperRight,
137 const Dune::FieldVector<Scalar, 3>& couplingPlaneNormal,
138 const LowDimGridView& lowDimGridView,
139 const LowDimGridData& lowDimGridData,
140 const std::string& modelParamGroup)
141 {
142 const auto couplingPlane = makeCouplingPlane(bulkGridLowerLeft, bulkGridUpperRight, couplingPlaneNormal, modelParamGroup);
143 const auto couplingPlaneNormalDirectionIndex = directionIndex(couplingPlaneNormal);
144 using ScalarVector = std::vector<Scalar>;
145
146 std::array<ScalarVector, 3> coordinates;
147 for (auto& c : coordinates)
148 c.reserve(lowDimGridView.size(1));
149
150 ScalarVector poreRadius;
151 poreRadius.reserve(lowDimGridView.size(1));
152
153 auto makeUnique = [](ScalarVector& v)
154 {
155 std::sort(v.begin(), v.end());
156 v.erase(std::unique(v.begin(), v.end()), v.end());
157 };
158
159 for (const auto& vertex : vertices(lowDimGridView))
160 {
161 const auto& pos = vertex.geometry().center();
162 if (intersectsPointGeometry(pos, couplingPlane))
163 {
164 poreRadius.push_back(lowDimGridData.parameters(vertex)[lowDimGridData.parameterIndex("PoreInscribedRadius")]);
165 for (int i = 0; i < 3; ++i)
166 coordinates[i].push_back(pos[i]);
167 }
168 }
169
170 if (std::any_of(poreRadius.begin(), poreRadius.end(), [&](auto& r) { return Dune::FloatCmp::eq(r, poreRadius[0]); }))
171 DUNE_THROW(Dune::GridError, "SnappyGridCreator in 3D currently only supports equal pore radii at the interface");
172
173 for (auto& c : coordinates)
174 makeUnique(c);
175
176 struct Data { Scalar pos; Scalar radius; };
177 std::array<std::optional<std::vector<Data>>, 3> result;
178
179 for (int i = 0; i < 3; ++i)
180 {
181 if (i != couplingPlaneNormalDirectionIndex)
182 {
183 std::vector<Data> tmp(coordinates[i].size());
184 for (int poreIdx = 0; poreIdx < tmp.size(); ++poreIdx)
185 tmp[poreIdx] = Data{coordinates[i][poreIdx], poreRadius[0]};
186
187 result[i] = std::move(tmp);
188 }
189 }
190
191 return result;
192 }
193
204 template<class LowDimGridView, class LowDimGridData>
205 static auto getPointsOnLine(const Dune::FieldVector<Scalar, 2>& bulkGridLowerLeft,
206 const Dune::FieldVector<Scalar, 2>& bulkGridUpperRight,
207 const Dune::FieldVector<Scalar, 2>& couplingPlaneNormal,
208 const LowDimGridView& lowDimGridView,
209 const LowDimGridData& lowDimGridData,
210 const std::string& modelParamGroup)
211 {
212 std::vector<bool> vertexVisited(lowDimGridView.size(LowDimGridView::dimension), false);
213
214 const auto axisParallelLines = makeAxisParallelLinesFromCouplingPlane(bulkGridLowerLeft, bulkGridUpperRight, couplingPlaneNormal, modelParamGroup);
215
216 //The line to check for intersections
217 const auto line = [&]()
218 {
219 for (const auto& l : axisParallelLines)
220 if (l.has_value())
221 return *l;
222 DUNE_THROW(Dune::InvalidStateException, "No line found");
223 }();
224
225 const auto orientation = line.corner(1) - line.corner(0);
226 const auto dirIdx = directionIndex(orientation);
227
228 struct Data { Scalar pos; Scalar radius;};
229 std::vector<Data> data;
230
231 for (const auto& element : elements(lowDimGridView))
232 {
233 for (std::size_t localVertexIdx = 0; localVertexIdx < 2; ++localVertexIdx)
234 {
235 if (const auto& pos = element.geometry().corner(localVertexIdx); intersectsPointGeometry(pos, line))
236 {
237 const auto& vertex = element.template subEntity<LowDimGridView::dimension>(localVertexIdx);
238 const auto vIdx = lowDimGridView.indexSet().index(vertex);
239 const auto poreRadius = lowDimGridData.parameters(vertex)[lowDimGridData.parameterIndex("PoreInscribedRadius")];
240 assert(poreRadius > 0.0);
241
242 if (vertexVisited[vIdx])
243 continue;
244 else
245 vertexVisited[vIdx] = true;
246
247 data.push_back({pos[dirIdx], poreRadius});
248 }
249 }
250 }
251
252 std::sort(data.begin(), data.end(),
253 [](const auto& pore0, const auto& pore1)
254 {
255 return pore0.pos < pore1.pos;
256 });
257
258 // check if any intersections were found
259 if (data.empty())
260 {
261 std::cout << "line boundaries: " << std::endl;
262 for (int k = 0; k < line.corners(); ++k)
263 std::cout << "(" << line.corner(k) << ") ";
264
265 std::cout << std::endl;
266 DUNE_THROW(Dune::GridError, "No coupled pores found");
267 }
268
269 std::array<std::optional<std::vector<Data>>, 2> result;
270 result[dirIdx] = data;
271 return result;
272 }
273};
274
275} // end namespace Detail
276
281template<int dim, class OtherGridCreator, class DiscMethod = DiscretizationMethods::None>
282class SnappyGridManager : public Dumux::GridManager<Dune::YaspGrid<dim, Dune::TensorProductCoordinates<typename OtherGridCreator::Grid::ctype, OtherGridCreator::Grid::LeafGridView::dimensionworld>>>
283{
284 using Scalar = typename OtherGridCreator::Grid::ctype;
285 using OtherGrid = typename OtherGridCreator::Grid;
286 using IntVector = std::vector<int>;
287 using ScalarVector = std::vector<Scalar>;
288
289 static constexpr auto dimWorld = OtherGrid::LeafGridView::dimensionworld;
290 using GlobalPosition = Dune::FieldVector<Scalar, dimWorld>;
291
293 using LowDimGridData = typename OtherGridCreator::GridData;
294
295 struct GridConstructionData
296 {
297 std::array<ScalarVector, dim> positions;
298 std::array<IntVector, dim> cells;
299 std::array<ScalarVector, dim> grading;
300 std::array<std::optional<ScalarVector>, dim> interfacePositions;
301 };
302
303public:
305 using ParentType::ParentType;
306
308 void init(const OtherGrid& otherGrid, const LowDimGridData& otherData, const std::string& modelParamGroup = "")
309 {
310 modelParamGroup_ = modelParamGroup;
311 std::array<ScalarVector, dim> positions;
312 std::array<IntVector, dim> cells;
313 std::array<ScalarVector, dim> grading;
314 std::array<std::optional<ScalarVector>, dim> interFacePositions;
316
317 const auto lowerLeft = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.LowerLeft");
318 const auto upperRight = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.UpperRight");
319
320 static const auto couplingPlaneNormal = getParamFromGroup<GlobalPosition>(modelParamGroup,
321 "Grid.CouplinglineNormal",
322 [](){ GlobalPosition tmp(0.0); tmp[tmp.size()-1] = 1.0; return tmp; }());
323
324 const auto couplingPlaneNormalDirectionIndex = SnappyGridManagerHelper::directionIndex(couplingPlaneNormal);
325 const auto couplingPlane = SnappyGridManagerHelper::makeCouplingPlane(lowerLeft, upperRight, couplingPlaneNormal, modelParamGroup);
326
327 std::cout << "plane: \n";
328 for (int i = 0; i < couplingPlane.corners(); ++i)
329 std::cout << couplingPlane.corner(i) << std::endl;
330
331 const auto pointsOnAxisParallelLines = SnappyGridManagerHelper::getPointsOnLine(lowerLeft, upperRight, couplingPlaneNormal, otherGrid.leafGridView(), otherData, modelParamGroup_);
332
333 for (int i = 0; i < dim; ++i)
334 {
335 // set the lower left positions
336 positions[i].push_back(lowerLeft[i]);
337
338 if (i != couplingPlaneNormalDirectionIndex) // treat cells parallel to the coupling plane
339 {
340 if (!pointsOnAxisParallelLines[i].has_value())
341 DUNE_THROW(Dune::GridError, "Something went wrong with the coupling plane normal");
342
343 const auto& pointsOnLine = (*pointsOnAxisParallelLines[i]);
344
345 std::cout << "point " << i << std::endl;
346 for (auto x : pointsOnLine)
347 std::cout << x.pos << std::endl;
348
349 // check for user-defined additional points in the upstream area
350 const ScalarVector upstreamPositions = getParamFromGroup<ScalarVector>(modelParamGroup, "Grid.UpstreamPositions" + std::to_string(i), ScalarVector{});
351
352 addUpstreamPositions_(i, upstreamPositions, positions, pointsOnLine);
353 addUpstreamCells_(i, upstreamPositions, cells);
354
355 addCouplingPositions_(i, positions, pointsOnLine, interFacePositions, lowerLeft, upperRight);
356 addCouplingCells_(i, cells, pointsOnLine);
357
358 // check for user-defined additional points in the downstream area
359 const ScalarVector downstreamPositions = getParamFromGroup<ScalarVector>(modelParamGroup, "Grid.DownstreamPositions" + std::to_string(i), ScalarVector{});
360
361 addDownstreamPositions_(i, downstreamPositions, positions, upperRight);
362 addDownstreamCells_(i, downstreamPositions, cells);
363
364 // set the upper right positions
365 positions[i].push_back(upperRight[i]);
366
367 // handle grading of the cells
368 // use 1 by default
369 grading[i].resize(positions[i].size()-1, 1.0);
370
371 addUpstreamGrading_(i, upstreamPositions, grading);
372 addDownstreamGrading_(i, downstreamPositions, positions, grading);
373 }
374 else // i == couplingPlaneNormalDirectionIndex
375 {
376 // treat the cells normal to the coupling plane
377 if (i != couplingPlaneNormalDirectionIndex)
378 DUNE_THROW(Dune::GridError, "Something went wrong with the coupling plane normal");
379
380 const ScalarVector normalPositions = getParamFromGroup<ScalarVector>(modelParamGroup, "Grid.Positions" + std::to_string(i), ScalarVector{});
381
382 // add positions, cells and grading
383 addNormalPositions_(i, normalPositions, positions, upperRight);
384 positions[i].push_back(upperRight[i]);
385 addNormalCells_(i, normalPositions, cells);
386 grading[i].resize(positions[i].size()-1, 1.0);
387 addNormalGrading_(i, normalPositions, grading);
388 }
389
390 if (positions[i].size() != cells[i].size() + 1)
391 DUNE_THROW(Dune::GridError, "Wrong number of cells in " << i);
392 }
393
394 // forward to the actual grid creator
395 ParentType::init(positions, cells, grading, modelParamGroup);
396
397 gridConstructionData_ = GridConstructionData{std::move(positions), std::move(cells), std::move(grading), std::move(interFacePositions)};
398 }
399
401 const GridConstructionData& getGridConstructionData() const
402 { return gridConstructionData_; }
403
404private:
405
409
410 template<class PointsOnLine>
411 void addUpstreamPositions_(const int directionIndex,
412 const ScalarVector& upstreamPositions,
413 std::array<ScalarVector, dim>& positions,
414 const PointsOnLine& points)
415 {
416 if (!upstreamPositions.empty())
417 {
418 const Scalar gridLowerLeft = positions[directionIndex][0];
419 for (const Scalar pos : upstreamPositions)
420 {
421 if ((pos < points[0].pos - points[0].radius) && (pos > gridLowerLeft))
422 positions[directionIndex].push_back(pos);
423 else
424 DUNE_THROW(Dune::RangeError, "Make sure to set positions only in the inlet");
425 }
426 }
427 }
428
429 void addUpstreamCells_(const int directionIndex,
430 const ScalarVector& upstreamPositions,
431 std::array<IntVector, dim>& cells)
432 {
433 const IntVector cellsUpstream = getParamFromGroup<IntVector>(modelParamGroup_,
434 "Grid.UpstreamCells" + std::to_string(directionIndex),
435 IntVector{});
436
437 if (cellsUpstream.empty())
438 return;
439
440 if (cellsUpstream.size() != upstreamPositions.size() + 1)
441 DUNE_THROW(Dumux::ParameterException, "UpstreamCells" << std::to_string(directionIndex) << " must equal UpstreamPositions" << std::to_string(directionIndex) << " + 1");
442
443 for (int c : cellsUpstream)
444 {
445 if (c < 1)
446 DUNE_THROW(Dumux::ParameterException, "UpstreamCells" << std::to_string(directionIndex) << " must have values greater than zero.");
447 cells[directionIndex].push_back(c);
448 }
449 }
450
451 void addUpstreamGrading_(const int directionIndex,
452 const ScalarVector& upstreamPositions,
453 std::array<ScalarVector, dim>& grading)
454 {
455 if (upstreamPositions.empty())
456 return;
457
458 const ScalarVector upstreamGrading = getParamFromGroup<ScalarVector>(modelParamGroup_, "Grid.UpstreamGrading" + std::to_string(directionIndex), ScalarVector{});
459
460 if (!upstreamGrading.empty())
461 {
462 if (upstreamGrading.size() != upstreamPositions.size() + 1)
463 DUNE_THROW(Dune::RangeError, "UpstreamGrading" << std::to_string(directionIndex) << " must equal UpstreamPositions" << std::to_string(directionIndex) << " + 1");
464
465 for (int i = 0; i < upstreamPositions.size() + 1; ++i)
466 grading[directionIndex][i] = upstreamGrading[i];
467 }
468 }
469
473
474 void addDownstreamPositions_(const int directionIndex,
475 const ScalarVector& downstreamPositions,
476 std::array<ScalarVector, dim>& gridPositions,
477 const GlobalPosition& gridUpperRight)
478 {
479 if (!downstreamPositions.empty())
480 {
481 for (const Scalar pos : downstreamPositions)
482 {
483 if ((pos > gridPositions[directionIndex].back()) && (pos < gridUpperRight[directionIndex]))
484 gridPositions[directionIndex].push_back(pos);
485 else
486 DUNE_THROW(Dune::RangeError, "Make sure to set ascending positions only in the outlet");
487 }
488 }
489 }
490
491 void addDownstreamCells_(const int directionIndex,
492 const ScalarVector& downstreamPositions,
493 std::array<IntVector, dim>& cells)
494 {
495 const IntVector downstreamcells = getParamFromGroup<IntVector>(modelParamGroup_,
496 "Grid.DownstreamCells" + std::to_string(directionIndex),
497 IntVector{});
498
499 if (downstreamcells.empty())
500 return;
501
502 if (downstreamcells.size() != downstreamPositions.size() + 1)
503 DUNE_THROW(Dumux::ParameterException, "DownstreamCells" << std::to_string(directionIndex) << " must equal DownstreamPositions" << std::to_string(directionIndex) << " + 1");
504
505 for (int c : downstreamcells)
506 {
507 if (c < 1)
508 DUNE_THROW(Dumux::ParameterException, "DownstreamCells" << std::to_string(directionIndex) << " must have values greater than zero.");
509 cells[directionIndex].push_back(c);
510 }
511 }
512
513 void addDownstreamGrading_(const int directionIndex,
514 const ScalarVector& downstreamPositions,
515 std::array<ScalarVector, dim>& gridPositions,
516 std::array<ScalarVector, dim>& grading)
517 {
518 if (downstreamPositions.empty())
519 return;
520
521 const ScalarVector downstreamGrading = getParamFromGroup<ScalarVector>(modelParamGroup_, "Grid.DownstreamGrading" + std::to_string(directionIndex), ScalarVector{});
522
523 if (!downstreamGrading.empty())
524 {
525 if (downstreamGrading.size() != downstreamPositions.size() + 1)
526 DUNE_THROW(Dune::RangeError, "DownstreamGrading" << std::to_string(directionIndex) << " must equal DownstreamPositions" << std::to_string(directionIndex) << " + 1");
527
528 const int offSet = gridPositions[directionIndex].size() - downstreamPositions.size() - 2;
529 for (int i = 0; i < downstreamPositions.size() + 1; ++i)
530 grading[directionIndex][offSet + i] = downstreamGrading[i];
531 }
532 }
533
537
538 template<class PointsOnLine>
539 void addCouplingPositions_(const int directionIndex,
540 std::array<ScalarVector, dim>& positions,
541 const PointsOnLine& points,
542 std::array<std::optional<ScalarVector>, dim>& interFacePositions,
543 const GlobalPosition& gridLowerLeft,
544 const GlobalPosition& gridUpperRight)
545 {
546 // create an empty vector for the given directionIndex
547 interFacePositions[directionIndex] = ScalarVector{};
548
549 // set the points for the pore body positions
550 for (const auto& point : points)
551 {
552 const auto left = point.pos - point.radius;
553 const auto right = point.pos + point.radius;
554
555 if (left < positions[directionIndex].back())
556 DUNE_THROW(Dune::RangeError, "Pore body radii are too large, they intersect!");
557
558 if (left > gridLowerLeft[directionIndex])
559 positions[directionIndex].push_back(left);
560
561 if (right < gridUpperRight[directionIndex])
562 positions[directionIndex].push_back(right);
563
564 interFacePositions[directionIndex]->push_back(left);
565 interFacePositions[directionIndex]->push_back(right);
566 assert(interFacePositions[directionIndex].has_value());
567 }
568 }
569
570 template<class PointsOnLine>
571 void addCouplingCells_(const int directionIndex,
572 std::array<IntVector, dim>& cells,
573 const PointsOnLine& points)
574 {
575 // set the number of cells above the porous medium
576 const int cellsPerPore = getParamFromGroup<int>(modelParamGroup_, "Grid.CellsPerPore");
577 const int fixedCellsBetweenPores = getParamFromGroup<int>(modelParamGroup_, "Grid.FixedCellsBetweenPores", -1);
578
579 // set the number of cells between the pore bodies
580 for (int i = 0; i < points.size(); ++i)
581 {
582 cells[directionIndex].push_back(cellsPerPore);
583 if (i < points.size() -1)
584 {
585 if (fixedCellsBetweenPores > 0)
586 cells[directionIndex].push_back(fixedCellsBetweenPores);
587 else
588 {
589 // set number of cells such that the spacing of the cells between the left and right pore body
590 // is the average of the spacings for the cells coupled to those two pore bodies
591 const auto spacingLeft = points[i].radius*2.0 / cellsPerPore;
592 const auto spacingRight = points[i+1].radius*2.0 / cellsPerPore;
593 const auto avgSpacing = (spacingLeft + spacingRight) / 2;
594 const auto lengthBetween = (points[i+1].pos - (points[i+1].radius))
595 - (points[i].pos + (points[i].radius));
596 const int cellsBetween = std::ceil(lengthBetween / avgSpacing);
597 cells[directionIndex].push_back(cellsBetween);
598 }
599 }
600 }
601 }
602
606
607 void addNormalPositions_(const int directionIndex,
608 const ScalarVector& normalPositions,
609 std::array<ScalarVector, dim>& gridPositions,
610 const GlobalPosition& gridUpperRight)
611 {
612 if (!normalPositions.empty())
613 {
614 for (const Scalar pos : normalPositions)
615 {
616 if ((pos > gridPositions[directionIndex].back()) && (pos < gridUpperRight[directionIndex]))
617 gridPositions[directionIndex].push_back(pos);
618 else
619 DUNE_THROW(Dune::RangeError, "Make sure to set ascending normal positions");
620 }
621 }
622 }
623
624 void addNormalCells_(const int directionIndex,
625 const ScalarVector& normalPositions,
626 std::array<IntVector, dim>& cells)
627 {
628 const IntVector cellsNormal = getParamFromGroup<IntVector>(modelParamGroup_, "Grid.Cells" + std::to_string(directionIndex));
629
630 if (cellsNormal.size() != normalPositions.size() + 1)
631 DUNE_THROW(Dumux::ParameterException, "Cells" << std::to_string(directionIndex) << " must be of size " << normalPositions.size() + 1);
632
633 for (int c : cellsNormal)
634 cells[directionIndex].push_back(c);
635 }
636
637 void addNormalGrading_(const int directionIndex,
638 const ScalarVector& normalPositions,
639 std::array<ScalarVector, dim>& grading)
640 {
641 const ScalarVector normalGrading = getParamFromGroup<ScalarVector>(modelParamGroup_, "Grid.Grading" + std::to_string(directionIndex), ScalarVector{});
642
643 if (!normalGrading.empty())
644 {
645 if (normalGrading.size() != normalPositions.size() + 1)
646 DUNE_THROW(Dune::RangeError, "Grading" << std::to_string(directionIndex) << " must be of size " << normalPositions.size() + 1);
647
648 for (int i = 0; i < normalPositions.size() + 1; ++i)
649 grading[directionIndex][i] = normalGrading[i];
650 }
651 }
652
653
654 std::string modelParamGroup_ = "";
655 GridConstructionData gridConstructionData_;
656};
657
658} // end namespace Dumux::PoreNetwork
659
660#endif
void init(const std::string &modelParamGroup="")
Make the grid. Implement this method in the specialization of this class for a grid type.
Definition: gridmanager_base.hh:63
The grid manager (this is the class used by the user) for all supported grid managers that constructs...
Definition: gridmanager_base.hh:336
Exception thrown if a run-time parameter is not specified correctly.
Definition: exceptions.hh:48
A helper for the grid creator that matches a free-flow grid to a PNM grid.
Definition: snappygridmanager.hh:31
static std::array< std::optional< Line >, dim > makeAxisParallelLinesFromCouplingPlane(const GlobalPosition &gridLowerLeft, const GlobalPosition &gridUpperRight, const GlobalPosition &couplingPlaneNormal, const std::string &modelParamGroup)
Creates lines parallel to the bounding box axis of the coupling plane. Creates one line for dim == 2 ...
Definition: snappygridmanager.hh:91
static auto getPointsOnLine(const Dune::FieldVector< Scalar, 3 > &bulkGridLowerLeft, const Dune::FieldVector< Scalar, 3 > &bulkGridUpperRight, const Dune::FieldVector< Scalar, 3 > &couplingPlaneNormal, const LowDimGridView &lowDimGridView, const LowDimGridData &lowDimGridData, const std::string &modelParamGroup)
Returns the lowDim positions intersecting with a given line.
Definition: snappygridmanager.hh:135
static auto getPointsOnLine(const Dune::FieldVector< Scalar, 2 > &bulkGridLowerLeft, const Dune::FieldVector< Scalar, 2 > &bulkGridUpperRight, const Dune::FieldVector< Scalar, 2 > &couplingPlaneNormal, const LowDimGridView &lowDimGridView, const LowDimGridData &lowDimGridData, const std::string &modelParamGroup)
Returns the lowDim positions intersecting with a given line.
Definition: snappygridmanager.hh:205
static unsigned int directionIndex(const GlobalPosition &vector)
Returns the direction index of a unit vector (0 = x, 1 = y, 2 = z)
Definition: snappygridmanager.hh:44
static auto couplingPlaneBoundingBox(const GlobalPosition &gridLowerLeft, const GlobalPosition &gridUpperRight, const GlobalPosition &couplingPlaneNormal, const std::string &modelParamGroup)
Definition: snappygridmanager.hh:50
static Plane makeCouplingPlane(const GlobalPosition &gridLowerLeft, const GlobalPosition &gridUpperRight, const GlobalPosition &couplingPlaneNormal, const std::string &modelParamGroup)
Definition: snappygridmanager.hh:69
A grid creator that matches a free-flow grid to a PNM grid.
Definition: snappygridmanager.hh:283
const GridConstructionData & getGridConstructionData() const
Return data used to create the snappy grid (needed for Dune::TensorProductCoordinates) and the locati...
Definition: snappygridmanager.hh:401
void init(const OtherGrid &otherGrid, const LowDimGridData &otherData, const std::string &modelParamGroup="")
Make the grid.
Definition: snappygridmanager.hh:308
Definition: consistentlyorientedgrid.hh:20
bool intersectsPointGeometry(const Dune::FieldVector< ctype, dimworld > &point, const Geometry &g)
Find out whether a point is inside a three-dimensional geometry.
Definition: intersectspointgeometry.hh:28
static unsigned int directionIndex(Vector &&vector)
Returns the direction index of the facet (0 = x, 1 = y, 2 = z)
Definition: staggeredgeometryhelper.hh:121
Detect if a point intersects a geometry.
Convenience header that includes all grid manager specializations.
constexpr Line line
Definition: couplingmanager1d3d_line.hh:31
Definition: discretization/porenetwork/fvelementgeometry.hh:24