Opened 10 years ago

Closed 10 years ago

#3057 closed defect (fixed)

Erronous FMI ModelStructure

Reported by: Rüdiger Franke Owned by: Willi Braun
Priority: critical Milestone: 1.9.2
Component: FMI Version: trunk
Keywords: Cc:

Description

In many cases the ModelStructure generated for FMI 2 is wrong. The following example triggers some of the problems:

model ModelStructureTest
  parameter Integer switch = 1;
  parameter Real p = 1;
  input Real u1;
  input Real u2;
  output Integer y1;
  output Real y2;
equation
  y1 = switch;
  if switch > 0 then
    y2 = p*u1;
  else
    y2 = u2;
  end if;
end ModelStructureTest;

OpenModelica #23881 generates the following modelDescription.xml:

<ModelVariables>
  <!-- Index of variable = "3" -->
  <ScalarVariable name="u1" valueReference="0" variability="continuous" causality="input" initial="approx"><Real/></ScalarVariable>
  <!-- Index of variable = "4" -->
  <ScalarVariable name="u2" valueReference="1" variability="continuous" causality="input" initial="approx"><Real/></ScalarVariable>
  <!-- Index of variable = "5" -->
  <ScalarVariable name="y2" valueReference="2" variability="continuous" causality="output" initial="calculated"><Real/></ScalarVariable>
  <!-- Index of variable = "7" -->
  <ScalarVariable name="p" valueReference="3" variability="fixed" causality="parameter" initial="exact"><Real start="1.0"/></ScalarVariable>
  <!-- Index of variable = "6" -->
  <ScalarVariable name="y1" valueReference="0" variability="discrete" causality="output" initial="calculated"><Integer/></ScalarVariable>
  <!-- Index of variable = "8" -->
  <ScalarVariable name="switch" valueReference="1" variability="fixed" causality="parameter" initial="exact"><Integer start="1"/></ScalarVariable>
</ModelVariables>
<ModelStructure>
  <Outputs>
    <Unknown index="5" dependencies="3" dependenciesKind="dependent"/>
    <Unknown index="6"/>
  </Outputs>
  <Derivatives></Derivatives>
  <InitialUnknowns></InitialUnknowns>
</ModelStructure>

The ModelVariables and ModelStructure exhibit the following errors:

  1. ModelVariables starts with index 3 instead of 1 (because the model contains no states?)
  2. ModelVariables lists the indices 5, 7, 6, 8 in this order (because the model contains integers?)
  3. ModelStructure/Outputs doesn't mention the dependency of y2 on u2 (because the parameter switch gets evaluated -- it works with an input switch?)

Change History (10)

in reply to:  description ; comment:1 by Willi Braun, 10 years ago

Owner: changed from Adeel Asghar to Willi Braun
Status: newaccepted

Replying to rfranke:

The ModelVariables and ModelStructure exhibit the following errors:

  1. ModelVariables starts with index 3 instead of 1 (because the model contains no states?)

Yes, it's because the model contains no states and
we add for some reasons a strange dummy state.

  1. ModelVariables lists the indices 5, 7, 6, 8 in this order (because the model contains integers?)

Yes, it's because of the integers.

  1. ModelStructure/Outputs doesn't mention the dependency of y2 on u2 (because the parameter switch gets evaluated -- it works with an input switch?)

No, the parameter shouldn't evaluated, I'll check that.

Last edited 10 years ago by Willi Braun (previous) (diff)

in reply to:  1 comment:2 by Willi Braun, 10 years ago

Replying to wbraun:

Replying to rfranke:

The ModelVariables and ModelStructure exhibit the following errors:

  1. ModelVariables starts with index 3 instead of 1 (because the model contains no states?)

Yes, it's because the model contains no states and
we add for some reasons a strange dummy state.

fixed in r23937.

in reply to:  1 comment:3 by Willi Braun, 10 years ago

Replying to wbraun:

Replying to rfranke:

The ModelVariables and ModelStructure exhibit the following errors:

  1. ModelVariables lists the indices 5, 7, 6, 8 in this order (because the model contains integers?)

Yes, it's because of the integers.

fixed in r23939.

in reply to:  1 comment:4 by Willi Braun, 10 years ago

Resolution: fixed
Status: acceptedclosed

Replying to wbraun:

Replying to rfranke:

The ModelVariables and ModelStructure exhibit the following errors:

  1. ModelVariables starts with index 3 instead of 1 (because the model contains no states?)

Yes, it's because the model contains no states and
we add for some reasons a strange dummy state.

  1. ModelVariables lists the indices 5, 7, 6, 8 in this order (because the model contains integers?)

Yes, it's because of the integers.

  1. ModelStructure/Outputs doesn't mention the dependency of y2 on u2 (because the parameter switch gets evaluated -- it works with an input switch?)

No, the parameter shouldn't evaluated, I'll check that.

Okay, yes the parameter is replaced in FrontEnd(see #3059), so the output is correct to the input ;).

comment:5 by Rüdiger Franke, 10 years ago

The changes didn't make it into today's nightly build for Windows anymore -- it's still r23933 :-(

Under Linux I got r23940 and there it looks good!

Btw. something went wrong with the binaries path under Linux recently. Since a couple of weeks it's not called binaries/linux64 anymore, but binaries/makefileParams.platform!?

Regarding the parameters: couldn't modelDescription.xml skip structural parameters to make sure that they cannot be modified anymore?

Alternatively structural parameters might be marked with causality="calculatedParameter", as seen for finalized parameters, e.g. when declaring:

model ModelStructureTest
  final parameter Integer switch = 1;
  ...

in reply to:  5 ; comment:6 by Willi Braun, 10 years ago

Replying to rfranke:

The changes didn't make it into today's nightly build for Windows anymore -- it's still r23933 :-(

Under Linux I got r23940 and there it looks good!

Btw. something went wrong with the binaries path under Linux recently. Since a couple of weeks it's not called binaries/linux64 anymore, but binaries/makefileParams.platform!?

I had changed there something, but it works for me, anyway, I'll check that.

Regarding the parameters: couldn't modelDescription.xml skip structural parameters to make sure that they cannot be modified anymore?

Alternatively structural parameters might be marked with causality="calculatedParameter", as seen for finalized parameters, e.g. when declaring:

model ModelStructureTest
  final parameter Integer switch = 1;
  ...

That sound reasonable, I'll see what I can do.

in reply to:  6 comment:7 by Willi Braun, 10 years ago

Replying to wbraun:

Replying to rfranke:

Btw. something went wrong with the binaries path under Linux recently. Since a couple of weeks it's not called binaries/linux64 anymore, but binaries/makefileParams.platform!?

I had changed there something, but it works for me, anyway, I'll check that.

Hopefully it's fixed in r23946.

in reply to:  5 comment:8 by Willi Braun, 10 years ago

Replying to rfranke:

The changes didn't make it into today's nightly build for Windows anymore -- it's still r23933 :-(

That because the windows nightly build failed last night :(.

comment:9 by Rüdiger Franke, 10 years ago

Resolution: fixed
Status: closedreopened

Testing the fixes, a remaining fourth problem shows up: The index counter jumps if there are constants present. The example:

model ModelStructureTest2
  parameter Integer switch = 1;
  constant Real p = 1;
  input Real u1;
end ModelStructureTest2;

gives:

<ModelVariables>
  <!-- Index of variable = "1" -->
  <ScalarVariable name="u1" initial="approx" causality="input" variability="continuous" valueReference="0"><Real/></ScalarVariable>
  <!-- Index of variable = "3" -->
  <ScalarVariable name="switch" initial="exact" causality="parameter" variability="fixed" valueReference="0"><Integer start="1"/></ScalarVariable>
</ModelVariables>

comment:10 by Willi Braun, 10 years ago

Resolution: fixed
Status: reopenedclosed

fixed again in r23962.

Note: See TracTickets for help on using tickets.