Opened 12 years ago

Closed 6 years ago

#1991 closed defect (fixed)

StateSelect Attribute with unfixed parameters wrong evaluated without warning

Reported by: Jens Frenkel Owned by: Per Östlund
Priority: high Milestone: 2.0.0
Component: New Instantiation Version: trunk
Keywords: Cc: Martin Sjölund, Willi Braun, Lennart Ochel

Description (last modified by Jens Frenkel)

Consider the following model. The state select attribute is set via unfixed parameters. The FrontEnd evaluates the unfixed parameters but report no warning about that. The result is totaly different to the exprected from the modelers view for y and z.

model StateSelectCheck
  parameter Boolean preferredStates=true;
  parameter Boolean preferredStatesUnfixed(fixed=false);
  parameter Boolean preferredStatesUnfixedStart(fixed=false,start=true);
  Real x(stateSelect = if preferredStates then StateSelect.prefer else StateSelect.avoid);
  Real y(stateSelect = if preferredStatesUnfixed then StateSelect.prefer else StateSelect.avoid);
  Real z(stateSelect = if preferredStatesUnfixedStart then StateSelect.prefer else StateSelect.avoid);
initial equation
  preferredStatesUnfixed = true;
  preferredStatesUnfixedStart = false;
equation
  der(z) = time;
  0 = x^2 + y^2 + z^2;
  y = x + z;
end StateSelectCheck;

Result after the FrontEnd:

class StateSelectCheck
  parameter Boolean preferredStates = true;
  parameter Boolean preferredStatesUnfixed(fixed = false);
  parameter Boolean preferredStatesUnfixedStart(start = true, fixed = false);
  Real x(StateSelect = StateSelect.prefer);
  Real y;
  Real z(StateSelect = StateSelect.prefer);
initial equation
  preferredStatesUnfixed = true;
  preferredStatesUnfixedStart = false;
equation
  der(z) = time;
  0.0 = x ^ 2.0 + y ^ 2.0 + z ^ 2.0;
  y = x + z;
end StateSelectCheck;

Attachments (1)

StateSelectCheck.mo (673 bytes ) - added by Jens Frenkel 12 years ago.

Download all attachments as: .zip

Change History (17)

by Jens Frenkel, 12 years ago

Attachment: StateSelectCheck.mo added

comment:1 by Jens Frenkel, 12 years ago

Description: modified (diff)

comment:2 by Martin Sjölund, 12 years ago

Note that it is valid for a tool to reject non-fixed structural parameters. That is, if the parameter cannot be evaluated like a constant, we could reject the model.

comment:3 by Martin Sjölund, 11 years ago

Milestone: 1.9.01.9.1

Postponed until 1.9.1

comment:4 by Martin Sjölund, 10 years ago

Milestone: 1.9.11.9.2

This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).

comment:5 by Martin Sjölund, 10 years ago

Milestone: 1.9.21.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

comment:6 by Martin Sjölund, 9 years ago

Milestone: 1.9.31.9.4

Moved to new milestone 1.9.4

comment:7 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.5

Milestone pushed to 1.9.5

comment:8 by Martin Sjölund, 9 years ago

Milestone: 1.9.51.10.0

Milestone renamed

comment:9 by Martin Sjölund, 8 years ago

Milestone: 1.10.01.11.0

Ticket retargeted after milestone closed

comment:10 by Martin Sjölund, 8 years ago

Milestone: 1.11.01.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:11 by Lennart Ochel, 7 years ago

Yes, that model should be rejected. But in fact, the state select attribute of y and z is ignored, i.e. removed, without any feedback.

comment:12 by Francesco Casella, 7 years ago

Component: FrontendNew Instantiation
Milestone: 1.12.02.0.0
Owner: changed from Adrian Pop to Per Östlund
Status: newassigned

As of v1.13.0-dev-155-g68350e9, using the new front end, the translation fails with

[1] 01:35:33 Translation Error
Internal error Instantiation of M failed with no error message.

[2] 01:35:34 Scripting Error
[C:/dev/OpenModelica64bit/OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo:1314:9-1314:72:writable]Modelica Assert: NFFlatten.makeStateSelectAttribute got non StateSelect value! 

I guess this is the expected behaviour, even though the error message is not that clear. @perost can you please check?

comment:13 by Francesco Casella, 7 years ago

The error message is now

[1] 19:11:38 Translation Error
[C:/dev/OpenModelica64bit/OMCompiler/Compiler/NFFrontEnd/NFCeval.mo: 1096:9-1097:96]:
Internal error NFCeval.evalIfExp:
unimplemented case for if preferredStatesUnfixed then StateSelect.prefer else StateSelect.avoid

I guess a clearer error message is still needed.

comment:14 by Francesco Casella, 6 years ago

Still valid as of v1.13.0-dev-798-g1c8bb86de

in reply to:  14 comment:15 by Per Östlund, 6 years ago

Replying to casella:

Still valid as of v1.13.0-dev-798-g1c8bb86de

The NF actually detected the error, but the logic for when to print an error message was wrong. With the fix in cc477d0 the model now fails with:

[test.mo:3:3-3:56:writable] Notification: From here:
[test.mo:6:10-6:96:writable] Error: Constant preferredStatesUnfixed is used without having been given a value.

Good enough?

comment:16 by Francesco Casella, 6 years ago

Resolution: fixed
Status: assignedclosed

Excellent!

Note: See TracTickets for help on using tickets.