CATIA-Systems / FMIKit-Simulink

Import and export Functional Mock-up Units with Simulink
Other
157 stars 51 forks source link

Direct Feedthrough in CoSimulation #219

Closed RobertoHRO closed 3 years ago

RobertoHRO commented 4 years ago

Hello Torsten,

in CoSimulation mode the S-function sfun_fmurun.* initialises the outputs to 0 - always. Can you adapt sfun_fmurun so that the outputs can be initialised correctly? In my opinion, it basically means that at least during initialisation the inputs can have direct feedthrough to the outputs also in CoSimulation mode.

I have built a minimum example based Testmodel1.slx. - This shows that sfun_fmurun in CoSimulation fmus gives a wrong result after the zero time step. On your request I will eMail it to you.

Suggested solution: Instead of the sequence:

mdlStart() 
fmi2Instantiate(…)
fmi2SetupExperiment(…)
fmi2EnterInitializationMode()
fmi2ExitInitializationMode()
mdlInitializeConditions() 
mdlOutputs() 

you could implement this sequence:

mdlStart() 
fmi2Instantiate(…)
fmi2SetupExperiment(…)
fmi2EnterInitializationMode()
fmi2SetReal(…)
fmi2ExitInitializationMode()
mdlInitializeConditions() 
mdlOutputs() 

Unfortunately this exceeds my CPP skills. At the end I would like to say thank you for this great tool. thank you!

Best regards Robert

t-sommer commented 4 years ago

What variables do you want to set in fmi2SetReal(…) in your proposed sequence, inputs and/or parameters?

RobertoHRO commented 4 years ago

Both, inputs and parameters.

A system which just outputs a parameter or input, should do this also at t=0.

chrbertsch commented 4 years ago

Having direct feedthrough at t=0 would if only be possible of the inputs of the underlying s-function would have the HasDirecththrough property. This will cause Simulink to localize lots of algebraic loops and cause much pain. Even though it is not nice, outputs start values have to be taken from parameters where there is no such problem.

RobertoHRO commented 4 years ago

Fortunately my initial outputs are so trivial that I can set them with FMIKit.setStartValue before the simulation. I would appreciate it if at least the parameters in the initialization of CoSimulation models would have a direct feedthrough.

t-sommer commented 4 years ago

I would appreciate it if at least the parameters in the initialization of CoSimulation models would have a direct feedthrough.

This should be the case. Can you provide steps to reproduce the problem?

RobertoHRO commented 4 years ago

I have built a minimum example based Testmodel1.slx. - The CoSimulation GRT fmu gives 0 on all outputs at t=0. feedthrough_test.zip

t-sommer commented 3 years ago

This should be fixed with 0f3821d078744adc8d2483f83bc9563521d6ba62