﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
2017	Division by Zero during Initialization	Christian Schubert	Lennart Ochel	"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{ \
}}}
"	defect	closed	blocker	1.9.0	Backend	trunk	fixed	initialization	Willi Braun Jens Frenkel
