From d208a5d5c830e3b8d4e91dc30bc69c1e6131c118 Mon Sep 17 00:00:00 2001 From: Norman JN Richardson Date: Mon, 2 Jan 2023 14:56:44 -0800 Subject: [PATCH 1/2] Add unit tests for stress at points --- sectionproperties/tests/test_stress.py | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/sectionproperties/tests/test_stress.py b/sectionproperties/tests/test_stress.py index 9d593974..b17d76e5 100644 --- a/sectionproperties/tests/test_stress.py +++ b/sectionproperties/tests/test_stress.py @@ -1,4 +1,5 @@ import pytest +import math import sectionproperties.pre.library.primitive_sections as primitive_sections from sectionproperties.analysis.section import Section @@ -48,3 +49,37 @@ def test_stress_runtime_errors(): sec.calculate_stress(Vy=1) sec.calculate_stress(Mzz=1) sec.get_stress_at_points(pts=[[10, 10]], Mzz=1) + + +def test_rectangle(): + Mxx = 7 + Sy = 50.0 * 100.0**2 / 6.0 + sig_max = Mxx / Sy + (sig_0, sig_1, sig_2) = sec.get_stress_at_points( + pts=[[25, 50], [25, 75], [25, 100]], Mxx=Mxx + ) + assert sig_0 == pytest.approx((0, 0, 0)) + assert sig_1 == pytest.approx((sig_max / 2.0, 0, 0)) + assert sig_2 == pytest.approx((sig_max, 0, 0)) + + +def test_rotated_rectangle(): + b = 50 + d = 100 + angle = math.atan(100 / 50) + rot_rect = ( + primitive_sections.rectangular_section(b=b, d=d) + .shift_section(-b / 2, -d / 2) + .rotate_section(angle, use_radians=True) + ) + rot_rect.create_mesh(mesh_sizes=0) # coarse mesh + rot_sec = Section(rot_rect) + rot_sec.calculate_geometric_properties() + rot_sec.calculate_warping_properties() + Mxx = 7 + cx = b / 2 * math.cos(angle) - d / 2 * math.sin(angle) + cy = b / 2 * math.sin(angle) + d / 2 * math.cos(angle) + Sy = b * d / 6.0 * cy + sig_max = Mxx / Sy + (sig_0, sig_1) = rot_sec.get_stress_at_points(pts=[[cx, 0], [cx, cy]], Mxx=Mxx) + assert sig_1 == pytest.approx((sig_max, 0, 0)) From 777ba323ce796ef0523d2000c10c2a5b71d45d6a Mon Sep 17 00:00:00 2001 From: Norman JN Richardson Date: Mon, 2 Jan 2023 15:18:24 -0800 Subject: [PATCH 2/2] Reorder calculations --- sectionproperties/tests/test_stress.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sectionproperties/tests/test_stress.py b/sectionproperties/tests/test_stress.py index b17d76e5..06957961 100644 --- a/sectionproperties/tests/test_stress.py +++ b/sectionproperties/tests/test_stress.py @@ -67,6 +67,11 @@ def test_rotated_rectangle(): b = 50 d = 100 angle = math.atan(100 / 50) + cx = b / 2 * math.cos(angle) - d / 2 * math.sin(angle) + cy = b / 2 * math.sin(angle) + d / 2 * math.cos(angle) + Sy = b * d / 6.0 * cy + Mxx = 7 + sig_max = Mxx / Sy rot_rect = ( primitive_sections.rectangular_section(b=b, d=d) .shift_section(-b / 2, -d / 2) @@ -76,10 +81,5 @@ def test_rotated_rectangle(): rot_sec = Section(rot_rect) rot_sec.calculate_geometric_properties() rot_sec.calculate_warping_properties() - Mxx = 7 - cx = b / 2 * math.cos(angle) - d / 2 * math.sin(angle) - cy = b / 2 * math.sin(angle) + d / 2 * math.cos(angle) - Sy = b * d / 6.0 * cy - sig_max = Mxx / Sy (sig_0, sig_1) = rot_sec.get_stress_at_points(pts=[[cx, 0], [cx, cy]], Mxx=Mxx) assert sig_1 == pytest.approx((sig_max, 0, 0))