Skip to content

Commit

Permalink
BackendEquation.solveEquation:
Browse files Browse the repository at this point in the history
- passed DAE.FunctionTree
- inline function calls 


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23654 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Vitalij Ruge committed Dec 3, 2014
1 parent d9c07f2 commit f28fb27
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
25 changes: 13 additions & 12 deletions Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -2124,9 +2124,10 @@ public function solveEquation "author: wbraun
Algorithm, when and if-equation are left as they are."
input BackendDAE.Equation eqn;
input DAE.Exp crefExp;
input Option<DAE.FunctionTree> functions;
output BackendDAE.Equation outEqn;
algorithm
outEqn := matchcontinue (eqn, crefExp)
outEqn := matchcontinue (eqn, crefExp, functions)
local
DAE.Exp e1, e2;
DAE.Exp res;
Expand All @@ -2136,33 +2137,33 @@ algorithm
DAE.ElementSource source;
BackendDAE.EquationAttributes eqAttr;

case (BackendDAE.EQUATION(exp=e1, scalar=e2, source=source, attr=eqAttr), _) equation
(res, _) = ExpressionSolve.solve(e1, e2, crefExp);
case (BackendDAE.EQUATION(exp=e1, scalar=e2, source=source, attr=eqAttr), _, _) equation
(res, _) = ExpressionSolve.solve2(e1, e2, crefExp, functions);
then (BackendDAE.EQUATION(crefExp, res, source, eqAttr));

case (BackendDAE.ARRAY_EQUATION(left=e1, right=e2, source=source, attr=eqAttr), _) equation
(res, _) = ExpressionSolve.solve(e1, e2, crefExp);
case (BackendDAE.ARRAY_EQUATION(left=e1, right=e2, source=source, attr=eqAttr), _, _) equation
(res, _) = ExpressionSolve.solve2(e1, e2, crefExp, functions);
then (BackendDAE.EQUATION(crefExp, res, source, eqAttr));

case (BackendDAE.SOLVED_EQUATION(componentRef=cref, exp=e2, source=source, attr=eqAttr), _) equation
case (BackendDAE.SOLVED_EQUATION(componentRef=cref, exp=e2, source=source, attr=eqAttr), _,_) equation
cr = Expression.expCref(crefExp);
true = ComponentReference.crefEqual(cref, cr);
then (BackendDAE.EQUATION(crefExp, e2, source, eqAttr));

case (BackendDAE.SOLVED_EQUATION(componentRef=cref, exp=e2, source=source, attr=eqAttr), _) equation
case (BackendDAE.SOLVED_EQUATION(componentRef=cref, exp=e2, source=source, attr=eqAttr), _, _) equation
cr = Expression.expCref(crefExp);
false = ComponentReference.crefEqual(cref, cr);
e1 = Expression.crefExp(cref);
(res, _) = ExpressionSolve.solve(e1, e2, crefExp);
(res, _) = ExpressionSolve.solve2(e1, e2, crefExp, functions);
then (BackendDAE.EQUATION(crefExp, res, source, eqAttr));

case (BackendDAE.RESIDUAL_EQUATION(exp=e2, source=source, attr=eqAttr), _) equation
case (BackendDAE.RESIDUAL_EQUATION(exp=e2, source=source, attr=eqAttr), _, _) equation
e1 = Expression.makeConstZero(Expression.typeof(e2));
(res, _) = ExpressionSolve.solve(e2, e1, crefExp);
(res, _) = ExpressionSolve.solve2(e2, e1, crefExp, functions);
then (BackendDAE.EQUATION(crefExp, res, source, eqAttr));

