Mesh.h 22.5 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file Mesh.h */

/** \defgroup Triangulation Triangulation module
 * @{ <img src="triangulation.png"> @}
 *
 * Example:
 *
 * @{ <img src="hierarchicalMesh.png"> @}
 *
 * \brief
 * Contains all triangulation classes.
 */

#ifndef AMDIS_MESH_H
#define AMDIS_MESH_H

// ============================================================================
// ===== includes =============================================================
// ============================================================================

#include "DOFAdmin.h"
#include "Line.h"
#include "Triangle.h"
#include "Tetrahedron.h"
#include "Element.h"
#include "ElInfo.h"
#include "FixVec.h"
#include "MemoryManager.h"
#include "Serializable.h"
#include "BoundaryCondition.h"
#include <deque>
#include <set>
#include <stdio.h>

namespace AMDiS {

  // ============================================================================
  // ===== forward declarations =================================================
  // ============================================================================

  template <typename T> class DimVec; 
  template <typename T> class VectorOfFixVecs;
  class Boundary;
  class Projection;
  class ElInfo;
  class Element;
  class MacroElement;
  class DOFAdmin;
  class MacroInfo;
  template<typename T> class WorldVector;
  class Quadrature;
  class Parametric;
  class PeriodicBC;
  class DOFVectorDOF;
  class VertexVector;

  // ============================================================================
  // ===== class Mesh ===========================================================
  // ============================================================================

  /** \ingroup Triangulation 
   * \brief
   * A Mesh holds all information about a triangulation. 
   */
  class Mesh : public Serializable
  {
  public:
    MEMORY_MANAGED(Mesh);

Thomas Witkowski's avatar
Thomas Witkowski committed
89
    /// Creates a mesh with the given name of dimension dim
90
    Mesh(const std::string& name, int dim);
91

Thomas Witkowski's avatar
Thomas Witkowski committed
92
    /// Destructor
93
94
    virtual ~Mesh();

Thomas Witkowski's avatar
Thomas Witkowski committed
95
    /// Reads macro triangulation.
96
97
    void initialize();

Thomas Witkowski's avatar
Thomas Witkowski committed
98
    /// Assignment operator
99
100
101
102
103
104
    Mesh& operator=(const Mesh&);

    /** \name static methods used while mesh traversal 
     * \{
     */

Thomas Witkowski's avatar
Thomas Witkowski committed
105
    /// Used while dof compress
106
107
    static int newDOFFct1(ElInfo* e);

Thomas Witkowski's avatar
Thomas Witkowski committed
108
    /// Used while dof compress
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
    static int newDOFFct2(ElInfo* e);
    /** \} */


    // ==========================================================================
    /** \name getting methods
     * \{
     */

    /** \brief
     * Returns geometric information about this mesh. With GeoIndex p it is 
     * specifiedm which information is requested.
     */
    inline int getGeo(GeoIndex p) const { 
      return Global::getGeo(p, dim); 
124
    }
125

Thomas Witkowski's avatar
Thomas Witkowski committed
126
    /// Returns \ref name of the mesh
127
    inline const std::string& getName() const { 
128
      return name; 
129
    }
130

Thomas Witkowski's avatar
Thomas Witkowski committed
131
    /// Returns \ref dim of the mesh
132
133
    inline int getDim() const { 
      return dim; 
134
    }
135

Thomas Witkowski's avatar
Thomas Witkowski committed
136
    /// Returns \ref nDOFEl of the mesh
137
138
    inline const int getNumberOfAllDOFs() const { 
      return nDOFEl; 
139
    }
140

Thomas Witkowski's avatar
Thomas Witkowski committed
141
    /// Returns \ref nNodeEl of the mesh
142
143
    inline const int getNumberOfNodes() const { 
      return nNodeEl; 
144
    }
145

Thomas Witkowski's avatar
Thomas Witkowski committed
146
    /// Returns \ref nVertices of the mesh
147
148
    inline const int getNumberOfVertices() const { 
      return nVertices; 
149
    }
150

Thomas Witkowski's avatar
Thomas Witkowski committed
151
    /// Returns \ref nEdges of the mesh 
152
153
    inline const int getNumberOfEdges() const { 
      return nEdges; 
154
    }
155

Thomas Witkowski's avatar
Thomas Witkowski committed
156
    /// Returns \ref nFaces of the mesh 
157
158
    inline const int getNumberOfFaces() const { 
      return nFaces; 
159
    }
160

Thomas Witkowski's avatar
Thomas Witkowski committed
161
    /// Returns \ref nLeaves of the mesh 
162
163
    inline const int getNumberOfLeaves() const { 
      return nLeaves; 
164
    }
165

Thomas Witkowski's avatar
Thomas Witkowski committed
166
    /// Returns \ref nElements of the mesh
167
168
    inline const int getNumberOfElements() const { 
      return nElements; 
169
    }
170

Thomas Witkowski's avatar
Thomas Witkowski committed
171
    /// Returns \ref maxEdgeNeigh of the mesh
172
173
    inline const int getMaxEdgeNeigh() const { 
      return maxEdgeNeigh; 
174
    }
175

Thomas Witkowski's avatar
Thomas Witkowski committed
176
    /// Returns \ref parametric of the mesh
177
178
    inline Parametric *getParametric() const { 
      return parametric; 
179
    }
180

Thomas Witkowski's avatar
Thomas Witkowski committed
181
    /// Returns \ref diam of the mesh
182
183
    inline const WorldVector<double>& getDiameter() const { 
      return diam; 
184
    }
185

Thomas Witkowski's avatar
Thomas Witkowski committed
186
    /// Returns nDOF[i] of the mesh
187
188
    inline const int getNumberOfDOFs(int i) const { 
      return nDOF[i]; 
189
    }
190

Thomas Witkowski's avatar
Thomas Witkowski committed
191
    /// Returns \ref elementPrototype of the mesh
192
193
    inline Element* getElementPrototype() { 
      return elementPrototype; 
194
    }
195

Thomas Witkowski's avatar
Thomas Witkowski committed
196
    /// Returns \ref leafDataPrototype of the mesh
197
198
    inline ElementData* getElementDataPrototype() { 
      return elementDataPrototype; 
199
    }
200

Thomas Witkowski's avatar
Thomas Witkowski committed
201
    /// Returns node[i] of the mesh 
202
203
    inline int getNode(int i) const { 
      return node[i]; 
204
    }
205
206
207
208
209
210
211
212
213

    /** \brief
     * Allocates the number of DOFs needed at position and registers the DOFs
     * at the DOFAdmins. The number of needed DOFs is the sum over the needed
     * DOFs of all DOFAdmin objects belonging to this mesh. 
     * The return value is a pointer to the first allocated DOF. 
     */
    DegreeOfFreedom *getDOF(GeoIndex position);

Thomas Witkowski's avatar
Thomas Witkowski committed
214
    /// Returns *(\ref admin[i]) of the mesh
215
216
    inline const DOFAdmin& getDOFAdmin(int i) const {
      return *(admin[i]);
217
    }
218
219
220
221
222
223

    /** \brief
     * Creates a DOFAdmin with name lname. nDOF specifies how many DOFs 
     * are needed at the different positions (see \ref DOFAdmin::nrDOF).
     * A pointer to the created DOFAdmin is returned.
     */
224
    const DOFAdmin* createDOFAdmin(const std::string& lname, DimVec<int> nDOF);
225
226
227
228
229

    /** \brief
     * Returns the size of \ref admin which is the number of the DOFAdmins
     * belonging to this mesh
     */
230
231
    const int getNumberOfDOFAdmin() const {
      return admin.size();
232
    }
233
234
235
236
237

    /** \brief
     * Returns the size of \ref macroElements which is the number of
     * of macro elements of this mesh
     */
238
239
    const int getNumberOfMacros() const {
      return macroElements.size();
240
    }
241

Thomas Witkowski's avatar
Thomas Witkowski committed
242
    /// Returns a DOFAdmin which at least manages vertex DOFs
243
244
    const DOFAdmin* getVertexAdmin() const;

Thomas Witkowski's avatar
Thomas Witkowski committed
245
    /// Allocates a array of DOF pointers. The array holds one pointer for each node.
246
    DegreeOfFreedom **createDOFPtrs();
247

Thomas Witkowski's avatar
Thomas Witkowski committed
248
    /// Returns \ref preserveCoarseDOFs of the mesh
249
250
    inline bool queryCoarseDOFs() const { 
      return preserveCoarseDOFs;
251
    }
252

Thomas Witkowski's avatar
Thomas Witkowski committed
253
    /// Returns an iterator to the begin of \ref macroElements
254
    inline std::deque<MacroElement*>::iterator firstMacroElement() {
255
      return macroElements.begin();
256
    }
257

Thomas Witkowski's avatar
Thomas Witkowski committed
258
    /// Returns macroElements[i].
259
260
    inline MacroElement *getMacroElement(int i) { 
      return macroElements[i]; 
261
    }
262

Thomas Witkowski's avatar
Thomas Witkowski committed
263
    /// Returns an iterator to the end of \ref macroElements
264
    inline std::deque<MacroElement*>::iterator endOfMacroElements() {
265
      return macroElements.end();
266
    }
267
268
269
270
271
272
273
274

    /** \} */

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

Thomas Witkowski's avatar
Thomas Witkowski committed
275
    /// Sets \ref name of the mesh
276
    inline void setName(const std::string& aName) { 
277
      name = aName;
278
    }
279

Thomas Witkowski's avatar
Thomas Witkowski committed
280
    /// Sets \ref nVertices of the mesh
281
282
    inline void setNumberOfVertices(int n) { 
      nVertices = n; 
283
    }
284

Thomas Witkowski's avatar
Thomas Witkowski committed
285
    /// Sets \ref nFaces of the mesh
286
287
    inline void setNumberOfFaces(int n) { 
      nFaces = n; 
288
    }
289

Thomas Witkowski's avatar
Thomas Witkowski committed
290
    /// Increments \ref nVertices by inc
291
292
    inline void incrementNumberOfVertices(int inc) { 
      nVertices += inc; 
293
    }
294
 
Thomas Witkowski's avatar
Thomas Witkowski committed
295
    /// Sets \ref nEdges of the mesh
296
297
    inline void setNumberOfEdges(int n) { 
      nEdges = n; 
298
    }
299

Thomas Witkowski's avatar
Thomas Witkowski committed
300
    /// Increments \ref nEdges by inc
301
302
    inline void incrementNumberOfEdges(int inc) { 
      nEdges += inc; 
303
    }
304

Thomas Witkowski's avatar
Thomas Witkowski committed
305
    /// Increments \ref nFaces by inc
306
307
    inline void incrementNumberOfFaces(int inc) { 
      nFaces += inc; 
308
    }
309

Thomas Witkowski's avatar
Thomas Witkowski committed
310
    /// Sets \ref nLeaves of the mesh
311
312
    inline void setNumberOfLeaves(int n) { 
      nLeaves = n; 
313
    }
314

Thomas Witkowski's avatar
Thomas Witkowski committed
315
    /// Increments \ref nLeaves by inc
316
317
    inline void incrementNumberOfLeaves(int inc) { 
      nLeaves += inc; 
318
    }
319

Thomas Witkowski's avatar
Thomas Witkowski committed
320
    /// Sets \ref nElements of the mesh
321
322
    inline void setNumberOfElements(int n) { 
      nElements = n; 
323
    }
324

Thomas Witkowski's avatar
Thomas Witkowski committed
325
    /// Increments \ref nElements by inc
326
327
    inline void incrementNumberOfElements(int inc) { 
      nElements += inc; 
328
    }
329

Thomas Witkowski's avatar
Thomas Witkowski committed
330
    /// Sets *\ref diam to w
331
332
    void setDiameter(const WorldVector<double>& w);

Thomas Witkowski's avatar
Thomas Witkowski committed
333
    /// Sets (*\ref diam)[i] to d
334
335
    void setDiameter(int i, double d);

Thomas Witkowski's avatar
Thomas Witkowski committed
336
    /// Sets \ref preserveCoarseDOFs = true
337
338
    inline void retainCoarseDOFs() {
      preserveCoarseDOFs = true;
339
    }
340

Thomas Witkowski's avatar
Thomas Witkowski committed
341
    /// Sets \ref preserveCoarseDOFs = b
342
343
    inline void setPreserveCoarseDOFs(bool b) {
      preserveCoarseDOFs = b;
344
    }
345

Thomas Witkowski's avatar
Thomas Witkowski committed
346
    /// Sets \ref preserveCoarseDOFs = false
347
348
    inline void noCoarseDOFs() {
      preserveCoarseDOFs = false;
349
    }
350

Thomas Witkowski's avatar
Thomas Witkowski committed
351
    /// Sets \ref elementPrototype of the mesh
352
353
    inline void setElementPrototype(Element* prototype) {
      elementPrototype = prototype;
354
355
    }
    
Thomas Witkowski's avatar
Thomas Witkowski committed
356
    /// Sets \ref elementDataPrototype of the mesh
357
358
    inline void setElementDataPrototype(ElementData* prototype) {
      elementDataPrototype = prototype;
359
    }
360

Thomas Witkowski's avatar
Thomas Witkowski committed
361
    ///
362
363
    inline void setParametric(Parametric *param) {
      parametric = param;
364
    }
365

Thomas Witkowski's avatar
Thomas Witkowski committed
366
    ///
367
368
    inline void setMaxEdgeNeigh(int m) { 
      maxEdgeNeigh = m; 
369
    }
370
371
372
373
  
