Liebe Gitlab-Nutzerin, lieber Gitlab-Nutzer,
es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Die Konten der externen Nutzer:innen sind über den Reiter "Standard" erreichbar.
Die Administratoren


Dear Gitlab user,
it is now possible to log in to our service using the ZIH login/LDAP. The accounts of external users can be accessed via the "Standard" tab.
The administrators

Mesh.h 26.5 KB
Newer Older
1 2 3 4 5 6 7
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
8
 * Authors:
9 10 11 12 13 14 15 16 17
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
18
 *
19
 ******************************************************************************/
20 21


22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

/** \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
39 40 41 42
#include <deque>
#include <set>
#include <stdio.h>
#include "AMDiS_fwd.h"
43 44 45 46 47 48 49 50 51 52 53 54
#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 {

55

56
  /** \ingroup Triangulation
57
   * \brief
58
   * A Mesh holds all information about a triangulation.
59 60 61 62
   */
  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(std::string name, int dim);
65

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

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
    Mesh& operator=(const Mesh&);

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

79
    /// Returns geometric information about this mesh. With GeoIndex p it is
Thomas Witkowski's avatar
Thomas Witkowski committed
80
    /// specified which information is requested.
81 82 83
    inline int getGeo(GeoIndex p) const
    {
      return Global::getGeo(p, dim);
84
    }
85

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

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

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

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

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

116 117 118 119
    /// Returns \ref nEdges of the mesh
    inline int getNumberOfEdges() const
    {
      return nEdges;
120
    }
121

122 123 124 125
    /// Returns \ref nFaces of the mesh
    inline int getNumberOfFaces() const
    {
      return nFaces;
126
    }
127

128 129 130 131
    /// Returns \ref nLeaves of the mesh
    inline int getNumberOfLeaves() const
    {
      return nLeaves;
132
    }
133

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

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

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

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

158
    /// Returns nDof[i] of the mesh
159 160
    inline int getNumberOfDofs(int i) const
    {
161
      TEST_EXIT_DBG(i <= dim)("Wrong index: %d %d\n", i, dim);
162
      return nDof[i];
163
    }
164

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

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

177 178 179 180
    /// Returns node[i] of the mesh
    inline int getNode(int i) const
    {
      return node[i];
181
    }
182

183 184
    /// 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
185 186
    /// DOFs of all DOFAdmin objects belonging to this mesh.
    /// The return value is a pointer to the first allocated DOF.
187
    DegreeOfFreedom *getDof(GeoIndex position);
188

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

195 196 197 198 199 200 201 202 203 204 205 206
    /// Returns the index of a given DOFMadmin pointer in the admin vector
    inline int getAdminIndex(const DOFAdmin* dofAdmin) const
    {
      size_t i = 0;
      for (; i < admin.size(); i++)
        if (admin[i] == dofAdmin)
          break;

      TEST_EXIT_DBG(i < admin.size())("Wrong DOF admin index: %d\n", i);
      return i;
    }

207
    /// Creates a DOFAdmin with name lname. nDof specifies how many DOFs
208 209
    /// are needed at the different positions (see \ref DOFAdmin::nrDOF).
    /// A pointer to the created DOFAdmin is returned.
210
    const DOFAdmin* createDOFAdmin(std::string lname, DimVec<int> nDof);
211

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
226
    /// Returns a DOFAdmin which at least manages vertex DOFs
227 228
    const DOFAdmin* getVertexAdmin() const;

229
    /// Allocates an array of DOF pointers. The array holds one pointer for
Thomas Witkowski's avatar
Thomas Witkowski committed
230
    /// each node.
Thomas Witkowski's avatar
Thomas Witkowski committed
231
    DegreeOfFreedom **createDofPtrs();
232

Thomas Witkowski's avatar
Thomas Witkowski committed
233
    /// Returns \ref preserveCoarseDOFs of the mesh
234 235
    inline bool queryCoarseDOFs() const
    {
236
      return preserveCoarseDOFs;
237
    }
238

Thomas Witkowski's avatar
Thomas Witkowski committed
239
    /// Returns an iterator to the begin of \ref macroElements
240
    inline std::deque<MacroElement*>::iterator firstMacroElement()
241
    {
242
      return macroElements.begin();
243
    }
244

Thomas Witkowski's avatar
Thomas Witkowski committed
245
    /// Returns macroElements[i].
246 247 248
    inline MacroElement *getMacroElement(int i)
    {
      return macroElements[i];
249
    }
250

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

257
    /// Returns \ref macroElements, the list of all macro elements in the mesh.
258
    std::deque<MacroElement*>& getMacroElements()
259 260 261 262
    {
      return macroElements;
    }

263 264 265 266 267 268
    /** \} */

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

