Skip to content

Commit e4b8b55

Browse files
committed
upgraded Quantity as dynamic
1 parent b19a035 commit e4b8b55

File tree

4 files changed

+88
-31
lines changed

4 files changed

+88
-31
lines changed

.appveyor.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ environment:
22
matrix:
33
- julia_version: 1
44
- julia_version: 1.6
5-
- julia_version: 1.8
5+
- julia_version: 1.10
6+
- julia_version: 1.11
67
- julia_version: nightly
78

89
platform:

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MeasureSystems"
22
uuid = "ea45d09e-59d0-491b-a101-09823c6a9fd4"
33
authors = ["Michael Reed"]
4-
version = "0.1.9"
4+
version = "0.2.0"
55

66
[deps]
77
Similitude = "d70e672a-ff44-4dfc-8031-4cc812d84922"
@@ -15,7 +15,7 @@ FieldConstants = "0.1"
1515
FieldAlgebra = "0.1"
1616
Measurements = "2"
1717
UnitSystems = "0.3.8"
18-
Similitude = "0.2.7"
18+
Similitude = "0.3"
1919
julia = "1"
2020

2121
[extras]

README.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,42 @@
55
[![DOI](https://zenodo.org/badge/372081673.svg)](https://zenodo.org/badge/latestdoi/372081673)
66
[![Build status](https://ci.appveyor.com/api/projects/status/rxo2lh76n3dr31c0?svg=true)](https://ci.appveyor.com/project/chakravala/measuresystems-jl)
77

8+
In the base `UnitSystems` package, simply `Float64` numbers are used to generate the group of `UnitSystem` constants.
9+
However, in the `MeasureSystems` package, instead constant measurements are used to generate an abstract multiplicative `Group`, which is only converted to a `Float64` value when appropriate or at compile time.
10+
11+
In `UnitSystems` and `MeasureSystems`, the spectrum of `Group{:Measures}` values is generated by a group of 11 mathematical constants (7 Integer primes and 4 Irrational numbers) with 33 physical measurement definitions.
12+
These are `𝟐`, `𝟑`, `𝟓`, `𝟕`, `𝟏𝟏`, `𝟏𝟗`, `𝟒𝟑`, `φ`, `γ`, ``, `τ`, `kB`, `NA`, `𝘩`, `𝘤`, `𝘦`, `Kcd`, `ΔνCs`, `R∞`, `α`, `μₑᵤ`, `μₚᵤ`, `ΩΛ`, `H0`, `g₀`, `aⱼ`, `au`, `ft`, `ftUS`, `lb`, `T₀`, `atm`, `inHg`, `RK90`, `KJ90`, `RK`, `KJ`, `Rᵤ2014`, `Ωᵢₜ`, `Vᵢₜ`, `kG`, `mP`, `GME`, `GMJ`.
13+
14+
Furthermore, in `MeasureSystems` there is a dimension type which encodes the dimensional `Group{:USQ}` for the `Quantity` type using the same implementation principles as the `Group{:Measures}`.
15+
This enables the unified usage of `Group` homomorphisms to transform `Quantity` algebra elements with varying numbers of dimensionless constants.
16+
17+
Originally, the Newtonian group used for `UnitSystems` would be made up of `force`, `mass`, `length`, `time` (or `F`, `M`, `L`, `T`).
18+
Although `force` is typically thought of as a derived dimension when the reference `gravity` is taken to be dimensionless, `force` is actually considered a base dimension in general engineering `UnitSystem` foundations.
19+
With the development of electricity and magnetism came an interest for an additional dimension called `charge` or `Q`.
20+
When the thermodynamics of `entropy` became further developed, the `temperature` or `Θ` was introduced as another dimension.
21+
In the field of chemistry, it became desirable to introduce another dimension of `molaramount` or `N` as fundamental.
22+
To complete the existing International System of Quantities (ISQ) it is also necessary to consider `luminousflux` or `J` as a visual perception related dimension.
23+
In order to resolve ambiguity with `solidangle` unit conversion, `angle` or `A` is explicitly tracked in the underlying dimension and `Group`.
24+
However, this is yet insufficient to fully specify all the historical variations of `UnitSystem`, including the `EMU`, `ESU`, `Gauss` and `LorentzHeavise` specifications.
25+
Therefore, there is also a dimension basis for `rationalization` (denoted `R`) and `lorentz` (denoted by `C⁻¹`).
26+
27+
In combination, all these required base dimension definitions are necessary in order to coherently implement unit conversion for `Quantity` elements.
28+
Since the existing International System of Quantities (ISQ) is an insufficient definition for dimension, a new Unified System of Quantities (`USQ`) is being proposed here as composed of `force`, `mass`, `length`, `time`, `charge`, `temperature`, `molaramount`, `luminousflux`, `angle`, `rationalization`, and a `nonstandard` dimension (denoted by `F`, `M`, `L`, `T`, `Q`, `Θ`, `N`, `J`, `A`, `R`, `C`).
29+
830
In aggregate, the `UnitSystem` data generated here constitutes a new universal standardization for dimensional analysis, which generalizes upon previous historical systems up to the 2019 redefinition and unifies them in a common `Universe`.
931
This enables a more precise and generalized standardization than the 2019 redefinition, which was comparatively limited in scope.
1032
Specified default `UnitSystem` values are to be taken as a newly defined mutually-compatible recommended standard, verified to be consistent and coherent.
1133
A `UnitSystem` can only be useful as a measuring standard if it can be scientifically reproduced, so the data here has been implemented in several important scientific programming languages (initially in the Julia language but also Wolfram language and Rust langauge) as well as presented abstractly in terms of dimensional formulas.
1234

13-
> In fact there is nothing transcendental about dimensions; the ultimate principle is precisely expressible (in Newton's terminology) as one of *similitude*, exact or approximate, to be tested by the rule that mere change in the magnitudes of the ordered scheme of units of measurement that is employed must not affect sensibly the forms of the equations that are the adequate expression of the underlying relations of the problem. (J.L., 1914)
14-
1535
Specifications for dimensional units are in the [UnitSystems.jl](https://github.com/chakravala/UnitSystems.jl) and [Similitude.jl](https://github.com/chakravala/Similitude.jl) and [MeasureSystems.jl](https://github.com/chakravala/MeasureSystems.jl) repositories.
1636
The three packages are designed so that they can be interchanged with compatibility.
1737
On its own `UnitSystems` is the fastest package, while `Similitude` (provides `Quantity` type) and `MeasureSystems` (introduces [Measurements.jl](https://github.com/JuliaPhysics/Measurements.jl) uncertainty) build additional features on top of `UnitSystems` base defintions.
18-
Additionally, in the `UnitSystems` repository there is an equivalent [Wolfram language paclet](https://reference.wolfram.com/language/guide/Paclets) `Kernel` and also an unmaintained Rust `src` implementation.
1938
Defaults are shared: `Metric`, `SI2019`, `CODATA`, `Conventional`, `International`, `InternationalMean`, `MetricTurn`, `MetricGradian`, `MetricDegree`, `MetricArcminute`, `MetricArcsecond`, `Engineering`, `Gravitational`, `FPS`, `IPS`, `British`, `English`, `Survey`, `Gauss`, `LorentzHeaviside`, `EMU`, `ESU`, `IAU`, `IAUE`, `IAUJ`, `Hubble`, `Cosmological`, `CosmologicalQuantum`, `Meridian`, `Nautical`, `MPH`, `KKH`, `MTS`, `FFF`, `Planck`, `PlanckGauss`, `Stoney`, `Hartree`, `Rydberg`, `Schrodinger`, `Electronic`, `Natural`, `NaturalGauss`, `QCD`, `QCDGauss`, `QCDoriginal`.
2039

2140
```Julia
2241
julia> using MeasureSystems # or UnitSystems or Similitude
2342
```
2443

25-
An optional environment variable `ENV["SIMILITUDE"]` induces `UnitSystems.similitude()` to return `true`, giving flexibility for building dependencies whenever it is desirable to toggle usage between `UnitSystems` (default) and `Similitude` (requires environment variable specification). For example, in `MeasureSystems` and `Geophysics` this option is used to increase flexibility with variety in local compilation workflow.
26-
2744
A `UnitSystem` is a consistent set of dimensional values selected to accomodate a particular use case or standardization.
2845
It is possible to convert derived physical quantities from any `UnitSystem` specification into any other using accurate values.
2946
Eleven fundamental constants `kB`, `ħ`, `𝘤`, `μ₀`, `mₑ`, `Mᵤ`, `Kcd`, `θ`, `λ`, `αL`, `g₀` are used to govern a specific unit system consistent scaling.
@@ -63,12 +80,4 @@ Thermodynamics: `temperature`, `entropy`, `specificentropy`, `volumeheatcapacity
6380
`molarmass`, `molality`, `mole`, `molarity`, `molarvolume`, `molarentropy`, `molarenergy`, `molarconductivity`, `molarsusceptibility`, `catalysis`, `specificity`, `diffusionflux`,
6481
`luminousflux`, `luminousintensity`, `luminance`, `illuminance`, `luminousenergy`, `luminousexposure`, `luminousefficacy`.
6582

66-
**Generalized dimensionless `Coupling`:**
67-
68-
```Julia
69-
Coupling{αG,α,μₑᵤ,μₚᵤ,ΩΛ}
70-
```
71-
Specification of `Universe` with the dimensionless `Coupling` constants `coupling`, `finestructure`, `electronunit`, `protonunit`, `protonelectron`, and `darkenergydensity`. Alterations to these values can be facilitated and quantified using parametric polymorphism.
72-
Due to the `Coupling` interoperability, the `MeasureSystems` package is made possible to support calculations with `Measurements` having error standard deviations.
73-
7483
Other similar packages include [UnitSystems.jl](https://github.com/chakravala/UnitSystems.jl), [Similitude.jl](https://github.com/chakravala/Similitude.jl), [PhysicalConstants.jl](https://github.com/JuliaPhysics/PhysicalConstants.jl), [MathPhysicalConstants.jl](https://github.com/LaGuer/MathPhysicalConstants.jl), [Unitful.jl](https://github.com/PainterQubits/Unitful.jl.git), [UnitfulUS.jl](https://github.com/PainterQubits/UnitfulUS.jl), [UnitfulAstro.jl](https://github.com/JuliaAstro/UnitfulAstro.jl), [UnitfulAtomic.jl](https://github.com/sostock/UnitfulAtomic.jl), [NaturallyUnitful.jl](https://github.com/MasonProtter/NaturallyUnitful.jl), and [UnitfulMoles.jl](https://github.com/rafaqz/UnitfulMoles.jl).

src/MeasureSystems.jl

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,22 @@ import Base: @pure, angle
2121
import UnitSystems
2222
import UnitSystems: UnitSystem, Systems, Constants, Physics, Convert, Dimensionless
2323
import UnitSystems: Coupling, measure, unit, universe, cache, Derived, logdb, expdb, dB
24-
export UnitSystems, Measure, measure, cache, Constant
24+
export UnitSystems, Measure, measure, cache, Constant, dimensions
2525
const dir = dirname(pathof(UnitSystems))
2626

27+
const usingSimilitude = true #UnitSystems.similitude()
28+
29+
if usingSimilitude
30+
import Similitude: CONSTDIM, CONSTVAL
31+
else
32+
const CONSTDIM = true
33+
const CONSTVAL = CONSTDIM
34+
end
2735
macro group(args...)
28-
FieldAlgebra.group(args...)
36+
CONSTDIM ? FieldAlgebra.group(args...) : FieldAlgebra.group2(args...)
37+
end
38+
macro group2(args...)
39+
CONSTVAL ? FieldAlgebra.group(args...) : FieldAlgebra.group2(args...)
2940
end
3041

3142
# measure
@@ -179,8 +190,6 @@ end
179190

180191
# unit systems
181192

182-
const usingSimilitude = true #UnitSystems.similitude()
183-
184193
if !usingSimilitude
185194
import UnitSystems: two, three, five, eleven, nineteen, fourtythree
186195
import UnitSystems: golden, eulergamma, tau
@@ -227,17 +236,32 @@ end
227236
if usingSimilitude
228237
export Similitude, 𝟙, Unified, quotient
229238
import Similitude
230-
import Similitude: Unified, coefprod, promoteint, USQ, quotient,dimlatex, morphism
231-
import Similitude: Group,AbelianGroup,LogGroup,ExpGroup,Quantity,Dimension,Quantities,𝟙,usq
232-
import Similitude: Values,value,vals,basis,valueat,showgroup,ratio,isq,dims,dimtext
239+
import Similitude: Unified, coefprod, promoteint, USQ, quotient, dimlatex, dimtext
240+
import Similitude: Group, AbelianGroup, LogGroup, ExpGroup, Quantity, Dimension, Quantities
241+
import Similitude: Values, value, vals, basis, valueat, showgroup, isq, dims, 𝟙,usq
242+
import Similitude: ratio, morphism, dimensions
233243
import FieldAlgebra: makeint, product
234244
for D (:F,:M,:L,:T,:Q,,:N,:J,:A,:R,:C)
235-
@eval const $D = Similitude.$D
245+
if CONSTDIM==Similitude.CONSTDIM
246+
@eval const $D = Similitude.$D
247+
elseif CONSTDIM
248+
@eval const $D = Constant(Similitude.$D)
249+
else
250+
@eval const $D = Similitude.param(Similitude.$D)
251+
end
236252
end
253+
Base.:*(a::Quantity{U},b::Measure) where U = Quantity{U}(cache(a.v*measure(b)),Similitude.dimensions(a))
254+
Base.:*(a::Measure,b::Quantity{U}) where U = Quantity{U}(cache(measure(a)*b.v),Similitude.dimensions(b))
255+
Base.:/(a::Quantity{U},b::Measure) where U = Quantity{U}(cache(a.v/measure(b)),Similitude.dimensions(a))
256+
Base.:/(a::Measure,b::Quantity{U}) where U = Quantity{U}(cache(measure(a)/b.v),Similitude.dimensions(b))
257+
Base.:+(a::Quantity{U},b::Measure) where U = Quantity{U}(cache(a.v+measure(b)),Similitude.dimensions(a))
258+
Base.:+(a::Measure,b::Quantity{U}) where U = Quantity{U}(cache(measure(a)-b.v),Similitude.dimensions(b))
259+
Base.:-(a::Quantity{U},b::Measure) where U = Quantity{U}(cache(a.v-measure(b)),Similitude.dimensions(a))
260+
Base.:-(a::Measure,b::Quantity{U}) where U = Quantity{U}(cache(measure(a)-b.v),Similitude.dimensions(b))
237261
FieldAlgebra.makeint(x::MeasureSystems.Measurements.Measurement) = x
238262
FieldAlgebra.promoteint(x::Measure) = x
239263
FieldAlgebra.latext(::Group{:Measures}) = Similitude.usqlatex
240-
@group Measures begin
264+
@group2 Measures begin
241265
kB = UnitSystems.kB
242266
NA = UnitSystems.NA
243267
𝘩 = UnitSystems.𝘩
@@ -284,7 +308,11 @@ FieldAlgebra.latext(::Group{:Measures}) = Similitude.usqlatex
284308
43 = 43
285309
end
286310
Base.show(io::IO,x::Group{:Measures}) = showgroup(io,x,basis,'𝟏')
287-
phys(j,k=vals) = Constant(valueat(j,k,:Measures))
311+
if CONSTVAL
312+
phys(j,k=vals) = Constant(valueat(j,k,:Measures))
313+
else
314+
phys(j,k=vals) = valueat(j,k,:Measures)
315+
end
288316
const sim = dirname(pathof(Similitude))
289317
include("$sim/constant.jl")
290318
Base.:*(a::Measure,b::Group{G,T,S,N}) where {G,T,S,N} = FieldAlgebra.times(factorize(a,Val(G)),b)
@@ -325,7 +353,7 @@ Base.:-(a::Measurements.Measurement,b::Constant{D}) where D = a-D
325353
Base.:-(a::Constant{D},b::Measurements.Measurement) where D = D-b
326354
else
327355
Constant(x) = x
328-
Quantity(x) = Constant(x)
356+
Quantity(x) = CONSTVAL ? Constant(x) : x
329357
Base.:*(a::Measurements.Measurement,b::UnitSystems.Constant{D}) where D = a*D
330358
Base.:*(a::UnitSystems.Constant{D},b::Measurements.Measurement) where D = D*b
331359
Base.:/(a::Measurements.Measurement,b::UnitSystems.Constant{D}) where D = a*inv(b)
@@ -356,10 +384,16 @@ import UnitSystems: RK1990,KJ1990,𝟏,𝟐,𝟑,𝟓,𝟕,𝟏𝟏,𝟏𝟗,
356384
const RK90,KJ90 = RK1990,KJ1990
357385
end
358386

359-
const LD,JD = Constant(384399)*(𝟐*𝟓)^3,Constant(778479)*(𝟐*𝟓)^6
360-
const μE☾ = Constant(measurement("81.300568(3)"))
387+
if CONSTVAL
388+
const LD,JD = Constant(384399)*(𝟐*𝟓)^3,Constant(778479)*(𝟐*𝟓)^6
389+
const μE☾ = Constant(measurement("81.300568(3)"))
390+
else
391+
const LD,JD = 384399*(𝟐*𝟓)^3,778479*(𝟐*𝟓)^6
392+
const μE☾ = measurement("81.300568(3)")
393+
end
361394

362395
import UnitSystems: GaussSystem, ElectricSystem, EntropySystem, AstronomicalSystem, unitname, normal
396+
println("MeasureSystems: initializing UnitSystems data")
363397
include("$dir/initdata.jl")
364398

365399
#const μ₀ = 2𝘩/𝘤/αinv/𝘦^2 # ≈ 4π*(1e-7+5.5e-17), exact charge
@@ -372,11 +406,17 @@ for unit ∈ UnitSystems.Convert
372406
@eval const $unit = Similitude.$unit
373407
end
374408
end
409+
println("MeasureSystems: deriving Quantity measurements")
375410
include("$sim/derived.jl")
411+
println("MeasureSystems: documenting kinematic units")
376412
include("$dir/kinematicdocs.jl")
413+
println("MeasureSystems: documenting electromagnetic units")
377414
include("$dir/electromagneticdocs.jl")
415+
println("MeasureSystems: documenting thermodynamic units")
378416
include("$dir/thermodynamicdocs.jl")
417+
println("MeasureSystems: documenting physics constants")
379418
include("$dir/physicsdocs.jl")
419+
println("MeasureSystems: documenting UnitSystems")
380420
include("$dir/systems.jl")
381421
else
382422
for CAL (:calₜₕ,:cal₄,:cal₁₀,:cal₂₀,:calₘ,:calᵢₜ)
@@ -385,8 +425,13 @@ for CAL ∈ (:calₜₕ,:cal₄,:cal₁₀,:cal₂₀,:calₘ,:calᵢₜ)
385425
end
386426
import UnitSystems: convertext, unitext
387427
const dir = dirname(pathof(UnitSystems))
388-
const zetta,zepto = Constant(1e21),Constant(1e-21)
389-
const yotta,yocto = Constant(1e24),Constant(1e-24)
428+
if CONSTVAL
429+
const zetta,zepto = Constant(1e21),Constant(1e-21)
430+
const yotta,yocto = Constant(1e24),Constant(1e-24)
431+
else
432+
const zetta,zepto = 1e21,1e-21
433+
const yotta,yocto = 1e24,1e-24
434+
end
390435
include("$dir/kinematic.jl")
391436
include("$dir/electromagnetic.jl")
392437
include("$dir/thermodynamic.jl")
@@ -396,6 +441,7 @@ end
396441

397442
# physical constants
398443

444+
if CONSTVAL
399445
@pure electronmass(U::typeof(Planck),C::Coupling) = sqrt(4π*coupling(C))
400446
@pure electronmass(U::typeof(PlanckGauss),C::Coupling) = sqrt(coupling(C))
401447
@pure electronmass(U::UnitSystem{kB,ħ,𝘤,μ₀,cache(√(αG*αinv))},C::Coupling) where {kB,ħ,𝘤,μ₀} = sqrt(coupling(C)/finestructure(C))
@@ -415,5 +461,6 @@ end
415461
@pure vacuumpermeability(U::UnitSystem{kB,ħ,𝘤,cache(μ₀)},C::Coupling) where {kB,ħ,𝘤} = finestructure(C)*2𝘩/𝘤/𝘦^2
416462
@pure vacuumpermeability(U::typeof(CODATA),C::Coupling) = 2RK2014*finestructure(C)/𝘤
417463
@pure vacuumpermeability(U::typeof(Conventional),C::Coupling) = 2RK1990*finestructure(C)/𝘤
464+
end
418465

419466
end # module

0 commit comments

Comments
 (0)