Triangle.h 5.72 KB
Newer Older
1 2 3 4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6 7
// ==                                                                        ==
// ============================================================================
8 9 10 11 12 13 14 15 16 17 18 19
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

/** \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:
41
    /// calls base class contructor.
42 43
    Triangle(Mesh* aMesh) 
      : Element(aMesh) 
44 45 46
    {}

    ~Triangle() {}
47

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

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

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

65 66 67 68
    /// implements Element::getGeo
    inline int getGeo(GeoIndex i) const 
    {
      switch (i) {
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
      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;
      }
92
    }
93

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

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

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

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

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

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

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

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

135 136 137 138 139 140 141 142 143
    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);
    }

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

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

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

155 156
    virtual int getPositionOfVertex(int side, int vertex) const 
    {
157 158 159 160
      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);

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

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

171
      return edge;
172
    }
173

174
    DofEdge getEdge(int localEdgeIndex) const
175 176 177 178 179 180
    {
      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];
181
      DofEdge edge = std::make_pair(std::min(dof0, dof1), std::max(dof0, dof1));
182 183 184

      return edge;
    }
185 186 187 188 189 190 191

    DofFace getFace(int localFaceIndex) const
    {
      ERROR_EXIT("This does not work in 1D!\n");
      return DofFace();
    }

192 193
    std::string getTypeName() const 
    { 
194
      return "Triangle"; 
195
    }
196

197
    void getNodeDofs(const FiniteElemSpace* feSpace, 
198
		     BoundaryObject bound,
199 200
		     DofContainer& dofs,
		     bool baseDofPtr = false) const;
201
    
202
    void getHigherOrderDofs(const FiniteElemSpace* feSpace, 
203
			    BoundaryObject bound,
204 205
			    DofContainer& dofs,
			    bool baseDofPtr = false) const;
206

207
  protected:
208 209
    /// vertexOfEdge[i][j] is the local number of the j-th vertex of the i-th 
    /// edge of this element.
210 211 212 213 214 215 216 217 218 219
    static const int vertexOfEdge[3][2];

    static const int sideOfChild[2][3];

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

}

#endif // AMDIS_TRIANGLE_H