    /** \} */
    // ==========================================================================

Thomas Witkowski's avatar
Thomas Witkowski committed
374
    /// Creates a new Element by cloning \ref elementPrototype
375
376
    Element* createNewElement(Element *parent = NULL);

Thomas Witkowski's avatar
Thomas Witkowski committed
377
    /// Creates a new ElInfo dependent of \ref dim of the mesh
378
379
    ElInfo* createNewElInfo();

Thomas Witkowski's avatar
Thomas Witkowski committed
380
    /// Frees DOFs at the given position pointed by dof 
381
382
    void freeDOF(DegreeOfFreedom* dof, GeoIndex position);

Thomas Witkowski's avatar
Thomas Witkowski committed
383
    /// Frees memory for the given element el
384
385
    void freeElement(Element* el);

Thomas Witkowski's avatar
Thomas Witkowski committed
386
    /// Performs DOF compression for all DOFAdmins (see \ref DOFAdmin::compress)
387
388
    void dofCompress();

Thomas Witkowski's avatar
Thomas Witkowski committed
389
    /// Adds a DOFAdmin to the mesh
390
    virtual void addDOFAdmin(DOFAdmin *admin);
391

392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
    /** \brief
     * Traverses the mesh. The argument level specifies the element level if 
     * CALL_EL_LEVEL or CALL_LEAF_EL_LEVEL, or the multigrid level if 
     * CALL_MG_LEVEL is set. Otherwise this variable is ignored. By the argument
     * fillFlag the elements to be traversed and data to be filled into ElInfo is
     * selected, using bitwise or of one CALL_... flag and several FILL_... 
     * flags. The argument elFct is a pointer to a function which is called on 
     * every element selected by the CALL_... part of fillFlag.
     * It is possible to use the recursive mesh traversal recursively, by calling
     * traverse() from elFct.
     */
    int traverse(int level, 
		 const Flag fillFlag,
		 int (*elFct)(ElInfo*));

Thomas Witkowski's avatar
Thomas Witkowski committed
407
    /// Clears \ref macroElements
408
409
    inline void clearMacroElements() { 
      macroElements.clear();
410
    }
411
  
Thomas Witkowski's avatar
Thomas Witkowski committed
412
    /// Adds a macro element to the mesh
413
414
    void addMacroElement(MacroElement* me);

Thomas Witkowski's avatar
Thomas Witkowski committed
415
    /// Frees the array of DOF pointers (see \ref createDOFPtrs)
416
417
    void freeDOFPtrs(DegreeOfFreedom **ptrs);

Thomas Witkowski's avatar
Thomas Witkowski committed
418
    /// Used by \ref findElementAtPoint. 
419
420
421
    bool findElInfoAtPoint(const WorldVector<double>& xy,
			   ElInfo *el_info,
			   DimVec<double>& bary,
422
			   const MacroElement *start_mel,
423
424
			   const WorldVector<double> *xy0,
			   double *sp);
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460

