Assembler.h 9.44 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
    virtual ~Assembler() {}
69

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


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

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

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

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

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

    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
103
    /// Returns \ref rowFESpace.
104 105
    inline const FiniteElemSpace* getRowFESpace() { 
      return rowFESpace; 
106
    }
107

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

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

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

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

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

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

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

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

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

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

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

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

  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
202 203 204 205 206

    void matVecAssemble(const ElInfo *mainElInfo, const ElInfo *auxElInfo,
			const ElInfo *smallElInfo, const ElInfo *largeElInfo,
			ElementVector *vec);

207 208 209 210 211 212 213
    /** \brief
     * Checks whether quadratures for sub assemblers are already set.
     * If not they will be created.
     */
    void checkQuadratures();

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

Thomas Witkowski's avatar
Thomas Witkowski committed
217
    /// Row FiniteElemSpace.
218 219
    const FiniteElemSpace *rowFESpace;

Thomas Witkowski's avatar
Thomas Witkowski committed
220
    /// Column FiniteElemSpace.
221 222
    const FiniteElemSpace *colFESpace;

Thomas Witkowski's avatar
Thomas Witkowski committed
223
    /// Number of rows.
224 225
    int nRow;

Thomas Witkowski's avatar
Thomas Witkowski committed
226
    /// Number of columns.
227 228
    int nCol;

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

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
241
    ///
242 243
    bool remember;

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
253
    /// Locally stored element vector
254 255 256 257 258 259 260 261 262 263 264 265 266 267
    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
268
    /// Used to check for new traverse.
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
    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
292
    /// Constructor
Thomas Witkowski's avatar
Thomas Witkowski committed
293
    StandardAssembler(Operator *op,
294 295 296 297
		      Quadrature *quad2,
		      Quadrature *quad1GrdPsi,
		      Quadrature *quad1GrdPhi,
		      Quadrature *quad0,
Thomas Witkowski's avatar
Thomas Witkowski committed
298 299
		      const FiniteElemSpace *rowFESpace,
		      const FiniteElemSpace *colFESpace = NULL);
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
  };

  // ============================================================================
  // ===== 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
317
    /// Constructor
Thomas Witkowski's avatar
Thomas Witkowski committed
318
    OptimizedAssembler(Operator *op,
319 320 321 322
		       Quadrature *quad2,
		       Quadrature *quad1GrdPsi,
		       Quadrature *quad1GrdPhi,
		       Quadrature *quad0,
Thomas Witkowski's avatar
Thomas Witkowski committed
323 324
		       const FiniteElemSpace *rowFESpace,
		       const FiniteElemSpace *colFESpace = NULL);
325 326 327 328 329
  };

}

#endif // AMDIS_ASSEMBLER_H