Skip to content

Commit

Permalink
Merge pull request #216 from Blueprints-org/159-feature-request-add-f…
Browse files Browse the repository at this point in the history
…ormula-58-from-nen_en_1992_1_1_c2_2011

159 feature request add formula 58 from nen en 1992 1 1 c2 2011
  • Loading branch information
egarciamendez authored Apr 8, 2024
2 parents ba31b70 + b59a829 commit f39b270
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""Formula 5.8 from NEN-EN 1992-1-1+C2:2011: Chapter 5 - Structural Analysis."""

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 M
from blueprints.validations import raise_if_negative


class Form5Dot8EffectiveSpan(Formula):
"""Class representing formula 5.8 for calculating the effective span of beams and slabs, :math:`l_{eff}`.
See Figure 5.4
"""

label = "5.8"
source_document = NEN_EN_1992_1_1_C2_2011

def __init__(
self,
l_n: M,
a_1: M,
a_2: M,
) -> None:
"""[:math:`l_{eff}`] the effective span of a member [:math:`m`].
NEN-EN 1992-1-1+C2:2011 art.5.3.2.2(1) - Formula (5.8)
Parameters
----------
l_n : M
[:math:`l_{n}`] clear distance between the faces of the supports [:math:`m`].
a_1 : M
[:math:`a_{1}`] values for :math:`a_{1}` and :math:`a_{2}` at each end of the span, may be determined from the appropriate :math:`a_{i}`
values in Figure 5.4 where t is the width of the supporting element as shown. [:math:`m`].
a_2 : M
[:math:`a_{2}`] values for :math:`a_{1}` and :math:`a_{2}` at each end of the span, may be determined from the appropriate :math:`a_{i}`
values in Figure 5.4 where t is the width of the supporting element as shown. [:math:`m`].
"""
super().__init__()
self.l_n = l_n
self.a_1 = a_1
self.a_2 = a_2

@staticmethod
def _evaluate(
l_n: M,
a_1: M,
a_2: M,
) -> M:
"""Evaluates the formula, for more information see the __init__ method."""
raise_if_negative(
l_n=l_n,
a_1=a_1,
a_2=a_2,
)
return l_n + a_1 + a_2

def latex(self) -> LatexFormula:
"""Returns LatexFormula object for formula 5.8."""
return LatexFormula(
return_symbol=r"l_{eff}",
result=f"{self:.3f}",
equation=r"l_{n} + a_{1} + a_{2}",
numeric_equation=f"{self.l_n:.3f} + {self.a_1:.3f} + {self.a_2:.3f}",
comparison_operator_label="=",
)
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 @@ -53,7 +53,7 @@ Total of 304 formulas present.
| 5.7 | :x: | | |
| 5.7a | :x: | | |
| 5.7b | :x: | | |
| 5.8 | :x: | | |
| 5.8 | :heavy_check_mark: | | Form5Dot8EffectiveSpan |
| 5.9 | :x: | | |
| 5.10a | :x: | | |
| 5.10b | :x: | | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_evaluation(self) -> None:
(-0.003, -5),
],
)
def test_raise_error_when_negative_theta_i_is_given(self, theta_i: float, n_axial_force: float) -> None:
def test_raise_error_when_negative_values_are_given(self, theta_i: float, n_axial_force: float) -> None:
"""Test negative values."""
with pytest.raises(NegativeValueError):
Form5Dot3bTransverseForceBracedMembers(theta_i=theta_i, n_axial_force=n_axial_force)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""Testing formula 5.8 of NEN-EN 1992-1-1+C2:2011."""

import pytest

from blueprints.codes.eurocode.nen_en_1992_1_1_c2_2011.chapter_5_structural_analysis.formula_5_8 import Form5Dot8EffectiveSpan
from blueprints.validations import NegativeValueError


class TestForm5Dot8EffectiveSpan:
"""Validation for formula 5.8 from NEN-EN 1992-1-1+C2:2011."""

def test_evaluation(self) -> None:
"""Test the evaluation of the result."""
# Example values
l_n = 5 # m
a_1 = 0.5 # m
a_2 = 0.35 # m

# Object to test
form_5_8 = Form5Dot8EffectiveSpan(l_n=l_n, a_1=a_1, a_2=a_2)

# Expected result, manually calculated
manually_calculated_result = 5.85 # kN

assert form_5_8 == pytest.approx(expected=manually_calculated_result, rel=1e-4)

@pytest.mark.parametrize(
("l_n", "a_1", "a_2"),
[
(-5, 0.5, 0.35),
(5, -0.5, 0.35),
(5, 0.5, -0.35),
],
)
def test_raise_error_when_negative_values_are_given(self, l_n: float, a_1: float, a_2: float) -> None:
"""Test negative values."""
with pytest.raises(NegativeValueError):
Form5Dot8EffectiveSpan(l_n=l_n, a_1=a_1, a_2=a_2)

@pytest.mark.parametrize(
("representation", "expected"),
[
(
"complete",
r"l_{eff} = l_{n} + a_{1} + a_{2} = 5.000 + 0.500 + 0.350 = 5.850",
),
("short", r"l_{eff} = 5.850"),
(
"string",
r"l_{eff} = l_{n} + a_{1} + a_{2} = 5.000 + 0.500 + 0.350 = 5.850",
),
],
)
def test_latex(self, representation: str, expected: str) -> None:
"""Test the latex representation of the formula."""
# Example values
l_n = 5 # m
a_1 = 0.5 # m
a_2 = 0.35 # m

# Object to test
form_5_8_latex = Form5Dot8EffectiveSpan(
l_n=l_n,
a_1=a_1,
a_2=a_2,
).latex()

actual = {
"complete": form_5_8_latex.complete,
"short": form_5_8_latex.short,
"string": str(form_5_8_latex),
}

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

0 comments on commit f39b270

Please sign in to comment.