3.1-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
55template<int dim, int dimworld>
56class GridManager<Dune::FoamGrid<dim, dimworld>>
57: public GridManagerBase<Dune::FoamGrid<dim, dimworld>>
58{
59public:
60 using Grid = Dune::FoamGrid<dim, dimworld>;
61 using ParentType = GridManagerBase<Grid>;
62
66 void init(const std::string& modelParamGroup = "")
67 {
68 // try to create it from file
69 if (hasParamInGroup(modelParamGroup, "Grid.File"))
70 {
71 ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup);
72 ParentType::maybeRefineGrid(modelParamGroup);
73 ParentType::loadBalance();
74 return;
75 }
76
77 // Then look for the necessary keys to construct a structured grid from the input file
78 else if (hasParamInGroup(modelParamGroup, "Grid.UpperRight"))
79 {
80 ParentType::template makeStructuredGrid<dim, dimworld>(ParentType::CellType::Simplex, modelParamGroup);
81 ParentType::maybeRefineGrid(modelParamGroup);
82 ParentType::loadBalance();
83 }
84
85 // Didn't find a way to construct the grid
86 else
87 {
88 const auto prefix = modelParamGroup == "" ? modelParamGroup : modelParamGroup + ".";
89 DUNE_THROW(ParameterException, "Please supply one of the parameters "
90 << prefix + "Grid.UpperRight"
91 << ", or a grid file in " << prefix + "Grid.File");
92
93 }
94 }
95};
96
111template<int dimworld>
112class GridManager<Dune::FoamGrid<1, dimworld>>
113: public GridManagerBase<Dune::FoamGrid<1, dimworld>>
114{
115public:
116 using Grid = Dune::FoamGrid<1, dimworld>;
117 using ParentType = GridManagerBase<Grid>;
118
122 void init(const std::string& modelParamGroup = "")
123 {
124 // try to create it from file
125 if (hasParamInGroup(modelParamGroup, "Grid.File"))
126 {
127 ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup);
128 ParentType::maybeRefineGrid(modelParamGroup);
129 ParentType::loadBalance();
130 return;
131 }
132
133 // The required parameters
134 using GlobalPosition = Dune::FieldVector<typename Grid::ctype, dimworld>;
135 const auto upperRight = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.UpperRight");
136 const auto lowerLeft = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.LowerLeft", GlobalPosition(0.0));
137 using CellArray = std::array<unsigned int, 1>;
138 const auto cells = getParamFromGroup<CellArray>(modelParamGroup, "Grid.Cells", std::array<unsigned int, 1>{{1}});
139
140 // make the grid (structured interval grid in dimworld space)
141 Dune::GridFactory<Grid> factory;
142
143 constexpr auto geomType = Dune::GeometryTypes::line;
144
145 // create a step vector
146 GlobalPosition step = upperRight;
147 step -= lowerLeft, step /= cells[0];
148
149 // create the vertices
150 GlobalPosition globalPos = lowerLeft;
151 for (unsigned int vIdx = 0; vIdx <= cells[0]; vIdx++, globalPos += step)
152 factory.insertVertex(globalPos);
153
154 // create the cells
155 for(unsigned int eIdx = 0; eIdx < cells[0]; eIdx++)
156 factory.insertElement(geomType, {eIdx, eIdx+1});
157
158 ParentType::gridPtr() = std::shared_ptr<Grid>(factory.createGrid());
159 ParentType::maybeRefineGrid(modelParamGroup);
160 ParentType::loadBalance();
161 }
162};
163
164#endif // HAVE_DUNE_FOAMGRID
165
166} // end namespace Dumux
167
168#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:454
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
Definition: common/properties/model.hh:34
Grid Grid
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:73