Skip to content

Commit bfc132e

Browse files
committed
fix: Correctly read SPH data
Reshapes complete SPH data array to allow for correct indexing. To deal with old and new database versions, which may or may not include strain rate, flags for strain and strain rate were separated, as `isphfg(9)` can be 6 or 12.
1 parent 25effb6 commit bfc132e

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

src/lasso/dyna/d3plot.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,8 @@ class SphSectionInfo:
12851285
has_material_density: bool = False
12861286
has_internal_energy: bool = False
12871287
has_n_affecting_neighbors: bool = False
1288-
has_strain_and_strainrate: bool = False
1288+
has_strain: bool = False
1289+
has_strainrate: bool = False
12891290
has_true_strains: bool = False
12901291
has_mass: bool = False
12911292
n_sph_history_vars: int = 0
@@ -2193,7 +2194,8 @@ def _read_sph_element_data_flags(self):
21932194
self._sph_info.has_material_density = sph_header_data["isphfg6"] != 0
21942195
self._sph_info.has_internal_energy = sph_header_data["isphfg7"] != 0
21952196
self._sph_info.has_n_affecting_neighbors = sph_header_data["isphfg8"] != 0
2196-
self._sph_info.has_strain_and_strainrate = sph_header_data["isphfg9"] != 0
2197+
self._sph_info.has_strain = sph_header_data["isphfg9"] != 0
2198+
self._sph_info.has_strainrate = sph_header_data["isphfg9"] > 6
21972199
self._sph_info.has_true_strains = sph_header_data["isphfg9"] < 0
21982200
self._sph_info.has_mass = sph_header_data["isphfg10"] != 0
21992201
self._sph_info.n_sph_history_vars = sph_header_data["isphfg11"]
@@ -5082,13 +5084,17 @@ def _read_states_sph(self, state_data: np.ndarray, var_index: int, array_dict: d
50825084

50835085
# extract data
50845086
try:
5085-
sph_data = state_data[:, var_index : var_index + n_particles * n_variables]
5087+
sph_data = state_data[:, var_index : var_index + n_particles * n_variables].reshape((
5088+
n_states,
5089+
n_particles,
5090+
n_variables,
5091+
))
50865092

50875093
i_var = 1
50885094

50895095
# deletion
50905096
try:
5091-
array_dict[ArrayType.sph_deletion] = sph_data[:, 0] < 0
5097+
array_dict[ArrayType.sph_deletion] = sph_data[:, :, 0] < 0
50925098
except Exception:
50935099
trb_msg = traceback.format_exc()
50945100
msg = "A failure in %s was caught:\n%s"
@@ -5097,7 +5103,7 @@ def _read_states_sph(self, state_data: np.ndarray, var_index: int, array_dict: d
50975103
# particle radius
50985104
if info.has_influence_radius:
50995105
try:
5100-
array_dict[ArrayType.sph_radius] = sph_data[:, i_var]
5106+
array_dict[ArrayType.sph_radius] = sph_data[:, :, i_var]
51015107
except Exception:
51025108
trb_msg = traceback.format_exc()
51035109
msg = "A failure in %s was caught:\n%s"
@@ -5108,7 +5114,7 @@ def _read_states_sph(self, state_data: np.ndarray, var_index: int, array_dict: d
51085114
# pressure
51095115
if info.has_particle_pressure:
51105116
try:
5111-
array_dict[ArrayType.sph_pressure] = sph_data[:, i_var]
5117+
array_dict[ArrayType.sph_pressure] = sph_data[:, :, i_var]
51125118
except Exception:
51135119
trb_msg = traceback.format_exc()
51145120
msg = "A failure in %s was caught:\n%s"
@@ -5119,20 +5125,18 @@ def _read_states_sph(self, state_data: np.ndarray, var_index: int, array_dict: d
51195125
# stress
51205126
if info.has_stresses:
51215127
try:
5122-
array_dict[ArrayType.sph_stress] = sph_data[
5123-
:, i_var : i_var + n_particles * 6
5124-
].reshape((n_states, n_particles, 6))
5128+
array_dict[ArrayType.sph_stress] = sph_data[:, :, i_var : i_var + 6]
51255129
except Exception:
51265130
trb_msg = traceback.format_exc()
51275131
msg = "A failure in %s was caught:\n%s"
51285132
LOGGER.warning(msg, "_read_states_sph, pressure", trb_msg)
51295133
finally:
5130-
i_var += 6 * n_particles
5134+
i_var += 6
51315135

51325136
# eff. plastic strain
51335137
if info.has_plastic_strain:
51345138
try:
5135-
array_dict[ArrayType.sph_effective_plastic_strain] = sph_data[:, i_var]
5139+
array_dict[ArrayType.sph_effective_plastic_strain] = sph_data[:, :, i_var]
51365140
except Exception:
51375141
trb_msg = traceback.format_exc()
51385142
msg = "A failure in %s was caught:\n%s"
@@ -5143,7 +5147,7 @@ def _read_states_sph(self, state_data: np.ndarray, var_index: int, array_dict: d
51435147
# density
51445148
if info.has_material_density:
51455149
try:
5146-
array_dict[ArrayType.sph_density] = sph_data[:, i_var]
5150+
array_dict[ArrayType.sph_density] = sph_data[:, :, i_var]
51475151
except Exception:
51485152
trb_msg = traceback.format_exc()
51495153
msg = "A failure in %s was caught:\n%s"
@@ -5154,7 +5158,7 @@ def _read_states_sph(self, state_data: np.ndarray, var_index: int, array_dict: d
51545158
# internal energy
51555159
if info.has_internal_energy:
51565160
try:
5157-
array_dict[ArrayType.sph_internal_energy] = sph_data[:, i_var]
5161+
array_dict[ArrayType.sph_internal_energy] = sph_data[:, :, i_var]
51585162
except Exception:
51595163
trb_msg = traceback.format_exc()
51605164
msg = "A failure in %s was caught:\n%s"
@@ -5165,42 +5169,39 @@ def _read_states_sph(self, state_data: np.ndarray, var_index: int, array_dict: d
51655169
# number of neighbors
51665170
if info.has_n_affecting_neighbors:
51675171
try:
5168-
array_dict[ArrayType.sph_n_neighbors] = sph_data[:, i_var]
5172+
array_dict[ArrayType.sph_n_neighbors] = sph_data[:, :, i_var]
51695173
except Exception:
51705174
trb_msg = traceback.format_exc()
51715175
msg = "A failure in %s was caught:\n%s"
51725176
LOGGER.warning(msg, "_read_states_sph, n_neighbors", trb_msg)
51735177
finally:
51745178
i_var += 1
51755179

5176-
# strain and strainrate
5177-
if info.has_strain_and_strainrate:
5180+
# strain
5181+
if info.has_strain:
51785182
try:
5179-
array_dict[ArrayType.sph_strain] = sph_data[
5180-
:, i_var : i_var + n_particles * 6
5181-
].reshape((n_states, n_particles, 6))
5183+
array_dict[ArrayType.sph_strain] = sph_data[:, :, i_var : i_var + 6]
51825184
except Exception:
51835185
trb_msg = traceback.format_exc()
51845186
msg = "A failure in %s was caught:\n%s"
51855187
LOGGER.warning(msg, "_read_states_sph, strain", trb_msg)
51865188
finally:
5187-
i_var += 6 * n_particles
5189+
i_var += 6
51885190

5191+
if info.has_strainrate:
51895192
try:
5190-
array_dict[ArrayType.sph_strainrate] = sph_data[
5191-
:, i_var : i_var + n_particles * 6
5192-
].reshape((n_states, n_particles, 6))
5193+
array_dict[ArrayType.sph_strainrate] = sph_data[:, :, i_var : i_var + 6]
51935194
except Exception:
51945195
trb_msg = traceback.format_exc()
51955196
msg = "A failure in %s was caught:\n%s"
51965197
LOGGER.warning(msg, "_read_states_sph, strainrate", trb_msg)
51975198
finally:
5198-
i_var += 6 * n_particles
5199+
i_var += 6
51995200

52005201
# mass
52015202
if info.has_mass:
52025203
try:
5203-
array_dict[ArrayType.sph_mass] = sph_data[:, i_var]
5204+
array_dict[ArrayType.sph_mass] = sph_data[:, :, i_var]
52045205
except Exception:
52055206
trb_msg = traceback.format_exc()
52065207
msg = "A failure in %s was caught:\n%s"

0 commit comments

Comments
 (0)