Skip to content

Commit

Permalink
Merge pull request #220 from Blueprints-org/163--feature-request-add-…
Browse files Browse the repository at this point in the history
…formula-511n-from-nen_en_1992_1_1_c2_2011
  • Loading branch information
egarciamendez authored Apr 15, 2024
2 parents c8187dc + 8bfdfad commit 68494a8
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Formula 5.11N 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, latex_fraction
from blueprints.type_alias import DIMENSIONLESS
from blueprints.validations import raise_if_less_or_equal_to_zero


class Form5Dot11nShearSlendernessCorrectionFactor(Formula):
"""Class representing formula 5.11N for the calculation of the shear slenderness correction factor [:math:`k_{λ}`]."""

label = "5.11N"
source_document = NEN_EN_1992_1_1_C2_2011

def __init__(
self,
lambda_factor: DIMENSIONLESS,
) -> None:
"""[:math:`k_{λ}`] Shear slenderness correction factor.
NEN-EN 1992-1-1+C2:2011 art.5.6.3(4) - Formula (5.11N)
Parameters
----------
lambda_factor : DIMENSIONLESS
[:math:`λ`] ratio of the distance between point of zero and maximum moment after redistribution and
effective depth, d [:math:`-`]
Use your own implementation for this value or use :class:`Form5Dot12nRatioDistancePointZeroAndMaxMoment`.
"""
super().__init__()
self.lambda_factor = lambda_factor

@staticmethod
def _evaluate(
lambda_factor: DIMENSIONLESS,
) -> DIMENSIONLESS:
"""Evaluates the formula, for more information see the __init__ method."""
raise_if_less_or_equal_to_zero(lambda_factor=lambda_factor)
return (lambda_factor / 3) ** 0.5

def latex(self) -> LatexFormula:
"""Returns LatexFormula object for formula 5.11N."""
return LatexFormula(
return_symbol=r"k_{λ}",
result=f"{self:.3f}",
equation=r"\sqrt{\frac{λ}{3}}",
numeric_equation=rf"\sqrt{latex_fraction(numerator=self.lambda_factor, denominator=3)}",
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 @@ -57,7 +57,7 @@ Total of 304 formulas present.
| 5.9 | :x: | | |
| 5.10a | :x: | | |
| 5.10b | :x: | | |
| 5.11N | :x: | | |
| 5.11N | :heavy_check_mark: | | Form5Dot11nShearSlendernessCorrectionFactor |
| 5.12N | :x: | | |
| 5.13N | :x: | | |
| 5.14 | :x: | | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Testing formula 5.11n 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_11n import Form5Dot11nShearSlendernessCorrectionFactor
from blueprints.validations import LessOrEqualToZeroError


class TestForm5Dot11nShearSlendernessCorrectionFactor:
"""Validation for formula 5.11N from NEN-EN 1992-1-1+C2:2011."""

def test_evaluation(self) -> None:
"""Test the evaluation of the result."""
# Example values
lambda_factor = 0.5 # -

# Object to test
form_5_11n = Form5Dot11nShearSlendernessCorrectionFactor(lambda_factor=lambda_factor)

# Expected result, manually calculated
manually_calculated_result = 0.40824 # -

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

@pytest.mark.parametrize(
"lambda_factor",
[
0,
-0.3,
],
)
def test_raise_error_when_negative_values_or_zero_are_given(
self,
lambda_factor: float,
) -> None:
"""Test negative or zero values."""
with pytest.raises(LessOrEqualToZeroError):
Form5Dot11nShearSlendernessCorrectionFactor(lambda_factor=lambda_factor)

@pytest.mark.parametrize(
("representation", "expected_result"),
[
("complete", r"k_{λ} = \sqrt{\frac{λ}{3}} = \sqrt\frac{0.3}{3} = 0.316"),
("short", "k_{λ} = 0.316"),
],
)
def test_latex(self, representation: str, expected_result: str) -> None:
"""Test the latex representation of the formula."""
# Example values
lambda_factor = 0.3 # -

# Object to test
latex = Form5Dot11nShearSlendernessCorrectionFactor(lambda_factor=lambda_factor).latex()

actual = {
"complete": latex.complete,
"short": latex.short,
}

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

0 comments on commit 68494a8

Please sign in to comment.