GenericOperatorTerm.h 22.8 KB
Newer Older
1
2
3
4
5
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
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/



/** \file GenericOperatorTerm.h */

#ifndef AMDIS_GENERIC_OPERATOR_TERM_H
#define AMDIS_GENERIC_OPERATOR_TERM_H

#include "AMDiS_fwd.h"
#include "OperatorTerm.h"
#include "ValueTypes.h"
#include "Functors.h"

#include <boost/static_assert.hpp>


#include "expressions/LazyOperatorTerm.h"
#include "expressions/AtomicExpression.h"
#include "expressions/LazyExpression.h"
39
#include "expressions/cmath_expr.h"
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

/** generic operator-terms provide an easy way of automated generation of
 * 'arbitrary' operator-terms out of some elementary operations, by using a 
 * recursive definition of the term. All necessary data will be initialized 
 * when an expression as part of the term uses this data.
 * Since no virtual functions, like in the AbstractFunction classes, are used
 * the overhead of a vtable is removed.
 * 
 * usage:
 * addZOT(Operator, Term) 
 *  ... add a zeroOrderTerm to Operator, i.e. (Term(x) * u, v)
 * 
 * addFOT(Operator, Term, FirstOrderType) 
 *  ... add a firstOrderTerm to Operator, (if Term::value_type = double) 
 *      i.e. (Term(x) * 1 * grad(u), v), rsp. (Term(x) * 1 * u, grad(v))
 * addFOT(Operator, Term, FirstOrderType)
 *  ... add a firstOrderTerm to Operator, (if Term::value_type = WorldVector)
 *      i.e. (Term(x) * b * grad(u), v), rsp. (Term(x) * u, grad(v))
 * addFOT<I>(Operator, Term, FirstOrderType)
 *  ... add a firstOrderTerm to Operator, 
 *      i.e. (Term(x) * e_I * grad(u), v), rsp. (Term(x) * e_I * u, grad(v))
 * 
 * addSOT(Operator, Term)
 *  ... add a secondOrderTerm to Operator, i.e. (Term(x) * grad(u), grad(v))
 * addSOT<I,J>(Operator, Term)
 *  ... add a secondOrderTerm to Operator, i.e. (E_IJ * Term(x) * grad(u), grad(v))
 * 
 * where Operator is eather a pointer or reference, FirstOrderType in {GRD_PHI, GRD_PSI}
 * and Term a componation of elementary terms by + - * /
 *  - constant(value) / value  ... a constant value
 *  - valueOf(DOFVector)       ... values of a DOFVector at QP
 *  - gradientOf(DOFVector)    ... gradient of a DOFVector at QP
 *  - derivative<I>(DOFVector) ... I'th partial derivative
 *  - X()                      ... coordinate at quadrature points
 *  - pow<I>(Term)             ... I'th power of a term
 *  - sqrt(Term)               ... square root of a term
 *  - Exp(Term)                ... exponential function of a term
 *  - function_<F>(Term)       ... evaluates F()(Term(iq))
 *  - function_(F f, Term)     ... evaluates f(Term(iq))
 * 
 * 
 * with F a functor that implements
 *   typedef (...) value_type;
 *   int getDegree(int d0);
 *   value_type operator()(const T0& v0) const;
 * 
 * respective
 *   int getDegree(int d0, int d1);
 *   value_type operator()(const T0& v0, const T1& v1) const;
 * 
 * respective
 *   int getDegree(int d0, int d1, int d2);
 *   value_type operator()(const T0& v0, const T1& v1, const T2& v2) const;
 * 
 * where the d0, d1, d2 give the polynomial degrees of the v0, v1, v2 terms.
 * */

namespace AMDiS {

// _______ ZeroOrderTerms ______________________________________________________

template<typename Term>
struct GenericZeroOrderTerm : public ZeroOrderTerm
{
  Term term;
  GenericZeroOrderTerm(const Term& term_)
    : ZeroOrderTerm(term_.getDegree()), term(term_) 
  {
    term.insertFeSpaces(auxFeSpaces);
  }

