Assembler.h 8.64 KB
Newer Older
1 2 3 4 5 6
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
8
// ==                                                                        ==
9 10 11
// ==  Institut fr Wissenschaftliches Rechnen                               ==
// ==  Zellescher Weg 12-14                                                  ==
// ==  01069 Dresden                                                         ==
12 13 14 15
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
16
// ==  https://gforge.zih.tu-dresden.de/projects/amdis/                      ==
17 18 19 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>
#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
    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
				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);

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

94 95
    /// Returns \ref colFeSpace.
    inline const FiniteElemSpace* getColFeSpace() 
96
    { 
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
    const FiniteElemSpace *rowFeSpace;
214

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

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

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

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

}

#endif // AMDIS_ASSEMBLER_H