Operator.h 96.4 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
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file Operator.h */

#ifndef AMDIS_OPERATOR_H
#define AMDIS_OPERATOR_H

#include <vector>
26
#include "AMDiS_fwd.h"
27
28
29
30
31
#include "FixVec.h"
#include "Flag.h"
#include "MatrixVector.h"
#include "ElInfo.h"
#include "AbstractFunction.h"
32
#include "OpenMP.h"
33
#include "SubAssembler.h"
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

namespace AMDiS {

  /** 
   * \ingroup Assembler
   * 
   * \brief
   * Base class for ZeroOrderTerm, FirstOrderTerm and SecondOrderTerm. 
   * OperatorTerms are the building blocks of an Operator. Each OperatorTerm
   * has its properties which are regarded, when constructing 
   * an Assembler for the corresponding Operator.
   */
  class OperatorTerm
  {
  public:
    /** \brief
     * Constructs an OperatorTerm with initially no properties.
     * degree_ is used to determine the degree of the needed quadrature
     * for the assemblage.  
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
54
    OperatorTerm(int deg) 
55
      : properties(0), 
Thomas Witkowski's avatar
Thomas Witkowski committed
56
57
	degree(deg),
	auxFESpaces(0)
58
    {}
59

Thomas Witkowski's avatar
Thomas Witkowski committed
60
61
    /// Destructor.
    virtual ~OperatorTerm() {}
62
63
64

    /** \brief
     * Virtual method. It's called by SubAssembler::initElement() for
Thomas Witkowski's avatar
Thomas Witkowski committed
65
66
     * each OperatorTerm belonging to this SubAssembler. E.g., vectors
     * and coordinates at quadrature points can be calculated here.
67
68
     */
    virtual void initElement(const ElInfo*, 
Thomas Witkowski's avatar
Thomas Witkowski committed
69
70
			     SubAssembler*,
			     Quadrature *quad = NULL) 
71
    {}
72

Thomas Witkowski's avatar
Thomas Witkowski committed
73
74
75
76
77
78
79
80
81
82
83
84
    virtual void initElement(const ElInfo* largeElInfo,
			     const ElInfo* smallElInfo,
			     SubAssembler*,
			     Quadrature *quad = NULL)
    {}

    /// Returs \auxFESpaces, the list of all aux fe spaces the operator makes use off.
    std::vector<const FiniteElemSpace*>& getAuxFESpaces() {
      return auxFESpaces;
    }

    /// Specifies whether the matrix of the term is symmetric
85
86
    void setSymmetric(bool symm);

Thomas Witkowski's avatar
Thomas Witkowski committed
87
    /// Returns true, if the term is piecewise constant, returns false otherwise
88
89
    inline bool isPWConst() { 
      return (degree == 0);
90
    }
91

Thomas Witkowski's avatar
Thomas Witkowski committed
92
    /// Returns true, if the term has a symmetric matrix, returns false otherwise.
93
94
    bool isSymmetric();

Thomas Witkowski's avatar
Thomas Witkowski committed
95
    /// Returns \ref degree.
96
97
    inline int getDegree() { 
      return degree; 
98
    }
99

Thomas Witkowski's avatar
Thomas Witkowski committed
100
    /// Evaluation of the OperatorTerm at all quadrature points.
Thomas Witkowski's avatar
Thomas Witkowski committed
101
102
    virtual void eval(int nPoints,
		      const double *uhAtQP,
103
104
		      const WorldVector<double> *grdUhAtQP,
		      const WorldMatrix<double> *D2UhAtQP,
Thomas Witkowski's avatar
Thomas Witkowski committed
105
		      double *result,
106
107
108
		      double factor) const = 0;

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
109
110
     * Determines the value of a dof vector at the quadrature points of a given 
     * element. It is used by all VecAtQP like operator terms.
111
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    double *getVectorAtQPs(DOFVectorBase<double>* vec,
			   const ElInfo* elInfo, 
			   SubAssembler* subAssembler,
			   Quadrature *quad);		   

    /** \brief
     * Determines the value of a dof vector at the quadrature points of a given 
     * element. This function is used, if an operator is assembled on two different
     * meshes using the dual traverse. The element, i.e. the small or the large one,
     * is choosen, which corresponds to the mesh the dof vector is defined on.
     */
    double *getVectorAtQPs(DOFVectorBase<double>* vec,
			   const ElInfo* smallElInfo, 
			   const ElInfo* largeElInfo, 
			   SubAssembler* subAssembler,
			   Quadrature *quad);	

Thomas Witkowski's avatar
Thomas Witkowski committed
129
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
130
131
132
133
134
    WorldVector<double>* getGradientsAtQPs(DOFVectorBase<double>* vec,
					   const ElInfo* elInfo,
					   SubAssembler* subAssembler,
					   Quadrature *quad);

Thomas Witkowski's avatar
Thomas Witkowski committed
135
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
136
137
138
139
140
141
142
143
    WorldVector<double>* getGradientsAtQPs(DOFVectorBase<double>* vec,
					   const ElInfo* smallElInfo, 
					   const ElInfo* largeElInfo,
					   SubAssembler* subAssembler,
					   Quadrature *quad);

  protected:
    /// Evaluation of \f$ \Lambda \cdot A \cdot \Lambda^t\f$.
144
    static void lalt(const DimVec<WorldVector<double> >& Lambda,
Thomas Witkowski's avatar
Thomas Witkowski committed
145
146
147
148
		     const WorldMatrix<double>& matrix,
		     DimMat<double>& LALt,
		     bool symm,
		     double factor);
149
150
151
152
153
154
155
156

