3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
gridmanager_ug.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_UG_HH
25#define DUMUX_IO_GRID_MANAGER_UG_HH
26
27#if HAVE_DUNE_UGGRID
28#include <dune/grid/uggrid.hh>
29#include <dune/grid/io/file/dgfparser/dgfug.hh>
30#endif
31
32#ifndef DUMUX_IO_GRID_MANAGER_BASE_HH
34#endif
35
37
38namespace Dumux {
39
40#if HAVE_DUNE_UGGRID
41
60template<int dim>
61class GridManager<Dune::UGGrid<dim>>
62: public GridManagerBase<Dune::UGGrid<dim>>
63{
64public:
65 using Grid = typename Dune::UGGrid<dim>;
66 using ParentType = GridManagerBase<Grid>;
67 using Element = typename Grid::template Codim<0>::Entity;
68
72 void init(const std::string& modelParamGroup = "")
73 {
74
75 // try to create it from a DGF or msh file in GridParameterGroup.File
76 if (hasParamInGroup(modelParamGroup, "Grid.File"))
77 {
78 preProcessing_(modelParamGroup);
79 ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup);
80 postProcessing_(modelParamGroup);
81 return;
82 }
83
84 // Then look for the necessary keys to construct from the input file
85 else if (hasParamInGroup(modelParamGroup, "Grid.UpperRight"))
86 {
87 preProcessing_(modelParamGroup);
88 // make the grid
89 const auto cellType = getParamFromGroup<std::string>(modelParamGroup, "Grid.CellType", "Cube");
90 if (cellType == "Cube")
91 ParentType::template makeStructuredGrid<dim, dim>(ParentType::CellType::Cube, modelParamGroup);
92 else if (cellType == "Simplex")
93 ParentType::template makeStructuredGrid<dim, dim>(ParentType::CellType::Simplex, modelParamGroup);
94 else
95 DUNE_THROW(Dune::IOError, "UGGrid only supports 'Cube' or 'Simplex' as cell type. Not '"<< cellType<<"'!");
96 postProcessing_(modelParamGroup);
97 }
98
99 // Didn't find a way to construct the grid
100 else
101 {
102 const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup + ".";
103 DUNE_THROW(ParameterException, "Please supply one of the parameters "
104 << prefix + "Grid.UpperRight"
105 << ", or a grid file in " << prefix + "Grid.File");
106
107 }
108 }
109
117 void loadBalance()
118 {
119 if (Dune::MPIHelper::getCommunication().size() > 1)
120 {
121 // if we may have dgf parameters use load balancing of the dgf pointer
122 if(ParentType::enableDgfGridPointer_)
123 {
124 ParentType::dgfGridPtr().loadBalance();
125 // update the grid data
126 ParentType::gridData_ = std::make_shared<typename ParentType::GridData>(ParentType::dgfGridPtr());
127 }
128
129 // if we have gmsh parameters we have to manually load balance the data
130 else if (ParentType::enableGmshDomainMarkers_)
131 {
132 // element and face markers are communicated during load balance
133 auto dh = ParentType::gridData_->createGmshDataHandle();
134 ParentType::gridPtr()->loadBalance(dh.interface());
135 // Right now, UGGrid cannot communicate element data. If this gets implemented, communicate the data here:
136 // ParentType::gridPtr()->communicate(dh.interface(), Dune::InteriorBorder_All_Interface, Dune::ForwardCommunication);
137 }
138 else
139 ParentType::gridPtr()->loadBalance();
140 }
141 }
142
143private:
147 void preProcessing_(const std::string& modelParamGroup)
148 {}
149
153 void postProcessing_(const std::string& modelParamGroup)
154 {
155 // Set refinement type
156 const auto refType = getParamFromGroup<std::string>(modelParamGroup, "Grid.RefinementType", "Local");
157 if (refType == "Local")
158 ParentType::grid().setRefinementType(Dune::UGGrid<dim>::RefinementType::LOCAL);
159 else if (refType == "Copy")
160 ParentType::grid().setRefinementType(Dune::UGGrid<dim>::RefinementType::COPY);
161 else
162 DUNE_THROW(Dune::IOError, "UGGrid only supports 'Local' or 'Copy' as refinement type. Not '"<< refType<<"'!");
163
164 // Set closure type
165 const auto closureType = getParamFromGroup<std::string>(modelParamGroup, "Grid.ClosureType", "Green");
166 if (closureType == "Green")
167 ParentType::grid().setClosureType(Dune::UGGrid<dim>::ClosureType::GREEN);
168 else if (closureType == "None")
169 ParentType::grid().setClosureType(Dune::UGGrid<dim>::ClosureType::NONE);
170 else
171 DUNE_THROW(Dune::IOError, "UGGrid only supports 'Green' or 'None' as closure type. Not '"<< closureType<<"'!");
172
173 // Check if should refine the grid
174 ParentType::maybeRefineGrid(modelParamGroup);
175 // do load balancing
176 loadBalance();
177 }
178};
179
180namespace Grid::Capabilities {
181
182// To the best of our knowledge UGGrid is view thread-safe for sequential runs
183// This specialization maybe be removed after we depend on Dune release 2.9 if is guaranteed by UGGrid itself by then
184template<int dim>
185struct MultithreadingSupported<Dune::UGGrid<dim>>
186{
187 template<class GV>
188 static bool eval(const GV& gv) // default is independent of the grid view
189 { return gv.comm().size() <= 1; }
190};
191
192} // end namespace Grid::Capabilities
193
194#endif // HAVE_DUNE_UGGRID
195
196} // end namespace Dumux
197
198#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
static bool eval(const GV &)
Definition: gridcapabilities.hh:81
Grid Grid
Definition: gridmanager_base.hh:69
void loadBalance()
Call loadBalance() function of the grid.
Definition: gridmanager_base.hh:98
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