Opened 12 years ago

Closed 7 years ago

#2015 closed defect (invalid)

Illegal discrete var assignement in if clause doesn't give error message

Reported by: Peter Aronsson Owned by: somebody
Priority: high Milestone: 1.12.0
Component: Frontend Version: 1.9.0Beta
Keywords: Cc:

Description

The following model is illegal:

class IllegalDiscreteVarInIfClause
  Real x(start = 1.0, fixed = true);
  Boolean b;
equation
  der(x) = -time;
  if noEvent(x < 0.5) then
  b = true;
  else
  b = false;
  end if;
end IllegalDiscreteVarInIfClause;

Because of the following statement in the modelica language specification:
Inside an if-expression, if-clause or for-clause, that is controlled by a non-discrete time switching expression
and not in the body of a when-clause, it is not legal to have assignments to discrete variables, equations between
discrete-time expressions, or real elementary relations/functions that should generate events. [This restriction is
necessary in order to guarantee that there all equations for discrete variable are discrete-time expressions, and to
ensure that crossing functions do not become active between events.]
(Version 3.3 page 32.

This does not produce an error message in OpenModelica 1.9.0 beta2

Change History (13)

comment:1 by Jan Brugård, 12 years ago

This corresponds to Wolfram MathCore ticket 3932.

Last edited 12 years ago by Jan Brugård (previous) (diff)

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

I was going to write something about this being the backend's job since you cannot know for sure if the variable is continuous or not in the frontend. But then I saw the noEvent().

Is noEvent the only way to make continous boolean expressions? If so it should be feasible to fix this.

comment:3 by Jan Brugård, 12 years ago

It is possible to make in other ways, e.g.

class IllegalDiscreteVarInIfClause
  Real x(start = 1.0, fixed = true);
  Boolean b;
  Boolean b2=<some continous expression>
equation
  der(x) = -time;
  if b2 then
  b = true;
  else
  b = false;
  end if;
end IllegalDiscreteVarInIfClause;

Independent of this, this should still be a frontend issue as there are a lot of things that the front-end needs to check depending on the variability of expressions (discrete or continuous).

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

No, that b2 is a discrete-time expression according to the specification:

3.8.3 Discrete-Time Expressions
Discrete-time expressions are:

  • Parameter expressions
  • Discrete-time variables, i.e., Integer, Boolean, String variables and enumeration variables, as well as Real variables assigned in when-clauses
  • ...

I believe this means that b2 is sampled whenever an event occurs, but it still is discrete. Find some other way of creating continuous boolean variables other than noEvent :)

Last edited 12 years ago by Martin Sjölund (previous) (diff)

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

Milestone: 1.9.01.9.1

Postponed until 1.9.1

comment:6 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:7 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:8 by Martin Sjölund, 9 years ago

Milestone: 1.9.31.9.4

Moved to new milestone 1.9.4

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

Milestone: 1.9.41.9.5

Milestone pushed to 1.9.5

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

Milestone: 1.9.51.10.0

Milestone renamed

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

Milestone: 1.10.01.11.0

Ticket retargeted after milestone closed

comment:12 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.

in reply to:  3 comment:13 by Francesco Casella, 7 years ago

Resolution: invalid
Status: newclosed

Replying to brugard:

It is possible to make in other ways, e.g.

class IllegalDiscreteVarInIfClause
  Real x(start = 1.0, fixed = true);
  Boolean b;
  Boolean b2=<some continous expression>
  ...

I may be wrong, but I can't see how a continuous expression could be assigned to a boolean variable, which is discrete by definition.

Note: See TracTickets for help on using tickets.