Operator.h 11.9 KB
Newer Older
1
2
3
4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6
7
// ==                                                                        ==
// ============================================================================
8
9
10
11
12
13
14
15
16
17
18
19
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


20
21
22
23
24
25
26

/** \file Operator.h */

#ifndef AMDIS_OPERATOR_H
#define AMDIS_OPERATOR_H

#include <vector>
27
#include "AMDiS_fwd.h"
28
29
30
31
32
#include "FixVec.h"
#include "Flag.h"
#include "MatrixVector.h"
#include "ElInfo.h"
#include "AbstractFunction.h"
33
#include "SubAssembler.h"
34
35
36
37
#include "OperatorTerm.h"
#include "ZeroOrderTerm.h"
#include "FirstOrderTerm.h"
#include "SecondOrderTerm.h"
38
39
40

namespace AMDiS {

41
42
  using namespace std;

43
44
45
46
47
48
49
50
51
52
53
54
55
  /** \brief
   * An Operator holds all information needed to assemble the system matrix
   * and the right hand side. It consists of four OperatorTerm lists each storing
   * Terms of a specific order and type. You can define your own Operator by 
   * creating an empty Operator and than adding OperatorTerms to it.
   * By calling \ref getElementMatrix() or \ref getElementVector() one can 
   * initiate the assembling procedure. Therefor each Operator has its own
   * Assembler, especially created for this Operator, by the first call of
   * \ref getElementMatrix() or \ref getElementVector(). 
   */
  class Operator
  {
  public:
56
57
    /// Obsolete consructor. Calling this constructor yields an error. Will be removed
    /// in on of the next revisions.
58
    Operator(Flag operatorType,
59
60
	     const FiniteElemSpace *rowFeSpace,
	     const FiniteElemSpace *colFeSpace = NULL);
61

62
63
64
65
    /// Constructs an empty Operator of type operatorType for the given FiniteElemSpace.
    Operator(const FiniteElemSpace *rowFeSpace,
	     const FiniteElemSpace *colFeSpace = NULL);

66
    /// Destructor.
Thomas Witkowski's avatar
Thomas Witkowski committed
67
    virtual ~Operator() {}
68

69
    /// Sets \ref optimized.
70
71
    inline void useOptimizedAssembler(bool opt) 
    {
72
      optimized = opt;
Thomas Witkowski's avatar
Thomas Witkowski committed
73
    }
74

75
    /// Returns \ref optimized.
76
77
    inline bool isOptimized() 
    {
78
      return optimized;
Thomas Witkowski's avatar
Thomas Witkowski committed
79
    }
80

81
    /// Adds a SecondOrderTerm to the Operator
82
83
    template <typename T>
    void addSecondOrderTerm(T *term);
84

85
    /// Adds a FirstOrderTerm to the Operator
86
    template <typename T>
87
88
89
    void addFirstOrderTerm(T *term, FirstOrderType type = GRD_PHI);

    /// Adds a ZeroOrderTerm to the Operator
90
91
    template <typename T>
    void addZeroOrderTerm(T *term);
92

93
94
95
96
    void addTerm(ZeroOrderTerm *term);
    void addTerm(FirstOrderTerm *term,
      FirstOrderType type);
    void addTerm(SecondOrderTerm *term);
97
98
99
100
101
102

