﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
5727	More issues with dynamic state selection and Jacobians	Francesco Casella	Karim Adbdelhak	"This issue is related to #5459 but I'm opening a separate ticket here because that ticket is too cluttered now.

Consider the attached test case, which is part of the FlexiCaL plant model that I'd like to present at the next Annual Meeting and to use as showcase for OMC in industrial-grade power generation systems, which is possible because the model is 100% public. 

Dymola produces the intended fixed set of 151 states
{{{
Statically selected continuous time states
fWPH_12_1.flowDRAIN.h[2]
fWPH_12_1.flowDRAIN.h[3]
fWPH_12_1.flowDRAIN.h[4]
fWPH_12_1.flowDRAIN.h[5]
fWPH_12_1.flowDRAIN.h[6]
fWPH_12_1.flowDRAIN.p
fWPH_12_1.flowFW_cond.htilde[]
fWPH_12_1.flowFW_cond.p
fWPH_12_1.flowFW_des.htilde[]
fWPH_12_1.flowFW_des.p
fWPH_12_1.flowFW_sub.htilde[]
fWPH_12_1.flowFW_sub.p
fWPH_12_1.flowSTEAM.h[2]
fWPH_12_1.flowSTEAM.h[3]
fWPH_12_1.flowSTEAM.h[4]
fWPH_12_1.flowSTEAM.h[5]
fWPH_12_1.flowSTEAM.h[6]
fWPH_12_1.Level_PID.I
fWPH_12_1.metalTubeFV_cond.Tvol[]
fWPH_12_1.metalTubeFV_des.Tvol[]
fWPH_12_1.metalTubeFV_sub.Tvol[]
fWPH_12_1.nusseltCondenser.hl
fWPH_12_1.nusseltCondenser.hv
fWPH_12_1.nusseltCondenser.p
fWPH_12_1.nusseltCondenser.zl
fWPH_12_1.ValveDynamic.y
fWPH_13_1.flowDRAIN.h[2]
fWPH_13_1.flowDRAIN.h[3]
fWPH_13_1.flowDRAIN.h[4]
fWPH_13_1.flowDRAIN.h[5]
fWPH_13_1.flowDRAIN.h[6]
fWPH_13_1.flowDRAIN.p
fWPH_13_1.flowFW_cond.htilde[]
fWPH_13_1.flowFW_cond.p
fWPH_13_1.flowFW_des.htilde[]
fWPH_13_1.flowFW_des.p
fWPH_13_1.flowFW_sub.htilde[]
fWPH_13_1.flowFW_sub.p
fWPH_13_1.flowSTEAM.h[2]
fWPH_13_1.flowSTEAM.h[3]
fWPH_13_1.flowSTEAM.h[4]
fWPH_13_1.flowSTEAM.h[5]
fWPH_13_1.flowSTEAM.h[6]
fWPH_13_1.Level_PID.I
fWPH_13_1.metalTubeFV_cond.Tvol[]
fWPH_13_1.metalTubeFV_des.Tvol[]
fWPH_13_1.metalTubeFV_sub.Tvol[]
fWPH_13_1.nusseltCondenser.hl
fWPH_13_1.nusseltCondenser.hv
fWPH_13_1.nusseltCondenser.p
fWPH_13_1.nusseltCondenser.zl
fWPH_13_1.ValveDynamic.y
fWPH_14_1.flowDRAIN.h[2]
fWPH_14_1.flowDRAIN.h[3]
fWPH_14_1.flowDRAIN.h[4]
fWPH_14_1.flowDRAIN.h[5]
fWPH_14_1.flowDRAIN.h[6]
fWPH_14_1.flowDRAIN.p
fWPH_14_1.flowFW_cond.htilde[]
fWPH_14_1.flowFW_cond.p
fWPH_14_1.flowFW_des.htilde[]
fWPH_14_1.flowFW_des.p
fWPH_14_1.flowFW_sub.htilde[]
fWPH_14_1.flowFW_sub.p
fWPH_14_1.flowSTEAM.h[2]
fWPH_14_1.flowSTEAM.h[3]
fWPH_14_1.flowSTEAM.h[4]
fWPH_14_1.flowSTEAM.h[5]
fWPH_14_1.flowSTEAM.h[6]
fWPH_14_1.Level_PID.I
fWPH_14_1.metalTubeFV_cond.Tvol[]
fWPH_14_1.metalTubeFV_des.Tvol[]
fWPH_14_1.metalTubeFV_sub.Tvol[]
fWPH_14_1.nusseltCondenser.hl
fWPH_14_1.nusseltCondenser.hv
fWPH_14_1.nusseltCondenser.p
fWPH_14_1.nusseltCondenser.zl
fWPH_14_1.ValveDynamic.y
IP_turbine3.phi
}}}

and runs the simulation in about 2 s. 

