Opened 12 years ago

Closed 12 years ago

#2017 closed defect (fixed)

Division by Zero during Initialization

Reported by: Christian Schubert Owned by: Lennart Ochel
Priority: blocker Milestone: 1.9.0
Component: Backend Version: trunk
Keywords: initialization Cc: Willi Braun, Jens Frenkel

Description

At least the following models produce a division by zero during initialization

Modelica.Electrical.Spice3.Examples.FourInverters
Modelica.Electrical.Spice3.Examples.Inverter
Modelica.Electrical.Spice3.Examples.InvertersApartRecord
Modelica.Electrical.Spice3.Examples.InvertersExtendedModel
Modelica.Electrical.Spice3.Examples.Nor

All fail with the same problem

division by zero in partial equation: ((v.T0 + (v.Tfalling - time)) * (v.V2 - v.V1)) / (v.Tfalling - v.Twidth) because v.Tfalling - v.Twidth == 0

Looking into the model I found, that during the very first call the wrong if-branch is selected. The code reads

    RELATIONHYSTERESIS(tmp16, time, ($Pv$PT0 + $Pv$PTrising), 2, Less);
    tmp22 = (modelica_boolean)tmp16;
    if(tmp22)

and the variables have the following values for

Modelica.Electrical.Spice3.Examples.Inverter
  time := 0;
  $Pv$PT0 := 0;
  $Pv$PTrising := 1e-13;

Nevertheless tmp16 is evaluated to 0 (= false).
Thus a wrong branch of the if is selected which causes a division by zero.

It seems to me that data->simulationInfo.discreteCall should be 1 instead of 0 during the first call. Because otherwise RELATIONHYSTERESIS will just use a pre value

#define RELATIONHYSTERESIS(res,exp1,exp2,index,op_w) { \
  if(data->simulationInfo.discreteCall == 0){ \
      res = data->simulationInfo.relationsPre[index]; \
  } else{ \

Attachments (1)

initialization.c.patch (477 bytes ) - added by Jens Frenkel 12 years ago.
Patch for this problem, maybe it helps

Download all attachments as: .zip

Change History (4)

by Jens Frenkel, 12 years ago

Attachment: initialization.c.patch added

Patch for this problem, maybe it helps

comment:1 by Lennart Ochel, 12 years ago

This is probably related to the workaround, where the initialization is called twice. The wrong branch is selected because the if-condition is not part of the initialization-problem. This is why the symbolic initialization should not yet be default.

comment:2 by Lennart Ochel, 12 years ago

Status: newaccepted
Modelica.Electrical.Spice3.Examples.InvertersApartRecord
Modelica.Electrical.Spice3.Examples.InvertersExtendedModel

are working gain. I have switched back to the numeric initialization until we support if/when initialization within the symbolic one.
Work in progress.

comment:3 by Lennart Ochel, 12 years ago

Resolution: fixed
Status: acceptedclosed

It seems that all mentioned examples are working again.

Note: See TracTickets for help on using tickets.