Skip to content

Commit

Permalink
- continue with division by zero implementation
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5048 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Feb 25, 2010
1 parent ed8745e commit e8c9c98
Showing 1 changed file with 74 additions and 8 deletions.
82 changes: 74 additions & 8 deletions Compiler/DAELow.mo
Expand Up @@ -416,6 +416,7 @@ protected import SimCodegen;
protected import System;
protected import Util;
protected import VarTransform;
protected import ValuesUtil;

protected constant BinTree emptyBintree=TREENODE(NONE,NONE,NONE) " Empty binary tree " ;

Expand Down Expand Up @@ -15455,6 +15456,17 @@ algorithm
end matchcontinue;
end daeVars;

public function daeKnVars
input DAELow inDAELow;
output Variables vars;
algorithm
vars := matchcontinue (inDAELow)
local Variables vars1,vars2;
case (DAELOW(orderedVars = vars1, knownVars = vars2))
then vars2;
end matchcontinue;
end daeKnVars;

public function makeExpType
"Transforms a Type to DAE.ExpType
"
Expand Down Expand Up @@ -16374,8 +16386,7 @@ algorithm
DAE.Exp exp;
list<DAE.Exp> explst;
DAE.ComponentRef cr;
list<Var> vars;
Variables variables;
Values.Value val;
// const expressions
case(exp,indlow)
equation
Expand All @@ -16385,10 +16396,16 @@ algorithm
// ComponentRef expressions
case(exp as DAE.CREF(componentRef=cr),indlow)
equation
variables = daeVars(indlow);
(vars,_) = getVar(cr,variables);
val = evalVariable(cr,indlow,{});
true = ValuesUtil.isZero(val);
then
(false,false);
(true,true);
case(exp,indlow)
equation
val = evalExpression(exp,indlow,{});
true = ValuesUtil.isZero(val);
then
(true,true);
case(exp,indlow)
then
(false,false);
Expand Down Expand Up @@ -16431,15 +16448,16 @@ algorithm
DAE.ComponentRef cr;
list<Var> vars;
Variables variables;
String se,seqn;
String se,se1,seqn;
case((_,{}),indlow) then indlow;
/* error */
case((eqn,exp::explst),indlow)
equation
(true,true) = checkExpBecomesZero(exp,indlow);
seqn = equationStr(eqn);
se = "";
Error.addMessage(Error.DIVISION_BY_ZERO, {seqn,se});
se = Exp.printExpStr(exp);
se1 = stringAppend(se, " = 0");
Error.addMessage(Error.DIVISION_BY_ZERO, {seqn,se1});
outdlow = checkEquationBecomesZero((eqn,explst),indlow);
then
outdlow;
Expand Down Expand Up @@ -16557,4 +16575,52 @@ algorithm
end matchcontinue;
end extractDivExpFromWhenEquation;

public function evalVariable
"function evalVariable
Evaluate the value of a variable."
input DAE.ComponentRef inCref;
input DAELow indlow;
input list<DAE.ComponentRef> inCrefLst;
output Values.Value outVal;
algorithm
outVal:=
matchcontinue (inCref,indlow,inCrefLst)
local
Variables vars;
Var var;
Option<Values.Value> bindValueo;
Values.Value bindValue;
case (inCref,indlow,inCrefLst)
equation
vars = daeVars(indlow);
({var as VAR(bindValue=bindValueo)},_) = getVar(inCref,vars);
SOME(bindValue) = bindValueo;
then
bindValue;
case (inCref,indlow,inCrefLst)
equation
vars = daeKnVars(indlow);
({var as VAR(bindValue=bindValueo)},_) = getVar(inCref,vars);
SOME(bindValue) = bindValueo;
then
bindValue;
end matchcontinue;
end evalVariable;

public function evalExpression
"function evalExpression
Evaluate the value of a expression."
input DAE.Exp inExp;
input DAELow indlow;
input list<DAE.ComponentRef> inCrefLst;
output Values.Value outVal;
algorithm
outVal:=
matchcontinue (inExp,indlow,inCrefLst)
case (inExp,indlow,inCrefLst)
then
Values.REAL(1.0);
end matchcontinue;
end evalExpression;

end DAELow;

0 comments on commit e8c9c98

Please sign in to comment.