    /** \brief
     * Access to an element at world coordinates xy. Some applications need the 
     * access to elements at a special location in world coordinates. Examples 
     * are characteristic methods for convection problems, or the implementation
     * of a special right hand side like point evaluations or curve integrals.
     * For such purposes, a routine is available which returns an element pointer
     * and corresponding barycentric coordinates.
     *
     * \param xy world coordinates of point
     * \param elp return address for a pointer to the element at xy
     * \param pary returns barycentric coordinates of xy
     * \param start_mel initial guess for the macro element containing xy or NULL
     * \param xy0 start point from a characteristic method, see below, or NULL
     * \param sp return address for relative distance to domain boundary in a 
     *        characteristic method, see below, or NULL
     * \return true is xy is inside the domain , false otherwise
     * 
     * For a characteristic method, where \f$ xy = xy_0 - V\tau \f$, it may be 
     * convenient to know the point on the domain's boundary which lies on the 
     * line segment between the old point xy0 and the new point xy, in case that 
     * xy is outside the domain. Such information is returned when xy0 and a 
     * pointer sp!=NULL are supplied: *sp is set to the value s such that 
     * \f$ xy_0 +s (xy -xy_0) \in \partial Domain \f$, and the element and local 
     * coordinates corresponding to that boundary point will be returned via elp 
     * and bary.
     *
     * The implementation of findElementAtPoint() is based on the transformation 
     * from world to local coordinates, available via the routine worldToCoord(),
     * At the moment, findElementAtPoint() works correctly only for domains with 
     * non-curved boundary. This is due to the fact that the implementation first
     * looks for the macro-element containing xy and then finds its path through 
     * the corresponding element tree based on the macro barycentric coordinates.
     * For non-convex domains, it is possible that in some cases a point inside
     * the domain is considered as external.
     */
461
462
463
    bool findElementAtPoint(const WorldVector<double>& xy,
			    Element **elp, 
			    DimVec<double>& bary,
464
			    const MacroElement *start_mel,
465
466
			    const WorldVector<double> *xy0,
			    double *sp);
467
468


Thomas Witkowski's avatar
Thomas Witkowski committed
469
    /// Returns FILL_ANY_?D
470
    inline static const Flag& getFillAnyFlag(int dim) {
471
      switch (dim) {
472
473
474
475
476
477
478
479
480
481
482
483
484
      case 1:
	return FILL_ANY_1D;
	break;
      case 2:
	return FILL_ANY_2D;
	break;
      case 3:
	return FILL_ANY_3D;
	break;
      default:
	ERROR_EXIT("invalid dim\n");
	return FILL_ANY_1D;
      }
485
    }
486

Thomas Witkowski's avatar
Thomas Witkowski committed
487
    /// Serialize the mesh to a file.
488
    void serialize(std::ostream &out);
489

Thomas Witkowski's avatar
Thomas Witkowski committed
490
    /// Deserialize a mesh from a file.
491
    void deserialize(std::istream &in);
492

Thomas Witkowski's avatar
Thomas Witkowski committed
493
    /// Returns \ref elementIndex and increments it by 1.
494
495
    inline int getNextElementIndex() { 
      return elementIndex++; 
496
    }
497

Thomas Witkowski's avatar
Thomas Witkowski committed
498
    /// Returns \ref initialized.
499
500
501
    inline bool isInitialized() {
      return initialized; 
    }
502
  
Thomas Witkowski's avatar
Thomas Witkowski committed
503
    ///
504
    inline std::map<BoundaryType, VertexVector*>& getPeriodicAssociations() {
505
      return periodicAssociations;
506
    }
507

Thomas Witkowski's avatar
Thomas Witkowski committed
508
    ///
509
510
    bool associated(DegreeOfFreedom dof1, DegreeOfFreedom dof2);

Thomas Witkowski's avatar
Thomas Witkowski committed
511
    ///
512
513
    bool indirectlyAssociated(DegreeOfFreedom dof1, DegreeOfFreedom dof2);

Thomas Witkowski's avatar
Thomas Witkowski committed
514
    /// Returns \macroFileInfo
515
    inline MacroInfo* getMacroFileInfo() { 
516
      return macroFileInfo;
517
    }
518

Thomas Witkowski's avatar
Thomas Witkowski committed
519
    ///
520
521
    void clearMacroFileInfo();

Thomas Witkowski's avatar
Thomas Witkowski committed
522
    ///
523
524
    int calcMemoryUsage();

525
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
526
    ///
527
528
    static const Flag FILL_NOTHING;

Thomas Witkowski's avatar
Thomas Witkowski committed
529
    ///
530
    static const Flag FILL_COORDS; 
531

Thomas Witkowski's avatar
Thomas Witkowski committed
532
    ///
533
    static const Flag FILL_BOUND; 
534

Thomas Witkowski's avatar
Thomas Witkowski committed
535
    ///
536
    static const Flag FILL_NEIGH; 
537

Thomas Witkowski's avatar
Thomas Witkowski committed
538
    ///
539
    static const Flag FILL_OPP_COORDS; 
540

Thomas Witkowski's avatar
Thomas Witkowski committed
541
    ///
542
543
    static const Flag FILL_ORIENTATION; 

Thomas Witkowski's avatar
Thomas Witkowski committed
544
    ///
545
    static const Flag FILL_ADD_ALL; 
546
  
Thomas Witkowski's avatar
Thomas Witkowski committed
547
    ///
548
    static const Flag FILL_ANY_1D; 
549

Thomas Witkowski's avatar
Thomas Witkowski committed
550
    ///
551
    static const Flag FILL_ANY_2D; 
552

Thomas Witkowski's avatar
Thomas Witkowski committed
553
    ///
554
    static const Flag FILL_ANY_3D; 
555

Thomas Witkowski's avatar
Thomas Witkowski committed
556
    ///
557
    static const Flag FILL_DET;
558

Thomas Witkowski's avatar
Thomas Witkowski committed
559
    ///
560
561
562
563
564
565
    static const Flag FILL_GRD_LAMBDA;

    //**************************************************************************
    //  flags for Mesh traversal                                                
    //**************************************************************************

Thomas Witkowski's avatar
Thomas Witkowski committed
566
    ///
567
568
    static const Flag CALL_EVERY_EL_PREORDER;      

Thomas Witkowski's avatar
Thomas Witkowski committed
569
    ///
570
571
    static const Flag CALL_EVERY_EL_INORDER;     

Thomas Witkowski's avatar
Thomas Witkowski committed
572
    ///
573
574
    static const Flag CALL_EVERY_EL_POSTORDER;    

Thomas Witkowski's avatar
Thomas Witkowski committed
575
    ///
576
577
    static const Flag CALL_LEAF_EL;   

Thomas Witkowski's avatar
Thomas Witkowski committed
578
    ///
579
580
    static const Flag CALL_LEAF_EL_LEVEL;  

Thomas Witkowski's avatar
Thomas Witkowski committed
581
    ///
582
583
    static const Flag CALL_EL_LEVEL; 

Thomas Witkowski's avatar
Thomas Witkowski committed
584
    ///
585
586
587
    static const Flag CALL_MG_LEVEL;

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
588
    ///
589
    bool findElementAtPointRecursive(ElInfo *elinfo,
590
				     const DimVec<double>& lambda,
591
				     int outside,
592
593
594
				     ElInfo *final_el_info);

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
595
    /// maximal number of DOFs at one position
596
597
    static const int MAX_DOF;

Thomas Witkowski's avatar
Thomas Witkowski committed
598
    /// Name of this Mesh
599
    std::string name;
600

Thomas Witkowski's avatar
Thomas Witkowski committed
601
    /// Dimension of this Mesh. Doesn't have to be equal to dimension of world.
602
603
    int dim;

Thomas Witkowski's avatar
Thomas Witkowski committed
604
    /// Number of vertices in this Mesh
605
606
    int nVertices;

Thomas Witkowski's avatar
Thomas Witkowski committed
607
    /// Number of Edges in this Mesh
608
609
    int nEdges;

Thomas Witkowski's avatar
Thomas Witkowski committed
610
    /// Number of leaf elements in this Mesh
611
612
    int nLeaves;

Thomas Witkowski's avatar
Thomas Witkowski committed
613
    /// Total number of elements in this Mesh
614
615
    int nElements;

Thomas Witkowski's avatar
Thomas Witkowski committed
616
    /// Number of faces in this Mesh
617
618
619
620
621
622
623
624
625
    int nFaces;

