ElInfo.cc 4.46 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "ElInfo.h"
#include "BasisFunction.h"
#include "Element.h"
#include "Line.h"
#include "Triangle.h"
#include "Tetrahedron.h"
#include "FiniteElemSpace.h"
#include "Flag.h"
#include "MacroElement.h"
#include "Mesh.h"
#include "Global.h"
#include "FixVec.h"
#include "DOFVector.h"

namespace AMDiS {

17
18
  int ElInfo::traverseId[16] = {-1, -1, -1, -1, -1, -1, -1, -1,
				-1, -1, -1, -1, -1, -1, -1, -1};
19
20
21
22
23
24
25
  int ElInfo::traverseIdCounter = 0;

  ElInfo::ElInfo(Mesh *aMesh) 
    : mesh_(aMesh),
      element_(NULL),
      parent_(NULL),
      macroElement_(NULL),
26
27
      level_(0),
      iChild(0),
28
29
30
31
32
      coord_(mesh_->getDim(), NO_INIT),
      boundary_(mesh_->getDim(), DEFAULT_VALUE, INTERIOR),
      projection_(mesh_->getDim(), NO_INIT),
      oppCoord_(mesh_->getDim(), NO_INIT),
      neighbour_(mesh_->getDim(), NO_INIT),
33
      neighbourCoord_(mesh_->getDim(), NO_INIT),
34
      oppVertex_(mesh_->getDim(), NO_INIT),
35
      grdLambda_(mesh_->getDim(), NO_INIT),
36
      subElemCoords(NULL)
37
38
  {
    projection_.set(NULL);
39
40
41
42

    for (int i = 0; i < neighbourCoord_.getSize(); i++) {
      neighbourCoord_[i].init(mesh_->getDim());
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
43
44

    dimOfWorld = Global::getGeo(WORLD);
45
46
47
48
  }

  ElInfo::~ElInfo()
  {
49
50
51
    if (subElemCoords) {
      DELETE subElemCoords;
    }
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  }


  /****************************************************************************/
  /*  transform local coordintes l to world coordinates; if w is non NULL      */
  /*  store them at w otherwise return a pointer to some local static         */
  /*  area containing world coordintes                                        */
  /****************************************************************************/
  const WorldVector<double> *ElInfo::coordToWorld(const DimVec<double>& l, 
						  WorldVector<double>* w) const

  {
    int dim = l.getSize() - 1;

66
67
    static WorldVector<double> world;
    WorldVector<double> *ret = w ? w : &world;
68
    double c = l[0];
69

70
    for (int j = 0; j < dimOfWorld; j++)
Thomas Witkowski's avatar
Thomas Witkowski committed
71
      (*ret)[j] = c * coord_[0][j];
72
  
Thomas Witkowski's avatar
Thomas Witkowski committed
73
    int vertices = Global::getGeo(VERTEX, dim);
74

75
    for (int i = 1; i < vertices; i++) {
76
      c = l[i];
77
      for (int j = 0; j < dimOfWorld; j++)
Thomas Witkowski's avatar
Thomas Witkowski committed
78
	(*ret)[j] += c * coord_[i][j];
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
    }
    return ret;
  }

  /****************************************************************************/
  /*  compute volume of an element                                            */
  /****************************************************************************/

  double ElInfo::calcDet() const
  {
    testFlag(Mesh::FILL_COORDS);
    return calcDet(coord_);
  }

  double ElInfo::calcDet(const FixVec<WorldVector<double>, VERTEX> &coords)
  {
95
    FUNCNAME("ElInfo::calcDet()");
96
97
98
99

    int dim = coords.getSize() - 1;
    int dow = Global::getGeo(WORLD);

100
    TEST_EXIT_DBG(dim <= dow)("dim > dow\n");
101
102
103
104
105
106
107
108
109
110
111

    double det = 0.0;

    if (dim == 0)
      return 1.0;

    // dim = dim of world
    WorldVector<double> e1, e2, e3, v0;

    v0 = coords[0];

112
    for (int i = 0; i < dow; i++) {
113
      e1[i] = coords[1][i] - v0[i];
114
      if (dim > 1)
115
	e2[i] = coords[2][i] - v0[i];
116
      if (dim > 2)
117
118
119
	e3[i] = coords[3][i] - v0[i];
    }
  
Thomas Witkowski's avatar
Thomas Witkowski committed
120
    switch (dow) {
121
122
123
124
    case 1:
      det = coords[1][0] - coords[0][0];
      break;
    case 2:
125
      if (dim == 1) {
126
127
	det = norm(&e1);
      } else {
128
	det = e1[0] * e2[1] - e1[1] * e2[0];
129
130
131
132
133
      }
      break;
    case 3: 
      {
	WorldVector<double> n;
134
	
135
	if (dim > 1) {
Thomas Witkowski's avatar
Thomas Witkowski committed
136
137
138
	  n[0] = e1[1] * e2[2] - e1[2] * e2[1];
	  n[1] = e1[2] * e2[0] - e1[0] * e2[2];
	  n[2] = e1[0] * e2[1] - e1[1] * e2[0];
139
	}
140
	
141
	if (dim == 1) {
142
143
144
145
	  det = norm(&e1);
	} else if (dim == 2) {
	  det = norm(&n);
	} else if (dim == 3) {
146
	  det = n[0] * e3[0] + n[1] * e3[1] + n[2] * e3[2];
147
	} else
Thomas Witkowski's avatar
Thomas Witkowski committed
148
	  ERROR_EXIT("not yet for problem dimension = %d", dim);
149
150
	break;
      } 
151
    default:
Thomas Witkowski's avatar
Thomas Witkowski committed
152
      ERROR_EXIT("not yet for Global::getGeo(WORLD) = %d", dow);
153
    }
154
    
155
156
157
158
159
    return abs(det);
  }

  void ElInfo::testFlag(const Flag& flags) const
  {
160
    TEST_EXIT_DBG(fillFlag_.isSet(flags))("flag not set\n");
161
162
163
164
165
  }


  void ElInfo::fillDetGrdLambda() 
  { 
166
    if (fillFlag_.isSet(Mesh::FILL_GRD_LAMBDA)) {
167
168
      det_ = calcGrdLambda(grdLambda_);
    } else {
169
      if (fillFlag_.isSet(Mesh::FILL_DET)) {
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
	det_ = calcDet();
      }
    }
  }

  BoundaryType ElInfo::getBoundary(GeoIndex pos, int i)
  {
    static int indexOffset[3][3] = {
      { 0, 0, 0},
      { 3, 0, 0},
      {10, 4, 0}
    };

    int dim = mesh_->getDim();
    int posIndex = DIM_OF_INDEX(pos, dim);
185
    int offset = indexOffset[dim - 1][posIndex];
186
    
187
188
189
190
    return boundary_[offset + i];
  }

}