    /** \brief
     * Calculates the element matrix for this ElInfo and adds it multiplied by
     * factor to userMat.
     */
    virtual void getElementMatrix(const ElInfo *elInfo, 
103
				  ElementMatrix& userMat, 
104
105
				  double factor = 1.0);

106
107
    virtual void getElementMatrix(const ElInfo *rowElInfo,
				  const ElInfo *colElInfo,
108
109
				  const ElInfo *smallElInfo,
				  const ElInfo *largeElInfo,
110
111
				  bool rowColFeSpaceEqual,
				  ElementMatrix& userMat,				  
112
113
				  double factor = 1.0);

114
115
116
117
118
    /** \brief
     * Calculates the element vector for this ElInfo and adds it multiplied by
     * factor to userVec.
     */
    virtual void getElementVector(const ElInfo *elInfo, 
119
				  ElementVector& userVec, 
120
121
				  double factor = 1.0);

Thomas Witkowski's avatar
Thomas Witkowski committed
122
123
124
125
    virtual void getElementVector(const ElInfo *mainElInfo, 
				  const ElInfo *auxElInfo,
				  const ElInfo *smallElInfo,
				  const ElInfo *largeElInfo,
126
				  ElementVector& userVec,
Thomas Witkowski's avatar
Thomas Witkowski committed
127
				  double factor = 1.0);
128

Thomas Witkowski's avatar
Thomas Witkowski committed
129
130
    /// That function must be called after one assembling cycle has been finished.
    void finishAssembling();
131

132
133
    /// Returns \ref rowFeSpace.
    inline const FiniteElemSpace *getRowFeSpace() 
134
    { 
135
      return rowFeSpace; 
136
    }
137

138
139
    /// Returns \ref colFeSpace.
    inline const FiniteElemSpace *getColFeSpace() 
140
    { 
141
      return colFeSpace; 
142
    }
143

144
145
    /// Returns \ref auxFeSpaces.
    inline std::set<const FiniteElemSpace*>& getAuxFeSpaces()
146
    {
147
      return auxFeSpaces;
Thomas Witkowski's avatar
Thomas Witkowski committed
148
149
    }

150
    /// Sets \ref uhOld.
151
152
    void setUhOld(const DOFVectorBase<double> *uhOld);

153
    /// Returns \ref uhOld.
154
155
    inline const DOFVectorBase<double> *getUhOld() 
    {
156
      return uhOld;
157
    }    
158

Thomas Witkowski's avatar
Thomas Witkowski committed
159
    /// Returns \ref assembler
160
    Assembler *getAssembler();
161

Thomas Witkowski's avatar
Thomas Witkowski committed
162
    /// Sets \ref assembler
163
    void setAssembler(Assembler *ass);
164

Thomas Witkowski's avatar
Thomas Witkowski committed
165
    /// Sets \ref fillFlag, the flag used for this Operator while mesh traversal.
166
167
    inline void setFillFlag(Flag f) 
    { 
168
      fillFlag = f; 
169
    }
170

Thomas Witkowski's avatar
Thomas Witkowski committed
171
    /// Sets \ref needDualTraverse.
172
173
    void setNeedDualTraverse(bool b) 
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
174
175
176
177
      needDualTraverse = b;
    }

    /// Returns \ref fillFlag
178
179
    inline Flag getFillFlag() 
    { 
180
      return fillFlag; 
181
    }
182

Thomas Witkowski's avatar
Thomas Witkowski committed
183
    /// Returns \ref needDualTraverse
184
185
    bool getNeedDualTraverse() 
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
186
187
188
189
      return needDualTraverse;
    }

    /// Initialization of the needed SubAssemblers using the given quadratures. 
190
    void initAssembler(Quadrature *quad2,
191
192
193
194
195
		       Quadrature *quad1GrdPsi,
		       Quadrature *quad1GrdPhi,
		       Quadrature *quad0);


Thomas Witkowski's avatar
Thomas Witkowski committed
196
    /// Calculates the needed quadrature degree for the given order. 
197
198
    int getQuadratureDegree(int order, FirstOrderType firstOrderType = GRD_PHI);

Thomas Witkowski's avatar
Thomas Witkowski committed
199
    /// Evaluation of all terms in \ref zeroOrder. 
200
201
    void evalZeroOrder(int nPoints,		       
		       const ElementVector& uhAtQP,
202
203
		       const WorldVector<double> *grdUhAtQP,
		       const WorldMatrix<double> *D2UhAtQP,
204
		       ElementVector& result,
205
206
		       double factor) const
    {
207
208
      for (vector<OperatorTerm*>::const_iterator termIt = zeroOrder.begin(); 
	   termIt != zeroOrder.end(); ++termIt)
Thomas Witkowski's avatar
Thomas Witkowski committed
209
	(*termIt)->eval(nPoints, uhAtQP, grdUhAtQP, D2UhAtQP, result, factor);
Thomas Witkowski's avatar
Thomas Witkowski committed
210
    }
211

212
    /// Evaluation of all terms in \ref firstOrderGrdPsi. 
Thomas Witkowski's avatar
Thomas Witkowski committed
213
    void evalFirstOrderGrdPsi(int nPoints,
214
			      const ElementVector& uhAtQP,
215
216
			      const WorldVector<double> *grdUhAtQP,
			      const WorldMatrix<double> *D2UhAtQP,
217
			      ElementVector& result,
218
			      double factor) const
