Mesh.h 25.8 KB
Newer Older
1
2
3
4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6
7
// ==                                                                        ==
// ============================================================================
8
9
10
11
12
13
14
15
16
17
18
19
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// 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 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

Thomas Witkowski's avatar
Thomas Witkowski committed
37
38
39
40
#include <deque>
#include <set>
#include <stdio.h>
#include "AMDiS_fwd.h"
41
42
43
44
45
46
47
48
49
50
51
52
#include "DOFAdmin.h"
#include "Line.h"
#include "Triangle.h"
#include "Tetrahedron.h"
#include "Element.h"
#include "ElInfo.h"
#include "FixVec.h"
#include "Serializable.h"
#include "BoundaryCondition.h"

namespace AMDiS {

53
54
55
  using namespace std;


56
57
58
59
60
61
62
  /** \ingroup Triangulation 
   * \brief
   * A Mesh holds all information about a triangulation. 
   */
  class Mesh : public Serializable
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
63
    /// Creates a mesh with the given name of dimension dim
64
    Mesh(string name, int dim);
65

Thomas Witkowski's avatar
Thomas Witkowski committed
66
    /// Destructor
67
68
    virtual ~Mesh();

Thomas Witkowski's avatar
Thomas Witkowski committed
69
    /// Reads macro triangulation.
70
71
    void initialize();

Thomas Witkowski's avatar
Thomas Witkowski committed
72
    /// Assignment operator
73
74
75
76
77
78
79
80
    Mesh& operator=(const Mesh&);

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

    /** \brief
     * Returns geometric information about this mesh. With GeoIndex p it is 
Backofen, Rainer's avatar
Backofen, Rainer committed
81
     * specified which information is requested.
82
     */
83
84
    inline int getGeo(GeoIndex p) const 
    { 
85
      return Global::getGeo(p, dim); 
86
    }
87

Thomas Witkowski's avatar
Thomas Witkowski committed
88
    /// Returns \ref name of the mesh
89
    inline string getName() const 
90
    { 
91
      return name; 
92
    }
93

Thomas Witkowski's avatar
Thomas Witkowski committed
94
    /// Returns \ref dim of the mesh
95
    inline int getDim() const
96
    { 
97
      return dim; 
98
    }
99

100
101
    /// Returns \ref nDofEl of the mesh
    inline const int getNumberOfAllDofs() const 
102
    { 
103
      return nDofEl; 
104
    }
105

Thomas Witkowski's avatar
Thomas Witkowski committed
106
    /// Returns \ref nNodeEl of the mesh
107
108
    inline const int getNumberOfNodes() const 
    { 
109
      return nNodeEl; 
110
    }
111

Thomas Witkowski's avatar
Thomas Witkowski committed
112
    /// Returns \ref nVertices of the mesh
113
114
    inline const int getNumberOfVertices() const 
    { 
115
      return nVertices; 
116
    }
117

Thomas Witkowski's avatar
Thomas Witkowski committed
118
    /// Returns \ref nEdges of the mesh 
119
120
    inline const int getNumberOfEdges() const 
    { 
121
      return nEdges; 
122
    }
123

Thomas Witkowski's avatar
Thomas Witkowski committed
124
    /// Returns \ref nFaces of the mesh 
125
126
    inline const int getNumberOfFaces() const 
    { 
127
      return nFaces; 
128
    }
129

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
142
    /// Returns \ref maxEdgeNeigh of the mesh
143
144
    inline const int getMaxEdgeNeigh() const 
    { 
145
      return maxEdgeNeigh; 
146
    }
147

Thomas Witkowski's avatar
Thomas Witkowski committed
148
    /// Returns \ref parametric of the mesh
149
150
    inline Parametric *getParametric() const 
    { 
151
      return parametric; 
152
    }
153

Thomas Witkowski's avatar
Thomas Witkowski committed
154
    /// Returns \ref diam of the mesh
155
156
    inline const WorldVector<double>& getDiameter() const 
    { 
157
      return diam; 
158
    }
159

160
161
    /// Returns nDof[i] of the mesh
    inline const int getNumberOfDofs(int i) const 
162
    { 
163
      return nDof[i]; 
164
    }
165

Thomas Witkowski's avatar
Thomas Witkowski committed
166
    /// Returns \ref elementPrototype of the mesh
167
168
    inline Element* getElementPrototype() 
    { 
169
      return elementPrototype; 
170
    }
171

Thomas Witkowski's avatar
Thomas Witkowski committed
172
    /// Returns \ref leafDataPrototype of the mesh
173
174
    inline ElementData* getElementDataPrototype() 
    { 
175
      return elementDataPrototype; 
176
    }
177

Thomas Witkowski's avatar
Thomas Witkowski committed
178
    /// Returns node[i] of the mesh 
179
180
    inline int getNode(int i) const 
    { 
181
      return node[i]; 
182
    }
183
184
185
186
187
188
189

    /** \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. 
     */
190
    DegreeOfFreedom *getDof(GeoIndex position);
191

Thomas Witkowski's avatar
Thomas Witkowski committed
192
    /// Returns *(\ref admin[i]) of the mesh
193
    inline const DOFAdmin& getDofAdmin(int i) const 
194
    {
195
      return *(admin[i]);
196
    }
197
198

    /** \brief
199
     * Creates a DOFAdmin with name lname. nDof specifies how many DOFs 
200
201
202
     * are needed at the different positions (see \ref DOFAdmin::nrDOF).
     * A pointer to the created DOFAdmin is returned.
     */
203
    const DOFAdmin* createDOFAdmin(string lname, DimVec<int> nDof);
204
205
206
207
208

    /** \brief
     * Returns the size of \ref admin which is the number of the DOFAdmins
     * belonging to this mesh
     */
209
210
    const int getNumberOfDOFAdmin() const 
    {
211
      return admin.size();
212
    }
213
214
215
216
217

    /** \brief
     * Returns the size of \ref macroElements which is the number of
     * of macro elements of this mesh
     */
218
219
    const int getNumberOfMacros() const 
    {
220
      return macroElements.size();
221
    }
222

Thomas Witkowski's avatar
Thomas Witkowski committed
223
    /// Returns a DOFAdmin which at least manages vertex DOFs
224
225
    const DOFAdmin* getVertexAdmin() const;

Thomas Witkowski's avatar
Thomas Witkowski committed
226
    /// Allocates a array of DOF pointers. The array holds one pointer for each node.
Thomas Witkowski's avatar
Thomas Witkowski committed
227
    DegreeOfFreedom **createDofPtrs();
228

Thomas Witkowski's avatar
Thomas Witkowski committed
229
    /// Returns \ref preserveCoarseDOFs of the mesh
230
231
    inline bool queryCoarseDOFs() const 
    { 
232
      return preserveCoarseDOFs;
233
    }
234

Thomas Witkowski's avatar
Thomas Witkowski committed
235
    /// Returns an iterator to the begin of \ref macroElements
236
    inline deque<MacroElement*>::iterator firstMacroElement() 
237
    {
238
      return macroElements.begin();
239
    }
240

Thomas Witkowski's avatar
Thomas Witkowski committed
241
    /// Returns macroElements[i].
242
243
    inline MacroElement *getMacroElement(int i) 
    { 
244
      return macroElements[i]; 
245
    }
246

Thomas Witkowski's avatar
Thomas Witkowski committed
247
    /// Returns an iterator to the end of \ref macroElements
248
    inline deque<MacroElement*>::iterator endOfMacroElements() 
249
    {
250
      return macroElements.end();
251
    }
252

253
    /// Returns \ref macroElements, the list of all macro elements in the mesh.
254
    deque<MacroElement*>& getMacroElements()
255
256
257
258
    {
      return macroElements;
    }

259
260
261
262
263
264
    /** \} */

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

Thomas Witkowski's avatar
Thomas Witkowski committed
265
    /// Sets \ref name of the mesh
266
    inline void setName(string aName) 
267
    { 
268
      name = aName;
269
    }
270

Thomas Witkowski's avatar
Thomas Witkowski committed
271
    /// Sets \ref nVertices of the mesh
272
273
    inline void setNumberOfVertices(int n) 
    { 
274
      nVertices = n; 
275
    }
276

Thomas Witkowski's avatar
Thomas Witkowski committed
277
    /// Sets \ref nFaces of the mesh
278
279
    inline void setNumberOfFaces(int n) 
    { 
280
      nFaces = n; 
281
    }
282

Thomas Witkowski's avatar
Thomas Witkowski committed
283
    /// Increments \ref nVertices by inc
284
285
    inline void incrementNumberOfVertices(int inc) 
    { 
286
      nVertices += inc; 
287
    }
288
 
Thomas Witkowski's avatar
Thomas Witkowski committed
289
    /// Sets \ref nEdges of the mesh
290
291
    inline void setNumberOfEdges(int n) 
    { 
292
      nEdges = n; 
293
    }
294

Thomas Witkowski's avatar
Thomas Witkowski committed
295
    /// Increments \ref nEdges by inc
296
297
    inline void incrementNumberOfEdges(int inc) 
    { 
298
      nEdges += inc; 
299
    }
300

Thomas Witkowski's avatar
Thomas Witkowski committed
301
    /// Increments \ref nFaces by inc
302
303
    inline void incrementNumberOfFaces(int inc) 
    { 
304
      nFaces += inc; 
305
    }
306

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

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

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

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

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

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
349
    /// Sets \ref preserveCoarseDOFs = false
350
351
    inline void noCoarseDOFs() 
    {
352
      preserveCoarseDOFs = false;
353
    }
354

Thomas Witkowski's avatar
Thomas Witkowski committed
355
    /// Sets \ref elementPrototype of the mesh
356
357
    inline void setElementPrototype(Element* prototype) 
    {
358
      elementPrototype = prototype;
359
360
    }
    
Thomas Witkowski's avatar
Thomas Witkowski committed
361
    /// Sets \ref elementDataPrototype of the mesh
362
363
    inline void setElementDataPrototype(ElementData* prototype) 
    {
364
      elementDataPrototype = prototype;
365
    }
366

Thomas Witkowski's avatar
Thomas Witkowski committed
367
    ///
368
369
    inline void setParametric(Parametric *param) 
    {
370
      parametric = param;
371
    }
372

Thomas Witkowski's avatar
Thomas Witkowski committed
373
    ///
374
375
    inline void setMaxEdgeNeigh(int m) 
    { 
376
      maxEdgeNeigh = m; 
377
    }
378
379
380
  
