Units

Units are supported by Unitful.jl and UnitfulAstro.jl

Default Units

You could set preferred units by

const uSI = u"m,s,A,K,cd,kg,mol"
preferunits(uSI)

or simply call si(), astro(), ugadget2() and cgs() are implemented in the same way.

This would affect unit promotions in Unitful package and default outputs in related packages, by setting Unitful.promotion and PhysicalParticles.uDefaults respectively.

Examples to get basic units:

julia> using PhysicalParticles
julia> getunits()(m, s, A, K, cd, kg, mol)
julia> getunits(uAstro)(kpc, Gyr, A, K, cd, M⊙, mol)
julia> getunits(uGadget2)(kpc, kpc s km^-1, A, K, cd, 1e10M⊙, mol)
julia> getunits(nothing)(nothing, nothing, nothing, nothing, nothing, nothing, nothing)
julia> getuLength()m
julia> getuTime(uSI)s
julia> getuCurrent(uCGS)A
julia> getuTemperature(nothing)
julia> getuLuminosity()cd
julia> getuMass()kg
julia> getuAmount()mol

Constants

Physical constants are imported from CODATA2018 supported by PhysicalConstants.jl. However, constants in PhysicalConstants may cause type error if they are not converted to default units.

To prevent this problem, construct an immutable struct Constant corresponding to the provided units:

julia> using PhysicalParticles
julia> Constant()Converted Constants: c = 306601.3937855506 kpc Gyr^-1 (light speed) G = 4.498502151469552e-6 kpc^3 M⊙^-1 Gyr^-2 (Newtonian constant of gravitation) h = 1.1044676394727103e-86 kpc^2 M⊙ Gyr^-1 (Planck constant) e = 5.076991387177732e-36 A Gyr (Elementary charge) m_e = 4.581240435253955e-61 M⊙ (Electron mass) m_n = 8.423451938769546e-58 M⊙ (Neutron mass) m_p = 8.411856872862986e-58 M⊙ (Protron mass) σ = 8.962263893181575e11 M⊙ K^-4 Gyr^-3 (Stefan-Boltzmann constant) H = 0.0757113815783328 Gyr^-1 (Hubble constant) k_B = 7.262467736391801e-60 kpc^2 M⊙ K^-1 Gyr^-2 (Kelvin-Boltzmann constant) ε_0 = 5.2154334438047174e11 A^2 Gyr^4 kpc^-3 M⊙^-1 (Vacuum electric permittivity) μ_0 = 2.0396767377343498e-23 kpc M⊙ A^-2 Gyr^-2 (Vacuum magnetic permeability) ACC0 = 3872.920970357523 kpc Gyr^-2 (Modified gravitational acceleration constant)
julia> Constant(uSI)Converted Constants: c = 2.99792458e8 m s^-1 (light speed) G = 6.6743e-11 m^3 kg^-1 s^-2 (Newtonian constant of gravitation) h = 6.62607015e-34 kg m^2 s^-1 (Planck constant) e = 1.602176634e-19 A s (Elementary charge) m_e = 9.1093837015e-31 kg (Electron mass) m_n = 1.67492749804e-27 kg (Neutron mass) m_p = 1.67262192369e-27 kg (Protron mass) σ = 5.6703744191844294e-8 kg K^-4 s^-3 (Stefan-Boltzmann constant) H = 2.399148907975663e-18 s^-1 (Hubble constant) k_B = 1.380649e-23 kg m^2 K^-1 s^-2 (Kelvin-Boltzmann constant) ε_0 = 8.8541878128e-12 A^2 s^4 kg^-1 m^-3 (Vacuum electric permittivity) μ_0 = 1.25663706212e-6 kg m A^-2 s^-2 (Vacuum magnetic permeability) ACC0 = 1.2e-10 m s^-2 (Modified gravitational acceleration constant)
julia> Constant(uCGS)Converted Constants: c = 2.99792458e10 cm s^-1 (light speed) G = 6.674299999999999e-8 cm^3 g^-1 s^-2 (Newtonian constant of gravitation) h = 6.62607015e-27 g cm^2 s^-1 (Planck constant) e = 1.602176634e-19 A s (Elementary charge) m_e = 9.1093837015e-28 g (Electron mass) m_n = 1.67492749804e-24 g (Neutron mass) m_p = 1.67262192369e-24 g (Protron mass) σ = 5.670374419184429e-5 g K^-4 s^-3 (Stefan-Boltzmann constant) H = 2.399148907975663e-18 s^-1 (Hubble constant) k_B = 1.380649e-16 g cm^2 K^-1 s^-2 (Kelvin-Boltzmann constant) ε_0 = 8.854187812800002e-21 A^2 s^4 g^-1 cm^-3 (Vacuum electric permittivity) μ_0 = 0.125663706212 g cm A^-2 s^-2 (Vacuum magnetic permeability) ACC0 = 1.2e-8 cm s^-2 (Modified gravitational acceleration constant)
julia> using Unitful
julia> ustrip(Constant())Converted Constants: c = 306601.3937855506 (light speed) G = 4.498502151469552e-6 (Newtonian constant of gravitation) h = 1.1044676394727103e-86 (Planck constant) e = 5.076991387177732e-36 (Elementary charge) m_e = 4.581240435253955e-61 (Electron mass) m_n = 8.423451938769546e-58 (Neutron mass) m_p = 8.411856872862986e-58 (Protron mass) σ = 8.962263893181575e11 (Stefan-Boltzmann constant) H = 0.0757113815783328 (Hubble constant) k_B = 7.262467736391801e-60 (Kelvin-Boltzmann constant) ε_0 = 5.2154334438047174e11 (Vacuum electric permittivity) μ_0 = 2.0396767377343498e-23 (Vacuum magnetic permeability) ACC0 = 3872.920970357523 (Modified gravitational acceleration constant)

