XdmfTopologyConverter.cpp 36.5 KB
Newer Older
1
2
#include <math.h>
#include "XdmfArray.hpp"
3
4
5
#include "XdmfAttribute.hpp"
#include "XdmfAttributeCenter.hpp"
#include "XdmfAttributeType.hpp"
6
7
#include "XdmfGeometry.hpp"
#include "XdmfGeometryType.hpp"
8
#include "XdmfGrid.hpp"
9
10
#include "XdmfTopology.hpp"
#include "XdmfTopologyConverter.hpp"
11
12
13
14
15
16
17
18
19
20
#include "XdmfTopologyType.hpp"

XdmfTopologyConverter::XdmfTopologyConverter()
{
}

XdmfTopologyConverter::~XdmfTopologyConverter()
{
}

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
struct XdmfTopologyConverter::PointComparison {
  bool operator()(const std::vector<double> & point1, const std::vector<double> & point2) const
  {
    double epsilon = 1e-6;
    for(unsigned int i=0; i<3; ++i)
    {
      if(fabs(point1[i] - point2[i]) > epsilon)
      {
        return point1[i] < point2[i];
      }
    }
    return false;
  }
};

class XdmfTopologyConverter::HexahedronToHexahedron64 {
public:

	HexahedronToHexahedron64()
	{
	}

	inline void computeInteriorPoints(std::vector<double> & leftPoint, std::vector<double> & rightPoint, std::vector<double> & point1, std::vector<double> & point2) const
	{
	  leftPoint[0] = (1.0/3.0)*(point2[0] + 2*point1[0]);
	  leftPoint[1] = (1.0/3.0)*(point2[1] + 2*point1[1]);
	  leftPoint[2] = (1.0/3.0)*(point2[2] + 2*point1[2]);

	  rightPoint[0] = (1.0/3.0)*(2*point2[0] + point1[0]);
	  rightPoint[1] = (1.0/3.0)*(2*point2[1] + point1[1]);
	  rightPoint[2] = (1.0/3.0)*(2*point2[2] + point1[2]);
	}

	inline void computeLeftPoint(std::vector<double> & leftPoint, std::vector<double> & point1, std::vector<double> & point2) const
	{
	  leftPoint[0] = (1.0/3.0)*(point2[0] + 2*point1[0]);
	  leftPoint[1] = (1.0/3.0)*(point2[1] + 2*point1[1]);
	  leftPoint[2] = (1.0/3.0)*(point2[2] + 2*point1[2]);
	}

	inline void computeRightPoint(std::vector<double> & rightPoint, std::vector<double> & point1, std::vector<double> & point2) const
	{
	  rightPoint[0] = (1.0/3.0)*(2*point2[0] + point1[0]);
	  rightPoint[1] = (1.0/3.0)*(2*point2[1] + point1[1]);
	  rightPoint[2] = (1.0/3.0)*(2*point2[2] + point1[2]);
	}

68
	inline void insertPointWithoutCheck(std::vector<double> & newPoint, const boost::shared_ptr<XdmfArray> & newConnectivity, const boost::shared_ptr<XdmfArray> & newPoints) const
69
	{
70
	  newConnectivity->pushBack(newPoints->getSize() / 3);
71
72
73
74
75
	  newPoints->pushBack(newPoint[0]);
	  newPoints->pushBack(newPoint[1]);
	  newPoints->pushBack(newPoint[2]);
	}

76
	inline void insertPointWithCheck(std::vector<double> & newPoint, std::map<std::vector<double>, unsigned int, PointComparison> & coordToIdMap, const boost::shared_ptr<XdmfArray> & newConnectivity, const boost::shared_ptr<XdmfArray> & newPoints) const
77
78
79
80
81
	{
	  std::map<std::vector<double>, unsigned int>::const_iterator iter = coordToIdMap.find(newPoint);
	  if(iter == coordToIdMap.end())
	  {
	    // Not inserted before
82
83
	    coordToIdMap[newPoint] = newPoints->getSize() / 3;;
	    insertPointWithoutCheck(newPoint, newConnectivity, newPoints);
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
	  }
	  else
	  {
	    newConnectivity->pushBack(iter->second);
	  }
	}

	boost::shared_ptr<XdmfGrid> convert(const boost::shared_ptr<XdmfGrid> gridToConvert) const
	{
		boost::shared_ptr<XdmfGrid> toReturn = XdmfGrid::New();
		toReturn->setName(gridToConvert->getName());
		toReturn->getGeometry()->setGeometryType(gridToConvert->getGeometry()->getGeometryType());
		toReturn->getTopology()->setTopologyType(XdmfTopologyType::Hexahedron_64());

		boost::shared_ptr<XdmfArray> newPoints = toReturn->getGeometry()->getArray();
		newPoints->initialize(gridToConvert->getGeometry()->getArray()->getType());
		newPoints->resize(gridToConvert->getGeometry()->getArray()->getSize(), 0);
101
102
103
104
105
106

		if(!gridToConvert->getGeometry()->getArray()->isInitialized())
		{
			gridToConvert->getGeometry()->getArray()->read();
		}

107
108
109
110
111
112
113
		// Copy all geometry values from old grid into new grid because we are keeping all old points.
		newPoints->copyValues(0, gridToConvert->getGeometry()->getArray(), 0, gridToConvert->getGeometry()->getArray()->getSize());

		boost::shared_ptr<XdmfArray> newConnectivity = toReturn->getTopology()->getArray();
		newConnectivity->initialize(gridToConvert->getTopology()->getArray()->getType());
		newConnectivity->reserve(64 * gridToConvert->getTopology()->getNumberElements());

114
115
116
117
118
		if(!gridToConvert->getTopology()->getArray()->isInitialized())
		{
			gridToConvert->getTopology()->getArray()->read();
		}

119
120
121
122
123
124
125
126
127
128
129
		std::vector<double> leftPoint(3);
		std::vector<double> rightPoint(3);
		std::map<std::vector<double>, unsigned int, PointComparison> coordToIdMap;

		for(unsigned int i=0; i<gridToConvert->getTopology()->getNumberElements(); ++i)
		{
			// Fill localNodes with original coordinate information.
			std::vector<std::vector<double> > localNodes(8, std::vector<double>(3));
			localNodes.reserve(44);
			for(int j=0; j<8; ++j)
			{
130
				gridToConvert->getGeometry()->getArray()->getValuesCopy(gridToConvert->getTopology()->getArray()->getValueCopy<unsigned int>(8*i + j) * 3, &localNodes[j][0], 3);
131
132
133
134
135
136
137
138
139
140
141
142
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
			}

			// Add old connectivity information to newConnectivity.
			newConnectivity->resize(newConnectivity->getSize() + 8, 0);
			newConnectivity->copyValues(64*i, gridToConvert->getTopology()->getArray(), 8*i, 8);

			// Case 0
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[0], localNodes[1]);
			localNodes.push_back(leftPoint);
			localNodes.push_back(rightPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 1
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[1], localNodes[2]);
			localNodes.push_back(leftPoint);
			localNodes.push_back(rightPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 2
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[2], localNodes[3]);
			localNodes.push_back(leftPoint);
			localNodes.push_back(rightPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 3
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[3], localNodes[0]);
			localNodes.push_back(leftPoint);
			localNodes.push_back(rightPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 4
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[4], localNodes[5]);
			localNodes.push_back(leftPoint);
			localNodes.push_back(rightPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 5
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[5], localNodes[6]);
			localNodes.push_back(leftPoint);
			localNodes.push_back(rightPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 6
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[6], localNodes[7]);
			localNodes.push_back(leftPoint);
			localNodes.push_back(rightPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 7
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[7], localNodes[4]);
			localNodes.push_back(leftPoint);
			localNodes.push_back(rightPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 8
			computeLeftPoint(leftPoint, localNodes[0], localNodes[4]);
			localNodes.push_back(leftPoint);
			insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 9
			this->computeLeftPoint(leftPoint, localNodes[1], localNodes[5]);
			localNodes.push_back(leftPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 10
			this->computeLeftPoint(leftPoint, localNodes[2], localNodes[6]);
			localNodes.push_back(leftPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 11
			this->computeLeftPoint(leftPoint, localNodes[3], localNodes[7]);
			localNodes.push_back(leftPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 12
			this->computeRightPoint(leftPoint, localNodes[0], localNodes[4]);
			localNodes.push_back(leftPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);

			 // Case 13
			this->computeRightPoint(leftPoint, localNodes[1], localNodes[5]);
			localNodes.push_back(leftPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 14
			this->computeRightPoint(leftPoint, localNodes[2], localNodes[6]);
			localNodes.push_back(leftPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 15
			this->computeRightPoint(leftPoint, localNodes[3], localNodes[7]);
			localNodes.push_back(leftPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 16
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[27], localNodes[24]);
			localNodes.push_back(leftPoint);
			localNodes.push_back(rightPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 17
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[25], localNodes[26]);
			localNodes.push_back(leftPoint);
			localNodes.push_back(rightPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 18
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[24], localNodes[25]);
			localNodes.push_back(leftPoint);
			localNodes.push_back(rightPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 19
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[26], localNodes[27]);
			localNodes.push_back(leftPoint);
			localNodes.push_back(rightPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 20
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[31], localNodes[28]);
			localNodes.push_back(leftPoint);
			localNodes.push_back(rightPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 21
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[29], localNodes[30]);
			localNodes.push_back(leftPoint);
			localNodes.push_back(rightPoint);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 22
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[28], localNodes[29]);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 23
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[30], localNodes[31]);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

			// Case 24
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[15], localNodes[10]);
			this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
			this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

		    // Case 25
			this->computeInteriorPoints(leftPoint, rightPoint, localNodes[11], localNodes[14]);
		    this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
		    this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

		    // Case 26
		    this->computeInteriorPoints(leftPoint, rightPoint, localNodes[23], localNodes[18]);
		    this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
		    this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

		    // Case 27
		    this->computeInteriorPoints(leftPoint, rightPoint, localNodes[19], localNodes[22]);
		    this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
		    this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);

		    // Case 28
		    this->computeInteriorPoints(leftPoint, rightPoint, localNodes[33], localNodes[34]);
307
308
		    this->insertPointWithoutCheck(leftPoint, newConnectivity, newPoints);
		    this->insertPointWithoutCheck(rightPoint, newConnectivity, newPoints);
309
310
311

		    // Case 29
		    this->computeInteriorPoints(leftPoint, rightPoint, localNodes[35], localNodes[32]);
312
313
		    this->insertPointWithoutCheck(leftPoint, newConnectivity, newPoints);
		    this->insertPointWithoutCheck(rightPoint, newConnectivity, newPoints);
314
315
316

		    // Case 30
		    this->computeInteriorPoints(leftPoint, rightPoint, localNodes[41], localNodes[42]);
317
318
		    this->insertPointWithoutCheck(leftPoint, newConnectivity, newPoints);
		    this->insertPointWithoutCheck(rightPoint, newConnectivity, newPoints);
319
320
321

		    // Case 31
		    this->computeInteriorPoints(leftPoint, rightPoint, localNodes[43], localNodes[40]);
322
323
		    this->insertPointWithoutCheck(leftPoint, newConnectivity, newPoints);
		    this->insertPointWithoutCheck(rightPoint, newConnectivity, newPoints);
324
325
326
327
328
		}
		return toReturn;
	}
};

329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
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
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
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
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
class XdmfTopologyConverter::Hexahedron64ToHexahedron {
public:

