Skip to content

Commit 19f570d

Browse files
committed
Write tests for concrete_column_section and add_bar
1 parent a3bc438 commit 19f570d

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

sectionproperties/tests/test_concrete_sections.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import numpy as np
33
import sectionproperties.pre.pre as pre
44
import sectionproperties.pre.library.concrete_sections as cs
5+
import sectionproperties.pre.library.primitive_sections as ps
56

67
r_tol = 1e-6
78
conc_mat = pre.Material(
@@ -135,3 +136,78 @@ def test_concrete_circular_section():
135136
# check areas
136137
check.almost_equal(conc_area, net_area - actual_steel_area, rel=r_tol)
137138
check.almost_equal(steel_area, actual_steel_area, rel=r_tol)
139+
140+
141+
def test_concrete_column_section():
142+
143+
concrete = pre.Material(
144+
name='Concrete', elastic_modulus=30.1e3, poissons_ratio=0.2, yield_strength=32,
145+
density=2.4e-6, color='lightgrey'
146+
)
147+
steel = pre.Material(
148+
name='Steel', elastic_modulus=200e3, poissons_ratio=0.3, yield_strength=500,
149+
density=7.85e-6, color='grey'
150+
)
151+
152+
geometry = cs.concrete_column_section(
153+
b=300, d=600, dia_bar=40, bar_area=500, cover=40, n_bars_b=3, n_bars_d=6,
154+
conc_mat=concrete, steel_mat=steel, filled=False, n_circle=4
155+
) # NOTE: Bar diam and Bar area do not match. This is intentional.
156+
geometry.create_mesh(mesh_sizes=[500])
157+
158+
# check geometry is created correctly
159+
conc_area = 0
160+
steel_area = 0
161+
162+
for geom in geometry.geoms:
163+
if geom.material == concrete:
164+
conc_area += geom.calculate_area()
165+
elif geom.material == steel:
166+
steel_area += geom.calculate_area()
167+
else:
168+
raise ValueError(
169+
"Material {0} is not correctly assigned".format(geom.material)
170+
)
171+
172+
net_area = 300 * 600
173+
actual_steel_area = 14 * 500.
174+
175+
check.almost_equal(conc_area, net_area - actual_steel_area, rel=r_tol)
176+
check.almost_equal(steel_area, actual_steel_area, rel=r_tol)
177+
178+
bar_centroids = [tuple(geom.geom.centroid.coords[0]) for geom in geometry.geoms[1:]]
179+
180+
from collections import Counter
181+
x_coords = Counter(round(coord[0], 0) for coord in bar_centroids)
182+
y_coords = Counter(round(coord[1], 0) for coord in bar_centroids)
183+
184+
# Validate that we have 14 bars with the correct x-coordinates
185+
check.equal(x_coords.get(60) , 6)
186+
check.equal(x_coords.get(150), 2)
187+
check.equal(x_coords.get(240), 6)
188+
189+
# Validate that we have 14 bars with the correct y-coordinates
190+
check.equal(y_coords.get(60) , 3)
191+
check.equal(y_coords.get(156), 2)
192+
check.equal(y_coords.get(252), 2)
193+
check.equal(y_coords.get(348), 2)
194+
check.equal(y_coords.get(444), 2)
195+
check.equal(y_coords.get(540), 3)
196+
197+
198+
def test_add_bar():
199+
rect = ps.rectangular_section(b=400, d=600)
200+
steel = pre.Material(
201+
name='Steel', elastic_modulus=200e3, poissons_ratio=0.3, yield_strength=500,
202+
density=7.85e-6, color='grey'
203+
)
204+
rect = cs.add_bar(rect, area=500, x=100, y=100, material=steel)
205+
rect = cs.add_bar(rect, area=500, x=200, y=200, material=steel)
206+
rect_area = rect.geoms[0].geom.area
207+
steel_area = 2 * 500.
208+
check.almost_equal(rect_area, 400*600 - steel_area)
209+
210+
bar_1 = rect.geoms[1]
211+
bar_2 = rect.geoms[2]
212+
check.almost_equal(bar_1.calculate_centroid(), (100, 100))
213+
check.almost_equal(bar_2.calculate_centroid(), (200, 200))

0 commit comments

Comments
 (0)