Assembler.h 9.45 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
32
33
34
35
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file Assembler.h */

/**
 * \defgroup Assembler Assembler module
 *
 * \brief
 * Contains the operator and assembler classes:
 * @{ <img src="assembler.png"> @}
 */

#ifndef AMDIS_ASSEMBLER_H
#define AMDIS_ASSEMBLER_H

#include <vector>
#include "FixVec.h"
#include "MemoryManager.h"
36
37
38
39
#include "ZeroOrderAssembler.h"
#include "FirstOrderAssembler.h"
#include "SecondOrderAssembler.h"
#include "ElInfo.h"
40
#include "OpenMP.h"
41
42
43
44
45
46
47

namespace AMDiS {

  class Element;
  class Quadrature;
  class ElementMatrix;
  class ElementVector;
48
  class Operator;
49
50
51
52
53
54
55
56
57
58
59
60
61
62

  /**
   * \ingroup Assembler
   * 
   * \brief
   * Assembles element matrices and vectors for a given Operator. Uses
   * one SubAssembler for all second order terms of the Operator, one for all
   * first order terms, and one for all zero order terms.
   */
  class Assembler
  {
  public:
    MEMORY_MANAGED(Assembler);

Thomas Witkowski's avatar
Thomas Witkowski committed
63
    /// Constructor
64
65
66
    Assembler(Operator *op,
	      const FiniteElemSpace *rowFESpace,
	      const FiniteElemSpace *colFESpace = NULL);
67

Thomas Witkowski's avatar
Thomas Witkowski committed
68
69
    /// Destructor
    ~Assembler();
70

71
72
73
    void initElementMatrix(ElementMatrix *elMat, 
			   const ElInfo *rowElInfo,
			   const ElInfo *colElInfo = NULL);
74
75


76
77
    void initElementVector(ElementVector *elVec,
			   const ElInfo *elInfo);
78

Thomas Witkowski's avatar
Thomas Witkowski committed
79
    /// Assembles the element matrix for the given ElInfo
80
81
82
83
84
85
    void calculateElementMatrix(const ElInfo *elInfo, 
				ElementMatrix *userMat, 
				double factor = 1.0);

    void calculateElementMatrix(const ElInfo *rowElInfo,
				const ElInfo *colElInfo,
86
87
				const ElInfo *smallElInfo,
				const ElInfo *largeElInfo,
88
89
				ElementMatrix *userMat,
				double factor = 1.0);
90

Thomas Witkowski's avatar
Thomas Witkowski committed
91
    /// Assembles the element vector for the given ElInfo
92
93
94
    void calculateElementVector(const ElInfo *elInfo, 
				ElementVector *userVec, 
				double factor = 1.0);
95

Thomas Witkowski's avatar
Thomas Witkowski committed
96
97
98
99
100
101
102
103

    void calculateElementVector(const ElInfo *mainElInfo, 
				const ElInfo *auxElInfo,
				const ElInfo *smallElInfo,
				const ElInfo *largeElInfo,
				ElementVector *userVec, 
				double factor = 1.0);

Thomas Witkowski's avatar
Thomas Witkowski committed
104
    /// Returns \ref rowFESpace.
105
106
    inline const FiniteElemSpace* getRowFESpace() { 
      return rowFESpace; 
107
    }
108

Thomas Witkowski's avatar
Thomas Witkowski committed
109
    /// Returns \ref colFESpace.
110
111
    inline const FiniteElemSpace* getColFESpace() { 
      return colFESpace; 
112
    }
113

Thomas Witkowski's avatar
Thomas Witkowski committed
114
    /// Returns \ref nRow.
115
116
    inline int getNRow() { 
      return nRow; 
117
    }
118

Thomas Witkowski's avatar
Thomas Witkowski committed
119
    /// Returns \ref nCol.
120
121
    inline int getNCol() { 
      return nCol; 
122
    }
123

Thomas Witkowski's avatar
Thomas Witkowski committed
124
    /// Sets \ref rememberElMat.
125
126
    inline void rememberElementMatrix(bool rem) { 
      rememberElMat = rem; 
127
    }
128

Thomas Witkowski's avatar
Thomas Witkowski committed
129
    /// Sets \ref rememberElVec.
130
131
    inline void rememberElementVector(bool rem) { 
      rememberElVec = rem; 
132
    }
133

Thomas Witkowski's avatar
Thomas Witkowski committed
134
    /// Returns \ref zeroOrderAssembler.
135
136
    inline ZeroOrderAssembler* getZeroOrderAssembler() {
      return zeroOrderAssembler;
137
    }
138
139
140
141
142

