﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
5595	Equations involving semiLinear are not solved correctly for tearing	Francesco Casella	Karim Adbdelhak	"Please check [https://libraries.openmodelica.org/branches/newInst/Modelica_3.2.3/files/Modelica_3.2.3_Modelica.Electrical.Machines.Examples.DCMachines.DCPM_Cooling.err Modelica.Electrical.Machines.Examples.DCMachines.DCPM_Cooling]. This model stopped working after [https://github.com/OpenModelica/OpenModelica/pull/256 PR 256], but I understand this PR is not the root cause, it simply revealed an existing problem.

The simulation fails because of a division by zero in torn equation 53. If you look at it in the debugger, you can see that equation
{{{
-outlet.flowPort.H_flow = semiLinear(-cooling.flowPort_a.m_flow, cooling.flowPort_b.h, cooling.h)
}}}
which comes from this original equation
{{{
flowPort_b.H_flow = semiLinear(flowPort_b.m_flow,flowPort_b.h,h);
}}}
was solved into
{{{
cooling.flowPort_b.h = (-((if (-cooling.flowPort_a.m_flow) >= 0.0 then 0.0 else (-cooling.flowPort_a.m_flow) * cooling.h) + outlet.flowPort.H_flow)) / (if (-cooling.flowPort_a.m_flow) >= 0.0 then -cooling.flowPort_a.m_flow else -0.0)
}}}
This looks weird to me. The definition of semiLinear(x, a, b) is
{{{
semiLinear(x,a,b) = if x > 0 then a*x else b*x
}}}
what the BE did was tantamount to trying to solve this equation for {{{a}}}. Obviously this only works if {{{x > 0}}}, otherwise it makes no sense. 

This should be definitely fixed, equations involving {{{semiLinear}}} can be solved w.r.t the first argument of {{{semiLinear}}}, but not w.r.t. the other two.

BTW, we are not implementing the optimizations in Section 3.7.2.5. This doesn't have very high priority, since {{{semiLinear}}} was first conceived for fluid modelling, but later abandoned in favour of {{{stream}}} connectors, and is currently only used in the {{{Modelica.Thermal.FluidHeatFlow}}} library, where normally the flows are positive, so the case {{{x = 0}}} is quite rare.

In any case, the current solution found by the BE seems incorrect to me, regardless of the missing optimization, and should be fixed with high priority."	defect	closed	blocker	1.16.0	Backend		fixed		Karim Adbdelhak Andreas Heuermann
