3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
gridmanager_foam.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_FOAM_HH
25#define DUMUX_IO_GRID_MANAGER_FOAM_HH
26
27// FoamGrid specific includes
28#if HAVE_DUNE_FOAMGRID
29#include <dune/foamgrid/foamgrid.hh>
30#include <dune/foamgrid/dgffoam.hh>
31#endif
32
33#ifndef DUMUX_IO_GRID_MANAGER_BASE_HH
35#endif
36
37namespace Dumux {
38
39#if HAVE_DUNE_FOAMGRID
40
56template<int dim, int dimworld>
57class GridManager<Dune::FoamGrid<dim, dimworld>>
58: public GridManagerBase<Dune::FoamGrid<dim, dimworld>>
59{
60public:
61 using Grid = Dune::FoamGrid<dim, dimworld>;
62 using ParentType = GridManagerBase<Grid>;
63
67 void init(const std::string& modelParamGroup = "")
68 {
69 // try to create it from file
70 if (hasParamInGroup(modelParamGroup, "Grid.File"))
71 {
72 ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup);
73 ParentType::maybeRefineGrid(modelParamGroup);
74 ParentType::loadBalance();
75 return;
76 }
77
78 // Then look for the necessary keys to construct a structured grid from the input file
79 else if (hasParamInGroup(modelParamGroup, "Grid.UpperRight"))
80 {
81 ParentType::template makeStructuredGrid<dim, dimworld>(ParentType::CellType::Simplex, modelParamGroup);
82 ParentType::maybeRefineGrid(modelParamGroup);
83 ParentType::loadBalance();
84 }
85
86 // Didn't find a way to construct the grid
87 else
88 {
89 const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup + ".";
90 DUNE_THROW(ParameterException, "Please supply one of the parameters "
91 << prefix + "Grid.UpperRight"
92 << ", or a grid file in " << prefix + "Grid.File");
93
94 }
95 }
96};
97
113template<int dimworld>
114class GridManager<Dune::FoamGrid<1, dimworld>>
115: public GridManagerBase<Dune::FoamGrid<1, dimworld>>
116{
117public:
118 using Grid = Dune::FoamGrid<1, dimworld>;
119 using ParentType = GridManagerBase<Grid>;
120
124 void init(const std::string& modelParamGroup = "")
125 {
126 // try to create it from file
127 if (hasParamInGroup(modelParamGroup, "Grid.File"))
128 {
129 ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup);
130 ParentType::maybeRefineGrid(modelParamGroup);
131 ParentType::loadBalance();
132 return;
133 }
134
135 // The required parameters
136 using GlobalPosition = Dune::FieldVector<typename Grid::ctype, dimworld>;
137 const auto upperRight = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.UpperRight");
138 const auto lowerLeft = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.LowerLeft", GlobalPosition(0.0));
139 using CellArray = std::array<unsigned int, 1>;
140 const auto cells = getParamFromGroup<CellArray>(modelParamGroup, "Grid.Cells", std::array<unsigned int, 1>{{1}});
141
142 // make the grid (structured interval grid in dimworld space)
143 Dune::GridFactory<Grid> factory;
144
145 constexpr auto geomType = Dune::GeometryTypes::line;
146
147 // create a step vector
148 GlobalPosition step = upperRight;
149 step -= lowerLeft, step /= cells[0];
150
151 // create the vertices
152 GlobalPosition globalPos = lowerLeft;
153 for (unsigned int vIdx = 0; vIdx <= cells[0]; vIdx++, globalPos += step)
154 factory.insertVertex(globalPos);
155
156 // create the cells
157 for(unsigned int eIdx = 0; eIdx < cells[0]; eIdx++)
158 factory.insertElement(geomType, {eIdx, eIdx+1});
159
160 ParentType::gridPtr() = std::shared_ptr<Grid>(factory.createGrid());
161 ParentType::maybeRefineGrid(modelParamGroup);
162 ParentType::loadBalance();
163 }
164};
165
166#endif // HAVE_DUNE_FOAMGRID
167
168} // end namespace Dumux
169
170#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
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