Triangle.h 5.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * 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 41 42

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

    ~Triangle() {}
49

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

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

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

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

96
    /// implements Element::hasSide
97 98
    bool hasSide(Element* sideElem) const;

99
    /// implements Element::sortFaceIndices
100
    void sortFaceIndices(int face, FixVec<int, WORLD> &vec) const;
101

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

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

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

126 127 128
    /// implements Element::getSideOfChild()
    virtual int getSideOfChild(int child, int side, int) const 
    {
129
      FUNCNAME_DBG("Triangle::getSideOfChild()");
130 131

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

134
      return sideOfChild[child][side];
135
    }
136

137 138
    int getSubObjOfChild(int childnr, GeoIndex subObj, int ithObj, int elType) const
    {
139
      FUNCNAME_DBG("Triangle::getSubObjOfChild()");
140 141 142 143 144 145

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

      return getSideOfChild(childnr, ithObj, elType);
    }

146 147 148
    /// implements Element::getVertexOfParent()
    virtual int getVertexOfParent(int child, int side, int = 0) const 
    {
149
      FUNCNAME_DBG("Triangle::getVertexOfParent()");
150 151

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

154
      return vertexOfParent[child][side];
155
    }
156

157 158
    virtual int getPositionOfVertex(int side, int vertex) const 
    {
159
      FUNCNAME_DBG("Triangle::getPositionOfVertex()");
160 161 162
      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);

163
      static const int positionOfVertex[3][3] = {{-1, 0, 1}, {1, -1, 0}, {0, 1, -1}};
164
      return positionOfVertex[side][vertex];
165
    }
166

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

173
      return edge;
174
    }
175

176
    DofEdge getEdge(int localEdgeIndex) const
177
    {
178
      FUNCNAME_DBG("Triangle::getEdge()");
179 180 181 182
      TEST_EXIT_DBG(localEdgeIndex >= 0 && localEdgeIndex < 3)("invalid edge\n");

      DegreeOfFreedom dof0 = dof[vertexOfEdge[localEdgeIndex][0]][0];
      DegreeOfFreedom dof1 = dof[vertexOfEdge[localEdgeIndex][1]][0];
183
      DofEdge edge = std::make_pair(std::min(dof0, dof1), std::max(dof0, dof1));
184 185 186

      return edge;
    }
187 188 189 190 191 192 193

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

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

199
    void getNodeDofs(const FiniteElemSpace* feSpace, 
200
		     BoundaryObject bound,
201 202
		     DofContainer& dofs,
		     bool baseDofPtr = false) const;
203
    
204
    void getHigherOrderDofs(const FiniteElemSpace* feSpace, 
205
			    BoundaryObject bound,
206
			    DofContainer& dofs,
207
			    bool baseDofPtr = false,
208
			    vector<GeoIndex>* dofGeoIndex = nullptr) const;
209

210 211 212 213 214
    void prepareNextBound(BoundaryObject &bound, int ithChild) const;

    void getSubBoundary(BoundaryObject bound, 
			vector<BoundaryObject> &subBound) const;

215
  protected:
216 217
    /// vertexOfEdge[i][j] is the local number of the j-th vertex of the i-th 
    /// edge of this element.
218 219 220 221 222 223 224 225 226 227
    static const int vertexOfEdge[3][2];

    static const int sideOfChild[2][3];

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

}

#endif // AMDIS_TRIANGLE_H