Arbitrary Unit Conversion#

class opstool.preprocessing.UnitSystem(length='m', force='kn', time='sec')[source]#

A class for unit conversion.

Parameters#

length: str, default=”m”

Length unit base. Optional [“inch”, “ft”, “mm”, “cm”, “m”].

force: str, default=”kN”

Force unit base. Optional [“lb”(“lbf”), “kip”, “n”, “kn”, “mn”, “kgf”, “tonf”].

time: str, default=”sec”

Time unit base. Optional [“sec”, “msec”].

Note

  • Mass and stress units can be automatically determined based on length and force units, optional mass units include [“mg”, “g”, “kg”, “ton”(“t”), “slug”], and optional stress units include [“pa”, “kpa”, “mpa”, “gpa”, “bar”, “psi”, “ksi”, “psf”, “ksf”].

  • You can enter any uppercase and lowercase forms, such as kn and kN, mpa and MPa are equivalent.

  • You can add a number after the unit to indicate a power, such as m3 for m*m*m.

Example#

import opstool as opst

UNIT = opst.UnitSystem(length="mm", force="N")
print(UNIT.m, UNIT.cm, UNIT.inch, UNIT.cm3)
print(UNIT.kN, UNIT.lb)
print(UNIT.KPa, UNIT.MPa, UNIT.GPa, UNIT.ksi)
print(UNIT)
1000.0 10.0 25.4 1000.0
1000.0 4.4482216282509
0.001 1.0 1000.0 6.8947572932
Length unit:
inch=25.4; ft=304.8; mm=1; cm=10.0; m=1000.0; 


Force unit:
lb=4.4482216282509; lbf=4.4482216282509; kip=4448.2216; n=1; kn=1000.0; 
mn=1000000.0; kgf=9.80665; tonf=9806.64999999931; 

Time unit:
sec=1; msec=1000.0; 

Mass unit:
mg=1e-09; g=1e-06; kg=0.001; ton=1.0; t=1.0; 
slug=0.014593902936999999; 

Pressure unit:
pa=1e-06; kpa=0.001; mpa=1.0; gpa=1000.0; bar=0.09999999999999999; 
psi=0.0068947572932; ksi=6.8947572932; psf=4.7880208e-05; ksf=0.047880246861601; 

UNIT = opst.UnitSystem(length="m", force="kN")
print(UNIT)
Length unit:
inch=0.0254; ft=0.3048; mm=0.001; cm=0.01; m=1; 


Force unit:
lb=0.0044482216282509; lbf=0.0044482216282509; kip=4.4482216; n=0.001; kn=1; 
mn=1000.0; kgf=0.00980664999999931; tonf=9.80664999999931; 

Time unit:
sec=1; msec=1000.0; 

Mass unit:
mg=1e-09; g=1e-06; kg=0.001; ton=1.0; t=1.0; 
slug=0.014593902936999999; 

Pressure unit:
pa=0.001; kpa=1.0; mpa=1000.0; gpa=1000000.0; bar=100.0; 
psi=6.8947572932000005; ksi=6894.7572932; psf=0.04788020800000001; ksf=47.880246861601; 

UNIT = opst.UnitSystem(length="ft", force="lb")
print(UNIT)
Length unit:
inch=0.0833333333; ft=1; mm=0.0032808398950131233; cm=0.03280839895013123; m=3.280839895013123; 


Force unit:
lb=1; lbf=1.0; kip=1000.0; n=0.22480894244318786; kn=224.80894244318787; 
mn=224820.1438848921; kgf=2.204622629412178; tonf=2204.622621851692; 

Time unit:
sec=1; msec=1000.0; 

Mass unit:
mg=6.852176565668366e-08; g=6.852176565668366e-05; kg=0.06852176565668366; ton=68.52176565668367; 
t=68.52176565668367; 
slug=0.9999999970655015; 

Pressure unit:
pa=0.020885434172157182; kpa=20.885434172157183; mpa=20885.434172157184; gpa=20885434.172157183; 
bar=2088.5434172157184; 
psi=143.99999958012924; ksi=143999.99958012925; psf=0.9999989323331938; ksf=999.9997439746032;