CompositeFEMOperator.cc 8.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


13
#include <boost/numeric/mtl/mtl.hpp>
14
#include "CompositeFEMOperator.h"
15
#include "OpenMP.h"
16
17
18
19
20
21
#include "SubElementAssembler.h"
#include "SubElInfo.h"
#include "SubPolytope.h"

void 
CompositeFEMOperator::getElementMatrix(const ElInfo *elInfo, 
22
				       ElementMatrix& userMat, 
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
				       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) {
Thomas Witkowski's avatar
Thomas Witkowski committed
67
    subElementAssembler = new SubElementAssembler(this, 
68
69
						  rowFeSpace, 
						  colFeSpace);
70
71
72
73
74
75
  }

  /**
   * Get intersection points.
   */
  intersecPoints = elLS->getElIntersecPoints();
Thomas Witkowski's avatar
Thomas Witkowski committed
76
  subPolytope = new SubPolytope(elInfo, 
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
				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");
  }

108
109
110
  ElementMatrix subPolMat1(subElementAssembler->getNRow(),
			   subElementAssembler->getNCol());
  set_to_zero(subPolMat1);
111
112
113
114
115
116
117
118
  subElementAssembler->getSubPolytopeMatrix(subPolytope,
					    subElementAssembler,
					    elInfo,
					    subPolMat1);  

  /**
   * Integration on second subpolytope produced by the intersection.
   */
119
120
121
122
123
124
  ElementMatrix elMat(subElementAssembler->getNRow(),
		      subElementAssembler->getNCol());
  set_to_zero(elMat);
  ElementMatrix subPolMat2(subElementAssembler->getNRow(),
			   subElementAssembler->getNCol());
  set_to_zero(subPolMat2);
125

126
127
  if (!assembler) {
    assembler =
128
      new StandardAssembler(this, NULL, NULL, NULL, NULL, rowFeSpace, colFeSpace);
129
130
131
132
133
134
135
136
137
138
  }

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

139
  assembler->calculateElementMatrix(elInfo, elMat, 1.0);
140
141
142
143
144
  subElementAssembler->getSubPolytopeMatrix(subPolytope,
					    subElementAssembler,
					    elInfo,
					    subPolMat2);

145
  elMat -= subPolMat2;
146
147

  // Get integral on element as sum of the two integrals on subpolytopes.
148
  elMat += subPolMat1;
149
150

  // Add integral to userMat.
151
  userMat += factor * elMat;
152

153
154
  // Free data
  delete subPolytope;
155
156
157
158
}

void 
CompositeFEMOperator::getElementVector(const ElInfo *elInfo, 
159
				       ElementVector& userVec, 
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
				       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) {
Thomas Witkowski's avatar
Thomas Witkowski committed
203
    subElementAssembler = new SubElementAssembler(this, 
204
205
						  rowFeSpace, 
						  colFeSpace);
206
207
208
209
210
211
  }

  /**
   * Get intersection points.
   */
  intersecPoints = elLS->getElIntersecPoints();
Thomas Witkowski's avatar
Thomas Witkowski committed
212
  subPolytope = new SubPolytope(elInfo, 
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
				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");
  }

244
245
  ElementVector subPolVec1(subElementAssembler->getNRow());
  set_to_zero(subPolVec1);
246
247
248
249
250
251
252
253
  subElementAssembler->getSubPolytopeVector(subPolytope,
					    subElementAssembler,
					    elInfo,
					    subPolVec1);  

  /**
   * Integration on second subpolytope produced by the intersection.
   */
254
255
256
257
  ElementVector elVec(subElementAssembler->getNRow());
  set_to_zero(elVec);
  ElementVector subPolVec2(subElementAssembler->getNRow());
  set_to_zero(subPolVec2);
258

259
260
  if (!assembler)
    assembler = 
261
      new StandardAssembler(this, NULL, NULL, NULL, NULL, rowFeSpace, colFeSpace);
262
263
264
265

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

270
  assembler->calculateElementVector(elInfo, elVec, 1.0);
271
272
273
274
275
  subElementAssembler->getSubPolytopeVector(subPolytope,
					    subElementAssembler,
					    elInfo,
					    subPolVec2);

276
  elVec -= subPolVec2;
277
278

  // Get integral on element as sum of the two integrals on subpolytopes.
279
  elVec += subPolVec1;
280
281

  // Add integral to userVec.
282
  userVec += factor * elVec;
283

284
285
  // Free data
  delete subPolytope;
286
}