ElInfo.h 15 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
// ==                                                                        ==
// ============================================================================

/** \file ElInfo.h */

#ifndef AMDIS_ELINFO_H
#define AMDIS_ELINFO_H

25
26
#include <boost/numeric/mtl/mtl.hpp>

27
28
29
30
31
#include "Flag.h"
#include "Boundary.h"
#include "Global.h"
#include "FixVec.h"
#include "Element.h"
32
#include "AMDiS_fwd.h" 
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

namespace AMDiS {

  /** \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: 
50
    /// Protected constructor. Avoids instatiation of the basis class
51
52
53
54
55
56
57
58
59
    ElInfo();

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

  public:
60
    /// Virtual destructor because ElInfo is pure virtual.
61
62
63
64
65
66
    virtual ~ElInfo();

    /** \brief
     * Assignement operator.
     * \param rhs right hand side.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
67
68
    ElInfo& operator=(const ElInfo& rhs) 
    {
69
70
71
72
73
      mesh_ = rhs.mesh_;
      element_ = rhs.element_;
      parent_ = rhs.parent_;
      macroElement_ = rhs.macroElement_;
      fillFlag_ = rhs.fillFlag_;
74
      level = rhs.level;
75
      iChild = rhs.iChild;
76
77
78
79
      coord_ = rhs.coord_;
      boundary_ = rhs.boundary_;
      oppCoord_ = rhs.oppCoord_;
      neighbour_ = rhs.neighbour_;
80
      neighbourCoord_ = rhs.neighbourCoord_;
81
      oppVertex = rhs.oppVertex;
82
      return *this;
83
    }
84
85
86
87
88
89

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

90
    /// Get ElInfo's \ref mesh_
Thomas Witkowski's avatar
Thomas Witkowski committed
91
92
    inline Mesh* getMesh() const 
    { 
93
      return mesh_; 
94
    }
95

96
    /// Get ElInfo's \ref macroElement_
Thomas Witkowski's avatar
Thomas Witkowski committed
97
98
    inline MacroElement* getMacroElement() const 
    { 
99
      return macroElement_; 
100
    }
101

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

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

114
    /// Get ElInfo's \ref fillFlag_
Thomas Witkowski's avatar
Thomas Witkowski committed
115
116
    inline Flag getFillFlag() const 
    { 
117
      return fillFlag_; 
118
    }
119

120
    /// Get ElInfo's \ref level
Thomas Witkowski's avatar
Thomas Witkowski committed
121
122
    inline int getLevel() const 
    { 
123
124
125
      return level; 
    }

126
    /// Get ElInfo's \ref iChild
Thomas Witkowski's avatar
Thomas Witkowski committed
127
128
    inline int getIChild() const 
    {
129
      return iChild;
130
    }
131
132
133
134
135

    /** \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.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
136
137
    inline WorldVector<double>& getCoord(int i) 
    { 
138
      return coord_[i]; 
139
    }
140
141
142
143
144

    /** \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.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
145
146
    inline const WorldVector<double>& getCoord(int i) const 
    { 
147
      return coord_[i]; 
148
    }
149
150
151
152
153

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

    /** \brief
     * Get ElInfo's \ref coord_. This is a FixVec<WorldVector<double> > filled with the
     * coordinates of the all vertice of element \ref el.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
163
164
    inline const FixVec<WorldVector<double>, VERTEX>& getCoords() const 
    { 
165
      return coord_; 
166
    }
167

168
    /// Get ElInfo's \ref oppCoord_[i]
Thomas Witkowski's avatar
Thomas Witkowski committed
169
170
    inline WorldVector<double>& getOppCoord(int i) 
    { 
171
      return oppCoord_[i]; 
172
    }
173

174
    /// Get ElInfo's \ref boundary_[i] 
Thomas Witkowski's avatar
Thomas Witkowski committed
175
176
    inline BoundaryType getBoundary(int i) const 
    { 
177
      return boundary_[i]; 
178
    }
179

180
    /// Get boundary type of i-th vertex/edge/face (pos).
181
182
    BoundaryType getBoundary(GeoIndex pos, int i);

183
    /// Get ElInfo's \ref neighbour_[i]
Thomas Witkowski's avatar
Thomas Witkowski committed
184
185
    inline Element* getNeighbour(int i) const 
    { 
186
      return neighbour_[i]; 
187
    }
188

189
    /// Get ElInfo's \ref neighbourCoord_[i]
Thomas Witkowski's avatar
Thomas Witkowski committed
190
191
    inline FixVec<WorldVector<double>, VERTEX> getNeighbourCoord(int i) const 
    {
192
193
194
      return neighbourCoord_[i];
    }

195
    /// Get ElInfo's \ref oppVertex[i] 
Thomas Witkowski's avatar
Thomas Witkowski committed
196
197
    inline unsigned char getOppVertex(int i) const 
    { 
198
      return oppVertex[i]; 
199
    }
200

Thomas Witkowski's avatar
Thomas Witkowski committed
201
202
    virtual int getSideOfNeighbour(int i) 
    { 
203
      return oppVertex[i]; 
204
    }
205

206
    /// Get ElInfo's \ref det_
Thomas Witkowski's avatar
Thomas Witkowski committed
207
208
    inline double getDet() const 
    { 
209
      return det_; 
210
    }
211

212
    /// Returns \ref grdLambda
Thomas Witkowski's avatar
Thomas Witkowski committed
213
214
    inline const DimVec<WorldVector<double> >& getGrdLambda() const 
    { 
Thomas Witkowski's avatar
Thomas Witkowski committed
215
      return grdLambda; 
216
    }
217

218
    /// Returns \ref projection_[i]
Thomas Witkowski's avatar
Thomas Witkowski committed
219
220
    inline Projection *getProjection(int i) const 
    {
221
      return projection_[i];
222
    }
223

224
    /// Returns \ref parametric
Thomas Witkowski's avatar
Thomas Witkowski committed
225
226
    inline bool getParametric() 
    { 
227
      return parametric; 
228
229
    }

230
231
232
233
234
    virtual void getSubElemCoordsMat(mtl::dense2D<double>& mat,
				     int basisFctsDegree) const {}

    virtual void getSubElemCoordsMat_so(mtl::dense2D<double>& mat,
					int basisFctsDegree) const {}
235
236
237
238
239
240
241

    /** \} */ 

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

242
    /// Set ElInfo's \ref mesh_
Thomas Witkowski's avatar
Thomas Witkowski committed
243
244
    inline void setMesh(Mesh* aMesh) 
    { 
245
      mesh_ = aMesh; 
246
    }
247

248
    /// Set ElInfo's \ref macroElement_
Thomas Witkowski's avatar
Thomas Witkowski committed
249
250
    inline void setMacroElement(MacroElement* mel) 
    { 
251
      macroElement_ = mel; 
252
    }
253

254
    /// Set ElInfo's \ref element
Thomas Witkowski's avatar
Thomas Witkowski committed
255
256
    inline void setElement(Element* elem) 
    { 
257
      element_ = elem; 
258
    }
259

260
    /// Set ElInfo's \ref parent_
Thomas Witkowski's avatar
Thomas Witkowski committed
261
262
    inline void setParent(Element* elem) 
    { 
263
      parent_ = elem; 
264
    }
265

266
    /// Set ElInfo's \ref fillFlag_
Thomas Witkowski's avatar
Thomas Witkowski committed
267
268
    inline void setFillFlag(Flag flag) 
    { 
269
      fillFlag_ = flag; 
270
    }
271

272
    /// Sets ElInfo's \ref coord_[i]. 
Thomas Witkowski's avatar
Thomas Witkowski committed
273
274
    inline void setCoord(int i,WorldVector<double>& coord) 
    { 
275
      coord_[i] = coord; 
276
    }
277

278
    /// Sets ElInfo's \ref coord. 
Thomas Witkowski's avatar
Thomas Witkowski committed
279
280
    inline void setCoords(FixVec<WorldVector<double>,VERTEX >& coords) 
    { 
281
      coord_ = coords; 
282
    }
283

284
    /// Set ElInfo's \ref level
Thomas Witkowski's avatar
Thomas Witkowski committed
285
286
    inline void setLevel(int l) 
    { 
287
288
289
      level = l; 
    }

290
    /// Set ElInfo's \ref boundary_[i] 
Thomas Witkowski's avatar
Thomas Witkowski committed
291
292
    inline void setBoundary(int i, BoundaryType t) 
    { 
293
      boundary_[i] = newBound(boundary_[i], t);
294
    }
295

296
    /// Set \ref projection_[i] = p
Thomas Witkowski's avatar
Thomas Witkowski committed
297
298
    inline void setProjection(int i, Projection *p) 
    {
299
      projection_[i] = p;
300
    }
301

302
    /// Set \ref det_ = d
Thomas Witkowski's avatar
Thomas Witkowski committed
303
304
    inline void setDet(double d) 
    { 
305
      det_ = d; 
306
    }
307

308
    /// Set \ref parametric = param
Thomas Witkowski's avatar
Thomas Witkowski committed
309
310
    inline void setParametric(bool param) 
    { 
311
      parametric = param; 
312
313
    }

314
315
316
317
318
319
320
321
322
323
324
325
    /// Set \ref refinementPath
    inline void setRefinementPath(unsigned long rPath)
    {
      refinementPath = rPath;
    } 

