MATLAB: How to speed up ODE15s

ode15s

Hello everybody I am trying to speed up a MATLAB code which numerically solves for deactivation process in a catalyst. The algorithm of the code which simply solves mass and momentum conservation equations plus an equation for chemical reaction over time and space(1D) is like below:
main()
statements
Initial values and boundary conditions
Timespan=[0 3600] // By discretizing equations in Z direction we get ODEs and then implement stiff ode solver to sweep in time
[t,w]=ODE15s(@transientfunction,timespan,w0)
outputs+graphs
end
transientfunction()
"FOR" loop // "for" loop is implemented to allocate the differential values at each cell which is around 100 cells.
end
***************************************************************Problem******************************************************
My problem here is that simulation of one hour (3600s) of deactivation process takes two days!!!(at the end I want to simulate it for 5years which I guess my grandson can check the result and be proud of his grandpa) I have tried to use "parfor" in transientfunction with 12 workers but not only the speed did not increase but also decreased! Time step in ODE15s solver is,specially at the beginning, gravely small. Is there any suggestion or advice out there that might help me or help this nice and lovely ode solver to speed up I look forward to your suggestions Thank you all Rasoul

Best Answer

Some things to try...
  1. For stiff problems you should always specify the Jacobian or its sparsity pattern via the options structure. Sometimes this can greatly improve performance since the solver estimates it numerically when you don't specify it. See odeset for more info.
  2. Try some of the other stiff solvers since they use a slightly cruder tolerance to calculate steps ( ode23s, ode23t, ode23tb). Since your ODE function contains a loop the fastest solver is likely to be the one with the fewest function evaluations. You can check that by setting 'Stats','on' with odeset and comparing the stats of each solver.
  3. If your equations include some conservation equations then you might have a system of Differential Algebraic Equations. If that's the case then you can continue using ode15s but might need to set some options as outlined on the linked page.