XdmfTopologyType.cpp 25.6 KB
Newer Older
Kenneth Leiter's avatar
Kenneth Leiter committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*****************************************************************************/
/*                                    XDMF                                   */
/*                       eXtensible Data Model and Format                    */
/*                                                                           */
/*  Id : XdmfTopologyType.cpp                                                */
/*                                                                           */
/*  Author:                                                                  */
/*     Kenneth Leiter                                                        */
/*     kenneth.leiter@arl.army.mil                                           */
/*     US Army Research Laboratory                                           */
/*     Aberdeen Proving Ground, MD                                           */
/*                                                                           */
/*     Copyright @ 2011 US Army Research Laboratory                          */
/*     All Rights Reserved                                                   */
/*     See Copyright.txt for details                                         */
/*                                                                           */
/*     This software is distributed WITHOUT ANY WARRANTY; without            */
/*     even the implied warranty of MERCHANTABILITY or FITNESS               */
/*     FOR A PARTICULAR PURPOSE.  See the above copyright notice             */
/*     for more information.                                                 */
/*                                                                           */
/*****************************************************************************/
23

24
#include <cctype>
25
#include <sstream>
26
#include <utility>
27
#include "XdmfError.hpp"
28
#include "XdmfTopologyType.hpp"
29
30

// Supported XdmfTopologyTypes
31
shared_ptr<const XdmfTopologyType>
32
XdmfTopologyType::NoTopologyType()
33
{
34
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
35
  static shared_ptr<const XdmfTopologyType>
36
    p(new XdmfTopologyType(0, 0, faces, 0, "NoTopology", NoCellType, 0x0));
37
  return p;
38
39
}

40
shared_ptr<const XdmfTopologyType>
41
XdmfTopologyType::Polyvertex()
42
{
43
44
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
45
  static shared_ptr<const XdmfTopologyType>
46
    p(new XdmfTopologyType(1, 0, faces, 0, "Polyvertex", Linear, 0x1));
47
  return p;
48
49
}

50
shared_ptr<const XdmfTopologyType>
51
XdmfTopologyType::Polyline(const unsigned int nodesPerElement)
52
{
53
54
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
55
56
57
58
59
60
61
62
  static std::map<unsigned int, shared_ptr<const XdmfTopologyType> >
    previousTypes;
  std::map<unsigned int, shared_ptr<const XdmfTopologyType> >::const_iterator
    type = previousTypes.find(nodesPerElement);
  if(type != previousTypes.end()) {
    return type->second;
  }
  shared_ptr<const XdmfTopologyType>
63
    p(new XdmfTopologyType(nodesPerElement, 0, faces, nodesPerElement - 1, 
64
                           "Polyline", Linear, 0x2));
65
  previousTypes[nodesPerElement] = p;
66
  return p;
67
68
}

69
shared_ptr<const XdmfTopologyType>
70
XdmfTopologyType::Polygon(const unsigned int nodesPerElement)
71
{
72
73
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
74
  static std::map<unsigned int, shared_ptr<const XdmfTopologyType> >
75
    previousTypes;
76
  std::map<unsigned int, shared_ptr<const XdmfTopologyType> >::const_iterator
77
78
79
80
    type = previousTypes.find(nodesPerElement);
  if(type != previousTypes.end()) {
    return type->second;
  }
81
  shared_ptr<const XdmfTopologyType>
82
    p(new XdmfTopologyType(nodesPerElement, 1, faces, nodesPerElement,
83
                           "Polygon", Linear, 0x3));
84
85
  previousTypes[nodesPerElement] = p;
  return p;
86
87
}

88
shared_ptr<const XdmfTopologyType>
89
XdmfTopologyType::Triangle()
90
{
91
92
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
93
  static shared_ptr<const XdmfTopologyType>
94
    p(new XdmfTopologyType(3, 1, faces, 3, "Triangle", Linear, 0x4));
95
  return p;
96
97
}

98
shared_ptr<const XdmfTopologyType>
99
XdmfTopologyType::Quadrilateral()
100
{
101
102
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
103
  static shared_ptr<const XdmfTopologyType>
104
    p(new XdmfTopologyType(4, 1, faces, 4, "Quadrilateral", Linear, 0x5));
105
  return p;
106
107
}

108
shared_ptr<const XdmfTopologyType>
109
XdmfTopologyType::Tetrahedron()
110
{
111
112
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::Triangle());
113
  static shared_ptr<const XdmfTopologyType>
114
    p(new XdmfTopologyType(4, 4, faces, 6, "Tetrahedron", Linear, 0x6));
115
  return p;
116
117
}

118
shared_ptr<const XdmfTopologyType>
119
XdmfTopologyType::Pyramid()
120
{
121
122
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
123
  static shared_ptr<const XdmfTopologyType>
124
    p(new XdmfTopologyType(5, 5, faces, 8, "Pyramid", Linear, 0x7));
125
  return p;
126
127
}

128
shared_ptr<const XdmfTopologyType>
129
XdmfTopologyType::Wedge()
130
{
131
132
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
133
  static shared_ptr<const XdmfTopologyType>
134
    p(new XdmfTopologyType(6, 5, faces, 9, "Wedge", Linear, 0x8));
135
  return p;
136
137
}

138
shared_ptr<const XdmfTopologyType>
139
XdmfTopologyType::Hexahedron()
140
{
141
142
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::Quadrilateral());
143
  static shared_ptr<const XdmfTopologyType>
144
    p(new XdmfTopologyType(8, 6, faces, 12, "Hexahedron", Linear, 0x9));
145
  return p;
146
147
}

148
shared_ptr<const XdmfTopologyType>
149
XdmfTopologyType::Edge_3()
150
{
151
152
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
153
  static shared_ptr<const XdmfTopologyType>
154
    p(new XdmfTopologyType(3, 0, faces, 1, "Edge_3", Quadratic, 0x22));
155
  return p;
156
157
}

158
shared_ptr<const XdmfTopologyType>
159
XdmfTopologyType::Triangle_6()
160
{
161
162
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
163
  static shared_ptr<const XdmfTopologyType>
164
    p(new XdmfTopologyType(6, 1, faces, 3, "Triangle_6", Quadratic, 0x24));
165
  return p;
166
167
}

168
shared_ptr<const XdmfTopologyType>
169
XdmfTopologyType::Quadrilateral_8()
170
{
171
172
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
173
  static shared_ptr<const XdmfTopologyType>
174
    p(new XdmfTopologyType(8, 1, faces, 4, "Quadrilateral_8", Quadratic, 0x25));
175
  return p;
176
177
}

178
shared_ptr<const XdmfTopologyType>
179
XdmfTopologyType::Quadrilateral_9()
180
{
181
182
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
183
  static shared_ptr<const XdmfTopologyType>
184
    p(new XdmfTopologyType(9, 1, faces, 4, "Quadrilateral_9", Quadratic, 0x23));
185
  return p;
186
187
}

188
shared_ptr<const XdmfTopologyType>
189
XdmfTopologyType::Tetrahedron_10()
190
{
191
192
193
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
  faces.push_back(XdmfTopologyType::Triangle_6());
194
  static shared_ptr<const XdmfTopologyType>
195
    p(new XdmfTopologyType(10, 4, faces, 6, "Tetrahedron_10", Quadratic, 0x26));
196
  return p;
197
198
}

199
shared_ptr<const XdmfTopologyType>
200
XdmfTopologyType::Pyramid_13()
201
{
202
203
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
204
  static shared_ptr<const XdmfTopologyType>
205
    p(new XdmfTopologyType(13, 5, faces, 8, "Pyramid_13", Quadratic, 0x27));
206
  return p;
207
208
}

209
shared_ptr<const XdmfTopologyType>
210
XdmfTopologyType::Wedge_15()
211
{
212
213
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
214
  static shared_ptr<const XdmfTopologyType>
215
    p(new XdmfTopologyType(15, 5, faces, 9, "Wedge_15", Quadratic, 0x28));
216
  return p;
217
218
}

219
shared_ptr<const XdmfTopologyType>
220
XdmfTopologyType::Wedge_18()
221
{
222
223
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
224
  static shared_ptr<const XdmfTopologyType>
225
    p(new XdmfTopologyType(18, 5, faces, 9, "Wedge_18", Quadratic, 0x29));
226
  return p;
227
228
}

