MeshStructure.h 4.13 KB
Newer Older
1
2
// ============================================================================
// ==                                                                        ==
3
// == Amdis - Adaptive multidimensional simulations                          ==
4
5
6
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
8
// ==                                                                        ==
9
10
11
// ==  Institut fr 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(const std::vector<unsigned long int>& initCode, int n) 
48
    {
49
50
      code = initCode;
      nElements = n;
51
      reset();
Thomas Witkowski's avatar
Thomas Witkowski committed
52
    }
53
54
55

    void reset();

56
57
    inline void commit() 
    {
58
59
      if (pos > 0)
	code.push_back(currentCode);
60
      reset();
Thomas Witkowski's avatar
Thomas Witkowski committed
61
    }
62
63
64
65
66
67
68

    bool skipBranch(MeshStructure *insert = NULL);

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

    bool nextElement(MeshStructure *insert = NULL);

69
70
    inline bool isLeafElement() 
    {
71
      return (currentCode & 1) == 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
72
    }
73

74
    /** \brief
75
76
     * Merges a mesh structure code with its own mesh structure code. The result
     * overwrites the own mesh structure code.
77
     */
78
    void merge(MeshStructure *struc) 
79
    {
80
      MeshStructure temp(*this);
81
      merge(&temp, struc, this);
Thomas Witkowski's avatar
Thomas Witkowski committed
82
    }
83

84
85
86
    /** \brief
     * Fits a given mesh to the mesh structure code. 
     *
87
88
89
     * \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.
90
     */
91
92
    void fitMeshToStructure(Mesh *mesh,
			    RefinementManager *manager,
93
94
			    bool checkPartition = false,
			    bool debugMode = false);
95

96
97
98
    /// Prints the mesh structure code.
    void print() 
    {
99
      FUNCNAME("MeshStructure::print()");
100

101
102
      reset();
      bool cont = true;
103
      while (cont) {
104
	if (isLeafElement())
105
	  MSG("0");
106
	else
107
	  MSG("1");
108
	
109
110
111
	cont = nextElement();
      }
      MSG("\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
112
    }
113

114
115
116
    /// Returns the mesh structure code.
    inline const std::vector<unsigned long int>& getCode() 
    {
117
      return code;
Thomas Witkowski's avatar
Thomas Witkowski committed
118
    }
119

120
121
    inline int getNumElements() 
    { 
122
      return nElements; 
Thomas Witkowski's avatar
Thomas Witkowski committed
123
    }
124

125
126
    inline int getCurrentElement() 
    {
127
      return currentElement;
Thomas Witkowski's avatar
Thomas Witkowski committed
128
    }
129

130
  protected:
131
    /// Insert a new element to the structure code. Is used by the init function.
132
133
    void insertElement(bool isLeaf);

134
    /// Merges two mesh structure codes to one structure code.     
135
136
137
138
    void merge(MeshStructure *structure1,
	       MeshStructure *structure2,
	       MeshStructure *result);

139
  protected:
140
    std::vector<unsigned long int> code;
141

142
    int currentIndex;
143

144
    unsigned long int currentCode;
145

146
    int pos;
147

148
    int currentElement;
149

150
    int nElements;
151

152
    static const int unsignedLongSize;
153
154
155
156
157
  };

}

#endif