CATIA-Systems / FMIKit-Simulink

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

Error when running created FMU with FMIKit-Simulink 2.8 and 2.9 (ModelExchange) #236

Closed YTV1590 closed 3 years ago

YTV1590 commented 3 years ago

Hello,

I am using R2017b and have managed to export an FMU using the FMIKit-Simulink 2.7, 2.8 and 2.9. However, when trying to import the FMU and running my simulation, I keep getting the error with the FMU exported with version 2.8 and 2.9:

An error occurred while running the simulation and the simulation was terminated Caused by: Auto solver has detected that the Jacobian matrix at time t=0.0 has entries which are not finite. The simulation will be stopped. There may be a singularity in the solution. If not, try reducing the step size (either by reducing the maximum step size or by tightening the error tolerances)

Or sometimes, this comes up:

An error occurred while running the simulation and the simulation was terminated Caused by: Derivative of state 'FMUMe' in block 'FMU1' at time 0.0 is not finite. The simulation will be stopped. There may be a singularity in the solution. If not, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances)

However when I do the simulation, using the FMU exported with 2.7, no error appears. I was hoping, that someone can help with this issue. Does the problem lie in my model block? But why does the simulation work with 2.7 but not with 2.8 or 2.9? Running the simulation with the model as a Simulink block rather than a FMU also works fine.

Reducing the fixed step size does not work for me though. I also tried changing the Solver many times but the error still remains.

Any help is appreciated.

Thank you!

t-sommer commented 3 years ago

Can you provide steps to reproduce the problem?

YTV1590 commented 3 years ago

Hi, thank you for reply.

For the export with your FMIKit, I build the FMU based on S-Function with FMI type ModelExchange and therefore have set the system target file to rtwsfcnfmi.tlc. The Solver type is set to Variable-step for the build and the CMake generator is set to MSYS Makefiles.

In order to be able to output a FMU, I have made some changes in some scripts because otherwise it would output me some errors. Those are not big changes but I am not sure if the changes might be responsible for the fmu not working probably, so I am going to state my changes here:

There were no changes necessary for FMIKit-Simulink-2.7 needed before doing the build with this version because no error appeared.

For the simulation and use of the exported the FMU, I have imported the FMU in my simulink model and set the Solver type to Variable-step and the solver to ode14x and fed my input on it.

Hope those informations help.

Thank you! Looking forward to your next reply :)

YTV1590 commented 3 years ago

I would like to add some information. Before doing all those changes, the first error I would get is:

Path_to_FMIKit-Simulink/rtwsfcnfmi/fmi2Functions.c: In function 'fmi2Reset':
Path_to_FMIKit-Simulink/rtwsfcnfmi/fmi2Functions.c:276:59: warning: passing argument 2 of 'InstantiateModel' from incompatible pointer type [-Wincompatible-pointer-types]
  Model *new_model = InstantiateModel(model->instanceName, logMessage, model->isCoSim, model->userData);

In file included from Path_to_FMIKit-Simulink/rtwsfcnfmi/fmi2Functions.c:20:
Path_to_FMIKit-Simulink/rtwsfcnfmi/sfunction.h:70:8: note: expected 'logMessageCallback' {aka 'void (*)(struct Model_s *, enum <anonymous>,  const char *, ...)'} but argument is of type 'void (*)(Model *, int,  const char *, ...)' {aka 'void (*)(struct Model_s *, int,  const char *, ...)'}
 Model *InstantiateModel(const char* instanceName, logMessageCallback logMessage, int isCoSim, void *userData);

Why would the type of the variable 'logMessage' turn out to be of type int instead of logMessageCallback here? Where and in which script can I see where the variable 'logMessage' is set?

Thanks in advance.

t-sommer commented 3 years ago

Can you share a Simulink model to reproduce the problem?