229
shared_ptr<const XdmfTopologyType>
230
XdmfTopologyType::Hexahedron_20()
231
{
232
233
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::Quadrilateral_8());
234
  static shared_ptr<const XdmfTopologyType>
235
    p(new XdmfTopologyType(20, 6, faces, 12, "Hexahedron_20", Quadratic, 0x30));
236
  return p;
237
238
}

239
shared_ptr<const XdmfTopologyType>
240
XdmfTopologyType::Hexahedron_24()
241
{
242
243
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
244
  static shared_ptr<const XdmfTopologyType>
245
    p(new XdmfTopologyType(24, 6, faces, 12, "Hexahedron_24", Quadratic, 0x31));
246
  return p;
247
248
}

249
shared_ptr<const XdmfTopologyType>
250
XdmfTopologyType::Hexahedron_27()
251
{
252
253
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::Quadrilateral_9());
254
  static shared_ptr<const XdmfTopologyType>
255
    p(new XdmfTopologyType(27, 6, faces, 12, "Hexahedron_27", Quadratic, 0x32));
256
  return p;
257
258
}

259
shared_ptr<const XdmfTopologyType>
260
XdmfTopologyType::Hexahedron_64()
261
{
262
263
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
264
  static shared_ptr<const XdmfTopologyType>
265
    p(new XdmfTopologyType(64, 6, faces, 12, "Hexahedron_64", Cubic, 0x33));
266
  return p;
267
268
}

269
shared_ptr<const XdmfTopologyType>
270
XdmfTopologyType::Hexahedron_125()
271
{
272
273
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
274
  static shared_ptr<const XdmfTopologyType>
275
    p(new XdmfTopologyType(125, 6, faces, 12, "Hexahedron_125", Quartic, 0x34));
276
  return p;
277
278
}

279
shared_ptr<const XdmfTopologyType>
280
XdmfTopologyType::Hexahedron_216()
281
{
282
283
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
284
  static shared_ptr<const XdmfTopologyType>
285
    p(new XdmfTopologyType(216, 6, faces, 12, "Hexahedron_216", Quintic, 0x35));
286
  return p;
287
288
}

289

290
shared_ptr<const XdmfTopologyType>
291
XdmfTopologyType::Hexahedron_343()
292
{
293
294
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
295
  static shared_ptr<const XdmfTopologyType>
296
    p(new XdmfTopologyType(343, 6, faces, 12, "Hexahedron_343", Sextic, 0x36));
297
  return p;
298
299
}

300
301
302
303

shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_512()
{
304
305
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
306
  static shared_ptr<const XdmfTopologyType>
307
    p(new XdmfTopologyType(512, 6, faces, 12, "Hexahedron_512", Septic, 0x37));
308
309
310
311
312
313
314
  return p;
}


shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_729()
{
315
316
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
317
  static shared_ptr<const XdmfTopologyType>
318
    p(new XdmfTopologyType(729, 6, faces, 12, "Hexahedron_729", Octic, 0x38));
319
320
321
322
323
324
325
  return p;
}


shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_1000()
{
326
327
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
328
  static shared_ptr<const XdmfTopologyType>
329
    p(new XdmfTopologyType(1000, 6, faces, 12, "Hexahedron_1000", Nonic, 0x39));
330
331
332
333
334
335
  return p;
}

shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_1331()
{
336
337
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
338
  static shared_ptr<const XdmfTopologyType>
339
    p(new XdmfTopologyType(1331, 6, faces, 12, "Hexahedron_1331", Decic, 0x40));
340
341
342
  return p;
}

343
344
345
shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_64()
{
346
347
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
348
  static shared_ptr<const XdmfTopologyType>
349
    p(new XdmfTopologyType(64, 6, faces, 12, "Hexahedron_Spectral_64", Cubic, 0x41));
350
351
352
353
354
355
  return p;
}

shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_125()
{
356
357
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
358
  static shared_ptr<const XdmfTopologyType>
359
    p(new XdmfTopologyType(125, 6, faces, 12, 
360
361
362
363
364
365
366
                           "Hexahedron_Spectral_125", Quartic, 0x42));
  return p;
}

shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_216()
{
367
368
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
369
  static shared_ptr<const XdmfTopologyType>
370
    p(new XdmfTopologyType(216, 6, faces, 12, 
371
372
373
374
375
376
377
378
                           "Hexahedron_Spectral_216", Quintic, 0x43));
  return p;
}


shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_343()
{
379
380
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
381
  static shared_ptr<const XdmfTopologyType>
382
    p(new XdmfTopologyType(343, 6, faces, 12, 
383
384
385
386
387
388
389
390
                           "Hexahedron_Spectral_343", Sextic, 0x44));
  return p;
}


shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_512()
{
391
392
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
393
  static shared_ptr<const XdmfTopologyType>
394
    p(new XdmfTopologyType(512, 6, faces, 12, 
395
396
397
398
399
400
401
402
                           "Hexahedron_Spectral_512", Septic, 0x45));
  return p;
}


shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_729()
{
403
404
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
405
  static shared_ptr<const XdmfTopologyType>
406
    p(new XdmfTopologyType(729, 6, faces, 12, 
407
408
409
410
411
412
413
414
                           "Hexahedron_Spectral_729", Octic, 0x46));
  return p;
}


shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_1000()
{
415
416
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
417
  static shared_ptr<const XdmfTopologyType>
418
    p(new XdmfTopologyType(1000, 6, faces, 12, 
419
420
421
422
423
424
425
                           "Hexahedron_Spectral_1000", Nonic, 0x47));
  return p;
}

shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_1331()
{
426
427
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
428
  static shared_ptr<const XdmfTopologyType>
429
    p(new XdmfTopologyType(1331, 6, faces, 12, 
430
431
432
                           "Hexahedron_Spectral_1331", Decic, 0x48));
  return p;
}
433

434
shared_ptr<const XdmfTopologyType>
435
XdmfTopologyType::Mixed()
436
{
437
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
438
  static shared_ptr<const XdmfTopologyType>
439
    p(new XdmfTopologyType(0, 0, faces, 0, "Mixed", Arbitrary, 0x70));
440
  return p;
441
442
}

