Skip to content

Commit

Permalink
Clean up BackendEquation.mo
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel authored and OpenModelica-Hudson committed Apr 15, 2017
1 parent 9abe3dc commit 8e24cbf
Show file tree
Hide file tree
Showing 26 changed files with 539 additions and 666 deletions.
80 changes: 40 additions & 40 deletions Compiler/BackEnd/BackendDAEOptimize.mo

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -190,7 +190,7 @@ algorithm
comp := List.map1r(inComp, arrayGet, mapIncRowEqn);
comp := List.fold2(comp, uniqueComp, imark, markarray, {});
//comp = List.unique(comp);
eqn_lst := List.map1r(comp, BackendEquation.equationNth1, eqns);
eqn_lst := List.map1r(comp, BackendEquation.get, eqns);
outComp := analyseStrongComponentBlock(comp, eqn_lst, varlst, vlst, syst, shared);
else
Error.addInternalError("function analyseStrongComponentScalar failed", sourceInfo());
Expand Down Expand Up @@ -437,47 +437,47 @@ algorithm
BackendDAE.InnerEquations innerEquations;

case BackendDAE.SINGLEEQUATION(eqn=e, var=v) equation
eqn = BackendEquation.equationNth1(inEquationArray, e);
eqn = BackendEquation.get(inEquationArray, e);
var = BackendVariable.getVarAt(inVariables, v);
then ({eqn}, {var}, e);

case BackendDAE.EQUATIONSYSTEM(eqns=elst, vars=vlst) equation
eqnlst = BackendEquation.getEqns(elst, inEquationArray);
eqnlst = BackendEquation.getList(elst, inEquationArray);
varlst = List.map1r(vlst, BackendVariable.getVarAt, inVariables);
e = listHead(elst);
then (eqnlst, varlst, e);

case BackendDAE.SINGLEARRAY(eqn=e, vars=vlst) equation
eqn = BackendEquation.equationNth1(inEquationArray, e);
eqn = BackendEquation.get(inEquationArray, e);
varlst = List.map1r(vlst, BackendVariable.getVarAt, inVariables);
then ({eqn}, varlst, e);

case BackendDAE.SINGLEIFEQUATION(eqn=e, vars=vlst) equation
eqn = BackendEquation.equationNth1(inEquationArray, e);
eqn = BackendEquation.get(inEquationArray, e);
varlst = List.map1r(vlst, BackendVariable.getVarAt, inVariables);
then ({eqn}, varlst, e);

case BackendDAE.SINGLEALGORITHM(eqn=e, vars=vlst) equation
eqn = BackendEquation.equationNth1(inEquationArray, e);
eqn = BackendEquation.get(inEquationArray, e);
varlst = List.map1r(vlst, BackendVariable.getVarAt, inVariables);
then ({eqn}, varlst, e);

case BackendDAE.SINGLECOMPLEXEQUATION(eqn=e, vars=vlst) equation
eqn = BackendEquation.equationNth1(inEquationArray, e);
eqn = BackendEquation.get(inEquationArray, e);
varlst = List.map1r(vlst, BackendVariable.getVarAt, inVariables);
then ({eqn}, varlst, e);

case BackendDAE.SINGLEWHENEQUATION(eqn=e, vars=vlst) equation
eqn = BackendEquation.equationNth1(inEquationArray, e);
eqn = BackendEquation.get(inEquationArray, e);
varlst = List.map1r(vlst, BackendVariable.getVarAt, inVariables);
then ({eqn}, varlst, e);

case BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(tearingvars=vlst, residualequations=elst, innerEquations=innerEquations)) equation
eqnlst = BackendEquation.getEqns(elst, inEquationArray);
eqnlst = BackendEquation.getList(elst, inEquationArray);
varlst = List.map1r(vlst, BackendVariable.getVarAt, inVariables);
(otherEqns,otherVarsLst,_) = List.map_3(innerEquations, BackendDAEUtil.getEqnAndVarsFromInnerEquation);
otherVars = List.flatten(otherVarsLst);
eqnlst1 = BackendEquation.getEqns(otherEqns, inEquationArray);
eqnlst1 = BackendEquation.getList(otherEqns, inEquationArray);
varlst1 = List.map1r(otherVars, BackendVariable.getVarAt, inVariables);
e = listHead(elst);
then (listAppend(eqnlst, eqnlst1), listAppend(varlst, varlst1), e);
Expand Down
42 changes: 21 additions & 21 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -504,7 +504,7 @@ public function mergeEqSystems
input BackendDAE.EqSystem System1;
input output BackendDAE.EqSystem System2;
algorithm
System2.orderedEqs := BackendEquation.mergeEquationArray(System1.orderedEqs,System2.orderedEqs);
System2.orderedEqs := BackendEquation.merge(System1.orderedEqs,System2.orderedEqs);
System2.orderedVars := BackendVariable.mergeVariables(System1.orderedVars,System2.orderedVars);
end mergeEqSystems;

Expand Down Expand Up @@ -1558,7 +1558,7 @@ algorithm
equation
(eqnsNew,varsNew) = splitoutEquationAndVars(rest,inEqns,inVars,eqnsNew,varsNew);
(eqn_lst,var_lst,_) = BackendDAETransform.getEquationAndSolvedVar(comp, inEqns, inVars);
eqnsNew = BackendEquation.addEquations(eqn_lst, eqnsNew);
eqnsNew = BackendEquation.addList(eqn_lst, eqnsNew);
varsNew = BackendVariable.addVars(var_lst, varsNew);
then (eqnsNew,varsNew);
end match;
Expand Down Expand Up @@ -1692,7 +1692,7 @@ algorithm

indx_lst_e := Array.foldIndex(indx_arr, translateArrayList, {});

el := BackendEquation.getEqns(indx_lst_e, ordererdEqs);
el := BackendEquation.getList(indx_lst_e, ordererdEqs);
arrEqs := BackendEquation.listEquation(el);
vl := BackendEquation.equationsVars(arrEqs, v);

Expand Down Expand Up @@ -2147,7 +2147,7 @@ algorithm

for idx in 1:num_eqs loop
// Get the equation.
eq := BackendEquation.equationNth1(inEqns, idx);
eq := BackendEquation.get(inEqns, idx);
// Compute the row.
rowTree := incidenceRow(eq, inVars, inIndexType, functionTree, AvlSetInt.EMPTY());
row := AvlSetInt.listKeys(rowTree);
Expand Down Expand Up @@ -2179,7 +2179,7 @@ algorithm
for idx in 1:num_eqs loop
if inMask[idx] then
// Get the equation.
eq := BackendEquation.equationNth1(inEqns, idx);
eq := BackendEquation.get(inEqns, idx);
// Compute the row.
rowTree := incidenceRow(eq, inVars, inIndexType, functionTree, AvlSetInt.EMPTY());
row := AvlSetInt.listKeys(rowTree);
Expand Down Expand Up @@ -2215,7 +2215,7 @@ algorithm

for idx in 1:num_eqs loop
// Get the equation.
eq := BackendEquation.equationNth1(inEqns, idx);
eq := BackendEquation.get(inEqns, idx);

// Compute the row.
(rowTree, size) := incidenceRow(eq, inVars, inIndexType, functionTree, AvlSetInt.EMPTY());
Expand Down Expand Up @@ -3183,7 +3183,7 @@ algorithm
case (_,_,_,_,_,_,(e::eqns))
equation
abse = intAbs(e);
eqn = BackendEquation.equationNth1(daeeqns, abse);
eqn = BackendEquation.get(daeeqns, abse);
(row,_) = incidenceRow(eqn,vars,inIndxType,functionTree,AvlSetInt.EMPTY());
oldvars = getOldVars(m,abse);
m_1 = Array.replaceAtWithFill(abse,AvlSetInt.listKeys(row),{},m);
Expand Down Expand Up @@ -3299,7 +3299,7 @@ algorithm
case (_,_,_,_,e::eqns,_,_,_,_)
equation
abse = intAbs(e);
eqn = BackendEquation.equationNth1(daeeqns, abse);
eqn = BackendEquation.get(daeeqns, abse);
(row,_) = incidenceRow(eqn,vars,inIndxType,functionTree,AvlSetInt.Tree.EMPTY());
scalarindxs = iMapEqnIncRow[abse];
oldvars = getOldVars(m,listHead(scalarindxs));
Expand Down Expand Up @@ -3351,7 +3351,7 @@ algorithm
not intGt(index,n)
equation
abse = intAbs(index);
eqn = BackendEquation.equationNth1(daeeqns, abse);
eqn = BackendEquation.get(daeeqns, abse);
rowsize = BackendEquation.equationSize(eqn);
(row,_) = incidenceRow(eqn,vars,inIndxType,functionTree,AvlSetInt.EMPTY());
new_size = size+rowsize;
Expand Down Expand Up @@ -3900,7 +3900,7 @@ protected
algorithm
for i1 in 1:numberOfEqs loop
// get the equation
e := BackendEquation.equationNth1(eqArr, i1);
e := BackendEquation.get(eqArr, i1);
// compute the row
(row,size,varsSolvedInWhenEqnsTuple) := adjacencyRowEnhanced(vars, e, i1, rowmark, globalKnownVars, trytosolve);
rowindxs := List.intRange2(rowSize+1, rowSize+size);
Expand Down Expand Up @@ -3995,7 +3995,7 @@ algorithm
i1 = index+1;

// get the equation
e = BackendEquation.equationNth1(eqArr, i1);
e = BackendEquation.get(eqArr, i1);
// compute the row
(row,_,_) = adjacencyRowEnhanced(vars, e, i1, rowmark, globalKnownVars, trytosolve);
// put it in the arrays
Expand Down Expand Up @@ -7312,7 +7312,7 @@ algorithm
rhs := DAE.RCONST(0.0);
end try;
eqn := BackendDAE.EQUATION(lhs, rhs, DAE.emptyElementSource, BackendDAE.EQ_ATTR_DEFAULT_BINDING);
parameterEqns := BackendEquation.addEquation(eqn, parameterEqns);
parameterEqns := BackendEquation.add(eqn, parameterEqns);
end createParameterEquations;


Expand Down Expand Up @@ -8102,7 +8102,7 @@ algorithm
outSysts := Dangerous.listReverseInPlace(outSysts);
end if;

outShared.removedEqs := BackendEquation.addEquations(reqns, outShared.removedEqs);
outShared.removedEqs := BackendEquation.addList(reqns, outShared.removedEqs);
end filterEmptySystems;

protected function filterEmptySystem
Expand Down Expand Up @@ -8910,37 +8910,37 @@ algorithm
case(BackendDAE.SINGLEEQUATION(eqn=eidx,var=vidx),_,_)
equation
var = BackendVariable.getVarAt(varArr,vidx);
eq = BackendEquation.equationNth1(eqArr,eidx);
eq = BackendEquation.get(eqArr,eidx);
then ({var},{vidx},{eq},{eidx});
case(BackendDAE.EQUATIONSYSTEM(eqns=eidxs,vars=vidxs),_,_)
equation
vars = List.map1(vidxs,BackendVariable.getVarAtIndexFirst,varArr);
eqs = BackendEquation.getEqns(eidxs,eqArr);
eqs = BackendEquation.getList(eidxs,eqArr);
then (vars,vidxs,eqs,eidxs);
case(BackendDAE.SINGLEARRAY(eqn=eidx,vars=vidxs),_,_)
equation
vars = List.map1(vidxs,BackendVariable.getVarAtIndexFirst,varArr);
eq = BackendEquation.equationNth1(eqArr,eidx);
eq = BackendEquation.get(eqArr,eidx);
then (vars,vidxs,{eq},{eidx});
case(BackendDAE.SINGLEALGORITHM(eqn=eidx,vars=vidxs),_,_)
equation
vars = List.map1(vidxs,BackendVariable.getVarAtIndexFirst,varArr);
eq = BackendEquation.equationNth1(eqArr,eidx);
eq = BackendEquation.get(eqArr,eidx);
then (vars,vidxs,{eq},{eidx});
case(BackendDAE.SINGLECOMPLEXEQUATION(eqn=eidx,vars=vidxs),_,_)
equation
vars = List.map1(vidxs,BackendVariable.getVarAtIndexFirst,varArr);
eq = BackendEquation.equationNth1(eqArr,eidx);
eq = BackendEquation.get(eqArr,eidx);
then (vars,vidxs,{eq},{eidx});
case(BackendDAE.SINGLEWHENEQUATION(eqn=eidx,vars=vidxs),_,_)
equation
vars = List.map1(vidxs,BackendVariable.getVarAtIndexFirst,varArr);
eq = BackendEquation.equationNth1(eqArr,eidx);
eq = BackendEquation.get(eqArr,eidx);
then (vars,vidxs,{eq},{eidx});
case(BackendDAE.SINGLEIFEQUATION(eqn=eidx,vars=vidxs),_,_)
equation
vars = List.map1(vidxs,BackendVariable.getVarAtIndexFirst,varArr);
eq = BackendEquation.equationNth1(eqArr,eidx);
eq = BackendEquation.get(eqArr,eidx);
then (vars,vidxs,{eq},{eidx});
case(BackendDAE.TORNSYSTEM(strictTearingSet = BackendDAE.TEARINGSET(residualequations=eidxs,tearingvars=vidxs, innerEquations=innerEquations)),_,_)
equation
Expand All @@ -8949,7 +8949,7 @@ algorithm
eidxs = listAppend(otherEqns,eidxs);
vidxs = listAppend(otherVars,vidxs);
vars = List.map1(vidxs,BackendVariable.getVarAtIndexFirst,varArr);
eqs = BackendEquation.getEqns(eidxs,eqArr);
eqs = BackendEquation.getList(eidxs,eqArr);
then (vars,vidxs,eqs,eidxs);
end match;
end getStrongComponentVarsAndEquations;
Expand Down
32 changes: 16 additions & 16 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -231,7 +231,7 @@ algorithm
BackendDAE.EquationArray eqns;
case (eqno,BackendDAE.EQSYSTEM(orderedEqs = eqns))
equation
eq = BackendEquation.equationNth1(eqns, eqno);
eq = BackendEquation.get(eqns, eqno);
printEquation(eq);
then
();
Expand Down Expand Up @@ -1021,7 +1021,7 @@ algorithm
print("SingleEquation: " + intString(e) + "\n");
var = BackendVariable.getVarAt(vars,v);
printVarList({var});
eqn = BackendEquation.equationNth1(eqns,e);
eqn = BackendEquation.get(eqns,e);
printEquationList({eqn});
print("\n");
dumpEqnsSolved2(rest,eqns,vars);
Expand All @@ -1032,7 +1032,7 @@ algorithm
print("Equationsystem " + jacobianTypeStr(jacType) + ":\n");
varlst = List.map1r(vlst, BackendVariable.getVarAt, vars);
printVarList(varlst);
eqnlst = BackendEquation.getEqns(elst,eqns);
eqnlst = BackendEquation.getList(elst,eqns);
printEquationList(eqnlst);
print("\n");
print("Jac:\n" + dumpJacobianStr(jac) + "\n");
Expand All @@ -1045,7 +1045,7 @@ algorithm
print("ArrayEquation:\n");
varlst = List.map1r(vlst, BackendVariable.getVarAt, vars);
printVarList(varlst);
eqn = BackendEquation.equationNth1(eqns,e);
eqn = BackendEquation.get(eqns,e);
printEquationList({eqn});
print("\n");
dumpEqnsSolved2(rest,eqns,vars);
Expand All @@ -1056,7 +1056,7 @@ algorithm
print("IfEquation:\n");
varlst = List.map1r(vlst, BackendVariable.getVarAt, vars);
printVarList(varlst);
eqn = BackendEquation.equationNth1(eqns,e);
eqn = BackendEquation.get(eqns,e);
printEquationList({eqn});
print("\n");
dumpEqnsSolved2(rest,eqns,vars);
Expand All @@ -1067,7 +1067,7 @@ algorithm
print("Algorithm:\n");
varlst = List.map1r(vlst, BackendVariable.getVarAt, vars);
printVarList(varlst);
eqn = BackendEquation.equationNth1(eqns,e);
eqn = BackendEquation.get(eqns,e);
printEquationList({eqn});
print("\n");
dumpEqnsSolved2(rest,eqns,vars);
Expand All @@ -1078,7 +1078,7 @@ algorithm
print("ComplexEquation:\n");
varlst = List.map1r(vlst, BackendVariable.getVarAt, vars);
printVarList(varlst);
eqn = BackendEquation.equationNth1(eqns,e);
eqn = BackendEquation.get(eqns,e);
printEquationList({eqn});
print("\n");
dumpEqnsSolved2(rest,eqns,vars);
Expand All @@ -1089,7 +1089,7 @@ algorithm
print("WhenEquation:\n");
varlst = List.map1r(vlst, BackendVariable.getVarAt, vars);
printVarList(varlst);
eqn = BackendEquation.equationNth1(eqns,e);
eqn = BackendEquation.get(eqns,e);
printEquationList({eqn});
print("\n");
dumpEqnsSolved2(rest,eqns,vars);
Expand All @@ -1109,10 +1109,10 @@ algorithm
print("\nresidual vars\n");
printVarList(varlst);
print("\ninternal equation\n");
eqnlst = BackendEquation.getEqns(elst1,eqns);
eqnlst = BackendEquation.getList(elst1,eqns);
printEquationList(eqnlst);
print("\nresidual equations\n");
eqnlst = BackendEquation.getEqns(elst,eqns);
eqnlst = BackendEquation.getList(elst,eqns);
printEquationList(eqnlst);
print("\n");
dumpEqnsSolved2(rest,eqns,vars);
Expand All @@ -1130,10 +1130,10 @@ algorithm
varlst = List.map1r(vlst, BackendVariable.getVarAt, vars);
printVarList(varlst);
print("\n");
eqnlst = BackendEquation.getEqns(elst1,eqns);
eqnlst = BackendEquation.getList(elst1,eqns);
printEquationList(eqnlst);
print("\n");
eqnlst = BackendEquation.getEqns(elst,eqns);
eqnlst = BackendEquation.getList(elst,eqns);
printEquationList(eqnlst);
print("\n");
dumpEqnsSolved2(rest,eqns,vars);
Expand All @@ -1145,10 +1145,10 @@ algorithm
varlst = List.map1r(vlst2, BackendVariable.getVarAt, vars);
printVarList(varlst);
print("\n");
eqnlst = BackendEquation.getEqns(elst1,eqns);
eqnlst = BackendEquation.getList(elst1,eqns);
printEquationList(eqnlst);
print("\n");
eqnlst = BackendEquation.getEqns(elst2,eqns);
eqnlst = BackendEquation.getList(elst2,eqns);
printEquationList(eqnlst);
print("\n");
dumpEqnsSolved2(rest,eqns,vars);
Expand Down Expand Up @@ -3056,7 +3056,7 @@ protected
String s1,s2,s3;
BackendDAE.Equation eqn;
algorithm
eqn := BackendEquation.equationNth1(eqns, e);
eqn := BackendEquation.get(eqns, e);
s2 := equationString(eqn);
s3 := intString(e);
outS := stringAppendList({inS,s3,": ",s2,";\n"});
Expand Down Expand Up @@ -4149,7 +4149,7 @@ algorithm
isResEq := Util.tuple21(listGet(attsIn,indx));
daeIdxStr := Util.tuple22(listGet(attsIn,indx));
typeStr := if isResEq then "residualEq" else "otherEq";
{eq} := BackendEquation.getEqns({indx}, eqs);
{eq} := BackendEquation.getList({indx}, eqs);
eqString := BackendDump.equationString(eq);
eqNodeId := getEqNodeIdx(indx);
idxString := intString(indx);
Expand Down

0 comments on commit 8e24cbf

Please sign in to comment.