Output all CVODE steps
These changes are cherry picked from the branch "work", which includes changes originally made to the master branch in October 2024. I hadn't had the time earlier to rebase my code on the major refactoring done to SystemSC.cpp on 19.11.2024 (6d7a397).
Note: This request is based on the maintenance/v2.1 branch, on which I have been working on.
Related Issues
- #1330
- #1530
Purpose
This pull request changes SystemSC so that:
-
doStep()always advances a single step of CVODE. -
stepUntil(double)steps to exactly the given time value. - Results are emitted for the nearest CVODE step according to the defined output interval.
- This allows emitting results at a faster rate than the maximum step size.
Approach
doStepCVODE() and doStepEuler() are changed to get the end time from stepUntil(), instead of just using the stopping time for the whole model.
doStepCVODE() is changed to:
- Return after each CVODE time step
- Single call from
doStep(), calls in a loop fromstepUntil(). - This allows the progress bar to be updated during simulation.
- Single call from
- CVODE is called with mode
CV_ONE_STEPinstead ofCV_NORMAL.- If the single step goes beyond the end time, a second call with
CV_NORMALis made. - The second call only interpolates the values, instead of advancing the solver.
- If the single step goes beyond the end time, a second call with
Also eliminates unnecessary calls to getContinuousStates() after the event loop but before updating inputs.
Note, that this change makes a logging interval of zero emit all solver time steps instead using the maximum step size. This may drastically increase the output file size, if the actual time step is much smaller than the maximum step size. The remedy is to set the logging interval to the maximum step size.
Note: The indentation of the while loop in doStepCVODE is unchanged to create simpler view of the changes.