@@ -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
0 commit comments