Operator.h 11.7 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
97
98


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

102
103
    virtual void getElementMatrix(const ElInfo *rowElInfo,
				  const ElInfo *colElInfo,
104
105
				  const ElInfo *smallElInfo,
				  const ElInfo *largeElInfo,
106
107
				  bool rowColFeSpaceEqual,
				  ElementMatrix& userMat,				  
108
109
				  double factor = 1.0);

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

Thomas Witkowski's avatar
Thomas Witkowski committed
118
119
120
121
    virtual void getElementVector(const ElInfo *mainElInfo, 
				  const ElInfo *auxElInfo,
				  const ElInfo *smallElInfo,
				  const ElInfo *largeElInfo,
122
				  ElementVector& userVec,
Thomas Witkowski's avatar
Thomas Witkowski committed
123
				  double factor = 1.0);
124

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

128
129
    /// Returns \ref rowFeSpace.
    inline const FiniteElemSpace *getRowFeSpace() 
130
    { 
131
      return rowFeSpace; 
132
    }
133

134
135
    /// Returns \ref colFeSpace.
    inline const FiniteElemSpace *getColFeSpace() 
136
    { 
137
      return colFeSpace; 
138
    }
139

140
141
    /// Returns \ref auxFeSpaces.
    inline std::set<const FiniteElemSpace*>& getAuxFeSpaces()
142
    {
143
      return auxFeSpaces;
Thomas Witkowski's avatar
Thomas Witkowski committed
144
145
    }

146
    /// Sets \ref uhOld.
147
148
    void setUhOld(const DOFVectorBase<double> *uhOld);

149
    /// Returns \ref uhOld.
150
151
    inline const DOFVectorBase<double> *getUhOld() 
    {
152
      return uhOld;
153
    }    
154

Thomas Witkowski's avatar
Thomas Witkowski committed
155
    /// Returns \ref assembler
156
    Assembler *getAssembler();
157

Thomas Witkowski's avatar
Thomas Witkowski committed
158
    /// Sets \ref assembler
159
    void setAssembler(Assembler *ass);
160

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

Thomas Witkowski's avatar
Thomas Witkowski committed
167
    /// Sets \ref needDualTraverse.
168
169
    void setNeedDualTraverse(bool b) 
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
170
171
172
173
      needDualTraverse = b;
    }

    /// Returns \ref fillFlag
174
175
    inline Flag getFillFlag() 
    { 
176
      return fillFlag; 
177
    }
178

Thomas Witkowski's avatar
Thomas Witkowski committed
179
    /// Returns \ref needDualTraverse
180
181
    bool getNeedDualTraverse() 
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
182
183
184
185
      return needDualTraverse;
    }

    /// Initialization of the needed SubAssemblers using the given quadratures. 
186
    void initAssembler(Quadrature *quad2,
187
188
189
190
191
		       Quadrature *quad1GrdPsi,
		       Quadrature *quad1GrdPhi,
		       Quadrature *quad0);


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

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

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

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

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

247
    /// Weak evaluation of all terms in \ref secondOrder. 
248
249
    void weakEvalSecondOrder(const vector<WorldVector<double> > &grdUhAtQP,
			     vector<WorldVector<double> > &result) const;
250
  
251
    /// Calls getLALt() for each term in \ref secondOrder and adds the results to LALt.
252
253
254
255
256
    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
257
    }
258
  
259
260
    /// Calls getLb() for each term in \ref firstOrderGrdPsi and adds the results to Lb.
    void getLbGrdPsi(const ElInfo *elInfo, 
261
262
263
264
265
		     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
266
    }
267

268
269
    /// Calls getLb() for each term in \ref firstOrderGrdPhi and adds the results to Lb.
    void getLbGrdPhi(const ElInfo *elInfo, 
270
271
272
273
274
		     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
275
    }
276

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

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

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

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

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

  public:
310
    /// Constant type flag for matrix operators. Obsolete, will be removed!
311
312
    static const Flag MATRIX_OPERATOR;

313
    /// Constant type flag for vector operators. Obsolete, will be removed!
314
315
316
    static const Flag VECTOR_OPERATOR;

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
317
    /// FiniteElemSpace for matrix rows and element vector
318
    const FiniteElemSpace *rowFeSpace;
319

320
321
    /// FiniteElemSpace for matrix columns. Can be equal to \rowFeSpace.
    const FiniteElemSpace *colFeSpace;
322

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

    /// Number of rows in the element matrix
327
328
    int nRow;

Thomas Witkowski's avatar
Thomas Witkowski committed
329
    /// Number of columns in the element matrix
330
331
    int nCol;

Thomas Witkowski's avatar
Thomas Witkowski committed
332
    /// Flag for mesh traversal
333
334
    Flag fillFlag;

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

338
339
340
341
342
    /** \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.
     */
343
    Assembler* assembler;
344

Thomas Witkowski's avatar
Thomas Witkowski committed
345
    /// List of all second order terms
346
    vector<OperatorTerm*> secondOrder;
347

Thomas Witkowski's avatar
Thomas Witkowski committed
348
    /// List of all first order terms derived to psi
349
    vector<OperatorTerm*> firstOrderGrdPsi;
350

Thomas Witkowski's avatar
Thomas Witkowski committed
351
    /// List of all first order terms derived to phi
352
    vector<OperatorTerm*> firstOrderGrdPhi;
353

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

    /** \brief
358
359
     * 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.
360
361
362
     */
    const DOFVectorBase<double> *uhOld;

Thomas Witkowski's avatar
Thomas Witkowski committed
363
    /// Spezifies whether optimized assemblers are used or not.
364
365
366
367
368
369
370
371
372
373
374
    bool optimized;

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

}

375
376
#include "Operator.hh"

377
#endif // AMDIS_OPERATOR_H