CATIA-Systems / FMIKit-Simulink

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

dont write 'INF' into modelDescription.xml #364

Open j-heyden opened 2 years ago

j-heyden commented 2 years ago

According to FMI standard using INF in xml files is not allowed (https://github.com/modelica/fmi-standard/issues/1784).

If there is a Simulink block Saturation, where the upper limit has the value inf and all parameters are visible (set_param(Sysroot,'VisibleParameters','')), this leads to

<ScalarVariable name="Parameters.Saturation_UpperSat" valueReference="1" causality="parameter" variability="tunable">
  <Real start="INF"/>
</ScalarVariable>

when using FMIKit 3.0 and Matlab 2021b. This INF is then wrong interpreted by other tools, as INF is not a allowed value.

t-sommer commented 2 years ago

What would be your preferred behavior for non-finite start values in FMI 2.0?

chrbertsch commented 2 years ago

What would be your preferred behavior for non-finite start values in FMI 2.0?

What about using the maximum allowed values?

t-sommer commented 2 years ago

The start value in the XML has to match the value in the binary. So you have two options:

oliverkotte commented 2 years ago

but isn't @chrbertsch 's suggestion a valid third option? the values in the XML and binary would match by convention, the max allowed value in the XML would correspond to INF in the binary.

t-sommer commented 2 years ago

If you have the following parameter in the binary

#include <math.h>

double Saturation_UpperSat = INFINITY;

// ...

how do you want to represent its start value in the XML without using the literal INF?

chrbertsch commented 2 years ago

how do you want to represent its start value in the XML without using the literal INF?

Perhaps it would be best (for FMI 2.0 FMUs) to replace INF during Code and XML generation by DBL_MAX (approx 1.8e308). Then XML and Code would be consistent.

This would work, if there are no hard comparisons to INF in the Code. (e.g., if x==INF)

t-sommer commented 2 years ago

You cannot make assumptions about the importers code. E.g. isfinite(x) would give different results when using the value from the XML vs. the binary.