Skip to content

Commit

Permalink
Replace MM trig functions with Modelica equivalents
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25079 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Mar 13, 2015
1 parent 89457a0 commit 9863ec8
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 164 deletions.
2 changes: 1 addition & 1 deletion Compiler/BackEnd/Differentiate.mo
Expand Up @@ -1926,7 +1926,7 @@ algorithm
case (e0 as DAE.BINARY(exp1 = DAE.RCONST(real=r),operator = DAE.POW(tp),exp2 = e1), _, _, _, _)
equation
(de1, funcs) = differentiateExp(e1, inDiffwrtCref, inInputData, inDiffType, inFunctionTree);
r = realLn(r);
r = log(r);
e = DAE.BINARY(DAE.BINARY(e0,DAE.MUL(tp),DAE.RCONST(r)),DAE.MUL(tp),de1);
then
(e, funcs);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/ExpressionSolve.mo
Expand Up @@ -801,7 +801,7 @@ algorithm
true = r1 > 0.0;
false = Expression.isConstOne(e1);
true = expHasCref(e2, inExp3);
r = realLn(r2) / realLn(r1);
r = log(r2) / log(r1);
res = DAE.RCONST(r);
then
(e2, res, true);
Expand Down
6 changes: 3 additions & 3 deletions Compiler/BackEnd/HpcOmTaskGraph.mo
Expand Up @@ -5581,9 +5581,9 @@ protected
Integer int;
Real real;
algorithm
real := realMul(inReal,realPow(10.0,intReal(nIn)));
real := realFloor(real);
outReal := realDiv(real,realPow(10.0,intReal(nIn)));
real := inReal * (10.0 ^ nIn);
real := floor(real);
outReal := real / (10.0 ^ nIn);
end roundReal;

//--------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/Matching.mo
Expand Up @@ -3212,7 +3212,7 @@ algorithm
(ass1,ass2,isyst,ishared,inArg);
case (_,_,_,_,_,_,_,BackendDAE.EQSYSTEM(m=SOME(m),mT=SOME(mt)),_,_,_,_,_,_,_,_)
equation
lim = realInt(realMul(0.1,realSqrt(intReal(arrayLength(ass1)))));
lim = integer(0.1 * sqrt(arrayLength(ass1)));
unmatched1 = ABMPphase(unmatched,i,nv,ne,m,mt,rowmarks,rlevel,colptrs,lim,ass1,ass2);
(i_1,unmatched1) = HKphase(i+1,unmatched,nv,ne,m,mt,rowmarks,collummarks,level,ass1,ass2,listLength(unmatched),{});
meqns = getEqnsforIndexReduction(unmatched1,ne,m,mt,ass1,ass2,inArg);
Expand Down
74 changes: 37 additions & 37 deletions Compiler/FrontEnd/Ceval.mo
Expand Up @@ -1274,70 +1274,70 @@ algorithm
case ("acos",{Values.REAL(real = rv)},_)
equation
true = rv >= -1.0 and rv <= 1.0;
rv_1 = realAcos(rv);
rv_1 = acos(rv);
then
Values.REAL(rv_1);
case ("asin",{Values.REAL(real = rv)},_)
equation
true = rv >= -1.0 and rv <= 1.0;
rv_1 = realAsin(rv);
rv_1 = asin(rv);
then
Values.REAL(rv_1);
case ("atan",{Values.REAL(real = rv)},_)
equation
rv_1 = realAtan(rv);
rv_1 = atan(rv);
then
Values.REAL(rv_1);
case ("atan2",{Values.REAL(real = rv1),Values.REAL(real = rv2)},_)
equation
rv_1 = realAtan2(rv1, rv2);
rv_1 = atan2(rv1, rv2);
then
Values.REAL(rv_1);
case ("cos",{Values.REAL(real = rv)},_)
equation
rv_1 = realCos(rv);
rv_1 = cos(rv);
then
Values.REAL(rv_1);
case ("cosh",{Values.REAL(real = rv)},_)
equation
rv_1 = realCosh(rv);
rv_1 = cosh(rv);
then
Values.REAL(rv_1);
case ("exp",{Values.REAL(real = rv)},_)
equation
rv_1 = realExp(rv);
rv_1 = exp(rv);
then
Values.REAL(rv_1);
case ("log",{Values.REAL(real = rv)},_)
equation
true = rv > 0;
rv_1 = realLn(rv);
rv_1 = log(rv);
then
Values.REAL(rv_1);
case ("log10",{Values.REAL(real = rv)},_)
equation
true = rv > 0;
rv_1 = realLog10(rv);
rv_1 = log10(rv);
then
Values.REAL(rv_1);
case ("sin",{Values.REAL(real = rv)},_)
equation
rv_1 = realSin(rv);
rv_1 = sin(rv);
then
Values.REAL(rv_1);
case ("sinh",{Values.REAL(real = rv)},_)
equation
rv_1 = realSinh(rv);
rv_1 = sinh(rv);
then
Values.REAL(rv_1);
case ("tan",{Values.REAL(real = rv)},_)
equation
rv_1 = realTan(rv);
rv_1 = tan(rv);
then
Values.REAL(rv_1);
case ("tanh",{Values.REAL(real = rv)},_)
equation
rv_1 = realTanh(rv);
rv_1 = tanh(rv);
then
Values.REAL(rv_1);

Expand Down Expand Up @@ -1754,7 +1754,7 @@ algorithm
case (cache,env,{exp},impl,st,msg,_)
equation
(cache,Values.REAL(rv),_) = ceval(cache,env,exp,impl,st,msg,numIter+1);
rv_1 = realExp(rv);
rv_1 = .exp(rv);
then
(cache,Values.REAL(rv_1),st);
end match;
Expand Down Expand Up @@ -2892,7 +2892,7 @@ algorithm
case (cache,env,{exp},impl,st,msg,_)
equation
(cache,Values.REAL(rv),_) = ceval(cache,env, exp, impl, st,msg,numIter+1);
rv_1 = realFloor(rv);
rv_1 = floor(rv);
then
(cache,Values.REAL(rv_1),st);
end match;
Expand Down Expand Up @@ -2928,7 +2928,7 @@ algorithm
equation
(cache,Values.REAL(rv),_) = ceval(cache, env, exp, impl, st, msg, numIter+1);

rv_1 = realFloor(rv);
rv_1 = floor(rv);
ri = realInt(rv_1);
rvt = intReal(ri);
ri_1 = ri + 1;
Expand Down Expand Up @@ -2975,7 +2975,7 @@ algorithm
Error.addSourceMessage(Error.NEGATIVE_SQRT, {}, info);
fail();
else
rv_1 = realSqrt(rv);
rv_1 = sqrt(rv);
end if;
then
(cache,Values.REAL(rv_1),st);
Expand Down Expand Up @@ -3009,7 +3009,7 @@ algorithm
case (cache,env,{exp},impl,st,msg,_)
equation
(cache,Values.REAL(rv),_) = ceval(cache,env, exp, impl, st,msg,numIter+1);
rv_1 = realSin(rv);
rv_1 = sin(rv);
then
(cache,Values.REAL(rv_1),st);
end match;
Expand Down Expand Up @@ -3041,7 +3041,7 @@ algorithm
case (cache,env,{exp},impl,st,msg,_)
equation
(cache,Values.REAL(rv),_) = ceval(cache,env, exp, impl, st,msg,numIter+1);
rv_1 = realSinh(rv);
rv_1 = sinh(rv);
then
(cache,Values.REAL(rv_1),st);
end match;
Expand Down Expand Up @@ -3073,7 +3073,7 @@ algorithm
case (cache,env,{exp},impl,st,msg,_)
equation
(cache,Values.REAL(rv),_) = ceval(cache,env, exp, impl, st,msg,numIter+1);
rv_1 = realCos(rv);
rv_1 = cos(rv);
then
(cache,Values.REAL(rv_1),st);
end match;
Expand Down Expand Up @@ -3105,7 +3105,7 @@ algorithm
case (cache,env,{exp},impl,st,msg,_)
equation
(cache,Values.REAL(rv),_) = ceval(cache,env, exp, impl, st,msg,numIter+1);
rv_1 = realCosh(rv);
rv_1 = cosh(rv);
then
(cache,Values.REAL(rv_1),st);
end match;
Expand Down Expand Up @@ -3138,7 +3138,7 @@ algorithm
equation
(cache,Values.REAL(rv),_) = ceval(cache,env, exp, impl, st,msg,numIter+1);
true = rv > 0; // TODO: Print error-message?
rv_1 = realLn(rv);
rv_1 = log(rv);
then
(cache,Values.REAL(rv_1),st);
end match;
Expand Down Expand Up @@ -3170,7 +3170,7 @@ algorithm
equation
(cache,Values.REAL(rv),_) = ceval(cache,env, exp, impl, st,msg,numIter+1);
true = rv > 0; // TODO: Print error-message?
rv_1 = realLog10(rv);
rv_1 = log10(rv);
then
(cache,Values.REAL(rv_1),st);
end match;
Expand Down Expand Up @@ -3202,7 +3202,7 @@ algorithm
case (cache,env,{exp},impl,st,msg,_)
equation
(cache,Values.REAL(rv),_) = ceval(cache,env, exp, impl, st,msg,numIter+1);
rv_1 = realTan(rv);
rv_1 = tan(rv);
then
(cache,Values.REAL(rv_1),st);
end match;
Expand Down Expand Up @@ -3234,7 +3234,7 @@ algorithm
case (cache,env,{exp},impl,st,msg,_)
equation
(cache,Values.REAL(rv),_) = ceval(cache,env, exp, impl, st,msg,numIter+1);
rv_1 = realTanh(rv);
rv_1 = tanh(rv);
then
(cache,Values.REAL(rv_1),st);
end match;
Expand Down Expand Up @@ -3267,7 +3267,7 @@ algorithm
equation
(cache,Values.REAL(rv),_) = ceval(cache,env, exp, impl, st,msg,numIter+1);
true = rv >= -1.0 and rv <= 1.0;
rv_1 = realAsin(rv);
rv_1 = asin(rv);
then
(cache,Values.REAL(rv_1),st);
end match;
Expand Down Expand Up @@ -3300,7 +3300,7 @@ algorithm
equation
(cache,Values.REAL(rv),_) = ceval(cache,env, exp, impl, st,msg,numIter+1);
true = rv >= -1.0 and rv <= 1.0;
rv_1 = realAcos(rv);
rv_1 = acos(rv);
then
(cache,Values.REAL(rv_1),st);
end match;
Expand Down Expand Up @@ -3332,7 +3332,7 @@ algorithm
case (cache,env,{exp},impl,st,msg,_) /* atan is not implemented in MetaModelica Compiler (MMC) for some strange reason. */
equation
(cache,Values.REAL(rv),_) = ceval(cache,env, exp, impl, st,msg,numIter+1);
rv_1 = realAtan(rv);
rv_1 = atan(rv);
then
(cache,Values.REAL(rv_1),st);
end match;
Expand Down Expand Up @@ -3364,7 +3364,7 @@ algorithm
equation
(cache,Values.REAL(rv_1),_) = ceval(cache,env, exp1, impl, st,msg,numIter+1);
(cache,Values.REAL(rv_2),_) = ceval(cache,env, exp2, impl, st,msg,numIter+1);
rv = realAtan2(rv_1,rv_2);
rv = atan2(rv_1,rv_2);
then
(cache,Values.REAL(rv),st);
end match;
Expand Down Expand Up @@ -3403,7 +3403,7 @@ algorithm
(cache,Values.REAL(rv2),_) = ceval(cache,env, exp2, impl, st,msg,numIter+1);
rv_1 = rv1 / rv2;
b = rv_1 < 0.0;
rv_2 = if b then realCeil(rv_1) else realFloor(rv_1);
rv_2 = if b then ceil(rv_1) else floor(rv_1);
then
(cache,Values.REAL(rv_2),st);
case (cache,env,{exp1,exp2},impl,st,msg,_)
Expand All @@ -3414,7 +3414,7 @@ algorithm
Error.addInternalError("cevalBuiltinDiv got Integer and Real (type error)\n", sourceInfo());
rv_1 = rv1 / rv2;
b = rv_1 < 0.0;
rv_2 = if b then realCeil(rv_1) else realFloor(rv_1);
rv_2 = if b then ceil(rv_1) else floor(rv_1);
then
(cache,Values.REAL(rv_2),st);
case (cache,env,{exp1,exp2},impl,st,msg,_)
Expand All @@ -3425,7 +3425,7 @@ algorithm
rv2 = intReal(ri);
rv_1 = rv1 / rv2;
b = rv_1 < 0.0;
rv_2 = if b then realCeil(rv_1) else realFloor(rv_1);
rv_2 = if b then ceil(rv_1) else floor(rv_1);
then
(cache,Values.REAL(rv_2),st);
case (cache,env,{exp1,exp2},impl,st,msg,_)
Expand Down Expand Up @@ -3500,7 +3500,7 @@ algorithm
(cache,Values.REAL(rv1),_) = ceval(cache,env, exp1, impl, st,msg,numIter+1);
(cache,Values.REAL(rv2),_) = ceval(cache,env, exp2, impl, st,msg,numIter+1);
rva = rv1 / rv2;
rvb = realFloor(rva);
rvb = floor(rva);
rvc = rvb * rv2;
rvd = rv1 - rvc;
then
Expand All @@ -3511,7 +3511,7 @@ algorithm
rv1 = intReal(ri);
(cache,Values.REAL(rv2),_) = ceval(cache,env, exp2, impl, st,msg,numIter+1);
rva = rv1 / rv2;
rvb = realFloor(rva);
rvb = floor(rva);
rvc = rvb * rv2;
rvd = rv1 - rvc;
then
Expand All @@ -3522,7 +3522,7 @@ algorithm
(cache,Values.INTEGER(ri),_) = ceval(cache,env, exp2, impl, st,msg,numIter+1);
rv2 = intReal(ri);
rva = rv1 / rv2;
rvb = realFloor(rva);
rvb = floor(rva);
rvc = rvb * rv2;
rvd = rv1 - rvc;
then
Expand All @@ -3534,10 +3534,10 @@ algorithm
rv1 = intReal(ri1);
rv2 = intReal(ri2);
rva = rv1 / rv2;
rvb = realFloor(rva);
rvb = floor(rva);
rvc = rvb * rv2;
rvd = rv1 - rvc;
ri_1 = realInt(rvd);
ri_1 = integer(rvd);
then
(cache,Values.INTEGER(ri_1),st);
case (cache,env,{exp1,exp2},impl,st,Absyn.MSG(info = info),_)
Expand Down

0 comments on commit 9863ec8

Please sign in to comment.