    /** \brief
     * Returns \ref firstOrderAssemblerGrdPsi or \ref firstOrderAssemblerGrdPhi
     * depending on type.
     */
143
    inline FirstOrderAssembler* getFirstOrderAssembler(FirstOrderType type = GRD_PSI) 
144
    {
145
      return (type == GRD_PSI) ? 
146
147
	firstOrderAssemblerGrdPsi : 
	firstOrderAssemblerGrdPhi;
148
    }
149

Thomas Witkowski's avatar
Thomas Witkowski committed
150
    /// Returns \ref secondOrderAssembler.
151
152
    inline SecondOrderAssembler* getSecondOrderAssembler() {
      return secondOrderAssembler;
153
    }
154

Thomas Witkowski's avatar
Thomas Witkowski committed
155
    /// Returns \ref operat;
156
157
    inline Operator* getOperator() { 
      return operat; 
158
    }
159

Thomas Witkowski's avatar
Thomas Witkowski committed
160
    /// Initialisation for the given ElInfo. The call is deligated to the sub assemblers.
Thomas Witkowski's avatar
Thomas Witkowski committed
161
162
    void initElement(const ElInfo *smallElInfo,
		     const ElInfo *largeElInfo = NULL,
163
164
		     Quadrature *quad = NULL);

Thomas Witkowski's avatar
Thomas Witkowski committed
165
    /// Sets quadratures of all sub assemblers.
166
167
168
169
170
    void setQuadratures(Quadrature *quad2,
			Quadrature *quad1GrdPsi,
			Quadrature *quad1GrdPhi,
			Quadrature *quad0) 
    {
171
      if (secondOrderAssembler) {
172
173
174
175
	TEST_EXIT(!secondOrderAssembler->getQuadrature())
	  ("quadrature already existing\n");
	secondOrderAssembler->setQuadrature(quad2);
      }
176
      if (firstOrderAssemblerGrdPsi) {
177
178
179
180
	TEST_EXIT(!firstOrderAssemblerGrdPsi->getQuadrature())
	  ("quadrature already existing\n");
	firstOrderAssemblerGrdPsi->setQuadrature(quad1GrdPsi);
      }
181
      if (firstOrderAssemblerGrdPhi) {
182
183
184
185
	TEST_EXIT(!firstOrderAssemblerGrdPhi->getQuadrature())
	  ("quadrature already existing\n");
	firstOrderAssemblerGrdPhi->setQuadrature(quad1GrdPhi);
      }
186
      if (zeroOrderAssembler) {
187
188
189
190
	TEST_EXIT(!zeroOrderAssembler->getQuadrature())
	  ("quadrature already existing\n");
	zeroOrderAssembler->setQuadrature(quad0);
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
191
192
193
194
    }

    /// That function must be called after one assembling cycle has been finished.
    void finishAssembling();
195
196
197
198
199
200
201
202

  protected:
    /** \brief
     * Vector assembling by element matrix-vector multiplication. 
     * Usefull if an element matrix was already calculated.
     */
    void matVecAssemble(const ElInfo *elInfo, ElementVector *vec);

Thomas Witkowski's avatar
Thomas Witkowski committed
203

Thomas Witkowski's avatar
Thomas Witkowski committed
204
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
205
206
207
208
    void matVecAssemble(const ElInfo *mainElInfo, const ElInfo *auxElInfo,
			const ElInfo *smallElInfo, const ElInfo *largeElInfo,
			ElementVector *vec);

209
    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
210
     * Checks whether quadratures for subassemblers are already set.
211
212
213
214
215
     * If not they will be created.
     */
    void checkQuadratures();

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
216
    /// Operator this Assembler belongs to.
217
218
    Operator *operat;

Thomas Witkowski's avatar
Thomas Witkowski committed
219
    /// Row FiniteElemSpace.
220
221
    const FiniteElemSpace *rowFESpace;

Thomas Witkowski's avatar
Thomas Witkowski committed
222
    /// Column FiniteElemSpace.
223
224
    const FiniteElemSpace *colFESpace;

Thomas Witkowski's avatar
Thomas Witkowski committed
225
    /// Number of rows.
226
227
    int nRow;

Thomas Witkowski's avatar
Thomas Witkowski committed
228
    /// Number of columns.
229
230
    int nCol;

Thomas Witkowski's avatar
Thomas Witkowski committed
231
    /// SubAssembler for the second order terms
232
233
    SecondOrderAssembler *secondOrderAssembler;

Thomas Witkowski's avatar
Thomas Witkowski committed
234
    /// SubAssembler for the first order terms (grdPsi)
Thomas Witkowski's avatar
Thomas Witkowski committed
235
    FirstOrderAssembler *firstOrderAssemblerGrdPsi;
236

Thomas Witkowski's avatar
Thomas Witkowski committed
237
    /// SubAssembler for the first order terms (grdPhi)
Thomas Witkowski's avatar
Thomas Witkowski committed
238
    FirstOrderAssembler *firstOrderAssemblerGrdPhi;  
239

Thomas Witkowski's avatar
Thomas Witkowski committed
240
    /// SubAssembler for the zero order terms
Thomas Witkowski's avatar
Thomas Witkowski committed
241
    ZeroOrderAssembler *zeroOrderAssembler;
242

Thomas Witkowski's avatar
Thomas Witkowski committed
243
    ///
244
245
    bool remember;

Thomas Witkowski's avatar
Thomas Witkowski committed
246
    /// Determines whether the element matrix should be stored locally.
247
248
    bool rememberElMat;

Thomas Witkowski's avatar
Thomas Witkowski committed
249
    /// Determines whether the element vector should be stored locally.
250
251
    bool rememberElVec;

Thomas Witkowski's avatar
Thomas Witkowski committed
252
    /// Locally stored element matrix
253
254
    ElementMatrix* elementMatrix;

Thomas Witkowski's avatar
Thomas Witkowski committed
255
    /// Locally stored element vector
256
257
258
259
260
261
262
263
264
265
266
267
268
269
    ElementVector* elementVector;
  
    /** \brief
     * Used to check whether \ref initElement() must be called, because
     * a new Element is visited.
     */
    Element* lastMatEl;

    /** \brief
     * Used to check whether \ref initElement() must be called, because
     * a new Element is visited.
     */
    Element* lastVecEl;

Thomas Witkowski's avatar
Thomas Witkowski committed
270
    /// Used to check for new traverse.
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
    int lastTraverseId;

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

  // ============================================================================
  // ===== class StandardAssembler =============================================
  // ============================================================================

  /**
   * \ingroup Assembler
   *
   * \brief
   * Assembler using non optimized sub assemblers.
   */
  class StandardAssembler : public Assembler
  {
  public:
    MEMORY_MANAGED(StandardAssembler);

Thomas Witkowski's avatar
Thomas Witkowski committed
294
    /// Constructor
Thomas Witkowski's avatar
Thomas Witkowski committed
295
    StandardAssembler(Operator *op,
296
297
298
299
		      Quadrature *quad2,
		      Quadrature *quad1GrdPsi,
		      Quadrature *quad1GrdPhi,
		      Quadrature *quad0,
Thomas Witkowski's avatar
Thomas Witkowski committed
300
301
		      const FiniteElemSpace *rowFESpace,
		      const FiniteElemSpace *colFESpace = NULL);
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
  };

  // ============================================================================
  // ===== class OptimizedAssembler =============================================
  // ============================================================================

  /**
   * \ingroup Assembler
   *
   * \brief
   * Assembler using optimized sub assemblers.
   */
  class OptimizedAssembler : public Assembler
  {
  public:
    MEMORY_MANAGED(OptimizedAssembler);

Thomas Witkowski's avatar
Thomas Witkowski committed
319
    /// Constructor
Thomas Witkowski's avatar
Thomas Witkowski committed
320
    OptimizedAssembler(Operator *op,
321
322
323
324
		       Quadrature *quad2,
		       Quadrature *quad1GrdPsi,
		       Quadrature *quad1GrdPhi,
		       Quadrature *quad0,
Thomas Witkowski's avatar
Thomas Witkowski committed
325
326
		       const FiniteElemSpace *rowFESpace,
		       const FiniteElemSpace *colFESpace = NULL);
327
328
329
330
331
  };

}

#endif // AMDIS_ASSEMBLER_H