SimBiology - sundials - ODE solver - CVODE
6 views (last 30 days)
Could someone explain me how I can use the sundials solver (CVODE), through my use of simBiology toolbox ?
I know ODE solvers of Matlab and I used to use ODE15s. However, the latter fails in integration of stiff problems. So, I tried to use CVODE solver. The same issue occurs (if you are interested to know more about that please see my post on sundials forum : http://sundials.2283335.n4.nabble.com/force-the-CVODE-solver-to-continue-despite-the-error-test-failed-repeatedly-or-with-h-hmin-td4655576.html ). So, I ended up with the following troubleshooting solution being suggested for the very same solver included in SimBiology package ( https://nl.mathworks.com/help/simbio/ug/troubleshooting-simulation-errors.html ). Here you can see that they talk about two options of MaximumNumberOfLogs and MaximumWallClock, the use of which can help to avoid this problem. So, as I can not find these two options in CVODE directly downloaded from https://computation.llnl.gov/projects/sundials/sundials-software , I thought maybe these two options are only available in the SimBiology. Now, the problem is the following : there is no enough information/tutorial on this tool. How I can chage the following line to make use of SimBiology ?
I appreciate a lot your help,
You are correct that MaximumNumberOfLogs and MaximumWallClock are SimBiology-specific options.
In order to simulate your model in SimBiology, you will have to translate the differential equations inside your function source_terms into a SimBiology model. We have designed SimBiology primarily for simulating systems of reactions, so the most common way to build a SimBiology model is by constructing a series of reactions. You can find a simple example of that here. If you prefer to translate a series of differential equations into a SimBiology model, you may prefer to define your model in terms of rate rules. You can find an example of that here.
Once you have defined your model (let's say, in variable modelObj), here's sample code that sets the solver to sundials, set MaximumNumberOfLogs and MaximumWallClock, and simulate the model:
configsetObj = getconfigset(modelObj);
configsetObj.SolverType = 'sundials';
configsetObj.MaximumNumberOfLogs = 100;
configsetObj.MaximumWallClock = 30;
[time, states] = sbiosimulate(modelObj);
It is technically possible to use arbitrary MATLAB functions with SimBiology. So you could in theory create a SimBiology model that calls source_terms to calculate the appropriate terms. But I would not recommend this approach. I think it would end up being very hard to read and extremely inefficient (that is, slow to simulate).
So, for all practical purposes, I would say you should not directly use source_terms with SimBiology. Instead, I would focus on finding an efficient way to convert source_terms into a SimBiology model.
Can you share your full code for source_terms? Depending on how that's written, I might be able to offer suggestions for writing a program to automatically create a SimBiology model from the file.