A Julia package implementing flexible conversions via natural units for Unitful.jl. Reexports Unitful.
- Define custom natural unit systems:
- Take any quantities to be 1.
- Retain arbitrary combinations of units.
- Dynamically derives appropriate unit combinations.
- Evaluate mass-dimension (or equivalent) for any quantity or unit.
Includes two standard unit systems:
PARTICLE_UNITSsetsc = ħ = k = 4πϵ₀ = 1,mol = NA. It is the default for all functions.QG_UNITSincludes all that plusG = 1. It has the aliasunitless.
Convert units via natural, with the option to use a custom combination of units
julia> using NaturallyUnitful
julia> natural(10u"N")
1.2316181391726781e13 eV^2
julia> natural(10u"N", u"kg")
3.913938995812104e-59 kg^2For quantities that are unitless in a given system, the exact unit specified will be used (if compatible).
julia> natural(10u"N", unitless) # In QG_UNITS, all quantities are unitless
8.262717639698035e-44
julia> natural(10u"N", unitless, u"s^-1")
1.5326173119543876 s^-1The unit that will be used by natural can be found using naturalunit.
julia> naturalunit(10u"N")
eV^2
julia> naturalunit(10u"N", u"kg")
kg^2
julia> naturalunit(10u"N", unitless)
julia> naturalunit(10u"N", unitless, u"s^-1")
s^-1Get the natural dimension(s) using natdims/natdim - this is the powers of the standard units needed to express the quantity. In particle units this is the 'mass-dimension'.
julia> natdim(10u"N") # Naturally eV^2
2//1
julia> natdims(10u"N", unitless) # There are 0 units left in this system
0-element StaticArraysCore.SVector{0, Rational{Int64}} with indices SOneTo(0)Define a new natural unit system via NaturalSystem. Imagine you want to set 10N = 1, for some reason...
julia> weirdsys = NaturalSystem((u"m", u"s"), (10u"N",));
julia> natural(u"kg", weirdsys)
0.1 s^2 m^-1
julia> natdims(u"kg", weirdsys)
2-element StaticArraysCore.SVector{2, Rational{Int64}} with indices SOneTo(2):
-1
2Any NaturalSystem can be called as a function like natural.
julia> weirdsys(u"kg")
0.1 s^2 m^-1
julia> unitless(u"kg")
4.5946711112415865e7