Tetrahedron.h 7.52 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file Tetrahedron.h */

#ifndef AMDIS_TETRAHEDRON_H
#define AMDIS_TETRAHEDRON_H

#include "Element.h"
#include "MemoryManager.h"

namespace AMDiS {

  /** \ingroup Triangulation 
   * \brief
   * A Tetrahedron is a 3-dimensional Element. 
   *
   * A Tetrahedron and its refinements:
   *
   * <img src = "tetrahedron.png">
   */
  class Tetrahedron : public Element
  {
  public:
    MEMORY_MANAGED(Tetrahedron);

    /** \brief
     * calls base class contructor.
     */
    Tetrahedron(Mesh* aMesh) : Element(aMesh) {};

    /** \brief
     * implements Element::clone
     */
    inline Element *clone() { return NEW Tetrahedron(mesh); };

    /** \brief
     * implements Element::getVertexOfEdge
     */
    inline int getVertexOfEdge(int i, int j) const {
      return vertexOfEdge[i][j];
    };

    /** \brief
     * implements Element::getVertexOfPosition
     */
    int getVertexOfPosition(GeoIndex position,
			    int      positionIndex,
			    int      vertexIndex) const;


    virtual int getPositionOfVertex(int side, int vertex) const {
      static int positionOfVertex[4][4] = {{-1,0,1,2},
					   {0,-1,1,2},
					   {0,1,-1,2},
					   {0,1,2,-1}};
      return positionOfVertex[side][vertex];
    };

    /** \brief
     * implements Element::getGeo
     */
    inline int getGeo(GeoIndex i) const {
      switch(i) {
      case VERTEX: case PARTS: case NEIGH:
	return 4;
	break;
      case EDGE:
	return 6;
      case FACE:
	return 4;
      case CENTER:
	return 1;
	break;
      case DIMEN:
	return 3;
	break;
      case BOUNDARY:
	return 14;
	break;
      case PROJECTION:
	return 10;
	break;
      default:
	ERROR_EXIT("invalid geo-index\n");
	return 0;
      }
    };

    /** \brief
     * implements Element::sideOfChild
     */
    //int sideOfChild(int child, 
    //		  int side, bool *isVirtual, 
    //		  unsigned char elementType=0);

    /** \brief
     * implements Element::hasSide
     */
    bool hasSide(Element* sideElem) const;

    /** \brief
     * implements Element::sortFaceIndices
     */
    const FixVec<int,WORLD>& sortFaceIndices(int face, 
					     FixVec<int,WORLD> *vec) const;

    /** \brief
     * implements Element::isLine. Returns false because this element is a 
     * Tetrahedron
     */
    inline bool isLine() const { return false; };

    /** \brief
     * implements Element::isTriangle. Returns false because this element is a 
     * Tetrahedron
     */
    inline bool isTriangle() const { return false; };
 
    /** \brief
     * implements Element::isTetrahedron. Returns true because this element is a 
     * Tetrahedron
     */
    inline bool isTetrahedron() const { return true; };

    // ===== Serializable implementation =====
  
    ::std::string getTypeName() const { return "Tetrahedron"; };

  public:
    /** \brief
     * nChildEdge[el_type][ichild][dir]                                      
     * gives local index of new edge on child[ichild] part of face [2+dir] on
     * the parent  
     */
    static const unsigned char nChildEdge[3][2][2];

    /** \brief
     * nChildFace[el_type][ichild][dir]                                     
     * gives local index of sub-face on child[ichild] part of face [2+dir] on
     * the parent   
     */
    static const unsigned char nChildFace[3][2][2];

    /** \brief
     * childVertex[el_type][child][i] =
     * parent's local vertex index of new vertex i.
     * 4 stands for the newly generated vertex                            
     */
    static const int childVertex[3][2][4];
 
    /** \brief
     * childEdge[el_type][child][i] =
     * parent's local edge index of new edge i
     * new edge 2 is half of old edge 0,
     * new edges 4,5 are really new edges, and value is different:
     * childEdge[][][4,5] = index of same edge in other child
     */
    static const int childEdge[3][2][6];

    /** \brief
     * adjacentChild[position][ichild]                                      
     * gives number of the adjacent child on a neighbour element:             
     *   position = 0  same position of element and neigh at refinement edge, 
     *   position = 1  different ...                                         
     */
    static const unsigned char adjacentChild[2][2];

    /** \brief
     * childOrientation[el_type][child] =
     *   +1 if orientation is not changed during refinement, 
     *   -1 if orientation is changed during refinement
     */
    static const signed char childOrientation[3][2];

    /** \brief
     * edgeOfDOFs[i][j]: gives the local index of edge with vertices i and j 
     */
    static const unsigned char edgeOfDOFs[4][4];

    static const int edgeOfFace[4][3];

    /** \brief
     * implements Element::getSideOfChild()
     */
    virtual int getSideOfChild(int child, int side, int elType = 0) const {
      FUNCNAME("Tetrahedron::getSideOfChild()");
      TEST_EXIT(child==0 || child==1)("child must be in (0,1)\n");
      TEST_EXIT(side >= 0 && side <= 3)("side must be between 0 and 3\n");
      TEST_EXIT(elType >= 0 && elType <= 2)("elType must be between 0 and 2\n");
      return sideOfChild[elType][child][side];
    };

    /** \brief
     * implements Element::getVertexOfParent()
     */
    virtual int getVertexOfParent(int child, int side, int elType = 0) const {
      FUNCNAME("Tetrahedron::getVertexOfParent()");
      TEST_EXIT(child==0 || child==1)("child must be in (0,1)\n");
      TEST_EXIT(side >= 0 && side <= 3)("side must be between 0 and 3\n");
      TEST_EXIT(elType >= 0 && elType <= 2)("elType must be between 0 and 2\n");
      return vertexOfParent[elType][child][side];
    };

    inline int getEdgeOfFace(int face, int edge) const {
      TEST_EXIT(face >= 0 && face < 4)("invalid face\n");
      TEST_EXIT(edge >= 0 && edge < 3)("invalid edge\n");
      return edgeOfFace[face][edge];
    };

  protected:

    /** \brief
     * vertexOfEdge[i][j] is the local number of the j-vertex of edge i
     */
    static const int vertexOfEdge[6][2]; 

    /** \brief
     * vertexOfFace[i][j] is the local number of the j-vertex of face i
     */
    static const int vertexOfFace[4][3];

    static const int sideOfChild[3][2][4];
  
    static const int vertexOfParent[3][2][4];
  };

}

#endif // AMDIS_TETRAHEDRON_H