Skip to content

Commit

Permalink
[BE] fix algorithm incidenceRow
Browse files Browse the repository at this point in the history
 - remove try catch and update discrete output var detection
 - add testcase for ticket #5659
  • Loading branch information
kabdelhak authored and adrpo committed Oct 21, 2019
1 parent 6bb7192 commit 2705ebe
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 18 deletions.
36 changes: 18 additions & 18 deletions OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -2638,16 +2638,16 @@ algorithm
Discrete output variables that do not occur get computed by pre().
Ticket #5659
*/
if indexTypeSovable(inIndexType) then
try
crefLst := CheckModel.algorithmStatementListOutputs(statementLst, DAE.EXPAND()); // expand as we're in an algorithm
for cr in crefLst loop
if indexTypeSolvable(inIndexType) then
crefLst := CheckModel.algorithmStatementListOutputs(statementLst, DAE.EXPAND()); // expand as we're in an algorithm
for cr in crefLst loop
try
(varslst, p) := BackendVariable.getVar(cr, vars);
res := incidenceRowExp1Discrete(varslst,p,res,0);
end for;
else
/* ... */
end try;
res := incidenceRowExp1Discrete(varslst, p, res);
else
/* Nothing to do, BackendVariable.getVar fails for $START, $PRE, time etc. */
end try;
end for;
end if;
then
(res,size);
Expand Down Expand Up @@ -3258,21 +3258,21 @@ protected function incidenceRowExp1Discrete
input list<BackendDAE.Var> inVarLst;
input list<Integer> inIntegerLst;
input AvlSetInt.Tree inVarIndxLst;
input Integer diffindex;
output AvlSetInt.Tree outVarIndxLst;
algorithm
outVarIndxLst := match (inVarLst,inIntegerLst,inVarIndxLst,diffindex)
outVarIndxLst := match (inVarLst,inIntegerLst)
local
list<BackendDAE.Var> rest;
list<Integer> irest;
AvlSetInt.Tree vars;
Integer i,i1,diffidx;
Boolean b;
case ({},{},vars,_) then vars;
case (BackendDAE.VAR(varKind = BackendDAE.DISCRETE())::rest,i::irest,_,_)
Integer i;
case ({}, {}) then inVarIndxLst;
case (BackendDAE.VAR(varKind = BackendDAE.DISCRETE())::rest, i::irest)
equation
vars = AvlSetInt.add(inVarIndxLst, i);
then incidenceRowExp1Discrete(rest,irest,vars,diffindex);
then incidenceRowExp1Discrete(rest,irest,vars);
case (_::rest, _::irest)
then incidenceRowExp1Discrete(rest,irest,inVarIndxLst);
end match;
end incidenceRowExp1Discrete;

Expand Down Expand Up @@ -9958,15 +9958,15 @@ algorithm
end match;
end containsHomotopyCall2;

protected function indexTypeSovable
protected function indexTypeSolvable
input BackendDAE.IndexType indexType;
output Boolean b;
algorithm
b := match indexType
case BackendDAE.SOLVABLE() then true;
else false;
end match;
end indexTypeSovable;
end indexTypeSolvable;

annotation(__OpenModelica_Interface="backend");
end BackendDAEUtil;
Expand Up @@ -15,6 +15,7 @@ bug_2271.mos \
bug_2286.mos \
bug_2286_literal.mos \
bug2888.mos \
bug_5659.mos \
ComplexSystem.mos \
DoubleWhenSequential.mos \
ForIterator1.mos \
Expand Down
37 changes: 37 additions & 0 deletions testsuite/simulation/modelica/algorithms_functions/bug_5659.mos
@@ -0,0 +1,37 @@
// name: bug_5659
// keywords:
// status: correct
// teardown_command: rm -rf bug_5659_* _bug_5659_* output.log
//
// tests for counting of algorithm section output variables involving
// arrays and records combined.
//

loadString("
/*slightly altered ticket model.
https://trac.openmodelica.org/OpenModelica/ticket/5659
*/
model bug_5659
discrete Real x;
discrete Real[2] data;
Real y;
algorithm
x := 1;
when sample(0, 0.1) then
data[1] := time;
end when;
y := cos(time);
end bug_5659;
"); getErrorString();

// bug_5659 has 4 equation(s) and 4 variable(s)
checkModel(bug_5659); getErrorString();

// Result:
// true
// ""
// "Check of bug_5659 completed successfully.
// Class bug_5659 has 4 equation(s) and 4 variable(s).
// 0 of these are trivial equation(s)."
// ""
// endResult

0 comments on commit 2705ebe

Please sign in to comment.