Blueprints-org / blueprints

Blueprints, open source python package for civil engineering calculations.
https://blueprints.readthedocs.io
GNU Lesser General Public License v2.1
15 stars 2 forks source link

[❓ Question]: How to implement inequalities like (9.11) from NEN-EN 1992-1-1+C2:2011 #50

Closed PetervWestrienen closed 8 months ago

PetervWestrienen commented 10 months ago

Preliminary Checks

What Have You Tried?

I tried implementing formula 9.11 from NEN-EN 1992-1-1+C2:2011, however I don't know what would be the best way to implement this formula for blueprints.

Question Description

Formula 9.11 is given as an inequality: image

My own interpretation would be to re-write this inequality in the form A_sw,min=...., but that would not match EC exactly. There are multiple inequalities such as this one in EC e.g. 4.3N and 4.4N are also inequalities. It might be a good idea to think about a way to generally handle these formulas.

Relevant Code or Steps

No response

Confirmation

egarciamendez commented 10 months ago

@Blueprints-org/maintainers Any thoughts on how to handle inequalities on the codes? afbeelding afbeelding afbeelding etc...

johan-tuls commented 10 months ago

In reality the formula is written as an inequality. However as the description says? $A{sw,min}$ is given bij this formula: ..... So I think this formula should be rewritten as $A{sw,min} =$ would be most logic. With a min value of ....

PetervWestrienen commented 10 months ago

Yes I agree that it would be logical for this formula, but for formulas like 4.3N and 4.4N this method would not work. These constraints could be implemented in the formulas in which they are used and thereafter be omitted as explicit formulas in blueprints.

rickdegoeij commented 10 months ago

For 4.3 and 4.4 you could probably also define a $\Delta c_{dev,min}$ and $\Delta c_{dev,max}$.

But I'm guessing the question is to get the exact formulas/equations of the Eurocode to be presented in the code. In that case these formulas would require an addition to the base class. The base class currently only handles floats. But these require a boolean result. So they are a bit incompatible at this time. If we handle boolean's we could simply write 9Dot11_result = (.... <= ......)

bro-wi commented 10 months ago

We could implement a baseclass that is suited for booleans, one challenge: we cannot inherrit from 'bool' so we have to write the complete implementation ourselves: not a problem but more work.

egarciamendez commented 10 months ago

My preferred solution is inclined towards treating these 'Formulas' as a boolean. Possibly by utilizing an 'InequalityFormula' base class (or another aptly named class 😉).

Consider these points:

What are your thoughts on this? 🔽


from abc import ABC, abstractmethod
import numpy as np

class InequalityFormula(ABC):
    def __init__(self) -> None:
        self._evaluation = None
        self.evaluate()

    @abstractmethod
    def evaluate(self) -> None:
        pass

    def __bool__(self) -> bool:
        return self._evaluation

class For9Dot11(InequalityFormula):
    def __init__(
        self,
        a_sw_min: float,
        alpha: float,
        s_r: float,
        s_t: float,
        f_ck: float,
        f_yk: float,
    ) -> None:
        self.a_sw_min = a_sw_min
        self.alpha = alpha
        self.s_r = s_r
        self.s_t = s_t
        self.f_ck = f_ck
        self.f_yk = f_yk
        super().__init__()

    def _left_side(self) -> float:
        alpha_degree = np.deg2rad(self.alpha)
        return (self.a_sw_min * (1.5 * np.sin(alpha_degree) + np.cos(alpha_degree))) / (
            self.s_r * self.s_t
        )

    def _right_side(self) -> float:
        return 0.08 * (np.sqrt(self.f_ck) / self.f_yk)

    def evaluate(self) -> None:
        self._evaluation = bool(self._left_side() <= self._right_side())

if __name__ == "__main__":
    inequality = For9Dot11(
        a_sw_min=0.001,
        alpha=45,
        s_r=0.2,
        s_t=0.2,
        f_ck=25,
        f_yk=500,
    )
    print(bool(inequality))  # This will print True or False based on the evaluation
    print(type(inequality))  # This will print <class '__main__.For9Dot11'>
    if inequality:
        print("The inequality is true")
    else:
        print("The inequality is false")
    # This will print "The inequality is false"