Opened 7 years ago
Closed 7 years ago
#4455 closed defect (fixed)
Unreasonable high deviation between imported FMU and original model
Reported by: | Bernhard Thiele | Owned by: | Lennart Ochel |
---|---|---|---|
Priority: | high | Milestone: | Future |
Component: | FMI | Version: | |
Keywords: | Cc: | Lennart Ochel, Adrian Pop |
Description
I wrote an exercise for exporting and importing model-exchange FMUs using OpenModelica and observed rather large deviations between the original model and the imported FMU which I can't explain. Exercise and underlying model are attached to this ticket.
The model below feeds the original PI controller with the same input as the FMU wrapped PI controller.
If I simulate that using standard settings (dassl, tolerance 1e-6) and plot the respective outputs, I get following result:
It is possible to get closer if one manually sets the step size and makes it very small (e.g., Euler with step size 0.0001s). The strange thing is, that the FMU is rather sensitive to changing the step size, e.g., for 0.001s it will be significantly different than for 0.0001s, while the result for the Modelica PI will not change significantly when doing this change.
Attachments (6)
Change History (10)
by , 7 years ago
Attachment: | screenshot1.png added |
---|
by , 7 years ago
by , 7 years ago
Attachment: | FMIExercise.mo added |
---|
by , 7 years ago
Attachment: | FMIExercise.pdf added |
---|
comment:1 by , 7 years ago
by , 7 years ago
by , 7 years ago
Attachment: | FMIExercise_Components_PI_me_FMU.mo added |
---|
Manually changed import file which is more closely aligned to the pseudo code in the specification
comment:2 by , 7 years ago
Update: I have implemented the idea in PR https://github.com/OpenModelica/OMCompiler/pull/1712, but it needs some extra checking.
comment:3 by , 7 years ago
Actually everything passes the testsuite, which surprises me a bit since some FMI tests failed when running them on my local machine (due to slighly different output to stdout).
https://test.openmodelica.org/hudson/job/OpenModelica_TEST_PULL_REQUEST/4372/
I think we can and should merge the PR.
@adrpo, @lochel: Do you have comments?
comment:4 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I merged the PR which should fix the issue.
I looked at the generated Modelica import code (
FMIExercise_Components_PI_me_FMU.mo
) and tried to improve it.The current import code doesn't enforce a particular ordering when setting the inputs. By using an algorithm section, as indicated in the diff below, it is possible to enforce that the input is set directly after the new time is set:
This gives a better result, e.g., simulation using euler with a step size of 0.001s results in:
Hence, it seems reasonable to change the importer if that improved results hold in general.
I also tried to programmatically change the logic so that it resembles more closely to the pseudo code given in the specification. The resulting file is attached. It works for this example, but misses more generic features (no event handling). Anyway, I will attach it, so that it is not lost.