case (BackendDAE.COMPLEX_EQUATION(left=e1, right=e2, source=source, attr=eqAttr), _) equation
(res, _) = ExpressionSolve.solve(e1, e2, crefExp);
case (BackendDAE.COMPLEX_EQUATION(left=e1, right=e2, source=source, attr=eqAttr), _, _) equation
(res, _) = ExpressionSolve.solve2(e1, e2, crefExp, functions);
then (BackendDAE.EQUATION(crefExp, res, source, eqAttr));
/*
case (eq as BackendDAE.ALGORITHM(alg=_), _)
Expand Down
11 changes: 7 additions & 4 deletions Compiler/BackEnd/Initialization.mo
Expand Up @@ -1499,7 +1499,7 @@ algorithm
//BackendDump.dumpList(markedComps, "markedComps: ");

repl = BackendVarTransform.emptyReplacements();
repl = setupVarReplacements(markedComps, inEqns, inVars, vecEqsToVar, repl, mapIncRowEqn, me);
repl = setupVarReplacements(markedComps, inEqns, inVars, vecEqsToVar, repl, mapIncRowEqn, me, inShared);
//BackendVarTransform.dumpReplacements(repl);
substEqns = applyVarReplacements(redundantEqn, inEqns, repl);

Expand Down Expand Up @@ -1698,6 +1698,7 @@ protected function setupVarReplacements
input BackendVarTransform.VariableReplacements inRepls "initially call this with empty replacements";
input array<Integer> inMapIncRowEqn;
input BackendDAE.AdjacencyMatrixEnhanced inME;
input BackendDAE.Shared inShared;
output BackendVarTransform.VariableReplacements outRepls;
algorithm
outRepls := matchcontinue (inMarkedEqns, inEqns, inVars, inVecEqToVar, inRepls, inMapIncRowEqn, inME)
Expand All @@ -1712,6 +1713,7 @@ algorithm
DAE.ComponentRef cref;
BackendDAE.Type type_;
DAE.Exp exp, exp1, x;
DAE.FunctionTree funcs;

case ({}, _, _, _, _, _, _)
then inRepls;
Expand All @@ -1727,16 +1729,17 @@ algorithm
cref = BackendVariable.varCref(var);
type_ = BackendVariable.varType(var);
x = DAE.CREF(cref, type_);
(eqn as BackendDAE.EQUATION(scalar=exp)) = BackendEquation.solveEquation(eqn, x);
BackendDAE.SHARED(functionTree = funcs) = inShared;
(eqn as BackendDAE.EQUATION(scalar=exp)) = BackendEquation.solveEquation(eqn, x, SOME(funcs));

varName = BackendVariable.varCref(var);
(exp1, _) = Expression.traverseExp(exp, BackendDAEUtil.replaceCrefsWithValues, (inVars, varName));
repls = BackendVarTransform.addReplacement(inRepls, varName, exp1, NONE());
repls = setupVarReplacements(markedEqns, inEqns, inVars, inVecEqToVar, repls, inMapIncRowEqn, inME);
repls = setupVarReplacements(markedEqns, inEqns, inVars, inVecEqToVar, repls, inMapIncRowEqn, inME, inShared);
then repls;

case (_::markedEqns, _, _, _, _, _, _) equation
repls = setupVarReplacements(markedEqns, inEqns, inVars, inVecEqToVar, inRepls, inMapIncRowEqn, inME);
repls = setupVarReplacements(markedEqns, inEqns, inVars, inVecEqToVar, inRepls, inMapIncRowEqn, inME, inShared);
then repls;
end matchcontinue;
end setupVarReplacements;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/XMLDump.mo
Expand Up @@ -1533,7 +1533,7 @@ algorithm
cref = BackendVariable.varCref(var);
varexp = Expression.crefExp(cref);
varexp = if BackendVariable.isStateVar(var) then Expression.expDer(varexp) else varexp;
eqn = BackendEquation.solveEquation(eqn, varexp);
eqn = BackendEquation.solveEquation(eqn, varexp, NONE());
dumpEquation(eqn, intString(index),addMMLCode);
dumpEqns2(eqns, vars, index+1, addMMLCode, false, true);
then ();
Expand Down

0 comments on commit f28fb27

Please sign in to comment.