    /** \brief
     * Maximal number of elements that share one edge; used to allocate memory 
     * to store pointers to the neighbour at the refinement/coarsening edge 
     * (only 3d);
     */
    int maxEdgeNeigh;

Thomas Witkowski's avatar
Thomas Witkowski committed
626
    /// Diameter of the mesh in the DIM_OF_WORLD directions
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
    WorldVector<double> diam;

    /** \brief
     * Is pointer to NULL if mesh contains no parametric elements else pointer 
     * to a Parametric object containing coefficients of the parameterization 
     * and related information
     */
    Parametric *parametric;

    /** \brief
     * If the value is non zero then preserve all DOFs on all levels (can
     * be used for multigrid, e.g.); otherwise all DOFs on the parent that are 
     * not handed over to a child are removed during refinement and added again 
     * on the parent during coarsening.
     */
    bool preserveCoarseDOFs;

Thomas Witkowski's avatar
Thomas Witkowski committed
644
    /// Number of all DOFs on a single element
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
    int nDOFEl;

    /** \brief
     * Number of DOFs at the different positions VERTEX, EDGE, (FACE,) CENTER on
     * an element:
     *
     * - nDOF[VERTEX]: number of DOFs at a vertex (>= 1)
     *
     * - nDOF[EDGE]: number of DOFs at an edge; if no DOFs are associated to
     *   edges, then this value is 0
     *
     * - nDOF[FACE]: number of DOFs at a face; if no DOFs are associated to
     *   faces, then this value is 0 (only 3d)
     *
     * - nDOF[CENTER]: number of DOFs at the barycenter; if no DOFs are 
     *   associated to the barycenter, then this value is 0
     */
    DimVec<int> nDOF;

    /** \brief
     * Number of nodes on a single element where DOFs are located; needed for 
     * the (de-) allocation of the dof-vector on the element (\ref Element::dof);
     */
    int nNodeEl;

