Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions src/sectionproperties_tools/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,36 @@ def extract_properties(
return props


def envelope_stress_results(stress_post: StressPost) -> dict[str, dict]:
def envelope_stress_results(stress_post: StressPost, single_material: bool = False) -> dict[str, dict]:
"""
Returns the envelope (min/max/absmax) of the stress results.

The names (keys) of the stress results are modified to match the names
used in sectionproperties's stress plots. e.g. "sig_zz_mxx" becomes "mxx_zz".

If 'single_material' is True and the 'stress_post' object represents stresses
that only occur in a single material, then the results will not be keyed by
material name unnecessarily. If either is False, then the returned dict
will be keyed by material.
"""
stress_results = stress_post.get_stress()[0]
stress_results.pop("material")
stress_results = stress_post.get_stress()
stress_envelopes = {}
for stress_dir_name, stress_array in stress_results.items():
trimmed_stress_name = stress_dir_name.replace("sig_", "")
stress_envelopes.setdefault(trimmed_stress_name, {})
max_stress = np.max(stress_array)
min_stress = np.min(stress_array)
absmax_stress = np.max(np.abs(stress_array))
stress_envelopes[trimmed_stress_name].update({"max": max_stress})
stress_envelopes[trimmed_stress_name].update({"min": min_stress})
stress_envelopes[trimmed_stress_name].update({"absmax": absmax_stress})
nest_by_material = True
if len(stress_results) == 1 and single_material:
nest_by_material = False
for material_stresses in stress_results:
material_name = material_stresses.pop("material")
stress_acc = stress_envelopes
if nest_by_material:
stress_envelopes.setdefault(material_name, {})
stress_acc = stress_envelopes[material_name]
for stress_dir_name, stress_array in material_stresses.items():
trimmed_stress_name = "_".join(stress_dir_name.replace("sig_", "").split("_")[::-1])
stress_acc.setdefault(trimmed_stress_name, {})
max_stress = np.max(stress_array)
min_stress = np.min(stress_array)
absmax_stress = np.max(np.abs(stress_array))
stress_acc[trimmed_stress_name].update({"max": max_stress})
stress_acc[trimmed_stress_name].update({"min": min_stress})
stress_acc[trimmed_stress_name].update({"absmax": absmax_stress})
return stress_envelopes
2 changes: 2 additions & 0 deletions src/sectionproperties_tools/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ def to_sectionproperties(self):
init_dict = self.to_init_dict()
if "geoms" in init_dict:
init_dict.update({"geoms": geom})
# if "geom" in init_dict:
new_inst = sec_prop_class(**init_dict)

for attr_name, attr_value in self:
Expand All @@ -231,6 +232,7 @@ def to_sectionproperties(self):
attr_value['triangles'] = np.array(attr_value['triangles'])
attr_value['triangle_attributes'] = np.array(attr_value['triangle_attributes'])
setattr(new_inst, attr_name, attr_value)
new_inst.geom = geom
return new_inst


Expand Down
Loading