FirstOrderTerm.cc 23.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "FirstOrderTerm.h"
#include "DOFVector.h"

namespace AMDiS {

  // =========== VecAtQP_FOT ==========

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

15
    auxFeSpaces.insert(dv->getFeSpace());
16
17
18
19
20
21
22
23
24
25
  }

  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;
26
    auxFeSpaces.insert(dv->getFeSpace());
27
28
29
30
31
32
33
34
35
  }

  void VecAtQP_FOT::initElement(const ElInfo* elInfo, 
				SubAssembler* subAssembler,
				Quadrature *quad) 
  {
    vecAtQPs = getVectorAtQPs(vec, elInfo, subAssembler, quad);
  }

36
37
38
39
40
41
42
43
  void VecAtQP_FOT::initElement(const ElInfo* smallElInfo,
				const ElInfo* largeElInfo,
				SubAssembler* subAssembler,
				Quadrature *quad)
  {
    vecAtQPs = getVectorAtQPs(vec, smallElInfo, largeElInfo, subAssembler, quad);
  }

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
  void VecAtQP_FOT::getLb(const ElInfo *elInfo, int nPoints, 
			  VectorOfFixVecs<DimVec<double> >& Lb) const 
  {
    const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();

    if (bOne > -1) {
      for (int iq = 0; iq < nPoints; iq++)
	lb_one(Lambda, Lb[iq], (*f)(vecAtQPs[iq]));
    } else if (b) {
      for (int iq = 0; iq < nPoints; iq++)
	lb(Lambda, *b, Lb[iq], (*f)(vecAtQPs[iq]));
    } else {
      for (int iq = 0; iq < nPoints; iq++)
	l1(Lambda, Lb[iq], (*f)(vecAtQPs[iq]));      
    }
  }

  void VecAtQP_FOT::eval(int nPoints,
			 const double *uhAtQP,
			 const WorldVector<double> *grdUhAtQP,
			 const WorldMatrix<double> *D2UhAtQP,
			 double *result,
			 double fac) 
  {
    int dow = Global::getGeo(WORLD);
  
    if (grdUhAtQP) {
      for (int iq = 0; iq < nPoints; iq++) {
	double factor = (*f)(vecAtQPs[iq]);
	double resultQP = 0.0;
	for (int i = 0; i < dow; i++)
75
76
	  resultQP += grdUhAtQP[iq][i];
		
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
	result[iq] += fac * factor * resultQP;
      } 
    }
  }

  
  // =========== CoordsAtQP_FOT ===========

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

  void CoordsAtQP_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++)
      l1(Lambda, Lb[iq], (*g)(coordsAtQPs[iq]));
  }

  void CoordsAtQP_FOT::eval(int nPoints,
			    const double *uhAtQP,
			    const WorldVector<double> *grdUhAtQP,
			    const WorldMatrix<double> *D2UhAtQP,
			    double *result,
			    double f) 
  {
    int dow = Global::getGeo(WORLD);
  
    if (grdUhAtQP) {
      for (int iq = 0; iq < nPoints; iq++) {
	double factor = (*g)(coordsAtQPs[iq]);
	double resultQP = 0.0;
	for (int i = 0; i < dow; i++)
	  resultQP += grdUhAtQP[iq][i];	
	result[iq] += f * factor * resultQP;
      }
    }
  }


  // ========== VecCoordsAtQP_FOT ==========

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

  void VecCoordsAtQP_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++)
135
      lb(Lambda, *b, Lb[iq], (*g)(coordsAtQPs[iq]));
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
  }

  void VecCoordsAtQP_FOT::eval(int nPoints,
			       const double *uhAtQP,
			       const WorldVector<double> *grdUhAtQP,
			       const WorldMatrix<double> *D2UhAtQP,
			       double *result,
			       double f) 
  {
    int dow = Global::getGeo(WORLD);
  
    if (grdUhAtQP) {
      for (int iq = 0; iq < nPoints; iq++) {
	double factor = (*g)(coordsAtQPs[iq]);
	double resultQP = 0.0;
	for (int i = 0; i < dow; i++)
	  resultQP += grdUhAtQP[iq][i];
	
	result[iq] += f * factor * resultQP;
      }
    }
  }


  // ========== VectorGradient_FOT ==========

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

