@@ -1336,6 +1336,9 @@ algorithm
13361336 newVarsCrefs_ = cr::inewVarsCrefs;
13371337 else
13381338 e = e1;
1339+ if b2 then
1340+ e = Expression . negate(e);
1341+ end if ;
13391342 eqnForNewVars_ = ieqnForNewVars;
13401343 newVarsCrefs_ = inewVarsCrefs;
13411344 end if ;
@@ -1356,6 +1359,43 @@ algorithm
13561359 e2 = Expression . makePureBuiltinCall("log" ,{e3},DAE . T_REAL_DEFAULT );
13571360 then (e1,e2,true ,eqnForNewVars_,newVarsCrefs_,idepth + 1 );
13581361
1362+ // cos(y) = x -> y = acos(x) + 2*pi*k
1363+ case (DAE . CALL (path = Absyn . IDENT (name = "cos" ),expLst = {e1}),_)
1364+ equation
1365+ true = expHasCref(e1, inExp3);
1366+ false = expHasCref(inExp2, inExp3);
1367+ tp = Expression . typeof(e1);
1368+
1369+ cr = ComponentReference . makeCrefIdent("$TMP_VAR_SOLVE_COS_FOR_EQN_" + intString(uniqueEqIndex) + "_" + intString(idepth), tp , {});
1370+ newVarsCrefs_ = cr ::inewVarsCrefs;
1371+
1372+ eqn = BackendDAE . SOLVED_EQUATION (cr, e1, DAE . emptyElementSource, BackendDAE . EQ_ATTR_DEFAULT_UNKNOWN );
1373+ eqnForNewVars_ = eqn::ieqnForNewVars;
1374+
1375+ e = Expression . crefExp(cr);
1376+ exP = Expression . makePureBuiltinCall("$_initialGuess" , {e}, tp);
1377+
1378+ cr = ComponentReference . makeCrefIdent("$TMP_VAR_SOLVE_COS_INV_FOR_EQN_" + intString(uniqueEqIndex) + "_" + intString(idepth), tp , {});
1379+ newVarsCrefs_ = cr ::newVarsCrefs_;
1380+
1381+ e2 = Expression . makePureBuiltinCall("acos" , {inExp2}, tp);
1382+ ee2 = Expression . makePureBuiltinCall("$_signNoNull" , {exP}, tp);
1383+
1384+ eqn = BackendDAE . SOLVED_EQUATION (cr, Expression . expMul(ee2,e2), DAE . emptyElementSource, BackendDAE . EQ_ATTR_DEFAULT_UNKNOWN );
1385+ eqnForNewVars_ = eqn::eqnForNewVars_;
1386+
1387+ e2 = Expression . crefExp(cr);
1388+ ee1 = DAE . RCONST (6 . 283185307179586476925286766559005768394338798750211641949889 );
1389+
1390+ e_1 = Expression . makeDiv(Expression . expSub(exP, e2), ee1);
1391+
1392+ e3 = Expression . makePureBuiltinCall("$_round" , {e_1}, tp);
1393+
1394+ lhs = Expression . expAdd(Expression . expMul(e3, ee1),e2);
1395+
1396+ then(e1, lhs, true , eqnForNewVars_, newVarsCrefs_, idepth + 1 );
1397+
1398+
13591399 // abs(f(x)) = g(y) -> f(x) = sign(f(x))*g(y)
13601400 case (DAE . CALL (path = Absyn . IDENT (name = "abs" ),expLst = {e1}), _)
13611401 equation
@@ -1374,6 +1414,9 @@ algorithm
13741414 lhs = Expression . expMul(e_1, inExp2);
13751415 else
13761416 lhs = inExp2;
1417+ if b2 then
1418+ lhs = Expression . negate(lhs);
1419+ end if ;
13771420 eqnForNewVars_ = ieqnForNewVars;
13781421 newVarsCrefs_ = inewVarsCrefs;
13791422 end if ;
@@ -1397,6 +1440,9 @@ algorithm
13971440 lhs = Expression . expMul(e_1, lhs);
13981441 else
13991442 lhs = Expression . expPow(inExp2,Expression . inverseFactors(e2));
1443+ if b2 then
1444+ lhs = Expression . negate(lhs);
1445+ end if ;
14001446 eqnForNewVars_ = ieqnForNewVars;
14011447 newVarsCrefs_ = inewVarsCrefs;
14021448 end if ;
0 commit comments