Assembler.h 8 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 27 28 29 30 31 32 33 34

/** \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>
35
#include "AMDiS_fwd.h"
36
#include "FixVec.h"
37 38 39 40
#include "ZeroOrderAssembler.h"
#include "FirstOrderAssembler.h"
#include "SecondOrderAssembler.h"
#include "ElInfo.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
    Assembler(Operator *op,
57 58
	      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
				bool rowColFeSpaceEqual,
73
				ElementMatrix& userMat,
74
				double factor = 1.0);
75

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

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

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

89 90
    /// Returns \ref rowFeSpace.
    inline const FiniteElemSpace* getRowFeSpace() 
91
    { 
92
      return rowFeSpace; 
93
    }
94

95 96
    /// Returns \ref colFeSpace.
    inline const FiniteElemSpace* getColFeSpace() 
97
    { 
98
      return colFeSpace; 
99
    }
100

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

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

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

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

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

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

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

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

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

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
197

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
213
    /// Row FiniteElemSpace.
214
    const FiniteElemSpace *rowFeSpace;
215

Thomas Witkowski's avatar
Thomas Witkowski committed
216
    /// Column FiniteElemSpace.
217
    const FiniteElemSpace *colFeSpace;
218

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

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

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

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

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

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

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

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
249
    /// Locally stored element vector
250
    ElementVector elementVector;
251 252 253

    ///
    ElementMatrix tmpMat;
254
  
Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
255 256
    /// Used to check whether \ref initElement() must be called, because
    /// a new Element is visited.
257 258
    Element* lastMatEl;

Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
259 260
    /// Used to check whether \ref initElement() must be called, because
    /// a new Element is visited.
261 262
    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,
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,
306 307
		       const FiniteElemSpace *rowFeSpace,
		       const FiniteElemSpace *colFeSpace = NULL);
308 309 310 311 312
  };

}

#endif // AMDIS_ASSEMBLER_H