-
Notifications
You must be signed in to change notification settings - Fork 58
Output all CVODE steps #1522
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
base: maintenance/v2.1
Are you sure you want to change the base?
Output all CVODE steps #1522
Conversation
|
Running the tests locally, it seems that:
I will look into it. |
|
It seems that CVODE doesn't properly take into account the given stopping time, when the stopping time is before a previously found root. It can be seen in this test output from EventTest.lua that should stop at 2.0, but instead step to 2.1 (the next root): Looking at CVODE source code, it really seems that the search for additional roots really overrides the test for the stopping time. I need to figure out a new way to handle the outputting of all steps. |
refs OpenModelica#1330 It seems that simply calling CVode with mode CV_NORMAL does not work correctly to return at the given stopping time, if the previous call stopped due to a root.
|
The approach in dd04f81 is clumsy, but I couldn't figure out any other way to force CVODE to always stop at or before The issue was that using a second call with This approach results in skipping the output of possible intermediate time steps, when the stopping time is at most maximum step size away from the current time. It is interesting that CVODE returns slightly different state values depending on whether the root is found in a call made using |
I found a solution for this using This also fixes issue #1530 that occurs when an input is changed while stopped between two calls to It can also happen when using the solution in #1524 to issue #1516 that omits some solver resets on events in which nothing significant happens to the states or their derivatives at an event. I will push the fix and a new test case to this branch. |



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
Purpose
This pull request changes
SystemSCso that:doStep()always advances a single step of CVODE.stepUntil(double)steps to exactly the given time value.Approach
doStepCVODE()anddoStepEuler()are changed to get the end time fromstepUntil(), instead of just using the stopping time for the whole model.doStepCVODE()is changed to:doStep(), calls in a loop fromstepUntil().CV_ONE_STEPinstead ofCV_NORMAL.CV_NORMALis made.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
doStepCVODEis unchanged to create simpler view of the changes.