-
-
Notifications
You must be signed in to change notification settings - Fork 122
Open
Labels
Description
I am currently not willing to trace that error down as i can circumvent it. I have not tested callback sets either.
using OrdinaryDiffEq, Unitful
function f(du,u,p,t) du .= 3*u"1/d"*u end
probl = ODEProblem(f, [2.0u"m"], (0.0u"s", 100*u"d"))
Intg = init(probl, Tsit5(),
callback=VectorContinuousCallback(
(out,u,t,int) -> out=[60.0 - ustrip(u"km",u[1])],
(int,idx) -> set_u!(int,[1.0*u"µm"]), 1),
save_everystep=false)
Intg2 = init(probl, Tsit5(), callback=ContinuousCallback(
(u,t,int) -> 60.0 - ustrip(u"km",u[1]),
(int) -> println(set_u!(int,[1.0*u"µm"]))),
save_everystep=false)
step!(Intg2, 2.5u"d", true)
step!(Intg2, 2.5u"d", true) # prints true, callback works
step!(Intg, 2.5u"d", true) # Errors
ERROR: DimensionError: m and 1.0 are not dimensionally compatible.
Stacktrace:
[1] convert(::Type{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}, ::Float64) at /home/joto/.julia/packages/Unitful/KE9TK/src/conversion.jl:111
[2] setindex!(::Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1}, ::Float64, ::Int64) at ./array.jl:782
[3] macro expansion at ./subarray.jl:295 [inlined]
[4] macro expansion at ./simdloop.jl:77 [inlined]
[5] copyto! at ./broadcast.jl:908 [inlined]
[6] copyto! at ./broadcast.jl:863 [inlined]
[7] materialize! at ./broadcast.jl:822 [inlined]
[8] determine_event_occurance at /home/joto/.julia/dev/DiffEqBase/src/callbacks.jl:474 [inlined]
[9] find_callback_time(::OrdinaryDiffEq.ODEIntegrator{Tsit5,true,Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Nothing,Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},DiffEqBase.NullParameters,Float64,Float64,Float64,Array{Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},1},ODESolution{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},2,Array{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},1},Nothing,Nothing,Array{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},1},Array{Array{Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},1},1},ODEProblem{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Tuple{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}}},true,DiffEqBase.NullParameters,ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},1},Array{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},1},Array{Array{Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}}},DiffEqBase.DEStats},ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},OrdinaryDiffEq.Tsit5Cache{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}},OrdinaryDiffEq.DEOptions{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Float64,Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},typeof(DiffEqBase.ODE_DEFAULT_NORM),typeof(LinearAlgebra.opnorm),CallbackSet{Tuple{VectorContinuousCallback{var"#3#5",var"#4#6",var"#4#6",typeof(DiffEqBase.INITIALIZE_DEFAULT),Float64,Int64,Missing,Nothing,Int64}},Tuple{}},typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN),typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE),typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK),DataStructures.BinaryHeap{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},DataStructures.LessThan},DataStructures.BinaryHeap{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},DataStructures.LessThan},Nothing,Nothing,Int64,Tuple{},Tuple{},Tuple{}},Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},Float64,DiffEqBase.CallbackCache{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1}},OrdinaryDiffEq.DefaultInit}, ::VectorContinuousCallback{var"#3#5",var"#4#6",var"#4#6",typeof(DiffEqBase.INITIALIZE_DEFAULT),Float64,Int64,Missing,Nothing,Int64}, ::Int64) at /home/joto/.julia/dev/DiffEqBase/src/callbacks.jl:693
[10] find_first_continuous_callback at /home/joto/.julia/dev/DiffEqBase/src/callbacks.jl:401 [inlined]
[11] handle_callbacks! at /home/joto/.julia/packages/OrdinaryDiffEq/RYCSN/src/integrators/integrator_utils.jl:247 [inlined]
[12] _loopfooter!(::OrdinaryDiffEq.ODEIntegrator{Tsit5,true,Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Nothing,Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},DiffEqBase.NullParameters,Float64,Float64,Float64,Array{Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},1},ODESolution{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},2,Array{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},1},Nothing,Nothing,Array{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},1},Array{Array{Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},1},1},ODEProblem{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Tuple{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}}},true,DiffEqBase.NullParameters,ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},1},Array{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},1},Array{Array{Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}}},DiffEqBase.DEStats},ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},OrdinaryDiffEq.Tsit5Cache{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}},OrdinaryDiffEq.DEOptions{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Float64,Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},typeof(DiffEqBase.ODE_DEFAULT_NORM),typeof(LinearAlgebra.opnorm),CallbackSet{Tuple{VectorContinuousCallback{var"#3#5",var"#4#6",var"#4#6",typeof(DiffEqBase.INITIALIZE_DEFAULT),Float64,Int64,Missing,Nothing,Int64}},Tuple{}},typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN),typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE),typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK),DataStructures.BinaryHeap{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},DataStructures.LessThan},DataStructures.BinaryHeap{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},DataStructures.LessThan},Nothing,Nothing,Int64,Tuple{},Tuple{},Tuple{}},Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},Float64,DiffEqBase.CallbackCache{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1}},OrdinaryDiffEq.DefaultInit}) at /home/joto/.julia/packages/OrdinaryDiffEq/RYCSN/src/integrators/integrator_utils.jl:202
[13] loopfooter! at /home/joto/.julia/packages/OrdinaryDiffEq/RYCSN/src/integrators/integrator_utils.jl:166 [inlined]
[14] step! at /home/joto/.julia/packages/OrdinaryDiffEq/RYCSN/src/iterator_interface.jl:13 [inlined]
[15] step!(::OrdinaryDiffEq.ODEIntegrator{Tsit5,true,Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Nothing,Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},DiffEqBase.NullParameters,Float64,Float64,Float64,Array{Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},1},ODESolution{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},2,Array{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},1},Nothing,Nothing,Array{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},1},Array{Array{Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},1},1},ODEProblem{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Tuple{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}}},true,DiffEqBase.NullParameters,ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},1},Array{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},1},Array{Array{Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}}},DiffEqBase.DEStats},ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},OrdinaryDiffEq.Tsit5Cache{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}},OrdinaryDiffEq.DEOptions{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Float64,Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},typeof(DiffEqBase.ODE_DEFAULT_NORM),typeof(LinearAlgebra.opnorm),CallbackSet{Tuple{VectorContinuousCallback{var"#3#5",var"#4#6",var"#4#6",typeof(DiffEqBase.INITIALIZE_DEFAULT),Float64,Int64,Missing,Nothing,Int64}},Tuple{}},typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN),typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE),typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK),DataStructures.BinaryHeap{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},DataStructures.LessThan},DataStructures.BinaryHeap{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}},DataStructures.LessThan},Nothing,Nothing,Int64,Tuple{},Tuple{},Tuple{}},Array{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}},1},Float64,DiffEqBase.CallbackCache{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1},Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1}},OrdinaryDiffEq.DefaultInit}, ::Quantity{Float64,𝐓,Unitful.FreeUnits{(d,),𝐓,nothing}}, ::Bool) at /home/joto/.julia/dev/DiffEqBase/src/integrator_interface.jl:571
[16] top-level scope at REPL[8]:1
The same problems also exist when using solve:
solve(probl,Tsit5(),callback=ContinuousCallback(
(u,t,int) -> 60.0 - ustrip(u"km",u[1]),
(int) -> println(set_u!(int,[1.0*u"µm"]))),save_everystep=false)
works fine however this fails in the same manner
solve(probl,Tsit5(), callback=VectorContinuousCallback(
(out,u,t,int) -> out=[60.0 - ustrip(u"km",u[1])],
(int,idx) -> set_u!(int,[1.0*u"µm"]), 1),save_everystep=false)
ERROR: DimensionError: m and 0.0 are not dimensionally compatible.
Stacktrace:
[1] convert(::Type{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}, ::Float64) at /home/joto/.julia/packages/Unitful/KE9TK/src/conversion.jl:111
[2] setindex!(::Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1}, ::Float64, ::Int64) at ./array.jl:782
[3] macro expansion at ./subarray.jl:295 [inlined]
[4] macro expansion at ./simdloop.jl:77 [inlined]
[5] copyto! at ./broadcast.jl:908 [inlined]
[6] copyto! at ./broadcast.jl:863 [inlined]
[7] materialize! at ./broadcast.jl:822 [inlined]
[8] determine_event_occurance at /home/joto/.julia/dev/DiffEqBase/src/callbacks.jl:474 [inlined]
[9] find_callback_time