Triangle.cc 4.52 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
49
50
51
  {
    static MatrixOfFixVecs<FixVec<int,WORLD> > *sorted_2d = NULL;

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

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

55
56
57
58
59
60
      (*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;
61
62
63
64
65
66
67
68
69
70
    }

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

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

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

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

  void Triangle::getVertexDofs(FiniteElemSpace* feSpace, int ithEdge, 
			       DofContainer& dofs, bool parentVertices) const
  {
    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()) {
	  child1->getFirstChild()->getVertexDofs(feSpace, 0, dofs);
	  dofs.push_back(child1->getFirstChild()->getDOF(2));
	  child1->getSecondChild()->getVertexDofs(feSpace, 1, dofs);
	}
      }
      break;
    case 1:
      {
	Element *child0 = child[0];
	if (child0 && child0->getFirstChild()) {
	  child0->getFirstChild()->getVertexDofs(feSpace, 0, dofs);
	  dofs.push_back(child[0]->getFirstChild()->getDOF(2));
	  child0->getSecondChild()->getVertexDofs(feSpace, 1, dofs);
	}
      }
      break;
    case 2:      
      if (child[0]) {
	child[0]->getVertexDofs(feSpace, 0, dofs);
	dofs.push_back(child[0]->getDOF(2));
	child[1]->getVertexDofs(feSpace, 1, dofs);
      }
      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");
      }
    }
  }


  void Triangle::getNonVertexDofs(FiniteElemSpace* feSpace, int ithEdge, 
				  DofContainer& dofs) const
  {
    FUNCNAME("Triange::getNonVertexDofs()");

    bool addThisEdge = false;

    switch (ithEdge) {
    case 0:
      if (child[1])
	child[1]->getNonVertexDofs(feSpace, 2, dofs);
      else
	addThisEdge = true;

      break;
    case 1:
      if (child[0])
	child[0]->getNonVertexDofs(feSpace, 2, dofs);
      else
	addThisEdge = true;

      break;
    case 2:
      if (child[0]) {
	child[0]->getNonVertexDofs(feSpace, 0, dofs);
	child[1]->getNonVertexDofs(feSpace, 1, dofs);
      } 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());      
    }
  }


197
}