Tetrahedron.cc 8.4 KB
Newer Older
1
2
3
4
5
#include "Tetrahedron.h"
#include "DOFAdmin.h"
#include "Mesh.h"
#include "CoarseningManager.h"
#include "FixVec.h"
6
#include "ElementDofIterator.h"
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

namespace AMDiS {

  const unsigned char Tetrahedron::nChildEdge[3][2][2] = {{{5,4},{4,5}},
							  {{5,4},{5,4}},
							  {{5,4},{5,4}}};
  const unsigned char Tetrahedron::nChildFace[3][2][2] = {{{1,2},{2,1}},
							  {{1,2},{1,2}},
							  {{1,2},{1,2}}};
  const int Tetrahedron::childVertex[3][2][4] = {{{0,2,3,4},{1,3,2,4}},
						 {{0,2,3,4},{1,2,3,4}},
						 {{0,2,3,4},{1,2,3,4}}};
  const int Tetrahedron::childEdge[3][2][6] = {{{1,2,0,5,5,4},{4,3,0,5,5,4}},
					       {{1,2,0,5,4,5},{3,4,0,5,4,5}},
					       {{1,2,0,5,4,5},{3,4,0,5,4,5}}};
  const unsigned char Tetrahedron::adjacentChild[2][2] = {{0,1}, {1,0}};

  const signed char Tetrahedron::childOrientation[3][2] = {{1,1}, 
							   {1,-1}, 
							   {1,-1}};

  const unsigned char Tetrahedron::edgeOfDOFs[4][4] =  {{255,0,1,2},
							{0,255,3,4},
							{1,3,255,5},
							{2,4,5,255}};

  const int Tetrahedron::vertexOfEdge[6][2] = {{0,1},
					       {0,2},
					       {0,3},
					       {1,2},
					       {1,3},
					       {2,3}};
  const int Tetrahedron::vertexOfFace[4][3] = {{1,2,3},
					       {0,2,3},
					       {0,1,3},
					       {0,1,2}};


  const int Tetrahedron::sideOfChild[3][2][4] = {{{-1, 3, 1, 2},  // type 0
						  {3, -1, 2, 1}},
						 {{-1, 3, 1, 2},  // type 1
						  {3, -1, 1, 2}},
						 {{-1, 3, 1, 2},  // type 2
						  {3, -1, 1, 2}}};

  const int Tetrahedron::vertexOfParent[3][2][4] = {{{0, 2, 3, -1},  // type 0
						     {1, 3, 2, -1}},
						    {{0, 2, 3, -1},  // type 1
						     {1, 2, 3, -1}},
						    {{0, 2, 3, -1},  // type 2
						     {1, 2, 3, -1}}};

  const int Tetrahedron::edgeOfFace[4][3] = {{5, 4, 3},  // face 0
					     {5, 2, 1},  // face 1
					     {4, 2, 0},  // face 2
					     {3, 1, 0}}; // face 3

  bool Tetrahedron::hasSide(Element* sideElem) const
  {
66
67
    FUNCNAME("Tetrahedron::hasSide()");
    TEST_EXIT_DBG(sideElem->isTriangle())("called for sideElem-type != Triangle\n");
68
69
70
71
72
    ERROR_EXIT("not yet\n");
    return false;
  }

  int Tetrahedron::getVertexOfPosition(GeoIndex position,
73
74
				       int positionIndex,
				       int vertexIndex) const 
75
  {
76
    FUNCNAME("Triangle::getVertexOfPosition()");
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
    switch(position) {
    case VERTEX:
      return positionIndex;
      break;
    case EDGE:
      return vertexOfEdge[positionIndex][vertexIndex];
      break;
    case FACE:
      return vertexOfFace[positionIndex][vertexIndex];
      break;
    case CENTER:
      return vertexIndex;
      break;
    default:
      ERROR_EXIT("invalid position\n");
      return 0;
    }
  }

