MeshStructure.h 5.68 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
114
			    bool debugMode = false,
			    int macroElIndex = -1);
115

116
117
118
    /// Prints the mesh structure code.
    void print() 
    {
119
      FUNCNAME("MeshStructure::print()");
120

121
122
      std::stringstream oss;

123
      if (empty()) {
124
125
126
127
128
129
130
131
132
133
134
135
	oss << "-" << std::endl;
      }	else {	
	reset();
	bool cont = true;
	while (cont) {
	  if (isLeafElement())
	    oss << "0";
	  else
	    oss << "1";
	  
	  cont = nextElement();
	}
136
      }
137
138

      MSG("Mesh structure code: %s\n", oss.str().c_str());
Thomas Witkowski's avatar
Thomas Witkowski committed
139
    }
140

141
142
143
    /// Returns the mesh structure code.
    inline const std::vector<unsigned long int>& getCode() 
    {
144
      return code;
Thomas Witkowski's avatar
Thomas Witkowski committed
145
    }
146

147
148
    inline int getNumElements() 
    { 
149
      return nElements; 
Thomas Witkowski's avatar
Thomas Witkowski committed
150
    }
151

152
153
    inline int getCurrentElement() 
    {
154
      return currentElement;
Thomas Witkowski's avatar
Thomas Witkowski committed
155
    }
156

157
158
159
160
161
162
163
164
    void setDebugMode(bool b)
    {
      debugMode = b;
    }

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

165
166
    void writeMeshFile(Mesh *mesh, std::string filename);

167
168
    void readMeshFile(Mesh *mesh, RefinementManager *refManager, std::string filename);

169
  protected:
170
    /// Insert a new element to the structure code. Is used by the init function.
171
172
    void insertElement(bool isLeaf);

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

175
    /// Merges two mesh structure codes to one structure code.     
176
177
178
179
    void merge(MeshStructure *structure1,
	       MeshStructure *structure2,
	       MeshStructure *result);

180
181
    void writeMacroElement(std::ofstream& file, int macroElIndex);

182
  protected:
183
    /// Mesh structure code.
184
    std::vector<unsigned long int> code;
185

186
    int currentIndex;
187

188
    unsigned long int currentCode;
189

190
    int pos;
191

192
    int currentElement;
193

194
    int nElements;
195

196
    /// If true, some output is printed to screen during mesh structure code generation.
197
198
    bool debugMode;

199
    static const int unsignedLongSize;
200
201
202
203
204
  };

}

#endif