Skip to content

Commit 88687b0

Browse files
author
Jens Frenkel
committed
- bugfix for BackendDAEUtil.getAdjacencyMatrixEnhancedScalar in case of algorithms
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13219 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent ce39861 commit 88687b0

File tree

1 file changed

+126
-6
lines changed

1 file changed

+126
-6
lines changed

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 126 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5129,6 +5129,7 @@ algorithm
51295129
BackendDAE.AdjacencyMatrixElementEnhanced row;
51305130
list<list<BackendDAE.Equation>> eqnslst;
51315131
list<BackendDAE.Equation> eqns;
5132+
list<DAE.ComponentRef> algoutCrefs;
51325133

51335134
// EQUATION
51345135
case (vars,BackendDAE.EQUATION(exp = e1,scalar = e2),_,_,_,_)
@@ -5198,20 +5199,26 @@ algorithm
51985199
(row,size);
51995200

52005201
// ALGORITHM For now assume that algorithm will be solvable for
5201-
// correct variables. I.e. find all variables in algorithm and add to lst.
5202-
// If algorithm later on needs to be inverted, i.e. solved for
5203-
// different variables than calculated, a non linear solver or
5204-
// analysis of algorithm itself needs to be implemented.
5202+
// output variables. Mark this as solved and input variables as unsolvable:
52055203
case (vars,BackendDAE.ALGORITHM(size=size,alg=alg),_,_,_,_)
52065204
equation
5205+
// get outputs
5206+
algoutCrefs = CheckModel.algorithmOutputs(alg);
5207+
// mark outputs as solved
5208+
row = adjacencyRowAlgorithmOutputs(algoutCrefs,vars,mark,rowmark,{});
5209+
// get inputs
52075210
expl = Algorithm.getAllExps(alg);
5208-
lst = incidenceRow1(expl, adjacencyRowExpEnhanced, vars, {},(mark,rowmark));
5209-
row = adjacencyRowEnhanced1(lst,Expression.makeSum(expl),DAE.RCONST(0.0),vars,kvars,mark,rowmark,{});
5211+
// mark inputs as unsolvable
5212+
((_,(_,_,_,row))) = Expression.traverseExpList(expl, adjacencyRowAlgorithmInputs, (vars,mark,rowmark,row));
52105213
then
52115214
(row,size);
52125215

52135216
// if Equation
52145217
// TODO : how to handle this?
5218+
// Proposal:
5219+
// mark all vars in conditions as unsolvable
5220+
// vars occure in all branches: check how they are occure
5221+
// vars occure not in all branches: mark as unsolvable
52155222
case(vars,BackendDAE.IF_EQUATION(conditions=expl,eqnstrue=eqnslst,eqnsfalse=eqns),_,_,_,_)
52165223
equation
52175224
print("Warning: BackendDAEUtil.adjacencyRowEnhanced does not handle if-equations propper!\n");
@@ -5229,6 +5236,119 @@ algorithm
52295236
end matchcontinue;
52305237
end adjacencyRowEnhanced;
52315238