    /** \} */

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

Thomas Witkowski's avatar
Thomas Witkowski committed
384
    /// Creates a new ElInfo dependent of \ref dim of the mesh
385
386
    ElInfo* createNewElInfo();

Thomas Witkowski's avatar
Thomas Witkowski committed
387
    /// Frees DOFs at the given position pointed by dof 
388
    void freeDof(DegreeOfFreedom* dof, GeoIndex position);
389

Thomas Witkowski's avatar
Thomas Witkowski committed
390
    /// Frees memory for the given element el
391
392
    void freeElement(Element* el);

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

Thomas Witkowski's avatar
Thomas Witkowski committed
396
    /// Adds a DOFAdmin to the mesh
397
    virtual void addDOFAdmin(DOFAdmin *admin);
398

399
400
401
    /// Recalculates the number of leave elements.
    void updateNumberOfLeaves();

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

411
    /* \brief
412
413
414
     * Removes a set of macro elements from the mesh. This works only for the case, 
     * that there are no global or local refinements, i.e., all macro elements have 
     * no children.
415
     */
416
    void removeMacroElements(std::set<MacroElement*>& macros,
Thomas Witkowski's avatar
Thomas Witkowski committed
417
			     const FiniteElemSpace* feSpace);
418

Thomas Witkowski's avatar
Thomas Witkowski committed
419
    /// Frees the array of DOF pointers (see \ref createDofPtrs)
420
    void freeDofPtrs(DegreeOfFreedom **ptrs);
421

Thomas Witkowski's avatar
Thomas Witkowski committed
422
    /// Used by \ref findElementAtPoint. 
423
424
425
    bool findElInfoAtPoint(const WorldVector<double>& xy,
			   ElInfo *el_info,
			   DimVec<double>& bary,
426
			   const MacroElement *start_mel,
427
428
			   const WorldVector<double> *xy0,
			   double *sp);
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
461
462
463
464

