Skip to content

Commit

Permalink
upgraded to UnitSystems v0.3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed May 27, 2022
1 parent 27d7640 commit d92144f
Show file tree
Hide file tree
Showing 7 changed files with 320 additions and 116 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Similitude"
uuid = "d70e672a-ff44-4dfc-8031-4cc812d84922"
authors = ["Michael Reed"]
version = "0.2.4"
version = "0.2.5"

[deps]
UnitSystems = "3a241a3c-2137-41aa-af5e-1388e404ca09"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ Unit conversion documentation is at https://geophysics.crucialflow.com/dev/conve

**Derived Unit conversions:**

Mechanics: `angle`, `solidangle`, `time`, `length`, `area`, `volume`, `wavenumber`, `angularwavenumber`, `fuelefficiency`, `numberdensity`, `frequency`, `angularfrequency`, `frequencydrift`, `speed`, `acceleration`, `jerk`, `snap`, `crackle`, `pop`, `volumeflow`,
Mechanics: `angle`, `solidangle`, `time`, `angulartime`, `length`, `angularlength`, `area`, `angulararea`, `volume`, `wavenumber`, `angularwavenumber`, `fuelefficiency`, `numberdensity`, `frequency`, `angularfrequency`, `frequencydrift`, `stagnance`, `speed`, `acceleration`, `jerk`, `snap`, `crackle`, `pop`, `volumeflow`, `etendue`, `photonintensity`, `photonirradiance`, `photonradiance`,
`inertia`, `mass`, `massflow`, `lineardensity`, `areadensity`, `density`, `specificweight`, `specificvolume`, `force`, `specificforce`, `gravityforce`, `pressure`, `compressibility`, `viscosity`, `diffusivity`, `rotationalinertia`, `impulse`, `momentum`, `angularmomentum`, `yank`, `energy`, `specificenergy`, `action`, `fluence`, `power`, `powerdensity`, `irradiance`, `radiance`, `radiantintensity`, `spectralflux`, `spectralexposure`, `soundexposure`, `impedance`, `specificimpedance`, `admittance`, `compliance`, `inertance`;
Electromagnetics: `charge`, `chargedensity`, `linearchargedensity`, `exposure`, `mobility`, `current`, `currentdensity`, `resistance`, `conductance`, `resistivity`, `conductivity`, `capacitance`, `inductance`, `reluctance`, `permeance`, `permittivity`, `permeability`, `susceptibility`, `specificsusceptibility`, `demagnetizingfactor`, `vectorpotential`, `electricpotential`, `magneticpotential`, `electricfield`, `magneticfield`, `electricflux`, `magneticflux`, `electricfluxdensity`, `magneticfluxdensity`, `electricdipolemoment`, `magneticdipolemoment`, `electricpolarizability`, `magneticpolarizability`, `magneticmoment`, `specificmagnetization`, `polestrength`;
Electromagnetics: `charge`, `chargedensity`, `linearchargedensity`, `exposure`, `mobility`, `current`, `currentdensity`, `resistance`, `conductance`, `resistivity`, `conductivity`, `capacitance`, `inductance`, `reluctance`, `permeance`, `permittivity`, `permeability`, `susceptibility`, `specificsusceptibility`, `demagnetizingfactor`, `vectorpotential`, `electricpotential`, `magneticpotential`, `electricfield`, `magneticfield`, `electricflux`, `magneticflux`, `electricdisplacement`, `magneticfluxdensity`, `electricdipolemoment`, `magneticdipolemoment`, `electricpolarizability`, `magneticpolarizability`, `magneticmoment`, `specificmagnetization`, `polestrength`;
Thermodynamics: `temperature`, `entropy`, `specificentropy`, `volumeheatcapacity`, `thermalconductivity`, `thermalconductance`, `thermalresistivity`, `thermalresistance`, `thermalexpansion`, `lapserate`,
`molarmass`, `molality`, `mole`, `molarity`, `molarvolume`, `molarentropy`, `molarenergy`, `molarconductivity`, `molarsusceptibility`, `catalysis`, `specificity`,
`molarmass`, `molality`, `mole`, `molarity`, `molarvolume`, `molarentropy`, `molarenergy`, `molarconductivity`, `molarsusceptibility`, `catalysis`, `specificity`, `diffusionflux`,
`luminousflux`, `luminousintensity`, `luminance`, `illuminance`, `luminousenergy`, `luminousexposure`, `luminousefficacy`.