  void initElement(const ElInfo* elInfo,
	    SubAssembler* subAssembler,
	    Quadrature *quad)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
115
    term.initElement(this, elInfo, subAssembler, quad, NULL);
116
117
118
119
120
121
122
123
  }


  void initElement(const ElInfo* smallElInfo,
	    const ElInfo* largeElInfo,
	    SubAssembler* subAssembler,
	    Quadrature *quad)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
124
    term.initElement(this, smallElInfo, largeElInfo, subAssembler, quad, NULL);
125
126
127
128
129
130
131
132
133
134
135
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
  }


  void getC(const ElInfo *elInfo, int nPoints, ElementVector& C)
  {
    for (int iq = 0; iq < nPoints; iq++)
      C[iq] += term(iq);
  }


  void eval( int nPoints,
	      const mtl::dense_vector<double>& uhAtQP,
	      const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	      const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	      mtl::dense_vector<double>& result,
	      double fac)
  {
    for (int iq = 0; iq < nPoints; iq++)
      result[iq] += fac * term(iq) * uhAtQP[iq];
  }
};

// _______ FirstOrderTerms _____________________________________________________


template<typename Term>
struct GenericFirstOrderTerm_1 : public FirstOrderTerm
{
  Term term;
  GenericFirstOrderTerm_1(const Term& term_)
    : FirstOrderTerm(term_.getDegree()), term(term_) 
  {
    term.insertFeSpaces(auxFeSpaces);
  }

  void initElement(const ElInfo* elInfo,
	    SubAssembler* subAssembler,
	    Quadrature *quad)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
164
    term.initElement(this, elInfo, subAssembler, quad);
165
166
167
168
169
170
171
172
  }


  void initElement(const ElInfo* smallElInfo,
	    const ElInfo* largeElInfo,
	    SubAssembler* subAssembler,
	    Quadrature *quad)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
173
    term.initElement(this, smallElInfo, largeElInfo, subAssembler, quad);
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
  }


  /// Implements FirstOrderTerm::getLb().
  void getLb(const ElInfo *elInfo,
	     std::vector<mtl::dense_vector<double> >& Lb) const
  {
    const DimVec<WorldVector<double> > &grdLambda = elInfo->getGrdLambda();
    const int nPoints = static_cast<int>(Lb.size());

    for (int iq = 0; iq < nPoints; iq++)
      l1(grdLambda, Lb[iq], term(iq));
  }
};


template<int I, typename Term>
struct GenericFirstOrderTerm_i : public FirstOrderTerm
{
  Term term;
  GenericFirstOrderTerm_i(const Term& term_)
    : FirstOrderTerm(term_.getDegree()), term(term_) 
  {
    term.insertFeSpaces(auxFeSpaces);
    FirstOrderTerm::bOne = I;
  }
  
  GenericFirstOrderTerm_i(const Term& term_, int I0)
    : FirstOrderTerm(term_.getDegree()), term(term_) 
  {
    term.insertFeSpaces(auxFeSpaces);
    FirstOrderTerm::bOne = I0;
    TEST_EXIT_DBG( I < 0 && I0 >= 0 )("You yould specify eather template<int I>, or constructor(int I0)\n");
  }

  void initElement(const ElInfo* elInfo,
	    SubAssembler* subAssembler,
	    Quadrature *quad)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
213
    term.initElement(this, elInfo, subAssembler, quad);
214
215
216
217
218
219
220
221
  }


  void initElement(const ElInfo* smallElInfo,
	    const ElInfo* largeElInfo,
	    SubAssembler* subAssembler,
	    Quadrature *quad)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
222
    term.initElement(this, smallElInfo, largeElInfo, subAssembler, quad);
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
  }


  /// Implements FirstOrderTerm::getLb().
  void getLb(const ElInfo *elInfo,
	     std::vector<mtl::dense_vector<double> >& Lb) const
  {
    const DimVec<WorldVector<double> > &grdLambda = elInfo->getGrdLambda();
    const int nPoints = static_cast<int>(Lb.size());

    for (int iq = 0; iq < nPoints; iq++)
      lb_one(grdLambda, Lb[iq], term(iq));
  }
};


