Triangle.cc 4.43 KB
Newer Older
1
2
3
4
5
#include "Triangle.h"
#include "DOFAdmin.h"
#include "Mesh.h"
#include "CoarseningManager.h"
#include "FixVec.h"
6
#include "ElementDofIterator.h"
7
8
9

namespace AMDiS {

Thomas Witkowski's avatar
Thomas Witkowski committed
10
11
12
  const int Triangle::vertexOfEdge[3][2] = {{1, 2}, {2, 0}, {0, 1}};
  const int Triangle::sideOfChild[2][3] = {{-1, 2, 0}, {2, -1, 1}};
  const int Triangle::vertexOfParent[2][3] = {{2, 0, -1}, {1, 2, -1}};
13
14
15
16

  bool Triangle::hasSide(Element* sideElem) const
  {
    FUNCNAME("Triangle::hasSide");
17
    TEST_EXIT_DBG(sideElem->isLine())("called for sideElem-type != Line\n");
18
19
20
21
    ERROR_EXIT("not yet\n");
    return false;
  }

22
23
  int Triangle::getVertexOfPosition(GeoIndex position, int positionIndex,
				    int vertexIndex) const 
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  {
    FUNCNAME("Triangle::getVertexOfPosition");
    switch(position) {
    case VERTEX:
      return positionIndex;
      break;
    case EDGE:
      return vertexOfEdge[positionIndex][vertexIndex];
      break;
    case CENTER:
      return vertexIndex;
      break;
    default:
      ERROR_EXIT("invalid position\n");
      return 0;
    }
  }

42
43
  const FixVec<int, WORLD>& Triangle::sortFaceIndices(int face, 
						      FixVec<int,WORLD> *vec) const
44
45
46
47
48
  {
    static MatrixOfFixVecs<FixVec<int,WORLD> > *sorted_2d = NULL;

    int no = 0;
    FixVec<int,WORLD> *val = NULL;
49
    const int *vof = vertexOfEdge[face];
50

51
52
    if (NULL == sorted_2d) {
      sorted_2d = new MatrixOfFixVecs<FixVec<int,WORLD> >(2, 3, 2, NO_INIT);
53

54
55
56
57
58
59
      (*sorted_2d)[1][0][1] = (*sorted_2d)[1][1][0] =
	(*sorted_2d)[2][0][0] = (*sorted_2d)[2][1][1] = 0;
      (*sorted_2d)[0][0][0] = (*sorted_2d)[0][1][1] =
	(*sorted_2d)[2][0][1] = (*sorted_2d)[2][1][0] = 1;
      (*sorted_2d)[0][0][1] = (*sorted_2d)[0][1][0] =
	(*sorted_2d)[1][0][0] = (*sorted_2d)[1][1][1] = 2;
60
61
62
63
64
65
66
67
68
69
    }

    if (dof[vof[0]][0] < dof[vof[1]][0])
      no = 0;
    else
      no = 1;

    if (vec) {
      val = vec;
      *val = (*sorted_2d)[face][no];
70
    } else {
71
      val = &((*sorted_2d)[face][no]);
72
    }
73

74
    return *(const_cast<const FixVec<int,WORLD>* >(val));
75
76
  }

77

78
  void Triangle::getVertexDofs(FiniteElemSpace* feSpace, 
79
			       BoundaryObject bound,
80
			       DofContainer& dofs) const
81
82
83
  {
    FUNCNAME("Triangle::getVertexDofs()");

84
85
86
    BoundaryObject nextBound = bound;

    switch (bound.ithObj) {
87
88
89
90
    case 0: 
      {
	Element *child1 = child[1];
	if (child1 && child1->getFirstChild()) {
91
92
93
	  nextBound.ithObj = 0;
	  child1->getFirstChild()->getVertexDofs(feSpace, nextBound, dofs);

94
	  dofs.push_back(child1->getFirstChild()->getDOF(2));
95
96
97

	  nextBound.ithObj = 1;
	  child1->getSecondChild()->getVertexDofs(feSpace, nextBound, dofs);
98
99
100
101
102
103
104
	}
      }
      break;
    case 1:
      {
	Element *child0 = child[0];
	if (child0 && child0->getFirstChild()) {
105
106
107
	  nextBound.ithObj = 0;
	  child0->getFirstChild()->getVertexDofs(feSpace, nextBound, dofs);

108
	  dofs.push_back(child[0]->getFirstChild()->getDOF(2));
109
110
111

	  nextBound.ithObj = 1;
	  child0->getSecondChild()->getVertexDofs(feSpace, nextBound, dofs);
112
113
114
115
116
	}
      }
      break;
    case 2:      
      if (child[0]) {
117
118
119
	nextBound.ithObj = 0;
	child[0]->getVertexDofs(feSpace, nextBound, dofs);

120
	dofs.push_back(child[0]->getDOF(2));
121
122
123

	nextBound.ithObj = 1;
	child[1]->getVertexDofs(feSpace, nextBound, dofs);
124
125
126
127
128
129
130
131
      }
      break;      
    default:
      ERROR_EXIT("Should never happen!\n");
    }
  }


132
  void Triangle::getNonVertexDofs(FiniteElemSpace* feSpace, 
133
				  BoundaryObject bound,
134
135
136
137
138
				  DofContainer& dofs) const
  {
    FUNCNAME("Triange::getNonVertexDofs()");

    bool addThisEdge = false;
139
    BoundaryObject nextBound = bound;
140

141
    switch (bound.ithObj) {
142
    case 0:
143
144
145
146
      if (child[1]) {
	nextBound.ithObj = 2;
	child[1]->getNonVertexDofs(feSpace, nextBound, dofs);
      } else {
147
	addThisEdge = true;
148
      }
149
150
151

      break;
    case 1:
152
153
154
155
      if (child[0]) {
	nextBound.ithObj = 2;
	child[0]->getNonVertexDofs(feSpace, nextBound, dofs);
      } else {
156
	addThisEdge = true;
157
      }
158
159
160
161

      break;
    case 2:
      if (child[0]) {
162
163
164
165
	nextBound.ithObj = 0;
	child[0]->getNonVertexDofs(feSpace, nextBound, dofs);
	nextBound.ithObj = 1;
	child[1]->getNonVertexDofs(feSpace, nextBound, dofs);
166
167
168
169
170
171
172
173
174
175
176
177
178
179
      } else {
	addThisEdge = true;
      } 

      break;
    default:
      ERROR_EXIT("Should never happen!\n");
    }

    if (addThisEdge) {
      ElementDofIterator elDofIter(feSpace, true);
      elDofIter.reset(this);
      do {
	if (elDofIter.getCurrentPos() == 1 && 
180
	    elDofIter.getCurrentElementPos() == bound.ithObj)
181
182
183
184
185
186
	  dofs.push_back(elDofIter.getDofPtr());	
      } while(elDofIter.next());      
    }
  }


187
}