219
220
221
    {      
      for (vector<OperatorTerm*>::const_iterator termIt = firstOrderGrdPsi.begin(); 
	   termIt != firstOrderGrdPsi.end(); ++termIt)
Thomas Witkowski's avatar
Thomas Witkowski committed
222
	(*termIt)->eval(nPoints, uhAtQP, grdUhAtQP, D2UhAtQP, result, factor);
Thomas Witkowski's avatar
Thomas Witkowski committed
223
    }
224

225
    /// Evaluation of all terms in \ref firstOrderGrdPhi. 
Thomas Witkowski's avatar
Thomas Witkowski committed
226
    void evalFirstOrderGrdPhi(int nPoints,
227
			      const ElementVector& uhAtQP,
228
229
			      const WorldVector<double> *grdUhAtQP,
			      const WorldMatrix<double> *D2UhAtQP,
230
			      ElementVector& result,
231
232
			      double factor) const
    {
233
234
      for (vector<OperatorTerm*>::const_iterator termIt = firstOrderGrdPhi.begin(); 
	   termIt != firstOrderGrdPhi.end(); ++termIt)
Thomas Witkowski's avatar
Thomas Witkowski committed
235
	(*termIt)->eval(nPoints, uhAtQP, grdUhAtQP, D2UhAtQP, result, factor);
Thomas Witkowski's avatar
Thomas Witkowski committed
236
    }
237

238
    /// Evaluation of all terms in \ref secondOrder. 
Thomas Witkowski's avatar
Thomas Witkowski committed
239
    void evalSecondOrder(int nPoints,
240
			 const ElementVector& uhAtQP,
241
242
			 const WorldVector<double> *grdUhAtQP,
			 const WorldMatrix<double> *D2UhAtQP,
243
			 ElementVector& result,
244
			 double factor) const
245
246
247
    {      
      for (vector<OperatorTerm*>::const_iterator termIt = secondOrder.begin(); 
	   termIt != secondOrder.end(); ++termIt)
Thomas Witkowski's avatar
Thomas Witkowski committed
248
	(*termIt)->eval(nPoints, uhAtQP, grdUhAtQP, D2UhAtQP, result, factor);
Thomas Witkowski's avatar
Thomas Witkowski committed
249
    }
250

251
    /// Weak evaluation of all terms in \ref secondOrder. 
252
253
    void weakEvalSecondOrder(const vector<WorldVector<double> > &grdUhAtQP,
			     vector<WorldVector<double> > &result) const;
254
  
255
    /// Calls getLALt() for each term in \ref secondOrder and adds the results to LALt.
256
257
258
259
260
    void getLALt(const ElInfo *elInfo, std::vector<mtl::dense2D<double> > &LALt) const
    {      
      for (vector<OperatorTerm*>::const_iterator termIt = secondOrder.begin(); 
	   termIt != secondOrder.end(); ++termIt)
	static_cast<SecondOrderTerm*>(*termIt)->getLALt(elInfo, LALt);
Thomas Witkowski's avatar
Thomas Witkowski committed
261
    }
262
  
263
264
    /// Calls getLb() for each term in \ref firstOrderGrdPsi and adds the results to Lb.
    void getLbGrdPsi(const ElInfo *elInfo, 
265
266
267
268
269
		     vector<mtl::dense_vector<double> >& Lb) const
    {      
      for (vector<OperatorTerm*>::const_iterator termIt = firstOrderGrdPsi.begin(); 
	   termIt != firstOrderGrdPsi.end(); ++termIt)
	static_cast<FirstOrderTerm*>(*termIt)->getLb(elInfo, Lb);
Thomas Witkowski's avatar
Thomas Witkowski committed
270
    }
271

272
273
    /// Calls getLb() for each term in \ref firstOrderGrdPhi and adds the results to Lb.
    void getLbGrdPhi(const ElInfo *elInfo, 
274
275
276
277
278
		     vector<mtl::dense_vector<double> >& Lb) const
    {      
      for (vector<OperatorTerm*>::const_iterator termIt = firstOrderGrdPhi.begin(); 
	   termIt != firstOrderGrdPhi.end(); ++termIt)
	static_cast<FirstOrderTerm*>(*termIt)->getLb(elInfo, Lb);
Thomas Witkowski's avatar
Thomas Witkowski committed
279
    }
280

281
    /// Calls getC() for each term in \ref zeroOrder and adds the results to c.
282
    void getC(const ElInfo *elInfo, int nPoints, ElementVector& c)
283
284
285
    {      
      for (vector<OperatorTerm*>::const_iterator termIt = zeroOrder.begin(); 
	   termIt != zeroOrder.end(); ++termIt)
Thomas Witkowski's avatar
Thomas Witkowski committed
286
	static_cast<ZeroOrderTerm*>(*termIt)->getC(elInfo, nPoints, c);
Thomas Witkowski's avatar
Thomas Witkowski committed
287
    }
288

Thomas Witkowski's avatar
Thomas Witkowski committed
289
    /// Returns true, if there are second order terms. Returns false otherwise.
290
291
    inline bool secondOrderTerms() 
    {
292
      return secondOrder.size() != 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
293
    }
294

295
    /// Returns true, if there are first order terms (grdPsi). Returns false otherwise.
296
297
    inline bool firstOrderTermsGrdPsi() 
    {
298
      return firstOrderGrdPsi.size() != 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
299
    }
300

301
    /// Returns true, if there are first order terms (grdPhi). Returns false otherwise.
302
303
    inline bool firstOrderTermsGrdPhi() 
    {
304
      return firstOrderGrdPhi.size() != 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
305
    }
306

307
    /// Returns true, if there are zero order terms. Returns false otherwise.
308
309
    inline bool zeroOrderTerms() 
    {
310
      return zeroOrder.size() != 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
311
    }
312
313

  public:
314
    /// Constant type flag for matrix operators. Obsolete, will be removed!
315
316
    static const Flag MATRIX_OPERATOR;

317
    /// Constant type flag for vector operators. Obsolete, will be removed!
318
319
320
    static const Flag VECTOR_OPERATOR;

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
321
    /// FiniteElemSpace for matrix rows and element vector
322
    const FiniteElemSpace *rowFeSpace;
323

324
325
    /// FiniteElemSpace for matrix columns. Can be equal to \rowFeSpace.
    const FiniteElemSpace *colFeSpace;
326

Thomas Witkowski's avatar
Thomas Witkowski committed
327
    /// List of aux fe spaces, e.g., if a term is multiplied with a DOF vector
328
    std::set<const FiniteElemSpace*> auxFeSpaces;
Thomas Witkowski's avatar
Thomas Witkowski committed
329
330

    /// Number of rows in the element matrix
331
332
    int nRow;

Thomas Witkowski's avatar
Thomas Witkowski committed
333
    /// Number of columns in the element matrix
334
335
    int nCol;

Thomas Witkowski's avatar
Thomas Witkowski committed
336
    /// Flag for mesh traversal
337
338
    Flag fillFlag;

Thomas Witkowski's avatar
Thomas Witkowski committed
339
340
341
    /// If true, the operator needs a dual traverse over two meshes for assembling.
    bool needDualTraverse;

342
343
344
345
346
    /** \brief
     * Calculates the element matrix and/or the element vector. It is
     * created especially for this Operator, when \ref getElementMatrix()
     * or \ref getElementVector is called for the first time.
     */
347
    Assembler* assembler;
348

Thomas Witkowski's avatar
Thomas Witkowski committed
349
    /// List of all second order terms
350
    vector<OperatorTerm*> secondOrder;
351

Thomas Witkowski's avatar
Thomas Witkowski committed
352
    /// List of all first order terms derived to psi
353
    vector<OperatorTerm*> firstOrderGrdPsi;
354

Thomas Witkowski's avatar
Thomas Witkowski committed
355
    /// List of all first order terms derived to phi
356
    vector<OperatorTerm*> firstOrderGrdPhi;
357

Thomas Witkowski's avatar
Thomas Witkowski committed
358
    /// List of all zero order terms
359
    vector<OperatorTerm*> zeroOrder;
360
361

    /** \brief
362
363
     * Pointer to the solution of the last timestep. Can be used for a more efficient
     * assemblage of the element vector when the element matrix was already computed.
364
365
366
     */
    const DOFVectorBase<double> *uhOld;

Thomas Witkowski's avatar
Thomas Witkowski committed
367
    /// Spezifies whether optimized assemblers are used or not.
368
369
370
371
372
373
374
375
376
377
378
    bool optimized;

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

}

379
380
#include "Operator.hh"

381
#endif // AMDIS_OPERATOR_H