Triangle.cc 4.73 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
79
  void Triangle::getVertexDofs(FiniteElemSpace* feSpace, 
			       int ithEdge, int elType,
80
81
82
			       DofContainer& dofs, 
			       bool reverseMode,
			       bool parentVertices) const
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
  {
    FUNCNAME("Triangle::getVertexDofs()");

    if (parentVertices) {
      switch (ithEdge) {
      case 0:
	dofs.push_back(dof[1]);
	break;
      case 1:
	dofs.push_back(dof[0]);
	break;
      case 2:
	dofs.push_back(dof[0]);
	break;
      default:
	ERROR_EXIT("Should never happen!\n");
      }
    }

    switch (ithEdge) {
    case 0: 
      {
	Element *child1 = child[1];
	if (child1 && child1->getFirstChild()) {
107
	  child1->getFirstChild()->getVertexDofs(feSpace, 0, elType, dofs, reverseMode);
108
	  dofs.push_back(child1->getFirstChild()->getDOF(2));
109
	  child1->getSecondChild()->getVertexDofs(feSpace, 1, elType, dofs, reverseMode);
110
111
112
113
114
115
116
	}
      }
      break;
    case 1:
      {
	Element *child0 = child[0];
	if (child0 && child0->getFirstChild()) {
117
	  child0->getFirstChild()->getVertexDofs(feSpace, 0, elType, dofs, reverseMode);
118
	  dofs.push_back(child[0]->getFirstChild()->getDOF(2));
119
	  child0->getSecondChild()->getVertexDofs(feSpace, 1, elType, dofs, reverseMode);
120
121
122
123
124
	}
      }
      break;
    case 2:      
      if (child[0]) {
125
	child[0]->getVertexDofs(feSpace, 0, elType, dofs, reverseMode);
126
	dofs.push_back(child[0]->getDOF(2));
127
	child[1]->getVertexDofs(feSpace, 1, elType, dofs, reverseMode);
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
      }
      break;      
    default:
      ERROR_EXIT("Should never happen!\n");
    }

    if (parentVertices) {
      switch (ithEdge) {
      case 0:
	dofs.push_back(dof[2]);
	break;
      case 1:
	dofs.push_back(dof[2]);
	break;
      case 2:
	dofs.push_back(dof[1]);
	break;
    default:
      ERROR_EXIT("Should never happen!\n");
      }
    }
  }


152
153
  void Triangle::getNonVertexDofs(FiniteElemSpace* feSpace, 
				  int ithEdge, int elType,
154
155
156
157
158
159
160
161
162
				  DofContainer& dofs) const
  {
    FUNCNAME("Triange::getNonVertexDofs()");

    bool addThisEdge = false;

    switch (ithEdge) {
    case 0:
      if (child[1])
163
	child[1]->getNonVertexDofs(feSpace, 2, elType, dofs);
164
165
166
167
168
169
      else
	addThisEdge = true;

      break;
    case 1:
      if (child[0])
170
	child[0]->getNonVertexDofs(feSpace, 2, elType, dofs);
171
172
173
174
175
176
      else
	addThisEdge = true;

      break;
    case 2:
      if (child[0]) {
177
178
	child[0]->getNonVertexDofs(feSpace, 0, elType, dofs);
	child[1]->getNonVertexDofs(feSpace, 1, elType, dofs);
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
      } 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 && 
	    elDofIter.getCurrentElementPos() == ithEdge)
	  dofs.push_back(elDofIter.getDofPtr());	
      } while(elDofIter.next());      
    }
  }


200
}