Skip to content

KLU not working #236

@huanglangwen

Description

@huanglangwen
using Sundials, SparseArrays

# Test for Jacobian usage
function Lotka(du, u, p, t)
  du[1] = u[1] - u[1] * u[2] # REPL[7], line 3:
  du[2] = -3 * u[2] + 1 * u[1] * u[2]
  nothing
end

function Lotka_jac(J,u,p,t)
  J[1,1] = 1.0 - u[2]
  J[1,2] = -u[1]
  J[2,1] = 1 * u[2]
  J[2,2] = -3 + u[1]
  nothing
end

J = sparse(ones(2,2))
Lotka_f = ODEFunction(Lotka,jac=Lotka_jac, jac_prototype=J)
prob = ODEProblem(Lotka_f,ones(2),(0.0,10.0))
sol = solve(prob,CVODE_BDF(linear_solver=:KLU))

got the error:

ERROR: ArgumentError: 1 == colptr[1] != 1
Stacktrace:
 [1] sparse_check(::Int64, ::Array{Int64,1}, ::Array{Int64,1}, ::Array{Float64,1}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\SparseArrays\src\sparsematrix.jl:58
 [2] SparseMatrixCSC(::Int64, ::Int64, ::Array{Int64,1}, ::Array{Int64,1}, ::Array{Float64,1}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\SparseArrays\src\sparsematrix.jl:39
 [3] convert(::Type{SparseMatrixCSC}, ::Ptr{Sundials._generic_SUNMatrix}) at D:\julia\julia1.3pkg\packages\Sundials\SKP8f\src\types_and_consts_additions.jl:49
 [4] cvodejac(::Float64, ::Ptr{Sundials._generic_N_Vector}, ::Ptr{Sundials._generic_N_Vector}, ::Ptr{Sundials._generic_SUNMatrix}, ::Sundials.FunJac{ODEFunction{true,typeof(Lotka),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,typeof(Lotka_jac),Nothing,Nothing,SparseMatrixCSC{Float64,Int64},Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,typeof(Lotka_jac),DiffEqBase.NullParameters,Nothing,SparseMatrixCSC{Float64,Int64},Array{Float64,1},Nothing,Nothing,Nothing}, ::Ptr{Sundials._generic_N_Vector}, ::Ptr{Sundials._generic_N_Vector}, ::Ptr{Sundials._generic_N_Vector}) at D:\julia\julia1.3pkg\packages\Sundials\SKP8f\src\common_interface\function_types.jl:66

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions