Opened 8 years ago

Last modified 7 years ago

#4432 new defect

unbalanced if-eqns are not detected

Reported by: anonymous Owned by: somebody
Priority: high Milestone: Future
Component: *unknown* Version: v1.12.0
Keywords: Cc:

Description

Following model is accepted even it is not really balanced. Also the result is really odd.

model ifeqns
  Real x(start=-1);
  Real y1,y2;
equation 
der(x) = sin(time);

if x > 0 then
  y1 = x;
  y2 = 2*y1*x;
elseif x > 0.75 then
  y2 = 2.0;
else
  y2 = 2*x;
  y1 = 3*x;
end if;

end ifeqns;

Change History (4)

comment:1 by Lennart Ochel, 8 years ago

Well, this model is not really accepted. It just passes the frontend, however the issue is detected later on and even the error message is quite helpful:

[<interactive>:8:1-16:7:writable] Error: If-equation with conditions that are not parameter expressions must have the same number of equations in each branch, equation count is {2,1,2} for each respective branch:
1 : y2 = 2.0 * y1 * x
2 : y1 = x
1 : y2 = 2.0
1 : y1 = 3.0 * x
2 : y2 = 2.0 * x

There are two issues to fix:

  • Don’t continue compilation when an error message is triggered.
  • Catch this already in the frontend.

comment:2 by Lennart Ochel, 8 years ago

The compilation continuous because of badly nested matchcontinue statements …

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

PR1957 moves this check to the BackendDAECreate part of the compiler, but I am unsure if there might be some models with parameter conditions that are evaluated in the backend at a later stage that would stop working with this change (in that case, there would need to be a check just before code generation).

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

@lochel - it seems my fears are true. Should we move the check for unbalanced if-equations to the simcode or should we evaluate the conditions during/before BackendDAECreate?

Note: See TracTickets for help on using tickets.