Opened 18 years ago

Last modified 18 years ago

#85 closed defect (fixed)

generates divide by zero code

Reported by: ms6ep Owned by: ms6ep
Priority: critical Milestone:
Component: Version:
Keywords: Cc: ms6ep, Adrian Pop

Description


Change History (2)

comment:1 by ms6ep, 18 years ago

The following model generates C code with expressions of the form "1.0 / 0.0".
A second nearly identical model is included that does not contain this bug. The
two models should be semantically identical.

model MilkingModel

Real V(start = 0) "Milk Volume";
parameter Integer i = 4 "Number of milking periods";
parameter Real H[i] = {20, 30, 45, 55} "Start time of ith milking period";
parameter Real MD[i] = {2, 2, 2, 2} "Duration of ith milking period";
parameter Real Vp[i] = {500,500,500,500} "Volume of ith milking period";

equation

der(V) = if time >= H[1] and time <= (H[1] + MD[1]) then

Vp[1] / MD[1]

else if time >= H[2] and time <= (H[2] + MD[2]) then

Vp[2] / MD[2]

else if time >= H[3] and time <= (H[3] + MD[3]) then

Vp[3] / MD[3]

else if time >= H[4] and time <= (H[4] + MD[4]) then

Vp[4] / MD[4]

else 0;

end MilkingModel;


model MilkingModel

Real V(start = 0) "Milk Volume";
Real dV;
parameter Integer i = 4 "Number of milking periods";
parameter Real H[i] = {20, 30, 45, 55} "Start time of ith milking period";
parameter Real MD[i] = {2, 2, 2, 2} "Duration of ith milking period";
parameter Real Vp[i] = {500,500,500,500} "Volume of ith milking period";

equation

der(V) = dV;
dV = if time >= H[1] and time <= (H[1] + MD[1]) then

Vp[1] / MD[1]

else if time >= H[2] and time <= (H[2] + MD[2]) then

Vp[2] / MD[2]

else if time >= H[3] and time <= (H[3] + MD[3]) then

Vp[3] / MD[3]

else if time >= H[4] and time <= (H[4] + MD[4]) then

Vp[4] / MD[4]

else 0;

end MilkingModel;

comment:2 by Peter Aronsson, 18 years ago

Both these models now works to compile and simulate.

Note: See TracTickets for help on using tickets.