Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Formula 5.16 from NEN-EN 1992-1-1+C2:2011: Chapter 5 - Structural Analysis #328

Merged
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Formula 5.17 from NEN-EN 1992-1-1+C2:2011: Chapter 5 - Structural Analysis."""

import math

from blueprints.codes.eurocode.nen_en_1992_1_1_c2_2011 import NEN_EN_1992_1_1_C2_2011
from blueprints.codes.formula import Formula
from blueprints.codes.latex_formula import LatexFormula
from blueprints.type_alias import KN, KN_M2, M
from blueprints.validations import raise_if_less_or_equal_to_zero, raise_if_negative


class Form5Dot17EffectiveLengthBucklingLoad(Formula):
"""Class representing formula 5.17 for the calculation of effective length of unbraced members, in the
case where criteria (2) and (3) do not apply such as by variable loading, :math:`l_0`.
"""

label = "5.17"
source_document = NEN_EN_1992_1_1_C2_2011

def __init__(self, ei: KN_M2, n_b: KN) -> None:
"""[:math:`l_{0}`] Effective length for unbraced members [:math:`m`].

NEN-EN 1992-1-1+C2:2011 art.5.8.3.2(6) - Formula (5.17)

Parameters
----------
ei : DIMENSIONLESS
[:math:`EI`] is a representative bending stiffness [:math:`-`].
RamiEvans marked this conversation as resolved.
Show resolved Hide resolved
n_b : DIMENSIONLESS
[:math:`N_{b}`] is the buckling load expressed in terms of EI (in equation (5.14) i should correspond
to this EI). [:math:`-`].
RamiEvans marked this conversation as resolved.
Show resolved Hide resolved
"""
super().__init__()
self.ei = ei
self.n_b = n_b

@staticmethod
def _evaluate(ei: KN_M2, n_b: KN) -> M:
"""Evaluates the formula, for more information see the __init__ method."""
raise_if_negative(ei=ei, n_b=n_b)
raise_if_less_or_equal_to_zero(n_b=n_b)
return math.pi * math.sqrt(ei / n_b)

def latex(self) -> LatexFormula:
"""Returns LatexFormula object for formula 5.17."""
return LatexFormula(
return_symbol=r"l_0",
result=f"{self:.3f}",
equation=r"\pi \cdot \sqrt{\frac{EI}{N_{b}}}",
numeric_equation=rf"\pi \cdot \sqrt{{\frac{{{self.ei}}}{{{self.n_b}}}}}",
comparison_operator_label="=",
)
5 changes: 5 additions & 0 deletions blueprints/type_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
M4 = float
# </editor-fold>

# <editor-fold desc="COMPOUNDS">
N_M2 = float
KN_M2 = float
# </editor-fold>

# <editor-fold desc="TIME">
HOURS = float
MINUTES = float
Expand Down
2 changes: 1 addition & 1 deletion docs/source/codes/eurocode/ec2_1992_1_1_2011/formulas.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Total of 304 formulas present.
| 5.14 | :heavy_check_mark: | | Form5Dot14SlendernessRatio |
| 5.15 | :heavy_check_mark: | | Form5Dot15EffectiveLengthBraced |
| 5.16 | :heavy_check_mark: | | Form5Dot16EffectiveLengthUnbraced |
| 5.17 | :x: | | |
| 5.17 | :heavy_check_mark: | | Form5Dot17EffectiveLengthBucklingLoad |
| 5.18 | :x: | | |
| 5.19 | :x: | | |
| 5.20 | :x: | | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Testing formula 5.16 of NEN-EN 1992-1-1+C2:2011."""
RamiEvans marked this conversation as resolved.
Show resolved Hide resolved

import pytest

from blueprints.codes.eurocode.nen_en_1992_1_1_c2_2011.chapter_5_structural_analysis.formula_5_17 import Form5Dot17EffectiveLengthBucklingLoad
from blueprints.validations import LessOrEqualToZeroError, NegativeValueError


class TestForm5Dot16EffectiveLengthUnbraced:
RamiEvans marked this conversation as resolved.
Show resolved Hide resolved
"""Validation for formula 5.17 from NEN-EN 1992-1-1+C2:2011."""

@pytest.fixture()
def form_5_17(self) -> Form5Dot17EffectiveLengthBucklingLoad:
"""Setup and teardown for test."""
return Form5Dot17EffectiveLengthBucklingLoad(ei=1_000_000, n_b=5)

def test_evaluation(self, form_5_17: Form5Dot17EffectiveLengthBucklingLoad) -> None:
"""Test the evaluation of the result."""
# Expected result, manually calculated
manually_calculated_result = 1404.96 # M
assert form_5_17 == pytest.approx(expected=manually_calculated_result, rel=1e-4)

@pytest.mark.parametrize(
("ei", "n_b"),
[
(-1_000_000, 5),
(1_000_000, -5),
(-1_000_000, -5),
],
)
def test_raise_error_when_zero_pars_are_given(self, ei: float, n_b: float) -> None:
"""Test zero values for ei, n_b."""
with pytest.raises(NegativeValueError):
Form5Dot17EffectiveLengthBucklingLoad(ei=ei, n_b=n_b)

def test_raise_error_when_negative_pars_are_given(self) -> None:
"""Test negative values for ei, n_b."""
ei = 1_000_000
n_b = 0
with pytest.raises(LessOrEqualToZeroError):
Form5Dot17EffectiveLengthBucklingLoad(ei=ei, n_b=n_b)

@pytest.mark.parametrize(
("representation", "expected"),
[
(
"complete",
r"l_0 = \pi \cdot \sqrt{\frac{EI}{N_{b}}} = \pi \cdot \sqrt{\frac{1000000}{5}} = 1404.963",
RamiEvans marked this conversation as resolved.
Show resolved Hide resolved
),
("short", r"l_0 = 1404.963"),
],
)
def test_latex(self, form_5_17: Form5Dot17EffectiveLengthBucklingLoad, representation: str, expected: str) -> None:
"""Test the latex representation of the formula."""
# Object to test
form_5_17_latex = form_5_17.latex()
actual = {"complete": form_5_17_latex.complete, "short": form_5_17_latex.short}

assert actual[representation] == expected, f"{representation} representation failed."