Quickstart¶
Quantities and conversion¶
from unitflow import m, cm, kg, s, N, si, kW, MW, rpm, rad
speed = 10 * m / s
area = 3 * m * 50 * cm
print(area.to(m**2))
power = 5000 * si.W
print(power.to(kW))
print(power.to(MW))
angular = (3000 * rpm).to(rad / s)
print(angular)
assert 1 * m == 100 * cm
Symbols and equations¶
from unitflow import kg, m, s, N, symbol
F = symbol("F", unit=N)
mass = symbol("m", unit=kg)
a = symbol("a", unit=m / s**2)
newtons_law = F == mass * a # Equation, not bool
Evaluate an expression¶
from unitflow import Quantity, symbol, N, m, W, rad, s
torque = symbol("torque", unit=N * m)
speed = symbol("speed", unit=rad / s)
expr = torque * speed
result = expr.evaluate(
{torque: Quantity(50, N * m), speed: Quantity(314, rad / s)}
)
print(result)
Numeric compilation (solvers)¶
from unitflow import symbol, N, m, rad, s
from unitflow.expr.compile import compile_numeric, compile_residual
torque = symbol("T", unit=N * m)
speed = symbol("w", unit=rad / s)
power = symbol("P", unit=N * m / s)
fn = compile_numeric(torque * speed, [torque, speed], {torque: N * m, speed: rad / s})
print(fn(50.0, 314.0))
eq = power == torque * speed
residual = compile_residual(eq, [power, torque, speed], {power: N * m / s, torque: N * m, speed: rad / s})
print(residual(5000.0, 50.0, 100.0))
More detail: Units and quantities, Symbolic constraints, NumPy integration, Serialization.