-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathxpltReader.cpp
2086 lines (1940 loc) · 57.7 KB
/
xpltReader.cpp
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
/*This file is part of the FEBio Studio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio-Studio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "xpltReader.h"
#include <MeshLib/FENodeFaceList.h>
#include <PostLib/FEDataManager.h>
#include <PostLib/FEMeshData_T.h>
#include <PostLib/FEState.h>
#include <PostLib/FEPostMesh.h>
#include <PostLib/FEPostModel.h>
using namespace Post;
using namespace std;
template <class Type> void ReadFaceData_REGION(xpltArchive& ar, Post::FEPostMesh& m, XpltReader::Surface &s, Post::FEMeshData &data)
{
int NF = s.nf;
vector<int> face(NF);
for (int i=0; i<(int) face.size(); ++i) face[i] = s.face[i].nid;
FEFaceData<Type,DATA_REGION>& df = dynamic_cast<FEFaceData<Type,DATA_REGION>&>(data);
Type a;
ar.read(a);
df.add(face, a);
}
template <class Type> void ReadElemData_REGION(xpltArchive& ar, XpltReader::Domain& dom, Post::FEMeshData& s, int ntype)
{
int NE = dom.ne;
vector<int> elem(NE);
for (int i=0; i<NE; ++i) elem[i] = dom.elem[i].index;
Type a;
ar.read(a);
Post::FEElementData<Type,DATA_REGION>& df = dynamic_cast<Post::FEElementData<Type,DATA_REGION>&>(s);
df.add(elem, a);
}
//=================================================================================================
XpltReader::DICT_ITEM::DICT_ITEM()
{
}
XpltReader::DICT_ITEM::DICT_ITEM(const DICT_ITEM& item)
{
ntype = item.ntype;
nfmt = item.nfmt;
strcpy(szname, item.szname);
index = item.index;
arraySize = item.arraySize;
arrayNames = item.arrayNames;
}
//=================================================================================================
//-----------------------------------------------------------------------------
XpltReader::XpltReader(xpltFileReader* xplt) : xpltParser(xplt)
{
m_pstate = 0;
}
XpltReader::~XpltReader()
{
}
//-----------------------------------------------------------------------------
void XpltReader::Clear()
{
m_dic.Clear();
m_Mat.clear();
m_Node.clear();
m_Dom.clear();
m_Surf.clear();
m_bHasDispl = false;
m_bHasStress = false;
m_bHasNodalStress = false;
m_bHasShellThickness = false;
m_bHasFluidPressure = false;
m_bHasElasticity = false;
m_nel = 0;
m_pstate = 0;
}
//-----------------------------------------------------------------------------
bool XpltReader::Load(FEPostModel& fem)
{
// make sure all data is cleared
Clear();
// read the root section
// (This section was already opened by xpltFileReader)
if (ReadRootSection(fem) == false) return false;
if (m_xplt->IsCanceled()) return false;
// Clear the end-flag of the root section
m_ar.CloseChunk();
if (m_ar.OpenChunk() != xpltArchive::IO_END) return false;
// Build the mesh
if (BuildMesh(fem) == false) return false;
if (m_xplt->IsCanceled()) return false;
// read the state sections (these could be compressed)
const xpltFileReader::HEADER& hdr = m_xplt->GetHeader();
m_ar.SetCompression(hdr.ncompression);
int read_state_flag = m_xplt->GetReadStateFlag();
int nstate = 0;
try{
while (true)
{
if (m_ar.OpenChunk() != xpltArchive::IO_OK) break;
if (m_ar.GetChunkID() == PLT_STATE)
{
if (m_pstate) { delete m_pstate; m_pstate = 0; }
if (ReadStateSection(fem) == false) break;
if (read_state_flag == XPLT_READ_ALL_STATES) { fem.AddState(m_pstate); m_pstate = 0; }
else if (read_state_flag == XPLT_READ_STATES_FROM_LIST)
{
vector<int> state_list = m_xplt->GetReadStates();
int n = (int) state_list.size();
for (int i=0; i<n; ++i)
{
if (state_list[i] == nstate)
{
fem.AddState(m_pstate);
m_pstate = 0;
break;
}
}
}
else if (read_state_flag == XPLT_READ_FIRST_AND_LAST)
{
if (nstate == 0)
{
fem.AddState(m_pstate);
m_pstate = 0;
}
}
}
else
errf("Error while reading state data.");
m_ar.CloseChunk();
// clear end-flag
if (m_ar.OpenChunk() != xpltArchive::IO_END)
{
break;
}
++nstate;
if (m_xplt->IsCanceled())
{
break;
}
}
if ((read_state_flag == XPLT_READ_LAST_STATE_ONLY) ||
(read_state_flag == XPLT_READ_FIRST_AND_LAST)) { fem.AddState(m_pstate); m_pstate = 0; }
}
catch (...)
{
errf("An unknown exception has occurred.\nNot all data was read in.");
}
Clear();
return true;
}
//-----------------------------------------------------------------------------
// Header section is already read by xpltFileReader
bool XpltReader::ReadRootSection(FEPostModel& fem)
{
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
int nid = m_ar.GetChunkID();
switch (nid)
{
case PLT_DICTIONARY: if (ReadDictionary(fem) == false) return false; break;
case PLT_MATERIALS : if (ReadMaterials (fem) == false) return false; break;
case PLT_GEOMETRY : if (ReadMesh (fem) == false) return false; break;
default:
return errf("Failed reading Root section");
}
m_ar.CloseChunk();
}
return true;
}
//-----------------------------------------------------------------------------
bool XpltReader::ReadDictItem(DICT_ITEM& it)
{
char szname[64] = {0};
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
int nid = m_ar.GetChunkID();
switch(nid)
{
case PLT_DIC_ITEM_TYPE : m_ar.read(it.ntype); break;
case PLT_DIC_ITEM_FMT : m_ar.read(it.nfmt ); break;
case PLT_DIC_ITEM_ARRAYSIZE : m_ar.read(it.arraySize); break;
case PLT_DIC_ITEM_ARRAYNAME :
{
char tmp[DI_NAME_SIZE] = {0};
m_ar.read(tmp, DI_NAME_SIZE);
it.arrayNames.push_back(tmp);
}
break;
case PLT_DIC_ITEM_NAME:
{
m_ar.read(szname, DI_NAME_SIZE);
char* sz = strchr(szname, '=');
if (sz) *sz++ = 0; else sz = szname;
strcpy(it.szname, sz);
}
break;
default:
return errf("Error while reading dictionary section");
}
m_ar.CloseChunk();
}
assert((it.arrayNames.size() == 0) || (it.arrayNames.size() == it.arraySize));
return true;
}
//-----------------------------------------------------------------------------
bool XpltReader::ReadDictionary(FEPostModel& fem)
{
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
int nid = m_ar.GetChunkID();
switch (nid)
{
case PLT_DIC_GLOBAL : ReadGlobalDicItems (); break;
case PLT_DIC_MATERIAL : ReadMaterialDicItems(); break;
case PLT_DIC_NODAL : ReadNodeDicItems (); break;
case PLT_DIC_DOMAIN : ReadElemDicItems (); break;
case PLT_DIC_SURFACE : ReadFaceDicItems (); break;
default:
return errf("Error while reading Dictionary.");
}
m_ar.CloseChunk();
}
// clear data manager
FEDataManager* pdm = fem.GetDataManager();
pdm->Clear();
// read nodal variables
int nfields = 0;
int i;
int nv = (int)m_dic.m_Node.size();
for (i=0; i<nv; ++i)
{
DICT_ITEM& it = m_dic.m_Node[i];
it.index = nfields++;
// add nodal field
Post::ModelDataField* pdf = nullptr;
switch (it.ntype)
{
case FLOAT : pdf = new FEDataField_T<Post::FENodeData<float > >(&fem, EXPORT_DATA); break;
case VEC3F : pdf = new FEDataField_T<Post::FENodeData<vec3f > >(&fem, EXPORT_DATA); break;
case MAT3FS : pdf = new FEDataField_T<Post::FENodeData<mat3fs > >(&fem, EXPORT_DATA); break;
case MAT3FD : pdf = new FEDataField_T<Post::FENodeData<mat3fd > >(&fem, EXPORT_DATA); break;
case TENS4FS: pdf = new FEDataField_T<Post::FENodeData<tens4fs> >(&fem, EXPORT_DATA); break;
case MAT3F : pdf = new FEDataField_T<Post::FENodeData<mat3f > >(&fem, EXPORT_DATA); break;
case ARRAY :
{
FEArrayDataField* data = new FEArrayDataField(&fem, NODE_DATA, DATA_ITEM, EXPORT_DATA);
data->SetArraySize(it.arraySize);
data->SetArrayNames(it.arrayNames);
pdf = data;
}
break;
default:
return errf("Error while reading dictionary");
}
pdf->SetName(it.szname);
pdm->AddDataField(pdf);
}
// read solid variables
nv = (int)m_dic.m_Elem.size();
for (i=0; i<nv; ++i)
{
DICT_ITEM& it = m_dic.m_Elem[i];
it.index = nfields++;
Post::ModelDataField* pdf = nullptr;
switch (it.nfmt)
{
case FMT_NODE:
{
switch (it.ntype)
{
case FLOAT : pdf = new FEDataField_T<Post::FEElementData<float ,DATA_NODE> >(&fem, EXPORT_DATA); break;
case VEC3F : pdf = new FEDataField_T<Post::FEElementData<vec3f ,DATA_NODE> >(&fem, EXPORT_DATA); break;
case MAT3FS : pdf = new FEDataField_T<Post::FEElementData<mat3fs ,DATA_NODE> >(&fem, EXPORT_DATA); break;
case MAT3FD : pdf = new FEDataField_T<Post::FEElementData<mat3fd ,DATA_NODE> >(&fem, EXPORT_DATA); break;
case TENS4FS: pdf = new FEDataField_T<Post::FEElementData<tens4fs,DATA_NODE> >(&fem, EXPORT_DATA); break;
case MAT3F : pdf = new FEDataField_T<Post::FEElementData<mat3f ,DATA_NODE> >(&fem, EXPORT_DATA); break;
case ARRAY :
{
FEArrayDataField* data = new FEArrayDataField(&fem, ELEM_DATA, DATA_NODE, EXPORT_DATA);
data->SetArraySize(it.arraySize);
data->SetArrayNames(it.arrayNames);
pdf = data;
}
break;
default:
assert(false);
return false;
}
}
break;
case FMT_ITEM:
{
switch (it.ntype)
{
case FLOAT : pdf = new FEDataField_T<Post::FEElementData<float ,DATA_ITEM> >(&fem, EXPORT_DATA); break;
case VEC3F : pdf = new FEDataField_T<Post::FEElementData<vec3f ,DATA_ITEM> >(&fem, EXPORT_DATA); break;
case MAT3FS : pdf = new FEDataField_T<Post::FEElementData<mat3fs ,DATA_ITEM> >(&fem, EXPORT_DATA); break;
case MAT3FD : pdf = new FEDataField_T<Post::FEElementData<mat3fd ,DATA_ITEM> >(&fem, EXPORT_DATA); break;
case TENS4FS: pdf = new FEDataField_T<Post::FEElementData<tens4fs,DATA_ITEM> >(&fem, EXPORT_DATA); break;
case MAT3F : pdf = new FEDataField_T<Post::FEElementData<mat3f ,DATA_ITEM> >(&fem, EXPORT_DATA); break;
case ARRAY :
{
FEArrayDataField* data = new FEArrayDataField(&fem, ELEM_DATA, DATA_ITEM, EXPORT_DATA);
data->SetArraySize(it.arraySize);
data->SetArrayNames(it.arrayNames);
pdf = data;
}
break;
case ARRAY_VEC3F:
{
FEArrayVec3DataField* data = new FEArrayVec3DataField(&fem, ELEM_DATA, EXPORT_DATA);
data->SetArraySize(it.arraySize);
data->SetArrayNames(it.arrayNames);
pdf = data;
}
break;
default:
assert(false);
return false;
}
}
break;
case FMT_MULT:
{
switch (it.ntype)
{
case FLOAT : pdf = new FEDataField_T<Post::FEElementData<float ,DATA_MULT> >(&fem, EXPORT_DATA); break;
case VEC3F : pdf = new FEDataField_T<Post::FEElementData<vec3f ,DATA_MULT> >(&fem, EXPORT_DATA); break;
case MAT3FS : pdf = new FEDataField_T<Post::FEElementData<mat3fs ,DATA_MULT> >(&fem, EXPORT_DATA); break;
case MAT3FD : pdf = new FEDataField_T<Post::FEElementData<mat3fd ,DATA_MULT> >(&fem, EXPORT_DATA); break;
case TENS4FS: pdf = new FEDataField_T<Post::FEElementData<tens4fs,DATA_MULT> >(&fem, EXPORT_DATA); break;
case MAT3F : pdf = new FEDataField_T<Post::FEElementData<mat3f ,DATA_MULT> >(&fem, EXPORT_DATA); break;
default:
assert(false);
return false;
}
}
break;
case FMT_REGION:
{
switch (it.ntype)
{
case FLOAT : pdf = new FEDataField_T<Post::FEElementData<float ,DATA_REGION> >(&fem, EXPORT_DATA); break;
case VEC3F : pdf = new FEDataField_T<Post::FEElementData<vec3f ,DATA_REGION> >(&fem, EXPORT_DATA); break;
case MAT3FS : pdf = new FEDataField_T<Post::FEElementData<mat3fs ,DATA_REGION> >(&fem, EXPORT_DATA); break;
case MAT3FD : pdf = new FEDataField_T<Post::FEElementData<mat3fd ,DATA_REGION> >(&fem, EXPORT_DATA); break;
case TENS4FS: pdf = new FEDataField_T<Post::FEElementData<tens4fs,DATA_REGION> >(&fem, EXPORT_DATA); break;
case MAT3F : pdf = new FEDataField_T<Post::FEElementData<mat3f ,DATA_REGION> >(&fem, EXPORT_DATA); break;
default:
assert(false);
return false;
}
}
break;
default:
assert(false);
return errf("Error while reading dictionary");
}
if (pdf == nullptr) return false;
pdf->SetName(it.szname);
pdm->AddDataField(pdf);
}
// read face variables
nv = (int)m_dic.m_Face.size();
for (i=0; i<nv; ++i)
{
DICT_ITEM& it = m_dic.m_Face[i];
it.index = nfields++;
Post::ModelDataField* pdf = nullptr;
switch (it.nfmt)
{
case FMT_NODE:
{
switch (it.ntype)
{
case FLOAT : pdf = new FEDataField_T<FEFaceData<float ,DATA_NODE> >(&fem, EXPORT_DATA); break;
case VEC3F : pdf = new FEDataField_T<FEFaceData<vec3f ,DATA_NODE> >(&fem, EXPORT_DATA); break;
case MAT3FS : pdf = new FEDataField_T<FEFaceData<mat3fs ,DATA_NODE> >(&fem, EXPORT_DATA); break;
case MAT3FD : pdf = new FEDataField_T<FEFaceData<mat3fd ,DATA_NODE> >(&fem, EXPORT_DATA); break;
case TENS4FS: pdf = new FEDataField_T<FEFaceData<tens4fs,DATA_NODE> >(&fem, EXPORT_DATA); break;
case MAT3F : pdf = new FEDataField_T<FEFaceData<mat3f ,DATA_NODE> >(&fem, EXPORT_DATA); break;
default:
assert(false);
}
}
break;
case FMT_ITEM:
{
switch (it.ntype)
{
case FLOAT : pdf = new FEDataField_T<FEFaceData<float ,DATA_ITEM> >(&fem, EXPORT_DATA); break;
case VEC3F : pdf = new FEDataField_T<FEFaceData<vec3f ,DATA_ITEM> >(&fem, EXPORT_DATA); break;
case MAT3FS : pdf = new FEDataField_T<FEFaceData<mat3fs ,DATA_ITEM> >(&fem, EXPORT_DATA); break;
case MAT3FD : pdf = new FEDataField_T<FEFaceData<mat3fd ,DATA_ITEM> >(&fem, EXPORT_DATA); break;
case TENS4FS: pdf = new FEDataField_T<FEFaceData<tens4fs,DATA_ITEM> >(&fem, EXPORT_DATA); break;
case MAT3F : pdf = new FEDataField_T<FEFaceData<mat3f ,DATA_ITEM> >(&fem, EXPORT_DATA); break;
default:
assert(false);
}
}
break;
case FMT_MULT:
{
switch (it.ntype)
{
case FLOAT : pdf = new FEDataField_T<FEFaceData<float ,DATA_MULT> >(&fem, EXPORT_DATA); break;
case VEC3F : pdf = new FEDataField_T<FEFaceData<vec3f ,DATA_MULT> >(&fem, EXPORT_DATA); break;
case MAT3FS : pdf = new FEDataField_T<FEFaceData<mat3fs ,DATA_MULT> >(&fem, EXPORT_DATA); break;
case MAT3FD : pdf = new FEDataField_T<FEFaceData<mat3fd ,DATA_MULT> >(&fem, EXPORT_DATA); break;
case TENS4FS: pdf = new FEDataField_T<FEFaceData<tens4fs,DATA_MULT> >(&fem, EXPORT_DATA); break;
case MAT3F : pdf = new FEDataField_T<FEFaceData<mat3f ,DATA_MULT> >(&fem, EXPORT_DATA); break;
default:
assert(false);
}
}
break;
case FMT_REGION:
{
switch (it.ntype)
{
case FLOAT : pdf = new FEDataField_T<FEFaceData<float ,DATA_REGION> >(&fem, EXPORT_DATA); break;
case VEC3F : pdf = new FEDataField_T<FEFaceData<vec3f ,DATA_REGION> >(&fem, EXPORT_DATA); break;
case MAT3FS : pdf = new FEDataField_T<FEFaceData<mat3fs ,DATA_REGION> >(&fem, EXPORT_DATA); break;
case MAT3FD : pdf = new FEDataField_T<FEFaceData<mat3fd ,DATA_REGION> >(&fem, EXPORT_DATA); break;
case TENS4FS: pdf = new FEDataField_T<FEFaceData<tens4fs,DATA_REGION> >(&fem, EXPORT_DATA); break;
case MAT3F : pdf = new FEDataField_T<FEFaceData<mat3f ,DATA_REGION> >(&fem, EXPORT_DATA); break;
default:
assert(false);
}
}
break;
default:
assert(false);
return errf("Error reading dictionary");
}
if (pdf == nullptr) return false;
fem.AddDataField(pdf, it.szname);
}
// add additional displacement fields
if (m_bHasDispl)
{
pdm->AddDataField(new StrainDataField(&fem, StrainDataField::LAGRANGE), "Lagrange strain");
pdm->AddDataField(new FEDataField_T<NodePosition >(&fem), "position" );
pdm->AddDataField(new FEDataField_T<NodeInitPos >(&fem), "initial position" );
}
// add additional stress fields
if (m_bHasStress)
{
pdm->AddDataField(new FEDataField_T<ElemPressure>(&fem), "pressure");
if (m_bHasFluidPressure) {
// make sure the "solid stress" field was not added to the plot file
if (pdm->FindDataField("solid stress") == -1)
pdm->AddDataField(new FEDataField_T<SolidStress>(&fem), "solid stress");
}
}
// add additional stress fields
if (m_bHasNodalStress)
{
pdm->AddDataField(new FEDataField_T<ElemNodalPressure>(&fem), "nodal pressure");
}
return true;
}
//-----------------------------------------------------------------------------
bool XpltReader::ReadGlobalDicItems()
{
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
int nid = m_ar.GetChunkID();
if (nid == PLT_DIC_ITEM)
{
DICT_ITEM it;
ReadDictItem(it);
m_dic.m_Glb.push_back(it);
}
else
{
assert(false);
return errf("Error reading Global section in Dictionary");
}
m_ar.CloseChunk();
}
return true;
}
//-----------------------------------------------------------------------------
bool XpltReader::ReadMaterialDicItems()
{
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
int nid = m_ar.GetChunkID();
if (nid == PLT_DIC_ITEM)
{
DICT_ITEM it;
ReadDictItem(it);
m_dic.m_Mat.push_back(it);
}
else
{
assert(false);
return errf("Error reading Material section in Dictionary");
}
m_ar.CloseChunk();
}
return true;
}
//-----------------------------------------------------------------------------
bool XpltReader::ReadNodeDicItems()
{
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
int nid = m_ar.GetChunkID();
if (nid == PLT_DIC_ITEM)
{
DICT_ITEM it;
ReadDictItem(it);
if (strcmp(it.szname, "displacement") == 0) m_bHasDispl = true;
m_dic.m_Node.push_back(it);
}
else
{
assert(false);
return errf("Error reading Node section in Dictionary");
}
m_ar.CloseChunk();
}
return true;
}
//-----------------------------------------------------------------------------
bool XpltReader::ReadElemDicItems()
{
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
int nid = m_ar.GetChunkID();
if (nid == PLT_DIC_ITEM)
{
DICT_ITEM it;
ReadDictItem(it);
if (strcmp(it.szname, "stress" ) == 0) m_bHasStress = true;
if (strcmp(it.szname, "nodal stress" ) == 0) m_bHasNodalStress = true;
if (strcmp(it.szname, "shell thickness") == 0) m_bHasShellThickness = true;
if (strcmp(it.szname, "fluid pressure" ) == 0) m_bHasFluidPressure = true;
if (strcmp(it.szname, "elasticity" ) == 0) m_bHasElasticity = true;
m_dic.m_Elem.push_back(it);
}
else
{
assert(false);
return errf("Error reading Element section in Dictionary");
}
m_ar.CloseChunk();
}
return true;
}
//-----------------------------------------------------------------------------
bool XpltReader::ReadFaceDicItems()
{
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
int nid = m_ar.GetChunkID();
if (nid == PLT_DIC_ITEM)
{
DICT_ITEM it;
ReadDictItem(it);
m_dic.m_Face.push_back(it);
}
else
{
assert(false);
return errf("Error reading Face section in Dictionary");
}
m_ar.CloseChunk();
}
return true;
}
//-----------------------------------------------------------------------------
bool XpltReader::ReadMaterials(FEPostModel& fem)
{
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
int nid = m_ar.GetChunkID();
if (nid == PLT_MATERIAL)
{
MATERIAL m;
char sz[DI_NAME_SIZE] = {0};
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
switch (m_ar.GetChunkID())
{
case PLT_MAT_ID : m_ar.read(m.nid); break;
case PLT_MAT_NAME: m_ar.read(sz, DI_NAME_SIZE); break;
}
m_ar.CloseChunk();
}
strcpy(m.szname, sz);
m_Mat.push_back(m);
}
else
{
assert(false);
return errf("Error while reading materials");
}
m_ar.CloseChunk();
}
CreateMaterials(fem);
return true;
}
//-----------------------------------------------------------------------------
void XpltReader::CreateMaterials(FEPostModel& fem)
{
// initialize material properties
fem.ClearMaterials();
int nmat = (int)m_Mat.size();
for (int i=0; i<nmat; i++)
{
Material m;
m.SetName(m_Mat[i].szname);
fem.AddMaterial(m);
}
}
//-----------------------------------------------------------------------------
bool XpltReader::ReadMesh(FEPostModel &fem)
{
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
switch (m_ar.GetChunkID())
{
case PLT_NODE_SECTION : if (ReadNodeSection (fem) == false) return false; break;
case PLT_DOMAIN_SECTION : if (ReadDomainSection (fem) == false) return false; break;
case PLT_SURFACE_SECTION: if (ReadSurfaceSection(fem) == false) return false; break;
case PLT_NODESET_SECTION: if (ReadNodeSetSection(fem) == false) return false; break;
default:
assert(false);
return errf("Error while reading mesh");
}
m_ar.CloseChunk();
}
return true;
}
//-----------------------------------------------------------------------------
bool XpltReader::ReadNodeSection(FEPostModel &fem)
{
const xpltFileReader::HEADER& hdr = m_xplt->GetHeader();
vector<float> a(3 * hdr.nn);
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
if (m_ar.GetChunkID() == PLT_NODE_COORDS) m_ar.read(a);
else
{
assert(false);
return errf("Error while reading Node section");
}
m_ar.CloseChunk();
}
m_Node.resize(hdr.nn);
for (int i=0; i<hdr.nn; ++i)
{
NODE& n = m_Node[i];
n.r.x = a[3*i ];
n.r.y = a[3*i+1];
n.r.z = a[3*i+2];
}
return true;
}
//-----------------------------------------------------------------------------
bool XpltReader::ReadDomainSection(FEPostModel &fem)
{
int nd = 0, index = 0;
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
if (m_ar.GetChunkID() == PLT_DOMAIN)
{
Domain D;
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
int nid = m_ar.GetChunkID();
if (nid == PLT_DOMAIN_HDR)
{
// read the domain header
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
switch (m_ar.GetChunkID())
{
case PLT_DOM_ELEM_TYPE: m_ar.read(D.etype); break;
case PLT_DOM_MAT_ID : m_ar.read(D.mid); break;
case PLT_DOM_ELEMS : m_ar.read(D.ne); break;
case PLT_DOM_NAME : m_ar.read(D.szname); break;
default:
assert(false);
return errf("Error while reading Domain section");
}
m_ar.CloseChunk();
}
}
else if (nid == PLT_DOM_ELEM_LIST)
{
assert(D.ne > 0);
D.elem.reserve(D.ne);
D.elist.reserve(D.ne);
int ne = 0;
switch (D.etype)
{
case PLT_ELEM_HEX8 : ne = 8; break;
case PLT_ELEM_PENTA : ne = 6; break;
case PLT_ELEM_PENTA15: ne = 15; break;
case PLT_ELEM_TET4 : ne = 4; break;
case PLT_ELEM_TET5 : ne = 5; break;
case PLT_ELEM_QUAD : ne = 4; break;
case PLT_ELEM_TRI : ne = 3; break;
case PLT_ELEM_TRUSS : ne = 2; break;
case PLT_ELEM_HEX20 : ne = 20; break;
case PLT_ELEM_HEX27 : ne = 27; break;
case PLT_ELEM_TET10 : ne = 10; break;
case PLT_ELEM_TET15 : ne = 15; break;
case PLT_ELEM_TET20 : ne = 20; break;
case PLT_ELEM_TRI6 : ne = 6; break;
case PLT_ELEM_QUAD8 : ne = 8; break;
case PLT_ELEM_QUAD9 : ne = 9; break;
case PLT_ELEM_PYRA5 : ne = 5; break;
case PLT_ELEM_PYRA13 : ne = 13; break;
default:
assert(false);
return errf("Error while reading Domain section");
}
assert((ne > 0)&&(ne <= FSElement::MAX_NODES));
int n[FSElement::MAX_NODES + 1];
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
if (m_ar.GetChunkID() == PLT_ELEMENT)
{
ELEM e;
m_ar.read(n, ne+1);
e.index = index++;
e.eid = n[0];
for (int i=0; i<ne; ++i) { e.node[i] = n[i+1]; assert(e.node[i] < (int)m_Node.size()); }
D.elem.push_back(e);
D.elist.push_back(e.index);
}
else
{
assert(false);
return errf("Error while reading Domain section");
}
m_ar.CloseChunk();
}
}
else
{
assert(false);
return errf("Error while reading Domain section");
}
m_ar.CloseChunk();
}
assert(D.ne == D.elem.size());
D.nid = nd++;
m_Dom.push_back(D);
}
else
{
assert(false);
return errf("Error while reading Domain section");
}
m_ar.CloseChunk();
}
return true;
}
//-----------------------------------------------------------------------------
bool XpltReader::ReadSurfaceSection(FEPostModel &fem)
{
const xpltFileReader::HEADER& hdr = m_xplt->GetHeader();
int nodes_per_facet = hdr.nmax_facet_nodes;
// in previous versions there was a bug in the number
// of nodes written so we need to make an adjustment.
if (hdr.nversion < 0x04) nodes_per_facet -= 2;
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
if (m_ar.GetChunkID() == PLT_SURFACE)
{
Surface S;
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
int nid = m_ar.GetChunkID();
if (nid == PLT_SURFACE_HDR)
{
// read the surface header
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
switch(m_ar.GetChunkID())
{
case PLT_SURFACE_ID : m_ar.read(S.sid); break;
case PLT_SURFACE_FACES: m_ar.read(S.nf); break;
case PLT_SURFACE_NAME : m_ar.read(S.szname, 64); break;
default:
assert(false);
return errf("Error while reading Surface section");
}
m_ar.CloseChunk();
}
}
else if (nid == PLT_FACE_LIST)
{
if (hdr.nversion == 1)
{
assert(S.nf > 0);
S.face.reserve(S.nf);
int n[5];
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
if (m_ar.GetChunkID() == PLT_FACE)
{
m_ar.read(n, 5);
FACE f;
f.nid = n[0];
f.node[0] = n[1];
f.node[1] = n[2];
f.node[2] = n[3];
f.node[3] = n[4];
f.nn = (f.node[3] == f.node[2] ? 3 : 4);
S.face.push_back(f);
}
else
{
assert(false);
return errf("Error while reading Surface section");
}
m_ar.CloseChunk();
}
}
else
{
assert(S.nf > 0);
S.face.reserve(S.nf);
int n[12];
assert(hdr.nmax_facet_nodes <= 10);
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
if (m_ar.GetChunkID() == PLT_FACE)
{
m_ar.read(n, nodes_per_facet+2);
FACE f;
f.nid = n[0];
f.nn = n[1];
for (int i=0; i<f.nn; ++i) f.node[i] = n[2+i];
S.face.push_back(f);
}
else
{
assert(false);
return errf("Error while reading Surface section");
}
m_ar.CloseChunk();
}
}
}
m_ar.CloseChunk();
}
assert(S.nf == S.face.size());
m_Surf.push_back(S);
}
else
{
assert(false);
return errf("Error while reading Surface section");
}
m_ar.CloseChunk();
}
return true;
}
//-----------------------------------------------------------------------------
bool XpltReader::ReadNodeSetSection(FEPostModel& fem)
{
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
if (m_ar.GetChunkID() == PLT_NODESET)
{
NodeSet S;
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
int nid = m_ar.GetChunkID();
if (nid == PLT_NODESET_HDR)
{
// read the nodeset header
while (m_ar.OpenChunk() == xpltArchive::IO_OK)
{
switch(m_ar.GetChunkID())
{
case PLT_NODESET_ID : m_ar.read(S.nid); break;
case PLT_NODESET_SIZE : m_ar.read(S.nn); break;
case PLT_NODESET_NAME : m_ar.read(S.szname); break;
default:
assert(false);
return errf("Error while reading NodeSet section");
}
m_ar.CloseChunk();
}
}
else if (nid == PLT_NODESET_LIST)
{
S.node.assign(S.nn, 0);
m_ar.read(S.node);
}
else
{
assert(false);
return errf("Error while reading NodeSet section");
}
m_ar.CloseChunk();
}
m_NodeSet.push_back(S);
}
else
{
assert(false);
return errf("Error while reading NodeSet section");
}
m_ar.CloseChunk();
}
return true;
}
//-----------------------------------------------------------------------------
bool XpltReader::BuildMesh(FEPostModel &fem)