@@ -154,39 +154,48 @@ algorithm
154154 DAE . ComponentRef cr;
155155 DAE . Exp e, expr, a, b;
156156 Option < DAE . Exp > eMin, eMax;
157- Boolean isZero ;
157+ Boolean simplifyToZero ;
158158
159- case DAE . CALL (path= Absyn . IDENT ("$OMC$PositiveMax" ),expLst= {e as DAE . CREF (componentRef= cr), expr}) algorithm
159+ // positiveMax(cref, eps) = 0 if variable(cref).max <= 0
160+ case DAE . CALL (path= Absyn . IDENT ("$OMC$PositiveMax" ),expLst= {e as DAE . CREF (componentRef= cr), expr})
161+ algorithm
160162 (eMin, eMax) := simplifyInStreamWorkExpresion(cr, outVars);
161- isZero := simplifyInStreamWorkSimplify(eMin, false );
163+ simplifyToZero := simplifyInStreamWorkSimplify(eMax, true ); // var.max <= 0.0
162164 tp := ComponentReference . crefTypeFull(cr);
163- then if isZero then Expression . createZeroExpression(tp) else Expression . makePureBuiltinCall("max" , {e, expr}, tp);
165+ then
166+ if simplifyToZero then Expression . createZeroExpression(tp) else Expression . makePureBuiltinCall("max" , {e, expr}, tp);
164167
165- case DAE . CALL (path= Absyn . IDENT ("$OMC$PositiveMax" ),expLst= {e as DAE . UNARY (DAE . UMINUS (tp), DAE . CREF (componentRef= cr)), expr}) algorithm
168+ // positiveMax(-cref, eps) = 0 if variable(cref).min >= 0
169+ case DAE . CALL (path= Absyn . IDENT ("$OMC$PositiveMax" ),expLst= {e as DAE . UNARY (DAE . UMINUS (tp), DAE . CREF (componentRef= cr)), expr})
170+ algorithm
166171 (eMin, eMax) := simplifyInStreamWorkExpresion(cr, outVars);
167- isZero := simplifyInStreamWorkSimplify(eMax, true );
168- then if isZero then Expression . createZeroExpression(tp) else Expression . makePureBuiltinCall("max" , {e, expr}, tp);
172+ simplifyToZero := simplifyInStreamWorkSimplify(eMin, false ); // var.min >= 0.0
173+ then
174+ if simplifyToZero then Expression . createZeroExpression(tp) else Expression . makePureBuiltinCall("max" , {e, expr}, tp);
169175
170- case DAE . CALL (path= Absyn . IDENT ("$OMC$PositiveMax" ),expLst= {e, expr}) guard Expression . isZero(e)
176+ // positiveMax(-cref, eps) = -cref where variable is constant <= 0
177+ case DAE . CALL (path= Absyn . IDENT ("$OMC$PositiveMax" ),expLst= {e, expr}) guard Expression . isNegativeOrZero(e)
171178 then e;
172179
173180 case DAE . CALL (path= Absyn . IDENT ("$OMC$PositiveMax" ),expLst= {e, expr})
174181 // print("\nsimplifyInStreamWork: ");
175182 // print(ExpressionDump.printExpStr(inExp));
176183 // print(" <-> ");
177184 // print(ExpressionDump.printExpStr(e));
178- then Expression . makePureBuiltinCall("max" , {e, expr}, Expression . typeof(e));
185+ then
186+ Expression . makePureBuiltinCall("max" , {e, expr}, Expression . typeof(e));
179187
180188 case DAE . CALL (path= Absyn . IDENT ("$OMC$inStreamDiv" ),expLst= {e, expr})
181189 algorithm
182190 e := ExpressionSimplify . simplify(e);
183191 expr := match(e)
184- case DAE . BINARY (a, DAE . DIV (), b)
185- guard Expression . isZero(a) and Expression . isZero(b)
186- then
187- expr;
188- else
189- e;
192+
193+ case DAE . BINARY (a, DAE . DIV (), b)
194+ guard Expression . isZero(a) and Expression . isZero(b)
195+ then expr;
196+
197+ else e;
198+
190199 end match;
191200 then
192201 expr;
@@ -207,7 +216,7 @@ algorithm
207216 try
208217 (v, _) := BackendVariable . getVarSingle(cr, vars);
209218 (outMin, outMax) := BackendVariable . getMinMaxAttribute(v);
210- return ;
219+ break ;
211220 else
212221 // search
213222 end try ;
0 commit comments