Skip to content

Don't call CVode with an interval it cannot integrate - #1621

Merged
AnHeuermann merged 2 commits into
OpenModelica:masterfrom
AnHeuermann:fix-cvode-do-step
Aug 13, 2026
Merged

Don't call CVode with an interval it cannot integrate#1621
AnHeuermann merged 2 commits into
OpenModelica:masterfrom
AnHeuermann:fix-cvode-do-step

Conversation

@AnHeuermann

Copy link
Copy Markdown
Member

Related Issues

Related to #1600. In OpenModelica/OpenModelica#16158 we get a new error with OMSimulator.

Purpose

doStepCVODE accumulates end_time while the event times come from the FMU, so an event landing on the last ULP before end_time leaves time < end_time true with nothing integrable in between:

time = 0.080000000000000001665 clock tick reported by the FMU
end_time = 0.080000000000000015543 accumulated by the loop
tout = min(tnext, end_time) = end_time gap = 1.39e-17

CVode rejects such an interval with CV_TOO_CLOSE, but only on the first call after a re-init - which is exactly the call following every event - so the whole simulation fails there.

Approach

Skip the call and take end_time as reached, using CVode's own too-close test.

@AnHeuermann AnHeuermann self-assigned this Aug 10, 2026
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 27.34%. Comparing base (77dcf25) to head (5826355).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1621      +/-   ##
==========================================
+ Coverage   27.23%   27.34%   +0.10%     
==========================================
  Files          69       69              
  Lines       13844    13847       +3     
  Branches     8615     8616       +1     
==========================================
+ Hits         3771     3786      +15     
+ Misses       8881     8871      -10     
+ Partials     1192     1190       -2     
Flag Coverage Δ
linux 27.34% <100.00%> (+0.10%) ⬆️

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.

AnHeuermann and others added 2 commits August 13, 2026 10:26
doStepCVODE accumulates end_time while the event times come from the FMU,
so an event landing on the last ULP before end_time leaves time < end_time
true with nothing integrable in between:

  time     = 0.080000000000000001665   clock tick reported by the FMU
  end_time = 0.080000000000000015543   accumulated by the loop
  tout     = min(tnext, end_time) = end_time      gap = 1.39e-17

CVode rejects such an interval with CV_TOO_CLOSE, but only on the first
call after a re-init - which is exactly the call following every event -
so the whole simulation fails there. Skip the call and take end_time as
reached, using CVode's own too-close test.

Reproduced by simulation/clockedStepBoundary: a Modelica.Clocked FMU whose
tick times are exact (k * period) against a communication step of 0.008,
which fails at t = 0.08 without this change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@AnHeuermann
AnHeuermann marked this pull request as ready for review August 13, 2026 09:10
@AnHeuermann
AnHeuermann enabled auto-merge (squash) August 13, 2026 09:17
@AnHeuermann
AnHeuermann merged commit 0dab0bc into OpenModelica:master Aug 13, 2026
4 checks passed
@AnHeuermann
AnHeuermann deleted the fix-cvode-do-step branch August 13, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant