24#ifndef DUMUX_TEST_IO_GRIDMANAGER_TESTS_HH
25#define DUMUX_TEST_IO_GRIDMANAGER_TESTS_HH
27#include <dune/common/version.hh>
28#include <dune/geometry/referenceelements.hh>
29#include <dune/grid/common/datahandleif.hh>
30#include <dune/grid/common/mcmgmapper.hh>
31#include <dune/grid/io/file/vtk.hh>
42template <
class Gr
idView>
44 :
public Dune::CommDataHandleIF< VertexHandleNonZeroMin<GridView>, int >
46 using Container = std::vector<int>;
51 , container_(container)
67 template<
class EntityType>
68 size_t size (
const EntityType &e)
const
74 template<
class MessageBufferImp,
class EntityType>
75 void gather(MessageBufferImp &buff,
const EntityType &e)
const
77 int vIdx = gridView_.indexSet().index(e);
78 buff.write(container_[vIdx]);
81 template<
class MessageBufferImp,
class EntityType>
82 void scatter(MessageBufferImp &buff,
const EntityType &e,
size_t n)
84 int vIdx = gridView_.indexSet().index(e);
90 if (container_[vIdx] == 0)
91 container_[vIdx] = tmp;
93 container_[vIdx] = min(container_[vIdx], tmp);
98 const GridView gridView_;
99 Container &container_;
105 using GridView =
typename Grid::LeafGridView;
106 using Scalar = double;
107 static const int dim = Grid::dimension;
109 using ReferenceElements =
typename Dune::ReferenceElements<Scalar, dim>;
114 const std::string& vtkFileName =
"test",
118 GridManager gridManager;
120 auto gridData = gridManager.getGridData();
121 const auto& leafGridView = gridManager.grid().leafGridView();
124 std::vector<int> boundaryMarker, elementMarker, rank;
125 getBoundaryMarkers_(leafGridView, gridData, boundaryMarker);
126 getElementMarkers_(leafGridView, gridData, elementMarker, type);
127 getRank_(leafGridView, rank);
130 Dune::VTKSequenceWriter<typename Grid::LeafGridView> vtkWriter(leafGridView, vtkFileName,
".",
"");
131 vtkWriter.addVertexData(boundaryMarker,
"boundaryMarker");
132 vtkWriter.addCellData(elementMarker,
"elementMarker");
133 vtkWriter.addCellData(rank,
"rank");
139 gridManager.grid().globalRefine(1);
140 getBoundaryMarkers_(leafGridView, gridData, boundaryMarker);
141 getElementMarkers_(leafGridView, gridData, elementMarker, type);
142 getRank_(leafGridView, rank);
148 const std::string& vtkFileName =
"test",
152 GridManager gridManager;
154 auto gridData = gridManager.getGridData();
157 std::vector<int> elementMarker, rank;
158 getElementMarkers_(gridManager.grid().leafGridView(), gridData, elementMarker, type);
159 getRank_(gridManager.grid().leafGridView(), rank);
162 Dune::VTKSequenceWriter<typename Grid::LeafGridView> vtkWriter(gridManager.grid().leafGridView(), vtkFileName,
".",
"");
163 vtkWriter.addCellData(elementMarker,
"elementMarker");
164 vtkWriter.addCellData(rank,
"rank");
170 gridManager.grid().globalRefine(1);
171 getElementMarkers_(gridManager.grid().leafGridView(), gridData, elementMarker, type);
172 getRank_(gridManager.grid().leafGridView(), rank);
178 const std::string& vtkFileName =
"test")
181 GridManager gridManager;
183 auto gridData = gridManager.getGridData();
186 std::vector<int> vertexMarker;
187 getVertexMarkers_(gridManager.grid().levelGridView(0), gridData, vertexMarker, type);
190 Dune::VTKSequenceWriter<typename Grid::LevelGridView> vtkWriter(gridManager.grid().levelGridView(0), vtkFileName,
".",
"");
191 vtkWriter.addVertexData(vertexMarker,
"vertexData");
197 static void getRank_(
const GridView& gridView, std::vector<int>& rank)
200 rank.resize(gridView.size(0));
202 for(
const auto& element : elements(gridView))
204 auto eIdx = gridView.indexSet().index(element);
205 rank[eIdx] = gridView.comm().rank();
209 template<
class Gr
idData>
210 static void getElementMarkers_(
const GridView& gridView,
211 const GridData& gridData,
212 std::vector<int>& elementMarker,
213 const std::string& type)
215 elementMarker.clear();
216 elementMarker.resize(gridView.size(0));
218 for(
const auto& element : elements(gridView))
220 const auto eIdx = gridView.indexSet().index(element);
222 elementMarker[eIdx] = gridData->getElementDomainMarker(element);
223 else if (type ==
"dgf")
224 elementMarker[eIdx] = gridData->parameters(element)[0];
226 DUNE_THROW(Dune::InvalidStateException,
"No parameters for type " << type);
230 template<
class LevelGr
idView,
class Gr
idData>
231 static void getVertexMarkers_(
const LevelGridView& gridView,
232 const GridData& gridData,
233 std::vector<int>& vertexMarker,
234 const std::string& type)
237 DUNE_THROW(Dune::InvalidStateException,
"Vertex marker only exist for dgf grids.");
239 vertexMarker.clear();
240 vertexMarker.resize(gridView.size(Grid::dimension));
242 for (
const auto& vertex : vertices(gridView.grid().levelGridView(0)))
244 const auto vIdx = gridView.indexSet().index(vertex);
245 vertexMarker[vIdx] = gridData->parameters(vertex)[0];
249 template<
class Gr
idData>
250 static void getBoundaryMarkers_(
const GridView& gridView,
251 const GridData& gridData,
252 std::vector<int>& boundaryMarker)
254 boundaryMarker.clear();
255 boundaryMarker.resize(gridView.size(dim), 0);
257 for(
const auto& element : elements(gridView))
259 for(
const auto& intersection :
intersections(gridView, element))
261 if (!intersection.boundary())
264 const auto refElement = ReferenceElements::general(element.geometry().type());
265 const auto numVertices = refElement.size(intersection.indexInInside(), 1, dim);
267 for(std::size_t vIdx = 0; vIdx < numVertices; vIdx++)
270 auto vIdxLocal = refElement.subEntity(intersection.indexInInside(), 1, vIdx, dim);
271 auto vIdxGlobal = gridView.indexSet().subIndex(element, vIdxLocal, dim);
274 if (boundaryMarker[vIdxGlobal] == 0)
275 boundaryMarker[vIdxGlobal] = gridData->getBoundaryDomainMarker(intersection);
278 if (boundaryMarker[vIdxGlobal] > gridData->getBoundaryDomainMarker(intersection))
279 boundaryMarker[vIdxGlobal] = gridData->getBoundaryDomainMarker(intersection);
289 if (gridView.comm().size() > 1)
291 VertexHandleNonZeroMin<GridView> dataHandle(boundaryMarker, gridView);
292 gridView.communicate(dataHandle,
293 Dune::InteriorBorder_All_Interface,
294 Dune::ForwardCommunication);
The available discretization methods in Dumux.
Dune::IteratorRange< typename MultiDomainGlue< DomainGridView, TargetGridView, DomainMapper, TargetMapper >::Intersections::const_iterator > intersections(const MultiDomainGlue< DomainGridView, TargetGridView, DomainMapper, TargetMapper > &glue)
Range generator to iterate with range-based for loops over all intersections as follows: for (const a...
Definition: glue.hh:62
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
The grid manager (this is the class used by the user) for all supported grid managers that constructs...
Definition: gridmanager_base.hh:312
data handle for parallel communication which takes the minimum non-zero values that are attached to v...
Definition: gridmanagertests.hh:45
bool fixedsize(int dim, int codim) const
Definition: gridmanagertests.hh:60
void gather(MessageBufferImp &buff, const EntityType &e) const
Definition: gridmanagertests.hh:75
size_t size(const EntityType &e) const
Definition: gridmanagertests.hh:68
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
Definition: gridmanagertests.hh:82
VertexHandleNonZeroMin(Container &container, const GridView &gridView)
Definition: gridmanagertests.hh:49
bool contains(int dim, int codim) const
Definition: gridmanagertests.hh:54
Definition: gridmanagertests.hh:104
static void testElementMarkers(const std::string &type="gmsh", const std::string &vtkFileName="test", bool refine=true)
Definition: gridmanagertests.hh:147
static void testBoundaryAndElementMarkers(const std::string &type="gmsh", const std::string &vtkFileName="test", bool refine=true)
Definition: gridmanagertests.hh:113
static void testVertexMarkers(const std::string &type="dgf", const std::string &vtkFileName="test")
Definition: gridmanagertests.hh:177
Convience header that includes all grid manager specializations.