Thomas Witkowski's avatar
Thomas Witkowski committed
269
    /// Sets \ref name of the mesh
270 271
    inline void setName(std::string aName)
    {
272
      name = aName;
273
    }
274

Thomas Witkowski's avatar
Thomas Witkowski committed
275
    /// Sets \ref nVertices of the mesh
276 277 278
    inline void setNumberOfVertices(int n)
    {
      nVertices = n;
279
    }
280

Thomas Witkowski's avatar
Thomas Witkowski committed
281
    /// Sets \ref nFaces of the mesh
282 283 284
    inline void setNumberOfFaces(int n)
    {
      nFaces = n;
285
    }
286

Thomas Witkowski's avatar
Thomas Witkowski committed
287
    /// Increments \ref nVertices by inc
288 289 290
    inline void incrementNumberOfVertices(int inc)
    {
      nVertices += inc;
291
    }
292

Thomas Witkowski's avatar
Thomas Witkowski committed
293
    /// Sets \ref nEdges of the mesh
294 295 296
    inline void setNumberOfEdges(int n)
    {
      nEdges = n;
297
    }
298

Thomas Witkowski's avatar
Thomas Witkowski committed
299
    /// Increments \ref nEdges by inc
300 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 308
    inline void incrementNumberOfFaces(int inc)
    {
      nFaces += inc;
309
    }
310

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
323
    /// Sets \ref nElements of the mesh
324 325 326
    inline void setNumberOfElements(int n)
    {
      nElements = n;
327
    }
328

Thomas Witkowski's avatar
Thomas Witkowski committed
329
    /// Increments \ref nElements by inc
330 331 332
    inline void incrementNumberOfElements(int inc)
    {
      nElements += inc;
333
    }
334

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
347
    /// Sets \ref preserveCoarseDOFs = b
348
    inline void setPreserveCoarseDOFs(bool b)
349
    {
350
      preserveCoarseDOFs = b;
351
    }
352

Thomas Witkowski's avatar
Thomas Witkowski committed
353
    /// Sets \ref preserveCoarseDOFs = false
354
    inline void noCoarseDOFs()
355
    {
356
      preserveCoarseDOFs = false;
357
    }
358

Thomas Witkowski's avatar
Thomas Witkowski committed
359
    /// Sets \ref elementPrototype of the mesh
360
    inline void setElementPrototype(Element* prototype)
361
    {
362
      elementPrototype = prototype;
363
    }
364

Thomas Witkowski's avatar
Thomas Witkowski committed
365
    /// Sets \ref elementDataPrototype of the mesh
366
    inline void setElementDataPrototype(ElementData* prototype)
367
    {
368
      elementDataPrototype = prototype;
369
    }
370

Thomas Witkowski's avatar
Thomas Witkowski committed
371
    ///
372
    inline void setParametric(Parametric *param)
373
    {
374
      parametric = param;
375
    }
376

Thomas Witkowski's avatar
Thomas Witkowski committed
377
    ///
378 379 380
    inline void setMaxEdgeNeigh(int m)
    {
      maxEdgeNeigh = m;
381
    }
382

383 384
    /** \} */

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

Thomas Witkowski's avatar
Thomas Witkowski committed
388
    /// Creates a new ElInfo dependent of \ref dim of the mesh
389 390
    ElInfo* createNewElInfo();

391
    /// Frees DOFs at the given position pointed by dof
392
    void freeDof(DegreeOfFreedom* dof, GeoIndex position);
393

Thomas Witkowski's avatar
Thomas Witkowski committed
394
    /// Frees memory for the given element el
395 396
    void freeElement(Element* el);

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

Thomas Witkowski's avatar
Thomas Witkowski committed
400
    /// Adds a DOFAdmin to the mesh
Thomas Witkowski's avatar
Thomas Witkowski committed
401
    void addDOFAdmin(DOFAdmin *admin);
402

403 404 405
    /// Recalculates the number of leave elements.
    void updateNumberOfLeaves();

Thomas Witkowski's avatar
Thomas Witkowski committed
406
    /// Clears \ref macroElements
407 408
    inline void clearMacroElements()
    {
409
      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);

415 416
    /// 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
417
    /// elements have no children.
418
    void removeMacroElements(std::set<MacroElement*>& macros,
419
			     std::vector<const FiniteElemSpace*>& feSpaces);
420

421
    void removeAllMacroElements();
422

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

426
    /// Used by \ref findElementAtPoint.
427 428 429
    bool findElInfoAtPoint(const WorldVector<double>& xy,
			   ElInfo *el_info,
			   DimVec<double>& bary,
430
			   const MacroElement *start_mel,
431 432
			   const WorldVector<double> *xy0,
			   double *sp);
