Skip to content

Commit

Permalink
[BE] do not allow incomplete function inverting
Browse files Browse the repository at this point in the history
  • Loading branch information
kabdelhak authored and adrpo committed Oct 21, 2020
1 parent 8dd669a commit 63d72ed
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -4759,24 +4759,24 @@ algorithm
equation
lst = adjacencyRowExpEnhanced(e1, vars, mark, rowmark, isInitial, {});
lst = adjacencyRowExpEnhanced(e2, vars, mark, rowmark, isInitial, lst);
row = adjacencyRowEnhanced1(lst,e1,e2,vars,globalKnownVars,mark,rowmark,{},trytosolve,shared);
row = adjacencyRowEnhanced1(lst,e1,e2,vars,globalKnownVars,mark,rowmark,{},trytosolve,1,shared);
then
(row,1);
// COMPLEX_EQUATION
case (vars,BackendDAE.COMPLEX_EQUATION(size=size,left=e1,right=e2),_,_,_)
equation
lst = adjacencyRowExpEnhanced(e1, vars, mark, rowmark, isInitial, {});
lst = adjacencyRowExpEnhanced(e2, vars, mark, rowmark, isInitial, lst);
row = adjacencyRowEnhanced1(lst,e1,e2,vars,globalKnownVars,mark,rowmark,{},trytosolve,shared);
row = adjacencyRowEnhanced1(lst,e1,e2,vars,globalKnownVars,mark,rowmark,{},trytosolve,size,shared);
then
(row,size);
// ARRAY_EQUATION
case (vars,BackendDAE.ARRAY_EQUATION(dimSize=ds,left=e1,right=e2),_,_,_)
equation
lst = adjacencyRowExpEnhanced(e1, vars, mark, rowmark, isInitial, {});
lst = adjacencyRowExpEnhanced(e2, vars, mark, rowmark, isInitial, lst);
row = adjacencyRowEnhanced1(lst,e1,e2,vars,globalKnownVars,mark,rowmark,{},trytosolve,shared);
size = List.fold(ds,intMul,1);
row = adjacencyRowEnhanced1(lst,e1,e2,vars,globalKnownVars,mark,rowmark,{},trytosolve,size,shared);
then
(row,size);

Expand All @@ -4786,14 +4786,14 @@ algorithm
expCref = Expression.crefExp(cr);
lst = adjacencyRowExpEnhanced(expCref, vars, mark, rowmark, isInitial, {});
lst = adjacencyRowExpEnhanced(e, vars, mark, rowmark, isInitial, lst);
row = adjacencyRowEnhanced1(lst,expCref,e,vars,globalKnownVars,mark,rowmark,{},trytosolve,shared);
row = adjacencyRowEnhanced1(lst,expCref,e,vars,globalKnownVars,mark,rowmark,{},trytosolve,1,shared);
then
(row,1);
// RESIDUAL_EQUATION
case (vars,BackendDAE.RESIDUAL_EQUATION(exp = e),_,_,_)
equation
lst = adjacencyRowExpEnhanced(e, vars, mark, rowmark, isInitial, {});
row = adjacencyRowEnhanced1(lst,e,DAE.RCONST(0.0),vars,globalKnownVars,mark,rowmark,{},trytosolve,shared);
row = adjacencyRowEnhanced1(lst,e,DAE.RCONST(0.0),vars,globalKnownVars,mark,rowmark,{},trytosolve,1,shared);
then
(row,1);

Expand Down Expand Up @@ -4862,7 +4862,7 @@ algorithm
// mark all negative because the when condition cannot used to solve a variable
lst = List.fold4(expl, adjacencyRowExpEnhanced, vars, mark, rowmark, isInitial, {});
_ = List.fold1(lst,markNegativ,rowmark,mark);
row1 = adjacencyRowEnhanced1(lst,DAE.RCONST(0.0),DAE.RCONST(0.0),vars,globalKnownVars,mark,rowmark,{},trytosolve,shared);
row1 = adjacencyRowEnhanced1(lst,DAE.RCONST(0.0),DAE.RCONST(0.0),vars,globalKnownVars,mark,rowmark,{},trytosolve,1,shared);