  const FixVec<int, WORLD>&
  Tetrahedron::sortFaceIndices(int face, FixVec<int,WORLD> *vec) const
  {
    static MatrixOfFixVecs<FixVec<int,WORLD> > *sorted_3d = NULL;
    FixVec<int,WORLD> *val = NULL;
101
    const int *vof = vertexOfFace[face];
102

103
104
    if (NULL == sorted_3d) {
      sorted_3d = new MatrixOfFixVecs<FixVec<int,WORLD> >(3, 4, 7, NO_INIT);
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
 
      (*sorted_3d)[0][0][0]=(*sorted_3d)[0][0][1]=
	(*sorted_3d)[0][0][2]=(*sorted_3d)[1][0][0]=
	(*sorted_3d)[1][0][1]=(*sorted_3d)[1][0][2]=
	(*sorted_3d)[1][1][0]=(*sorted_3d)[1][2][1]=
	(*sorted_3d)[1][3][0]=(*sorted_3d)[1][4][2]=
	(*sorted_3d)[1][5][1]=(*sorted_3d)[1][6][2]=
	(*sorted_3d)[2][0][0]=(*sorted_3d)[2][0][1]=
	(*sorted_3d)[2][0][2]=(*sorted_3d)[2][1][0]=
	(*sorted_3d)[2][2][1]=(*sorted_3d)[2][3][0]=
	(*sorted_3d)[2][4][2]=(*sorted_3d)[2][5][1]=
	(*sorted_3d)[2][6][2]=(*sorted_3d)[3][0][0]=
	(*sorted_3d)[3][0][1]=(*sorted_3d)[3][0][2]=
	(*sorted_3d)[3][1][0]=(*sorted_3d)[3][2][1]=
	(*sorted_3d)[3][3][0]=(*sorted_3d)[3][4][2]=
	(*sorted_3d)[3][5][1]=(*sorted_3d)[3][6][2]=0;

      (*sorted_3d)[0][1][0]=(*sorted_3d)[0][2][1]=
	(*sorted_3d)[0][3][0]=(*sorted_3d)[0][4][2]=
	(*sorted_3d)[0][5][1]=(*sorted_3d)[0][6][2]=
	(*sorted_3d)[2][1][2]=(*sorted_3d)[2][2][0]=
	(*sorted_3d)[2][3][1]=(*sorted_3d)[2][4][1]=
	(*sorted_3d)[2][5][2]=(*sorted_3d)[2][6][0]=
	(*sorted_3d)[3][1][2]=(*sorted_3d)[3][2][0]=
	(*sorted_3d)[3][3][1]=(*sorted_3d)[3][4][1]=
	(*sorted_3d)[3][5][2]=(*sorted_3d)[3][6][0]=1;

      (*sorted_3d)[0][1][2]=(*sorted_3d)[0][2][0]=
	(*sorted_3d)[0][3][1]=(*sorted_3d)[0][4][1]=
	(*sorted_3d)[0][5][2]=(*sorted_3d)[0][6][0]=
	(*sorted_3d)[1][1][2]=(*sorted_3d)[1][2][0]=
	(*sorted_3d)[1][3][1]=(*sorted_3d)[1][4][1]=
	(*sorted_3d)[1][5][2]=(*sorted_3d)[1][6][0]=
	(*sorted_3d)[3][1][1]=(*sorted_3d)[3][2][2]=
	(*sorted_3d)[3][3][2]=(*sorted_3d)[3][4][0]=
	(*sorted_3d)[3][5][0]=(*sorted_3d)[3][6][1]=2;

      (*sorted_3d)[0][1][1]=(*sorted_3d)[0][2][2]=
	(*sorted_3d)[0][3][2]=(*sorted_3d)[0][4][0]=
	(*sorted_3d)[0][5][0]=(*sorted_3d)[0][6][1]=
	(*sorted_3d)[1][1][1]=(*sorted_3d)[1][2][2]=
	(*sorted_3d)[1][3][2]=(*sorted_3d)[1][4][0]=
	(*sorted_3d)[1][5][0]=(*sorted_3d)[1][6][1]=
	(*sorted_3d)[2][1][1]=(*sorted_3d)[2][2][2]=
	(*sorted_3d)[2][3][2]=(*sorted_3d)[2][4][0]=
	(*sorted_3d)[2][5][0]=(*sorted_3d)[2][6][1]=3;
    }

153
    int no = 0;
154
155
156
157
158
159
160
    if (dof[vof[0]][0] < dof[vof[1]][0])
      no++;
    if (dof[vof[1]][0] < dof[vof[2]][0])
      no += 2;
    if (dof[vof[2]][0] < dof[vof[0]][0])
      no += 4;

161
    if (!(no >= 1  &&  no <= 6))
162
163
164
165
166
167
      ERROR_EXIT("can not sort face indices of element %d at face %d\n", 
		 getIndex(), face);

    if (vec) {
      val = vec;
      *val = (*sorted_3d)[face][no];
168
    } else {
169
      val = &((*sorted_3d)[face][no]);
170
    }
171
172
173
174

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

175
176
  void Tetrahedron::getVertexDofs(FiniteElemSpace* feSpace, 
				  int ith, int elType,
177
178
179
				  DofContainer& dofs, 
				  bool reverseMode,
				  bool parentVertices) const
180
181
  {
    FUNCNAME("Tetrahedron::getVertexDofs()");
182
183
184
185

    if (parentVertices) {
      switch (ith) {
      case 0:
186
	dofs.push_back(dof[1]); dofs.push_back(dof[2]); dofs.push_back(dof[3]);
187
188
	break;
      case 1:
189
	dofs.push_back(dof[0]); dofs.push_back(dof[2]); dofs.push_back(dof[3]);
190
191
	break;
      case 2:
192
	dofs.push_back(dof[0]); dofs.push_back(dof[1]); dofs.push_back(dof[3]);
193
194
	break;
      case 3:
195
	dofs.push_back(dof[0]); dofs.push_back(dof[1]); dofs.push_back(dof[2]);
196
197
198
199
200
201
202
203
204
205
206
207
208
209
	break;
      default:
	ERROR_EXIT("Should never happen!\n");
      }
    }

    switch (ith) {
    case 0:
      {
	if (sideOfChild[elType][0][ith] != -1) {
	  std::cout << "ERROR 1 WITH elType = " << elType << "!\n";
	  exit(0);
	}

210
211
212
213
214
215
	if (child[1]) 
	  child[1]->getVertexDofs(feSpace, 
				  sideOfChild[elType][1][ith], 
				  (elType + 1) % 3,
				  dofs, 
				  reverseMode);
216
217
218
219
220
221
222
223
224
      }
      break;
    case 1:
      {
	if (sideOfChild[elType][1][ith] != -1) {
	  std::cout << "ERROR 2 WITH elType = " << elType << "!\n";
	  exit(0);
	}

225
226
227
228
229
230
	if (child[0]) 
	  child[0]->getVertexDofs(feSpace, 
				  sideOfChild[elType][0][ith], 
				  (elType + 1) % 3,
				  dofs,
				  reverseMode);
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
      }
      break;

    case 2:
    case 3:
      {
	if (child[0]) {
	  int c1 = sideOfChild[elType][0][ith];
	  int c2 = sideOfChild[elType][1][ith];

	  if (c1 == -1 || c2 == -1) {
	    std::cout << "ERROR 3 WITH elType = " << elType << std::endl;
	    exit(0);
	  }

246
247
248
249
250
251
252
253
254
	  if (reverseMode) {
	    child[1]->getVertexDofs(feSpace, c2, (elType + 1) % 3, dofs, false);
	    dofs.push_back(child[0]->getDOF(3));
	    child[0]->getVertexDofs(feSpace, c1, (elType + 1) % 3, dofs, false);
	  } else {
	    child[0]->getVertexDofs(feSpace, c1, (elType + 1) % 3, dofs, false);
	    dofs.push_back(child[0]->getDOF(3));
	    child[1]->getVertexDofs(feSpace, c2, (elType + 1) % 3, dofs, false);
	  }
255
256
257
258
259
260
	}
      }
      break;
    default:
      ERROR_EXIT("Should never happen!\n");
    }
261
262
  }

263
264
  void Tetrahedron::getNonVertexDofs(FiniteElemSpace* feSpace,
				     int ith, int elType,
265
266
267
				     DofContainer& dofs) const
  {
    FUNCNAME("Tetrahedron::getNonVertexDofs()");
268
269
270

    if (child[0]) {
      int childFace0 = sideOfChild[elType][0][ith];
271
      int childFace1 = sideOfChild[elType][1][ith];
272
273
274
275
276
277
278
279
280
281
282
283
284
285

      TEST_EXIT(childFace0 != -1 || childFace1 != -1)
	("No new face for child elements!\n");

      if (childFace0 != -1) 
	child[0]->getNonVertexDofs(feSpace, childFace0, (elType + 1) % 3, dofs);

      if (childFace1 != -1) 
	child[1]->getNonVertexDofs(feSpace, childFace1, (elType + 1) % 3, dofs);
    } else { 
      ElementDofIterator elDofIter(feSpace, true);
      elDofIter.reset(this);
      do {
	if (elDofIter.getCurrentPos() == 2 && 
286
287
288
289
	    elDofIter.getCurrentElementPos() == ith) {
	  ERROR_EXIT("Check this, if it will really work!\n");
	  dofs.push_back(elDofIter.getDofPtr());	
	}	
290
291
      } while(elDofIter.next());      
    }
292
293
  }

294
}