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:2 by , 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.
follow-up: 13 comment:3 by , 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 , 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 :)
comment:6 by , 10 years ago
Milestone: | 1.9.1 → 1.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 , 10 years ago
Milestone: | 1.9.2 → 1.9.3 |
---|
Milestone changed to 1.9.3 since 1.9.2 was released.
comment:12 by , 8 years ago
Milestone: | 1.11.0 → 1.12.0 |
---|
Milestone moved to 1.12.0 due to 1.11.0 already being released.
comment:13 by , 7 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
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.
This corresponds to Wolfram MathCore ticket 3932.