Skip to content

Commit

Permalink
- keep dimension information of derived variable but check when sorti…
Browse files Browse the repository at this point in the history
…ng if all elements are derived.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13517 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Oct 19, 2012
1 parent cb3e316 commit e3b0c69
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -3501,7 +3501,7 @@ algorithm
((BackendDAE.VAR(cr,BackendDAE.STATE(),a,prl,b,c,d,lstSubs,source,dae_var_attr,comment,ct) :: _),_) = BackendVariable.getVar(cr, vars) "der(der(s)) s is state => der_der_s" ;
dummyder = ComponentReference.crefPrefixDer(cr);
dummyder = ComponentReference.crefPrefixDer(dummyder);
vars_1 = BackendVariable.addVar(BackendDAE.VAR(dummyder, BackendDAE.DUMMY_DER(), a, prl, b, NONE(), NONE(), {}, source, NONE(), comment, ct), vars);
vars_1 = BackendVariable.addVar(BackendDAE.VAR(dummyder, BackendDAE.DUMMY_DER(), a, prl, b, NONE(), NONE(), lstSubs, source, NONE(), comment, ct), vars);
e = Expression.makeCrefExp(dummyder,DAE.T_REAL_DEFAULT);
then
((e, (vars_1,i+1)));
Expand All @@ -3510,7 +3510,7 @@ algorithm
equation
((BackendDAE.VAR(cr,BackendDAE.DUMMY_DER(),a,prl,b,c,d,lstSubs,source,dae_var_attr,comment,ct) :: _),_) = BackendVariable.getVar(cr, vars) "der(der_s)) der_s is dummy var => der_der_s" ;
dummyder = ComponentReference.crefPrefixDer(cr);
vars_1 = BackendVariable.addVar(BackendDAE.VAR(dummyder, BackendDAE.DUMMY_DER(), a, prl, b, NONE(), NONE(), {}, source, NONE(), comment, ct), vars);
vars_1 = BackendVariable.addVar(BackendDAE.VAR(dummyder, BackendDAE.DUMMY_DER(), a, prl, b, NONE(), NONE(), lstSubs, source, NONE(), comment, ct), vars);
e = Expression.makeCrefExp(dummyder,DAE.T_REAL_DEFAULT);
then
((e, (vars_1,i+1)));
Expand All @@ -3519,7 +3519,7 @@ algorithm
equation
((BackendDAE.VAR(cr,BackendDAE.VARIABLE(),a,prl,b,c,d,lstSubs,source,dae_var_attr,comment,ct) :: _),_) = BackendVariable.getVar(cr, vars) "der(v) v is alg var => der_v" ;
dummyder = ComponentReference.crefPrefixDer(cr);
vars_1 = BackendVariable.addVar(BackendDAE.VAR(dummyder, BackendDAE.DUMMY_DER(), a, prl, b, NONE(), NONE(), {}, source, NONE(), comment, ct), vars);
vars_1 = BackendVariable.addVar(BackendDAE.VAR(dummyder, BackendDAE.DUMMY_DER(), a, prl, b, NONE(), NONE(), lstSubs, source, NONE(), comment, ct), vars);
e = Expression.makeCrefExp(dummyder,DAE.T_REAL_DEFAULT);
then
((e, (vars_1,i+1)));
Expand Down
22 changes: 18 additions & 4 deletions Compiler/BackEnd/IndexReduction.mo
Expand Up @@ -2117,6 +2117,11 @@ algorithm
array<Integer> select;
list<tuple<DAE.Exp,list<Integer>>> determinants;
Integer hack;

BackendDAE.EqSystem subsyst;
BackendDAE.IncidenceMatrix m;
BackendDAE.IncidenceMatrix mt;

case(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)
equation
true = intEq(listLength(dstates),eqnsSize);
Expand Down Expand Up @@ -2193,10 +2198,15 @@ algorithm
Debug.fcall(Flags.BLT_DUMP, BackendDump.debugStrIntStrIntStr, ("Select ",rang," from ",listLength(states),"\n"));
Debug.fcall(Flags.BLT_DUMP, BackendDump.debuglst,((states,BackendDAETransform.dumpStates,"\n","\n")));
Debug.fcall(Flags.BLT_DUMP, print, ("Select as dummyStates:\n"));
Debug.fcall(Flags.BLT_DUMP, BackendDump.debuglst,((dstates,BackendDAETransform.dumpStates,"\n","\n")));
Debug.fcall(Flags.BLT_DUMP, BackendDump.debuglst,((dstates,BackendDAETransform.dumpStates,"\n","\n")));

//subsyst = BackendDAE.EQSYSTEM(vars,eqns,NONE(),NONE(),BackendDAE.NO_MATCHING());
//(subsyst,m,mt,_,_) = BackendDAEUtil.getIncidenceMatrixScalar(subsyst, BackendDAE.NORMAL());
// dumpSystemGraphML(subsyst,ishared,NONE(),"System" +& intString(unassignedEqnsSize) +& ".graphml");

// get jacobian for all variables
SOME(jac) = BackendDAEUtil.calculateJacobianEnhanced(vars, eqns, me, true, ishared);
//print("Jac: " +& BackendDump.dumpJacobianStr(SOME(jac)) +& "\n");
//print("Jac: " +& BackendDump.dumpJacobianStr(SOME(jac)) +& "\n");
// get for each state the determinant of the jacobian [state,dummystates]
digraph = arrayCreate(eqnsSize,{});
select = arrayCreate(varSize,-1);
Expand Down Expand Up @@ -3742,7 +3752,7 @@ algorithm
//dummyder = ComponentReference.crefPrefixDer(cr);
dummyder = ComponentReference.makeCrefQual("$_DER",DAE.T_REAL_DEFAULT,{},cr);
(eqns_1,so1) = addDummyStateEqn(vars,eqns,cr,dummyder,so,i,eindx,mapIncRowEqn,mt);
vars_1 = BackendVariable.addVar(BackendDAE.VAR(dummyder, BackendDAE.STATE(), a, prl, b, NONE(), NONE(), {}, source, SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),NONE(),NONE(),NONE(),SOME(DAE.NEVER()),NONE(),NONE(),NONE(),NONE(),NONE(),NONE())), comment, ct), vars);
vars_1 = BackendVariable.addVar(BackendDAE.VAR(dummyder, BackendDAE.STATE(), a, prl, b, NONE(), NONE(), lstSubs, source, SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),NONE(),NONE(),NONE(),SOME(DAE.NEVER()),NONE(),NONE(),NONE(),NONE(),NONE(),NONE())), comment, ct), vars);
e = Expression.makeCrefExp(dummyder,DAE.T_REAL_DEFAULT);
then
((DAE.CALL(Absyn.IDENT("der"),{e},DAE.callAttrBuiltinReal), (vars_1,eqns_1,so1,i::ilst,eindx,mapIncRowEqn,mt)));
Expand Down Expand Up @@ -3934,6 +3944,8 @@ algorithm
GraphML.Graph g;
DAE.ComponentRef cr;
Integer id;
Boolean b;
String color;
case ((v as BackendDAE.VAR(varName=cr),(id,g)))
equation
true = BackendVariable.isStateVar(v);
Expand All @@ -3943,9 +3955,11 @@ algorithm
then ((v,(id+1,g)));
case ((v as BackendDAE.VAR(varName=cr),(id,g)))
equation
b = BackendVariable.isVarDiscrete(v);
color = Util.if_(b,GraphML.COLOR_PURPLE,GraphML.COLOR_RED);
//g = GraphML.addNode("v" +& intString(id),ComponentReference.printComponentRefStr(cr),GraphML.COLOR_RED,GraphML.ELLIPSE(),g);
//g = GraphML.addNode("v" +& intString(id),intString(id),GraphML.COLOR_RED,GraphML.ELLIPSE(),g);
g = GraphML.addNode("v" +& intString(id),intString(id) +& ": " +&ComponentReference.printComponentRefStr(cr),GraphML.COLOR_RED,GraphML.ELLIPSE(),g);
g = GraphML.addNode("v" +& intString(id),intString(id) +& ": " +&ComponentReference.printComponentRefStr(cr),color,GraphML.ELLIPSE(),g);
then ((v,(id+1,g)));
case _ then inTpl;
end matchcontinue;
Expand Down
8 changes: 6 additions & 2 deletions Compiler/BackEnd/SimCodeUtil.mo
Expand Up @@ -7328,7 +7328,7 @@ algorithm
array<Option<SimCode.SimVar>> vararray;
DAE.ComponentRef cr;
DAE.Type tp;
Integer size;
Integer size,listsize;
DAE.Dimensions dims;
list<Integer> dimsint;

Expand All @@ -7340,6 +7340,9 @@ algorithm
tp = ComponentReference.crefLastType(cr);
// get size of last type
size = Expression.sizeOf(tp);
listsize = listLength(varlst);
// only sort if all vars there
true = intEq(size,listsize);
// alloc the array
vararray = arrayCreate(size,NONE());
// insert vars in array
Expand All @@ -7355,7 +7358,8 @@ algorithm
SimCode.SIMVAR(name=cr)::_ = varlst;
crstr = ComponentReference.printComponentRefStr(cr);
Debug.fprintln(Flags.FAILTRACE, "SimCodeUtil.sortArrayVars failed on " +& crstr +& "\n");
sortedVars = List.sort(varlst,comparingArrayVarsIndexes);
//sortedVars = List.sort(varlst,comparingArrayVarsIndexes);
sortedVars = varlst;
sortedVars = listAppend(sortedVars,iVars);
then
sortedVars;
Expand Down

0 comments on commit e3b0c69

Please sign in to comment.