@@ -409,6 +409,7 @@ preprocessing for solve1,
409409 DAE . ComponentRef cr;
410410 DAE . Boolean con, new_x, collect := true , inlineFun := true ;
411411 Integer iter;
412+ Integer depth := 0 ;
412413
413414 algorithm
414415 (x, _) := ExpressionSimplify . simplify(inExp1);
@@ -436,7 +437,7 @@ preprocessing for solve1,
436437 con := new_x or con;
437438 // TODO: use new defined function, which missing in the cpp runtime
438439 if not stringEqual(Config . simCodeTarget(), "Cpp" ) then
439- (x, y, new_x, eqnForNewVars, newVarsCrefs) := preprocessingSolveTmpVars(x, y, inExp3, uniqueEqIndex, eqnForNewVars, newVarsCrefs);
440+ (x, y, new_x, eqnForNewVars, newVarsCrefs, depth ) := preprocessingSolveTmpVars(x, y, inExp3, uniqueEqIndex, eqnForNewVars, newVarsCrefs, depth );
440441 con := new_x or con;
441442 end if ;
442443
@@ -1212,16 +1213,18 @@ e.g. for solve abs()
12121213 input Option < Integer > uniqueEqIndex "offset for tmp vars" ;
12131214 input list< BackendDAE . Equation > ieqnForNewVars;
12141215 input list< DAE . ComponentRef > inewVarsCrefs;
1216+ input Integer idepth;
12151217 output DAE . Exp x;
12161218 output DAE . Exp y;
12171219 output Boolean new_x;
12181220 output list< BackendDAE . Equation > eqnForNewVars "eqn for tmp vars" ;
12191221 output list< DAE . ComponentRef > newVarsCrefs;
1222+ output Integer odepth;
12201223algorithm
1221- (x, y, new_x, eqnForNewVars, newVarsCrefs) := match(uniqueEqIndex)
1224+ (x, y, new_x, eqnForNewVars, newVarsCrefs, odepth ) := match(uniqueEqIndex)
12221225 local Integer i;
1223- case (SOME (i)) then preprocessingSolveTmpVarsWork(inExp1, inExp2, inExp3, i, ieqnForNewVars, inewVarsCrefs);
1224- else then (inExp1, inExp2, false , ieqnForNewVars, inewVarsCrefs);
1226+ case (SOME (i)) then preprocessingSolveTmpVarsWork(inExp1, inExp2, inExp3, i, ieqnForNewVars, inewVarsCrefs, idepth );
1227+ else then (inExp1, inExp2, false , ieqnForNewVars, inewVarsCrefs, idepth );
12251228 end match;
12261229end preprocessingSolveTmpVars;
12271230
@@ -1237,15 +1240,16 @@ e.g. for solve abs
12371240 input Integer uniqueEqIndex "offset for tmp vars" ;
12381241 input list< BackendDAE . Equation > ieqnForNewVars;
12391242 input list< DAE . ComponentRef > inewVarsCrefs;
1243+ input Integer idepth "depth of tmp var" ;
12401244 output DAE . Exp x;
12411245 output DAE . Exp y;
12421246 output Boolean new_x;
12431247 output list< BackendDAE . Equation > eqnForNewVars "eqn for tmp vars" ;
12441248 output list< DAE . ComponentRef > newVarsCrefs;
1249+ output Integer odepth;
12451250algorithm
1246- (x, y, new_x, eqnForNewVars, newVarsCrefs) := matchcontinue(inExp1, inExp2)
1251+ (x, y, new_x, eqnForNewVars, newVarsCrefs, odepth ) := matchcontinue(inExp1, inExp2)
12471252 local DAE . Exp e1, e_1, e, e2, exP, lhs;
1248- list< DAE . Exp > lhsF, singCall;
12491253 DAE . ComponentRef cr;
12501254 DAE . Type tp;
12511255 BackendDAE . Equation eqn;
@@ -1257,43 +1261,36 @@ algorithm
12571261 case (DAE . CALL (path = Absyn . IDENT (name = "abs" ),expLst = {e1}), _)
12581262 equation
12591263 tp = Expression . typeof(e1);
1260- cr = ComponentReference . makeCrefIdent("$TMP_VAR_SOLVE_ABS_FOR_EQN_" + intString(uniqueEqIndex), tp , {});
1264+ cr = ComponentReference . makeCrefIdent("$TMP_VAR_SOLVE_ABS_FOR_EQN_" + intString(uniqueEqIndex) + "_" + intString(idepth) , tp , {});
12611265 eqn = BackendDAE . SOLVED_EQUATION (cr, e1, DAE . emptyElementSource, BackendDAE . EQ_ATTR_DEFAULT_UNKNOWN );
12621266 e = Expression . crefExp(cr);
1263- exP = Expression . makePureBuiltinCall("$_initialGuess" ,{inExp3},tp);
1264- e_1 = Expression . makePureBuiltinCall("$_signNoNull" ,{exP},tp);
1265- lhsF = Expression . factors(inExp2);
1266- (singCall,_) = List . split1OnTrue(lhsF, Expression . isFunCall, "$_signNoNull" );
1267- b = listLength(singCall) == 0 ;
1268- lhs = if b then Expression . expMul(e_1,inExp2) else inExp2;
1269- eqnForNewVars_ = if b then eqn::ieqnForNewVars else ieqnForNewVars;
1270- newVarsCrefs_ = if b then cr ::inewVarsCrefs else inewVarsCrefs;
1271- then(e1, lhs, true , eqnForNewVars_, newVarsCrefs_);
1267+ exP = Expression . makePureBuiltinCall("$_initialGuess" , {e}, tp);
1268+ e_1 = Expression . makePureBuiltinCall("$_signNoNull" , {exP}, tp);
1269+ lhs = Expression . expMul(e_1, inExp2);
1270+ eqnForNewVars_ = eqn::ieqnForNewVars;
1271+ newVarsCrefs_ = cr::inewVarsCrefs;
1272+ then(e1, lhs, true , eqnForNewVars_, newVarsCrefs_, idepth + 1 );
12721273
12731274 // x^n = y -> x = y^(1/n)
1274- case (DAE . BINARY (e1,DAE . POW (tp),e2),_)
1275+ case (DAE . BINARY (e1, DAE . POW (tp), e2),_)
12751276 equation
1276- cr = ComponentReference . makeCrefIdent("$TMP_VAR_SOLVE_POW_FOR_EQN_" + intString(uniqueEqIndex), tp , {});
1277+ cr = ComponentReference . makeCrefIdent("$TMP_VAR_SOLVE_POW_FOR_EQN_" + intString(uniqueEqIndex) + "_" + intString(idepth) , tp , {});
12771278 eqn = BackendDAE . SOLVED_EQUATION (cr, e1, DAE . emptyElementSource, BackendDAE . EQ_ATTR_DEFAULT_UNKNOWN );
12781279 e = Expression . crefExp(cr);
12791280 exP = Expression . makePureBuiltinCall("$_initialGuess" ,{e},tp);
12801281 e_1 = Expression . makePureBuiltinCall("$_signNoNull" ,{exP},tp);
1281- lhsF = Expression . factors(inExp2);
1282- (singCall,_) = List . split1OnTrue(lhsF, Expression . isFunCall, "$_signNoNull" );
1283- b = listLength(singCall) == 0 ;
1284- eqnForNewVars_ = if b then eqn::ieqnForNewVars else ieqnForNewVars;
1285- newVarsCrefs_ = if b then cr ::inewVarsCrefs else inewVarsCrefs;
1282+ eqnForNewVars_ = eqn::ieqnForNewVars;
1283+ newVarsCrefs_ = cr ::inewVarsCrefs;
12861284 lhs = Expression . expPow(inExp2,DAE . BINARY (Expression . makeConstOne(tp),DAE . DIV (tp),e2));
1287- lhs = if b then Expression . expMul(e_1,lhs) else lhs;
1288- then(e1, lhs, true , eqnForNewVars_, newVarsCrefs_);
1285+ lhs = Expression . expMul(e_1, lhs) ;
1286+ then(e1, lhs, true , eqnForNewVars_, newVarsCrefs_, idepth + 1 );
12891287
1290- else (inExp1, inExp2, false , ieqnForNewVars, inewVarsCrefs);
1288+ else (inExp1, inExp2, false , ieqnForNewVars, inewVarsCrefs, idepth );
12911289 end matchcontinue;
12921290
12931291end preprocessingSolveTmpVarsWork;
12941292
12951293
1296-
12971294protected function solveIfExp
12981295"
12991296 solve:
0 commit comments