Operator.h 104 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
    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.
80
81
    std::vector<const FiniteElemSpace*>& getAuxFESpaces() 
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
82
83
84
85
      return auxFESpaces;
    }

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

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

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

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

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

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
112
113
     * Determines the value of a dof vector at the quadrature points of a given 
     * element. It is used by all VecAtQP like operator terms.
114
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
    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
132
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
133
134
135
136
137
    WorldVector<double>* getGradientsAtQPs(DOFVectorBase<double>* vec,
					   const ElInfo* elInfo,
					   SubAssembler* subAssembler,
					   Quadrature *quad);

Thomas Witkowski's avatar
Thomas Witkowski committed
138
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
139
140
141
142
143
144
145
146
    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$.
147
    static void lalt(const DimVec<WorldVector<double> >& Lambda,
Thomas Witkowski's avatar
Thomas Witkowski committed
148
149
150
151
		     const WorldMatrix<double>& matrix,
		     DimMat<double>& LALt,
		     bool symm,
		     double factor);
152
153
154
155
156
157
158
159

    /** \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
160
161
			DimMat<double>& LALt,
			double factor);
162

163
164
    /// 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
    /// Evaluation of \f$ \Lambda \cdot b\f$ if b contains the value 1.0 in each component.
175
    static void l1(const DimVec<WorldVector<double> >& Lambda,
Thomas Witkowski's avatar
Thomas Witkowski committed
176
177
		   DimVec<double>& Lb,
		   double factor)
178
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
179
      int dim = Lb.getSize() - 1;
180
      const int dimOfWorld = Global::getGeo(WORLD);
181
182
183
184

      for (int i = 0; i <= dim; i++) {
	double val = 0.0;
      
185
	for (int j = 0; j < dimOfWorld; j++)
186
	  val += Lambda[i][j];
187

188
189
190
	val *= factor;
	Lb[i] += val;
      }    
191
    }
192
193

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
194
    /// Stores the properties of this OperatorTerm
195
196
    Flag properties;

Thomas Witkowski's avatar
Thomas Witkowski committed
197
    /// Polynomial degree of the term. Used to detemine the degree of the quadrature.
198
199
    int degree;

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

    /// Pointer to the Operator this OperatorTerm belongs to.
204
205
    Operator* operat;

Thomas Witkowski's avatar
Thomas Witkowski committed
206
    /// Flag for piecewise constant terms
207
208
    static const Flag PW_CONST;

Thomas Witkowski's avatar
Thomas Witkowski committed
209
    /// Flag for symmetric terms
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
    static const Flag SYMMETRIC;

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

  /**
   * \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
228
    /// Constructor.
229
230
231
    SecondOrderTerm(int deg) 
      : OperatorTerm(deg) 
    {}
232

233
    /// Destructor.
234
235
    virtual ~SecondOrderTerm() 
    {}
236

237
    /// Evaluation of \f$ \Lambda A \Lambda^t \f$ at all quadrature points.
238
    virtual void getLALt(const ElInfo *elInfo, 
Thomas Witkowski's avatar
Thomas Witkowski committed
239
			 int nPoints, 
240
241
			 DimMat<double> **result) const = 0;

242
    /// Evaluation of \f$ A \nabla u(\vec{x}) \f$ at all quadrature points.
Thomas Witkowski's avatar
Thomas Witkowski committed
243
    virtual void weakEval(int nPoints,
244
245
246
247
248
249
250
251
252
253
254
255
256
257
			  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
258
    /// Constructor.
259
260
261
262
    Laplace_SOT() 
      : SecondOrderTerm(0) 
    {
      setSymmetric(true);
263
    }
264

265
    /// Implenetation of SecondOrderTerm::getLALt().
Thomas Witkowski's avatar
Thomas Witkowski committed
266
    inline void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const
267
268
269
    {
      const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();

270
      for (int iq = 0; iq < nPoints; iq++)
271
	l1lt(Lambda, *(LALt[iq]), 1.0);
272
    }
273

274
    /// Implementation of SecondOrderTerm::eval().
Thomas Witkowski's avatar
Thomas Witkowski committed
275
    inline void eval(int nPoints,
276
277
		     const double *,
		     const WorldVector<double> *,
Thomas Witkowski's avatar
Thomas Witkowski committed
278
279
280
		     const WorldMatrix<double> *D2UhAtQP,
		     double *result,
		     double factor) const
281
282
283
284
    {
      int dow = Global::getGeo(WORLD);
    
      if (D2UhAtQP) {
Thomas Witkowski's avatar
Thomas Witkowski committed
285
	for (int iq = 0; iq < nPoints; iq++) {
286
	  double resultQP = 0.0;
287
	  for (int i = 0; i < dow; i++) 
288
289
290
291
	    resultQP += D2UhAtQP[iq][i][i];
	  result[iq] += factor * resultQP;
	}
      }
292
    }
293

294
    /// Implenetation of SecondOrderTerm::weakEval().
Thomas Witkowski's avatar
Thomas Witkowski committed
295
    void weakEval(int nPoints,
296
297
298
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const
    {
299
      if (grdUhAtQP)
300
	for (int iq = 0; iq < nPoints; iq++)
301
	  result[iq] += grdUhAtQP[iq];
302
303
    }
  };
304
305
306
307
308
309
310
311
312
313
314

  /**
   * \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
315
    /// Constructor.
316
    FactorLaplace_SOT(double f) 
317
318
      : SecondOrderTerm(0)  
    {
319
320
321
322
      factor = new double;
      *factor = f;

      setSymmetric(true);
323
    }
324

Thomas Witkowski's avatar
Thomas Witkowski committed
325
    /// Constructor.
326
    FactorLaplace_SOT(double *fptr) 
327
328
      : SecondOrderTerm(0), 
	factor(fptr)
329
330
    {
      setSymmetric(true);
331
    }
332

333
    /// Implements SecondOrderTerm::getLALt().
Thomas Witkowski's avatar
Thomas Witkowski committed
334
    inline void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const
335
    {
336
      const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();
Thomas Witkowski's avatar
Thomas Witkowski committed
337
      for (int iq = 0; iq < nPoints; iq++) 
338
	l1lt(Lambda, *(LALt[iq]), (*factor));
339
    }
340

341
    /// Implenetation of SecondOrderTerm::eval().
Thomas Witkowski's avatar
Thomas Witkowski committed
342
    void eval(int nPoints,
343
	      const double *,
344
345
346
347
348
	      const WorldVector<double> *,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double f) const
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
349
      int dow = Global::getGeo(WORLD);
350

Thomas Witkowski's avatar
Thomas Witkowski committed
351
      if (D2UhAtQP) {
Thomas Witkowski's avatar
Thomas Witkowski committed
352
	for (int iq = 0; iq < nPoints; iq++) {
353
	  double resultQP = 0.0;
Thomas Witkowski's avatar
Thomas Witkowski committed
354
	  for (int i = 0; i < dow; i++) {
355
356
357
358
359
	    resultQP += D2UhAtQP[iq][i][i];
	  }
	  result[iq] += resultQP * f * (*factor);
	}
      }
360
    }
361

362
    /// Implenetation of SecondOrderTerm::weakEval().
Thomas Witkowski's avatar
Thomas Witkowski committed
363
    void weakEval(int nPoints,
364
365
366
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const
    {
367
368
      if (grdUhAtQP)
	for (int iq = 0; iq < nPoints; iq++)
369
	  axpy(*factor, grdUhAtQP[iq], result[iq]);
370
    }
371
372

  private:
373
    /// Pointer to the factor.
374
375
376
377
378
379
380
381
382
383
384
385
386
387
    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
388
    /// Constructor.
389
390
391
    MatrixFct_SOT(DOFVectorBase<double> *dv, 
		  AbstractFunction<WorldMatrix<double>, double> *fct,
		  AbstractFunction<WorldVector<double>, WorldMatrix<double> > *div,
Thomas Witkowski's avatar
Thomas Witkowski committed
392
		  bool sym = false);
393
394
395
396
397
398
399
400
401
402

    /** \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
403
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
404
405
406
407
  
    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
408
409
    void eval(int nPoints,
	      const double *uhAtQP,
410
411
412
413
414
415
416
417
	      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
418
    void weakEval(int nPoints,
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
		  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
438
439
440
    /** \brief
     *
     */
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
    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
458
    /// Constructor
459
    Matrix_SOT(WorldMatrix<double> mat) 
Thomas Witkowski's avatar
Thomas Witkowski committed
460
      : SecondOrderTerm(0), matrix(mat)
461
462
463
    {
      symmetric = matrix.isSymmetric();
      setSymmetric(symmetric);
464
    }
465
466
467
468

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
469
470
471
472
    inline void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const
    {
      const DimVec<WorldVector<double> >& Lambda = elInfo->getGrdLambda();
      for (int iq = 0; iq < nPoints; iq++) 
473
	lalt(Lambda, matrix, *(LALt[iq]), symmetric, 1.0);
474
    }
475
476
477
478
  
    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
479
480
    void eval(int nPoints,
	      const double *uhAtQP,
481
482
483
484
485
486
487
488
	      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
489
    void weakEval(int nPoints,
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
		  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
516
    /// Constructor.
517
    FactorIJ_SOT(int x_i, int x_j, double f) 
Thomas Witkowski's avatar
Thomas Witkowski committed
518
      : SecondOrderTerm(0), xi(x_i), xj(x_j)
519
520
521
522
523
    {
      factor = new double;
      *factor = f;

      setSymmetric(xi == xj);
524
    }
525

Thomas Witkowski's avatar
Thomas Witkowski committed
526
    /// Constructor.
527
    FactorIJ_SOT(int x_i, int x_j, double *fptr) 
Thomas Witkowski's avatar
Thomas Witkowski committed
528
      : SecondOrderTerm(0), xi(x_i), xj(x_j), factor(fptr)
529
530
    {
      setSymmetric(xi == xj);
531
    }
532
533
534
535

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
536
    inline void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const
537
538
    {
      const DimVec<WorldVector<double> > &Lambda     = elInfo->getGrdLambda();
539
      for (int iq = 0; iq < nPoints; iq++)
540
	lalt_kl(Lambda, xi, xj, *(LALt[iq]), (*factor));
541
    }
542
543
544
545

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
546
    void eval(int nPoints,
547
548
549
550
551
552
	      const double              *,
	      const WorldVector<double> *,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double fac) const
    {
553
554
      if (D2UhAtQP)
	for (int iq = 0; iq < nPoints; iq++)
555
	  result[iq] += (*factor) * D2UhAtQP[iq][xi][xj] * fac;
556
    }
557
558
559
560

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
561
    void weakEval(int nPoints,
562
563
564
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const
    {
565
566
      if (grdUhAtQP)
	for (int iq = 0; iq < nPoints; iq++)
567
	  result[iq][xi] += (*factor) * grdUhAtQP[iq][xj];
568
    }
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591

  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
592
593
    /// Constructor.
    VecAtQP_SOT(DOFVectorBase<double> *dv, AbstractFunction<double, double> *af);
594

Thomas Witkowski's avatar
Thomas Witkowski committed
595
    /// Implementation of \ref OperatorTerm::initElement().
596
597
598
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

Thomas Witkowski's avatar
Thomas Witkowski committed
599
600
601
602
603
    /// Implementation of \ref OperatorTerm::initElement() for multilpe meshes.
    void initElement(const ElInfo* smallElInfo,
		     const ElInfo* largeElInfo,
		     SubAssembler* subAssembler,
		     Quadrature *quad = NULL);
604

Thomas Witkowski's avatar
Thomas Witkowski committed
605
606
607
608
609
610
    /// 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,
611
612
613
614
615
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

Thomas Witkowski's avatar
Thomas Witkowski committed
616
617
    /// Implenetation of SecondOrderTerm::weakEval().
    void weakEval(int nPoints,
618
619
620
621
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

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

Thomas Witkowski's avatar
Thomas Witkowski committed
625
    /// Pointer to an array containing the DOFVector evaluated at quadrature points.
626
627
    double* vecAtQPs;

Thomas Witkowski's avatar
Thomas Witkowski committed
628
    /// Function evaluated at \ref vecAtQPs.
629
630
631
    AbstractFunction<double, double> *f;
  };

632
633
634
635
636
637
638
639
640
641
  /**
   * \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
642
    /// Constructor.
643
    Vec2AtQP_SOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2, 
Thomas Witkowski's avatar
Thomas Witkowski committed
644
		 BinaryAbstractFunction<double, double, double> *af);
645
646
647
648
649
650
651
652
653
654

    /** \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
655
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;    
656
657
658
659
    
    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
660
    void eval(int nPoints,
661
662
663
664
665
666
667
668
669
	      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
670
    void weakEval(int nPoints,
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
		  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;
  };

694
695
696
697
698
699
700
701
702
  /**
   * \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
703
704
705
    /// Constructor.
    CoordsAtQP_SOT(AbstractFunction<double, WorldVector<double> > *af)
      : SecondOrderTerm(af->getDegree()), g(af)
706
707
    {
      setSymmetric(true);
Thomas Witkowski's avatar
Thomas Witkowski committed
708
    }
709
710
711
712
713
714
715
716
717
718

    /** \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
719
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;    
720
721
722
723

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
724
725
    void eval(int nPoints,
	      const double *uhAtQP,
726
727
728
729
730
731
732
733
	      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
734
    void weakEval(int nPoints,
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
		  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
762
    /// Constructor.
763
    MatrixGradient_SOT(DOFVectorBase<double> *dv,
Thomas Witkowski's avatar
Thomas Witkowski committed
764
765
766
		       AbstractFunction<WorldMatrix<double>, WorldVector<double> > *af,
		       AbstractFunction<WorldVector<double>, WorldMatrix<double> > *divAf,
		       bool symm = false);
767
768
769
770
771
772
773
774
775
776

    /** \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
777
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
778
779
780
781

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
782
783
    void eval(int nPoints,
	      const double *uhAtQP,
784
785
786
787
788
789
790
791
	      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
792
    void weakEval(int nPoints,
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
		  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
829
830
831
    /// Constructor.
    FctGradient_SOT(DOFVectorBase<double> *dv,  
		    AbstractFunction<double, WorldVector<double> > *af);
832
833
834
835
836
837
838
839
840
841

    /** \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
842
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
843
844
845
846

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
847
848
    void eval(int nPoints,
	      const double *uhAtQP,
849
850
851
852
853
854
855
856
	      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
857
    void weakEval(int nPoints,
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
		  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
888
    /// Constructor.
889
    VecAndGradientAtQP_SOT(DOFVectorBase<double> *dv,
Thomas Witkowski's avatar
Thomas Witkowski committed
890
			   BinaryAbstractFunction<double, double, WorldVector<double> > *af);
891
892
893
894
895
896
897
898
899
900

    /** \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
901
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
902
903
904
905

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
906
907
    void eval(int nPoints,
	      const double *uhAtQP,
908
909
910
911
912
913
914
915
	      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
916
    void weakEval(int nPoints,
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
		  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;
  };

936
937
938
939
940
941
942
943
944
945
946
  /**
   * \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
947
    /// Constructor.
948
    VecMatrixGradientAtQP_SOT(DOFVectorBase<double> *dv,
Thomas Witkowski's avatar
Thomas Witkowski committed
949
950
951
			      BinaryAbstractFunction<WorldMatrix<double>, double, WorldVector<double> > *af,
			      AbstractFunction<WorldVector<double>, WorldMatrix<double> > *divAf,
			      bool symm = false);
952
953
954
955
956
957
958
959
960
961

    /** \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
962
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
963
964
965
966

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
967
968
    void eval(int nPoints,
	      const double *uhAtQP,
969
970
971
972
973
974
975
976
	      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
977
    void weakEval(int nPoints,
978
979
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;
Thomas Witkowski's avatar
Thomas Witkowski committed
980
    
981
982
  protected:
    DOFVectorBase<double>* vec;
Thomas Witkowski's avatar
Thomas Witkowski committed
983
    
984
985
986
987
988
    /** \brief
     * Function wich maps \ref gradAtQPs to a double.
     */
    BinaryAbstractFunction<WorldMatrix<double>, 
			   double, WorldVector<double> > *f;
Thomas Witkowski's avatar
Thomas Witkowski committed
989
990
991
992
993
994
995
996
997
998
999
1000
    
    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;
  };
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012

  /**
   * \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
1013
    /// Constructor.
1014
1015
    VecGradCoordsAtQP_SOT(DOFVectorBase<double> *dv,
			  TertiaryAbstractFunction<double, double,
Thomas Witkowski's avatar
Thomas Witkowski committed
1016
			  WorldVector<double>, WorldVector<double> > *af);
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026

    /** \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
1027
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
1028
1029
1030
1031

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1032
1033
    void eval(int nPoints,
	      const double *uhAtQP,
1034
1035
1036
1037
1038
1039
1040
1041
	      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
1042
    void weakEval(int nPoints,
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
		  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
1076
    /// Constructor.
1077
    VecAndCoordsAtQP_SOT(DOFVectorBase<double> *dv, 
Thomas Witkowski's avatar
Thomas Witkowski committed
1078
			 BinaryAbstractFunction<double, double, WorldVector<double> > *af);
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088

    /** \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
1089
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;    
1090

Thomas Witkowski's avatar
Thomas Witkowski committed
1091
1092
    void eval(int nPoints,
	      const double *uhAtQP,
1093
1094
1095
1096
1097
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

Thomas Witkowski's avatar
Thomas Witkowski committed
1098
    void weakEval(int nPoints,
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
		  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
1133
    /// Constructor.
1134
1135
1136
    MatrixGradientAndCoords_SOT(DOFVectorBase<double> *dv,
				BinaryAbstractFunction<WorldMatrix<double>,
				WorldVector<double> , 
Thomas Witkowski's avatar
Thomas Witkowski committed
1137
				WorldVector<double> > *af,
1138
				AbstractFunction<WorldVector<double>,
Thomas Witkowski's avatar
Thomas Witkowski committed
1139
1140
				WorldMatrix<double> > *divAf,
				bool symm = false);
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150

    /** \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
1151
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
1152
1153
1154
1155

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1156
1157
    void eval(int nPoints,
	      const double *uhAtQP,
1158
1159
1160
1161
1162
1163
1164
1165
	      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
1166
    void weakEval(int nPoints,
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
		  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
1198
    /// Constructor.
1199
1200
    General_SOT(std::vector<DOFVectorBase<double>*> vecs,
		std::vector<DOFVectorBase<double>*> grads,
1201
1202
		TertiaryAbstractFunction<WorldMatrix<double>, 
		  WorldVector<double>,
1203
1204
		  std::vector<double>, 
		  std::vector<WorldVector<double> > > *f,
1205
1206
		AbstractFunction<WorldVector<double>, 
		  WorldMatrix<double> > *divFct,
Thomas Witkowski's avatar
Thomas Witkowski committed
1207
		bool symmetric);
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218

    /** \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
1219
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
1220
1221
1222
1223

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1224
1225
    void eval(int nPoints,
	      const double *uhAtQP,
1226
1227
1228
1229
1230
1231
1232
1233
	      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
1234
    void weakEval(int nPoints,
1235
1236
1237
1238
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

  protected:
1239
    std::vector<DOFVectorBase<double>*> vecs_; 
1240

1241
    std::vector<DOFVectorBase<double>*> grads_;
1242
1243
1244

    TertiaryAbstractFunction<WorldMatrix<double>, 
			     WorldVector<double>,
1245
1246
			     std::vector<double>, 
			     std::vector<WorldVector<double> > > *f_;
1247
1248
1249
1250
1251
1252

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

    WorldVector<double> *coordsAtQPs_;

1253
    std::vector<double*> vecsAtQPs_;
1254

1255
    std::vector<WorldVector<double>*> gradsAtQPs_;
1256
1257
1258
1259
1260
1261
1262

    bool symmetric_;
  };

  class GeneralParametric_SOT : public SecondOrderTerm
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
1263
    /// Constructor.
1264
1265
    GeneralParametric_SOT(std::vector<DOFVectorBase<double>*> vecs,
			  std::vector<DOFVectorBase<double>*> grads,
1266
1267
1268
			  QuartAbstractFunction<WorldMatrix<double>, 
			  WorldVector<double>,
			  WorldVector<double>,
1269
1270
			  std::vector<double>, 
			  std::vector<WorldVector<double> > > *f,
1271
1272
			  AbstractFunction<WorldVector<double>, 
			  WorldMatrix<double> > *divFct,
Thomas Witkowski's avatar
Thomas Witkowski committed
1273
			  bool symmetric);
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284

    /** \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
1285
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
1286
1287
1288
1289

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1290
1291
    void eval(int nPoints,
	      const double *uhAtQP,
1292
1293
1294
1295
1296
1297
1298
1299
	      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
1300
    void weakEval(int nPoints,
1301
1302
1303
1304
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

  protected:
1305
    std::vector<DOFVectorBase<double>*> vecs_; 
1306

1307
    std::vector<DOFVectorBase<double>*> grads_;
1308
1309
1310
1311

    QuartAbstractFunction<WorldMatrix<double>, 
			  WorldVector<double>,
			  WorldVector<double>,
1312
1313
			  std::vector<double>, 
			  std::vector<WorldVector<double> > > *f_;
1314
1315
1316
1317
1318
1319
1320

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

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

1321
    std::vector<double*> vecsAtQPs_;
1322

1323
    std::vector<WorldVector<double>*> gradsAtQPs_;
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341

    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
1342
    /// Constructor.
1343
1344
    FirstOrderTerm(int deg) 
      : OperatorTerm(deg) 
Thomas Witkowski's avatar
Thomas Witkowski committed
1345
    {}
1346
1347
1348
1349

    /** \brief
     * Destructor.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1350
    virtual ~FirstOrderTerm() {}
1351
1352
1353
1354
1355

    /** \brief
     * Evaluation of \f$ \Lambda b \f$.
     */
    virtual void getLb(const ElInfo *elInfo,
Thomas Witkowski's avatar
Thomas Witkowski committed
1356
		       int nPoints, 
1357
1358
1359
1360
1361
		       VectorOfFixVecs<DimVec<double> >& result) const = 0;

    /** \brief
     * Implenetation of FirstOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1362
1363
    void eval(int nPoints,
	      const double *,
1364
1365
1366
1367
1368
1369
1370
1371
	      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
1372
	for (int iq = 0; iq < nPoints; iq++) {
1373
1374
1375
1376
1377
1378
1379
	  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