5239+
protected function adjacencyRowAlgorithmOutputs
5240+
"function: adjacencyRowAlgorithmOutputs
5241+
author: Frenkel TUD 10-2012
5242+
Helper function to adjacencyRowEnhanced. Mark all algorithm outputs
5243+
as solved."
5244+
input list<DAE.ComponentRef> algOutputs;
5245+
input BackendDAE.Variables inVariables;
5246+
input Integer mark;
5247+
input array<Integer> rowmark;
5248+
input BackendDAE.AdjacencyMatrixElementEnhanced iRow;
5249+
output BackendDAE.AdjacencyMatrixElementEnhanced outRow;
5250+
algorithm
5251+
outRow := matchcontinue(algOutputs,inVariables,mark,rowmark,iRow)
5252+
local
5253+
DAE.ComponentRef cr;
5254+
list<DAE.ComponentRef> rest;
5255+
list<Integer> vindx;
5256+
BackendDAE.AdjacencyMatrixElementEnhanced row;
5257+
case ({},_,_,_,_) then iRow;
5258+
case (cr::rest,_,_,_,_)
5259+
equation
5260+
(_,vindx) = BackendVariable.getVar(cr,inVariables);
5261+
row = adjacencyRowAlgorithmOutputs1(vindx,mark,rowmark,iRow);
5262+
then
5263+
adjacencyRowAlgorithmOutputs(rest,inVariables,mark,rowmark,row);
5264+
end matchcontinue;
5265+
end adjacencyRowAlgorithmOutputs;
5266+
5267+
protected function adjacencyRowAlgorithmOutputs1
5268+
"function: adjacencyRowAlgorithmOutputs
5269+
author: Frenkel TUD 10-2012
5270+
Helper function to adjacencyRowEnhanced. Mark all algorithm outputs
5271+
as solved."
5272+
input list<Integer> vindx;
5273+
input Integer mark;
5274+
input array<Integer> rowmark;
5275+
input BackendDAE.AdjacencyMatrixElementEnhanced iRow;
5276+
output BackendDAE.AdjacencyMatrixElementEnhanced outRow;
5277+
algorithm
5278+
outRow := matchcontinue(vindx,mark,rowmark,iRow)
5279+
local
5280+
Integer i;
5281+
list<Integer> rest;
5282+
case ({},_,_,_) then iRow;
5283+
case (i::rest,_,_,_)
5284+
equation
5285+
_ = arrayUpdate(rowmark,i,mark);
5286+
then
5287+
adjacencyRowAlgorithmOutputs1(rest,mark,rowmark,(i,BackendDAE.SOLVABILITY_SOLVED())::iRow);
5288+
end matchcontinue;
5289+
end adjacencyRowAlgorithmOutputs1;
5290+
5291+
protected function adjacencyRowAlgorithmInputs
5292+
"function: adjacencyRowAlgorithmInputs
5293+
author: Frenkel TUD 10-2012
5294+
Helper function to adjacencyRowEnhanced. Mark all algorithm inputs
5295+
as unsolvable."
5296+
input tuple<DAE.Exp,tuple<BackendDAE.Variables,Integer,array<Integer>,BackendDAE.AdjacencyMatrixElementEnhanced>> iTpl;
5297+
output tuple<DAE.Exp,tuple<BackendDAE.Variables,Integer,array<Integer>,BackendDAE.AdjacencyMatrixElementEnhanced>> oTpl;
5298+
algorithm
5299+
oTpl := matchcontinue(iTpl)
5300+
local
5301+
DAE.Exp e;
5302+
DAE.ComponentRef cr;
5303+
BackendDAE.Variables vars;
5304+
Integer mark;
5305+
array<Integer>rowmark;
5306+
BackendDAE.AdjacencyMatrixElementEnhanced row;
5307+
list<Integer> vindx;
5308+
case ((e as DAE.CREF(componentRef=cr),(vars,mark,rowmark,row)))
5309+
equation
5310+
(_,vindx) = BackendVariable.getVar(cr,vars);
5311+
row = adjacencyRowAlgorithmInputs1(vindx,mark,rowmark,row);
5312+
then
5313+
((e,(vars,mark,rowmark,row)));
5314+
else
5315+
then
5316+
iTpl;
5317+
end matchcontinue;
5318+
end adjacencyRowAlgorithmInputs;
5319+
5320+
protected function adjacencyRowAlgorithmInputs1
5321+
"function: adjacencyRowAlgorithmInputs1
5322+
author: Frenkel TUD 10-2012
5323+
Helper function to adjacencyRowEnhanced. Mark all algorithm inputs
5324+
as unsolvable."
5325+
input list<Integer> vindx;
5326+
input Integer mark;
5327+
input array<Integer> rowmark;
5328+
input BackendDAE.AdjacencyMatrixElementEnhanced iRow;
5329+
output BackendDAE.AdjacencyMatrixElementEnhanced outRow;
5330+
algorithm
5331+
outRow := matchcontinue(vindx,mark,rowmark,iRow)
5332+
local
5333+
Integer i;
5334+
list<Integer> rest;
5335+
case ({},_,_,_) then iRow;
5336+
case (i::rest,_,_,_)
5337+
equation
5338+
// not allready handled
5339+
false = intEq(intAbs(rowmark[i]),mark);
5340+
_ = arrayUpdate(rowmark,i,-mark);
5341+
then
5342+
adjacencyRowAlgorithmInputs1(rest,mark,rowmark,(i,BackendDAE.SOLVABILITY_UNSOLVABLE())::iRow);
5343+
case (i::rest,_,_,_)
5344+
equation
5345+
// not allready handled
5346+
true = intEq(intAbs(rowmark[i]),mark);
5347+
then
5348+
adjacencyRowAlgorithmInputs1(rest,mark,rowmark,iRow);
5349+
end matchcontinue;
5350+
end adjacencyRowAlgorithmInputs1;
5351+
52325352
protected function adjacencyRowWhenEnhanced
52335353
"function: adjacencyRowWhenEnhanced
52345354
author: Frenkel TUD

0 commit comments

Comments
 (0)