Skip to content

Commit

Permalink
- bugfix emtpy Replacements, check also derConst replacements
Browse files Browse the repository at this point in the history
- add for time independent states candidates derConst replacement

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14571 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Dec 29, 2012
1 parent cacb180 commit 0bff240
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
47 changes: 40 additions & 7 deletions Compiler/BackEnd/BackendVarTransform.mo
Expand Up @@ -791,11 +791,15 @@ end avoidDoubleHashLookup;
public function replacementEmpty
input VariableReplacements repl;
output Boolean empty;
protected
HashTable2.HashTable ht;
algorithm
REPLACEMENTS(hashTable = ht) := repl;
empty := intGt(BaseHashTable.hashTableCurrentSize(ht),0);
empty := match(repl)
local
HashTable2.HashTable ht,derConst;
case REPLACEMENTS(hashTable = ht,derConst=NONE())
then
intGt(BaseHashTable.hashTableCurrentSize(ht),0);
case REPLACEMENTS(derConst=SOME(_)) then false;
end match;
end replacementEmpty;

/*********************************************************/
Expand Down Expand Up @@ -1331,12 +1335,11 @@ public function replaceEquations
algorithm
(outEqns,replacementPerformed) := matchcontinue(inEqns,repl,inFuncTypeExpExpToBooleanOption)
local
HashTable2.HashTable ht;
list<BackendDAE.Equation> eqns;
case(_,REPLACEMENTS(hashTable = ht),_)
case(_,_,_)
equation
// Do not do empty replacements; it just takes time ;)
true = intGt(BaseHashTable.hashTableCurrentSize(ht),0);
false = replacementEmpty(repl);
(eqns,replacementPerformed) = replaceEquations2(inEqns,repl,inFuncTypeExpExpToBooleanOption,{},false);
then
(eqns,replacementPerformed);
Expand Down Expand Up @@ -2292,6 +2295,36 @@ algorithm
end match;
end dumpExtendReplacements;

public function dumpDerConstReplacements
"function: dumpReplacements
Prints the variable derConst replacements on form var1 -> exp"
input VariableReplacements inVariableReplacements;
algorithm
_:=
match (inVariableReplacements)
local
String str,len_str;
Integer len;
HashTable2.HashTable ht;
list<tuple<DAE.ComponentRef,DAE.Exp>> tplLst;
case (REPLACEMENTS(derConst= SOME(ht)))
equation
(tplLst) = BaseHashTable.hashTableList(ht);
str = stringDelimitList(List.map(tplLst,printReplacementTupleStr),"\n");
print("DerConstReplacements: (");
len = listLength(tplLst);
len_str = intString(len);
print(len_str);
print(")\n");
print("=============\n");
print(str);
print("\n");
then
();
else then ();
end match;
end dumpDerConstReplacements;

protected function printReplacementTupleStr "help function to dumpReplacements"
input tuple<DAE.ComponentRef,DAE.Exp> tpl;
output String str;
Expand Down
9 changes: 6 additions & 3 deletions Compiler/BackEnd/RemoveSimpleEquations.mo
Expand Up @@ -1706,7 +1706,7 @@ algorithm
DAE.ComponentRef pcr,cr;
EquationAttributes eqnAttributes;
DAE.ElementSource source;
Boolean negate,replacable,constExp;
Boolean negate,replacable,constExp,isState;
DAE.Exp exp,exp1,expcr;
BackendDAE.Variables vars;
list<BackendDAE.Equation> eqnslst;
Expand Down Expand Up @@ -1764,10 +1764,12 @@ algorithm
replacable = replaceableAlias(v,unreplacable);
// set fixed=true if replacable
v = Debug.bcallret2(replacable,BackendVariable.setVarFixed,v,true,v);
(vars,shared,_,eqnslst) = optMoveVarShared(replacable,v,i,eqnAttributes,exp,BackendVariable.addKnVarDAE,iMT,iVars,ishared,iEqnslst);
(vars,shared,isState,eqnslst) = optMoveVarShared(replacable,v,i,eqnAttributes,exp,BackendVariable.addKnVarDAE,iMT,iVars,ishared,iEqnslst);
constExp = Expression.isConst(exp);
// add to replacements if constant
repl = Debug.bcallret4(replacable and constExp, BackendVarTransform.addReplacement,iRepl, cr, exp,SOME(BackendVarTransform.skipPreChangeEdgeOperator),iRepl);
// if state der(var) has to replaced to 0
repl = Debug.bcallret3(isState,BackendVarTransform.addDerConstRepl, cr, DAE.RCONST(0.0), repl, repl);
exp = Expression.crefExp(cr);
vsattr = addVarSetAttributes(v,false,mark,simpleeqnsarr,EMPTYVARSETATTRIBUTES);
rows = List.removeOnTrue(r,intEq,iMT[i]);
Expand Down Expand Up @@ -2735,7 +2737,8 @@ algorithm
case (true,BackendDAE.DAE(systs,BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcTree,BackendDAE.EVENT_INFO(whenClauseLst,zeroCrossingLst,sampleLst,relationsLst,numberOfRealtions,numMathFunctions),eoc,btp,symjacs)),_)
equation
Debug.fcall(Flags.DUMP_REPL, BackendVarTransform.dumpReplacements, repl);
Debug.fcall(Flags.DUMP_REPL, BackendVarTransform.dumpExtendReplacements, repl);
Debug.fcall(Flags.DUMP_REPL, BackendVarTransform.dumpExtendReplacements, repl);
Debug.fcall(Flags.DUMP_REPL, BackendVarTransform.dumpDerConstReplacements, repl);
// replace moved vars in knvars,remeqns
(aliasVars,(_,varlst)) = BackendVariable.traverseBackendDAEVarsWithUpdate(aliasVars,replaceAliasVarTraverser,(repl,{}));
aliasVars = List.fold(varlst,fixAliasConstBindings,aliasVars);
Expand Down

0 comments on commit 0bff240

Please sign in to comment.