**Generalized dimensionless `Coupling`:**
Expand Down
159 changes: 141 additions & 18 deletions src/Similitude.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,48 +84,45 @@ function Quantity(u::UnitSystem)
kB = Quantity{F*L/Θ,U}(UnitSystems.boltzmann(U))
ħ = Quantity{F*L*T/A,U}(UnitSystems.planckreduced(U))
c = Quantity{L/T,U}(UnitSystems.lightspeed(U))
μ0 = Quantity{F*T*T*C*C/(Q*Q*A*A)/Λ,U}(UnitSystems.permeability(U))
μ0 = Quantity{F*T*T*C*C/(Q*Q)/R,U}(UnitSystems.permeability(U))
mₑ = Quantity{M,U}(UnitSystems.electronmass(U))
Mᵤ = Quantity{M/N,U}(UnitSystems.molarmass(U))
Kcd = Quantity{J*T/F/L,U}(UnitSystems.luminousefficacy(U))
a = Quantity{𝟙,U}(UnitSystems.angle(U))
λ = Quantity{Λ*A*A,U}(UnitSystems.rationalization(U))
θ = Quantity{A,U}(UnitSystems.angle(U))
λ = Quantity{R,U}(UnitSystems.rationalization(U))
αL = Quantity{inv(C),U}(UnitSystems.lorentz(U))
g₀ = Quantity{M*L/(F*T*T),U}(UnitSystems.gravity(U))
τ = Quantity{A,U}(UnitSystems.twopi(U))
τ = UnitSystems.tau(U)
x = UnitSystems.two(U)
y = UnitSystems.three(U)
z = UnitSystems.five(U)
u = UnitSystems.seven(U)
v = UnitSystems.eleven(U)
w = UnitSystems.nineteen(U)
q = UnitSystems.fourtythree(U)
UnitSystem(kB,ħ,c,μ0,mₑ,Mᵤ,Kcd,a,λ,αL,g₀,Universe,τ,x,y,z,u,v,w,q)
UnitSystem(kB,ħ,c,μ0,mₑ,Mᵤ,Kcd,θ,λ,αL,g₀,Universe,τ,x,y,z,u,v,w,q)
end

const LD,JD = Constant(384399)*𝟏𝟎^3,Constant(778479)*𝟏𝟎^6
const LD,JD = Constant(384399)*(𝟐*𝟓)^3,Constant(778479)*(𝟐*𝟓)^6
const μE☾ = Constant(UnitSystems.μE☾)

import UnitSystems: GaussSystem, EntropySystem, ElectricSystem, AstronomicalSystem
include("$dir/initdata.jl")

const Unified = Quantity(UnitSystem(F*L/Θ,F*L*T/A,L/T,F*T*T*C*C/(Q*Q)/R,M,M/N,J*T/F/L,A,R,inv(C),M*L/(F*T*T),Universe,τ,𝟐,𝟑,𝟓,𝟕,𝟏𝟏,𝟏𝟗,𝟒𝟑))
dimtext(::typeof(normal(Unified))) = Values("kB","ħ","𝘤","μ₀","mₑ","Mᵤ","Kcd","ϕ","λ","αL","g₀")

export Unified
unitname(::typeof(normal(Unified))) = "Unified"
(u::typeof(normal(Unified)))(d::Group) = UnitSystem(d)
(u::UnitSystem)(d::Group) = normal(Metric)(d)

for unit Convert
if unit (:length,:time,:angle,:molarmass,:luminousintensity,:luminance,:luminousefficacy,:angularfrequency,:angularwavenumber,:angularmomentum,:solidangle,:magneticdipolemoment,:radiantintensity,:radiance)
if unit (:length,:time,:angle,:molarmass,:luminousefficacy)
@eval const $unit = dimensions(UnitSystems.$unit(UnitSystems.Natural,Natural))
end
end
const gravityforce = acceleration/specificforce
const solidangle = A*A
const angularfrequency = A/T
const angularwavenumber = A/L
const angularmomentum = F*L*T*A
const magneticdipolemoment = F/M*L*T*Q/A/C
const luminousintensity = luminousflux/solidangle
const luminance = luminousintensity/area
const radiantintensity = power/solidangle
const radiance = radiantintensity/area

@doc """
(D::Dimension)(U::UnitSystem,S::UnitSystem) = ConvertUnit{D,U,S}()
Expand All @@ -142,7 +139,7 @@ There still exists further opportunity to expand on the implementation of `Conve
""" ConvertUnit

@doc """
(U::UnitSystem)(v::Number, D::Dimension) = Quantity{D,U}(v)
(U::UnitSystem)(v::Number, D::Dimension) ↦ Quantity(D,U,v) = Quantity{D,U}(v)
Numerical `Quantity` having value `v` with `D::Dimension` specified in `U::UnitSystem`.
```Julia
Expand All @@ -152,17 +149,143 @@ $(Metric(1,energy))
julia> English(1,energy)
$(English(1,energy))
```
There still exists further opportunity to expand on the implementation of `Quantity`.
An alternate syntax `Quantity(D::Dimension, U::UnitSystem, v::Number)` is also available as standard syntax.
When `using UnitSystems` instead of `using Similitude`, this same syntax can be written so that code doesn't need to be changed while the output is generated.
""" Quantity

include("derived.jl")

(u::typeof(normal(UnitSystems.QCD)))(d::Group) = normal(Planck)(d)

for dim (:angle, :length, :time)
@eval begin
Base.sqrt(x::typeof($dim)) = sqrt(evaldim(x))
Base.cbrt(x::typeof($dim)) = cbrt(evaldim(x))
Base.inv(x::typeof($dim)) = inv(evaldim(x))
Base.log(x::typeof($dim)) = log(evaldim(x))
Base.log2(x::typeof($dim)) = log2(evaldim(x))
Base.log10(x::typeof($dim)) = log10(evaldim(x))
Base.log(b::Number,x::typeof($dim)) = log(b,evaldim(x))
Base.exp(x::typeof($dim)) = exp(evaldim(x))
Base.exp2(x::typeof($dim)) = exp2(evaldim(x))
Base.exp10(x::typeof($dim)) = exp10(evaldim(x))
Base.:^(b::T,x::typeof($dim)) where T<:Number = b^evaldim(x)
Base.:^(a::typeof($dim),b::Number) = evaldim(a)^b
Base.:^(a::typeof($dim),b::Integer) = evaldim(a)^b
Base.:^(a::typeof($dim),b::Rational) = evaldim(a)^b
Base.:*(a::typeof($dim),b::Dimension) = evaldim(a)*b
Base.:/(a::typeof($dim),b::Dimension) = evaldim(a)/b
Base.:*(a::Dimension,b::typeof($dim)) = a*evaldim(b)
Base.:/(a::Dimension,b::typeof($dim)) = a/evaldim(b)
Base.:*(a::Number,b::typeof($dim)) = a*evaldim(b)
Base.:*(a::typeof($dim),b::Number) = evaldim(a)*b
Base.:/(a::Number,b::typeof($dim)) = a*inv(evaldim(b))
Base.:/(a::typeof($dim),b::Number) = evaldim(a)*inv(b)
end
for dim2 (:angle, :length, :time)
@eval begin
Base.:*(a::typeof($dim),b::typeof($dim2)) = evaldim(a)*evaldim(b)
Base.:/(a::typeof($dim),b::typeof($dim2)) = evaldim(a)*evaldim(b)
end
end
end

include("$dir/kinematicdocs.jl")
include("$dir/electromagneticdocs.jl")
include("$dir/thermodynamicdocs.jl")
include("$dir/physicsdocs.jl")
include("$dir/systems.jl")

@doc """
Dimension{D} <: AbstractModule
Physical `Dimension` represented by `Group` element `D`.
```Julia
F, M, L, T, Q, Θ, N, J, A, R, C
```
Operations on `Dimension` are closed (`*`, `/`, `+`, `-`, `^`).
```Julia
julia> force(Unified)
$(force(Unified))
julia> mass(Unified)
$(mass(Unified))
julia> length(Unified)
$(length(Unified))
julia> time(Unified)
$(time(Unified))
julia> charge(Unified)
$(charge(Unified))
julia> temperature(Unified)
$(temperature(Unified))
julia> molaramount(Unified)
$(molaramount(Unified))
julia> luminousflux(Unified)
$(luminousflux(Unified))
julia> angle(Unified)
$(angle(Unified))
julia> rationalization(Unified)
$(rationalization(Unified))
julia> lorentz(Unified)
$(lorentz(Unified))
```
Derived `Dimension` can be obtained from multiplicative base of 11 fundamental `Dimension` symbols corresponding to `force`, `mass`, `length`, `time`, `charge`, `temperature`, `molaramount`, `luminousflux`, `angle`, `demagnetizingfactor`, and a `nonstandard` dimension.
Mechanics: `angle`, `$(listext(Kinematic))`, `$(listext(Mechanical))`;
Electromagnetics: `$(listext(Electromagnetic))`;
Thermodynamics: `$(listext(Thermodynamic))`,
`$(listext(Molar))`, `$(listext(Photometric))`.
""" Dimension

