Operator.h 99 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file Operator.h */

#ifndef AMDIS_OPERATOR_H
#define AMDIS_OPERATOR_H

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

namespace AMDiS {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
165
    /// Evaluation of \f$ \Lambda \cdot b\f$.
166
    static void lb(const DimVec<WorldVector<double> >& Lambda,
Thomas Witkowski's avatar
Thomas Witkowski committed
167
168
169
		   const WorldVector<double>& b,
		   DimVec<double>& Lb,
		   double factor);
170

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

      for (int i = 0; i <= dim; i++) {
	double val = 0.0;
      
182
	for (int j = 0; j < dimOfWorld; j++)
183
	  val += Lambda[i][j];
184

185
186
187
	val *= factor;
	Lb[i] += val;
      }    
188
    }
189
190

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
191
    /// Stores the properties of this OperatorTerm
192
193
    Flag properties;

Thomas Witkowski's avatar
Thomas Witkowski committed
194
    /// Polynomial degree of the term. Used to detemine the degree of the quadrature.
195
196
    int degree;

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

    /// Pointer to the Operator this OperatorTerm belongs to.
201
202
    Operator* operat;

Thomas Witkowski's avatar
Thomas Witkowski committed
203
    /// Flag for piecewise constant terms
204
205
    static const Flag PW_CONST;

Thomas Witkowski's avatar
Thomas Witkowski committed
206
    /// Flag for symmetric terms
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
    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
225
    /// Constructor.
226
227
228
    SecondOrderTerm(int deg) 
      : OperatorTerm(deg) 
    {}
229

230
    /// Destructor.
231
232
    virtual ~SecondOrderTerm() 
    {}
233

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

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

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

267
      for (int iq = 0; iq < nPoints; iq++)
268
	l1lt(Lambda, *(LALt[iq]), 1.0);
269
    }
270

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

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

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

      setSymmetric(true);
322
    }
323

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

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


    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
346
    void eval(int nPoints,
347
	      const double *,
348
349
350
351
352
	      const WorldVector<double> *,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double f) const
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
353
      int dow = Global::getGeo(WORLD);
354

Thomas Witkowski's avatar
Thomas Witkowski committed
355
      if (D2UhAtQP) {
Thomas Witkowski's avatar
Thomas Witkowski committed
356
	for (int iq = 0; iq < nPoints; iq++) {
357
	  double resultQP = 0.0;
Thomas Witkowski's avatar
Thomas Witkowski committed
358
	  for (int i = 0; i < dow; i++) {
359
360
361
362
363
	    resultQP += D2UhAtQP[iq][i][i];
	  }
	  result[iq] += resultQP * f * (*factor);
	}
      }
364
    }
365
366
367
368

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
369
    void weakEval(int nPoints,
370
371
372
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
373
      if (grdUhAtQP) {
Thomas Witkowski's avatar
Thomas Witkowski committed
374
	for (int iq = 0; iq < nPoints; iq++) {
375
376
377
	  axpy(*factor, grdUhAtQP[iq], result[iq]);
	}
      }
378
    }
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397

  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
398
    /// Constructor.
399
400
401
    MatrixFct_SOT(DOFVectorBase<double> *dv, 
		  AbstractFunction<WorldMatrix<double>, double> *fct,
		  AbstractFunction<WorldVector<double>, WorldMatrix<double> > *div,
Thomas Witkowski's avatar
Thomas Witkowski committed
402
		  bool sym = false);
403
404
405
406
407
408
409
410
411
412

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

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
479
    inline void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const{
480
481
482
      const DimVec<WorldVector<double> >& Lambda     = elInfo->getGrdLambda();
      //double det = elInfo->getDet();
      int iq;
Thomas Witkowski's avatar
Thomas Witkowski committed
483
      for(iq = 0; iq < nPoints; iq++) 
484
	lalt(Lambda, matrix, *(LALt[iq]), symmetric, 1.0);
485
    }
486
487
488
489
  
    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
