Assembler.h 7.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * 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 35 36

/** \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>
37
#include "AMDiS_fwd.h"
38
#include "FixVec.h"
39 40 41 42
#include "ZeroOrderAssembler.h"
#include "FirstOrderAssembler.h"
#include "SecondOrderAssembler.h"
#include "ElInfo.h"
43 44 45 46 47 48 49 50 51 52 53 54 55 56

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
57
    /// Constructor
58
    Assembler(Operator *op,
59 60
	      const FiniteElemSpace *rowFeSpace,
	      const FiniteElemSpace *colFeSpace = NULL);
61

Thomas Witkowski's avatar
Thomas Witkowski committed
62 63
    /// Destructor
    ~Assembler();
64

Thomas Witkowski's avatar
Thomas Witkowski committed
65
    /// Assembles the element matrix for the given ElInfo
66
    void calculateElementMatrix(const ElInfo *elInfo, 
67
				ElementMatrix& userMat, 
68 69 70 71
				double factor = 1.0);

    void calculateElementMatrix(const ElInfo *rowElInfo,
				const ElInfo *colElInfo,
72 73
				const ElInfo *smallElInfo,
				const ElInfo *largeElInfo,
74
				bool rowColFeSpaceEqual,
75
				ElementMatrix& userMat,
76
				double factor = 1.0);
77

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

Thomas Witkowski's avatar
Thomas Witkowski committed
83 84 85 86 87

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
199

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
215
    /// Row FiniteElemSpace.
216
    const FiniteElemSpace *rowFeSpace;
217

Thomas Witkowski's avatar
Thomas Witkowski committed
218
    /// Column FiniteElemSpace.
219
    const FiniteElemSpace *colFeSpace;
220

Thomas Witkowski's avatar
Thomas Witkowski committed
221
    /// Number of rows.
222 223
    int nRow;

Thomas Witkowski's avatar
Thomas Witkowski committed
224
    /// Number of columns.
225 226
    int nCol;

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

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
239
    ///
240 241
    bool remember;

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
248
    /// Locally stored element matrix
249
    ElementMatrix elementMatrix;
250

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

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

Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
261 262
    /// Used to check whether \ref initElement() must be called, because
    /// a new Element is visited.
263 264
    Element* lastVecEl;

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

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

}

#endif // AMDIS_ASSEMBLER_H