template<typename Term>
struct GenericFirstOrderTerm_b : public FirstOrderTerm
{
  Term term;
  
  GenericFirstOrderTerm_b(const Term& term_)
    : FirstOrderTerm(term_.getDegree()), term(term_)
  {
    term.insertFeSpaces(auxFeSpaces);
  }

  void initElement(const ElInfo* elInfo,
	    SubAssembler* subAssembler,
	    Quadrature *quad)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
254
    term.initElement(this, elInfo, subAssembler, quad);
255
256
257
258
259
260
261
262
  }


  void initElement(const ElInfo* smallElInfo,
	    const ElInfo* largeElInfo,
	    SubAssembler* subAssembler,
	    Quadrature *quad)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
263
    term.initElement(this, smallElInfo, largeElInfo, subAssembler, quad);
264
265
266
267
268
269
270
271
272
273
274
  }


  /// Implements FirstOrderTerm::getLb().
  void getLb(const ElInfo *elInfo,
	     std::vector<mtl::dense_vector<double> >& Lb) const
  {
    const DimVec<WorldVector<double> > &grdLambda = elInfo->getGrdLambda();
    const int nPoints = static_cast<int>(Lb.size());

    for (int iq = 0; iq < nPoints; iq++)
275
      lb(grdLambda, term(iq), Lb[iq], 1.0);
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
  }
};

// _______ SecondOrderTerms ____________________________________________________


template<typename Term>
struct GenericSecondOrderTerm_1 : public SecondOrderTerm
{
  Term term;
  
  GenericSecondOrderTerm_1(const Term& term_)
    : SecondOrderTerm(term_.getDegree()), term(term_) 
  {
    term.insertFeSpaces(auxFeSpaces);
    setSymmetric(true);
  }

  void initElement(const ElInfo* elInfo,
	    SubAssembler* subAssembler,
	    Quadrature *quad)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
298
    term.initElement(this, elInfo, subAssembler, quad);
299
300
301
302
303
304
305
306
  }


  void initElement(const ElInfo* smallElInfo,
	    const ElInfo* largeElInfo,
	    SubAssembler* subAssembler,
	    Quadrature *quad)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
307
    term.initElement(this, smallElInfo, largeElInfo, subAssembler, quad);
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
  }
  
  /// Implements SecondOrderTerm::getLALt().
  void getLALt(const ElInfo *elInfo, std::vector<mtl::dense2D<double> > &LALt) const
  {
    const DimVec<WorldVector<double> > &grdLambda = elInfo->getGrdLambda();
    const int nPoints = static_cast<int>(LALt.size());

    for (int iq = 0; iq < nPoints; iq++) 
      l1lt(grdLambda, LALt[iq], term(iq));
  }

  /// Implenetation of SecondOrderTerm::eval().
  void eval(int nPoints,
	    const mtl::dense_vector<double>& uhAtQP,
	    const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	    const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	    mtl::dense_vector<double>& result,
	    double f) 
  {
    int dow = Global::getGeo(WORLD);

    if (num_rows(D2UhAtQP) > 0) {
      for (int iq = 0; iq < nPoints; iq++) {
	double resultQP = 0.0;
	for (int i = 0; i < dow; i++) {
	  resultQP += D2UhAtQP[iq][i][i];
	}
	result[iq] += resultQP * f * term(iq);
      }
    }
  }

  /// Implenetation of SecondOrderTerm::weakEval().
  void weakEval(const std::vector<WorldVector<double> > &grdUhAtQP,
		std::vector<WorldVector<double> > &result) 
  {
    int nPoints = grdUhAtQP.size();
    for (int iq = 0; iq < nPoints; iq++)
      axpy(term(iq), grdUhAtQP[iq], result[iq]);
  }
};



template<typename Term, bool symmetric = true>
struct GenericSecondOrderTerm_A : public SecondOrderTerm
{
  Term term;
  
  GenericSecondOrderTerm_A(const Term& term_)
    : SecondOrderTerm(term_.getDegree()), term(term_) 
  {
    term.insertFeSpaces(auxFeSpaces);
    setSymmetric(symmetric);
  }

  void initElement(const ElInfo* elInfo,
	    SubAssembler* subAssembler,
	    Quadrature *quad)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
369
    term.initElement(this, elInfo, subAssembler, quad);
370
371
372
373
374
375
376
377
  }


  void initElement(const ElInfo* smallElInfo,
	    const ElInfo* largeElInfo,
	    SubAssembler* subAssembler,
	    Quadrature *quad)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
378
    term.initElement(this, smallElInfo, largeElInfo, subAssembler, quad);
379
380
381
382
383
384
385
386
387
388
389
390
391
392
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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
  }
  
  void getLALt(const ElInfo *elInfo, 
	       std::vector<mtl::dense2D<double> > &LALt) const
  {
    const DimVec<WorldVector<double> > &grdLambda = elInfo->getGrdLambda();
    const int nPoints = static_cast<int>(LALt.size());

    for (int iq = 0; iq < nPoints; iq++)
      lalt(grdLambda, term(iq), LALt[iq], symmetric, 1.0);
  }

  void eval(int nPoints,
	    const mtl::dense_vector<double>& uhAtQP,
	    const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	    const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	    mtl::dense_vector<double>& result,
	    double factor) 
  {
    int dow = Global::getGeo(WORLD);

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

      WorldMatrix<double> A = term(iq);

      if (num_rows(D2UhAtQP) > 0)
	for (int i = 0; i < dow; i++)
	  for (int j = 0; j < dow; j++)
	    resultQP += A[i][j] * D2UhAtQP[iq][j][i];

//       if (num_rows(grdUhAtQP) > 0)
// 	resultQP += (*divFct)(A) * grdUhAtQP[iq];

      result[iq] += resultQP * factor;
    }
  }

  void weakEval(const std::vector<WorldVector<double> > &grdUhAtQP,
		std::vector<WorldVector<double> > &result)
  {
    int nPoints = grdUhAtQP.size();
    WorldMatrix<double> A;
    for (int iq = 0; iq < nPoints; iq++) {
      A = term(iq);
      result[iq] += term(iq) * grdUhAtQP[iq];
    }    
  }
};



template<int I, int J, typename Term>
struct GenericSecondOrderTerm_ij : public SecondOrderTerm
{
  Term term;
  int row, col;
  
  GenericSecondOrderTerm_ij(const Term& term_)
    : SecondOrderTerm(term_.getDegree()), term(term_), row(I), col(J)
  {
    term.insertFeSpaces(auxFeSpaces);
    setSymmetric(row == col);
  }
  
  GenericSecondOrderTerm_ij(const Term& term_, int I0, int J0)
    : SecondOrderTerm(term_.getDegree()), term(term_), row(I0), col(J0)
  {
    term.insertFeSpaces(auxFeSpaces);
    setSymmetric(row == col);
    TEST_EXIT_DBG( I < 0 && I0 >= 0 && J < 0 && J0 >= 0 ) 
      ("You yould specify eather template<int I, int J>, or constructor(int I0, int J0)\n");
  }

  void initElement(const ElInfo* elInfo,
	    SubAssembler* subAssembler,
	    Quadrature *quad)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
457
    term.initElement(this, elInfo, subAssembler, quad);
458
459
460
461
462
463
464
465
  }


  void initElement(const ElInfo* smallElInfo,
	    const ElInfo* largeElInfo,
	    SubAssembler* subAssembler,
	    Quadrature *quad)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
