Operator.cc 96 KB
Newer Older
1
2
3
4
5
6
#include "Operator.h"
#include "ElInfo.h"
#include "Assembler.h"
#include "FixVec.h"
#include "DOFVector.h"
#include "Quadrature.h"
7
#include "OpenMP.h"
8
9
10
11
12
13
14
15
16
17
18
19

namespace AMDiS {

  const Flag OperatorTerm::PW_CONST = 1;
  const Flag OperatorTerm::SYMMETRIC = 2;

  const Flag Operator::MATRIX_OPERATOR = 1;
  const Flag Operator::VECTOR_OPERATOR = 2;


  int Operator::getQuadratureDegree(int order, FirstOrderType firstOrderType) 
  {
20
    std::vector<OperatorTerm*>* terms = NULL;
21
    int myRank = omp_get_thread_num();
22
23
24

    switch(order) {
    case 0:
25
      terms = &zeroOrder[myRank];
26
27
28
      break;
    case 1:
      if (firstOrderType == GRD_PHI)
29
	terms = &firstOrderGrdPhi[myRank];
30
      else 
31
	terms = &firstOrderGrdPsi[myRank];
32
33
      break;
    case 2:
34
      terms = &secondOrder[myRank];
35
36
37
38
39
40
41
42
43
44
      break;
    }

    const BasisFunction *psi = rowFESpace->getBasisFcts();
    const BasisFunction *phi = colFESpace->getBasisFcts();

    int psiDegree = psi->getDegree();
    int phiDegree = phi->getDegree();
    int maxTermDegree = 0;

Thomas Witkowski's avatar
Thomas Witkowski committed
45
    for (int i = 0; i < static_cast<int>(terms->size()); i++) {
46
47
48
      OperatorTerm *term = (*terms)[i];
      maxTermDegree = max(maxTermDegree, term->degree);
    }
49
50
   
    return psiDegree + phiDegree - order + maxTermDegree;
51
52
53
54
55
  }


  void OperatorTerm::setSymmetric(bool symm)
  {
56
    if (symm)
57
      properties.setFlag(SYMMETRIC);
58
59
    else
      properties.unsetFlag(SYMMETRIC);       
60
61
62
63
64
65
66
  }

  bool OperatorTerm::isSymmetric()
  {
    return properties.isSet(SYMMETRIC);
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
67
68
69
70
71
72
73
  double *OperatorTerm::getVectorAtQPs(DOFVectorBase<double>* vec,
				       const ElInfo* elInfo, 
				       SubAssembler* subAssembler,
				       Quadrature *quad)
  {
    FUNCNAME("OperatorTerm::getVectorAtQPs()");

74
    TEST_EXIT_DBG(elInfo->getMesh() == vec->getFESpace()->getMesh())
Thomas Witkowski's avatar
Thomas Witkowski committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
      ("There is something wrong!\n");
      
    return subAssembler->getVectorAtQPs(vec, elInfo, quad);
  }

  double *OperatorTerm::getVectorAtQPs(DOFVectorBase<double>* vec,
				       const ElInfo* smallElInfo, 
				       const ElInfo* largeElInfo, 
				       SubAssembler* subAssembler,
				       Quadrature *quad)
  {
    FUNCNAME("OperatorTerm::getVectorAtQPs()");

    TEST_EXIT(smallElInfo->getMesh() == vec->getFESpace()->getMesh() ||
	      largeElInfo->getMesh() == vec->getFESpace()->getMesh())
      ("There is something wrong!\n");

    if (smallElInfo->getLevel() == largeElInfo->getLevel()) {

      // Both elements have the same size, so we can use the simple procedure
      // to determine the vecAtQPs.
      
97
      if (vec->getFESpace()->getMesh() == smallElInfo->getMesh())
Thomas Witkowski's avatar
Thomas Witkowski committed
98
	return subAssembler->getVectorAtQPs(vec, smallElInfo, quad);
99
100
      else
	return subAssembler->getVectorAtQPs(vec, largeElInfo, quad);      
Thomas Witkowski's avatar
Thomas Witkowski committed
101
102
103
104
105
106

    } else {

      // The two elements are different. If the vector is defined on the mesh of the
      // small element, we can still use the simple procedure to determine the vecAtQPs.

107
      if (vec->getFESpace()->getMesh() == largeElInfo->getMesh())
Thomas Witkowski's avatar
Thomas Witkowski committed
108
	return subAssembler->getVectorAtQPs(vec, smallElInfo, largeElInfo, quad);
109
      else
Thomas Witkowski's avatar
Thomas Witkowski committed
110
111
112
113
114
115
116
117
118
119
120
	return subAssembler->getVectorAtQPs(vec, smallElInfo, quad);
    }
  }

  WorldVector<double>* OperatorTerm::getGradientsAtQPs(DOFVectorBase<double>* vec,
						       const ElInfo* elInfo,
						       SubAssembler* subAssembler,
						       Quadrature *quad)
  {
    FUNCNAME("OperatorTerm::getGradientsAtQPs()");

Thomas Witkowski's avatar
Thomas Witkowski committed
121
    TEST_EXIT_DBG(elInfo->getMesh() == vec->getFESpace()->getMesh())
Thomas Witkowski's avatar
Thomas Witkowski committed
122
123
124
125
126
127
128
129
130
131
132
133
134
      ("There is something wrong!\n");

    return subAssembler->getGradientsAtQPs(vec, elInfo, quad);
  }

  WorldVector<double>* OperatorTerm::getGradientsAtQPs(DOFVectorBase<double>* vec,
						       const ElInfo* smallElInfo, 
						       const ElInfo* largeElInfo,
						       SubAssembler* subAssembler,
						       Quadrature *quad)
  {
    FUNCNAME("OperatorTerm::getGradientsAtQPs()");

135
136
    ERROR_EXIT("Not yet tested!\n");

Thomas Witkowski's avatar
Thomas Witkowski committed
137
138
139
140
141
142
143
144
145
    TEST_EXIT(smallElInfo->getMesh() == vec->getFESpace()->getMesh() ||
	      largeElInfo->getMesh() == vec->getFESpace()->getMesh())
      ("There is something wrong!\n");

    if (smallElInfo->getLevel() == largeElInfo->getLevel()) {

      // Both elements have the same size, so we can use the simple procedure
      // to determine the gradients.
      
146
      if (vec->getFESpace()->getMesh() == smallElInfo->getMesh())
Thomas Witkowski's avatar
Thomas Witkowski committed
147
	return subAssembler->getGradientsAtQPs(vec, smallElInfo, quad);
148
149
      else
	return subAssembler->getGradientsAtQPs(vec, largeElInfo, quad);      
Thomas Witkowski's avatar
Thomas Witkowski committed
150
151
152
153
154
155

    } else {

      // The two elements are different. If the vector is defined on the mesh of the
      // small element, we can still use the simple procedure to determine the gradients.

156
      if (vec->getFESpace()->getMesh() == largeElInfo->getMesh())
Thomas Witkowski's avatar
Thomas Witkowski committed
157
	return subAssembler->getGradientsAtQPs(vec, smallElInfo, largeElInfo, quad);
158
      else
Thomas Witkowski's avatar
Thomas Witkowski committed
159
160
161
162
	return subAssembler->getGradientsAtQPs(vec, smallElInfo, quad);
    }
  }

163
  void OperatorTerm::lalt(const DimVec<WorldVector<double> >& Lambda,
164
165
166
			  const WorldMatrix<double>& matrix,
			  DimMat<double>& LALt,
			  bool symm,
167
			  double factor) const
168
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
169
    int j, k, l;
170
    const int dimOfWorld = Global::getGeo(WORLD);
171
    int dim = LALt.getNumRows() - 1;
172
173
174
  
    double val = 0.0;

175
    if (symm) {
Thomas Witkowski's avatar
Thomas Witkowski committed
176
      for (int i = 0; i <= dim; i++) {
177
178
179
	val = 0.0;
	for (k = 0; k < dimOfWorld; k++)
	  for (l = 0; l < dimOfWorld; l++)
180
181
182
	    val += Lambda[i][k] * matrix[k][l] * Lambda[i][l];
	val *= factor;
	LALt[i][i] += val;
183
	for (j = i + 1; j <= dim; j++) {
184
185
186
	  val = 0.0;
	  for (k = 0; k < dimOfWorld; k++)
	    for (l = 0; l < dimOfWorld; l++)
187
188
189
190
191
192
193
	      val += Lambda[i][k] * matrix[k][l] * Lambda[j][l];
	  val *= factor;
	  LALt[i][j] += val;
	  LALt[j][i] += val;
	}
      }    
    } else {	
Thomas Witkowski's avatar
Thomas Witkowski committed
194
      for (int i = 0; i <= dim; i++) {
195
	for (j = 0; j <= dim; j++) {
196
197
198
	  val = 0.0;
	  for (k = 0; k < dimOfWorld; k++)
	    for (l = 0; l < dimOfWorld; l++) 
199
200
201
202
203
204
205
206
207
208
	      val += Lambda[i][k] * matrix[k][l] * Lambda[j][l];
	  val *= factor;
	  LALt[i][j] += val;
	}
      }    
    }      
  }

