version 3.8
gridmanager_mmesh.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_GRID_MANAGER_MMESH_HH
13#define DUMUX_IO_GRID_MANAGER_MMESH_HH
14
15#if HAVE_DUNE_MMESH
16#include <dune/mmesh/mmesh.hh>
17#endif
18
19#ifndef DUMUX_IO_GRID_MANAGER_BASE_HH
21#endif
22
23namespace Dumux {
24
25#if HAVE_DUNE_MMESH
26
42template<int dim>
43class GridManager<Dune::MovingMesh<dim>>
44: public GridManagerBase<Dune::MovingMesh<dim>>
45{
46public:
47 using Grid = Dune::MovingMesh<dim>;
48 using ParentType = GridManagerBase<Grid>;
49
53 void init(const std::string& modelParamGroup = "")
54 {
55 // try to create it from file
56 if (hasParamInGroup(modelParamGroup, "Grid.File"))
57 {
58 ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup);
59 ParentType::maybeRefineGrid(modelParamGroup);
60 ParentType::loadBalance();
61 return;
62 }
63
64 // Then look for the necessary keys to construct a structured grid from the input file
65 else if (hasParamInGroup(modelParamGroup, "Grid.UpperRight"))
66 {
67 using GlobalPosition = Dune::FieldVector<typename Grid::ctype, dim>;
68 const auto upperRight = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.UpperRight");
69 const auto lowerLeft = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.LowerLeft", GlobalPosition(0.0));
70
71 using CellArray = std::array<unsigned int, dim>;
72 CellArray numCells; numCells.fill(1);
73 numCells = getParamFromGroup<CellArray>(modelParamGroup, "Grid.Cells", numCells);
74
75 // Insert uniformly spaced vertices
76 std::array<unsigned int, dim> numVertices = numCells;
77 for (int i = 0; i < dim; ++i)
78 numVertices[i]++;
79
80 Dune::MMeshImplicitGridFactory<Grid> factory;
81
82 // Insert equally spaced vertices
83 Dune::FactoryUtilities::MultiIndex<dim> index(numVertices);
84 for (int i = 0; i < index.cycle(); ++i, ++index)
85 {
86 GlobalPosition pos(0);
87 for (int j=0; j<dim; j++)
88 pos[j] = lowerLeft[j] + index[j] * (upperRight[j]-lowerLeft[j])/(numVertices[j]-1);
89
90 factory.insertVertex(pos);
91 }
92
93 this->gridPtr() = std::unique_ptr<Grid>(factory.createGrid());
94 ParentType::maybeRefineGrid(modelParamGroup);
95 ParentType::loadBalance();
96 }
97
98 // Didn't find a way to construct the grid
99 else
100 {
101 const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup + ".";
102 DUNE_THROW(ParameterException, "Please supply one of the parameters "
103 << prefix + "Grid.UpperRight"
104 << ", or a grid file in " << prefix + "Grid.File");
105
106 }
107 }
108};
109
110#endif // HAVE_DUNE_MMESH
111
112} // end namespace Dumux
113
114#endif
Grid Grid
Definition: gridmanager_base.hh:57
std::shared_ptr< Grid > & gridPtr()
Returns a reference to the grid pointer (std::shared_ptr<Grid>)
Definition: gridmanager_base.hh:145
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
Provides a grid manager for all supported grid managers with input file interfaces....
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
Definition: adapt.hh:17
Definition: common/pdesolver.hh:24