@doc """
Unified = UnitSystem(...) # Unified System of Quantities (USQ)
F, M, L, T, Q, Θ, N, J, A, R, C # fundamental base dimensions
Standard `Unified` system of `Quantities` (USQ) in terms of `UnitSystem` basis, transformed from the basis of `force`, `mass`, `length`, `time`, `charge`, `temperature`, `molaramount`, `luminousflux`, `angle`, `rationalization`, and a `nonstandard` dimension.
```Julia
julia> boltzmann(Unified) # entropy
$(boltzmann(Unified))
julia> planckreduced(Unified) # angularmomentum
$(planckreduced(Unified))
julia> lightspeed(Unified) # speed
$(lightspeed(Unified))
julia> vacuumpermeability(Unified) # permeability
$(vacuumpermeability(Unified))
julia> electronmass(Unified) # mass
$(electronmass(Unified))
julia> molarmass(Unified) # molarmass
$(molarmass(Unified))
julia> luminousefficacy(Unified) # luminousefficacy
$(luminousefficacy(Unified))
julia> radian(Unified) # angle
$(radian(Unified))
julia> rationalization(Unified) # demagnetizingfactor
$(rationalization(Unified))
julia> lorentz(Unified) # nonstandard
$(lorentz(Unified))
julia> gravity(Unified) # gravityforce
$(gravity(Unified))
```
""" Unified

end # module
64 changes: 42 additions & 22 deletions src/constant.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,47 @@
# https://github.com/chakravala
# https://crucialflow.com

import UnitSystems: isconstant

include("$dir/constant.jl")

@pure factorize(x,a,b,c,d,e,f,g,h) = Similitude.factorize(x,param(a),param(b),param(c),param(d),param(e),param(f),param(g),param(h))

@pure Constant(D::Number) = 𝟏*D
@pure Constant(D::Float64) = Constant(factorize(D,τ,𝟐,𝟑,𝟓,𝟕,𝟏𝟏,𝟏𝟗,𝟒𝟑))
@pure Constant(D::Int) = Constant(factorize(D,τ,𝟐,𝟑,𝟓,𝟕,𝟏𝟏,𝟏𝟗,𝟒𝟑))
@pure Constant(D::Constant) = D
@pure Constant(D::AbelianGroup) = Constant{D}()
@pure Constant(N::Number) = 𝟏*N
@pure Constant(D::Dimension) = D
@pure Constant(::typeof(MathConstants.φ)) = φ
@pure Constant(::typeof(MathConstants.γ)) = Constant(valueat(35,vals))
@pure Constant(::typeof(ℯ)) = Constant(valueat(36,vals))
@pure Constant(::typeof(π)) = τ/𝟐
@pure Constant(::typeof(exp)) = Constant(ℯ)
@pure Constant(N::Float64) = Constant(factorize(N,τ,𝟐,𝟑,𝟓,𝟕,𝟏𝟏,𝟏𝟗,𝟒𝟑))
@pure Constant(N::Int) = Constant(factorize(N,τ,𝟐,𝟑,𝟓,𝟕,𝟏𝟏,𝟏𝟗,𝟒𝟑))
@pure Constant(N::AbelianGroup) = Constant{N}()

#printone(io::IO,::Val{vals}) = print(io, '𝟏')
Base.show(io::IO,x::Constant{D}) where D = (showgroup(io,D,Natural,'𝟏'); print(io, " = ", constant(D)))
Base.show(io::IO,x::Constant{N}) where N = (showgroup(io,N,Natural,'𝟏'); print(io, " = ", constant(N)))

@pure constant(::Constant{D}) where D = constant(D)
@pure constant(::Constant{N}) where N = constant(N)
constant(d::LogGroup{B},C=UnitSystems.Universe) where B = log(B,constant(value(d),C))
constant(d::ExpGroup{B},C=UnitSystems.Universe) where B = B^constant(value(d),C)

