ElInfo.cc 3.75 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
  std::vector<std::map<unsigned long, mtl::dense2D<double> > > ElInfo::subElemMatrices(4);
18

19
  ElInfo::ElInfo(Mesh *aMesh) 
Thomas Witkowski's avatar
Thomas Witkowski committed
20
21
22
23
    : mesh(aMesh),
      element(NULL),
      parent(NULL),
      macroElement(NULL),
24
      level(0),
25
      elType(0),
26
      iChild(0),
Thomas Witkowski's avatar
Thomas Witkowski committed
27
28
29
30
31
32
33
34
      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),
      neighbourCoord(mesh->getDim(), NO_INIT),
      oppVertex(mesh->getDim(), NO_INIT),
      grdLambda(mesh->getDim(), NO_INIT),
35
36
      refinementPath(0),
      refinementPathLength(0)
37
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
38
    projection.set(NULL);
39

40
    for (int i = 0; i < neighbourCoord.getSize(); i++)
Thomas Witkowski's avatar
Thomas Witkowski committed
41
      neighbourCoord[i].init(mesh->getDim());
Thomas Witkowski's avatar
Thomas Witkowski committed
42
43

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

  ElInfo::~ElInfo()
47
  {}
48

49
50
  void ElInfo::coordToWorld(const DimVec<double>& l, 
			    WorldVector<double>& w) const
51
52

  {
53
54
    testFlag(Mesh::FILL_COORDS);

55
    double c = l[0];
56

57
    for (int j = 0; j < dimOfWorld; j++)
Thomas Witkowski's avatar
Thomas Witkowski committed
58
      w[j] = c * coord[0][j];
59
  
60
    int vertices = Global::getGeo(VERTEX, l.getSize() - 1);
61

62
    for (int i = 1; i < vertices; i++) {
63
      c = l[i];
64
      for (int j = 0; j < dimOfWorld; j++)
Thomas Witkowski's avatar
Thomas Witkowski committed
65
	w[j] += c * coord[i][j];
66
67
68
69
70
71
    }
  }

  double ElInfo::calcDet() const
  {
    testFlag(Mesh::FILL_COORDS);
Thomas Witkowski's avatar
Thomas Witkowski committed
72
    return calcDet(coord);
73
74
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
75
  double ElInfo::calcDet(const FixVec<WorldVector<double>, VERTEX> &coords) const
76
  {
77
    FUNCNAME("ElInfo::calcDet()");
78
79
80
81

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

82
    TEST_EXIT_DBG(dim <= dow)("dim > dow\n");
83
84
85
86
87
88

    double det = 0.0;

    if (dim == 0)
      return 1.0;

Thomas Witkowski's avatar
Thomas Witkowski committed
89
    switch (dow) {
90
91
92
93
    case 1:
      det = coords[1][0] - coords[0][0];
      break;
    case 2:
94
      if (dim == 1) {
Thomas Witkowski's avatar
Thomas Witkowski committed
95
96
97
98
99

	WorldVector<double> e1;

	e1[0] = coords[1][0] - coords[0][0];
	e1[1] = coords[1][1] - coords[0][1];
100
	det = norm(&e1);
Thomas Witkowski's avatar
Thomas Witkowski committed
101

102
      } else {
Thomas Witkowski's avatar
Thomas Witkowski committed
103
104
105
106

	det = (coords[1][0] - coords[0][0]) * (coords[2][1] - coords[0][1]) - 
	  (coords[1][1] - coords[0][1]) * (coords[2][0] - coords[0][0]);

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

Thomas Witkowski's avatar
Thomas Witkowski committed
144

145
  void ElInfo::testFlag(const Flag& flags) const
Thomas Witkowski's avatar
Thomas Witkowski committed
146
  {    
147
    TEST_EXIT_DBG(fillFlag.isSet(flags))("flag not set\n");
148
149
150
151
152
  }


  void ElInfo::fillDetGrdLambda() 
  { 
Thomas Witkowski's avatar
Thomas Witkowski committed
153
154
    if (fillFlag.isSet(Mesh::FILL_GRD_LAMBDA)) {
      det = calcGrdLambda(grdLambda);
155
    } else {
Thomas Witkowski's avatar
Thomas Witkowski committed
156
157
      if (fillFlag.isSet(Mesh::FILL_DET))
	det = calcDet();
158
159
160
161
162
163
164
165
166
167
168
    }
  }

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

Thomas Witkowski's avatar
Thomas Witkowski committed
169
    int dim = mesh->getDim();
170
    int posIndex = DIM_OF_INDEX(pos, dim);
171
    int offset = indexOffset[dim - 1][posIndex];
172
    
Thomas Witkowski's avatar
Thomas Witkowski committed
173
    return boundary[offset + i];
174
175
176
  }

}