open-simulation-platform / libcosim

OSP C++ co-simulation library
https://open-simulation-platform.github.io/libcosim
Mozilla Public License 2.0
61 stars 10 forks source link

Run fmi2SetXXX function to initialize FMU start values #778

Open davidhjp01 opened 1 week ago

davidhjp01 commented 1 week ago

According to FMI 2.0.4 spec (Section 4.2.4), start values are read during instantiated state via fmi2SetXXX . But libcosim does not run these functions in instantiated state and this makes some of FMUs exported (e.g. Simulink) not initializing values accordingly.

For example see below cosim_demo_app that runs an integrator whose initial condition is set via parameter Parameter.Integrator_x0:

image image

The initial condition is not properly set via the parameter (i.e. not starting from 10). On the other hand, fmpy properly initialize this value when set in the simulation setting: image

To fix this, this PR added an additional function initialize_start_values() that runs before simulator::setup() in fixed_step_algorithm::cosim::impl::initialize()

Check state_init_test.cpp to observe different behaviours with the previous libcosim version

davidhjp01 commented 2 days ago

I guess this PR contains some conflicts with #777, will need to update based on the merge :)