-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtkCGNSReaderInternal.cxx
1039 lines (961 loc) · 29.1 KB
/
vtkCGNSReaderInternal.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
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
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
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
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
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
848
849
850
851
852
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
// -*- c++ -*-
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCGNSReaderInternal.h
Copyright (c) 2013-2014 Mickael Philit
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm 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.
=========================================================================*/
#include "vtkCGNSReaderInternal.h"
#include <algorithm>
#include "vtkCellType.h"
#include "cgio_helpers.h"
namespace CGNSRead
{
//------------------------------------------------------------------------------
int setUpRind(const int cgioNum, const double rindId, int *rind)
{
CGNSRead::char_33 dataType;
if (cgio_get_data_type(cgioNum, rindId, dataType) != CG_OK)
{
std::cerr << "Problem while reading Rind data type\n";
return 1;
}
if (strcmp(dataType, "I4") == 0)
{
std::vector<int> mdata;
CGNSRead::readNodeData<int>(cgioNum, rindId, mdata);
for (std::size_t index=0; index < mdata.size(); index++)
{
rind[index] = static_cast<int>(mdata[index]);
}
}
else if (strcmp(dataType, "I8") == 0)
{
std::vector<cglong_t> mdata;
CGNSRead::readNodeData<cglong_t> ( cgioNum, rindId, mdata );
for (std::size_t index=0; index < mdata.size(); index++)
{
rind[index] = static_cast<int>(mdata[index]);
}
}
return 0;
}
//------------------------------------------------------------------------------
int getFirstNodeId(const int cgioNum, const double parentId,
const char *label, double *id)
{
int nId, n, nChildren, len;
int ier = 0;
char nodeLabel[CGIO_MAX_NAME_LENGTH+1];
if (cgio_number_children(cgioNum, parentId, &nChildren) != CG_OK)
{
return 1;
}
if (nChildren < 1)
{
return 1;
}
double *idList = new double[nChildren];
cgio_children_ids(cgioNum, parentId, 1, nChildren, &len, idList);
if (len != nChildren)
{
delete[] idList;
std::cerr << "Mismatch in number of children and child IDs read"
<< std::endl;
return 1;
}
nId = 0;
for (n = 0; n < nChildren; n++)
{
if (cgio_get_label(cgioNum, idList[n], nodeLabel))
{
return 1;
}
if (0 == strcmp(nodeLabel, label))
{
*id = idList[n];
nId = 1;
}
else
{
cgio_release_id(cgioNum, idList[n]);
}
if (nId != 0)
{
break;
}
}
n++;
while (n < nChildren)
{
cgio_release_id(cgioNum, idList[n]);
n++;
}
if (nId < 1)
{
*id = 0.0;
ier = 1;
}
delete[] idList;
return ier;
}
//------------------------------------------------------------------------------
int get_section_connectivity(const int cgioNum, const double cgioSectionId,
const int dim, const cgsize_t* srcStart,
const cgsize_t* srcEnd, const cgsize_t* srcStride,
const cgsize_t* memStart, const cgsize_t* memEnd,
const cgsize_t* memStride, const cgsize_t* memDim,
vtkIdType* localElements)
{
const char *connectivityPath = "ElementConnectivity";
double cgioElemConnectId;
char dataType[3];
std::size_t sizeOfCnt;
cgio_get_node_id(cgioNum, cgioSectionId, connectivityPath, &cgioElemConnectId);
cgio_get_data_type(cgioNum, cgioElemConnectId, dataType);
if (strcmp(dataType, "I4") == 0)
{
sizeOfCnt = sizeof(int);
}
else if (strcmp(dataType, "I8") == 0)
{
sizeOfCnt = sizeof ( cglong_t );
}
else
{
std::cerr << "ElementConnectivity data_type unknown\n";
}
if (sizeOfCnt == sizeof(vtkIdType))
{
if (cgio_read_data(cgioNum, cgioElemConnectId,
srcStart, srcEnd, srcStride, dim, memDim,
memStart, memEnd, memStride,
(void *) localElements) != CG_OK)
{
char message[81];
cgio_error_message(message);
std::cerr << "cgio_read_data :" << message;
}
}
else
{
// Need to read into temp array to convert data
cgsize_t nn = 1;
for(int ii=0; ii< dim; ii++)
{
nn *= memDim[ii];
}
if (sizeOfCnt == sizeof(int))
{
int *data = new int[nn];
if (data == 0)
{
std::cerr << "Allocation failed for temporary connectivity array\n";
}
if (cgio_read_data(cgioNum, cgioElemConnectId,
srcStart, srcEnd, srcStride, dim, memDim,
memStart, memEnd, memStride,
(void *) data) != CG_OK)
{
delete[] data;
char message[81];
cgio_error_message(message);
std::cerr << "cgio_read_data :" << message;
return 1;
}
for (cgsize_t n = 0; n < nn; n++)
{
localElements[n] = static_cast<vtkIdType>(data[n]);
}
delete[] data;
}
else if (sizeOfCnt == sizeof(cglong_t))
{
cglong_t* data = new cglong_t[nn];
if (data == 0)
{
std::cerr << "Allocation failed for temporary connectivity array\n";
return 1;
}
if ( cgio_read_data(cgioNum, cgioElemConnectId,
srcStart, srcEnd, srcStride, dim, memDim,
memStart, memEnd, memStride,
(void *) data) != CG_OK)
{
delete[] data;
char message[81];
cgio_error_message ( message );
std::cerr << "cgio_read_data :" << message;
return 1;
}
for (cgsize_t n = 0; n < nn; n++)
{
localElements[n] = static_cast<vtkIdType>(data[n]);
}
delete[] data;
}
}
cgio_release_id(cgioNum, cgioElemConnectId);
return 0;
}
//------------------------------------------------------------------------------
int GetVTKElemType(CGNS_ENUMT(ElementType_t) elemType, bool &higherOrderWarning,
bool &cgnsOrderFlag)
{
int cellType;
higherOrderWarning = false;
cgnsOrderFlag = false;
//
switch(elemType)
{
case CGNS_ENUMV(NODE):
cellType = VTK_VERTEX;
break;
case CGNS_ENUMV(BAR_2):
cellType = VTK_LINE;
break;
case CGNS_ENUMV(BAR_3):
cellType = VTK_QUADRATIC_EDGE;
higherOrderWarning = true;
break;
//case CGNS_ENUMV(BAR_4):
// cellType = VTK_CUBIC_LINE;
// higherOrderWarning = true;
// break;
case CGNS_ENUMV(TRI_3) :
cellType = VTK_TRIANGLE;
break;
case CGNS_ENUMV(TRI_6):
cellType = VTK_QUADRATIC_TRIANGLE;
higherOrderWarning = true;
break;
case CGNS_ENUMV(QUAD_4):
cellType = VTK_QUAD;
break;
case CGNS_ENUMV(QUAD_8):
cellType = VTK_QUADRATIC_QUAD;
higherOrderWarning = true;
break;
case CGNS_ENUMV(QUAD_9):
cellType = VTK_BIQUADRATIC_QUAD;
higherOrderWarning = true;
break;
case CGNS_ENUMV(TETRA_4):
cellType = VTK_TETRA;
break;
case CGNS_ENUMV(TETRA_10):
cellType = VTK_QUADRATIC_TETRA;
higherOrderWarning = true;
break;
case CGNS_ENUMV(PYRA_5):
cellType = VTK_PYRAMID;
break;
case CGNS_ENUMV(PYRA_14):
cellType = VTK_QUADRATIC_PYRAMID;
higherOrderWarning = true;
break;
case CGNS_ENUMV(PENTA_6):
cellType = VTK_WEDGE;
break;
case CGNS_ENUMV(PENTA_15):
cellType = VTK_QUADRATIC_WEDGE;
higherOrderWarning = true;
cgnsOrderFlag = true;
break;
case CGNS_ENUMV(PENTA_18):
cellType = VTK_BIQUADRATIC_QUADRATIC_WEDGE;
higherOrderWarning = true;
cgnsOrderFlag = true;
break;
case CGNS_ENUMV(HEXA_8):
cellType = VTK_HEXAHEDRON;
break;
case CGNS_ENUMV(HEXA_20):
cellType = VTK_QUADRATIC_HEXAHEDRON;
higherOrderWarning = true;
cgnsOrderFlag = true;
break;
case CGNS_ENUMV(HEXA_27):
cellType = VTK_TRIQUADRATIC_HEXAHEDRON;
higherOrderWarning = true;
cgnsOrderFlag = true;
break;
default:
cellType = VTK_EMPTY_CELL;
break;
}
return cellType;
}
//----------------------------------------------------------------------
//static const int NULL_translate[27] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
// 16,17,18,19,20,21,22,23,24,25,26};
//CGNS --> VTK ordering of Elements
static const int NODE_ToVTK[1] = {0};
static const int BAR_2_ToVTK[2] = {0,1};
static const int BAR_3_ToVTK[3] = {0,1,2};
static const int BAR_4_ToVTK[4] = {0,1,2,3};
static const int TRI_3_ToVTK[3] = {0,1,2};
static const int TRI_6_ToVTK[6] = {0,1,2,3,4,5};
static const int QUAD_4_ToVTK[4] = {0,1,2,3};
static const int QUAD_8_ToVTK[8] = {0,1,2,3,4,5,6,7};
static const int QUAD_9_ToVTK[9] = {0,1,2,3,4,5,6,7,8};
static const int TETRA_4_ToVTK[4] = {0,1,2,3};
static const int TETRA_10_ToVTK[10] = {0,1,2,3,4,5,6,7,8,9};
static const int PYRA_5_ToVTK[5] = {0,1,2,3,4};
static const int PYRA_14_ToVTK[14] = {0,1,2,3,4,
5,6,7,8,9,
10,11,12,13
};
static const int PENTA_6_ToVTK[6] = {0,1,2,3,4,5};
static const int PENTA_15_ToVTK[15] = {0,1,2,3,4,5,6,7,8,
12,13,14,
9,10,11
};
static const int PENTA_18_ToVTK[18] = {0,1,2,3,4,5,6,7,8,
12,13,14,
9,10,11,
15,16,17
};
static const int HEXA_8_ToVTK[8] = {0,1,2,3,4,5,6,7};
static const int HEXA_20_ToVTK[20] = {0,1,2,3,4,5,6,7,
8,9,10,11,
16,17,18,19,
12,13,14,15
};
static const int HEXA_27_ToVTK[27] = {0,1,2,3,4,5,6,7,
8,9,10,11,
16,17,18,19,
12,13,14,15,
24,22,21,23,
20,25,26
};
//------------------------------------------------------------------------------
inline const int * getTranslator(const int cellType)
{
switch (cellType)
{
case VTK_VERTEX:
case VTK_LINE:
case VTK_QUADRATIC_EDGE:
case VTK_CUBIC_LINE:
case VTK_TRIANGLE:
case VTK_QUADRATIC_TRIANGLE:
case VTK_QUAD:
case VTK_QUADRATIC_QUAD:
case VTK_BIQUADRATIC_QUAD:
case VTK_TETRA:
case VTK_QUADRATIC_TETRA:
case VTK_PYRAMID:
case VTK_QUADRATIC_PYRAMID:
case VTK_WEDGE:
return NULL;
case VTK_QUADRATIC_WEDGE:
return CGNSRead::PENTA_15_ToVTK;
case VTK_BIQUADRATIC_QUADRATIC_WEDGE:
return CGNSRead::PENTA_18_ToVTK;
case VTK_HEXAHEDRON:
return NULL;
case VTK_QUADRATIC_HEXAHEDRON:
return CGNSRead::HEXA_20_ToVTK;
case VTK_TRIQUADRATIC_HEXAHEDRON:
return CGNSRead::HEXA_27_ToVTK;
default:
return NULL;
}
}
//------------------------------------------------------------------------------
void CGNS2VTKorder(const vtkIdType size, const int *cells_types,
vtkIdType *elements)
{
const int maxPointsPerCells = 27;
int tmp[maxPointsPerCells];
const int *translator;
vtkIdType pos = 0;
for (vtkIdType icell = 0; icell < size; ++icell)
{
translator = getTranslator(cells_types[icell]);
vtkIdType numPointsPerCell = elements[pos];
pos++;
if (translator != NULL)
{
for (vtkIdType ip = 0; ip < numPointsPerCell; ++ip)
{
tmp[ip] = elements[translator[ip]+pos];
}
for (vtkIdType ip = 0; ip < numPointsPerCell; ++ip)
{
elements[pos+ip] = tmp[ip];
}
}
pos += numPointsPerCell;
}
}
//------------------------------------------------------------------------------
void CGNS2VTKorderMonoElem(const vtkIdType size, const int cell_type,
vtkIdType *elements)
{
const int maxPointsPerCells = 27;
int tmp[maxPointsPerCells];
const int *translator;
translator = getTranslator(cell_type);
if (translator == NULL)
{
return;
}
vtkIdType pos = 0;
for (vtkIdType icell = 0; icell < size; ++icell)
{
vtkIdType numPointsPerCell = elements[pos];
pos++;
for (vtkIdType ip = 0; ip < numPointsPerCell; ++ip)
{
tmp[ip] = elements[translator[ip]+pos];
}
for (vtkIdType ip = 0; ip < numPointsPerCell; ++ip)
{
elements[pos+ip] = tmp[ip];
}
pos += numPointsPerCell;
}
}
//------------------------------------------------------------------------------
bool testValidVector(const CGNSVector& item)
{
// apply some logic and return true or false
return (item.numComp == 0);
}
//------------------------------------------------------------------------------
void fillVectorsFromVars(std::vector< CGNSRead::CGNSVariable >& vars,
std::vector< CGNSRead::CGNSVector >& vectors,
const int physicalDim)
{
// get number of scalars and vectors
const std::size_t nvar = vars.size();
std::size_t len;
char_33 name;
for (std::size_t n = 0; n < nvar; ++n)
{
vars[n].isComponent = false;
vars[n].xyzIndex = 0;
}
for (std::size_t n = 0; n < nvar; ++n)
{
len = strlen(vars[n].name) - 1;
switch (vars[n].name[len])
{
case 'X':
vars[n].xyzIndex = 1;
vars[n].isComponent = true;
break;
case 'Y':
vars[n].xyzIndex = 2;
vars[n].isComponent = true;
break;
case 'Z':
vars[n].xyzIndex = 3;
vars[n].isComponent = true;
break;
}
if (vars[n].isComponent == true)
{
strcpy(name, vars[n].name);
name[len] = '\0';
std::vector< CGNSRead::CGNSVector >::iterator iter =
CGNSRead::getVectorFromName(vectors, name);
if (iter != vectors.end())
{
iter->numComp += vars[n].xyzIndex ;
iter->xyzIndex[vars[n].xyzIndex-1] = (int) n ;
}
else
{
CGNSRead::CGNSVector newVector;
newVector.xyzIndex[0] = -1;
newVector.xyzIndex[1] = -1;
newVector.xyzIndex[2] = -1;
newVector.numComp = vars[n].xyzIndex ;
newVector.xyzIndex[vars[n].xyzIndex-1] = (int) n ;
strcpy(newVector.name , name);
vectors.push_back(newVector);
}
}
}
// Detect and tag invalid vector :
bool invalid = false;
for (std::vector<CGNSRead::CGNSVector>::iterator iter = vectors.begin();
iter != vectors.end(); ++iter)
{
// Check if number of component agrees with phys_dim
if (((physicalDim == 3) && (iter->numComp != 6)) ||
((physicalDim == 2) && (iter->numComp != 3)))
{
for (int index = 0; index < physicalDim; index++)
{
int nv = iter->xyzIndex[index];
if (nv >= 0)
{
vars[nv].isComponent = false;
}
}
iter->numComp = 0;
invalid = true;
}
// Check if a variable is present with a similar
// name as the vector being built
if (CGNSRead::isACGNSVariable(vars, iter->name) == true)
{
//vtkWarningMacro ( "Warning, vector " << iter->name
// << " can't be assembled." << std::endl );
for (int index = 0; index < physicalDim; index++)
{
int n = iter->xyzIndex[index];
if (n >= 0)
{
vars[n].isComponent = false;
}
}
iter->numComp = 0;
invalid = true;
}
if (iter->numComp > 0)
{
// Check if DataType_t are identical for all components
if ((vars[iter->xyzIndex[0]].dt != vars[iter->xyzIndex[1]].dt) ||
(vars[iter->xyzIndex[0]].dt != vars[iter->xyzIndex[physicalDim-1]].dt))
{
for (int index = 0; index < physicalDim; index++)
{
int n = iter->xyzIndex[index];
if (n >= 0)
{
vars[n].isComponent = false;
}
}
iter->numComp = 0;
invalid = true;
}
}
}
// Remove invalid vectors
if (invalid == true)
{
vectors.erase(std::remove_if(vectors.begin(), vectors.end(),
CGNSRead::testValidVector),
vectors.end());
}
}
//------------------------------------------------------------------------------
bool vtkCGNSMetaData::Parse(const char* cgnsFileName)
{
if (!cgnsFileName)
{
return false;
}
if (this->LastReadFilename == cgnsFileName)
{
return true;
}
int cgioNum;
int ier;
double rootId;
char nodeLabel[CGIO_MAX_NAME_LENGTH+1];
// use cgio routine to open the file
if (cgio_open_file(cgnsFileName, CGIO_MODE_READ, 0, &cgioNum ) != CG_OK)
{
cgio_error_exit("cgio_file_open");
}
if ( cgio_get_root_id(cgioNum, &rootId) != CG_OK)
{
cgio_error_exit("cgio_get_root_id");
}
// Get base id list :
std::vector<double> baseIds;
ier = readBaseIds(cgioNum, rootId, baseIds);
if ( ier != 0 )
{
return false;
}
if ( this->baseList.size() > 0 )
{
this->baseList.clear();
}
this->baseList.resize(baseIds.size());
// Read base list
for (std::size_t numBase=0; numBase < baseIds.size(); numBase++)
{
// base names for later selection
readBaseCoreInfo(cgioNum, baseIds[numBase], this->baseList[numBase]);
std::vector<double> baseChildId;
getNodeChildrenId(cgioNum, baseIds[numBase], baseChildId);
std::size_t nzones = 0;
std::size_t nn;
for (nzones = 0, nn = 0; nn < baseChildId.size(); ++nn)
{
if (cgio_get_label(cgioNum, baseChildId[nn], nodeLabel) != CG_OK)
{
return false;
}
if (strcmp(nodeLabel, "Zone_t") == 0)
{
if (nzones < nn)
{
baseChildId[nzones] = baseChildId[nn];
}
nzones++;
}
else if (strcmp(nodeLabel, "Family_t") == 0)
{
readBaseFamily(cgioNum, baseChildId[nn],
this->baseList[numBase]);
}
else if (strcmp(nodeLabel, "BaseIterativeData_t") == 0)
{
readBaseIteration(cgioNum, baseChildId[nn],
this->baseList[numBase]);
}
else if (strcmp(nodeLabel, "ReferenceState_t") == 0)
{
readBaseReferenceState(cgioNum, baseChildId[nn],
this->baseList[numBase]);
}
else
{
cgio_release_id(cgioNum, baseChildId[nn]);
}
}
this->baseList[numBase].nzones = static_cast<int>(nzones);
if (this->baseList[numBase].times.size() < 1)
{
// If no time information were found
// just put default values
this->baseList[numBase].steps.clear();
this->baseList[numBase].times.clear();
this->baseList[numBase].steps.push_back(0);
this->baseList[numBase].times.push_back(0.0);
}
if ( nzones > 0 )
{
// variable name and more, based on first zone only
readZoneInfo(cgioNum, baseChildId[0], this->baseList[numBase]);
}
}
// Same Timesteps in all root nodes
// or separated time range by root nodes
// timesteps need to be sorted for each root node
this->GlobalTime.clear();
for (std::size_t numBase=0; numBase < baseList.size(); numBase++)
{
if (numBase == 0)
{
this->GlobalTime = this->baseList[numBase].times;
continue;
}
const std::vector<double>& times = this->baseList[numBase].times;
if (times.front() > this->GlobalTime.back())
{
this->GlobalTime.insert( this->GlobalTime.end(),
times.begin(), times.end());
}
if (times.back() < this->GlobalTime.front())
{
this->GlobalTime.insert( this->GlobalTime.begin(),
times.begin(), times.end());
}
}
this->LastReadFilename = cgnsFileName;
cgio_close_file ( cgioNum );
return true;
}
//------------------------------------------------------------------------------
vtkCGNSMetaData::vtkCGNSMetaData()
{
}
//------------------------------------------------------------------------------
vtkCGNSMetaData::~vtkCGNSMetaData()
{
}
//------------------------------------------------------------------------------
void vtkCGNSMetaData::PrintSelf(std::ostream& os)
{
os << "--> vtkCGNSMetaData" << std::endl;
os << "LastReadFileName: " << this->LastReadFilename << std::endl;
os << "Base information:" << std::endl;
for (std::size_t b=0; b < this->baseList.size(); b++)
{
os << " Base name: " << this->baseList[b].name << std::endl ;
os << " number of zones: " << this->baseList[b].nzones << std::endl;
os << " number of time steps: "<< this->baseList[b].times.size()
<< std::endl;
os << " use unsteady grid: "<< this->baseList[b].useGridPointers
<< std::endl;
os << " use unsteady flow: "<< this->baseList[b].useFlowPointers
<< std::endl;
for (int i = 0;
i < this->baseList[b].PointDataArraySelection.GetNumberOfArrays();
++i)
{
os << " Vertex :: ";
os << this->baseList[b].PointDataArraySelection.GetArrayName(i)
<< std::endl;
}
for (int i = 0;
i < this->baseList[b].CellDataArraySelection.GetNumberOfArrays();
++i)
{
os << " Cell :: ";
os << this->baseList[b].CellDataArraySelection.GetArrayName(i)
<< std::endl;
}
os << " Family Number: "<< this->baseList[b].family.size() << std::endl;
for (std::size_t fam=0; fam< this->baseList[b].family.size(); fam++)
{
os << " Family: " << this->baseList[b].family[fam].name << " is BC: "
<< this->baseList[b].family[fam].isBC << std::endl;
}
os << " Reference State:"<< std::endl;
std::map<std::string, double>::iterator iter;
for (iter = this->baseList[b].referenceState.begin();
iter !=this->baseList[b].referenceState.end(); iter++)
{
os << " Variable: " << iter->first;
os << " Value: " << iter->second << std::endl;
}
}
}
#ifdef PARAVIEW_USE_MPI
//------------------------------------------------------------------------------
static void BroadcastCGNSString(vtkMultiProcessController* ctrl,
CGNSRead::char_33 & str)
{
int len = 33;
if ( str )
{
ctrl->Broadcast(&len, 1, 0);
ctrl->Broadcast(&str[0], len, 0);
}
else
{
len = 0;
ctrl->Broadcast(&len, 1, 0);
}
}
//------------------------------------------------------------------------------
static void BroadcastString(vtkMultiProcessController* controller,
std::string& str, int rank)
{
unsigned long len = static_cast<unsigned long>(str.size()) + 1;
controller->Broadcast(&len, 1, 0);
if (len)
{
if (rank)
{
std::vector<char> tmp;
tmp.resize(len);
controller->Broadcast(&(tmp[0]), len, 0);
str = &tmp[0];
}
else
{
const char* start = str.c_str();
std::vector<char> tmp(start, start + len);
controller->Broadcast(&tmp[0], len, 0);
}
}
}
//------------------------------------------------------------------------------
static void BroadcastDoubleVector(vtkMultiProcessController* controller,
std::vector<double>& dvec, int rank)
{
unsigned long len = static_cast<unsigned long>(dvec.size());
controller->Broadcast(&len, 1, 0);
if (rank)
{
dvec.resize(len);
}
if (len)
{
controller->Broadcast(&dvec[0], len, 0);
}
}
//------------------------------------------------------------------------------
static void BroadcastIntVector(vtkMultiProcessController* controller,
std::vector<int>& ivec, int rank)
{
unsigned long len = static_cast<unsigned long>(ivec.size());
controller->Broadcast(&len, 1, 0);
if (rank)
{
ivec.resize(len);
}
if (len)
{
controller->Broadcast(&ivec[0], len, 0);
}
}
//------------------------------------------------------------------------------
static void BroadcastSelection(vtkMultiProcessController* controller,
CGNSRead::vtkCGNSArraySelection & selection,
int rank)
{
unsigned long len = static_cast<unsigned long>(selection.size());
controller->Broadcast(&len, 1, 0);
if ( rank == 0 )
{
std::map<std::string, bool>::iterator ite;
int tmp;
for (ite = selection.begin(); ite != selection.end(); ++ ite)
{
unsigned long len = static_cast<unsigned long>(ite->first.size()) + 1;
controller->Broadcast(&len, 1, 0);
if (len)
{
const char* start = ite->first.c_str();
std::vector<char> tmp(start, start + len);
controller->Broadcast(&tmp[0], len, 0);
}
tmp = (int) ite->second;
controller->Broadcast(&tmp, 1, 0);
}
}
else
{
unsigned long i;
for (i = 0; i < len; ++ i)
{
std::string key;
int tmp;
CGNSRead::BroadcastString(controller, key, rank);
selection[key] = false;
controller->Broadcast(&tmp, 1, 0);
selection[key] = (bool) tmp;
}
}
}
//------------------------------------------------------------------------------
static void BroadcastRefState(vtkMultiProcessController* controller,
std::map<std::string,double> & refInfo, int rank)
{
unsigned long len = static_cast<unsigned long>(refInfo.size());
controller->Broadcast(&len, 1, 0);
if (rank == 0)
{
std::map<std::string, double>::iterator ite;
for (ite = refInfo.begin(); ite != refInfo.end(); ++ ite)
{
unsigned long len = static_cast<unsigned long>(ite->first.size()) + 1;
controller->Broadcast(&len, 1, 0);
if (len)
{
const char* start = ite->first.c_str();
std::vector<char> tmp(start, start + len);
controller->Broadcast(&tmp[0], len, 0);
}
controller->Broadcast(&ite->second, 1, 0);
}
}
else
{
for (unsigned long i = 0; i < len; ++i)
{
std::string key;
CGNSRead::BroadcastString(controller, key, rank);
refInfo[key] = 0.0;
controller->Broadcast(&refInfo[key], 1, 0);
}
}
}
//------------------------------------------------------------------------------
static void BroadcastFamilies(vtkMultiProcessController* controller,
std::vector<CGNSRead::FamilyInformation>& famInfo,
int rank)
{
unsigned long len = static_cast<unsigned long>(famInfo.size());
controller->Broadcast(&len, 1, 0);
if (rank != 0)
{
famInfo.resize(len);
}
std::vector<CGNSRead::FamilyInformation>::iterator ite;
for (ite = famInfo.begin(); ite != famInfo.end(); ++ite)
{
BroadcastCGNSString(controller, ite->name);
int flags = 0;
if (rank == 0)
{
if (ite->isBC == true)
{
flags = 1;
}
controller->Broadcast(&flags, 1, 0);
}
else
{
controller->Broadcast(&flags, 1, 0);
if ((flags & 1) != 0)
{
ite->isBC = true;
}
}
}
}
//------------------------------------------------------------------------------
void vtkCGNSMetaData::Broadcast(vtkMultiProcessController* controller,
int rank)
{
unsigned long len = static_cast<unsigned long>(this->baseList.size());
controller->Broadcast(&len, 1, 0);
if (rank != 0)
{
this->baseList.resize(len);
}
std::vector<CGNSRead::BaseInformation>::iterator ite;
for (ite = this->baseList.begin(); ite != baseList.end(); ++ite)
{
CGNSRead::BroadcastCGNSString(controller, ite->name);
controller->Broadcast(&ite->cellDim, 1, 0);
controller->Broadcast(&ite->physicalDim, 1, 0);
controller->Broadcast(&ite->baseNumber, 1, 0);
controller->Broadcast(&ite->nzones, 1, 0);
int flags = 0;
if (rank == 0)
{
if (ite->useGridPointers == true)