1
#ifndef DUNE_HYBRID_TESTGRIDS_HH
2
#define DUNE_HYBRID_TESTGRIDS_HH
6
\brief Provides C++ code that creates hybrid grids suitable for unit tests,
10
#include <dune/common/static_assert.hh>
11
#include <dune/grid/common/gridfactory.hh>
15
template <class GridType>
16
GridType* make2DHybridTestGrid()
18
dune_static_assert(GridType::dimension==2,
19
"Instantiate make2dHybridTestGrid only for 2d grids!");
21
// Start grid creation
22
GridFactory<GridType> factory;
24
// The list of grid vertex positions
27
double vertices[16][2] = {{0, 0},
44
// Create the grid vertices
45
for (int i=0; i<numVertices; i++) {
46
Dune::FieldVector<double,2> pos;
47
pos[0] = vertices[i][0];
48
pos[1] = vertices[i][1];
49
factory.insertVertex(pos);
52
// Create the triangle elements
54
unsigned int triangles[2][3] = {{9, 10, 11},
57
for (int i=0; i<numTriangles; i++) {
58
std::vector<unsigned int> cornerIDs(3);
59
for (int j=0; j<3; j++)
60
cornerIDs[j] = triangles[i][j];
61
factory.insertElement(Dune::GeometryType(Dune::GeometryType::simplex,2),cornerIDs);
64
// Create the quadrilateral elements
65
int numQuadrilaterals = 9;
66
unsigned int quadrilaterals[9][4] = {{0, 4, 7, 8},
76
for (int i=0; i<numQuadrilaterals; i++) {
77
std::vector<unsigned int> cornerIDs(4);
78
for (int j=0; j<4; j++)
79
cornerIDs[j] = quadrilaterals[i][j];
80
factory.insertElement(Dune::GeometryType(Dune::GeometryType::cube,2),cornerIDs);
83
// Finish initialization
84
return factory.createGrid();
88
template <class GridType>
89
GridType* make3DHybridTestGrid()
91
dune_static_assert(GridType::dimension==3,
92
"Instantiate make3DHybridTestGrid only for 3d grids!");
94
// Start grid creation
95
GridFactory<GridType> factory;
97
// The list of grid vertex positions
100
double vertices[61][3] = {{0, 0, 0},
162
// Create the grid vertices
163
for (int i=0; i<numVertices; i++) {
164
Dune::FieldVector<double,3> pos;
165
for (int j=0; j<3; j++)
166
pos[j] = vertices[i][j];
167
factory.insertVertex(pos);
172
// Create the tetrahedron elements
173
int numTetrahedra = 54;
174
unsigned int tetrahedra[54][4] = {{10, 29, 3, 32},
229
for (int i=0; i<numTetrahedra; i++) {
230
std::vector<unsigned int> cornerIDs(4);
231
for (int j=0; j<4; j++)
232
cornerIDs[j] = tetrahedra[i][j]-1;
233
factory.insertElement(Dune::GeometryType(Dune::GeometryType::simplex,3),cornerIDs);
236
// Create the pyramid elements
237
int numPyramids = 27;
238
unsigned int pyramids[27][5] = {{28, 30, 29, 31, 32},
244
{29, 31, 33, 35, 37},
245
{33, 35, 34, 36, 37},
251
{34, 36, 38, 39, 40},
256
{41, 44, 42, 43, 45},
258
{30, 46, 31, 47, 48},
260
{42, 43, 46, 47, 48},
262
{36, 50, 39, 51, 52},
264
{44, 51, 43, 50, 52}};
266
for (int i=0; i<numPyramids; i++) {
267
std::vector<unsigned int> cornerIDs(5);
268
for (int j=0; j<5; j++)
269
cornerIDs[j] = pyramids[i][j]-1;
270
factory.insertElement(Dune::GeometryType(Dune::GeometryType::pyramid,3),cornerIDs);
273
// Create the prism elements
275
unsigned int prisms[8][6] = {{28, 53, 29, 30, 56, 31},
276
{53, 54, 29, 56, 57, 31},
277
{30, 56, 31, 46, 59, 47},
278
{56, 57, 31, 59, 60, 47},
279
{29, 54, 33, 31, 57, 35},
280
{54, 55, 33, 57, 58, 35},
281
{31, 57, 35, 47, 60, 49},
282
{57, 58, 35, 60, 61, 49}};
285
for (int i=0; i<numPrisms; i++) {
286
std::vector<unsigned int> cornerIDs(6);
287
for (int j=0; j<6; j++)
288
cornerIDs[j] = prisms[i][j]-1;
289
factory.insertElement(Dune::GeometryType(Dune::GeometryType::prism,3),cornerIDs);
292
// Create the hexahedron elements
293
int numHexahedra = 9;
294
unsigned int hexahedra[9][8] = {{1, 9, 12, 21, 13, 22, 25, 27},
295
{9, 2, 21, 10, 22, 14, 27, 23},
296
{21, 10, 11, 3, 27, 23, 24, 15},
297
{12, 21, 4, 11, 25, 27, 16, 24},
298
{13, 22, 25, 27, 5, 17, 20, 26},
299
{22, 14, 27, 23, 17, 6, 26, 18},
300
{27, 23, 24, 15, 26, 18, 19, 7},
301
{25, 27, 16, 24, 20, 26, 8, 19},
302
{7, 31, 36, 35, 43, 47, 50, 49}};
305
for (int i=0; i<numHexahedra; i++) {
306
std::vector<unsigned int> cornerIDs(8);
307
for (int j=0; j<8; j++)
308
cornerIDs[j] = hexahedra[i][j]-1;
309
factory.insertElement(Dune::GeometryType(Dune::GeometryType::cube,3),cornerIDs);
312
// Finish initialization
313
return factory.createGrid();