Skip to content

Commit ffa69b5

Browse files
Refactor get_stress_at_point + add docstrings
1 parent 3a7eff8 commit ffa69b5

File tree

1 file changed

+17
-52
lines changed

1 file changed

+17
-52
lines changed

sectionproperties/analysis/section.py

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@ def get_sf_p(self):
21292129
)
21302130

21312131
def get_stress_at_point(
2132-
self, pt: List[float], N=0, Mxx=0, Myy=0, M11=0, M22=0, Mzz=0, Vx=0, Vy=0
2132+
self, pt: List[float], N=0, Mxx=0, Myy=0, M11=0, M22=0, Mzz=0, Vx=0, Vy=0, agg_func=np.average
21332133
) -> Tuple[float]:
21342134
"""Calaculates the stress at a point within an element for given design actions
21352135
and returns *(sigma_zz, tau_xz, tau_yz)*
@@ -2144,63 +2144,21 @@ def get_stress_at_point(
21442144
:param float M11: Bending moment about the centroidal 11-axis
21452145
:param float M22: Bending moment about the centroidal 22-axis
21462146
:param float Mzz: Torsion moment about the centroidal zz-axis
2147+
:param agg_function: A function that aggregates the stresses if the point is shared by several elements.
2148+
If the point, pt, is shared by several elements (e.g. if it is a node or on an edge), the stress
2149+
(sigma_zz, tau_xz, tau_yz) are retrieved from each element and combined according to this function.
2150+
By default, `numpy.average` is used.
2151+
:type agg_function: function, optional
21472152
:return: Resultant normal and shear stresses (sigma_zz, tau_xz, tau_yz)
21482153
:rtype: tuple(float, float, float)
21492154
"""
2150-
2151-
action = {
2152-
"N": N,
2153-
"Mxx": Mxx,
2154-
"Myy": Myy,
2155-
"M11": M11,
2156-
"M22": M22,
2157-
"Mzz": Mzz,
2158-
"Vx": Vx,
2159-
"Vy": Vy,
2160-
}
2161-
2162-
sect_prop = {
2163-
"ea": self.section_props.ea,
2164-
"cx": self.section_props.cx,
2165-
"cy": self.section_props.cy,
2166-
"ixx": self.section_props.ixx_c,
2167-
"iyy": self.section_props.iyy_c,
2168-
"ixy": self.section_props.ixy_c,
2169-
"i11": self.section_props.i11_c,
2170-
"i22": self.section_props.i22_c,
2171-
"phi": self.section_props.phi,
2172-
"j": self.section_props.j,
2173-
"Delta_s": self.section_props.Delta_s,
2174-
"nu": self.section_props.nu_eff,
2175-
}
2176-
2177-
# find the Tri6 element containing the point
2178-
tri_id = None
2179-
for (idx, tri) in enumerate(self.elements):
2180-
if tri.point_within_element(pt):
2181-
tri_id = idx
2182-
2183-
if tri_id is None:
2184-
raise ValueError(f"The point {pt} is outside of the section boundary.")
2185-
2186-
tri = self.elements[tri_id]
2187-
2188-
# get the stess at the point
2189-
sigs = tri.local_element_stress(
2190-
p=pt,
2191-
**action,
2192-
**sect_prop,
2193-
omega=self.section_props.omega[tri.node_ids],
2194-
psi_shear=self.section_props.psi_shear[tri.node_ids],
2195-
phi_shear=self.section_props.phi_shear[tri.node_ids],
2196-
)
2197-
2198-
return sigs
2155+
sigs = self.get_stress_at_points([pt], N, Mxx, Myy, M11, M22, Mzz, Vx, Vy, agg_func)
2156+
return next(sigs)
21992157

22002158

22012159
def get_stress_at_points(
22022160
self, pts: List[List[float]], N=0, Mxx=0, Myy=0, M11=0, M22=0, Mzz=0, Vx=0, Vy=0, agg_func=np.average
2203-
) -> List[Tuple[float]]:
2161+
) -> List[Tuple]:
22042162
"""Calaculates the stress at a set of points within an element for given design actions
22052163
and returns *(sigma_zz, tau_xz, tau_yz)*
22062164
@@ -2214,6 +2172,11 @@ def get_stress_at_points(
22142172
:param float M11: Bending moment about the centroidal 11-axis
22152173
:param float M22: Bending moment about the centroidal 22-axis
22162174
:param float Mzz: Torsion moment about the centroidal zz-axis
2175+
:param agg_function: A function that aggregates the stresses if the point is shared by several elements.
2176+
If the point, pt, is shared by several elements (e.g. if it is a node or on an edge), the stress
2177+
(sigma_zz, tau_xz, tau_yz) are retrieved from each element and combined according to this function.
2178+
By default, `numpy.average` is used.
2179+
:type agg_function: function, optional
22172180
:return: Resultant normal and shear stresses list[(sigma_zz, tau_xz, tau_yz)]
22182181
:rtype: list[tuple(float, float, float)]
22192182
"""
@@ -2252,7 +2215,9 @@ def get_stress_at_points(
22522215
for pt in pts:
22532216
query_geom = asPoint(pt)
22542217
tri_ids = [index_by_id[id(poly)] for poly in s_tree.query(query_geom) if poly.intersects(query_geom)]
2255-
if len(tri_ids)==1:
2218+
if len(tri_ids) ==0:
2219+
sig = None
2220+
elif len(tri_ids)==1:
22562221
tri = self.elements[tri_ids[0]]
22572222
sig = tri.local_element_stress(
22582223
p=pt,

0 commit comments

Comments
 (0)