Skip to content

Adapt to fmi4c instance handles - #1638

Merged
AnHeuermann merged 2 commits into
OpenModelica:masterfrom
AnHeuermann:update-fmi4c
Sep 28, 2026
Merged

AnHeuermann merged 2 commits into
OpenModelica:masterfrom
AnHeuermann:update-fmi4c

Conversation

@AnHeuermann

@AnHeuermann AnHeuermann commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Related Issues

Some users want to compile OMSimulator on macOS. But there are some issues like OpenModelica/OMSimulator-3rdParty#94.
We should update fmi4c to the latest version. Another upside: We get rid of many compiler warnings.

Purpose

Approach

fmi4c renamed fmiHandle to fmuHandle and moved all runtime calls to fmi2InstanceHandle/fmi3InstanceHandle returned by the instantiate functions. Store that instance per component and pass it to every get/set/step/terminate call, and reset it after freeInstance to avoid a double free in the destructor.

SignalDerivative is split into FMI 2 and FMI 3 variants, since the handle types no longer alias; FMI 3 has no setRealInputDerivatives. Output derivatives are now fetched by getRealOutputDerivatives, which returns the FMI status instead of logging it inside a constructor, so getRealOutputDerivative reports a failed request as oms_status_error and no undefined values are forwarded to connected inputs.

Drop the "Loading FMI version 3..." line from the expected test results, which fmi4c no longer prints.

🤖 Generated with Claude Code

@AnHeuermann AnHeuermann self-assigned this Aug 26, 2026
@AnHeuermann AnHeuermann added the CI/Update Submodules Allow a pull request to update submodules label Aug 26, 2026
@AnHeuermann
AnHeuermann marked this pull request as draft August 26, 2026 14:58
@codecov

codecov Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 28.92157% with 145 lines in your changes missing coverage. Please review.
✅ Project coverage is 27.43%. Comparing base (ebf28bd) to head (0e256f9).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/OMSimulatorLib/SignalDerivative.cpp 0.00% 39 Missing ⚠️
src/OMSimulatorLib/ComponentFMU3CS.cpp 16.66% 9 Missing and 26 partials ⚠️
src/OMSimulatorLib/ComponentFMU3ME.cpp 40.00% 4 Missing and 26 partials ⚠️
src/OMSimulatorLib/ComponentFMUCS.cpp 28.57% 12 Missing and 8 partials ⚠️
src/OMSimulatorLib/ComponentFMUME.cpp 52.94% 7 Missing and 9 partials ⚠️
src/OMSimulatorLib/Component.h 0.00% 1 Missing ⚠️
src/OMSimulatorLib/ComponentFMU3CS.h 0.00% 1 Missing ⚠️
src/OMSimulatorLib/ComponentFMU3ME.h 0.00% 1 Missing ⚠️
src/OMSimulatorLib/ComponentFMUCS.h 0.00% 1 Missing ⚠️
src/OMSimulatorLib/ComponentFMUME.h 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1638   +/-   ##
=======================================
  Coverage   27.43%   27.43%           
=======================================
  Files          72       72           
  Lines       13889    13917   +28     
  Branches     8966     8982   +16     
=======================================
+ Hits         3810     3818    +8     
- Misses       8876     8896   +20     
  Partials     1203     1203           
Flag Coverage Δ
linux 27.43% <28.92%> (+<0.01%) ⬆️

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
AnHeuermann requested a review from arun3688 August 26, 2026 15:29
@AnHeuermann

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 26, 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 Aug 26, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change separates FMU descriptor handles from instantiated FMI 2 and FMI 3 component handles. FMI 3 derivative retrieval is implemented. FMI 3 expected outputs no longer include loading messages. The 3rdParty submodule reference is updated.

Changes

FMI instance handle separation

