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

« back to all changes in this revision

Viewing changes to dune/grid/alugrid/3d/topology.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_ALU3DGRIDTOPOLOGY_HH
 
2
#define DUNE_ALU3DGRIDTOPOLOGY_HH
 
3
 
 
4
//- system includes 
 
5
#include <cassert>
 
6
 
 
7
namespace Dune {
 
8
 
 
9
  // types of the elementes, 
 
10
  // i.e . tetra or hexa, mixed is not implemeneted 
 
11
  enum ALU3dGridElementType { tetra = 4, hexa = 7, mixed, error };
 
12
 
 
13
  template <ALU3dGridElementType type>
 
14
  struct EntityCount {};
 
15
 
 
16
  template <>
 
17
  struct EntityCount<tetra> {
 
18
    enum {numFaces = 4};
 
19
    enum {numVertices = 4};
 
20
    enum {numEdges = 6};
 
21
    enum {numVerticesPerFace = 3};
 
22
    enum {numEdgesPerFace = 3}; 
 
23
  };
 
24
 
 
25
  template <>
 
26
  struct EntityCount<hexa> {
 
27
    enum {numFaces = 6};
 
28
    enum {numVertices = 8};
 
29
    enum {numEdges = 12};
 
30
    enum {numVerticesPerFace = 4};
 
31
    enum {numEdgesPerFace = 4};
 
32
  };
 
33
  
 
34
 
 
35
  //! Maps indices of the Dune reference element onto the indices of the
 
36
  //! ALU3dGrid reference element and vice-versa.
 
37
  template <ALU3dGridElementType type>
 
38
  class ElementTopologyMapping 
 
39
  {
 
40
  public:
 
41
    enum { numFaces = EntityCount<type>::numFaces };
 
42
    enum { numVertices = EntityCount<type>::numVertices };
 
43
    enum { numEdges = EntityCount<type>::numEdges };
 
44
    enum { numVerticesPerFace = EntityCount<type>::numVerticesPerFace };
 
45
   
 
46
    //! Maps face index from Dune onto ALU3dGrid reference element
 
47
    static int dune2aluFace(int index);
 
48
    //! Maps face index from ALU3dGrid onto Dune reference element
 
49
    static int alu2duneFace(int index);
 
50
 
 
51
    //! Maps edge index from Dune onto ALU3dGrid reference element
 
52
    static int dune2aluEdge(int index);
 
53
    //! Maps edge index from ALU3dGrid onto Dune reference element
 
54
    static int alu2duneEdge(int index);
 
55
 
 
56
    //! Maps vertex index from Dune onto ALU3dGrid reference element
 
57
    static int dune2aluVertex(int index);
 
58
    //! Maps vertex index from ALU3dGrid onto Dune reference element
 
59
    static int alu2duneVertex(int index);
 
60
 
 
61
    static int generic2aluFace ( const int index );
 
62
    static int alu2genericFace ( const int index );
 
63
 
 
64
    static int generic2aluVertex ( const int index );
 
65
    static int alu2genericVertex ( const int index );
 
66
 
 
67
    //! Return 1 if faces in ALU3dGrid and Dune reference element
 
68
    //! have the same orientation (edge 0->1 is taken as reference as
 
69
    //! they are the same in both reference elements), -1 otherwise.
 
70
    //! The index is a Dune face index 
 
71
    static int faceOrientation(int index);
 
72
 
 
73
    //! Maps local vertex index of a face onto a global vertex index 
 
74
    //! (Dune->ALU3dGrid)
 
75
    //! \param face Face index (Dune reference element)
 
76
    //! \param localVertex Local vertex index on face <i>face</i> (Dune reference 
 
77
    //! element)
 
78
    //! \return global vertex index in ALU3dGrid reference element
 
79
    static int dune2aluFaceVertex(int face, int localVertex);
 
80
    //! Maps local vertex index of a face onto a global vertex index 
 
81
    //! (ALU3dGrid->Dune)
 
82
    //! \param face Face index (ALU3dGrid reference element)
 
83
    //! \param localVertex Local vertex index on face <i>face</i>
 
84
    //! (ALU3dGrid reference element)
 
85
    //! \return global vertex index in Dune reference element
 
86
    static int alu2duneFaceVertex(int face, int localVertex);
 
87
 
 
88
    /** \brief Maps a local vertex on a face onto a global vertex
 
89
     *
 
90
     *  \param[in]  face   index of the face (with respect to ALU reference
 
91
     *                     element)
 
92
     *  \param[in]  local  local index of vertex on the face
 
93
     *  \returns global index of vertex in ALU reference element
 
94
     */
 
95
    static int faceVertex ( int face, int local );
 
96
 
 
97
  private:
 
98
    const static int dune2aluFace_[numFaces];
 
99
    const static int alu2duneFace_[numFaces];
 
100
 
 
101
    const static int dune2aluEdge_[numEdges];
 
102
    const static int alu2duneEdge_[numEdges];
 
103
 
 
104
    const static int dune2aluVertex_[numVertices];
 
105
    const static int alu2duneVertex_[numVertices];
 
106
 
 
107
    static const int generic2aluFace_[ numFaces ];
 
108
    static const int alu2genericFace_[ numFaces ];
 
109
 
 
110
    static const int generic2aluVertex_[ numVertices ];
 
111
    static const int alu2genericVertex_[ numVertices ];
 
112
 
 
113
    const static int faceOrientation_[numFaces];
 
114
 
 
115
    const static int dune2aluFaceVertex_[numFaces][numVerticesPerFace];
 
116
    const static int alu2duneFaceVertex_[numFaces][numVerticesPerFace];
 
117
 
 
118
    static const int faceVertex_[ numFaces ][ numVerticesPerFace ];
 
119
  };
 
120
 
 
121
  //! Maps indices of the Dune reference face onto the indices of the
 
122
  //! ALU3dGrid reference face and vice-versa.
 
123
  template <ALU3dGridElementType type>
 
124
  class FaceTopologyMapping {
 
125
  public:
 
126
    //! Maps vertex index from Dune onto ALU3dGrid reference face
 
127
    static int dune2aluVertex(int index);
 
128
    //! Maps vertex index from Dune onto ALU3dGrid reference face, where the
 
129
    //! face in the ALU3dGrid has the twist <i>twist</i> compared to the orientation
 
130
    //! of the respective face in the reference element
 
131
    //! \param index local Dune vertex index on the particular face (i.e. the 
 
132
    //! face which has a twist <i>twist</i> compared to the reference element's face 
 
133
    //! \param twist twist of the face in consideration
 
134
    //! \return local ALU3dGrid vertex index on reference element face
 
135
    static int dune2aluVertex(int index, int twist);
 
136
    //! Maps vertex index from ALU3dGrid onto Dune reference face
 
137
    static int alu2duneVertex(int index);
 
138
    //! Maps vertex index from ALU3dGrid onto Dune reference face, where the
 
139
    //! face in the ALU3dGrid has the twist <i>twist</i> compared to the orientation
 
140
    //! of the respective face in the reference element
 
141
    //! \param index local ALU3dGrid vertex index on the particular face (i.e.
 
142
    //! the face which has a twist <i>twist</i> compared to the reference element's
 
143
    //! face 
 
144
    //! \param twist twist of the face in consideration
 
145
    //! \return local Dune vertex index on reference element face
 
146
    static int alu2duneVertex(int index, int twist);
 
147
    //! Maps edge index from Dune onto ALU3dGrid reference face
 
148
    static int dune2aluEdge(int index);
 
149
    //! Maps edge index from ALU3dGrid onto Dune reference face
 
150
    static int alu2duneEdge(int index);
 
151
    //  private:
 
152
    static int twist(int index, int faceTwist);
 
153
    static int invTwist(int index, int faceTwist);
 
154
  
 
155
    static int twistedDuneIndex( const int idx, const int twist );
 
156
 
 
157
    // for each aluTwist apply additional mapping 
 
158
    static int aluTwistMap(const int aluTwist);
 
159
  private:
 
160
    const static int dune2aluVertex_[EntityCount<type>::numVerticesPerFace];
 
161
    const static int alu2duneVertex_[EntityCount<type>::numVerticesPerFace];
 
162
 
 
163
    const static int dune2aluEdge_[EntityCount<type>::numEdgesPerFace];
 
164
    const static int alu2duneEdge_[EntityCount<type>::numEdgesPerFace];
 
165
 
 
166
    const static int alu2duneTwist_[ 2 * EntityCount<type>::numVerticesPerFace ];
 
167
    const static int aluTwistMap_[ 2 * EntityCount<type>::numVerticesPerFace ];
 
168
  };
 
169
 
 
170
  //- IMPLEMENTATION
 
171
  //- class ElementTopologyMapping
 
172
  template <ALU3dGridElementType type>
 
173
  inline int ElementTopologyMapping<type>::dune2aluFace(int index) {
 
174
    assert(index >= 0 && index < numFaces);
 
175
    return dune2aluFace_[index];
 
176
  }
 
177
  
 
178
  template <ALU3dGridElementType type>
 
179
  inline int ElementTopologyMapping<type>::alu2duneFace(int index) {
 
180
    assert(index >= 0 && index < numFaces);
 
181
    return alu2duneFace_[index];
 
182
  }
 
183
 
 
184
  template <ALU3dGridElementType type>
 
185
  inline int ElementTopologyMapping<type>::dune2aluEdge(int index) {
 
186
    assert(index >= 0 && index < numEdges);
 
187
    return dune2aluEdge_[index];
 
188
  }
 
189
  
 
190
  template <ALU3dGridElementType type>
 
191
  inline int ElementTopologyMapping<type>::alu2duneEdge(int index) {
 
192
    assert(index >= 0 && index < numEdges);
 
193
    return alu2duneEdge_[index];
 
194
  }
 
195
 
 
196
  template <ALU3dGridElementType type>
 
197
  inline int ElementTopologyMapping<type>::dune2aluVertex(int index) 
 
198
  {
 
199
    assert(index >= 0 && index < numVertices);
 
200
    return dune2aluVertex_[index];
 
201
  }
 
202
 
 
203
  template <ALU3dGridElementType type>
 
204
  inline int ElementTopologyMapping<type>::alu2duneVertex(int index) {
 
205
    assert(index >= 0 && index < numVertices);
 
206
    return alu2duneVertex_[index];
 
207
  }
 
208
 
 
209
  template< ALU3dGridElementType type >
 
210
  inline int ElementTopologyMapping< type >::generic2aluFace ( const int index )
 
211
  {
 
212
    assert( (index >= 0) && (index < numFaces) );
 
213
    return generic2aluFace_[ index ];
 
214
  }
 
215
 
 
216
  template< ALU3dGridElementType type >
 
217
  inline int ElementTopologyMapping< type >::alu2genericFace ( const int index )
 
218
  {
 
219
    assert( (index >= 0) && (index < numFaces) );
 
220
    return alu2genericFace_[ index ];
 
221
  }
 
222
 
 
223
  template< ALU3dGridElementType type >
 
224
  inline int ElementTopologyMapping< type >::generic2aluVertex ( const int index )
 
225
  {
 
226
    assert( (index >= 0) && (index < numVertices) );
 
227
    return generic2aluVertex_[ index ];
 
228
  }
 
229
 
 
230
  template< ALU3dGridElementType type >
 
231
  inline int ElementTopologyMapping< type >::alu2genericVertex ( const int index )
 
232
  {
 
233
    assert( (index >= 0) && (index < numVertices) );
 
234
    return alu2genericVertex_[ index ];
 
235
  }
 
236
 
 
237
  template <ALU3dGridElementType type>
 
238
  inline int ElementTopologyMapping<type>::faceOrientation(int index) {
 
239
    assert(index >= 0 && index < numVertices);
 
240
    return faceOrientation_[index];
 
241
  }
 
242
 
 
243
  template <ALU3dGridElementType type>
 
244
  inline int ElementTopologyMapping<type>::
 
245
  dune2aluFaceVertex(int face, int localVertex) {
 
246
    assert(face >= 0 && face < numFaces);
 
247
    assert(localVertex >= 0 && localVertex < numVerticesPerFace);
 
248
    return dune2aluFaceVertex_[face][localVertex];
 
249
  }
 
250
 
 
251
  template <ALU3dGridElementType type>
 
252
  inline int ElementTopologyMapping<type>::
 
253
  alu2duneFaceVertex(int face, int localVertex) {
 
254
    assert(face >= 0 && face < numFaces);
 
255
    assert(localVertex >= 0 && localVertex < numVerticesPerFace);
 
256
    return alu2duneFaceVertex_[face][localVertex];
 
257
  }
 
258
 
 
259
  template< ALU3dGridElementType type >
 
260
  inline int ElementTopologyMapping< type >::faceVertex ( int face, int local )
 
261
  {
 
262
    assert( (face >= 0) && (face < numFaces) );
 
263
    assert( (local >= 0) && (local < numVerticesPerFace) );
 
264
    return faceVertex_[ face ][ local ];
 
265
  }
 
266
 
 
267
  //- class FaceTopologyMapping
 
268
  template <ALU3dGridElementType type>
 
269
  inline int FaceTopologyMapping<type>::dune2aluVertex(int index) {
 
270
    assert(index >= 0 && index < EntityCount<type>::numVerticesPerFace);
 
271
    return dune2aluVertex_[index];
 
272
  }
 
273
 
 
274
  template <ALU3dGridElementType type>
 
275
  inline int FaceTopologyMapping<type>::dune2aluVertex(int index, int twist) {
 
276
    assert(index >= 0 && index < EntityCount<type>::numVerticesPerFace);
 
277
    return invTwist(dune2aluVertex_[index], twist);
 
278
  }
 
279
 
 
280
  template <ALU3dGridElementType type>
 
281
  inline int FaceTopologyMapping<type>::alu2duneVertex(int index) {
 
282
    assert(index >= 0 && index < EntityCount<type>::numVerticesPerFace);
 
283
    return alu2duneVertex_[index];
 
284
  }
 
285
 
 
286
  template <ALU3dGridElementType type>
 
287
  inline int FaceTopologyMapping<type>::alu2duneVertex(int index, int twist) 
 
288
  {
 
289
    assert(index >= 0 && index < EntityCount<type>::numVerticesPerFace);
 
290
    return alu2duneVertex_[invTwist(index, twist)];
 
291
  }
 
292
 
 
293
  template <ALU3dGridElementType type>
 
294
  inline int FaceTopologyMapping<type>::alu2duneEdge(int index) {
 
295
    assert(index >= 0 && index < EntityCount<type>::numEdgesPerFace);
 
296
    return alu2duneEdge_[index];
 
297
  }
 
298
 
 
299
  template <ALU3dGridElementType type>
 
300
  inline int FaceTopologyMapping<type>::
 
301
  aluTwistMap(const int aluTwist) 
 
302
  {
 
303
    // this map has been calculated by grid/test/checktwists.cc 
 
304
    // and the dune-fem twist calculator 
 
305
    // this should be revised after the release 2.1
 
306
    return aluTwistMap_[ aluTwist + ((type == tetra) ? 3 : 4) ];  
 
307
  }
 
308
 
 
309
  template <ALU3dGridElementType type>
 
310
  inline int FaceTopologyMapping<type>::
 
311
  twistedDuneIndex(const int duneIdx, const int aluTwist) 
 
312
  {
 
313
    if( type == tetra ) 
 
314
    {
 
315
      // apply alu2dune twist mapping (only for tetra)
 
316
      const int twist = alu2duneTwist_[ aluTwist + 3 ];
 
317
      return alu2duneVertex( dune2aluVertex(duneIdx) , twist );
 
318
    }
 
319
    else 
 
320
     return alu2duneVertex( dune2aluVertex(duneIdx) , aluTwist );
 
321
  }
 
322
 
 
323
  template <ALU3dGridElementType type>
 
324
  inline int FaceTopologyMapping<type>::dune2aluEdge(int index) {
 
325
    assert(index >= 0 && index < EntityCount<type>::numEdgesPerFace);
 
326
    return dune2aluEdge_[index];
 
327
  }
 
328
 
 
329
} // end namespace Dune
 
330
#endif