  void OperatorTerm::lalt_kl(const DimVec<WorldVector<double> >& Lambda,
			     int k, int l,
Thomas Witkowski's avatar
Thomas Witkowski committed
209
210
			     DimMat<double>& LALt,
			     double factor)
211
212
213
  {
    int dim = LALt.getNumRows() - 1;

Thomas Witkowski's avatar
Thomas Witkowski committed
214
215
    for (int i = 0; i <= dim; i++)
      for (int j = 0; j <= dim; j++)
216
217
218
219
	LALt[i][j] += factor * Lambda[i][k] * Lambda[j][l];
  }

  Operator::Operator(Flag operatorType,
Thomas Witkowski's avatar
Thomas Witkowski committed
220
221
222
223
		     const FiniteElemSpace *row,
		     const FiniteElemSpace *col)
    : rowFESpace(row), 
      colFESpace(col ? col : row),
224
225
226
      type(operatorType), 
      fillFlag(Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS | 
	       Mesh::FILL_DET | Mesh::FILL_GRD_LAMBDA),
Thomas Witkowski's avatar
Thomas Witkowski committed
227
      needDualTraverse(false),
228
229
230
      uhOld(NULL),
      optimized(true)
  {
231
    int maxThreads = omp_get_overall_max_threads();
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246

    assembler.resize(maxThreads);
    secondOrder.resize(maxThreads);
    firstOrderGrdPsi.resize(maxThreads);
    firstOrderGrdPhi.resize(maxThreads);
    zeroOrder.resize(maxThreads);

    for (int i = 0; i < maxThreads; i++) {
      assembler[i] = NULL;
      secondOrder[i].resize(0);
      firstOrderGrdPsi[i].resize(0);
      firstOrderGrdPhi[i].resize(0);
      zeroOrder[i].resize(0);
    }

247
248
    nRow = rowFESpace->getBasisFcts()->getNumber();
    nCol = colFESpace->getBasisFcts()->getNumber();
Thomas Witkowski's avatar
Thomas Witkowski committed
249
  }
250

251
252

