Skip to content

Commit 3a7eff8

Browse files
Add get_stress_at_points
1 parent faba5b7 commit 3a7eff8

File tree

1 file changed

+87
-1
lines changed

1 file changed

+87
-1
lines changed

sectionproperties/analysis/section.py

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import sectionproperties.analysis.solver as solver
2828
import sectionproperties.post.post as post
2929

30+
from shapely.geometry import asPoint, Polygon
31+
from shapely.strtree import STRtree
3032

3133
class Section:
3234
"""Class for structural cross-sections.
@@ -2129,7 +2131,7 @@ def get_sf_p(self):
21292131
def get_stress_at_point(
21302132
self, pt: List[float], N=0, Mxx=0, Myy=0, M11=0, M22=0, Mzz=0, Vx=0, Vy=0
21312133
) -> Tuple[float]:
2132-
"""Calaculates the stress at a point wiithin an element for given design actions
2134+
"""Calaculates the stress at a point within an element for given design actions
21332135
and returns *(sigma_zz, tau_xz, tau_yz)*
21342136
21352137
:param pt: The point. A list of the x and y coordinate
@@ -2196,6 +2198,90 @@ def get_stress_at_point(
21962198
return sigs
21972199

21982200

2201+
def get_stress_at_points(
2202+
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]]:
2204+
"""Calaculates the stress at a set of points within an element for given design actions
2205+
and returns *(sigma_zz, tau_xz, tau_yz)*
2206+
2207+
:param pts: The points. A list of several x and y coordinates
2208+
:type pts: list[list[float, float]]
2209+
:param float N: Axial force
2210+
:param float Vx: Shear force acting in the x-direction
2211+
:param float Vy: Shear force acting in the y-direction
2212+
:param float Mxx: Bending moment about the centroidal xx-axis
2213+
:param float Myy: Bending moment about the centroidal yy-axis
2214+
:param float M11: Bending moment about the centroidal 11-axis
2215+
:param float M22: Bending moment about the centroidal 22-axis
2216+
:param float Mzz: Torsion moment about the centroidal zz-axis
2217+
:return: Resultant normal and shear stresses list[(sigma_zz, tau_xz, tau_yz)]
2218+
:rtype: list[tuple(float, float, float)]
2219+
"""
2220+
2221+
action = {
2222+
"N": N,
2223+
"Mxx": Mxx,
2224+
"Myy": Myy,
2225+
"M11": M11,
2226+
"M22": M22,
2227+
"Mzz": Mzz,
2228+
"Vx": Vx,
2229+
"Vy": Vy,
2230+
}
2231+
2232+
sect_prop = {
2233+
"ea": self.section_props.ea,
2234+
"cx": self.section_props.cx,
2235+
"cy": self.section_props.cy,
2236+
"ixx": self.section_props.ixx_c,
2237+
"iyy": self.section_props.iyy_c,
2238+
"ixy": self.section_props.ixy_c,
2239+
"i11": self.section_props.i11_c,
2240+
"i22": self.section_props.i22_c,
2241+
"phi": self.section_props.phi,
2242+
"j": self.section_props.j,
2243+
"Delta_s": self.section_props.Delta_s,
2244+
"nu": self.section_props.nu_eff,
2245+
}
2246+
2247+
#create the search tree
2248+
p_mesh = [Polygon(self.geometry.mesh["vertices"][tri][0:3]) for tri in self.geometry.mesh["triangles"]]
2249+
s_tree = STRtree(p_mesh)
2250+
index_by_id = dict((id(poly), i) for i, poly in enumerate(p_mesh))
2251+
2252+
for pt in pts:
2253+
query_geom = asPoint(pt)
2254+
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:
2256+
tri = self.elements[tri_ids[0]]
2257+
sig = tri.local_element_stress(
2258+
p=pt,
2259+
**action,
2260+
**sect_prop,
2261+
omega=self.section_props.omega[tri.node_ids],
2262+
psi_shear=self.section_props.psi_shear[tri.node_ids],
2263+
phi_shear=self.section_props.phi_shear[tri.node_ids],
2264+
)
2265+
else:
2266+
sigs = []
2267+
for idx in tri_ids:
2268+
tri = self.elements[idx]
2269+
sigs.append(tri.local_element_stress(
2270+
p=pt,
2271+
**action,
2272+
**sect_prop,
2273+
omega=self.section_props.omega[tri.node_ids],
2274+
psi_shear=self.section_props.psi_shear[tri.node_ids],
2275+
phi_shear=self.section_props.phi_shear[tri.node_ids],
2276+
)
2277+
)
2278+
sig = (
2279+
agg_func([sig[0] for sig in sigs]),
2280+
agg_func([sig[1] for sig in sigs]),
2281+
agg_func([sig[2] for sig in sigs]),
2282+
)
2283+
yield sig
2284+
21992285
class PlasticSection:
22002286
"""Class for the plastic analysis of cross-sections.
22012287

0 commit comments

Comments
 (0)