Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/common_interface/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractODEProblem{uType, tupType, i
utmp = NVector(_u0)

use_jac_prototype = (isa(prob.f.jac_prototype, SparseArrays.SparseMatrixCSC) &&
LinearSolver ∈ SPARSE_SOLVERS)
LinearSolver ∈ SPARSE_SOLVERS) ||
prob.f.jac_prototype isa AbstractSciMLOperator
userfun = FunJac(f!,
prob.f.jac,
prob.p,
Expand Down Expand Up @@ -341,6 +342,7 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractODEProblem{uType, tupType, i
end

if typeof(prob.f.jac_prototype) <: AbstractSciMLOperator
"here!!!!"
function getcfunjtimes(::T) where {T}
@cfunction(jactimes,
Cint,
Expand Down
1 change: 1 addition & 0 deletions src/nvector_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Conversion happens in two steps within ccall:
"""
Base.cconvert(::Type{N_Vector}, v::Vector{realtype}) = convert(NVector, v) # will just return v if v is an NVector
Base.unsafe_convert(::Type{N_Vector}, nv::NVector) = nv.n_v
Base.copy!(v::Vector, nv::Ptr{Sundials._generic_N_Vector}) = copy!(v, convert(NVector, nv))

Base.similar(nv::NVector) = NVector(similar(nv.v))

Expand Down
9 changes: 7 additions & 2 deletions test/common_interface/jacobians.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ end
Lotka_f = ODEFunction(Lotka; jac = Lotka_jac)
prob = ODEProblem(Lotka_f, ones(2), (0.0, 10.0))
good_sol = solve(prob, CVODE_BDF())
testsol = solve(prob, CVODE_BDF(), saveat = 0.1, abstol = 1e-12, reltol = 1e-12)
@test jac_called == true

Lotka_f = ODEFunction(Lotka;
Expand All @@ -33,10 +34,14 @@ sol9 = solve(prob, CVODE_BDF(; linear_solver = :KLU))
@test jac_called == true
@test Array(sol9) ≈ Array(good_sol)

Lotka_fj = ODEFunction(Lotka; jac_prototype = JacVec(Lotka, ones(2)))
Lotka_fj = ODEFunction(Lotka;
jac_prototype = JacVec((du, u) -> Lotka(du, u, (), 0.0), ones(2),
SciMLBase.NullParameters()))

prob = ODEProblem(Lotka_fj, ones(2), (0.0, 10.0))
sol9 = solve(prob, CVODE_BDF(; linear_solver = :GMRES))
sol9 = solve(prob, CVODE_BDF(; linear_solver = :GMRES), saveat = 0.1, abstol = 1e-12,
reltol = 1e-12)
@test Array(sol9) ≈ Array(testsol)

function f2!(res, du, u, p, t)
res[1] = 1.01du[1]
Expand Down