Skip to content

Update SUNDIALS to 7.8.0 - #1600

Merged
AnHeuermann merged 9 commits into
OpenModelica:masterfrom
AnHeuermann:sundials-v7.8.0
Jul 31, 2026
Merged

Update SUNDIALS to 7.8.0#1600
AnHeuermann merged 9 commits into
OpenModelica:masterfrom
AnHeuermann:sundials-v7.8.0

Conversation

@AnHeuermann

Copy link
Copy Markdown
Member

Related Issues

OpenModelica will be updated to SUNDIALS v7.8.0, so OMSimulator needs to be updated first.
They share SUNDIALS, so they need to agree on the version.

Changes

Bump 3rdParty, which replaces the patched sundials-5.4.0 source copy with a pristine submodule pinned to v7.8.0, and port the solvers to the new API.

In the integrated OpenModelica build (OPENMODELICA_NEW_CMAKE_BUILD) this block is skipped and we link the SUNDIALS that OMC configured, so the two option sets have to stay in agreement.

Going from 5.4.0 to 7.8.0 crosses two breaking releases:

  • Every SUNDIALS object is now created against a SUNContext. SystemSC, SystemSC3 and KinsolSolver each own one and pass it to N_VNew_Serial, SUNDenseMatrix, SUNLinSol_Dense, CVodeCreate and KINCreate. It has to be created before the first such object and freed after the last one.
  • realtype -> sunrealtype.
  • KINSetErrHandlerFn is gone; the error handler is pushed onto the SUNContext with SUNContext_PushErrHandler and now reports a source location plus a SUNErrCode instead of a module name and message string. Package level codes (KIN_* and friends) are not SUNErrCodes, so SUNGetErrMsg() is only used when SUNDIALS did not supply a message, the same rule its own default handler uses.
  • KINSetPrintLevel and KINSetInfoHandlerFn are gone with no equivalent, so sundialsInfoHandlerFunction is dropped. KINSOL's progress output only exists via the SUNLogger, which is compiled out at the logging level SUNDIALS is built with here.
  • SUNDIALS no longer writes to a FILE* of its own. Up to SUNDIALS 5 CVODE printed to cv_errfp, which defaulted to stderr; the same messages now go through the SUNContext error handler chain, whose default handler writes to the SUNLogger's error stream. Either way that bypasses OMSimulator's logger, so the logger's error and warning streams are muted per context and we report through logError as before.

While in here, report the allocation failures in KinsolSolver::NewKinsolSolver that were silently ignored: the five N_VNew_Serial calls, SUNDenseMatrix and SUNLinSol_Dense were used without checking for NULL. Also correct two copy-pasted messages that blamed N_VNew_Serial for a failing SUNDenseMatrix.

Also follow the oms::3rd::cvode/kinsol -> oms::3rd::sundials::cvode/kinsol alias rename from 3rdParty.

@AnHeuermann AnHeuermann self-assigned this Jul 24, 2026
@AnHeuermann AnHeuermann added the CI/Update Submodules Allow a pull request to update submodules label Jul 24, 2026
@AnHeuermann

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

SUNDIALS integrations were updated to use SUNContext-aware APIs, callback types, logging configuration, resource cleanup, and namespaced link targets for KINSOL and CVODE.

Changes

SUNDIALS context migration

Layer / File(s) Summary
SUNDIALS API and build wiring
3rdParty, src/OMSimulatorLib/AlgLoop.h, src/OMSimulatorLib/SystemSC.h, src/OMSimulatorLib/SystemSC3.h, src/OMSimulatorLib/CMakeLists.txt
SUNDIALS declarations and solver data structures gain SUNContext support, callback types use sunrealtype, the submodule pointer is updated, and library targets use namespaced SUNDIALS dependencies.
KINSOL SUNContext lifecycle
src/OMSimulatorLib/AlgLoop.cpp
KINSOL creates a shared context for solver allocations and error handling, uses context-aware constructors, suppresses logger filenames, and frees the context during destruction.
SystemSC CVODE context integration
src/OMSimulatorLib/SystemSC.cpp
CVODE initialization passes the shared context to vectors, matrices, linear solvers, and CVodeCreate; termination and reset free it.
SystemSC3 CVODE context integration
src/OMSimulatorLib/SystemSC3.cpp
SystemSC3 applies the same context-aware CVODE allocation and cleanup changes while updating callback signatures and logger configuration.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: arun3688

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: updating SUNDIALS to version 7.8.0.
Description check ✅ Passed The description covers the issue context, purpose, and implementation details, though the template headings are not exact.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3fba4264-b353-407b-b942-ee2e70505ef6

📥 Commits

Reviewing files that changed from the base of the PR and between 3d3018b and b433c74.

📒 Files selected for processing (8)
  • 3rdParty
  • src/OMSimulatorLib/AlgLoop.cpp
  • src/OMSimulatorLib/AlgLoop.h
  • src/OMSimulatorLib/CMakeLists.txt
  • src/OMSimulatorLib/SystemSC.cpp
  • src/OMSimulatorLib/SystemSC.h
  • src/OMSimulatorLib/SystemSC3.cpp
  • src/OMSimulatorLib/SystemSC3.h