466
    term.initElement(this, smallElInfo, largeElInfo, subAssembler, quad);
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
  }

  void getLALt(const ElInfo *elInfo, 
	       std::vector<mtl::dense2D<double> > &LALt) const
  {
    const DimVec<WorldVector<double> > &grdLambda = elInfo->getGrdLambda();
    const int nPoints = static_cast<int>(LALt.size());

    for (int iq = 0; iq < nPoints; iq++)
      lalt_kl(grdLambda, row, col, LALt[iq], term(iq));
  }  

  void eval(int nPoints,
	    const mtl::dense_vector<double>& uhAtQP,
	    const mtl::dense_vector<WorldVector<double> >& grdUhAtQP,
	    const mtl::dense_vector<WorldMatrix<double> >& D2UhAtQP,
	    mtl::dense_vector<double>& result,
	    double fac) 
  {
    if (num_rows(D2UhAtQP) > 0) {
      for (int iq = 0; iq < nPoints; iq++)
	result[iq] += D2UhAtQP[iq][row][col] * term(iq) * fac;
    }
  }

  void weakEval(const std::vector<WorldVector<double> > &grdUhAtQP,
				std::vector<WorldVector<double> > &result) 
  {
    int nPoints = grdUhAtQP.size();
    for (int iq = 0; iq < nPoints; iq++)
      result[iq][row] += grdUhAtQP[iq][col] * term(iq);
  }
};


// _____________________________________________________________________________

template <typename Term>
void addZOT(Operator* op, const Term& term)
{
  op->addZeroOrderTerm(new GenericZeroOrderTerm<Term>(term));
}

template <typename Term>
void addZOT(Operator& op, const Term& term)
{
  op.addZeroOrderTerm(new GenericZeroOrderTerm<Term>(term));
}

516
517
518
519
520
521
522
523
524
525
526
inline void addZOT(Operator* op, double term)
{
  addZOT(op, constant(term));
}

inline void addZOT(Operator& op, double term)
{
  addZOT(op, constant(term));
}


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
553
554
555
556
557
558
559
560
561
// .............................................................................
// Rosenbrock method

// template <typename Term>
// void addZOT_(Operator* op, const Term& term)
// {
//   if (op->getUhOld()) {
//     addZOT(op, jacobian(term,0) * ...
//     
// }

// template <typename Term>
// void addZOT(Operator& op, const Term& term)
// {
//   op.addZeroOrderTerm(new GenericZeroOrderTerm<Term>(term));
// }


// _____________________________________________________________________________

// first order term using FirstOrderTerm::l1
template <typename Term>
inline typename boost::enable_if< typename boost::is_same<double, typename Term::value_type>::type >::type
addFOT(Operator* op, const Term& term, FirstOrderType type)
{
  op->addFirstOrderTerm(new GenericFirstOrderTerm_1<Term>(term), type);
}

template <typename Term>
inline typename boost::enable_if< typename boost::is_same<double, typename Term::value_type>::type >::type
addFOT(Operator& op, const Term& term, FirstOrderType type)
{
  op.addFirstOrderTerm(new GenericFirstOrderTerm_1<Term>(term), type);
}

562
563
564
565
566
567
568
569
570
571
inline void addFOT(Operator* op, double term, FirstOrderType type)
{
  addFOT(op, constant(term), type);
}

inline void addFOT(Operator& op, double term, FirstOrderType type)
{
  addFOT(op, constant(term), type);
}

572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
// first order term using FirstOrderTerm::lb_one
template <int I, typename Term>
inline typename boost::enable_if< typename boost::is_same<double, typename Term::value_type>::type >::type
addFOT(Operator* op, const Term& term, FirstOrderType type)
{
  op->addFirstOrderTerm(new GenericFirstOrderTerm_i<I,Term>(term), type);
}

template <int I, typename Term>
inline typename boost::enable_if< typename boost::is_same<double, typename Term::value_type>::type >::type
addFOT(Operator& op, const Term& term, FirstOrderType type)
{
  op.addFirstOrderTerm(new GenericFirstOrderTerm_i<I,Term>(term), type);
}

587
588
589
590
591
592
593
594
595
596
597
598
template <int I>
inline void addFOT(Operator* op, double term, FirstOrderType type)
{
  addFOT<I>(op, constant(term), type);
}

template <int I>
inline void addFOT(Operator& op, double term, FirstOrderType type)
{
  addFOT<I>(op, constant(term), type);
}

