Assembler.h 8.56 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() { 
      return rowFESpace; 
91
    }
92

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
103
    /// Returns \ref nCol.
104 105
    inline int getNCol() { 
      return nCol; 
106
    }
107

Thomas Witkowski's avatar
Thomas Witkowski committed
108
    /// Sets \ref rememberElMat.
109 110
    inline void rememberElementMatrix(bool rem) { 
      rememberElMat = rem; 
111
    }
112

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

Thomas Witkowski's avatar
Thomas Witkowski committed
118
    /// Returns \ref zeroOrderAssembler.
119 120
    inline ZeroOrderAssembler* getZeroOrderAssembler() {
      return zeroOrderAssembler;
121
    }
122 123 124 125 126

    /** \brief
     * Returns \ref firstOrderAssemblerGrdPsi or \ref firstOrderAssemblerGrdPhi
     * depending on type.
     */
127
    inline FirstOrderAssembler* getFirstOrderAssembler(FirstOrderType type = GRD_PSI) 
128
    {
129
      return (type == GRD_PSI) ? 
130 131
	firstOrderAssemblerGrdPsi : 
	firstOrderAssemblerGrdPhi;
132
    }
133

Thomas Witkowski's avatar
Thomas Witkowski committed
134
    /// Returns \ref secondOrderAssembler.
135 136
    inline SecondOrderAssembler* getSecondOrderAssembler() {
      return secondOrderAssembler;
137
    }
138

Thomas Witkowski's avatar
Thomas Witkowski committed
139
    /// Returns \ref operat;
140 141
    inline Operator* getOperator() { 
      return operat; 
142
    }
143

Thomas Witkowski's avatar
Thomas Witkowski committed
144
    /// Initialisation for the given ElInfo. The call is deligated to the sub assemblers.
Thomas Witkowski's avatar
Thomas Witkowski committed
145 146
    void initElement(const ElInfo *smallElInfo,
		     const ElInfo *largeElInfo = NULL,
147 148
		     Quadrature *quad = NULL);

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

    /// That function must be called after one assembling cycle has been finished.
    void finishAssembling();
179 180 181 182 183 184

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

Thomas Witkowski's avatar
Thomas Witkowski committed
187

Thomas Witkowski's avatar
Thomas Witkowski committed
188
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
189 190
    void matVecAssemble(const ElInfo *mainElInfo, const ElInfo *auxElInfo,
			const ElInfo *smallElInfo, const ElInfo *largeElInfo,
191
			ElementVector& vec);
Thomas Witkowski's avatar
Thomas Witkowski committed
192

193
    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
194
     * Checks whether quadratures for subassemblers are already set.
195 196 197 198 199
     * If not they will be created.
     */
    void checkQuadratures();

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
200
    /// Operator this Assembler belongs to.
201 202
    Operator *operat;

Thomas Witkowski's avatar
Thomas Witkowski committed
203
    /// Row FiniteElemSpace.
204 205
    const FiniteElemSpace *rowFESpace;

Thomas Witkowski's avatar
Thomas Witkowski committed
206
    /// Column FiniteElemSpace.
207 208
    const FiniteElemSpace *colFESpace;

Thomas Witkowski's avatar
Thomas Witkowski committed
209
    /// Number of rows.
210 211
    int nRow;

Thomas Witkowski's avatar
Thomas Witkowski committed
212
    /// Number of columns.
213 214
    int nCol;

Thomas Witkowski's avatar
Thomas Witkowski committed
215
    /// SubAssembler for the second order terms
216 217
    SecondOrderAssembler *secondOrderAssembler;

Thomas Witkowski's avatar
Thomas Witkowski committed
218
    /// SubAssembler for the first order terms (grdPsi)
Thomas Witkowski's avatar
Thomas Witkowski committed
219
    FirstOrderAssembler *firstOrderAssemblerGrdPsi;
220

Thomas Witkowski's avatar
Thomas Witkowski committed
221
    /// SubAssembler for the first order terms (grdPhi)
Thomas Witkowski's avatar
Thomas Witkowski committed
222
    FirstOrderAssembler *firstOrderAssemblerGrdPhi;  
223

Thomas Witkowski's avatar
Thomas Witkowski committed
224
    /// SubAssembler for the zero order terms
Thomas Witkowski's avatar
Thomas Witkowski committed
225
    ZeroOrderAssembler *zeroOrderAssembler;
226

Thomas Witkowski's avatar
Thomas Witkowski committed
227
    ///
228 229
    bool remember;

Thomas Witkowski's avatar
Thomas Witkowski committed
230
    /// Determines whether the element matrix should be stored locally.
231 232
    bool rememberElMat;

Thomas Witkowski's avatar
Thomas Witkowski committed
233
    /// Determines whether the element vector should be stored locally.
234 235
    bool rememberElVec;

Thomas Witkowski's avatar
Thomas Witkowski committed
236
    /// Locally stored element matrix
237
    ElementMatrix elementMatrix;
238

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

  /**
   * \ingroup Assembler
   *
   * \brief
   * Assembler using optimized sub assemblers.
   */
  class OptimizedAssembler : public Assembler
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
291
    /// Constructor
Thomas Witkowski's avatar
Thomas Witkowski committed
292
    OptimizedAssembler(Operator *op,
293 294 295 296
		       Quadrature *quad2,
		       Quadrature *quad1GrdPsi,
		       Quadrature *quad1GrdPhi,
		       Quadrature *quad0,
Thomas Witkowski's avatar
Thomas Witkowski committed
297 298
		       const FiniteElemSpace *rowFESpace,
		       const FiniteElemSpace *colFESpace = NULL);
299 300 301 302 303
  };

}

#endif // AMDIS_ASSEMBLER_H