Skip to content

Commit

Permalink
-Added constrain() with vector arguments
Browse files Browse the repository at this point in the history
- Added simplification to propagate noEvent operator on expressions down to relation subexpressions
-Added symbolic expansion of skew function

git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/MathCoreOSMC@3905 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Feb 20, 2009
1 parent aeb5542 commit b53e94f
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 126 deletions.
10 changes: 9 additions & 1 deletion Compiler/Builtin.mo
Expand Up @@ -2519,6 +2519,14 @@ protected constant tuple<Types.TType, Option<Type_a>> array1dimrealarray1dimreal
("z",(Types.T_ARRAY(Types.DIM(SOME(1)),(Types.T_REAL({}),NONE)),NONE))
},
(Types.T_REAL({}),NONE)),NONE);
protected constant tuple<Types.TType, Option<Type_a>> array1dimrealarray1dimrealarray1dimreal2array1dimreal=(
Types.T_FUNCTION(
{
("x",(Types.T_ARRAY(Types.DIM(SOME(1)),(Types.T_REAL({}),NONE)),NONE)),
("y",(Types.T_ARRAY(Types.DIM(SOME(1)),(Types.T_REAL({}),NONE)),NONE)),
("z",(Types.T_ARRAY(Types.DIM(SOME(1)),(Types.T_REAL({}),NONE)),NONE))
},
(Types.T_ARRAY(Types.DIM(SOME(1)),(Types.T_REAL({}),NONE)),NONE)),NONE);
protected constant tuple<Types.TType, Option<Type_a>> realrealreal2real=(
Types.T_FUNCTION(
{
Expand Down Expand Up @@ -3230,7 +3238,7 @@ algorithm
env = Env.extendFrameT(env, "mod", intInt2int);
env = Env.extendFrameT(env, "mod", realReal2real);
env = Env.extendFrameT(env, "constrain", realrealreal2real);
env = Env.extendFrameT(env, "constrain", intintint2int);
env = Env.extendFrameT(env, "constrain", array1dimrealarray1dimrealarray1dimreal2array1dimreal);
/*
env = Env.extendFrameT(env, "semiLinear", realRealReal2real);
env = Env.extendFrameT(env, "delay", realReal2real);
Expand Down
12 changes: 10 additions & 2 deletions Compiler/DAE.mo
Expand Up @@ -5579,6 +5579,8 @@ algorithm (traversedDaeList,Type_a) := matchcontinue(daeList,func,extraArg)
list<list<Element>> tbs,tbs_1;
list<Exp.Exp> conds,conds_1;
Stream st;
Absyn.Path path;
list<Exp.Exp> expl;
case({},_,extraArg) then ({},extraArg);
case(VAR(cr,kind,dir,prot,tp,optExp,dims,fl,st,clsLst,attr,cmt,io,ftp)::dae,func,extraArg)
equation
Expand Down Expand Up @@ -5687,8 +5689,14 @@ algorithm (traversedDaeList,Type_a) := matchcontinue(daeList,func,extraArg)
equation
(e11,extraArg) = func(e1,extraArg);
(dae2,extraArg) = traverseDAE(dae,func,extraArg);
then (TERMINATE(e11)::dae2,extraArg);

then (TERMINATE(e11)::dae2,extraArg);

case(NORETCALL(path,expl)::dae,func,extraArg)
equation
(expl,extraArg) = traverseDAEExpList(expl,func,extraArg);
(dae2,extraArg) = traverseDAE(dae,func,extraArg);
then (NORETCALL(path,expl)::dae2,extraArg);

case(REINIT(cr,e1)::dae,func,extraArg)
equation
(e11,extraArg) = func(e1,extraArg);
Expand Down
69 changes: 63 additions & 6 deletions Compiler/Exp.mo
Expand Up @@ -2086,7 +2086,7 @@ algorithm
local
Real v,rv;
Integer n,i_1,i;
Exp e,res,exp,c,f,t_1,f_1,e1_1,exp_1,e1,e_1,e2,e2_1,exp_2,exp_3,e3_1,e3;
Exp e,res,exp,c,f,t_1,f_1,e1_1,exp_1,e1,e_1,e2,e2_1,exp_2,exp_3,e3_1,e3,cond;
Type t,tp_1,tp,tp1,tp2,t1;
Boolean b,remove_if;
Ident idn;
Expand All @@ -2098,7 +2098,15 @@ algorithm
Operator op;
String before, after;
Real time1,time2;


/* noEvent propagated to relations */
case(CALL(Absyn.IDENT("noEvent"),{e},tpl,builtin,tp))
local Boolean tpl,builtin; Type tp;
equation
e1 = simplify1(stripNoEvent(e));
e2 = addNoEventToRelations(e1);
then e2;

case (CAST(ty = REAL(),exp=e ))
local Exp e; Real v;
equation
Expand All @@ -2122,6 +2130,11 @@ algorithm
res = ARRAY(tp,b,exps_1);
then
res;

case(CAST(tp,IFEXP(cond,e1,e2))) equation
e1_1 = simplify1(CAST(tp,e1));
e2_1 = simplify1(CAST(tp,e2));
then IFEXP(cond,e1_1,e2_1);

case (CAST(ty = tp,exp = e))
local list<list<tuple<Exp, Boolean>>> exps,exps_1;
Expand Down Expand Up @@ -2209,7 +2222,7 @@ algorithm
local
Exp ae1;
equation
e = simplifyAsub(e, i) "For arbitrary vector operations, e.g (a+b-c){1} => a{1}+b{1}-c{1}" ;
e = simplifyAsub(e, i) "For arbitrary vector operations, e.g (a+b-c)[1] => a[1]+b[1]-c[1]" ;
then
e;

Expand Down Expand Up @@ -2303,7 +2316,47 @@ algorithm
end matchcontinue;
end simplify1;

protected function simplifyCref
public function stripNoEvent
" Function that strips all noEvent() calls in an expression"
input Exp e;
output Exp outE;
algorithm
((outE,_)) := traverseExp(e,stripNoEventExp,0);
end stripNoEvent;

protected function stripNoEventExp "
traversal function for stripNoEvent"
input tuple<Exp,Integer/*dummy*/> inTpl;
output tuple<Exp,Integer> outTpl;
algorithm
outTpl := matchcontinue(inTpl)
local Exp e; Integer i;
case((CALL(path=Absyn.IDENT("noEvent"),expLst={e}),i)) then ((e,i));
case((e,i)) then ((e,i));
end matchcontinue;
end stripNoEventExp;

public function addNoEventToRelations
" Function that adds a noEvent() call to all relations in an expression"
input Exp e;
output Exp outE;
algorithm
((outE,_)) := traverseExp(e,addNoEventToRelationExp,0);
end addNoEventToRelations;

protected function addNoEventToRelationExp "
traversal function for addNoEventToRelations"
input tuple<Exp,Integer/*dummy*/> inTpl;
output tuple<Exp,Integer> outTpl;
algorithm
outTpl := matchcontinue(inTpl)
local Exp e; Integer i;
case((e as RELATION(exp1=_),i)) then ((CALL(Absyn.IDENT("noEvent"),{e},false,true,BOOL()),i));
case((e,i)) then ((e,i));
end matchcontinue;
end addNoEventToRelationExp;

protected function simplifyCref
" Function for simplifying
x[{y,z,q}] to {x[y], x[z], x[q]}"
input ComponentRef inCREF;
Expand Down Expand Up @@ -3660,7 +3713,7 @@ algorithm
outExp:=
matchcontinue (inExp,inInteger)
local
Exp e_1,e,e1_1,e2_1,e1,e2,exp;
Exp e_1,e,e1_1,e2_1,e1,e2,exp,cond;
Type t,t_1,t2;
Integer indx,i_1,n;
Operator op,op2;
Expand Down Expand Up @@ -3875,6 +3928,10 @@ algorithm
e_1 = simplify1(ASUB(e,{ae1}));
then
e_1;
case(e as IFEXP(cond,e1,e2),indx) equation
e1_1 = simplifyAsub(e1, indx);
e2_1 = simplifyAsub(e2, indx);
then IFEXP(cond,e1_1,e2_1);
end matchcontinue;
end simplifyAsub;

Expand Down Expand Up @@ -6948,7 +7005,7 @@ algorithm str := matchcontinue(oexp)
case(SOME(e)) local Exp e; then printExpStr(e);
end matchcontinue;
end printOptExpStr;

public function printExpStr
"function: printExpStr
This function prints a complete expression."
Expand Down
25 changes: 23 additions & 2 deletions Compiler/Inst.mo
Expand Up @@ -8214,10 +8214,13 @@ algorithm

case (cache,env,mod,pre,csets,ci_state,SCode.EQ_NORETCALL(cr,fargs),initial_,impl)
local Exp.ComponentRef cr_2; Exp.Type t; Absyn.Path path; list<Exp.Exp> expl; Absyn.FunctionArgs fargs;
Exp.Exp exp;
equation
(cache,Exp.CALL(path,expl,_,_,_),_,_) = Static.elabExp(cache,env,Absyn.CALL(cr,fargs),impl,NONE,false);
(cache,exp,_,_) = Static.elabExp(cache,env,Absyn.CALL(cr,fargs),impl,NONE,false);
(cache,exp) = Prefix.prefixExp(cache,env,exp,pre);
dae = instEquationNoRetCallVectorization(exp);
then
(cache,{DAE.NORETCALL(path,expl)},env,csets,ci_state);
(cache,dae,env,csets,ci_state);

case (_,env,_,_,_,_,eqn,_,impl)
equation
Expand All @@ -8229,6 +8232,24 @@ algorithm
end matchcontinue;
end instEquationCommon;

protected function instEquationNoRetCallVectorization "creates DAE for NORETCALLs and also performs vectorization if needed"
input Exp.Exp expCall;
output list<DAE.Element> dae;
algorithm
dae := matchcontinue(expCall)
local Absyn.Path fn; list<Exp.Exp> expl; Exp.Type ty; Boolean s; Exp.Exp e;
list<DAE.Element> dae1,dae2;
case(expCall as Exp.CALL(path=fn,expLst=expl)) then {DAE.NORETCALL(fn,expl)};
case(Exp.ARRAY(ty,s,e::expl)) equation
dae1 = instEquationNoRetCallVectorization(Exp.ARRAY(ty,s,expl));
dae2 = instEquationNoRetCallVectorization(e);
dae = listAppend(dae1,dae2);
then dae;
case(Exp.ARRAY(ty,s,{})) equation
then {};
end matchcontinue;
end instEquationNoRetCallVectorization;

protected function makeDAEArrayEqToReinitForm "
Author: BZ, 2009-02
Function for transforming DAE equations into DAE.REINIT form, used by instEquationCommon
Expand Down

0 comments on commit b53e94f

Please sign in to comment.