XdmfTopologyType.cpp 39.7 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 <cmath>
26
#include <sstream>
27
#include <string.h>
28
#include <utility>
29
#include <vector>
30

31
#include "XdmfError.hpp"
32
#include "XdmfTopologyType.hpp"
33
#include "XdmfStringUtils.hpp"
34

35 36
std::map<std::string, shared_ptr<const XdmfTopologyType>(*)()> XdmfTopologyType::mTopologyDefinitions;

37
// Supported XdmfTopologyTypes
38
shared_ptr<const XdmfTopologyType>
39
XdmfTopologyType::NoTopologyType()
40
{
41
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
42
  static shared_ptr<const XdmfTopologyType>
43 44 45 46 47 48 49 50 51
  /* XdmfTopologyType(numPoints, // if variable will be read from xmf file
                      numFaces, 
                      faces, 
                      numConnectingLines,
                      TopologyName,
                      Linear/Quadratic/Arbitrary/Structured,
                      CellType)
    Cell type is denoted by the number after the x
    */
52
    p(new XdmfTopologyType(0, 0, faces, 0, "NoTopology", NoCellType, 0x0));
53
  return p;
54 55
}

56
shared_ptr<const XdmfTopologyType>
57
XdmfTopologyType::Polyvertex()
58
{
59 60
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
61
  static shared_ptr<const XdmfTopologyType>
62
    p(new XdmfTopologyType(1, 0, faces, 0, "Polyvertex", Linear, 0x1));
63
  return p;
64 65
}

66
shared_ptr<const XdmfTopologyType>
67
XdmfTopologyType::Polyline(const unsigned int nodesPerElement)
68
{
69 70
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
71 72 73 74 75 76 77 78
  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>
79
    p(new XdmfTopologyType(nodesPerElement, 0, faces, nodesPerElement - 1,
80
                           "Polyline", Linear, 0x2));
81
  previousTypes[nodesPerElement] = p;
82
  return p;
83 84
}

85
shared_ptr<const XdmfTopologyType>
86
XdmfTopologyType::Polygon(const unsigned int nodesPerElement)
87
{
88 89
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
90
  static std::map<unsigned int, shared_ptr<const XdmfTopologyType> >
91
    previousTypes;
92
  std::map<unsigned int, shared_ptr<const XdmfTopologyType> >::const_iterator
93 94 95 96
    type = previousTypes.find(nodesPerElement);
  if(type != previousTypes.end()) {
    return type->second;
  }
97
  shared_ptr<const XdmfTopologyType>
98
    p(new XdmfTopologyType(nodesPerElement, 1, faces, nodesPerElement,
99
                           "Polygon", Linear, 0x3));
100 101
  previousTypes[nodesPerElement] = p;
  return p;
102 103
}

104
shared_ptr<const XdmfTopologyType>
105
XdmfTopologyType::Triangle()
106
{
107 108
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
109
  static shared_ptr<const XdmfTopologyType>
110
    p(new XdmfTopologyType(3, 1, faces, 3, "Triangle", Linear, 0x4));
111
  return p;
112 113
}

114
shared_ptr<const XdmfTopologyType>
115
XdmfTopologyType::Quadrilateral()
116
{
117 118
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
119
  static shared_ptr<const XdmfTopologyType>
120
    p(new XdmfTopologyType(4, 1, faces, 4, "Quadrilateral", Linear, 0x5));
121
  return p;
122 123
}

124
shared_ptr<const XdmfTopologyType>
125
XdmfTopologyType::Tetrahedron()
126
{
127 128
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::Triangle());
129
  static shared_ptr<const XdmfTopologyType>
130
    p(new XdmfTopologyType(4, 4, faces, 6, "Tetrahedron", Linear, 0x6));
131
  return p;
132 133
}

134
shared_ptr<const XdmfTopologyType>
135
XdmfTopologyType::Pyramid()
136
{
137 138
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
139
  static shared_ptr<const XdmfTopologyType>
140
    p(new XdmfTopologyType(5, 5, faces, 8, "Pyramid", Linear, 0x7));
141
  return p;
142 143
}

144
shared_ptr<const XdmfTopologyType>
145
XdmfTopologyType::Wedge()
146
{
147 148
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
149
  static shared_ptr<const XdmfTopologyType>
150
    p(new XdmfTopologyType(6, 5, faces, 9, "Wedge", Linear, 0x8));
151
  return p;
152 153
}

154
shared_ptr<const XdmfTopologyType>
155
XdmfTopologyType::Hexahedron()
156
{
157 158
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::Quadrilateral());
159
  static shared_ptr<const XdmfTopologyType>
160
    p(new XdmfTopologyType(8, 6, faces, 12, "Hexahedron", Linear, 0x9));
161
  return p;
162 163
}

164 165 166 167 168 169 170 171 172
shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Polyhedron()
{
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  static shared_ptr<const XdmfTopologyType>
    p(new XdmfTopologyType(0, 0, faces, 0, "Polyhedron", Linear, 0x10));
  return p;
}

173
shared_ptr<const XdmfTopologyType>
174
XdmfTopologyType::Edge_3()
175
{
176 177
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
178
  static shared_ptr<const XdmfTopologyType>
179
    p(new XdmfTopologyType(3, 0, faces, 1, "Edge_3", Quadratic, 0x22));
180
  return p;
181 182
}

183
shared_ptr<const XdmfTopologyType>
184
XdmfTopologyType::Triangle_6()
185
{
186 187
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
188
  static shared_ptr<const XdmfTopologyType>
189
    p(new XdmfTopologyType(6, 1, faces, 3, "Triangle_6", Quadratic, 0x24));
190
  return p;
191 192
}

193
shared_ptr<const XdmfTopologyType>
194
XdmfTopologyType::Quadrilateral_8()
195
{
196 197
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
198
  static shared_ptr<const XdmfTopologyType>
199
    p(new XdmfTopologyType(8, 1, faces, 4, "Quadrilateral_8", Quadratic, 0x25));
200
  return p;
201 202
}

203
shared_ptr<const XdmfTopologyType>
204
XdmfTopologyType::Quadrilateral_9()
205
{
206 207
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
208
  static shared_ptr<const XdmfTopologyType>
209
    p(new XdmfTopologyType(9, 1, faces, 4, "Quadrilateral_9", Quadratic, 0x23));
210
  return p;
211 212
}

213
shared_ptr<const XdmfTopologyType>
214
XdmfTopologyType::Tetrahedron_10()
215
{
216 217 218
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
  faces.push_back(XdmfTopologyType::Triangle_6());
219
  static shared_ptr<const XdmfTopologyType>
220
    p(new XdmfTopologyType(10, 4, faces, 6, "Tetrahedron_10", Quadratic, 0x26));
221
  return p;
222 223
}

224
shared_ptr<const XdmfTopologyType>
225
XdmfTopologyType::Pyramid_13()
226
{
227 228
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
229
  static shared_ptr<const XdmfTopologyType>
230
    p(new XdmfTopologyType(13, 5, faces, 8, "Pyramid_13", Quadratic, 0x27));
231
  return p;
232 233
}

234
shared_ptr<const XdmfTopologyType>
235
XdmfTopologyType::Wedge_15()
236
{
237 238
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
239
  static shared_ptr<const XdmfTopologyType>
240
    p(new XdmfTopologyType(15, 5, faces, 9, "Wedge_15", Quadratic, 0x28));
241
  return p;
242 243
}

244
shared_ptr<const XdmfTopologyType>
245
XdmfTopologyType::Wedge_18()
246
{
247 248
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
249
  static shared_ptr<const XdmfTopologyType>
250
    p(new XdmfTopologyType(18, 5, faces, 9, "Wedge_18", Quadratic, 0x29));
251
  return p;
252 253
}

254
shared_ptr<const XdmfTopologyType>
255
XdmfTopologyType::Hexahedron_20()
256
{
257 258
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::Quadrilateral_8());
259
  static shared_ptr<const XdmfTopologyType>
260
    p(new XdmfTopologyType(20, 6, faces, 12, "Hexahedron_20", Quadratic, 0x30));
261
  return p;
262 263
}

264
shared_ptr<const XdmfTopologyType>
265
XdmfTopologyType::Hexahedron_24()
266
{
267 268
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
269
  static shared_ptr<const XdmfTopologyType>
270
    p(new XdmfTopologyType(24, 6, faces, 12, "Hexahedron_24", Quadratic, 0x31));
271
  return p;
272 273
}

274
shared_ptr<const XdmfTopologyType>
275
XdmfTopologyType::Hexahedron_27()
276
{
277 278
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::Quadrilateral_9());
279
  static shared_ptr<const XdmfTopologyType>
280
    p(new XdmfTopologyType(27, 6, faces, 12, "Hexahedron_27", Quadratic, 0x32));
281
  return p;
282 283
}

284
shared_ptr<const XdmfTopologyType>
285
XdmfTopologyType::Hexahedron_64()
286
{
287 288
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
289
  static shared_ptr<const XdmfTopologyType>
290
    p(new XdmfTopologyType(64, 6, faces, 12, "Hexahedron_64", Cubic, 0x33));
291
  return p;
292 293
}

294
shared_ptr<const XdmfTopologyType>
295
XdmfTopologyType::Hexahedron_125()
296
{
297 298
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
299
  static shared_ptr<const XdmfTopologyType>
300
    p(new XdmfTopologyType(125, 6, faces, 12, "Hexahedron_125", Quartic, 0x34));
301
  return p;
302 303
}

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

314

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

325 326 327 328

shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_512()
{
329 330
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
331
  static shared_ptr<const XdmfTopologyType>
332
    p(new XdmfTopologyType(512, 6, faces, 12, "Hexahedron_512", Septic, 0x37));
333 334 335 336 337 338 339
  return p;
}


shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_729()
{
340 341
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
342
  static shared_ptr<const XdmfTopologyType>
343
    p(new XdmfTopologyType(729, 6, faces, 12, "Hexahedron_729", Octic, 0x38));
344 345 346 347 348 349 350
  return p;
}


shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_1000()
{
351 352
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
353
  static shared_ptr<const XdmfTopologyType>
354
    p(new XdmfTopologyType(1000, 6, faces, 12, "Hexahedron_1000", Nonic, 0x39));
355 356 357 358 359 360
  return p;
}

shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_1331()
{
361 362
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
363
  static shared_ptr<const XdmfTopologyType>
364
    p(new XdmfTopologyType(1331, 6, faces, 12, "Hexahedron_1331", Decic, 0x40));
365 366 367
  return p;
}

368 369 370
shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_64()
{
371 372
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
373
  static shared_ptr<const XdmfTopologyType>
374
    p(new XdmfTopologyType(64, 6, faces, 12, "Hexahedron_Spectral_64", Cubic, 0x41));
375 376 377 378 379 380
  return p;
}

shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_125()
{
381 382
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
383
  static shared_ptr<const XdmfTopologyType>
384
    p(new XdmfTopologyType(125, 6, faces, 12,
385 386 387 388 389 390 391
                           "Hexahedron_Spectral_125", Quartic, 0x42));
  return p;
}

shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_216()
{
392 393
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
394
  static shared_ptr<const XdmfTopologyType>
395
    p(new XdmfTopologyType(216, 6, faces, 12,
396 397 398 399 400 401 402 403
                           "Hexahedron_Spectral_216", Quintic, 0x43));
  return p;
}


shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_343()
{
404 405
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
406
  static shared_ptr<const XdmfTopologyType>
407
    p(new XdmfTopologyType(343, 6, faces, 12,
408 409 410 411 412 413 414 415
                           "Hexahedron_Spectral_343", Sextic, 0x44));
  return p;
}


shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_512()
{
416 417
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
418
  static shared_ptr<const XdmfTopologyType>
419
    p(new XdmfTopologyType(512, 6, faces, 12,
420 421 422 423 424 425 426 427
                           "Hexahedron_Spectral_512", Septic, 0x45));
  return p;
}


shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_729()
{
428 429
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
430
  static shared_ptr<const XdmfTopologyType>
431
    p(new XdmfTopologyType(729, 6, faces, 12,
432 433 434 435 436 437 438 439
                           "Hexahedron_Spectral_729", Octic, 0x46));
  return p;
}


shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_1000()
{
440 441
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
442
  static shared_ptr<const XdmfTopologyType>
443
    p(new XdmfTopologyType(1000, 6, faces, 12,
444 445 446 447 448 449 450
                           "Hexahedron_Spectral_1000", Nonic, 0x47));
  return p;
}

shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Hexahedron_Spectral_1331()
{
451 452
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
  faces.push_back(XdmfTopologyType::NoTopologyType());
453
  static shared_ptr<const XdmfTopologyType>
454
    p(new XdmfTopologyType(1331, 6, faces, 12,
455 456 457
                           "Hexahedron_Spectral_1331", Decic, 0x48));
  return p;
}
458

459
shared_ptr<const XdmfTopologyType>
460
XdmfTopologyType::Mixed()
461
{
462
  std::vector<shared_ptr<const XdmfTopologyType> > faces;
463
  static shared_ptr<const XdmfTopologyType>
464
    p(new XdmfTopologyType(0, 0, faces, 0, "Mixed", Arbitrary, 0x70));
465
  return p;
466 467
}

468 469 470 471 472 473 474 475 476 477 478
void
XdmfTopologyType::InitTypes()
{
  mTopologyDefinitions["NOTOPOLOGY"] = NoTopologyType;
  mTopologyDefinitions["POLYVERTEX"] = Polyvertex;
  mTopologyDefinitions["TRIANGLE"] = Triangle;
  mTopologyDefinitions["QUADRILATERAL"] = Quadrilateral;
  mTopologyDefinitions["TETRAHEDRON"] = Tetrahedron;
  mTopologyDefinitions["PYRAMID"] = Pyramid;
  mTopologyDefinitions["WEDGE"] = Wedge;
  mTopologyDefinitions["HEXAHEDRON"] = Hexahedron;
479
  mTopologyDefinitions["POLYHEDRON"] = Polyhedron;
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 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
  mTopologyDefinitions["EDGE_3"] = Edge_3;
  mTopologyDefinitions["TRIANGLE_6"] = Triangle_6;
  mTopologyDefinitions["QUADRILATERAL_8"] = Quadrilateral_8;
  mTopologyDefinitions["QUADRILATERAL_9"] = Quadrilateral_9;
  mTopologyDefinitions["TETRAHEDRON_10"] = Tetrahedron_10;
  mTopologyDefinitions["PYRAMID_13"] = Pyramid_13;
  mTopologyDefinitions["WEDGE_15"] = Wedge_15;
  mTopologyDefinitions["WEDGE_18"] = Wedge_18;
  mTopologyDefinitions["HEXAHEDRON_20"] = Hexahedron_20;
  mTopologyDefinitions["HEXAHEDRON_24"] = Hexahedron_24;
  mTopologyDefinitions["HEXAHEDRON_27"] = Hexahedron_27;
  mTopologyDefinitions["HEXAHEDRON_64"] = Hexahedron_64;
  mTopologyDefinitions["HEXAHEDRON_125"] = Hexahedron_125;
  mTopologyDefinitions["HEXAHEDRON_216"] = Hexahedron_216;
  mTopologyDefinitions["HEXAHEDRON_343"] = Hexahedron_343;
  mTopologyDefinitions["HEXAHEDRON_512"] = Hexahedron_512;
  mTopologyDefinitions["HEXAHEDRON_729"] = Hexahedron_729;
  mTopologyDefinitions["HEXAHEDRON_1000"] = Hexahedron_1000;
  mTopologyDefinitions["HEXAHEDRON_1331"] = Hexahedron_1331;
  mTopologyDefinitions["HEXAHEDRON_SPECTRAL_64"] = Hexahedron_Spectral_64;
  mTopologyDefinitions["HEXAHEDRON_SPECTRAL_125"] = Hexahedron_Spectral_125;
  mTopologyDefinitions["HEXAHEDRON_SPECTRAL_216"] = Hexahedron_Spectral_216;
  mTopologyDefinitions["HEXAHEDRON_SPECTRAL_343"] = Hexahedron_Spectral_343;
  mTopologyDefinitions["HEXAHEDRON_SPECTRAL_512"] = Hexahedron_Spectral_512;
  mTopologyDefinitions["HEXAHEDRON_SPECTRAL_729"] = Hexahedron_Spectral_729;
  mTopologyDefinitions["HEXAHEDRON_SPECTRAL_1000"] = Hexahedron_Spectral_1000;
  mTopologyDefinitions["HEXAHEDRON_SPECTRAL_1331"] = Hexahedron_Spectral_1331;
  mTopologyDefinitions["MIXED"] = Mixed;
}

unsigned int
XdmfTopologyType::calculateHypercubeNumElements(unsigned int numDims,
                                                unsigned int elementNumDims) const
{
  if (elementNumDims > numDims) {
    return 0;
  }
  else if (elementNumDims == numDims) {
    return 1;
  }
  else {
    // The calculation has 3 parts
    // First is the 2 taken to the power of
    // the object's dimensionality minus the element's dimensionality.
    unsigned int part1 = std::pow((double)2, (double)(numDims - elementNumDims));
    // The second part is numDims!/(numDims-elementdims)!
    unsigned int part2 = 1;
    for (unsigned int i = numDims; i > (numDims - elementNumDims); --i)
    {
      part2 *= i;
    }
    // The third part is elementDims!
    unsigned int part3 = 1;
    for (unsigned int i = 1; i <= elementNumDims; ++i)
    {
      part3 *= i;
    }
    return part1 * (part2 / part3);
  }
}