    /** \brief
     * Gives the index of the first node at vertex, edge, face (only 3d), and 
     * barycenter:
     *
     * - node[VERTEX]: has always value 0; dof[0],...,dof[N_VERTICES-1] are 
     *   always DOFs at the vertices;
     *
     * - node[EDGE]: dof[node[EDGE]],..., dof[node[EDGE]+N_EDGES-1] are the DOFs
     *   at the N_EDGES edges, if DOFs are located at edges;
     *
     * - node[FACE]: dof[node[FACE]],..., dof[node[FACE]+N_FACES-1] are the DOFs
     *   at the N_FACES faces, if DOFs are located at faces (only 3d);
     *
     * - node[CENTER]: dof[node[CENTER]] are the DOFs at the barycenter, if DOFs
     *   are located at the barycenter;
     */
    DimVec<int> node;

Thomas Witkowski's avatar
Thomas Witkowski committed
688
    /// List of all DOFAdmins
689
    std::vector<DOFAdmin*> admin;
690

Thomas Witkowski's avatar
Thomas Witkowski committed
691
    /// List of all MacroElements of this Mesh
692
    std::deque<MacroElement*> macroElements;
693

Thomas Witkowski's avatar
Thomas Witkowski committed
694
    /// Needed during DOF compression (\ref DOFAdmin::compress).
695
    std::vector<DegreeOfFreedom> newDOF;
696

Thomas Witkowski's avatar
Thomas Witkowski committed
697
    /// Needed during DOF compression (\ref DOFAdmin::compress).
698
699
700
701
702
703
704
705
706
    static DOFAdmin *compressAdmin;

    /** \brief
     * Used for recursive mesh traversal. Static pointer to the mesh
     * that should be traversed. This allows access to the mesh even
     * from the static traverse routines
     */
    static Mesh* traversePtr;

Thomas Witkowski's avatar
Thomas Witkowski committed
707
    /// Used by compress- and check functions. Number of the current DOFAdmin
708
709
    static int iadmin;

Thomas Witkowski's avatar
Thomas Witkowski committed
710
    /// Used by check functions
711
    static std::vector<DegreeOfFreedom> dof_used;
712

Thomas Witkowski's avatar
Thomas Witkowski committed
713
    ///
714
    static std::map<DegreeOfFreedom, DegreeOfFreedom*> serializedDOFs;
715
716
717
718
719
720
721
722
723

    /** \brief
     * Used while mesh refinement. To create new elements 
     * elementPrototype->clone() is called, which returns a Element of the
     * same type as elementPrototype. So e.g. Elements of the different
     * dimensions can be created in a uniform way. 
     */
    Element* elementPrototype;

Thomas Witkowski's avatar
Thomas Witkowski committed
724
    /// Prototype for leaf data. Used for creation of new leaf data while refinement.
725
726
    ElementData* elementDataPrototype;

Thomas Witkowski's avatar
Thomas Witkowski committed
727
    /// Used for enumeration of all mesh elements
728
729
    int elementIndex;

Thomas Witkowski's avatar
Thomas Witkowski committed
730
    /// True if the mesh is already initialized, false otherwise.
731
732
    bool initialized;

Thomas Witkowski's avatar
Thomas Witkowski committed
733
    /// Map of managed periodic vertex associations.
734
    std::map<BoundaryType, VertexVector*> periodicAssociations;
735
736
737
738
739

    /** \brief
     * If the mesh has been created by reading a macro file, here 
     * the information are stored about the content of the file.
     */
740
    MacroInfo *macroFileInfo;
741
742

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
743
    /// for findElement-Fcts
744
    DimVec<double> final_lambda;
745
746

    /** \brief
747
748
     * Temporary variables that are used in functions \ref fineElInfoatPoint and
     * \ref fineElementAtPointRecursive.
749
     */
750
    const WorldVector<double> *g_xy0, *g_xy;
751
752

    /** \brief
753
754
     * Temporary variable that is used in functions \ref fineElInfoatPoint and
     * \ref fineElementAtPointRecursive.
755
756
     */    
    double *g_sp;
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
   
    friend class MacroInfo;
    friend class MacroReader;
    friend class MacroWriter;
    friend class MacroElement;
    friend class Element;
    friend void Element::newDOFFct1(const DOFAdmin*);
    friend void Element::newDOFFct2(const DOFAdmin*);
  };

}

#endif  // AMDIS_MESH_H