Hello all,
I am new to this forum
I am somewhat confused on how to solve DAEs using the DifferentialEquations package -
I am trying to solve a large system, that I think requires explicit Jacobian definition.
I defined a minimal problem to learn how to do this from the example in DifferentialEquations, but I seem to be doing something wrong - if I try to solve my small problem without dealing with Jacobians - I get quick results - when I try to incorporate the jacobain to my calculation the IDA crashes - Any diea why or how to fix it? Also I read that it is possible to solve DAEs using the ODEProblems, any advice how to do that would also be appreciated to.
Here is the code i was trying:
p=[2,1.2,3]
function f(res,du,u,p,t)
res[1] = du[1] - p[1] * u[1] + p[2] * u[1]*u[2]
res[2] = du[2] -p[3] * u[2] - u[1]*u[2]
res[3]= u[2] + u[1] - u[3]
end
function g(::Type{Val{:jac}},J,du,u,p,gamma,t)
J[1,1] = gamma - p[1] + p[2] * u[2]
J[1,2] = p[2]* u[1]
# J[1,3] = 0
J[2,1] = - 1 * u[2]
J[2,2] = gamma - p[3] - u[1]
# J[2,3] = 0
# J[3,1] = 1
# J[3,2] = 1
# j[3,3] = -1
nothing
end
I tested g 3 ways as is, without comments and commenting only J[3,:]
Then I run the DAE:
fg = DAEFunction(f;jac=g)
dIC=[-0.8,-4]
IC =[1.0,1.0,2.0]
tspan=(0.0,10.0)
diff_vars = [true,true, false]
#works, but does not take into consideration jacobian defined in g
testProb = DAEProblem(f,dIC,IC,tspan,p,differential_vars=diff_vars)
sol = solve(testProb,IDA(linear_solver=:GMRES))
# does not work
testProb2 = DAEProblem(fg,dIC,IC,tspan,p,differential_vars=diff_vars)
sol = solve(testProb2,IDA(linear_solver=:GMRES))
Here is the error form the IDA
[IDAS ERROR] IDACalcIC The residual routine or the linear setup or solve routine had a recoverable error, but IDACalcIC was unable to recover.
Out[147]:
retcode: InitialFailure Interpolation: 3rd order Hermite t: 1-element Array{Float64,1}: 0.0 u: 1-element Array{Array{Float64,1},1}: [1.0, 1.0, 2.0]
Any advice is appreciated
A