ElementObjectData.h 8.23 KB
Newer Older
Thomas Witkowski's avatar
Thomas Witkowski committed
1
2
3
4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
Thomas Witkowski's avatar
Thomas Witkowski committed
6
7
// ==                                                                        ==
// ============================================================================
8
9
10
11
12
13
14
15
16
17
18
19
//
// 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
20
21
22
23
24
25
26
27
28
29
30
31
32

/** \file ElementObjectData.h */

#ifndef AMDIS_ELEMENTOBJECTDATA_H
#define AMDIS_ELEMENTOBJECTDATA_H

#include <map>
#include <vector>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>

#include "Global.h"
#include "Boundary.h"
33
#include "Serializer.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

namespace AMDiS {

  struct ElementObjectData {
    ElementObjectData(int a = -1, int b = 0, BoundaryType c = INTERIOR)
      : elIndex(a),
	ithObject(b),
	boundaryType(c)
    {}
    
    int elIndex;
    
    int ithObject;
    
    BoundaryType boundaryType;
49
50


51
    void serialize(std::ostream &out) const
52
53
54
55
56
57
58
59
60
61
62
63
64
65
    {
      SerUtil::serialize(out, elIndex);
      SerUtil::serialize(out, ithObject);
      SerUtil::serialize(out, boundaryType);
    }


    void deserialize(std::istream &in)
    {
      SerUtil::deserialize(in, elIndex);
      SerUtil::deserialize(in, ithObject);
      SerUtil::deserialize(in, boundaryType);
    }

66
67
68
69
70
71
72
73
74
75
76
77
78
79

    bool operator==(ElementObjectData& cmp) const
    {
      return (elIndex == cmp.elIndex &&
	      ithObject == cmp.ithObject &&
	      boundaryType == cmp.boundaryType);
    }

    bool operator<(const ElementObjectData& rhs) const
    {
      return (elIndex < rhs.elIndex ||
	      (elIndex == rhs.elIndex &&
	       ithObject < rhs.ithObject));
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
80
81
82
83
84
85
  };



  class ElementObjects {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
86
87
    ElementObjects()
      : iterGeoPos(CENTER)
Thomas Witkowski's avatar
Thomas Witkowski committed
88
89
    {}

90
91

    void addVertex(Element *el, int ith, BoundaryType bound = INTERIOR)
Thomas Witkowski's avatar
Thomas Witkowski committed
92
    {
93
94
      //    DegreeOfFreedom vertex = el->getObject<DegreeOfFreedom>(ith);
      DegreeOfFreedom vertex = el->getDof(ith, 0);
95
96
97
98
99
      int elIndex = el->getIndex();
      ElementObjectData elObj(elIndex, ith, bound);

      vertexElements[vertex].push_back(elObj);
      vertexLocalMap[elObj] = vertex;
Thomas Witkowski's avatar
Thomas Witkowski committed
100
101
    }

102
103

    void addEdge(Element *el, int ith, BoundaryType bound = INTERIOR)
Thomas Witkowski's avatar
Thomas Witkowski committed
104
    {
105
106
      //      DofEdge edge = el->getObject<DofEdge>(ith);
      DofEdge edge = el->getEdge(ith);
107
108
109
110
111
112
113
114
115
116
      int elIndex = el->getIndex();
      ElementObjectData elObj(elIndex, ith, bound);

      edgeElements[edge].push_back(elObj);
      edgeLocalMap[elObj] = edge;
    }


    void addFace(Element *el, int ith, BoundaryType bound = INTERIOR)
    {
117
118
      //      DofFace face = el->getObject<DofFace>(ith);
      DofFace face = el->getFace(ith);
119
120
121
122
123
      int elIndex = el->getIndex();
      ElementObjectData elObj(elIndex, ith, bound);

      faceElements[face].push_back(elObj);
      faceLocalMap[elObj] = face;
Thomas Witkowski's avatar
Thomas Witkowski committed
124
125
    }

126
127

    void addElement(Element *el, BoundaryType bound = INTERIOR)
Thomas Witkowski's avatar
Thomas Witkowski committed
128
    {
129
130
131
132
133
134
135
136
      for (int i = 0; i < el->getGeo(VERTEX); i++)
	addVertex(el, i);

      for (int i = 0; i < el->getGeo(EDGE); i++)
	addEdge(el, i);      

      for (int i = 0; i < el->getGeo(FACE); i++)
	addFace(el, i);
Thomas Witkowski's avatar
Thomas Witkowski committed
137
138
    }

139

Thomas Witkowski's avatar
Thomas Witkowski committed
140
    void createRankData(std::map<int, int>& macroElementRankMap);
Thomas Witkowski's avatar
Thomas Witkowski committed
141

142

Thomas Witkowski's avatar
Thomas Witkowski committed
143
144
145
146
147
148
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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
    bool iterate(GeoIndex pos)
    {
      if (iterGeoPos == CENTER) {
	iterGeoPos = pos;
	switch (iterGeoPos) {
	case VERTEX:
	  vertexIter = vertexInRank.begin();
	  break;
	case EDGE:
	  edgeIter = edgeInRank.begin();
	  break;
	case FACE:
	  faceIter = faceInRank.begin();
	  break;
	default:
	  ERROR_EXIT("Not GeoIndex %d!\n", iterGeoPos);
	}
      } else {
	switch (iterGeoPos) {
	case VERTEX:
	  ++vertexIter;
	  break;
	case EDGE:
	  ++edgeIter;
	  break;
	case FACE:
	  ++faceIter;
	  break;
	default:
	  ERROR_EXIT("Not GeoIndex %d!\n", iterGeoPos);
	}
      }

      switch (iterGeoPos) {
      case VERTEX:
	if (vertexIter == vertexInRank.end()) {
	  iterGeoPos = CENTER;
	  return false;
	}
	break;
      case EDGE:
	if (edgeIter == edgeInRank.end()) {
	  iterGeoPos = CENTER;
	  return false;
	}
	break;
      case FACE:
	if (faceIter == faceInRank.end()) {
	  iterGeoPos = CENTER;
	  return false;
	}
	break;
      default:
	ERROR_EXIT("Should not happen!\n");	
      }

      return true;
    }


