~ubuntu-branches/ubuntu/trusty/dune-grid/trusty

« back to all changes in this revision

Viewing changes to doc/grids/gridfactory/hybridtestgrids.hh

  • Committer: Package Import Robot
  • Author(s): Ansgar Burchardt
  • Date: 2012-04-06 11:31:20 UTC
  • Revision ID: package-import@ubuntu.com-20120406113120-x0z4e0qqgfhmaj2a
Tags: upstream-2.2~svn7982
ImportĀ upstreamĀ versionĀ 2.2~svn7982

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef DUNE_HYBRID_TESTGRIDS_HH
 
2
#define DUNE_HYBRID_TESTGRIDS_HH
 
3
 
 
4
/** \file
 
5
    \author Oliver Sander
 
6
    \brief Provides C++ code that creates hybrid grids suitable for unit tests,
 
7
        using the GridFactory.
 
8
*/
 
9
 
 
10
#include <dune/common/static_assert.hh>
 
11
#include <dune/grid/common/gridfactory.hh>
 
12
 
 
13
namespace Dune {
 
14
 
 
15
    template <class GridType>
 
16
    GridType* make2DHybridTestGrid()
 
17
    {
 
18
        dune_static_assert(GridType::dimension==2,
 
19
                           "Instantiate make2dHybridTestGrid only for 2d grids!");
 
20
 
 
21
        // Start grid creation
 
22
        GridFactory<GridType> factory;
 
23
        
 
24
        // The list of grid vertex positions
 
25
        int numVertices = 16;
 
26
        
 
27
        double vertices[16][2] = {{0, 0},
 
28
                                  {0.5, 0},
 
29
                                  {0.5, 0.5},
 
30
                                  {0, 0.5},
 
31
                                  {0.25, 0},
 
32
                                  {0.5, 0.25},
 
33
                                  {0.25, 0.5},
 
34
                                  {0, 0.25},
 
35
                                  {0.25, 0.25},
 
36
                                  {1, 0},
 
37
                                  {1, 0.5},
 
38
                                  {0.75, 0.25},
 
39
                                  {1, 1},
 
40
                                  {0.5, 1},
 
41
                                  {0, 1},
 
42
                                  {0.25, 0.75}};
 
43
        
 
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);
 
50
        }
 
51
        
 
52
        // Create the triangle elements
 
53
        int numTriangles = 2;
 
54
        unsigned int triangles[2][3] = {{9, 10, 11},
 
55
                                        {15, 13, 14}};
 
56
        
 
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);
 
62
        }
 
63
        
 
64
        // Create the quadrilateral elements
 
65
        int numQuadrilaterals = 9;
 
66
        unsigned int quadrilaterals[9][4] = {{0, 4, 7, 8},
 
67
                                             {4, 1, 8, 5},
 
68
                                             {8, 5, 6, 2},
 
69
                                             {7, 8, 3, 6},
 
70
                                             {1, 9, 5, 11},
 
71
                                             {5, 11, 2, 10},
 
72
                                             {2, 10, 13, 12},
 
73
                                             {3, 6, 14, 15},
 
74
                                             {6, 2, 15, 13}};
 
75
        
 
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);
 
81
        }
 
82
        
 
83
        // Finish initialization
 
84
        return factory.createGrid();
 
85
    }
 
86
    
 
87
    
 
88
    template <class GridType>
 
89
    GridType* make3DHybridTestGrid()
 
90
    {
 
91
        dune_static_assert(GridType::dimension==3,
 
92
                           "Instantiate make3DHybridTestGrid only for 3d grids!");
 
93
 
 
94
        // Start grid creation
 
95
        GridFactory<GridType> factory;
 
96
        
 
97
        // The list of grid vertex positions
 
98
        int numVertices = 61;
 
99
        
 
100
        double vertices[61][3] = {{0, 0, 0},
 
101
                                  {0.5, 0, 0},
 
102
                                  {0.5, 0.5, 0},
 
103
                                  {0, 0.5, 0},
 
104
                                  {0, 0, 0.5},
 
105
                                  {0.5, 0, 0.5},
 
106
                                  {0.5, 0.5, 0.5},
 
107
                                  {0, 0.5, 0.5},
 
108
                                  {0.25, 0, 0},
 
109
                                  {0.5, 0.25, 0},
 
110
                                  {0.25, 0.5, 0},
 
111
                                  {0, 0.25, 0},
 
112
                                  {0, 0, 0.25},
 
113
                                  {0.5, 0, 0.25},
 
114
                                  {0.5, 0.5, 0.25},
 
115
                                  {0, 0.5, 0.25},
 
116
                                  {0.25, 0, 0.5},
 
117
                                  {0.5, 0.25, 0.5},
 
118
                                  {0.25, 0.5, 0.5},
 
119
                                  {0, 0.25, 0.5},
 
120
                                  {0.25, 0.25, 0},
 
121
                                  {0.25, 0, 0.25},
 
122
                                  {0.5, 0.25, 0.25},
 
123
                                  {0.25, 0.5, 0.25},
 
124
                                  {0, 0.25, 0.25},
 
125
                                  {0.25, 0.25, 0.5},
 
126
                                  {0.25, 0.25, 0.25},
 
127
                                  {1, 0, 0},
 
128
                                  {1, 0.5, 0},
 
129
                                  {1, 0, 0.5},
 
130
                                  {1, 0.5, 0.5},
 
131
                                  {0.75, 0.25, 0.25},
 
132
                                  {1, 1, 0},
 
133
                                  {0.5, 1, 0},
 
134
                                  {1, 1, 0.5},
 
135
                                  {0.5, 1, 0.5},
 
136
                                  {0.75, 0.75, 0.25},
 
137
                                  {0, 1, 0},
 
138
                                  {0, 1, 0.5},
 
139
                                  {0.25, 0.75, 0.25},
 
140
                                  {0, 0, 1},
 
141
                                  {0.5, 0, 1},
 
142
                                  {0.5, 0.5, 1},
 
143
                                  {0, 0.5, 1},
 
144
                                  {0.25, 0.25, 0.75},
 
145
                                  {1, 0, 1},
 
146
                                  {1, 0.5, 1},
 
147
                                  {0.75, 0.25, 0.75},
 
148
                                  {1, 1, 1},
 
149
                                  {0.5, 1, 1},
 
150
                                  {0, 1, 1},
 
151
                                  {0.25, 0.75, 0.75},
 
152
                                  {1.5, 0, 0},
 
153
                                  {1.5, 0.5, 0},
 
154
                                  {1.5, 1, 0},
 
155
                                  {1.5, 0, 0.5},
 
156
                                  {1.5, 0.5, 0.5},
 
157
                                  {1.5, 1, 0.5},
 
158
                                  {1.5, 0, 1},
 
159
                                  {1.5, 0.5, 1},
 
160
                                  {1.5, 1, 1}};
 
161
        
 
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);
 
168
        }
 
169
        
 
170
        
 
171
        
 
172
        // Create the tetrahedron elements
 
173
        int numTetrahedra = 54;
 
174
        unsigned int tetrahedra[54][4] = {{10, 29, 3, 32},
 
175
                                          {10, 2, 28, 32},
 
176
                                          {10, 28, 29, 32},
 
177
                                          {14, 28, 2, 32},
 
178
                                          {14, 6, 30, 32},
 
179
                                          {14, 30, 28, 32},
 
180
                                          {15, 31, 7, 32},
 
181
                                          {15, 3, 29, 32},
 
182
                                          {15, 29, 31, 32},
 
183
                                          {18, 30, 6, 32},
 
184
                                          {18, 7, 31, 32},
 
185
                                          {18, 31, 30, 32},
 
186
                                          {15, 29, 3, 37},
 
187
                                          {15, 7, 31, 37},
 
188
                                          {15, 31, 29, 37},
 
189
                                          {15, 36, 7, 37},
 
190
                                          {15, 3, 34, 37},
 
191
                                          {15, 34, 36, 37},
 
192
                                          {11, 38, 4, 40},
 
193
                                          {11, 3, 34, 40},
 
194
                                          {11, 34, 38, 40},
 
195
                                          {15, 34, 3, 40},
 
196
                                          {15, 7, 36, 40},
 
197
                                          {15, 36, 34, 40},
 
198
                                          {16, 39, 8, 40},
 
199
                                          {16, 4, 38, 40},
 
200
                                          {16, 38, 39, 40},
 
201
                                          {19, 36, 7, 40},
 
202
                                          {19, 8, 39, 40},
 
203
                                          {19, 39, 36, 40},
 
204
                                          {17, 42, 6, 45},
 
205
                                          {17, 5, 41, 45},
 
206
                                          {17, 41, 42, 45},
 
207
                                          {18, 43, 7, 45},
 
208
                                          {18, 6, 42, 45},
 
209
                                          {18, 42, 43, 45},
 
210
                                          {19, 44, 8, 45},
 
211
                                          {19, 7, 43, 45},
 
212
                                          {19, 43, 44, 45},
 
213
                                          {20, 41, 5, 45},
 
214
                                          {20, 8, 44, 45},
 
215
                                          {20, 44, 41, 45},
 
216
                                          {18, 31, 7, 48},
 
217
                                          {18, 6, 30, 48},
 
218
                                          {18, 30, 31, 48},
 
219
                                          {18, 42, 6, 48},
 
220
                                          {18, 7, 43, 48},
 
221
                                          {18, 43, 42, 48},
 
222
                                          {19, 39, 8, 52},
 
223
                                          {19, 7, 36, 52},
 
224
                                          {19, 36, 39, 52},
 
225
                                          {19, 43, 7, 52},
 
226
                                          {19, 8, 44, 52},
 
227
                                          {19, 44, 43, 52}};
 
228
        
 
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);
 
234
        }
 
235
        
 
236
        // Create the pyramid elements
 
237
        int numPyramids = 27;
 
238
        unsigned int pyramids[27][5] = {{28, 30, 29, 31, 32},
 
239
                                        {10, 23, 2,  14, 32},
 
240
                                        {14, 23, 6,  18, 32},
 
241
                                        {18, 23, 7,  15, 32},
 
242
                                        {15, 23, 3,  10, 32},
 
243
                                        {3,  29, 34, 33, 37},
 
244
                                        {29, 31, 33, 35, 37},
 
245
                                        {33, 35, 34, 36, 37},
 
246
                                        {7,  36, 31, 35, 37},
 
247
                                        {11, 24, 3,  15, 40},
 
248
                                        {15, 24, 7,  19, 40},
 
249
                                        {19, 24, 8,  16, 40},
 
250
                                        {16, 24, 4,  11, 40},
 
251
                                        {34, 36, 38, 39, 40},
 
252
                                        {20, 26, 8,  19, 45},
 
253
                                        {19, 26, 7,  18, 45},
 
254
                                        {18, 26, 6,  17, 45},
 
255
                                        {17, 26, 5,  20, 45},
 
256
                                        {41, 44, 42, 43, 45},
 
257
                                        {6,  42, 30, 46, 48},
 
258
                                        {30, 46, 31, 47, 48},
 
259
                                        {31, 47, 7,  43, 48},
 
260
                                        {42, 43, 46, 47, 48},
 
261
                                        {7,  43, 36, 50, 52},
 
262
                                        {36, 50, 39, 51, 52},
 
263
                                        {39, 51, 8,  44, 52},
 
264
                                        {44, 51, 43, 50, 52}};
 
265
        
 
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);
 
271
        }
 
272
        
 
273
        // Create the prism elements
 
274
        int numPrisms = 8;
 
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}};
 
283
        
 
284
        
 
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);
 
290
        }
 
291
        
 
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}};
 
303
        
 
304
        
 
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);
 
310
        }
 
311
        
 
312
        // Finish initialization
 
313
        return factory.createGrid();
 
314
    }
 
315
    
 
316
}
 
317
 
 
318
#endif