    /** \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.
     */
465
466
467
    bool findElementAtPoint(const WorldVector<double>& xy,
			    Element **elp, 
			    DimVec<double>& bary,
468
			    const MacroElement *start_mel,
469
470
			    const WorldVector<double> *xy0,
			    double *sp);
471

472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
    /** \brief
     * Returns for a given dof its world coordinates in this mesh. Because we do
     * not have any direct connection between dofs and coordinates, this function
     * has to search for the element in this mesh, that contains the dof. Than the
     * coordinates can be computed. Therefore, this function is very costly and
     * should be used for debugging purpose only.
     *
     * @param[in]    dof       A pointer to the dof we have to search for.
     * @param[in]    feSpace   The fe space to be used for the search.
     * @param[out]   coords    World vector that stores the coordinates of the dof.
     *
     * The function returns true, if the dof was found, otherwise false.
     */
    bool getDofIndexCoords(const DegreeOfFreedom* dof, 
			   const FiniteElemSpace* feSpace,
487
488
489
490
			   WorldVector<double>& coords)
    {
      return getDofIndexCoords(*dof, feSpace, coords);
    }
491

492
493
494
495
496

    /** \brief
     * This function is equal to \ref getDofIndexCoords as defined above, but takes
     * a DOF index instead of a DOF pointer.
     */
497
498
499
    bool getDofIndexCoords(DegreeOfFreedom dof, 
			   const FiniteElemSpace* feSpace,
			   WorldVector<double>& coords);
500

501
    /** \brief
502
503
504
     * Traverse the whole mesh and stores to each DOF of the given finite
     * element space the coordinates in a given DOFVector. Works in the same
     * way as the function \ref getDofIndexCoords defined above.
505
     *
506
507
     * @param[in]   feSpace   The FE space to be used for the search.
     * @param[out]  coords    DOF vector that stores the coordinates to each DOF.
508
509
510
511
     */
    void getDofIndexCoords(const FiniteElemSpace* feSpace,
			   DOFVector<WorldVector<double> >& coords);

512
513
514
515
516
517
518
519
520
    /** \brief
     * Traverse the mesh and get all DOFs in this mesh for a given FE space.
     *
     * @param[in]   feSpace   The FE space to be used for collecting DOFs.
     * @param[out]  allDofs   The set which is filled with all DOFs.
     */
    void getAllDofs(FiniteElemSpace *feSpace, 
		    std::set<const DegreeOfFreedom*>& allDofs);

Thomas Witkowski's avatar
Thomas Witkowski committed
521
    /// Returns FILL_ANY_?D
522
523
    inline static const Flag& getFillAnyFlag(int dim) 
    {
524
      switch (dim) {
525
526
527
528
529
530
531
532
533
534
535
536
537
      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;
      }
538
    }
539

Thomas Witkowski's avatar
Thomas Witkowski committed
540
    /// Serialize the mesh to a file.
541
    void serialize(ostream &out);
542

Thomas Witkowski's avatar
Thomas Witkowski committed
543
    /// Deserialize a mesh from a file.
544
    void deserialize(istream &in);
545

Thomas Witkowski's avatar
Thomas Witkowski committed
546
    /// Returns \ref elementIndex and increments it by 1.
547
548
    inline int getNextElementIndex() 
    { 
549
      return elementIndex++; 
550
    }
551

Thomas Witkowski's avatar
Thomas Witkowski committed
552
    /// Returns \ref initialized.
553
554
    inline bool isInitialized() 
    {
555
556
      return initialized; 
    }
557
  
Thomas Witkowski's avatar
Thomas Witkowski committed
558
    ///
559
    inline map<BoundaryType, VertexVector*>& getPeriodicAssociations() 
560
    {
561
      return periodicAssociations;
562
    }
563

564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
    /// Returns the periodic association for a specific boundary type.
    inline VertexVector& getPeriodicAssociations(BoundaryType b)
    {
      FUNCNAME("Mesh::getPeriodicAssociations()");

      TEST_EXIT_DBG(periodicAssociations.count(b) == 1)
	("There are no periodic assoications for boundary type %d!\n", b);

      return (*(periodicAssociations[b]));
    }

    
    /// Returns whether the given boundary type is periodic, i.e., if there is
    /// a periodic association for this boundary type.
    inline bool isPeriodicAssociation(BoundaryType b)
    {
      return (periodicAssociations.count(b) == 1 ? true : false);
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
583
    ///
584
585
    bool associated(DegreeOfFreedom dof1, DegreeOfFreedom dof2);

Thomas Witkowski's avatar
Thomas Witkowski committed
586
    ///
587
588
    bool indirectlyAssociated(DegreeOfFreedom dof1, DegreeOfFreedom dof2);

Thomas Witkowski's avatar
Thomas Witkowski committed
589
    /// Returns \macroFileInfo
590
591
    inline MacroInfo* getMacroFileInfo() 
    { 
592
      return macroFileInfo;
593
    }
594

595
596
597
598
599
600
601
602
603
604
605
606
    /// Increment the value of mesh change index, see \ref changeIndex.
    inline void incChangeIndex()
    {
      changeIndex++;
    }

    /// Returns the mesh change index, see \ref changeIndex.
    inline long getChangeIndex()
    {
      return changeIndex;
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
607
    ///
608
609
    void clearMacroFileInfo();

Thomas Witkowski's avatar
Thomas Witkowski committed
610
    ///
611
612
    int calcMemoryUsage();

613
614
615
    ///
    void deleteMeshStructure();

616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    /// In parallel computations the level of all macro elements is equal to the number
    /// of global pre refinements, \ref nParallelPreRefinements.
    inline int getMacroElementLevel()
    {
      return nParallelPreRefinements;
    }
#else
    /// In sequentiel computations the level of all macro elements is always 0.
    inline int getMacroElementLevel()
    {
      return 0;
    }
#endif

631
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
632
    ///
633
634
    static const Flag FILL_NOTHING;

Thomas Witkowski's avatar
Thomas Witkowski committed
635
    ///
636
    static const Flag FILL_COORDS; 
637

Thomas Witkowski's avatar
Thomas Witkowski committed
638
    ///
639
    static const Flag FILL_BOUND; 
640

Thomas Witkowski's avatar
Thomas Witkowski committed
641
    ///
642
    static const Flag FILL_NEIGH; 
643

Thomas Witkowski's avatar
Thomas Witkowski committed
644
    ///
645
    static const Flag FILL_OPP_COORDS; 
646

Thomas Witkowski's avatar
Thomas Witkowski committed
647
    ///
648
649
    static const Flag FILL_ORIENTATION; 

Thomas Witkowski's avatar
Thomas Witkowski committed
650
    ///
651
    static const Flag FILL_ADD_ALL; 
652
  
Thomas Witkowski's avatar
Thomas Witkowski committed
653
    ///
654
    static const Flag FILL_ANY_1D; 
655

Thomas Witkowski's avatar
Thomas Witkowski committed
656
    ///
657
    static const Flag FILL_ANY_2D; 
658

Thomas Witkowski's avatar
Thomas Witkowski committed
659
    ///
660
    static const Flag FILL_ANY_3D; 
661

Thomas Witkowski's avatar
Thomas Witkowski committed
662
    ///
663
    static const Flag FILL_DET;
664

Thomas Witkowski's avatar
Thomas Witkowski committed
665
    ///
666
667
668
669
670
671
    static const Flag FILL_GRD_LAMBDA;

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

Thomas Witkowski's avatar
Thomas Witkowski committed
672
    ///
673
    static const Flag CALL_EVERY_EL_PREORDER;
674

Thomas Witkowski's avatar
Thomas Witkowski committed
675
    ///
676
    static const Flag CALL_EVERY_EL_INORDER;
677

Thomas Witkowski's avatar
Thomas Witkowski committed
678
    ///
679
    static const Flag CALL_EVERY_EL_POSTORDER;
680

Thomas Witkowski's avatar
Thomas Witkowski committed
681
    ///
682
    static const Flag CALL_LEAF_EL;
683

Thomas Witkowski's avatar
Thomas Witkowski committed
684
    ///
685
    static const Flag CALL_LEAF_EL_LEVEL;
686

Thomas Witkowski's avatar
Thomas Witkowski committed
687
    ///
688
    static const Flag CALL_EL_LEVEL;
689

Thomas Witkowski's avatar
Thomas Witkowski committed
690
    ///
691
692
    static const Flag CALL_MG_LEVEL;

693
694
695
    /// If set, left and right children are swapped in traverse.
    static const Flag CALL_REVERSE_MODE;

696
  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
697
    ///
698
    bool findElementAtPointRecursive(ElInfo *elinfo,
699
				     const DimVec<double>& lambda,
700
				     int outside,
701
702
				     ElInfo *final_el_info);

703
704
705
706
707
708
709
710
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    /** \brief
     * This functions is called in parallel computations by the function \ref
     * Mesh::initialize(). It checks that the macro file has enough macro elements
     * for the number of used processors and that all macro elements are of type 0.
     * If this is not the case, that macro mesh is globally refined in an
     * apropriate way and is written to a new macro file.
     *
711
712
     * The function overwrittes the macro and periodic filenames, if a new macro
     * fule was created for the current parallel usage.
713
     *
714
715
716
717
718
719
720
     * \param[in/out]  macroFilename      Name of the macro mesh file.
     * \param[in/out]  periodicFilename   If periodic boundaries are used, name of the
     *                                    periodicity file. Otherwise, the string must
     *                                    be empty.
     * \param[in]      check              If the mesh should be checked to be a correct
     *                                    AMDiS macro mesh, the value must be 1 and 0
     *                                    otherwise.
721
     */
722
723
    void checkParallelMacroFile(string &macroFilename, 
				string &periodicFilename,
724
725
726
				int check);
#endif

727
  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
728
    /// maximal number of DOFs at one position
729
730
    static const int MAX_DOF;

Thomas Witkowski's avatar
Thomas Witkowski committed
731
    /// Name of this Mesh
732
    string name;
733

Thomas Witkowski's avatar
Thomas Witkowski committed
734
    /// Dimension of this Mesh. Doesn't have to be equal to dimension of world.
735
736
    int dim;

Thomas Witkowski's avatar
Thomas Witkowski committed
737
    /// Number of vertices in this Mesh
738
739
    int nVertices;

Thomas Witkowski's avatar
Thomas Witkowski committed
740
    /// Number of Edges in this Mesh
741
742
    int nEdges;

Thomas Witkowski's avatar
Thomas Witkowski committed
743
    /// Number of leaf elements in this Mesh
744
745
    int nLeaves;

Thomas Witkowski's avatar
Thomas Witkowski committed
746
    /// Total number of elements in this Mesh
747
748
    int nElements;

Thomas Witkowski's avatar
Thomas Witkowski committed
749
    /// Number of faces in this Mesh
750
751
752
753
754
755
756
757
758
    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
759
    /// Diameter of the mesh in the DIM_OF_WORLD directions
760
761
762
763
764
765
766
767
768
769
    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
770
771
772
773
774
775
776
     * When an element is refined, not all dofs of the coarse element must be 
     * part of the new elements. An example are centered dofs when using higher
     * lagrange basis functions. The midpoint dof of the parents element is not
     * a dof of the both children elements. Therefore, the dof can be deleted. In
     * some situation, e.g., when using multigrid techniques, it can be necessary to
     * store this coarse dofs. Then this variable must be set to true. If false, the
     * not required coarse dofs will be deleted.
777
778
779
     */
    bool preserveCoarseDOFs;

Thomas Witkowski's avatar
Thomas Witkowski committed
780
    /// Number of all DOFs on a single element
781
    int nDofEl;
782
783
784
785
786

    /** \brief
     * Number of DOFs at the different positions VERTEX, EDGE, (FACE,) CENTER on
     * an element:
     *
787
     * - nDof[VERTEX]: number of DOFs at a vertex (>= 1)
788
     *
789
     * - nDof[EDGE]: number of DOFs at an edge; if no DOFs are associated to
790
791
     *   edges, then this value is 0
     *
792
     * - nDof[FACE]: number of DOFs at a face; if no DOFs are associated to
793
794
     *   faces, then this value is 0 (only 3d)
     *
795
     * - nDof[CENTER]: number of DOFs at the barycenter; if no DOFs are 
796
797
     *   associated to the barycenter, then this value is 0
     */
798
    DimVec<int> nDof;
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823

    /** \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
824
    /// List of all DOFAdmins
825
    vector<DOFAdmin*> admin;
826

Thomas Witkowski's avatar
Thomas Witkowski committed
827
    /// List of all MacroElements of this Mesh
828
    deque<MacroElement*> macroElements;
829

Thomas Witkowski's avatar
Thomas Witkowski committed
830
    /// Used by check functions
831
    static vector<DegreeOfFreedom> dof_used;
832

833
834
835
836
837
838
839
840
841
842
    /** \brief
     * This map is used for serialization and deserialization of mesh elements. 
     * During the serialization process, all elements are visited and their dof indices
     * are written to the file. If a dof index at a position, i.e. vertex, line or face,
     * was written to file, the combination of dof index and position is inserted to
     * this map. That ensures that the same dof at the same position, but being part of
     * another element, is not written twice to the file. 
     * When a state should be deserialized, the information can be used to construct
     * exactly the same dof structure.
     */
843
    static map<pair<DegreeOfFreedom, int>, DegreeOfFreedom*> serializedDOFs;
844
845
846
847
848
849
850
851
852

    /** \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
853
    /// Prototype for leaf data. Used for creation of new leaf data while refinement.
854
855
    ElementData* elementDataPrototype;

Thomas Witkowski's avatar
Thomas Witkowski committed
856
    /// Used for enumeration of all mesh elements
857
858
    int elementIndex;

Thomas Witkowski's avatar
Thomas Witkowski committed
859
    /// True if the mesh is already initialized, false otherwise.
860
861
    bool initialized;

Thomas Witkowski's avatar
Thomas Witkowski committed
862
    /// Map of managed periodic vertex associations.
863
    map<BoundaryType, VertexVector*> periodicAssociations;
864
865

    /** \brief
866
867
     * If the mesh has been created by reading a macro file, here the information are
     * are stored about the content of the file.
868
     */
869
    MacroInfo *macroFileInfo;
870

871
872
873
874
875
876
877
    /** \brief
     * This index is incremented every time the mesh is changed, e.g. by the refinement
     * or the coarsening manager. It can be used by other object if the mesh has been
     * changed by first copying this variable elsewhere and comparing its values.
     */
    long changeIndex;

878
879
880
881
882
883
884
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    /// In parallel computations the mesh may be globally prerefined to achieve a fine
    /// enought starting mesh for the given number of ranks. The value of the variable
    /// will be defined in function \ref checkParallelMacroFile.
    int nParallelPreRefinements;
#endif

885
  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
886
    /// for findElement-Fcts
887
    DimVec<double> final_lambda;
888
889

    /** \brief
890
891
     * Temporary variables that are used in functions \ref fineElInfoatPoint and
     * \ref fineElementAtPointRecursive.
892
     */
893
    const WorldVector<double> *g_xy0, *g_xy;
894
895

    /** \brief
896
897
     * Temporary variable that is used in functions \ref fineElInfoatPoint and
     * \ref fineElementAtPointRecursive.
898
899
     */    
    double *g_sp;
900
901
902
903
904
905
906
907
908
909
910
911
912
   
    friend class MacroInfo;
    friend class MacroReader;
    friend class MacroWriter;
    friend class MacroElement;
    friend class Element;
  };

}

#endif  // AMDIS_MESH_H