Skip to content

Commit

Permalink
- Improve the error message when trying to use a non-linear system of…
Browse files Browse the repository at this point in the history
… equations in a when-equation

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5893 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Aug 9, 2010
1 parent 1c97aa0 commit 885d0c8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
24 changes: 23 additions & 1 deletion Compiler/DAELow.mo
Expand Up @@ -14179,7 +14179,7 @@ algorithm
end matchcontinue;
end printEquationNo;

protected function printEquation "function: printEquation
public function printEquation "function: printEquation
author: PA

Helper function to print_equations
Expand Down Expand Up @@ -16618,4 +16618,26 @@ algorithm
DAE.ET_REAL());
end makeDerCref;

public function equationSource "Retrieve the source from a DAELow equation"
input Equation eq;
output DAE.ElementSource source;
algorithm
source := matchcontinue eq
case EQUATION(source=source) then source;
case ARRAY_EQUATION(source=source) then source;
case SOLVED_EQUATION(source=source) then source;
case RESIDUAL_EQUATION(source=source) then source;
case WHEN_EQUATION(source=source) then source;
case ALGORITHM(source=source) then source;
case COMPLEX_EQUATION(source=source) then source;
end matchcontinue;
end equationSource;

public function equationInfo "Retrieve the line number information from a DAELow equation"
input Equation eq;
output Absyn.Info info;
algorithm
info := DAEUtil.getElementSourceFileInfo(equationSource(eq));
end equationInfo;

end DAELow;
29 changes: 25 additions & 4 deletions Compiler/SimCode.mo
Expand Up @@ -2350,11 +2350,13 @@ algorithm
list<DAELow.Equation> rest,rest2;
DAELow.MultiDimEquation[:] aeqns;
VarTransform.VariableReplacements repl;
DAELow.Equation eq;
list<SimEqSystem> eqSystemsRest;
list<Integer> ds;
list<Option<Integer>> ad;
list<DAE.Subscript> subs;
list<tuple<Integer,list<list<DAE.Subscript>>>> entrylst1,entrylst2;
list<tuple<Integer,list<list<DAE.Subscript>>>> entrylst1,entrylst2;
DAE.ComponentRef left;
case ({}, _, inEntrylst) then ({},inEntrylst);
case ((DAELow.EQUATION(exp = e1,scalar = e2) :: rest), aeqns, inEntrylst)
equation
Expand Down Expand Up @@ -2386,9 +2388,28 @@ algorithm
(eqSystemsRest,entrylst2) = createNonlinearResidualEquations(rest, aeqns, entrylst1);
then
(SES_RESIDUAL(res_exp) :: eqSystemsRest,entrylst2);
case (_,_,_)

case ((eq as DAELow.WHEN_EQUATION(whenEquation = DAELow.WHEN_EQ(left = left, right = e2)))::rest,aeqns,inEntrylst)
equation
// This following does not work. It does not take index or elseWhen into account.
// The generated code for the when-equation also does not solve a linear system; it uses the variables directly.
/*
tp = Exp.typeof(e2);
e1 = DAE.CREF(left,tp);
res_exp = DAE.BINARY(e1,DAE.SUB(tp),e2);
res_exp = Exp.simplify(res_exp);
res_exp = replaceDerOpInExp(res_exp);
(eqSystemsRest,entrylst1) = createNonlinearResidualEquations(rest, aeqns, inEntrylst);
then
(SES_RESIDUAL(res_exp) :: eqSystemsRest,entrylst1);
*/
Error.addSourceMessage(Error.UNSUPPORTED_LANGUAGE_FEATURE, {"non-linear equations within when-equations","Perform non-linear operations outside the when-equation (this is slower, but works)"},DAELow.equationInfo(eq));
then
fail();

case (eq::_,_,_)
equation
Error.addMessage(Error.INTERNAL_ERROR, {"SimCode.createNonlinearResidualEquations failed"});
Error.addSourceMessage(Error.INTERNAL_ERROR, {"SimCode.createNonlinearResidualEquations failed"},DAELow.equationInfo(eq));
then
fail();
end matchcontinue;
Expand Down Expand Up @@ -3575,7 +3596,7 @@ algorithm
case (dlowEq,_,_,_)
equation
DAELow.dumpEqns({dlowEq});
Error.addMessage(Error.INTERNAL_ERROR,{"dlowEqToExp failed"});
Error.addSourceMessage(Error.INTERNAL_ERROR,{"dlowEqToExp failed"},DAELow.equationInfo(dlowEq));
then
fail();
end matchcontinue;
Expand Down

0 comments on commit 885d0c8

Please sign in to comment.