MeshStructure.h 4.46 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
22
23
24
25
// ==                                                                        ==
// ============================================================================

/** \file MeshStructure.h */

#ifndef AMDIS_MESHSTRUCTURE_H
#define AMDIS_MESHSTRUCTURE_H

#include <vector>
Thomas Witkowski's avatar
Thomas Witkowski committed
26
#include "AMDiS_fwd.h"
27
28
#include "Global.h"

29
30
31
32
33
34
namespace AMDiS {

  class MeshStructure
  {
  public:
    MeshStructure()
35
36
37
38
39
      : currentIndex(0),
	currentCode(0),
	pos(0),
	currentElement(0),
	nElements(0)
Thomas Witkowski's avatar
Thomas Witkowski committed
40
    {}
41
42
43
  
    void clear();

44
    /// Creates a mesh structure code from a mesh object by traversing it in preorder.
45
46
    void init(Mesh *mesh);

47
    void init(Element *el, int ithSide, int elType, bool reverseOrder);
48

49
    void init(const std::vector<unsigned long int>& initCode, int n) 
50
    {
51
52
      code = initCode;
      nElements = n;
53
      reset();
Thomas Witkowski's avatar
Thomas Witkowski committed
54
    }
55

56
57
58
59
    /** \brief
     * Sets all position counters, that are used to traverse the code, to the starting
     * position. The code itself is not changed.
     */
60
61
    void reset();

62
63
    inline void commit() 
    {
64
65
      if (pos > 0)
	code.push_back(currentCode);
66
      reset();
Thomas Witkowski's avatar
Thomas Witkowski committed
67
    }
68
69
70
71
72
73
74

    bool skipBranch(MeshStructure *insert = NULL);

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

    bool nextElement(MeshStructure *insert = NULL);

75
76
    inline bool isLeafElement() 
    {
77
      return (currentCode & 1) == 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
78
    }
79

80
    /** \brief
81
82
     * Merges a mesh structure code with its own mesh structure code. The result
     * overwrites the own mesh structure code.
83
     */
84
    void merge(MeshStructure *struc) 
85
    {
86
      MeshStructure temp(*this);
87
      merge(&temp, struc, this);
Thomas Witkowski's avatar
Thomas Witkowski committed
88
    }
89

90
91
92
    /** \brief
     * Fits a given mesh to the mesh structure code. 
     *
93
94
95
     * \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.
96
     */
97
98
    void fitMeshToStructure(Mesh *mesh,
			    RefinementManager *manager,
99
100
			    bool checkPartition = false,
			    bool debugMode = false);
101

102
103
104
    /// Prints the mesh structure code.
    void print() 
    {
105
      FUNCNAME("MeshStructure::print()");
106

107
108
      reset();
      bool cont = true;
109
      while (cont) {
110
	if (isLeafElement())
111
	  std::cout << "0";
112
	else
113
	  std::cout << "1";
114
	
115
116
	cont = nextElement();
      }
117
      std::cout << std::endl;
Thomas Witkowski's avatar
Thomas Witkowski committed
118
    }
119

120
121
122
    /// Returns the mesh structure code.
    inline const std::vector<unsigned long int>& getCode() 
    {
123
      return code;
Thomas Witkowski's avatar
Thomas Witkowski committed
124
    }
125

126
127
    inline int getNumElements() 
    { 
128
      return nElements; 
Thomas Witkowski's avatar
Thomas Witkowski committed
129
    }
130

131
132
    inline int getCurrentElement() 
    {
133
      return currentElement;
Thomas Witkowski's avatar
Thomas Witkowski committed
134
    }
135

136
  protected:
137
    /// Insert a new element to the structure code. Is used by the init function.
138
139
    void insertElement(bool isLeaf);

140
    void addAlongSide(Element *el, int ithSide, int elType, bool reverseOrder);
141

142
    /// Merges two mesh structure codes to one structure code.     
143
144
145
146
    void merge(MeshStructure *structure1,
	       MeshStructure *structure2,
	       MeshStructure *result);

147
  protected:
148
    std::vector<unsigned long int> code;
149

150
    int currentIndex;
151

152
    unsigned long int currentCode;
153

154
    int pos;
155

156
    int currentElement;
157

158
    int nElements;
159

160
    static const int unsignedLongSize;
161
162
163
164
165
  };

}

#endif