QuickstartΒΆ

This example shows how to use structuralcodes to calculate the response of a rectangular reinforced concrete section. Follow the example step-by-step, or skip to the end if you are in a hurry.

Import relevant functions and classes:

from shapely import Polygon

from structuralcodes import set_design_code
from structuralcodes.geometry import SurfaceGeometry, add_reinforcement
from structuralcodes.materials.concrete import create_concrete
from structuralcodes.materials.reinforcement import create_reinforcement
from structuralcodes.sections import GenericSection

See also

Library structure.

Set the active design code to Eurocode 2, 2004 (ec2_2004):

# Set the active design code
set_design_code('ec2_2004')

Create a concrete and a reinforcement material:

# Create a concrete and a reinforcement
fck = 45
fyk = 500
ftk = 550
Es = 200000
epsuk = 0.07

# These factory functions create concrete and reinforcement materials according
# to the globally set design code
concrete = create_concrete(fck=fck)
reinforcement = create_reinforcement(fyk=fyk, Es=Es, ftk=ftk, epsuk=epsuk)

See also

Material reference.

The concrete factory create_concrete().

The reinforcement create_reinforcement().

Create a SurfaceGeometry based on a shapely.Polygon and the Concrete created with create_concrete():

# Create a rectangular geometry
width = 250
height = 500
polygon = Polygon(
    [
        (-width / 2, -height / 2),
        (width / 2, -height / 2),
        (width / 2, height / 2),
        (-width / 2, height / 2),
    ]
)  # We leverage shapely to create geometries
geometry = SurfaceGeometry(
    poly=polygon, material=concrete
)  # A SurfaceGeometry is a shapely Polygon with an assigned material

Add reinforcement to the geometry:

# Add reinforcement
diameter_reinf = 25
cover = 50

geometry = add_reinforcement(
    geometry,
    (
        -width / 2 + cover + diameter_reinf / 2,
        -height / 2 + cover + diameter_reinf / 2,
    ),
    diameter_reinf,
    reinforcement,
)  # The add_reinforcement function returns a CompoundGeometry
geometry = add_reinforcement(
    geometry,
    (
        width / 2 - cover - diameter_reinf / 2,
        -height / 2 + cover + diameter_reinf / 2,
    ),
    diameter_reinf,
    reinforcement,
)

Create a GenericSection based on the geometry:

# Create section
section = GenericSection(geometry)

Call the .calculate_moment_curvature() method on the GenericSectionCalculator to calculate the moment-curvature relation:

# Calculate the moment-curvature response
moment_curvature = section.section_calculator.calculate_moment_curvature()

Full example:

 1"""Quickstart example."""
 2
 3from shapely import Polygon
 4
 5from structuralcodes import set_design_code
 6from structuralcodes.geometry import SurfaceGeometry, add_reinforcement
 7from structuralcodes.materials.concrete import create_concrete
 8from structuralcodes.materials.reinforcement import create_reinforcement
 9from structuralcodes.sections import GenericSection
10
11# Set the active design code
12set_design_code('ec2_2004')
13
14# Create a concrete and a reinforcement
15fck = 45
16fyk = 500
17ftk = 550
18Es = 200000
19epsuk = 0.07
20
21# These factory functions create concrete and reinforcement materials according
22# to the globally set design code
23concrete = create_concrete(fck=fck)
24reinforcement = create_reinforcement(fyk=fyk, Es=Es, ftk=ftk, epsuk=epsuk)
25
26# Create a rectangular geometry
27width = 250
28height = 500
29polygon = Polygon(
30    [
31        (-width / 2, -height / 2),
32        (width / 2, -height / 2),
33        (width / 2, height / 2),
34        (-width / 2, height / 2),
35    ]
36)  # We leverage shapely to create geometries
37geometry = SurfaceGeometry(
38    poly=polygon, material=concrete
39)  # A SurfaceGeometry is a shapely Polygon with an assigned material
40
41# Add reinforcement
42diameter_reinf = 25
43cover = 50
44
45geometry = add_reinforcement(
46    geometry,
47    (
48        -width / 2 + cover + diameter_reinf / 2,
49        -height / 2 + cover + diameter_reinf / 2,
50    ),
51    diameter_reinf,
52    reinforcement,
53)  # The add_reinforcement function returns a CompoundGeometry
54geometry = add_reinforcement(
55    geometry,
56    (
57        width / 2 - cover - diameter_reinf / 2,
58        -height / 2 + cover + diameter_reinf / 2,
59    ),
60    diameter_reinf,
61    reinforcement,
62)
63
64# Create section
65section = GenericSection(geometry)
66
67# Calculate the moment-curvature response
68moment_curvature = section.section_calculator.calculate_moment_curvature()