Triangle.h 6.14 KB
Newer Older
1
2
3
4
5
6
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
8
// ==                                                                        ==
9
10
11
// ==  Institut fr Wissenschaftliches Rechnen                               ==
// ==  Zellescher Weg 12-14                                                  ==
// ==  01069 Dresden                                                         ==
12
13
14
15
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
16
// ==  https://gforge.zih.tu-dresden.de/projects/amdis/                      ==
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// ==                                                                        ==
// ============================================================================

/** \file Triangle.h */

#ifndef AMDIS_TRIANGLE_H
#define AMDIS_TRIANGLE_H

#include "Element.h"

namespace AMDiS {

  /** \ingroup Triangulation 
   * \brief
   * A Triangle is a 2-dimensional Element.
   *
   * A Triangle and its refinements:
   *
   * <img src = "triangle.png">
   */
  class Triangle : public Element
  {
  public:
40
    /// calls base class contructor.
41
42
    Triangle(Mesh* aMesh) 
      : Element(aMesh) 
43
44
45
    {}

    ~Triangle() {}
46

47
48
49
    /// implements Element::clone
    inline Element *clone() 
    { 
Thomas Witkowski's avatar
Thomas Witkowski committed
50
      return new Triangle(mesh); 
51
    }
52

53
54
55
    /// implements Element::getVertexOfEdge
    inline int getVertexOfEdge(int i, int j) const 
    {
56
      return vertexOfEdge[i][j];
57
    }
58

59
    /// implements Element::getVertexOfPosition
60
    int getVertexOfPosition(GeoIndex position,
61
62
			    int positionIndex,
			    int vertexIndex) const;
63

64
65
66
67
    /// implements Element::getGeo
    inline int getGeo(GeoIndex i) const 
    {
      switch (i) {
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
      case VERTEX: case PARTS: case NEIGH:
	return 3;
	break;
      case EDGE:
	return 3;
      case FACE:
	return 0;
      case CENTER:
	return 1;
	break;
      case DIMEN:
	return 2;
	break;
      case BOUNDARY:
	return 6;
	break;
      case PROJECTION:
	return 3;
	break;
      default:
	ERROR_EXIT("invalid geo-index\n");
	return 0;
      }
91
    }
92

93
    /// implements Element::hasSide
94
95
    bool hasSide(Element* sideElem) const;

96
    /// implements Element::sortFaceIndices
97
    const FixVec<int,WORLD>& sortFaceIndices(int face, FixVec<int,WORLD> *vec) const;
98

99
100
101
    /// implements Element::isLine. Returns false because this element is a Triangle
    inline bool isLine() const 
    { 
102
      return false; 
103
    }
104
 
105
106
107
    /// implements Element::isTriangle. Returns true because this element is a Triangle
    inline bool isTriangle() const 
    { 
108
      return true; 
109
    }
110

111
    /// implements Element::isTetrahedron. Returns false because this element is a Triangle
112
113
    inline bool isTetrahedron() const 
    { 
114
      return false; 
115
    }
116

117
118
119
120
121
122
    /// Element type number is not used in 2d, so return 0.
    inline int getChildType(int) const
    {
      return 0;
    }

123
124
125
    /// implements Element::getSideOfChild()
    virtual int getSideOfChild(int child, int side, int) const 
    {
126
      FUNCNAME("Triangle::getSideOfChild()");
127
128

      TEST_EXIT_DBG(child == 0 || child == 1)("child must be in (0,1)\n");
129
      TEST_EXIT_DBG(side >= 0 && side <= 2)("side must be between 0 and 2\n");
130

131
      return sideOfChild[child][side];
132
    }
133

134
135
136
137
138
139
140
141
142
    int getSubObjOfChild(int childnr, GeoIndex subObj, int ithObj, int elType) const
    {
      FUNCNAME("Triangle::getSubObjOfChild()");

      TEST_EXIT_DBG(subObj == EDGE)("Not yet implemented!\n");

      return getSideOfChild(childnr, ithObj, elType);
    }

143
144
145
    /// implements Element::getVertexOfParent()
    virtual int getVertexOfParent(int child, int side, int = 0) const 
    {
146
      FUNCNAME("Triangle::getVertexOfParent()");
147
148

      TEST_EXIT_DBG(child == 0 || child == 1)("child must be in (0,1)\n");
149
      TEST_EXIT_DBG(side >= 0 && side <= 2)("side must be between 0 and 2\n");
150

151
      return vertexOfParent[child][side];
152
    }
153

154
155
    virtual int getPositionOfVertex(int side, int vertex) const 
    {
156
157
158
159
      FUNCNAME("Triangle::getPositionOfVertex()");
      TEST_EXIT_DBG(side >= 0 && side <= 2)("Wrong side number %d!\n", side);
      TEST_EXIT_DBG(vertex >= 0 && vertex <= 2)("Wrong vertex number %d!\n", vertex);

160
      static int positionOfVertex[3][3] = {{-1, 0, 1}, {1, -1, 0}, {0, 1, -1}};
161
      return positionOfVertex[side][vertex];
162
    }
163

164
165
    inline int getEdgeOfFace(int face, int edge) const 
    {
166
      FUNCNAME("Triangle::getEdgeOfFace()");
167
168
      TEST_EXIT_DBG(face == 0)("face must be zero at triangle\n");
      TEST_EXIT_DBG(edge >= 0 && edge < 3)("invalid edge\n");
169

170
      return edge;
171
    }
172
173
174
175
176
177
178
179
180
181
182
183

    GlobalEdge getEdge(int localEdgeIndex) const
    {
      FUNCNAME("Triangle::getEdge()");
      TEST_EXIT_DBG(localEdgeIndex >= 0 && localEdgeIndex < 3)("invalid edge\n");

      DegreeOfFreedom dof0 = dof[vertexOfEdge[localEdgeIndex][0]][0];
      DegreeOfFreedom dof1 = dof[vertexOfEdge[localEdgeIndex][1]][0];
      GlobalEdge edge = std::make_pair(min(dof0, dof1), max(dof0, dof1));

      return edge;
    }
184
 
185
186
    std::string getTypeName() const 
    { 
187
      return "Triangle"; 
188
    }
189

190
    void getVertexDofs(FiniteElemSpace* feSpace, 
191
		       BoundaryObject bound,
192
		       DofContainer& dofs) const;
193

194
    void getNonVertexDofs(FiniteElemSpace* feSpace, 
195
			  BoundaryObject bound,
196
197
			  DofContainer& dofs) const;

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
  protected:
    /** \brief
     * vertexOfEdge[i][j] is the local number of the j-th vertex of the i-th 
     * edge of this element.
     */
    static const int vertexOfEdge[3][2];

    static const int sideOfChild[2][3];

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

}

#endif // AMDIS_TRIANGLE_H