ElInfo.h 15.3 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file ElInfo.h */

#ifndef AMDIS_ELINFO_H
#define AMDIS_ELINFO_H

#include "Flag.h"
#include "Boundary.h"
#include "Global.h"
#include "FixVec.h"
#include "Element.h"

namespace AMDiS {

  class MacroElement;
  class Mesh;
  class Element;
  class BasisFunction;
  class Projection;
  template<typename ReturnType, typename ArgumentType> class AbstractFunction;

  /** \ingroup Traverse
   * \brief 
   * An ElInfo object holds informations wich are not stored in the corresponding
   * element. It is filled during mesh traversal by the traversal routines.
   * A fill flag determines which informations should be filled and which elements
   * should be visited. Since it is a
   * pure virtual base class for the dimension speciefic ElInfo classes, it must
   * not be instantiated directly.
   * \see ElInfo1d \see ElInfo2d \see ElInfo3d
   */

  class ElInfo
  {
  protected: 
54
    /// Protected constructor. Avoids instatiation of the basis class
55
56
57
58
59
60
61
62
63
    ElInfo();

    /** \brief
     * Protected constructor. Avoids instatiation of the basis class.
     * \param mesh pointer to the corresponding mesh.
     */
    ElInfo(Mesh *mesh);

  public:
64
    /// Virtual destructor because ElInfo is pure virtual.
65
66
67
68
69
70
71
72
73
74
75
76
    virtual ~ElInfo();

    /** \brief
     * Assignement operator.
     * \param rhs right hand side.
     */
    ElInfo& operator=(const ElInfo& rhs) {
      mesh_ = rhs.mesh_;
      element_ = rhs.element_;
      parent_ = rhs.parent_;
      macroElement_ = rhs.macroElement_;
      fillFlag_ = rhs.fillFlag_;
77
      level = rhs.level;
78
      iChild = rhs.iChild;
79
80
81
82
      coord_ = rhs.coord_;
      boundary_ = rhs.boundary_;
      oppCoord_ = rhs.oppCoord_;
      neighbour_ = rhs.neighbour_;
83
      neighbourCoord_ = rhs.neighbourCoord_;
84
85
      oppVertex_ = rhs.oppVertex_;
      return *this;
86
    }
87
88
89
90
91
92

  public:
    /** \name getting methods
     * \{ 
     */

93
    /// Get ElInfo's \ref mesh_
94
95
    inline Mesh* getMesh() const { 
      return mesh_; 
96
    }
97

98
    /// Get ElInfo's \ref macroElement_
99
100
    inline MacroElement* getMacroElement() const { 
      return macroElement_; 
101
    }
102

103
    /// Get ElInfo's \ref element
104
105
    inline Element* getElement() const { 
      return element_; 
106
    }
107

108
    /// Get ElInfo's \ref parent_
109
110
    inline Element* getParent() const { 
      return parent_; 
111
    }
112

113
    /// Get ElInfo's \ref fillFlag_
114
115
    inline Flag getFillFlag() const { 
      return fillFlag_; 
116
    }
117

118
    /// Get ElInfo's \ref level
119
120
121
122
    inline int getLevel() const { 
      return level; 
    }

123
    /// Get ElInfo's \ref iChild
124
125
    inline int getIChild() const {
      return iChild;
126
    }
127
128
129
130
131
132
133

    /** \brief
     * Get ElInfo's \ref coord_[i]. This is a WorldVector<double> filled with the
     * coordinates of the i-th vertex of element \ref el.
     */
    inline WorldVector<double>& getCoord(int i) { 
      return coord_[i]; 
134
    }
135
136
137
138
139
140
141

    /** \brief
     * Get ElInfo's \ref coord_[i]. This is a WorldVector<double> filled with the
     * coordinates of the i-th vertex of element \ref el.
     */
    inline const WorldVector<double>& getCoord(int i) const { 
      return coord_[i]; 
142
    }
143
144
145
146
147

    /** \brief
     * Get ElInfo's \ref coord_. This is a FixVec<WorldVector<double> > filled with the
     * coordinates of the all vertice of element \ref el.
     */
148
    inline FixVec<WorldVector<double>, VERTEX>& getCoords() { 
149
      return coord_; 
150
    }
151
152
153
154
155

    /** \brief
     * Get ElInfo's \ref coord_. This is a FixVec<WorldVector<double> > filled with the
     * coordinates of the all vertice of element \ref el.
     */
156
    inline const FixVec<WorldVector<double>, VERTEX>& getCoords() const { 
157
      return coord_; 
158
    }
159

160
    /// Get ElInfo's \ref oppCoord_[i]
161
162
    inline WorldVector<double>& getOppCoord(int i) { 
      return oppCoord_[i]; 
163
    }
164

165
    /// Get ElInfo's \ref boundary_[i] 
166
    inline BoundaryType getBoundary(int i) const { 
167
      return boundary_[i]; 
168
    }
169

170
    /// Get boundary type of i-th vertex/edge/face (pos).
171
172
    BoundaryType getBoundary(GeoIndex pos, int i);

173
    /// Get ElInfo's \ref neighbour_[i]
174
175
    inline Element* getNeighbour(int i) const { 
      return neighbour_[i]; 
176
    }
177

178
    /// Get ElInfo's \ref neighbourCoord_[i]
179
180
181
182
    inline FixVec<WorldVector<double>, VERTEX> getNeighbourCoord(int i) const {
      return neighbourCoord_[i];
    }

183
    /// Get ElInfo's \ref oppVertex_[i] 
184
185
    inline unsigned char getOppVertex(int i) const { 
      return oppVertex_[i]; 
186
    }
187
188
189

    virtual int getSideOfNeighbour(int i) { 
      return oppVertex_[i]; 
190
    }
191

192
    /// Get ElInfo's \ref det_
193
194
    inline double getDet() const { 
      return det_; 
195
    }
196

197
    /// Returns \ref grdLambda
198
    inline const DimVec<WorldVector<double> >& getGrdLambda() const { 
Thomas Witkowski's avatar
Thomas Witkowski committed
199
      return grdLambda; 
200
    }
201

202
    /// Returns \ref projection_[i]
203
204
    inline Projection *getProjection(int i) const {
      return projection_[i];
205
    }
206

207
    /// Returns \ref parametric_
208
209
    inline bool getParametric() { 
      return parametric_; 
210
211
    }

212
213
214
215
216
217
    /** \brief
     * Returns the element transformation matrix \ref subElemCoordsMat .
     * This value is set only during dual traverse.
     */
    inline DimMat<double> *getSubElemCoordsMat() const {
      return subElemCoordsMat;
218
    }
219
220
221
222
223
224
225

    /** \} */ 

    /** \name setting methods
     * \{ 
     */

226
    /// Set ElInfo's \ref mesh_
227
228
    inline void setMesh(Mesh* aMesh) { 
      mesh_ = aMesh; 
229
    }
230

231
    /// Set ElInfo's \ref macroElement_
232
233
    inline void setMacroElement(MacroElement* mel) { 
      macroElement_ = mel; 
234
    }
235

236
    /// Set ElInfo's \ref element
237
238
    inline void setElement(Element* elem) { 
      element_ = elem; 
239
    }
240

241
    /// Set ElInfo's \ref parent_
242
243
    inline void setParent(Element* elem) { 
      parent_ = elem; 
244
    }
245

246
    /// Set ElInfo's \ref fillFlag_
247
248
    inline void setFillFlag(Flag flag) { 
      fillFlag_ = flag; 
249
    }
250

251
    /// Sets ElInfo's \ref coord_[i]. 
252
253
    inline void setCoord(int i,WorldVector<double>& coord) { 
      coord_[i] = coord; 
254
    }
255

256
    /// Sets ElInfo's \ref coord. 
257
258
    inline void setCoords(FixVec<WorldVector<double>,VERTEX >& coords) { 
      coord_ = coords; 
259
    }
260

261
    /// Set ElInfo's \ref level
262
    inline void setLevel(int l) { 
263
264
265
      level = l; 
    }

266
    /// Set ElInfo's \ref boundary_[i] 
267
268
    inline void setBoundary(int i, BoundaryType t) { 
      boundary_[i] = newBound(boundary_[i], t);
269
    }
270

271
    /// Set \ref projection_[i] = p
272
273
    inline void setProjection(int i, Projection *p) {
      projection_[i] = p;
274
    }
275

276
    /// Set \ref det_ = d
277
278
    inline void setDet(double d) { 
      det_ = d; 
279
    }
280

281
    /// Set \ref parametric_ = param
282
283
    inline void setParametric(bool param) { 
      parametric_ = param; 
284
285
    }

286
287
288
289
290
291
    /** \brief
     * Sets the element transformation matrix \ref subElemCoordsMat .
     * This value is used only during dual traverse.
     */
    inline void setSubElemCoordsMat(DimMat<double> *mat) {
      subElemCoordsMat = mat;
292
    }
293
294
295
296
297
298
299
300
301
302
303
304
305
306
  
