Skip to content

bug: Changing the width of the quick start example throwing an exception #362

@Cobse

Description

@Cobse

Changing the width of the quick start example is causing the moment_curvature calculation to fail with the error underneath. AI suggest this is a refactoring issue in the library itself.

ERROR

'BeamSectionCalculator' object has no attribute 'triangulated_data'
  File "E:\Github\Python_Testing\structural_codes\quick_start.py", line 71, in <module>
    moment_curvature = section.section_calculator.calculate_moment_curvature()
AttributeError: 'BeamSectionCalculator' object has no attribute 'triangulated_data'

AI suggestion bug:

Root Cause

The structuralcodes library has an incomplete refactoring. In BeamSectionCalculator.__init__, the attribute was renamed:

# __init__ sets the NEW name:
self.integration_data = None   # renamed from triangulated_data

But one of the internal helper methods (_quick_exponential_find / _slow_linear_find inside _prefind_range_curvature_equilibrium) still uses the old name:

# Old code still present in the library:
self.integrator.integrate_strain_response_on_geometry(
    geom, [eps_0_b, curv, 0], tri=self.triangulated_data  # <-- AttributeError!
)

Why quick_start.py works but yours doesn't

The faulty code path (_prefind_range_curvature_equilibrium) is only triggered when the initial neutral axis guess has an axial force imbalance > 1e-2. In find_equilibrium_fixed_curvature:

if abs(dn_a) <= 1e-2:
    return [eps_0_a, curv, 0]   # quick_start.py exits here (small 250×500 section)
eps_0_b, dn_b = self._prefind_range_curvature_equilibrium(...)  # rectange_analysis.py hits this

The larger 1000×500 mm section produces a larger initial imbalance, pushing it past the 1e-2 threshold and into the buggy code path. The smaller 250×500 section stays within tolerance and exits early.

Example Code

"""Quickstart example."""

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 BeamSection

import matplotlib.pyplot as plt
import seaborn as sns

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

# 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)

# Create a rectangular geometry
width = 1000
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
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 section
section = BeamSection(geometry)

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions