version 3.10-dev
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// 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_FOAM_HH
13#define DUMUX_IO_GRID_MANAGER_FOAM_HH
14
15// FoamGrid specific includes
16#if HAVE_DUNE_FOAMGRID
17#include <dune/foamgrid/foamgrid.hh>
18#include <dune/foamgrid/dgffoam.hh>
19#endif
20
21#ifndef DUMUX_IO_GRID_MANAGER_BASE_HH
23#endif
24
26
27namespace Dumux {
28
29#if HAVE_DUNE_FOAMGRID
30
46template<int dim, int dimworld>
47class GridManager<Dune::FoamGrid<dim, dimworld>>
48: public GridManagerBase<Dune::FoamGrid<dim, dimworld>>
49{
50public:
51 using Grid = Dune::FoamGrid<dim, dimworld>;
52 using ParentType = GridManagerBase<Grid>;
53
57 void init(const std::string& modelParamGroup = "")
58 {
59 // try to create it from file
60 if (hasParamInGroup(modelParamGroup, "Grid.File"))
61 {
62 ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup);
63 ParentType::maybeRefineGrid(modelParamGroup);
64 ParentType::loadBalance();
65 return;
66 }
67
68 // Then look for the necessary keys to construct a structured grid from the input file
69 else if (hasParamInGroup(modelParamGroup, "Grid.UpperRight"))
70 {
71 ParentType::template makeStructuredGrid<dim, dimworld>(ParentType::CellType::Simplex, modelParamGroup);
72 ParentType::maybeRefineGrid(modelParamGroup);
73 ParentType::loadBalance();
74 }
75
76 // Didn't find a way to construct the grid
77 else
78 {
79 const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup + ".";
80 DUNE_THROW(ParameterException, "Please supply one of the parameters "
81 << prefix + "Grid.UpperRight"
82 << ", or a grid file in " << prefix + "Grid.File");
83
84 }
85 }
86};
87
103template<int dimworld>
104class GridManager<Dune::FoamGrid<1, dimworld>>
105: public GridManagerBase<Dune::FoamGrid<1, dimworld>>
106{
107public:
108 using Grid = Dune::FoamGrid<1, dimworld>;
109 using ParentType = GridManagerBase<Grid>;
110
114 void init(const std::string& modelParamGroup = "")
115 {
116 // try to create it from file
117 if (hasParamInGroup(modelParamGroup, "Grid.File"))
118 {
119 ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup);
120 ParentType::maybeRefineGrid(modelParamGroup);
121 ParentType::loadBalance();
122 return;
123 }
124
125 // The required parameters
126 using GlobalPosition = Dune::FieldVector<typename Grid::ctype, dimworld>;
127 const auto upperRight = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.UpperRight");
128 const auto lowerLeft = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.LowerLeft", GlobalPosition(0.0));
129 using CellArray = std::array<unsigned int, 1>;
130 const auto cells = getParamFromGroup<CellArray>(modelParamGroup, "Grid.Cells", std::array<unsigned int, 1>{{1}});
131
132 // make the grid (structured interval grid in dimworld space)
133 Dune::GridFactory<Grid> factory;
134
135 constexpr auto geomType = Dune::GeometryTypes::line;
136
137 // create a step vector
138 GlobalPosition step = upperRight;
139 step -= lowerLeft, step /= cells[0];
140
141 // create the vertices
142 GlobalPosition globalPos = lowerLeft;
143 for (unsigned int vIdx = 0; vIdx <= cells[0]; vIdx++, globalPos += step)
144 factory.insertVertex(globalPos);
145
146 // create the cells
147 for(unsigned int eIdx = 0; eIdx < cells[0]; eIdx++)
148 factory.insertElement(geomType, {eIdx, eIdx+1});
149
150 ParentType::gridPtr() = std::shared_ptr<Grid>(factory.createGrid());
151 ParentType::maybeRefineGrid(modelParamGroup);
152 ParentType::loadBalance();
153 }
154};
155
156namespace Grid::Capabilities {
157
158// To the best of our knowledge FoamGrid is view thread-safe
159// This specialization can be removed after we depend on Dune release 2.9 in which this is guaranteed by FoamGrid itself
160template<int dim, int dimworld>
161struct MultithreadingSupported<Dune::FoamGrid<dim, dimworld>>
162{
163 template<class GV>
164 static bool eval(const GV&) // default is independent of the grid view
165 { return true; }
166};
167
168} // end namespace Grid::Capabilities
169
170#endif // HAVE_DUNE_FOAMGRID
171
172} // end namespace Dumux
173
174#endif
Grid Grid
Definition: gridmanager_base.hh:57
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
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:165
constexpr Line line
Definition: couplingmanager1d3d_line.hh:31
Definition: adapt.hh:17
Definition: common/pdesolver.hh:24
static bool eval(const GV &)
Definition: gridcapabilities.hh:69