Skip to content

Commit 7d3820e

Browse files
committed
First content
modified: Project.toml modified: src/MechGlueDiffEqBase.jl
1 parent f48c580 commit 7d3820e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ uuid = "2532746b-52b5-4539-9431-8bb183ab067f"
33
authors = ["hustf <[email protected]> and contributors"]
44
version = "0.1.0"
55

6+
[deps]
7+
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
8+
MechanicalUnits = "e6be9192-89dc-11e9-36e6-5dbcb28f419e"
9+
610
[compat]
711
julia = "1"
812

src/MechGlueDiffEqBase.jl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
module MechGlueDiffEqBase
22

3-
# Write your package code here.
3+
using MechanicalUnits
4+
import MechanicalUnits.Unitfu as Unitful
5+
import DiffEqBase
6+
import DiffEqBase: value, ODE_DEFAULT_NORM, UNITLESS_ABS2
7+
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))
22+
end
23+
424

525
end

0 commit comments

Comments
 (0)