MeshStructure.h 5.79 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>
26
27
#include <stdint.h>

Thomas Witkowski's avatar
Thomas Witkowski committed
28
#include "AMDiS_fwd.h"
29
#include "Global.h"
30
#include "parallel/InteriorBoundary.h"
31

32
33
34
35
36
37
namespace AMDiS {

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

48
49
50
51
52
53
54
55
56
57
    /** \brief
     * Creates a mesh structure code from a mesh object by traversing it in 
     * preorder.
     *
     * \param[in]  mesh           Mesh that is used to create the structure code.
     * \param[in]  macroElIndex   If the value is set to -1, the structure code is
     *                            created for the whole mesh. Otherwise, it is done
     *                            only for the macro element with this index.
     */
    void init(Mesh *mesh, int macroElIndex = -1);
58
   
59
60
    void init(BoundaryObject &bound);

61
    void init(const std::vector<uint64_t>& initCode, int n) 
62
    {
63
64
      code = initCode;
      nElements = n;
65
      reset();
Thomas Witkowski's avatar
Thomas Witkowski committed
66
    }
67

68
69
70
71
    /** \brief
     * Sets all position counters, that are used to traverse the code, to the starting
     * position. The code itself is not changed.
     */
72
73
    void reset();

74
75
76
77
78
79
    /// Returns whether the code is empty or not.
    inline bool empty()
    {
      return (nElements == 0);
    }

80
81
    inline void commit() 
    {
82
83
      if (pos > 0)
	code.push_back(currentCode);
84
      reset();
Thomas Witkowski's avatar
Thomas Witkowski committed
85
    }
86
87
88
89
90
91
92

    bool skipBranch(MeshStructure *insert = NULL);

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

    bool nextElement(MeshStructure *insert = NULL);

93
94
    inline bool isLeafElement() 
    {
95
      return (currentCode & 1) == 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
96
    }
97

98
    /** \brief
99
100
     * Merges a mesh structure code with its own mesh structure code. The result
     * overwrites the own mesh structure code.
101
     */
102
    void merge(MeshStructure *struc) 
103
    {
104
      MeshStructure temp(*this);
105
      merge(&temp, struc, this);
Thomas Witkowski's avatar
Thomas Witkowski committed
106
    }
107

108
109
110
    /** \brief
     * Fits a given mesh to the mesh structure code. 
     *
111
112
113
114
115
116
117
118
     * \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.
119
     */
120
121
    void fitMeshToStructure(Mesh *mesh,
			    RefinementManager *manager,
122
			    bool debugMode = false,
Thomas Witkowski's avatar
Thomas Witkowski committed
123
124
			    int macroElIndex = -1,
			    bool ignoreFinerMesh = false);
125

126
    /// Prints the mesh structure code.
127
    void print(bool resetCode = true); 
128

129
    /// Returns the mesh structure code.
130
    inline const std::vector<uint64_t>& getCode() 
131
    {
132
      return code;
Thomas Witkowski's avatar
Thomas Witkowski committed
133
    }
134

135
136
    inline int getNumElements() 
    { 
137
      return nElements; 
Thomas Witkowski's avatar
Thomas Witkowski committed
138
    }
139

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

145
146
147
148
149
150
151
152
    void setDebugMode(bool b)
    {
      debugMode = b;
    }

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

153
154
155
156
157
158
159
160
161
162
163
    void getMeshStructureValues(Mesh *mesh,
				int macroElIndex,
				const DOFVector<double>* vec,
				std::vector<double>& values);


    void setMeshStructureValues(Mesh *mesh,
				int macroElIndex,
				DOFVector<double>* vec,
				const std::vector<double>& values);

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

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

170
    /// Merges two mesh structure codes to one structure code.     
171
172
173
174
    void merge(MeshStructure *structure1,
	       MeshStructure *structure2,
	       MeshStructure *result);

175
  protected:
176
    /// Mesh structure code.
177
    std::vector<uint64_t> code;
178

179
    int currentIndex;
180

181
    uint64_t currentCode;
182

183
    int pos;
184

185
    int currentElement;
186

187
    int nElements;
188

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

192
    static const int structureSize;
193
194

    friend class ArhWriter;
195
196
197
198
199
  };

}

#endif