ElementObjectData.cc 8.59 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


Thomas Witkowski's avatar
Thomas Witkowski committed
13
14
15
16
#include "ElementObjectData.h"

namespace AMDiS {

Thomas Witkowski's avatar
Thomas Witkowski committed
17
  void ElementObjects::createRankData(std::map<int, int>& macroElementRankMap) 
Thomas Witkowski's avatar
Thomas Witkowski committed
18
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
19
20
21
22
    FUNCNAME("ElementObjects::createRankData()");

    vertexOwner.clear();
    vertexInRank.clear();
Thomas Witkowski's avatar
Thomas Witkowski committed
23
24
    for (std::map<DegreeOfFreedom, std::vector<ElementObjectData> >::iterator it = vertexElements.begin();
	 it != vertexElements.end(); ++it) {
Thomas Witkowski's avatar
Thomas Witkowski committed
25
26
27
      for (std::vector<ElementObjectData>::iterator it2 = it->second.begin(); 
	   it2 != it->second.end(); ++it2) {
	int elementInRank = macroElementRankMap[it2->elIndex];
Thomas Witkowski's avatar
Thomas Witkowski committed
28
	
Thomas Witkowski's avatar
Thomas Witkowski committed
29
30
31
32
	if (it2->elIndex > vertexInRank[it->first][elementInRank].elIndex)
	  vertexInRank[it->first][elementInRank] = *it2;

	vertexOwner[it->first] = std::max(vertexOwner[it->first], elementInRank);
Thomas Witkowski's avatar
Thomas Witkowski committed
33
34
35
      }
    }
    
Thomas Witkowski's avatar
Thomas Witkowski committed
36
37
38

    edgeOwner.clear();
    edgeInRank.clear();
Thomas Witkowski's avatar
Thomas Witkowski committed
39
40
    for (std::map<DofEdge, std::vector<ElementObjectData> >::iterator it = edgeElements.begin();
	 it != edgeElements.end(); ++it) {
Thomas Witkowski's avatar
Thomas Witkowski committed
41
42
43
      for (std::vector<ElementObjectData>::iterator it2 = it->second.begin(); 
	   it2 != it->second.end(); ++it2) {
	int elementInRank = macroElementRankMap[it2->elIndex];
Thomas Witkowski's avatar
Thomas Witkowski committed
44
	
Thomas Witkowski's avatar
Thomas Witkowski committed
45
46
47
48
	if (it2->elIndex > edgeInRank[it->first][elementInRank].elIndex)
	  edgeInRank[it->first][elementInRank] = *it2;

	edgeOwner[it->first] = std::max(edgeOwner[it->first], elementInRank);
Thomas Witkowski's avatar
Thomas Witkowski committed
49
50
51
      }
    }
    
Thomas Witkowski's avatar
Thomas Witkowski committed
52
53
54