433 434

    /** \brief
435 436
     * Access to an element at world coordinates xy. Some applications need the
     * access to elements at a special location in world coordinates. Examples
437 438 439 440 441 442 443 444
     * 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
445 446
     * \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
447
     * \param sp return address for relative distance to domain boundary in a
448
     *        characteristic method, see below, or NULL
449
     * \return true is xy is inside the domain , false otherwise
450 451 452 453 454 455 456 457
     *
     * 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
458 459
     * and bary.
     *
460
     * The implementation of findElementAtPoint() is based on the transformation
461
     * from world to local coordinates, available via the routine worldToCoord(),
462
     * At the moment, findElementAtPoint() works correctly only for domains with
463
     * non-curved boundary. This is due to the fact that the implementation first
464
     * looks for the macro-element containing xy and then finds its path through
465 466 467 468
     * 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.
     */
469
    bool findElementAtPoint(const WorldVector<double>& xy,
470
			    Element **elp,
471
			    DimVec<double>& bary,
472
			    const MacroElement *start_mel,
473 474
			    const WorldVector<double> *xy0,
			    double *sp);
475

476 477 478 479 480 481 482 483 484 485 486 487 488
    /** \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.
     */
489
    bool getDofIndexCoords(const DegreeOfFreedom* dof,
490
			   const FiniteElemSpace* feSpace,
491 492 493 494
			   WorldVector<double>& coords)
    {
      return getDofIndexCoords(*dof, feSpace, coords);
    }
495

496

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

503
    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
504
     * Traverse the whole mesh and stores to each DOF the coordinates in a given
505
     * DOFVector. Works in the same way as the function \ref getDofIndexCoords
Thomas Witkowski's avatar
Thomas Witkowski committed
506
     * defined above.
507
     *
508
     * @param[out]  coords    DOF vector that stores the coordinates to each DOF.
509
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
510
    void getDofIndexCoords(DOFVector<WorldVector<double> >& coords);
511 512 513 514
    void getDofCoords(DOFVector<WorldVector<double> >& coords)
    {
      getDofIndexCoords(coords);
    }
515

516

517 518 519 520 521 522
    /** \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.
     */
523
    void getAllDofs(const FiniteElemSpace *feSpace,
524 525
		    std::set<const DegreeOfFreedom*>& allDofs);

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
548
    /// Deserialize a mesh from a file.
549
    void deserialize(std::istream &in);
550

Thomas Witkowski's avatar
Thomas Witkowski committed
551
    /// Returns \ref elementIndex and increments it by 1.
552 553 554
    inline int getNextElementIndex()
    {
      return elementIndex++;
555
    }
556

Thomas Witkowski's avatar
Thomas Witkowski committed
557
    /// Returns \ref initialized.
558
    inline bool isInitialized()
559
    {
560
      return initialized;
561
    }
562

Thomas Witkowski's avatar
Thomas Witkowski committed
563
    ///
564
    inline std::map<BoundaryType, std::vector<VertexVector*> >& getPeriodicAssociations()
565
    {
566
      return periodicAssociations;
567
    }
568

569
    /// Returns the periodic association for a specific boundary type.
570
    VertexVector& getPeriodicAssociations(BoundaryType b, const DOFAdmin* admin = NULL);
571

572 573
    inline void setPeriodicAssociations(BoundaryType b, VertexVector* vec)
    {
574 575 576 577 578 579 580 581
      std::map<BoundaryType, std::vector<VertexVector*> >::iterator lb = periodicAssociations.lower_bound(b);
      if (lb != periodicAssociations.end() && !periodicAssociations.key_comp()(b, lb->first)) {
        lb->second.push_back(vec);
      } else {
        std::vector<VertexVector*> v;
        v.push_back(vec);
        periodicAssociations.insert(lb, std::make_pair(b, v));
      }
582
    }
583

584

585 586 587 588 589 590 591
    /// 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
592
    ///
593 594 595 596 597 598
    bool associated(DegreeOfFreedom dof1, DegreeOfFreedom dof2, int iadmin = 0);

    inline bool associated(DegreeOfFreedom dof1, DegreeOfFreedom dof2, const DOFAdmin* dofAdmin)
    {
      return associated(dof1, dof2, getAdminIndex(dofAdmin));
    }
599

Thomas Witkowski's avatar
Thomas Witkowski committed
600
    ///
601 602 603 604 605 606
    bool indirectlyAssociated(DegreeOfFreedom dof1, DegreeOfFreedom dof2, int iadmin = 0);

    inline bool indirectlyAssociated(DegreeOfFreedom dof1, DegreeOfFreedom dof2, const DOFAdmin* dofAdmin)
    {
      return indirectlyAssociated(dof1, dof2, getAdminIndex(dofAdmin));
    }
