Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion structuralcodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from . import codes, core, geometry, materials, sections
from .codes import get_design_codes, set_design_code, set_national_annex
from .core.errors import StructuralCodesWarning
from .core.errors import InformationWarning, StructuralCodesWarning

__version__ = '0.6.4'

Expand All @@ -20,3 +20,4 @@
]

warnings.filterwarnings(action='error', category=StructuralCodesWarning)
warnings.filterwarnings(action='always', category=InformationWarning)
14 changes: 12 additions & 2 deletions structuralcodes/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ class StructuralCodesWarning(Warning):


class NoConvergenceWarning(StructuralCodesWarning):
"""A warning that indicates that no convergence was reached for an
iterative solver.
"""Warning for lack of convergence.

A warning that indicates that no convergence was reached for an
iterative solver. The solution should be inspected with care.
"""


class InformationWarning(StructuralCodesWarning):
"""Warning for simple information.

A warning that indicates that some information that should be taken care
by user, but the calculation is not invalid.
"""
9 changes: 5 additions & 4 deletions structuralcodes/sections/_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from structuralcodes.materials.basic import ElasticMaterial

from ..core.base import Section, SectionCalculator
from ..core.errors import NoConvergenceWarning
from ..core.errors import InformationWarning, NoConvergenceWarning
from .section_integrators import SectionIntegrator, integrator_factory


Expand Down Expand Up @@ -149,10 +149,11 @@ def _calculate_gross_section_properties(self) -> s_res.SectionProperties:
if isinstance(polygon, MultiPolygon):
gp.perimeter = 0.0
warnings.warn(
'Perimiter computation for a multi polygon is not defined.'
'Perimiter computation for a multi polygon is not defined.',
category=InformationWarning,
)

gp.perimeter = polygon.exterior.length
else:
gp.perimeter = polygon.exterior.length

# Computation of area: this is taken directly from shapely
gp.area = self.section.geometry.area
Expand Down
30 changes: 29 additions & 1 deletion tests/test_sections/test_generic_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
from shapely import Polygon

from structuralcodes.codes.ec2_2004 import reinforcement_duct_props
from structuralcodes.core.errors import NoConvergenceWarning
from structuralcodes.core.errors import (
InformationWarning,
NoConvergenceWarning,
)
from structuralcodes.geometry import (
CircularGeometry,
CompoundGeometry,
RectangularGeometry,
SurfaceGeometry,
add_reinforcement,
Expand Down Expand Up @@ -1993,3 +1997,27 @@ def test_section_mm_domain_warning(b, h, n_bars, diameter, fck, fyk):

# Check that the results arrays have the same size
assert len(res.m_y) == len(res_good.m_y)


def test_perimeter_multipolygon():
"""Test calculating the perimeter of a multipolygon.

This resoves issue #329.
"""
mat = ElasticMaterial(E=210000, density=7850)
rect1 = SurfaceGeometry(
poly=Polygon([(0, 0), (100, 0), (100, 10), (0, 10)]),
material=mat,
)
rect2 = SurfaceGeometry(
poly=Polygon([(0, 200), (100, 200), (100, 210), (0, 210)]),
material=mat,
)

compound = CompoundGeometry([rect1, rect2])
section = GenericSection(compound, integrator='marin')

with pytest.warns(InformationWarning):
gp = section.gross_properties

assert math.isclose(gp.perimeter, 0)
Loading