Operator.h 97 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// ============================================================================
// ==                                                                        ==
// == 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>
#include "FixVec.h"
#include "Flag.h"
#include "MemoryManager.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

namespace AMDiS {

  class Assembler;
  class ElInfo;
  class FiniteElemSpace;
  class Operator;
  class SubAssembler;
  class ElementMatrix;
  class ElementVector;
  class Quadrature;
  template<typename T> class DOFVectorBase;

  // ============================================================================
  // ===== class OperatorTerm ===================================================
  // ============================================================================

  /** 
   * \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:
    MEMORY_MANAGED(OperatorTerm);

    /** \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
70
    OperatorTerm(int deg) 
71
      : properties(0), 
Thomas Witkowski's avatar
Thomas Witkowski committed
72
73
	degree(deg),
	auxFESpaces(0)
74
    {}
75

Thomas Witkowski's avatar
Thomas Witkowski committed
76
77
    /// Destructor.
    virtual ~OperatorTerm() {}
78
79
80

    /** \brief
     * Virtual method. It's called by SubAssembler::initElement() for
Thomas Witkowski's avatar
Thomas Witkowski committed
81
82
     * each OperatorTerm belonging to this SubAssembler. E.g., vectors
     * and coordinates at quadrature points can be calculated here.
83
84
     */
    virtual void initElement(const ElInfo*, 
Thomas Witkowski's avatar
Thomas Witkowski committed
85
86
			     SubAssembler*,
			     Quadrature *quad = NULL) 
87
    {}
88

Thomas Witkowski's avatar
Thomas Witkowski committed
89
90
91
92
93
94
95
96
97
98
99
100
    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
101
102
    void setSymmetric(bool symm);

Thomas Witkowski's avatar
Thomas Witkowski committed
103
    /// Returns true, if the term is piecewise constant, returns false otherwise
104
105
    inline bool isPWConst() { 
      return (degree == 0);
106
    }
107

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

Thomas Witkowski's avatar
Thomas Witkowski committed
111
    /// Returns \ref degree.
112
113
    inline int getDegree() { 
      return degree; 
114
    }
115

Thomas Witkowski's avatar
Thomas Witkowski committed
116
    /// Evaluation of the OperatorTerm at all quadrature points.
Thomas Witkowski's avatar
Thomas Witkowski committed
117
118
    virtual void eval(int nPoints,
		      const double *uhAtQP,
119
120
		      const WorldVector<double> *grdUhAtQP,
		      const WorldMatrix<double> *D2UhAtQP,
Thomas Witkowski's avatar
Thomas Witkowski committed
121
		      double *result,
122
123
124
		      double factor) const = 0;

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
125
126
     * Determines the value of a dof vector at the quadrature points of a given 
     * element. It is used by all VecAtQP like operator terms.
127
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    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
145
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
146
147
148
149
150
    WorldVector<double>* getGradientsAtQPs(DOFVectorBase<double>* vec,
					   const ElInfo* elInfo,
					   SubAssembler* subAssembler,
					   Quadrature *quad);

Thomas Witkowski's avatar
Thomas Witkowski committed
151
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
152
153
154
155
156
157
158
159
    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$.
160
    static void lalt(const DimVec<WorldVector<double> >& Lambda,
Thomas Witkowski's avatar
Thomas Witkowski committed
161
162
163
164
		     const WorldMatrix<double>& matrix,
		     DimMat<double>& LALt,
		     bool symm,
		     double factor);
165
166
167
168
169
170
171
172

