TchilDill / openpile

Pile calculations package. OpenPile aims to be democratize pile calculations for engineers and researchers in academia.
GNU General Public License v3.0
11 stars 4 forks source link

Adding new pile materials #28

Closed daalgi closed 7 months ago

daalgi commented 7 months ago

I was trying to add a new material type following the current implementation of Pile. Here's the code:

@dataclass(config=PydanticConfig)
class Pile:
    # ...
    material: Literal["Steel", "Concrete"]
    # ...

    def __post_init__(self):
        # ...

        # Create material specific specs for given material
        if self.material == "Steel":
            # unit weight
            self._uw = 78.0  # kN/m3
            # young modulus
            self._young_modulus = 210.0e6  # kPa
            # Poisson's ratio
            self._nu = 0.3
        elif self.material == "Concrete":
            # unit weight
            self._uw = 25.0  # kN/m3
            # young modulus
            self._young_modulus = 30.0e6  # kPa
            # Poisson's ratio
            self._nu = 0.2            
        else:
            raise UserWarning

When I try to add a test creating a concrete pile, there's a pydantic validation error:

pile = construct.Pile(
    name="",
    kind="Circular",
    material="Concrete",
    top_elevation=0,
    pile_sections={
        length": [20],
        diameter": [1.0],
        wall thickness": [0.5],
    },
)
E   pydantic.error_wrappers.ValidationError: 1 validation error for Pile
E   material
E     unexpected value; permitted: 'Steel' (type=value_error.const; given=Concrete; permitted=('Steel',))

pydantic\dataclasses.py:425: ValidationError

TestPile::test_concrete_pile - pydantic.error_wrappers.ValidationError: 1 validation error for Pile

Even if I define material as material: Literal["Concrete"], I still get the very same error saying that only "Steel" is a permitted value. Where're the permitted values defined?

daalgi commented 7 months ago

The problem was that openpile was installed from the main repo as a dependency, so the locally updated code had no effect on the tests. Solved updating requirements.txt:

#-e git+https://github.com/TchilDill/openpile.git@e8aac1b7152a3ccbf6955d7df6f435d7f1ea753a#egg=openpile
-e file:///D:/path/to/openpile

And then installing again:

pip install -r requirements.txt