MacroElement.h 5.79 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
49
50
51
52
53
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file MacroElement.h */

#ifndef AMDIS_MACROELEMENT_H
#define AMDIS_MACROELEMENT_H

#include <deque>
#include <stdio.h>
#include "Boundary.h"
#include "Global.h"
#include "MemoryManager.h"
#include "Projection.h"
#include "FixVec.h"
#include "Serializable.h"

namespace AMDiS {

  class Element;
  class ElInfo;
  class Mesh;

  template<typename T> class WorldVector;
  template<typename T> class DimVec;

  /** \ingroup Triangulation
   * \brief
   * MacroElements form the macro triangulation of a Mesh. In a MacroElement
   * geometrical information are stored, which are used in mesh traversal,
   * to calculate the desired information and fill it in an ElInfo object. 
   */ 
  class MacroElement : public Serializable
  {
  public:
    MEMORY_MANAGED(MacroElement);

54
    /// Creates a new MacroElement. The mesh is needed only to get the dimension
55
56
    MacroElement(int dim); 

57
    /// Destructor.
58
59
    virtual ~MacroElement();

60
    ///
61
62
    MacroElement& operator=(const MacroElement &el);

63
64
65
66
    /** \name getting methods
     * \{
     */

67
    /// Returns \ref index.
68
    inline int getIndex() const {
69
      return index; 
70
    }
71

72
    /// Returns ref projection[i]. 
73
    inline Projection *getProjection(int i) const {
74
      return projection[i];
75
    }
76

77
    /// Returns \ref el
78
    inline Element* getElement() const {
79
      return element; 
80
    }
81

82
    /// Returns the i-th neighbour of this MacroElement \ref neighbour[i]
83
    inline MacroElement* getNeighbour(int i) const {
84
      return neighbour[i];
85
    }
86

87
    /// Returns the i-th opp-vertex of this MacroElement \ref oppVertex[i]
88
    inline char getOppVertex(int i) const {
89
      return oppVertex[i];
90
    }
91

92
    /// Returns \ref coord[i]
93
    inline WorldVector<double>& getCoord(int i) {
94
      return coord[i];    
95
    }
96

97
    /// Returns \ref coord
98
    inline FixVec<WorldVector<double>, VERTEX>& getCoord() {
99
      return coord;    
100
    }
101

102
    /// Returns \ref boundary[i]
103
    inline BoundaryType getBoundary(int i) const {
104
      return boundary[i]; 
105
    }
106

107
    /// Returns \ref elType
108
    inline unsigned char getElType() const {
109
      return elType; 
110
    }
111
112
113
114
115
116
117

    /** \} */

    /** \name setting methods
     * \{
     */

118
    /// Sets \ref index
119
    inline void setIndex(int n) {
120
      index = n ; 
121
    }
122

123
    /// Sets \ref element if not yet set.
124
125
126
127
128
129
130
    inline void setElement(Element* element_) {
      if (!element) {
	element = element_; 
      } else {
	if (element != element_) 
	  ERROR("Trying to change element in MacroElement\n");   
      }
131
    }
132

133
    /// Sets \ref elType
134
135
    inline void setElType(unsigned char typ) {
      elType = typ; 
136
    }
137
138


139
    /// Sets \ref projection[i] = p.
140
    inline void setProjection(int i, Projection *p) {
141
      projection[i] = p;
142
    }
143

144
    /// Sets the i-th Neighbour to n
145
    inline void setNeighbour(int i, MacroElement *n) {
146
      neighbour[i] = n;
147
    }
148

149
    /// Sets the i-th opp vertex to c
150
151
    inline void  setOppVertex(int i, char c) {
      oppVertex[i] = c;
152
    }
153

154
    /// Sets \ref boundary[i] to b
155
    inline void setBoundary(int i, BoundaryType b) {
156
      boundary[i] = b; 
157
    }
158

159
    ///
160
    inline void setCoord(int i, const WorldVector<double> c) {
161
      coord[i] = c;
162
    }
163
164
165
166

    /** \} */


167
    /// Writes the macro element to a file.
168
    void serialize(std::ostream &out);
169

170
    /// Reads a macro element from a file.
171
    void deserialize(std::istream &in);
172

173
    ///
174
    inline void writeNeighboursTo(std::vector<int> *indices) {
175
      deserializedNeighbourIndices_ = indices;
176
177
    }

178
    ///
179
    int calcMemoryUsage();
180
181

  protected:
182
    /// Element of this MacroElement.
183
184
    Element *element;

185
    /// Coordinates of the vertices.
186
187
    FixVec<WorldVector<double>, VERTEX> coord;

188
    /// Boundary type of each boundary part (face/edge/vertex)
189
190
    FixVec<BoundaryType, BOUNDARY> boundary;

191
    /// Boundary projection to curved boundaries or element projections.
192
193
    FixVec<Projection*, PROJECTION> projection;

194
    /// Pointers to all neighbours of this MacroElement 
195
196
    FixVec<MacroElement*, NEIGH> neighbour;

197
    /// opp vertices of this MacroElement
198
199
    FixVec<char, NEIGH> oppVertex;

200
    /// index of this MacroElement
201
202
    int index;  

203
    /// Element type of the MacroElement
204
205
    unsigned char elType;  

206
    ///
207
    std::vector<int> *deserializedNeighbourIndices_;
208

209

210
211
212
213
214
215
216
217
218
219
220
    friend class MacroInfo;
    friend class MacroReader;
    friend class ElInfo1d;
    friend class ElInfo2d;
    friend class ElInfo3d;
  };

}


#endif  // AMDIS_MACROELEMENT_H