Skip to content

Commit 681407b

Browse files
committed
- fix over-determined initialization (e.g. ThermoPower.PowerPlants.SteamTurbineGroup.Tests.TestSTG_cc)
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21134 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 0d9dee9 commit 681407b

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

Compiler/BackEnd/Initialization.mo

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,12 +1075,13 @@ protected function getConsistentEquations "author: mwenzler"
10751075
input array<Integer> vecVarToEqs;
10761076
input BackendDAE.Variables vars;
10771077
input BackendDAE.Shared shared;
1078+
input Integer counter;
10781079
output list<Integer> outUnassignedEqns;
10791080
output Boolean outConsistent;
10801081
algorithm
1081-
(outUnassignedEqns, outConsistent) := matchcontinue(inUnassignedEqns, inEqns, inEqnsOrig, inM,vecVarToEqs, vars, shared)
1082+
(outUnassignedEqns, outConsistent) := matchcontinue(inUnassignedEqns, inEqns, inEqnsOrig, inM,vecVarToEqs, vars, shared, counter)
10821083
local
1083-
Integer currEqID, currVarID, currID;
1084+
Integer currEqID, currVarID, currID, nVars, nEqns;
10841085
list<Integer> unassignedEqns, unassignedEqns2, listVar;
10851086
list<BackendDAE.Equation> eqns_list;
10861087
list<BackendDAE.Equation> eqns_list_new;
@@ -1099,10 +1100,13 @@ algorithm
10991100
DAE.FunctionTree funcs;
11001101
list<BackendDAE.Equation> list_inEqns;
11011102

1102-
case ({}, _, _, _, _, _, _)
1103+
case ({}, _, _, _, _, _, _, _)
11031104
then ({}, true);
11041105

1105-
case (currID::unassignedEqns, _, _, _, _, _, _) equation
1106+
case (currID::unassignedEqns, _, _, _, _, _, _, _) equation
1107+
nVars = BackendVariable.varsSize(vars);
1108+
nEqns = BackendDAEUtil.equationSize(inEqnsOrig);
1109+
true = intLe(counter, nEqns-nVars);
11061110
eqn = BackendEquation.equationNth1(inEqns, currID);
11071111
BackendDAE.EQUATION(exp=lhs, scalar=rhs) = eqn;
11081112
exp = DAE.BINARY(lhs, DAE.SUB(DAE.T_REAL_DEFAULT), rhs);
@@ -1114,10 +1118,10 @@ algorithm
11141118
eqn = BackendEquation.equationNth1(inEqnsOrig, currID);
11151119
Error.addCompilerNotification("The following equation is consistent and got removed from the initialization problem: " +& BackendDump.equationString(eqn));
11161120

1117-
(unassignedEqns2, consistent) = getConsistentEquations(unassignedEqns, inEqns, inEqnsOrig, inM, vecVarToEqs, vars, shared);
1121+
(unassignedEqns2, consistent) = getConsistentEquations(unassignedEqns, inEqns, inEqnsOrig, inM, vecVarToEqs, vars, shared, counter+1);
11181122
then (currID::unassignedEqns2, consistent);
11191123

1120-
case (currID::unassignedEqns, _, _, _, _, _, _) equation
1124+
case (currID::unassignedEqns, _, _, _, _, _, _, _) equation
11211125
true=emptyListOfIncidenceMatrix({currID},inM,vecVarToEqs, false);
11221126
eqn = BackendEquation.equationNth1(inEqns, currID);
11231127
BackendDAE.EQUATION(exp=lhs, scalar=rhs) = eqn;
@@ -1131,10 +1135,10 @@ algorithm
11311135
eqn2 = BackendEquation.equationNth1(inEqnsOrig, currID);
11321136
Error.addCompilerError("The initialization problem is inconsistent due to the following equation: " +& BackendDump.equationString(eqn2) +& " (" +& BackendDump.equationString(eqn) +& ")");
11331137

1134-
(unassignedEqns2, consistent) = getConsistentEquations(unassignedEqns, inEqns, inEqnsOrig, inM, vecVarToEqs, vars, shared);
1138+
(unassignedEqns2, consistent) = getConsistentEquations(unassignedEqns, inEqns, inEqnsOrig, inM, vecVarToEqs, vars, shared, counter);
11351139
then ({}, false);
11361140

1137-
case (currID::unassignedEqns, _, _, _, _, _, _) equation
1141+
case (currID::unassignedEqns, _, _, _, _, _, _, _) equation
11381142
true=emptyListOfIncidenceMatrix({currID},inM,vecVarToEqs, false);
11391143
eqn = BackendEquation.equationNth1(inEqns, currID);
11401144
BackendDAE.EQUATION(exp=lhs, scalar=rhs) = eqn;
@@ -1157,10 +1161,10 @@ algorithm
11571161
eqn2 = BackendEquation.equationNth1(inEqnsOrig, currID);
11581162
Error.addCompilerNotification("It was not possible to analyze the given system symbolically, because the relevant equations are part of an algebraic loop. This is not supported yet.");
11591163

1160-
(unassignedEqns2, consistent) = getConsistentEquations(unassignedEqns, inEqns, inEqnsOrig, inM, vecVarToEqs, vars, shared);
1164+
(unassignedEqns2, consistent) = getConsistentEquations(unassignedEqns, inEqns, inEqnsOrig, inM, vecVarToEqs, vars, shared, counter);
11611165
then ({}, false);
11621166

1163-
case (currID::unassignedEqns, _, _, _, _, _, _) equation
1167+
case (currID::unassignedEqns, _, _, _, _, _, _, _) equation
11641168
//true = intEq(listLength(inM[currID]), 0);
11651169
true=emptyListOfIncidenceMatrix({currID},inM,vecVarToEqs, false);
11661170
eqn = BackendEquation.equationNth1(inEqns, currID);
@@ -1177,9 +1181,9 @@ algorithm
11771181

11781182
then ({}, false);
11791183

1180-
case (currID::unassignedEqns, _, _, _, _ , _, _) equation
1184+
case (currID::unassignedEqns, _, _, _, _ , _, _, _) equation
11811185
false=emptyListOfIncidenceMatrix({currID},inM,vecVarToEqs, true);
1182-
(unassignedEqns2, consistent) = getConsistentEquations(unassignedEqns, inEqns, inEqnsOrig, inM, vecVarToEqs,vars, shared);
1186+
(unassignedEqns2, consistent) = getConsistentEquations(unassignedEqns, inEqns, inEqnsOrig, inM, vecVarToEqs,vars, shared, counter);
11831187
then (unassignedEqns2, consistent);
11841188
end matchcontinue;
11851189
end getConsistentEquations;
@@ -1692,7 +1696,7 @@ algorithm
16921696
unassignedEqns=adaptUnassignedEqns(unassignedEqns, {}, mapIncRowEqn);
16931697
eqns_1=removeEqswork(unassignedEqns,eqns_list,vars,outRepl);
16941698
substEqns = BackendEquation.listEquation(eqns_1);
1695-
(outUnassignedEqns, true) = getConsistentEquations(unassignedEqns, substEqns, eqns, m2, vec1,vars, shared);
1699+
(outUnassignedEqns, true) = getConsistentEquations(unassignedEqns, substEqns, eqns, m2, vec1,vars, shared, 1);
16961700

16971701
// remove all unassigned equations
16981702
substEqns = BackendEquation.equationDelete(substEqns, outUnassignedEqns);

0 commit comments

Comments
 (0)