MeshStructure.h 4.94 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
22
23
24
25
// ==                                                                        ==
// ============================================================================

/** \file MeshStructure.h */

#ifndef AMDIS_MESHSTRUCTURE_H
#define AMDIS_MESHSTRUCTURE_H

#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
48
    void init(Mesh *mesh);

49
    void init(Element *el, int ithSide, int elType, bool reverseOrder);
50

51
52
    void init(BoundaryObject &bound);

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

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

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

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

    bool skipBranch(MeshStructure *insert = NULL);

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

    bool nextElement(MeshStructure *insert = NULL);

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

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

100
101
102
    /** \brief
     * Fits a given mesh to the mesh structure code. 
     *
103
104
105
     * \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.
106
     */
107
108
    void fitMeshToStructure(Mesh *mesh,
			    RefinementManager *manager,
109
110
			    bool checkPartition = false,
			    bool debugMode = false);
111

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

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

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

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

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

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

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

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

163
    void addAlongSide(Element *el, int ithSide, int elType, bool reverseOrder);
164

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

170
  protected:
171
    std::vector<unsigned long int> code;
172

173
    int currentIndex;
174

175
    unsigned long int currentCode;
176

177
    int pos;
178

179
    int currentElement;
180

181
    int nElements;
182

183
184
    bool debugMode;

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

}

#endif