Skip to content

Commit

Permalink
- Preparation for new "remove simple equations" module: This introduc…
Browse files Browse the repository at this point in the history
…es a new variable attribute named "unreplaceable". This is needed to prevent unintended replacements for generated variables (e.g. symbolic jacobian, encapsulated when conditions, substituted common sub-expressions, ...)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25467 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Apr 9, 2015
1 parent f158abb commit 409e11d
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 122 deletions.
5 changes: 3 additions & 2 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -190,7 +190,7 @@ public
uniontype Var "variables"
record VAR
.DAE.ComponentRef varName "variable name";
VarKind varKind "Kind of variable";
VarKind varKind "kind of variable";
.DAE.VarDirection varDirection "input, output or bidirectional";
.DAE.VarParallelism varParallelism "parallelism of the variable. parglobal, parlocal or non-parallel";
Type varType "built-in type or enumeration";
Expand All @@ -202,7 +202,8 @@ uniontype Var "variables"
Option<TearingSelect> tearingSelectOption "value for TearingSelect";
Option<SCode.Comment> comment "this contains the comment and annotation from Absyn";
.DAE.ConnectorType connectorType "flow, stream, unspecified or not connector.";
.DAE.VarInnerOuter innerOuter "inner, outer, inner outer or unspecified";
.DAE.VarInnerOuter innerOuter "inner, outer, inner outer or unspecified";
Boolean unreplaceable "indicates if it is allowed to replace this variable";
end VAR;
end Var;

Expand Down
6 changes: 3 additions & 3 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -610,7 +610,7 @@ algorithm
(dae_var_attr, source, _) = Inline.inlineStartAttribute(dae_var_attr, source, (SOME(functionTree), {DAE.NORM_INLINE()}));
ts = BackendDAEUtil.setTearingSelectAttribute(comment);
then
(BackendDAE.VAR(name, kind_1, dir, prl, tp, NONE(), NONE(), dims, source, dae_var_attr, ts, comment, ct, DAEUtil.toDAEInnerOuter(io)));
(BackendDAE.VAR(name, kind_1, dir, prl, tp, NONE(), NONE(), dims, source, dae_var_attr, ts, comment, ct, DAEUtil.toDAEInnerOuter(io), false));
end match;
end lowerDynamicVar;

Expand Down Expand Up @@ -676,7 +676,7 @@ algorithm
(dae_var_attr, source, _) = Inline.inlineStartAttribute(dae_var_attr, source, fnstpl);
ts = NONE();
then
(BackendDAE.VAR(name, kind_1, dir, prl, tp, bind1, NONE(), dims, source, dae_var_attr, ts, comment, ct, DAEUtil.toDAEInnerOuter(io)), inlineHT,eqLst);
(BackendDAE.VAR(name, kind_1, dir, prl, tp, bind1, NONE(), dims, source, dae_var_attr, ts, comment, ct, DAEUtil.toDAEInnerOuter(io), false), inlineHT, eqLst);

else
equation
Expand Down Expand Up @@ -995,7 +995,7 @@ algorithm
(dae_var_attr, source, _) = Inline.inlineStartAttribute(dae_var_attr, source, (SOME(functionTree), {DAE.NORM_INLINE()}));
ts = NONE();
then
BackendDAE.VAR(name, kind_1, dir, prl, tp, bind, NONE(), dims, source, dae_var_attr, ts, comment, ct, DAEUtil.toDAEInnerOuter(io));
BackendDAE.VAR(name, kind_1, dir, prl, tp, bind, NONE(), dims, source, dae_var_attr, ts, comment, ct, DAEUtil.toDAEInnerOuter(io), false);
end match;
end lowerExtObjVar;

Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -575,7 +575,7 @@ algorithm
equation
cr = ComponentReference.crefPrefixDer(cr);
then
BackendDAE.VAR(cr,BackendDAE.STATE_DER(),dir,prl,tp,exp,v,dim,source,attr,ts,comment,ct, io);
BackendDAE.VAR(cr, BackendDAE.STATE_DER(), dir, prl, tp, exp, v, dim, source, attr, ts, comment, ct, io, false);

