Skip to content

Commit

Permalink
added sorting of equations and a check for switching the name of dumm…
Browse files Browse the repository at this point in the history
…y der in case of tornado from "der_<name>" to "_D_<name>

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1372 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x02lucpo committed Dec 22, 2004
1 parent 1c8386e commit 9cdece4
Showing 1 changed file with 161 additions and 7 deletions.
168 changes: 161 additions & 7 deletions modeq/daelow.rml
Expand Up @@ -45,7 +45,7 @@ module DAELow:
DAE.InstDims *
DAE.StartValue * (* value of start attribute *)
int * (* index in impl. vector *)
string *(* original variable name *)
string *(* original variable name *)
Absyn.Path (* classname variable belongs to *)


Expand Down Expand Up @@ -92,7 +92,8 @@ module DAELow:

relation dump: DAELow => ()
relation dump_vars: Var list => ()

relation dump_eqns: Equation list => ()

relation lower: (DAE.DAElist) => DAELow

relation incidence_matrix: (DAELow) => IncidenceMatrix
Expand Down Expand Up @@ -141,6 +142,7 @@ with "types.rml"
with "explode.rml"
with "dump.rml"
with "system.rml"
with "rtopts.rml"

val empty_bintree = TREENODE(NONE,NONE,NONE)

Expand All @@ -149,7 +151,8 @@ relation lower: (DAE.DAElist) => DAELow =
rule states(lst,empty_bintree) => s &
lower2(lst,s) => (low as DAELOW(vars,knvars,eqns,reqns)) &
(* print "lowered dae:" & dump low &*)
remove_simple_equations(low,s) => low'
remove_simple_equations(low,s) => daeUnsorted &
sort_eqn(daeUnsorted) => low'
(* & print "removed simple equations, dae:" &
dump low' *)
(*list_length(vars) => varlen &
Expand All @@ -165,6 +168,53 @@ relation lower: (DAE.DAElist) => DAELow =
end



(** relation sort_eqn
** This relation sorts the equation. It puts first the algebraic eqns
** and last the differentiated eqns
**
**
**)
relation sort_eqn : DAELow => DAELow =

rule extract_algebraic_and_differential_eqn(eqns) => (algEqns,diffEqns) &
(*print "ALGEBRAIC EQUATIONS\n" &
dump_eqns(algEqns) &
print "\n\nDIFFERENTIATED EQUATIONS\n" &
dump_eqns(diffEqns) &*)
list_append(algEqns,diffEqns) => res
---------------------------------------
sort_eqn(dae as DAELOW(vars,varKnList,eqns,simpleEqns))
=> DAELOW(vars,varKnList,res,simpleEqns)


rule print "sort_eqn failed \n"
---------------------------------------
sort_eqn(dae) => fail
end

relation extract_algebraic_and_differential_eqn: (Equation list) => (Equation list,Equation list) =

rule
---------------------------------------
extract_algebraic_and_differential_eqn([]) => ([],[])

rule is_algebraic(exp1) => true &
is_algebraic(exp2) => true &
extract_algebraic_and_differential_eqn(rest) => (resAlgEqn,resDiffEqn)
---------------------------------------
extract_algebraic_and_differential_eqn((eqn as EQUATION(exp1,exp2))::rest)
=> (eqn::resAlgEqn,resDiffEqn)

rule
extract_algebraic_and_differential_eqn(rest) => (resAlgEqn,resDiffEqn)
---------------------------------------
extract_algebraic_and_differential_eqn((eqn as EQUATION(exp1,exp2))::rest)
=> (resAlgEqn,eqn::resDiffEqn)

end


relation dump: DAELow => () =

rule print "Variables\n" &
Expand Down Expand Up @@ -1603,11 +1653,17 @@ end

relation create_dummy_var: (Exp.ComponentRef) => Exp.ComponentRef =

rule string_append("der_",id) => id'
rule RTOpts.tornado_cg => true &
string_append("_D_",id) => id'
-------------------------------
create_dummy_var(Exp.CREF_IDENT(id,subs))
=> Exp.CREF_IDENT(id',subs)

rule string_append("der_",id) => id'
-------------------------------
create_dummy_var(Exp.CREF_IDENT(id,subs))
=> Exp.CREF_IDENT(id',subs)

rule create_dummy_var(cr) => cr'
------------------------
create_dummy_var(Exp.CREF_QUAL(id,subs,cr))
Expand Down Expand Up @@ -1710,15 +1766,15 @@ relation differentiate_eqns: (DAELow,
Derive.differentiate_equation_time(eqn,timevars) => eqn' &
(* update equation row in IncidenceMatrix *)
Debug.fprint("bltdump", "High index problem, differentiated equation: " )&
print "differentiated equation " &
(*print "differentiated equation " &
equation_str eqn => str &
print str & print "\n" &
Debug.fprint("bltdump", str) &
Debug.fprint("bltdump", " to ") &
equation_str eqn' => str &
print " to " & print str & print "\n" &
Debug.fprint("bltdump",str) &
Debug.fprint("bltdump", "\n") &
Debug.fprint("bltdump", "\n") &*)
list_append(eqns,[eqn']) => eqns' &
list_length(eqns') => leneqns & (* length gives index of new equation *)
differentiate_eqns(DAELOW(v,kv,eqns',seqns),m,mt,nv,nf,es)
Expand Down Expand Up @@ -3005,4 +3061,102 @@ relation bintree_to_list_opt: (BinTree option, Key list, Value list)
---------------------------------------------
bintree_to_list_opt(SOME(bt),klst,vlst) => (klst,vlst)
end



relation is_algebraic : (Exp.Exp) => bool =

axiom is_algebraic(Exp.END) => true

axiom is_algebraic(Exp.ICONST(x)) => true

axiom is_algebraic(Exp.RCONST(x)) => true

axiom is_algebraic(Exp.SCONST(s)) => true

axiom is_algebraic(Exp.BCONST(false)) => true

axiom is_algebraic(Exp.BCONST(true)) => true

axiom is_algebraic(Exp.CREF(c,_)) => true

rule is_algebraic (e1) => true &
is_algebraic (e2) => true
------------------------
is_algebraic (Exp.BINARY(e1, op as Exp.SUB(ty), e2 as Exp.BINARY(e21, Exp.SUB(ty2), e22))) => true

rule is_algebraic (e1) => true &
is_algebraic (e2) => true
------------------------
is_algebraic (Exp.BINARY(e1, op, e2)) => true

rule is_algebraic (e) => true
----------------------------
is_algebraic(Exp.UNARY(op, e)) => true

rule is_algebraic (e1) => true &
is_algebraic (e2) => true
----------------------------------------------------------------
is_algebraic(Exp.LBINARY(e1, op, e2)) => true

rule is_algebraic (e) => true
---------------------------------------------------
is_algebraic(Exp.LUNARY(op, e)) => true

rule is_algebraic(e1) => true &
is_algebraic(e2) => true
-----------------------------------------------------------------
is_algebraic(Exp.RELATION(e1, op, e2)) => true

rule is_algebraic(c) => true &
is_algebraic(t) => true &
is_algebraic(f) => true
----------------------------
is_algebraic(Exp.IFEXP(c,t,f)) => true

axiom is_algebraic(Exp.CALL(Absyn.IDENT("der"), args,_,_)) => false

axiom is_algebraic(Exp.CALL(fcn, args,_,_)) => true


axiom is_algebraic (Exp.ARRAY(_,_,es)) => true

axiom is_algebraic (Exp.TUPLE(es)) => true

axiom is_algebraic (Exp.MATRIX(_,_,es)) => true

rule is_algebraic (start) => true &
is_algebraic (stop) => true
-------------------------------------------------------------
is_algebraic (Exp.RANGE(_,start,NONE,stop)) => true

rule is_algebraic (start) => true &
is_algebraic (step) => true &
is_algebraic (stop) => true
-------------------------------------
is_algebraic (Exp.RANGE(_,start,SOME(step),stop)) => true

axiom is_algebraic (Exp.CAST(REAL,Exp.ICONST(ival))) => true

axiom is_algebraic (Exp.CAST(REAL,Exp.UNARY(Exp.UMINUS(_),Exp.ICONST(ival)))) => true

axiom is_algebraic (Exp.CAST(Exp.REAL,e)) => true

axiom is_algebraic (Exp.CAST(Exp.REAL,e)) => true

rule is_algebraic (e) => true
---------------------------------------
is_algebraic (Exp.ASUB(e,i)) => true

axiom is_algebraic (Exp.SIZE(cr,SOME(dim))) => true

axiom is_algebraic (Exp.SIZE(cr,NONE)) => true

axiom is_algebraic (Exp.REDUCTION(fcn,exp,id,iterexp)) => true

axiom is_algebraic (_) => true

end




0 comments on commit 9cdece4

Please sign in to comment.