    /** \} */


    /** \brief
     * Returns the absolute value of the determinant of the affine linear 
     * parametrization's Jacobian
     */
    virtual double calcDet() const;

    /** \brief
     * Used by non static method \ref calcDet(). Calculates the determinant
     * for a given vector of vertex coordinates.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
307
    double calcDet(const FixVec<WorldVector<double>, VERTEX> &coords) const;
308
309
310
311
312
313
314
315

    /** \brief
     * Checks whether flag is set in ElInfo's \ref fillFlag_. If not, the program
     * exits.
     */
    void testFlag(const Flag& flag) const;

    /** \brief
316
317
     * Transforms local barycentric coordinates of a point defined on this element
     * to global world coordinates.
318
     */
319
320
    void coordToWorld(const DimVec<double>& lambda,
		      WorldVector<double>& world) const;
321
322
323
  

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
324
     * Fills ElInfo's \ref det_ and \ref grdLambda entries.
325
326
327
328
329
330
331
332
333
334
335
336
     */
    virtual void fillDetGrdLambda();

    // ===== pure virtual functions. Must be overriden in sub-classes ============

    /** \brief
     * Returns a pointer to a vector, which contains the barycentric coordinates
     * with respect to \ref element of a point with world coordinates world.
     * The barycentric coordinates are stored in lambda. 
     * pure virtual => must be overriden in sub-class.
     */
    virtual const int worldToCoord(const WorldVector<double>& world, 
337
				   DimVec<double>* lambda) const = 0;
338
339
340
341
342
343
344
345
346
347
348
349

    /** \brief
     * Fills this ElInfo with macro element information of mel.
     * pure virtual => must be overriden in sub-class.
     */
    virtual void fillMacroInfo(const MacroElement *mel) = 0;

    /** \brief
     * Fills this ElInfo for the child ichild using hierarchy information and
     * parent data parentInfo.
     * pure virtual => must be overriden in sub-class.
     */
350
    virtual void fillElInfo(int ichild, const ElInfo *parentInfo) = 0;
351
352
353
354
355
356
357

    /** \brief
     * calculates the Jacobian of the barycentric coordinates on \element and stores
     * the matrix in grd_lam. The return value of the function is the absolute
     * value of the determinant of the affine linear paraetrization's Jacobian.
     * pure virtual => must be overriden in sub-class.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
358
    virtual double calcGrdLambda(DimVec<WorldVector<double> >& grd_lam) = 0;
359
360
361
362
363
364
365

    /** \brief
     * calculates a normal of the given side (1d,2d: edge, 3d: face) of \ref element.
     * Returns the absolute value of the determinant of the
     * transformation to the reference element.
     * pure virtual => must be overriden in sub-class.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
366
    virtual double getNormal(int side, WorldVector<double> &normal) = 0;
367
368
369
370
371
372
373
374
375
376


    /** \brief
     * calculates a normal of the element in dim of world = dim + 1.
     * Returns the absolute value of the determinant of the
     * transformation to the reference element.
     * pure virtual => must be overriden in sub-class.
     */
    virtual double getElementNormal(WorldVector<double> &elementNormal) const 
    {
377
378
      FUNCNAME("ElInfo::getElementNormal()");

379
380
381
      ERROR("virtual function not implemented in this sub-class ");
    
      return(0.0);
382
    }
383

384
385
    virtual void getRefSimplexCoords(const BasisFunction *basisFcts,
				     DimMat<double> *coords) const = 0;
386

387
388
389
    virtual void getSubElementCoords(const BasisFunction *basisFcts,
				     int iChild,
				     DimMat<double> *coords) const = 0;
390
391

  protected:
392
    /// Pointer to the current mesh
393
394
    Mesh *mesh_;

395
    /// Pointer to the current element
396
397
    Element *element_;

398
    /// \ref element is child of element parent_
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
    Element *parent_;

    /** \brief 
     * \ref element is an element of the binary tree located at MacroElement 
     * macroElement_
     */
    MacroElement *macroElement_;

    /** \brief
     * Indicates wich elements will be called and wich information should be
     * present while mesh traversal.
     */
    Flag fillFlag_;

    /** \brief 
     * Level of the element. The level is zero for macro elements and the level
     * of the children is (level of the parent + 1). level_ is filled always by
     * the traversal routines.
     */
418
419
    unsigned char level;

420
421
422
423
424
    /** \brief
     * This ElInfo is the iChild-th child of the parent element.
     */
    int iChild;

425
426
427
428
    /** \brief 
     * \ref coord_[i] is a WorldVector<double> storing the world coordinates of the
     * i-th vertex of element \ref element.
     */
429
    FixVec<WorldVector<double>, VERTEX> coord_;
430
431
432
433
434
435
436
437

    /** \brief 
     * boundary_[i] is the BoundaryType of the i-th edge/face
     * for i=0,...,N_NEIGH - 1. In 3d 
     * (*boundary_)[N_FACES + i] is a pointer to the Boundary
     * object of the i-th edge, for i=0,..,N_EDGES - 1. It is
     * a pointer to NULL for an interior edge/face.
     */
438
    FixVec<BoundaryType, BOUNDARY> boundary_;
439
440
441
442
443
444
445
446
447
448

    /** \brief
     * Vector storing pointers to projections for each face, edge, vertex.
     */
    FixVec<Projection*, PROJECTION> projection_;

    /** \brief 
     * oppCoord_[i] coordinates of the i-th neighbour vertex opposite the
     * common edge/face.
     */
449
    FixVec<WorldVector<double>, NEIGH> oppCoord_;
450
451
452
453
454

    /** \brief 
     * neighbour_[i] pointer to the element at the edge/face with local index i.
     * It is a pointer to NULL for boundary edges/faces.
     */
455
456
457
458
459
460
461
    FixVec<Element*, NEIGH> neighbour_;

    /** \brief
     * neighbourCoord_[i][j] are the coordinate of the j-th vertex of the i-th
     * neighbour element with the common edge/face.
     */
    FixVec<FixVec<WorldVector<double>, VERTEX>, NEIGH> neighbourCoord_;
462
463
464
465
466
467

    /** \brief 
     * oppVertex_[i] is undefined if neighbour_[i] is a pointer to NULL. 
     * Otherwise it is the local index of the neighbour's vertex opposite the
     * common edge/face.
     */
468
    FixVec<unsigned char, NEIGH> oppVertex_;
469

Thomas Witkowski's avatar
Thomas Witkowski committed
470
    /// Elements determinant.
471
472
    double det_;

Thomas Witkowski's avatar
Thomas Witkowski committed
473
    /// Gradient of lambda.
Thomas Witkowski's avatar
Thomas Witkowski committed
474
    DimVec<WorldVector<double> > grdLambda;
475

Thomas Witkowski's avatar
Thomas Witkowski committed
476
    /// True, if this elInfo stores parametrized information. False, otherwise.
477
478
    bool parametric_;

Thomas Witkowski's avatar
Thomas Witkowski committed
479
    /// Stores the world dimension.
Thomas Witkowski's avatar
Thomas Witkowski committed
480
481
    int dimOfWorld;

482
483
484
485
486
487
488
489
    /** \brief
     * This is a transformation matrix used during dual traverse. It is set, if
     * the current element is the smaller element of an element pair in the traverse.
     * Then this matrix defines a mapping for points defined in barycentric 
     * coordinates on the larger element, to the barycentric coordinates of the smaller
     * element.
     */
    DimMat<double> *subElemCoordsMat;
490

491
492
493
494
495
496
497
498
499
    // ===== static public members ================================================
  public:
    /** \brief 
     * child_vertex[el_type][child][i] = father's local vertex index of new 
     * vertex i. 4 stands for the newly generated vertex .
     */
    static const int childVertex[3][2][4];

    /** \brief 
500
     * child_edge[el_type][child][i] = father's local edge index of new edge i.
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
     * new edge 2 is half of old edge 0, new edges 4,5 are really new edges, and
     * value is different: child_edge[][][4,5] = index of same edge in other
     * child.
     */
    static const int childEdge[3][2][6];

    friend class ElInfo1d;
    friend class ElInfo2d;
    friend class ElInfo3d;
  };

}

#include "ElInfo1d.h"
#include "ElInfo2d.h"
#include "ElInfo3d.h"

#endif  // AMDIS_ELINFO_H