MeshStructure.h 4.27 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
48
    void init(Element *el, int ithSide, int elType);

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

    void reset();

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

    bool skipBranch(MeshStructure *insert = NULL);

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

    bool nextElement(MeshStructure *insert = NULL);

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

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

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

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

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

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

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

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

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

136
137
    void addAlongSide(Element *el, int ithSide, int elType);

138
    /// Merges two mesh structure codes to one structure code.     
139
140
141
142
    void merge(MeshStructure *structure1,
	       MeshStructure *structure2,
	       MeshStructure *result);

143
  protected:
144
    std::vector<unsigned long int> code;
145

146
    int currentIndex;
147

148
    unsigned long int currentCode;
149

150
    int pos;
151

152
    int currentElement;
153

154
    int nElements;
155

156
    static const int unsignedLongSize;
157
158
159
160
161
  };

}

#endif