﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
5771	Bogus CSE in power plant models using Modelica.Media	Francesco Casella	Karim Adbdelhak	"Please consider the attached test case. I ran it with the performance logger, and discovered several weird things that gobble up a lot of time. 

The first one is the following assignment
{{{
(assign) fWPH_11_1.flowSTEAM.drdp[1] :=
if noEvent(Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).region == 3)
then 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).rho * 
(Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).cv * 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).rho + 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).pt) / 
(Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).rho ^ 2.0 * 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).pd * 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).cv + 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).T * 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).pt ^ 2.0) 
else if noEvent(Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).region == 4)
then Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).rho * 
(Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).rho * 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).cv / 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).dpT + 1.0) / 
(Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).dpT * 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).T) 
else (-Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).rho ^ 2.0) * 
(Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).vp * 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).cp - 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).vt / 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).rho +
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).T * 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).vt ^ 2.0) / 
Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0).cp
}}}
What I see here is many time the same function call with different field accessors, like {{{f(a,b,c).x, f(a,b,c).y, f(a,b,c).z}}}. I'm not sure what this notation exactly means, i.e., if this is a shorthand meaning that the function (returning a record) is only called once and then the record fields are only accessed, or if the function is actually called several times with the same arguments, each time taking one output and throwing away everything else. 

However, I would expect the function  {{{Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, STEAMin.h, 0, 0)}}} to be called only once, the result stored in a {{{$cse}}} auxiliary variable and then the various field retrived from the {{{$cse}}} variable. Why isn't this happening? Can you please check?

Another weird thing is seeing these two assignments:
{{{
$cse45 := Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, fWPH_11_1.flowSTEAM.htilde[2], 0, 0);
$cse33 := Modelica.Media.Water.IF97_Utilities.waterBaseProp_ph(fWPH_11_1.nusseltCondenser.p, fWPH_11_1.flowSTEAM.htilde[2], 0, 0);
}}} 
Aren't {{{$cse45}}} and {{{$cse33}}} exactly the same?

I guess we have a lot of margin for improvement here :)"	defect	closed	high	1.16.0	Backend		fixed		Andreas Heuermann giovanni.mangola@…
