Skip to content

Commit f8c335f

Browse files
committed
- break redundant calculations
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21721 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 212bc30 commit f8c335f

File tree

1 file changed

+8
-68
lines changed

1 file changed

+8
-68
lines changed

Compiler/BackEnd/Initialization.mo

Lines changed: 8 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,7 @@ algorithm
12231223
(syst, m_, _, _, mapIncRowEqn) := BackendDAEUtil.getIncidenceMatrixScalar(syst, BackendDAE.SOLVABLE(), SOME(funcs));
12241224
//BackendDump.dumpEqSystem(syst, "fixInitialSystem");
12251225
//BackendDump.dumpVariables(inInitVars, "selected initialization variables");
1226+
//BackendDump.dumpIncidenceMatrix(m_);
12261227

12271228
// get state-index list
12281229
stateIndices := BackendVariable.getVarIndexFromVar(inInitVars, inVars);
@@ -1239,15 +1240,13 @@ algorithm
12391240
// modify incidence matrix for under-determined systems
12401241
nAddEqs := intMax(nVars-nEqns + inIndex, inIndex);
12411242
//print("nAddEqs: " +& intString(nAddEqs) +& "\n");
1242-
m := fixUnderDeterminedSystem(m_, stateIndices, nEqns, nAddEqs);
1243-
//BackendDump.dumpIncidenceMatrix(m);
1243+
m_ := fixUnderDeterminedSystem(m_, stateIndices, nEqns, nAddEqs);
1244+
SOME(m) := BackendDAEUtil.copyIncidenceMatrix(SOME(m_)) "deep copy" ;
12441245

12451246
// modify incidence matrix for over-determined systems
12461247
nAddVars := intMax(nEqns-nVars + inIndex, inIndex);
12471248
//print("nAddVars: " +& intString(nAddVars) +& "\n");
12481249
m := fixOverDeterminedSystem(m, initEqsIndices, nVars, nAddVars);
1249-
//BackendDump.dumpIncidenceMatrix(m);
1250-
//BackendDump.dumpIncidenceMatrix(m_);
12511250

12521251
// match the system (nVars+nAddVars == nEqns+nAddEqs)
12531252
vec1 := arrayCreate(nVars+nAddVars, -1);
@@ -1271,7 +1270,7 @@ algorithm
12711270

12721271
// symbolic consistency check
12731272
(me, _, _, _) := BackendDAEUtil.getAdjacencyMatrixEnhancedScalar(syst, inShared);
1274-
(_, _, _) := consistencyCheck(redundantEqns, inEqns, inVars, inShared, nAddVars, m, me, vec1, vec2, mapIncRowEqn);
1273+
(_, _, _) := consistencyCheck(redundantEqns, inEqns, inVars, inShared, nAddVars, m_, me, vec1, vec2, mapIncRowEqn);
12751274

12761275
// remove all unassigned equations
12771276
outEqns := BackendEquation.compressEquations(inEqns);
@@ -1484,11 +1483,8 @@ algorithm
14841483
//BackendDump.dumpList(inRedundantEqns, "inRedundantEqns: ");
14851484
//BackendDump.dumpIncidenceMatrix(inM);
14861485

1487-
// remove unnecessary temporary edges from incidence matrix
1488-
// TODO: The result should be the original incidence matrix. So, why don't we use it?
1489-
m = removeTempEdges(inM, nVars, nAddVars, 1);
1490-
mT = BackendDAEUtil.transposeMatrix(m, nVars+nAddVars);
1491-
//BackendDump.dumpIncidenceMatrix(m);
1486+
mT = BackendDAEUtil.transposeMatrix(inM, nVars+nAddVars);
1487+
//BackendDump.dumpIncidenceMatrix(inM);
14921488

14931489
// get the sorting and algebraic loops
14941490
comps = BackendDAETransform.tarjanAlgorithm(mT, vecEqsToVar);
@@ -1511,7 +1507,7 @@ algorithm
15111507
marker_list = List.fill(0, listLength(flatComps));
15121508
markerEq = List.fill(0, nEqns);
15131509

1514-
(markedComps, markedComps2, true, markedComps3) = compsMarker(currRedundantEqn, vecVarToEqs, m, flatComps, marker_list, markerEq, outLoopListComps);
1510+
(markedComps, markedComps2, true, markedComps3) = compsMarker(currRedundantEqn, vecVarToEqs, inM, flatComps, marker_list, markerEq, outLoopListComps);
15151511
//BackendDump.dumpList(markedComps, "markedComps: ");
15161512
//BackendDump.dumpList(markedComps2, "markedComps2: ");
15171513
//BackendDump.dumpList(markedComps3, "markedComps3: ");
@@ -1521,7 +1517,7 @@ algorithm
15211517
//BackendVarTransform.dumpReplacements(repl);
15221518
substEqns = applyVarReplacements(redundantEqn, inEqns, repl);
15231519

1524-
(outRange, true, uncheckedEquations) = getConsistentEquation(redundantEqn, substEqns, inEqns, m, vecVarToEqs, inVars, inShared, 1);
1520+
(outRange, true, uncheckedEquations) = getConsistentEquation(redundantEqn, substEqns, inEqns, inM, vecVarToEqs, inVars, inShared, 1);
15251521
(consistentEquations, inconsistentEquations, uncheckedEquations2) = consistencyCheck(restRedundantEqns, inEqns, inVars, inShared, nAddVars, inM, me, vecVarToEqs, vecEqsToVar, mapIncRowEqn);
15261522

15271523
consistentEquations = listAppend(consistentEquations, outRange);
@@ -1569,62 +1565,6 @@ algorithm
15691565
end matchcontinue;
15701566
end isVarExplicitSolvable;
15711567

1572-
1573-
protected function removeTempEdges "
1574-
This function removes all the unneeded edges of the additionally introduced
1575-
variables.
1576-
TODO: This function is probably not needed..."
1577-
input BackendDAE.IncidenceMatrix inM;
1578-
input Integer inNVars "number of actual variables" ;
1579-
input Integer inNAddVars "number of tmp variables" ;
1580-
input Integer inCounter "initially call this with 1" ;
1581-
output BackendDAE.IncidenceMatrix outM;
1582-
algorithm
1583-
outM := matchcontinue(inM, inNVars, inNAddVars, inCounter)
1584-
local
1585-
BackendDAE.IncidenceMatrix m;
1586-
list<Integer> oldIndices, newIndices;
1587-
1588-
case (_, _, _, _) equation
1589-
false = intLe(inCounter, inNVars+inNAddVars);
1590-
then inM;
1591-
1592-
case (_, _, _, _) equation
1593-
true = intLe(inCounter, inNVars+inNAddVars) "just to be careful" ;
1594-
oldIndices = inM[inCounter];
1595-
newIndices = removeTempEdges2(oldIndices, inNVars, inCounter);
1596-
m = arrayUpdate(inM, inCounter, newIndices);
1597-
m = removeTempEdges(m, inNVars, inNAddVars, inCounter+1);
1598-
then m;
1599-
end matchcontinue;
1600-
end removeTempEdges;
1601-
1602-
protected function removeTempEdges2
1603-
input list<Integer> inIndices;
1604-
input Integer inSize "number of actual variables" ;
1605-
input Integer inCounter;
1606-
output list<Integer> outListInteger;
1607-
algorithm
1608-
outListInteger := matchcontinue (inIndices, inSize, inCounter)
1609-
local
1610-
Integer oldIndex;
1611-
list<Integer> oldIndices, newIndices;
1612-
1613-
case ({}, _, _)
1614-
then {};
1615-
1616-
case (oldIndex::oldIndices, _, _) equation
1617-
true = intGt(oldIndex, inSize);
1618-
newIndices = removeTempEdges2(oldIndices, inSize, inCounter);
1619-
then newIndices;
1620-
1621-
case (oldIndex::oldIndices, _, _) equation
1622-
false = intGt(oldIndex, inSize) "just to be careful" ;
1623-
newIndices = removeTempEdges2(oldIndices, inSize, inCounter);
1624-
then oldIndex::newIndices;
1625-
end matchcontinue;
1626-
end removeTempEdges2;
1627-
16281568
protected function splitStrongComponents "author: mwenzler"
16291569
input list<list<Integer>> inComps "list of strong components" ;
16301570
output list<Integer> outListComps "all components of size 1" ;

0 commit comments

Comments
 (0)