# Sundials and SecondOrderODEProblem (OrdinaryDiffEq) not compatible

Unfortunately I cannot get a working example of using a SecondOrderODEProblem and any Sundials solver. One workaround is to reformulate the problem as a ODEProblem, but perhaps you know more than I do.

This shows the problem:

``````using OrdinaryDiffEq
ω = 1
x₀ = [0.0]
dx₀ = [π/2]
tspan = (0.0, 2π)

function harmonic_oscillator(ddu,du,u,ω,t)
ddu .= -ω^2 * u
end

prob = SecondOrderODEProblem(harmonic_oscillator, dx₀, x₀, tspan, ω)

#Tsit 5 works
sol = solve(prob, Tsit5())

using Sundials
# error using CVODE_BDF
sol = solve(prob, CVODE_BDF())
``````

Tsit5 works and for COVDE_BDF I get the following error message:

``````ERROR: LoadError: MethodError: Cannot `convert` an object of type Array{Float64,1} to an object of type RecursiveArrayTools.ArrayPartition{Float64,Tuple{Array{Float64,1},Array{Float64,1}}}
Closest candidates are:
convert(::Type{T}, ::T) where T<:AbstractArray at abstractarray.jl:14
convert(::Type{T}, ::LinearAlgebra.Factorization) where T<:AbstractArray at /build/julia/src/julia-1.5.3/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/factorization.jl:55
convert(::Type{T}, ::T) where T at essentials.jl:171
...
Stacktrace:
[1] save_value!(::Array{RecursiveArrayTools.ArrayPartition{Float64,Tuple{Array{Float64,1},Array{Float64,1}}},1}, ::Array{Float64,1}, ::Type{RecursiveArrayTools.ArrayPartition{Float64,Tuple{Array{Float64,1},Array{Float64,1}}}}, ::Tuple{Int64}, ::Type{Val{true}}) at ~/.julia/packages/Sundials/1nn1O/src/common_interface/integrator_utils.jl:116
[2] save_value!(::Array{RecursiveArrayTools.ArrayPartition{Float64,Tuple{Array{Float64,1},Array{Float64,1}}},1}, ::Array{Float64,1}, ::Type{RecursiveArrayTools.ArrayPartition{Float64,Tuple{Array{Float64,1},Array{Float64,1}}}}, ::Tuple{Int64}) at ~/.julia/packages/Sundials/1nn1O/src/common_interface/integrator_utils.jl:115
[3] __init(::ODEProblem{RecursiveArrayTools.ArrayPartition{Float64,Tuple{Array{Float64,1},Array{Float64,1}}},Tuple{Float64,Float64},true,Int64,DynamicalODEFunction{true,ODEFunction{true,typeof(harmonic_oscillator),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},ODEFunction{true,DiffEqBase.var"#255#257",LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},SecondOrderODEProblem{true}}, ::CVODE_BDF{:Newton,:Dense,Nothing,Nothing}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}; verbose::Bool, callback::Nothing, abstol::Float64, reltol::Float64, saveat::Array{Float64,1}, tstops::Array{Float64,1}, maxiters::Int64, dt::Nothing, dtmin::Float64, dtmax::Float64, timeseries_errors::Bool, dense_errors::Bool, save_everystep::Bool, save_on::Bool, save_start::Bool, save_end::Bool, dense::Bool, progress::Bool, progress_name::String, progress_message::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), save_timeseries::Nothing, advance_to_tstop::Bool, stop_at_next_tstop::Bool, userdata::Nothing, alias_u0::Bool, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at ~/.julia/packages/Sundials/1nn1O/src/common_interface/solve.jl:329
[4] __init(::ODEProblem{RecursiveArrayTools.ArrayPartition{Float64,Tuple{Array{Float64,1},Array{Float64,1}}},Tuple{Float64,Float64},true,Int64,DynamicalODEFunction{true,ODEFunction{true,typeof(harmonic_oscillator),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},ODEFunction{true,DiffEqBase.var"#255#257",LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},SecondOrderODEProblem{true}}, ::CVODE_BDF{:Newton,:Dense,Nothing,Nothing}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}) at ~/.julia/packages/Sundials/1nn1O/src/common_interface/solve.jl:56
[5] __solve(::ODEProblem{RecursiveArrayTools.ArrayPartition{Float64,Tuple{Array{Float64,1},Array{Float64,1}}},Tuple{Float64,Float64},true,Int64,DynamicalODEFunction{true,ODEFunction{true,typeof(harmonic_oscillator),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},ODEFunction{true,DiffEqBase.var"#255#257",LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},SecondOrderODEProblem{true}}, ::CVODE_BDF{:Newton,:Dense,Nothing,Nothing}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Type{Val{true}}; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at ~/.julia/packages/Sundials/1nn1O/src/common_interface/solve.jl:13
[6] __solve at ~/.julia/packages/Sundials/1nn1O/src/common_interface/solve.jl:13 [inlined] (repeats 5 times)
[7] #solve_call#460 at ~/.julia/packages/DiffEqBase/F3qfC/src/solve.jl:65 [inlined]
[8] solve_call at ~/.julia/packages/DiffEqBase/F3qfC/src/solve.jl:52 [inlined]
[9] solve_up(::ODEProblem{RecursiveArrayTools.ArrayPartition{Float64,Tuple{Array{Float64,1},Array{Float64,1}}},Tuple{Float64,Float64},true,Int64,DynamicalODEFunction{true,ODEFunction{true,typeof(harmonic_oscillator),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},ODEFunction{true,DiffEqBase.var"#255#257",LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},SecondOrderODEProblem{true}}, ::Nothing, ::RecursiveArrayTools.ArrayPartition{Float64,Tuple{Array{Float64,1},Array{Float64,1}}}, ::Int64, ::CVODE_BDF{:Newton,:Dense,Nothing,Nothing}; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at ~.julia/packages/DiffEqBase/F3qfC/src/solve.jl:86
[10] solve_up at ~/.julia/packages/DiffEqBase/F3qfC/src/solve.jl:79 [inlined]
[11] #solve#461 at ~/.julia/packages/DiffEqBase/F3qfC/src/solve.jl:74 [inlined]
[12] solve(::ODEProblem{RecursiveArrayTools.ArrayPartition{Float64,Tuple{Array{Float64,1},Array{Float64,1}}},Tuple{Float64,Float64},true,Int64,DynamicalODEFunction{true,ODEFunction{true,typeof(harmonic_oscillator),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},ODEFunction{true,DiffEqBase.var"#255#257",LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},SecondOrderODEProblem{true}}, ::CVODE_BDF{:Newton,:Dense,Nothing,Nothing}) at ~/.julia/packages/DiffEqBase/F3qfC/src/solve.jl:72
[13] top-level scope at ~/juliaproblems/2ndOrderODEandSundials.jl:24
[14] invokelatest(::Any, ::Any, ::Vararg{Any,N} where N; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at ./essentials.jl:710
[15] invokelatest(::Any, ::Any, ::Vararg{Any,N} where N) at ./essentials.jl:709
[16] inlineeval(::Module, ::String, ::Int64, ::Int64, ::String; softscope::Bool) at ~/.vscode-oss/extensions/julialang.language-julia-1.0.10/scripts/packages/VSCodeServer/src/eval.jl:185
[17] (::VSCodeServer.var"#61#65"{String,Int64,Int64,String,Module,Bool,VSCodeServer.ReplRunCodeRequestParams})() at ~/.vscode-oss/extensions/julialang.language-julia-1.0.10/scripts/packages/VSCodeServer/src/eval.jl:144
[18] withpath(::VSCodeServer.var"#61#65"{String,Int64,Int64,String,Module,Bool,VSCodeServer.ReplRunCodeRequestParams}, ::String) at ~/.vscode-oss/extensions/julialang.language-julia-1.0.10/scripts/packages/VSCodeServer/src/repl.jl:124
[19] (::VSCodeServer.var"#60#64"{String,Int64,Int64,String,Module,Bool,Bool,VSCodeServer.ReplRunCodeRequestParams})() at ~/.vscode-oss/extensions/julialang.language-julia-1.0.10/scripts/packages/VSCodeServer/src/eval.jl:142
[20] hideprompt(::VSCodeServer.var"#60#64"{String,Int64,Int64,String,Module,Bool,Bool,VSCodeServer.ReplRunCodeRequestParams}) at ~/.vscode-oss/extensions/julialang.language-julia-1.0.10/scripts/packages/VSCodeServer/src/repl.jl:36
[21] (::VSCodeServer.var"#59#63"{String,Int64,Int64,String,Module,Bool,Bool,VSCodeServer.ReplRunCodeRequestParams})() at ~/.vscode-oss/extensions/julialang.language-julia-1.0.10/scripts/packages/VSCodeServer/src/eval.jl:110
[22] with_logger at ./logging.jl:514 [inlined]
[23] (::VSCodeServer.var"#58#62"{VSCodeServer.ReplRunCodeRequestParams})() at ~/.vscode-oss/extensions/julialang.language-julia-1.0.10/scripts/packages/VSCodeServer/src/eval.jl:109
[24] #invokelatest#1 at ./essentials.jl:710 [inlined]
[25] invokelatest(::Any) at ./essentials.jl:709
[26] macro expansion at ~/.vscode-oss/extensions/julialang.language-julia-1.0.10/scripts/packages/VSCodeServer/src/eval.jl:27 [inlined]