MacroElement.cc 4.48 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/
20
21


22
23
#include <string>
#include <map>
24
25
26
27
28
29
#include "MacroElement.h"
#include "Boundary.h"
#include "FiniteElemSpace.h"
#include "Mesh.h"
#include "FixVec.h"
#include "FixVecConvert.h"
30
#include "Serializer.h"
31
32
33
34

namespace AMDiS {

  MacroElement::MacroElement(int dim)
35
    : element(NULL),
36
37
38
39
40
41
42
      coord(dim, NO_INIT),
      boundary(dim, DEFAULT_VALUE, INTERIOR),
      projection(dim, NO_INIT),
      neighbour(dim, NO_INIT),
      oppVertex(dim, NO_INIT),
      index(-1), 
      elType(0),
43
      deserializedNeighbourIndices(NULL)
44
  {
45
46
    neighbour.set((MacroElement*)(NULL));
    projection.set((Projection*)(NULL));
47
48
  }

49

50
51
  MacroElement::~MacroElement()
  {
52
    if (element)
53
      delete element;    
54
55
  }

56

57
58
59
60
61
62
63
64
65
66
67
68
69
70
  MacroElement& MacroElement::operator=(const MacroElement &el)
  {
    if (this == &el)
      return *this;

    coord = el.coord;
    boundary = el.boundary;
    projection = el.projection;
    oppVertex = el.oppVertex;
    index = el.index;
    elType = el.elType;  
    
    return *this;
  }
71

72

73
  void MacroElement::serialize(std::ostream &out)
74
75
  {
    // write element-tree
Thomas Witkowski's avatar
Thomas Witkowski committed
76
    out << element->getTypeName() << "\n";
77
78
79
    element->serialize(out);

    // write coords
Thomas Witkowski's avatar
Thomas Witkowski committed
80
    int size = coord.getSize();
81
82
    SerUtil::serialize(out, size);

Thomas Witkowski's avatar
Thomas Witkowski committed
83
    for (int i = 0; i < size; i++)
84
85
86
87
88
89
90
      coord[i].serialize(out);

    // write boundary
    boundary.serialize(out);

    // write projection
    size = projection.getSize();
91
    SerUtil::serialize(out, size);
Thomas Witkowski's avatar
Thomas Witkowski committed
92
    for (int i = 0; i < size; i++) {
93
      int id = projection[i] ? projection[i]->getID() : -1;
94
      SerUtil::serialize(out, id);
95
96
97
98
    }

    // write neighbour
    size = neighbour.getSize();
99
    SerUtil::serialize(out, size);
Thomas Witkowski's avatar
Thomas Witkowski committed
100
    for (int i = 0; i < size; i++) {
101
      int index = neighbour[i] ? neighbour[i]->getIndex() : -1;
102
      SerUtil::serialize(out, index);
103
104
105
106
107
108
    }
  
    // write oppVertex
    oppVertex.serialize(out);

    // write index
109
    SerUtil::serialize(out, index);
110
111

    // write elType
112
    SerUtil::serialize(out, elType);
113
114
  }

115

Thomas Witkowski's avatar
Thomas Witkowski committed
116
  void MacroElement::deserialize(std::istream &in)
117
  {
118
119
120
121
    FUNCNAME("MacroElement::deserialize()");

    // === Read element-tree. ===

Thomas Witkowski's avatar
Thomas Witkowski committed
122
    std::string typeName;
123
124
125
    in >> typeName;
    in.get();

126
    if (element) {
127
128
      TEST_EXIT(typeName == element->getTypeName())("wrong element type name\n");
    } else {
129
      if (typeName == "Line") 
130
	element = new Line(NULL);
131
      if (typeName == "Triangle")
132
	element = new Triangle(NULL);
133
      if (typeName == "Tetrahedron") 
134
	element = new Tetrahedron(NULL);
135
136
137
138
    }

    element->deserialize(in);

139
140
    // === Read coords. ===

141
    int size;
142
143
144
    SerUtil::deserialize(in, size);
    
    if (coord.getSize())
145
      TEST_EXIT(coord.getSize() == size)("invalid size\n");
146
    else
147
      coord.initSize(size);
148
149
    
    for (int i = 0; i < size; i++)
150
151
152
153
      coord[i].deserialize(in);

    boundary.deserialize(in);

154
    // === Read projections. ===
155

156
157
158
    SerUtil::deserialize(in, size);

    if (projection.getSize())
159
      TEST_EXIT(projection.getSize() == size)("invalid size\n");
160
    else
161
      projection.initSize(size);
162
    
163
    for (int i = 0; i < size; i++) {
164
      int id;
165
      SerUtil::deserialize(in, id);
166
      projection[i] = (id != -1) ? Projection::getProjection(id) : NULL;
167
168
    }

169
170
171
    // === Read neighbour indices. ===

    SerUtil::deserialize(in, size);
172
  
173
174
    TEST_EXIT(deserializedNeighbourIndices)
      ("Neighbour indices for deserializing not set!\n");
175
    
176
    deserializedNeighbourIndices->resize(size);
177

178
    if (neighbour.getSize())
179
      TEST_EXIT(neighbour.getSize() == size)("invalid size\n");
180
    else
181
      neighbour.initSize(size);
182
183
184
    
    for (int i = 0; i < size; i++)
      SerUtil::deserialize(in, (*deserializedNeighbourIndices)[i]);
185

186
    deserializedNeighbourIndices = NULL;
187
188
189
190

    // read oppVertex
    oppVertex.deserialize(in);

191
192
    SerUtil::deserialize(in, index);
    SerUtil::deserialize(in, elType);
193
194
195
  }

}