Units
Jutul assumes that all physical quantities are represented in SI units internally (or another consistent system). To facilitate conversion between different unit systems, Jutul provides utility functions to convert values to and from SI units.
There are also Julia packages like Unitful.jl and DynamicQuantities.jl that can be used to embed units in types, but these are not directly integrated with Jutul at this time. Performing calculations with your unit system of choice before striping units and passing values in SI to Jutul is the recommended approach.
Jutul.convert_to_si — Function
convert_to_si(value, unit_name::String)Convert value to SI representation from value in the unit given by unit_symbol.
Available units
You can get a list of all available units via Jutul.available_units(). The values in Jutul itself are:
A, BTU, British thermal unit, Da, F, Gal, J, K, Kelvin, L, N, Pa, R, Rankine, Standard barrel, W, amp, ampere, atm, atmosphere, bar, btu, dalton, darcy, day, dyn, dyne, farad, feet, ft, g, gal, gallon_us, gram, hour, in, inch, joule, kelvin, kg, kilogram, l, lb, lbf, liter, litre, m, meter, minute, mol, newton, pascal, poise, pound, pound-force, psi, rankine, s, second, site, stb, tonne, usgal, watt, year.
In addition units can be prefixed with standard SI prefixes. Available prefixes are:
quetta, ronna, yotta, zetta, exa, peta, tera, giga, mega, kilo, hecto, deca, deci, centi, milli, micro, nano, pico, femto, atto, zepto, yocto, ronto, quecto.
This utility can also handle composite units, e.g. "kilometer/hour" or "meter/second^2". Note that relative temperature units (Celsius and Fahrenheit) must be converted to absolute units (Kelvin or Rankine) before being used in composite units.
Examples
julia> convert_to_si(1.0, :hour) # Get 1 hour represented as seconds
3600.0
julia> convert_to_si(5.0, "kilometer/hour") # Get 5 kilometers per hour represented as seconds
1.3888888888888888
julia> convert_to_si(1.0, "milligram") # Get 1 milligram represented as kilograms
1.0e-6Jutul.convert_from_si — Function
convert_from_si(value, unit_name::Union{Symbol, String})Convert value from SI representation to the unit in unit_symbol.
Examples
julia> convert_from_si(3600.0, :hour) # Get 3600 s represented as hours
1.0Jutul.si_unit — Function
si_unit(u::Union{String, Symbol})Get the multiplicative SI unit conversion factor for a single unit. The return value is given so that x*si_unit(:name) will convert x to the SI representation of the unit with the given name. Composite units are also supported via strings, e.g. si_unit("feet^3/second").
Examples
julia> si_unit(:day) # Get days represented as seconds
86400.0Jutul.@si_str — Macro
si"kg/meter"A string macro to convert unit strings to SI conversion factors. Convenience function for si_unit.
Examples
julia> si"day" # Get days represented as seconds
86400.0
julia> si"kilometer/hour" # Get kilometers per hour represented as seconds
0.2777777777777778
julia> si"3.14*kilometer/hour" # Get 3.14 kilometers per hour represented as seconds
0.8722222222222222
julia> si"100gram + 0.1kilogram" # Get 100 grams + 0.1 kilogram represented as kilograms
0.2