UnitSystems.unit(x::Constant,y=1) = x
@pure promoteint(v::Constant) = isone(v) ? 1 : v

Base.:^(::UnitSystems.Constant{A},::Constant{B}) where {A,B} = Constant{A^B}()
Base.:*(::UnitSystems.Constant{A},b::Constant) where A = Constant(A)*b
Base.:*(a::Constant,::UnitSystems.Constant{B}) where B = a*Constant(B)
Base.:/(::UnitSystems.Constant{A},b::Constant) where A = Constant(A)/b
Base.:/(a::Constant,::UnitSystems.Constant{B}) where B = a/Constant(B)

#Base.:*(a::Constant{N},b::Dimension{D}) where {N,D} = Dimension{N*D}()
#Base.:*(a::Dimension{D},b::Constant{N}) where {D,N} = Dimension{D*N}()
Base.:/(a::Constant,b::Dimension) = a*inv(b)
Base.:/(a::Dimension,b::Constant) = a*inv(b)

Base.:*(a::UnitSystems.Constant{A},b::Constant{B}) where {A,B} = Constant{A*B}()
Base.:*(a::Constant{A},b::UnitSystems.Constant{B}) where {A,B} = Constant{A*B}()
Base.:/(a::UnitSystems.Constant{A},b::Constant{B}) where {A,B} = Constant{A/B}()
Base.:/(a::Constant{A},b::UnitSystems.Constant{B}) where {A,B} = Constant{A/B}()
coefprod(a::Constant,b) = a*Constant(b)
coefprod(a,b::Constant) = Constant(a)*b
coefprod(a::Constant,b::Constant) = a*b

Base.:+(a::Constant,b::Similitude.Quantity{D,U}) where {D,U} = U(D)==𝟙 ? Similitude.Quantity{D,U}(a+b.v) : throw(error("$(U(D)) ≠ 𝟙 "))
Base.:+(a::Similitude.Quantity{D,U},b::Constant) where {D,U} = U(D)==𝟙 ? Similitude.Quantity{D,U}(a.v+b) : throw(error("$(U(D)) ≠ 𝟙 "))
Expand All @@ -47,7 +65,7 @@ Base.:/(a::Similitude.Quantity{D,U},b::Constant) where {D,U} = Similitude.Quanti

phys(j,k=vals) = Constant(valueat(j,k))

for i 1:vals-10
for i 1:vals-11
@eval begin
export $(Symbol(basis[i]))
const $(Symbol(basis[i])) = Constant(valueat($i,vals))
Expand All @@ -56,17 +74,19 @@ end

export factorize

const τ = Constant(valueat(37,vals))
const golden = Constant(valueat(34,vals))
const eulergamma = Constant(valueat(35,vals))
const tau = Constant(valueat(37,vals))
const 𝟏 = Constant(valueat(0,vals))
const 𝟐 = Constant(valueat(38,vals))
const 𝟑 = Constant(valueat(39,vals))
const 𝟓 = Constant(valueat(40,vals))
const 𝟕 = Constant(valueat(41,vals))
const 𝟏𝟏 = Constant(valueat(42,vals))
const 𝟏𝟗 = Constant(valueat(43,vals))
const 𝟒𝟑 = Constant(valueat(44,vals))
const 𝟏𝟎 = 𝟐*𝟓
const two = Constant(valueat(38,vals))
const three = Constant(valueat(39,vals))
const five = Constant(valueat(40,vals))
const seven = Constant(valueat(41,vals))
const eleven = Constant(valueat(42,vals))
const nineteen = Constant(valueat(43,vals))
const fourtythree = Constant(valueat(44,vals))
const 𝟐,𝟑,𝟓,𝟕,𝟏𝟏,𝟏𝟗,𝟒𝟑 = two,three,five,seven,eleven,nineteen,fourtythree
const zetta,zepto,yotta,yocto = (𝟐*𝟓)^21, (𝟐*𝟓)^-21, (𝟐*𝟓)^24, (𝟐*𝟓)^-24
const αinv = inv(α)
const αinv,φ,τ = inv(α),golden,tau
const RK1990,KJ1990 = RK90,KJ90
const RK2014,KJ2014 = RK,KJ
Loading

2 comments on commit d92144f

@chakravala
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/61193

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.5 -m "<description of version>" d92144f13958bf5c27103806e9b89e2af61f2147
git push origin v0.2.5

Please sign in to comment.