Assembler.h 8.76 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

63 64 65
    void initElementMatrix(ElementMatrix *elMat, 
			   const ElInfo *rowElInfo,
			   const ElInfo *colElInfo = NULL);
66 67


68 69
    void initElementVector(ElementVector *elVec,
			   const ElInfo *elInfo);
70

Thomas Witkowski's avatar
Thomas Witkowski committed
71
    /// Assembles the element matrix for the given ElInfo
72 73 74 75 76 77
    void calculateElementMatrix(const ElInfo *elInfo, 
				ElementMatrix *userMat, 
				double factor = 1.0);

    void calculateElementMatrix(const ElInfo *rowElInfo,
				const ElInfo *colElInfo,
78 79
				const ElInfo *smallElInfo,
				const ElInfo *largeElInfo,
80 81
				ElementMatrix *userMat,
				double factor = 1.0);
82

Thomas Witkowski's avatar
Thomas Witkowski committed
83
    /// Assembles the element vector for the given ElInfo
84 85 86
    void calculateElementVector(const ElInfo *elInfo, 
				ElementVector *userVec, 
				double factor = 1.0);
87

Thomas Witkowski's avatar
Thomas Witkowski committed
88 89 90 91 92 93 94 95

    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
96
    /// Returns \ref rowFESpace.
97 98
    inline const FiniteElemSpace* getRowFESpace() { 
      return rowFESpace; 
99
    }
100

Thomas Witkowski's avatar
Thomas Witkowski committed
101
    /// Returns \ref colFESpace.
102 103
    inline const FiniteElemSpace* getColFESpace() { 
      return colFESpace; 
104
    }
105

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

Thomas Witkowski's avatar
Thomas Witkowski committed
111
    /// Returns \ref nCol.
112 113
    inline int getNCol() { 
      return nCol; 
114
    }
115

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
126
    /// Returns \ref zeroOrderAssembler.
127 128
    inline ZeroOrderAssembler* getZeroOrderAssembler() {
      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() {
      return secondOrderAssembler;
145
    }
146

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

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

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

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

  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
195

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
247
    /// Locally stored element vector
248 249 250 251 252 253 254 255 256 257 258 259 260 261
    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
262
    /// Used to check for new traverse.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
    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
280
    /// Constructor
Thomas Witkowski's avatar
Thomas Witkowski committed
281
    StandardAssembler(Operator *op,
282 283 284 285
		      Quadrature *quad2,
		      Quadrature *quad1GrdPsi,
		      Quadrature *quad1GrdPhi,
		      Quadrature *quad0,
Thomas Witkowski's avatar
Thomas Witkowski committed
286 287
		      const FiniteElemSpace *rowFESpace,
		      const FiniteElemSpace *colFESpace = NULL);
288 289 290 291 292 293 294 295 296 297 298
  };

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

}

#endif // AMDIS_ASSEMBLER_H