OMC instead produces the following dynamic state selection:
{{{
 * Number of states: 151 ($STATESET1.x[6],$STATESET1.x[5],$STATESET1.x[4],
 $STATESET1.x[3],$STATESET1.x[2],$STATESET1.x[1],
constantSpeed.phi,
fWPH_12_1.ValveDynamic.y,
fWPH_12_1.Level_PID.I,
fWPH_12_1.flowFW_des.p,
fWPH_12_1.flowFW_des.htilde[1],
fWPH_12_1.flowFW_des.htilde[2],
fWPH_12_1.flowFW_des.htilde[3],
fWPH_12_1.flowFW_des.htilde[4],
fWPH_12_1.flowFW_des.htilde[5],
fWPH_12_1.flowFW_cond.p,
fWPH_12_1.flowFW_cond.htilde[1],
fWPH_12_1.flowFW_cond.htilde[2],
fWPH_12_1.flowFW_cond.htilde[3],
fWPH_12_1.flowFW_cond.htilde[4],
fWPH_12_1.flowFW_cond.htilde[5],
fWPH_12_1.flowFW_sub.p,
fWPH_12_1.flowFW_sub.htilde[1],
fWPH_12_1.flowFW_sub.htilde[2],
fWPH_12_1.flowFW_sub.htilde[3],
fWPH_12_1.flowFW_sub.htilde[4],
fWPH_12_1.flowFW_sub.htilde[5],
fWPH_12_1.flowDRAIN.p,
fWPH_12_1.flowDRAIN.htilde[1],
fWPH_12_1.flowDRAIN.htilde[2],
fWPH_12_1.flowDRAIN.htilde[3],
fWPH_12_1.flowDRAIN.htilde[4],
fWPH_12_1.flowDRAIN.htilde[5],
fWPH_12_1.flowSTEAM.htilde[1],
fWPH_12_1.flowSTEAM.htilde[2],
fWPH_12_1.flowSTEAM.htilde[3],
fWPH_12_1.flowSTEAM.htilde[4],
fWPH_12_1.flowSTEAM.htilde[5],
fWPH_12_1.metalTubeFV_des.Tvol[1],
fWPH_12_1.metalTubeFV_des.Tvol[2],
fWPH_12_1.metalTubeFV_des.Tvol[3],
fWPH_12_1.metalTubeFV_des.Tvol[4],
fWPH_12_1.metalTubeFV_des.Tvol[5],
fWPH_12_1.metalTubeFV_cond.Tvol[1],
fWPH_12_1.metalTubeFV_cond.Tvol[2],
fWPH_12_1.metalTubeFV_cond.Tvol[3],
fWPH_12_1.metalTubeFV_cond.Tvol[4],
fWPH_12_1.metalTubeFV_cond.Tvol[5],
fWPH_12_1.metalTubeFV_sub.Tvol[1],
fWPH_12_1.metalTubeFV_sub.Tvol[2],
fWPH_12_1.metalTubeFV_sub.Tvol[3],
fWPH_12_1.metalTubeFV_sub.Tvol[4],
fWPH_12_1.metalTubeFV_sub.Tvol[5],
fWPH_12_1.nusseltCondenser.zl,
fWPH_12_1.nusseltCondenser.p,
fWPH_12_1.nusseltCondenser.hv,
fWPH_12_1.nusseltCondenser.hl,
fWPH_13_1.ValveDynamic.y,
fWPH_13_1.Level_PID.I,
fWPH_13_1.flowFW_des.p,
fWPH_13_1.flowFW_des.htilde[1],
fWPH_13_1.flowFW_des.htilde[2],
fWPH_13_1.flowFW_des.htilde[3],
fWPH_13_1.flowFW_des.htilde[4],
fWPH_13_1.flowFW_des.htilde[5],
fWPH_13_1.flowFW_cond.p,
fWPH_13_1.flowFW_cond.htilde[1],
fWPH_13_1.flowFW_cond.htilde[2],
fWPH_13_1.flowFW_cond.htilde[3],
fWPH_13_1.flowFW_cond.htilde[4],
fWPH_13_1.flowFW_cond.htilde[5],
fWPH_13_1.flowFW_sub.p,
fWPH_13_1.flowFW_sub.htilde[1],
fWPH_13_1.flowFW_sub.htilde[2],
fWPH_13_1.flowFW_sub.htilde[3],
fWPH_13_1.flowFW_sub.htilde[4],
fWPH_13_1.flowFW_sub.htilde[5],
fWPH_13_1.flowDRAIN.p,
fWPH_13_1.flowDRAIN.htilde[1],
fWPH_13_1.flowDRAIN.htilde[2],
fWPH_13_1.flowDRAIN.htilde[3],
fWPH_13_1.flowDRAIN.htilde[4],
fWPH_13_1.flowDRAIN.htilde[5],
fWPH_13_1.metalTubeFV_des.Tvol[1],
fWPH_13_1.metalTubeFV_des.Tvol[2],
fWPH_13_1.metalTubeFV_des.Tvol[3],
fWPH_13_1.metalTubeFV_des.Tvol[4],
fWPH_13_1.metalTubeFV_des.Tvol[5],
fWPH_13_1.metalTubeFV_cond.Tvol[1],
fWPH_13_1.metalTubeFV_cond.Tvol[2],
fWPH_13_1.metalTubeFV_cond.Tvol[3],
fWPH_13_1.metalTubeFV_cond.Tvol[4],
fWPH_13_1.metalTubeFV_cond.Tvol[5],
fWPH_13_1.metalTubeFV_sub.Tvol[1],
fWPH_13_1.metalTubeFV_sub.Tvol[2],
fWPH_13_1.metalTubeFV_sub.Tvol[3],
fWPH_13_1.metalTubeFV_sub.Tvol[4],
fWPH_13_1.metalTubeFV_sub.Tvol[5],
fWPH_13_1.nusseltCondenser.zl,
fWPH_13_1.nusseltCondenser.hv,
fWPH_13_1.nusseltCondenser.hl,
fWPH_14_1.ValveDynamic.y,
fWPH_14_1.Level_PID.I,
fWPH_14_1.flowFW_des.p,
fWPH_14_1.flowFW_des.htilde[1],
fWPH_14_1.flowFW_des.htilde[2],
fWPH_14_1.flowFW_des.htilde[3],
fWPH_14_1.flowFW_des.htilde[4],
fWPH_14_1.flowFW_des.htilde[5],
fWPH_14_1.flowFW_cond.p,
fWPH_14_1.flowFW_cond.htilde[1],
fWPH_14_1.flowFW_cond.htilde[2],
fWPH_14_1.flowFW_cond.htilde[3],
fWPH_14_1.flowFW_cond.htilde[4],
fWPH_14_1.flowFW_cond.htilde[5],
fWPH_14_1.flowFW_sub.p,
fWPH_14_1.flowFW_sub.htilde[1],
fWPH_14_1.flowFW_sub.htilde[2],
fWPH_14_1.flowFW_sub.htilde[3],
fWPH_14_1.flowFW_sub.htilde[4],
fWPH_14_1.flowFW_sub.htilde[5],
fWPH_14_1.flowDRAIN.p,
fWPH_14_1.flowDRAIN.htilde[1],
fWPH_14_1.flowDRAIN.htilde[2],
fWPH_14_1.flowDRAIN.htilde[3],
fWPH_14_1.flowDRAIN.htilde[4],
fWPH_14_1.flowDRAIN.htilde[5],
fWPH_14_1.flowSTEAM.htilde[1],
fWPH_14_1.flowSTEAM.htilde[2],
fWPH_14_1.flowSTEAM.htilde[3],
fWPH_14_1.flowSTEAM.htilde[4],
fWPH_14_1.flowSTEAM.htilde[5],
fWPH_14_1.metalTubeFV_des.Tvol[1],
fWPH_14_1.metalTubeFV_des.Tvol[2],
fWPH_14_1.metalTubeFV_des.Tvol[3],
fWPH_14_1.metalTubeFV_des.Tvol[4],
fWPH_14_1.metalTubeFV_des.Tvol[5],
fWPH_14_1.metalTubeFV_cond.Tvol[1],
fWPH_14_1.metalTubeFV_cond.Tvol[2],
fWPH_14_1.metalTubeFV_cond.Tvol[3],
fWPH_14_1.metalTubeFV_cond.Tvol[4],
fWPH_14_1.metalTubeFV_cond.Tvol[5],
fWPH_14_1.metalTubeFV_sub.Tvol[1],
fWPH_14_1.metalTubeFV_sub.Tvol[2],
fWPH_14_1.metalTubeFV_sub.Tvol[3],
fWPH_14_1.metalTubeFV_sub.Tvol[4],
fWPH_14_1.metalTubeFV_sub.Tvol[5],
fWPH_14_1.nusseltCondenser.zl,
fWPH_14_1.nusseltCondenser.p,
fWPH_14_1.nusseltCondenser.hv,
fWPH_14_1.nusseltCondenser.hl)
}}}

