Skip to content

Commit

Permalink
Fix #7439 (#7440)
Browse files Browse the repository at this point in the history
- Change back to using List.map1BoolOr in Expression.expContains, since
  using List.isMemberOnTrue swaps the arguments.
  • Loading branch information
perost committed May 5, 2021
1 parent 7929596 commit 3806526
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 64 deletions.
88 changes: 27 additions & 61 deletions OMCompiler/Compiler/FrontEnd/Expression.mo
Expand Up @@ -9562,6 +9562,12 @@ algorithm
end match;
end expStructuralEqualListLst;

public function expContainsList
input list<DAE.Exp> expl;
input DAE.Exp exp;
output Boolean contains = List.map1BoolOr(expl, expContains, exp);
end expContainsList;

public function expContains
"Returns true if first expression contains the second one as a sub expression.
Only constants, component references or der(componentReference) can be checked
Expand Down Expand Up @@ -9596,52 +9602,34 @@ algorithm

case (DAE.ENUM_LITERAL(), _) then false;

case (DAE.ARRAY(array=expLst), _) equation
res = List.isMemberOnTrue(inExp2, expLst, expContains);
then res;

case (DAE.MATRIX(matrix=expl), _) equation
res = List.map1ListBoolOr(expl, expContains, inExp2);
then res;
case (DAE.ARRAY(array=expLst), _) then expContainsList(expLst, inExp2);
case (DAE.MATRIX(matrix=expl), _) then List.map1ListBoolOr(expl, expContains, inExp2);

case (DAE.CREF(componentRef=cr1), DAE.CREF(componentRef=cr2)) equation
res = ComponentReference.crefEqual(cr1, cr2);
if not res then
expLst = List.map(ComponentReference.crefSubs(cr1), getSubscriptExp);
res = List.isMemberOnTrue(inExp2, expLst, expContains);
res = expContainsList(expLst, inExp2);
end if;
then res;

case ((DAE.CREF()), _) then false;

case (DAE.BINARY(exp1=e1, exp2=e2), _) equation
res = expContains(e1, inExp2);
res = if res then true else expContains(e2, inExp2);
then res;
case (DAE.BINARY(exp1=e1, exp2=e2), _)
then expContains(e1, inExp2) or expContains(e2, inExp2);

case (DAE.UNARY(exp=e), _) equation
res = expContains(e, inExp2);
then res;
case (DAE.UNARY(exp=e), _) then expContains(e, inExp2);

case (DAE.LBINARY(exp1=e1, exp2=e2), _) equation
res = expContains(e1, inExp2);
res = if res then true else expContains(e2, inExp2);
then res;
case (DAE.LBINARY(exp1=e1, exp2=e2), _)
then expContains(e1, inExp2) or expContains(e2, inExp2);

case (DAE.LUNARY(exp=e), _) equation
res = expContains(e, inExp2);
then res;
case (DAE.LUNARY(exp=e), _) then expContains(e, inExp2);

case (DAE.RELATION(exp1=e1, exp2=e2), _) equation
res = expContains(e1, inExp2);
res = if res then true else expContains(e2, inExp2);
then res;
case (DAE.RELATION(exp1=e1, exp2=e2), _)
then expContains(e1, inExp2) or expContains(e2, inExp2);

case (DAE.IFEXP(expCond=c, expThen=t, expElse=f), _) equation
res = expContains(c, inExp2);
res = if res then true else expContains(t, inExp2);
res = if res then true else expContains(f, inExp2);
then res;
case (DAE.IFEXP(expCond=c, expThen=t, expElse=f), _)
then expContains(c, inExp2) or expContains(t, inExp2) or expContains(f, inExp2);

case (DAE.CALL(path=Absyn.IDENT(name="der"), expLst={DAE.CREF(cr1)}),
DAE.CALL(path=Absyn.IDENT(name="der"), expLst={DAE.CREF(cr2)})) equation
Expand All @@ -9653,37 +9641,16 @@ algorithm
case (DAE.CALL(path=Absyn.IDENT(name="previous")), _) then false;

// special rule for no arguments
case (DAE.CALL(expLst={}), _)
then false;
case (DAE.CALL(expLst={}), _) then false;

// general case for arguments
case (DAE.CALL(expLst=expLst), _) equation
res = List.isMemberOnTrue(inExp2, expLst, expContains);
then res;

case (DAE.RECORD(exps=expLst), _) equation
res = List.isMemberOnTrue(inExp2, expLst, expContains);
then res;

case (DAE.PARTEVALFUNCTION(expList=expLst), DAE.CREF()) equation
res = List.isMemberOnTrue(inExp2, expLst, expContains);
then res;

case (DAE.CAST(ty=DAE.T_REAL(), exp=DAE.ICONST()), _)
then false;

case (DAE.CAST(ty=DAE.T_REAL(), exp=e), _) equation
res = expContains(e, inExp2);
then res;