else inVar;
end match;
Expand Down
54 changes: 24 additions & 30 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -389,8 +389,7 @@ protected
algorithm
name := Expression.reductionIterName(iter);
cr := ComponentReference.makeCrefIdent(name,DAE.T_INTEGER_DEFAULT,{});
backendVar := BackendDAE.VAR(cr,BackendDAE.VARIABLE(),DAE.BIDIR(),DAE.NON_PARALLEL(),DAE.T_INTEGER_DEFAULT,NONE(),NONE(),{},
DAE.emptyElementSource,NONE(),NONE(),NONE(),DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER());
backendVar := BackendDAE.VAR(cr, BackendDAE.VARIABLE(), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_INTEGER_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
end makeIterVariable;

protected function checkEquationSize"author: Frenkel TUD 2010-12
Expand Down Expand Up @@ -907,7 +906,7 @@ algorithm
true = Expression.isConst(e);
(_, v, _) = Ceval.ceval(cache, graph, e, false, NONE(), Absyn.NO_MSG(),0);
then
BackendDAE.VAR(cr, vk, vd, prl, ty, SOME(e), SOME(v), dims, src, va, ts, c, ct, io);
BackendDAE.VAR(cr, vk, vd, prl, ty, SOME(e), SOME(v), dims, src, va, ts, c, ct, io, false);
else inVar;
end matchcontinue;
end calculateValue;
Expand Down Expand Up @@ -6059,6 +6058,7 @@ algorithm
list<BackendDAE.WhenClause> whenClauseLst;
Type_a ext_arg_1,ext_arg_2,ext_arg_4,ext_arg_5,ext_arg_6;
list<BackendDAE.EqSystem> systs;

case (BackendDAE.DAE(eqs=systs,shared=BackendDAE.SHARED(knownVars = vars2,initialEqs = ieqns,removedEqs = reqns, eventInfo = BackendDAE.EVENT_INFO(whenClauseLst=whenClauseLst))),_,_)
equation
ext_arg_1 = List.fold1(systs,traverseBackendDAEExpsEqSystem,func,inTypeA);
Expand All @@ -6068,11 +6068,10 @@ algorithm
(_,ext_arg_6) = BackendDAETransform.traverseBackendDAEExpsWhenClauseLst(whenClauseLst,func,ext_arg_5);
then
ext_arg_6;
else
equation
Error.addMessage(Error.INTERNAL_ERROR,{"BackendDAEUtil.traverseBackendDAEExps failed"});
then
fail();

else equation
Error.addMessage(Error.INTERNAL_ERROR,{"BackendDAEUtil.traverseBackendDAEExps failed"});
then fail();
end matchcontinue;
end traverseBackendDAEExps;

Expand Down Expand Up @@ -6501,15 +6500,14 @@ protected function traverseBackendDAEExpsVarWithUpdate "author: Frenkel TUD
output Type_a outA;
end FuncExpType;
algorithm
(ovar,outTypeA) :=
matchcontinue (inVar,func,inTypeA)
(ovar, outTypeA) := matchcontinue(inVar)
local
DAE.Exp e1;
DAE.ComponentRef cref;
list<DAE.Dimension> instdims;
Option<DAE.VariableAttributes> attr;
Option<BackendDAE.TearingSelect> ts;
Type_a ext_arg_1,ext_arg_2;
Option<BackendDAE.TearingSelect> ts;
Type_a ext_arg_1, ext_arg_2;
VarKind varKind;
DAE.VarDirection varDirection;
DAE.VarParallelism varParallelism;
Expand All @@ -6519,28 +6517,24 @@ algorithm
Option<SCode.Comment> comment;
DAE.ConnectorType ct;
DAE.VarInnerOuter io;
Boolean unreplaceable;

case (NONE(),_,_) then (NONE(),inTypeA);
case NONE()
then (NONE(), inTypeA);

case (SOME(BackendDAE.VAR(cref,varKind,varDirection,varParallelism,varType,SOME(e1),bindValue,instdims,source,attr,ts,comment,ct,io)),_,_)
equation
(e1,ext_arg_1) = func(e1,inTypeA);
(attr,ext_arg_2) = traverseBackendDAEVarAttr(attr,func,ext_arg_1);
then
(SOME(BackendDAE.VAR(cref,varKind,varDirection,varParallelism,varType,SOME(e1),bindValue,instdims,source,attr,ts,comment,ct,io)),ext_arg_2);
case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1), bindValue, instdims, source, attr, ts, comment, ct, io, unreplaceable)) equation
(e1, ext_arg_1) = func(e1, inTypeA);
(attr, ext_arg_2) = traverseBackendDAEVarAttr(attr, func, ext_arg_1);
then (SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1), bindValue, instdims, source, attr, ts, comment, ct, io, unreplaceable)), ext_arg_2);

case (SOME(BackendDAE.VAR(cref,varKind,varDirection,varParallelism,varType,NONE(),bindValue,instdims,source,attr,ts,comment,ct,io)),_,_)
equation
(attr,ext_arg_2) = traverseBackendDAEVarAttr(attr,func,inTypeA);
then
(SOME(BackendDAE.VAR(cref,varKind,varDirection,varParallelism,varType,NONE(),bindValue,instdims,source,attr,ts,comment,ct,io)),ext_arg_2);
case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), bindValue, instdims, source, attr, ts, comment, ct, io, unreplaceable)) equation
(attr, ext_arg_2) = traverseBackendDAEVarAttr(attr, func, inTypeA);
then (SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), bindValue, instdims, source, attr, ts, comment, ct, io, unreplaceable)), ext_arg_2);

