58 using ct =
typename Dune::YaspGrid<dim, Coordinates>::ctype;
59 using GlobalPosition = Dune::FieldVector<ct, dim>;
61 using Grid =
typename Dune::YaspGrid<dim, Coordinates>;
67 void init(
const std::string& modelParamGroup =
"")
73 postProcessing_(modelParamGroup);
84 std::array<int, dim> cells; cells.fill(1);
89 const std::bitset<dim> periodic;
95 ParentType::gridPtr() = createGrid_(modelParamGroup, upperRight, cells, periodic, overlap, Coordinates{});
97 postProcessing_(modelParamGroup);
103 const auto prefix = modelParamGroup ==
"" ? modelParamGroup : modelParamGroup +
".";
105 << prefix +
"Grid.UpperRight"
106 <<
", or a grid file in " << prefix +
"Grid.File");
115 std::unique_ptr<Grid> createGrid_(
const std::string& modelParamGroup,
116 const GlobalPosition& upperRight,
117 const std::array<int, dim>& cells,
118 const std::bitset<dim>& periodic,
120 Dune::EquidistantCoordinates<ct, dim>)
const
125 return std::make_unique<Grid>(upperRight, cells, periodic, overlap);
131 Dune::YaspFixedSizePartitioner<dim> lb(partitioning);
132 return std::make_unique<Grid>(upperRight, cells, periodic, overlap,
typename Grid::CollectiveCommunicationType(), &lb);
139 std::unique_ptr<Grid> createGrid_(
const std::string& modelParamGroup,
140 const GlobalPosition& upperRight,
141 const std::array<int, dim>& cells,
142 const std::bitset<dim>& periodic,
144 Dune::EquidistantOffsetCoordinates<ct, dim>)
const
151 return std::make_unique<Grid>(lowerLeft, upperRight, cells, periodic, overlap);
157 Dune::YaspFixedSizePartitioner<dim> lb(partitioning);
158 return std::make_unique<Grid>(lowerLeft, upperRight, cells, periodic, overlap,
typename Grid::CollectiveCommunicationType(), &lb);
165 void postProcessing_(
const std::string& modelParamGroup)
169 ParentType::grid().refineOptions(keepPhysicalOverlap);
170 ParentType::maybeRefineGrid(modelParamGroup);
171 ParentType::loadBalance();
205:
public GridManagerBase<Dune::YaspGrid<dim, Dune::TensorProductCoordinates<ctype, dim> > >
208 using Grid =
typename Dune::YaspGrid<dim, Dune::TensorProductCoordinates<ctype, dim> >;
214 void init(
const std::string& modelParamGroup =
"")
219 std::array<std::vector<ctype>, dim> positions;
220 for (
int i = 0; i < dim; ++i)
221 positions[i] =
getParamFromGroup<std::vector<ctype>>(modelParamGroup,
"Grid.Positions" + std::to_string(i));
224 std::array<std::vector<int>, dim> cells;
225 for (
int i = 0; i < dim; ++i)
227 cells[i].resize(positions[i].size()-1, 1.0);
232 std::array<std::vector<ctype>, dim> grading;
233 for (
int i = 0; i < dim; ++i)
235 grading[i].resize(positions[i].size()-1, 1.0);
240 init(positions, cells, grading, modelParamGroup);
246 void init(
const std::array<std::vector<ctype>, dim>& positions,
247 const std::array<std::vector<int>, dim>& cells,
248 const std::array<std::vector<ctype>, dim>& grading,
249 const std::string& modelParamGroup =
"")
258 const std::bitset<dim> periodic;
261 for (
unsigned int dimIdx = 0; dimIdx < dim; ++dimIdx)
263 if (cells[dimIdx].size() + 1 != positions[dimIdx].size())
265 DUNE_THROW(Dune::RangeError,
"Make sure to specify correct \"Cells\" and \"Positions\" arrays");
267 if (grading[dimIdx].size() + 1 != positions[dimIdx].size())
269 DUNE_THROW(Dune::RangeError,
"Make sure to specify correct \"Grading\" and \"Positions\" arrays");
271 ctype temp = std::numeric_limits<ctype>::lowest();
272 for (
unsigned int posIdx = 0; posIdx < positions[dimIdx].size(); ++posIdx)
274 if (temp > positions[dimIdx][posIdx])
276 DUNE_THROW(Dune::RangeError,
"Make sure to specify a monotone increasing \"Positions\" array");
278 temp = positions[dimIdx][posIdx];
282 const auto globalPositions = computeGlobalPositions_(positions, cells, grading, verbose);
294 Dune::YaspFixedSizePartitioner<dim> lb(partitioning);
295 ParentType::gridPtr() = std::make_shared<Grid>(globalPositions, periodic, overlap,
typename Grid::CollectiveCommunicationType(), &lb);
298 postProcessing_(modelParamGroup);
305 void postProcessing_(
const std::string& modelParamGroup)
309 ParentType::grid().refineOptions(keepPhysicalOverlap);
310 ParentType::maybeRefineGrid(modelParamGroup);
311 ParentType::loadBalance();
315 std::array<std::vector<ctype>, dim>
316 computeGlobalPositions_(
const std::array<std::vector<ctype>, dim>& positions,
317 const std::array<std::vector<int>, dim>& cells,
318 const std::array<std::vector<ctype>, dim>& grading,
319 bool verbose =
false)
321 std::array<std::vector<ctype>, dim> globalPositions;
323 for (
int dimIdx = 0; dimIdx < dim; dimIdx++)
325 for (
int zoneIdx = 0; zoneIdx < cells[dimIdx].size(); ++zoneIdx)
327 ctype lower = positions[dimIdx][zoneIdx];
328 ctype upper = positions[dimIdx][zoneIdx+1];
329 int numCells = cells[dimIdx][zoneIdx];
330 ctype gradingFactor = grading[dimIdx][zoneIdx];
331 ctype length = upper - lower;
333 bool increasingCellSize =
false;
337 std::cout <<
"dim " << dimIdx
338 <<
" lower " << lower
339 <<
" upper " << upper
340 <<
" numCells " << numCells
341 <<
" grading " << gradingFactor;
344 if (gradingFactor > 1.0)
346 increasingCellSize =
true;
351 if (gradingFactor < 0.0)
354 gradingFactor = abs(gradingFactor);
355 if (gradingFactor < 1.0)
357 increasingCellSize =
true;
362 if (gradingFactor > 1.0 - 1e-7 && gradingFactor < 1.0 + 1e-7)
364 height = 1.0 / numCells;
367 std::cout <<
" -> h " << height * length << std::endl;
373 height = (1.0 - gradingFactor) / (1.0 - pow(gradingFactor, numCells));
377 std::cout <<
" -> grading_eff " << gradingFactor
378 <<
" h_min " << height * pow(gradingFactor, 0) * length
379 <<
" h_max " << height * pow(gradingFactor, numCells-1) * length
384 std::vector<ctype> localPositions;
385 localPositions.push_back(0);
386 for (
int i = 0; i < numCells-1; i++)
389 if (!(gradingFactor < 1.0 + 1e-7 && gradingFactor > 1.0 - 1e-7))
391 if (increasingCellSize)
393 hI *= pow(gradingFactor, i);
397 hI *= pow(gradingFactor, numCells-i-1);
400 localPositions.push_back(localPositions[i] + hI);
403 for (
int i = 0; i < localPositions.size(); i++)
405 localPositions[i] *= length;
406 localPositions[i] += lower;
409 for (
unsigned int i = 0; i < localPositions.size(); ++i)
411 globalPositions[dimIdx].push_back(localPositions[i]);
414 globalPositions[dimIdx].push_back(positions[dimIdx].back());
417 return globalPositions;
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:454
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:246