    /** \brief
     * Evaluation of \f$ \Lambda \cdot A \cdot \Lambda^t\f$ for \f$ A \f$
     * the matrix having a ONE in the position \f$ (K,L) \f$
     * and ZEROS in all other positions.
     */
    static void lalt_kl(const DimVec<WorldVector<double> >& Lambda,
			int k, int l,
Thomas Witkowski's avatar
Thomas Witkowski committed
157
158
			DimMat<double>& LALt,
			double factor);
159
160
161
162
163
164

    /** \brief
     * Evaluation of \f$ \Lambda \cdot A \cdot \Lambda^t\f$ for A equal to the 
     * identity.
     */
    static void l1lt(const DimVec<WorldVector<double> >& Lambda,
Thomas Witkowski's avatar
Thomas Witkowski committed
165
166
		     DimMat<double>& LALt,
		     double factor);
167

Thomas Witkowski's avatar
Thomas Witkowski committed
168
    /// Evaluation of \f$ \Lambda \cdot b\f$.
169
    static void lb(const DimVec<WorldVector<double> >& Lambda,
Thomas Witkowski's avatar
Thomas Witkowski committed
170
171
172
		   const WorldVector<double>& b,
		   DimVec<double>& Lb,
		   double factor);
173
174
175
176
177
178

    /** \brief
     * Evaluation of \f$ \Lambda \cdot b\f$ if b contains the value 1.0 in
     * each component.
     */
    static void l1(const DimVec<WorldVector<double> >& Lambda,
Thomas Witkowski's avatar
Thomas Witkowski committed
179
180
		   DimVec<double>& Lb,
		   double factor)
181
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
182
      int dim = Lb.getSize() - 1;
183
      const int dimOfWorld = Global::getGeo(WORLD);
184
185
186
187
188
189
190
191
192
193

      for (int i = 0; i <= dim; i++) {
	double val = 0.0;
      
	for (int j = 0; j < dimOfWorld; j++) {
	  val += Lambda[i][j];
	}
	val *= factor;
	Lb[i] += val;
      }    
194
    }
195
196

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
197
    /// Stores the properties of this OperatorTerm
198
199
    Flag properties;

Thomas Witkowski's avatar
Thomas Witkowski committed
200
    /// Polynomial degree of the term. Used to detemine the degree of the quadrature.
201
202
    int degree;

Thomas Witkowski's avatar
Thomas Witkowski committed
203
204
205
206
    /// List off all fe spaces, the operator term makes use off.
    std::vector<const FiniteElemSpace*> auxFESpaces;

    /// Pointer to the Operator this OperatorTerm belongs to.
207
208
    Operator* operat;

Thomas Witkowski's avatar
Thomas Witkowski committed
209
    /// Flag for piecewise constant terms
210
211
    static const Flag PW_CONST;

Thomas Witkowski's avatar
Thomas Witkowski committed
212
    /// Flag for symmetric terms
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
    static const Flag SYMMETRIC;

    friend class SubAssembler;
    friend class ZeroOrderAssembler;
    friend class FirstOrderAssembler;
    friend class SecondOrderAssembler;
    friend class Operator;
  };

  // ============================================================================
  // =====  class SecondOrderTerm ===============================================
  // ============================================================================

  /**
   * \ingroup Assembler
   * 
   * \brief
   * Describes the second order terms: \f$ \nabla \cdot A \nabla u(\vec{x}) \f$
   */
  class SecondOrderTerm : public OperatorTerm
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
235
    /// Constructor.
236
237
238
    SecondOrderTerm(int deg) 
      : OperatorTerm(deg) 
    {}
239
240
241
242

    /** \brief
     * Destructor.
     */
243
244
    virtual ~SecondOrderTerm() 
    {}
245
246
247
248
249

    /** \brief
     * Evaluation of \f$ \Lambda A \Lambda^t \f$ at all quadrature points.
     */
    virtual void getLALt(const ElInfo *elInfo, 
Thomas Witkowski's avatar
Thomas Witkowski committed
250
			 int nPoints, 
251
252
253
254
255
			 DimMat<double> **result) const = 0;

    /** \brief
     * Evaluation of \f$ A \nabla u(\vec{x}) \f$ at all quadrature points.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
256
    virtual void weakEval(int nPoints,
257
258
259
260
261
262
263
264
265
266
267
268
269
270
			  const WorldVector<double> *grdUhAtQP,
			  WorldVector<double> *result) const = 0;

  };

  /**
   * \ingroup Assembler
   * 
   * \brief
   * Implements the laplace operator: \f$ \Delta u(\vec{x}) \f$
   */
  class Laplace_SOT : public SecondOrderTerm 
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
271
    /// Constructor.
272
273
274
275
    Laplace_SOT() 
      : SecondOrderTerm(0) 
    {
      setSymmetric(true);
276
    }
277
278
279
280

    /** \brief
     * Implenetation of SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
281
    inline void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const
282
283
284
    {
      const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();

Thomas Witkowski's avatar
Thomas Witkowski committed
285
      for (int iq = 0; iq < nPoints; iq++) {
286
287
	l1lt(Lambda, *(LALt[iq]), 1.0);
      }
288
    }
289
290
291
292

    /** \brief
     * Implementation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
293
294
295
296
297
298
    inline void eval(int nPoints,
		     const double * ,    // uhAtQP
		     const WorldVector<double> * ,  // grdUhAtQP
		     const WorldMatrix<double> *D2UhAtQP,
		     double *result,
		     double factor) const
299
300
301
302
    {
      int dow = Global::getGeo(WORLD);
    
      if (D2UhAtQP) {
Thomas Witkowski's avatar
Thomas Witkowski committed
303
	for (int iq = 0; iq < nPoints; iq++) {
304
305
306
307
308
309
310
	  double resultQP = 0.0;
	  for (int i = 0; i < dow; i++) {
	    resultQP += D2UhAtQP[iq][i][i];
	  }
	  result[iq] += factor * resultQP;
	}
      }
311
    }
312
313
314
315

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
316
    void weakEval(int nPoints,
317
318
319
320
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const
    {
      if (grdUhAtQP) {
Thomas Witkowski's avatar
Thomas Witkowski committed
321
	for (int iq = 0; iq < nPoints; iq++) { 
322
323
324
	  result[iq] += grdUhAtQP[iq];
	}
      }
325
326
    }
  };
327
328
329
330
331
332
333
334
335
336
337

  /**
   * \ingroup Assembler
   * 
   * \brief
   * Implements the laplace operator multiplied with a scalar factor:
   * \f$ f \cdot \Delta u(\vec{x}) \f$
   */
  class FactorLaplace_SOT : public SecondOrderTerm 
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
338
    /// Constructor.
339
    FactorLaplace_SOT(double f) 
340
341
      : SecondOrderTerm(0)  
    {
342
343
344
345
      factor = new double;
      *factor = f;

      setSymmetric(true);
346
    }
347

Thomas Witkowski's avatar
Thomas Witkowski committed
348
    /// Constructor.
349
    FactorLaplace_SOT(double *fptr) 
350
351
      : SecondOrderTerm(0), 
	factor(fptr)
352
353
    {
      setSymmetric(true);
354
    }
355
356
357
358

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
359
    inline void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const
360
    {
361
      const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();
Thomas Witkowski's avatar
Thomas Witkowski committed
362
      for (int iq = 0; iq < nPoints; iq++) 
363
	l1lt(Lambda, *(LALt[iq]), (*factor));
364
    }
365
366
367
368
369


    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
370
    void eval(int nPoints,
371
	      const double *,
372
373
374
375
376
	      const WorldVector<double> *,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double f) const
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
377
      int dow = Global::getGeo(WORLD);
378

Thomas Witkowski's avatar
Thomas Witkowski committed
379
      if (D2UhAtQP) {
Thomas Witkowski's avatar
Thomas Witkowski committed
380
	for (int iq = 0; iq < nPoints; iq++) {
381
	  double resultQP = 0.0;
Thomas Witkowski's avatar
Thomas Witkowski committed
382
	  for (int i = 0; i < dow; i++) {
383
384
385
386
387
	    resultQP += D2UhAtQP[iq][i][i];
	  }
	  result[iq] += resultQP * f * (*factor);
	}
      }
388
    }
389
390
391
392

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
393
    void weakEval(int nPoints,
394
395
396
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
397
      if (grdUhAtQP) {
Thomas Witkowski's avatar
Thomas Witkowski committed
398
	for (int iq = 0; iq < nPoints; iq++) {
399
400
401
	  axpy(*factor, grdUhAtQP[iq], result[iq]);
	}
      }
402
    }
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421

  private:
    /** \brief
     * Pointer to the factor.
     */
    double *factor;
  };

  /**
   * \ingroup Assembler
   * 
   * \brief
   * SecondOrderTerm where A is a function which maps a DOFVector evaluated at
   * a given quadrature point to a WolrdMatrix:
   * \f$ \nabla \cdot A(v(\vec{x})) \nabla u(\vec{x}) \f$
   */
  class MatrixFct_SOT : public SecondOrderTerm 
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
422
    /// Constructor.
423
424
425
    MatrixFct_SOT(DOFVectorBase<double> *dv, 
		  AbstractFunction<WorldMatrix<double>, double> *fct,
		  AbstractFunction<WorldVector<double>, WorldMatrix<double> > *div,
Thomas Witkowski's avatar
Thomas Witkowski committed
426
		  bool sym = false);
427
428
429
430
431
432
433
434
435
436

    /** \brief
     * Implementation of \ref OperatorTerm::initElement().
     */
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
437
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
438
439
440
441
  
    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
442
443
    void eval(int nPoints,
	      const double *uhAtQP,
444
445
446
447
448
449
450
451
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
452
    void weakEval(int nPoints,
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

  protected:
    /** \brief
     * DOFVector to be evaluated at quadrature points.
     */
    DOFVectorBase<double>* vec;

    /** \brief
     * Pointer to the values of the DOFVector at quadrature points.
     */
    double* vecAtQPs;

    /** \brief
     * Function for A.
     */
    AbstractFunction<WorldMatrix<double>, double>* matrixFct;

Thomas Witkowski's avatar
Thomas Witkowski committed
472
473
474
    /** \brief
     *
     */
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
    AbstractFunction<WorldVector<double>, WorldMatrix<double> >* divFct;

    /** \brief
     * True, if \ref matrixFct produces always symmetric matrices.
     */
    bool symmetric;
  };

  /** 
   * \ingroup Assembler
   *
   * \brief
   * SecondOrderTerm where A is a given fixed WorldMatrix<double>:
   * \f$ \nabla \cdot A \nabla u(\vec{x}) \f$
   */
  class Matrix_SOT : public SecondOrderTerm {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
492
    /// Constructor
493
    Matrix_SOT(WorldMatrix<double> mat) 
Thomas Witkowski's avatar
Thomas Witkowski committed
494
      : SecondOrderTerm(0), matrix(mat)
495
496
497
    {
      symmetric = matrix.isSymmetric();
      setSymmetric(symmetric);
498
    }
499
500
501
502

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
503
    inline void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const{
504
505
506
      const DimVec<WorldVector<double> >& Lambda     = elInfo->getGrdLambda();
      //double det = elInfo->getDet();
      int iq;
Thomas Witkowski's avatar
Thomas Witkowski committed
507
      for(iq = 0; iq < nPoints; iq++) 
508
	lalt(Lambda, matrix, *(LALt[iq]), symmetric, 1.0);
509
    }
510
511
512
513
  
    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
514
515
    void eval(int nPoints,
	      const double *uhAtQP,
516
517
518
519
520
521
522
523
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
524
    void weakEval(int nPoints,
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
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

  protected:
    /** \brief
     * Matrix stroring A.
     */
    WorldMatrix<double> matrix;

    /** \brief
     * True, if \ref matrix is symmetric.
     */
    bool symmetric;
  };

  /** 
   * \ingroup Assembler
   *
   * \brief
   * SecondOrderTerm where A is a WorldMatrix<double> having a ONE in position IJ
   * and ZERO in all other positions
   * \f$ \nabla \cdot A \nabla u(\vec{x}) \f$
   */
  class FactorIJ_SOT : public SecondOrderTerm 
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
551
    /// Constructor.
552
    FactorIJ_SOT(int x_i, int x_j, double f) 
Thomas Witkowski's avatar
Thomas Witkowski committed
553
      : SecondOrderTerm(0), xi(x_i), xj(x_j)
554
555
556
557
558
    {
      factor = new double;
      *factor = f;

      setSymmetric(xi == xj);
559
    }
560

Thomas Witkowski's avatar
Thomas Witkowski committed
561
    /// Constructor.
562
    FactorIJ_SOT(int x_i, int x_j, double *fptr) 
Thomas Witkowski's avatar
Thomas Witkowski committed
563
      : SecondOrderTerm(0), xi(x_i), xj(x_j), factor(fptr)
564
565
    {
      setSymmetric(xi == xj);
566
    }
567
568
569
570

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
571
    inline void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const
572
573
574
    {
      const DimVec<WorldVector<double> > &Lambda     = elInfo->getGrdLambda();
      int iq;
Thomas Witkowski's avatar
Thomas Witkowski committed
575
      for(iq = 0; iq < nPoints; iq++)
576
	lalt_kl(Lambda, xi, xj, *(LALt[iq]), (*factor));
577
    }
578
579
580
581

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
582
    void eval(int nPoints,
583
584
585
586
587
588
589
590
	      const double              *,
	      const WorldVector<double> *,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double fac) const
    {
      int iq;
      if(D2UhAtQP) {
Thomas Witkowski's avatar
Thomas Witkowski committed
591
	for(iq = 0; iq < nPoints; iq++) {
592
593
594
	  result[iq] += (*factor) * D2UhAtQP[iq][xi][xj] * fac;
	}
      }
595
    }
596
597
598
599

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
600
    void weakEval(int nPoints,
601
602
603
604
605
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const
    {
      if(grdUhAtQP) {
	int iq;
Thomas Witkowski's avatar
Thomas Witkowski committed
606
	for(iq = 0; iq < nPoints; iq++) {
607
608
609
	  result[iq][xi] += (*factor) * grdUhAtQP[iq][xj];
	}
      }
610
    }
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633

  private:
    /** \brief
     * Directions for the derivatives.
     */
    int xi, xj;

    /** \brief
     * Pointer to the factor.
     */
    double *factor;
  };

  /**
   * \ingroup Assembler
   *  
   * \brief
   * Laplace operator multiplied with a function evaluated at the quadrature
   * points of a given DOFVector:
   * \f$ f(v(\vec{x})) \Delta u(\vec{x}) \f$
   */
  class VecAtQP_SOT : public SecondOrderTerm {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
634
635
    /// Constructor.
    VecAtQP_SOT(DOFVectorBase<double> *dv, AbstractFunction<double, double> *af);
636

Thomas Witkowski's avatar
Thomas Witkowski committed
637
    /// Implementation of \ref OperatorTerm::initElement().
638
639
640
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

Thomas Witkowski's avatar
Thomas Witkowski committed
641
642
643
644
645
    /// Implementation of \ref OperatorTerm::initElement() for multilpe meshes.
    void initElement(const ElInfo* smallElInfo,
		     const ElInfo* largeElInfo,
		     SubAssembler* subAssembler,
		     Quadrature *quad = NULL);
646

Thomas Witkowski's avatar
Thomas Witkowski committed
647
648
649
650
651
652
    /// Implements SecondOrderTerm::getLALt().
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;    

    /// Implenetation of SecondOrderTerm::eval().
    void eval(int nPoints,
	      const double *uhAtQP,
653
654
655
656
657
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

Thomas Witkowski's avatar
Thomas Witkowski committed
658
659
    /// Implenetation of SecondOrderTerm::weakEval().
    void weakEval(int nPoints,
660
661
662
663
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
664
    /// DOFVector to be evaluated at quadrature points.
665
666
    DOFVectorBase<double>* vec;

Thomas Witkowski's avatar
Thomas Witkowski committed
667
    /// Pointer to an array containing the DOFVector evaluated at quadrature points.
668
669
    double* vecAtQPs;

Thomas Witkowski's avatar
Thomas Witkowski committed
670
    /// Function evaluated at \ref vecAtQPs.
671
672
673
    AbstractFunction<double, double> *f;
  };

674
675
676
677
678
679
680
681
682
683
  /**
   * \ingroup Assembler
   *  
   * \brief
   * Laplace operator multiplied with a function evaluated at the quadrature
   * points of a given DOFVector:
   * \f$ f(v(\vec{x}), w(\vec{x})) \Delta u(\vec{x}) \f$
   */
  class Vec2AtQP_SOT : public SecondOrderTerm {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
684
    /// Constructor.
685
    Vec2AtQP_SOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2, 
Thomas Witkowski's avatar
Thomas Witkowski committed
686
		 BinaryAbstractFunction<double, double, double> *af);
687
688
689
690
691
692
693
694
695
696

    /** \brief
     * Implementation of \ref OperatorTerm::initElement().
     */
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
697
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;    
698
699
700
701
    
    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
702
    void eval(int nPoints,
703
704
705
706
707
708
709
710
711
	      const double *uhAtQP,
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;
    
    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
712
    void weakEval(int nPoints,
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;
    
  protected:
    /** \brief
     * DOFVector to be evaluated at quadrature points.
     */
    DOFVectorBase<double>* vec1;
    DOFVectorBase<double>* vec2;
    
    /** \brief
     * Pointer to an array containing the DOFVector evaluated at quadrature
     * points.
     */
    double* vecAtQPs1;
    double* vecAtQPs2;
    
    /** \brief
     * Function evaluated at \ref vecAtQPs.
     */
    BinaryAbstractFunction<double, double, double> *f;
  };

736
737
738
739
740
741
742
743
744
  /**
   * \ingroup Assembler
   * 
   * \brief
   * Laplace multiplied with a function evaluated at each quadrature point:
   * \f$ f(\vec{x}) \Delta u(\vec{x}) \f$
   */
  class CoordsAtQP_SOT : public SecondOrderTerm {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
745
746
747
    /// Constructor.
    CoordsAtQP_SOT(AbstractFunction<double, WorldVector<double> > *af)
      : SecondOrderTerm(af->getDegree()), g(af)
748
749
    {
      setSymmetric(true);
Thomas Witkowski's avatar
Thomas Witkowski committed
750
    }
751
752
753
754
755
756
757
758
759
760

    /** \brief
     * Implementation of \ref OperatorTerm::initElement().
     */
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
761
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;    
762
763
764
765

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
766
767
    void eval(int nPoints,
	      const double *uhAtQP,
768
769
770
771
772
773
774
775
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
776
    void weakEval(int nPoints,
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
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;


  protected:
    /** \brief
     * Stores coordinates at quadrature points. Set in \ref initElement().
     */
    WorldVector<double>* coordsAtQPs;

    /** \brief
     * Function evaluated at quadrature points.
     */
    AbstractFunction<double, WorldVector<double> > *g;
  };

  /**
   * \ingroup Assembler
   *
   * \brief
   * SecondOrderTerm where A is a function which maps the gradient of a 
   * DOFVector at each quadrature point to WorldMatrix<double>:
   * \f$ \nabla \cdot A(\nabla v(\vec{x})) \nabla u(\vec{x})\f$
   */
  class MatrixGradient_SOT : public SecondOrderTerm
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
804
    /// Constructor.
805
    MatrixGradient_SOT(DOFVectorBase<double> *dv,
Thomas Witkowski's avatar
Thomas Witkowski committed
806
807
808
		       AbstractFunction<WorldMatrix<double>, WorldVector<double> > *af,
		       AbstractFunction<WorldVector<double>, WorldMatrix<double> > *divAf,
		       bool symm = false);
809
810
811
812
813
814
815
816
817
818

    /** \brief
     * Implementation of \ref OperatorTerm::initElement().
     */
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
819
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
820
821
822
823

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
824
825
    void eval(int nPoints,
	      const double *uhAtQP,
826
827
828
829
830
831
832
833
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
834
    void weakEval(int nPoints,
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

  protected:
    DOFVectorBase<double>* vec;

    /** \brief
     * Function which maps each entry in \ref gradAtQPs to a WorldMatrix<double>.
     */
    AbstractFunction<WorldMatrix<double>, WorldVector<double> > *f;

    AbstractFunction<WorldVector<double>, WorldMatrix<double> > *divFct;

    /** \brief
     * Pointer to a WorldVector<double> array containing the gradients of the DOFVector
     * at each quadrature point.
     */
    WorldVector<double>* gradAtQPs;

    /** \brief
     * True, if \ref f provides always a symmetric WorldMatrix<double>.
     */
    bool symmetric;
  };

  /**
   * \ingroup Assembler
   *
   * \brief
   * Laplace multiplied with a function which maps the gradient of a DOFVector
   * at each quadrature point to a double:
   * \f$ f(\nabla v(\vec{x})) \Delta u(\vec{x}) \f$
   */
  class FctGradient_SOT : public SecondOrderTerm
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
871
872
873
    /// Constructor.
    FctGradient_SOT(DOFVectorBase<double> *dv,  
		    AbstractFunction<double, WorldVector<double> > *af);
874
875
876
877
878
879
880
881
882
883

    /** \brief
     * Implementation of \ref OperatorTerm::initElement().
     */
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
884
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
885
886
887
888

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
889
890
    void eval(int nPoints,
	      const double *uhAtQP,
891
892
893
894
895
896
897
898
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
899
    void weakEval(int nPoints,
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

  protected:
    DOFVectorBase<double>* vec;

    /** \brief
     * Function wich maps \ref gradAtQPs to a double.
     */
    AbstractFunction<double, WorldVector<double> > *f;

    /** \brief
     * Pointer to a WorldVector<double> array containing the gradients of the DOFVector
     * at each quadrature point.
     */
    WorldVector<double>* gradAtQPs;
  };


  /**
   * \ingroup Assembler
   *
   * \brief
   * Laplace multiplied with a function which maps the gradient of a DOFVector
   * at each quadrature point to a double:
   * \f$ f(\nabla v(\vec{x})) \Delta u(\vec{x}) \f$
   */
  class VecAndGradientAtQP_SOT : public SecondOrderTerm
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
930
    /// Constructor.
931
    VecAndGradientAtQP_SOT(DOFVectorBase<double> *dv,
Thomas Witkowski's avatar
Thomas Witkowski committed
932
			   BinaryAbstractFunction<double, double, WorldVector<double> > *af);
933
934
935
936
937
938
939
940
941
942

    /** \brief
     * Implementation of \ref OperatorTerm::initElement().
     */
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
943
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
944
945
946
947

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
948
949
    void eval(int nPoints,
	      const double *uhAtQP,
950
951
952
953
954
955
956
957
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
958
    void weakEval(int nPoints,
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

  protected:
    DOFVectorBase<double>* vec;

    /** \brief
     * Function wich maps \ref gradAtQPs to a double.
     */
    BinaryAbstractFunction<double, double, WorldVector<double> > *f;

    /** \brief
     * Pointer to a WorldVector<double> array containing the gradients of the DOFVector
     * at each quadrature point.
     */
    double* vecAtQPs;
    WorldVector<double>* gradAtQPs;
  };

978
979
980
981
982
983
984
985
986
987
988
  /**
   * \ingroup Assembler
   *
   * \brief
   * Laplace multiplied with a function which maps the gradient of a DOFVector
   * at each quadrature point to a double:
   * \f$ \nabla \cdot A(v(\vec{x}), \nabla v(\vec{x})) \nabla u(\vec{x}) \f$
   */
  class VecMatrixGradientAtQP_SOT : public SecondOrderTerm
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
989
    /// Constructor.
990
    VecMatrixGradientAtQP_SOT(DOFVectorBase<double> *dv,
Thomas Witkowski's avatar
Thomas Witkowski committed
991
992
993
			      BinaryAbstractFunction<WorldMatrix<double>, double, WorldVector<double> > *af,
			      AbstractFunction<WorldVector<double>, WorldMatrix<double> > *divAf,
			      bool symm = false);
994
995
996
997
998
999
1000
1001
1002
1003

    /** \brief
     * Implementation of \ref OperatorTerm::initElement().
     */
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1004
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
1005
1006
1007
1008

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1009
1010
    void eval(int nPoints,
	      const double *uhAtQP,
1011
1012
1013
1014
1015
1016
1017
1018
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1019
    void weakEval(int nPoints,
1020
1021
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;
Thomas Witkowski's avatar
Thomas Witkowski committed
1022
    
1023
1024
  protected:
    DOFVectorBase<double>* vec;
Thomas Witkowski's avatar
Thomas Witkowski committed
1025
    
1026
1027
1028
1029
1030
    /** \brief
     * Function wich maps \ref gradAtQPs to a double.
     */
    BinaryAbstractFunction<WorldMatrix<double>, 
			   double, WorldVector<double> > *f;
Thomas Witkowski's avatar
Thomas Witkowski committed
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
    
    AbstractFunction<WorldVector<double>, WorldMatrix<double> > *divFct;
    
    /** \brief
     * Pointer to a WorldVector<double> array containing the gradients of the DOFVector
     * at each quadrature point.
     */
    double* vecAtQPs;
    WorldVector<double>* gradAtQPs;
    
    bool symmetric;
  };
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054

  /**
   * \ingroup Assembler
   *
   * \brief
   * Laplace multiplied with a function which maps the gradient of a DOFVector
   * at each quadrature point to a double:
   * \f$ f(\nabla v(\vec{x})) \Delta u(\vec{x}) \f$
   */
  class VecGradCoordsAtQP_SOT : public SecondOrderTerm
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
1055
    /// Constructor.
1056
1057
    VecGradCoordsAtQP_SOT(DOFVectorBase<double> *dv,
			  TertiaryAbstractFunction<double, double,
Thomas Witkowski's avatar
Thomas Witkowski committed
1058
			  WorldVector<double>, WorldVector<double> > *af);
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068

    /** \brief
     * Implementation of \ref OperatorTerm::initElement().
     */
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1069
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
1070
1071
1072
1073

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1074
1075
    void eval(int nPoints,
	      const double *uhAtQP,
1076
1077
1078
1079
1080
1081
1082
1083
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1084
    void weakEval(int nPoints,
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

  protected:
    DOFVectorBase<double>* vec;

    /** \brief
     * Function wich maps \ref gradAtQPs to a double.
     */
    TertiaryAbstractFunction<double, double, WorldVector<double>,
			     WorldVector<double> > *f;

    /** \brief
     * Pointer to a WorldVector<double> array containing the gradients of the DOFVector
     * at each quadrature point.
     */
    double* vecAtQPs;
    WorldVector<double>* gradAtQPs;
    WorldVector<double>* coordsAtQPs;
  
  };


  /**
   * \ingroup Assembler
   *  
   * \brief
   * Laplace operator multiplied with a function evaluated at the quadrature
   * points of a given DOFVector:
   * \f$ -f(v(\vec{x})) \Delta u(\vec{x}) \f$
   */
  class VecAndCoordsAtQP_SOT : public SecondOrderTerm {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
1118
    /// Constructor.
1119
    VecAndCoordsAtQP_SOT(DOFVectorBase<double> *dv, 
Thomas Witkowski's avatar
Thomas Witkowski committed
1120
			 BinaryAbstractFunction<double, double, WorldVector<double> > *af);
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130

    /** \brief
     * Implementation of \ref OperatorTerm::initElement().
     */
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /** \brief
     * Implements SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1131
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;    
1132

Thomas Witkowski's avatar
Thomas Witkowski committed
1133
1134
    void eval(int nPoints,
	      const double *uhAtQP,
1135
1136
1137
1138
1139
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

Thomas Witkowski's avatar
Thomas Witkowski committed
1140
    void weakEval(int nPoints,
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

  protected:
    /** \brief
     * DOFVector to be evaluated at quadrature points.
     */
    DOFVectorBase<double>* vec;

    /** \brief
     * Pointer to an array containing the DOFVector evaluated at quadrature
     * points.
     */
    double* vecAtQPs;
  
    WorldVector<double>* coordsAtQPs;

    /** \brief
     * Function evaluated at \ref vecAtQPs.
     */
    BinaryAbstractFunction<double, double,  WorldVector<double> > *f;
  };

  /**
   * \ingroup Assembler
   *
   * \brief
   * SecondOrderTerm where A is a function which maps the gradient of a 
   * DOFVector at each quadrature point to WorldMatrix<double>:
   * \f$ \nabla \cdot A(\nabla v(\vec{x})) \nabla u(\vec{x})\f$
   */
  class MatrixGradientAndCoords_SOT : public SecondOrderTerm
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
1175
    /// Constructor.
1176
1177
1178
    MatrixGradientAndCoords_SOT(DOFVectorBase<double> *dv,
				BinaryAbstractFunction<WorldMatrix<double>,
				WorldVector<double> , 
Thomas Witkowski's avatar
Thomas Witkowski committed
1179
				WorldVector<double> > *af,
1180
				AbstractFunction<WorldVector<double>,
Thomas Witkowski's avatar
Thomas Witkowski committed
1181
1182
				WorldMatrix<double> > *divAf,
				bool symm = false);
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192

    /** \brief
     * Implementation of \ref OperatorTerm::initElement().
     */
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1193
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
1194
1195
1196
1197

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1198
1199
    void eval(int nPoints,
	      const double *uhAtQP,
1200
1201
1202
1203
1204
1205
1206
1207
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1208
    void weakEval(int nPoints,
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

  protected:
    DOFVectorBase<double>* vec;

    /** \brief
     * Function which maps each entry in \ref gradAtQPs to a WorldMatrix<double>.
     */
    BinaryAbstractFunction<WorldMatrix<double>,
			   WorldVector<double>, WorldVector<double> > *f;

    AbstractFunction<WorldVector<double>, WorldMatrix<double> > *divFct;

    /** \brief
     * Pointer to a WorldVector<double> array containing the gradients of the DOFVector
     * at each quadrature point.
     */
    WorldVector<double>* gradAtQPs;

    WorldVector<double>* coordsAtQPs;

    /** \brief
     * True, if \ref f provides always a symmetric WorldMatrix<double>.
     */
    bool symmetric;
  };

  class General_SOT : public SecondOrderTerm
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
1240
    /// Constructor.
1241
1242
    General_SOT(std::vector<DOFVectorBase<double>*> vecs,
		std::vector<DOFVectorBase<double>*> grads,
1243
1244
		TertiaryAbstractFunction<WorldMatrix<double>, 
		  WorldVector<double>,
1245
1246
		  std::vector<double>, 
		  std::vector<WorldVector<double> > > *f,
1247
1248
		AbstractFunction<WorldVector<double>, 
		  WorldMatrix<double> > *divFct,
Thomas Witkowski's avatar
Thomas Witkowski committed
1249
		bool symmetric);
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260

    /** \brief
     * Implementation of \ref OperatorTerm::initElement().
     */
    void initElement(const ElInfo*, 
		     SubAssembler* ,
		     Quadrature *quad= NULL);

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1261
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
1262
1263
1264
1265

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1266
1267
    void eval(int nPoints,
	      const double *uhAtQP,
1268
1269
1270
1271
1272
1273
1274
1275
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1276
    void weakEval(int nPoints,
1277
1278
1279
1280
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

  protected:
1281
    std::vector<DOFVectorBase<double>*> vecs_; 
1282

1283
    std::vector<DOFVectorBase<double>*> grads_;
1284
1285
1286

    TertiaryAbstractFunction<WorldMatrix<double>, 
			     WorldVector<double>,
1287
1288
			     std::vector<double>, 
			     std::vector<WorldVector<double> > > *f_;
1289
1290
1291
1292
1293
1294

    AbstractFunction<WorldVector<double>, 
		     WorldMatrix<double> > *divFct_;

    WorldVector<double> *coordsAtQPs_;

1295
    std::vector<double*> vecsAtQPs_;
1296

1297
    std::vector<WorldVector<double>*> gradsAtQPs_;
1298
1299
1300
1301
1302
1303
1304

    bool symmetric_;
  };

  class GeneralParametric_SOT : public SecondOrderTerm
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
1305
    /// Constructor.
1306
1307
    GeneralParametric_SOT(std::vector<DOFVectorBase<double>*> vecs,
			  std::vector<DOFVectorBase<double>*> grads,
1308
1309
1310
			  QuartAbstractFunction<WorldMatrix<double>, 
			  WorldVector<double>,
			  WorldVector<double>,
1311
1312
			  std::vector<double>, 
			  std::vector<WorldVector<double> > > *f,
1313
1314
			  AbstractFunction<WorldVector<double>, 
			  WorldMatrix<double> > *divFct,
Thomas Witkowski's avatar
Thomas Witkowski committed
1315
			  bool symmetric);
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326

    /** \brief
     * Implementation of \ref OperatorTerm::initElement().
     */
    void initElement(const ElInfo*, 
		     SubAssembler* ,
		     Quadrature *quad= NULL);

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1327
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
1328
1329
1330
1331

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1332
1333
    void eval(int nPoints,
	      const double *uhAtQP,
1334
1335
1336
1337
1338
1339
1340
1341
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1342
    void weakEval(int nPoints,
1343
1344
1345
1346
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

  protected:
1347
    std::vector<DOFVectorBase<double>*> vecs_; 
1348

1349
    std::vector<DOFVectorBase<double>*> grads_;
1350
1351
1352
1353

    QuartAbstractFunction<WorldMatrix<double>, 
			  WorldVector<double>,
			  WorldVector<double>,
1354
1355
			  std::vector<double>, 
			  std::vector<WorldVector<double> > > *f_;
1356
1357
1358
1359
1360
1361
1362

    AbstractFunction<WorldVector<double>, 
		     WorldMatrix<double> > *divFct_;

    WorldVector<double> *coordsAtQPs_;
    WorldVector<double> elementNormal_;

1363
    std::vector<double*> vecsAtQPs_;
1364

1365
    std::vector<WorldVector<double>*> gradsAtQPs_;
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383

    bool symmetric_;
  };


  // ============================================================================
  // ===== class FirstOrderTerm =================================================
  // ============================================================================

  /**
   * \ingroup Assembler
   * 
   * \brief
   * Describes the first order terms: \f$ b \cdot \nabla u(\vec{x}) \f$
   */
  class FirstOrderTerm : public OperatorTerm
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
1384
    /// Constructor.
1385
1386
    FirstOrderTerm(int deg) 
      : OperatorTerm(deg) 
Thomas Witkowski's avatar
Thomas Witkowski committed
1387
    {}
1388
1389
1390
1391

    /** \brief
     * Destructor.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1392
    virtual ~FirstOrderTerm() {}
1393
1394
1395
1396
1397

    /** \brief
     * Evaluation of \f$ \Lambda b \f$.
     */
    virtual void getLb(const ElInfo *elInfo,
Thomas Witkowski's avatar
Thomas Witkowski committed
1398
		       int nPoints, 
1399
1400
1401
1402
1403
		       VectorOfFixVecs<DimVec<double> >& result) const = 0;

    /** \brief
     * Implenetation of FirstOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1404
1405
    void eval(int nPoints,
	      const double *,
1406
1407
1408
1409
1410
1411
1412
1413
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *,
	      double *result,
	      double factor) const 
    {
      int dow = Global::getGeo(WORLD);

      if (grdUhAtQP) {
Thomas Witkowski's avatar
Thomas Witkowski committed
1414
	for (int iq = 0; iq < nPoints; iq++) {
1415
1416
1417
1418
1419
1420
1421
	  double resultQP = 0.0;
	  for (int i = 0; i < dow; i++) {
	    resultQP += grdUhAtQP[iq][i];
	  }
	  result[iq] += resultQP * factor;
	}
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
1422
    }
1423

Thomas Witkowski's avatar
Thomas Witkowski committed
1424
  };
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435

  /**
   * \ingroup Assembler
   *
   * \brief
   * First order term: \f$ b \cdot \nabla u(\vec{x}) \f$ with a vector b which 
   * only consits of entries equal to one.
   */
  class Simple_FOT : public FirstOrderTerm
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
1436
    /// Constructor.
1437
1438
    Simple_FOT() 
      : FirstOrderTerm(0) 
Thomas Witkowski's avatar
Thomas Witkowski committed
1439
    {}
1440
1441
1442
1443
1444

    /** \brief
     * Implements FirstOrderTerm::getLb().
     */
    inline void getLb(const ElInfo *elInfo, 
Thomas Witkowski's avatar
Thomas Witkowski committed
1445
		      int nPoints, 
1446
1447
1448
1449
		      VectorOfFixVecs<DimVec<double> >& Lb) const 
    {
      const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();

Thomas Witkowski's avatar
Thomas Witkowski committed
1450
      for (int iq = 0; iq < nPoints; iq++) {
1451
1452
	l1(Lambda, Lb[iq], 1.0);
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
1453
    }