541
shared_ptr<const XdmfTopologyType>
542 543 544 545 546 547 548 549
XdmfTopologyType::New(const unsigned int id)
{
  if(id == XdmfTopologyType::NoTopologyType()->getID()) {
    return XdmfTopologyType::NoTopologyType();
  }
  else if(id == XdmfTopologyType::Polyvertex()->getID()) {
    return XdmfTopologyType::Polyvertex();
  }
550 551
  else if(id == XdmfTopologyType::Polyline(0)->getID()) {
    return XdmfTopologyType::Polyline(0);
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
  }
  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();
  }
574 575 576
  else if(id == XdmfTopologyType::Polyhedron()->getID()) {
    return XdmfTopologyType::Polyhedron();
  }
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
  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();
  }
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
  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();
633
  }
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
  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();
  }
658 659 660
  else if(id == XdmfTopologyType::Mixed()->getID()) {
    return XdmfTopologyType::Mixed();
  }
661
  return shared_ptr<const XdmfTopologyType>();
662 663
}

664
XdmfTopologyType::XdmfTopologyType(const unsigned int nodesPerElement,
665
                                   const unsigned int facesPerElement,
666
                                   const std::vector<shared_ptr<const XdmfTopologyType> > & faces,
667
                                   const unsigned int edgesPerElement,
668 669 670 671
                                   const std::string & name,
                                   const CellType cellType,
                                   const unsigned int id) :
  mCellType(cellType),
672 673
  mEdgesPerElement(edgesPerElement),
  mFacesPerElement(facesPerElement),
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
674
  mFaces(faces),
675 676 677
  mID(id),
  mName(name),
  mNodesPerElement(nodesPerElement)
678 679
{
}
680

681 682 683 684
XdmfTopologyType::~XdmfTopologyType()
{
}

685
shared_ptr<const XdmfTopologyType>
686 687
XdmfTopologyType::New(const std::map<std::string, std::string> & itemProperties)
{
688 689
  InitTypes();

690 691 692 693 694
  std::map<std::string, std::string>::const_iterator type =
    itemProperties.find("Type");
  if(type == itemProperties.end()) {
    type = itemProperties.find("TopologyType");
  }
695
  if(type == itemProperties.end()) {
696
    XdmfError::message(XdmfError::FATAL,
697 698
                       "Neither 'Type' nor 'TopologyType' found in "
                       "itemProperties in XdmfTopologyType::New");
699
  }
700
  const std::string typeVal = XdmfStringUtils::toUpper(type->second);
701 702 703

  std::map<std::string, std::string>::const_iterator nodesPerElement =
    itemProperties.find("NodesPerElement");
704

705 706 707 708 709 710 711 712
  std::map<std::string, shared_ptr<const XdmfTopologyType>(*)()>::const_iterator returnType
    = mTopologyDefinitions.find(typeVal);

  if (returnType == mTopologyDefinitions.end()) {
    if(typeVal.compare("POLYLINE") == 0) {
      if(nodesPerElement != itemProperties.end()) {
        return Polyline(atoi(nodesPerElement->second.c_str()));
      }
713 714 715
      XdmfError::message(XdmfError::FATAL,
                         "'NodesPerElement' not in itemProperties and type "
                         "'POLYLINE' selected in XdmfTopologyType::New");
716
    }
717 718 719 720
    else if(typeVal.compare("POLYGON") == 0) {
      if(nodesPerElement != itemProperties.end()) {
        return Polygon(atoi(nodesPerElement->second.c_str()));
      }
721 722 723
      XdmfError::message(XdmfError::FATAL,
                         "'NodesPerElement' not in itemProperties and type "
                         "'POLYGON' selected in XdmfTopologyType::New");
724 725 726 727 728
    }
    else {
      XdmfError::message(XdmfError::FATAL,
                         "Invalid Type selected in XdmfTopologyType::New");

729
    }
730
  }
731 732
  else {
    return (*(returnType->second))();
733
  }
734 735

  XdmfError::message(XdmfError::FATAL,
736
                     "Invalid Type selected in XdmfTopologyType::New");
737

738
  // unreachable
739
  return shared_ptr<const XdmfTopologyType>();
740 741 742 743 744 745 746 747
}

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

748 749 750 751 752 753
unsigned int
XdmfTopologyType::getEdgesPerElement() const
{
  return mEdgesPerElement;
}

754
shared_ptr<const XdmfTopologyType>
755
XdmfTopologyType::getFaceType() const
756 757 758 759 760 761 762 763 764
{
  if (mFaces.size() == 0) {
    return XdmfTopologyType::NoTopologyType();
  }
  else {
    return mFaces[0];
  }
}