443
shared_ptr<const XdmfTopologyType>
444
445
446
447
448
449
450
451
XdmfTopologyType::New(const unsigned int id)
{
  if(id == XdmfTopologyType::NoTopologyType()->getID()) {
    return XdmfTopologyType::NoTopologyType();
  }
  else if(id == XdmfTopologyType::Polyvertex()->getID()) {
    return XdmfTopologyType::Polyvertex();
  }
452
453
  else if(id == XdmfTopologyType::Polyline(0)->getID()) {
    return XdmfTopologyType::Polyline(0);
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
  }
  else if(id == XdmfTopologyType::Polygon(0)->getID()) {
    return XdmfTopologyType::Polygon(0);
  }
  else if(id == XdmfTopologyType::Triangle()->getID()) {
    return XdmfTopologyType::Triangle();
  }
  else if(id == XdmfTopologyType::Quadrilateral()->getID()) {
    return XdmfTopologyType::Quadrilateral();
  }
  else if(id == XdmfTopologyType::Tetrahedron()->getID()) {
    return XdmfTopologyType::Tetrahedron();
  }
  else if(id == XdmfTopologyType::Pyramid()->getID()) {
    return XdmfTopologyType::Pyramid();
  }
  else if(id == XdmfTopologyType::Wedge()->getID()) {
    return XdmfTopologyType::Wedge();
  }
  else if(id == XdmfTopologyType::Hexahedron()->getID()) {
    return XdmfTopologyType::Hexahedron();
  }
  else if(id == XdmfTopologyType::Edge_3()->getID()) {
    return XdmfTopologyType::Edge_3();
  }
  else if(id == XdmfTopologyType::Triangle_6()->getID()) {
    return XdmfTopologyType::Triangle_6();
  }
  else if(id == XdmfTopologyType::Quadrilateral_8()->getID()) {
    return XdmfTopologyType::Quadrilateral_8();
  }
  else if(id == XdmfTopologyType::Quadrilateral_9()->getID()) {
    return XdmfTopologyType::Quadrilateral_9();
  }
  else if(id == XdmfTopologyType::Tetrahedron_10()->getID()) {
    return XdmfTopologyType::Tetrahedron_10();
  }
  else if(id == XdmfTopologyType::Pyramid_13()->getID()) {
    return XdmfTopologyType::Pyramid_13();
  }
  else if(id == XdmfTopologyType::Wedge_15()->getID()) {
    return XdmfTopologyType::Wedge_15();
  }
  else if(id == XdmfTopologyType::Wedge_18()->getID()) {
    return XdmfTopologyType::Wedge_18();
  }
  else if(id == XdmfTopologyType::Hexahedron_20()->getID()) {
    return XdmfTopologyType::Hexahedron_20();
  }
  else if(id == XdmfTopologyType::Hexahedron_24()->getID()) {
    return XdmfTopologyType::Hexahedron_24();
  }
  else if(id == XdmfTopologyType::Hexahedron_27()->getID()) {
    return XdmfTopologyType::Hexahedron_27();
  }
  else if(id == XdmfTopologyType::Hexahedron_64()->getID()) {
    return XdmfTopologyType::Hexahedron_64();
  }
  else if(id == XdmfTopologyType::Hexahedron_125()->getID()) {
    return XdmfTopologyType::Hexahedron_125();
  }
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
  else if(id == XdmfTopologyType::Hexahedron_216()->getID()) {
    return XdmfTopologyType::Hexahedron_216();
  }
  else if(id == XdmfTopologyType::Hexahedron_343()->getID()) {
    return XdmfTopologyType::Hexahedron_343();
  }
  else if(id == XdmfTopologyType::Hexahedron_512()->getID()) {
    return XdmfTopologyType::Hexahedron_512();
  }
  else if(id == XdmfTopologyType::Hexahedron_729()->getID()) {
    return XdmfTopologyType::Hexahedron_729();
  }
  else if(id == XdmfTopologyType::Hexahedron_1000()->getID()) {
    return XdmfTopologyType::Hexahedron_1000();
  }
  else if(id == XdmfTopologyType::Hexahedron_1331()->getID()) {
    return XdmfTopologyType::Hexahedron_1331();
532
  }
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
  else if(id == XdmfTopologyType::Hexahedron_Spectral_64()->getID()) {
    return XdmfTopologyType::Hexahedron_Spectral_64();
  }
  else if(id == XdmfTopologyType::Hexahedron_Spectral_125()->getID()) {
    return XdmfTopologyType::Hexahedron_Spectral_125();
  }
  else if(id == XdmfTopologyType::Hexahedron_Spectral_216()->getID()) {
    return XdmfTopologyType::Hexahedron_Spectral_216();
  }
  else if(id == XdmfTopologyType::Hexahedron_Spectral_343()->getID()) {
    return XdmfTopologyType::Hexahedron_Spectral_343();
  }
  else if(id == XdmfTopologyType::Hexahedron_Spectral_512()->getID()) {
    return XdmfTopologyType::Hexahedron_Spectral_512();
  }
  else if(id == XdmfTopologyType::Hexahedron_Spectral_729()->getID()) {
    return XdmfTopologyType::Hexahedron_Spectral_729();
  }
  else if(id == XdmfTopologyType::Hexahedron_Spectral_1000()->getID()) {
    return XdmfTopologyType::Hexahedron_Spectral_1000();
  }
  else if(id == XdmfTopologyType::Hexahedron_Spectral_1331()->getID()) {
    return XdmfTopologyType::Hexahedron_Spectral_1331();
  }
557
558
559
  else if(id == XdmfTopologyType::Mixed()->getID()) {
    return XdmfTopologyType::Mixed();
  }
560
  return shared_ptr<const XdmfTopologyType>();
561
562
}

563
XdmfTopologyType::XdmfTopologyType(const unsigned int nodesPerElement,
564
                                   const unsigned int facesPerElement,
565
                                   const std::vector<shared_ptr<const XdmfTopologyType> > & faces,
566
                                   const unsigned int edgesPerElement,
567
568
569
570
                                   const std::string & name,
                                   const CellType cellType,
                                   const unsigned int id) :
  mCellType(cellType),
571
572
  mEdgesPerElement(edgesPerElement),
  mFacesPerElement(facesPerElement),
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
573
  mFaces(faces),
574
575
576
  mID(id),
  mName(name),
  mNodesPerElement(nodesPerElement)
577
578
{
}
579

580
581
582
583
XdmfTopologyType::~XdmfTopologyType()
{
}

584
shared_ptr<const XdmfTopologyType>
585
586
587
588
589
590
591
XdmfTopologyType::New(const std::map<std::string, std::string> & itemProperties)
{
  std::map<std::string, std::string>::const_iterator type =
    itemProperties.find("Type");
  if(type == itemProperties.end()) {
    type = itemProperties.find("TopologyType");
  }
592
  if(type == itemProperties.end()) {
593
594
595
596
597
598
599
600
    try {
      XdmfError::message(XdmfError::FATAL, 
                         "Neither 'Type' nor 'TopologyType' found in "
                         "itemProperties in XdmfTopologyType::New");
    }
    catch (XdmfError e) {
      throw e;
    }
601
602
603
604
605
606
  }
  std::string typeVal = type->second;
  std::transform(typeVal.begin(),
                 typeVal.end(),
                 typeVal.begin(),
                 (int(*)(int))toupper);
607
608
609

  std::map<std::string, std::string>::const_iterator nodesPerElement =
    itemProperties.find("NodesPerElement");
610
611
612
613
614
615
616
617
618
619

  if(typeVal.compare("NOTOPOLOGY") == 0) {
    return NoTopologyType();
  }
  else if(typeVal.compare("POLYVERTEX") == 0) {
    return Polyvertex();
  }
  else if(typeVal.compare("POLYLINE") == 0) {
    if(nodesPerElement != itemProperties.end()) {
      return Polyline(atoi(nodesPerElement->second.c_str()));
620
    }
621
622
623
624
625
626
627
628
    try {
      XdmfError::message(XdmfError::FATAL, 
                           "'NodesPerElement' not in itemProperties and type "
                         "'POLYLINE' selected in XdmfTopologyType::New");
    }
    catch (XdmfError e) {
      throw e;
    }
629
630
631
632
  }
  else if(typeVal.compare("POLYGON") == 0) {
    if(nodesPerElement != itemProperties.end()) {
      return Polygon(atoi(nodesPerElement->second.c_str()));
633
    }
634
635
636
637
638
639
640
641
    try {
      XdmfError::message(XdmfError::FATAL, 
                         "'NodesPerElement' not in itemProperties and type "
                         "'POLYGON' selected in XdmfTopologyType::New");
    }
    catch (XdmfError e) {
      throw e;
    }
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
  }
  else if(typeVal.compare("TRIANGLE") == 0) {
    return Triangle();
  }
  else if(typeVal.compare("QUADRILATERAL") == 0) {
    return Quadrilateral();
  }
  else if(typeVal.compare("TETRAHEDRON") == 0) {
    return Tetrahedron();
  }
  else if(typeVal.compare("PYRAMID") == 0) {
    return Pyramid();
  }
  else if(typeVal.compare("WEDGE") == 0) {
    return Wedge();
  }
  else if(typeVal.compare("HEXAHEDRON") == 0) {
    return Hexahedron();
  }
  else if(typeVal.compare("EDGE_3") == 0) {
    return Edge_3();
  }
  else if(typeVal.compare("TRIANGLE_6") == 0) {
    return Triangle_6();
  }
  else if(typeVal.compare("QUADRILATERAL_8") == 0) {
    return Quadrilateral_8();
  }
  else if(typeVal.compare("TETRAHEDRON_10") == 0) {
    return Tetrahedron_10();
  }
  else if(typeVal.compare("PYRAMID_13") == 0) {
    return Pyramid_13();
675
  }
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
  else if(typeVal.compare("WEDGE_15") == 0) {
    return Wedge_15();
  }
  else if(typeVal.compare("HEXAHEDRON_20") == 0) {
    return Hexahedron_20();
  }
  else if(typeVal.compare("HEXAHEDRON_24") == 0) {
    return Hexahedron_24();
  }
  else if(typeVal.compare("HEXAHEDRON_27") == 0) {
    return Hexahedron_27();
  }
  else if(typeVal.compare("HEXAHEDRON_64") == 0) {
    return Hexahedron_64();
  }
  else if(typeVal.compare("HEXAHEDRON_125") == 0) {
    return Hexahedron_125();
  }
  else if(typeVal.compare("HEXAHEDRON_216") == 0) {
    return Hexahedron_216();
  }
  else if(typeVal.compare("HEXAHEDRON_343") == 0) {
    return Hexahedron_343();
  }
  else if(typeVal.compare("HEXAHEDRON_512") == 0) {
    return Hexahedron_512();
  }
  else if(typeVal.compare("HEXAHEDRON_729") == 0) {
    return Hexahedron_729();
  }
  else if(typeVal.compare("HEXAHEDRON_1000") == 0) {
    return Hexahedron_1000();
  }
  else if(typeVal.compare("HEXAHEDRON_1331") == 0) {
    return Hexahedron_1331();
  }
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
  else if(typeVal.compare("HEXAHEDRON_SPECTRAL_64") == 0) {
    return Hexahedron_Spectral_64();
  }
  else if(typeVal.compare("HEXAHEDRON_SPECTRAL_125") == 0) {
    return Hexahedron_Spectral_125();
  }
  else if(typeVal.compare("HEXAHEDRON_SPECTRAL_216") == 0) {
    return Hexahedron_Spectral_216();
  }
  else if(typeVal.compare("HEXAHEDRON_SPECTRAL_343") == 0) {
    return Hexahedron_Spectral_343();
  }
  else if(typeVal.compare("HEXAHEDRON_SPECTRAL_512") == 0) {
    return Hexahedron_Spectral_512();
  }
  else if(typeVal.compare("HEXAHEDRON_SPECTRAL_729") == 0) {
    return Hexahedron_Spectral_729();
  }
  else if(typeVal.compare("HEXAHEDRON_SPECTRAL_1000") == 0) {
    return Hexahedron_Spectral_1000();
  }
  else if(typeVal.compare("HEXAHEDRON_SPECTRAL_1331") == 0) {
    return Hexahedron_Spectral_1331();
  }
736
737
738
739
  else if(typeVal.compare("MIXED") == 0) {
    return Mixed();
  }
  
740
741
742
743
744
745
746
  try {
    XdmfError::message(XdmfError::FATAL, 
                       "Invalid Type selected in XdmfTopologyType::New");
  }
  catch (XdmfError e) {
    throw e;
  }
747

748
  return shared_ptr<const XdmfTopologyType>();
749
750
751
752
753
754
755
756
}

