ElementObjectData.h 8.64 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

namespace AMDiS {

37
38
39
40
41
42
43
44
45
  using namespace std;

  template<typename T>
  struct PerBoundMap 
  {
    typedef map<pair<T, T>, BoundaryType> type;
    typedef typename type::iterator iterator;
  };

Thomas Witkowski's avatar
Thomas Witkowski committed
46
47
48
49
50
51
52
53
54
55
56
57
  struct ElementObjectData {
    ElementObjectData(int a = -1, int b = 0, BoundaryType c = INTERIOR)
      : elIndex(a),
	ithObject(b),
	boundaryType(c)
    {}
    
    int elIndex;
    
    int ithObject;
    
    BoundaryType boundaryType;
58
59


60
    void serialize(ostream &out) const
61
62
63
64
65
66
67
    {
      SerUtil::serialize(out, elIndex);
      SerUtil::serialize(out, ithObject);
      SerUtil::serialize(out, boundaryType);
    }


68
    void deserialize(istream &in)
69
70
71
72
73
74
    {
      SerUtil::deserialize(in, elIndex);
      SerUtil::deserialize(in, ithObject);
      SerUtil::deserialize(in, boundaryType);
    }

75
76
77
78
79
80
81
82
83
84
85
86
87
88

    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
89
90
91
92
93
94
  };



  class ElementObjects {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
95
96
    ElementObjects()
      : iterGeoPos(CENTER)
Thomas Witkowski's avatar
Thomas Witkowski committed
97
98
    {}

99
100

    void addVertex(Element *el, int ith, BoundaryType bound = INTERIOR)
Thomas Witkowski's avatar
Thomas Witkowski committed
101
    {
102
      DegreeOfFreedom vertex = el->getDof(ith, 0);
103
104
105
106
107
      int elIndex = el->getIndex();
      ElementObjectData elObj(elIndex, ith, bound);

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

110
111

    void addEdge(Element *el, int ith, BoundaryType bound = INTERIOR)
Thomas Witkowski's avatar
Thomas Witkowski committed
112
    {
113
      DofEdge edge = el->getEdge(ith);
114
115
116
117
118
119
120
121
122
123
      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)
    {
124
      DofFace face = el->getFace(ith);
125
126
127
128
129
      int elIndex = el->getIndex();
      ElementObjectData elObj(elIndex, ith, bound);

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

132
133

    void addElement(Element *el, BoundaryType bound = INTERIOR)
Thomas Witkowski's avatar
Thomas Witkowski committed
134
    {
135
136
137
138
139
140
141
142
      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
143
144
    }

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
    void addPeriodicVertex(pair<DegreeOfFreedom, DegreeOfFreedom> perVertex, 
			   BoundaryType bType)
    {
      periodicVertices[perVertex] = bType;
    }
    
    void addPeriodicEdge(pair<DofEdge, DofEdge> perEdge, BoundaryType bType)
    {
      periodicEdges[perEdge] = bType;
    }

    void addPeriodicFace(pair<DofFace, DofFace> perFace, BoundaryType bType)
    {
      periodicFaces[perFace] = bType;
    }
160

161
    void createRankData(map<int, int>& macroElementRankMap);
Thomas Witkowski's avatar
Thomas Witkowski committed
162

163

Thomas Witkowski's avatar
Thomas Witkowski committed
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
    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;
    }


224
    map<int, ElementObjectData>& getIterateData()
Thomas Witkowski's avatar
Thomas Witkowski committed
225
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
    {
      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;
      }
    }

265

Thomas Witkowski's avatar
Thomas Witkowski committed
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
    int getOwner(DegreeOfFreedom vertex)
    {
      return vertexOwner[vertex];
    }

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

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

281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297

    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));
    }


298
    vector<ElementObjectData>& getElements(DegreeOfFreedom vertex)
Thomas Witkowski's avatar
Thomas Witkowski committed
299
300
301
302
    {
      return vertexElements[vertex];
    }

303
    vector<ElementObjectData>& getElements(DofEdge edge)
Thomas Witkowski's avatar
Thomas Witkowski committed
304
305
306
307
    {
      return edgeElements[edge];
    }

308
    vector<ElementObjectData>& getElements(DofFace face)
Thomas Witkowski's avatar
Thomas Witkowski committed
309
310
311
312
    {
      return faceElements[face];
    }

313

314
    map<int, ElementObjectData>& getElementsInRank(DegreeOfFreedom vertex)
315
316
317
318
    {
      return vertexInRank[vertex];
    }

319
    map<int, ElementObjectData>& getElementsInRank(DofEdge edge)
320
321
322
323
    {
      return edgeInRank[edge];
    }

324
    map<int, ElementObjectData>& getElementsInRank(DofFace face)
325
326
327
328
    {
      return faceInRank[face];
    }

329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
    DegreeOfFreedom getVertexLocalMap(ElementObjectData &data)
    {
      return vertexLocalMap[data];
    }

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

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

344
    void serialize(ostream &out);
345

346
    void deserialize(istream &in);
347
348

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

351
    void deserialize(istream &in, vector<ElementObjectData>& elVec);
352

353
    void serialize(ostream &out, map<int, ElementObjectData>& data);
354

355
    void deserialize(istream &in, map<int, ElementObjectData>& data);
356

Thomas Witkowski's avatar
Thomas Witkowski committed
357
  private:
358
359
360
    map<DegreeOfFreedom, vector<ElementObjectData> > vertexElements;
    map<DofEdge, vector<ElementObjectData> > edgeElements;
    map<DofFace, vector<ElementObjectData> > faceElements;
Thomas Witkowski's avatar
Thomas Witkowski committed
361

362

363
364
365
    map<ElementObjectData, DegreeOfFreedom> vertexLocalMap;
    map<ElementObjectData, DofEdge> edgeLocalMap;
    map<ElementObjectData, DofFace> faceLocalMap;
366
367


368
369
370
    map<DegreeOfFreedom, int> vertexOwner;
    map<DofEdge, int> edgeOwner;
    map<DofFace, int> faceOwner;
Thomas Witkowski's avatar
Thomas Witkowski committed
371

372

373
374
375
    map<DegreeOfFreedom, map<int, ElementObjectData> > vertexInRank;
    map<DofEdge, map<int, ElementObjectData> > edgeInRank;
    map<DofFace, map<int, ElementObjectData> > faceInRank;
Thomas Witkowski's avatar
Thomas Witkowski committed
376

377
378
379
    map<DegreeOfFreedom, map<int, ElementObjectData> >::iterator vertexIter;
    map<DofEdge, map<int, ElementObjectData> >::iterator edgeIter;
    map<DofFace, map<int, ElementObjectData> >::iterator faceIter;
Thomas Witkowski's avatar
Thomas Witkowski committed
380
381

    GeoIndex iterGeoPos;
382
383
384
385
386
387

  public:
    // The following three data structures store periodic DOFs, edges and faces.
    PerBoundMap<DegreeOfFreedom>::type periodicVertices;
    PerBoundMap<DofEdge>::type periodicEdges;
    PerBoundMap<DofFace>::type periodicFaces;
Thomas Witkowski's avatar
Thomas Witkowski committed
388
389
390
391
392
  };

}

#endif