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 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
      std::stringstream oss;

117
      if (empty()) {
118
119
120
121
122
123
124
125
126
127
128
129
	oss << "-" << std::endl;
      }	else {	
	reset();
	bool cont = true;
	while (cont) {
	  if (isLeafElement())
	    oss << "0";
	  else
	    oss << "1";
	  
	  cont = nextElement();
	}
130
      }
131
132

      MSG("Mesh structure code: %s\n", oss.str().c_str());
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
160
    void writeMeshFile(Mesh *mesh, std::string filename);

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

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

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

172
173
    void writeMacroElement(std::ofstream& file, int macroElIndex);

174
  protected:
175
    /// Mesh structure code.
176
    std::vector<unsigned long int> code;
177

178
    int currentIndex;
179

180
    unsigned long int currentCode;
181

182
    int pos;
183

184
    int currentElement;
185

186
    int nElements;
187

188
    /// If true, some output is printed to screen during mesh structure code generation.
189
190
    bool debugMode;

191
    static const int unsignedLongSize;
192
193
194
195
196
  };

}

#endif