Opened 10 years ago
Closed 10 years ago
#2855 closed defect (fixed)
Unnecessary mixed-integer equations could be solved by better BLT
Reported by: | Francesco Casella | Owned by: | Lennart Ochel |
---|---|---|---|
Priority: | blocker | Milestone: | 1.9.1 |
Component: | Backend | Version: | trunk |
Keywords: | Cc: | Patrick Täuber |
Description
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
Change History (3)
comment:1 by , 10 years ago
Cc: | added |
---|---|
Owner: | changed from | to
Status: | new → accepted |
comment:2 by , 10 years ago
comment:3 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | accepted → closed |
None of the test models produce back end issues anymore. In some cases there are codegen and runtime issues. Hence, the current implementation has to be improved anyway, but it seem to work fine for the particular examples from above.
Francesco, can you please verify if it is working for you? You will need at least r22641.