    /// Set \ref refinementPathLength
    inline void setRefinementPathLength(int length)
    {
      refinementPathLength = length;
    }

326
327
328
329
330
331
332
333
334
335
336
337
338
    /** \} */


    /** \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
339
    double calcDet(const FixVec<WorldVector<double>, VERTEX> &coords) const;
340
341
342
343
344
345
346
347

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

    /** \brief
348
349
     * Transforms local barycentric coordinates of a point defined on this element
     * to global world coordinates.
350
     */
351
352
    void coordToWorld(const DimVec<double>& lambda,
		      WorldVector<double>& world) const;
353
  
354
    /// Fills ElInfo's \ref det_ and \ref grdLambda entries.
355
356
357
358
359
360
361
362
363
    virtual void fillDetGrdLambda();

    /** \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, 
364
				   DimVec<double>* lambda) const = 0;
365
366
367
368
369
370
371
372
373
374
375
376

    /** \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.
     */
377
    virtual void fillElInfo(int ichild, const ElInfo *parentInfo) = 0;
378
379
380
381
382
383
384

    /** \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
385
    virtual double calcGrdLambda(DimVec<WorldVector<double> >& grd_lam) = 0;
386
387
388
389
390
391
392

    /** \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
393
    virtual double getNormal(int side, WorldVector<double> &normal) = 0;
394
395
396
397
398
399
400
401
402
403


    /** \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 
    {
404
405
      FUNCNAME("ElInfo::getElementNormal()");

406
407
408
      ERROR("virtual function not implemented in this sub-class ");
    
      return(0.0);
409
    }
410
411

  protected:
412
    /// Pointer to the current mesh
413
414
    Mesh *mesh_;

415
    /// Pointer to the current element
416
417
    Element *element_;

418
    /// \ref element is child of element parent_
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
    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.
     */
438
439
    unsigned char level;

440
441
442
443
444
    /** \brief
     * This ElInfo is the iChild-th child of the parent element.
     */
    int iChild;

445
446
447
448
    /** \brief 
     * \ref coord_[i] is a WorldVector<double> storing the world coordinates of the
     * i-th vertex of element \ref element.
     */
449
    FixVec<WorldVector<double>, VERTEX> coord_;
450
451
452
453
454
455
456
457

