24#ifndef DUMUX_IO_GRID_MANAGER_YASP_HH
25#define DUMUX_IO_GRID_MANAGER_YASP_HH
27#include <dune/common/math.hh>
29#include <dune/grid/yaspgrid.hh>
30#include <dune/grid/io/file/dgfparser/dgfyasp.hh>
32#ifndef DUMUX_IO_GRID_MANAGER_BASE_HH
59template<
class Coordinates,
int dim>
64 using GlobalPosition = Dune::FieldVector<ct, dim>;
72 void init(
const std::string& modelParamGroup =
"")
77 ParentType::makeGridFromDgfFile(getParamFromGroup<std::string>(modelParamGroup,
"Grid.File"));
78 postProcessing_(modelParamGroup);
86 const auto upperRight = getParamFromGroup<GlobalPosition>(modelParamGroup,
"Grid.UpperRight");
89 std::array<int, dim> cells; cells.fill(1);
90 cells = getParamFromGroup<std::array<int, dim>>(modelParamGroup,
"Grid.Cells", cells);
94 const std::bitset<dim> periodic;
97 const int overlap = getParamFromGroup<int>(modelParamGroup,
"Grid.Overlap", 1);
99 if constexpr (std::is_same_v<Dune::EquidistantCoordinates<ct, dim>, Coordinates>)
100 init(upperRight, cells, modelParamGroup, overlap, periodic);
103 const auto lowerLeft = getParamFromGroup<GlobalPosition>(modelParamGroup,
"Grid.LowerLeft", GlobalPosition(0.0));
104 init(lowerLeft, upperRight, cells, modelParamGroup, overlap, periodic);
111 const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup +
".";
113 << prefix +
"Grid.UpperRight"
114 <<
", or a grid file in " << prefix +
"Grid.File");
123 void init(
const GlobalPosition& upperRight,
124 const std::array<int, dim>& cells,
125 const std::string& modelParamGroup =
"",
126 const int overlap = 1,
127 const std::bitset<dim> periodic = std::bitset<dim>{})
129 static_assert(std::is_same_v<Dune::EquidistantCoordinates<ct, dim>, Coordinates>,
130 "Use init function taking lowerLeft as argument when working with EquidistantOffsetCoordinates");
135 ParentType::gridPtr() = std::make_unique<Grid>(upperRight, cells, periodic, overlap);
140 const auto partitioning = getParamFromGroup<std::array<int, dim>>(modelParamGroup,
"Grid.Partitioning");
141 Dune::YaspFixedSizePartitioner<dim> lb(partitioning);
142 ParentType::gridPtr() = std::make_unique<Grid>(upperRight, cells, periodic, overlap,
typename Grid::CollectiveCommunication(), &lb);
145 postProcessing_(modelParamGroup);
152 void init(
const GlobalPosition& lowerLeft,
153 const GlobalPosition& upperRight,
154 const std::array<int, dim>& cells,
155 const std::string& modelParamGroup =
"",
156 const int overlap = 1,
157 const std::bitset<dim> periodic = std::bitset<dim>{})
159 static_assert(std::is_same_v<Dune::EquidistantOffsetCoordinates<ct, dim>, Coordinates>,
160 "LowerLeft can only be specified with EquidistantOffsetCoordinates");
165 ParentType::gridPtr() = std::make_unique<Grid>(lowerLeft, upperRight, cells, periodic, overlap);
170 const auto partitioning = getParamFromGroup<std::array<int, dim>>(modelParamGroup,
"Grid.Partitioning");
171 Dune::YaspFixedSizePartitioner<dim> lb(partitioning);
172 ParentType::gridPtr() = std::make_unique<Grid>(lowerLeft, upperRight, cells, periodic, overlap,
typename Grid::CollectiveCommunication(), &lb);
175 postProcessing_(modelParamGroup);
183 void postProcessing_(
const std::string& modelParamGroup)
186 const bool keepPhysicalOverlap = getParamFromGroup<bool>(modelParamGroup,
"Grid.KeepPhysicalOverlap",
true);
187 ParentType::grid().refineOptions(keepPhysicalOverlap);
188 ParentType::maybeRefineGrid(modelParamGroup);
189 ParentType::loadBalance();
222template<
class ctype,
int dim>
224:
public GridManagerBase<Dune::YaspGrid<dim, Dune::TensorProductCoordinates<ctype, dim> > >
233 void init(
const std::string& modelParamGroup =
"")
238 std::array<std::vector<ctype>, dim> positions;
239 for (
int i = 0; i < dim; ++i)
240 positions[i] =
getParamFromGroup<std::vector<ctype>>(modelParamGroup,
"Grid.Positions" + std::to_string(i));
243 std::array<std::vector<int>, dim> cells;
244 for (
int i = 0; i < dim; ++i)
246 cells[i].resize(positions[i].size()-1, 1.0);
247 cells[i] = getParamFromGroup<std::vector<int>>(modelParamGroup,
"Grid.Cells" + std::to_string(i), cells[i]);
251 std::array<std::vector<ctype>, dim> grading;
252 for (
int i = 0; i < dim; ++i)
254 grading[i].resize(positions[i].size()-1, 1.0);
255 grading[i] = getParamFromGroup<std::vector<ctype>>(modelParamGroup,
"Grid.Grading" + std::to_string(i), grading[i]);
259 init(positions, cells, grading, modelParamGroup);
265 void init(
const std::array<std::vector<ctype>, dim>& positions,
266 const std::array<std::vector<int>, dim>& cells,
267 const std::array<std::vector<ctype>, dim>& grading,
268 const std::string& modelParamGroup =
"")
271 const int overlap = getParamFromGroup<int>(modelParamGroup,
"Grid.Overlap", 1);
272 const bool verbose = getParamFromGroup<bool>(modelParamGroup,
"Grid.Verbosity",
false);
275 const std::bitset<dim> periodic;
278 for (
unsigned int dimIdx = 0; dimIdx < dim; ++dimIdx)
280 if (cells[dimIdx].size() + 1 != positions[dimIdx].size())
282 DUNE_THROW(Dune::RangeError,
"Make sure to specify correct \"Cells\" and \"Positions\" arrays");
284 if (grading[dimIdx].size() + 1 != positions[dimIdx].size())
286 DUNE_THROW(Dune::RangeError,
"Make sure to specify correct \"Grading\" and \"Positions\" arrays");
288 ctype temp = std::numeric_limits<ctype>::lowest();
289 for (
unsigned int posIdx = 0; posIdx < positions[dimIdx].size(); ++posIdx)
291 if (temp > positions[dimIdx][posIdx])
293 DUNE_THROW(Dune::RangeError,
"Make sure to specify a monotone increasing \"Positions\" array");
295 temp = positions[dimIdx][posIdx];
299 const auto globalPositions = computeGlobalPositions_(positions, cells, grading, verbose);
305 ParentType::gridPtr() = std::make_shared<Grid>(globalPositions, periodic, overlap);
310 const auto partitioning = getParamFromGroup<std::array<int, dim>>(modelParamGroup,
"Grid.Partitioning");
311 Dune::YaspFixedSizePartitioner<dim> lb(partitioning);
312 ParentType::gridPtr() = std::make_shared<Grid>(globalPositions, periodic, overlap,
typename Grid::CollectiveCommunication(), &lb);
315 postProcessing_(modelParamGroup);
322 void postProcessing_(
const std::string& modelParamGroup)
325 const bool keepPhysicalOverlap = getParamFromGroup<bool>(modelParamGroup,
"Grid.KeepPhysicalOverlap",
true);
326 ParentType::grid().refineOptions(keepPhysicalOverlap);
327 ParentType::maybeRefineGrid(modelParamGroup);
328 ParentType::loadBalance();
332 std::array<std::vector<ctype>, dim>
333 computeGlobalPositions_(
const std::array<std::vector<ctype>, dim>& positions,
334 const std::array<std::vector<int>, dim>& cells,
335 const std::array<std::vector<ctype>, dim>& grading,
336 bool verbose =
false)
338 std::array<std::vector<ctype>, dim> globalPositions;
341 for (
int dimIdx = 0; dimIdx < dim; dimIdx++)
343 for (
int zoneIdx = 0; zoneIdx < cells[dimIdx].size(); ++zoneIdx)
345 ctype lower = positions[dimIdx][zoneIdx];
346 ctype upper = positions[dimIdx][zoneIdx+1];
347 int numCells = cells[dimIdx][zoneIdx];
348 ctype gradingFactor = grading[dimIdx][zoneIdx];
349 ctype length = upper - lower;
351 bool increasingCellSize =
false;
355 std::cout <<
"dim " << dimIdx
356 <<
" lower " << lower
357 <<
" upper " << upper
358 <<
" numCells " << numCells
359 <<
" grading " << gradingFactor;
362 if (gradingFactor > 1.0)
364 increasingCellSize =
true;
369 if (gradingFactor < 0.0)
372 gradingFactor = abs(gradingFactor);
373 if (gradingFactor < 1.0)
375 increasingCellSize =
true;
380 if (gradingFactor > 1.0 - 1e-7 && gradingFactor < 1.0 + 1e-7)
382 height = 1.0 / numCells;
385 std::cout <<
" -> h " << height * length << std::endl;
391 height = (1.0 - gradingFactor) / (1.0 - power(gradingFactor, numCells));
395 std::cout <<
" -> grading_eff " << gradingFactor
396 <<
" h_min " << height * power(gradingFactor, 0) * length
397 <<
" h_max " << height * power(gradingFactor, numCells-1) * length
402 std::vector<ctype> localPositions;
403 localPositions.push_back(0);
404 for (
int i = 0; i < numCells-1; i++)
407 if (!(gradingFactor < 1.0 + 1e-7 && gradingFactor > 1.0 - 1e-7))
409 if (increasingCellSize)
411 hI *= power(gradingFactor, i);
415 hI *= power(gradingFactor, numCells-i-1);
418 localPositions.push_back(localPositions[i] + hI);
421 for (
int i = 0; i < localPositions.size(); i++)
423 localPositions[i] *= length;
424 localPositions[i] += lower;
427 for (
unsigned int i = 0; i < localPositions.size(); ++i)
429 globalPositions[dimIdx].push_back(localPositions[i]);
432 globalPositions[dimIdx].push_back(positions[dimIdx].back());
435 return globalPositions;
439namespace Grid::Capabilities {
443template<
class Coordinates,
int dim>
dune-grid capabilities compatibility layer
Provides a grid manager for all supported grid managers with input file interfaces....
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition: parameters.hh:161
bool hasParamInGroup(const std::string ¶mGroup, const std::string ¶m)
Check whether a key exists in the parameter tree with a model group prefix.
Definition: parameters.hh:177
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
Definition: deprecated.hh:149
Exception thrown if a run-time parameter is not specified correctly.
Definition: exceptions.hh:60
Definition: gridcapabilities.hh:79
Definition: consistentlyorientedgrid.hh:32
The grid manager (this is the class used by the user) for all supported grid managers that constructs...
Definition: gridmanager_base.hh:324
The grid manager base interface (public) and methods common to most grid manager specializations (pro...
Definition: gridmanager_base.hh:67
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:75
typename Dune::YaspGrid< dim, Coordinates > Grid
Definition: gridmanager_yasp.hh:66
void init(const std::string &modelParamGroup="")
Make the grid. This is implemented by specializations of this method.
Definition: gridmanager_yasp.hh:72
void init(const GlobalPosition &upperRight, const std::array< int, dim > &cells, const std::string &modelParamGroup="", const int overlap=1, const std::bitset< dim > periodic=std::bitset< dim >{})
Make the grid using input data not read from the input file.
Definition: gridmanager_yasp.hh:123
void init(const GlobalPosition &lowerLeft, const GlobalPosition &upperRight, const std::array< int, dim > &cells, const std::string &modelParamGroup="", const int overlap=1, const std::bitset< dim > periodic=std::bitset< dim >{})
Make the grid using input data not read from the input file.
Definition: gridmanager_yasp.hh:152
typename Dune::YaspGrid< dim, Dune::TensorProductCoordinates< ctype, dim > > Grid
Definition: gridmanager_yasp.hh:227
void init(const std::array< std::vector< ctype >, dim > &positions, const std::array< std::vector< int >, dim > &cells, const std::array< std::vector< ctype >, dim > &grading, const std::string &modelParamGroup="")
Make the grid using input data not read from the input file.
Definition: gridmanager_yasp.hh:265
void init(const std::string &modelParamGroup="")
Make the grid. This is implemented by specializations of this method.
Definition: gridmanager_yasp.hh:233
static bool eval(const GV &gv)
Definition: gridmanager_yasp.hh:447