MeshStructure.h 5.01 KB
Newer Older
1
2
// ============================================================================
// ==                                                                        ==
3
// == Amdis - Adaptive multidimensional simulations                          ==
4
5
6
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
8
// ==                                                                        ==
9
10
11
// ==  Institut fr 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
     * \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.
104
     */
105
106
    void fitMeshToStructure(Mesh *mesh,
			    RefinementManager *manager,
107
108
			    bool checkPartition = false,
			    bool debugMode = false);
109

110
111
112
    /// Prints the mesh structure code.
    void print() 
    {
113
      FUNCNAME("MeshStructure::print()");
114

115
116
117
118
119
      if (empty()) {
	std::cout << "-" << std::endl;
	return;
      }	
	
120
121
      reset();
      bool cont = true;
122
      while (cont) {
123
	if (isLeafElement())
124
	  std::cout << "0";
125
	else
126
	  std::cout << "1";
127
	
128
129
	cont = nextElement();
      }
130
      std::cout << std::endl;
Thomas Witkowski's avatar
Thomas Witkowski committed
131
    }
132

133
134
135
    /// Returns the mesh structure code.
    inline const std::vector<unsigned long int>& getCode() 
    {
136
      return code;
Thomas Witkowski's avatar
Thomas Witkowski committed
137
    }
138

139
140
    inline int getNumElements() 
    { 
141
      return nElements; 
Thomas Witkowski's avatar
Thomas Witkowski committed
142
    }
143

144
145
    inline int getCurrentElement() 
    {
146
      return currentElement;
Thomas Witkowski's avatar
Thomas Witkowski committed
147
    }
148

149
150
151
152
153
154
155
156
    void setDebugMode(bool b)
    {
      debugMode = b;
    }

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

157
  protected:
158
    /// Insert a new element to the structure code. Is used by the init function.
159
160
    void insertElement(bool isLeaf);

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

163
    /// Merges two mesh structure codes to one structure code.     
164
165
166
167
    void merge(MeshStructure *structure1,
	       MeshStructure *structure2,
	       MeshStructure *result);

168
  protected:
169
    /// Mesh structure code.
170
    std::vector<unsigned long int> code;
171

172
    int currentIndex;
173

174
    unsigned long int currentCode;
175

176
    int pos;
177

178
    int currentElement;
179

180
    int nElements;
181

182
    /// If true, some output is printed to screen during mesh structure code generation.
183
184
    bool debugMode;

185
    static const int unsignedLongSize;
186
187
188
189
190
  };

}

#endif