Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#5497 closed defect (invalid)

OMC accepting illegal edge operator and generating wrong code

Reported by: Andreas Heuermann Owned by: somebody
Priority: high Milestone: 2.0.0
Component: Frontend Version: v1.14.0-dev-nightly
Keywords: edge relation Cc:

Description

OMC accepts edge operator with a relation as input. The modelica reference https://build.openmodelica.org/Documentation/ModelicaReference.Operators.%27edge()%27.html states that edge should only accept boolean values.
Whe should generate a warning or an error.

The backend-DAE is also wrong. For the model

model HystereseBug
  input Real u;
  output Real y;
equation
  when {u>1, u<-1} then
    y = if edge(u>u_max) then 1 else -1;
  end when;
end HystereseBug;

edge(u>u_max) gets expandet to edge(u)>edge(u_max) and that generates wrong code:

hystBug._y = if (hystBug.u and not pre(hystBug.u)) > (hystBug.u_max and not hystBug.u_max) then 1.0 else -1.0;

Suggested solution:
Add a warning from Frontend for these kind of edge usage.
Add a tmp variable and replace it in edge. Then everything in the backend should (hopefully) work with edge(tmp).

Change History (3)

comment:1 by Andreas Heuermann, 6 years ago

Resolution: invalid
Status: newclosed

comment:2 by Francesco Casella, 6 years ago

@AnHeuermann, why was this invalid?

comment:3 by Andreas Heuermann, 6 years ago

It's allready fixed with the new frontend.

Last edited 6 years ago by Andreas Heuermann (previous) (diff)
Note: See TracTickets for help on using tickets.