else
equation
true = Flags.isSet(Flags.FAILTRACE);
Debug.trace("- BackendDAE.traverseBackendDAEExpsVar failed\n");
then
fail();
else equation
true = Flags.isSet(Flags.FAILTRACE);
Debug.trace("- BackendDAE.traverseBackendDAEExpsVar failed\n");
then fail();
end matchcontinue;
end traverseBackendDAEExpsVarWithUpdate;

Expand Down
12 changes: 6 additions & 6 deletions Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -2229,7 +2229,7 @@ algorithm

case (_, DAE.RELATION(e1, DAE.LESS(_), e2, _, _)) equation
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER());
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
rhs = Expression.expSub(e1,e2);
(rhs, _) = ExpressionSimplify.simplify1(rhs);
expNull = DAE.RCONST(0.0);
Expand All @@ -2239,7 +2239,7 @@ algorithm

case (_, DAE.RELATION(e1, DAE.LESSEQ(_), e2, _, _)) equation
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER());
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
rhs = Expression.expSub(e1,e2);
(rhs, _) = ExpressionSimplify.simplify1(rhs);
expNull = DAE.RCONST(0.0);
Expand All @@ -2249,7 +2249,7 @@ algorithm

case (_, DAE.RELATION(e1, DAE.GREATER(_), e2, _, _)) equation
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER());
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
rhs = Expression.expSub(e2,e1);
(rhs, _) = ExpressionSimplify.simplify1(rhs);
expNull = DAE.RCONST(0.0);
Expand All @@ -2259,7 +2259,7 @@ algorithm

case (_, DAE.RELATION(e1, DAE.GREATEREQ(_), e2, _, _)) equation
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER());
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
rhs = Expression.expSub(e2,e1);
(rhs, _) = ExpressionSimplify.simplify(rhs);
expNull = DAE.RCONST(0.0);
Expand All @@ -2269,7 +2269,7 @@ algorithm

case (_, DAE.RELATION(e1, DAE.EQUAL(_), e2, _, _)) equation
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER());
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
rhs = Expression.expSub(e2,e1);
(rhs, _) = ExpressionSimplify.simplify(rhs);
expNull = DAE.RCONST(0.0);
Expand All @@ -2284,7 +2284,7 @@ algorithm
end try;

lhs := ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar := BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER());
dummyVar := BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
dummyVar := BackendVariable.mergeAliasVars(dummyVar, v, false, knvars);
eqn := BackendDAE.SOLVED_EQUATION(lhs, e1, Source, BackendDAE.EQ_ATTR_DEFAULT_UNKNOWN);

Expand Down
21 changes: 10 additions & 11 deletions Compiler/BackEnd/BackendInline.mo
Expand Up @@ -492,9 +492,8 @@ protected function inlineVar
output BackendDAE.Var outVar;
output Boolean inlined;
algorithm
(outVar,inlined) := match(inVar,inElementList)
(outVar, inlined) := match(inVar)
local
Inline.Functiontuple fns;
DAE.ComponentRef varName;
BackendDAE.VarKind varKind;
DAE.VarDirection varDirection;
Expand All @@ -503,21 +502,21 @@ algorithm
Option<Values.Value> bindValue;
DAE.InstDims arrayDim;
Option<DAE.VariableAttributes> values,values1;
Option<BackendDAE.TearingSelect> ts;
Option<BackendDAE.TearingSelect> ts;
Option<SCode.Comment> comment;
DAE.ConnectorType ct;
BackendDAE.Var var;
DAE.ElementSource source;
Option<DAE.Exp> bind;
Boolean b1,b2;
DAE.VarInnerOuter io;
case(BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,bindValue,arrayDim,source,values,ts,comment,ct,io),fns)
equation
(bind,source,b1) = Inline.inlineExpOpt(bind,fns,source);
(values1,source,b2) = Inline.inlineStartAttribute(values,source,fns);
then
(BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,bindValue,arrayDim,source,values1,ts,comment,ct,io),b1 or b2);
case(var,_) then (var,false);
Boolean unreplaceable;

case BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,bindValue,arrayDim,source,values,ts,comment,ct,io,unreplaceable) equation
(bind,source,b1) = Inline.inlineExpOpt(bind,inElementList,source);
(values1,source,b2) = Inline.inlineStartAttribute(values,source,inElementList);
then (BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,bindValue,arrayDim,source,values1,ts,comment,ct,io,unreplaceable), b1 or b2);

else (inVar, false);
end match;
end inlineVar;

Expand Down

0 comments on commit 409e11d

Please sign in to comment.