-
-
Notifications
You must be signed in to change notification settings - Fork 79
pass user jacobian to cvode #79
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
Comments
I think this is something that should be added to the simplified interface, which is being overhauled (see #75). We would love the contribution. |
But I need a solution first 😅👍🏻 |
What exactly is the |
It is defined in
|
Hi Steven, acroy, In type _DlsMat
_type::Cint
M::Clong
N::Clong
ldim::Clong
mu::Clong
ml::Clong
s_mu::Clong
data::Ptr{realtype}
ldata::Clong
cols::Ptr{Ptr{realtype}}
end
typealias DlsMat Ptr{_DlsMat} I think I somewhat figured it out. The convert method is function convert(::Type{Matrix}, J::DlsMat)
_dlsmat = unsafe_load(J)
# own is false as memory is allocated by sundials
pointer_to_array(_dlsmat.data, (_dlsmat.M, _dlsmat.N), false)
end I have tests passing in a custom problem where I provide the rhs and the jacobian. I suspected I could have had troubles with the row/column-order difference between C and julia, but this seems to work. |
While C uses row-major ordering, apparently the matrix in |
Not really a problem! Much better 😏 |
As a step forward I report here @ChrisRackauckas 's hints on solving this: We need to grab |
Well, @gasagna's solution is great for the simplified interface. The common interface can just check It looks like setting up the preconditioners has the same difficulties, so I think this solution can be applied there as well (for KINSOL, CVODE, and IDA). I'll probably take a deeper look into this in a week or so since this is probably the biggest thing the interface is missing for Sundials. |
The common interface now passes the Jacobian to CVODE. IDA is next and I'll close the issue. |
Thanks for your help @gasagna. I was able to use this and now the Jacobians pass to CVODE and IDA on the common interface bindings. |
Hi,
I am looking to implement the required code to pass the rhs jacobian to sundials to avoid expensive finite-difference approximations. According to the example
cvde_Roberts_dns.jl
, at line 26 (this link) this needs implementing a wrapper fromSundials._DlsMat
toMatrix
and the user jacobian wrapper.My strategy for the latter is as follows:
i.e. the same
FunJac
type is used to store the rhs and the jacobian. Appropriate julia callbacks are then defined for the rhs and jacobian usingcfunction
and dispatch, along the lines of:Now the missing piece is how to define the
convert(::Type{Matrix}, J::DlsMat)
method called in the jacobian. Any pointers (no pun intended) are welcome. Is the code incvode_Roberts_dns.jl
a valid approach? It looks beyond my CJulia-fu skills...I am actually writing this as part of a personal package but could contribute it to Sundials if requested.
The text was updated successfully, but these errors were encountered: