Skip to content

Commit

Permalink
(#100) added 2.1b
Browse files Browse the repository at this point in the history
  • Loading branch information
PetervWestrienen committed Dec 28, 2023
1 parent f852164 commit 3db50e5
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Package contains the formulas from chapter 2: Basic of geotechnical design of NEN 9997-1+C2:2017."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
""""Formula 2.1b from NEN 9997-1+C2:2017: Chapter 2: Basis of geotechnical design."""
from blueprints.codes.formula import Formula
from blueprints.type_alias import DIMENSIONLESS
from blueprints.validations import raise_if_negative


class Form2Dot1BRepresentativeValue(Formula):
"""Class representing formula 2.1b for the calculation of the representative value :math:`F_{rep}` of actions."""

label = "2.1b"
source_document = "NEN 9997-1+C2:2017"

def __init__(self, psi: DIMENSIONLESS, f_k: float) -> None:
"""[:math:`F_{rep}`] Representative value of actions.
NEN 9997-1+C2:2017 art.2.4.6.1(2) - Formula (2.1b)
Parameters
----------
psi : DIMENSIONLESS
[:math:`Ψ`] factor for converting the characteristic value to the representative value [-].
f_k : float
[:math:`F_{k}`] Characteristic value of actions.
"""
super().__init__()
self.psi = psi
self.f_k = f_k

@staticmethod
def _evaluate(
psi: DIMENSIONLESS,
f_k: float,
) -> float:
"""Evaluates the formula, for more information see the __init__ method."""
raise_if_negative(psi=psi, f_k=f_k)
return psi * f_k
1 change: 1 addition & 0 deletions tests/codes/eurocode/nen_9997_1_c2_2017/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Package contains tests for the formulas of NEN 9997-1-C2:2017."""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Package contains the tests for the formulas from chapter 2: Basic of geotechnical design of NEN 9997-1+C2:2017."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
""""Testing Formula 2.1b from NEN 9997-1+C2:2017: Chapter 2: Basis of geotechnical design."""
import pytest

from blueprints.codes.eurocode.nen_9997_1_c2_2017.chapter_2_basic_of_geotechnical_design.formula_2_1_b import Form2Dot1BRepresentativeValue
from blueprints.validations import NegativeValueError


class TestForm2Dot1BRepresentativeValue:
"""Validation for formula 2.1b from NEN 9997-1+C2:2017."""

def test_evaluation(self) -> None:
"""Test the evaluation of the result."""
# example values
psi = 1.2 # [-]
f_k = 100 # kN

form_2_1_b = Form2Dot1BRepresentativeValue(psi=psi, f_k=f_k)

# manually calculated result
manually_calculated_result = 120

assert form_2_1_b == pytest.approx(expected=manually_calculated_result, rel=1e-9)

def test_raise_error_if_negative_psi(self) -> None:
"""Test that a NegativeValueError is raised when a negative value is passed for psi."""
psi = -1
f_k = 100

with pytest.raises(NegativeValueError):
Form2Dot1BRepresentativeValue(psi=psi, f_k=f_k)

def test_raise_error_if_negative_f_k(self) -> None:
"""Test that a NegativeValueError is raised when a negative value is passed for f_k."""
psi = 1.2
f_k = -100

with pytest.raises(NegativeValueError):
Form2Dot1BRepresentativeValue(psi=psi, f_k=f_k)

0 comments on commit 3db50e5

Please sign in to comment.