|
1 | 1 | module MechGlueDiffEqBase |
2 | | - |
3 | | -using MechanicalUnits |
4 | | -import MechanicalUnits.Unitfu as Unitful |
5 | | -import DiffEqBase |
| 2 | +import MechanicalUnits.Unitfu.AbstractQuantity |
6 | 3 | import DiffEqBase: value, ODE_DEFAULT_NORM, UNITLESS_ABS2 |
| 4 | +export value, ODE_DEFAULT_NORM, UNITLESS_ABS2, Unitfu |
7 | 5 |
|
8 | | -function __init__() |
9 | | - # Glue code copied from DiffEqBase.jl init.jl |
10 | | - # Here, we are using an alias. We are actually using types from Unitfu, but |
11 | | - # with the alias Unitful. Unitfu should only vary from Unitful in how it shows and parses quantities. |
12 | | - value(x::Type{Unitful.AbstractQuantity{T,D,U}}) where {T,D,U} = T |
13 | | - value(x::Unitful.AbstractQuantity) = x.val |
14 | | - @inline function ODE_DEFAULT_NORM(u::AbstractArray{<:Unitful.AbstractQuantity,N},t) where {N} |
15 | | - sqrt(sum(x->ODE_DEFAULT_NORM(x[1],x[2]),zip((value(x) for x in u),Iterators.repeated(t))) / length(u)) |
16 | | - end |
17 | | - @inline function ODE_DEFAULT_NORM(u::Array{<:Unitful.AbstractQuantity,N},t) where {N} |
18 | | - sqrt(sum(x->ODE_DEFAULT_NORM(x[1],x[2]),zip((value(x) for x in u),Iterators.repeated(t))) / length(u)) |
19 | | - end |
20 | | - @inline ODE_DEFAULT_NORM(u::Unitful.AbstractQuantity,t) = abs(value(u)) |
21 | | - @inline UNITLESS_ABS2(x::Unitful.AbstractQuantity) = real(abs2(x)/oneunit(x)*oneunit(x)) |
| 6 | +function value(x::Type{AbstractQuantity{T,D,U}}) where {T,D,U} |
| 7 | + T |
| 8 | +end |
| 9 | +function value(x::AbstractQuantity) |
| 10 | + x.val |
| 11 | +end |
| 12 | +@inline function ODE_DEFAULT_NORM(u::AbstractArray{<:AbstractQuantity,N},t) where {N} |
| 13 | + sqrt(sum(x->ODE_DEFAULT_NORM(x[1],x[2]),zip((value(x) for x in u),Iterators.repeated(t))) / length(u)) |
| 14 | +end |
| 15 | +@inline function ODE_DEFAULT_NORM(u::Array{<:AbstractQuantity,N},t) where {N} |
| 16 | + sqrt(sum(x->ODE_DEFAULT_NORM(x[1],x[2]),zip((value(x) for x in u),Iterators.repeated(t))) / length(u)) |
| 17 | +end |
| 18 | +@inline function ODE_DEFAULT_NORM(u::AbstractQuantity,t) |
| 19 | + abs(value(u)) |
| 20 | +end |
| 21 | +@inline function UNITLESS_ABS2(x::AbstractQuantity) |
| 22 | + real(abs2(x)/oneunit(x)*oneunit(x)) |
22 | 23 | end |
23 | 24 |
|
24 | 25 |
|
|
0 commit comments