MeshStructure.h 5.2 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 checkPartition = false,
113
			    bool debugMode = false,
Thomas Witkowski's avatar
Thomas Witkowski committed
114
115
			    int macroElIndex = -1,
			    bool ignoreFinerMesh = false);
116

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

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

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

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

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

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

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

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

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

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

159
    int currentIndex;
160

161
    unsigned long int currentCode;
162

163
    int pos;
164

165
    int currentElement;
166

167
    int nElements;
168

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

172
    static const int unsignedLongSize;
173
174

    friend class ArhWriter;
175
176
177
178
179
  };

}

#endif