7.1.2. Units Example
Units are an important part of limitstates. All limitstates objects that have units store the type of unit they use. The following example showcases how the unit converters are embeded in different objects, and can be used. The types of converters avalible is detailed in units.
Similar to example 1, we define a material object. On initiation it will have one set of units:
import limitstates as ls
import limitstates.design.csa.s16.c24 as s16
Fy = 350
mat = s16.MaterialSteelCsa24(Fy, sUnit='MPa')
The units for stress used in this material are stored in the ‘iUnit’ attribute, where “i” is the type of unit. In this case were getting stress, so the sUnit attribute stores the stress and sConvert method can be used to find the conversion factor between the base unit and another valid input unit. Using the converter attribute, we can easily do spot conversions on our attribute to determine the in a different unit.
print(mat.sUnit)
ksiFactor = mat.sConvert('ksi')
Fyksi = mat.Fy * ksiFactor
Similarly, object that has a length dimension will have a lUnit attribute, and a lConvert method. An example is shown below, where a sections area can be converted from one set of units to another.
L = 6
sectionName = 'W310X118'
steelSections = ls.getSteelSections(mat, 'csa', 'cisc_12', 'w')
section = ls.getByName(steelSections, sectionName)
print(section.lUnit)
lfactor = section.lConvert('in')
Ain = section.A * lfactor**2
The full example is below:
"""
All limistate objects that have units store the type of unit they use.
The following example showcases how the unit converters are embeded in
different objects, and can be used.
"""
import limitstates as ls
import limitstates.design.csa.s16.c24 as s16
# The material is defined in one set of units on initialization.
Fy = 350
mat = s16.MaterialSteelCsa24(Fy, sUnit='MPa')
# The stress unit is stored, and sConvert returns a conversion factor.
print(mat.sUnit)
ksiFactor = mat.sConvert('ksi')
Fyksi = mat.Fy * ksiFactor
# Similarly, the steel sections store the length they are in
L = 6
sectionName = 'W310X118'
steelSections = ls.getSteelSections(mat, 'csa', 'cisc_12', 'w')
section = ls.getByName(steelSections, sectionName)
# Return the current unit, in this case mm
print(section.lUnit)
# find the conversion factor for area between inches and mm.
lfactor = section.lConvert('in')
Ain = section.A * lfactor**2