Skip to content

Commit

Permalink
transitioned to FieldAlgebra
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Oct 5, 2022
1 parent e2b87e3 commit e311bfb
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ environment:
matrix:
- julia_version: 1
- julia_version: 1.6
- julia_version: 1.7
- julia_version: 1.8
- julia_version: nightly

platform:
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ os:
julia:
- 1.0
- 1.6
- 1.7
- 1.8
- nightly
matrix:
allow_failures:
Expand Down
11 changes: 7 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
name = "MeasureSystems"
uuid = "ea45d09e-59d0-491b-a101-09823c6a9fd4"
authors = ["Michael Reed"]
version = "0.1.5"
version = "0.1.6"

[deps]
Similitude = "d70e672a-ff44-4dfc-8031-4cc812d84922"
UnitSystems = "3a241a3c-2137-41aa-af5e-1388e404ca09"
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"

FieldAlgebra = "0b62d163-fd1d-4060-a953-4385d03545e2"
FieldConstants = "73d362c4-b7ec-495f-a538-f22f12d4d8ae"

[compat]
FieldConstants = "0.1"
FieldAlgebra = "0.1"
Measurements = "2"
UnitSystems = "0.3.4"
Similitude = "0.2"
UnitSystems = "0.3.8"
Similitude = "0.2.6"
julia = "1"

[extras]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ additional constants `molarmass`, `luminousefficacy`, `gravity`, `angle`, `turn`

Physics constant documentation is at https://geophysics.crucialflow.com/dev/constants

Standardized unit/derived quantities are `hyperfine`, `loschmidt`, `wienwavelength`, `wienfrequency`, `mechanicalheat`, `eddington`, `solarmass`, `jupitermass`, `earthmass`, `lunarmass`, `earthradius`, `greatcircle`, `radarmile`, `hubble`, `cosmological`, `radian`, `steradian`, `degree`, `squaredegree`, `gradian`, `arcminute`, `arcsecond`, `second`, `minute`, `hour`, `day`, `gaussianmonth`, `siderealmonth`, `synodicmonth`, `year`, `gaussianyear`, `siderealyear`, `jovianyear`, `angstrom`, `inch`, `foot`, `surveyfoot`, `yard`, `meter`, `earthmeter`, `mile`, `statutemile`, `meridianmile`, `admiraltymile`, `nauticalmile`, `lunardistance`, `astronomicalunit`, `jupiterdistance`, `lightyear`, `parsec`, `bubnoff`, `ips`, `fps`, `fpm`, `ms`, `kmh`, `mph`, `knot`, `mps`, `barn`, `hectare`, `acre`, `surveyacre`, `liter`, `gallon`, `quart`, `pint`, `cup`, `fluidounce`, `teaspoon`, `tablespoon`, `grain`, `gram`, `earthgram`, `kilogram`, `tonne`, `ton`, `pound`, `ounce`, `slug`, `slinch`, `hyl`, `dyne`, `newton`, `poundal`, `poundforce`, `kilopond`, `psi`, `pascal`, `bar`, `barye`, `technicalatmosphere`, `atmosphere`, `inchmercury`, `torr`, `electronvolt`, `erg`, `joule`, `footpound`, `calorie`, `kilocalorie`, `meancalorie`, `earthcalorie`, `thermalunit`, `gasgallon`, `tontnt`, `watt`, `horsepower`, `horsepowerwatt`, `horsepowermetric`, `electricalhorsepower`, `tonsrefrigeration`, `boilerhorsepower`, `coulomb`, `earthcoulomb`, `ampere`, `volt`, `henry`, `ohm`, `siemens`, `farad`, `weber`, `tesla`, `abcoulomb`, `abampere`, `abvolt`, `abhenry`, `abohm`, `abmho`, `abfarad`, `maxwell`, `gauss`, `oersted`, `gilbert`, `statcoulomb`, `statampere`, `statvolt`, `stathenry`, `statohm`, `statmho`, `statfarad`, `statweber`, `stattesla`, `kelvin`, `rankine`, `celsius`, `fahrenheit`, `sealevel`, `boiling`, `mole`, `earthmole`, `poundmole`, `slugmole`, `slinchmole`, `katal`, `amagat`, `lumen`, `candela`, `lux`, `phot`, `footcandle`, `nit`, `apostilb`, `stilb`, `lambert`, `footlambert`, `bril`, `neper`, `bel`, `decibel`, `hertz`, `apm`, `rpm`, `kayser`, `diopter`, `gforce`, `galileo`, `eotvos`, `darcy`, `poise`, `reyn`, `stokes`, `rayl`, `mpge`, `langley`, `jansky`, `solarflux`, `curie`, `sievert`, `roentgen`, `rem`.
Standardized unit/derived quantities are `hyperfine`, `loschmidt`, `wienwavelength`, `wienfrequency`, `mechanicalheat`, `eddington`, `solarmass`, `jupitermass`, `earthmass`, `lunarmass`, `earthradius`, `greatcircle`, `radarmile`, `hubble`, `cosmological`, `radian`, `steradian`, `degree`, `squaredegree`, `gradian`, `arcminute`, `arcsecond`, `second`, `minute`, `hour`, `day`, `gaussianmonth`, `siderealmonth`, `synodicmonth`, `year`, `gaussianyear`, `siderealyear`, `jovianyear`, `angstrom`, `inch`, `foot`, `surveyfoot`, `yard`, `meter`, `earthmeter`, `mile`, `statutemile`, `meridianmile`, `admiraltymile`, `nauticalmile`, `lunardistance`, `astronomicalunit`, `jupiterdistance`, `lightyear`, `parsec`, `bubnoff`, `ips`, `fps`, `fpm`, `ms`, `kmh`, `mph`, `knot`, `mps`, `barn`, `hectare`, `acre`, `surveyacre`, `liter`, `gallon`, `quart`, `pint`, `cup`, `fluidounce`, `teaspoon`, `tablespoon`, `grain`, `gram`, `earthgram`, `kilogram`, `tonne`, `ton`, `pound`, `ounce`, `slug`, `slinch`, `hyl`, `dyne`, `newton`, `poundal`, `poundforce`, `kilopond`, `psi`, `pascal`, `bar`, `barye`, `technicalatmosphere`, `atmosphere`, `inchmercury`, `torr`, `electronvolt`, `erg`, `joule`, `footpound`, `calorie`, `kilocalorie`, `meancalorie`, `earthcalorie`, `thermalunit`, `gasgallon`, `tontnt`, `watt`, `horsepower`, `horsepowerwatt`, `horsepowermetric`, `electricalhorsepower`, `tonsrefrigeration`, `boilerhorsepower`, `coulomb`, `earthcoulomb`, `ampere`, `volt`, `henry`, `ohm`, `siemens`, `farad`, `weber`, `tesla`, `abcoulomb`, `abampere`, `abvolt`, `abhenry`, `abohm`, `abmho`, `abfarad`, `maxwell`, `gauss`, `oersted`, `gilbert`, `statcoulomb`, `statampere`, `statvolt`, `stathenry`, `statohm`, `statmho`, `statfarad`, `statweber`, `stattesla`, `kelvin`, `rankine`, `celsius`, `fahrenheit`, `sealevel`, `boiling`, `mole`, `earthmole`, `poundmole`, `slugmole`, `slinchmole`, `katal`, `amagat`, `lumen`, `candela`, `lux`, `phot`, `footcandle`, `nit`, `apostilb`, `stilb`, `lambert`, `footlambert`, `bril`, `neper`, `bel`, `decibel`, `hertz`, `apm`, `rpm`, `kayser`, `diopter`, `gforce`, `galileo`, `eotvos`, `darcy`, `poise`, `reyn`, `stokes`, `rayl`, `mpge`, `langley`, `jansky`, `solarflux`, `curie`, `gray`, `roentgen`, `rem`.

Standard physics units are at https://geophysics.crucialflow.com/dev/units

Expand Down
177 changes: 110 additions & 67 deletions src/MeasureSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ module MeasureSystems
# https://github.com/chakravala
# https://crucialflow.com

using FieldConstants, FieldAlgebra
import FieldAlgebra: coef, coefprod, factorize, showgroup, product, makeint, measure
import FieldAlgebra: AbstractModule, AbelianGroup, Group, LogGroup, ExpGroup
import FieldAlgebra: value, isonezero, islog, base, Variables
import Base: @pure, angle
import UnitSystems
import UnitSystems: UnitSystem, Systems, Constants, Physics, Convert, Dimensionless
import UnitSystems: Coupling, measure, unit, universe, cache, Derived, logdb, expdb, dB
export UnitSystems, Measure, measure, cache
export UnitSystems, Measure, measure, cache, Constant
const dir = dirname(pathof(UnitSystems))

macro group(args...)
FieldAlgebra.group(args...)
end

# measure

using Measurements
struct Measure{N} end
struct Measure{N} <: Real end
const measure_cache = Measurement{Float64}[]
@pure measure(::Measure{N}) where N = measure_cache[N]
function cache(M::Measurement{Float64})
Expand All @@ -37,6 +45,20 @@ end
Base.show(io::IO,M::Measure{N}) where N = show(io,measure(M))
Base.one(::Measure) = 𝟏
Base.zero(::Measure) = 𝟏-𝟏
FieldConstants.Constant(N::Measurement) = Constant{cache(N)}()
Base.inv(M::Measure) = cache(inv(measure(M)))
Base.sqrt(M::Measure) = cache(inv(measure(M)))

Base.:*(a::Number,b::Measure) = cache(a*measure(b))
Base.:*(a::Measure,b::Number) = cache(measure(a)*b)
Base.:/(a::Number,b::Measure) = cache(a/measure(b))
Base.:/(a::Measure,b::Number) = cache(measure(a)/b)
Base.:+(a::Number,b::Measure) = cache(a+measure(b))
Base.:+(a::Measure,b::Number) = cache(measure(a)-b)
Base.:+(a::Measurement,b::Measure) = cache(a+measure(b))
Base.:+(a::Measure,b::Measurement) = cache(measure(a)-b)
Base.:-(a::Number,b::Measure) = cache(a-measure(b))
Base.:-(a::Measure,b::Number) = cache(measure(a)-b)

# unit systems

