MeshStructure.h 4.34 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file MeshStructure.h */

#ifndef AMDIS_MESHSTRUCTURE_H
#define AMDIS_MESHSTRUCTURE_H

#include <vector>
#include "MemoryManager.h"

namespace AMDiS {

  class RefinementManager;
  class TraverseStack;
  class ElInfo;

  class MeshStructure
  {
  public:
    MEMORY_MANAGED(MeshStructure);

    MeshStructure()
      : currentIndex_(0),
	currentCode_(0),
	pos_(0),
	currentElement_(0),
	numElements_(0)
    {};
  
    void clear();

49
50
51
    /** \brief
     * Creates a mesh structure code from a Mesh object by traversing it in preorder.
     */
52
53
    void init(Mesh *mesh);

54
    void init(const std::vector<unsigned long int>& code, int numElements) {
55
56
57
58
59
60
61
62
      code_ = code;
      numElements_ = numElements;
      reset();
    };

    void reset();

    inline void commit() {
63
      if (pos_ > 0) {
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
	code_.push_back(currentCode_);
      }
      reset();
    };

    bool skipBranch(MeshStructure *insert = NULL);

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

    bool nextElement(MeshStructure *insert = NULL);

    inline bool isLeafElement() {
      return (currentCode_ & 1) == 0;
    };

79
80
81
82
    /** \brief
     * Merges a mesh structure code with its own mesh structure code. The
     * result overwrites the own mesh structure code.
     */
83
84
85
86
87
    void merge(MeshStructure *structure) {
      MeshStructure temp(*this);
      merge(&temp, structure, this);
    };

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

100
101
102
    /** \brief
     * Prints the mesh structure code.
     */
103
104
    void print() {
      FUNCNAME("MeshStructure::print()");
105

106
107
      reset();
      bool cont = true;
108
109
      while (cont) {
	if (isLeafElement()) {
110
111
112
113
114
115
116
117
118
	  MSG("0");
	} else {
	  MSG("1");
	}
	cont = nextElement();
      }
      MSG("\n");
    };

119
120
121
    /** \brief
     * Returns the mesh structure code.
     */
122
123
124
125
126
127
128
129
130
131
132
133
    inline const std::vector<unsigned long int>& getCode() {
      return code_;
    };

    inline int getNumElements() { 
      return numElements_; 
    };

    inline int getCurrentElement() {
      return currentElement_;
    };

134
135
136
137
138
139
140
141
142
143
144
145
146
147
  protected:
    /** \brief
     * Insert a new element to the structure code. Is used by the init 
     * function.
     */
    void insertElement(bool isLeaf);

    /** \brief
     * Merges two mesh structure codes to one structure code.     
     */
    void merge(MeshStructure *structure1,
	       MeshStructure *structure2,
	       MeshStructure *result);

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
  protected:
    std::vector<unsigned long int> code_;

    int currentIndex_;

    unsigned long int currentCode_;

    int pos_;

    int currentElement_;

    int numElements_;

    static const int unsignedLongSize_;
  };

}

#endif