Assembler.h 8.6 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
// ============================================================================
// ==                                                                        ==
// == 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"
35
36
37
38
#include "ZeroOrderAssembler.h"
#include "FirstOrderAssembler.h"
#include "SecondOrderAssembler.h"
#include "ElInfo.h"
39
#include "OpenMP.h"
40
#include "AMDiS_fwd.h"
41
42
43
44
45
46
47
48
49
50
51
52
53
54

namespace AMDiS {

  /**
   * \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:
Thomas Witkowski's avatar
Thomas Witkowski committed
55
    /// Constructor
56
57
58
    Assembler(Operator *op,
	      const FiniteElemSpace *rowFESpace,
	      const FiniteElemSpace *colFESpace = NULL);
59

Thomas Witkowski's avatar
Thomas Witkowski committed
60
61
    /// Destructor
    ~Assembler();
62

Thomas Witkowski's avatar
Thomas Witkowski committed
63
    /// Assembles the element matrix for the given ElInfo
64
    void calculateElementMatrix(const ElInfo *elInfo, 
65
				ElementMatrix& userMat, 
66
67
68
69
				double factor = 1.0);

    void calculateElementMatrix(const ElInfo *rowElInfo,
				const ElInfo *colElInfo,
70
71
				const ElInfo *smallElInfo,
				const ElInfo *largeElInfo,
72
				ElementMatrix& userMat,
73
				double factor = 1.0);
74

Thomas Witkowski's avatar
Thomas Witkowski committed
75
    /// Assembles the element vector for the given ElInfo
76
    void calculateElementVector(const ElInfo *elInfo, 
77
				ElementVector& userVec, 
78
				double factor = 1.0);
79

Thomas Witkowski's avatar
Thomas Witkowski committed
80
81
82
83
84

    void calculateElementVector(const ElInfo *mainElInfo, 
				const ElInfo *auxElInfo,
				const ElInfo *smallElInfo,
				const ElInfo *largeElInfo,
85
				ElementVector& userVec, 
Thomas Witkowski's avatar
Thomas Witkowski committed
86
87
				double factor = 1.0);

Thomas Witkowski's avatar
Thomas Witkowski committed
88
    /// Returns \ref rowFESpace.
89
90
    inline const FiniteElemSpace* getRowFESpace() 
    { 
91
      return rowFESpace; 
92
    }
93

Thomas Witkowski's avatar
Thomas Witkowski committed
94
    /// Returns \ref colFESpace.
95
96
    inline const FiniteElemSpace* getColFESpace() 
    { 
97
      return colFESpace; 
98
    }
99

Thomas Witkowski's avatar
Thomas Witkowski committed
100
    /// Returns \ref nRow.
101
102
    inline int getNRow() 
    { 
103
      return nRow; 
104
    }
105

Thomas Witkowski's avatar
Thomas Witkowski committed
106
    /// Returns \ref nCol.
107
108
    inline int getNCol() 
    { 
109
      return nCol; 
110
    }
111

Thomas Witkowski's avatar
Thomas Witkowski committed
112
    /// Sets \ref rememberElMat.
113
114
    inline void rememberElementMatrix(bool rem) 
    { 
115
      rememberElMat = rem; 
116
    }
117

Thomas Witkowski's avatar
Thomas Witkowski committed
118
    /// Sets \ref rememberElVec.
119
120
    inline void rememberElementVector(bool rem) 
    { 
121
      rememberElVec = rem; 
122
    }
123

Thomas Witkowski's avatar
Thomas Witkowski committed
124
    /// Returns \ref zeroOrderAssembler.
125
126
    inline ZeroOrderAssembler* getZeroOrderAssembler() 
    {
127
      return zeroOrderAssembler;
128
    }
129
130
131
132
133

    /** \brief
     * Returns \ref firstOrderAssemblerGrdPsi or \ref firstOrderAssemblerGrdPhi
     * depending on type.
     */
134
    inline FirstOrderAssembler* getFirstOrderAssembler(FirstOrderType type = GRD_PSI) 
135
    {
136
      return (type == GRD_PSI) ? 
137
138
	firstOrderAssemblerGrdPsi : 
	firstOrderAssemblerGrdPhi;
139
    }
140

Thomas Witkowski's avatar
Thomas Witkowski committed
141
    /// Returns \ref secondOrderAssembler.
142
143
    inline SecondOrderAssembler* getSecondOrderAssembler() 
    {
144
      return secondOrderAssembler;
145
    }
146

Thomas Witkowski's avatar
Thomas Witkowski committed
147
    /// Returns \ref operat;
148
149
    inline Operator* getOperator() 
    { 
150
      return operat; 
151
    }
152

Thomas Witkowski's avatar
Thomas Witkowski committed
153
    /// Initialisation for the given ElInfo. The call is deligated to the sub assemblers.
Thomas Witkowski's avatar
Thomas Witkowski committed
154
155
    void initElement(const ElInfo *smallElInfo,
		     const ElInfo *largeElInfo = NULL,
156
157
		     Quadrature *quad = NULL);

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