Expand Down Expand Up @@ -88,80 +110,101 @@ end
if usingSimilitude
export Similitude, 𝟙, Unified
import Similitude
import Similitude: Unified, coefprod, promoteint
import Similitude: Unified, coefprod, promoteint, USQ
import Similitude: Group,AbelianGroup,LogGroup,ExpGroup,Quantity,Dimension,Quantities,𝟙,usq
import Similitude: Values,value,vals,basis,valueat,makeint,showgroup,ratio,isq,dims,dimtext
import Similitude: Values,value,vals,basis,valueat,showgroup,ratio,isq,dims,dimtext
import FieldAlgebra: makeint, product
for D (:F,:M,:L,:T,:Q,,:N,:J,:A,:R,:C)
@eval const $D = Similitude.$D
end
Similitude.makeint(x::MeasureSystems.Measurements.Measurement) = x
@pure function constant(d::Group,C::Coupling=UnitSystems.Universe,dc=d.c); cs =
UnitSystems.kB^makeint(d.v[1])*
UnitSystems.NA^makeint(d.v[2])*
UnitSystems.𝘩^makeint(d.v[3])*
UnitSystems.𝘤^makeint(d.v[4])*
UnitSystems.𝘦^makeint(d.v[5])*
UnitSystems.Kcd^makeint(d.v[6])*
UnitSystems.ΔνCs^makeint(d.v[7])*
UnitSystems.g₀^makeint(d.v[14])*
UnitSystems.aⱼ^makeint(d.v[15])*
UnitSystems.ft^makeint(d.v[17])*
UnitSystems.ftUS^makeint(d.v[18])*
UnitSystems.lb^makeint(d.v[19])*
UnitSystems.T₀^makeint(d.v[20])*
UnitSystems.atm^makeint(d.v[21])*
UnitSystems.inHg^makeint(d.v[22])*
UnitSystems.RK1990^makeint(d.v[23])*
UnitSystems.KJ1990^makeint(d.v[24])*
UnitSystems.Ωᵢₜ^makeint(d.v[28])*
UnitSystems.Vᵢₜ^makeint(d.v[29])*
UnitSystems.kG^makeint(d.v[30])*
Base.MathConstants.φ^makeint(d.v[34])*
Base.MathConstants.γ^makeint(d.v[35])*
Base.MathConstants.^makeint(d.v[36])*
(2π)^makeint(d.v[37]); is =
2.0^makeint(d.v[38])*
3.0^makeint(d.v[39])*
5.0^makeint(d.v[40])*
7.0^makeint(d.v[41])*
11.0^makeint(d.v[42])*
19.0^makeint(d.v[43])*
43.0^makeint(d.v[44]); me =
abs(d.v[8])+abs(d.v[9])+abs(d.v[10])+abs(d.v[11])+abs(d.v[12])+abs(d.v[13])+abs(d.v[16])+abs(d.v[25])+abs(d.v[26])+abs(d.v[27])+abs(d.v[31])+abs(d.v[32])+abs(d.v[33])
if iszero(me); return cs*(is*d.c); else; ms =
measurement("10973731.5681601(210)")^makeint(d.v[8])* #R∞
inv(measurement("137.035999084(21)"))^makeint(d.v[9])* #α
inv(measurement("1822.888486209(53)"))^makeint(d.v[10])* #μₑᵤ
measurement("1.007276466621(53)")^makeint(d.v[11])* #μₑᵤ
measurement("0.6889(56)")^makeint(d.v[12])* #ΩΛ
measurement("67.66(42)")^makeint(d.v[13])* #H0
measurement("149597870700(3)")^makeint(d.v[16])* #au
measurement("25812.8074555(59)")^makeint(d.v[25])* #RK
(measurement("483597.8525(30)")*1e9)^makeint(d.v[26])* #KJ
measurement("8.3144598(48)")^makeint(d.v[27])* #Rᵤ
measurement("0.00000002176434(24)")^makeint(d.v[31])* #mP
(measurement("3.986004418(8)")*1e14)^makeint(d.v[32])* #GME
(measurement("1.26686534(9)")*1e17)^makeint(d.v[33]) #GMJ
return (cs*(is*d.c))*ms; end
FieldAlgebra.makeint(x::MeasureSystems.Measurements.Measurement) = x
FieldAlgebra.promoteint(x::Measure) = x
@group Measures begin
kB = UnitSystems.kB
NA = UnitSystems.NA
𝘩 = UnitSystems.𝘩
𝘤 = UnitSystems.𝘤
𝘦 = UnitSystems.𝘦
Kcd = UnitSystems.Kcd
ΔνCs = UnitSystems.ΔνCs
R∞ measurement("10973731.5681601(210)")
α inv(measurement("137.035999084(21)"))
μₑᵤ inv(measurement("1822.888486209(53)"))
μₚᵤ measurement("1.007276466621(53)")
ΩΛ measurement("0.6889(56)")
H0 measurement("67.66(42)")
g₀ = UnitSystems.g₀
aⱼ = UnitSystems.aⱼ
au measurement("149597870700(3)")
ft = UnitSystems.ft
ftUS = UnitSystems.ftUS
lb = UnitSystems.lb
T₀ = UnitSystems.T₀
atm = UnitSystems.atm
inHg = UnitSystems.inHg
RK90 = UnitSystems.RK1990
KJ90 = UnitSystems.KJ1990
RK measurement("25812.8074555(59)")
KJ measurement("483597.8525(30)")*1e9
Rᵤ2014 measurement("8.3144598(48)")
Ωᵢₜ = UnitSystems.Ωᵢₜ
Vᵢₜ = UnitSystems.Vᵢₜ
kG = UnitSystems.kG
mP measurement("0.00000002176434(24)")
GME measurement("3.986004418(8)")*1e14
GMJ measurement("1.26686534(9)")*1e17
φ = Base.MathConstants.φ
γ = Base.MathConstants.γ
= Base.MathConstants.
τ 2π
2 = 2
3 = 3
5 = 5
7 = 7
11 = 11
19 = 19
43 = 43
end
Base.show(io::IO,x::Group{:Measures}) = showgroup(io,x,basis,'𝟏')
phys(j,k=vals) = Constant(valueat(j,k,:Measures))
const sim = dirname(pathof(Similitude))
include("$sim/constant.jl")
Base.:*(a::Measurements.Measurement,b::Constant{D}) where D = a*constant(D)
Base.:*(a::Constant{D},b::Measurements.Measurement) where D = constant(D)*b
Base.:*(a::Measure,b::Group{G,T,S,N}) where {G,T,S,N} = FieldAlgebra.times(factorize(a,Val(G)),b)
Base.:*(a::Group{G,T,S,N},b::Measure) where {G,T,S,N} = FieldAlgebra.times(a,factorize(b,Val(G)))
Base.:/(a::Measure,b::Group{G,T,S,N}) where {G,T,S,N} = a*inv(b)
Base.:/(a::Group{G,T,S,N},b::Measure) where {G,T,S,N} = a*inv(b)
Base.:+(a::Measure,b::Group{:Measures,T,S,N}) where {T,S,N} = a+FieldAlgebra.product(b)
Base.:+(a::Group{:Measures,T,S,N},b::Measure) where {T,S,N} = FieldAlgebra.product(a)+b
Base.:*(a::Group{:Measures},b::Group{:USQ}) = Group(b.v,a*b.c,Val(:USQ))
Base.:*(a::Group{:USQ},b::Group{:Measures}) = Group(a.v,a.c*b,Val(:USQ))
Base.:/(a::Group{:Measures},b::Group{:USQ}) = a*inv(b)
Base.:/(a::Group{:USQ},b::Group{:Measures}) = a*inv(b)
Base.:+(a::Group{:Measures,T,S,N} where {T,S},b::Group{:Measures,T,S,N} where {T,S}) where N = product(a)+product(b)
Base.:+(a::Number,b::Group{:Measures,T,S,N} where {T,S}) where N = a+product(b)
Base.:+(a::Group{:Measures,T,S,N} where {T,S},b::Number) where N = product(a)+b
Base.:+(a::Constant,b::Group{:Measures,T,S,N} where {T,S}) where N = a+product(b)
Base.:+(a::Group{:Measures,T,S,N} where {T,S},b::Constant) where N = product(a)+b
Base.:-(a::Group{:Measures,T,S,N} where {T,S},b::Group{:Measures,T,S,N} where {T,S}) where N = product(a)-product(b)
Base.:-(a::Number,b::Group{:Measures,T,S,N} where {T,S}) where N = a-product(b)
Base.:-(a::Group{:Measures,T,S,N} where {T,S},b::Number) where N = product(a)-b
Base.:-(a::Constant,b::Group{:Measures,T,S,N} where {T,S}) where N = a-product(b)
Base.:-(a::Group{:Measures,T,S,N} where {T,S},b::Constant) where N = product(a)-b
Base.:*(a::Group{:Constants,T,S,N} where {T,S},b::Group{:Measures,T,S,N} where {T,S}) where N = Group(a.v+b.v,coefprod(coef(a),coef(b)),Val(:Measures))
Base.:*(a::Group{:Measures,T,S,N} where {T,S},b::Group{:Constants,T,S,N} where {T,S}) where N = Group(a.v+b.v,coefprod(coef(a),coef(b)),Val(:Measures))
Base.:/(a::Group{:Constants,T,S,N} where {T,S},b::Group{:Measures,T,S,N} where {T,S}) where N = Group(a.v-b.v,coefprod(coef(a),coef(b)),Val(:Measures))
Base.:/(a::Group{:Measures,T,S,N} where {T,S},b::Group{:Constants,T,S,N} where {T,S}) where N = Group(a.v-b.v,coefprod(coef(a),coef(b)),Val(:Measures))
#Base.:+(a::Group{:Constants,T,S,N} where {T,S},b::Group{:Measures,T,S,N} where {T,S}) where {N,G} = Group(a.v+b.v,coefprod(coef(a),coef(b)),Val(G))
#Base.:+(a::Group{:Measures,T,S,N} where {T,S},b::Group{:Constants,T,S,N} where {T,S}) where N = Group(a.v+b.v,coefprod(coef(a),coef(b)),Val(:Measures))
#Base.:-(a::Group{:Constants,T,S,N} where {T,S},b::Group{:Measures,T,S,N} where {T,S}) where {N,G} = Group(a.v+b.v,coefprod(coef(a),coef(b)),Val(G))
#Base.:-(a::Group{:Measures,T,S,N} where {T,S},b::Group{:Constants,T,S,N} where {T,S}) where N = Group(a.v+b.v,coefprod(coef(a),coef(b)),Val(:Measures))
Base.:*(a::Measurements.Measurement,b::Constant{D}) where D = a*D
Base.:*(a::Constant{D},b::Measurements.Measurement) where D = D*b
Base.:/(a::Measurements.Measurement,b::Constant{D}) where D = a*inv(b)
Base.:/(a::Constant{D},b::Measurements.Measurement) where D = a*inv(b)
Base.:+(a::Measurements.Measurement,b::Constant{D}) where D = a+constant(D)
Base.:+(a::Constant{D},b::Measurements.Measurement) where D = constant(D)+b
Base.:-(a::Measurements.Measurement,b::Constant{D}) where D = a-constant(D)
Base.:-(a::Constant{D},b::Measurements.Measurement) where D = constant(D)-b
#=Base.:*(a::Measurements.Measurement,b::Similitude.Constant{D}) where D = a*Constant{D}()
Base.:*(a::Similitude.Constant{D},b::Measurements.Measurement) where D = Constant{D}()*b
Base.:/(a::Measurements.Measurement,b::Similitude.Constant{D}) where D = a*inv(b)
Base.:/(a::Similitude.Constant{D},b::Measurements.Measurement) where D = a*inv(b)=#
Base.:*(a::Similitude.Constant{A},b::Constant{B}) where {A,B} = Constant{A*B}()
Base.:*(a::Constant{A},b::Similitude.Constant{B}) where {A,B} = Constant{A*B}()
Base.:/(a::Similitude.Constant{A},b::Constant{B}) where {A,B} = Constant{A/B}()
Base.:/(a::Constant{A},b::Similitude.Constant{B}) where {A,B} = Constant{A/B}()
Base.:+(a::Measurements.Measurement,b::Constant{D}) where D = a+D
Base.:+(a::Constant{D},b::Measurements.Measurement) where D = D+b
Base.:-(a::Measurements.Measurement,b::Constant{D}) where D = a-D
Base.:-(a::Constant{D},b::Measurements.Measurement) where D = D-b
else
Constant(x) = x
Quantity(x) = Constant(x)
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MeasureSystems, Test

@test 1000normal(molarmass(Metric)) normal(molarmass(Gauss))
@test normal(luminousefficacy(Metric)) 1e7*normal(luminousefficacy(Gauss))
@test 1000normal(molarmass(Metric)) == 1normal(molarmass(Gauss))
@test 1normal(luminousefficacy(Metric)) == 1e7*normal(luminousefficacy(Gauss))

2 comments on commit e311bfb

@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/69545

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.1.6 -m "<description of version>" e311bfb5117615ce0187a539de2835d334cc6a13
git push origin v0.1.6

Please sign in to comment.