﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
3778	noEvent(x>0) fails to guard against sqrt(x) for x<0	Michael Wetter	somebody	"Hi

The regression test

{{{
Buildings.Fluid.FixedResistances.Examples.FixedResistancesExplicit
}}}
fails with ""Model error: Argument of sqrt(res22.dp) was -5 should be >= 0""

This is triggered from
{{{
m_flow := if noEvent(dp>dp_turbulent) then k*sqrt(dp)
             elseif noEvent(dp<-dp_turbulent) then -k*sqrt(-dp)
             else (k^2*5/4/m_flow_turbulent)*dp-k/4/(m_flow_turbulent/k)^5*dp^3;
}}}
According to the Modelica specification, this is the correct implementation. However, when reformulating as
{{{
m_flow := if noEvent(dp>dp_turbulent) then k*sqrt(abs(dp))
             elseif noEvent(dp<-dp_turbulent) then -k*sqrt(abs(-dp))
             else (k^2*5/4/m_flow_turbulent)*dp-k/4/(m_flow_turbulent/k)^5*dp^3;
}}}
the example works. Hence, this looks like the implementation of {{{noEvent}}} is wrong in OpenModelica.

This fix makes the following tests work:
{{{
simulate(Buildings.Fluid.Examples.Performance.Example1v1);
simulate(Buildings.Fluid.Examples.Performance.Example1v2);
simulate(Buildings.Fluid.Examples.Performance.Example2);
simulate(Buildings.Fluid.HeatExchangers.Examples.DryCoilCounterFlowPControl);
simulate(Buildings.Fluid.FixedResistances.Examples.FixedResistancesExplicit);
simulate(Buildings.Fluid.Examples.ResistanceVolumeFlowReversal);
}}}"	defect	new	high	Future	*unknown*				
