3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_IO_GRID_MANAGER_MMESH_HH
25#define DUMUX_IO_GRID_MANAGER_MMESH_HH
26
27#if HAVE_DUNE_MMESH
28#include <dune/mmesh/mmesh.hh>
29#endif
30
31#ifndef DUMUX_IO_GRID_MANAGER_BASE_HH
33#endif
34
35namespace Dumux {
36
37#if HAVE_DUNE_MMESH
38
54template<int dim>
55class GridManager<Dune::MovingMesh<dim>>
56: public GridManagerBase<Dune::MovingMesh<dim>>
57{
58public:
59 using Grid = Dune::MovingMesh<dim>;
60 using ParentType = GridManagerBase<Grid>;
61
65 void init(const std::string& modelParamGroup = "")
66 {
67 // try to create it from file
68 if (hasParamInGroup(modelParamGroup, "Grid.File"))
69 {
70 ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup);
71 ParentType::maybeRefineGrid(modelParamGroup);
72 ParentType::loadBalance();
73 return;
74 }
75
76 // Then look for the necessary keys to construct a structured grid from the input file
77 else if (hasParamInGroup(modelParamGroup, "Grid.UpperRight"))
78 {
79 using GlobalPosition = Dune::FieldVector<typename Grid::ctype, dim>;
80 const auto upperRight = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.UpperRight");
81 const auto lowerLeft = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.LowerLeft", GlobalPosition(0.0));
82
83 using CellArray = std::array<unsigned int, dim>;
84 CellArray numCells; numCells.fill(1);
85 numCells = getParamFromGroup<CellArray>(modelParamGroup, "Grid.Cells", numCells);
86
87 // Insert uniformly spaced vertices
88 std::array<unsigned int, dim> numVertices = numCells;
89 for (int i = 0; i < dim; ++i)
90 numVertices[i]++;
91
92 Dune::MMeshImplicitGridFactory<Grid> factory;
93
94 // Insert equally spaced vertices
95 Dune::FactoryUtilities::MultiIndex<dim> index(numVertices);
96 for (int i = 0; i < index.cycle(); ++i, ++index)
97 {
98 GlobalPosition pos(0);
99 for (int j=0; j<dim; j++)
100 pos[j] = lowerLeft[j] + index[j] * (upperRight[j]-lowerLeft[j])/(numVertices[j]-1);
101
102 factory.insertVertex(pos);
103 }
104
105 this->gridPtr() = std::unique_ptr<Grid>(factory.createGrid());
106 ParentType::maybeRefineGrid(modelParamGroup);
107 ParentType::loadBalance();
108 }
109
110 // Didn't find a way to construct the grid
111 else
112 {
113 const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup + ".";
114 DUNE_THROW(ParameterException, "Please supply one of the parameters "
115 << prefix + "Grid.UpperRight"
116 << ", or a grid file in " << prefix + "Grid.File");
117
118 }
119 }
120};
121
122#endif // HAVE_DUNE_MMESH
123
124} // end namespace Dumux
125
126#endif
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:391
Definition: adapt.hh:29
Definition: common/pdesolver.hh:35
Grid Grid
Definition: gridmanager_base.hh:75
std::shared_ptr< Grid > & gridPtr()
Returns a reference to the grid pointer (std::shared_ptr<Grid>)
Definition: gridmanager_base.hh:142
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:81