    std::map<int, ElementObjectData>& getIterateData()
    {
      switch (iterGeoPos) {
      case VERTEX:
	return vertexIter->second;
	break;
      case EDGE:
	return edgeIter->second;
	break;
      case FACE:
	return faceIter->second;
	break;
      default:
	ERROR_EXIT("Should not happen!\n");

	// Will never be reached, just to avoid compiler warnings.
	return faceIter->second;
      }
    }


    int getIterateOwner()
    {
      switch (iterGeoPos) {
      case VERTEX:
	return vertexOwner[vertexIter->first];
	break;
      case EDGE:
	return edgeOwner[edgeIter->first];
	break;
      case FACE:
	return faceOwner[faceIter->first];
	break;
      default:
	ERROR_EXIT("Should not happen!\n");

	// Will never be reached, just to avoid compiler warnings.
	return -1;
      }
    }

244

Thomas Witkowski's avatar
Thomas Witkowski committed
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
    int getOwner(DegreeOfFreedom vertex)
    {
      return vertexOwner[vertex];
    }

    int getOwner(DofEdge edge)
    {
      return edgeOwner[edge];
    }

    int getOwner(DofFace face)
    {
      return faceOwner[face];
    }

260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

    int isInRank(DegreeOfFreedom vertex, int rank)
    {
      return (vertexInRank[vertex].count(rank));
    }

    int isInRank(DofEdge edge, int rank)
    {
      return (edgeInRank[edge].count(rank));
    }

    int isInRank(DofFace face, int rank)
    {
      return (faceInRank[face].count(rank));
    }


Thomas Witkowski's avatar
Thomas Witkowski committed
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
    std::vector<ElementObjectData>& getElements(DegreeOfFreedom vertex)
    {
      return vertexElements[vertex];
    }

    std::vector<ElementObjectData>& getElements(DofEdge edge)
    {
      return edgeElements[edge];
    }

    std::vector<ElementObjectData>& getElements(DofFace face)
    {
      return faceElements[face];
    }

292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

    std::map<int, ElementObjectData>& getElementsInRank(DegreeOfFreedom vertex)
    {
      return vertexInRank[vertex];
    }

    std::map<int, ElementObjectData>& getElementsInRank(DofEdge edge)
    {
      return edgeInRank[edge];
    }

    std::map<int, ElementObjectData>& getElementsInRank(DofFace face)
    {
      return faceInRank[face];
    }

308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
    DegreeOfFreedom getVertexLocalMap(ElementObjectData &data)
    {
      return vertexLocalMap[data];
    }

    DofEdge getEdgeLocalMap(ElementObjectData &data)
    {
      return edgeLocalMap[data];
    }

    DofFace getFaceLocalMap(ElementObjectData &data)
    {
      return faceLocalMap[data];
    }

323
324
325
326
327
328
329
330
331
332
333
334
335
    void serialize(std::ostream &out);

    void deserialize(std::istream &in);

  private:
    void serialize(std::ostream &out, std::vector<ElementObjectData>& elVec);

    void deserialize(std::istream &in, std::vector<ElementObjectData>& elVec);

    void serialize(std::ostream &out, std::map<int, ElementObjectData>& data);

    void deserialize(std::istream &in, std::map<int, ElementObjectData>& data);

Thomas Witkowski's avatar
Thomas Witkowski committed
336
337
338
339
340
  private:
    std::map<DegreeOfFreedom, std::vector<ElementObjectData> > vertexElements;
    std::map<DofEdge, std::vector<ElementObjectData> > edgeElements;
    std::map<DofFace, std::vector<ElementObjectData> > faceElements;

341
342
343
344
345
346

    std::map<ElementObjectData, DegreeOfFreedom> vertexLocalMap;
    std::map<ElementObjectData, DofEdge> edgeLocalMap;
    std::map<ElementObjectData, DofFace> faceLocalMap;


Thomas Witkowski's avatar
Thomas Witkowski committed
347
348
349
350
    std::map<DegreeOfFreedom, int> vertexOwner;
    std::map<DofEdge, int> edgeOwner;
    std::map<DofFace, int> faceOwner;

351

Thomas Witkowski's avatar
Thomas Witkowski committed
352
353
354
355
    std::map<DegreeOfFreedom, std::map<int, ElementObjectData> > vertexInRank;
    std::map<DofEdge, std::map<int, ElementObjectData> > edgeInRank;
    std::map<DofFace, std::map<int, ElementObjectData> > faceInRank;

356

Thomas Witkowski's avatar
Thomas Witkowski committed
357
358
359
360
361
362
363
364
365
366
    std::map<DegreeOfFreedom, std::map<int, ElementObjectData> >::iterator vertexIter;
    std::map<DofEdge, std::map<int, ElementObjectData> >::iterator edgeIter;
    std::map<DofFace, std::map<int, ElementObjectData> >::iterator faceIter;

    GeoIndex iterGeoPos;
  };

}

#endif