3.6-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
38
39namespace Dumux {
40
41#if HAVE_DUNE_FOAMGRID
42
58template<int dim, int dimworld>
59class GridManager<Dune::FoamGrid<dim, dimworld>>
60: public GridManagerBase<Dune::FoamGrid<dim, dimworld>>
61{
62public:
63 using Grid = Dune::FoamGrid<dim, dimworld>;
64 using ParentType = GridManagerBase<Grid>;
65
69 void init(const std::string& modelParamGroup = "")
70 {
71 // try to create it from file
72 if (hasParamInGroup(modelParamGroup, "Grid.File"))
73 {
74 ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup);
75 ParentType::maybeRefineGrid(modelParamGroup);
76 ParentType::loadBalance();
77 return;
78 }
79
80 // Then look for the necessary keys to construct a structured grid from the input file
81 else if (hasParamInGroup(modelParamGroup, "Grid.UpperRight"))
82 {
83 ParentType::template makeStructuredGrid<dim, dimworld>(ParentType::CellType::Simplex, modelParamGroup);
84 ParentType::maybeRefineGrid(modelParamGroup);
85 ParentType::loadBalance();
86 }
87
88 // Didn't find a way to construct the grid
89 else
90 {
91 const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup + ".";
92 DUNE_THROW(ParameterException, "Please supply one of the parameters "
93 << prefix + "Grid.UpperRight"
94 << ", or a grid file in " << prefix + "Grid.File");
95
96 }
97 }
98};
99
115template<int dimworld>
116class GridManager<Dune::FoamGrid<1, dimworld>>
117: public GridManagerBase<Dune::FoamGrid<1, dimworld>>
118{
119public:
120 using Grid = Dune::FoamGrid<1, dimworld>;
121 using ParentType = GridManagerBase<Grid>;
122
126 void init(const std::string& modelParamGroup = "")
127 {
128 // try to create it from file
129 if (hasParamInGroup(modelParamGroup, "Grid.File"))
130 {
131 ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup);
132 ParentType::maybeRefineGrid(modelParamGroup);
133 ParentType::loadBalance();
134 return;
135 }
136
137 // The required parameters
138 using GlobalPosition = Dune::FieldVector<typename Grid::ctype, dimworld>;
139 const auto upperRight = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.UpperRight");
140 const auto lowerLeft = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.LowerLeft", GlobalPosition(0.0));
141 using CellArray = std::array<unsigned int, 1>;
142 const auto cells = getParamFromGroup<CellArray>(modelParamGroup, "Grid.Cells", std::array<unsigned int, 1>{{1}});
143
144 // make the grid (structured interval grid in dimworld space)
145 Dune::GridFactory<Grid> factory;
146
147 constexpr auto geomType = Dune::GeometryTypes::line;
148
149 // create a step vector
150 GlobalPosition step = upperRight;
151 step -= lowerLeft, step /= cells[0];
152
153 // create the vertices
154 GlobalPosition globalPos = lowerLeft;
155 for (unsigned int vIdx = 0; vIdx <= cells[0]; vIdx++, globalPos += step)
156 factory.insertVertex(globalPos);
157
158 // create the cells
159 for(unsigned int eIdx = 0; eIdx < cells[0]; eIdx++)
160 factory.insertElement(geomType, {eIdx, eIdx+1});
161
162 ParentType::gridPtr() = std::shared_ptr<Grid>(factory.createGrid());
163 ParentType::maybeRefineGrid(modelParamGroup);
164 ParentType::loadBalance();
165 }
166};
167
168namespace Grid::Capabilities {
169
170// To the best of our knowledge FoamGrid is view thread-safe
171// This specialization can be removed after we depend on Dune release 2.9 in which this is guaranteed by FoamGrid itself
172template<int dim, int dimworld>
173struct MultithreadingSupported<Dune::FoamGrid<dim, dimworld>>
174{
175 template<class GV>
176 static bool eval(const GV&) // default is independent of the grid view
177 { return true; }
178};
179
180} // end namespace Grid::Capabilities
181
182#endif // HAVE_DUNE_FOAMGRID
183
184} // end namespace Dumux
185
186#endif
dune-grid capabilities compatibility layer
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:177
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
Definition: deprecated.hh:149
constexpr Line line
Definition: couplingmanager1d3d_line.hh:43
static bool eval(const GV &)
Definition: gridcapabilities.hh:81
Grid Grid
Definition: gridmanager_base.hh:69
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:75