version 3.11-dev
Loading...
Searching...
No Matches
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-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
13#ifndef DUMUX_IO_GRID_MANAGER_FOAM_HH
14#define DUMUX_IO_GRID_MANAGER_FOAM_HH
15
16// FoamGrid specific includes
17#if HAVE_DUNE_FOAMGRID
18#include <dune/foamgrid/foamgrid.hh>
19#include <dune/foamgrid/dgffoam.hh>
20#endif
21
22#ifndef DUMUX_IO_GRID_MANAGER_BASE_HH
24#endif
25
27
28namespace Dumux {
29
30#if HAVE_DUNE_FOAMGRID
31
51template<int dim, int dimworld>
52class GridManager<Dune::FoamGrid<dim, dimworld>>
53: public GridManagerBase<Dune::FoamGrid<dim, dimworld>>
54{
55public:
56 using Grid = Dune::FoamGrid<dim, dimworld>;
58
62 void init(const std::string& modelParamGroup = "")
63 {
64 // First, try to create it from file
65 if (hasParamInGroup(modelParamGroup, "Grid.File"))
66 {
67 ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup);
68 ParentType::maybeRefineGrid(modelParamGroup);
70 return;
71 }
72
73 // Then look for the necessary keys to construct a structured grid from the input file
74 else if (hasParamInGroup(modelParamGroup, "Grid.UpperRight"))
75 {
76 ParentType::template makeStructuredGrid<dim, dimworld>(ParentType::CellType::Simplex, modelParamGroup);
77 ParentType::maybeRefineGrid(modelParamGroup);
79 }
80
81 // Didn't find a way to construct the grid
82 else
83 {
84 const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup + ".";
85 DUNE_THROW(ParameterException, "Please supply one of the parameters "
86 << prefix + "Grid.UpperRight"
87 << ", or a grid file in " << prefix + "Grid.File");
88
89 }
90 }
91};
92
112template<int dimworld>
113class GridManager<Dune::FoamGrid<1, dimworld>>
114: public GridManagerBase<Dune::FoamGrid<1, dimworld>>
115{
116public:
117 using Grid = Dune::FoamGrid<1, dimworld>;
119
123 void init(const std::string& modelParamGroup = "")
124 {
125 // Try to create it from file
126 if (hasParamInGroup(modelParamGroup, "Grid.File"))
127 {
128 ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup);
129 ParentType::maybeRefineGrid(modelParamGroup);
131 return;
132 }
133
134 // The required parameters
135 using GlobalPosition = Dune::FieldVector<typename Grid::ctype, dimworld>;
136 const auto upperRight = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.UpperRight");
137 const auto lowerLeft = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.LowerLeft", GlobalPosition(0.0));
138 using CellArray = std::array<unsigned int, 1>;
139 const auto cells = getParamFromGroup<CellArray>(modelParamGroup, "Grid.Cells", std::array<unsigned int, 1>{{1}});
140
141 // make the grid (structured interval grid in dimworld space)
142 Dune::GridFactory<Grid> factory;
143
144 constexpr auto geomType = Dune::GeometryTypes::line;
145
146 // create a step vector
147 GlobalPosition step = upperRight;
148 step -= lowerLeft, step /= cells[0];
149
150 // create the vertices
151 GlobalPosition globalPos = lowerLeft;
152 for (unsigned int vIdx = 0; vIdx <= cells[0]; vIdx++, globalPos += step)
153 factory.insertVertex(globalPos);
154
155 // create the cells
156 for(unsigned int eIdx = 0; eIdx < cells[0]; eIdx++)
157 factory.insertElement(geomType, {eIdx, eIdx+1});
158
159 ParentType::gridPtr() = std::shared_ptr<Grid>(factory.createGrid());
160 ParentType::maybeRefineGrid(modelParamGroup);
162 }
163};
164
165namespace Grid::Capabilities {
166
167// To the best of our knowledge FoamGrid is view thread-safe
168// This specialization can be removed after we depend on Dune release 2.9 in which this is guaranteed by FoamGrid itself
169template<int dim, int dimworld>
170struct MultithreadingSupported<Dune::FoamGrid<dim, dimworld>>
171{
172 template<class GV>
173 static bool eval(const GV&) // default is independent of the grid view
174 { return true; }
175};
176
177} // end namespace Grid::Capabilities
178
179#endif // HAVE_DUNE_FOAMGRID
180
181} // end namespace Dumux
182
183#endif
void init(const std::string &modelParamGroup="")
Make the grid. This is implemented by specializations of this method.
Definition gridmanager_foam.hh:123
GridManagerBase< Grid > ParentType
Definition gridmanager_foam.hh:118
Dune::FoamGrid< 1, dimworld > Grid
Definition gridmanager_foam.hh:117
Dune::FoamGrid< dim, dimworld > Grid
Definition gridmanager_foam.hh:56
GridManagerBase< Grid > ParentType
Definition gridmanager_foam.hh:57
void init(const std::string &modelParamGroup="")
Make the grid. This is implemented by specializations of this method.
Definition gridmanager_foam.hh:62
The grid manager base interface (public) and methods common to most grid manager specializations (pro...
Definition gridmanager_base.hh:56
void maybeRefineGrid(const std::string &modelParamGroup)
Definition gridmanager_base.hh:315
void makeGridFromFile(const std::string &fileName, const std::string &modelParamGroup)
Definition gridmanager_base.hh:205
void makeStructuredGrid(CellType cellType, const std::string &modelParamGroup)
Definition gridmanager_base.hh:286
void loadBalance()
Definition gridmanager_base.hh:98
@ Simplex
Definition gridmanager_base.hh:280
std::shared_ptr< Grid > & gridPtr()
Definition gridmanager_base.hh:163
The grid manager (this is the class used by the user) for all supported grid managers that constructs...
Definition gridmanager_base.hh:344
Exception thrown if a run-time parameter is not specified correctly.
Definition exceptions.hh:48
dune-grid capabilities compatibility layer
Provides a grid manager for all supported grid managers with input file interfaces....
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition parameters.hh:149
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
Definition adapt.hh:17
Definition common/pdesolver.hh:24
static bool eval(const GV &)
Definition gridmanager_foam.hh:173