Triangle.h 5.17 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
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file Triangle.h */

#ifndef AMDIS_TRIANGLE_H
#define AMDIS_TRIANGLE_H

#include "Element.h"
#include "MemoryManager.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:
    MEMORY_MANAGED(Triangle);

    /** \brief
     * calls base class contructor.
     */
46 47 48
    Triangle(Mesh* aMesh) 
      : Element(aMesh) 
    {};
49 50 51 52

    /** \brief
     * implements Element::clone
     */
53 54
    inline Element *clone() { 
      return NEW Triangle(mesh); 
55
    }
56 57 58 59 60 61 62


    /** \brief
     * implements Element::getVertexOfEdge
     */
    inline int getVertexOfEdge(int i, int j) const {
      return vertexOfEdge[i][j];
63
    }
64 65 66 67 68

    /** \brief
     * implements Element::getVertexOfPosition
     */
    int getVertexOfPosition(GeoIndex position,
69 70
			    int positionIndex,
			    int vertexIndex) const;
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

    /** \brief
     * implements Element::getGeo
     */
    inline int getGeo(GeoIndex i) const {
      switch(i) {
      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;
      }
100
    }
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

    /** \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 
     * Triangle
     */
117 118
    inline bool isLine() const { 
      return false; 
119
    }
120 121 122 123 124
 
    /** \brief
     * implements Element::isTriangle. Returns true because this element is a 
     * Triangle
     */
125 126
    inline bool isTriangle() const { 
      return true; 
127
    }
128 129 130 131 132

    /** \brief
     * implements Element::isTetrahedron. Returns false because this element is a 
     * Triangle
     */
133 134
    inline bool isTetrahedron() const { 
      return false; 
135
    }
136 137 138 139 140 141

    /** \brief
     * implements Element::getSideOfChild()
     */
    virtual int getSideOfChild(int child, int side, int) const {
      FUNCNAME("Triangle::getSideOfChild()");
142 143
      TEST_EXIT_DBG(child==0 || child==1)("child must be in (0,1)\n");
      TEST_EXIT_DBG(side >= 0 && side <= 2)("side must be between 0 and 2\n");
144
      return sideOfChild[child][side];
145
    }
146 147 148 149 150 151

    /** \brief
     * implements Element::getVertexOfParent()
     */
    virtual int getVertexOfParent(int child, int side, int=0) const {
      FUNCNAME("Triangle::getVertexOfParent()");
152 153
      TEST_EXIT_DBG(child==0 || child==1)("child must be in (0,1)\n");
      TEST_EXIT_DBG(side >= 0 && side <= 2)("side must be between 0 and 2\n");
154
      return vertexOfParent[child][side];
155
    }
156 157 158 159 160 161 162

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

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

    // ===== Serializable implementation =====
  
170
    std::string getTypeName() const { 
171
      return "Triangle"; 
172
    }
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188

  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