Skip to content

233 Formula 5.8 from NEN-EN 1993-1-1 #519

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions .github/prompts/comparison_formula.prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
- Make sure the script returns a bool.
- Keep all formatting and naming conventions such as they are presented in the template.
- If variable descriptions are given or found, copy precisely and fully from input or Eurocode.
- Variablenames are always lowercase.
- Variable names are always lowercase in line with PEP8.
- In the LaTeX formula, edit the return symbol such that it is the left hand side of the equation
- Edit the _equation variable such that it represents the right hand side of the equation
- LaTeX variables should be rounded to 3 decimals.
- LaTeX variables should be rounded to 3 decimals as default, but could be overwritten at usage level.
- Import the necessary typehinting with type alias units found in type_alias.py and remove the unused imported type aliases. Forces in N, (Bending) moments in Nmm, distances in mm, areas in mm^2, Stress in MPa, angles in DEG, no unit is DIMENSIONLESS. When dealing with angles, use np.deg2rad.

## Template for service
Expand Down Expand Up @@ -58,14 +58,14 @@ class Form5Dot38aCheckRelativeSlendernessRatio(Formula):

return (lambda_y / lambda_z <= 2) and (lambda_z / lambda_y <= 2)

def latex(self) -> LatexFormula:
def latex(self, n: int = 3) -> LatexFormula:
"""Returns LatexFormula object for formula 5.38a."""
_equation: str = r"\left( \frac{\lambda_{y}}{\lambda_{z}} \leq 2 \text{ and } \frac{\lambda_{z}}{\lambda_{y}} \leq 2 \right)"
_numeric_equation: str = latex_replace_symbols(
_equation,
{
"lambda_y": f"{self.lambda_y:.3f}",
"lambda_z": f"{self.lambda_z:.3f}",
"lambda_y": f"{self.lambda_y:.{n}f}",
"lambda_z": f"{self.lambda_z:.{n}f}",
},
False,
)
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,5 @@ cython_debug/
.vscode/

# ENV file
.ENV
.ENV
/local/
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.4
rev: v0.9.9
hooks:
# Run the linter.
- id: ruff
Expand All @@ -26,7 +26,7 @@ repos:
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.14.1
rev: v1.15.0
hooks:
- id: mypy
language_version: python3.12
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Module containing all formulas from 1993-1-1+C2+A1:2016: Chapter 5 - Structural analysis."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"""Formula 5.8 from NEN-EN 1993-1-1+C2+A1:2016: Chapter 5 - Structural Analysis."""

import numpy as np

from blueprints.codes.eurocode.nen_en_1993_1_1_c2_a1_2016 import NEN_EN_1993_1_1_C2_A1_2016
from blueprints.codes.formula import Formula
from blueprints.codes.latex_formula import LatexFormula, latex_replace_symbols
from blueprints.type_alias import DIMENSIONLESS, MM2, MPA, N
from blueprints.validations import raise_if_less_or_equal_to_zero


class Form5Dot8CheckSlenderness(Formula):
r"""Class representing formula 5.8 for check of slenderness."""

label = "5.8"
source_document = NEN_EN_1993_1_1_C2_A1_2016

def __init__(
self,
lambda_bar: DIMENSIONLESS,
a: MM2,
f_y: MPA,
n_ed: N,
) -> None:
r"""Check the slenderness ratio.

NEN-EN 1993-1-1+C2+A1:2016 art.5.3.2(6) - Formula (5.8)

Parameters
----------
lambda_bar : DIMENSIONLESS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\overline{\lambda}

[$\lambda_{bar}$] Non-dimensional slenderness [-].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the in-plane non-dimensional slenderness calculated for the member considered as hinged at
its ends

a : MM2
[$A$] Cross-sectional area [$mm^2$].
f_y : MPA
[$f_y$] Yield strength [$MPa$].
n_ed : N
[$N_{Ed}$] Design value of the compression force [$N$].
"""
super().__init__()
self.lambda_bar = lambda_bar
self.a = a
self.f_y = f_y
self.n_ed = n_ed

@staticmethod
def _evaluate(
lambda_bar: DIMENSIONLESS,
a: MM2,
f_y: MPA,
n_ed: N,
) -> bool:
"""Evaluates the formula, for more information see the __init__ method."""
raise_if_less_or_equal_to_zero(lambda_bar=lambda_bar, A=a, f_y=f_y, N_Ed=n_ed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lambda_bar and A and fy can be zero. use raise_if_negative instead.


return lambda_bar > 0.5 * np.sqrt(a * f_y / n_ed)

def latex(self) -> LatexFormula:
"""Returns LatexFormula object for formula 5.8."""
n = 2
_equation: str = r"\left( \lambda_{bar} > 0.5 \sqrt{\frac{A \cdot f_{y}}{N_{Ed}}} \right)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i personally prefer a \cdot after the 0.5, but its up to you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\overline{\lambda}

_numeric_equation: str = latex_replace_symbols(
_equation,
{
r"\lambda_{bar}": f"{self.lambda_bar:.{n}f}",
"A": f"{self.a:.{n}f}",
"f_{y}": f"{self.f_y:.{n}f}",
"N_{Ed}": f"{self.n_ed:.{n}f}",
},
False,
)
return LatexFormula(
return_symbol=r"CHECK",
result="OK" if self.__bool__() else "\\text{Not OK}",
equation=_equation,
numeric_equation=_numeric_equation,
comparison_operator_label="\\to",
unit="",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests for the module `nen_en_1993_1_1_c2_a1_2016.chapter_5_structural_analysis`."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""Testing formula 5.8 of NEN-EN 1993-1-1+C2+A1:2016."""

import pytest

from blueprints.codes.eurocode.nen_en_1993_1_1_c2_a1_2016.chapter_5_structural_analysis.formula_5_8 import Form5Dot8CheckSlenderness
from blueprints.validations import LessOrEqualToZeroError


class TestForm5Dot8CheckSlenderness:
"""Validation for formula 5.8 from NEN-EN 1993-1-1+C2+A1:2016."""

def test_evaluation(self) -> None:
"""Tests the evaluation of the result."""
# Example values
lambda_bar = 1.0
a = 1000.0
f_y = 355.0
n_ed = 100000.0

# Object to test
formula = Form5Dot8CheckSlenderness(lambda_bar=lambda_bar, a=a, f_y=f_y, n_ed=n_ed)

# Expected result, manually calculated
expected_result = True

assert formula == expected_result

@pytest.mark.parametrize(
("lambda_bar", "a", "f_y", "n_ed"),
[
(-1.0, 1000.0, 355.0, 100000.0), # lambda_bar is negative
(1.0, -1000.0, 355.0, 100000.0), # a is negative
(1.0, 1000.0, -355.0, 100000.0), # f_y is negative
(1.0, 1000.0, 355.0, -100000.0), # n_ed is negative
(0.0, 1000.0, 355.0, 100000.0), # lambda_bar is zero
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 35-37 not needed for tests, as they can be zero.

(1.0, 0.0, 355.0, 100000.0), # a is zero
(1.0, 1000.0, 0.0, 100000.0), # f_y is zero
(1.0, 1000.0, 355.0, 0.0), # n_ed is zero
],
)
def test_raise_error_when_invalid_values_are_given(self, lambda_bar: float, a: float, f_y: float, n_ed: float) -> None:
"""Test invalid values."""
with pytest.raises(LessOrEqualToZeroError):
Form5Dot8CheckSlenderness(lambda_bar, a, f_y, n_ed)

def test_latex(self) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is not in line with all other formula latex tests. could you add the full short and complete result?

"""Test the latex representation of the formula."""
# Example values
lambda_bar = 1.0
a = 1000.0
f_y = 355.0
n_ed = 100000.0

# Object to test
formula = Form5Dot8CheckSlenderness(lambda_bar=lambda_bar, a=a, f_y=f_y, n_ed=n_ed)
latex = formula.latex()

expected_equation = r"\left( \lambda_{bar} > 0.5 \sqrt{\frac{A \cdot f_{y}}{N_{Ed}}} \right)"
expected_numeric_equation = r"\left( 1.00 > 0.5 \sqrt{\frac{1000.00 \cdot 355.00}{100000.00}} \right)"
expected_result = "OK"

assert latex.equation == expected_equation
assert latex.numeric_equation == expected_numeric_equation
assert latex.result == expected_result