ThummeTo / FMIImport.jl

FMIImport.jl implements the import functionalities of the FMI-standard (fmi-standard.org) for the Julia programming language. FMIImport.jl provides the foundation for the Julia packages FMI.jl and FMIFlux.jl.
MIT License
18 stars 17 forks source link

Different (correct) handling of dependencies="" #130

Open halentin opened 1 day ago

halentin commented 1 day ago

The standard specifies different behaviour for dependencies="" and the dependencies-Tag not being present at all:

If dependencies is not present, it must be assumed that the unknown depends on all knowns. If dependencies is present as empty list, the unknown depends on none of the knowns. Otherwise the unknown depends on the knowns defined by the given value references.

(from FMI3-Standard)

Currently we handle the first and second case identically with modelDescription.modelStructure.continuousStateDerivatives[n].dependencies = nothing. This leads to some very pessimistic handling of dependency-information in the second case. We basically have to assume that every variable that actually depends on nothing depends on everything instead. If a FMU has even one of those, we dont gain any performance from using Sparsity-Information.

I propose to leave the first case as it is (modelStructure.continuousStateDerivatives[n].dependencies = nothing) and using an empty array for the second case (modelStructure.continuousStateDerivatives[n].dependencies = UInt[]). This makes it possible to differentiate the two cases while adding minimal overhead (1 pointer/allocation per empty dependencies and they are not that common as far as i can tell).

This PR contains the behaviour described above, as well as Tests for it.

Note that there are currently no FMI3-Reference-FMUs with dependencies="", so there is currently no Test for this case. I submitted an upstream-Issue: https://github.com/modelica/Reference-FMUs/issues/597#issue-2559398283