607

Thomas Witkowski's avatar
Thomas Witkowski committed
608
    /// Returns \macroFileInfo
609 610
    inline MacroInfo* getMacroFileInfo()
    {
611
      return macroFileInfo;
612
    }
613

614 615 616 617 618 619 620 621 622 623 624 625
    /// 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
626
    ///
627 628
    void clearMacroFileInfo();

Thomas Witkowski's avatar
Thomas Witkowski committed
629
    ///
630 631
    int calcMemoryUsage();

632 633 634
    ///
    void deleteMeshStructure();

635
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
636
    /// In parallel computations the level of all macro elements is equal to the
637
    /// number of global pre refinements, \ref nParallelPreRefinements.
638 639 640 641 642 643 644 645 646 647 648 649
    inline int getMacroElementLevel()
    {
      return nParallelPreRefinements;
    }
#else
    /// In sequentiel computations the level of all macro elements is always 0.
    inline int getMacroElementLevel()
    {
      return 0;
    }
#endif

650 651
    /// Creates a map for all elements in mesh that maps from element indices
    /// to the corresponding pointers.
652
    void getElementIndexMap(std::map<int, Element*> &elIndexMap);
653

654
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
655
    ///
656 657
    static const Flag FILL_NOTHING;

Thomas Witkowski's avatar
Thomas Witkowski committed
658
    ///
659
    static const Flag FILL_COORDS;
660

Thomas Witkowski's avatar
Thomas Witkowski committed
661
    ///
662
    static const Flag FILL_BOUND;
663

Thomas Witkowski's avatar
Thomas Witkowski committed
664
    ///
665
    static const Flag FILL_NEIGH;
666

Thomas Witkowski's avatar
Thomas Witkowski committed
667
    ///
668
    static const Flag FILL_OPP_COORDS;
669

Thomas Witkowski's avatar
Thomas Witkowski committed
670
    ///
671
    static const Flag FILL_ORIENTATION;
672

Thomas Witkowski's avatar
Thomas Witkowski committed
673
    ///
674 675
    static const Flag FILL_ADD_ALL;

Thomas Witkowski's avatar
Thomas Witkowski committed
676
    ///
677
    static const Flag FILL_ANY_1D;
678

Thomas Witkowski's avatar
Thomas Witkowski committed
679
    ///
680
    static const Flag FILL_ANY_2D;
681

Thomas Witkowski's avatar
Thomas Witkowski committed
682
    ///
683
    static const Flag FILL_ANY_3D;
684

Thomas Witkowski's avatar
Thomas Witkowski committed
685
    ///
686
    static const Flag FILL_DET;
687

Thomas Witkowski's avatar
Thomas Witkowski committed
688
    ///
689 690 691
    static const Flag FILL_GRD_LAMBDA;

    //**************************************************************************
692
    //  flags for Mesh traversal
693 694
    //**************************************************************************

Thomas Witkowski's avatar
Thomas Witkowski committed
695
    ///
696
    static const Flag CALL_EVERY_EL_PREORDER;
697

Thomas Witkowski's avatar
Thomas Witkowski committed
698
    ///
699
    static const Flag CALL_EVERY_EL_INORDER;
700

Thomas Witkowski's avatar
Thomas Witkowski committed
701
    ///
702
    static const Flag CALL_EVERY_EL_POSTORDER;
703

Thomas Witkowski's avatar
Thomas Witkowski committed
704
    ///
705
    static const Flag CALL_LEAF_EL;
706

Thomas Witkowski's avatar
Thomas Witkowski committed
707
    ///
708
    static const Flag CALL_LEAF_EL_LEVEL;
709

Thomas Witkowski's avatar
Thomas Witkowski committed
710
    ///
711
    static const Flag CALL_EL_LEVEL;
712

Thomas Witkowski's avatar
Thomas Witkowski committed
713
    ///
714 715
    static const Flag CALL_MG_LEVEL;

716 717 718
    /// If set, left and right children are swapped in traverse.
    static const Flag CALL_REVERSE_MODE;

719
  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
720
    ///
721
    bool findElementAtPointRecursive(ElInfo *elinfo,
722
				     const DimVec<double>& lambda,
723
				     int outside,
724 725
				     ElInfo *final_el_info);

726 727 728 729 730 731 732 733
#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.
     *
734 735
     * The function overwrittes the macro and periodic filenames, if a new macro
     * fule was created for the current parallel usage.
736
     *
737 738 739 740 741 742 743
     * \param[in/out]  macroFilename      Name of the macro mesh file.
     * \param[in/out]  periodicFilename   If periodic boundaries are used, na