Skip to content

Commit

Permalink
- improve initialization approach for over-determined systems
Browse files Browse the repository at this point in the history
- add some test cases for over-determined systems


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21081 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Jun 12, 2014
1 parent fa64728 commit 9929864
Show file tree
Hide file tree
Showing 3 changed files with 748 additions and 225 deletions.
3 changes: 3 additions & 0 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -739,16 +739,19 @@ algorithm
Option< .DAE.VariableAttributes> values;
DAE.Exp exp,exp1;
Values.Value bindValue;

case ((v as BackendDAE.VAR(varName=varName,varKind=BackendDAE.PARAM(),bindExp=SOME(exp)),(repl,vars)))
equation
((exp1, _)) = Expression.traverseExp(exp, BackendDAEUtil.replaceCrefsWithValues, (vars, varName));
repl_1 = BackendVarTransform.addReplacement(repl, varName, exp1,NONE());
then ((v,(repl_1,vars)));

case ((v as BackendDAE.VAR(varName=varName,varKind=BackendDAE.PARAM(),bindValue=SOME(bindValue)),(repl,vars)))
equation
exp = ValuesUtil.valueExp(bindValue);
repl_1 = BackendVarTransform.addReplacement(repl, varName, exp,NONE());
then ((v,(repl_1,vars)));

case _ then inTpl;
end matchcontinue;
end removeParametersFinder;
Expand Down
76 changes: 76 additions & 0 deletions Compiler/BackEnd/BackendVarTransform.mo
Expand Up @@ -2522,6 +2522,82 @@ algorithm
end matchcontinue;
end replaceSTMT_IF;

/*********************************************************/
/* divide by zero */
/*********************************************************/

public function divideByZeroReplacements
input VariableReplacements inVariableReplacements;
output Boolean divideByZero;
output Integer pos;
output DAE.Ident ident;
protected
HashTable2.HashTable ht;
list<tuple<DAE.ComponentRef, DAE.Exp>> tplLst;
algorithm
REPLACEMENTS(hashTable=ht) := inVariableReplacements;
(tplLst) := BaseHashTable.hashTableList(ht);
(divideByZero, pos, ident) := divideByZeroReplacements2(tplLst, 1, false, 0, "???");
end divideByZeroReplacements;

protected function divideByZeroReplacements2
input list<tuple<DAE.ComponentRef, DAE.Exp>> tplLst;
input Integer counter;
input Boolean InDivideByZero;
input Integer InPos;
input DAE.Ident InIdent;
output Boolean divideByZero;
output Integer pos;
output DAE.Ident ident;
algorithm
(divideByZero, pos, ident) := matchcontinue (tplLst, counter, InDivideByZero, InPos, InIdent)
local
list<tuple<DAE.ComponentRef, DAE.Exp>> tplLst2;
DAE.Exp exp;
Boolean BooleanControlExp;
String str;
DAE.ComponentRef cr;

case({}, _, _, _, _)
then (InDivideByZero, 0, InIdent);

case ((cr, exp) :: tplLst2, _, false, _, _) equation
((_, BooleanControlExp)) = Expression.traverseExp(exp, controlExp, false);
false = BooleanControlExp;

str = ComponentReference.printComponentRefStr(cr);

(divideByZero, pos, ident) = divideByZeroReplacements2(tplLst2, counter+1, BooleanControlExp, counter, str);
then (divideByZero, pos, ident);

case((cr, exp) :: tplLst2, _, _, _, _) equation
str = ComponentReference.printComponentRefStr(cr);
then (true, counter, str);
end matchcontinue;
end divideByZeroReplacements2;

protected function controlExp
input tuple<DAE.Exp, Boolean > inTuple;
output tuple<DAE.Exp, Boolean > outTuple;
algorithm
outTuple := matchcontinue(inTuple)
local
DAE.Exp exp1 , exp2, exp3;
DAE.Operator operator;
Boolean b;

case ((_, true))
then inTuple;

case((exp3 as DAE.BINARY(exp1, DAE.DIV(_), exp2), false)) equation
b = Expression.isZero(exp2);
then((exp3, b));

case ((exp1, _))
then ((exp1, false));
end matchcontinue;
end controlExp;

/*********************************************************/
/* dump replacements */
/*********************************************************/
Expand Down

0 comments on commit 9929864

Please sign in to comment.