599
600
601
602
603
604
605
606
607
608
609
610
611
612
template <typename Term>
inline typename boost::enable_if< typename boost::is_same<double, typename Term::value_type>::type >::type
addFOT(Operator* op, const Term& term, int I, FirstOrderType type)
{
  op->addFirstOrderTerm(new GenericFirstOrderTerm_i<-1,Term>(term,I), type);
}

template <typename Term>
inline typename boost::enable_if< typename boost::is_same<double, typename Term::value_type>::type >::type
addFOT(Operator& op, const Term& term, int I, FirstOrderType type)
{
  op.addFirstOrderTerm(new GenericFirstOrderTerm_i<-1,Term>(term,I), type);
}

613
614
615
616
617
618
619
620
621
622
inline void addFOT(Operator* op, double term, int I, FirstOrderType type)
{
  addFOT(op, constant(term), I, type);
}

inline void addFOT(Operator& op, double term, int I, FirstOrderType type)
{
  addFOT(op, constant(term), I, type);
}

623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
// first order term using FirstOrderTerm::lb
template <typename Term>
inline typename boost::enable_if< typename boost::is_same<WorldVector<double>, typename Term::value_type>::type >::type
addFOT(Operator* op, const Term& term, FirstOrderType type)
{
  op->addFirstOrderTerm(new GenericFirstOrderTerm_b<Term>(term), type);
}

template <typename Term>
inline typename boost::enable_if< typename boost::is_same<WorldVector<double>, typename Term::value_type>::type >::type
addFOT(Operator& op, const Term& term, FirstOrderType type)
{
  op.addFirstOrderTerm(new GenericFirstOrderTerm_b<Term>(term), type);
}

638
639
640
641
642
643
644
645
646
647
inline void addFOT(Operator* op, WorldVector<double> term, FirstOrderType type)
{
  addFOT(op, constant(term), type);
}

inline void addFOT(Operator& op, WorldVector<double> term, FirstOrderType type)
{
  addFOT(op, constant(term), type);
}

648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
// _____________________________________________________________________________

// second order term using matrix functions
template <typename Term>
inline typename boost::enable_if< typename boost::is_same<WorldMatrix<double>, typename Term::value_type>::type >::type
addSOT(Operator* op, const Term& term)
{
  op->addSecondOrderTerm(new GenericSecondOrderTerm_A<Term>(term));
}
template <typename Term>
inline typename boost::enable_if< typename boost::is_same<WorldMatrix<double>, typename Term::value_type>::type >::type
addSOT(Operator& op, const Term& term)
{
  op.addSecondOrderTerm(new GenericSecondOrderTerm_A<Term>(term));
}

664
665
666
667
668
669
670
671
672
673
inline void addSOT(Operator* op, WorldMatrix<double> term)
{
  addSOT(op, constant(term));
}

inline void addSOT(Operator& op, WorldMatrix<double> term)
{
  addSOT(op, constant(term));
}

674
675
676
677
678
679
680
681
682
683
684
685
686
687
template <bool Symmetric, typename Term>
inline typename boost::enable_if< typename boost::is_same<WorldMatrix<double>, typename Term::value_type>::type >::type
addSOT(Operator* op, const Term& term)
{
  op->addSecondOrderTerm(new GenericSecondOrderTerm_A<Term, Symmetric>(term));
}

template <bool Symmetric, typename Term>
inline typename boost::enable_if< typename boost::is_same<WorldMatrix<double>, typename Term::value_type>::type >::type
addSOT(Operator& op, const Term& term)
{
  op.addSecondOrderTerm(new GenericSecondOrderTerm_A<Term, Symmetric>(term));
}

688
689
690
691
692
693
694
695
696
697
698
699
template <bool Symmetric>
inline void addSOT(Operator* op, WorldMatrix<double> term)
{
  addSOT<Symmetric>(op, constant(term));
}

template <bool Symmetric>
inline void addSOT(Operator& op, WorldMatrix<double> term)
{
  addSOT<Symmetric>(op, constant(term));
}

700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
// second order term using scalar functions with identity matrix
template <typename Term>
inline typename boost::enable_if< typename boost::is_same<double, typename Term::value_type>::type >::type
addSOT(Operator* op, const Term& term)
{
  op->addSecondOrderTerm(new GenericSecondOrderTerm_1<Term>(term));
}

template <typename Term>
inline typename boost::enable_if< typename boost::is_same<double, typename Term::value_type>::type >::type
addSOT(Operator& op, const Term& term)
{
  op.addSecondOrderTerm(new GenericSecondOrderTerm_1<Term>(term));
}

715
716
717
718
719
720
721
722
723
724
inline void addSOT(Operator* op, double term)
{
  addSOT(op, constant(term));
}

inline void addSOT(Operator& op, double term)
{
  addSOT(op, constant(term));
}

725
726
727
728
729
730
731
732
733
734
735
736
737
// second order term using matrix=0 with matrix_ij = function value
template <int I, int J, typename Term>
void addSOT(Operator* op, const Term& term)
{
  op->addSecondOrderTerm(new GenericSecondOrderTerm_ij<I,J,Term>(term));
}

template <int I, int J, typename Term>
void addSOT(Operator& op, const Term& term)
{
  op.addSecondOrderTerm(new GenericSecondOrderTerm_ij<I,J,Term>(term));
}

738
739
740
741
742
743
744
745
746
747
748
template <int I, int J>
inline void addSOT(Operator* op, double term)
{
  addSOT<I,J>(op, constant(term));
}
template <int I, int J>
inline void addSOT(Operator& op, double term)
{
  addSOT<I,J>(op, constant(term));
}

749
750
751
752
753
754
755
756
757
758
759
760
template <typename Term>
void addSOT(Operator* op, const Term& term, int I, int J)
{
  op->addSecondOrderTerm(new GenericSecondOrderTerm_ij<-1,-1,Term>(term,I,J));
}

template <typename Term>
void addSOT(Operator& op, const Term& term, int I, int J)
{
  op.addSecondOrderTerm(new GenericSecondOrderTerm_ij<-1,-1,Term>(term,I,J));
}

761
762
763
764
765
766
767
768
769
770
inline void addSOT(Operator* op, double term, int I, int J)
{
  addSOT(op, constant(term), I, J);
}

inline void addSOT(Operator& op, double term, int I, int J)
{
  addSOT(op, constant(term), I, J);
}

771
772
773
774
775
776
777
778
779
780
781
782
783
784
785

// _____________________________________________________________________________


template<typename TOut>
inline result_of::Function1<result_of::Wrapper<TOut,WorldVector<double> >, result_of::Coords>
eval(AbstractFunction<TOut, WorldVector<double> >* fct) { return function_(wrap(fct), X()); }

// C++11:
// template<typename TOut>
// inline auto eval(AbstractFunction<TOut, WorldVector<double> >* fct) -> decltype( function_(wrap(fct), X()) )
// { return function_(wrap(fct), X()); }



Praetorius, Simon's avatar
Praetorius, Simon committed
786
787
template<typename Term>
inline typename boost::enable_if<typename boost::is_base_of<LazyOperatorTermBase, Term>::type, typename Term::value_type>::type
788
integrate(Term term, Mesh* mesh_ = NULL);
Praetorius, Simon's avatar
Praetorius, Simon committed
789
790
791


template<typename Term>
792
inline typename boost::enable_if<typename boost::is_base_of<LazyOperatorTermBase, Term>::type, void>::type
Praetorius, Simon's avatar
Praetorius, Simon committed
793
794
795
796
797
798
transformDOF(Term term, DOFVector<typename Term::value_type>* result);

template<typename Term>
typename boost::enable_if<typename boost::is_base_of<LazyOperatorTermBase, Term>::type, 
			  DOFVector<typename Term::value_type>& >::type
operator<<(DOFVector<typename Term::value_type>& result, const Term& term);
799
800
}

Praetorius, Simon's avatar
Praetorius, Simon committed
801
802
#include "GenericOperatorTerm.hh"

803
#endif // AMDIS_GENERIC_OPERATOR_TERM_H