Skip to content

Commit 1cdd9f7

Browse files
committed
modified: Project.toml v0.1.2
modified: src/MechGlueDiffEqBase.jl Drop __init__()
1 parent 7d3820e commit 1cdd9f7

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name = "MechGlueDiffEqBase"
22
uuid = "2532746b-52b5-4539-9431-8bb183ab067f"
33
authors = ["hustf <[email protected]> and contributors"]
4-
version = "0.1.0"
4+
version = "0.1.2"
55

66
[deps]
77
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
88
MechanicalUnits = "e6be9192-89dc-11e9-36e6-5dbcb28f419e"
9+
Unitfu = "5ee08b94-2369-4f4a-b8c7-99333ba35fb0"
910

1011
[compat]
1112
julia = "1"

src/MechGlueDiffEqBase.jl

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
module MechGlueDiffEqBase
2-
3-
using MechanicalUnits
4-
import MechanicalUnits.Unitfu as Unitful
5-
import DiffEqBase
2+
import MechanicalUnits.Unitfu.AbstractQuantity
63
import DiffEqBase: value, ODE_DEFAULT_NORM, UNITLESS_ABS2
4+
export value, ODE_DEFAULT_NORM, UNITLESS_ABS2, Unitfu
75

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))
2223
end
2324

2425

0 commit comments

Comments
 (0)