Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pre-compilation error #44

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions src/equivalences.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# equivalences containing angular dimensions

const _temporal_dims = [Time, Frequency, AngularPeriod, AngularVelocity]
const _spatial_dims = [Length, Wavenumber, AngularWavelength, AngularWavenumber]
const _temporal_units = Dict(
Time => s, Frequency => Hz, AngularPeriod => s/radᵃ, AngularVelocity => radᵃ/s)
const _spatial_units = Dict(
Length => m, Wavenumber => m^-1, AngularWavelength => m/radᵃ, AngularWavenumber => radᵃ/m
)

# periodic equivalence for both temporal and spatial frequency
"""
Periodic()
Expand Down Expand Up @@ -53,16 +61,23 @@ struct Periodic <: Equivalence end
@eqrelation Periodic (Length / AngularWavelength = 2π * radᵃ)
@eqrelation Periodic (AngularWavelength * Wavenumber = 1/(2π * radᵃ))
# default to `uconvert` behavior, temporal
@eqrelation Periodic (Frequency / Frequency = 1)
@eqrelation Periodic (Time / Time = 1)
@eqrelation Periodic (AngularVelocity / AngularVelocity = 1)
@eqrelation Periodic (AngularPeriod / AngularPeriod = 1)
for D ∈ _spatial_dims
@eval begin
function UnitfulEquivalences.edconvert(::dimtype($D), x::$D, equivalence::Periodic)
u = _spatial_units[$D]
return uconvert(u, x)
end
end
end
# default to `uconvert` behavior, spatial
@eqrelation Periodic (Wavenumber / Wavenumber = 1)
@eqrelation Periodic (Length / Length = 1)
@eqrelation Periodic (AngularWavenumber / AngularWavenumber = 1)
@eqrelation Periodic (AngularWavelength / AngularWavelength = 1)

for D ∈ _temporal_dims
@eval begin
function UnitfulEquivalences.edconvert(::dimtype($D), x::$D, equivalence::Periodic)
u = _temporal_units[$D]
return uconvert(u, x)
end
end
end

# periodic equivalence with a specific dispersion relation relating temporal and spatial
# frequencies
Expand Down Expand Up @@ -143,24 +158,16 @@ struct Dispersion <: Equivalence
end
end

const _temporal_frequency_dims = [Time, Frequency, AngularPeriod, AngularVelocity]
const _spatial_frequency_dims = [Length, Wavenumber, AngularWavelength, AngularWavenumber]
const _temporal_frequency_units = Dict(
Time => s, Frequency => Hz, AngularPeriod => s/radᵃ, AngularVelocity => radᵃ/s)
const _spatial_frequency_units = Dict(
Length => m, Wavenumber => 1/m, AngularWavelength => m/radᵃ, AngularWavenumber => radᵃ/m
)

# use all the equivalences in Periodic
for T1 ∈ _temporal_frequency_dims, T2 ∈ _temporal_frequency_dims
for T1 ∈ _temporal_dims, T2 ∈ _temporal_dims
@eval begin
function UnitfulEquivalences.edconvert(d::dimtype($T1), x::$T2, ::Dispersion)
return edconvert(d, x, Periodic())
end
end
end

for T1 ∈ _spatial_frequency_dims, T2 ∈ _spatial_frequency_dims
for T1 ∈ _spatial_dims, T2 ∈ _spatial_dims
@eval begin
function UnitfulEquivalences.edconvert(d::dimtype($T1), x::$T2, ::Dispersion)
return edconvert(d, x, Periodic())
Expand All @@ -169,7 +176,7 @@ for T1 ∈ _spatial_frequency_dims, T2 ∈ _spatial_frequency_dims
end

# add new equivalences between temporal <-> spatial frequencies
for D_in ∈ _spatial_frequency_dims, D_out ∈ _temporal_frequency_dims
for D_in ∈ _spatial_dims, D_out ∈ _temporal_dims
@eval begin
function UnitfulEquivalences.edconvert(
::dimtype($D_out), x::$D_in, equivalence::Dispersion
Expand All @@ -178,13 +185,13 @@ for D_in ∈ _spatial_frequency_dims, D_out ∈ _temporal_frequency_dims
"`dispersion` function not defined"))
k = uconvert(radᵃ/m, x, Periodic())
ω = equivalence.dispersion(k)
u = _temporal_frequency_units[$D_out]
u = _temporal_units[$D_out]
return uconvert(u, ω, Periodic())
end
end
end

for D_in ∈ _temporal_frequency_dims, D_out ∈ _spatial_frequency_dims
for D_in ∈ _temporal_dims, D_out ∈ _spatial_dims
@eval begin
function UnitfulEquivalences.edconvert(
::dimtype($D_out), x::$D_in, equivalence::Dispersion
Expand All @@ -193,7 +200,7 @@ for D_in ∈ _temporal_frequency_dims, D_out ∈ _spatial_frequency_dims
"`dispersion_inverse` function not defined"))
ω = uconvert(radᵃ/s, x, Periodic())
k = equivalence.dispersion_inverse(ω)
u = _spatial_frequency_units[$D_out]
u = _spatial_units[$D_out]
return uconvert(u, k, Periodic())
end
end
Expand Down
Loading