    /** \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
173
174
			DimMat<double>& LALt,
			double factor);
175
176
177
178
179
180

    /** \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
181
182
		     DimMat<double>& LALt,
		     double factor);
183

Thomas Witkowski's avatar
Thomas Witkowski committed
184
    /// Evaluation of \f$ \Lambda \cdot b\f$.
185
    static void lb(const DimVec<WorldVector<double> >& Lambda,
Thomas Witkowski's avatar
Thomas Witkowski committed
186
187
188
		   const WorldVector<double>& b,
		   DimVec<double>& Lb,
		   double factor);
189
190
191
192
193
194

    /** \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
195
196
		   DimVec<double>& Lb,
		   double factor)
197
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
198
199
      int dim = Lb.getSize() - 1;
      static const int dimOfWorld = Global::getGeo(WORLD);
200
201
202
203
204
205
206
207
208
209

      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;
      }    
210
    }
211
212

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
213
    /// Stores the properties of this OperatorTerm
214
215
    Flag properties;

Thomas Witkowski's avatar
Thomas Witkowski committed
216
    /// Polynomial degree of the term. Used to detemine the degree of the quadrature.
217
218
    int degree;

Thomas Witkowski's avatar
Thomas Witkowski committed
219
220
221
222
    /// List off all fe spaces, the operator term makes use off.
    std::vector<const FiniteElemSpace*> auxFESpaces;

    /// Pointer to the Operator this OperatorTerm belongs to.
223
224
    Operator* operat;

Thomas Witkowski's avatar
Thomas Witkowski committed
225
    /// Flag for piecewise constant terms
226
227
    static const Flag PW_CONST;

Thomas Witkowski's avatar
Thomas Witkowski committed
228
    /// Flag for symmetric terms
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
    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
251
    /// Constructor.
252
253
254
    SecondOrderTerm(int deg) 
      : OperatorTerm(deg) 
    {}
255
256
257
258

    /** \brief
     * Destructor.
     */
259
260
    virtual ~SecondOrderTerm() 
    {}
261
262
263
264
265

    /** \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
266
			 int nPoints, 
267
268
269
270
271
			 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
272
    virtual void weakEval(int nPoints,
273
274
275
276
277
278
279
280
281
282
283
284
285
286
			  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
287
    /// Constructor.
288
289
290
291
    Laplace_SOT() 
      : SecondOrderTerm(0) 
    {
      setSymmetric(true);
292
    }
293
294
295
296

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

Thomas Witkowski's avatar
Thomas Witkowski committed
301
      for (int iq = 0; iq < nPoints; iq++) {
302
303
	l1lt(Lambda, *(LALt[iq]), 1.0);
      }
304
    }
305
306
307
308

    /** \brief
     * Implementation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
309
310
311
312
313
314
    inline void eval(int nPoints,
		     const double * ,    // uhAtQP
		     const WorldVector<double> * ,  // grdUhAtQP
		     const WorldMatrix<double> *D2UhAtQP,
		     double *result,
		     double factor) const
315
316
317
318
    {
      int dow = Global::getGeo(WORLD);
    
      if (D2UhAtQP) {
Thomas Witkowski's avatar
Thomas Witkowski committed
319
	for (int iq = 0; iq < nPoints; iq++) {
320
321
322
323
324
325
326
	  double resultQP = 0.0;
	  for (int i = 0; i < dow; i++) {
	    resultQP += D2UhAtQP[iq][i][i];
	  }
	  result[iq] += factor * resultQP;
	}
      }
327
    }
328
329
330
331

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
332
    void weakEval(int nPoints,
333
334
335
336
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const
    {
      if (grdUhAtQP) {
Thomas Witkowski's avatar
Thomas Witkowski committed
337
	for (int iq = 0; iq < nPoints; iq++) { 
338
339
340
	  result[iq] += grdUhAtQP[iq];
	}
      }
341
342
    }
  };
343
344
345
346
347
348
349
350
351
352
353

  /**
   * \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
354
    /// Constructor.
355
    FactorLaplace_SOT(double f) 
356
357
      : SecondOrderTerm(0)  
    {
358
359
360
361
      factor = new double;
      *factor = f;

      setSymmetric(true);
362
    }
363

Thomas Witkowski's avatar
Thomas Witkowski committed
364
    /// Constructor.
365
    FactorLaplace_SOT(double *fptr) 
366
367
      : SecondOrderTerm(0), 
	factor(fptr)
368
369
    {
      setSymmetric(true);
370
    }
371
372
373
374

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
375
    inline void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const
376
    {
377
      const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();
Thomas Witkowski's avatar
Thomas Witkowski committed
378
      for (int iq = 0; iq < nPoints; iq++) 
379
	l1lt(Lambda, *(LALt[iq]), (*factor));
380
    }
381
382
383
384
385


    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
386
    void eval(int nPoints,
387
	      const double *,
388
389
390
391
392
	      const WorldVector<double> *,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double f) const
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
393
      int dow = Global::getGeo(WORLD);
394

Thomas Witkowski's avatar
Thomas Witkowski committed
395
      if (D2UhAtQP) {
Thomas Witkowski's avatar
Thomas Witkowski committed
396
	for (int iq = 0; iq < nPoints; iq++) {
397
	  double resultQP = 0.0;
Thomas Witkowski's avatar
Thomas Witkowski committed
398
	  for (int i = 0; i < dow; i++) {
399
400
401
402
403
	    resultQP += D2UhAtQP[iq][i][i];
	  }
	  result[iq] += resultQP * f * (*factor);
	}
      }
404
    }
405
406
407
408

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
409
    void weakEval(int nPoints,
410
411
412
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
413
      if (grdUhAtQP) {
Thomas Witkowski's avatar
Thomas Witkowski committed
414
	for (int iq = 0; iq < nPoints; iq++) {
415
416
417
	  axpy(*factor, grdUhAtQP[iq], result[iq]);
	}
      }
418
    }
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437

  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
438
    /// Constructor.
439
440
441
    MatrixFct_SOT(DOFVectorBase<double> *dv, 
		  AbstractFunction<WorldMatrix<double>, double> *fct,
		  AbstractFunction<WorldVector<double>, WorldMatrix<double> > *div,
Thomas Witkowski's avatar
Thomas Witkowski committed
442
		  bool sym = false);
443
444
445
446
447
448
449
450
451
452

    /** \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
453
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
454
455
456
457
  
    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
458
459
    void eval(int nPoints,
	      const double *uhAtQP,
460
461
462
463
464
465
466
467
	      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
468
    void weakEval(int nPoints,
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
		  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
488
489
490
    /** \brief
     *
     */
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
    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
508
    /// Constructor
509
    Matrix_SOT(WorldMatrix<double> mat) 
Thomas Witkowski's avatar
Thomas Witkowski committed
510
      : SecondOrderTerm(0), matrix(mat)
511
512
513
    {
      symmetric = matrix.isSymmetric();
      setSymmetric(symmetric);
514
    }
515
516
517
518

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
519
    inline void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const{
520
521
522
      const DimVec<WorldVector<double> >& Lambda     = elInfo->getGrdLambda();
      //double det = elInfo->getDet();
      int iq;
Thomas Witkowski's avatar
Thomas Witkowski committed
523
      for(iq = 0; iq < nPoints; iq++) 
524
	lalt(Lambda, matrix, *(LALt[iq]), symmetric, 1.0);
525
    }
526
527
528
529
  
    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
530
531
    void eval(int nPoints,
	      const double *uhAtQP,
532
533
534
535
536
537
538
539
	      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
540
    void weakEval(int nPoints,
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
		  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
567
    /// Constructor.
568
    FactorIJ_SOT(int x_i, int x_j, double f) 
Thomas Witkowski's avatar
Thomas Witkowski committed
569
      : SecondOrderTerm(0), xi(x_i), xj(x_j)
570
571
572
573
574
    {
      factor = new double;
      *factor = f;

      setSymmetric(xi == xj);
575
    }
576

Thomas Witkowski's avatar
Thomas Witkowski committed
577
    /// Constructor.
578
    FactorIJ_SOT(int x_i, int x_j, double *fptr) 
Thomas Witkowski's avatar
Thomas Witkowski committed
579
      : SecondOrderTerm(0), xi(x_i), xj(x_j), factor(fptr)
580
581
    {
      setSymmetric(xi == xj);
582
    }
583
584
585
586

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
587
    inline void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const
588
589
590
    {
      const DimVec<WorldVector<double> > &Lambda     = elInfo->getGrdLambda();
      int iq;
Thomas Witkowski's avatar
Thomas Witkowski committed
591
      for(iq = 0; iq < nPoints; iq++)
592
	lalt_kl(Lambda, xi, xj, *(LALt[iq]), (*factor));
593
    }
594
595
596
597

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
598
    void eval(int nPoints,
599
600
601
602
603
604
605
606
	      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
607
	for(iq = 0; iq < nPoints; iq++) {
608
609
610
	  result[iq] += (*factor) * D2UhAtQP[iq][xi][xj] * fac;
	}
      }
611
    }
612
613
614
615

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
616
    void weakEval(int nPoints,
617
618
619
620
621
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const
    {
      if(grdUhAtQP) {
	int iq;
Thomas Witkowski's avatar
Thomas Witkowski committed
622
	for(iq = 0; iq < nPoints; iq++) {
623
624
625
	  result[iq][xi] += (*factor) * grdUhAtQP[iq][xj];
	}
      }
626
    }
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649

  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
650
651
    /// Constructor.
    VecAtQP_SOT(DOFVectorBase<double> *dv, AbstractFunction<double, double> *af);
652

Thomas Witkowski's avatar
Thomas Witkowski committed
653
    /// Implementation of \ref OperatorTerm::initElement().
654
655
656
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

Thomas Witkowski's avatar
Thomas Witkowski committed
657
658
659
660
661
    /// Implementation of \ref OperatorTerm::initElement() for multilpe meshes.
    void initElement(const ElInfo* smallElInfo,
		     const ElInfo* largeElInfo,
		     SubAssembler* subAssembler,
		     Quadrature *quad = NULL);
662

Thomas Witkowski's avatar
Thomas Witkowski committed
663
664
665
666
667
668
    /// 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,
669
670
671
672
673
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

Thomas Witkowski's avatar
Thomas Witkowski committed
674
675
    /// Implenetation of SecondOrderTerm::weakEval().
    void weakEval(int nPoints,
676
677
678
679
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

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

Thomas Witkowski's avatar
Thomas Witkowski committed
683
    /// Pointer to an array containing the DOFVector evaluated at quadrature points.
684
685
    double* vecAtQPs;

Thomas Witkowski's avatar
Thomas Witkowski committed
686
    /// Function evaluated at \ref vecAtQPs.
687
688
689
    AbstractFunction<double, double> *f;
  };

690
691
692
693
694
695
696
697
698
699
  /**
   * \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
700
    /// Constructor.
701
    Vec2AtQP_SOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2, 
Thomas Witkowski's avatar
Thomas Witkowski committed
702
		 BinaryAbstractFunction<double, double, double> *af);
703
704
705
706
707
708
709
710
711
712

    /** \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
713
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;    
714
715
716
717
    
    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
718
    void eval(int nPoints,
719
720
721
722
723
724
725
726
727
	      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
728
    void weakEval(int nPoints,
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
		  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;
  };

752
753
754
755
756
757
758
759
760
  /**
   * \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
761
762
763
    /// Constructor.
    CoordsAtQP_SOT(AbstractFunction<double, WorldVector<double> > *af)
      : SecondOrderTerm(af->getDegree()), g(af)
764
765
    {
      setSymmetric(true);
Thomas Witkowski's avatar
Thomas Witkowski committed
766
    }
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
		  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
820
    /// Constructor.
821
    MatrixGradient_SOT(DOFVectorBase<double> *dv,
Thomas Witkowski's avatar
Thomas Witkowski committed
822
823
824
		       AbstractFunction<WorldMatrix<double>, WorldVector<double> > *af,
		       AbstractFunction<WorldVector<double>, WorldMatrix<double> > *divAf,
		       bool symm = false);
825
826
827
828
829
830
831
832
833
834

    /** \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
835
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
836
837
838
839

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
840
841
    void eval(int nPoints,
	      const double *uhAtQP,
842
843
844
845
846
847
848
849
	      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
850
    void weakEval(int nPoints,
851
852
853
854
855
856
857
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
		  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
887
888
889
    /// Constructor.
    FctGradient_SOT(DOFVectorBase<double> *dv,  
		    AbstractFunction<double, WorldVector<double> > *af);
890
891
892
893
894
895
896
897
898
899

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

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
905
906
    void eval(int nPoints,
	      const double *uhAtQP,
907
908
909
910
911
912
913
914
	      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
915
    void weakEval(int nPoints,
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
		  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
946
    /// Constructor.
947
    VecAndGradientAtQP_SOT(DOFVectorBase<double> *dv,
Thomas Witkowski's avatar
Thomas Witkowski committed
948
			   BinaryAbstractFunction<double, double, WorldVector<double> > *af);
949
950
951
952
953
954
955
956
957
958

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

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
964
965
    void eval(int nPoints,
	      const double *uhAtQP,
966
967
968
969
970
971
972
973
	      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
974
    void weakEval(int nPoints,
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
		  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;
  };

994
995
996
997
998
999
1000
1001
1002
1003
1004
  /**
   * \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
1005
    /// Constructor.
1006
    VecMatrixGradientAtQP_SOT(DOFVectorBase<double> *dv,
Thomas Witkowski's avatar
Thomas Witkowski committed
1007
1008
1009
			      BinaryAbstractFunction<WorldMatrix<double>, double, WorldVector<double> > *af,
			      AbstractFunction<WorldVector<double>, WorldMatrix<double> > *divAf,
			      bool symm = false);
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019

    /** \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
1020
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
1021
1022
1023
1024

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1025
1026
    void eval(int nPoints,
	      const double *uhAtQP,
1027
1028
1029
1030
1031
1032
1033
1034
	      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
1035
    void weakEval(int nPoints,
1036
1037
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;
Thomas Witkowski's avatar
Thomas Witkowski committed
1038
    
1039
1040
  protected:
    DOFVectorBase<double>* vec;
Thomas Witkowski's avatar
Thomas Witkowski committed
1041
    
1042
1043
1044
1045
1046
    /** \brief
     * Function wich maps \ref gradAtQPs to a double.
     */
    BinaryAbstractFunction<WorldMatrix<double>, 
			   double, WorldVector<double> > *f;
Thomas Witkowski's avatar
Thomas Witkowski committed
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
    
    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;
  };
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070

  /**
   * \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
1071
    /// Constructor.
1072
1073
    VecGradCoordsAtQP_SOT(DOFVectorBase<double> *dv,
			  TertiaryAbstractFunction<double, double,
Thomas Witkowski's avatar
Thomas Witkowski committed
1074
			  WorldVector<double>, WorldVector<double> > *af);
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084

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

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1090
1091
    void eval(int nPoints,
	      const double *uhAtQP,
1092
1093
1094
1095
1096
1097
1098
1099
	      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
1100
    void weakEval(int nPoints,
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
1133
		  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
1134
    /// Constructor.
1135
    VecAndCoordsAtQP_SOT(DOFVectorBase<double> *dv, 
Thomas Witkowski's avatar
Thomas Witkowski committed
1136
			 BinaryAbstractFunction<double, double, WorldVector<double> > *af);
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146

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

Thomas Witkowski's avatar
Thomas Witkowski committed
1149
1150
    void eval(int nPoints,
	      const double *uhAtQP,
1151
1152
1153
1154
1155
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

Thomas Witkowski's avatar
Thomas Witkowski committed
1156
    void weakEval(int nPoints,
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
		  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
1191
    /// Constructor.
1192
1193
1194
    MatrixGradientAndCoords_SOT(DOFVectorBase<double> *dv,
				BinaryAbstractFunction<WorldMatrix<double>,
				WorldVector<double> , 
Thomas Witkowski's avatar
Thomas Witkowski committed
1195
				WorldVector<double> > *af,
1196
				AbstractFunction<WorldVector<double>,
Thomas Witkowski's avatar
Thomas Witkowski committed
1197
1198
				WorldMatrix<double> > *divAf,
				bool symm = false);
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208

    /** \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
1209
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
1210
1211
1212
1213

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1214
1215
    void eval(int nPoints,
	      const double *uhAtQP,
1216
1217
1218
1219
1220
1221
1222
1223
	      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
1224
    void weakEval(int nPoints,
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
		  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
1256
    /// Constructor.
1257
1258
    General_SOT(std::vector<DOFVectorBase<double>*> vecs,
		std::vector<DOFVectorBase<double>*> grads,
1259
1260
		TertiaryAbstractFunction<WorldMatrix<double>, 
		  WorldVector<double>,
1261
1262
		  std::vector<double>, 
		  std::vector<WorldVector<double> > > *f,
1263
1264
		AbstractFunction<WorldVector<double>, 
		  WorldMatrix<double> > *divFct,
Thomas Witkowski's avatar
Thomas Witkowski committed
1265
		bool symmetric);
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276

    /** \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
1277
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
1278
1279
1280
1281

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1282
1283
    void eval(int nPoints,
	      const double *uhAtQP,
1284
1285
1286
1287
1288
1289
1290
1291
	      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
1292
    void weakEval(int nPoints,
1293
1294
1295
1296
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

  protected:
1297
    std::vector<DOFVectorBase<double>*> vecs_; 
1298

1299
    std::vector<DOFVectorBase<double>*> grads_;
1300
1301
1302

    TertiaryAbstractFunction<WorldMatrix<double>, 
			     WorldVector<double>,
1303
1304
			     std::vector<double>, 
			     std::vector<WorldVector<double> > > *f_;
1305
1306
1307
1308
1309
1310

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

    WorldVector<double> *coordsAtQPs_;

1311
    std::vector<double*> vecsAtQPs_;
1312

1313
    std::vector<WorldVector<double>*> gradsAtQPs_;
1314
1315
1316
1317
1318
1319
1320

    bool symmetric_;
  };

  class GeneralParametric_SOT : public SecondOrderTerm
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
1321
    /// Constructor.
1322
1323
    GeneralParametric_SOT(std::vector<DOFVectorBase<double>*> vecs,
			  std::vector<DOFVectorBase<double>*> grads,
1324
1325
1326
			  QuartAbstractFunction<WorldMatrix<double>, 
			  WorldVector<double>,
			  WorldVector<double>,
1327
1328
			  std::vector<double>, 
			  std::vector<WorldVector<double> > > *f,
1329
1330
			  AbstractFunction<WorldVector<double>, 
			  WorldMatrix<double> > *divFct,
Thomas Witkowski's avatar
Thomas Witkowski committed
1331
			  bool symmetric);
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342

    /** \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
1343
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
1344
1345
1346
1347

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1348
1349
    void eval(int nPoints,
	      const double *uhAtQP,
1350
1351
1352
1353
1354
1355
1356
1357
	      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
1358
    void weakEval(int nPoints,
1359
1360
1361
1362
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

  protected:
1363
    std::vector<DOFVectorBase<double>*> vecs_; 
1364

1365
    std::vector<DOFVectorBase<double>*> grads_;
1366
1367
1368
1369

    QuartAbstractFunction<WorldMatrix<double>, 
			  WorldVector<double>,
			  WorldVector<double>,
1370
1371
			  std::vector<double>, 
			  std::vector<WorldVector<double> > > *f_;
1372
1373
1374
1375
1376
1377
1378

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

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

1379
    std::vector<double*> vecsAtQPs_;
1380

1381
    std::vector<WorldVector<double>*> gradsAtQPs_;
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399

    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
1400
    /// Constructor.
1401
1402
    FirstOrderTerm(int deg) 
      : OperatorTerm(deg) 
Thomas Witkowski's avatar
Thomas Witkowski committed
1403
    {}
1404
1405
1406
1407

    /** \brief
     * Destructor.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1408
    virtual ~FirstOrderTerm() {}
1409
1410
1411
1412
1413

    /** \brief
     * Evaluation of \f$ \Lambda b \f$.
     */
    virtual void getLb(const ElInfo *elInfo,
Thomas Witkowski's avatar
Thomas Witkowski committed
1414
		       int nPoints, 
1415
1416
1417
1418
1419
		       VectorOfFixVecs<DimVec<double> >& result) const = 0;

    /** \brief
     * Implenetation of FirstOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
1420
1421
    void eval(int nPoints,
	      const double *,
1422
1423
1424
1425
1426
1427
1428
1429
	      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
1430
	for (int iq = 0; iq < nPoints; iq++) {
1431
1432
1433
1434
1435
1436
1437
	  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
1438
    }
1439

Thomas Witkowski's avatar
Thomas Witkowski committed
1440
  };
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451

  /**
   * \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
1452
    /// Constructor.
1453
1454
    Simple_FOT() 
      : FirstOrderTerm(0) 
Thomas Witkowski's avatar
Thomas Witkowski committed
1455
    {}
1456
1457
1458
1459
1460

    /** \brief
     * Implements FirstOrderTerm::getLb().
     */
    inline void getLb(const ElInfo *elInfo, 
Thomas Witkowski's avatar
Thomas Witkowski committed
1461
		      int nPoints, 
1462
1463
1464
1465
		      VectorOfFixVecs<DimVec<double> >& Lb) const 
    {
      const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();

Thomas Witkowski's avatar
Thomas Witkowski committed
1466
      for (int iq = 0; iq < nPoints; iq++) {
1467
1468
	l1(Lambda, Lb[iq], 1.0);
      }
Thomas Witkowski's avatar
Thomas Witkowski committed