version 3.8
parametersforgeneratedgrid.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_IO_PARAMETERS_FOR_GENERATED_GRID
13#define DUMUX_IO_PARAMETERS_FOR_GENERATED_GRID
14
15#include <algorithm>
16#include <array>
17#include <numeric>
18#include <random>
19#include <string>
20#include <vector>
21
22#include <dune/common/exceptions.hh>
23#include <dune/grid/common/exceptions.hh>
24#include <dune/geometry/axisalignedcubegeometry.hh>
25
32
33namespace Dumux::PoreNetwork {
34
39template <class Grid, class Scalar>
41{
42 using GridView = typename Grid::LeafGridView;
43 using Element = typename Grid::template Codim<0>::Entity;
44 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
45 using Vertex = typename Grid::template Codim<Grid::dimension>::Entity;
46
47 static constexpr auto dim = Grid::dimension;
48 static constexpr auto dimWorld = Grid::dimensionworld;
49 using BoundaryList = std::array<int, 2*dimWorld>;
50
51public:
52
53 ParametersForGeneratedGrid(const GridView& gridView, const std::string& paramGroup)
54 : gridView_(gridView)
55 , paramGroup_(paramGroup)
56 , priorityList_(getPriorityList_())
57 {
58 computeBoundingBox_();
59 boundaryFaceIndex_ = getBoundaryFacemarkerInput_();
60 }
61
67 int boundaryFaceMarkerAtPos(const GlobalPosition& pos) const
68 {
69 // set the priority which decides the order the vertices on the boundary are indexed
70 // by default, vertices on min/max faces in x direction have the highest priority, followed by y and z
71 for (auto boundaryIdx : priorityList_)
72 {
73 if (onBoundary_(pos, boundaryIdx))
74 return boundaryFaceIndex_[boundaryIdx];
75 }
76 return -1;
77 }
78
84 int throatLabel(const std::array<int, 2>& poreLabels) const
85 {
86 if (poreLabels[0] == poreLabels[1]) // both vertices are inside the domain or on the same boundary face
87 return poreLabels[0];
88 if (poreLabels[0] == -1) // vertex1 is inside the domain, vertex2 is on a boundary face
89 return poreLabels[1];
90 if (poreLabels[1] == -1) // vertex2 is inside the domain, vertex1 is on a boundary face
91 return poreLabels[0];
92
93 // use the priority list to find out which pore label is favored
94 for(const auto i : priorityList_)
95 {
96 if (poreLabels[0] == boundaryFaceIndex_[i])
97 return poreLabels[0];
98 if (poreLabels[1] == boundaryFaceIndex_[i])
99 return poreLabels[1];
100 }
101
102 DUNE_THROW(Dune::InvalidStateException, "Something went wrong with the throat labels");
103 }
104
108 template <class SetParameter, class GetParameter>
109 void assignParameters(const SetParameter& setParameter,
110 const GetParameter& getParameter,
111 const std::size_t numSubregions)
112 {
113 using cytpe = typename GlobalPosition::value_type;
114 using InternalBoundingBox = Dune::AxisAlignedCubeGeometry<cytpe, dimWorld, dimWorld>;
115 std::vector<InternalBoundingBox> internalBoundingBoxes;
116
117 // divide the network into subregions, if specified
118 if (numSubregions > 0)
119 {
120 // get bounding boxes of subregions
121 for (int i = 0; i < numSubregions; ++i)
122 {
123 auto lowerLeft = getParamFromGroup<GlobalPosition>(paramGroup_, "Grid.Subregion" + std::to_string(i) + ".LowerLeft");
124 auto upperRight = getParamFromGroup<GlobalPosition>(paramGroup_, "Grid.Subregion" + std::to_string(i) + ".UpperRight");
125 internalBoundingBoxes.emplace_back(std::move(lowerLeft), std::move(upperRight));
126 }
127 }
128
129 // get the maximum possible pore body radii such that pore bodies do not intersect
130 // (requires ThroatRegionId, if specified)
131 const std::vector<Scalar> maxPoreRadius = getMaxPoreRadii_(numSubregions, getParameter);
132 std::vector<bool> poreRadiusLimited(gridView_.size(dim), false);
133
134 // get a helper function for getting the pore radius of a pore body not belonging to a subregion
135 auto defaultPoreRadius = poreRadiusGenerator_(-1);
136
137 // get helper functions for pore body radii on subregions
138 std::vector<decltype(defaultPoreRadius)> subregionPoreRadius;
139 for (int i = 0; i < numSubregions; ++i)
140 subregionPoreRadius.emplace_back(poreRadiusGenerator_(i));
141
142 // get helper function for pore volume
143 const auto poreVolume = poreVolumeGenerator_(getParameter);
144
145 // treat the pore body parameters (label, radius and maybe regionId)
146 for (const auto& vertex : vertices(gridView_))
147 {
148 const auto& pos = vertex.geometry().center();
149 const auto vIdxGlobal = gridView_.indexSet().index(vertex);
150 const auto poreLabel = boundaryFaceMarkerAtPos(pos);
151 setParameter(vertex, "PoreLabel", poreLabel);
152
153 // sets the minimum of the given value and the maximum possible pore body radius
154 // and keeps track of capped radii
155 auto setRadiusAndLogIfCapped = [&](const Scalar value)
156 {
157 if (value > maxPoreRadius[vIdxGlobal])
158 {
159 poreRadiusLimited[vIdxGlobal] = true;
160 setParameter(vertex, "PoreInscribedRadius", maxPoreRadius[vIdxGlobal]);
161 }
162 else
163 setParameter(vertex, "PoreInscribedRadius", value);
164 };
165
166 if (numSubregions == 0) // assign radius if no subregions are specified
167 setRadiusAndLogIfCapped(defaultPoreRadius(vertex, poreLabel));
168 else // assign region ids and radii to vertices if they are within a subregion
169 {
170 // default value for vertices not belonging to a subregion
171 setParameter(vertex, "PoreRegionId", -1);
172 setRadiusAndLogIfCapped(defaultPoreRadius(vertex, poreLabel));
173
174 for (int id = 0; id < numSubregions; ++id)
175 {
176 const auto& subregion = internalBoundingBoxes[id];
177 if (intersectsPointGeometry(vertex.geometry().center(), subregion))
178 {
179 setParameter(vertex, "PoreRegionId", id);
180 setRadiusAndLogIfCapped(subregionPoreRadius[id](vertex, poreLabel));
181 }
182 }
183 }
184
185 setParameter(vertex, "PoreVolume", poreVolume(vertex, poreLabel));
186 }
187
188 // treat throat parameters
189 auto defaultThroatInscribedRadius = throatInscribedRadiusGenerator_(-1, getParameter);
190 auto defaultThroatLength = throatLengthGenerator_(-1, getParameter);
191
192 // get helper functions for throat radii and lengths on subregions
193 std::vector<decltype(defaultThroatInscribedRadius)> subregionThroatInscribedRadius;
194 std::vector<decltype(defaultThroatLength)> subregionThroatLength;
195 for (int i = 0; i < numSubregions; ++i)
196 {
197 subregionThroatInscribedRadius.emplace_back(throatInscribedRadiusGenerator_(i, getParameter));
198 subregionThroatLength.emplace_back(throatLengthGenerator_(i, getParameter));
199 }
200
201 // set throat parameters
202 for (const auto& element : elements(gridView_))
203 {
204 if (numSubregions == 0) // assign values if no subregions are specified
205 {
206 setParameter(element, "ThroatInscribedRadius", defaultThroatInscribedRadius(element));
207 setParameter(element, "ThroatLength", defaultThroatLength(element));
208 }
209 else // assign values to throats if they are within a subregion
210 {
211 // default value for elements not belonging to a subregion
212 setParameter(element, "ThroatRegionId", -1);
213 setParameter(element, "ThroatInscribedRadius", defaultThroatInscribedRadius(element));
214 setParameter(element, "ThroatLength", defaultThroatLength(element));
215
216 for (int id = 0; id < numSubregions; ++id)
217 {
218 const auto& subregion = internalBoundingBoxes[id];
219 if (intersectsPointGeometry(element.geometry().center(), subregion))
220 {
221 setParameter(element, "ThroatRegionId", id);
222 setParameter(element, "ThroatInscribedRadius", subregionThroatInscribedRadius[id](element));
223 setParameter(element, "ThroatLength", subregionThroatLength[id](element));
224 }
225 }
226 }
227
228 // set the throat label
229 const auto vertex0 = element.template subEntity<dim>(0);
230 const auto vertex1 = element.template subEntity<dim>(1);
231 const std::array poreLabels{static_cast<int>(getParameter(vertex0, "PoreLabel")),
232 static_cast<int>(getParameter(vertex1, "PoreLabel"))};
233 setParameter(element, "ThroatLabel", throatLabel(poreLabels));
234 }
235
236 const auto numPoreRadiusLimited = std::count(poreRadiusLimited.begin(), poreRadiusLimited.end(), true);
237 if (numPoreRadiusLimited > 0)
238 std::cout << "*******\nWarning! " << numPoreRadiusLimited << " out of " << poreRadiusLimited.size()
239 << " pore body radii have been capped automatically in order to prevent intersecting pores\n*******" << std::endl;
240 }
241
242private:
243
250 BoundaryList getPriorityList_() const
251 {
252 const auto list = [&]()
253 {
254 BoundaryList priorityList;
255 std::iota(priorityList.begin(), priorityList.end(), 0);
256
257 if (hasParamInGroup(paramGroup_, "Grid.PriorityList"))
258 {
259 try {
260 // priorities can also be set in the input file
261 priorityList = getParamFromGroup<BoundaryList>(paramGroup_, "Grid.PriorityList");
262 }
263 // make sure that a priority for each direction is set
264 catch(Dune::RangeError& e) {
265 DUNE_THROW(Dumux::ParameterException, "You must specify priorities for all directions (" << dimWorld << ") \n" << e.what());
266 }
267 // make sure each direction is only set once
268 if (!isUnique_(priorityList))
269 DUNE_THROW(Dumux::ParameterException, "You must specify priorities for all directions (duplicate directions)");
270
271 //make sure that the directions are correct (ranging from 0 to dimWorld-1)
272 if (std::any_of(priorityList.begin(), priorityList.end(), []( const int i ){ return (i < 0 || i >= 2*dimWorld); }))
273 DUNE_THROW(Dumux::ParameterException, "You must specify priorities for correct directions (0-" << 2*dimWorld-1 << ")");
274 }
275 return priorityList;
276 }();
277 return list;
278 }
279
280 void computeBoundingBox_()
281 {
282 // calculate the bounding box of the local partition of the grid view
283 for (const auto& vertex : vertices(gridView_))
284 {
285 for (int i = 0; i < dimWorld; i++)
286 {
287 using std::min;
288 using std::max;
289 bBoxMin_[i] = min(bBoxMin_[i], vertex.geometry().corner(0)[i]);
290 bBoxMax_[i] = max(bBoxMax_[i], vertex.geometry().corner(0)[i]);
291 }
292 }
293 }
294
298 BoundaryList getBoundaryFacemarkerInput_() const
299 {
300 BoundaryList boundaryFaceMarker;
301 std::fill(boundaryFaceMarker.begin(), boundaryFaceMarker.end(), 0);
302 boundaryFaceMarker[0] = 1;
303 boundaryFaceMarker[1] = 1;
304
305 if (hasParamInGroup(paramGroup_, "Grid.BoundaryPoreLabels"))
306 {
307 const auto input = getParamFromGroup<std::vector<std::string>>(paramGroup_, "Grid.BoundaryPoreLabels");
308 for (const auto& entry : input)
309 {
310 const std::string errorMessage = "You must specify BoundaryPoreLabels in the format pos:num, where pos can be xMin, xMax, yMin, yMax, zMin, zMax and num is the corresponding label.\n"
311 "Example (2D, defaults are used for the remaining boundaries): xMin:2 yMax:3\n";
312 if (entry.find(':') == std::string::npos)
313 DUNE_THROW(Dumux::ParameterException, errorMessage);
314
315 static const std::map<std::string, int> labels = {{"xMin", 0}, {"xMax", 1}, {"yMin", 2}, {"yMax", 3}, {"zMin", 4}, {"zMax", 5}};
316 const auto splitEntry = split(entry, ":");
317 const std::string location = std::string(splitEntry[0].begin(), splitEntry[0].end());
318 int value = 0;
319 try {
320 value = std::stoi(std::string(splitEntry[1].begin(), splitEntry[1].end()));
321 }
322 catch(...) {
323 DUNE_THROW(Dumux::ParameterException, errorMessage);
324 }
325
326 if (splitEntry.size() != 2)
327 DUNE_THROW(Dumux::ParameterException, errorMessage);
328 if (!labels.count(location))
329 DUNE_THROW(Dumux::ParameterException, errorMessage);
330 else
331 boundaryFaceMarker[labels.at(location)] = value;
332 }
333 }
334 return boundaryFaceMarker;
335 }
336
337 // returns the maximum possible pore body radii such that pore bodies do not intersect
338 template <class GetParameter>
339 std::vector<Scalar> getMaxPoreRadii_(std::size_t numSubregions, const GetParameter& getParameter) const
340 {
341 const auto numVertices = gridView_.size(dim);
342 std::vector<Scalar> maxPoreRadius(numVertices, std::numeric_limits<Scalar>::max());
343
344 if (!getParamFromGroup<bool>(paramGroup_, "Grid.CapPoreRadii", true))
345 return maxPoreRadius;
346
347 // check for a user-specified fixed throat length
348 const Scalar inputThroatLength = getParamFromGroup<Scalar>(paramGroup_, "Grid.ThroatLength", -1.0);
349 std::vector<Scalar> subregionInputThroatLengths;
350
351 if (numSubregions > 0)
352 {
353 for (int i = 0; i < numSubregions; ++i)
354 {
355 // adapt the parameter group if there are subregions
356 const std::string paramGroup = paramGroup_ + ".SubRegion" + std::to_string(i);
357 const Scalar subregionInputThroatLength = getParamFromGroup<Scalar>(paramGroup, "Grid.ThroatLength", -1.0);
358 subregionInputThroatLengths.push_back(subregionInputThroatLength);
359 }
360 }
361
362 for (const auto& element : elements(gridView_))
363 {
364 // do not cap the pore radius if a user-specified throat length if given
365 if (numSubregions > 0)
366 {
367 // check subregions
368 const auto subregionId = getParameter(element, "ThroatRegionId");
369 if (subregionId >= 0)
370 {
371 // throat lies within a subregion
372 if (subregionInputThroatLengths[subregionId] > 0.0)
373 continue;
374 }
375 else if (inputThroatLength > 0.0) // throat does not lie within a subregion
376 continue;
377 }
378 else if (inputThroatLength > 0.0) // no subregions
379 continue;
380
381 // No fixed throat lengths given, check for max. pore radius.
382 // We define this as 1/2 of the length (minus a user specified value) of the shortest pore throat attached to the pore body.
383 const Scalar delta = element.geometry().volume();
384 static const Scalar minThroatLength = getParamFromGroup<Scalar>(paramGroup_, "Grid.MinThroatLength", 1e-6);
385 const Scalar maxRadius = (delta - minThroatLength)/2.0;
386 for (int vIdxLocal = 0; vIdxLocal < 2 ; ++vIdxLocal)
387 {
388 const int vIdxGlobal = gridView_.indexSet().subIndex(element, vIdxLocal, dim);
389 maxPoreRadius[vIdxGlobal] = std::min(maxPoreRadius[vIdxGlobal], maxRadius);
390 }
391 }
392
393 return maxPoreRadius;
394 }
395
396 // returns a function taking a vertex and a pore label and returning a radius
397 std::function<Scalar(const Vertex&, const int)> poreRadiusGenerator_(const int subregionId) const
398 {
399 // adapt the parameter name if there are subregions
400 const std::string prefix = subregionId < 0 ? "Grid." : "Grid.Subregion" + std::to_string(subregionId) + ".";
401
402 // prepare random number generation for lognormal parameter distribution
403 std::mt19937 generator;
404
405 // check if pores for certain labels should be treated in a special way
406 const auto poreLabelsToSetFixedRadius = getParamFromGroup<std::vector<int>>(paramGroup_, prefix + "PoreLabelsToSetFixedRadius", std::vector<int>{});
407 const auto poreLabelsToApplyFactorForRadius = getParamFromGroup<std::vector<int>>(paramGroup_, prefix + "PoreLabelsToApplyFactorForRadius", std::vector<int>{});
408 const auto poreRadiusForLabel = getParamFromGroup<std::vector<Scalar>>(paramGroup_, prefix + "FixedPoreRadiusForLabel", std::vector<Scalar>{});
409 const auto poreRadiusFactorForLabel = getParamFromGroup<std::vector<Scalar>>(paramGroup_, prefix + "PoreRadiusFactorForLabel", std::vector<Scalar>{});
410
411 const auto generateFunction = [&](auto& poreRadiusDist)
412 {
413 return [=](const auto& vertex, const int poreLabel) mutable
414 {
415 const auto radius = poreRadiusDist(generator);
416
417 // check if pores for certain labels should be treated in a special way
418 if (poreLabelsToSetFixedRadius.empty() && poreLabelsToApplyFactorForRadius.empty())
419 return radius; // nothing special to be done
420
421 // set a fixed radius for a given label
422 else if (!poreLabelsToSetFixedRadius.empty() || !poreRadiusForLabel.empty())
423 {
424 if (poreLabelsToSetFixedRadius.size() != poreRadiusForLabel.size())
425 DUNE_THROW(Dumux::ParameterException, "PoreLabelsToSetFixedRadius must be of same size as FixedPoreRadiusForLabel");
426
427 if (const auto it = std::find(poreLabelsToSetFixedRadius.begin(), poreLabelsToSetFixedRadius.end(), poreLabel); it != poreLabelsToSetFixedRadius.end())
428 return poreRadiusForLabel[std::distance(poreLabelsToSetFixedRadius.begin(), it)];
429 }
430
431 // multiply the pore radius by a given value for a given label
432 else if (!poreLabelsToApplyFactorForRadius.empty() || !poreRadiusFactorForLabel.empty())
433 {
434 if (poreLabelsToApplyFactorForRadius.size() != poreRadiusFactorForLabel.size())
435 DUNE_THROW(Dumux::ParameterException, "PoreLabelsToApplyFactorForRadius must be of same size as PoreRadiusFactorForLabel");
436
437 if (const auto it = std::find(poreLabelsToApplyFactorForRadius.begin(), poreLabelsToApplyFactorForRadius.end(), poreLabel); it != poreLabelsToApplyFactorForRadius.end())
438 return poreRadiusFactorForLabel[std::distance(poreLabelsToApplyFactorForRadius.begin(), it)] * radius;
439 }
440
441 // default
442 return radius;
443 };
444 };
445
446 const Scalar fixedPoreRadius = getParamFromGroup<Scalar>(paramGroup_, prefix + "PoreInscribedRadius", -1.0);
447 // return random radius according to a user-specified distribution
448 if (fixedPoreRadius <= 0.0)
449 {
450 // allow to specify a seed to get reproducible results
451 const auto seed = getParamFromGroup<unsigned int>(paramGroup_, prefix + "ParameterRandomNumberSeed", std::random_device{}());
452 generator.seed(seed);
453
454 const auto type = getParamFromGroup<std::string>(paramGroup_, prefix + "ParameterType", "lognormal");
455 if (type == "lognormal")
456 {
457 // if we use a lognormal distribution, get the mean and standard deviation from input file
458 const auto [meanPoreRadius, stddevPoreRadius] = getDistributionInputParams_("Lognormal", prefix,
459 "MeanPoreInscribedRadius",
460 "StandardDeviationPoreInscribedRadius");
461 const Scalar variance = stddevPoreRadius*stddevPoreRadius;
462
463 using std::log;
464 using std::sqrt;
465 const Scalar mu = log(meanPoreRadius/sqrt(1.0 + variance/(meanPoreRadius*meanPoreRadius)));
466 const Scalar sigma = sqrt(log(1.0 + variance/(meanPoreRadius*meanPoreRadius)));
467
468 Dumux::SimpleLogNormalDistribution<> poreRadiusDist(mu, sigma);
469 return generateFunction(poreRadiusDist);
470 }
471 else if (type == "uniform")
472 {
473 // if we use a uniform distribution, get the min and max from input file
474 const auto [minPoreRadius, maxPoreRadius] = getDistributionInputParams_("Uniform", prefix,
475 "MinPoreInscribedRadius",
476 "MaxPoreInscribedRadius");
477 Dumux::SimpleUniformDistribution<> poreRadiusDist(minPoreRadius, maxPoreRadius);
478 return generateFunction(poreRadiusDist);
479 }
480 else
481 DUNE_THROW(Dune::InvalidStateException, "Unknown parameter type " << type);
482 }
483
484 // always return a fixed constant radius
485 else
486 {
487 auto poreRadiusDist = [fixedPoreRadius](auto& gen){ return fixedPoreRadius; };
488 return generateFunction(poreRadiusDist);
489 }
490 }
491
492 // print helpful error message if params are not properly provided
493 std::array<Scalar, 2> getDistributionInputParams_(const std::string& distributionName,
494 const std::string& prefix,
495 const std::string& paramName0,
496 const std::string& paramName1) const
497 {
498 try
499 {
500 return std::array{getParamFromGroup<Scalar>(paramGroup_, prefix + paramName0),
501 getParamFromGroup<Scalar>(paramGroup_, prefix + paramName1)};
502 }
503 catch (const Dumux::ParameterException& e)
504 {
505 std::cout << "\n" << distributionName << " pore-size distribution needs input parameters "
506 << prefix + paramName0 << " and " << prefix + paramName1 << ".\n"
507 << "Alternatively, use " << prefix << "PoreInscribedRadius to set a fixed inscribed pore radius." << std::endl;
508 DUNE_THROW(Dumux::ParameterException, e.what());
509 }
510 }
511
512 template <class GetParameter>
513 auto poreVolumeGenerator_(const GetParameter& getParameter) const
514 {
515 const auto geometry = Pore::shapeFromString(getParamFromGroup<std::string>(paramGroup_, "Grid.PoreGeometry"));
516 const auto capPoresOnBoundaries = getParamFromGroup<std::vector<int>>(paramGroup_, "Grid.CapPoresOnBoundaries", std::vector<int>{});
517 if (!isUnique_(capPoresOnBoundaries))
518 DUNE_THROW(Dune::InvalidStateException, "CapPoresOnBoundaries must not contain duplicates");
519
520 // automatically determine the pore volume if not provided by the grid file
521 return [=] (const auto& vertex, const auto vIdx)
522 {
523 const Scalar r = getParameter(vertex, "PoreInscribedRadius");
524 const Scalar volume = [&]
525 {
526 if (geometry == Pore::Shape::cylinder)
527 {
528 static const Scalar fixedHeight = getParamFromGroup<Scalar>(paramGroup_, "Grid.PoreHeight", -1.0);
529 const Scalar h = fixedHeight > 0.0 ? fixedHeight : getParameter(vertex, "PoreHeight");
530 return Pore::volume(geometry, r, h);
531 }
532 else
533 return Pore::volume(geometry, r);
534 }();
535
536 if (capPoresOnBoundaries.empty())
537 return volume;
538 else
539 {
540 std::size_t numCaps = 0;
541 Scalar factor = 1.0;
542 const auto& pos = vertex.geometry().center();
543 for (auto boundaryIdx : capPoresOnBoundaries)
544 {
545 if (onBoundary_(pos, boundaryIdx))
546 {
547 factor *= 0.5;
548 ++numCaps;
549 }
550 }
551
552 if (numCaps > dimWorld)
553 DUNE_THROW(Dune::InvalidStateException, "Pore " << vIdx << " at " << pos << " capped " << numCaps << " times. Capping should not happen more than " << dimWorld << " times");
554
555 return volume * factor;
556 }
557 };
558 }
559
560 // returns a lambda taking a element and returning a radius
561 template <class GetParameter>
562 auto throatInscribedRadiusGenerator_(const int subregionId, const GetParameter& getParameter) const
563 {
564 // adapt the parameter name if there are subregions
565 const std::string prefix = subregionId < 0 ? "Grid." : "Grid.Subregion" + std::to_string(subregionId) + ".";
566
567 // check for a user-specified fixed throat radius
568 const Scalar inputThroatInscribedRadius = getParamFromGroup<Scalar>(paramGroup_, prefix + "ThroatInscribedRadius", -1.0);
569
570 // shape parameter for calculation of throat radius
571 const Scalar throatN = getParamFromGroup<Scalar>(paramGroup_, prefix + "ThroatInscribedRadiusN", 0.1);
572
573 return [=](const Element& element)
574 {
575 const Scalar delta = element.geometry().volume();
576 const std::array<Vertex, 2> vertices = {element.template subEntity<dim>(0), element.template subEntity<dim>(1)};
577
578 // the element parameters (throat radius and length)
579 if (inputThroatInscribedRadius > 0.0)
580 return inputThroatInscribedRadius;
581 else
582 {
583 const Scalar poreRadius0 = getParameter(vertices[0], "PoreInscribedRadius");
584 const Scalar poreRadius1 = getParameter(vertices[1], "PoreInscribedRadius");
585 return Throat::averagedRadius(poreRadius0, poreRadius1, delta, throatN);
586 }
587 };
588 }
589
590 // returns a lambda taking a element and returning a length
591 template <class GetParameter>
592 auto throatLengthGenerator_(int subregionId, const GetParameter& getParameter) const
593 {
594 // adapt the parameter name if there are subregions
595 const std::string prefix = subregionId < 0 ? "Grid." : "Grid.Subregion" + std::to_string(subregionId) + ".";
596 const Scalar inputThroatLength = getParamFromGroup<Scalar>(paramGroup_, prefix + "ThroatLength", -1.0);
597 // decide whether to subtract the pore radii from the throat length or not
598 const bool subtractRadiiFromThroatLength = getParamFromGroup<bool>(paramGroup_, prefix + "SubtractPoreInscribedRadiiFromThroatLength", true);
599
600 return [=](const Element& element)
601 {
602 if (inputThroatLength > 0.0)
603 return inputThroatLength;
604
605 const Scalar delta = element.geometry().volume();
606 if (subtractRadiiFromThroatLength)
607 {
608 const std::array<Vertex, 2> vertices = {element.template subEntity<dim>(0), element.template subEntity<dim>(1)};
609 const Scalar result = delta - getParameter(vertices[0], "PoreInscribedRadius") - getParameter(vertices[1], "PoreInscribedRadius");
610 if (result <= 0.0)
611 DUNE_THROW(Dune::GridError, "Pore radii are so large they intersect! Something went wrong at element " << gridView_.indexSet().index(element));
612 else
613 return result;
614 }
615 else
616 return delta;
617 };
618 }
619
620 bool onBoundary_(const GlobalPosition& pos, std::size_t boundaryIdx) const
621 {
622 constexpr auto eps = 1e-8; //TODO
623
624 static constexpr std::array boundaryIdxToCoordinateIdx{0, 0, 1, 1, 2, 2};
625 const auto coordinateIdx = boundaryIdxToCoordinateIdx[boundaryIdx];
626 auto isMaxBoundary = [] (int n) { return (n % 2 != 0); };
627
628 if (isMaxBoundary(boundaryIdx))
629 return pos[coordinateIdx] > bBoxMax_[coordinateIdx] - eps;
630 else
631 return pos[coordinateIdx] < bBoxMin_[coordinateIdx] + eps;
632 }
633
634 // check if a container is unique
635 // copy the container such that is does not get altered by std::sort
636 template <class T>
637 bool isUnique_(T t) const
638 {
639 std::sort(t.begin(), t.end());
640 return (std::unique(t.begin(), t.end()) == t.end());
641 }
642
643 const GridView gridView_;
644
645 const std::string paramGroup_;
646 BoundaryList priorityList_;
647 BoundaryList boundaryFaceIndex_;
648
650 GlobalPosition bBoxMin_ = GlobalPosition(std::numeric_limits<double>::max());
651 GlobalPosition bBoxMax_ = GlobalPosition(std::numeric_limits<double>::min());
652};
653
654} // namespace Dumux::PoreNetwork
655
656#endif
Exception thrown if a run-time parameter is not specified correctly.
Definition: exceptions.hh:48
Helper class to assign parameters to a generated grid.
Definition: parametersforgeneratedgrid.hh:41
int throatLabel(const std::array< int, 2 > &poreLabels) const
Computes and returns the label of a given throat.
Definition: parametersforgeneratedgrid.hh:84
ParametersForGeneratedGrid(const GridView &gridView, const std::string &paramGroup)
Definition: parametersforgeneratedgrid.hh:53
int boundaryFaceMarkerAtPos(const GlobalPosition &pos) const
Returns the boundary face marker index at given position.
Definition: parametersforgeneratedgrid.hh:67
void assignParameters(const SetParameter &setParameter, const GetParameter &getParameter, const std::size_t numSubregions)
Assign parameters for generically created grids.
Definition: parametersforgeneratedgrid.hh:109
A simple log-normal distribution.
Definition: random.hh:183
A simple uniform distribution based on a biased uniform number generator.
Definition: random.hh:30
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 ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: distance.hh:282
auto volume(const Geometry &geo, unsigned int integrationOrder=4)
The volume of a given geometry.
Definition: volume.hh:159
bool hasParamInGroup(const std::string &paramGroup, const std::string &param)
Check whether a key exists in the parameter tree with a model group prefix.
Definition: parameters.hh:165
Detect if a point intersects a geometry.
Shape shapeFromString(const std::string &s)
Get the shape from a string description of the shape.
Definition: poreproperties.hh:44
Scalar volume(Shape shape, Scalar inscribedRadius)
Returns the volume of a given geometry based on the inscribed radius.
Definition: poreproperties.hh:61
Scalar averagedRadius(const Scalar poreRadiusOne, const Scalar poreRadiusTwo, const Scalar centerTocenterDist, const Scalar n=0.1)
Returns the radius of a pore throat.
Definition: throatproperties.hh:68
Definition: discretization/porenetwork/fvelementgeometry.hh:24
std::vector< std::string_view > split(std::string_view str, std::string_view delim, bool removeEmpty=false)
Definition: stringutilities.hh:68
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
This file contains functions related to calculate pore-body properties.
Some tools for random number generation.
Helpers for working with strings.
This file contains functions related to calculate pore-throat properties.