ElInfo.cc 4.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#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 {

  int ElInfo::traverseId = -1;
  int ElInfo::traverseIdCounter = 0;

  ElInfo::ElInfo(Mesh *aMesh) 
    : mesh_(aMesh),
      element_(NULL),
      parent_(NULL),
      macroElement_(NULL),
      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),
30
      neighbourCoord_(mesh_->getDim(), NO_INIT),
31
      oppVertex_(mesh_->getDim(), NO_INIT),
32
      grdLambda_(mesh_->getDim(), NO_INIT) 
33
34
  {
    projection_.set(NULL);
35
36
37
38

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

    dimOfWorld = Global::getGeo(WORLD);
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  }

  ElInfo::~ElInfo()
  {
  }


  /****************************************************************************/
  /*  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;

59
    static WorldVector<double> world[4];
60
    WorldVector<double> *ret = w ? w : &world[omp_get_thread_num()];
61
    double c = l[0];
62

63
    for (int j = 0; j < dimOfWorld; j++)
Thomas Witkowski's avatar
Thomas Witkowski committed
64
      (*ret)[j] = c * coord_[0][j];
65
  
Thomas Witkowski's avatar
Thomas Witkowski committed
66
    int vertices = Global::getGeo(VERTEX, dim);
67

68
    for (int i = 1; i < vertices; i++) {
69
      c = l[i];
70
      for (int j = 0; j < dimOfWorld; j++)
Thomas Witkowski's avatar
Thomas Witkowski committed
71
	(*ret)[j] += c * coord_[i][j];
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
    }
    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)
  {
88
    FUNCNAME("ElInfo::calcDet()");
89
90
91
92

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

93
    TEST_EXIT_DBG(dim <= dow)("dim > dow\n");
94
95
96
97
98
99
100
101
102
103
104

    double det = 0.0;

    if (dim == 0)
      return 1.0;

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

    v0 = coords[0];

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

  void ElInfo::testFlag(const Flag& flags) const
  {
153
    TEST_EXIT_DBG(fillFlag_.isSet(flags))("flag not set\n");
154
155
156
157
158
  }


  void ElInfo::fillDetGrdLambda() 
  { 
159
    if (fillFlag_.isSet(Mesh::FILL_GRD_LAMBDA)) {
160
161
      det_ = calcGrdLambda(grdLambda_);
    } else {
162
      if (fillFlag_.isSet(Mesh::FILL_DET)) {
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
	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);
178
    int offset = indexOffset[dim - 1][posIndex];
179
    
180
181
182
183
    return boundary_[offset + i];
  }

}