Skip to content

Commit

Permalink
- partial support for Media Models
Browse files Browse the repository at this point in the history
- Matching.c: do not generate transposet incidence madrix if not necessary
- move some Media Models to working group

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13997 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Nov 20, 2012
1 parent 9b48df5 commit 1f66755
Show file tree
Hide file tree
Showing 7 changed files with 482 additions and 148 deletions.
133 changes: 30 additions & 103 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -4230,70 +4230,47 @@ end incidenceRowExp1withInput;

public function transposeMatrix
"function: transposeMatrix
author: PA
author: Frenkel TUD 2012-11
Calculates the transpose of the incidence matrix,
i.e. which equations each variable is present in."
input BackendDAE.IncidenceMatrix m;
input Integer nRowsMt;
output BackendDAE.IncidenceMatrixT mt;
protected
list<list<Integer>> mlst,mtlst;
algorithm
mlst := arrayList(m);
mtlst := transposeMatrix2(mlst);
mt := listArray(mtlst);
mt := arrayCreate(nRowsMt,{});
((mt,_)) := Util.arrayFold(m,transposeRow,(mt,1));
end transposeMatrix;

protected function transposeMatrix2
"function: transposeMatrix2
author: PA
Helper function to transposeMatrix"
input list<list<Integer>> inIntegerLstLst;
output list<list<Integer>> outIntegerLstLst;
algorithm
outIntegerLstLst := matchcontinue (inIntegerLstLst)
local
Integer neq;
list<list<Integer>> mt,m;
case (m)
equation
neq = listLength(m);
mt = transposeMatrix3(m, neq, 0, {});
then
mt;
case (_)
equation
print("- BackendDAEUtil.transposeMatrix2 failed\n");
then
fail();
end matchcontinue;
end transposeMatrix2;

protected function transposeMatrix3
"function: transposeMatrix3
protected function transposeRow
"function: transposeRow
author: PA
Helper function to transposeMatrix2"
input list<list<Integer>> inIntegerLstLst1;
input Integer inInteger2;
input Integer inInteger3;
input list<list<Integer>> inIntegerLstLst4;
output list<list<Integer>> outIntegerLstLst;
Helper function to transposeMatrix2.
Input: BackendDAE.IncidenceMatrix (eqn => var)
Input: row number (variable)
Input: iterator (start with one)
inputs: (int list list, int /* row */,int /* iter */)
outputs: int list"
input list<Integer> row;
input tuple<BackendDAE.IncidenceMatrixT,Integer> inTpl "(m,index)";
output tuple<BackendDAE.IncidenceMatrixT,Integer> outTpl;
algorithm
outIntegerLstLst := matchcontinue (inIntegerLstLst1,inInteger2,inInteger3,inIntegerLstLst4)
outTpl := match (row,inTpl)
local
Integer neq_1,eqno_1,neq,eqno;
list<list<Integer>> mt_1,m,mt;
list<Integer> row;
case (_,0,_,_) then {};
case (m,neq,eqno,mt)
Integer i,indx,indx1,iabs;
list<Integer> res,col;
BackendDAE.IncidenceMatrixT mt;
case ({},(mt,indx)) then ((mt,indx+1));
case (i::res,(mt,indx))
equation
neq_1 = neq - 1;
eqno_1 = eqno + 1;
mt_1 = transposeMatrix3(m, neq_1, eqno_1, mt);
row = transposeRow(m, eqno_1, 1);
iabs = intAbs(i);
mt = Util.arrayExpand(iabs - arrayLength(mt),mt,{});
col = mt[iabs];
indx1 = Util.if_(intLt(i,0),-indx,indx);
_ = arrayUpdate(mt,iabs,indx1::col);
then
(row :: mt_1);
end matchcontinue;
end transposeMatrix3;
transposeRow(res, (mt,indx));
end match;
end transposeRow;

public function absIncidenceMatrix
"function absIncidenceMatrix
Expand Down Expand Up @@ -4322,56 +4299,6 @@ algorithm
res := List.flatten(mlst);
end varsIncidenceMatrix;

protected function transposeRow
"function: transposeRow
author: PA
Helper function to transposeMatrix2.
Input: BackendDAE.IncidenceMatrix (eqn => var)
Input: row number (variable)
Input: iterator (start with one)
inputs: (int list list, int /* row */,int /* iter */)
outputs: int list"
input list<list<Integer>> inIntegerLstLst1;
input Integer inInteger2;
input Integer inInteger3;
output list<Integer> outIntegerLst;
algorithm
outIntegerLst := matchcontinue (inIntegerLstLst1,inInteger2,inInteger3)
local
Integer eqn_1,varno,eqn,varno_1,eqnneg;
list<Integer> res,m;
list<list<Integer>> ms;
case ({},_,_) then {};
case ((m :: ms),varno,eqn)
equation
true = listMember(varno, m);
eqn_1 = eqn + 1;
res = transposeRow(ms, varno, eqn_1);
then
(eqn :: res);
case ((m :: ms),varno,eqn)
equation
varno_1 = 0 - varno "Negative index present, state variable. list_member(varno,m) => false &" ;
true = listMember(varno_1, m);
eqnneg = 0 - eqn;
eqn_1 = eqn + 1;
res = transposeRow(ms, varno, eqn_1);
then
(eqnneg :: res);
case ((m :: ms),varno,eqn)
equation
eqn_1 = eqn + 1 "not present at all" ;
res = transposeRow(ms, varno, eqn_1);
then
res;
case (_,_,_)
equation
print("- BackendDAEUtil.transposeRow failed\n");
then
fail();
end matchcontinue;
end transposeRow;

public function updateIncidenceMatrix
"function: updateIncidenceMatrix
author: PA
Expand Down Expand Up @@ -4765,7 +4692,7 @@ algorithm
(BackendDAE.EQSYSTEM(v,eq,SOME(m),SOME(mT),matching),m,mT);
case(BackendDAE.EQSYSTEM(v,eq,SOME(m),NONE(),matching),_)
equation
mT = transposeMatrix(m);
mT = transposeMatrix(m,BackendVariable.varsSize(v));
then
(BackendDAE.EQSYSTEM(v,eq,SOME(m),SOME(mT),matching),m,mT);
case(BackendDAE.EQSYSTEM(v,eq,SOME(m),SOME(mT),matching),_)
Expand Down
14 changes: 10 additions & 4 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -4245,11 +4245,17 @@ public function varStateSelectPrioAlias
DAE.StateSelect ss;
algorithm
ss := varStateSelect(v);
prio := varStateSelectPrioAlias2(ss);
prio := stateSelectToInteger(ss);
end varStateSelectPrioAlias;

protected function varStateSelectPrioAlias2
"helper function to varStateSelectPrioAlias"
public function stateSelectToInteger
"helper function to stateSelectToInteger
return
Never: -1
Avoid: 0
Default: 1
Prefer: 2
Always: 3"
input DAE.StateSelect ss;
output Integer prio;
algorithm
Expand All @@ -4260,6 +4266,6 @@ algorithm
case (DAE.PREFER()) then 2;
case (DAE.ALWAYS()) then 3;
end match;
end varStateSelectPrioAlias2;
end stateSelectToInteger;

end BackendVariable;

0 comments on commit 1f66755

Please sign in to comment.