    /// That function must be called after one assembling cycle has been finished.
    void finishAssembling();
188
189
190
191
192
193

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

Thomas Witkowski's avatar
Thomas Witkowski committed
196

Thomas Witkowski's avatar
Thomas Witkowski committed
197
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
198
199
    void matVecAssemble(const ElInfo *mainElInfo, const ElInfo *auxElInfo,
			const ElInfo *smallElInfo, const ElInfo *largeElInfo,
200
			ElementVector& vec);
Thomas Witkowski's avatar
Thomas Witkowski committed
201

202
    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
203
     * Checks whether quadratures for subassemblers are already set.
204
205
206
207
208
     * If not they will be created.
     */
    void checkQuadratures();

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
209
    /// Operator this Assembler belongs to.
210
211
    Operator *operat;

Thomas Witkowski's avatar
Thomas Witkowski committed
212
    /// Row FiniteElemSpace.
213
214
    const FiniteElemSpace *rowFESpace;

Thomas Witkowski's avatar
Thomas Witkowski committed
215
    /// Column FiniteElemSpace.
216
217
    const FiniteElemSpace *colFESpace;

Thomas Witkowski's avatar
Thomas Witkowski committed
218
    /// Number of rows.
219
220
    int nRow;

Thomas Witkowski's avatar
Thomas Witkowski committed
221
    /// Number of columns.
222
223
    int nCol;

Thomas Witkowski's avatar
Thomas Witkowski committed
224
    /// SubAssembler for the second order terms
225
226
    SecondOrderAssembler *secondOrderAssembler;

Thomas Witkowski's avatar
Thomas Witkowski committed
227
    /// SubAssembler for the first order terms (grdPsi)
Thomas Witkowski's avatar
Thomas Witkowski committed
228
    FirstOrderAssembler *firstOrderAssemblerGrdPsi;
229

Thomas Witkowski's avatar
Thomas Witkowski committed
230
    /// SubAssembler for the first order terms (grdPhi)
Thomas Witkowski's avatar
Thomas Witkowski committed
231
    FirstOrderAssembler *firstOrderAssemblerGrdPhi;  
232

Thomas Witkowski's avatar
Thomas Witkowski committed
233
    /// SubAssembler for the zero order terms
Thomas Witkowski's avatar
Thomas Witkowski committed
234
    ZeroOrderAssembler *zeroOrderAssembler;
235

Thomas Witkowski's avatar
Thomas Witkowski committed
236
    ///
237
238
    bool remember;

Thomas Witkowski's avatar
Thomas Witkowski committed
239
    /// Determines whether the element matrix should be stored locally.
240
241
    bool rememberElMat;

Thomas Witkowski's avatar
Thomas Witkowski committed
242
    /// Determines whether the element vector should be stored locally.
243
244
    bool rememberElVec;

Thomas Witkowski's avatar
Thomas Witkowski committed
245
    /// Locally stored element matrix
246
    ElementMatrix elementMatrix;
247

Thomas Witkowski's avatar
Thomas Witkowski committed
248
    /// Locally stored element vector
249
    ElementVector elementVector;
250
251
252
253
254
255
256
257
258
259
260
261
262
  
    /** \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
263
    /// Used to check for new traverse.
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
    int lastTraverseId;

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

  /**
   * \ingroup Assembler
   *
   * \brief
   * Assembler using non optimized sub assemblers.
   */
  class StandardAssembler : public Assembler
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
281
    /// Constructor
Thomas Witkowski's avatar
Thomas Witkowski committed
282
    StandardAssembler(Operator *op,
283
284
285
286
		      Quadrature *quad2,
		      Quadrature *quad1GrdPsi,
		      Quadrature *quad1GrdPhi,
		      Quadrature *quad0,
Thomas Witkowski's avatar
Thomas Witkowski committed
287
288
		      const FiniteElemSpace *rowFESpace,
		      const FiniteElemSpace *colFESpace = NULL);
289
290
291
292
293
294
295
296
297
298
299
  };

  /**
   * \ingroup Assembler
   *
   * \brief
   * Assembler using optimized sub assemblers.
   */
  class OptimizedAssembler : public Assembler
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
300
    /// Constructor
Thomas Witkowski's avatar
Thomas Witkowski committed
301
    OptimizedAssembler(Operator *op,
302
303
304
305
		       Quadrature *quad2,
		       Quadrature *quad1GrdPsi,
		       Quadrature *quad1GrdPhi,
		       Quadrature *quad0,
Thomas Witkowski's avatar
Thomas Witkowski committed
306
307
		       const FiniteElemSpace *rowFESpace,
		       const FiniteElemSpace *colFESpace = NULL);
308
309
310
311
312
  };

}

#endif // AMDIS_ASSEMBLER_H