Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requirement on Jacobian for CVODE_BDF #291

Open
yhchang96 opened this issue Dec 19, 2020 · 3 comments
Open

requirement on Jacobian for CVODE_BDF #291

yhchang96 opened this issue Dec 19, 2020 · 3 comments

Comments

@yhchang96
Copy link

When I use CVODE_BDF to solve a coupled stiff ODE (a PDE discretized using method of lines) with around ~1000 variables, is it necessary to provide the exact Jacobian or is it sufficient to just provide the sparsity structure (it is sparse) of the Jacobian? In Matlab using ode15s or in scipy using scipy.integrate.solve_ivp we can just provide the sparsity structure of the Jacobian and the solver will compute the Jacobian numerically using finite difference. This is what I have been doing since I know the sparsity structure (which already gives a pretty decent speedup compared to not giving the sparsity structure) but computing the Jacobian is fairly complicated. What about in Julia DifferentialEquations? It's not clear from the documentation what's actually required. I have something like

prob = ODEProblem(dhdt!, h0, (0.0,tf), p)
sol = solve(prob, alg=CVODE_BDF())

which gives what I expect by comparing with solutions computed with MATLAB. But when I try something like

f = ODEFunction(dhdt!; jac_prototype=jpattern) #jpattern is a sparse matrix which gives the sparsity structure of Jacobian
prob_sparse = ODEProblem(f, h0, (0.0,tf), p)
sol_sparse = solve(prob_sparse, alg=CVODE_BDF(linear_solver=:BCG))

it just gives the wrong answer.

@ChrisRackauckas
Copy link
Member

For everything but CVODE we take over and use SparseDiffTools.jl to generate it directly from the sparsity pattern. With CVODE we leave the default Jacobian handling to Sundials, but in 2021 we probably shouldn't because at this point we want to exploit all of these sparsity and AD tools which are missing from Sundials but exist in the SciML ecosystem. So we should really slap our standard DiffEq interface on this portion and take control away from Sundials for the Jacobian building.

@jd-lara might be able to help here.

Moving to Sundials.jl because it's solver-specific.

@ChrisRackauckas ChrisRackauckas transferred this issue from SciML/DifferentialEquations.jl Dec 20, 2020
@jd-lara
Copy link
Contributor

jd-lara commented Dec 21, 2020

I am not sure what could this be. There are tests in pure Sundials that do work properly, we need to check that the common interface is sending to Sundials the correct thing.

@jd-lara
Copy link
Contributor

jd-lara commented Dec 21, 2020

@yhchang96 try without specifying the linear solver. I've had issues with the default tolerances of the linear solvers in Sundials before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants