3.3.0
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_UG
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
36namespace Dumux {
37
38#if HAVE_UG
39
58template<int dim>
59class GridManager<Dune::UGGrid<dim>>
60: public GridManagerBase<Dune::UGGrid<dim>>
61{
62public:
63 using Grid = typename Dune::UGGrid<dim>;
64 using ParentType = GridManagerBase<Grid>;
65 using Element = typename Grid::template Codim<0>::Entity;
66
70 void init(const std::string& modelParamGroup = "")
71 {
72
73 // try to create it from a DGF or msh file in GridParameterGroup.File
74 if (hasParamInGroup(modelParamGroup, "Grid.File"))
75 {
76 preProcessing_(modelParamGroup);
77 ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup);
78 postProcessing_(modelParamGroup);
79 return;
80 }
81
82 // Then look for the necessary keys to construct from the input file
83 else if (hasParamInGroup(modelParamGroup, "Grid.UpperRight"))
84 {
85 preProcessing_(modelParamGroup);
86 // make the grid
87 const auto cellType = getParamFromGroup<std::string>(modelParamGroup, "Grid.CellType", "Cube");
88 if (cellType == "Cube")
89 ParentType::template makeStructuredGrid<dim, dim>(ParentType::CellType::Cube, modelParamGroup);
90 else if (cellType == "Simplex")
91 ParentType::template makeStructuredGrid<dim, dim>(ParentType::CellType::Simplex, modelParamGroup);
92 else
93 DUNE_THROW(Dune::IOError, "UGGrid only supports 'Cube' or 'Simplex' as cell type. Not '"<< cellType<<"'!");
94 postProcessing_(modelParamGroup);
95 }
96
97 // Didn't find a way to construct the grid
98 else
99 {
100 const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup + ".";
101 DUNE_THROW(ParameterException, "Please supply one of the parameters "
102 << prefix + "Grid.UpperRight"
103 << ", or a grid file in " << prefix + "Grid.File");
104
105 }
106 }
107
115 void loadBalance()
116 {
117 if (Dune::MPIHelper::getCollectiveCommunication().size() > 1)
118 {
119 // if we may have dgf parameters use load balancing of the dgf pointer
120 if(ParentType::enableDgfGridPointer_)
121 {
122 ParentType::dgfGridPtr().loadBalance();
123 // update the grid data
124 ParentType::gridData_ = std::make_shared<typename ParentType::GridData>(ParentType::dgfGridPtr());
125 }
126
127 // if we have gmsh parameters we have to manually load balance the data
128 else if (ParentType::enableGmshDomainMarkers_)
129 {
130 // element and face markers are communicated during load balance
131 auto dh = ParentType::gridData_->createGmshDataHandle();
132 ParentType::gridPtr()->loadBalance(dh.interface());
133 // Right now, UGGrid cannot communicate element data. If this gets implemented, communicate the data here:
134 // ParentType::gridPtr()->communicate(dh.interface(), Dune::InteriorBorder_All_Interface, Dune::ForwardCommunication);
135 }
136 else
137 ParentType::gridPtr()->loadBalance();
138 }
139 }
140
141private:
145 void preProcessing_(const std::string& modelParamGroup)
146 {}
147
151 void postProcessing_(const std::string& modelParamGroup)
152 {
153 // Set refinement type
154 const auto refType = getParamFromGroup<std::string>(modelParamGroup, "Grid.RefinementType", "Local");
155 if (refType == "Local")
156 ParentType::grid().setRefinementType(Dune::UGGrid<dim>::RefinementType::LOCAL);
157 else if (refType == "Copy")
158 ParentType::grid().setRefinementType(Dune::UGGrid<dim>::RefinementType::COPY);
159 else
160 DUNE_THROW(Dune::IOError, "UGGrid only supports 'Local' or 'Copy' as refinment type. Not '"<< refType<<"'!");
161
162 // Set closure type
163 const auto closureType = getParamFromGroup<std::string>(modelParamGroup, "Grid.ClosureType", "Green");
164 if (closureType == "Green")
165 ParentType::grid().setClosureType(Dune::UGGrid<dim>::ClosureType::GREEN);
166 else if (closureType == "None")
167 ParentType::grid().setClosureType(Dune::UGGrid<dim>::ClosureType::NONE);
168 else
169 DUNE_THROW(Dune::IOError, "UGGrid only supports 'Green' or 'None' as closure type. Not '"<< closureType<<"'!");
170
171 // Check if should refine the grid
172 ParentType::maybeRefineGrid(modelParamGroup);
173 // do load balancing
174 loadBalance();
175 }
176};
177
178#endif // HAVE_UG
179
180} // end namespace Dumux
181
182#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:390
Definition: adapt.hh:29
Definition: common/pdesolver.hh:35
Grid Grid
Definition: gridmanager_base.hh:68
void loadBalance()
Call loadBalance() function of the grid.
Definition: gridmanager_base.hh:96
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:74