﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
5170	GenerationOfFMUs examples in the MSL are broken because of unrecognized redundant initial equations	Francesco Casella	Karim Adbdelhak	"The four {{{GenerationOfFMU}}} models in the MSL 3.2.3:
[https://libraries.openmodelica.org/branches/master/Modelica_trunk/files/Modelica_trunk_Modelica.Electrical.Analog.Examples.GenerationOfFMUs.err Modelica.Electrical.Analog.Examples.GenerationOfFMUs]
[https://libraries.openmodelica.org/branches/master/Modelica_trunk/files/Modelica_trunk_Modelica.Mechanics.Rotational.Examples.GenerationOfFMUs.err Modelica.Mechanics.Rotational.Examples.GenerationOfFMUs]
[https://libraries.openmodelica.org/branches/master/Modelica_trunk/files/Modelica_trunk_Modelica.Mechanics.Translational.Examples.GenerationOfFMUs.err Modelica.Mechanics.Translational.Examples.GenerationOfFMUs]
[https://libraries.openmodelica.org/branches/master/Modelica_trunk/files/Modelica_trunk_Modelica.Thermal.HeatTransfer.Examples.GenerationOfFMUs.err Modelica.Thermal.HeatTransfer.Examples.GenerationOfFMUs]
all share the same issue. They involve the initialization of high-index systems with redundant and consistent initial equations. All of them fail during {{{analyzeInitialSystem}}} with this kind of error
{{{
Error: The given system is mixed-determined.   [index > 3]
Please checkout the option ""--maxMixedDeterminedIndex"".
Error: No system for the symbolic initialization was generated
}}}
I prepared a reduced model that replicates the issue, please find it attached. It contains the following two variable declarations with {{{fixed = true}}}
{{{
Real directCapacity.heatCapacitor.T(quantity = ""ThermodynamicTemperature"", unit = ""K"", displayUnit = ""degC"", min = 0.0, start = 293.15, fixed = true, nominal = 300.0) ""Temperature of element"";
Real inverseCapacity.mass.T(quantity = ""ThermodynamicTemperature"", unit = ""K"", displayUnit = ""degC"", min = 0.0, start = 293.15, fixed = true, nominal = 300.0) ""Temperature of element"";
}}}
and the following chain of equalities
{{{
directCapacity.heatCapacitor.T = directCapacity.heatCapacitor.port.T;
directCapacity.heatCapacitor.port.T = directCapacity.heatFlowToTemperature.heatPort.T;
directCapacity.heatFlowToTemperature.y = directCapacity.heatFlowToTemperature.heatPort.T
directCapacity.heatFlowToTemperature.y = directCapacity.heatFlowToTemperature.p;
directCapacity.heatFlowToTemperature.p = directCapacity.T;
directCapacity.T = inverseCapacity.T;
inverseCapacity.temperatureToHeatFlow.p = inverseCapacity.T;
inverseCapacity.temperatureToHeatFlow.u = Modelica.Blocks.Interfaces.Adaptors.Functions.state1({inverseCapacity.temperatureToHeatFlow.p, inverseCapacity.temperatureToHeatFlow.u1}, time);
inverseCapacity.temperatureToHeatFlow.u = inverseCapacity.temperatureToHeatFlow.heatPort.T
inverseCapacity.temperatureToHeatFlow.heatPort.T = inverseCapacity.mass.port.T;
inverseCapacity.mass.T = inverseCapacity.mass.port.T;
}}}
which is ultimately equivalent to 
{{{
directCapacity.heatCapacitor.T = inverseCapacity.mass.T
}}}
that involves two differentiated variables, thus leading to an index-2 problem with overdetermined and consistent initial equations.

We do have algorithms in OMC to deal with this case (see [http://www.ep.liu.se/ecp/096/124/ecp14096124.pdf paper]). The chain of equality equations is trivial and handled by alias elimination, except for the equation
{{{
inverseCapacity.temperatureToHeatFlow.u = Modelica.Blocks.Interfaces.Adaptors.Functions.state1({inverseCapacity.temperatureToHeatFlow.p, inverseCapacity.temperatureToHeatFlow.u1}, time);
}}}
The function {{{state1()}}} has {{{lateInline = true}}}, so it should be eventually eliminated once the index has been analyzed. By turning on {{{-d=optdaedump}}} this seems to be the case: the pre-optimization phase ends with the {{{state1()}}} function call still in place
{{{
7/7 (1): inverseCapacity.mass.T = Modelica.Blocks.Interfaces.Adaptors.Functions.state1({directCapacity.heatFlowToTemperature.y, directCapacity.derT}, time)   [dynamic |0|0|0|0|] 
}}}
but then, the next time the dynamic equations are printed out, it shows up (correctly) as
{{{
7/7 (1): inverseCapacity.mass.T = directCapacity.heatFlowToTemperature.y   [dynamic |0|0|0|0|] 
}}}
However, for some reason the redundant initial equation is ultimately not eliminated, leading to a mixed-determined initialization problem.

I tentatively assign this issue to @Karim.Abdelhak, since he's working on index reduction. You may co-ordinate with @lochel, who wrote the algorithm to remove the redundant initial equations."	defect	closed	blocker	1.14.0	Backend		fixed		Lennart Ochel Per Östlund
