Skip to content

Commit

Permalink
Merge branch 'main' into 349-feature-request-add-latex-to-existing-fo…
Browse files Browse the repository at this point in the history
…rmulas-from-1992-1-1-chapter-5
  • Loading branch information
egarciamendez authored Nov 23, 2024
2 parents 02340e5 + cfb23f1 commit 3745e14
Show file tree
Hide file tree
Showing 11 changed files with 570 additions and 23 deletions.
75 changes: 55 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,63 @@ Our mission is to reduce the cost and time associated with civil engineering cal

## (Upcoming) Features

* Eurocode formulas:
* NEN-EN 1992-1-1+C2:2011 :construction:
* NEN-EN 1993-1-1+C2+A1:2016 :construction:
* NEN-EN 1993-1-9+C2:2012 :construction:
* NEN-EN 1993-5:2008 :construction:
* NEN 9997-1+C2:2017 :construction:

* Reinforced Concrete Section :construction:
* Rectangular section :heavy_check_mark:
* Circular section :x:
* Eurocode formulas
- [ ] NEN-EN 1992-1-1+C2:2011 ![](https://img.shields.io/badge/50-%25-grey?style=plastic&labelColor=yellow)
- [ ] NEN-EN 1993-1-1+C2+A1:2016 ![](https://img.shields.io/badge/20%25-grey?style=plastic&labelColor=orange)
- [ ] NEN-EN 1993-1-9+C2:2012 ![](https://img.shields.io/badge/20%25-grey?style=plastic&labelColor=orange)
- [ ] NEN-EN 1993-5:2008 ![](https://img.shields.io/badge/20%25-grey?style=plastic&labelColor=orange)
- [ ] NEN 9997-1+C2:2017 ![](https://img.shields.io/badge/20%25-grey?style=plastic&labelColor=orange)

* Material definitions
- [x] Concrete (NEN-EN 1992) ✔️
- [x] Rebar Steel (NEN-EN 1992) ✔️
- [x] Soil (NEN-EN 1997) ✔️

* Reinforced Concrete Section
- [x] Rectangular section ✔️
- [ ] Circular section

* Strain-stress analysis for reinforced concrete sections:
* Rectangular section :construction:
* Circular section :x:

* Concrete checks:
* Nominal concrete cover (NEN-EN 1992-1-1: Chapter 4) :construction:

* Common calculations:
* L-walls :x:
* Spring constants calculations for piles :x:
* Sheet-pile checks (strength, stability, deflection, local buckling, etc.) :x:
- [ ] Rectangular section ![](https://img.shields.io/badge/20%25-grey?style=plastic&labelColor=orange)
- [ ] Circular section

* Concrete checks
- [ ] Nominal concrete cover (NEN-EN 1992-1-1: Chapter 4) ![](https://img.shields.io/badge/50-%25-grey?style=plastic&labelColor=yellow)
- [ ] Anchorage- and Laplengths (NEN-EN 1992-1-1: Chapter 8)
- [ ] Shear Resistance (NEN-EN 1992-1-1: Chapter 6.2)
- [ ] Shear Resistance circular shapes;
- [ ] Torsion (NEN-EN 1992-1-1: Chapter 6.3)
- [ ] Punching Shear (NEN-EN 1992-1-1: Chapter 6.4)
- [ ] Fatigue (NEN-EN 1992-1-1: Chapter 6.8)
- [ ] Crack Control (NEN-EN 1992-1-1: Chapter 7.3)
- [ ] Creep and Shrinkage (NEN-EN 1992-1-1: Chapter 3.1.4)

* Timber checks (NEN-EN 1995)
- *To Be Determined*

* Steel checks (NEN-EN 1993)
- *To Be Determined*

* Geotechnical checks (NEN-EN 9997-1
- *To Be Determined*

* Common calculations
- [ ] L-walls
- [ ] Spring constants calculations for piles
- [ ] Sheet-pile checks (strength, stability, deflection, local buckling, etc.)

<details>

<summary> Progress definitions </summary>

| Icon | Definition |
| --- | --------- |
| ![](https://img.shields.io/badge/20%25-grey?style=plastic&labelColor=orange) | Just started |
| ![](https://img.shields.io/badge/50-%25-grey?style=plastic&labelColor=yellow) | Making progress |
| ![](https://img.shields.io/badge/80%25--grey?style=plastic&labelColor=yellowgreen) | In Review |
| ✔️ | Done |

</details>

## Installation

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""Formula 5.10a 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.latex_formula import LatexFormula
from blueprints.type_alias import DIMENSIONLESS, M
from blueprints.validations import raise_if_less_or_equal_to_zero


class Form5Dot10aRedistributionOfMomentsLowerFck:
r"""Class representing formula 5.10a for the redistribution of moments in continuous beams or slabs when :math:`f_{ck} \leq 50 MPa`."""

label = "5.10a"
source_document = NEN_EN_1992_1_1_C2_2011

def __init__(self, delta: DIMENSIONLESS, k1: DIMENSIONLESS, k2: DIMENSIONLESS, xu: M, d: M) -> None:
r"""[:math:`δ`] Redistribution of moments in continuous beams or slabs when :math:`f_{ck} \leq 50 MPa`.
NEN-EN 1992-1-1+C2:2011 art.5.5(4) - Formula (5.10a)
Parameters
----------
delta : DIMENSIONLESS
[:math:`δ`] is the ratio of the redistributed moment to the elastic moment.
k1 : DIMENSIONLESS
[:math:`k1`] is a coefficient for redistribution.
k2 : DIMENSIONLESS
[:math:`k2`] is a coefficient for redistribution.
xu : M
[:math:`x_u`] is the depth of the compression zone in the ultimate limit state after redistribution.
d : M
[:math:`d`] is the effective depth of the section.
"""
super().__init__()
self.delta = delta
self.k1 = k1
self.k2 = k2
self.xu = xu
self.d = d
raise_if_less_or_equal_to_zero(delta=delta, k1=k1, k2=k2, xu=xu, d=d)

@property
def left_hand_side(self) -> DIMENSIONLESS:
"""Calculate the left hand side of the comparison.
Returns
-------
DIMENSIONLESS
Left hand side of the comparison.
"""
return self.delta

@property
def right_hand_side(self) -> DIMENSIONLESS:
"""Calculate the right hand side of the comparison.
Returns
-------
DIMENSIONLESS
Right hand side of the comparison.
"""
raise_if_less_or_equal_to_zero(d=self.d)
raise_if_less_or_equal_to_zero(xu=self.xu)
return self.k1 + self.k2 * (self.xu / self.d)

@property
def ratio(self) -> DIMENSIONLESS:
"""Ratio between left hand side and right hand side of the comparison, commonly referred to as unity check."""
return self.left_hand_side / self.right_hand_side

def __bool__(self) -> bool:
"""Evaluates the comparison, for more information see the __init__ method."""
return self.left_hand_side >= self.right_hand_side

def __str__(self) -> str:
"""Return the result of the comparison."""
return self.latex().complete

def latex(self) -> LatexFormula:
"""Returns LatexFormula object for formula 5.10a."""
return LatexFormula(
return_symbol=r"CHECK",
result="OK" if self.__bool__() else "\\text{Not OK}",
equation=r"\delta \geq k_1 + k_2 \frac{x_u}{d}",
numeric_equation=rf"{self.left_hand_side:.3f} \geq {self.k1} + {self.k2} \frac{{{self.xu}}}{{{self.d}}}",
comparison_operator_label=r"\rightarrow",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Formula 5.19 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, KN_M
from blueprints.validations import raise_if_less_or_equal_to_zero


class Form5Dot19EffectiveCreepCoefficient(Formula):
"""Class representing formula 5.19 for the calculation of the effective creep coefficient, ϕef."""

label = "5.19"
source_document = NEN_EN_1992_1_1_C2_2011

def __init__(self, phi_inf_t0: DIMENSIONLESS, m0_eqp: KN_M, m0_ed: KN_M) -> None:
"""[:math:`ϕ_{ef}`] Effective creep coefficient.
NEN-EN 1992-1-1+C2:2011 art.5.8.4(2) - Formula (5.19)
Parameters
----------
phi_inf_t0 : DIMENSIONLESS
[:math:`ϕ (∞,t0)`] is the final value of the creep coefficient according to art. 3.1.4.
m0_eqp : KN_M
[:math:`M_{0,Eqp}`] is the first-order bending moment in the quasi-permanent load combination (SLS).
m0_ed : KN_M
[:math:`M_{0,Ed}`] is the first-order bending moment in the ultimate limit state (ULS).
"""
super().__init__()
self.phi_inf_t0 = phi_inf_t0
self.m0_eqp = m0_eqp
self.m0_ed = m0_ed

@staticmethod
def _evaluate(phi_inf_t0: DIMENSIONLESS, m0_eqp: KN_M, m0_ed: KN_M) -> DIMENSIONLESS:
"""Evaluates the formula, for more information see the __init__ method."""
raise_if_less_or_equal_to_zero(m0_ed=m0_ed)
return phi_inf_t0 * (m0_eqp / m0_ed)

def latex(self) -> LatexFormula:
"""Returns LatexFormula object for formula 5.19."""
return LatexFormula(
return_symbol=r"\phi_{ef}",
result=f"{self:.3f}",
equation=r"\phi (\infty,t_0) \cdot \frac{M_{0,Eqp}}{M_{0,Ed}}",
numeric_equation=rf"{self.phi_inf_t0} \cdot \frac{{{self.m0_eqp}}}{{{self.m0_ed}}}",
comparison_operator_label="=",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""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, :math:`E_{cd}`."""

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 which is the recommended value.
"""
super().__init__()
self.e_cm = e_cm
self.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="=",
)
59 changes: 59 additions & 0 deletions blueprints/codes/latex_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,62 @@ def latex_max_curly_brackets(*args: str | float) -> str:
"""
arguments = [str(arg) for arg in args]
return f"\\max \\left\\{{{'; '.join(arguments)}\\right\\}}"


def latex_replace_symbols(template: str, replacements: dict[str, str], unique_symbol_check: bool = True) -> str:
r"""
Replace symbols in a LaTeX template string based on the provided dictionary.
This function searches the template for symbols specified in the
replacements and replaces them with their corresponding
values. It also checks for the occurrence of symbols based on the
unique_symbol_check parameter, raising an error if necessary.
Examples
--------
>>> latex_template = r"\frac{K_{MOD}}{B}"
>>> replacements = {"K_{MOD}": "1.0", "B": "y"}
>>> latex_replace_symbols(latex_template, replacements)
'\frac{1.0}{y}
Parameters
----------
template: str
The original LaTeX string containing symbols to replace.
replacements: dict[str, str]
A dictionary where keys are symbols to be replaced and values
are their replacements.
unique_symbol_check: bool, optional
If True (default), raises an error if a symbol appears more
than once in the template. If False, multiple occurrences
will be replaced without error.
Returns
-------
str
The modified LaTeX string with symbols replaced.
Raises
------
ValueError
If a symbol in the dictionary is not found in the template,
or if a symbol appears more than once when single_symbol_search is True.
"""
_filled_latex_string: str = template
for symbol, replacement in replacements.items():
occurrences = _filled_latex_string.count(symbol)

# Check for the presence of the symbol in the template
if occurrences == 0:
raise ValueError(f"Symbol '{symbol}' not found in the template.")

# If single_symbol_search is True, check for multiple occurrences
if unique_symbol_check and occurrences > 1:
raise ValueError(f"Symbol '{symbol}' found multiple times in the template.")

# Replace the symbol with its replacement
_filled_latex_string = _filled_latex_string.replace(symbol, replacement)

return _filled_latex_string
6 changes: 3 additions & 3 deletions docs/source/codes/eurocode/ec2_1992_1_1_2011/formulas.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Total of 304 formulas present.
| 5.7b | :heavy_check_mark: | | Form5Dot7bFlangeEffectiveFlangeWidth |
| 5.8 | :heavy_check_mark: | | Form5Dot8EffectiveSpan |
| 5.9 | :heavy_check_mark: | | Form5Dot9DesignSupportMomentReduction |
| 5.10a | :x: | | |
| 5.10a | :heavy_check_mark: | | Form5Dot10aRedistributionOfMomentsLowerFck |
| 5.10b | :x: | | |
| 5.11N | :heavy_check_mark: | | Form5Dot11nShearSlendernessCorrectionFactor |
| 5.12N | :heavy_check_mark: | | Form5Dot12nRatioDistancePointZeroAndMaxMoment |
Expand All @@ -65,8 +65,8 @@ Total of 304 formulas present.
| 5.16 | :heavy_check_mark: | | Form5Dot16EffectiveLengthUnbraced |
| 5.17 | :heavy_check_mark: | | Form5Dot17EffectiveLengthBucklingLoad |
| 5.18 | :heavy_check_mark: | | Form5Dot18ComparisonGeneralSecondOrderEffects |
| 5.19 | :x: | | |
| 5.20 | :x: | | |
| 5.19 | :heavy_check_mark: | | Form5Dot19EffectiveCreepCoefficient |
| 5.20 | :heavy_check_mark: | | Form5Dot20DesignModulusElasticity |
| 5.21 | :x: | | |
| 5.22 | :x: | | |
| 5.23 | :x: | | |
Expand Down
Loading

0 comments on commit 3745e14

Please sign in to comment.