	Hexahedron64ToHexahedron()
	{
	}

	boost::shared_ptr<XdmfGrid> convert(const boost::shared_ptr<XdmfGrid> gridToConvert) const
	{
		boost::shared_ptr<XdmfGrid> toReturn = XdmfGrid::New();
		toReturn->setName(gridToConvert->getName());

		toReturn->setGeometry(gridToConvert->getGeometry());
		toReturn->getTopology()->setTopologyType(XdmfTopologyType::Hexahedron());

		boost::shared_ptr<XdmfArray> oldConnectivity = gridToConvert->getTopology()->getArray();
		boost::shared_ptr<XdmfArray> newConnectivity = toReturn->getTopology()->getArray();
		newConnectivity->initialize(oldConnectivity->getType());
		newConnectivity->resize(216 * gridToConvert->getTopology()->getNumberElements(), 0);

		if(!oldConnectivity->isInitialized())
		{
			oldConnectivity->read();
		}

		for(unsigned int i=0; i<gridToConvert->getTopology()->getNumberElements(); ++i)
		{
			const unsigned int startIndex = 216 * i;
			const unsigned int valuesStartIndex = 64 * i;
			newConnectivity->copyValues(startIndex + 0, oldConnectivity, 0 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 1, oldConnectivity, 8 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 2, oldConnectivity, 48 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 3, oldConnectivity, 15 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 4, oldConnectivity, 24 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 5, oldConnectivity, 36 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 6, oldConnectivity, 56 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 7, oldConnectivity, 33 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 8, oldConnectivity, 8 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 9, oldConnectivity, 9 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 10, oldConnectivity, 49 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 11, oldConnectivity, 48 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 12, oldConnectivity, 36 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 13, oldConnectivity, 37 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 14, oldConnectivity, 57 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 15, oldConnectivity, 56 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 16, oldConnectivity, 9 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 17, oldConnectivity, 1 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 18, oldConnectivity, 10 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 19, oldConnectivity, 49 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 20, oldConnectivity, 37 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 21, oldConnectivity, 25 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 22, oldConnectivity, 34 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 23, oldConnectivity, 57 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 24, oldConnectivity, 15 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 25, oldConnectivity, 48 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 26, oldConnectivity, 51 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 27, oldConnectivity, 14 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 28, oldConnectivity, 33 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 29, oldConnectivity, 56 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 30, oldConnectivity, 59 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 31, oldConnectivity, 32 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 32, oldConnectivity, 48 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 33, oldConnectivity, 49 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 34, oldConnectivity, 50 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 35, oldConnectivity, 51 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 36, oldConnectivity, 56 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 37, oldConnectivity, 57 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 38, oldConnectivity, 58 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 39, oldConnectivity, 59 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 40, oldConnectivity, 49 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 41, oldConnectivity, 10 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 42, oldConnectivity, 11 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 43, oldConnectivity, 50 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 44, oldConnectivity, 57 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 45, oldConnectivity, 34 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 46, oldConnectivity, 35 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 47, oldConnectivity, 58 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 48, oldConnectivity, 14 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 49, oldConnectivity, 51 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 50, oldConnectivity, 13 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 51, oldConnectivity, 3 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 52, oldConnectivity, 32 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 53, oldConnectivity, 59 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 54, oldConnectivity, 39 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 55, oldConnectivity, 27 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 56, oldConnectivity, 51 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 57, oldConnectivity, 50 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 58, oldConnectivity, 12 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 59, oldConnectivity, 13 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 60, oldConnectivity, 59 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 61, oldConnectivity, 58 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 62, oldConnectivity, 38 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 63, oldConnectivity, 39 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 64, oldConnectivity, 50 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 65, oldConnectivity, 11 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 66, oldConnectivity, 2 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 67, oldConnectivity, 12 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 68, oldConnectivity, 58 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 69, oldConnectivity, 35 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 70, oldConnectivity, 26 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 71, oldConnectivity, 38 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 72, oldConnectivity, 24 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 73, oldConnectivity, 36 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 74, oldConnectivity, 56 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 75, oldConnectivity, 33 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 76, oldConnectivity, 28 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 77, oldConnectivity, 44 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 78, oldConnectivity, 60 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 79, oldConnectivity, 41 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 80, oldConnectivity, 36 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 81, oldConnectivity, 37 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 82, oldConnectivity, 57 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 83, oldConnectivity, 56 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 84, oldConnectivity, 44 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 85, oldConnectivity, 45 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 86, oldConnectivity, 61 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 87, oldConnectivity, 60 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 88, oldConnectivity, 37 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 89, oldConnectivity, 25 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 90, oldConnectivity, 34 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 91, oldConnectivity, 57 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 92, oldConnectivity, 45 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 93, oldConnectivity, 29 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 94, oldConnectivity, 42 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 95, oldConnectivity, 61 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 96, oldConnectivity, 33 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 97, oldConnectivity, 56 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 98, oldConnectivity, 59 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 99, oldConnectivity, 32 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 100, oldConnectivity, 41 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 101, oldConnectivity, 60 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 102, oldConnectivity, 63 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 103, oldConnectivity, 40 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 104, oldConnectivity, 56 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 105, oldConnectivity, 57 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 106, oldConnectivity, 58 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 107, oldConnectivity, 59 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 108, oldConnectivity, 60 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 109, oldConnectivity, 61 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 110, oldConnectivity, 62 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 111, oldConnectivity, 63 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 112, oldConnectivity, 57 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 113, oldConnectivity, 34 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 114, oldConnectivity, 35 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 115, oldConnectivity, 58 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 116, oldConnectivity, 61 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 117, oldConnectivity, 42 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 118, oldConnectivity, 43 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 119, oldConnectivity, 62 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 120, oldConnectivity, 32 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 121, oldConnectivity, 59 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 122, oldConnectivity, 39 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 123, oldConnectivity, 27 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 124, oldConnectivity, 40 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 125, oldConnectivity, 63 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 126, oldConnectivity, 47 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 127, oldConnectivity, 31 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 128, oldConnectivity, 59 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 129, oldConnectivity, 58 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 130, oldConnectivity, 38 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 131, oldConnectivity, 39 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 132, oldConnectivity, 63 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 133, oldConnectivity, 62 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 134, oldConnectivity, 46 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 135, oldConnectivity, 47 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 136, oldConnectivity, 58 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 137, oldConnectivity, 35 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 138, oldConnectivity, 26 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 139, oldConnectivity, 38 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 140, oldConnectivity, 62 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 141, oldConnectivity, 43 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 142, oldConnectivity, 30 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 143, oldConnectivity, 46 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 144, oldConnectivity, 28 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 145, oldConnectivity, 44 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 146, oldConnectivity, 60 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 147, oldConnectivity, 41 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 148, oldConnectivity, 4 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 149, oldConnectivity, 16 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 150, oldConnectivity, 52 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 151, oldConnectivity, 23 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 152, oldConnectivity, 44 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 153, oldConnectivity, 45 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 154, oldConnectivity, 61 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 155, oldConnectivity, 60 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 156, oldConnectivity, 16 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 157, oldConnectivity, 17 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 158, oldConnectivity, 53 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 159, oldConnectivity, 52 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 160, oldConnectivity, 45 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 161, oldConnectivity, 29 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 162, oldConnectivity, 42 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 163, oldConnectivity, 61 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 164, oldConnectivity, 17 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 165, oldConnectivity, 5 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 166, oldConnectivity, 18 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 167, oldConnectivity, 53 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 168, oldConnectivity, 41 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 169, oldConnectivity, 60 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 170, oldConnectivity, 63 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 171, oldConnectivity, 40 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 172, oldConnectivity, 23 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 173, oldConnectivity, 52 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 174, oldConnectivity, 55 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 175, oldConnectivity, 22 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 176, oldConnectivity, 60 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 177, oldConnectivity, 61 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 178, oldConnectivity, 62 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 179, oldConnectivity, 63 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 180, oldConnectivity, 52 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 181, oldConnectivity, 53 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 182, oldConnectivity, 54 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 183, oldConnectivity, 55 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 184, oldConnectivity, 61 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 185, oldConnectivity, 42 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 186, oldConnectivity, 43 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 187, oldConnectivity, 62 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 188, oldConnectivity, 53 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 189, oldConnectivity, 18 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 190, oldConnectivity, 19 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 191, oldConnectivity, 54 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 192, oldConnectivity, 40 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 193, oldConnectivity, 63 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 194, oldConnectivity, 47 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 195, oldConnectivity, 31 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 196, oldConnectivity, 22 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 197, oldConnectivity, 55 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 198, oldConnectivity, 21 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 199, oldConnectivity, 7 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 200, oldConnectivity, 63 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 201, oldConnectivity, 62 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 202, oldConnectivity, 46 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 203, oldConnectivity, 47 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 204, oldConnectivity, 55 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 205, oldConnectivity, 54 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 206, oldConnectivity, 20 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 207, oldConnectivity, 21 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 208, oldConnectivity, 62 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 209, oldConnectivity, 43 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 210, oldConnectivity, 30 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 211, oldConnectivity, 46 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 212, oldConnectivity, 54 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 213, oldConnectivity, 19 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 214, oldConnectivity, 6 + valuesStartIndex, 1);
			newConnectivity->copyValues(startIndex + 215, oldConnectivity, 20 + valuesStartIndex, 1);
		}

		for(unsigned int i=0; i<gridToConvert->getNumberOfAttributes(); ++i)
		{
			boost::shared_ptr<XdmfAttribute> currAttribute = gridToConvert->getAttribute(i);
			if(currAttribute->getAttributeCenter() == XdmfAttributeCenter::Node())
			{
				toReturn->insert(currAttribute);
			}
			else if(currAttribute->getAttributeCenter() == XdmfAttributeCenter::Cell())
			{
				if(!currAttribute->getArray()->isInitialized())
				{
					currAttribute->getArray()->read();
				}

				boost::shared_ptr<XdmfAttribute> newAttribute = XdmfAttribute::New();
				newAttribute->setName(currAttribute->getName());
				newAttribute->setAttributeType(currAttribute->getAttributeType());
				newAttribute->setAttributeCenter(currAttribute->getAttributeCenter());

				boost::shared_ptr<XdmfArray> vals = newAttribute->getArray();
				vals->initialize(currAttribute->getArray()->getType());
				vals->resize(currAttribute->getArray()->getSize() * 27, 0);
				for(unsigned int j=0; j<currAttribute->getArray()->getSize(); ++j)
				{
					vals->copyValues(j * 27, currAttribute->getArray(), j, 27, 1, 0);
				}
				toReturn->insert(newAttribute);
			}
		}
		return toReturn;
	}
};

609
boost::shared_ptr<XdmfGrid> XdmfTopologyConverter::convert(const boost::shared_ptr<XdmfGrid> gridToConvert, const boost::shared_ptr<const XdmfTopologyType> topologyType) const
610
{
611
612
613
614
615
616
	boost::shared_ptr<const XdmfTopologyType> topologyTypeToConvert = gridToConvert->getTopology()->getTopologyType();
	if(topologyTypeToConvert == topologyType)
	{
		// No conversion necessary
		return gridToConvert;
	}
617

618
619
620
621
	if(gridToConvert->getGeometry()->getGeometryType() != XdmfGeometryType::XYZ())
	{
		assert(false);
	}
622

623
624
625
626
627
628
629
630
	if(topologyTypeToConvert == XdmfTopologyType::Hexahedron())
	{
		if(topologyType == XdmfTopologyType::Hexahedron_64())
		{
			HexahedronToHexahedron64 converter;
			return converter.convert(gridToConvert);
		}
	}
631
632
633
634
635
636
637
638
	else if(topologyTypeToConvert == XdmfTopologyType::Hexahedron_64())
	{
		if(topologyType == XdmfTopologyType::Hexahedron())
		{
			Hexahedron64ToHexahedron converter;
			return converter.convert(gridToConvert);
		}
	}
639
640
	assert(false);
}