﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
5226	Support conditional equations in tearing	Francesco Casella	Willi Braun	"Consider the following model, already discussed in #5206
{{{
model NonSatIntEq
  Real x;
  Real y;
  Real usat;
  Real u;
  parameter Real y0(fixed = false, start = 8);
  parameter Real T = 1;
  parameter Real k = 10;
  parameter Real uMin = 0;
  parameter Real uMax = 1;
parameter Real y_ref = 8;
initial equation
  der(x) = 0;
  if u > usat then
    u = usat + 1;
  else
    y = y_ref;
  end if;
equation
  T * der(x) = usat - x;
  y = k * x;
  usat = homotopy(actual = smooth(0, if u > uMax then uMax else if u < uMin then uMin else u), simplified = u);
  u = y0 - y;
end NonSatIntEq;
}}}
The back-end could select {{{u}}} as a tearing variable to solve the initialization problem. Unfortunately, the following warnings are issued
{{{
[1] 00:44:12 Scripting Notification
 
The selection of a new tearing variable failed. 


[2] 00:44:12 Translation Warning
Function Tearing.selectTearingVar failed at least once. Use -d=tearingdump or -d=tearingdumpV for more information.

[3] 00:44:12 Translation Warning
Iteration variables with default zero start attribute in equation system with analytic Jacobian:
         usat:VARIABLE() .NonSatIntEq type: Real 
         u:VARIABLE() .NonSatIntEq type: Real 
         y:VARIABLE() .NonSatIntEq type: Real 
         x:VARIABLE() .NonSatIntEq type: Real 
}}}
The transformational debugger shows a system of four implicit equations, but only shows three residuals. Lots of {{{Matrix Singular}}} messages are issued, and eventually a wrong initial solution (not in steady-state) is accepted at the beginning of the simulation.

If the conditional equation is manually converted to this equation
{{{
(if u > usat then u - (usat + 1) else y - y_ref) = 0;
}}}
then the tearing is applied successfully and the initialization problem is solved correctly.

Please fix the back-end to process these conditional equations correctly as far as tearing is concerned."	defect	closed	critical	1.14.0	Backend		fixed		Karim Adbdelhak