168
    auxFeSpaces.insert(dv->getFeSpace());
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
  }

  void VectorGradient_FOT::initElement(const ElInfo* elInfo, 
				       SubAssembler* subAssembler,
				       Quadrature *quad) 
  {
    gradAtQPs = getGradientsAtQPs(vec, elInfo, subAssembler, quad);
  }

  void VectorGradient_FOT::getLb(const ElInfo *elInfo, int nPoints, 
				 VectorOfFixVecs<DimVec<double> >& Lb) const 
  {
    const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();
    if (f) {
      for (int iq = 0; iq < nPoints; iq++)
	lb(Lambda, (*f)(gradAtQPs[iq]), Lb[iq], 1.0);      
    } else {
      for (int iq = 0; iq < nPoints; iq++)
	lb(Lambda, gradAtQPs[iq], Lb[iq], 1.0);      
    }
  }

  void VectorGradient_FOT::eval(int nPoints,
				const double *uhAtQP,
				const WorldVector<double> *grdUhAtQP,
				const WorldMatrix<double> *D2UhAtQP,
				double *result,
				double factor) 
  { 
    if (grdUhAtQP) {
      if (f) {
	for (int iq = 0; iq < nPoints; iq++) {
	  WorldVector<double> b = (*f)(gradAtQPs[iq]);
	  result[iq] += b * grdUhAtQP[iq] * factor;
	}
      } else {
	for (int iq = 0; iq < nPoints; iq++)
	  result[iq] += gradAtQPs[iq] * grdUhAtQP[iq] * factor;	
      }
    }
  }


  // =========== VectorFct_FOT ==========

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

220
    auxFeSpaces.insert(dv->getFeSpace());
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
  }

  void VectorFct_FOT::initElement(const ElInfo* elInfo, 
				  SubAssembler* subAssembler,
				  Quadrature *quad) 
  {
    vecAtQPs = getVectorAtQPs(vec, elInfo, subAssembler, quad);
  }

  void VectorFct_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++)
      lb(Lambda, (*vecFct)(vecAtQPs[iq]), Lb[iq], 1.0);    
  }

  void VectorFct_FOT::eval(int nPoints,
			   const double *uhAtQP,
			   const WorldVector<double> *grdUhAtQP,
			   const WorldMatrix<double> *D2UhAtQP,
			   double *result,
			   double factor) 
  {
    if (grdUhAtQP) {
      for (int iq = 0; iq < nPoints; iq++) {
	WorldVector<double> b = (*vecFct)(vecAtQPs[iq]);
	result[iq] += b * grdUhAtQP[iq] * factor;
      }
    }
  }


  // =========== VecFctAtQP_FOT ==========
  
  void VecFctAtQP_FOT::initElement(const ElInfo* elInfo, 
				   SubAssembler* subAssembler,
				   Quadrature *quad) 
  {
    coordsAtQPs = subAssembler->getCoordsAtQPs(elInfo, quad);
  }


  void VecFctAtQP_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++)
      lb(Lambda, (*g)(coordsAtQPs[iq]), Lb[iq], 1.0);    
  }

  void VecFctAtQP_FOT::eval(int nPoints,
			    const double *uhAtQP,
			    const WorldVector<double> *grdUhAtQP,
			    const WorldMatrix<double> *D2UhAtQP,
			    double *result,
			    double f) 
  {
    int dow = Global::getGeo(WORLD);
  
    if (grdUhAtQP) {
      for (int iq = 0; iq < nPoints; iq++) {
	double resultQP = 0.0;
	const WorldVector<double> &b = (*g)(coordsAtQPs[iq]);
	for (int i = 0; i < dow; i++)
	  resultQP += b[i] * grdUhAtQP[iq][i];	
	result[iq] += f * resultQP;
      }
    }
  }


  // =========== VecGrad_FOT ===========

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

302
303
    auxFeSpaces.insert(dv1->getFeSpace());
    auxFeSpaces.insert(dv2->getFeSpace());    
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
  }

  void VecGrad_FOT::initElement(const ElInfo* elInfo, 
				SubAssembler* subAssembler,
				Quadrature *quad) 
  {
    vecAtQPs = getVectorAtQPs(vec1, elInfo, subAssembler, quad);
    gradAtQPs = getGradientsAtQPs(vec2, elInfo, subAssembler, quad);
  }

  void VecGrad_FOT::initElement(const ElInfo* smallElInfo,
				const ElInfo* largeElInfo,
				SubAssembler* subAssembler,
				Quadrature *quad)
  {
    vecAtQPs = getVectorAtQPs(vec1, smallElInfo, largeElInfo, subAssembler, quad);
    gradAtQPs = getGradientsAtQPs(vec2, smallElInfo, largeElInfo, subAssembler, quad);
  }

  void VecGrad_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++)
      lb(Lambda, (*vecFct)(vecAtQPs[iq], gradAtQPs[iq]), Lb[iq], 1.0);
  }
  
  void VecGrad_FOT::eval(int nPoints,
			 const double *uhAtQP,
			 const WorldVector<double> *grdUhAtQP,
			 const WorldMatrix<double> *D2UhAtQP,
			 double *result,
			 double factor) 
  {
    if (grdUhAtQP) {
      for (int iq = 0; iq < nPoints; iq++) {
	WorldVector<double> b = (*vecFct)(vecAtQPs[iq], gradAtQPs[iq]);
	result[iq] += b * grdUhAtQP[iq] * factor;
      }
    }
  }


  // =========== FctGrad2_FOT ===========

  void FctGrad2_FOT::initElement(const ElInfo* elInfo, 
				SubAssembler* subAssembler,
				Quadrature *quad) 
  {
    grad1AtQPs = subAssembler->getGradientsAtQPs(vec1, elInfo, quad);
    grad2AtQPs = subAssembler->getGradientsAtQPs(vec2, elInfo, quad);
  }

  void FctGrad2_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++)
      lb(Lambda, (*vecFct)(grad1AtQPs[iq], grad2AtQPs[iq]), Lb[iq], 1.0);
  }
  
  void FctGrad2_FOT::eval(int nPoints,
			  const double *uhAtQP,
			  const WorldVector<double> *grdUhAtQP,
			  const WorldMatrix<double> *D2UhAtQP,
			  double *result,
			  double factor) 
  {
    if (grdUhAtQP) {
      for (int iq = 0; iq < nPoints; iq++) {
	WorldVector<double> b = (*vecFct)(grad1AtQPs[iq], grad2AtQPs[iq]);
	result[iq] += b * grdUhAtQP[iq] * factor;
      }
    }
  }


  // ========== Vec2AndGradAtQP_FOT ==========

  Vec2AndGradAtQP_FOT::Vec2AndGradAtQP_FOT(DOFVectorBase<double> *dv1, 
					   DOFVectorBase<double> *dv2,
					   TertiaryAbstractFunction<double, double, double, WorldVector<double> > *f_, WorldVector<double> *b_)
    : FirstOrderTerm(f_->getDegree()), 
      vec1(dv1), 
      vec2(dv2), 
      f(f_), 
      b(b_)
  {   
391
392
    auxFeSpaces.insert(dv1->getFeSpace()); 
    auxFeSpaces.insert(dv2->getFeSpace());
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
  }

  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,
				 double fac) 
  {   
    if (grdUhAtQP)
      for (int iq = 0; iq < nPoints; iq++)
	result[iq] += fac * 
	  (*f)(vec1AtQPs[iq], vec2AtQPs[iq], gradAtQPs1[iq]) * 
	  ((*b) * grdUhAtQP[iq]);
  }


  // ========== FctVecAtQP_FOT ==========


  FctVecAtQP_FOT::FctVecAtQP_FOT(DOFVectorBase<double> *dv,
				 BinaryAbstractFunction<double, WorldVector<double>, double> *f_,
				 WorldVector<double> *b_)
    : FirstOrderTerm(f_->getDegree()), vec(dv), f(f_), b(b_)
  {
437
    auxFeSpaces.insert(dv->getFeSpace());
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
  }

  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)
	lb(Lambda, *b, Lb[iq], (*f)(coordsAtQPs[iq], vecAtQPs[iq]));
      else
	l1(Lambda, Lb[iq], (*f)(coordsAtQPs[iq], vecAtQPs[iq]));
    }
  }
  
  void FctVecAtQP_FOT::eval(int nPoints,
			    const double *uhAtQP,
			    const WorldVector<double> *grdUhAtQP,
			    const WorldMatrix<double> *D2UhAtQP,
			    double *result,
			    double fac) 
  {
    if (grdUhAtQP)
      for (int iq = 0; iq < nPoints; iq++)
	result[iq] += 
	  fac * (*f)(coordsAtQPs[iq], vecAtQPs[iq]) * ((*b) * grdUhAtQP[iq]);
  }


  // ========== Vec2AtQP_FOT ==========

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

484
485
    auxFeSpaces.insert(dv1->getFeSpace()); 
    auxFeSpaces.insert(dv2->getFeSpace());
486
487
488
489
490
491
492
493
494
495
496
  }

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

    bOne = bIdx;
497
498
    auxFeSpaces.insert(dv1->getFeSpace()); 
    auxFeSpaces.insert(dv2->getFeSpace());
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
  }

  void Vec2AtQP_FOT::initElement(const ElInfo* elInfo, 
				 SubAssembler* subAssembler,
				 Quadrature *quad) 
  { 
    vec1AtQPs = subAssembler->getVectorAtQPs(vec1, elInfo, quad);
    vec2AtQPs = subAssembler->getVectorAtQPs(vec2, elInfo, quad);
  }
    
  void Vec2AtQP_FOT::getLb(const ElInfo *elInfo, int nPoints, 
			   VectorOfFixVecs<DimVec<double> >& Lb) const 
  {
    const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();

    if (bOne > -1) {
      for (int iq = 0; iq < nPoints; iq++)
	lb_one(Lambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq]));
    } else if (b) {
      for (int iq = 0; iq < nPoints; iq++)
	lb(Lambda, *b, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq]));
    } else {
      for (int iq = 0; iq < nPoints; iq++)
	l1(Lambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq]));
    }
  }
  
  void Vec2AtQP_FOT::eval(int nPoints,
			  const double *uhAtQP,
			  const WorldVector<double> *grdUhAtQP,
			  const WorldMatrix<double> *D2UhAtQP,
			  double *result,
			  double fac) 
  {
    if (grdUhAtQP)
      for (int iq = 0; iq < nPoints; iq++) 
	result[iq] += fac * (*f)(vec1AtQPs[iq], vec2AtQPs[iq]) * ((*b) * grdUhAtQP[iq]);
  }

  
  // ========== Vec3FctAtQP_FOT ==========

  Vec3FctAtQP_FOT::Vec3FctAtQP_FOT(DOFVectorBase<double> *dv1, 
				   DOFVectorBase<double> *dv2, 
				   DOFVectorBase<double> *dv3,
				   TertiaryAbstractFunction<double, double, double, double> *f_,
				   WorldVector<double> *bvec)
    : FirstOrderTerm(f_->getDegree()), 
      vec1(dv1), 
      vec2(dv2), 
      vec3(dv3), 
      f(f_),
      b(bvec)
  { 
553
554
555
    auxFeSpaces.insert(dv1->getFeSpace()); 
    auxFeSpaces.insert(dv2->getFeSpace()); 
    auxFeSpaces.insert(dv3->getFeSpace());   
556
557
558
559
560
561
562
563
564
565
566
567
568
569
  }

  Vec3FctAtQP_FOT::Vec3FctAtQP_FOT(DOFVectorBase<double> *dv1, 
				   DOFVectorBase<double> *dv2, 
				   DOFVectorBase<double> *dv3,
				   TertiaryAbstractFunction<double, double, double, double> *f_,
				   int b)
    : FirstOrderTerm(f_->getDegree()), 
      vec1(dv1), 
      vec2(dv2), 
      vec3(dv3), 
      f(f_)
  { 
    bOne = b;
570
571
572
    auxFeSpaces.insert(dv1->getFeSpace()); 
    auxFeSpaces.insert(dv2->getFeSpace()); 
    auxFeSpaces.insert(dv3->getFeSpace());   
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
  }

  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);
  }
  
  void Vec3FctAtQP_FOT::getLb(const ElInfo *elInfo, int nPoints, 
			      VectorOfFixVecs<DimVec<double> >& Lb) const 
  {
    const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();
    if (bOne > -1) {
      for (int iq = 0; iq < nPoints; iq++)
	lb_one(Lambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq], vec3AtQPs[iq]));
    } else {
      for (int iq = 0; iq < nPoints; iq++) {
	if (b)
	  lb(Lambda, *b, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq], vec3AtQPs[iq]));
	else
	  l1(Lambda, Lb[iq], (*f)(vec1AtQPs[iq], vec2AtQPs[iq], vec3AtQPs[iq]));
      }
    }
  }

  void Vec3FctAtQP_FOT::eval(int nPoints,
			     const double *uhAtQP,
			     const WorldVector<double> *grdUhAtQP,
			     const WorldMatrix<double> *D2UhAtQP,
			     double *result,
			     double fac) 
  {
    if (grdUhAtQP)
      for (int iq = 0; iq < nPoints; iq++)
	result[iq] += fac * (*f)(vec1AtQPs[iq], vec2AtQPs[iq] ,vec3AtQPs[iq]) * 
	  ((*b) * grdUhAtQP[iq]);
  }


  // =========== General_FOT ==========

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

