Operator.h 97.2 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
      int dim = Lb.getSize() - 1;
199
      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
  /**
   * \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$