-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathd3plot.py
9774 lines (8304 loc) · 386 KB
/
d3plot.py
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
import ctypes
from dataclasses import dataclass
import logging
import mmap
import os
import pprint
import re
import struct
import tempfile
import traceback
import typing
import webbrowser
from typing import Any, BinaryIO, Dict, Iterable, List, Set, Tuple, Union
import numpy as np
from ..femzip.femzip_api import FemzipAPI, FemzipBufferInfo, FemzipVariableCategory
from ..io.binary_buffer import BinaryBuffer
from ..io.files import open_file_or_filepath
from ..logging import get_logger
from ..plotting import plot_shell_mesh
from .array_type import ArrayType
from .d3plot_header import D3plotFiletype, D3plotHeader
from .femzip_mapper import FemzipMapper, filter_femzip_variables
from .filter_type import FilterType
# pylint: disable = too-many-lines
FORTRAN_OFFSET = 1
LOGGER = get_logger(__name__)
def _check_ndim(d3plot, array_dim_names: Dict[str, List[str]]):
"""Checks if the specified array is fine in terms of ndim
Parameters
----------
d3plot: D3plot
d3plot holding arrays
array_dim_names: Dict[str, List[str]]
"""
for type_name, dim_names in array_dim_names.items():
if type_name in d3plot.arrays:
array = d3plot.arrays[type_name]
if array.ndim != len(dim_names):
msg = "Array {0} must have {1} instead of {2} dimensions: ({3})"
dim_names_text = ", ".join(dim_names)
raise ValueError(msg.format(type_name, len(dim_names), array.ndim, dim_names_text))
def _check_array_occurrence(
d3plot, array_names: List[str], required_array_names: List[str]
) -> bool:
"""Check if an array exists, if all depending on it exist too
Parameters
----------
array_names: List[str]
list of base arrays
required_array_names: List[str]
list of array names which would be required
Returns
-------
exists: bool
if the arrays exist or not
Raises
------
ValueError
If a required array is not present
"""
if any(name in d3plot.arrays for name in array_names):
if not all(name in d3plot.arrays for name in required_array_names):
msg = "The arrays '{0}' require setting also the arrays '{1}'"
raise ValueError(msg.format(", ".join(array_names), ", ".join(required_array_names)))
return True
return False
def _negative_to_positive_state_indexes(indexes: Set[int], n_entries) -> Set[int]:
"""Convert negative indexes of an iterable to positive ones
Parameters
----------
indexes: Set[int]
indexes to check and convert
n_entries: int
total number of entries
Returns
-------
new_entries: Set[int]
the positive indexes
"""
new_entries: Set[int] = set()
for _, index in enumerate(indexes):
new_index = index + n_entries if index < 0 else index
if new_index >= n_entries:
err_msg = "State '{0}' exceeds the maximum number of states of '{1}'"
raise ValueError(err_msg.format(index, n_entries))
new_entries.add(new_index)
return new_entries
# pylint: disable = too-many-instance-attributes
class D3plotWriterSettings:
"""Settings class for d3plot writing"""
def __init__(self, d3plot: Any, block_size_bytes: int, single_file: bool):
# check the writing types
if d3plot.header.itype == np.int32:
self.itype = "<i"
elif d3plot.header.itype == np.int64:
self.itype = "<q"
else:
msg = "Invalid type for integers: {0}. np.int32 or np.int64 is required."
raise RuntimeError(msg.format(d3plot.itype))
if d3plot.header.ftype == np.float32:
self.ftype = "<f"
elif d3plot.header.ftype == np.float64:
self.ftype = "<d"
else:
msg = "Invalid type for floats: {0}. np.float32 or np.float64 is required."
raise RuntimeError(msg.format(d3plot.ftype))
assert isinstance(d3plot, D3plot)
self.d3plot = d3plot
self._header = {}
self.block_size_bytes = block_size_bytes
self.mattyp = 0
self.single_file = single_file
self.mdlopt = 0
self.n_shell_layers = 0
self.n_rigid_shells = 0
self.unique_beam_part_indexes = np.empty(0, dtype=self.itype)
self.unique_shell_part_indexes = np.empty(0, dtype=self.itype)
self.unique_solid_part_indexes = np.empty(0, dtype=self.itype)
self.unique_tshell_part_indexes = np.empty(0, dtype=self.itype)
self._str_codec = "utf-8"
self.has_node_temperature_gradient = False
self.has_node_residual_forces = False
self.has_node_residual_moments = False
self.has_plastic_strain_tensor = False
self.has_thermal_strain_tensor = False
self.n_solid_layers = 1
self._allowed_int_types = (np.int8, np.int16, np.int32, np.int64, int)
self._allowed_float_types = (np.float32, np.float64, float)
@property
def wordsize(self):
"""Get the wordsize to use for the d3plot
Returns
-------
worsize : int
D3plot wordsize
"""
return self.d3plot.header.wordsize
@property
def header(self):
"""Dictionary holding all d3plot header information
Notes
-----
The header is being build from the data stored in the d3plot.
"""
return self._header
@header.setter
def set_header(self, new_header: dict):
assert isinstance(new_header, dict)
self._header = new_header
# pylint: disable = too-many-branches, too-many-statements, too-many-locals
def build_header(self):
"""Build the new d3plot header"""
new_header = {}
# TITLE
new_header["title"] = self.d3plot.header.title
# RUNTIME
new_header["runtime"] = self.d3plot.header.runtime
# FILETYPE
new_header["filetype"] = self.d3plot.header.filetype.value
# SOURCE VERSION
new_header["source_version"] = self.d3plot.header.source_version
# RELEASE VERSION
new_header["release_version"] = self.d3plot.header.release_version
# SOURCE VERSION
new_header["version"] = self.d3plot.header.version
# NDIM
# check for rigid body data
has_rigid_body_data = False
has_reduced_rigid_body_data = False
if (
ArrayType.rigid_body_coordinates in self.d3plot.arrays
or ArrayType.rigid_body_rotation_matrix in self.d3plot.arrays
):
has_rigid_body_data = True
has_reduced_rigid_body_data = True
if (
ArrayType.rigid_body_velocity in self.d3plot.arrays
or ArrayType.rigid_body_rot_velocity in self.d3plot.arrays
or ArrayType.rigid_body_acceleration in self.d3plot.arrays
or ArrayType.rigid_body_rot_acceleration in self.d3plot.arrays
):
has_reduced_rigid_body_data = False
# check for rigid road
required_arrays = [
ArrayType.rigid_road_node_ids,
ArrayType.rigid_road_node_coordinates,
ArrayType.rigid_road_ids,
ArrayType.rigid_road_segment_node_ids,
ArrayType.rigid_road_segment_road_id,
]
_check_array_occurrence(
self.d3plot, array_names=required_arrays, required_array_names=required_arrays
)
has_rigid_road = ArrayType.rigid_road_node_ids in self.d3plot.arrays
# check for mattyp shit
# self.mattyp = 0
# if not is_d3part and ArrayType.part_material_type in self.d3plot.arrays:
# self.mattyp = 1
# elif is_d3part and ArrayType.part_material_type in self.d3plot.arrays:
# #
# self.mattyp = 0
# check for mattyp
is_d3part = self.d3plot.header.filetype == D3plotFiletype.D3PART
self.mattyp = 0
if not is_d3part and ArrayType.part_material_type in self.d3plot.arrays:
self.mattyp = 1
# rigid shells
if ArrayType.element_shell_part_indexes in self.d3plot.arrays:
part_mattyp = self.d3plot.arrays[ArrayType.part_material_type]
shell_part_indexes = self.d3plot.arrays[ArrayType.element_shell_part_indexes]
self.n_rigid_shells = (part_mattyp[shell_part_indexes] == 20).sum()
elif is_d3part:
self.mattyp = 0
# set ndim finally
#
# This also confuses me from the manual ...
# It doesn't specify ndim clearly and only gives ranges.
#
# - has rigid body: rigid body data (movement etc.)
# - rigid road: rigid road data
# - mattyp: array with material types for each part
#
# Table:
# |----------------|--------------------|------------|---------|----------|
# | has_rigid_body | reduced rigid body | rigid road | mattyp | ndim |
# |----------------|--------------------|------------|---------|----------|
# | False | False | False | 0 | 4 |
# | False | False | False | 1 | 5 |
# | False (?) | False | True | 0 | 6 |
# | False | False | True | 1 | 7 |
# | True | False | False | 0 | 8 |
# | True | True | True | 0 | 9 |
# |----------------|--------------------|------------|---------|----------|
#
# uncertainties: mattyp 0 or 1 ?!?!?
if (
not has_rigid_body_data
and not has_reduced_rigid_body_data
and not has_rigid_road
and self.mattyp == 0
):
new_header["ndim"] = 4
elif (
not has_rigid_body_data
and not has_reduced_rigid_body_data
and not has_rigid_road
and self.mattyp == 1
):
new_header["ndim"] = 5
elif (
not has_rigid_body_data
and not has_reduced_rigid_body_data
and has_rigid_road
and self.mattyp == 0
):
new_header["ndim"] = 6
elif (
not has_rigid_body_data
and not has_reduced_rigid_body_data
and has_rigid_road
and self.mattyp == 1
):
new_header["ndim"] = 7
elif (
has_rigid_body_data
and not has_reduced_rigid_body_data
and not has_rigid_road
and self.mattyp == 0
):
new_header["ndim"] = 8
elif (
has_rigid_body_data
and has_reduced_rigid_body_data
and has_rigid_road
and self.mattyp == 0
):
new_header["ndim"] = 9
else:
raise RuntimeError("Cannot determine haeder variable ndim.")
# NUMNP
new_header["numnp"] = (
self.d3plot.arrays[ArrayType.node_coordinates].shape[0]
if ArrayType.node_coordinates in self.d3plot.arrays
else 0
)
# ICODE
new_header["icode"] = self.d3plot.header.legacy_code_type
# IT aka temperatures
_check_array_occurrence(
self.d3plot,
array_names=[ArrayType.node_heat_flux],
required_array_names=[ArrayType.node_temperature],
)
it_temp = 0
if ArrayType.node_mass_scaling in self.d3plot.arrays:
it_temp += 10
if (
ArrayType.node_temperature in self.d3plot.arrays
and ArrayType.node_heat_flux not in self.d3plot.arrays
):
it_temp += 1
elif (
ArrayType.node_temperature in self.d3plot.arrays
and ArrayType.node_heat_flux in self.d3plot.arrays
):
node_temp_shape = self.d3plot.arrays[ArrayType.node_temperature].shape
if node_temp_shape.ndim == 2:
it_temp += 2
elif node_temp_shape.ndim == 3:
it_temp += 3
else:
msg = "{1} is supposed to have either 2 or 3 dims and not '{0}'"
raise RuntimeError(msg.format(node_temp_shape.ndim, ArrayType.node_temperature))
else:
# caught by _check_array_occurrence
pass
new_header["it"] = it_temp
# IU - disp field indicator
new_header["iu"] = 1 if ArrayType.node_displacement in self.d3plot.arrays else 0
# IV - velicoty field indicator
new_header["iv"] = 1 if ArrayType.node_velocity in self.d3plot.arrays else 0
# IA - velicoty field indicator
new_header["ia"] = 1 if ArrayType.node_acceleration in self.d3plot.arrays else 0
# NEL8 - solid count
n_solids = (
self.d3plot.arrays[ArrayType.element_solid_node_indexes].shape[0]
if ArrayType.element_solid_node_indexes in self.d3plot.arrays
else 0
)
new_header["nel8"] = n_solids
# helper var to track max material index across all element types
# this is required to allocate the part array later
# new_header["nmmat"] = 0
# NUMMAT8 - solid material count
required_arrays = [
ArrayType.element_solid_node_indexes,
ArrayType.element_solid_part_indexes,
]
_check_array_occurrence(
self.d3plot,
array_names=required_arrays,
required_array_names=required_arrays,
)
if ArrayType.element_solid_part_indexes in self.d3plot.arrays:
part_indexes = self.d3plot.arrays[ArrayType.element_solid_part_indexes]
unique_part_indexes = np.unique(part_indexes)
self.unique_solid_part_indexes = unique_part_indexes
new_header["nummat8"] = len(unique_part_indexes)
# max_index = unique_part_indexes.max() + 1 \
# if len(part_indexes) else 0
# new_header["nmmat"] = max(new_header["nmmat"],
# max_index)
else:
new_header["nummat8"] = 0
# NUMDS
new_header["numds"] = self.d3plot.header.has_shell_four_inplane_gauss_points
# NUMST
new_header["numst"] = self.d3plot.header.unused_numst
# NV3D - number of solid vars
# NEIPH - number of solid history vars
n_solid_layers = self.d3plot.check_array_dims(
{
ArrayType.element_solid_stress: 2,
ArrayType.element_solid_effective_plastic_strain: 2,
ArrayType.element_solid_history_variables: 2,
ArrayType.element_solid_plastic_strain_tensor: 2,
ArrayType.element_solid_thermal_strain_tensor: 2,
},
"n_solid_layers",
)
n_solid_layers = 1 if n_solid_layers < 1 else n_solid_layers
self.n_solid_layers = n_solid_layers
if n_solid_layers not in (1, 8):
err_msg = "Solids must have either 1 or 8 integration layers not {0}."
raise ValueError(err_msg.format(self.n_solid_layers))
n_solid_hist_vars, _ = self.count_array_state_var(
array_type=ArrayType.element_solid_history_variables,
dimension_names=["n_timesteps", "n_solids", "n_solid_layers", "n_history_vars"],
has_layers=True,
n_layers=n_solid_layers,
)
n_solid_hist_vars = n_solid_hist_vars // n_solid_layers
if ArrayType.element_solid_strain in self.d3plot.arrays:
n_solid_hist_vars += 6
# It is uncertain if this is counted as history var
if ArrayType.element_solid_plastic_strain_tensor in self.d3plot.arrays:
n_solid_hist_vars += 6
# It is uncertain if this is counted as history var
if ArrayType.element_solid_thermal_strain_tensor in self.d3plot.arrays:
n_solid_hist_vars += 6
n_solid_vars = (7 + n_solid_hist_vars) * n_solid_layers
new_header["neiph"] = (
n_solid_hist_vars if n_solids != 0 else self.d3plot.header.n_solid_history_vars
)
new_header["nv3d"] = n_solid_vars if n_solids != 0 else self.d3plot.header.n_solid_vars
# NEL2 - beam count
new_header["nel2"] = (
self.d3plot.arrays[ArrayType.element_beam_node_indexes].shape[0]
if ArrayType.element_beam_node_indexes in self.d3plot.arrays
else 0
)
# NUMMAT2 - beam material count
required_arrays = [
ArrayType.element_beam_node_indexes,
ArrayType.element_beam_part_indexes,
]
_check_array_occurrence(
self.d3plot,
array_names=required_arrays,
required_array_names=required_arrays,
)
if ArrayType.element_beam_part_indexes in self.d3plot.arrays:
part_indexes = self.d3plot.arrays[ArrayType.element_beam_part_indexes]
unique_part_indexes = np.unique(part_indexes)
new_header["nummat2"] = len(unique_part_indexes)
self.unique_beam_part_indexes = unique_part_indexes
# max_index = unique_part_indexes.max() + 1 \
# if len(unique_part_indexes) else 0
# new_header["nmmat"] = max(new_header["nmmat"],
# max_index)
else:
new_header["nummat2"] = 0
# NEIPB - beam history vars per integration point
array_dims = {
ArrayType.element_beam_shear_stress: 2,
ArrayType.element_beam_axial_stress: 2,
ArrayType.element_beam_plastic_strain: 2,
ArrayType.element_beam_axial_strain: 2,
ArrayType.element_beam_history_vars: 2,
}
n_beam_layers = self.d3plot.check_array_dims(array_dims, "n_beam_layers")
new_header["beamip"] = n_beam_layers
new_header["neipb"] = 0
if ArrayType.element_beam_history_vars in self.d3plot.arrays:
array = self.d3plot.arrays[ArrayType.element_beam_history_vars]
if array.ndim != 4:
msg = (
"Array '{0}' was expected to have 4 dimensions "
"(n_timesteps, n_beams, n_modes (3+n_beam_layers), "
"n_beam_history_vars)."
)
raise ValueError(msg.format(ArrayType.element_beam_history_vars))
if array.shape[3] < 3:
msg = (
"Array '{0}' dimension 3 must have have at least three"
" entries (beam layers: average, min, max)"
)
raise ValueError(msg.format(ArrayType.element_beam_history_vars))
if array.shape[3] != 3 + n_beam_layers:
msg = "Array '{0}' dimension 3 must have size (3+n_beam_layers). {1} != (3+{2})"
raise ValueError(msg.format(ArrayType.element_beam_history_vars))
new_header["neipb"] = array.shape[3]
# NV1D - beam variable count
new_header["nv1d"] = (
6 + 5 * new_header["beamip"] + new_header["neipb"] * (3 + new_header["beamip"])
)
# NEL4 - number of shells
n_shells = (
self.d3plot.arrays[ArrayType.element_shell_node_indexes].shape[0]
if ArrayType.element_shell_node_indexes in self.d3plot.arrays
else 0
)
new_header["nel4"] = n_shells
# NUMMAT4 - shell material count
required_arrays = [
ArrayType.element_shell_node_indexes,
ArrayType.element_shell_part_indexes,
]
_check_array_occurrence(
self.d3plot,
array_names=required_arrays,
required_array_names=required_arrays,
)
if ArrayType.element_shell_part_indexes in self.d3plot.arrays:
part_indexes = self.d3plot.arrays[ArrayType.element_shell_part_indexes]
unique_part_indexes = np.unique(part_indexes)
new_header["nummat4"] = len(unique_part_indexes)
self.unique_shell_part_indexes = unique_part_indexes
# max_index = unique_part_indexes.max() + 1 \
# if len(unique_part_indexes) else 0
# new_header["nmmat"] = max(new_header["nmmat"],
# max_index)
else:
new_header["nummat4"] = 0
# NEIPS -shell history variable count
n_shell_layers = 0
if (
ArrayType.element_shell_history_vars in self.d3plot.arrays
or ArrayType.element_tshell_history_variables in self.d3plot.arrays
):
n_shell_history_vars, n_shell_layers = self.count_array_state_var(
array_type=ArrayType.element_shell_history_vars,
dimension_names=["n_timesteps", "n_shells", "n_shell_layers", "n_history_vars"],
has_layers=True,
n_layers=n_shell_layers,
)
n_tshell_history_vars, n_tshell_layers = self.count_array_state_var(
array_type=ArrayType.element_tshell_history_variables,
dimension_names=["n_timesteps", "n_tshells", "n_shell_layers", "n_history_vars"],
has_layers=True,
n_layers=n_shell_layers,
)
if n_shell_layers != n_tshell_layers:
msg = (
"Shells and thick shells must have the same amount "
"of integration layers: {0} != {1}"
)
raise RuntimeError(msg.format(n_shell_layers, n_tshell_layers))
# we are tolerant here and simply add zero padding for the other
# field later on
new_header["neips"] = max(
n_tshell_history_vars // n_tshell_layers, n_shell_history_vars // n_shell_layers
)
else:
new_header["neips"] = 0
array_dims = {
ArrayType.element_shell_stress: 2,
ArrayType.element_shell_effective_plastic_strain: 2,
ArrayType.element_shell_history_vars: 2,
ArrayType.element_tshell_stress: 2,
ArrayType.element_tshell_effective_plastic_strain: 2,
ArrayType.element_tshell_history_variables: 2,
}
n_shell_layers = self.d3plot.check_array_dims(array_dims, "n_shell_layers")
self.n_shell_layers = n_shell_layers
# NELTH - number of thick shell elements
n_thick_shells = (
self.d3plot.arrays[ArrayType.element_tshell_node_indexes].shape[0]
if ArrayType.element_tshell_node_indexes in self.d3plot.arrays
else 0
)
new_header["nelth"] = n_thick_shells
# IOSHL1 - shell & solid stress flag
if (
ArrayType.element_shell_stress in self.d3plot.arrays
or ArrayType.element_tshell_stress in self.d3plot.arrays
):
new_header["ioshl1"] = 1000
else:
# if either stress or pstrain is written for solids
# the whole block of 7 basic variables is always written
# to the file
if (
ArrayType.element_solid_stress in self.d3plot.arrays
or ArrayType.element_solid_effective_plastic_strain in self.d3plot.arrays
):
new_header["ioshl1"] = 999
else:
new_header["ioshl1"] = 0
if n_shells == 0 and n_thick_shells == 0 and n_solids == 0:
new_header["ioshl1"] = (
self.d3plot.header.raw_header["ioshl1"]
if "ioshl1" in self.d3plot.header.raw_header
else 0
)
if n_shells == 0 and n_thick_shells == 0 and n_solids != 0:
if (
"ioshl1" in self.d3plot.header.raw_header
and self.d3plot.header.raw_header["ioshl1"] == 1000
):
new_header["ioshl1"] = 1000
# IOSHL2 - shell & solid pstrain flag
if (
ArrayType.element_shell_effective_plastic_strain in self.d3plot.arrays
or ArrayType.element_tshell_effective_plastic_strain in self.d3plot.arrays
):
new_header["ioshl2"] = 1000
else:
if ArrayType.element_solid_effective_plastic_strain in self.d3plot.arrays:
new_header["ioshl2"] = 999
else:
new_header["ioshl2"] = 0
if n_shells == 0 and n_thick_shells == 0 and n_solids == 0:
new_header["ioshl2"] = (
self.d3plot.header.raw_header["ioshl2"]
if "ioshl2" in self.d3plot.header.raw_header
else 0
)
if n_shells == 0 and n_thick_shells == 0 and n_solids != 0:
if (
"ioshl2" in self.d3plot.header.raw_header
and self.d3plot.header.raw_header["ioshl2"] == 1000
):
new_header["ioshl2"] = 1000
# IOSHL3 - shell forces flag
if (
ArrayType.element_shell_shear_force in self.d3plot.arrays
or ArrayType.element_shell_bending_moment in self.d3plot.arrays
or ArrayType.element_shell_normal_force in self.d3plot.arrays
):
new_header["ioshl3"] = 1000
else:
# new_header["ioshl3"] = 999
new_header["ioshl3"] = 0
if n_shells == 0:
new_header["ioshl3"] = (
self.d3plot.header.raw_header["ioshl3"]
if "ioshl3" in self.d3plot.header.raw_header
else 0
)
# IOSHL4 - shell energy+2 unknown+thickness flag
if (
ArrayType.element_shell_thickness in self.d3plot.arrays
or ArrayType.element_shell_unknown_variables in self.d3plot.arrays
or ArrayType.element_shell_internal_energy in self.d3plot.arrays
):
new_header["ioshl4"] = 1000
else:
# new_header["ioshl4"] = 999
new_header["ioshl4"] = 0
if n_shells == 0:
new_header["ioshl4"] = (
self.d3plot.header.raw_header["ioshl4"]
if "ioshl4" in self.d3plot.header.raw_header
else 0
)
# IDTDT - Flags for various data in the database
new_header["idtdt"] = 0
istrn = 0
if (
ArrayType.element_shell_strain in self.d3plot.arrays
or ArrayType.element_solid_strain in self.d3plot.arrays
or ArrayType.element_tshell_strain in self.d3plot.arrays
):
# new_header["idtdt"] = 10000
istrn = 1
new_header["istrn"] = istrn
if ArrayType.node_temperature_gradient in self.d3plot.arrays:
new_header["idtdt"] += 1
self.has_node_temperature_gradient = True
if (
ArrayType.node_residual_forces in self.d3plot.arrays
or ArrayType.node_residual_moments in self.d3plot.arrays
):
new_header["idtdt"] += 10
self.has_node_residual_forces = True
self.has_node_residual_moments = True
if (
ArrayType.element_shell_plastic_strain_tensor in self.d3plot.arrays
or ArrayType.element_solid_plastic_strain_tensor in self.d3plot.arrays
):
new_header["idtdt"] += 100
self.has_plastic_strain_tensor = True
if (
ArrayType.element_shell_thermal_strain_tensor in self.d3plot.arrays
or ArrayType.element_solid_thermal_strain_tensor in self.d3plot.arrays
):
new_header["idtdt"] += 1000
self.has_thermal_strain_tensor = True
if new_header["idtdt"] > 100 and new_header["istrn"]:
new_header["idtdt"] += 10000
# info of element deletion is encoded into maxint ...
element_deletion_arrays = [
ArrayType.element_beam_is_alive,
ArrayType.element_shell_is_alive,
ArrayType.element_tshell_is_alive,
ArrayType.element_solid_is_alive,
]
mdlopt = 0
if any(name in self.d3plot.arrays for name in element_deletion_arrays):
mdlopt = 2
elif ArrayType.node_is_alive in self.d3plot.arrays:
mdlopt = 1
self.mdlopt = mdlopt
# MAXINT - shell integration layer count
array_dims = {
ArrayType.element_shell_stress: 2,
ArrayType.element_shell_effective_plastic_strain: 2,
ArrayType.element_shell_history_vars: 2,
ArrayType.element_tshell_stress: 2,
ArrayType.element_tshell_effective_plastic_strain: 2,
}
n_shell_layers = self.d3plot.check_array_dims(array_dims, "n_layers")
# beauty fix: take old shell layers if none exist
if n_shell_layers == 0:
n_shell_layers = self.d3plot.header.n_shell_tshell_layers
if mdlopt == 0:
new_header["maxint"] = n_shell_layers
elif mdlopt == 1:
new_header["maxint"] = -n_shell_layers
elif mdlopt == 2:
new_header["maxint"] = -(n_shell_layers + 10000)
# NV2D - shell variable count
has_shell_stress = new_header["ioshl1"] == 1000
has_shell_pstrain = new_header["ioshl2"] == 1000
has_shell_forces = new_header["ioshl3"] == 1000
has_shell_other = new_header["ioshl4"] == 1000
new_header["nv2d"] = (
n_shell_layers * (6 * has_shell_stress + has_shell_pstrain + new_header["neips"])
+ 8 * has_shell_forces
+ 4 * has_shell_other
+ 12 * istrn
+ n_shell_layers * self.has_plastic_strain_tensor * 6
+ self.has_thermal_strain_tensor * 6
)
# NMSPH - number of sph nodes
new_header["nmsph"] = (
len(self.d3plot.arrays[ArrayType.sph_node_indexes])
if ArrayType.sph_node_indexes in self.d3plot.arrays
else 0
)
# NGPSPH - number of sph materials
new_header["ngpsph"] = (
len(np.unique(self.d3plot.arrays[ArrayType.sph_node_material_index]))
if ArrayType.sph_node_material_index in self.d3plot.arrays
else 0
)
# NUMMATT - thick shell material count
required_arrays = [
ArrayType.element_tshell_node_indexes,
ArrayType.element_tshell_part_indexes,
]
_check_array_occurrence(
self.d3plot,
array_names=required_arrays,
required_array_names=required_arrays,
)
if ArrayType.element_tshell_part_indexes in self.d3plot.arrays:
part_indexes = self.d3plot.arrays[ArrayType.element_tshell_part_indexes]
unique_part_indexes = np.unique(part_indexes)
new_header["nummatt"] = len(unique_part_indexes)
self.unique_tshell_part_indexes = unique_part_indexes
# max_index = unique_part_indexes.max() + 1 \
# if len(part_indexes) else 0
# new_header["nmmat"] = max(new_header["nmmat"],
# max_index)
else:
new_header["nummatt"] = 0
# NV3DT
new_header["nv3dt"] = (
n_shell_layers * (6 * has_shell_stress + has_shell_pstrain + new_header["neips"])
+ 12 * istrn
)
# IALEMAT - number of ALE materials
new_header["ialemat"] = (
len(self.d3plot.arrays[ArrayType.ale_material_ids])
if ArrayType.ale_material_ids in self.d3plot.arrays
else 0
)
# NCFDV1
new_header["ncfdv1"] = 0
# NCFDV2
new_header["ncfdv2"] = 0
# NADAPT - number of adapted element to parent pairs ?!?
new_header["ncfdv2"] = 0
# NUMRBS (written to numbering header)
if ArrayType.rigid_body_coordinates in self.d3plot.arrays:
array = self.d3plot.arrays[ArrayType.rigid_body_coordinates]
if array.ndim != 3:
msg = "Array '{0}' was expected to have {1} dimensions ({2})."
raise ValueError(
msg.format(
ArrayType.rigid_wall_force,
3,
",".join(["n_timesteps", "n_rigid_bodies", "x_y_z"]),
)
)
new_header["numrbs"] = array.shape[1]
else:
new_header["numrbs"] = 0
# NMMAT - material count (very complicated stuff ...)
tmp_nmmat = (
new_header["nummat2"]
+ new_header["nummat4"]
+ new_header["nummat8"]
+ new_header["nummatt"]
+ new_header["numrbs"]
)
if (
ArrayType.part_ids in self.d3plot.arrays
or ArrayType.part_internal_energy in self.d3plot.arrays
or ArrayType.part_kinetic_energy in self.d3plot.arrays
or ArrayType.part_mass in self.d3plot.arrays
or ArrayType.part_velocity in self.d3plot.arrays
):
tmp_nmmat2 = self.d3plot.check_array_dims(
{
ArrayType.part_ids: 0,
ArrayType.part_internal_energy: 1,
ArrayType.part_kinetic_energy: 1,
ArrayType.part_mass: 1,
ArrayType.part_velocity: 1,
},
"n_parts",
)
new_header["nmmat"] = tmp_nmmat2
# FIX
# ...
if new_header["nmmat"] > tmp_nmmat:
new_header["numrbs"] = (
new_header["nmmat"]
- new_header["nummat2"]
- new_header["nummat4"]
- new_header["nummat8"]
- new_header["nummatt"]
)
else:
new_header["nmmat"] = tmp_nmmat
# NARBS - words for arbitrary numbering of everything
# requires nmmat thus it was placed here
new_header["narbs"] = (
new_header["numnp"]
+ new_header["nel8"]
+ new_header["nel2"]
+ new_header["nel4"]
+ new_header["nelth"]
+ 3 * new_header["nmmat"]
)
# narbs header data
if ArrayType.part_ids in self.d3plot.arrays:
new_header["narbs"] += 16
else:
new_header["narbs"] += 10
# NGLBV - number of global variables
n_rigid_wall_vars = 0
n_rigid_walls = 0
if ArrayType.rigid_wall_force in self.d3plot.arrays:
n_rigid_wall_vars = 1
array = self.d3plot.arrays[ArrayType.rigid_wall_force]
if array.ndim != 2:
msg = "Array '{0}' was expected to have {1} dimensions ({2})."
raise ValueError(
msg.format(
ArrayType.rigid_wall_force, 2, ",".join(["n_timesteps", "n_rigid_walls"])
)
)
n_rigid_walls = array.shape[1]
if ArrayType.rigid_wall_position in self.d3plot.arrays:
n_rigid_wall_vars = 4
array = self.d3plot.arrays[ArrayType.rigid_wall_position]
if array.ndim != 3:
msg = "Array '{0}' was expected to have {1} dimensions ({2})."
raise ValueError(
msg.format(
ArrayType.rigid_wall_position,
3,
",".join(["n_timesteps", "n_rigid_walls", "x_y_z"]),
)
)
n_rigid_walls = array.shape[1]
new_header["n_rigid_walls"] = n_rigid_walls
new_header["n_rigid_wall_vars"] = n_rigid_wall_vars
n_global_variables = 0
if ArrayType.global_kinetic_energy in self.d3plot.arrays:
n_global_variables = 1
if ArrayType.global_internal_energy in self.d3plot.arrays:
n_global_variables = 2
if ArrayType.global_total_energy in self.d3plot.arrays:
n_global_variables = 3
if ArrayType.global_velocity in self.d3plot.arrays:
n_global_variables = 6
if ArrayType.part_internal_energy in self.d3plot.arrays:
n_global_variables = 6 + 1 * new_header["nmmat"]
if ArrayType.part_kinetic_energy in self.d3plot.arrays:
n_global_variables = 6 + 2 * new_header["nmmat"]
if ArrayType.part_velocity in self.d3plot.arrays:
n_global_variables = 6 + 5 * new_header["nmmat"]
if ArrayType.part_mass in self.d3plot.arrays:
n_global_variables = 6 + 6 * new_header["nmmat"]
if ArrayType.part_hourglass_energy in self.d3plot.arrays:
n_global_variables = 6 + 7 * new_header["nmmat"]
if n_rigid_wall_vars * n_rigid_walls != 0:
n_global_variables = 6 + 7 * new_header["nmmat"] + n_rigid_wall_vars * n_rigid_walls
new_header["nglbv"] = n_global_variables
# NUMFLUID - total number of ALE fluid groups
new_header["numfluid"] = 0
# INN - Invariant node numbering fore shell and solid elements
if self.d3plot.header.has_invariant_numbering:
if "inn" in self.d3plot.header.raw_header and self.d3plot.header.raw_header["inn"] != 0:
new_header["inn"] = self.d3plot.header.raw_header["inn"]
else:
new_header["inn"] = int(self.d3plot.header.has_invariant_numbering)
else:
new_header["inn"] = 0
# NPEFG
airbag_arrays = [
ArrayType.airbags_first_particle_id,
ArrayType.airbags_n_particles,
ArrayType.airbags_ids,
ArrayType.airbags_n_gas_mixtures,
ArrayType.airbags_n_chambers,
ArrayType.airbag_n_active_particles,
ArrayType.airbag_bag_volume,
ArrayType.airbag_particle_gas_id,
ArrayType.airbag_particle_chamber_id,
ArrayType.airbag_particle_leakage,