Skip to content

Commit

Permalink
[BE] rename incidence to adjacency matrix
Browse files Browse the repository at this point in the history
 - misleading name incidence matrix changed to adjacency matrix
 - all instances of incidence Incidence and INCIDENCE have been replaced
  • Loading branch information
kabdelhak authored and adrpo committed Jan 24, 2020
1 parent 315a2d2 commit fdfd6ac
Show file tree
Hide file tree
Showing 67 changed files with 1,869 additions and 1,873 deletions.
40 changes: 20 additions & 20 deletions OMCompiler/Compiler/BackEnd/AdjacencyMatrix.mo
Expand Up @@ -65,17 +65,17 @@ public function traverseAdjacencyMatrix<T>
output BackendDAE.AdjacencyMatrix outM;
output T outTypeA;
partial function FuncType
input BackendDAE.IncidenceMatrixElement elem;
input BackendDAE.AdjacencyMatrixElement elem;
input Integer pos;
input T inTpl;
output list<Integer> outList;
output T outTpl;
end FuncType;
algorithm
(outM, outTypeA) := traverseIncidenceMatrix1(inM, func, 1, arrayLength(inM), inTypeA);
(outM, outTypeA) := traverseAdjacencyMatrix1(inM, func, 1, arrayLength(inM), inTypeA);
end traverseAdjacencyMatrix;

protected function traverseIncidenceMatrix1<T>
protected function traverseAdjacencyMatrix1<T>
input BackendDAE.AdjacencyMatrix inM;
input FuncType func;
input Integer pos "iterated 1..len";
Expand All @@ -84,18 +84,18 @@ protected function traverseIncidenceMatrix1<T>
output BackendDAE.AdjacencyMatrix outM;
output T outTypeA;
partial function FuncType
input BackendDAE.IncidenceMatrixElement elem;
input BackendDAE.AdjacencyMatrixElement elem;
input Integer pos;
input T inTpl;
output list<Integer> outList;
output T outTpl;
end FuncType;
algorithm
(outM, outTypeA) := traverseIncidenceMatrix2(inM, func, pos, len, intGt(pos, len), inTypeA);
(outM, outTypeA) := traverseAdjacencyMatrix2(inM, func, pos, len, intGt(pos, len), inTypeA);
annotation(__OpenModelica_EarlyInline = true);
end traverseIncidenceMatrix1;
end traverseAdjacencyMatrix1;

protected function traverseIncidenceMatrix2<T>
protected function traverseAdjacencyMatrix2<T>
input BackendDAE.AdjacencyMatrix inM;
input FuncType func;
input Integer pos "iterated 1..len";
Expand All @@ -105,7 +105,7 @@ protected function traverseIncidenceMatrix2<T>
output BackendDAE.AdjacencyMatrix outM;
output T outTypeA;
partial function FuncType
input BackendDAE.IncidenceMatrixElement elem;
input BackendDAE.AdjacencyMatrixElement elem;
input Integer pos;
input T inTpl;
output list<Integer> outList;
Expand All @@ -124,13 +124,13 @@ algorithm
case false equation
(eqns, extArg) = func(inM[pos], pos, inTypeA);
eqns1 = List.removeOnTrue(pos, intLt, eqns);
(m1, extArg1) = traverseIncidenceMatrixList(eqns1, inM, func, arrayLength(inM), pos, extArg);
(m2, extArg2) = traverseIncidenceMatrix2(m1, func, pos+1, len, intGt(pos+1, len), extArg1);
(m1, extArg1) = traverseAdjacencyMatrixList(eqns1, inM, func, arrayLength(inM), pos, extArg);
(m2, extArg2) = traverseAdjacencyMatrix2(m1, func, pos+1, len, intGt(pos+1, len), extArg1);
then (m2, extArg2);
end match;
end traverseIncidenceMatrix2;
end traverseAdjacencyMatrix2;

protected function traverseIncidenceMatrixList<T>
protected function traverseAdjacencyMatrixList<T>
input list<Integer> inLst "elements to traverse";
input BackendDAE.AdjacencyMatrix inM;
input FuncType func;
Expand All @@ -140,7 +140,7 @@ protected function traverseIncidenceMatrixList<T>
output BackendDAE.AdjacencyMatrix outM;
output T outTypeA;
partial function FuncType
input BackendDAE.IncidenceMatrixElement elem;
input BackendDAE.AdjacencyMatrixElement elem;
input Integer pos;
input T inTpl;
output list<Integer> outList;
Expand All @@ -165,24 +165,24 @@ algorithm
(eqns, extArg) = func(inM[pos], pos, inTypeA);
eqns1 = List.removeOnTrue(maxpos, intLt, eqns);
alleqns = List.unionOnTrueList({rest, eqns1}, intEq);
(m, extArg1) = traverseIncidenceMatrixList(alleqns, inM, func, len, maxpos, extArg);
(m, extArg1) = traverseAdjacencyMatrixList(alleqns, inM, func, len, maxpos, extArg);
then (m, extArg1);

case (pos::rest) equation
// do not leave the list
true = intLt(pos, len+1);
(m, extArg) = traverseIncidenceMatrixList(rest, inM, func, len, maxpos, inTypeA);
(m, extArg) = traverseAdjacencyMatrixList(rest, inM, func, len, maxpos, inTypeA);
then (m, extArg);

else equation
true = Flags.isSet(Flags.FAILTRACE);
Debug.trace("- BackendDAEOptimize.traverseIncidenceMatrixList failed\n");
Debug.trace("- BackendDAEOptimize.traverseAdjacencyMatrixList failed\n");
then fail();
end matchcontinue;
end traverseIncidenceMatrixList;
end traverseAdjacencyMatrixList;

public function getOtherEqSysAdjacencyMatrix
"This function removes tvar and res from incidence matrix."
"This function removes tvar and res from adjacency matrix."
input BackendDAE.AdjacencyMatrix m;
input Integer size;
input Integer index;
Expand Down Expand Up @@ -219,7 +219,7 @@ algorithm
end isAssigned;

public function transposeAdjacencyMatrix
"Calculates the transpose of the incidence matrix,
"Calculates the transpose of the adjacency matrix,
i.e. which equations each variable is present in."
input BackendDAE.AdjacencyMatrix m;
input Integer nRowsMt;
Expand Down Expand Up @@ -263,7 +263,7 @@ algorithm
end transposeRow;

public function absAdjacencyMatrix "author: PA
Applies absolute value to all entries in the incidence matrix.
Applies absolute value to all entries in the adjacency matrix.
This can be used when e.g. der(x) and x are considered the same variable."
input BackendDAE.AdjacencyMatrix m;
output BackendDAE.AdjacencyMatrix res;
Expand Down
24 changes: 10 additions & 14 deletions OMCompiler/Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -674,17 +674,13 @@ end TimeEvent;
// AdjacencyMatrixes
//
public
type IncidenceMatrixElementEntry = Integer;
type IncidenceMatrixElement = list<IncidenceMatrixElementEntry>;
type IncidenceMatrix = array<IncidenceMatrixElement> "array<list<Integer>>";
type IncidenceMatrixT = IncidenceMatrix
type AdjacencyMatrixElementEntry = Integer;
type AdjacencyMatrixElement = list<AdjacencyMatrixElementEntry>;
type AdjacencyMatrix = array<AdjacencyMatrixElement> "array<list<Integer>>";
type AdjacencyMatrixT = AdjacencyMatrix
"a list of equation indices (1..n), one for each variable. Equations that -only-
contain the state variable and not the derivative have a negative index.";

public
type AdjacencyMatrix = IncidenceMatrix;
type AdjacencyMatrixT = IncidenceMatrixT;

type AdjacencyMatrixMapping = tuple<array<list<Integer>>, array<Integer>, IndexType, Boolean, Boolean>
"a mapping for adjacency matrices that contains:
array<list<Integer>>: array index -> scalar index list
Expand Down Expand Up @@ -724,12 +720,12 @@ type Constraints = list<.DAE.Constraint> "Constraints on the solvability of the

public
uniontype IndexType
record ABSOLUTE "incidence matrix with absolute indexes" end ABSOLUTE;
record NORMAL "incidence matrix with positive/negative indexes" end NORMAL;
record SOLVABLE "incidence matrix with only solvable entries, for example {a,b,c}[d] then d is skipped" end SOLVABLE;
record BASECLOCK_IDX "incidence matrix for base-clock partitioning" end BASECLOCK_IDX;
record SUBCLOCK_IDX "incidence matrix for sub-clock partitioning" end SUBCLOCK_IDX;
record SPARSE "incidence matrix as normal, but add for inputs also a value" end SPARSE;
record ABSOLUTE "adjacency matrix with absolute indexes" end ABSOLUTE;
record NORMAL "adjacency matrix with positive/negative indexes" end NORMAL;
record SOLVABLE "adjacency matrix with only solvable entries, for example {a,b,c}[d] then d is skipped" end SOLVABLE;
record BASECLOCK_IDX "adjacency matrix for base-clock partitioning" end BASECLOCK_IDX;
record SUBCLOCK_IDX "adjacency matrix for sub-clock partitioning" end SUBCLOCK_IDX;
record SPARSE "adjacency matrix as normal, but add for inputs also a value" end SPARSE;
end IndexType;

//
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -173,7 +173,7 @@ algorithm
NONE()
));
BackendDAEUtil.checkBackendDAEWithErrorMsg(outBackendDAE);
BackendDAEUtil.checkIncidenceMatrixSolvability(syst, functionTree,BackendDAEUtil.isInitializationDAE(outBackendDAE.shared));
BackendDAEUtil.checkAdjacencyMatrixSolvability(syst, functionTree,BackendDAEUtil.isInitializationDAE(outBackendDAE.shared));
if Flags.isSet(Flags.DUMP_BACKENDDAE_INFO) then
Error.addSourceMessage(Error.BACKENDDAEINFO_LOWER,{String(BackendEquation.equationArraySize(syst.orderedEqs)), String(BackendVariable.varsSize(syst.orderedVars))},AbsynUtil.dummyInfo);
end if;
Expand Down
6 changes: 3 additions & 3 deletions OMCompiler/Compiler/BackEnd/BackendDAEEXT.mo
Expand Up @@ -204,14 +204,14 @@ end getF;
see: http://bmi.osu.edu/~kamer/index.html
*****************************************/

public function setIncidenceMatrix "author: Frenkel TUD 2012-04"
public function setAdjacencyMatrix "author: Frenkel TUD 2012-04"
input Integer nv;
input Integer ne;
input Integer nz;
input array<list<Integer>> m;

external "C" BackendDAEEXT_setIncidenceMatrix(nv,ne,nz,m) annotation(Library = "omcruntime");
end setIncidenceMatrix;
external "C" BackendDAEEXT_setAdjacencyMatrix(nv,ne,nz,m) annotation(Library = "omcruntime");
end setAdjacencyMatrix;

/* TODO: Implement an external C function for bootstrapped omc or remove me. DO NOT SIMPLY REMOVE THIS COMMENT
public function cheapmatching
Expand Down

0 comments on commit fdfd6ac

Please sign in to comment.