Skip to content

Commit

Permalink
Better handling of redundant initial equations
Browse files Browse the repository at this point in the history
- check for redundant initial equations after simplification
  and remove them in RemoveSimpleEquations.
- warn about consistency/inconsistency.
- better error messages

ticket:4525
  • Loading branch information
ptaeuber authored and OpenModelica-Hudson committed Oct 5, 2017
1 parent d3f9ab1 commit 215f1b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
11 changes: 5 additions & 6 deletions Compiler/BackEnd/Initialization.mo
Expand Up @@ -268,7 +268,7 @@ algorithm
Error.addCompilerWarning("Assuming fixed start value for the following " + intString(listLength(dumpVars)) + " variables:\n" + warnAboutVars2(dumpVars));
end if;
if b2 then
Error.addCompilerWarning("Assuming redundant initial conditions for the following " + intString(listLength(removedEqns)) + " initial equations:\n" + warnAboutEqns2(removedEqns));
Error.addMessage(Error.INITIALIZATION_OVER_SPECIFIED, {"The following " + intString(listLength(removedEqns)) + " initial equations are redundant, so they are removed from the initialization sytem:\n" + warnAboutEqns2(removedEqns)});
end if;
else
if b1 then
Expand Down Expand Up @@ -1692,8 +1692,7 @@ algorithm

outMarkedEqns := downCompsMarker(listReverse(inFlatComps), inVecVarToEq, inM, inFlatComps, markedEqns, inLoopListComps);
else
// TODO: change the message
Error.addCompilerNotification("It was not possible to analyze the given system symbolically, because the relevant equations are part of an algebraic loop. This is not supported yet.");
Error.addCompilerNotification("It was not possible to check the given initialization system for consistency symbolically, because the relevant equations are part of an algebraic loop. This is not supported yet.");
fail();
end try;
end compsMarker;
Expand Down Expand Up @@ -1731,7 +1730,7 @@ algorithm
then markedEqns;

else equation
Error.addCompilerNotification("It was not possible to analyze the given system symbolically, because the relevant equations are part of an algebraic loop. This is not supported yet.");
Error.addCompilerNotification("It was not possible to check the given initialization system for consistency symbolically, because the relevant equations are part of an algebraic loop. This is not supported yet.");
then fail();
end matchcontinue;
end compsMarker2;
Expand Down Expand Up @@ -1859,7 +1858,7 @@ algorithm
//listParameter = parameterCheck(exp);
//true = listEmpty(listParameter);
eqn = BackendEquation.get(inEqnsOrig, inUnassignedEqn);
Error.addCompilerNotification("The following equation is consistent and got removed from the initialization problem: " + BackendDump.equationString(eqn));
// Error.addCompilerNotification("The following equation is consistent and got removed from the initialization problem: " + BackendDump.equationString(eqn));
then ({inUnassignedEqn}, true, {});

case _ equation
Expand Down Expand Up @@ -1911,7 +1910,7 @@ algorithm
false = listEmpty(listVar);

_ = BackendEquation.get(inEqnsOrig, inUnassignedEqn);
Error.addCompilerNotification("It was not possible to analyze the given system symbolically, because the relevant equations are part of an algebraic loop. This is not supported yet.");
Error.addCompilerNotification("It was not possible to check the given initialization system for consistency symbolically, because the relevant equations are part of an algebraic loop. This is not supported yet.");
then ({}, false, {});

case _ equation
Expand Down
22 changes: 21 additions & 1 deletion Compiler/BackEnd/RemoveSimpleEquations.mo
Expand Up @@ -3941,13 +3941,33 @@ protected function replaceEquationTraverser "
algorithm
(outEq,outTpl) := match (inEq,inTpl)
local
BackendDAE.Equation e;
BackendDAE.Equation e, eqn;
DAE.Exp lhs, rhs, res;
BackendVarTransform.VariableReplacements repl;
list<BackendDAE.Equation> eqns, eqns1;
Boolean b, b1;
case (e, (repl, eqns, b))
equation
(eqns1, b1) = BackendVarTransform.replaceEquations({e}, repl, SOME(BackendVarTransform.skipPreChangeEdgeOperator));
if BackendEquation.isInitialEquation(e) and BackendEquation.isEquation(e) then
eqn = listHead(eqns1);

lhs = BackendEquation.getEquationLHS(eqn);
rhs = BackendEquation.getEquationRHS(eqn);
res = Expression.createResidualExp(lhs, rhs);

if Expression.isConst(res) then
if Expression.isZero(res) then
Error.addCompilerNotification("The following initial equation is redundant and consistent due to simplifications in RemoveSimpleEquations and therefore removed from the initialization problem: " + BackendDump.equationString(e) + (if b1 then " -> " + BackendDump.equationString(eqn) else ""));
eqns1 = {};
b1 = true;
else
Error.addCompilerWarning("The following initial equation is inconsistent due to simplifications in RemoveSimpleEquations and therefore removed from the initialization problem: " + BackendDump.equationString(e) + (if b1 then " -> " + BackendDump.equationString(eqn) else ""));
eqns1 = {};
b1 = true;
end if;
end if;
end if;
eqns = listAppend(eqns1, eqns);
then (e, (repl, eqns, b or b1));
end match;
Expand Down

0 comments on commit 215f1b1

Please sign in to comment.