Triangle.cc 6.25 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


13
14
15
16
17
#include "Triangle.h"
#include "DOFAdmin.h"
#include "Mesh.h"
#include "CoarseningManager.h"
#include "FixVec.h"
18
#include "ElementDofIterator.h"
19
20
21

namespace AMDiS {

Thomas Witkowski's avatar
Thomas Witkowski committed
22
23
24
  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}};
25
26
27
28

  bool Triangle::hasSide(Element* sideElem) const
  {
    FUNCNAME("Triangle::hasSide");
29
    TEST_EXIT_DBG(sideElem->isLine())("called for sideElem-type != Line\n");
30
31
32
33
    ERROR_EXIT("not yet\n");
    return false;
  }

34
35
  int Triangle::getVertexOfPosition(GeoIndex position, int positionIndex,
				    int vertexIndex) const 
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  {
    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;
    }
  }

54
  const FixVec<int, WORLD>& Triangle::sortFaceIndices(int face, 
55
						      FixVec<int, WORLD> *vec) const
56
  {
57
    static MatrixOfFixVecs<FixVec<int, WORLD> > *sorted_2d = NULL;
58
59

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

63
    if (NULL == sorted_2d) {
64
      sorted_2d = new MatrixOfFixVecs<FixVec<int, WORLD> >(2, 3, 2, NO_INIT);
65

66
67
68
69
70
71
      (*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;
72
73
74
75
76
77
78
79
80
81
    }

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

    if (vec) {
      val = vec;
      *val = (*sorted_2d)[face][no];
82
    } else {
83
      val = &((*sorted_2d)[face][no]);
84
    }
85

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

89

90
91
92
  void Triangle::getNodeDofs(FiniteElemSpace* feSpace, 
			     BoundaryObject bound,
			     DofContainer& dofs) const
93
  {
94
    FUNCNAME("Triangle::getNodeDofs()");
95

96
97
98
99
100
101
102
    if (bound.subObj == VERTEX) {
      dofs.push_back(dof[bound.ithObj]);
      return;
    }

    TEST_EXIT_DBG(bound.subObj == EDGE)("This should not happen!\n");

103
104
105
    BoundaryObject nextBound = bound;

    switch (bound.ithObj) {
106
107
    case 0: 
      {
108
109
110
	if (child[1] && child[1]->getFirstChild()) {
 	  if (bound.reverseMode) {
 	    nextBound.ithObj = 1;
111
 	    child[1]->getSecondChild()->getNodeDofs(feSpace, nextBound, dofs);
112
 	    dofs.push_back(child[1]->getFirstChild()->getDof(2));	    
113
 	    nextBound.ithObj = 0;
114
 	    child[1]->getFirstChild()->getNodeDofs(feSpace, nextBound, dofs);	    
115
116
 	  } else {
	    nextBound.ithObj = 0;
117
	    child[1]->getFirstChild()->getNodeDofs(feSpace, nextBound, dofs);	    
118
	    dofs.push_back(child[1]->getFirstChild()->getDof(2));	    
119
	    nextBound.ithObj = 1;
120
	    child[1]->getSecondChild()->getNodeDofs(feSpace, nextBound, dofs);
121
	  }
122
123
124
125
126
	}
      }
      break;
    case 1:
      {
127
128
129
	if (child[0] && child[0]->getFirstChild()) {
	  if (bound.reverseMode) {
	    nextBound.ithObj = 1;
130
	    child[0]->getSecondChild()->getNodeDofs(feSpace, nextBound, dofs);
131
	    dofs.push_back(child[0]->getFirstChild()->getDof(2));
132
	    nextBound.ithObj = 0;
133
	    child[0]->getFirstChild()->getNodeDofs(feSpace, nextBound, dofs);
134
135
	  } else {
	    nextBound.ithObj = 0;
136
	    child[0]->getFirstChild()->getNodeDofs(feSpace, nextBound, dofs);
137
	    dofs.push_back(child[0]->getFirstChild()->getDof(2));
138
	    nextBound.ithObj = 1;
139
	    child[0]->getSecondChild()->getNodeDofs(feSpace, nextBound, dofs);
140
	  }
141
142
143
144
145
	}
      }
      break;
    case 2:      
      if (child[0]) {
146
147
	if (bound.reverseMode) {
	  nextBound.ithObj = 1;
148
	  child[1]->getNodeDofs(feSpace, nextBound, dofs);
149
	  dofs.push_back(child[0]->getDof(2));	  
150
	  nextBound.ithObj = 0;
151
	  child[0]->getNodeDofs(feSpace, nextBound, dofs);
152
153
	} else {
	  nextBound.ithObj = 0;
154
	  child[0]->getNodeDofs(feSpace, nextBound, dofs);	  
155
	  dofs.push_back(child[0]->getDof(2));	  
156
	  nextBound.ithObj = 1;
157
	  child[1]->getNodeDofs(feSpace, nextBound, dofs);
158
	}
159
160
161
162
163
164
165
166
      }
      break;      
    default:
      ERROR_EXIT("Should never happen!\n");
    }
  }


167
168
169
  void Triangle::getHigherOrderDofs(FiniteElemSpace* feSpace, 
				    BoundaryObject bound,
				    DofContainer& dofs) const
170
  {
171
    FUNCNAME("Triange::getHigherOrderDofs()");
172

173
174
175
176
177
    if (bound.subObj == VERTEX)
      return;

    TEST_EXIT_DBG(bound.subObj == EDGE)("This should not happen!\n");

178
    bool addThisEdge = false;
179
    BoundaryObject nextBound = bound;
180

181
    switch (bound.ithObj) {
182
    case 0:
183
184
      if (child[1]) {
	nextBound.ithObj = 2;
185
	child[1]->getHigherOrderDofs(feSpace, nextBound, dofs);
186
      } else {
187
	addThisEdge = true;
188
      }
189
190
191

      break;
    case 1:
192
193
      if (child[0]) {
	nextBound.ithObj = 2;
194
	child[0]->getHigherOrderDofs(feSpace, nextBound, dofs);
195
      } else {
196
	addThisEdge = true;
197
      }
198
199
200
201

      break;
    case 2:
      if (child[0]) {
202
203
	if (bound.reverseMode) {
	  nextBound.ithObj = 1;
204
	  child[1]->getHigherOrderDofs(feSpace, nextBound, dofs);
205
	  nextBound.ithObj = 0;
206
	  child[0]->getHigherOrderDofs(feSpace, nextBound, dofs);
207
208
	} else {
	  nextBound.ithObj = 0;
209
	  child[0]->getHigherOrderDofs(feSpace, nextBound, dofs);
210
	  nextBound.ithObj = 1;
211
	  child[1]->getHigherOrderDofs(feSpace, nextBound, dofs);
212
	}
213
214
215
216
217
218
219
220
221
222
      } else {
	addThisEdge = true;
      } 

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

    if (addThisEdge) {
223
      DofContainer addDofs;
224
225
226
227
      ElementDofIterator elDofIter(feSpace, true);
      elDofIter.reset(this);
      do {
	if (elDofIter.getCurrentPos() == 1 && 
228
	    elDofIter.getCurrentElementPos() == bound.ithObj)
229
	  addDofs.push_back(elDofIter.getDofPtr());	
230
      } while(elDofIter.next());      
231
232
233
234
235
236
237
238


      if (bound.reverseMode)
 	for (int i = addDofs.size() - 1; i >= 0; i--)
 	  dofs.push_back(addDofs[i]);
      else
 	for (unsigned int i = 0; i < addDofs.size(); i++) 
 	  dofs.push_back(addDofs[i]);      
239
240
241
242
    }
  }


243
}