MeshStructure.h 6.33 KB
Newer Older
1
2
3
4
5
6
7
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
8
 * Authors:
9
10
11
12
13
14
15
16
17
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
18
 *
19
 ******************************************************************************/
20
21


22
23
24

/** \file MeshStructure.h */

25
26
#ifndef AMDIS_MESH_STRUCTURE_H
#define AMDIS_MESH_STRUCTURE_H
27
28

#include <vector>
29
30
#include <stdint.h>

Thomas Witkowski's avatar
Thomas Witkowski committed
31
#include "AMDiS_fwd.h"
32
#include "Global.h"
33
#include "BoundaryObject.h"
34

35
36
#ifndef NDEBUG
  #define WITH_ELINDEX true
37
#else
38
  #define WITH_ELINDEX false
39
40
#endif

41
42
43
44
45
46
namespace AMDiS {

  class MeshStructure
  {
  public:
    MeshStructure()
47
48
49
50
      : currentIndex(0),
	currentCode(0),
	pos(0),
	currentElement(0),
51
52
	nElements(0),
	debugMode(false)
Thomas Witkowski's avatar
Thomas Witkowski committed
53
    {}
54

55
56
    void clear();

57

58
    /** \brief
59
     * Creates a mesh structure code from a mesh object by traversing it in
60
61
62
63
64
65
66
67
     * 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);
68

69
    void init(BoundaryObject &bound, Element* mesh = NULL);
70

71
    void init(const std::vector<uint64_t>& initCode, int n)
72
    {
73
74
      code = initCode;
      nElements = n;
75
      reset();
Thomas Witkowski's avatar
Thomas Witkowski committed
76
    }
77

78
    /// Sets all position counters, that are used to traverse the code, to the
79
    /// starting position. The code itself is not changed.
80
81
    void reset();

82
83
84
85
86
87
    /// Returns whether the code is empty or not.
    inline bool empty()
    {
      return (nElements == 0);
    }

88
    inline void commit()
89
    {
90
91
      if (pos > 0)
	code.push_back(currentCode);
92
      reset();
Thomas Witkowski's avatar
Thomas Witkowski committed
93
    }
94

95
    bool skipBranch(MeshStructure *insert = NULL);
96
97
98

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

99
    bool nextElement(MeshStructure *insert = NULL);
100

101
102
    int lookAhead(unsigned int n = 1);

103
    inline bool isLeafElement()
104
    {
105
      return (currentCode & 1) == 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
106
    }
107

108
109
    /// Merges a mesh structure code with its own mesh structure code. The result
    /// overwrites the own mesh structure code.
110
    void merge(MeshStructure *struc)
111
    {
112
      MeshStructure temp(*this);
113
      merge(&temp, struc, this);
Thomas Witkowski's avatar
Thomas Witkowski committed
114
    }
115

116
    /** \brief
117
     * Fits a given mesh to the mesh structure code.
118
     *
119
     * \param debugMode     In debugMode, the whole mesh is fitted to the mesh
120
     *                      structure code. Otherwise, the mesh is fitted only on
121
     *                      the partition of the current process.
122
     * \param macroElIndex  If the mesh structure code represents only one macro
123
     *                      element, this can be denoted here by its index. In this
124
     *                      case, only the corresponding macro element will be
125
     *                      fitted to the code. Otherwise, this variable is
126
     *                      negative and the whole mesh will be adapted.
127
     */
128
129
    void fitMeshToStructure(Mesh *mesh,
			    RefinementManager *manager,
130
			    bool debugMode = false,
Thomas Witkowski's avatar
Thomas Witkowski committed
131
132
			    int macroElIndex = -1,
			    bool ignoreFinerMesh = false);
133

Thomas Witkowski's avatar
Thomas Witkowski committed
134
    /// Converts the mesh structure code to a string (for debugging).
135
    std::string toStr(bool resetCode = true);
136

137
    /// Prints the mesh structure code.
138
    void print(bool resetCode = true);
139

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

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

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

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

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

164
165
166
167
168
    /** \brief
     * Creates a value array of a given DOFVector. This value array corresponds
     * to the mesh structure code of the element and thus can easily be used
     * to reconstruct the values of the DOFVector on the same element (e.g., after
     * the mesh and the value array has been redistributed in parallel
169
     * computations).
170
171
172
173
     *
     * \param[in]  macroElIndex  Index of the macro element for which the value
     *                           structure code must be created.
     * \param[in]  vec           DOFVector to be used for creating the value code.
174
     * \param[out] values        Resulting value structure code.
175
176
     */
    void getMeshStructureValues(int macroElIndex,
177
				const DOFVector<double>* vec,
178
179
				std::vector<double>& values,
				bool withElIndex = WITH_ELINDEX);
180
181


182
183
184
185
186
187
188
189
190
    /** \brief
     * Uses a value structure code, e.g. created by \ref getMeshStructureValues,
     * to reconstruct the data of a DOFVector on a given macro element.
     *
     * \param[in]  macroElIndex  Macro element index the code is related to.
     * \param[out] vec           DOFVector that should be reconstructed.
     * \param[in]  values        Value structure code.
     */
    void setMeshStructureValues(int macroElIndex,
191
				DOFVector<double>* vec,
192
193
				const std::vector<double>& values,
				bool withElIndex = WITH_ELINDEX);
194

195
    /// Insert a new element to the structure code. Is used by the init function.
196
197
    void insertElement(bool isLeaf);

198
199
  protected:

200
201
202
203
    void addAlongSide(Element *el,
		      GeoIndex subObj,
		      int ithObj,
		      int elType,
204
		      bool reverseOrder);
205

206
    /// Merges two mesh structure codes to one structure code.
207
208
209
210
    void merge(MeshStructure *structure1,
	       MeshStructure *structure2,
	       MeshStructure *result);

211
  protected:
212
    /// Mesh structure code.
213
    std::vector<uint64_t> code;
214

215
    int currentIndex;
216

217
    uint64_t currentCode;
218

219
    int pos;
220

221
    int currentElement;
222

223
    int nElements;
224

225
    /// If true, some output is printed to screen during mesh structure
226
    /// code generation.
227
228
    bool debugMode;

229
    static const int structureSize;
230

231
232
233
234
235
  };

}

#endif