Skip to content

Commit

Permalink
Further fixes to ASUB bug in Exp.simlify.
Browse files Browse the repository at this point in the history
Added dummy state always present to make dassl happy if run with model without states.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1979 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Nov 23, 2005
1 parent bf0032f commit 39ff25a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
26 changes: 26 additions & 0 deletions Compiler/DAELow.rml
Expand Up @@ -356,6 +356,7 @@ relation lower: (DAE.DAElist) => DAELow =

rule states(lst,empty_bintree) => s &
lower2(lst,s,[]) => (vars,knvars,eqns,reqns,ieqns,algs,whenclauses) &
add_dummy_state(vars,eqns) => (vars,eqns) &
list_reverse whenclauses => whenclauses' &
lower_algorithms(vars,algs) => algeqns &
list_append(algeqns,eqns) => eqns &
Expand All @@ -373,6 +374,31 @@ relation lower: (DAE.DAElist) => DAELow =
=> DAELOW(vars',knvars,eqnarr,reqnarr,ieqnarr,algarr,EVENT_INFO(whenclauses',zero_crossings))
end

(** relation: add_dummy_state
**
** In order for the solver to work correctly at least one state variable
** must exist in the equation system. This relation therefore adds a
** dummy state variable and an equation for that variable.
**)
relation add_dummy_state: (Variables, (* vars*)
Equation list) (*eqns*)
=> (Variables,
Equation list) =

rule add_var(VAR(Exp.CREF_IDENT("$dummy",[]),STATE,DAE.BIDIR,DAE.REAL,
NONE,NONE,[],NONE,-1,"$dummy",[],NONE,NONE,
DAE.NON_CONNECTOR),vars) => vars'

-------------------
add_dummy_state(vars,eqns)
=> (vars',
EQUATION(Exp.CALL(Absyn.IDENT("der"),
[Exp.CREF(Exp.CREF_IDENT("$dummy",[]),Exp.REAL)],
false,
true),
Exp.RCONST(0.0))::eqns)
end

(** relation: dump_zc_str
**
** Dumps a zerocrossing into a string, for debugging purposes.
Expand Down
23 changes: 21 additions & 2 deletions Compiler/Exp.rml
Expand Up @@ -1404,11 +1404,30 @@ relation simplify_asub: (Exp, int) => Exp =
simplify_asub(BINARY(e1,DIV_ARRAY_SCALAR(t),e2),indx)
=> (BINARY(e1',DIV_ARRAY_SCALAR(t),e2'))

(* arbitrary binary expressions *)
rule simplify_asub(e1,indx) => e1' &
simplify_asub(e2,indx) => e2'
----------------------------
simplify_asub(BINARY(e1,ADD_ARR(t),e2),indx)
=> (BINARY(e1',ADD_ARR(t),e2'))

rule simplify_asub(e1,indx) => e1' &
simplify_asub(e2,indx) => e2'
----------------------------
simplify_asub(BINARY(e1,SUB_ARR(t),e2),indx)
=> (BINARY(e1',SUB_ARR(t),e2'))


rule int_sub (indx,1) => i' &
list_nth(exps,i') => exp
-----------------------
simplify_asub (ARRAY(t,b,exps),indx) => exp

rule int_sub (indx,1) => i' &
list_nth(exps,i') => (expl) &
Util.split_tuple2_list(expl) => (expl',bls) &
Util.bool_and_list(bls) => b
-----------------------
simplify_asub(BINARY(e1,op,e2),indx) => BINARY(e1',op,e2')
simplify_asub( MATRIX(t,n,exps),indx) => ARRAY(t,b,expl')

rule simplify(ASUB(e,indx)) => e'
--------------------------------
Expand Down

0 comments on commit 39ff25a

Please sign in to comment.