Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 24 additions & 39 deletions Compiler/BackEnd/SymbolicJacobian.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ protected function getSparsePattern2
protected
list<Integer> localList;
algorithm
localList := getSparsePatternHelp(inInputVars, invarSparse, inMark, inUsed, inmarkValue, {});
localList := getSparsePatternHelp(inInputVars, invarSparse, inMark, inUsed, inmarkValue);
List.map2_0(inSolvedVars, Array.updateIndexFirst, localList, invarSparse);
List.map2_0(inEqns, Array.updateIndexFirst, localList, ineqnSparse);
end getSparsePattern2;
Expand All @@ -1462,47 +1462,32 @@ protected function getSparsePatternHelp
input array<Integer> inMark;
input array<Integer> inUsed;
input Integer inmarkValue;
input list<Integer> inLocalList;
output list<Integer> outLocalList;
algorithm
outLocalList := match (inInputVars, invarSparse, inMark, inUsed, inmarkValue, inLocalList)
local
list<Integer> localList, varSparse, rest;
Integer arrayElement, var;
case ({},_,_,_,_,_) then inLocalList;
case (var::rest,_,_,_,_,_)
equation
arrayElement = arrayGet(inUsed, var);
localList = if intEq(1, arrayElement) then getSparsePatternHelp2(var, inMark, inmarkValue, inLocalList) else inLocalList;
output list<Integer> outLocalList = {};
protected
Integer arrayElement;
list<Integer> varSparse;
algorithm
for var in inInputVars loop
arrayElement := arrayGet(inUsed, var);
if intEq(1, arrayElement) then
arrayElement := arrayGet(inMark, var);
if not intEq(inmarkValue, arrayElement) then
arrayUpdate(inMark, var, inmarkValue);
outLocalList := var::outLocalList;
end if;
end if;

varSparse = arrayGet(invarSparse, var);
localList = List.fold2(varSparse, getSparsePatternHelp2, inMark, inmarkValue, localList);
localList = getSparsePatternHelp(rest, invarSparse, inMark, inUsed, inmarkValue, localList);
then localList;
end match;
varSparse := arrayGet(invarSparse, var);
for v in varSparse loop
arrayElement := arrayGet(inMark, v);
if not intEq(inmarkValue, arrayElement) then
arrayUpdate(inMark, v, inmarkValue);
outLocalList := v::outLocalList;
end if;
end for;
end for;
end getSparsePatternHelp;

protected function getSparsePatternHelp2
input Integer inInputVar;
input array<Integer> inMark;
input Integer inmarkValue;
input list<Integer> inLocalList;
output list<Integer> outLocalList;
algorithm
outLocalList := matchcontinue(inInputVar, inMark, inmarkValue, inLocalList)
local
Integer arrayElement;
case (_,_,_,_)
equation
arrayElement = arrayGet(inMark, inInputVar);
false = intEq(inmarkValue, arrayElement);
arrayUpdate(inMark, inInputVar, inmarkValue);
then inInputVar::inLocalList;
else
then inLocalList;
end matchcontinue;
end getSparsePatternHelp2;

public function transposeSparsePattern
input list<list<Integer>> inSparsePattern;
input array<list<Integer>> inAccumList;
Expand Down
55 changes: 23 additions & 32 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2864,15 +2864,17 @@ protected function simplifyAddJoinTerms
output list<tuple<DAE.Exp, Real>> outTplExpRealLst = {};
protected
list<tuple<DAE.Exp, Real>> tplExpRealLst = inTplExpRealLst;
tuple<DAE.Exp, Real> t;
DAE.Exp e;
Real coeff, coeff2;
algorithm

while not listEmpty(tplExpRealLst) loop
(e, coeff) :: tplExpRealLst := tplExpRealLst;
t :: tplExpRealLst := tplExpRealLst;
(e, coeff) := t;
(coeff2, tplExpRealLst) := simplifyAddJoinTermsFind(e, tplExpRealLst);
coeff := coeff + coeff2;
outTplExpRealLst := (e, coeff) :: outTplExpRealLst;
outTplExpRealLst := (if coeff2==0 then t else (e, coeff)) :: outTplExpRealLst;
end while;
//outTplExpRealLst := listReverse(outTplExpRealLst);
end simplifyAddJoinTerms;
Expand All @@ -2882,31 +2884,21 @@ protected function simplifyAddJoinTermsFind
Helper function to simplifyAddJoinTerms, finds all occurences of Expression."
input DAE.Exp inExp;
input list<tuple<DAE.Exp, Real>> inTplExpRealLst;
output Real outReal;
output list<tuple<DAE.Exp, Real>> outTplExpRealLst;
output Real outReal = 0.0;
output list<tuple<DAE.Exp, Real>> outTplExpRealLst = {};
protected
DAE.Exp e;
Real coeff;
algorithm
(outReal,outTplExpRealLst) := matchcontinue (inExp,inTplExpRealLst)
local
Real coeff2,coeff3,coeff;
list<tuple<DAE.Exp, Real>> res,rest;
DAE.Exp e,e2;

case (_,{}) then (0.0,{});

case (e,((e2,coeff) :: rest))
equation
true = Expression.expEqual(e, e2);
(coeff2,res) = simplifyAddJoinTermsFind(e, rest);
coeff3 = coeff + coeff2;
then
(coeff3,res);

case (e,((e2,coeff) :: rest)) /* not Expression.expEqual */
equation
(coeff2,res) = simplifyAddJoinTermsFind(e, rest);
then
(coeff2,((e2,coeff) :: res));
end matchcontinue;
for t in inTplExpRealLst loop
(e,coeff) := t;
if Expression.expEqual(inExp, e) then
outReal := outReal + coeff;
else
outTplExpRealLst := t::outTplExpRealLst;
end if;
end for;
outTplExpRealLst := Dangerous.listReverseInPlace(outTplExpRealLst);
end simplifyAddJoinTermsFind;

protected function simplifyAddMakeMul
Expand All @@ -2919,7 +2911,6 @@ protected
tuple<DAE.Exp, Real> tplExpReal;
algorithm
for tplExpReal in inTplExpRealLst loop

outExpLst := matchcontinue (tplExpReal)
local
DAE.Exp e;
Expand Down Expand Up @@ -2951,14 +2942,14 @@ protected function simplifyBinaryAddCoeff2
input DAE.Exp inExp;
output tuple<DAE.Exp, Real> outRes;
algorithm
outRes := matchcontinue (inExp)
outRes := match (inExp)
local
DAE.Exp exp,e1,e2,e;
Real coeff,coeff_1;
Integer icoeff;
Type tp;

case ((exp as DAE.CREF())) then ((exp,1.0));
case (DAE.CREF()) then ((inExp,1.0));

case (DAE.UNARY(operator = DAE.UMINUS(ty = DAE.T_REAL()), exp = exp))
equation
Expand All @@ -2985,14 +2976,14 @@ algorithm
((e1,coeff_1));

case (DAE.BINARY(exp1 = e1,operator = DAE.ADD(),exp2 = e2))
equation
true = Expression.expEqual(e1, e2);
guard
Expression.expEqual(e1, e2)
then
((e1,2.0));

else ((inExp,1.0));

end matchcontinue;
end match;
end simplifyBinaryAddCoeff2;

protected function simplifyBinaryMulCoeff2
Expand Down