Skip to content

Commit

Permalink
Added formula 5.20
Browse files Browse the repository at this point in the history
  • Loading branch information
RamiEvansRHDHV committed Oct 16, 2024
1 parent be84fc6 commit 8598f76
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Formula 5.20 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 DIMENSIONLESS, MPA
from blueprints.validations import raise_if_less_or_equal_to_zero


class Form5Dot20DesignModulusElasticity(Formula):
"""Class representing formula 5.20 for the calculation of the design modulus of elasticity, Ecd."""

label = "5.20"
source_document = NEN_EN_1992_1_1_C2_2011

def __init__(self, e_cm: MPA, gamma_ce: DIMENSIONLESS = 1.2) -> None:
r"""[:math:`E_{cd}`] Design modulus of elasticity.
NEN-EN 1992-1-1+C2:2011 art.5.8.6(3) - Formula (5.20)
Parameters
----------
e_cm : MPA
[:math:`E_{cm}`] is the characteristic modulus of elasticity of concrete.
gamma_ce : DIMENSIONLESS, optional
[:math:`\gamma_{CE}`] is the factor for the design value of the modulus of elasticity. Default is 1.2.
"""
super().__init__()
self.e_cm = e_cm
self.gamma_ce = gamma_ce
raise_if_less_or_equal_to_zero(e_cm=e_cm, gamma_ce=gamma_ce)

@staticmethod
def _evaluate(e_cm: MPA, gamma_ce: DIMENSIONLESS) -> MPA:
"""Evaluates the formula, for more information see the __init__ method."""
raise_if_less_or_equal_to_zero(gamma_ce=gamma_ce)
return e_cm / gamma_ce

def latex(self) -> LatexFormula:
"""Returns LatexFormula object for formula 5.20."""
return LatexFormula(
return_symbol=r"E_{cd}",
result=f"{self:.3f}",
equation=r"\frac{E_{cm}}{\gamma_{CE}}",
numeric_equation=rf"\frac{{{self.e_cm}}}{{{self.gamma_ce}}}",
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 @@ -66,7 +66,7 @@ Total of 304 formulas present.
| 5.17 | :heavy_check_mark: | | Form5Dot17EffectiveLengthBucklingLoad |
| 5.18 | :heavy_check_mark: | | Form5Dot18ComparisonGeneralSecondOrderEffects |
| 5.19 | :x: | | |
| 5.20 | :x: | | |
| 5.20 | :heavy_check_mark: | | Form5Dot20DesignModulusElasticity |
| 5.21 | :x: | | |
| 5.22 | :x: | | |
| 5.23 | :x: | | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Testing formula 5.20 from 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_20 import Form5Dot20DesignModulusElasticity
from blueprints.validations import LessOrEqualToZeroError


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

@pytest.fixture
def form_5_20(self) -> Form5Dot20DesignModulusElasticity:
"""Setup and teardown for test."""
return Form5Dot20DesignModulusElasticity(e_cm=30000, gamma_ce=1.2)

def test_evaluation(self, form_5_20: Form5Dot20DesignModulusElasticity) -> None:
"""Test the evaluation of the result."""
# Expected result, manually calculated
manually_calculated_result = 30000 / 1.2
assert form_5_20 == pytest.approx(manually_calculated_result, rel=1e-4)

@pytest.mark.parametrize(
("e_cm", "gamma_ce"),
[
(30000, 0),
],
)
def test_raise_error_when_zero_pars_are_given(self, e_cm: float, gamma_ce: float) -> None:
"""Test zero values for e_cm, gamma_ce."""
with pytest.raises(LessOrEqualToZeroError):
Form5Dot20DesignModulusElasticity(e_cm=e_cm, gamma_ce=gamma_ce)

@pytest.mark.parametrize(
("e_cm", "gamma_ce", "expected"),
[
(30000, 1.2, 25000),
(35000, 1.2, 29166.67),
],
)
def test_properties(self, e_cm: float, gamma_ce: float, expected: float) -> None:
"""Test the properties of the formula."""
form_5_20 = Form5Dot20DesignModulusElasticity(e_cm=e_cm, gamma_ce=gamma_ce)
assert form_5_20 == pytest.approx(expected, rel=1e-4)

def test_latex(self, form_5_20: Form5Dot20DesignModulusElasticity) -> None:
"""Test the latex representation of the formula."""
# Object to test
form_5_20_latex = form_5_20.latex()
expected_complete = r"E_{cd} = \frac{E_{cm}}{\gamma_{CE}} = \frac{30000}{1.2} = 25000.000"
expected_short = r"E_{cd} = 25000.000"

assert form_5_20_latex.complete == expected_complete, "Complete representation failed."
assert form_5_20_latex.short == expected_short, "Short representation failed."

0 comments on commit 8598f76

Please sign in to comment.