765 766 767 768 769 770
unsigned int
XdmfTopologyType::getFacesPerElement() const
{
  return mFacesPerElement;
}

771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
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
{
792
  collectedProperties.insert(std::make_pair("Type", this->getName()));
793
  if(mName.compare("Polygon") == 0 || mName.compare("Polyline") == 0) {
794 795
    std::stringstream nodesPerElement;
    nodesPerElement << mNodesPerElement;
796 797
    collectedProperties.insert(std::make_pair("NodesPerElement",
                                              nodesPerElement.str()));
798
  }
799
}
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847

// C Wrappers

int XdmfTopologyTypePolyvertex()
{
  return XDMF_TOPOLOGY_TYPE_POLYVERTEX;
}

int XdmfTopologyTypePolyline()
{
  return XDMF_TOPOLOGY_TYPE_POLYLINE;
}

int XdmfTopologyTypePolygon()
{
  return XDMF_TOPOLOGY_TYPE_POLYGON;
}

int XdmfTopologyTypeTriangle()
{
  return XDMF_TOPOLOGY_TYPE_TRIANGLE;
}

int XdmfTopologyTypeQuadrilateral()
{
  return XDMF_TOPOLOGY_TYPE_QUADRILATERAL;
}

int XdmfTopologyTypeTetrahedron()
{
  return XDMF_TOPOLOGY_TYPE_TETRAHEDRON;
}

int XdmfTopologyTypePyramid()
{
  return XDMF_TOPOLOGY_TYPE_PYRAMID;
}

int XdmfTopologyTypeWedge()
{
  return XDMF_TOPOLOGY_TYPE_WEDGE;
}

int XdmfTopologyTypeHexahedron()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON;
}

848 849 850 851 852
int XdmfTopologyTypePolyhedron()
{
  return XDMF_TOPOLOGY_TYPE_POLYHEDRON;
}

853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
int XdmfTopologyTypeEdge_3()
{
  return XDMF_TOPOLOGY_TYPE_EDGE_3;
}

int XdmfTopologyTypeTriangle_6()
{
  return XDMF_TOPOLOGY_TYPE_TRIANGLE_6;
}

int XdmfTopologyTypeQuadrilateral_8()
{
  return XDMF_TOPOLOGY_TYPE_QUADRILATERAL_8;
}

int XdmfTopologyTypeQuadrilateral_9()
{
  return XDMF_TOPOLOGY_TYPE_QUADRILATERAL_9;
}

int XdmfTopologyTypeTetrahedron_10()
{
  return XDMF_TOPOLOGY_TYPE_TETRAHEDRON_10;
}

int XdmfTopologyTypePyramid_13()
{
  return XDMF_TOPOLOGY_TYPE_PYRAMID_13;
}

int XdmfTopologyTypeWedge_15()
{
  return XDMF_TOPOLOGY_TYPE_WEDGE_15;
}

int XdmfTopologyTypeWedge_18()
{
  return XDMF_TOPOLOGY_TYPE_WEDGE_18;
}

int XdmfTopologyTypeHexahedron_20()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_20;
}

int XdmfTopologyTypeHexahedron_24()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_24;
}

int XdmfTopologyTypeHexahedron_27()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_27;
}

int XdmfTopologyTypeHexahedron_64()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_64;
}

int XdmfTopologyTypeHexahedron_125()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_125;
}

int XdmfTopologyTypeHexahedron_216()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_216;
}

int XdmfTopologyTypeHexahedron_343()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_343;
}

int XdmfTopologyTypeHexahedron_512()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_512;
}

int XdmfTopologyTypeHexahedron_729()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_729;
}

int XdmfTopologyTypeHexahedron_1000()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1000;
}

int XdmfTopologyTypeHexahedron_1331()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1331;
}

int XdmfTopologyTypeHexahedron_Spectral_64()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_64;
}

int XdmfTopologyTypeHexahedron_Spectral_125()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_125;
}

int XdmfTopologyTypeHexahedron_Spectral_216()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_216;
}

int XdmfTopologyTypeHexahedron_Spectral_343()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_343;
}

int XdmfTopologyTypeHexahedron_Spectral_512()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_512;
}

int XdmfTopologyTypeHexahedron_Spectral_729()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_729;
}

int XdmfTopologyTypeHexahedron_Spectral_1000()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1000;
}

int XdmfTopologyTypeHexahedron_Spectral_1331()
{
  return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1331;
}

int XdmfTopologyTypeMixed()
{
  return XDMF_TOPOLOGY_TYPE_MIXED;
}

shared_ptr<const XdmfTopologyType> intToType(int type, int nodes = 0)
{
  switch (type) {
    case XDMF_TOPOLOGY_TYPE_POLYVERTEX:
      return XdmfTopologyType::Polyvertex();
      break;
    case XDMF_TOPOLOGY_TYPE_POLYLINE:
      return XdmfTopologyType::Polyline(nodes);
      break;
    case XDMF_TOPOLOGY_TYPE_POLYGON:
      return XdmfTopologyType::Polygon(nodes);
      break;
    case XDMF_TOPOLOGY_TYPE_TRIANGLE:
      return XdmfTopologyType::Triangle();
      break;
    case XDMF_TOPOLOGY_TYPE_QUADRILATERAL:
      return XdmfTopologyType::Quadrilateral();
      break;
    case XDMF_TOPOLOGY_TYPE_TETRAHEDRON:
      return XdmfTopologyType::Tetrahedron();
      break;
    case XDMF_TOPOLOGY_TYPE_PYRAMID:
      return XdmfTopologyType::Pyramid();
      break;
    case XDMF_TOPOLOGY_TYPE_WEDGE:
      return XdmfTopologyType::Wedge();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON:
      return XdmfTopologyType::Hexahedron();
      break;
1023 1024 1025
    case XDMF_TOPOLOGY_TYPE_POLYHEDRON:
      return XdmfTopologyType::Polyhedron();
      break;
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
    case XDMF_TOPOLOGY_TYPE_EDGE_3:
      return XdmfTopologyType::Edge_3();
      break;
    case XDMF_TOPOLOGY_TYPE_TRIANGLE_6:
      return XdmfTopologyType::Triangle_6();
      break;
    case XDMF_TOPOLOGY_TYPE_QUADRILATERAL_8:
      return XdmfTopologyType::Quadrilateral_8();
      break;
    case XDMF_TOPOLOGY_TYPE_QUADRILATERAL_9:
      return XdmfTopologyType::Quadrilateral_9();
      break;
    case XDMF_TOPOLOGY_TYPE_TETRAHEDRON_10:
      return XdmfTopologyType::Tetrahedron_10();
      break;
    case XDMF_TOPOLOGY_TYPE_PYRAMID_13:
      return XdmfTopologyType::Pyramid_13();
      break;
    case XDMF_TOPOLOGY_TYPE_WEDGE_15:
      return XdmfTopologyType::Wedge_15();
      break;
    case XDMF_TOPOLOGY_TYPE_WEDGE_18:
      return XdmfTopologyType::Wedge_18();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_20:
      return XdmfTopologyType::Hexahedron_20();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_24:
      return XdmfTopologyType::Hexahedron_24();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_27:
      return XdmfTopologyType::Hexahedron_27();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_64:
      return XdmfTopologyType::Hexahedron_64();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_125:
      return XdmfTopologyType::Hexahedron_125();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_216:
      return XdmfTopologyType::Hexahedron_216();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_343:
      return XdmfTopologyType::Hexahedron_343();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_512:
      return XdmfTopologyType::Hexahedron_512();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_729:
      return XdmfTopologyType::Hexahedron_729();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1000:
      return XdmfTopologyType::Hexahedron_1000();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1331:
      return XdmfTopologyType::Hexahedron_1331();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_64:
      return XdmfTopologyType::Hexahedron_Spectral_64();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_125:
      return XdmfTopologyType::Hexahedron_Spectral_125();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_216:
      return XdmfTopologyType::Hexahedron_Spectral_216();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_343:
      return XdmfTopologyType::Hexahedron_Spectral_343();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_512:
      return XdmfTopologyType::Hexahedron_Spectral_512();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_729:
      return XdmfTopologyType::Hexahedron_Spectral_729();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1000:
      return XdmfTopologyType::Hexahedron_Spectral_1000();
      break;
    case XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1331:
      return XdmfTopologyType::Hexahedron_Spectral_1331();
      break;
    case XDMF_TOPOLOGY_TYPE_MIXED:
      return XdmfTopologyType::Mixed();
      break;
    default:
      return shared_ptr<const XdmfTopologyType>();
      break;
  }
}