case (DAE.ASUB(exp=e, sub=expLst), _) equation
res = List.isMemberOnTrue(inExp2, expLst, expContains);
res = if res then true else expContains(e, inExp2);
then res;

case (DAE.REDUCTION(expr=e), _) equation
res = expContains(e, inExp2);
then res;
case (DAE.CALL(expLst=expLst), _) then expContainsList(expLst, inExp2);
case (DAE.RECORD(exps=expLst), _) then expContainsList(expLst, inExp2);
case (DAE.PARTEVALFUNCTION(expList=expLst), DAE.CREF()) then expContainsList(expLst, inExp2);
case (DAE.CAST(ty=DAE.T_REAL(), exp=DAE.ICONST()), _) then false;
case (DAE.CAST(ty=DAE.T_REAL(), exp=e), _) then expContains(e, inExp2);
case (DAE.ASUB(exp=e, sub=expLst), _) then expContainsList(expLst, inExp2) or expContains(e, inExp2);
case (DAE.REDUCTION(expr=e), _) then expContains(e, inExp2);

else equation
true = Flags.isSet(Flags.FAILTRACE);
Expand Down Expand Up @@ -12345,7 +12312,6 @@ algorithm
true = intGt(i, 0);
field_names = list(v.name for v in varLst);
e = DAE.RECORD(name, expl, field_names, ty);
//e = DAE.CALL(name, expl, DAE.CALL_ATTR(ty, false, false, false, false, DAE.NO_INLINE(), DAE.NO_TAIL()));
(e, _) = traverseExpBottomUp(e, traversingextendArrExp, true);
then
(e, true);
Expand Down
Expand Up @@ -40,7 +40,13 @@ runScript(modelTesting);getErrorString();
// Warning: The model contains alias variables with redundant start and/or conflicting nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts.
// Warning: Some equations could not be differentiated for following variables having attribute stateSelect=StateSelect.prefer. They will be treated as if they had stateSelect=StateSelect.default
// ========================================
// 1: volume.medium.T
// 1: volume.medium.Xi[6]
// 2: volume.medium.Xi[5]
// 3: volume.medium.Xi[4]
// 4: volume.medium.Xi[3]
// 5: volume.medium.Xi[2]
// 6: volume.medium.Xi[1]
// 7: volume.medium.T
// Please use -d=bltdump for more information.
//
// "true
Expand Down
4 changes: 4 additions & 0 deletions testsuite/simulation/modelica/inheritances/Ticket4258a.mos
Expand Up @@ -33,6 +33,10 @@ simulate(simple_BasicHX_water_gas); getErrorString();
// 4: WT_Nachreformer.pipe_1.mediums[3].T
// 5: WT_Nachreformer.pipe_1.mediums[4].T
// Please use -d=bltdump for more information.
// Warning: Some equations could not be differentiated for following variables having attribute stateSelect=StateSelect.prefer. They will be treated as if they had stateSelect=StateSelect.default
// ========================================
// 1: WT_Nachreformer.pipe_2.flowModel.m_flows[5]
// Please use -d=bltdump for more information.
// Warning: The initial conditions are not fully specified. For more information set -d=initialization. In OMEdit Tools->Options->Simulation->Show additional information from the initialization process, in OMNotebook call setCommandLineOptions(\"-d=initialization\").
// "
// endResult
16 changes: 14 additions & 2 deletions testsuite/simulation/modelica/inheritances/Ticket4258b.mos
Expand Up @@ -21,8 +21,20 @@ buildModel(Eco); getErrorString();
// "Warning: The model contains alias variables with redundant start and/or conflicting nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts.
// Warning: Some equations could not be differentiated for following variables having attribute stateSelect=StateSelect.prefer. They will be treated as if they had stateSelect=StateSelect.default
// ========================================
// 1: FGchannel.mediums[1].T
// 2: FGchannel.mediums[2].T
// 1: FGchannel.mediums[1].Xi[1]
// 2: FGchannel.mediums[1].Xi[2]
// 3: FGchannel.mediums[1].Xi[3]
// 4: FGchannel.mediums[1].Xi[4]
// 5: FGchannel.mediums[1].Xi[5]
// 6: FGchannel.mediums[1].Xi[6]
// 7: FGchannel.mediums[1].T
// 8: FGchannel.mediums[2].Xi[1]
// 9: FGchannel.mediums[2].Xi[2]
// 10: FGchannel.mediums[2].Xi[3]
// 11: FGchannel.mediums[2].Xi[4]
// 12: FGchannel.mediums[2].Xi[5]
// 13: FGchannel.mediums[2].Xi[6]
// 14: FGchannel.mediums[2].T
// Please use -d=bltdump for more information.
// Warning: The initial conditions are not fully specified. For more information set -d=initialization. In OMEdit Tools->Options->Simulation->Show additional information from the initialization process, in OMNotebook call setCommandLineOptions(\"-d=initialization\").
// "
Expand Down

0 comments on commit 3806526

Please sign in to comment.