forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkLSDynaReader.cxx
3804 lines (3374 loc) · 123 KB
/
vtkLSDynaReader.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: vtkLSDynaReader.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
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.
=========================================================================*/
/*----------------------------------------------------------------------------
Copyright (c) Sandia Corporation
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
----------------------------------------------------------------------------*/
// NOTE TO DEVELOPERS: ========================================================
//
// This is a really big reader.
// It uses several classes defined in Utilities/LSDyna:
// - LSDynaFamily:
// A class to abstract away I/O from families of output files.
// This performs the actual reads and writes plus any required byte swapping.
// Also contains a subclass, LSDynaFamilyAdaptLevel, used to store
// file+offset
// information for each mesh adaptation's state info.
// - LSDynaMetaData:
// A class to hold metadata about a particular file (such as time steps,
// the start of state information for each time step, the number of
// adaptive remeshes, and the large collection of constants that determine
// the available attributes). It contains an LSDynaFamily instance.
//It also uses a helper vtk class
// - vtkLSDynaSummaryParser:
// A class to parse XML summary files containing part names and their IDs.
// This class is used by vtkLSDynaReader::ReadInputDeckXML().
// This class is preceded by some file-static constants and utility routines.
#include "vtkLSDynaReader.h"
#include "vtkLSDynaSummaryParser.h"
#include "vtkLSDynaPartCollection.h"
#include "LSDynaFamily.h"
#include "LSDynaMetaData.h"
#include "vtksys/SystemTools.hxx"
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cassert>
#include "vtkCellType.h"
#include "vtkDataObject.h"
#include "vtkDoubleArray.h"
#include "vtkIdTypeArray.h"
#include "vtkUnsignedCharArray.h"
#include "vtkFloatArray.h"
#include "vtkPoints.h"
#include "vtkInformation.h"
#include "vtkInformationDoubleVectorKey.h"
#include "vtkInformationVector.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkUnstructuredGrid.h"
vtkStandardNewMacro(vtkLSDynaReader);
// Names of vtkDataArrays provided with grid:
#define LS_ARRAYNAME_DEATH "Death"
#define LS_ARRAYNAME_USERID "UserID"
#define LS_ARRAYNAME_SPECIES_BLNK "SpeciesXX"
#define LS_ARRAYNAME_SPECIES_FMT "Species%02d"
#define LS_ARRAYNAME_SPECIES_01 "Species01"
#define LS_ARRAYNAME_SPECIES_02 "Species02"
#define LS_ARRAYNAME_SPECIES_03 "Species03"
#define LS_ARRAYNAME_SPECIES_04 "Species04"
#define LS_ARRAYNAME_SPECIES_05 "Species05"
#define LS_ARRAYNAME_SPECIES_06 "Species06"
#define LS_ARRAYNAME_SPECIES_07 "Species07"
#define LS_ARRAYNAME_SPECIES_08 "Species08"
#define LS_ARRAYNAME_SPECIES_09 "Species09"
#define LS_ARRAYNAME_SPECIES_10 "Species10"
#define LS_ARRAYNAME_TEMPERATURE "Temperature"
#define LS_ARRAYNAME_DEFLECTION "Deflection"
#define LS_ARRAYNAME_VELOCITY "Velocity"
#define LS_ARRAYNAME_ACCELERATION "Acceleration"
#define LS_ARRAYNAME_PRESSURE "Pressure"
#define LS_ARRAYNAME_VORTICITY "Vorticity"
#define LS_ARRAYNAME_RESULTANTVORTICITY "ResVorticity"
#define LS_ARRAYNAME_ENSTROPHY "Enstrophy"
#define LS_ARRAYNAME_HELICITY "Helicity"
#define LS_ARRAYNAME_STREAMFUNCTION "StreamFunc"
#define LS_ARRAYNAME_ENTHALPY "Enthalpy"
#define LS_ARRAYNAME_DENSITY "Density"
#define LS_ARRAYNAME_TURBULENTKE "TurbulentKE"
#define LS_ARRAYNAME_DISSIPATION "Dissipation"
#define LS_ARRAYNAME_EDDYVISCOSITY "EddyVisc"
#define LS_ARRAYNAME_RADIUSOFINFLUENCE "InfluenceRadius"
#define LS_ARRAYNAME_NUMNEIGHBORS "NumberOfNeighbors"
#define LS_ARRAYNAME_SEGMENTID "SegmentID"
#define LS_ARRAYNAME_STRAIN "Strain"
#define LS_ARRAYNAME_STRESS "Stress"
#define LS_ARRAYNAME_EPSTRAIN "EffPlastStrn"
#define LS_ARRAYNAME_INTEGRATIONPOINT "IntPtData"
#define LS_ARRAYNAME_RESULTANTS "Resultants"
#define LS_ARRAYNAME_ELEMENTMISC "ElementMisc"
#define LS_ARRAYNAME_INTERNALENERGY "InternalEnergy"
#define LS_ARRAYNAME_AXIALFORCE "AxialForce"
#define LS_ARRAYNAME_SHEARRESULTANT "ShearResultant"
#define LS_ARRAYNAME_BENDINGRESULTANT "BendingResultant"
#define LS_ARRAYNAME_TORSIONRESULTANT "TorsionResultant"
#define LS_ARRAYNAME_NORMALRESULTANT "NormalResultant"
#define LS_ARRAYNAME_AXIALSTRAIN "AxialStrain"
#define LS_ARRAYNAME_AXIALSTRESS "AxialStress"
#define LS_ARRAYNAME_SHEARSTRAIN "ShearStrain"
#define LS_ARRAYNAME_SHEARSTRESS "ShearStress"
#define LS_ARRAYNAME_PLASTICSTRAIN "PlasticStrain"
#define LS_ARRAYNAME_THICKNESS "Thickness"
#define LS_ARRAYNAME_MASS "Mass"
#define LS_ARRAYNAME_VOLUME_FRACTION_FMT "VolumeFraction%02d"
#define LS_ARRAYNAME_DOMINANT_GROUP "DominantGroup"
#define LS_ARRAYNAME_SPECIES_MASS_FMT "SpeciesMass%02d"
// Possible material options
#define LS_MDLOPT_NONE 0
#define LS_MDLOPT_POINT 1
#define LS_MDLOPT_CELL 2
#ifdef VTK_LSDYNA_DBG_MULTIBLOCK
static void vtkDebugMultiBlockStructure( vtkIndent indent, vtkMultiGroupDataSet* mbds );
#endif // VTK_LSDYNA_DBG_MULTIBLOCK
namespace
{
static const char* vtkLSDynaCellTypes[] =
{
"Point",
"Beam",
"Shell",
"Thick Shell",
"Solid",
"Rigid Body",
"Road Surface"
};
static void vtkLSGetLine( ifstream& deck, std::string& line )
{
#if !defined(_WIN32) && !defined(_MSC_VER) && !defined(__BORLANDC__)
// One line implementation for everyone but Windows (MSVC6 and BCC32 are the troublemakers):
std::getline( deck, line, '\n' );
#else
// Feed Windows its food cut up into little pieces
int linechar;
line = "";
while ( deck.good() )
{
linechar = deck.get();
if ( linechar == '\r' || linechar == '\n' )
return;
line += linechar;
}
#endif
}
// Read in lines until one that's
// - not empty, and
// - not a comment
// is encountered. Return with that text stored in \a line.
// If an error or EOF is hit, return 0. Otherwise, return 1.
static int vtkLSNextSignificantLine( ifstream& deck, std::string& line )
{
while ( deck.good() )
{
vtkLSGetLine( deck, line );
if ( ! line.empty() && line[0] != '$' )
{
return 1;
}
}
return 0;
}
static void vtkLSTrimWhitespace( std::string& line )
{
std::string::size_type llen = line.length();
while ( llen &&
( line[llen - 1] == ' ' ||
line[llen - 1] == '\t' ||
line[llen - 1] == '\r' ||
line[llen - 1] == '\n' ) )
{
--llen;
}
std::string::size_type nameStart = 0;
while ( nameStart < llen &&
( line[nameStart] == ' ' ||
line[nameStart] == '\t' ) )
{
++nameStart;
}
line = line.substr( nameStart, llen - nameStart );
}
static void vtkLSDowncaseFirstWord( std::string& downcased, const std::string& line )
{
std::string::size_type i;
std::string::value_type chr;
int leadingSpace = 0;
downcased = "";
for ( i = 0; i < line.length(); ++i )
{
chr = tolower( line[i] );
if ( chr == ' ' || chr == '\t' )
{
if ( leadingSpace )
{ // We've trimmed leading whitespace already, so we're done with the word.
return;
}
}
else
{
leadingSpace = 1;
if ( chr == ',' )
{ // We're at a separator (other than whitespace). No need to continue.
return;
}
}
downcased += chr;
}
}
void vtkLSSplitString( std::string& input, std::vector<std::string>& splits, const char* separators )
{
std::string::size_type posBeg = 0;
std::string::size_type posEnd;
do {
posEnd = input.find_first_of( separators, posBeg );
if ( posEnd > posBeg )
{
// don't include empty entries in splits.
// NOTE: This means ",comp,1, ,3" with separators ", " yields "comp","1","3", not "","comp","1","","","3".
splits.push_back( input.substr( posBeg, posEnd - posBeg ) );
}
posBeg = input.find_first_not_of( separators, posEnd );
} while ( posBeg != std::string::npos );
}
template<int hostBitSize, int fileBitSize, int cellLength> struct Converter
{
//general use case that the host
//bit size and file bit size are the same
vtkIdType* convert(vtkIdType* buff, const vtkIdType&)
{
return buff;
}
};
template<int cellLength> struct Converter<8,4,cellLength>
{
//specilization of 64bit machine and 32bit file
//so we have to copy each item individually
vtkIdType* convert(int* buff, const vtkIdType& size)
{
for(vtkIdType i=0;i<size;++i)
{
this->Conn[i]=static_cast<vtkIdType>(buff[i]);
}
return Conn;
}
vtkIdType Conn[cellLength];
};
template<int cellLength> struct Converter<4,8,cellLength>
{
//specilization for reading 64 bit files on a 32 bit machine
//which means reading the bottom half of the long long
vtkIdType* convert(int* buff, const vtkIdType& size)
{
vtkIdType idx=0;
for(vtkIdType i=0;i<size;i+=2,++idx)
{
this->Conn[idx]=static_cast<vtkIdType>(buff[i]);
}
return Conn;
}
vtkIdType Conn[cellLength];
};
template<int type,int wordSize,int cellLength>
struct FillBlock
{
Converter<sizeof(vtkIdType),wordSize,cellLength> BC;
template<typename T>
FillBlock(T* buff, vtkLSDynaPartCollection *parts,LSDynaMetaData *p,
const vtkIdType& numWordsPerCell, const int& cellType)
{
//determine the relationship between the file bit size and
//the host machine bit size. This allows us to read 64 bit files on a
//32 bit machine. The Converter allows us to easily convert 32bit
//arrays to 64bit arrays
const int numWordsPerIdType (p->Fam.GetWordSize() / sizeof(T));
const vtkIdType numFileWordsPerCell(numWordsPerCell * numWordsPerIdType);
const vtkIdType offsetToMatId(numWordsPerIdType *(numWordsPerCell-1));
vtkIdType *conn;
vtkIdType nc=0,j=0,matlId=0;
vtkIdType numCellsToSkip=0, numCellsToSkipEnd=0, chunkSize=0;
//get from the part the read information for this lsdyna block type
parts->GetPartReadInfo(type,nc,numCellsToSkip,numCellsToSkipEnd);
p->Fam.SkipWords(numFileWordsPerCell * numCellsToSkip ); //skip to the right start id
//buffer the amount in small chunks so we don't create a massive buffer
vtkIdType numChunks = p->Fam.InitPartialChunkBuffering(nc,numWordsPerCell);
for(vtkIdType i=0; i < numChunks; ++i)
{
chunkSize = p->Fam.GetNextChunk( LSDynaFamily::Int);
buff = p->Fam.GetBufferAs<T>();
for (j=0; j<chunkSize;j+=numWordsPerCell)
{
conn = BC.convert(buff,offsetToMatId);
buff+=offsetToMatId;
matlId = static_cast<vtkIdType>(*buff);
buff+=numWordsPerIdType;
parts->InsertCell(type,matlId,cellType,cellLength,conn);
}
}
p->Fam.SkipWords(numFileWordsPerCell * numCellsToSkipEnd);
}
};
template<int wordSize,int cellLength>
struct FillBlock<LSDynaMetaData::SOLID,wordSize,cellLength>
{
Converter<sizeof(vtkIdType),wordSize,cellLength> BC;
template<typename T>
FillBlock(T* buff, vtkLSDynaPartCollection *parts,LSDynaMetaData *p,
const vtkIdType& numWordsPerCell, const int& vtkNotUsed(cellType) )
{
//determine the relationship between the file bit size and
//the host machine bit size. This allows us to read 64 bit files on a
//32 bit machine. The Converter allows us to easily convert 32bit
//arrays to 64bit arrays
const int numWordsPerIdType (p->Fam.GetWordSize() / sizeof(T));
const vtkIdType numFileWordsPerCell(numWordsPerCell * numWordsPerIdType);
const vtkIdType offsetToMatId(numWordsPerIdType * cellLength);
vtkIdType *conn;
//This is a read solids template specialization since it has a special use
//case for cell length based on the connectivity mapping
vtkIdType nc=0,j=0,matlId=0;
vtkIdType numCellsToSkip=0, numCellsToSkipEnd=0, chunkSize=0;
//get from the part the read information for this lsdyna block type
parts->GetPartReadInfo(LSDynaMetaData::SOLID,nc,numCellsToSkip,numCellsToSkipEnd);
p->Fam.SkipWords(numFileWordsPerCell * numCellsToSkip); //skip to the right start id
//buffer the amount in small chunks so we don't create a massive buffer
vtkIdType numChunks = p->Fam.InitPartialChunkBuffering(nc,numWordsPerCell);
vtkIdType npts = 0;
int ctype = 0;
for(vtkIdType i=0; i < numChunks; ++i)
{
chunkSize = p->Fam.GetNextChunk( LSDynaFamily::Int);
buff = p->Fam.GetBufferAs<T>();
for (j=0; j<chunkSize;j+=numWordsPerCell)
{
conn = BC.convert(buff,offsetToMatId);
buff+=offsetToMatId;
matlId = static_cast<vtkIdType>(*buff);
buff+=numWordsPerIdType;
//Detect repeated connectivity entries to determine element type
if (conn[3] == conn[7])
{
ctype = VTK_TETRA;
npts = 4;
}
else if (conn[4] == conn[7])
{
ctype = VTK_PYRAMID;
npts = 5;
}
else if (conn[5] == conn[7])
{
ctype = VTK_WEDGE;
npts = 6;
}
else
{
ctype = VTK_HEXAHEDRON;
npts = 8;
}
//push this cell back into the unstructured grid for this part(if the part is active)
parts->InsertCell(LSDynaMetaData::SOLID,matlId,ctype,npts,conn);
}
}
p->Fam.SkipWords(numFileWordsPerCell * numCellsToSkipEnd);
}
};
template<int wordSize,int cellLength>
struct FillBlock<LSDynaMetaData::SHELL,wordSize,cellLength>
{
Converter<sizeof(vtkIdType),wordSize,cellLength> BC;
template<typename T>
FillBlock(T* buff, vtkLSDynaPartCollection *parts,LSDynaMetaData *p,
const vtkIdType& numWordsPerCell, const int& cellType)
{
//determine the relationship between the file bit size and
//the host machine bit size. This allows us to read 64 bit files on a
//32 bit machine. The Converter allows us to easily convert 32bit
//arrays to 64bit arrays
const int numWordsPerIdType (p->Fam.GetWordSize() / sizeof(T));
const vtkIdType numFileWordsPerCell(numWordsPerCell * numWordsPerIdType);
const vtkIdType offsetToMatId(numWordsPerIdType * cellLength);
vtkIdType *conn;
//This is a read RIGID_BODY and SHELL template specialization since it
//has a weird weaving of cell types
bool haveRigidMaterials = (p->Dict["MATTYP"] != 0) &&
p->RigidMaterials.size();
vtkIdType nc=0, j=0,matlId=0;
vtkIdType numCellsToSkip=0, numCellsToSkipEnd=0, chunkSize=0;
//get from the part the read information for this lsdyna block type
parts->GetPartReadInfo(LSDynaMetaData::SHELL,nc,numCellsToSkip,numCellsToSkipEnd);
p->Fam.SkipWords(numFileWordsPerCell * numCellsToSkip); //skip to the right start id
//buffer the amount in small chunks so we don't create a massive buffer
vtkIdType numChunks = p->Fam.InitPartialChunkBuffering(nc,numWordsPerCell);
int pType = 0;
for(vtkIdType i=0; i < numChunks; ++i)
{
chunkSize = p->Fam.GetNextChunk( LSDynaFamily::Int);
buff = p->Fam.GetBufferAs<T>();
for (j=0; j<chunkSize;j+=numWordsPerCell)
{
conn = BC.convert(buff,offsetToMatId);
buff+=offsetToMatId;
matlId = static_cast<vtkIdType>(*buff);
buff+=numWordsPerIdType;
if ( haveRigidMaterials &&
p->RigidMaterials.find( matlId ) == p->RigidMaterials.end())
{
pType = LSDynaMetaData::RIGID_BODY;
}
else
{
pType = LSDynaMetaData::SHELL;
}
parts->InsertCell(pType,matlId,cellType,cellLength,conn);
}
}
p->Fam.SkipWords(numFileWordsPerCell * numCellsToSkipEnd);
}
};
template<int wordSize,int cellLength>
struct FillBlock<LSDynaMetaData::ROAD_SURFACE,wordSize,cellLength>
{
template<typename T>
FillBlock(T*, vtkLSDynaPartCollection *parts,LSDynaMetaData *p,
const vtkIdType&, const int& cellType)
{
//This is a ROAD_SURFACE specialization
//has a weird weaving of cell types
vtkIdType nc=0,segId=0,segSz=0;
vtkIdType numCellsToSkip=0, numCellsToSkipEnd=0;
//get from the part the read information for this lsdyna block type
parts->GetPartReadInfo(LSDynaMetaData::SHELL,nc,numCellsToSkip,numCellsToSkipEnd);
//the road surface format is horrible for parallel reading.
//we don't know the number of cells in each road surface.
//only the total number of cells. So we have to do some fun stuff to correctly skip
//this is unoptimized since I don't have any road surface data
vtkIdType currentCell=0;
vtkIdType conn[4];
for (vtkIdType i=0; i<p->Dict["NSURF"]; ++i)
{
p->Fam.BufferChunk( LSDynaFamily::Int, 2 );
segId = p->Fam.GetNextWordAsInt();
segSz = p->Fam.GetNextWordAsInt();
p->Fam.BufferChunk( LSDynaFamily::Int, 4*segSz );
for (vtkIdType t=0; t<segSz; ++t, ++currentCell)
{
if(currentCell >= numCellsToSkip)
{
for (int j=0; j<4; ++j )
{
conn[j] = p->Fam.GetNextWordAsInt() - 1;
}
parts->InsertCell(LSDynaMetaData::ROAD_SURFACE,segId,cellType,4,conn);
}
}
}
}
};
}
// =================================================== Start of public interface
vtkLSDynaReader::vtkLSDynaReader()
{
this->P = new LSDynaMetaData;
this->SetNumberOfInputPorts(0);
this->SetNumberOfOutputPorts(1);
this->TimeStepRange[0] = 0;
this->TimeStepRange[1] = 0;
this->DeformedMesh = 1;
this->RemoveDeletedCells = 1;
this->DeletedCellsAsGhostArray = 0;
this->InputDeck = 0;
this->Parts = NULL;
}
vtkLSDynaReader::~vtkLSDynaReader()
{
this->ResetPartsCache();
this->SetInputDeck(0);
delete this->P;
this->P = 0;
}
void vtkLSDynaReader::PrintSelf( ostream &os, vtkIndent indent )
{
this->Superclass::PrintSelf( os, indent );
os << indent << "Title: \"" << this->GetTitle() << "\"" << endl;
os << indent << "InputDeck: " << (this->InputDeck ? this->InputDeck : "(null)") << endl;
os << indent << "DeformedMesh: " << (this->DeformedMesh ? "On" : "Off") << endl;
os << indent << "RemoveDeletedCells: " << (this->RemoveDeletedCells ? "On" : "Off") << endl;
os << indent << "TimeStepRange: " << this->TimeStepRange[0] << ", " << this->TimeStepRange[1] << endl;
if (this->P)
{
os << indent << "PrivateData: " << this->P << endl;
}
else
{
os << indent << "PrivateData: (none)" << endl;
}
os << indent << "Show Deleted Cells as Ghost Cells: "<<
(this->DeletedCellsAsGhostArray ? "On" : "Off") << endl;
os << indent << "Dimensionality: " << this->GetDimensionality() << endl;
os << indent << "Nodes: " << this->GetNumberOfNodes() << endl;
os << indent << "Cells: " << this->GetNumberOfCells() << endl;
os << indent << "PointArrays: ";
for ( int i=0; i<this->GetNumberOfPointArrays(); ++i )
{
os << this->GetPointArrayName( i ) << " ";
}
os << endl;
os << "CellArrays: " << endl;
for ( int ct = 0; ct < LSDynaMetaData::NUM_CELL_TYPES; ++ct )
{
os << vtkLSDynaCellTypes[ct] << ":" << endl;
for ( int i = 0; i < this->GetNumberOfCellArrays( ct ); ++i )
{
os << this->GetCellArrayName( ct, i ) << " ";
}
os << endl;
}
os << endl;
os << indent << "Time Steps: " << this->GetNumberOfTimeSteps() << endl;
for ( int j=0; j<this->GetNumberOfTimeSteps(); ++j )
{
os.precision(5);
os.width(12);
os << this->GetTimeValue(j) ;
if ( (j+1) % 8 == 0 && j != this->GetNumberOfTimeSteps()-1 )
{
os << endl << indent;
}
else
{
os << " ";
}
}
os << endl;
}
void vtkLSDynaReader::Dump( ostream& os )
{
vtkIndent indent;
os << indent << "Title: \"" << this->GetTitle() << "\"" << endl
<< indent << "DeformedMesh: " << (this->DeformedMesh ? "On" : "Off") << endl
<< indent << "RemoveDeletedCells: " << (this->RemoveDeletedCells ? "On" : "Off") << endl
<< indent << "TimeStepRange: " << this->TimeStepRange[0] << ", " << this->TimeStepRange[1] << endl
<< indent << "PrivateData: " << this->P << endl
<< indent << "Dimensionality: " << this->GetDimensionality() << endl
<< indent << "Nodes: " << this->GetNumberOfNodes() << endl
<< indent << "Cells: " << this->GetNumberOfCells() << endl
<< indent << "PointArrays: ";
for ( int i=0; i<this->GetNumberOfPointArrays(); ++i )
{
os << this->GetPointArrayName( i ) << " ";
}
os << endl
<< "CellArrays:" << endl;
for ( int ct = 0; ct < LSDynaMetaData::NUM_CELL_TYPES; ++ct )
{
os << vtkLSDynaCellTypes[ct] << ":" << endl;
for ( int i = 0; i < this->GetNumberOfCellArrays( ct ); ++i )
{
os << this->GetCellArrayName( ct, i ) << " ";
}
os << endl;
}
os << endl;
os << indent << "Time Steps: " << this->GetNumberOfTimeSteps() << endl;
for ( int j=0; j<this->GetNumberOfTimeSteps(); ++j )
{
os.precision(5);
os.width(12);
os << this->GetTimeValue(j) ;
if ( (j+1) % 8 == 0 && j != this->GetNumberOfTimeSteps()-1 )
{
os << endl << indent;
}
else
{
os << " ";
}
}
os << endl;
}
void vtkLSDynaReader::DebugDump()
{
this->Dump( cout );
}
int vtkLSDynaReader::CanReadFile( const char* fname )
{
if ( ! fname )
return 0;
std::string dbDir = vtksys::SystemTools::GetFilenamePath( fname );
std::string dbName = vtksys::SystemTools::GetFilenameName( fname );
std::string dbExt;
std::string::size_type dot;
LSDynaMetaData* p = new LSDynaMetaData;
int result = 0;
// GetFilenameExtension doesn't look for the rightmost "." ... do it ourselves.
dot = dbName.rfind( '.' );
if ( dot != std::string::npos )
{
dbExt = dbName.substr( dot );
}
else
{
dbExt = "";
}
p->Fam.SetDatabaseDirectory( dbDir );
if ( dbExt == ".k" || dbExt == ".lsdyna" )
{
p->Fam.SetDatabaseBaseName( "/d3plot" );
}
else
{
vtksys::SystemTools::Stat_t st;
if ( vtksys::SystemTools::Stat( fname, &st ) == 0 )
{
dbName.insert( 0, "/" );
p->Fam.SetDatabaseBaseName( dbName.c_str() );
}
else
{
p->Fam.SetDatabaseBaseName( "/d3plot" );
}
}
// If the time step is set before RequestInformation is called, we must
// read the header information immediately in order to determine whether
// the timestep that's been passed is valid. If it's not, we ignore it.
if ( ! p->FileIsValid )
{
if ( p->Fam.GetDatabaseDirectory().empty() )
{
result = -1;
}
else
{
if ( p->Fam.GetDatabaseBaseName().empty() )
{
p->Fam.SetDatabaseBaseName( "/d3plot" ); // not a bad assumption.
}
p->Fam.ScanDatabaseDirectory();
if ( p->Fam.GetNumberOfFiles() < 1 )
{
result = -1;
}
else
{
if ( p->Fam.DetermineStorageModel() != 0 )
result = 0;
else
result = 1;
}
}
}
delete p;
return result > 0; // -1 and 0 are both problems, 1 indicates success.
}
void vtkLSDynaReader::SetDatabaseDirectory( const char* f )
{
vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting DatabaseDirectory to " << f );
if ( ! f )
{
if ( ! this->P->Fam.GetDatabaseDirectory().empty() )
{ // no string => no database directory
this->P->Reset();
this->SetInputDeck( 0 );
this->ResetPartsCache();
this->Modified();
}
return;
}
if ( strcmp(this->P->Fam.GetDatabaseDirectory().c_str(), f) )
{
this->P->Reset();
this->SetInputDeck( 0 );
this->P->Fam.SetDatabaseDirectory( std::string(f) );
this->ResetPartsCache();
this->Modified();
}
}
const char* vtkLSDynaReader::GetDatabaseDirectory()
{
return this->P->Fam.GetDatabaseDirectory().c_str();
}
int vtkLSDynaReader::IsDatabaseValid()
{
return this->P->FileIsValid;
}
void vtkLSDynaReader::SetFileName( const char* f )
{
std::string dbDir = vtksys::SystemTools::GetFilenamePath( f );
std::string dbName = vtksys::SystemTools::GetFilenameName( f );
std::string dbExt;
std::string::size_type dot;
// GetFilenameExtension doesn't look for the rightmost "." ... do it ourselves.
dot = dbName.rfind( '.' );
if ( dot != std::string::npos )
{
dbExt = dbName.substr( dot );
}
else
{
dbExt = "";
}
this->SetDatabaseDirectory( dbDir.c_str() );
if ( dbExt == ".k" || dbExt == ".lsdyna" )
{
this->SetInputDeck( f );
this->P->Fam.SetDatabaseBaseName( "/d3plot" );
}
else
{
vtksys::SystemTools::Stat_t st;
if ( vtksys::SystemTools::Stat( f, &st ) == 0 )
{
dbName.insert( 0, "/" );
this->P->Fam.SetDatabaseBaseName( dbName.c_str() );
}
else
{
this->P->Fam.SetDatabaseBaseName( "/d3plot" );
}
}
}
const char* vtkLSDynaReader::GetFileName()
{
// This is completely thread UNsafe. But what to do?
static std::string filenameSurrogate;
filenameSurrogate = this->P->Fam.GetDatabaseDirectory() + "/d3plot";
return filenameSurrogate.c_str();
}
char* vtkLSDynaReader::GetTitle()
{
return this->P->Title;
}
int vtkLSDynaReader::GetDimensionality()
{
return this->P->Dimensionality;
}
void vtkLSDynaReader::SetTimeStep( vtkIdType t )
{
LSDynaMetaData* p = this->P;
if ( p->CurrentState == t )
{
return;
}
// If the time step is set before RequestInformation is called, we must
// read the header information immediately in order to determine whether
// the timestep that's been passed is valid. If it's not, we ignore it.
if ( ! p->FileIsValid )
{
if ( p->Fam.GetDatabaseDirectory().empty() )
{
vtkErrorMacro( "You haven't set the LS-Dyna database directory!" );
return;
}
p->Fam.SetDatabaseBaseName( "/d3plot" ); // force this for now.
p->Fam.ScanDatabaseDirectory();
if ( p->Fam.GetNumberOfFiles() < 1 )
{
p->FileIsValid = 0;
return;
}
p->Fam.DetermineStorageModel();
p->MaxFileLength = p->FileSizeFactor*512*512*p->Fam.GetWordSize();
p->FileIsValid = 1;
// OK, now we have a list of files. Next, determine the length of the
// state vector (#bytes of data stored per time step):
this->ReadHeaderInformation( 0 );
// Finally, we can loop through and determine where all the state
// vectors start for each time step.
this->ScanDatabaseTimeSteps();
}
// Now, make sure we update the dictionary to contain information
// relevant to the adaptation level that matches the requested timestep.
if ( t >= 0 && t < (int) p->TimeValues.size() )
{
if ( p->Fam.GetCurrentAdaptLevel() != p->Fam.TimeAdaptLevel( t ) )
{
if ( this->ReadHeaderInformation( p->Fam.TimeAdaptLevel( t ) ) == 0 )
{
// unable to read the header information for the adaptation level corresponding
// to the requested time step
return;
}
}
}
p->CurrentState = t;
this->Modified();
}
vtkIdType vtkLSDynaReader::GetTimeStep()
{
return this->P->CurrentState;
}
vtkIdType vtkLSDynaReader::GetNumberOfTimeSteps()
{
return (vtkIdType) this->P->TimeValues.size();
}
double vtkLSDynaReader::GetTimeValue( vtkIdType s )
{
if ( s < 0 || s >= (vtkIdType) this->P->TimeValues.size() )
{
return -1.0;
}
return this->P->TimeValues[s];
}
vtkIdType vtkLSDynaReader::GetNumberOfNodes()
{
return this->P->NumberOfNodes;
}
vtkIdType vtkLSDynaReader::GetNumberOfCells()
{
vtkIdType tmp=0;
for ( int c=0; c<LSDynaMetaData::NUM_CELL_TYPES; ++c )
{
tmp += this->P->NumberOfCells[c];
}
return tmp;
}
vtkIdType vtkLSDynaReader::GetNumberOfSolidCells()
{
return this->P->NumberOfCells[LSDynaMetaData::SOLID];
}
vtkIdType vtkLSDynaReader::GetNumberOfThickShellCells()
{
return this->P->NumberOfCells[LSDynaMetaData::THICK_SHELL];
}
vtkIdType vtkLSDynaReader::GetNumberOfShellCells()
{
return this->P->NumberOfCells[LSDynaMetaData::SHELL];
}
vtkIdType vtkLSDynaReader::GetNumberOfRigidBodyCells()
{
return this->P->NumberOfCells[LSDynaMetaData::RIGID_BODY];
}
vtkIdType vtkLSDynaReader::GetNumberOfRoadSurfaceCells()
{
return this->P->NumberOfCells[LSDynaMetaData::ROAD_SURFACE];
}
vtkIdType vtkLSDynaReader::GetNumberOfBeamCells()
{
return this->P->NumberOfCells[LSDynaMetaData::BEAM];
}
vtkIdType vtkLSDynaReader::GetNumberOfParticleCells()
{
return this->P->NumberOfCells[LSDynaMetaData::PARTICLE];
}
vtkIdType vtkLSDynaReader::GetNumberOfContinuumCells()
{
vtkIdType tmp=0;
for ( int c=LSDynaMetaData::PARTICLE+1; c<LSDynaMetaData::NUM_CELL_TYPES; ++c )
{
tmp += this->P->NumberOfCells[c];
}
return tmp;
}
// =================================== Point array queries
int vtkLSDynaReader::GetNumberOfPointArrays()
{
return (int) this->P->PointArrayNames.size();
}
const char* vtkLSDynaReader::GetPointArrayName( int a )
{
if ( a < 0 || a >= (int) this->P->PointArrayNames.size() )
return 0;
return this->P->PointArrayNames[a].c_str();
}
int vtkLSDynaReader::GetPointArrayStatus( int a )
{
if ( a < 0 || a >= (int) this->P->PointArrayStatus.size() )
return 0;
return this->P->PointArrayStatus[a];
}
void vtkLSDynaReader::SetPointArrayStatus( int a, int stat )
{
if ( a < 0 || a >= (int) this->P->PointArrayStatus.size() )
{
vtkWarningMacro( "Cannot set status of non-existent point array " << a );
return;
}
if ( stat == this->P->PointArrayStatus[a] )
return;
this->P->PointArrayStatus[a] = stat;
this->ResetPartsCache();
this->Modified();
}