XdmfTopologyType::CellType
XdmfTopologyType::getCellType() const
{
  return mCellType;
}

757
758
759
760
761
762
unsigned int
XdmfTopologyType::getEdgesPerElement() const
{
  return mEdgesPerElement;
}

763
764
765
766
767
768
769
770
771
772
773
shared_ptr<const XdmfTopologyType>
XdmfTopologyType::getFaceType()
{
  if (mFaces.size() == 0) {
    return XdmfTopologyType::NoTopologyType();
  }
  else {
    return mFaces[0];
  }
}

774
775
776
777
778
779
unsigned int
XdmfTopologyType::getFacesPerElement() const
{
  return mFacesPerElement;
}

780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
unsigned int
XdmfTopologyType::getID() const
{
  return mID;
}

std::string
XdmfTopologyType::getName() const
{
  return mName;
}

unsigned int
XdmfTopologyType::getNodesPerElement() const
{
  return mNodesPerElement;
}

void
XdmfTopologyType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
801
  collectedProperties.insert(std::make_pair("Type", this->getName()));
802
  if(mName.compare("Polygon") == 0 || mName.compare("Polyline") == 0) {
803
804
    std::stringstream nodesPerElement;
    nodesPerElement << mNodesPerElement;
805
806
    collectedProperties.insert(std::make_pair("NodesPerElement",
                                              nodesPerElement.str()));
807
  }
808
}