﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
2855	Unnecessary mixed-integer equations could be solved by better BLT	Francesco Casella	Lennart Ochel	"Consider the following test cases (the second requires to install the ExternalMedia library from https://github.com/modelica/ExternalMedia, I am sorry but I could not replicate the problem in a simpler way)
{{{
package TestMixedInteger
  package TestMedium
    extends Modelica.Media.Interfaces.PartialTwoPhaseMedium;

    redeclare record extends ThermodynamicState
      Temperature T;
      AbsolutePressure p;
      SpecificEnthalpy h;
      Density d;
    end ThermodynamicState;

    redeclare function setState_ph
      input AbsolutePressure p;
      input SpecificEnthalpy h;
      input FixedPhase phase = 0;
      output ThermodynamicState state;
    algorithm
      state.p := p;
      state.h := h;
      state.T := (h-1e5)/4200 + 20;
      state.d := 995 - (state.T-293)*0.1;
      state.phase :=0;
    end setState_ph;

    redeclare function extends density
    algorithm
      d := state.d;
    end density;

  end TestMedium;

  model Test1
    replaceable package Medium = TestMedium
      constrainedby Modelica.Media.Interfaces.PartialTwoPhaseMedium;
    Medium.AbsolutePressure p1(start = 6e5);
    Medium.Density rho;
    Medium.ThermodynamicState state;
    Modelica.SIunits.MassFlowRate m_flow;
  equation
    state = Medium.setState_ph(p1,1e5);
    rho = Medium.density(state);
    m_flow = 1e-4*sqrt(rho*(p1-5e5));
    m_flow = 1;
  end Test1;

  model Test2
    extends Test1(redeclare package Medium =
          ExternalMedia.Examples.WaterCoolProp);
  end Test2;

  model Test3
    extends Test1(redeclare package Medium =  
          Modelica.Media.Water.StandardWater);
  end Test3;
end TestMixedInteger;
}}}

Code generated by OMC r22383 for Test1 and Test3 do not include any mixed-integer equations. Test2 instead ends up in a mixed-integer system of equations, involving the {{{state.phase}}} Integer. 

This is completely unnecessary, as Test2 could be solved this way:
{{{
m_flow = 1;
// solved as m_flow :=1

{state.d} = Medium.setState_ph(p1,1e5);
rho = state.d
m_flow = 1e-4*sqrt(rho*(p1-5e5));
// p1 is the tearing variable, state.d and rho are torn

{state.T, state.a, ..., state.phase} = Medium.setState(p1, 1e5)
// solved by re-computing state := Medium.setState_ph(p1,1e5),
// or just by keeping the last results computed at the previous time
// step and held in some auxiliary variable containing all the function
// outputs
}}}

In other words, the state.phase unknown integer is not needed to solve for p1, m_flow, and rho, and there are no further variables that depend on it, so there is no reason why it should be included in the strong component, ending up in a mixed-integer system of equations.

Incidentally, I do not understand why mixed-integer equations do not show up in Test1. As far as I understand, the structure of the problem is exactly the same, the only difference being that in Test2, function setState_ph calls an external C function to fill in the fields of the record. Maybe this detail could be helpful to find a solution to this problem"	defect	closed	blocker	1.9.1	Backend	trunk	fixed		Patrick Täuber