    faceOwner.clear();
    faceInRank.clear();
Thomas Witkowski's avatar
Thomas Witkowski committed
55
56
    for (std::map<DofFace, std::vector<ElementObjectData> >::iterator it = faceElements.begin();
	 it != faceElements.end(); ++it) {
Thomas Witkowski's avatar
Thomas Witkowski committed
57
58
59
      for (std::vector<ElementObjectData>::iterator it2 = it->second.begin(); 
	   it2 != it->second.end(); ++it2) {
	int elementInRank = macroElementRankMap[it2->elIndex];
Thomas Witkowski's avatar
Thomas Witkowski committed
60
	
Thomas Witkowski's avatar
Thomas Witkowski committed
61
62
63
64
	if (it2->elIndex > faceInRank[it->first][elementInRank].elIndex)
	  faceInRank[it->first][elementInRank] = *it2;

	faceOwner[it->first] = std::max(faceOwner[it->first], elementInRank);
Thomas Witkowski's avatar
Thomas Witkowski committed
65
66
67
68
      }
    }
  }

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

  void ElementObjects::serialize(std::ostream &out)
  {
    FUNCNAME("ElementObjects::serialize()");

    int nSize = vertexElements.size();
    SerUtil::serialize(out, nSize);
    for (std::map<DegreeOfFreedom, std::vector<ElementObjectData> >::iterator it = vertexElements.begin();
	 it != vertexElements.end(); ++it) {
      SerUtil::serialize(out, it->first);
      serialize(out, it->second);
    }

    nSize = edgeElements.size();
    SerUtil::serialize(out, nSize);
    for (std::map<DofEdge, std::vector<ElementObjectData> >::iterator it = edgeElements.begin();
	 it != edgeElements.end(); ++it) {
      SerUtil::serialize(out, it->first);
      serialize(out, it->second);
    }

    nSize = faceElements.size();
    SerUtil::serialize(out, nSize);
    for (std::map<DofFace, std::vector<ElementObjectData> >::iterator it = faceElements.begin();
	 it != faceElements.end(); ++it) {
      SerUtil::serialize(out, it->first);
      serialize(out, it->second);
    }


99

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    nSize = vertexLocalMap.size();
    SerUtil::serialize(out, nSize);
    for (std::map<ElementObjectData, DegreeOfFreedom>::iterator it = vertexLocalMap.begin();
	 it != vertexLocalMap.end(); ++it) {
      it->first.serialize(out);
      SerUtil::serialize(out, it->second);
    }

    nSize = edgeLocalMap.size();
    SerUtil::serialize(out, nSize);
    for (std::map<ElementObjectData, DofEdge>::iterator it = edgeLocalMap.begin();
	 it != edgeLocalMap.end(); ++it) {
      it->first.serialize(out);
      SerUtil::serialize(out, it->second);
    }

    nSize = faceLocalMap.size();
    SerUtil::serialize(out, nSize);
    for (std::map<ElementObjectData, DofFace>::iterator it = faceLocalMap.begin();
	 it != faceLocalMap.end(); ++it) {
      it->first.serialize(out);
      SerUtil::serialize(out, it->second);
    }



126
127
128
129
130
131
    SerUtil::serialize(out, vertexOwner);
    SerUtil::serialize(out, edgeOwner);
    SerUtil::serialize(out, faceOwner);


    nSize = vertexInRank.size();
132
    SerUtil::serialize(out, nSize);
133
134
135
136
137
138
139
    for (std::map<DegreeOfFreedom, std::map<int, ElementObjectData> >::iterator it = vertexInRank.begin();
	 it != vertexInRank.end(); ++it) {
      SerUtil::serialize(out, it->first);
      serialize(out, it->second);
    }

    nSize = edgeInRank.size();
140
    SerUtil::serialize(out, nSize);
141
142
143
144
145
146
147
    for (std::map<DofEdge, std::map<int, ElementObjectData> >::iterator it = edgeInRank.begin();
	 it != edgeInRank.end(); ++it) {
      SerUtil::serialize(out, it->first);
      serialize(out, it->second);
    }

    nSize = faceInRank.size();
148
    SerUtil::serialize(out, nSize);
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
    for (std::map<DofFace, std::map<int, ElementObjectData> >::iterator it = faceInRank.begin();
	 it != faceInRank.end(); ++it) {
      SerUtil::serialize(out, it->first);
      serialize(out, it->second);
    }

  }


  void ElementObjects::deserialize(std::istream &in)
  {
    FUNCNAME("ElementObjects::deserialize()");

    int nSize;
    SerUtil::deserialize(in, nSize);
    vertexElements.clear();
    for (int i = 0; i < nSize; i++) {
      DegreeOfFreedom dof;
      std::vector<ElementObjectData> data;
      SerUtil::deserialize(in, dof);
      deserialize(in, data);
      vertexElements[dof] = data;
    }

    SerUtil::deserialize(in, nSize);
    edgeElements.clear();
    for (int i = 0; i < nSize; i++) {
      DofEdge edge;
      std::vector<ElementObjectData> data;
      SerUtil::deserialize(in, edge);
      deserialize(in, data);
      edgeElements[edge] = data;
    }

    SerUtil::deserialize(in, nSize);
    faceElements.clear();
    for (int i = 0; i < nSize; i++) {
      DofFace face;
      std::vector<ElementObjectData> data;
      SerUtil::deserialize(in, face);
      deserialize(in, data);
      faceElements[face] = data;
    }
192
   
193

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225

    SerUtil::deserialize(in, nSize);
    vertexLocalMap.clear();
    for (int i = 0; i < nSize; i++) {
      ElementObjectData data;
      DegreeOfFreedom dof;
      data.deserialize(in);
      SerUtil::deserialize(in, dof);
      vertexLocalMap[data] = dof;
    }

    SerUtil::deserialize(in, nSize);
    edgeLocalMap.clear();
    for (int i = 0; i < nSize; i++) {
      ElementObjectData data;
      DofEdge edge;
      data.deserialize(in);
      SerUtil::deserialize(in, edge);
      edgeLocalMap[data] = edge;
    }

    SerUtil::deserialize(in, nSize);
    faceLocalMap.clear();
    for (int i = 0; i < nSize; i++) {
      ElementObjectData data;
      DofFace face;
      data.deserialize(in);
      SerUtil::deserialize(in, face);
      faceLocalMap[data] = face;
    }


226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
    SerUtil::deserialize(in, vertexOwner);
    SerUtil::deserialize(in, edgeOwner);
    SerUtil::deserialize(in, faceOwner);


    SerUtil::deserialize(in, nSize);
    vertexInRank.clear();
    for (int i = 0; i < nSize; i++) {
      DegreeOfFreedom dof;
      std::map<int, ElementObjectData> data;
      SerUtil::deserialize(in, dof);
      deserialize(in, data);
      vertexInRank[dof] = data;
    }

    SerUtil::deserialize(in, nSize);
    edgeInRank.clear();
    for (int i = 0; i < nSize; i++) {
      DofEdge edge;
      std::map<int, ElementObjectData> data;
      SerUtil::deserialize(in, edge);
      deserialize(in, data);
      edgeInRank[edge] = data;
    }

    SerUtil::deserialize(in, nSize);
    faceInRank.clear();
    for (int i = 0; i < nSize; i++) {
      DofFace face;
      std::map<int, ElementObjectData> data;
      SerUtil::deserialize(in, face);
      deserialize(in, data);
      faceInRank[face] = data;
    }
  }


  void ElementObjects::serialize(std::ostream &out, std::vector<ElementObjectData>& elVec)
  {
    int nSize = elVec.size();
    SerUtil::serialize(out, nSize);
    for (int i = 0; i < nSize; i++)
      elVec[i].serialize(out);
  }


  void ElementObjects::deserialize(std::istream &in, std::vector<ElementObjectData>& elVec)
  {
    int nSize;
    SerUtil::deserialize(in, nSize);
    elVec.resize(nSize);
    for (int i = 0; i < nSize; i++)
      elVec[i].deserialize(in);
  }

  
  void ElementObjects::serialize(std::ostream &out, std::map<int, ElementObjectData>& data)
  {
    int nSize = data.size();
    SerUtil::serialize(out, nSize);
    for (std::map<int, ElementObjectData>::iterator it = data.begin();
	 it != data.end(); ++it) {
      SerUtil::serialize(out, it->first);
      it->second.serialize(out);
    }
  }

  
  void ElementObjects::deserialize(std::istream &in, std::map<int, ElementObjectData>& data)
  {
    int nSize;
    SerUtil::deserialize(in, nSize);
    for (int i = 0; i < nSize; i++) {
      int index;
      ElementObjectData elObj;
      SerUtil::deserialize(in, index);
      elObj.deserialize(in);

      data[index] = elObj;
    }
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
308
}