(row, size) = adjacencyRowEnhancedEqnLst(eqnselse, vars, mark, rowmark, globalKnownVars, trytosolve,shared);
lst = List.map(row,Util.tuple31);
Expand Down Expand Up @@ -5082,7 +5082,7 @@ algorithm
_ = List.fold1(lst,markNegativ,rowmark,mark);
//leftexp = Expression.crefExp(left);
lst = adjacencyRowExpEnhanced(leftexp, vars, mark, rowmark, isInitial, lst);
outRow = adjacencyRowEnhanced1(lst,leftexp,right,vars,globalKnownVars,mark,rowmark,outRow,false,shared);
outRow = adjacencyRowEnhanced1(lst,leftexp,right,vars,globalKnownVars,mark,rowmark,outRow,false,1,shared);
then ();

case BackendDAE.ASSIGN(leftexp, right) equation
Expand All @@ -5093,7 +5093,7 @@ algorithm
// mark all negative because the when condition cannot used to solve a variable
_ = List.fold1(lst,markNegativ,rowmark,mark);
lst = adjacencyRowExpEnhanced(leftexp, vars, mark, rowmark, isInitial, lst);
outRow = adjacencyRowEnhanced1(lst,leftexp,right,vars,globalKnownVars,mark,rowmark,outRow,false,shared);
outRow = adjacencyRowEnhanced1(lst,leftexp,right,vars,globalKnownVars,mark,rowmark,outRow,false,1,shared);
then ();

else ();
Expand Down Expand Up @@ -5132,6 +5132,7 @@ protected function adjacencyRowEnhanced1
input array<Integer> rowmark;
input BackendDAE.AdjacencyMatrixElementEnhanced inRow;
input Boolean trytosolve;
input Integer size;
input BackendDAE.Shared shared;
output BackendDAE.AdjacencyMatrixElementEnhanced outRow;
algorithm
Expand Down Expand Up @@ -5166,7 +5167,7 @@ algorithm
true = ComponentReference.crefEqualNoStringCompare(cr, cr1);
false = Expression.expHasDerCref(e2,cr);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,_,DAE.CALL(path= Absyn.IDENT("der"),expLst={DAE.CREF(componentRef = cr)}),_,_,_,_,_)
equation
rabs = intAbs(r);
Expand All @@ -5177,7 +5178,7 @@ algorithm
true = ComponentReference.crefEqualNoStringCompare(cr, cr1);
false = Expression.expHasDerCref(e1,cr);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,DAE.CREF(componentRef=cr),_,_,_,_,_,_)
equation
rabs = intAbs(r);
Expand All @@ -5188,7 +5189,7 @@ algorithm
true = ComponentReference.crefEqualNoStringCompare(cr, cr1);
false = Expression.expHasCrefNoPreorDer(e2,cr);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,DAE.CREF(componentRef=cr),_,_,_,_,_,_)
equation
rabs = intAbs(r);
Expand All @@ -5200,7 +5201,7 @@ algorithm
true = ComponentReference.crefEqualNoStringCompare(cr, crarr);
false = Expression.expHasCrefNoPreorDer(e2,cr);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,DAE.LUNARY(operator=DAE.NOT(_),exp=DAE.CREF(componentRef=cr)),_,_,_,_,_,_)
equation
rabs = intAbs(r);
Expand All @@ -5211,7 +5212,7 @@ algorithm
true = ComponentReference.crefEqualNoStringCompare(cr, cr1);
false = Expression.expHasCrefNoPreorDer(e2,cr);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,DAE.UNARY(operator=DAE.UMINUS(_),exp=DAE.CREF(componentRef=cr)),_,_,_,_,_,_)
equation
rabs = intAbs(r);
Expand All @@ -5222,7 +5223,7 @@ algorithm
true = ComponentReference.crefEqualNoStringCompare(cr, cr1);
false = Expression.expHasCrefNoPreorDer(e2,cr);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,DAE.UNARY(operator=DAE.UMINUS_ARR(_),exp=DAE.CREF(componentRef=cr)),_,_,_,_,_,_)
equation
rabs = intAbs(r);
Expand All @@ -5234,7 +5235,7 @@ algorithm
true = ComponentReference.crefEqualNoStringCompare(cr, crarr);
false = Expression.expHasCrefNoPreorDer(e2,cr);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,_,DAE.CREF(componentRef=cr),_,_,_,_,_)
equation
rabs = intAbs(r);
Expand All @@ -5245,7 +5246,7 @@ algorithm
true = ComponentReference.crefEqualNoStringCompare(cr, cr1);
false = Expression.expHasCrefNoPreorDer(e1,cr);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,_,DAE.CREF(componentRef=cr),_,_,_,_,_)
equation
rabs = intAbs(r);
Expand All @@ -5257,7 +5258,7 @@ algorithm
true = ComponentReference.crefEqualNoStringCompare(cr, crarr);
false = Expression.expHasCrefNoPreorDer(e1,cr);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,_,DAE.LUNARY(operator=DAE.NOT(_),exp=DAE.CREF(componentRef=cr)),_,_,_,_,_)
equation
rabs = intAbs(r);
Expand All @@ -5268,7 +5269,7 @@ algorithm
true = ComponentReference.crefEqualNoStringCompare(cr, cr1);
false = Expression.expHasCrefNoPreorDer(e1,cr);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,_,DAE.UNARY(operator=DAE.UMINUS(_),exp=DAE.CREF(componentRef=cr)),_,_,_,_,_)
equation
rabs = intAbs(r);
Expand All @@ -5279,7 +5280,7 @@ algorithm
true = ComponentReference.crefEqualNoStringCompare(cr, cr1);
false = Expression.expHasCrefNoPreorDer(e1,cr);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,_,DAE.UNARY(operator=DAE.UMINUS_ARR(_),exp=DAE.CREF(componentRef=cr)),_,_,_,_,_)
equation
rabs = intAbs(r);
Expand All @@ -5291,7 +5292,7 @@ algorithm
true = ComponentReference.crefEqualNoStringCompare(cr, crarr);
false = Expression.expHasCrefNoPreorDer(e1,cr);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,DAE.CREF(componentRef=cr),_,_,_,_,_,_)
equation
rabs = intAbs(r);
Expand All @@ -5302,7 +5303,7 @@ algorithm
true = ComponentReference.crefPrefixOf(cr, cr1);
false = Expression.expHasCrefNoPreorDer(e2,cr);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,_,DAE.CREF(componentRef=cr),_,_,_,_,_)
equation
rabs = intAbs(r);
Expand All @@ -5313,7 +5314,7 @@ algorithm
true = ComponentReference.crefPrefixOf(cr, cr1);
false = Expression.expHasCrefNoPreorDer(e1,cr);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,DAE.CALL(path=path,expLst=explst,attr=DAE.CALL_ATTR(ty= DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(path1)))),_,_,_,_,_,_)
equation
true = AbsynUtil.pathEqual(path,path1);
Expand All @@ -5325,7 +5326,7 @@ algorithm
true = expCrefLstHasCref(explst,cr1);
false = Expression.expHasCrefNoPreorDer(e2,cr1);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,_,DAE.CALL(path=path,expLst=explst,attr=DAE.CALL_ATTR(ty= DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(path1)))),_,_,_,_,_)
equation
true = AbsynUtil.pathEqual(path,path1);
Expand All @@ -5337,7 +5338,7 @@ algorithm
true = expCrefLstHasCref(explst,cr1);
false = Expression.expHasCrefNoPreorDer(e1,cr1);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,DAE.TUPLE(PR=explst),DAE.CALL(),_,_,_,_,_)
equation
rabs = intAbs(r);
Expand All @@ -5352,10 +5353,12 @@ algorithm
true = expCrefLstHasCref(crexplst,cr1);
false = Expression.expHasCrefNoPreorDer(e2,cr1);
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_SOLVED(),{})::inRow,trytosolve,size,shared);
case(r::rest,_,_,_,_,_,_,_)
// case: state derivative
equation
// ticket #6806, only allow inverting of function if the sizes match
1 = size;
// if not negated rowmark then linear or nonlinear
true = intGt(r,0);
false = intEq(rowmark[r],-mark);
Expand All @@ -5381,9 +5384,11 @@ algorithm
end if;
end if;
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,solvab,cons)::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,solvab,cons)::inRow,trytosolve,size,shared);
case(r::rest,_,_,_,_,_,_,_)
equation
// ticket #6806, only allow inverting of function if the sizes match
1 = size;
rabs = intAbs(r);
// if not negated rowmark then linear or nonlinear
false = intEq(rowmark[rabs],-mark);
Expand All @@ -5407,10 +5412,10 @@ algorithm
end if;
end if;
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,solvab,cons)::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,solvab,cons)::inRow,trytosolve,size,shared);
case(r::rest,_,_,_,_,_,_,_)
then
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_UNSOLVABLE(),{})::inRow,trytosolve,shared);
adjacencyRowEnhanced1(rest,e1,e2,vars,globalKnownVars,mark,rowmark,(r,BackendDAE.SOLVABILITY_UNSOLVABLE(),{})::inRow,trytosolve,size,shared);
end matchcontinue;
end adjacencyRowEnhanced1;

Expand Down

0 comments on commit 63d72ed

Please sign in to comment.