CompositeFEMOperator.cc 9.1 KB
Newer Older
1
2
3
4
#include "CompositeFEMOperator.h"

#include "ElementMatrix.h"
#include "ElementVector.h"
5
#include "OpenMP.h"
6
7
8
9
10
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

#include "SubElementAssembler.h"
#include "SubElInfo.h"
#include "SubPolytope.h"

void 
CompositeFEMOperator::getElementMatrix(const ElInfo *elInfo, 
				       ElementMatrix *userMat, 
				       double factor)
{
  FUNCNAME("CompositeFEMOperator::getElementMatrix");

  VectorOfFixVecs<DimVec<double> > *intersecPoints = NULL;
  SubPolytope *subPolytope = NULL;
  double levelSetSubPolytope;
  ElementMatrix *elMat;
  ElementMatrix *subPolMat1;
  ElementMatrix *subPolMat2;
  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");
  }

  subPolMat1 = NEW ElementMatrix(subElementAssembler->getNRow(),
				 subElementAssembler->getNCol());
  subPolMat1->set(0.0);
  subElementAssembler->getSubPolytopeMatrix(subPolytope,
					    subElementAssembler,
					    elInfo,
					    subPolMat1);  

  /**
   * Integration on second subpolytope produced by the intersection.
   */
  elMat = NEW ElementMatrix(subElementAssembler->getNRow(),
			    subElementAssembler->getNCol());
  elMat->set(0.0);
  subPolMat2 = NEW ElementMatrix(subElementAssembler->getNRow(),
				 subElementAssembler->getNCol());
  subPolMat2->set(0.0);

120
121
122
123
124
  int myRank = omp_get_thread_num();

  if (!assembler[myRank]) {
    assembler[myRank] =
      NEW StandardAssembler(this, NULL, NULL, NULL, NULL, rowFESpace, colFESpace);
125
126
127
128
129
130
131
132
133
134
  }

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

135
  assembler[myRank]->calculateElementMatrix(elInfo, elMat, 1.0);
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
  subElementAssembler->getSubPolytopeMatrix(subPolytope,
					    subElementAssembler,
					    elInfo,
					    subPolMat2);

  axpy(-1.0, *subPolMat2, *elMat);

  // Get integral on element as sum of the two integrals on subpolytopes.
  axpy(1.0, *subPolMat1, *elMat);

  // Add integral to userMat.
  axpy(factor, *elMat, *userMat);

  /**
   * Free data.
   */
  DELETE subPolytope;
  DELETE elMat;
  DELETE subPolMat1;
  DELETE subPolMat2;

  return;
}

void 
CompositeFEMOperator::getElementVector(const ElInfo *elInfo, 
				       ElementVector *userVec, 
				       double factor)
{
  FUNCNAME("CompositeFEMOperator::getElementVector");

  VectorOfFixVecs<DimVec<double> >*intersecPoints = NULL;
  SubPolytope *subPolytope = NULL;
  double levelSetSubPolytope;
  ElementVector *elVec;
  ElementVector *subPolVec1;
  ElementVector *subPolVec2;
  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");
  }

  subPolVec1 = NEW ElementVector(subElementAssembler->getNRow());
  subPolVec1->set(0.0);
  subElementAssembler->getSubPolytopeVector(subPolytope,
					    subElementAssembler,
					    elInfo,
					    subPolVec1);  

  /**
   * Integration on second subpolytope produced by the intersection.
   */
  elVec = NEW ElementVector(subElementAssembler->getNRow());
  elVec->set(0.0);
  subPolVec2 = NEW ElementVector(subElementAssembler->getNRow());
  subPolVec2->set(0.0);

265
266
267
268
269
  int myRank = omp_get_thread_num();

  if (!assembler[myRank]) {
    assembler[myRank] = 
      NEW StandardAssembler(this, NULL, NULL, NULL, NULL, rowFESpace, colFESpace);
270
271
272
273
274
  }

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

279
  assembler[myRank]->calculateElementVector(elInfo, elVec, 1.0);
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
  subElementAssembler->getSubPolytopeVector(subPolytope,
					    subElementAssembler,
					    elInfo,
					    subPolVec2);

  axpy(-1.0, *subPolVec2, *elVec);

  // Get integral on element as sum of the two integrals on subpolytopes.
  axpy(1.0, *subPolVec1, *elVec);

  // Add integral to userVec.
  axpy(factor, *elVec, *userVec);

  /**
   * Free data.
   */
  DELETE subPolytope;
  DELETE elVec;
  DELETE subPolVec1;
  DELETE subPolVec2;

  return;
}