Skip to content

Commit 965a3e9

Browse files
committed
fixes: CompositeGeometry had str in .geoms; stress_extractor now has keys to match plot stresses
1 parent 95ee710 commit 965a3e9

File tree

3 files changed

+302
-14
lines changed

3 files changed

+302
-14
lines changed

src/sectionproperties_tools/extraction.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,36 @@ def extract_properties(
7777
return props
7878

7979

80-
def envelope_stress_results(stress_post: StressPost) -> dict[str, dict]:
80+
def envelope_stress_results(stress_post: StressPost, single_material: bool = False) -> dict[str, dict]:
8181
"""
8282
Returns the envelope (min/max/absmax) of the stress results.
83+
84+
The names (keys) of the stress results are modified to match the names
85+
used in sectionproperties's stress plots. e.g. "sig_zz_mxx" becomes "mxx_zz".
86+
87+
If 'single_material' is True and the 'stress_post' object represents stresses
88+
that only occur in a single material, then the results will not be keyed by
89+
material name unnecessarily. If either is False, then the returned dict
90+
will be keyed by material.
8391
"""
84-
stress_results = stress_post.get_stress()[0]
85-
stress_results.pop("material")
92+
stress_results = stress_post.get_stress()
8693
stress_envelopes = {}
87-
for stress_dir_name, stress_array in stress_results.items():
88-
trimmed_stress_name = stress_dir_name.replace("sig_", "")
89-
stress_envelopes.setdefault(trimmed_stress_name, {})
90-
max_stress = np.max(stress_array)
91-
min_stress = np.min(stress_array)
92-
absmax_stress = np.max(np.abs(stress_array))
93-
stress_envelopes[trimmed_stress_name].update({"max": max_stress})
94-
stress_envelopes[trimmed_stress_name].update({"min": min_stress})
95-
stress_envelopes[trimmed_stress_name].update({"absmax": absmax_stress})
94+
nest_by_material = True
95+
if len(stress_results) == 1 and single_material:
96+
nest_by_material = False
97+
for material_stresses in stress_results:
98+
material_name = material_stresses.pop("material")
99+
stress_acc = stress_envelopes
100+
if nest_by_material:
101+
stress_envelopes.setdefault(material_name, {})
102+
stress_acc = stress_envelopes[material_name]
103+
for stress_dir_name, stress_array in material_stresses.items():
104+
trimmed_stress_name = "_".join(stress_dir_name.replace("sig_", "").split("_")[::-1])
105+
stress_acc.setdefault(trimmed_stress_name, {})
106+
max_stress = np.max(stress_array)
107+
min_stress = np.min(stress_array)
108+
absmax_stress = np.max(np.abs(stress_array))
109+
stress_acc[trimmed_stress_name].update({"max": max_stress})
110+
stress_acc[trimmed_stress_name].update({"min": min_stress})
111+
stress_acc[trimmed_stress_name].update({"absmax": absmax_stress})
96112
return stress_envelopes

src/sectionproperties_tools/serialize.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def to_sectionproperties(self):
221221
init_dict = self.to_init_dict()
222222
if "geoms" in init_dict:
223223
init_dict.update({"geoms": geom})
224+
# if "geom" in init_dict:
224225
new_inst = sec_prop_class(**init_dict)
225226

226227
for attr_name, attr_value in self:
@@ -231,6 +232,7 @@ def to_sectionproperties(self):
231232
attr_value['triangles'] = np.array(attr_value['triangles'])
232233
attr_value['triangle_attributes'] = np.array(attr_value['triangle_attributes'])
233234
setattr(new_inst, attr_name, attr_value)
235+
new_inst.geom = geom
234236
return new_inst
235237

236238

0 commit comments

Comments
 (0)