CompositeFEMOperator.cc 8.69 KB
Newer Older
1
#include <boost/numeric/mtl/mtl.hpp>
2
#include "CompositeFEMOperator.h"
3
#include "OpenMP.h"
4
5
6
7
8
9
#include "SubElementAssembler.h"
#include "SubElInfo.h"
#include "SubPolytope.h"

void 
CompositeFEMOperator::getElementMatrix(const ElInfo *elInfo, 
10
				       ElementMatrix& userMat, 
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
				       double factor)
{
  FUNCNAME("CompositeFEMOperator::getElementMatrix");

  VectorOfFixVecs<DimVec<double> > *intersecPoints = NULL;
  SubPolytope *subPolytope = NULL;
  double levelSetSubPolytope;
  DimVec<double> subElVertexBarCoords(elInfo->getMesh()->getDim());

  /**
   * Get element status. Does element lie completely inside the integration 
   * domain, completely outside of the integration domain or is it 
   * intersected by the boundary ?
   */
  elStatus = elLS->createElementLevelSet(elInfo);

  /**
   * element status == completely inside or outside  
   *                                       --->  take the "normal" 
   *                                             integration routine
   *                                             Operator::getElementMatrix
   * element status == lies on boundary  ---> integration on subpolytopes and 
   *                                          subelements
   */
  if (elStatus == ElementLevelSet::LEVEL_SET_INTERIOR  ||  
      elStatus == ElementLevelSet::LEVEL_SET_EXTERIOR) {

    elLS->setLevelSetDomain(elStatus);
    Operator::getElementMatrix(elInfo, userMat, factor);
    return;
  }

  /***************************************************************************
   * Integration on intersected element.
   *
   * The integral is calculated as the sum of integrals on the two 
   * subpolytopes given by the intersection. 
   * We only calculate the integral on one of the subpolytopes. The 
   * integral on the second subpolytope then is the difference between the 
   * integral on the complete element and the integral on the first 
   * subpolytope.
   */

  if(!subElementAssembler) {
    subElementAssembler = NEW SubElementAssembler(this, 
						  rowFESpace, 
						  colFESpace);
  }

  /**
   * Get intersection points.
   */
  intersecPoints = elLS->getElIntersecPoints();
  subPolytope = NEW SubPolytope(elInfo, 
				intersecPoints, 
				elLS->getNumElIntersecPoints());
  
  /**
   * Calculate integral on element.
   *
   * Whether a subpolytope lies inside or outside the integration domain is 
   * decided using the level set of the first vertex in the first subelement 
   * of the subpolytope. (The subelements of a subpolytope are created in 
   * such a way that this vertex always is a vertex of the element 
   * and not an intersection point. Thus the level set of this vertex really 
   * is unequal to zero.)
   */

  /**
   * Integration on subPolytope.
   */
  subElVertexBarCoords = subPolytope->getSubElement(0)->getLambda(0);
  levelSetSubPolytope = elLS->getVertexPos(
			(const DimVec<double>) subElVertexBarCoords);

  if (levelSetSubPolytope < 0) {
    elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_INTERIOR);
  }
  else if (levelSetSubPolytope > 0) {
    elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_EXTERIOR);
  }
  else {
    ERROR_EXIT("cannot get position of subpolytope\n");
  }

96
97
98
  ElementMatrix subPolMat1(subElementAssembler->getNRow(),
			   subElementAssembler->getNCol());
  set_to_zero(subPolMat1);
99
100
101
102
103
104
105
106
  subElementAssembler->getSubPolytopeMatrix(subPolytope,
					    subElementAssembler,
					    elInfo,
					    subPolMat1);  

  /**
   * Integration on second subpolytope produced by the intersection.
   */
107
108
109
110
111
112
  ElementMatrix elMat(subElementAssembler->getNRow(),
		      subElementAssembler->getNCol());
  set_to_zero(elMat);
  ElementMatrix subPolMat2(subElementAssembler->getNRow(),
			   subElementAssembler->getNCol());
  set_to_zero(subPolMat2);
113

114
115
116
117
118
  int myRank = omp_get_thread_num();

  if (!assembler[myRank]) {
    assembler[myRank] =
      NEW StandardAssembler(this, NULL, NULL, NULL, NULL, rowFESpace, colFESpace);
119
120
121
122
123
124
125
126
127
128
  }

  if (elLS->getLevelSetDomain() == 
      ElementLevelSet::LEVEL_SET_INTERIOR) {
    elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_EXTERIOR);
  }
  else {
    elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_INTERIOR);
  }

129
  assembler[myRank]->calculateElementMatrix(elInfo, elMat, 1.0);
130
131
132
133
134
  subElementAssembler->getSubPolytopeMatrix(subPolytope,
					    subElementAssembler,
					    elInfo,
					    subPolMat2);

135
  elMat -= subPolMat2;
