MeshStructure.h 6.33 KB
Newer Older
1
2
// ============================================================================
// ==                                                                        ==
3
// == Amdis - Adaptive multidimensional simulations                          ==
4
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6
7
// ==                                                                        ==
// ============================================================================
8
9
10
11
12
13
14
15
16
17
18
19
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


20
21
22

/** \file MeshStructure.h */

23
24
#ifndef AMDIS_MESH_STRUCTURE_H
#define AMDIS_MESH_STRUCTURE_H
25
26

#include <vector>
27
28
#include <stdint.h>

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

33
34
35
36
37
38
namespace AMDiS {

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

49

50
51
52
53
54
55
56
57
58
59
    /** \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);
60
   
61
62
    void init(BoundaryObject &bound);

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

70
71
    /// 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
    int lookAhead(unsigned int n = 1);

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

100
101
    /// Merges a mesh structure code with its own mesh structure code. The result
    /// overwrites the own mesh structure code.
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
     * \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.
114
115
     * \param macroElIndex  If the mesh structure code represents only one macro 
     *                      element, this can be denoted here by its index. In this
116
117
118
     *                      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

Thomas Witkowski's avatar
Thomas Witkowski committed
126
127
128
    /// Converts the mesh structure code to a string (for debugging).
    string toStr(bool resetCode = true);
    
129
    /// Prints the mesh structure code.
130
    void print(bool resetCode = true); 
131

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

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

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

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

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

156
157
158
159
160
161
162
163
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
     * computations). 
     *
     * \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.
     * \param[out] values        Resulting value structure code.     
     */
    void getMeshStructureValues(int macroElIndex,
169
170
171
172
				const DOFVector<double>* vec,
				std::vector<double>& values);


173
174
175
176
177
178
179
180
181
    /** \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,
182
183
184
				DOFVector<double>* vec,
				const std::vector<double>& values);

185
  protected:
186
    /// Insert a new element to the structure code. Is used by the init function.
187
188
    void insertElement(bool isLeaf);

189
190
191
192
193
    void addAlongSide(Element *el, 
		      GeoIndex subObj, 
		      int ithObj, 
		      int elType, 
		      bool reverseOrder);
194

195
    /// Merges two mesh structure codes to one structure code.     
196
197
198
199
    void merge(MeshStructure *structure1,
	       MeshStructure *structure2,
	       MeshStructure *result);

200
  protected:
201
    /// Mesh structure code.
202
    std::vector<uint64_t> code;
203

204
    int currentIndex;
205

206
    uint64_t currentCode;
207

208
    int pos;
209

210
    int currentElement;
211

212
    int nElements;
213

214
215
    /// If true, some output is printed to screen during mesh structure 
    /// code generation.
216
217
    bool debugMode;

218
    static const int structureSize;
219
220

    friend class ArhWriter;
221
222
223
224
225
  };

}

#endif