Opened 6 years ago

Last modified 3 years ago

#5041 new defect

assert on parameters are not called in the right order

Reported by: Francesco Casella Owned by: Lennart Ochel
Priority: critical Milestone:
Component: Backend Version:
Keywords: Cc:

Description

Please consider the following test case

model TestInitialAssert
  parameter Real p = 0;
  parameter Real q = 1/p;
initial equation
  assert(p > 0, "p must be positive");
end TestInitialAssert;

OMEdit fails with

assert | debug | division by zero at time 0, (a=1) / (b=0), where divisor b expression is: p

In fact, the model contains an assertion on p that could convey more useful information to the end user, but which is not triggered because the expression 1/p is evaluated first and causes the initialization to fail, which is precisely the reason why the assertion was put there in the first place.

Recommendation: assertions should be evaluated as early as possible in the BLT, i.e. as soon as the variables/parameters they depend on have been computed.

In this case, the assertion on p should be computed right after the binding equation p = 1 has been evaluated, also in the case the assertion is put in the equation section.

Change History (4)

comment:1 by Francesco Casella, 5 years ago

Milestone: 1.14.01.16.0

Releasing 1.14.0 which is stable and has many improvements w.r.t. 1.13.2. This issue is rescheduled to 1.16.0

comment:2 by Francesco Casella, 4 years ago

Milestone: 1.16.01.17.0

Retargeted to 1.17.0 after 1.16.0 release

comment:3 by Francesco Casella, 4 years ago

Milestone: 1.17.01.18.0

Retargeted to 1.18.0 because of 1.17.0 timed release.

comment:4 by Francesco Casella, 3 years ago

Milestone: 1.18.0

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.