490
491
    void eval(int nPoints,
	      const double *uhAtQP,
492
493
494
495
496
497
498
499
	      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
500
    void weakEval(int nPoints,
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
		  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
527
    /// Constructor.
528
    FactorIJ_SOT(int x_i, int x_j, double f) 
Thomas Witkowski's avatar
Thomas Witkowski committed
529
      : SecondOrderTerm(0), xi(x_i), xj(x_j)
530
531
532
533
534
    {
      factor = new double;
      *factor = f;

      setSymmetric(xi == xj);
535
    }
536

Thomas Witkowski's avatar
Thomas Witkowski committed
537
    /// Constructor.
538
    FactorIJ_SOT(int x_i, int x_j, double *fptr) 
Thomas Witkowski's avatar
Thomas Witkowski committed
539
      : SecondOrderTerm(0), xi(x_i), xj(x_j), factor(fptr)
540
541
    {
      setSymmetric(xi == xj);
542
    }
543
544
545
546

    /** \brief
     * Implements SecondOrderTerm::getLALt().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
547
    inline void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const
548
549
550
    {
      const DimVec<WorldVector<double> > &Lambda     = elInfo->getGrdLambda();
      int iq;
Thomas Witkowski's avatar
Thomas Witkowski committed
551
      for(iq = 0; iq < nPoints; iq++)
552
	lalt_kl(Lambda, xi, xj, *(LALt[iq]), (*factor));
553
    }
554
555
556
557

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
558
    void eval(int nPoints,
559
560
561
562
563
564
565
566
	      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
567
	for(iq = 0; iq < nPoints; iq++) {
568
569
570
	  result[iq] += (*factor) * D2UhAtQP[iq][xi][xj] * fac;
	}
      }
571
    }
572
573
574
575

    /** \brief
     * Implenetation of SecondOrderTerm::weakEval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
576
    void weakEval(int nPoints,
577
578
579
580
581
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const
    {
      if(grdUhAtQP) {
	int iq;
Thomas Witkowski's avatar
Thomas Witkowski committed
582
	for(iq = 0; iq < nPoints; iq++) {
583
584
585
	  result[iq][xi] += (*factor) * grdUhAtQP[iq][xj];
	}
      }
586
    }
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609

  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
610
611
    /// Constructor.
    VecAtQP_SOT(DOFVectorBase<double> *dv, AbstractFunction<double, double> *af);
612

Thomas Witkowski's avatar
Thomas Witkowski committed
613
    /// Implementation of \ref OperatorTerm::initElement().
614
615
616
    void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
		     Quadrature *quad = NULL);

Thomas Witkowski's avatar
Thomas Witkowski committed
617
618
619
620
621
    /// Implementation of \ref OperatorTerm::initElement() for multilpe meshes.
    void initElement(const ElInfo* smallElInfo,
		     const ElInfo* largeElInfo,
		     SubAssembler* subAssembler,
		     Quadrature *quad = NULL);
622

Thomas Witkowski's avatar
Thomas Witkowski committed
623
624
625
626
627
628
    /// 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,
629
630
631
632
633
	      const WorldVector<double> *grdUhAtQP,
	      const WorldMatrix<double> *D2UhAtQP,
	      double *result,
	      double factor) const;

Thomas Witkowski's avatar
Thomas Witkowski committed
634
635
    /// Implenetation of SecondOrderTerm::weakEval().
    void weakEval(int nPoints,
636
637
638
639
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;

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

Thomas Witkowski's avatar
Thomas Witkowski committed
643
    /// Pointer to an array containing the DOFVector evaluated at quadrature points.
644
645
    double* vecAtQPs;

Thomas Witkowski's avatar
Thomas Witkowski committed
646
    /// Function evaluated at \ref vecAtQPs.
647
648
649
    AbstractFunction<double, double> *f;
  };

650
651
652
653
654
655
656
657
658
659
  /**
   * \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
660
    /// Constructor.
661
    Vec2AtQP_SOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2, 
Thomas Witkowski's avatar
Thomas Witkowski committed
662
		 BinaryAbstractFunction<double, double, double> *af);
663
664
665
666
667
668
669
670
671
672

    /** \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
673
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;    
674
675
676
677
    
    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
678
    void eval(int nPoints,
679
680
681
682
683
684
685
686
687
	      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
688
    void weakEval(int nPoints,
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
		  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;
  };

712
713
714
715
716
717
718
719
720
  /**
   * \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
721
722
723
    /// Constructor.
    CoordsAtQP_SOT(AbstractFunction<double, WorldVector<double> > *af)
      : SecondOrderTerm(af->getDegree()), g(af)
724
725
    {
      setSymmetric(true);
Thomas Witkowski's avatar
Thomas Witkowski committed
726
    }
727
728
729
730
731
732
733
734
735
736

    /** \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
737
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;    
738
739
740
741

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
742
743
    void eval(int nPoints,
	      const double *uhAtQP,
744
745
746
747
748
749
750
751
	      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
752
    void weakEval(int nPoints,
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
		  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
780
    /// Constructor.
781
    MatrixGradient_SOT(DOFVectorBase<double> *dv,
Thomas Witkowski's avatar
Thomas Witkowski committed
782
783
784
		       AbstractFunction<WorldMatrix<double>, WorldVector<double> > *af,
		       AbstractFunction<WorldVector<double>, WorldMatrix<double> > *divAf,
		       bool symm = false);
785
786
787
788
789
790
791
792
793
794

    /** \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
795
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
796
797
798
799

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
800
801
    void eval(int nPoints,
	      const double *uhAtQP,
802
803
804
805
806
807
808
809
	      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
810
    void weakEval(int nPoints,
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
		  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
847
848
849
    /// Constructor.
    FctGradient_SOT(DOFVectorBase<double> *dv,  
		    AbstractFunction<double, WorldVector<double> > *af);
850
851
852
853
854
855
856
857
858
859

    /** \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
860
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
861
862
863
864

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
865
866
    void eval(int nPoints,
	      const double *uhAtQP,
867
868
869
870
871
872
873
874
	      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
875
    void weakEval(int nPoints,
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
		  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
906
    /// Constructor.
907
    VecAndGradientAtQP_SOT(DOFVectorBase<double> *dv,
Thomas Witkowski's avatar
Thomas Witkowski committed
908
			   BinaryAbstractFunction<double, double, WorldVector<double> > *af);
909
910
911
912
913
914
915
916
917
918

    /** \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
919
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
920
921
922
923

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
924
925
    void eval(int nPoints,
	      const double *uhAtQP,
926
927
928
929
930
931
932
933
	      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
934
    void weakEval(int nPoints,
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
		  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;
  };

954
955
956
957
958
959
960
961
962
963
964
  /**
   * \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
965
    /// Constructor.
966
    VecMatrixGradientAtQP_SOT(DOFVectorBase<double> *dv,
Thomas Witkowski's avatar
Thomas Witkowski committed
967
968
969
			      BinaryAbstractFunction<WorldMatrix<double>, double, WorldVector<double> > *af,
			      AbstractFunction<WorldVector<double>, WorldMatrix<double> > *divAf,
			      bool symm = false);
970
971
972
973
974
975
976
977
978
979

    /** \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
980
    void getLALt(const ElInfo *elInfo, int nPoints, DimMat<double> **LALt) const;
981
982
983
984

    /** \brief
     * Implenetation of SecondOrderTerm::eval().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
985
986
    void eval(int nPoints,
	      const double *uhAtQP,
987
988
989
990
991
992
993
994
	      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
995
    void weakEval(int nPoints,
996
997
		  const WorldVector<double> *grdUhAtQP,
		  WorldVector<double> *result) const;
Thomas Witkowski's avatar
Thomas Witkowski committed
998
    
999
1000
  protected:
    DOFVectorBase<double>* vec;