ElInfo.cc 3.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#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 {

  ElInfo::ElInfo(Mesh *aMesh) 
    : mesh_(aMesh),
      element_(NULL),
      parent_(NULL),
      macroElement_(NULL),
22
      level(0),
23
      iChild(0),
24
25
26
27
28
      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),
29
      neighbourCoord_(mesh_->getDim(), NO_INIT),
30
      oppVertex_(mesh_->getDim(), NO_INIT),
Thomas Witkowski's avatar
Thomas Witkowski committed
31
      grdLambda(mesh_->getDim(), NO_INIT),
32
33
      refinementPath(0),
      refinementPathLength(0)
34
35
  {
    projection_.set(NULL);
36

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

    dimOfWorld = Global::getGeo(WORLD);
41
42
43
  }

  ElInfo::~ElInfo()
44
  {}
45

46
47
  void ElInfo::coordToWorld(const DimVec<double>& l, 
			    WorldVector<double>& w) const
48
49

  {
50
    double c = l[0];
51

52
    for (int j = 0; j < dimOfWorld; j++)
53
      w[j] = c * coord_[0][j];
54
  
55
    int vertices = Global::getGeo(VERTEX, l.getSize() - 1);
56

57
    for (int i = 1; i < vertices; i++) {
58
      c = l[i];
59
      for (int j = 0; j < dimOfWorld; j++)
60
	w[j] += c * coord_[i][j];
61
62
63
64
65
66
67
68
69
    }
  }

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

Thomas Witkowski's avatar
Thomas Witkowski committed
70
  double ElInfo::calcDet(const FixVec<WorldVector<double>, VERTEX> &coords) const
71
  {
72
    FUNCNAME("ElInfo::calcDet()");
73
74
75
76

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

77
    TEST_EXIT_DBG(dim <= dow)("dim > dow\n");
78
79
80
81
82
83

    double det = 0.0;

    if (dim == 0)
      return 1.0;

Thomas Witkowski's avatar
Thomas Witkowski committed
84
    switch (dow) {
85
86
87
88
    case 1:
      det = coords[1][0] - coords[0][0];
      break;
    case 2:
89
      if (dim == 1) {
Thomas Witkowski's avatar
Thomas Witkowski committed
90
91
92
93
94

	WorldVector<double> e1;

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

97
      } else {
Thomas Witkowski's avatar
Thomas Witkowski committed
98
99
100
101

	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]);

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

  void ElInfo::testFlag(const Flag& flags) const
  {
141
    TEST_EXIT_DBG(fillFlag_.isSet(flags))("flag not set\n");
142
143
144
145
146
  }


  void ElInfo::fillDetGrdLambda() 
  { 
147
    if (fillFlag_.isSet(Mesh::FILL_GRD_LAMBDA)) {
Thomas Witkowski's avatar
Thomas Witkowski committed
148
      det_ = calcGrdLambda(grdLambda);
149
    } else {
150
      if (fillFlag_.isSet(Mesh::FILL_DET))
151
152
153
154
155
156
157
158
159
160
161
162
163
164
	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);
165
    int offset = indexOffset[dim - 1][posIndex];
166
    
167
168
169
170
    return boundary_[offset + i];
  }

}