Operator.h 12 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 ZeroOrderTerm to the Operator
82
    template <typename T>
83
    void addZeroOrderTerm(T *term);
84

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

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

93
    /// Adds a ZeroOrderTerm to the Operator
94
    void addTerm(ZeroOrderTerm *term);
95
96

    /// Adds a FirstOrderTerm to the Operator
97
98
    void addTerm(FirstOrderTerm *term,
      FirstOrderType type);
99
100

    /// Adds a SecondOrderTerm to the Operator
101
    void addTerm(SecondOrderTerm *term);
102
103
104
105
106
107

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

111
112
    virtual void getElementMatrix(const ElInfo *rowElInfo,
				  const ElInfo *colElInfo,
113
114
				  const ElInfo *smallElInfo,
				  const ElInfo *largeElInfo,
115
116
				  bool rowColFeSpaceEqual,
				  ElementMatrix& userMat,				  
117
118
				  double factor = 1.0);

119
120
121
122
123
    /** \brief
     * Calculates the element vector for this ElInfo and adds it multiplied by
     * factor to userVec.
     */
    virtual void getElementVector(const ElInfo *elInfo, 
124
				  ElementVector& userVec, 
125
126
				  double factor = 1.0);

Thomas Witkowski's avatar
Thomas Witkowski committed
127
128
129
130
    virtual void getElementVector(const ElInfo *mainElInfo, 
				  const ElInfo *auxElInfo,
				  const ElInfo *smallElInfo,
				  const ElInfo *largeElInfo,
131
				  ElementVector& userVec,
Thomas Witkowski's avatar
Thomas Witkowski committed
132
				  double factor = 1.0);
133

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

137
138
    /// Returns \ref rowFeSpace.
    inline const FiniteElemSpace *getRowFeSpace() 
139
    { 
140
      return rowFeSpace; 
141
    }
142

143
144
    /// Returns \ref colFeSpace.
    inline const FiniteElemSpace *getColFeSpace() 
145
    { 
146
      return colFeSpace; 
147
    }
148

149
150
    /// Returns \ref auxFeSpaces.
    inline std::set<const FiniteElemSpace*>& getAuxFeSpaces()
151
    {
152
      return auxFeSpaces;
Thomas Witkowski's avatar
Thomas Witkowski committed
153
154
    }

155
    /// Sets \ref uhOld.
156
157
    void setUhOld(const DOFVectorBase<double> *uhOld);

158
    /// Returns \ref uhOld.
159
160
    inline const DOFVectorBase<double> *getUhOld() 
    {
161
      return uhOld;
162
    }    
163

Thomas Witkowski's avatar
Thomas Witkowski committed
164
    /// Returns \ref assembler
165
    Assembler *getAssembler();
166

Thomas Witkowski's avatar
Thomas Witkowski committed
167
    /// Sets \ref assembler
168
    void setAssembler(Assembler *ass);
169

Thomas Witkowski's avatar
Thomas Witkowski committed
170
    /// Sets \ref fillFlag, the flag used for this Operator while mesh traversal.
171
172
    inline void setFillFlag(Flag f) 
    { 
173
      fillFlag = f; 
174
    }
175

Thomas Witkowski's avatar
Thomas Witkowski committed
176
    /// Sets \ref needDualTraverse.
177
178
    void setNeedDualTraverse(bool b) 
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
179
180
181
182
      needDualTraverse = b;
    }

    /// Returns \ref fillFlag
183
184
    inline Flag getFillFlag() 
    { 
185
      return fillFlag; 
186
    }
187

Thomas Witkowski's avatar
Thomas Witkowski committed
188
    /// Returns \ref needDualTraverse
189
190
    bool getNeedDualTraverse() 
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
191
192
193
194
      return needDualTraverse;
    }

    /// Initialization of the needed SubAssemblers using the given quadratures. 
195
    void initAssembler(Quadrature *quad2,
196
197
198
199
200
		       Quadrature *quad1GrdPsi,
		       Quadrature *quad1GrdPhi,
		       Quadrature *quad0);


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

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

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

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

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

256
    /// Weak evaluation of all terms in \ref secondOrder. 
257
258
    void weakEvalSecondOrder(const vector<WorldVector<double> > &grdUhAtQP,
			     vector<WorldVector<double> > &result) const;
259
  
260
    /// Calls getLALt() for each term in \ref secondOrder and adds the results to LALt.
261
262
263
264
265
    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
266
    }
267
  
268
269
    /// Calls getLb() for each term in \ref firstOrderGrdPsi and adds the results to Lb.
    void getLbGrdPsi(const ElInfo *elInfo, 
270
271
272
273
274
		     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
275
    }
276

277
278
    /// Calls getLb() for each term in \ref firstOrderGrdPhi and adds the results to Lb.
    void getLbGrdPhi(const ElInfo *elInfo, 
279
280
281
282
283
		     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
284
    }
285

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

Thomas Witkowski's avatar
Thomas Witkowski committed
294
    /// Returns true, if there are second order terms. Returns false otherwise.
295
296
    inline bool secondOrderTerms() 
    {
297
      return secondOrder.size() != 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
298
    }
299

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

306
    /// Returns true, if there are first order terms (grdPhi). Returns false otherwise.
307
308
    inline bool firstOrderTermsGrdPhi() 
    {
309
      return firstOrderGrdPhi.size() != 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
310
    }
311

312
    /// Returns true, if there are zero order terms. Returns false otherwise.
313
314
    inline bool zeroOrderTerms() 
    {
315
      return zeroOrder.size() != 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
316
    }
317
318

  public:
319
    /// Constant type flag for matrix operators. Obsolete, will be removed!
320
321
    static const Flag MATRIX_OPERATOR;

322
    /// Constant type flag for vector operators. Obsolete, will be removed!
323
324
325
    static const Flag VECTOR_OPERATOR;

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
326
    /// FiniteElemSpace for matrix rows and element vector
327
    const FiniteElemSpace *rowFeSpace;
328

329
330
    /// FiniteElemSpace for matrix columns. Can be equal to \rowFeSpace.
    const FiniteElemSpace *colFeSpace;
331

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

    /// Number of rows in the element matrix
336
337
    int nRow;

Thomas Witkowski's avatar
Thomas Witkowski committed
338
    /// Number of columns in the element matrix
339
340
    int nCol;

Thomas Witkowski's avatar
Thomas Witkowski committed
341
    /// Flag for mesh traversal
342
343
    Flag fillFlag;

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

347
348
349
350
351
    /** \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.
     */
352
    Assembler* assembler;
353

Thomas Witkowski's avatar
Thomas Witkowski committed
354
    /// List of all second order terms
355
    vector<OperatorTerm*> secondOrder;
356

Thomas Witkowski's avatar
Thomas Witkowski committed
357
    /// List of all first order terms derived to psi
358
    vector<OperatorTerm*> firstOrderGrdPsi;
359

Thomas Witkowski's avatar
Thomas Witkowski committed
360
    /// List of all first order terms derived to phi
361
    vector<OperatorTerm*> firstOrderGrdPhi;
362

Thomas Witkowski's avatar
Thomas Witkowski committed
363
    /// List of all zero order terms
364
    vector<OperatorTerm*> zeroOrder;
365
366

    /** \brief
367
368
     * 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.
369
370
371
     */
    const DOFVectorBase<double> *uhOld;

Thomas Witkowski's avatar
Thomas Witkowski committed
372
    /// Spezifies whether optimized assemblers are used or not.
373
374
375
376
377
378
379
380
381
382
383
    bool optimized;

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

}

384
385
#include "Operator.hh"

386
#endif // AMDIS_OPERATOR_H