with 6 dynamically chosen states.

This has two very bad consequences: a very long compilation time and a very long simulation time, around 30 seconds. I suspect both are due to the unnecessary need of solving some large algebraic loops due to the bad choice of states, since the {{{nls.c}}} file is 12 MB, at least 6X bigger than all the other ones, and it is by far the longest to compile. 

The lenghty simulation may also be traced back to the very long time taken to compute the numerical Jacobians, around 8 seconds. All results are obtained with an i7-8550 Intel CPU. 

During the simulation, we get the error message
{{{
Warning: maximal number of iteration reached but no root found
}}}
about 120 times, which also suggests something wrong with the state selection is unnecessarily 

I'm not sure if coloured Jacobians are not available in case of dynamic state selection, which could partly explain this very long time, since the system has 151 states. I ask for confirmation of this possible explanation.

In any case, it is well-known from other test cases (such as those reported in #5459) that having a dynamic state selection instead of the right static one often implies a huge performance degradation.

@Karim, we should be able to get the same static selection that Dymola gets (or something equivalent in terms of aliases), which is also the one I expect from a modelling point of view.

Getting this model to work properly has strategic value for me and for OMC in general, so I'd be glad if you could have a look at it. I think the issues involved are still the same that plagued #5459.

Thanks!"	defect	closed	critical	1.16.0	Backend		fixed		Andreas Heuermann