Comment thread 3rdParty Outdated
Comment thread src/OMSimulatorLib/AlgLoop.cpp
Comment thread src/OMSimulatorLib/AlgLoop.cpp Outdated
@AnHeuermann
AnHeuermann marked this pull request as ready for review July 24, 2026 16:07
@AnHeuermann AnHeuermann mentioned this pull request Jul 27, 2026
@AnHeuermann
AnHeuermann force-pushed the sundials-v7.8.0 branch 2 times, most recently from 773e251 to f8881f6 Compare July 27, 2026 15:51
@AnHeuermann

Copy link
Copy Markdown
Member Author

We have a new CVODE issue when testing Strair.py:

error:   [doStepCVODE] CVode failed with flag = -27

Looks like SUNDIALS 7.x is checking to not integrate over a too small interval after CVodeInit() / CVodeReInit() was called.
Probably a similar error as in CATIA-Systems/FMPy#882.

@AnHeuermann

Copy link
Copy Markdown
Member Author

I might want to fix #1603 before merging this. Not sure but would be good to know that the event handling is not breaking when skipping CVODE calls if we are on an event.

AnHeuermann and others added 5 commits July 30, 2026 10:51
Bump 3rdParty, which replaces the patched sundials-5.4.0 source copy with a
pristine submodule pinned to v7.8.0, and port the solvers to the new API.

In the integrated OpenModelica build (OPENMODELICA_NEW_CMAKE_BUILD) this
block is skipped and we link the SUNDIALS that OMC configured, so the two
option sets have to stay in agreement.

Going from 5.4.0 to 7.8.0 crosses two breaking releases:

- Every SUNDIALS object is now created against a SUNContext. SystemSC,
  SystemSC3 and KinsolSolver each own one and pass it to N_VNew_Serial,
  SUNDenseMatrix, SUNLinSol_Dense, CVodeCreate and KINCreate. It has to be
  created before the first such object and freed after the last one.
- realtype -> sunrealtype.
- KINSetErrHandlerFn is gone; the error handler is pushed onto the SUNContext
  with SUNContext_PushErrHandler and now reports a source location plus a
  SUNErrCode instead of a module name and message string. Package level codes
  (KIN_* and friends) are not SUNErrCodes, so SUNGetErrMsg() is only used when
  SUNDIALS did not supply a message, the same rule its own default handler uses.
- KINSetPrintLevel and KINSetInfoHandlerFn are gone with no equivalent, so
  sundialsInfoHandlerFunction is dropped. KINSOL's progress output only exists
  via the SUNLogger, which is compiled out at the logging level SUNDIALS is
  built with here.
- SUNDIALS no longer writes to a FILE* of its own. Up to SUNDIALS 5 CVODE
  printed to cv_errfp, which defaulted to stderr; the same messages now go
  through the SUNContext error handler chain, whose default handler writes to
  the SUNLogger's error stream. Either way that bypasses OMSimulator's logger,
  so the logger's error and warning streams are muted per context and we report
  through logError as before.

While in here, report the allocation failures in KinsolSolver::NewKinsolSolver
that were silently ignored: the five N_VNew_Serial calls, SUNDenseMatrix and
SUNLinSol_Dense were used without checking for NULL. Also correct two
copy-pasted messages that blamed N_VNew_Serial for a failing SUNDenseMatrix.

Also follow the oms::3rd::cvode/kinsol -> oms::3rd::sundials::cvode/kinsol
alias rename from 3rdParty.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Skip steps with |tout - tn| < 2*uround*max(|tn|,|tout|)
* Go directly to tout
@AnHeuermann

Copy link
Copy Markdown
Member Author

The error CV_TOO_CLOSE=-27 "The output and initial times are too close to each other" disappeared after removing the "fix" for it. I'm not sure why. I prefer to change as little as possible in this PR, so I removed it. If it becomes an issue we can always re-add a function to prevent running CVODE on too short intervals.

@AnHeuermann

Copy link
Copy Markdown
Member Author

I also updated src/OMSimulatorLib/SystemSC3.cpp, but as of now it is dead code that isn't accessed for 3.0 ME FMUs.

@AnHeuermann
AnHeuermann merged commit 67373ba into OpenModelica:master Jul 31, 2026
4 checks passed
@AnHeuermann
AnHeuermann deleted the sundials-v7.8.0 branch July 31, 2026 11:22
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.17241% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 27.23%. Comparing base (6287cf4) to head (55b25d7).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/OMSimulatorLib/AlgLoop.cpp 41.66% 14 Missing and 7 partials ⚠️
src/OMSimulatorLib/SystemSC.cpp 77.27% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1600      +/-   ##
==========================================
+ Coverage   27.20%   27.23%   +0.03%     
==========================================
  Files          69       69              
  Lines       13825    13844      +19     
  Branches     8600     8615      +15     
==========================================
+ Hits         3761     3771      +10     
- Misses       8878     8881       +3     
- Partials     1186     1192       +6     
Flag Coverage Δ
linux 27.23% <55.17%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/Update Submodules Allow a pull request to update submodules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants