Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illegal call sequence #154

Open
AnHeuermann opened this issue Oct 26, 2022 · 1 comment
Open

Illegal call sequence #154

AnHeuermann opened this issue Oct 26, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@AnHeuermann
Copy link

Description

I think I'm using FMI.jl to call FMI2 functions in an illegal call sequence.
When the FMU is in event mode it should not be allowed to call fmi2SetReal on a non-input variable.

I'm not sure if I want this to get fixed, because I'm doing it wrong by changing a non-input variable that is not a state
and need this capability of FMI.jl.

How to reproduce

Create a FMI 2 ModelExchange FMU with e.g. OpenModelica for

model simpleLoop
  Real r(min = 0);
  Real s(min = -sqrt(2), max = sqrt(2));
  Real x(start=1.0), y(start=0.5);
  Real x_ref, y_ref;
equation
  r = 1+time;
  s = sqrt((2-time)*0.9);

  r^2 = x^2 + y^2;
  r*s = x + y;

  x_ref = r * (s/2 + sqrt(1/2-s^2/4));
  y_ref = r*s - x_ref;
end simpleLoop;

Here variables r and s should have default variability continuous and causality local:

<ScalarVariable
  name="r"
  valueReference="0"
  >
  <Real min="0.0"/>
</ScalarVariable>
<ScalarVariable
  name="s"
  valueReference="1"
  >
  <Real min="-1.414213562373095" max="1.414213562373095"/>
</ScalarVariable>

Judging from the State Machine of Calling Sequence (FMI Specification 2.0.2 section 3.2.3) it is only allowed to call fmi2SetReal on a real input variables.
So if it has causality=input and variability=continuous
or it has causality=input and variability=discrete
or variability=tunable.

As far as I can tell FMI.jl is not stopping me from calling fmiSet on r or s.

import FMI
import FMIImport
fmu = FMI.fmiLoad("simpleLoop.fmu")
FMI.fmiInstantiate!(fmu)
# FMU instantiated
FMI.fmiSetupExperiment(fmu, 0.0, 1.0)
FMI.fmiEnterInitializationMode(fmu)
# FMU in initialization iode
FMI.fmiExitInitializationMode(fmu)
# FMU in event mode
FMIImport.fmi2SetReal(fmu, "r", 42)  # Illegal call

Expected Result

Throw an error when calling fmi2SetReal is not allowed and add a flag to allow illegal call sequences anyway.

Versions 'n Stuff

  • Julia: Julia Version 1.8.1
  • OS: Ubuntu Focal
  • FMI.jl v0.10.0
  • FMIImport.jl v0.11.1
@ThummeTo
Copy link
Owner

ThummeTo commented Dec 9, 2022

Jap, we can check for that.
However most FMUs return warnings/errors if calling sequence is violated - in some cases variables are settable without issues (and applied) even if it's against the calling sequence (e.g. because the properties defined in the model description aren't 100% correct), so we should not prevent the user from doing so if the FMU can handle it. Warning seems a nice in-between.

@ThummeTo ThummeTo added the enhancement New feature or request label Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants