fib-international / structuralcodes

A Python library for structural engineering calculations
https://fib-international.github.io/structuralcodes/
Apache License 2.0
108 stars 22 forks source link

feat: handle units #205

Open mortenengen opened 3 weeks ago

mortenengen commented 3 weeks ago

Description

An attempt to handle units. Note: this is still a very immature draft!

Two classes are added to core: UnitSet and UnitConverter. UnitSet is a dataclass responsible for storing a set of units intended to be used by a Material class. UnitConverter uses two UnitSets to convert between them.

Example

This example shows how two sets of units are selected and passed to the unit converter. Furthermore, it shows how to convert stress, lengeth and force with the unit converter.

from structuralcodes.core._units import UnitSet, UnitConverter

from_units = UnitSet(length='mm', force='N')
to_units = UnitSet(length='m', force='kN')

converter = UnitConverter(
    from_units=from_units,
    to_units=to_units,
)

converter.convert_stress_backwards(35e3)
converter.convert_length_forwards(30)
converter.convert_force_forwards(4e3)

To do