Skip to content

Commit

Permalink
- added error massage for 0^-n were n > 0
Browse files Browse the repository at this point in the history
- added some cases for solve
 - a^n = c where n is odd
 - log(a) = b
 - exp(a) = b



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20597 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Vitalij Ruge committed May 14, 2014
1 parent 2a436a6 commit cf2a74d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
65 changes: 65 additions & 0 deletions Compiler/BackEnd/ExpressionSolve.mo
Expand Up @@ -184,6 +184,8 @@ algorithm
local
DAE.ComponentRef cr,cr1;
DAE.Type tp;
DAE.Exp e1,e2;
Real r;
list<DAE.Statement> asserts;

// special case for inital system when already solved, cr1 = $_start(...)
Expand Down Expand Up @@ -225,6 +227,69 @@ algorithm
false = Expression.expHasDerCref(inExp2, cr);
then
(inExp1,{});

// log(a) = b => a = exp(b)
case (DAE.CALL(path = Absyn.IDENT(name = "log"),expLst = {DAE.CREF(componentRef = cr1)}),_,DAE.CREF(componentRef = cr))
equation
true = ComponentReference.crefEqual(cr, cr1);
false = Expression.expHasDerCref(inExp2, cr);
e2 = Expression.makeBuiltinCall("exp",{inExp2},DAE.T_REAL_DEFAULT);
then
(e2,{});

// b = log(a)=> a = exp(b)
case (_,DAE.CALL(path = Absyn.IDENT(name = "log"),expLst = {DAE.CREF(componentRef = cr1)}),DAE.CREF(componentRef = cr))
equation
true = ComponentReference.crefEqual(cr, cr1);
false = Expression.expHasDerCref(inExp1, cr);
e2 = Expression.makeBuiltinCall("exp",{inExp1},DAE.T_REAL_DEFAULT);
then
(e2,{});

// exp(a) = b => a = log(b)
case (DAE.CALL(path = Absyn.IDENT(name = "exp"),expLst = {DAE.CREF(componentRef = cr1)}),_,DAE.CREF(componentRef = cr))
equation
true = ComponentReference.crefEqual(cr, cr1);
false = Expression.expHasDerCref(inExp2, cr);
e2 = Expression.makeBuiltinCall("log",{inExp2},DAE.T_REAL_DEFAULT);
then
(e2,{});

// b = exp(a)=> a = exp(b)
case (_,DAE.CALL(path = Absyn.IDENT(name = "exp"),expLst = {DAE.CREF(componentRef = cr1)}),DAE.CREF(componentRef = cr))
equation
true = ComponentReference.crefEqual(cr, cr1);
false = Expression.expHasDerCref(inExp1, cr);
e2 = Expression.makeBuiltinCall("log",{inExp1},DAE.T_REAL_DEFAULT);
then
(e2,{});

// a^n = c => a = c^-n
// where n is odd
case (DAE.BINARY(DAE.CREF(componentRef = cr1),DAE.POW(tp),DAE.RCONST(r)), _, DAE.CREF(componentRef = cr))
equation
1.0 = realMod(r,2.0);
true = ComponentReference.crefEqual(cr, cr1);
false = Expression.expHasDerCref(inExp2, cr);
r = realNeg(r);
e1 = DAE.RCONST(r);
e2 = DAE.BINARY(inExp2,DAE.POW(tp),e1);
then
(e2,{});

// c = a^n => a = c^-n
// where n is odd
case (_, DAE.BINARY(DAE.CREF(componentRef = cr1),DAE.POW(tp),DAE.RCONST(r)), DAE.CREF(componentRef = cr))
equation
1.0 = realMod(r,2.0);
true = ComponentReference.crefEqual(cr, cr1);
false = Expression.expHasDerCref(inExp1, cr);
r = realNeg(r);
e1 = DAE.RCONST(r);
e2 = DAE.BINARY(inExp1,DAE.POW(tp),e1);
then
(e2,{});

// -cr = exp
case (DAE.UNARY(operator = DAE.UMINUS(ty=_), exp = DAE.CREF(componentRef = cr1)),_,DAE.CREF(componentRef = cr))
equation
Expand Down
6 changes: 5 additions & 1 deletion SimulationRuntime/c/util/utility.c
Expand Up @@ -31,6 +31,8 @@

#include "utility.h"
#include "modelica_string.h"
#include "simulation_data.h"
#include "../simulation/options.h"
#include <regex.h>
#include <string.h>

Expand All @@ -39,7 +41,9 @@ modelica_real real_int_pow(modelica_real base, modelica_integer n)
modelica_real result = 1.0;
modelica_integer m = n < 0;
if(m) {
n = -n;
if(base == 0.0)
errorStreamPrint(LOG_STDOUT, 0, "evaluation problem for 0^%i ",n);
n = -n;
}
while(n != 0) {
if((n % 2) != 0) {
Expand Down

0 comments on commit cf2a74d

Please sign in to comment.