136
137

  // Get integral on element as sum of the two integrals on subpolytopes.
138
  elMat += subPolMat1;
139
140

  // Add integral to userMat.
141
  userMat += factor * elMat;
142

143
144
  // Free data
  delete subPolytope;
145
146
147
148
}

void 
CompositeFEMOperator::getElementVector(const ElInfo *elInfo, 
149
				       ElementVector& userVec, 
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
				       double factor)
{
  FUNCNAME("CompositeFEMOperator::getElementVector");

  VectorOfFixVecs<DimVec<double> >*intersecPoints = NULL;
  SubPolytope *subPolytope = NULL;
  double levelSetSubPolytope;
  DimVec<double> subElVertexBarCoords(elInfo->getMesh()->getDim());

  /**
   * Get element status. Does element lie completely inside the integration 
   * domain, completely outside of the integration domain or is it 
   * intersected by the boundary ?
   */
  elStatus = elLS->createElementLevelSet(elInfo);

  /**
   * element status == completely inside or outside  
   *                                        --->  take the "normal" 
   *                                              integration routine  
   *                                              Operator::getElementVector
   * element status == lies on boundary  ---> integration on subpolytopes and 
   *                                          subelements
   */
  if (elStatus == ElementLevelSet::LEVEL_SET_INTERIOR  ||  
      elStatus == ElementLevelSet::LEVEL_SET_EXTERIOR) {

    elLS->setLevelSetDomain(elStatus);
    Operator::getElementVector(elInfo, userVec, factor);
    return;
  }

  /*********************************************************************************
   * Integration on intersected element.
   *
   * The integral is calculated as the sum of integrals on the two 
   * subpolytopes given by the intersection. 
   * We only calculate the integral on one of the subpolytopes. The integral 
   * on the second subpolytope then is the difference between the integral on 
   * the complete element and the integral on the first subpolytope.
   */

  if(!subElementAssembler) {
    subElementAssembler = NEW SubElementAssembler(this, 
						  rowFESpace, 
						  colFESpace);
  }

  /**
   * Get intersection points.
   */
  intersecPoints = elLS->getElIntersecPoints();
  subPolytope = NEW SubPolytope(elInfo, 
				intersecPoints, 
				elLS->getNumElIntersecPoints());

  /**
   * Calculate integral on element.
   *
   * Whether a subpolytope lies inside or outside the integration domain is 
   * decided using the level set of the first vertex in the first subelement 
   * of the subpolytope. (The subelements of a subpolytope are created in 
   * such a way that this vertex is always a vertex of the element and not 
   * an intersection point. Thus the level set of this vertex really is 
   * unequal to zero.)
   */

  /**
   * Integration on ubPolytope.
   */
  subElVertexBarCoords = subPolytope->getSubElement(0)->getLambda(0);
  levelSetSubPolytope = elLS->getVertexPos(
			(const DimVec<double>) subElVertexBarCoords);

  if (levelSetSubPolytope < 0) {
    elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_INTERIOR);
  }
  else if (levelSetSubPolytope > 0) {
    elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_EXTERIOR);
  }
  else {
    ERROR_EXIT("cannot get position of subpolytope\n");
  }

234
235
  ElementVector subPolVec1(subElementAssembler->getNRow());
  set_to_zero(subPolVec1);
236
237
238
239
240
241
242
243
  subElementAssembler->getSubPolytopeVector(subPolytope,
					    subElementAssembler,
					    elInfo,
					    subPolVec1);  

  /**
   * Integration on second subpolytope produced by the intersection.
   */
244
245
246
247
  ElementVector elVec(subElementAssembler->getNRow());
  set_to_zero(elVec);
  ElementVector subPolVec2(subElementAssembler->getNRow());
  set_to_zero(subPolVec2);
248

249
250
251
252
253
  int myRank = omp_get_thread_num();

  if (!assembler[myRank]) {
    assembler[myRank] = 
      NEW StandardAssembler(this, NULL, NULL, NULL, NULL, rowFESpace, colFESpace);
254
255
256
257
258
  }

  if (elLS->getLevelSetDomain() == 
      ElementLevelSet::LEVEL_SET_INTERIOR) {
    elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_EXTERIOR);
259
  } else {
260
261
262
    elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_INTERIOR);
  }

263
  assembler[myRank]->calculateElementVector(elInfo, elVec, 1.0);
264
265
266
267
268
  subElementAssembler->getSubPolytopeVector(subPolytope,
					    subElementAssembler,
					    elInfo,
					    subPolVec2);

269
  elVec -= subPolVec2;
270
271

  // Get integral on element as sum of the two integrals on subpolytopes.
272
  elVec += subPolVec1;
273
274

  // Add integral to userVec.
275
  userVec += factor * elVec;
276

277
278
  // Free data
  delete subPolytope;
279
}