Changeset c572316 in OpenModelica


Ignore:
Timestamp:
2012-11-15T23:41:47+01:00 (11 years ago)
Author:
Jens Frenkel <jens.frenkel@…>
Branches:
Added-citation-metadata, maintenance/v1.14, maintenance/v1.15, maintenance/v1.16, maintenance/v1.17, maintenance/v1.18, maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, maintenance/v1.23, master, omlib-staging
Children:
0fda3e2
Parents:
92c84b1
Message:
  • ExpressionSolve: ab = f(..) -> a = sign(pre(a))*(f(...)(1/b))

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13911 f25d12d1-65f4-0310-ae8a-bbce733d8d8e

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Compiler/BackEnd/ExpressionSolve.mo

    r92c84b1 rc572316  
    311311      DAE.ComponentRef cr,cr1;
    312312      DAE.Exp invCr;
    313       DAE.Type tp;
     313      DAE.Type tp,tp1;
    314314      list<DAE.Exp> factors;
    315315      list<DAE.Statement> asserts;
     
    373373      then
    374374        (rhs,asserts);
     375       
     376    // a^b = f(..) -> a = sign(pre(a))*(f(...)^(1/b))   
     377    case (_,_,DAE.CREF(componentRef = cr),_)
     378      equation
     379        e = Expression.makeDiff(inExp1,inExp2);
     380        ((e,(_,false,SOME(DAE.BINARY(operator=DAE.POW(tp1),exp2 = a))))) = Expression.traverseExpTopDown(e, traversingVarOnlyinPow, (cr,false,NONE()));
     381        tp = Expression.typeof(e);
     382        (z,_) = Expression.makeZeroExpression(Expression.arrayDimension(tp));
     383        (rhs,asserts) = solve(e,z,inExp3);
     384        a = Expression.expDiv(DAE.RCONST(1.0),a);
     385        rhs = DAE.BINARY(rhs,DAE.POW(tp1),a);
     386        tp = Expression.typeof(inExp3);                   
     387        dere = Expression.makeBuiltinCall("pre",{inExp3},tp);
     388        dere = Expression.makeBuiltinCall("sign",{dere},DAE.T_INTEGER_DEFAULT);
     389        rhs = Expression.expMul(dere,rhs);
     390      then
     391        (rhs,asserts);       
    375392/*
    376393    case (_,_,DAE.CREF(componentRef = cr),_)
     
    415432end solve2;
    416433
     434protected function traversingVarOnlyinPow "
     435@author: Frenkel TUD 2011-04
     436Returns true if in the exp the componentRef is only in pow"
     437  input tuple<DAE.Exp, tuple<DAE.ComponentRef,Boolean,Option<DAE.Exp>>> inExp;
     438  output tuple<DAE.Exp, Boolean, tuple<DAE.ComponentRef,Boolean,Option<DAE.Exp>>> outExp;
     439algorithm
     440  outExp := matchcontinue(inExp)
     441    local
     442      Boolean b;
     443      DAE.ComponentRef cr,cr1;
     444      DAE.Exp e,e1,e2;
     445      Option<DAE.Exp> oe;
     446
     447    case ((e as DAE.BINARY(exp1 = e1 as DAE.CREF(componentRef = cr1),operator = DAE.POW(_),exp2 = e2), (cr,false,NONE())))
     448      equation
     449        true = ComponentReference.crefPrefixOf(cr1,cr);
     450        false = Expression.expHasCrefNoPreorDer(e2, cr);
     451      then
     452        ((e1,false,(cr,false,SOME(e))));
     453   
     454    case ((e as DAE.CREF(componentRef = cr1), (cr,false,oe)))
     455      equation
     456        b = ComponentReference.crefEqualNoStringCompare(cr,cr1);
     457      then
     458        ((e,not b,(cr,b,oe)));
     459   
     460    case ((e as DAE.CREF(componentRef = cr1), (cr,false,oe)))
     461      equation
     462        b = ComponentReference.crefPrefixOf(cr1,cr);
     463      then
     464        ((e,not b,(cr,b,oe)));   
     465   
     466    case (((e,(cr,b,oe)))) then ((e,not b,(cr,b,oe)));
     467   
     468  end matchcontinue;
     469end traversingVarOnlyinPow;
     470
    417471protected function generateAssert
    418472  input DAE.Exp inExp1;
     
    423477  output list<DAE.Statement> outAsserts;
    424478algorithm
    425   (outExp,outAsserts) := matchcontinue (inExp1,inExp2,inExp3,a,inAsserts)
     479  outAsserts := matchcontinue (inExp1,inExp2,inExp3,a,inAsserts)
    426480    local
    427481      DAE.Exp a,z;
Note: See TracChangeset for help on using the changeset viewer.