    /** \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.
     */
458
    FixVec<BoundaryType, BOUNDARY> boundary_;
459
460
461
462
463
464
465
466
467
468

    /** \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.
     */
469
    FixVec<WorldVector<double>, NEIGH> oppCoord_;
470
471
472
473
474

    /** \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.
     */
475
476
477
478
479
480
481
    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_;
482
483

    /** \brief 
484
     * oppVertex[i] is undefined if neighbour_[i] is a pointer to NULL. 
485
486
487
     * Otherwise it is the local index of the neighbour's vertex opposite the
     * common edge/face.
     */
488
    FixVec<unsigned char, NEIGH> oppVertex;
489

Thomas Witkowski's avatar
Thomas Witkowski committed
490
    /// Elements determinant.
491
492
    double det_;

Thomas Witkowski's avatar
Thomas Witkowski committed
493
    /// Gradient of lambda.
Thomas Witkowski's avatar
Thomas Witkowski committed
494
    DimVec<WorldVector<double> > grdLambda;
495

Thomas Witkowski's avatar
Thomas Witkowski committed
496
    /// True, if this elInfo stores parametrized information. False, otherwise.
497
    bool parametric;
498

Thomas Witkowski's avatar
Thomas Witkowski committed
499
    /// Stores the world dimension.
Thomas Witkowski's avatar
Thomas Witkowski committed
500
501
    int dimOfWorld;

502
503
504
505
    unsigned long refinementPath;

    int refinementPathLength;

506
507
508
509
510
511
512
    /** \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.
     */
513
    mtl::dense2D<double> subElemCoordsMat;
514

515
516
    mtl::dense2D<double> subElemCoordsMat_so;

517
518
519
520
521
522
523
524
  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 
525
     * child_edge[el_type][child][i] = father's local edge index of new edge i.
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
     * 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