MeshStructure.h 5.17 KB
Newer Older
1
2
// ============================================================================
// ==                                                                        ==
3
// == Amdis - Adaptive multidimensional simulations                          ==
4
5
6
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
8
// ==                                                                        ==
9
10
11
// ==  Institut für Wissenschaftliches Rechnen                               ==
// ==  Zellescher Weg 12-14                                                  ==
// ==  01069 Dresden                                                         ==
12
13
14
15
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
16
// ==  https://gforge.zih.tu-dresden.de/projects/amdis/                      ==
17
18
19
20
21
// ==                                                                        ==
// ============================================================================

/** \file MeshStructure.h */

22
23
#ifndef AMDIS_MESH_STRUCTURE_H
#define AMDIS_MESH_STRUCTURE_H
24
25

#include <vector>
Thomas Witkowski's avatar
Thomas Witkowski committed
26
#include "AMDiS_fwd.h"
27
#include "Global.h"
28
#include "parallel/InteriorBoundary.h"
29

30
31
32
33
34
35
namespace AMDiS {

  class MeshStructure
  {
  public:
    MeshStructure()
36
37
38
39
      : currentIndex(0),
	currentCode(0),
	pos(0),
	currentElement(0),
40
41
	nElements(0),
	debugMode(false)
Thomas Witkowski's avatar
Thomas Witkowski committed
42
    {}
43
44
45
  
    void clear();

46
    /// Creates a mesh structure code from a mesh object by traversing it in preorder.
47
    void init(Mesh *mesh);
48
   
49
50
    void init(BoundaryObject &bound);

51
    void init(const std::vector<unsigned long int>& initCode, int n) 
52
    {
53
54
      code = initCode;
      nElements = n;
55
      reset();
Thomas Witkowski's avatar
Thomas Witkowski committed
56
    }
57

58
59
60
61
    /** \brief
     * Sets all position counters, that are used to traverse the code, to the starting
     * position. The code itself is not changed.
     */
62
63
    void reset();

64
65
66
67
68
69
    /// Returns whether the code is empty or not.
    inline bool empty()
    {
      return (nElements == 0);
    }

70
71
    inline void commit() 
    {
72
73
      if (pos > 0)
	code.push_back(currentCode);
74
      reset();
Thomas Witkowski's avatar
Thomas Witkowski committed
75
    }
76
77
78
79
80
81
82

    bool skipBranch(MeshStructure *insert = NULL);

    ElInfo *skipBranch(ElInfo *elInfo, TraverseStack *stack);

    bool nextElement(MeshStructure *insert = NULL);

83
84
    inline bool isLeafElement() 
    {
85
      return (currentCode & 1) == 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
86
    }
87

88
    /** \brief
89
90
     * Merges a mesh structure code with its own mesh structure code. The result
     * overwrites the own mesh structure code.
91
     */
92
    void merge(MeshStructure *struc) 
93
    {
94
      MeshStructure temp(*this);
95
      merge(&temp, struc, this);
Thomas Witkowski's avatar
Thomas Witkowski committed
96
    }
97

98
99
100
    /** \brief
     * Fits a given mesh to the mesh structure code. 
     *
101
102
103
104
105
106
107
108
     * \param debugMode     In debugMode, the whole mesh is fitted to the mesh structure
     *                      code. Otherwise, the mesh is fitted only on the partition
     *                      of the current process.
     * \param macroElIndex  If the mesh structure code represents only one macro 
     *                      element, this can be denoted here by its index. In this
     *                      case, only the corresponding macro element will be fitted
     *                      to the code. Otherwise, this variable is negative and the
     *                      whole mesh will be adapted.
109
     */
110
111
    void fitMeshToStructure(Mesh *mesh,
			    RefinementManager *manager,
112
			    bool debugMode = false,
Thomas Witkowski's avatar
Thomas Witkowski committed
113
114
			    int macroElIndex = -1,
			    bool ignoreFinerMesh = false);
115

116
    /// Prints the mesh structure code.
117
    void print(bool resetCode = true); 
118

119
120
121
    /// Returns the mesh structure code.
    inline const std::vector<unsigned long int>& getCode() 
    {
122
      return code;
Thomas Witkowski's avatar
Thomas Witkowski committed
123
    }
124

125
126
    inline int getNumElements() 
    { 
127
      return nElements; 
Thomas Witkowski's avatar
Thomas Witkowski committed
128
    }
129

130
131
    inline int getCurrentElement() 
    {
132
      return currentElement;
Thomas Witkowski's avatar
Thomas Witkowski committed
133
    }
134

135
136
137
138
139
140
141
142
    void setDebugMode(bool b)
    {
      debugMode = b;
    }

    /// Returns true, if the given mesh structure code is equal to this one.
    bool compare(MeshStructure &other);

143
  protected:
144
    /// Insert a new element to the structure code. Is used by the init function.
145
146
    void insertElement(bool isLeaf);

147
    void addAlongSide(Element *el, GeoIndex subObj, int ithObj, int elType, bool reverseOrder);
148

149
    /// Merges two mesh structure codes to one structure code.     
150
151
152
153
    void merge(MeshStructure *structure1,
	       MeshStructure *structure2,
	       MeshStructure *result);

154
  protected:
155
    /// Mesh structure code.
156
    std::vector<unsigned long int> code;
157

158
    int currentIndex;
159

160
    unsigned long int currentCode;
161

162
    int pos;
163

164
    int currentElement;
165

166
    int nElements;
167

168
    /// If true, some output is printed to screen during mesh structure code generation.
169
170
    bool debugMode;

171
    static const int unsignedLongSize;
172
173

    friend class ArhWriter;
174
175
176
177
178
  };

}

#endif