  void Operator::setUhOld(const DOFVectorBase<double> *vec)
253
  {
254
255
    uhOld = vec;
    auxFeSpaces.insert(vec->getFESpace());
256
257
  }

258

259
  void Operator::getElementMatrix(const ElInfo *elInfo, 
260
				  ElementMatrix& userMat, 
261
262
				  double factor)
  {
263
264
    int myRank = omp_get_thread_num();

265
    if (!assembler[myRank])
266
      initAssembler(myRank, NULL, NULL, NULL, NULL);
267

268
    assembler[myRank]->calculateElementMatrix(elInfo, userMat, factor);
269
270
  }

271

Thomas Witkowski's avatar
Thomas Witkowski committed
272
273
  void Operator::getElementMatrix(const ElInfo *rowElInfo, const ElInfo *colElInfo,
				  const ElInfo *smallElInfo, const ElInfo *largeElInfo,
274
				  ElementMatrix& userMat, 
275
276
277
278
				  double factor)
  {
    int myRank = omp_get_thread_num();

279
    if (!assembler[myRank])
280
281
282
      initAssembler(myRank, NULL, NULL, NULL, NULL);

    assembler[myRank]->calculateElementMatrix(rowElInfo, colElInfo, 
283
					      smallElInfo, largeElInfo,
284
285
286
    					      userMat, factor);
  }

287

288
  void Operator::getElementVector(const ElInfo *elInfo, 
289
				  ElementVector& userVec, 
290
291
				  double factor)
  {
292
293
    int myRank = omp_get_thread_num();

294
    if (!assembler[myRank])
295
      initAssembler(myRank, NULL, NULL, NULL, NULL);
296

297
    assembler[myRank]->calculateElementVector(elInfo, userVec, factor);
298
299
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
300
301
  void Operator::getElementVector(const ElInfo *mainElInfo, const ElInfo *auxElInfo,
				  const ElInfo *smallElInfo, const ElInfo *largeElInfo,
302
				  ElementVector& userVec,
Thomas Witkowski's avatar
Thomas Witkowski committed
303
304
305
306
				  double factor)
  {
    int myRank = omp_get_thread_num();

307
    if (!assembler[myRank])
Thomas Witkowski's avatar
Thomas Witkowski committed
308
309
310
311
312
313
314
      initAssembler(myRank, NULL, NULL, NULL, NULL);

    assembler[myRank]->calculateElementVector(mainElInfo, auxElInfo, 
					      smallElInfo, largeElInfo,
					      userVec, factor);
  }

315
316
  void Operator::initAssembler(int rank,
			       Quadrature *quad2,
317
318
319
			       Quadrature *quad1GrdPsi,
			       Quadrature *quad1GrdPhi,
			       Quadrature *quad0) 
320
  {    
321
322
323
324
#ifdef _OPENMP
#pragma omp critical (initAssembler)
#endif
      {
325
326
327
328
329
330
331
332
	if (optimized)
	  assembler[rank] = 
	    new OptimizedAssembler(this, quad2, quad1GrdPsi, quad1GrdPhi, quad0,
				   rowFESpace, colFESpace);
	else
	  assembler[rank] = 
	    new StandardAssembler(this, quad2, quad1GrdPsi, quad1GrdPhi, quad0,
				  rowFESpace, colFESpace);	
333
334
335
      }
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
336
337
338
339
340
  void Operator::finishAssembling()
  {
    assembler[omp_get_thread_num()]->finishAssembling();
  }

341

Thomas Witkowski's avatar
Thomas Witkowski committed
342
343
344
345
346
347
348

  VecAtQP_ZOT::VecAtQP_ZOT(DOFVectorBase<double> *dv,
			   AbstractFunction<double, double> *af)
    : ZeroOrderTerm(af ? af->getDegree() : 0), vec(dv), f(af)
  {
    TEST_EXIT(dv)("No vector!\n");

349
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
350
351
352
353
354
355
356
357
358
359
360
361
  }

  MultVecAtQP_ZOT::MultVecAtQP_ZOT(DOFVectorBase<double> *dv1,
				   DOFVectorBase<double> *dv2,
				   AbstractFunction<double, double> *af1,
				   AbstractFunction<double, double> *af2)
    : ZeroOrderTerm(af1->getDegree() + af2->getDegree()), 
      vec1(dv1), vec2(dv2), f1(af1), f2(af2)
  {
    TEST_EXIT(dv1)("No first vector!\n");
    TEST_EXIT(dv2)("No second vector!\n");

362
363
    auxFeSpaces.insert(dv1->getFESpace());
    auxFeSpaces.insert(dv2->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
364
365
366
367
368
369
370
371
372
373
  }

  Vec2AtQP_ZOT::Vec2AtQP_ZOT(DOFVectorBase<double> *dv1,
			     DOFVectorBase<double> *dv2,
			     BinaryAbstractFunction<double, double, double> *af)
    : ZeroOrderTerm(af->getDegree()), vec1(dv1), vec2(dv2), f(af)
  {
    TEST_EXIT(dv1)("No first vector!\n");
    TEST_EXIT(dv2)("No second vector!\n");

374
375
    auxFeSpaces.insert(dv1->getFESpace());
    auxFeSpaces.insert(dv2->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
376
377
378
379
380
381
382
383
384
385
386
387
  }

  Vec3AtQP_ZOT::Vec3AtQP_ZOT(DOFVectorBase<double> *dv1,
			     DOFVectorBase<double> *dv2,
			     DOFVectorBase<double> *dv3,
			     TertiaryAbstractFunction<double, double, double, double> *af)
    : ZeroOrderTerm(af->getDegree()), vec1(dv1), vec2(dv2), vec3(dv3), f(af)
  {
    TEST_EXIT(dv1)("No first vector!\n");
    TEST_EXIT(dv2)("No second vector!\n");
    TEST_EXIT(dv3)("No thierd vector!\n");

388
389
390
    auxFeSpaces.insert(dv1->getFESpace());
    auxFeSpaces.insert(dv2->getFESpace());
    auxFeSpaces.insert(dv3->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
391
392
393
394
395
396
397
398
  }

  FctGradientCoords_ZOT::FctGradientCoords_ZOT(DOFVectorBase<double> *dv,
					       BinaryAbstractFunction<double, WorldVector<double>, WorldVector<double> > *af)
    : ZeroOrderTerm(af->getDegree()), vec(dv), f(af)
  {
    TEST_EXIT(dv)("No vector!\n");

399
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
400
401
402
403
404
405
406
407
  }

  VecGradCoordsAtQP_ZOT::VecGradCoordsAtQP_ZOT(DOFVectorBase<double> *dv,
					       TertiaryAbstractFunction<double, double, WorldVector<double>, WorldVector<double> > *af)
    : ZeroOrderTerm(af->getDegree()), vec(dv), f(af) 
  {
    TEST_EXIT(dv)("No vector!\n");

408
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
409
410
411
412
413
414
415
416
  }

  VecAndCoordsAtQP_ZOT::VecAndCoordsAtQP_ZOT(DOFVectorBase<double> *dv,
					     BinaryAbstractFunction<double, double, WorldVector<double> > *af)
    : ZeroOrderTerm(af->getDegree()), vec(dv), f(af) 
  {
    TEST_EXIT(dv)("No vector!\n");

417
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
418
419
420
421
422
423
424
425
426
  }

  Vec2AndGradAtQP_ZOT::Vec2AndGradAtQP_ZOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2,
					   TertiaryAbstractFunction<double, double, WorldVector<double>, double > *af)
    : ZeroOrderTerm(af->getDegree()), vec1(dv1), vec2(dv2), f(af) 
  {
    TEST_EXIT(dv1)("No first vector!\n");
    TEST_EXIT(dv2)("No second vector!\n");

427
428
    auxFeSpaces.insert(dv1->getFESpace());
    auxFeSpaces.insert(dv2->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
429
430
431
432
433
434
435
436
  }

  FctGradient_ZOT::FctGradient_ZOT(DOFVectorBase<double> *dv,
				   AbstractFunction<double, WorldVector<double> > *af)
    : ZeroOrderTerm(af->getDegree()), vec(dv), f(af)
  {
    TEST_EXIT(dv)("No vector!\n");

437
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
438
439
440
441
442
443
444
445
  }

  VecAndGradAtQP_ZOT::VecAndGradAtQP_ZOT(DOFVectorBase<double> *dv,
					 BinaryAbstractFunction<double, double, WorldVector<double> > *af)
    : ZeroOrderTerm(af->getDegree()), vec(dv), f(af) 
  {
    TEST_EXIT(dv)("No vector!\n");

446
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
447
448
449
450
451
452
453
454
455
456
  }

  VecAndGradVecAtQP_ZOT::VecAndGradVecAtQP_ZOT(DOFVectorBase<double> *dv, 
					       DOFVectorBase<double> *dGrd,
					       BinaryAbstractFunction<double, double, WorldVector<double> > *af) 
    : ZeroOrderTerm(af->getDegree()), vec(dv), vecGrd(dGrd), f(af) 
  {
    TEST_EXIT(dv)("No vector!\n");
    TEST_EXIT(dGrd)("No gradient vector!\n");

457
458
    auxFeSpaces.insert(dv->getFESpace());
    auxFeSpaces.insert(dGrd->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
459
460
461
462
463
464
465
466
467
468
469
470
  }

  VecAndGradVec2AtQP_ZOT::VecAndGradVec2AtQP_ZOT(DOFVectorBase<double> *dv, 
						 DOFVectorBase<double> *dGrd1, 
						 DOFVectorBase<double> *dGrd2, 
						 TertiaryAbstractFunction<double, double, WorldVector<double>, WorldVector<double> > *af) 
    : ZeroOrderTerm(af->getDegree()), vec(dv), vecGrd1(dGrd1), vecGrd2(dGrd2), f(af) 
  {
    TEST_EXIT(dv)("No vector!\n");
    TEST_EXIT(dGrd1)("No first gradient vector!\n");
    TEST_EXIT(dGrd2)("No second gradient vector!\n");

471
472
473
    auxFeSpaces.insert(dv->getFESpace());
    auxFeSpaces.insert(dGrd1->getFESpace());
    auxFeSpaces.insert(dGrd2->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
474
475
476
477
478
479
480
481
482
483
484
  }

  VecOfDOFVecsAtQP_ZOT::VecOfDOFVecsAtQP_ZOT(const std::vector<DOFVectorBase<double>*>& dv, 
					     AbstractFunction<double, std::vector<double> > *af)
    : ZeroOrderTerm(af->getDegree()), vecs(dv), f(af) 
  {
    vecsAtQPs.resize(vecs.size());

    for (int i = 0; i < static_cast<int>(dv.size()); i++) {
      TEST_EXIT(dv[i])("One vector is NULL!\n");

485
      auxFeSpaces.insert(dv[i]->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
486
487
488
489
490
491
492
493
494
495
496
497
    }
  } 

  VecOfGradientsAtQP_ZOT::VecOfGradientsAtQP_ZOT(const std::vector<DOFVectorBase<double>*>& dv,
						 AbstractFunction<double, std::vector<WorldVector<double>*> > *af) 
    : ZeroOrderTerm(af->getDegree()), vecs(dv), f(af) 
  {
    gradsAtQPs.resize(vecs.size());

    for (int i = 0; i < static_cast<int>(dv.size()); i++) {
      TEST_EXIT(dv[i])("One vector is NULL!\n");

498
      auxFeSpaces.insert(dv[i]->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
    }
  } 

  VecDivergence_ZOT::VecDivergence_ZOT(int nComponents,
				       DOFVectorBase<double> *vec0,
				       DOFVectorBase<double> *vec1,
				       DOFVectorBase<double> *vec2)
    : ZeroOrderTerm(0)
  {
    vecs.resize(nComponents);
    gradsAtQPs.resize(nComponents);
    vecs[0] = vec0;
    vecs[1] = vec1;
    vecs[2] = vec2;

514
    auxFeSpaces.insert(vec0->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
515
    if (vec1) 
516
      auxFeSpaces.insert(vec1->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
517
    if (vec2) 
518
      auxFeSpaces.insert(vec2->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
519
520
521
522
523
524
525
526
527
528
529
530
  }


  VecAndVecOfGradientsAtQP_ZOT::VecAndVecOfGradientsAtQP_ZOT(DOFVector<double> *v,
							     const std::vector<DOFVector<double>*>& dv,
							     BinaryAbstractFunction<double, double, std::vector<WorldVector<double>*> > *af)
    : ZeroOrderTerm(af->getDegree()), vec(v), vecs(dv), f(af)
  {
    gradsAtQPs.resize(vecs.size());

    TEST_EXIT(v)("No vector!\n");

531
    auxFeSpaces.insert(v->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
532
533
534
    for (int i = 0; i < static_cast<int>(dv.size()); i++) {
      TEST_EXIT(dv[i])("One gradient vector is NULL!\n");

535
      auxFeSpaces.insert(dv[i]->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
536
537
538
    }
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
539
540
541
542
543
544
545
546
547

  Vec2AndGrad2AtQP_ZOT::Vec2AndGrad2AtQP_ZOT(DOFVectorBase<double> *dv1, 
					     DOFVectorBase<double> *dv2,
					     QuartAbstractFunction<double, double, double, WorldVector<double>,WorldVector<double> > *af)
    : ZeroOrderTerm(af->getDegree()), vec1(dv1), vec2(dv2), f(af) 
  {
    TEST_EXIT(dv1)("No first vector!\n");
    TEST_EXIT(dv2)("No second vector!\n");
    
548
549
    auxFeSpaces.insert(dv1->getFESpace());
    auxFeSpaces.insert(dv2->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
  }

  void Vec2AndGrad2AtQP_ZOT::initElement(const ElInfo* elInfo, 
					 SubAssembler* subAssembler,
					 Quadrature *quad) 
  {
    vecAtQPs1 = getVectorAtQPs(vec1, elInfo, subAssembler, quad);
    vecAtQPs2 = getVectorAtQPs(vec2, elInfo, subAssembler, quad);
    gradAtQPs1 = getGradientsAtQPs(vec1, elInfo, subAssembler, quad);
    gradAtQPs2 = getGradientsAtQPs(vec2, elInfo, subAssembler, quad);
  }
  
  
  void Vec2AndGrad2AtQP_ZOT::eval(int nPoints,
				  const double *uhAtQP,
				  const WorldVector<double> *grdUhAtQP,
				  const WorldMatrix<double> *D2UhAtQP,
				  double *result,
Thomas Witkowski's avatar
Thomas Witkowski committed
568
				  double fac) 
Thomas Witkowski's avatar
Thomas Witkowski committed
569
570
571
  {
    for (int iq = 0; iq < nPoints; iq++)
      result[iq] += 
Thomas Witkowski's avatar
Thomas Witkowski committed
572
	fac * (*f)(vecAtQPs1[iq], vecAtQPs2[iq], gradAtQPs1[iq], gradAtQPs2[iq]) * 
Thomas Witkowski's avatar
Thomas Witkowski committed
573
574
575
	uhAtQP[iq];
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
576
  void Vec2AndGrad2AtQP_ZOT::getC(const ElInfo *, int nPoints, std::vector<double> &C)  
Thomas Witkowski's avatar
Thomas Witkowski committed
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
  { 
    for (int iq = 0; iq < nPoints; iq++)
      C[iq] += (*f)(vecAtQPs1[iq], vecAtQPs2[iq], gradAtQPs1[iq], gradAtQPs2[iq]);
  }

  Vec2AndGradVecAtQP_ZOT::Vec2AndGradVecAtQP_ZOT(DOFVectorBase<double> *dv1, 
						 DOFVectorBase<double> *dv2, 
						 DOFVectorBase<double> *dGrd,
						 TertiaryAbstractFunction<double, double,double, WorldVector<double> > *af) 
    : ZeroOrderTerm(af->getDegree()), vec1(dv1), vec2(dv2), vecGrd(dGrd), f(af) 
  {
    TEST_EXIT(dv1)("No vector!\n");
    TEST_EXIT(dv2)("No vector!\n");
    TEST_EXIT(dGrd)("No gradient vector!\n");
    
592
593
594
    auxFeSpaces.insert(dv1->getFESpace());
    auxFeSpaces.insert(dv2->getFESpace());
    auxFeSpaces.insert(dGrd->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
595
596
597
598
599
600
601
602
603
604
605
  }
  
  void Vec2AndGradVecAtQP_ZOT::initElement(const ElInfo* elInfo, 
					   SubAssembler* subAssembler,
					   Quadrature *quad) 
  {
    vec1AtQPs = getVectorAtQPs(vec1, elInfo, subAssembler, quad);
    vec2AtQPs = getVectorAtQPs(vec2, elInfo, subAssembler, quad);
    gradAtQPs = getGradientsAtQPs(vecGrd, elInfo, subAssembler, quad);
  }
  
Thomas Witkowski's avatar
Thomas Witkowski committed
606
  void Vec2AndGradVecAtQP_ZOT::getC(const ElInfo *, int nPoints, std::vector<double> &C)  
Thomas Witkowski's avatar
Thomas Witkowski committed
607
608
609
610
611
612
613
614
615
616
  { 
    for (int iq = 0; iq < nPoints; iq++)
      C[iq] += (*f)(vec1AtQPs[iq], vec2AtQPs[iq], gradAtQPs[iq]);
  }
  
  void Vec2AndGradVecAtQP_ZOT::eval(int nPoints,
				   const double *uhAtQP,
				   const WorldVector<double> *grdUhAtQP,
				   const WorldMatrix<double> *D2UhAtQP,
				   double *result,
Thomas Witkowski's avatar
Thomas Witkowski committed
617
				   double fac) 
Thomas Witkowski's avatar
Thomas Witkowski committed
618
619
620
621
622
623
  {
    for (int iq = 0; iq < nPoints; iq++)
      result[iq] += 
	fac * (*f)(vec1AtQPs[iq], vec2AtQPs[iq], gradAtQPs[iq]) * uhAtQP[iq];
  }
  
Thomas Witkowski's avatar
Thomas Witkowski committed
624
625
626
627
628
629
630
631
632
633
634
  General_ZOT::General_ZOT(std::vector<DOFVectorBase<double>*> vecs,
			   std::vector<DOFVectorBase<double>*> grads,
			   TertiaryAbstractFunction<double, WorldVector<double>, std::vector<double>, std::vector<WorldVector<double> > > *af)
    : ZeroOrderTerm(af->getDegree()), vecs_(vecs), grads_(grads), f_(af)
  {
    vecsAtQPs_.resize(vecs_.size());
    gradsAtQPs_.resize(grads_.size());

    for (int i = 0; i < static_cast<int>(vecs.size()); i++) {
      TEST_EXIT(vecs[i])("One vector is NULL!\n");

635
      auxFeSpaces.insert(vecs[i]->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
636
637
638
639
640
    }   

    for (int i = 0; i < static_cast<int>(grads.size()); i++) {
      TEST_EXIT(grads[i])("One gradient vector is NULL!\n");

641
      auxFeSpaces.insert(grads[i]->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
642
    }   
Thomas Witkowski's avatar
Thomas Witkowski committed
643
644
645

    vecsArg.resize(vecs_.size());
    gradsArg.resize(grads_.size());
Thomas Witkowski's avatar
Thomas Witkowski committed
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
  }

  GeneralParametric_ZOT::GeneralParametric_ZOT(std::vector<DOFVectorBase<double>*> vecs,
					       std::vector<DOFVectorBase<double>*> grads,
					       QuartAbstractFunction<double, 
					       WorldVector<double>,
					       WorldVector<double>,
					       std::vector<double>, 
					       std::vector<WorldVector<double> > > *af)
    : ZeroOrderTerm(af->getDegree()), vecs_(vecs), grads_(grads), f_(af)
  {
    vecsAtQPs_.resize(vecs_.size());
    gradsAtQPs_.resize(grads_.size());

    for (int i = 0; i < static_cast<int>(vecs.size()); i++) {
      TEST_EXIT(vecs[i])("One vector is NULL!\n");

663
      auxFeSpaces.insert(vecs[i]->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
664
665
666
667
668
    }   

    for (int i = 0; i < static_cast<int>(grads.size()); i++) {
      TEST_EXIT(grads[i])("One gradient vector is NULL!\n");

669
      auxFeSpaces.insert(grads[i]->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
670
671
672
673
674
675
676
677
678
679
    }   
  }

  VecAtQP_FOT::VecAtQP_FOT(DOFVectorBase<double> *dv,
			   AbstractFunction<double, double> *af,
			   WorldVector<double> *wv)
    : FirstOrderTerm(af->getDegree()), vec(dv), f(af), b(wv)
  {
    TEST_EXIT(dv)("No vector!\n");

680
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
681
682
  }

683
684
685
686
687
688
689
690
  VecAtQP_FOT::VecAtQP_FOT(DOFVectorBase<double> *dv,
			   AbstractFunction<double, double> *af,
			   int bIdx)
    : FirstOrderTerm(af->getDegree()), vec(dv), f(af)
  {
    TEST_EXIT(dv)("No vector!\n");

    bOne = bIdx;
691
    auxFeSpaces.insert(dv->getFESpace());
692
693
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
694
695
696
697
698
699
  VectorGradient_FOT::VectorGradient_FOT(DOFVectorBase<double> *dv,
					 AbstractFunction<WorldVector<double>, WorldVector<double> > *af)
    : FirstOrderTerm(af->getDegree()), vec(dv), f(af)
  {
    TEST_EXIT(dv)("No vector!\n");

700
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
701
702
703
704
705
706
707
708
  }

  VectorFct_FOT::VectorFct_FOT(DOFVectorBase<double> *dv,
			       AbstractFunction<WorldVector<double>, double> *fct)
    : FirstOrderTerm(fct->getDegree()), vec(dv), vecFct(fct) 
  {
    TEST_EXIT(dv)("No vector!\n");

709
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
710
711
712
713
714
715
716
717
718
  }

  VecGrad_FOT::VecGrad_FOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2,
			   BinaryAbstractFunction<WorldVector<double>, double, WorldVector<double> > *fct)
    : FirstOrderTerm(fct->getDegree()), vec1(dv1), vec2(dv2), vecFct(fct) 
  {
    TEST_EXIT(dv1)("No first vector!\n");
    TEST_EXIT(dv2)("No second vector!\n");

719
720
    auxFeSpaces.insert(dv1->getFESpace());
    auxFeSpaces.insert(dv2->getFESpace());    
Thomas Witkowski's avatar
Thomas Witkowski committed
721
722
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
723
724
725
  Vec2AndGradAtQP_FOT::Vec2AndGradAtQP_FOT(DOFVectorBase<double> *dv1, 
					   DOFVectorBase<double> *dv2,
					   TertiaryAbstractFunction<double, double, double, WorldVector<double> > *f_, WorldVector<double> *b_)
726
    : FirstOrderTerm(f_->getDegree()), 
Thomas Witkowski's avatar
Thomas Witkowski committed
727
728
729
730
731
      vec1(dv1), 
      vec2(dv2), 
      f(f_), 
      b(b_)
  {   
732
733
    auxFeSpaces.insert(dv1->getFESpace()); 
    auxFeSpaces.insert(dv2->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
  }

  void Vec2AndGradAtQP_FOT::initElement(const ElInfo* elInfo, 
					SubAssembler* subAssembler,
					Quadrature *quad) 
  { 
    vec1AtQPs = subAssembler->getVectorAtQPs(vec1, elInfo, quad);
    vec2AtQPs = subAssembler->getVectorAtQPs(vec2, elInfo, quad);
    gradAtQPs1 = getGradientsAtQPs(vec1, elInfo, subAssembler, quad);
  }
  
  
  void Vec2AndGradAtQP_FOT::getLb(const ElInfo *elInfo, int nPoints, VectorOfFixVecs<DimVec<double> >& Lb) const {
    const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();
    for (int iq = 0; iq < nPoints; iq++) {
      if (b)
	lb(Lambda, *b, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq],gradAtQPs1[iq]));
      else
	l1(Lambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq], gradAtQPs1[iq]));
    }
  }
  
  void Vec2AndGradAtQP_FOT::eval(int nPoints,
				 const double *uhAtQP,
				 const WorldVector<double> *grdUhAtQP,
				 const WorldMatrix<double> *D2UhAtQP,
				 double *result,
Thomas Witkowski's avatar
Thomas Witkowski committed
761
				 double fac) 
Thomas Witkowski's avatar
Thomas Witkowski committed
762
763
764
765
766
767
768
769
  {   
    if (grdUhAtQP)
      for (int iq = 0; iq < nPoints; iq++)
	result[iq] += fac * 
	  (*f)(vec1AtQPs[iq], vec2AtQPs[iq], gradAtQPs1[iq]) * 
	  ((*b) * grdUhAtQP[iq]);
  }

770

Thomas Witkowski's avatar
Thomas Witkowski committed
771
  FctVecAtQP_FOT::FctVecAtQP_FOT(DOFVectorBase<double> *dv,
772
				 BinaryAbstractFunction<double, WorldVector<double>, double> *f_,
Thomas Witkowski's avatar
Thomas Witkowski committed
773
774
775
				 WorldVector<double> *b_)
    : FirstOrderTerm(f_->getDegree()), vec(dv), f(f_), b(b_)
  {
776
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
  }


  void FctVecAtQP_FOT::initElement(const ElInfo* elInfo, 
				   SubAssembler* subAssembler,
				   Quadrature *quad) 
  { 
    vecAtQPs = subAssembler->getVectorAtQPs(vec, elInfo, quad);
    coordsAtQPs = subAssembler->getCoordsAtQPs(elInfo, quad);
  }


  void FctVecAtQP_FOT::getLb(const ElInfo *elInfo, int nPoints, 
			     VectorOfFixVecs<DimVec<double> >& Lb) const 
  {
    const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();
    for (int iq = 0; iq < nPoints; iq++) {
      if (b)
795
	lb(Lambda, *b, Lb[iq], (*f)(coordsAtQPs[iq], vecAtQPs[iq]));
Thomas Witkowski's avatar
Thomas Witkowski committed
796
      else
797
	l1(Lambda, Lb[iq], (*f)(coordsAtQPs[iq], vecAtQPs[iq]));
Thomas Witkowski's avatar
Thomas Witkowski committed
798
799
800
801
    }
  }
  
  void FctVecAtQP_FOT::eval(int nPoints,
Thomas Witkowski's avatar
Thomas Witkowski committed
802
			    const double *uhAtQP,
Thomas Witkowski's avatar
Thomas Witkowski committed
803
804
805
			    const WorldVector<double> *grdUhAtQP,
			    const WorldMatrix<double> *D2UhAtQP,
			    double *result,
Thomas Witkowski's avatar
Thomas Witkowski committed
806
			    double fac) 
Thomas Witkowski's avatar
Thomas Witkowski committed
807
808
809
810
  {
    if (grdUhAtQP)
      for (int iq = 0; iq < nPoints; iq++)
	result[iq] += 
811
	  fac * (*f)(coordsAtQPs[iq], vecAtQPs[iq]) * ((*b) * grdUhAtQP[iq]);
Thomas Witkowski's avatar
Thomas Witkowski committed
812
813
814
  }

  Vec2AtQP_FOT::Vec2AtQP_FOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2,
815
			     BinaryAbstractFunction<double, double, double> *af,
Thomas Witkowski's avatar
Thomas Witkowski committed
816
			     WorldVector<double> *b_)
817
    : FirstOrderTerm(af->getDegree()), vec1(dv1), vec2(dv2), f(af), b(b_)
Thomas Witkowski's avatar
Thomas Witkowski committed
818
  {   
819
820
821
    TEST_EXIT(dv1)("No first vector!\n");
    TEST_EXIT(dv2)("No second vector!\n");

822
823
    auxFeSpaces.insert(dv1->getFESpace()); 
    auxFeSpaces.insert(dv2->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
824
825
  }

826
  Vec2AtQP_FOT::Vec2AtQP_FOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2,
827
			     BinaryAbstractFunction<double, double, double> *af,
828
			     int bIdx)
829
    : FirstOrderTerm(af->getDegree()), vec1(dv1), vec2(dv2), f(af)
830
  {   
831
832
833
    TEST_EXIT(dv1)("No first vector!\n");
    TEST_EXIT(dv2)("No second vector!\n");

834
    bOne = bIdx;
835
836
    auxFeSpaces.insert(dv1->getFESpace()); 
    auxFeSpaces.insert(dv2->getFESpace());
837
838
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
839
840
841
842
843
844
845
846
  void Vec2AtQP_FOT::initElement(const ElInfo* elInfo, 
				 SubAssembler* subAssembler,
				 Quadrature *quad) 
  { 
    vec1AtQPs = subAssembler->getVectorAtQPs(vec1, elInfo, quad);
    vec2AtQPs = subAssembler->getVectorAtQPs(vec2, elInfo, quad);
  }
    
847
848
  void Vec2AtQP_FOT::getLb(const ElInfo *elInfo, int nPoints, 
			   VectorOfFixVecs<DimVec<double> >& Lb) const 
Thomas Witkowski's avatar
Thomas Witkowski committed
849
850
  {
    const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();
851
852
853

    if (bOne > -1) {
      for (int iq = 0; iq < nPoints; iq++)
854
	lb_one(Lambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq]));
855
856
    } else if (b) {
      for (int iq = 0; iq < nPoints; iq++)
857
	lb(Lambda, *b, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq]));
858
859
    } else {
      for (int iq = 0; iq < nPoints; iq++)
860
	l1(Lambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq]));
Thomas Witkowski's avatar
Thomas Witkowski committed
861
862
863
864
    }
  }
  
  void Vec2AtQP_FOT::eval(int nPoints,
865
			  const double *uhAtQP,
Thomas Witkowski's avatar
Thomas Witkowski committed
866
867
868
			  const WorldVector<double> *grdUhAtQP,
			  const WorldMatrix<double> *D2UhAtQP,
			  double *result,
Thomas Witkowski's avatar
Thomas Witkowski committed
869
			  double fac) 
Thomas Witkowski's avatar
Thomas Witkowski committed
870
871
872
  {
    if (grdUhAtQP)
      for (int iq = 0; iq < nPoints; iq++) 
873
	result[iq] += fac * (*f)(vec1AtQPs[iq], vec2AtQPs[iq]) * ((*b) * grdUhAtQP[iq]);
Thomas Witkowski's avatar
Thomas Witkowski committed
874
875
  }

876
877
878
879
880

  Vec3FctAtQP_FOT::Vec3FctAtQP_FOT(DOFVectorBase<double> *dv1, 
				   DOFVectorBase<double> *dv2, 
				   DOFVectorBase<double> *dv3,
				   TertiaryAbstractFunction<double, double, double, double> *f_,
881
				   WorldVector<double> *bvec)
882
    : FirstOrderTerm(f_->getDegree()), 
883
884
885
886
887
888
      vec1(dv1), 
      vec2(dv2), 
      vec3(dv3), 
      f(f_),
      b(bvec)
  { 
889
890
891
    auxFeSpaces.insert(dv1->getFESpace()); 
    auxFeSpaces.insert(dv2->getFESpace()); 
    auxFeSpaces.insert(dv3->getFESpace());   
892
893
  }

894
895
896
897
898

  Vec3FctAtQP_FOT::Vec3FctAtQP_FOT(DOFVectorBase<double> *dv1, 
				   DOFVectorBase<double> *dv2, 
				   DOFVectorBase<double> *dv3,
				   TertiaryAbstractFunction<double, double, double, double> *f_,
899
				   int b)
900
    : FirstOrderTerm(f_->getDegree()), 
901
902
903
904
      vec1(dv1), 
      vec2(dv2), 
      vec3(dv3), 
      f(f_)
Thomas Witkowski's avatar
Thomas Witkowski committed
905
  { 
906
    bOne = b;
907
908
909
    auxFeSpaces.insert(dv1->getFESpace()); 
    auxFeSpaces.insert(dv2->getFESpace()); 
    auxFeSpaces.insert(dv3->getFESpace());   
Thomas Witkowski's avatar
Thomas Witkowski committed
910
911
912
913
914
915
916
917
918
919
920
921
  }

  void Vec3FctAtQP_FOT::initElement(const ElInfo* elInfo, 
				    SubAssembler* subAssembler,
				    Quadrature *quad) 
  { 
    vec1AtQPs = subAssembler->getVectorAtQPs(vec1, elInfo, quad);
    vec2AtQPs = subAssembler->getVectorAtQPs(vec2, elInfo, quad);
    vec3AtQPs = subAssembler->getVectorAtQPs(vec3, elInfo, quad);
  }
  
  
922
923
  void Vec3FctAtQP_FOT::getLb(const ElInfo *elInfo, int nPoints, 
			      VectorOfFixVecs<DimVec<double> >& Lb) const 
Thomas Witkowski's avatar
Thomas Witkowski committed
924
925
  {
    const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();
926
927
    if (bOne > -1) {
      for (int iq = 0; iq < nPoints; iq++)
928
	lb_one(Lambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq], vec3AtQPs[iq]));
929
930
931
    } else {
      for (int iq = 0; iq < nPoints; iq++) {
	if (b)
932
	  lb(Lambda, *b, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq], vec3AtQPs[iq]));
933
	else
934
	  l1(Lambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq], vec3AtQPs[iq]));
935
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
936
937
938
    }
  }

939

Thomas Witkowski's avatar
Thomas Witkowski committed
940
  void Vec3FctAtQP_FOT::eval(int nPoints,
941
			     const double *uhAtQP,
Thomas Witkowski's avatar
Thomas Witkowski committed
942
943
944
			     const WorldVector<double> *grdUhAtQP,
			     const WorldMatrix<double> *D2UhAtQP,
			     double *result,
Thomas Witkowski's avatar
Thomas Witkowski committed
945
			     double fac) 
Thomas Witkowski's avatar
Thomas Witkowski committed
946
947
948
  {
    if (grdUhAtQP)
      for (int iq = 0; iq < nPoints; iq++)
949
	result[iq] += fac * (*f)(vec1AtQPs[iq], vec2AtQPs[iq] ,vec3AtQPs[iq]) * 
Thomas Witkowski's avatar
Thomas Witkowski committed
950
951
952
953
	  ((*b) * grdUhAtQP[iq]);
  }


Thomas Witkowski's avatar
Thomas Witkowski committed
954
955
956
957
958
959
960
961
962
963
964
965
966
967
  General_FOT::General_FOT(std::vector<DOFVectorBase<double>*> vecs,
			   std::vector<DOFVectorBase<double>*> grads,
			   TertiaryAbstractFunction<WorldVector<double>, 
			   WorldVector<double>,
			   std::vector<double>, 
			   std::vector<WorldVector<double> > > *af)
    : FirstOrderTerm(af->getDegree()), vecs_(vecs), grads_(grads), f_(af)
  {
    vecsAtQPs_.resize(vecs_.size());
    gradsAtQPs_.resize(grads_.size());

    for (int i = 0; i < static_cast<int>(vecs.size()); i++) {
      TEST_EXIT(vecs[i])("One vector is NULL!\n");

968
      auxFeSpaces.insert(vecs[i]->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
969
970
971
972
973
    }   

    for (int i = 0; i < static_cast<int>(grads.size()); i++) {
      TEST_EXIT(grads[i])("One gradient vector is NULL!\n");

974
      auxFeSpaces.insert(grads[i]->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
    }   
  }

  GeneralParametric_FOT::GeneralParametric_FOT(std::vector<DOFVectorBase<double>*> vecs,
					       std::vector<DOFVectorBase<double>*> grads,
					       QuartAbstractFunction<WorldVector<double>, 
					       WorldVector<double>,
					       WorldVector<double>,
					       std::vector<double>, 
					       std::vector<WorldVector<double> > > *af)
    : FirstOrderTerm(af->getDegree()), vecs_(vecs), grads_(grads), f_(af)
  {
    vecsAtQPs_.resize(vecs_.size());
    gradsAtQPs_.resize(grads_.size());

    for (int i = 0; i < static_cast<int>(vecs.size()); i++) {
      TEST_EXIT(vecs[i])("One vector is NULL!\n");

993
      auxFeSpaces.insert(vecs[i]->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
994
995
996
997
998
    }   

    for (int i = 0; i < static_cast<int>(grads.size()); i++) {
      TEST_EXIT(grads[i])("One gradient vector is NULL!\n");

999
      auxFeSpaces.insert(grads[i]->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
    }   
  }

  MatrixFct_SOT::MatrixFct_SOT(DOFVectorBase<double> *dv, 
			       AbstractFunction<WorldMatrix<double>, double> *fct,
			       AbstractFunction<WorldVector<double>, WorldMatrix<double> > *div,
			       bool sym)
    : SecondOrderTerm(fct->getDegree()), 
      vec(dv), 
      matrixFct(fct), 
      divFct(div),
      symmetric(sym)
  {
    setSymmetric(symmetric);

    TEST_EXIT(dv)("No vector!\n");

1017
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
  }

  VecAtQP_SOT::VecAtQP_SOT(DOFVectorBase<double> *dv, 
			   AbstractFunction<double, double> *af)
    : SecondOrderTerm(af->getDegree()), vec(dv), f(af)
  {
    setSymmetric(true);

    TEST_EXIT(dv)("No vector!\n");

1028
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
  }

  Vec2AtQP_SOT::Vec2AtQP_SOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2, 
			     BinaryAbstractFunction<double, double, double> *af)
    : SecondOrderTerm(af->getDegree()), vec1(dv1), vec2(dv2), f(af)
  {
    setSymmetric(true);

    TEST_EXIT(dv1)("No first vector!\n");
    TEST_EXIT(dv2)("No second vector!\n");

1040
1041
    auxFeSpaces.insert(dv1->getFESpace());
    auxFeSpaces.insert(dv2->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
1042
1043
1044
1045
1046
1047
  }

  MatrixGradient_SOT::MatrixGradient_SOT(DOFVectorBase<double> *dv,
					 AbstractFunction<WorldMatrix<double>, WorldVector<double> > *af,
					 AbstractFunction<WorldVector<double>, WorldMatrix<double> > *divAf,
					 bool symm) 
1048
1049
1050
1051
1052
1053
    : SecondOrderTerm(af->getDegree()), 
      vec(dv), 
      f(af), 
      divFct(divAf),
      gradAtQPs(NULL),
      symmetric(symm)
Thomas Witkowski's avatar
Thomas Witkowski committed
1054
1055
1056
1057
1058
  {
    setSymmetric(symmetric);

    TEST_EXIT(dv)("No vector!\n");

1059
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
1060
1061
1062
1063
1064
1065
1066
1067
  }

  FctGradient_SOT::FctGradient_SOT(DOFVectorBase<double> *dv,
				   AbstractFunction<double, WorldVector<double> > *af)
    : SecondOrderTerm(af->getDegree()), vec(dv), f(af)
  {
    TEST_EXIT(dv)("No vector!\n");

1068
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
  }

  VecMatrixGradientAtQP_SOT::VecMatrixGradientAtQP_SOT(DOFVectorBase<double> *dv,
						       BinaryAbstractFunction<WorldMatrix<double>, double, WorldVector<double> > *af,
						       AbstractFunction<WorldVector<double>, WorldMatrix<double> > *divAf,
						       bool symm)
    : SecondOrderTerm(af->getDegree()), vec(dv), f(af), 
      divFct(divAf), symmetric(symm)
  {
    setSymmetric(symmetric);

    TEST_EXIT(dv)("No vector!\n");

1082
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
1083
1084
1085
1086
1087
1088
1089
1090
1091
  }

  VecGradCoordsAtQP_SOT::VecGradCoordsAtQP_SOT(DOFVectorBase<double> *dv,
					       TertiaryAbstractFunction<double, double,
					       WorldVector<double>, WorldVector<double> > *af)
    : SecondOrderTerm(af->getDegree()), vec(dv), f(af)
  {
    TEST_EXIT(dv)("No vector!\n");

1092
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
  }

  VecAndCoordsAtQP_SOT::VecAndCoordsAtQP_SOT(DOFVectorBase<double> *dv, 
					     BinaryAbstractFunction<double, double, WorldVector<double> > *af)
    : SecondOrderTerm(af->getDegree()), vec(dv), f(af)
  {
    setSymmetric(true);

    TEST_EXIT(dv)("No vector!\n");

1103
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
  }

  MatrixGradientAndCoords_SOT::MatrixGradientAndCoords_SOT(DOFVectorBase<double> *dv,
							   BinaryAbstractFunction<WorldMatrix<double>,
							   WorldVector<double>, WorldVector<double> > *af,
							   AbstractFunction<WorldVector<double>,
							   WorldMatrix<double> > *divAf,
							   bool symm) 
    : SecondOrderTerm(af->getDegree()), vec(dv), f(af), divFct(divAf), symmetric(symm)
  {
    setSymmetric(symmetric);

    TEST_EXIT(dv)("No vector!\n");

1118
    auxFeSpaces.insert(dv->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
1119
1120
  }

1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139

  MatrixVec2_SOT::MatrixVec2_SOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2, 
			       BinaryAbstractFunction<double, double, double> *f,
			       WorldMatrix<double> Af,
			       bool sym)
    : SecondOrderTerm(f->getDegree()), 
      vec1(dv1),
      vec2(dv2), 
      fct(f), 
      A(Af),
      symmetric(sym)
  {
    FUNCNAME("MatrixVec2_SOT::MatrixVec2_SOT()");

    setSymmetric(symmetric);

    TEST_EXIT_DBG(dv1)("No vector!\n");
    TEST_EXIT_DBG(dv2)("No vector!\n");
    
1140
1141
    auxFeSpaces.insert(dv1->getFESpace());
    auxFeSpaces.insert(dv2->getFESpace());
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
  }

  void MatrixVec2_SOT::initElement(const ElInfo* elInfo, 
				  SubAssembler* subAssembler,
				  Quadrature *quad) 
  {
    vec1AtQPs = getVectorAtQPs(vec1, elInfo, subAssembler, quad);
    vec2AtQPs = getVectorAtQPs(vec2, elInfo, subAssembler, quad);
  }
  
  void MatrixVec2_SOT::getLALt(const ElInfo *elInfo, int nPoints, 
			       DimMat<double> **LALt) const 
  {      
    const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();
    for (int iq = 0; iq < nPoints; iq++)
      lalt(Lambda, A, *(LALt[iq]), symmetric, (*fct)(vec1AtQPs[iq], vec2AtQPs[iq]));
  }

  void MatrixVec2_SOT::eval(int nPoints,
			    const double *uhAtQP,
			    const WorldVector<double> *grdUhAtQP,
			    const WorldMatrix<double> *D2UhAtQP,
			    double *result,
Thomas Witkowski's avatar
Thomas Witkowski committed
1165
			    double factor) 
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
  {
    int dow = Global::getGeo(WORLD);
    
    for (int iq = 0; iq < nPoints; iq++) {
      double resultQP = 0.0;

      if (D2UhAtQP)
	for (int i = 0; i < dow; i++)
	  for (int j = 0; j < dow; j++)
	    resultQP += A[i][j] * D2UhAtQP[iq][j][i];
    
      result[iq] += resultQP * factor * (*fct)(vec1AtQPs[iq], vec2AtQPs[iq]);
    }
  }

1181
  void MatrixVec2_SOT::weakEval(const std::vector<WorldVector<double> > &grdUhAtQP,
1182
				std::vector<WorldVector<double> > &result)
1183
  {
1184
1185
1186
    int nPoints = grdUhAtQP.size();
    for (int iq = 0; iq < nPoints; iq++)
      result[iq] += A * grdUhAtQP[iq] * (*fct)(vec1AtQPs[iq], vec2AtQPs[iq]);
1187
1188
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
  General_SOT::General_SOT(std::vector<DOFVectorBase<double>*> vecs,
			   std::vector<DOFVectorBase<double>*> grads,
			   TertiaryAbstractFunction<WorldMatrix<double>, 
  			     WorldVector<double>,
			     std::vector<double>, 
			     std::vector<WorldVector<double> > > *f,
			   AbstractFunction<WorldVector<double>, 
			     WorldMatrix<double> > *divFct,
			     bool symmetric)
      : SecondOrderTerm(f->getDegree()),
	vecs_(vecs),
	grads_(grads),
	f_(f),
	divFct_(divFct),
	symmetric_(symmetric)
  {
    vecsAtQPs_.resize(vecs_.size());
    gradsAtQPs_.resize(grads_.size());

    for (int i = 0; i < static_cast<int>(vecs.size()); i++) {
      TEST_EXIT(vecs[i])("One vector is NULL!\n");

1211
      auxFeSpaces.insert(vecs[i]->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
1212
1213
1214
1215
1216
    }   

    for (int i = 0; i < static_cast<int>(grads.size()); i++) {
      TEST_EXIT(grads[i])("One gradient vector is NULL!\n");

1217
      auxFeSpaces.insert(grads[i]->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
    }
  }

  GeneralParametric_SOT::GeneralParametric_SOT(std::vector<DOFVectorBase<double>*> vecs,
					       std::vector<DOFVectorBase<double>*> grads,
					       QuartAbstractFunction<WorldMatrix<double>, 
					         WorldVector<double>,
					         WorldVector<double>,
					         std::vector<double>, 
					         std::vector<WorldVector<double> > > *f,
					       AbstractFunction<WorldVector<double>, 
					         WorldMatrix<double> > *divFct,
					       bool symmetric)
    : SecondOrderTerm(f->getDegree()),
      vecs_(vecs),
      grads_(grads),
      f_(f),
      divFct_(divFct),
      symmetric_(symmetric)
  {
    vecsAtQPs_.resize(vecs_.size());
    gradsAtQPs_.resize(grads_.size());

    for (int i = 0; i < static_cast<int>(vecs.size()); i++) {
      TEST_EXIT(vecs[i])("One vector is NULL!\n");

1244
      auxFeSpaces.insert(vecs[i]->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
1245
1246
1247
1248
1249
    }   

    for (int i = 0; i < static_cast<int>(grads.size()); i++) {
      TEST_EXIT(grads[i])("One gradient vector is NULL!\n");

1250
      auxFeSpaces.insert(grads[i]->getFESpace());
Thomas Witkowski's avatar
Thomas Witkowski committed
1251
1252
1253
1254
1255
1256
1257
1258
1259
    }
  }

  VecAndGradAtQP_SOT::VecAndGradAtQP_SOT(DOFVectorBase<double> *dv,
					 BinaryAbstractFunction<double, double, WorldVector<double> > *af)
    : SecondOrderTerm(af->getDegree()), vec(dv), f(af) 
  {
    TEST_EXIT(dv)("No vector!\n");