MeshStructure.h 4.91 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
28
#include "Global.h"

29
30
31
32
33
34
namespace AMDiS {

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

45
    /// Creates a mesh structure code from a mesh object by traversing it in preorder.
46
47
    void init(Mesh *mesh);

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

50
51
    void init(BoundaryObject &bound);

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

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

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

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

    bool skipBranch(MeshStructure *insert = NULL);

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

    bool nextElement(MeshStructure *insert = NULL);

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

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

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

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

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

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

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

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

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

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

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

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

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

169
  protected:
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
183
    bool debugMode;

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

}

#endif