Zerovalues

ZeroValue is useful for accumulated summation, array initialization, etc. Examples:

julia> using PhysicalParticles
julia> ZeroValue(nothing) Zero Values: len = 0.0 pos = PVector{Float64}(0.0, 0.0, 0.0) vel = PVector{Float64}(0.0, 0.0, 0.0) acc = PVector{Float64}(0.0, 0.0, 0.0) pot = 0.0 potpermass = 0.0 mass = 0.0 density = 0.0
julia> ZeroValue() Zero Values: len = 0.0 kpc pos = PVector(0.0 kpc, 0.0 kpc, 0.0 kpc) vel = PVector(0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1) acc = PVector(0.0 kpc Gyr^-2, 0.0 kpc Gyr^-2, 0.0 kpc Gyr^-2) pot = 0.0 kpc^2 M⊙ Gyr^-2 potpermass = 0.0 kpc^2 Gyr^-2 mass = 0.0 M⊙ density = 0.0 M⊙ kpc^-3
julia> ZeroValue(uSI) Zero Values: len = 0.0 m pos = PVector(0.0 m, 0.0 m, 0.0 m) vel = PVector(0.0 m s^-1, 0.0 m s^-1, 0.0 m s^-1) acc = PVector(0.0 m s^-2, 0.0 m s^-2, 0.0 m s^-2) pot = 0.0 kg m^2 s^-2 potpermass = 0.0 m^2 s^-2 mass = 0.0 kg density = 0.0 kg m^-3
julia> ZeroValue(uCGS) Zero Values: len = 0.0 cm pos = PVector(0.0 cm, 0.0 cm, 0.0 cm) vel = PVector(0.0 cm s^-1, 0.0 cm s^-1, 0.0 cm s^-1) acc = PVector(0.0 cm s^-2, 0.0 cm s^-2, 0.0 cm s^-2) pot = 0.0 g cm^2 s^-2 potpermass = 0.0 cm^2 s^-2 mass = 0.0 g density = 0.0 g cm^-3
julia> ZeroValue(Measurement) Zero Values: len = 0.0 ± 0.0 kpc pos = PVector(0.0 ± 0.0 kpc, 0.0 ± 0.0 kpc, 0.0 ± 0.0 kpc) vel = PVector(0.0 ± 0.0 kpc Gyr^-1, 0.0 ± 0.0 kpc Gyr^-1, 0.0 ± 0.0 kpc Gyr^-1) acc = PVector(0.0 ± 0.0 kpc Gyr^-2, 0.0 ± 0.0 kpc Gyr^-2, 0.0 ± 0.0 kpc Gyr^-2) pot = 0.0 ± 0.0 kpc^2 M⊙ Gyr^-2 potpermass = 0.0 ± 0.0 kpc^2 Gyr^-2 mass = 0.0 ± 0.0 M⊙ density = 0.0 M⊙ kpc^-3
julia> ZeroValue(BigFloat) Zero Values: len = 0.0 kpc pos = PVector(0.0 kpc, 0.0 kpc, 0.0 kpc) vel = PVector(0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1, 0.0 kpc Gyr^-1) acc = PVector(0.0 kpc Gyr^-2, 0.0 kpc Gyr^-2, 0.0 kpc Gyr^-2) pot = 0.0 kpc^2 M⊙ Gyr^-2 potpermass = 0.0 kpc^2 Gyr^-2 mass = 0.0 M⊙ density = 0.0 M⊙ kpc^-3