int typeToInt(shared_ptr<const XdmfTopologyType> type)
{
  if (type->getID() == XdmfTopologyType::Polyvertex()->getID()) {
    return XDMF_TOPOLOGY_TYPE_POLYVERTEX;
  }
  else if (type->getID() == XdmfTopologyType::Polyline(0)->getID()) {
    return XDMF_TOPOLOGY_TYPE_POLYLINE;
  }
  else if (type->getID() == XdmfTopologyType::Polygon(0)->getID()) {
    return XDMF_TOPOLOGY_TYPE_POLYGON;
  }
  else if (type->getID() == XdmfTopologyType::Triangle()->getID()) {
    return XDMF_TOPOLOGY_TYPE_TRIANGLE;
  }
  else if (type->getID() == XdmfTopologyType::Quadrilateral()->getID()) {
    return XDMF_TOPOLOGY_TYPE_QUADRILATERAL;
  }
  else if (type->getID() == XdmfTopologyType::Tetrahedron()->getID()) {
    return XDMF_TOPOLOGY_TYPE_TETRAHEDRON;
  }
  else if (type->getID() == XdmfTopologyType::Pyramid()->getID()) {
    return XDMF_TOPOLOGY_TYPE_PYRAMID;
  }
  else if (type->getID() == XdmfTopologyType::Wedge()->getID()) {
    return XDMF_TOPOLOGY_TYPE_WEDGE;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON;
  }
1145 1146 1147
  else if (type->getID() == XdmfTopologyType::Polyhedron()->getID()) {
    return XDMF_TOPOLOGY_TYPE_POLYHEDRON;
  }
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277
  else if (type->getID() == XdmfTopologyType::Edge_3()->getID()) {
    return XDMF_TOPOLOGY_TYPE_EDGE_3;
  }
  else if (type->getID() == XdmfTopologyType::Triangle_6()->getID()) {
    return XDMF_TOPOLOGY_TYPE_TRIANGLE_6;
  }
  else if (type->getID() == XdmfTopologyType::Quadrilateral_8()->getID()) {
    return XDMF_TOPOLOGY_TYPE_QUADRILATERAL_8;
  }
  else if (type->getID() == XdmfTopologyType::Quadrilateral_9()->getID()) {
    return XDMF_TOPOLOGY_TYPE_QUADRILATERAL_9;
  }
  else if (type->getID() == XdmfTopologyType::Tetrahedron_10()->getID()) {
    return XDMF_TOPOLOGY_TYPE_TETRAHEDRON_10;
  }
  else if (type->getID() == XdmfTopologyType::Pyramid_13()->getID()) {
    return XDMF_TOPOLOGY_TYPE_PYRAMID_13;
  }
  else if (type->getID() == XdmfTopologyType::Wedge_15()->getID()) {
    return XDMF_TOPOLOGY_TYPE_WEDGE_15;
  }
  else if (type->getID() == XdmfTopologyType::Wedge_18()->getID()) {
    return XDMF_TOPOLOGY_TYPE_WEDGE_18;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_20()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_20;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_24()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_24;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_27()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_27;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_64()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_64;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_125()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_125;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_216()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_216;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_343()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_343;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_512()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_512;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_729()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_729;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_1000()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1000;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_1331()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1331;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_64()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_64;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_125()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_125;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_216()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_216;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_343()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_343;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_512()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_512;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_729()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_729;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_1000()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1000;
  }
  else if (type->getID() == XdmfTopologyType::Hexahedron_Spectral_1331()->getID()) {
    return XDMF_TOPOLOGY_TYPE_HEXAHEDRON_SPECTRAL_1331;
  }
  else if (type->getID() == XdmfTopologyType::Mixed()->getID()) {
    return XDMF_TOPOLOGY_TYPE_MIXED;
  }
  else {
    return -1;
  }
}

int XdmfTopologyTypeGetCellType(int type)
{
  return intToType(type)->getCellType();
}

unsigned int XdmfTopologyTypeGetEdgesPerElement(int type, int * status)
{
  XDMF_ERROR_WRAP_START(status)
  return  intToType(type)->getEdgesPerElement();
  XDMF_ERROR_WRAP_END(status)
  return 0;
}

unsigned int XdmfTopologyTypeGetFacesPerElement(int type, int * status)
{
  XDMF_ERROR_WRAP_START(status)
  return  intToType(type)->getFacesPerElement();
  XDMF_ERROR_WRAP_END(status)
  return 0;
}

int XdmfTopologyTypeGetFaceType(int type)
{
  return typeToInt(intToType(type)->getFaceType());
}

unsigned int XdmfTopologyTypeGetID(int type)
{
  return intToType(type)->getID();
}

char * XdmfTopologyTypeGetName(int type)
{
  char * returnPointer = strdup(intToType(type)->getName().c_str());
  return returnPointer;
}

unsigned int XdmfTopologyTypeGetNodesPerElement(int type)
{
  return  intToType(type)->getNodesPerElement();
}