631
      auxFeSpaces.insert(vecs[i]->getFeSpace());
632
633
634
635
636
    }   

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

637
      auxFeSpaces.insert(grads[i]->getFeSpace());
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
    }   
  }

  void General_FOT::initElement(const ElInfo* elInfo, 
				SubAssembler* subAssembler,
				Quadrature *quad)
  {
    int nVecs = static_cast<int>(vecs_.size());
    int nGrads = static_cast<int>(grads_.size());

    coordsAtQPs_ = subAssembler->getCoordsAtQPs(elInfo, quad);

    for (int i = 0; i < nVecs; i++)
      vecsAtQPs_[i] = getVectorAtQPs(vecs_[i], elInfo, subAssembler, quad);    
    for (int i = 0; i < nGrads; i++)
      gradsAtQPs_[i] = getGradientsAtQPs(grads_[i], elInfo, subAssembler, quad);    
  }

  void General_FOT::getLb(const ElInfo *elInfo, 
			  int nPoints, 
			  VectorOfFixVecs<DimVec<double> >& result) const
  {
    int nVecs = static_cast<int>(vecs_.size());
    int nGrads = static_cast<int>(grads_.size());

    std::vector<double> vecsArg(nVecs);
    std::vector<WorldVector<double> > gradsArg(nGrads);

    const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();

    for (int iq = 0; iq < nPoints; iq++) {
      for (int i = 0; i < nVecs; i++)
	vecsArg[i] = vecsAtQPs_[i][iq];      
      for (int i = 0; i < nGrads; i++) 
	gradsArg[i] = gradsAtQPs_[i][iq];      

      lb(Lambda, (*f_)(coordsAtQPs_[iq], vecsArg, gradsArg), 
	 result[iq], 1.0);
    }
  }

  void General_FOT::eval(int nPoints,
			 const double *uhAtQP,
			 const WorldVector<double> *grdUhAtQP,
			 const WorldMatrix<double> *D2UhAtQP,
			 double *result,
			 double factor) 
  {
    int dow = Global::getGeo(WORLD);  
    int nVecs = static_cast<int>(vecs_.size());
    int nGrads = static_cast<int>(grads_.size());

    std::vector<double> vecsArg(nVecs);
    std::vector<WorldVector<double> > gradsArg(nGrads);

    if (grdUhAtQP) {
      for (int iq = 0; iq < nPoints; iq++) {
	double resultQP = 0.0;

	for (int i = 0; i < nVecs; i++)
	  vecsArg[i] = vecsAtQPs_[i][iq];	
	for (int i = 0; i < nGrads; i++)
	  gradsArg[i] = gradsAtQPs_[i][iq];	

	const WorldVector<double> &b = (*f_)(coordsAtQPs_[iq], vecsArg, gradsArg);

	for (int i = 0; i < dow; i++) 
	  resultQP += grdUhAtQP[iq][i] * b[i];
	
	result[iq] += factor * resultQP;
      }
    }
  }


  // =========== GeneralParametric_FOT ==========

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

730
      auxFeSpaces.insert(vecs[i]->getFeSpace());
731
732
733
734
735
    }   

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

736
      auxFeSpaces.insert(grads[i]->getFeSpace());
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
    }   
  }


  void GeneralParametric_FOT::initElement(const ElInfo* elInfo, 
					  SubAssembler* subAssembler,
					  Quadrature *quad)
  {
    int nVecs = static_cast<int>(vecs_.size());
    int nGrads = static_cast<int>(grads_.size());

    elInfo->getElementNormal(elementNormal_);
    coordsAtQPs_ = subAssembler->getCoordsAtQPs(elInfo, quad);

    for (int i = 0; i < nVecs; i++)
      vecsAtQPs_[i] = getVectorAtQPs(vecs_[i], elInfo, subAssembler, quad);    
    for (int i = 0; i < nGrads; i++) 
      gradsAtQPs_[i] = getGradientsAtQPs(grads_[i], elInfo, subAssembler, quad);    
  }

  void GeneralParametric_FOT::getLb(const ElInfo *elInfo, 
				    int nPoints, 
				    VectorOfFixVecs<DimVec<double> >& result) const
  {
    int nVecs = static_cast<int>(vecs_.size());
    int nGrads = static_cast<int>(grads_.size());

    std::vector<double> vecsArg(nVecs);
    std::vector<WorldVector<double> > gradsArg(nGrads);

    const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();
    for (int iq = 0; iq < nPoints; iq++) {
      for (int i = 0; i < nVecs; i++)
	vecsArg[i] = vecsAtQPs_[i][iq];      
      for (int i = 0; i < nGrads; i++)
	gradsArg[i] = gradsAtQPs_[i][iq];
      
      lb(Lambda, (*f_)(coordsAtQPs_[iq],  elementNormal_, vecsArg, gradsArg), result[iq], 1.0);
    }
  }

  void GeneralParametric_FOT::eval(int nPoints,
				   const double *uhAtQP,
				   const WorldVector<double> *grdUhAtQP,
				   const WorldMatrix<double> *D2UhAtQP,
				   double *result,
				   double factor) 
  {
    int dow = Global::getGeo(WORLD);
    int nVecs = static_cast<int>(vecs_.size());
    int nGrads = static_cast<int>(grads_.size());

    std::vector<double> vecsArg(nVecs);
    std::vector<WorldVector<double> > gradsArg(nGrads);

    if (grdUhAtQP) {
      for (int iq = 0; iq < nPoints; iq++) {
	double resultQP = 0.0;

	for (int i = 0; i < nVecs; i++)
	  vecsArg[i] = vecsAtQPs_[i][iq];
	for (int i = 0; i < nGrads; i++)
	  gradsArg[i] = gradsAtQPs_[i][iq];	

	const WorldVector<double> &b = (*f_)(coordsAtQPs_[iq],  elementNormal_, vecsArg, gradsArg);

	for (int i = 0; i < dow; i++)
	  resultQP += grdUhAtQP[iq][i] * b[i];
	
	result[iq] += factor * resultQP;
      }
    }
  }



}