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

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
67
68
69
70
71
72
    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_;
73
      level = rhs.level;
74
      iChild = rhs.iChild;
75
76
77
78
      coord_ = rhs.coord_;
      boundary_ = rhs.boundary_;
      oppCoord_ = rhs.oppCoord_;
      neighbour_ = rhs.neighbour_;
79
      neighbourCoord_ = rhs.neighbourCoord_;
80
81
      oppVertex_ = rhs.oppVertex_;
      return *this;
82
    }
83
84
85
86
87
88

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

89
    /// Get ElInfo's \ref mesh_
90
91
    inline Mesh* getMesh() const { 
      return mesh_; 
92
    }
93

94
    /// Get ElInfo's \ref macroElement_
95
96
    inline MacroElement* getMacroElement() const { 
      return macroElement_; 
97
    }
98

99
    /// Get ElInfo's \ref element
100
101
    inline Element* getElement() const { 
      return element_; 
102
    }
103

104
    /// Get ElInfo's \ref parent_
105
106
    inline Element* getParent() const { 
      return parent_; 
107
    }
108

109
    /// Get ElInfo's \ref fillFlag_
110
111
    inline Flag getFillFlag() const { 
      return fillFlag_; 
112
    }
113

114
    /// Get ElInfo's \ref level
115
116
117
118
    inline int getLevel() const { 
      return level; 
    }

119
    /// Get ElInfo's \ref iChild
120
121
    inline int getIChild() const {
      return iChild;
122
    }
123
124
125
126
127
128
129

    /** \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]; 
130
    }
131
132
133
134
135
136
137

    /** \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]; 
138
    }
139
140
141
142
143

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

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

156
    /// Get ElInfo's \ref oppCoord_[i]
157
158
    inline WorldVector<double>& getOppCoord(int i) { 
      return oppCoord_[i]; 
159
    }
160

161
    /// Get ElInfo's \ref boundary_[i] 
162
    inline BoundaryType getBoundary(int i) const { 
163
      return boundary_[i]; 
164
    }
165

166
    /// Get boundary type of i-th vertex/edge/face (pos).
167
168
    BoundaryType getBoundary(GeoIndex pos, int i);

169
    /// Get ElInfo's \ref neighbour_[i]
170
171
    inline Element* getNeighbour(int i) const { 
      return neighbour_[i]; 
172
    }
173

174
    /// Get ElInfo's \ref neighbourCoord_[i]
175
176
177
178
    inline FixVec<WorldVector<double>, VERTEX> getNeighbourCoord(int i) const {
      return neighbourCoord_[i];
    }

179
    /// Get ElInfo's \ref oppVertex_[i] 
180
181
    inline unsigned char getOppVertex(int i) const { 
      return oppVertex_[i]; 
182
    }
183
184
185

    virtual int getSideOfNeighbour(int i) { 
      return oppVertex_[i]; 
186
    }
187

188
    /// Get ElInfo's \ref det_
189
190
    inline double getDet() const { 
      return det_; 
191
    }
192

193
    /// Returns \ref grdLambda
194
    inline const DimVec<WorldVector<double> >& getGrdLambda() const { 
Thomas Witkowski's avatar
Thomas Witkowski committed
195
      return grdLambda; 
196
    }
197

198
    /// Returns \ref projection_[i]
199
200
    inline Projection *getProjection(int i) const {
      return projection_[i];
201
    }
202

203
    /// Returns \ref parametric_
204
205
    inline bool getParametric() { 
      return parametric_; 
206
207
    }

208
209
210
211
    /** \brief
     * Returns the element transformation matrix \ref subElemCoordsMat .
     * This value is set only during dual traverse.
     */
212
    inline const mtl::dense2D<double>& getSubElemCoordsMat() const {
213
      return subElemCoordsMat;
214
    }
215
216
217
218
219
220
221

    /** \} */ 

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

222
    /// Set ElInfo's \ref mesh_
223
224
    inline void setMesh(Mesh* aMesh) { 
      mesh_ = aMesh; 
225
    }
226

227
    /// Set ElInfo's \ref macroElement_
228
229
    inline void setMacroElement(MacroElement* mel) { 
      macroElement_ = mel; 
230
    }
231

232
    /// Set ElInfo's \ref element
233
234
    inline void setElement(Element* elem) { 
      element_ = elem; 
235
    }
236

237
    /// Set ElInfo's \ref parent_
238
239
    inline void setParent(Element* elem) { 
      parent_ = elem; 
240
    }
241

242
    /// Set ElInfo's \ref fillFlag_
243
244
    inline void setFillFlag(Flag flag) { 
      fillFlag_ = flag; 
245
    }
246

247
    /// Sets ElInfo's \ref coord_[i]. 
248
249
    inline void setCoord(int i,WorldVector<double>& coord) { 
      coord_[i] = coord; 
250
    }
251

252
    /// Sets ElInfo's \ref coord. 
253
254
    inline void setCoords(FixVec<WorldVector<double>,VERTEX >& coords) { 
      coord_ = coords; 
255
    }
256

257
    /// Set ElInfo's \ref level
258
    inline void setLevel(int l) { 
259
260
261
      level = l; 
    }

262
    /// Set ElInfo's \ref boundary_[i] 
263
264
    inline void setBoundary(int i, BoundaryType t) { 
      boundary_[i] = newBound(boundary_[i], t);
265
    }
266

267
    /// Set \ref projection_[i] = p
268
269
    inline void setProjection(int i, Projection *p) {
      projection_[i] = p;
270
    }
271

272
    /// Set \ref det_ = d
273
274
    inline void setDet(double d) { 
      det_ = d; 
275
    }
276

277
    /// Set \ref parametric_ = param
278
279
    inline void setParametric(bool param) { 
      parametric_ = param; 
280
281
    }

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


    /** \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
303
    double calcDet(const FixVec<WorldVector<double>, VERTEX> &coords) const;
304
305
306
307
308
309
310
311

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

    /** \brief
312
313
     * Transforms local barycentric coordinates of a point defined on this element
     * to global world coordinates.
314
     */
315
316
    void coordToWorld(const DimVec<double>& lambda,
		      WorldVector<double>& world) const;
317
  
318
    /// Fills ElInfo's \ref det_ and \ref grdLambda entries.
319
320
321
322
323
324
325
326
327
    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, 
328
				   DimVec<double>* lambda) const = 0;
329
330
331
332
333
334
335
336
337
338
339
340

    /** \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.
     */
341
    virtual void fillElInfo(int ichild, const ElInfo *parentInfo) = 0;
342
343
344
345
346
347
348

    /** \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
349
    virtual double calcGrdLambda(DimVec<WorldVector<double> >& grd_lam) = 0;
350
351
352
353
354
355
356

    /** \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
357
    virtual double getNormal(int side, WorldVector<double> &normal) = 0;
358
359
360
361
362
363
364
365
366
367


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

370
371
372
      ERROR("virtual function not implemented in this sub-class ");
    
      return(0.0);
373
    }
374

375
376
377
378
379
380
381
382
    virtual void getRefSimplexCoords(const BasisFunction *basisFcts,
				     mtl::dense2D<double>& coords) const = 0;

    virtual void getSubElementCoords(const BasisFunction *basisFcts,
				     int iChild,
				     mtl::dense2D<double>& coords) const = 0;


383
  protected:
384
    /// Pointer to the current mesh
385
386
    Mesh *mesh_;

387
    /// Pointer to the current element
388
389
    Element *element_;

390
    /// \ref element is child of element parent_
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
    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.
     */
410
411
    unsigned char level;

412
413
414
415
416
    /** \brief
     * This ElInfo is the iChild-th child of the parent element.
     */
    int iChild;

417
418
419
420
    /** \brief 
     * \ref coord_[i] is a WorldVector<double> storing the world coordinates of the
     * i-th vertex of element \ref element.
     */
421
    FixVec<WorldVector<double>, VERTEX> coord_;
422
423
424
425
426
427
428
429

    /** \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.
     */
430
    FixVec<BoundaryType, BOUNDARY> boundary_;
431
432
433
434
435
436
437
438
439
440

    /** \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.
     */
441
    FixVec<WorldVector<double>, NEIGH> oppCoord_;
442
443
444
445
446

    /** \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.
     */
447
448
449
450
451
452
453
    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_;
454
455
456
457
458
459

    /** \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.
     */
460
    FixVec<unsigned char, NEIGH> oppVertex_;
461

Thomas Witkowski's avatar
Thomas Witkowski committed
462
    /// Elements determinant.
463
464
    double det_;

Thomas Witkowski's avatar
Thomas Witkowski committed
465
    /// Gradient of lambda.
Thomas Witkowski's avatar
Thomas Witkowski committed
466
    DimVec<WorldVector<double> > grdLambda;
467

Thomas Witkowski's avatar
Thomas Witkowski committed
468
    /// True, if this elInfo stores parametrized information. False, otherwise.
469
470
    bool parametric_;

Thomas Witkowski's avatar
Thomas Witkowski committed
471
    /// Stores the world dimension.
Thomas Witkowski's avatar
Thomas Witkowski committed
472
473
    int dimOfWorld;

474
475
476
477
478
479
480
    /** \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.
     */
481
    mtl::dense2D<double> subElemCoordsMat;
482

483
484
485
486
487
488
489
490
  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 
491
     * child_edge[el_type][child][i] = father's local edge index of new edge i.
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
     * 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