-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkCGNSReader.cxx
2984 lines (2628 loc) · 91.4 KB
/
vtkCGNSReader.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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCGNSReader.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 "vtkCGNSReader.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkCallbackCommand.h"
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkDataArraySelection.h"
#include "vtkIdTypeArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkTypeInt32Array.h"
#include "vtkTypeInt64Array.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkStructuredGrid.h"
#include "vtkUnsignedIntArray.h"
#include "vtkUnstructuredGrid.h"
#include "vtkVertex.h"
#include "vtkPolyhedron.h"
#include "vtkErrorCode.h"
#include "vtkCharArray.h"
#include "vtkDoubleArray.h"
#include "vtkFloatArray.h"
#include "vtkIntArray.h"
#include "vtkLongArray.h"
#include "vtkInformationStringKey.h"
#include "vtkPVInformationKeys.h"
#include <algorithm>
#include <iterator>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <vtksys/SystemTools.hxx>
#ifdef PARAVIEW_USE_MPI
#include "vtkMultiProcessController.h"
#endif
#include "cgio_helpers.h"
vtkStandardNewMacro ( vtkCGNSReader );
namespace
{
struct duo_t
{
duo_t()
{
pair[0] = 0;
pair[1] = 0;
}
int& operator[](std::size_t n) { return pair[n]; }
const int& operator[](std::size_t n) const { return pair[n]; }
private:
int pair[2];
};
}
//----------------------------------------------------------------------------
vtkCGNSReader::vtkCGNSReader()
{
this->FileName = NULL;
this->LoadBndPatch = 0;
this->NumberOfBases = 0;
this->ActualTimeStep = 0;
this->DoublePrecisionMesh = 1;
this->CreateEachSolutionAsBlock = 0;
this->PointDataArraySelection = vtkDataArraySelection::New();
this->CellDataArraySelection = vtkDataArraySelection::New();
this->BaseSelection = vtkDataArraySelection::New();
// Setup the selection callback to modify this object when an array
// selection is changed.
this->SelectionObserver = vtkCallbackCommand::New();
this->SelectionObserver->SetCallback(&vtkCGNSReader::SelectionModifiedCallback);
this->SelectionObserver->SetClientData(this);
this->PointDataArraySelection->AddObserver(vtkCommand::ModifiedEvent,
this->SelectionObserver);
this->CellDataArraySelection->AddObserver(vtkCommand::ModifiedEvent,
this->SelectionObserver);
this->BaseSelection->AddObserver(vtkCommand::ModifiedEvent,
this->SelectionObserver);
this->SetNumberOfInputPorts(0);
this->SetNumberOfOutputPorts(1);
#ifdef PARAVIEW_USE_MPI
this->ProcRank = 0;
this->ProcSize = 1;
this->Controller = NULL;
this->SetController(vtkMultiProcessController::GetGlobalController());
#endif
}
//----------------------------------------------------------------------------
vtkCGNSReader::~vtkCGNSReader()
{
this->SetFileName(0);
this->PointDataArraySelection->RemoveObserver(this->SelectionObserver);
this->PointDataArraySelection->Delete();
this->CellDataArraySelection->RemoveObserver(this->SelectionObserver);
this->CellDataArraySelection->Delete();
this->BaseSelection->RemoveObserver(this->SelectionObserver);
this->BaseSelection->Delete();
this->SelectionObserver->Delete();
#ifdef PARAVIEW_USE_MPI
this->SetController(NULL);
#endif
}
#ifdef PARAVIEW_USE_MPI
//----------------------------------------------------------------------------
void vtkCGNSReader::SetController(vtkMultiProcessController* c)
{
if (this->Controller == c)
{
return;
}
this->Modified();
if (this->Controller)
{
this->Controller->UnRegister(this);
}
this->Controller = c;
if (this->Controller)
{
this->Controller->Register(this);
this->ProcRank = this->Controller->GetLocalProcessId();
this->ProcSize = this->Controller->GetNumberOfProcesses();
}
if (!this->Controller || this->ProcSize <= 0)
{
this->ProcRank = 0;
this->ProcSize = 1;
}
}
#endif
//------------------------------------------------------------------------------
bool vtkCGNSReader::IsVarEnabled(CGNS_ENUMT(GridLocation_t) varcentering,
const CGNSRead::char_33 name)
{
vtkDataArraySelection *DataSelection = 0;
if (varcentering == CGNS_ENUMV(Vertex))
{
DataSelection = this->PointDataArraySelection;
}
else
{
DataSelection = this->CellDataArraySelection;
}
return (DataSelection->ArrayIsEnabled(name) != 0);
}
//------------------------------------------------------------------------------
int vtkCGNSReader::getGridAndSolutionName(const int base,
CGNSRead::char_33 GridCoordName,
CGNSRead::char_33 SolutionName,
bool& readGridCoordName,
bool& readSolutionName)
{
//
// Get Coordinates and FlowSolution node names
readGridCoordName = true;
readSolutionName = true;
if ((this->Internal.GetBase(base).useGridPointers == true) ||
(this->Internal.GetBase(base).useFlowPointers == true))
{
CGNSRead::char_33 zoneIterName;
double ziterId = 0;
std::size_t ptSize = 32*this->Internal.GetBase(base).steps.size() + 1;
char *pointers = new char[ptSize];
if (CGNSRead::getFirstNodeId(this->cgioNum, this->currentId,
"ZoneIterativeData_t", &ziterId) == CG_OK)
{
cgio_get_name(cgioNum, ziterId, zoneIterName);
//
CGNSRead::char_33 nodeLabel;
CGNSRead::char_33 nodeName;
std::vector<double> iterChildId;
CGNSRead::getNodeChildrenId(cgioNum, ziterId, iterChildId);
for (std::size_t nn = 0; nn < iterChildId.size(); nn++)
{
if (cgio_get_name(cgioNum, iterChildId[nn], nodeName) != CG_OK)
{
return 1;
}
if (cgio_get_label(cgioNum, iterChildId[nn], nodeLabel) != CG_OK)
{
return 1;
}
bool isDataArray = (strcmp(nodeLabel, "DataArray_t") == 0);
if (isDataArray &&
(strcmp(nodeName, "GridCoordinatesPointers") == 0))
{
cgio_read_block_data(this->cgioNum, iterChildId[nn],
(cgsize_t)(this->ActualTimeStep*32 + 1),
(cgsize_t)(this->ActualTimeStep*32 + 32),
( void * ) GridCoordName);
GridCoordName[32] ='\0';
readGridCoordName = false;
}
else if (isDataArray &&
(strcmp(nodeName, "FlowSolutionPointers") == 0))
{
cgio_read_block_data(this->cgioNum, iterChildId[nn],
(cgsize_t)(this->ActualTimeStep*32 + 1),
(cgsize_t)(this->ActualTimeStep*32 + 32),
(void *) SolutionName);
SolutionName[32] ='\0';
readSolutionName = false;
}
cgio_release_id(cgioNum, iterChildId[nn]);
}
}
else
{
strcpy(GridCoordName, "GridCoordinates");
strcpy(SolutionName, "FlowSolution");
}
delete [] pointers;
}
//
if (readGridCoordName)
{
// By default the grid name should be GridCoordinates
strcpy(GridCoordName, "GridCoordinates");
}
return 0;
}
//------------------------------------------------------------------------------
int vtkCGNSReader::getCoordsIdAndFillRind(const CGNSRead::char_33 GridCoordName,
const int physicalDim,
std::size_t& nCoordsArray,
std::vector<double>& gridChildId,
int* rind)
{
char nodeLabel[CGIO_MAX_NAME_LENGTH+1];
std::size_t na;
nCoordsArray = 0;
// Get GridCoordinate node ID for low level access
double gridId;
if (cgio_get_node_id(this->cgioNum, this->currentId,
GridCoordName, &gridId) != CG_OK)
{
char message[81];
cgio_error_message(message);
vtkErrorMacro(<< "Error while reading mesh coordinates node :" << message);
return 1;
}
// Get the number of Coordinates in GridCoordinates node
CGNSRead::getNodeChildrenId(this->cgioNum, gridId, gridChildId);
for (int n = 0; n < 6; n++)
{
rind[n] = 0;
}
for (nCoordsArray = 0, na = 0; na < gridChildId.size(); ++na)
{
if ( cgio_get_label(cgioNum, gridChildId[na], nodeLabel) != CG_OK)
{
vtkErrorMacro(<< "Not enough coordinates in node "
<< GridCoordName << "\n");
continue;
}
if (strcmp(nodeLabel, "DataArray_t") == 0)
{
if (nCoordsArray < na)
{
gridChildId[nCoordsArray] = gridChildId[na];
}
nCoordsArray++;
}
else if ( strcmp(nodeLabel, "Rind_t") == 0)
{
// check for rind
CGNSRead::setUpRind(this->cgioNum, gridChildId[na], rind);
}
else
{
cgio_release_id(cgioNum, gridChildId[na]);
}
}
if (nCoordsArray < static_cast<std::size_t>(physicalDim))
{
vtkErrorMacro(<< "Not enough coordinates in node "
<< GridCoordName << "\n");
return 1;
}
cgio_release_id(this->cgioNum, gridId);
return 0;
}
//------------------------------------------------------------------------------
int vtkCGNSReader::getVarsIdAndFillRind(const double cgioSolId,
std::size_t& nVarArray,
CGNS_ENUMT(GridLocation_t) & varCentering,
std::vector<double>& solChildId,
int* rind)
{
char nodeLabel[CGIO_MAX_NAME_LENGTH+1];
std::size_t na;
nVarArray = 0;
for (int n = 0; n < 6; ++n)
{
rind[n] = 0;
}
CGNSRead::getNodeChildrenId ( this->cgioNum, cgioSolId, solChildId );
for (nVarArray = 0, na = 0; na < solChildId.size(); ++na)
{
if (cgio_get_label(cgioNum, solChildId[na], nodeLabel) != CG_OK)
{
vtkErrorMacro(<< "Error while reading node label in solution\n");
continue;
}
if (strcmp(nodeLabel, "DataArray_t") == 0)
{
if (nVarArray < na)
{
solChildId[nVarArray] = solChildId[na];
}
nVarArray++;
}
else if ( strcmp(nodeLabel, "Rind_t") == 0)
{
CGNSRead::setUpRind(this->cgioNum, solChildId[na], rind);
}
else if ( strcmp(nodeLabel, "GridLocation_t") == 0)
{
CGNSRead::char_33 dataType;
if (cgio_get_data_type(cgioNum, solChildId[na], dataType) != CG_OK)
{
return 1;
}
if (strcmp(dataType, "C1") != 0)
{
std::cerr << "Unexpected data type for GridLocation_t node"
<< std::endl;
return 1;
}
std::string location;
CGNSRead::readNodeStringData(this->cgioNum, solChildId[na], location);
if (location == "Vertex")
{
varCentering = CGNS_ENUMV(Vertex);
}
else if (location == "CellCenter")
{
varCentering = CGNS_ENUMV(CellCenter);
}
else
{
varCentering = CGNS_ENUMV(GridLocationNull);
}
}
else
{
cgio_release_id(this->cgioNum, solChildId[na]);
}
}
return 0;
}
//------------------------------------------------------------------------------
int vtkCGNSReader::fillArrayInformation(const std::vector<double>& solChildId,
const int physicalDim,
std::vector< CGNSRead::CGNSVariable >& cgnsVars,
std::vector< CGNSRead::CGNSVector >& cgnsVectors)
{
// Read variable names
for (std::size_t ff = 0; ff < cgnsVars.size(); ++ff)
{
cgio_get_name(cgioNum, solChildId[ff], cgnsVars[ff].name);
cgnsVars[ff].isComponent = false;
cgnsVars[ff].xyzIndex = 0;
// read node data type
CGNSRead::char_33 dataType;
cgio_get_data_type(cgioNum , solChildId[ff], dataType);
if (strcmp(dataType, "R8") == 0)
{
cgnsVars[ff].dt = CGNS_ENUMV(RealDouble);
}
else if (strcmp(dataType, "R4") == 0)
{
cgnsVars[ff].dt = CGNS_ENUMV(RealSingle);
}
else if (strcmp(dataType, "I4") == 0)
{
cgnsVars[ff].dt = CGNS_ENUMV(Integer);
}
else if ( strcmp(dataType, "I8") == 0)
{
cgnsVars[ff].dt = CGNS_ENUMV(LongInteger);
}
else
{
continue;
}
}
// Create vector name from available variable
// when VarX, VarY, VarZ is detected
CGNSRead::fillVectorsFromVars(cgnsVars, cgnsVectors, physicalDim);
return 0;
}
//------------------------------------------------------------------------------
int vtkCGNSReader::AllocateVtkArray(const int physicalDim, const vtkIdType nVals,
const CGNS_ENUMT(GridLocation_t) varCentering,
const std::vector< CGNSRead::CGNSVariable >& cgnsVars,
const std::vector< CGNSRead::CGNSVector >& cgnsVectors,
std::vector<vtkDataArray *>& vtkVars)
{
for (std::size_t ff = 0; ff < cgnsVars.size(); ff++)
{
vtkVars[ff] = 0;
if (cgnsVars[ff].isComponent == false)
{
if (IsVarEnabled(varCentering, cgnsVars[ff].name) == false)
{
continue;
}
switch(cgnsVars[ff].dt)
{
// Other case to handle
case CGNS_ENUMV(Integer):
vtkVars[ff] = vtkIntArray::New();
break;
case CGNS_ENUMV(LongInteger):
vtkVars[ff] = vtkLongArray::New();
break;
case CGNS_ENUMV(RealSingle):
vtkVars[ff] = vtkFloatArray::New();
break;
case CGNS_ENUMV(RealDouble):
vtkVars[ff] = vtkDoubleArray::New();
break;
case CGNS_ENUMV(Character):
vtkVars[ff] = vtkCharArray::New();
break;
}
vtkVars[ff]->SetName(cgnsVars[ff].name);
vtkVars[ff]->SetNumberOfComponents(1);
vtkVars[ff]->SetNumberOfTuples(nVals);
}
}
for (std::vector<CGNSRead::CGNSVector>::const_iterator iter = cgnsVectors.begin();
iter != cgnsVectors.end(); ++iter)
{
vtkDataArray *arr = 0;
if (IsVarEnabled(varCentering, iter->name) == false)
{
continue;
}
int nv = iter->xyzIndex[0];
switch (cgnsVars[nv].dt)
{
// TODO: other cases
case CGNS_ENUMV(Integer):
arr = vtkIntArray::New();
break;
case CGNS_ENUMV(LongInteger):
arr = vtkLongArray::New();
break;
case CGNS_ENUMV(RealSingle):
arr = vtkFloatArray::New();
break;
case CGNS_ENUMV(RealDouble):
arr = vtkDoubleArray::New();
break;
case CGNS_ENUMV(Character):
arr = vtkCharArray::New();
break;
}
arr->SetName(iter->name);
arr->SetNumberOfComponents(physicalDim);
arr->SetNumberOfTuples(nVals);
for (int dim = 0; dim < physicalDim; ++dim)
{
arr->SetComponentName(static_cast<vtkIdType>(dim),
cgnsVars[iter->xyzIndex[dim]].name);
vtkVars[iter->xyzIndex[dim]] = arr;
}
}
return 0;
}
//------------------------------------------------------------------------------
int vtkCGNSReader::AttachReferenceValue(const int base, vtkDataSet* ds)
{
// Handle Reference Values (Mach Number, ...)
const std::map< std::string, double>& arrState =
this->Internal.GetBase(base).referenceState;
std::map< std::string, double>::const_iterator iteRef = arrState.begin();
for (iteRef = arrState.begin(); iteRef != arrState.end(); iteRef++)
{
vtkDoubleArray* refValArray = vtkDoubleArray::New();
refValArray->SetNumberOfComponents(1);
refValArray->SetName(iteRef->first.c_str());
refValArray->InsertNextValue(iteRef->second);
ds->GetFieldData()->AddArray(refValArray);
refValArray->Delete();
}
return 0;
}
//------------------------------------------------------------------------------
int vtkCGNSReader::GetCurvilinearZone(int base, int zone,
int cellDim, int physicalDim,
cgsize_t *zsize,
vtkMultiBlockDataSet *mbase)
{
int rind[6];
int n;
//int ier;
// Source Layout
cgsize_t srcStart[3] = {1,1,1};
cgsize_t srcStride[3] = {1,1,1};
cgsize_t srcEnd[3];
// Memory Destination Layout
cgsize_t memStart[3] = {1,1,1};
cgsize_t memStride[3] = {3,1,1};
cgsize_t memEnd[3] = {1,1,1};
cgsize_t memDims[3] = {1,1,1};
vtkIdType nPts = 0;
// Get Coordinates and FlowSolution node names
bool readGridCoordName = true;
bool readSolutionName = true;
CGNSRead::char_33 GridCoordName;
CGNSRead::char_33 SolutionName;
std::vector<double> gridChildId;
std::size_t nCoordsArray = 0;
this->getGridAndSolutionName(base, GridCoordName, SolutionName,
readGridCoordName, readSolutionName);
this->getCoordsIdAndFillRind(GridCoordName, physicalDim,
nCoordsArray, gridChildId, rind);
// Rind was parsed (or not) then populate dimensions :
// Compute structured grid coordinate range
for (n = 0; n < cellDim; n++)
{
srcStart[n] = rind[2*n] + 1;
srcEnd[n] = rind[2*n] + zsize[n];
memEnd[n] = zsize[n];
memDims[n] = zsize[n];
}
// Compute number of points
nPts = static_cast<vtkIdType>(memEnd[0]*memEnd[1]*memEnd[2]);
// Populate the extent array
int extent[6] = {0,0,0,0,0,0};
extent[1] = memEnd[0]-1;
extent[3] = memEnd[1]-1;
extent[5] = memEnd[2]-1;
// wacky hack ...
// memory aliasing is done
// since in vtk points array stores XYZ contiguously
// and they are stored separatly in cgns file
// the memory layout is set so that one cgns file array
// will be filling every 3 chuncks in memory
memEnd[0] *= 3;
// Set up points
vtkPoints *points = vtkPoints::New();
//
// vtkPoints assumes float data type
//
if (this->DoublePrecisionMesh != 0)
{
points->SetDataTypeToDouble();
}
//
// Resize vtkPoints to fit data
//
points->SetNumberOfPoints(nPts);
//
// Populate the coordinates. Put in 3D points with z=0 if the mesh is 2D.
//
if (this->DoublePrecisionMesh != 0) // DOUBLE PRECISION MESHPOINTS
{
CGNSRead::get_XYZ_mesh<double,float>(this->cgioNum, gridChildId, nCoordsArray,
cellDim, nPts,
srcStart, srcEnd, srcStride,
memStart, memEnd, memStride, memDims,
points);
}
else // SINGLE PRECISION MESHPOINTS
{
CGNSRead::get_XYZ_mesh<float,double>(this->cgioNum, gridChildId, nCoordsArray,
cellDim, nPts,
srcStart, srcEnd, srcStride,
memStart, memEnd, memStride, memDims,
points );
}
//----------------------------------------------------------------------------
// Handle solutions
//----------------------------------------------------------------------------
vtkMultiBlockDataSet* mzone = vtkMultiBlockDataSet::New();
bool CreateEachSolutionAsBlock = (this->CreateEachSolutionAsBlock != 0); // Debugging mode !
bool nosolutionread = false;
if (readSolutionName != true)
{
CGNS_ENUMT(GridLocation_t) varCentering = CGNS_ENUMV(Vertex);
double cgioSolId;
double cgioVarId;
if (cgio_get_node_id(this->cgioNum, this->currentId, SolutionName,
&cgioSolId) != CG_OK)
{
nosolutionread = true;
}
else
{
std::vector<double> solChildId;
std::size_t nVarArray = 0;
this->getVarsIdAndFillRind(cgioSolId, nVarArray, varCentering,
solChildId, rind);
vtkStructuredGrid *sgrid = vtkStructuredGrid::New();
sgrid->SetExtent(extent);
sgrid->SetPoints(points);
bool skip = false;
if ((varCentering != CGNS_ENUMV(Vertex)) &&
(varCentering != CGNS_ENUMV(CellCenter)))
{
vtkWarningMacro(<< "Solution " << SolutionName
<< " centering is not supported\n");
skip = true;
}
if (skip != true)
{
vtkDebugMacro(<< "Reading solution :" << SolutionName << "\n");
std::vector< CGNSRead::CGNSVariable > cgnsVars(nVarArray);
std::vector< CGNSRead::CGNSVector > cgnsVectors;
this->fillArrayInformation(solChildId, physicalDim, cgnsVars, cgnsVectors);
// Source
cgsize_t fieldSrcStart[3] = {1,1,1};
cgsize_t fieldSrcStride[3] = {1,1,1};
cgsize_t fieldSrcEnd[3];
// Destination Memory
cgsize_t fieldMemStart[3] = {1,1,1};
cgsize_t fieldMemStride[3] = {1,1,1};
cgsize_t fieldMemEnd[3] = {1,1,1};
cgsize_t fieldMemDims[3] = {1,1,1};
vtkIdType nVals = 0;
// Get solution data range
int nsc = varCentering == CGNS_ENUMV(Vertex) ? 0 : cellDim;
for (n = 0; n < cellDim; ++n)
{
fieldSrcStart[n] = rind[2*n] + 1;
fieldSrcEnd[n] = rind[2*n] + zsize[n+nsc];
fieldMemEnd[n] = zsize[n+nsc];
fieldMemDims[n] = zsize[n+nsc];
}
// compute number of field values
nVals = static_cast<vtkIdType>(fieldMemEnd[0]*fieldMemEnd[1]*fieldMemEnd[2]);
//
// VECTORS aliasing ...
// destination
cgsize_t fieldVectMemStart[3] = {1,1,1};
cgsize_t fieldVectMemStride[3] = {3,1,1};
cgsize_t fieldVectMemEnd[3] = {1,1,1};
cgsize_t fieldVectMemDims[3] = {1,1,1};
fieldVectMemStride[0] = static_cast<cgsize_t> ( physicalDim );
fieldVectMemDims[0] = fieldMemDims[0]*fieldVectMemStride[0];
fieldVectMemDims[1] = fieldMemDims[1];
fieldVectMemDims[2] = fieldMemDims[2];
fieldVectMemEnd[0] = fieldMemEnd[0]*fieldVectMemStride[0];
fieldVectMemEnd[1] = fieldMemEnd[1];
fieldVectMemEnd[2] = fieldMemEnd[2];
//
std::vector<vtkDataArray *> vtkVars(nVarArray);
// Count number of vars and vectors
// Assign vars and vectors to a vtkvars array
this->AllocateVtkArray(physicalDim, nVals, varCentering,
cgnsVars, cgnsVectors, vtkVars);
// Load Data
for (std::size_t ff = 0; ff < nVarArray; ++ff)
{
// only read allocated fields
if (vtkVars[ff] == 0)
{
continue;
}
cgioVarId = solChildId[ff];
// quick transfer of data because data types is given by cgns database
if (cgnsVars[ff].isComponent == false)
{
if (cgio_read_data(this->cgioNum, cgioVarId,
fieldSrcStart, fieldSrcEnd, fieldSrcStride,
cellDim, fieldMemDims,
fieldMemStart, fieldMemEnd, fieldMemStride,
(void *) vtkVars[ff]->GetVoidPointer(0)) != CG_OK)
{
char message[81];
cgio_error_message(message);
vtkErrorMacro(<<"cgio_read_data :" << message);
}
}
else
{
if (cgio_read_data(this->cgioNum, cgioVarId,
fieldSrcStart, fieldSrcEnd, fieldSrcStride,
cellDim, fieldVectMemDims,
fieldVectMemStart, fieldVectMemEnd, fieldVectMemStride,
(void *) vtkVars[ff]->GetVoidPointer(cgnsVars[ff].xyzIndex-1)) != CG_OK)
{
char message[81];
cgio_error_message(message);
vtkErrorMacro(<<"cgio_read_data :" << message);
}
}
cgio_release_id(this->cgioNum, cgioVarId);
}
cgio_release_id(this->cgioNum, cgioSolId);
// Append data to StructuredGrid
vtkDataSetAttributes* dsa = 0;
if (varCentering == CGNS_ENUMV(Vertex)) //ON_NODES
{
dsa = sgrid->GetPointData();
}
if (varCentering == CGNS_ENUMV(CellCenter)) //ON_CELL
{
dsa = sgrid->GetCellData();
}
// SetData in vtk Structured Zone + Clean Pointers
for (std::size_t nv = 0; nv < nVarArray; ++nv)
{
// only transfer allocated fields
if (vtkVars[nv] == 0)
{
continue;
}
if ((cgnsVars[nv].isComponent == false) ||
(cgnsVars[nv].xyzIndex == 1))
{
dsa->AddArray(vtkVars[nv]);
vtkVars[nv]->Delete();
}
vtkVars[nv] = 0;
}
}
//
this->AttachReferenceValue(base, sgrid);
//
mbase->SetBlock(zone, sgrid);
sgrid->Delete();
}
}
else if (!CreateEachSolutionAsBlock)
{
nosolutionread = true;
//
vtkStructuredGrid *sgrid = vtkStructuredGrid::New();
sgrid->SetExtent(extent);
sgrid->SetPoints(points);
//
int requiredSol = 1;
int cellSolution = 0;
int pointSolution = 0;
// Read List of Solution ids
std::vector<double> zoneChildId;
CGNSRead::getNodeChildrenId(this->cgioNum, this->currentId, zoneChildId);
char nodeLabel[CGIO_MAX_NAME_LENGTH+1];
//
for (std::size_t nn = 0; nn < zoneChildId.size(); nn++)
{
bool skip = false;
cgio_get_label(cgioNum, zoneChildId[nn], nodeLabel);
if (strcmp(nodeLabel, "FlowSolution_t") == 0)
{
CGNS_ENUMT(GridLocation_t) varCentering = CGNS_ENUMV(Vertex);
double cgioSolId = zoneChildId[nn];
double cgioVarId;
std::size_t nVarArray = 0;
std::vector<double> solChildId;
cgio_get_name(this->cgioNum, zoneChildId[nn], SolutionName);
this->getVarsIdAndFillRind(cgioSolId, nVarArray, varCentering, solChildId, rind);
if (varCentering != CGNS_ENUMV(Vertex))
{
pointSolution++;
skip = (pointSolution != requiredSol);
}
else if (varCentering != CGNS_ENUMV(CellCenter))
{
cellSolution++;
skip = (cellSolution != requiredSol);
}
else
{
vtkWarningMacro(<< "Solution " << SolutionName
<< " centering is not supported\n");
skip = true;
}
if (skip)
{
cgio_release_id(cgioNum, zoneChildId[nn]);
continue;
}
nosolutionread = false;
// Read Variables
vtkDebugMacro(<< "Reading solution :" << SolutionName << "\n");
std::vector< CGNSRead::CGNSVariable > cgnsVars(nVarArray);
std::vector< CGNSRead::CGNSVector > cgnsVectors;
this->fillArrayInformation(solChildId, physicalDim, cgnsVars, cgnsVectors);
// Source
cgsize_t fieldSrcStart[3] = {1,1,1};
cgsize_t fieldSrcStride[3] = {1,1,1};
cgsize_t fieldSrcEnd[3];
// Destination Memory
cgsize_t fieldMemStart[3] = {1,1,1};
cgsize_t fieldMemStride[3] = {1,1,1};
cgsize_t fieldMemEnd[3] = {1,1,1};
cgsize_t fieldMemDims[3] = {1,1,1};
vtkIdType nVals = 0;
// Get solution data range
int nsc = varCentering == CGNS_ENUMV ( Vertex ) ? 0 : cellDim;
for (n = 0; n < cellDim; ++n)
{
fieldSrcStart[n] = rind[2*n] + 1;
fieldSrcEnd[n] = rind[2*n] + zsize[n+nsc];
fieldMemEnd[n] = zsize[n+nsc];
fieldMemDims[n] = zsize[n+nsc];
}
// compute number of field values
nVals = static_cast<vtkIdType>(fieldMemEnd[0]*fieldMemEnd[1]*fieldMemEnd[2]);
//
// VECTORS aliasing ...
// destination
cgsize_t fieldVectMemStart[3] = {1,1,1};
cgsize_t fieldVectMemStride[3] = {3,1,1};
cgsize_t fieldVectMemEnd[3] = {1,1,1};
cgsize_t fieldVectMemDims[3] = {1,1,1};
fieldVectMemStride[0] = static_cast<cgsize_t>(physicalDim);
fieldVectMemDims[0] = fieldMemDims[0]*fieldVectMemStride[0];
fieldVectMemDims[1] = fieldMemDims[1];
fieldVectMemDims[2] = fieldMemDims[2];
fieldVectMemEnd[0] = fieldMemEnd[0]*fieldVectMemStride[0];
fieldVectMemEnd[1] = fieldMemEnd[1];
fieldVectMemEnd[2] = fieldMemEnd[2];
//
// Count number of vars and vectors
// Assign vars and vectors to a vtkvars array
std::vector<vtkDataArray *> vtkVars(nVarArray);
this->AllocateVtkArray(physicalDim, nVals, varCentering, cgnsVars, cgnsVectors, vtkVars);
// Load Data
for (std::size_t ff = 0; ff < nVarArray; ++ff)
{
// only read allocated fields
if (vtkVars[ff] == 0)
{
continue;
}
cgioVarId = solChildId[ff];
// quick transfer of data because data types is given by cgns database
if (cgnsVars[ff].isComponent == false)
{
if (cgio_read_data(this->cgioNum, cgioVarId,
fieldSrcStart, fieldSrcEnd, fieldSrcStride,
cellDim, fieldMemDims,
fieldMemStart, fieldMemEnd, fieldMemStride,
(void *) vtkVars[ff]->GetVoidPointer(0)) != CG_OK)
{
char message[81];
cgio_error_message(message);
vtkErrorMacro(<<"cgio_read_data :" << message);
}
}
else
{
if (cgio_read_data(this->cgioNum, cgioVarId,
fieldSrcStart, fieldSrcEnd, fieldSrcStride,
cellDim, fieldVectMemDims,
fieldVectMemStart, fieldVectMemEnd, fieldVectMemStride,
(void *) vtkVars[ff]->GetVoidPointer(cgnsVars[ff].xyzIndex-1)) != CG_OK)
{
char message[81];
cgio_error_message(message);
vtkErrorMacro(<<"cgio_read_data :" << message);
}
}
cgio_release_id(this->cgioNum, cgioVarId);
}
// Append data to StructuredGrid
vtkDataSetAttributes* dsa = 0;
if (varCentering == CGNS_ENUMV(Vertex)) //ON_NODES
{
dsa = sgrid->GetPointData();
}
if (varCentering == CGNS_ENUMV(CellCenter)) //ON_CELL
{