Layer / File(s) Summary
Handle type contracts
3rdParty, src/OMSimulatorLib/Component.h, src/OMSimulatorLib/ComponentFMU*.h, src/OMSimulatorLib/FMUInfo.*, src/OMSimulatorLib/Variable.*
Public and private APIs now use fmuHandle*. FMI 2 and FMI 3 components store separate instance handles.
Derivative handle support
src/OMSimulatorLib/SignalDerivative.*
FMI 2 derivative operations use instance handles. FMI 3 output derivatives are retrieved for the requested order and non-finite values are replaced with zero.
FMI 2 component runtime
src/OMSimulatorLib/ComponentFMUCS.cpp, src/OMSimulatorLib/ComponentFMUME.cpp
FMI 2 lifecycle, simulation, variable, derivative, event, continuous-state, and FMU state operations now use instantiated component handles.
FMI 3 component runtime
src/OMSimulatorLib/ComponentFMU3CS.cpp, src/OMSimulatorLib/ComponentFMU3ME.cpp
FMI 3 lifecycle, simulation, variable, derivative, event, continuous-state, and FMU state operations now use instantiated component handles. FMI 3 input derivative setting returns logError_NotImplemented.
Expected output updates
testsuite/tests/CompositeModels/*.py, testsuite/tests/reference-fmus/3.0/*/*.py, testsuite/tests/simulation/*.py
FMI 3 expected results no longer include Loading FMI version 3... messages.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: arun3688

Merge Risk: 🟡 Moderate · up to 3d9b6

The update changes FMI runtime handle usage but currently treats FMI 3 derivative failures as successful calls, which can allow invalid values into simulations. This bounded correctness issue should be fixed before merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.46% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 137 functions across 15 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the main change: adapting OMSimulator to fmi4c instance handles.
Description check ✅ Passed The description includes all required sections: Related Issues, Purpose, and Approach. It explains the fmi4c update, API changes, instance-handle handling, derivative changes, and test updates.
Full details: Docstring Coverage

Explanation

Docstring coverage is 1.46% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 137 functions across 15 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI

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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b5b77758-3e86-4f99-a4f5-f526989ccf90

📥 Commits

Reviewing files that changed from the base of the PR and between bb5a80f and 3d9b6a2.

📒 Files selected for processing (35)
  • 3rdParty
  • src/OMSimulatorLib/Component.h
  • src/OMSimulatorLib/ComponentFMU3CS.cpp
  • src/OMSimulatorLib/ComponentFMU3CS.h
  • src/OMSimulatorLib/ComponentFMU3ME.cpp
  • src/OMSimulatorLib/ComponentFMU3ME.h
  • src/OMSimulatorLib/ComponentFMUCS.cpp
  • src/OMSimulatorLib/ComponentFMUCS.h
  • src/OMSimulatorLib/ComponentFMUME.cpp
  • src/OMSimulatorLib/ComponentFMUME.h
  • src/OMSimulatorLib/FMUInfo.cpp
  • src/OMSimulatorLib/FMUInfo.h
  • src/OMSimulatorLib/SignalDerivative.cpp
  • src/OMSimulatorLib/SignalDerivative.h
  • src/OMSimulatorLib/Variable.cpp
  • src/OMSimulatorLib/Variable.h
  • testsuite/tests/CompositeModels/FeedthroughConnections.py
  • testsuite/tests/CompositeModels/FeedthroughSetValue1.py
  • testsuite/tests/CompositeModels/FeedthroughSetValue2.py
  • testsuite/tests/CompositeModels/connectFmi2AndFmi3.py
  • testsuite/tests/reference-fmus/3.0/cs/BouncingBall-cs.py
  • testsuite/tests/reference-fmus/3.0/cs/Dahlquist-cs.py
  • testsuite/tests/reference-fmus/3.0/cs/Feedthrough-cs.py
  • testsuite/tests/reference-fmus/3.0/cs/Resource-cs.py
  • testsuite/tests/reference-fmus/3.0/cs/Stair-cs.py
  • testsuite/tests/reference-fmus/3.0/cs/VanDerPol-cs.py
  • testsuite/tests/reference-fmus/3.0/me/BouncingBall-me.py
  • testsuite/tests/reference-fmus/3.0/me/Dahlquist-me.py
  • testsuite/tests/reference-fmus/3.0/me/Feedthrough-me.py
  • testsuite/tests/reference-fmus/3.0/me/Resource-me.py
  • testsuite/tests/reference-fmus/3.0/me/Stair-me.py
  • testsuite/tests/reference-fmus/3.0/me/VanDerPol-me.py
  • testsuite/tests/simulation/FMI3_SimpleSimulation1.py
  • testsuite/tests/simulation/FMI3_SimpleSimulation2.py
  • testsuite/tests/simulation/FMI3_SimpleSimulation3.py
💤 Files with no reviewable changes (19)
  • testsuite/tests/CompositeModels/connectFmi2AndFmi3.py
  • testsuite/tests/CompositeModels/FeedthroughSetValue2.py
  • testsuite/tests/simulation/FMI3_SimpleSimulation1.py
  • testsuite/tests/reference-fmus/3.0/me/Dahlquist-me.py
  • testsuite/tests/reference-fmus/3.0/cs/Stair-cs.py
  • testsuite/tests/reference-fmus/3.0/cs/Resource-cs.py
  • testsuite/tests/CompositeModels/FeedthroughSetValue1.py
  • testsuite/tests/reference-fmus/3.0/me/Stair-me.py
  • testsuite/tests/simulation/FMI3_SimpleSimulation2.py
  • testsuite/tests/reference-fmus/3.0/cs/VanDerPol-cs.py
  • testsuite/tests/simulation/FMI3_SimpleSimulation3.py
  • testsuite/tests/reference-fmus/3.0/cs/BouncingBall-cs.py
  • testsuite/tests/reference-fmus/3.0/me/Feedthrough-me.py
  • testsuite/tests/reference-fmus/3.0/me/BouncingBall-me.py
  • testsuite/tests/reference-fmus/3.0/me/Resource-me.py
  • testsuite/tests/reference-fmus/3.0/cs/Dahlquist-cs.py
  • testsuite/tests/reference-fmus/3.0/cs/Feedthrough-cs.py
  • testsuite/tests/reference-fmus/3.0/me/VanDerPol-me.py
  • testsuite/tests/CompositeModels/FeedthroughConnections.py

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread src/OMSimulatorLib/SignalDerivative.cpp Resolved
AnHeuermann and others added 2 commits September 28, 2026 10:52
fmi4c renamed fmiHandle to fmuHandle and moved all runtime calls to
fmi2InstanceHandle/fmi3InstanceHandle returned by the instantiate
functions. Store that instance per component and pass it to every
get/set/step/terminate call, and reset it after freeInstance to avoid
a double free in the destructor.

SignalDerivative is split into FMI 2 and FMI 3 variants, since the
handle types no longer alias; FMI 3 has no setRealInputDerivatives.

Drop the "Loading FMI version 3..." line from the expected test
results, which fmi4c no longer prints.
SignalDerivative fetched output derivatives in its constructor, so a failing
fmi2_getRealOutputDerivatives/fmi3_getOutputDerivatives was only logged and
getRealOutputDerivative still returned oms_status_ok with undefined values.
Fetch them through getRealOutputDerivatives, which returns the status and
clears the derivatives on failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AnHeuermann
AnHeuermann enabled auto-merge (squash) September 28, 2026 09:01
@AnHeuermann
AnHeuermann merged commit 77ffdaf into OpenModelica:master Sep 28, 2026
6 checks passed
@AnHeuermann
AnHeuermann deleted the update-fmi4c branch September 28, 2026 09:12
arun3688 pushed a commit to OpenModelica/OpenModelica that referenced this pull request Oct 9, 2026
The pinned OMSimulator (381bc560) looks for libOMSimulator.dll in
OMSimulator/../../../bin, which in the lib/<arch>/omc install layout is
lib/bin, one level too high, so the OMSimulator Python server does not
start on Windows and OMEdit cannot open SSP models there.

Brings in, among others:
- OpenModelica/OMSimulator#1659: the DLL directory is computed by CMake
  for the install layout, with a search fallback (fixes #17146)
- OpenModelica/OMSimulator#1664: SSP MetaData, including the SSD-level
  MetaData that attaches omuq studies, is kept on import/export (#17074)
- OpenModelica/OMSimulator#1638: adapt to fmi4c instance handles
- reset support and instance name fixes in the fmu class, the PySide6
  OMSimulatorGui enabled by default, macOS arm64 CI

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant