Skip to content

Commit

Permalink
improve symbolic jacobian generation
Browse files Browse the repository at this point in the history
- generate sparse pattern for algebraic loops with GENERIC_JACOBIAN()
  • Loading branch information
Willi Braun authored and OpenModelica-Hudson committed Nov 24, 2016
1 parent e4cfc38 commit 95e5e65
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 181 deletions.
5 changes: 4 additions & 1 deletion Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -728,7 +728,7 @@ uniontype Jacobian
end FULL_JACOBIAN;

record GENERIC_JACOBIAN
SymbolicJacobian jacobian;
Option<SymbolicJacobian> jacobian;
SparsePattern sparsePattern;
SparseColoring coloring;
end GENERIC_JACOBIAN;
Expand All @@ -754,6 +754,9 @@ type SparsePattern = tuple<list<tuple< .DAE.ComponentRef, list< .DAE.ComponentRe
list< .DAE.ComponentRef>>, // diffed vars
Integer>; // nonZeroElements

public
constant SparsePattern emptySparsePattern = ({},{},({},{}),0);

public
type SparseColoring = list<list< .DAE.ComponentRef>>; // colouring

Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -1917,7 +1917,7 @@ algorithm
case BackendDAE.EMPTY_JACOBIAN()
then -1;
/* TODO: implement/check for GENERIC_JACOBIAN */
case BackendDAE.GENERIC_JACOBIAN(jacobian=(_,_,vars1,vars2,_))
case BackendDAE.GENERIC_JACOBIAN(jacobian=SOME((_,_,vars1,vars2,_)))
guard
listLength(vars1) == listLength(vars2)
then listLength(vars1);
Expand Down
6 changes: 3 additions & 3 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -5943,9 +5943,9 @@ algorithm
BackendDAE.BackendDAE bdae;
case BackendDAE.EQUATIONSYSTEM(jac=BackendDAE.FULL_JACOBIAN(SOME(jac)))
then traverseBackendDAEExpsJacobianEqn(jac, inFunc, arg);
case BackendDAE.EQUATIONSYSTEM(jac=BackendDAE.GENERIC_JACOBIAN(jacobian = (bdae,_,_,_,_)))
case BackendDAE.EQUATIONSYSTEM(jac=BackendDAE.GENERIC_JACOBIAN(jacobian = SOME((bdae,_,_,_,_))))
then traverseBackendDAEExps(bdae, inFunc, arg);
case BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(jac=BackendDAE.GENERIC_JACOBIAN(jacobian = (bdae,_,_,_,_))))
case BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(jac=BackendDAE.GENERIC_JACOBIAN(jacobian = SOME((bdae,_,_,_,_)))))
then traverseBackendDAEExps(bdae, inFunc, arg);
else arg;
end match;
Expand Down Expand Up @@ -6001,7 +6001,7 @@ algorithm
BackendDAE.BackendDAE bdae;
Type_a arg;
case ({}, _, _) then inTypeA;
case (BackendDAE.STATESET(jacobian = BackendDAE.GENERIC_JACOBIAN(jacobian = (bdae,_,_,_,_)))::rest, _, _)
case (BackendDAE.STATESET(jacobian = BackendDAE.GENERIC_JACOBIAN(jacobian = SOME((bdae,_,_,_,_))))::rest, _, _)
equation
arg = traverseBackendDAEExps(bdae, inFunc, inTypeA);
then
Expand Down
9 changes: 8 additions & 1 deletion Compiler/BackEnd/BackendDump.mo
Expand Up @@ -2241,12 +2241,19 @@ algorithm
s = "FULL JACOBIAN:\n";
s = s + dumpJacobianStr(fJac);
then s;
case(BackendDAE.GENERIC_JACOBIAN(jacobian=sJac))
case(BackendDAE.GENERIC_JACOBIAN(jacobian=SOME(sJac),sparsePattern=sparsePattern))
equation
((dae,_,_,_,_)) = sJac;
s = "GENERIC JACOBIAN:\n";
dumpBackendDAE(dae,"Directional Derivatives System");
dumpSparsityPattern(sparsePattern,"Sparse Pattern");
then s;
case(BackendDAE.GENERIC_JACOBIAN(jacobian=NONE(),sparsePattern=sparsePattern))
equation
s = "GENERIC JACOBIAN:\n";
dumpSparsityPattern(sparsePattern,"Sparse Pattern");
then s;

case(BackendDAE.EMPTY_JACOBIAN())
equation
s = "EMPTY JACOBIAN:\n";
Expand Down

0 comments on commit 95e5e65

Please sign in to comment.