Skip to content

Commit

Permalink
Fixed bug in model inputs. They can not be removed in remove_simple_e…
Browse files Browse the repository at this point in the history
…quations.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1823 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jun 22, 2005
1 parent cb6040a commit 0a2fbb8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 25 deletions.
12 changes: 6 additions & 6 deletions Compiler/Ceval.rml
Expand Up @@ -1047,13 +1047,13 @@ end
-------------------------------
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("clearCache"),[],_,_),st as Interactive.SYMBOLTABLE(p,fp,ic,iv,cf)) => (Values.BOOL(true),newst)

rule Dump.unparse_str(p,false) => str
rule Dump.unparse_str(p(*,false*)) => str
-------------------
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("list"),[],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf)) => (Values.STRING(str),st)

rule Static.component_ref_to_path(cr) => path &
Interactive.get_pathed_class_in_program(path,p) => class &
Dump.unparse_str(Absyn.PROGRAM([class],Absyn.TOP),false) => str
Dump.unparse_str(Absyn.PROGRAM([class],Absyn.TOP)(*,false*)) => str
-------------------
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("list"),[Exp.CREF(cr,_)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf)) => (Values.STRING(str),st)

Expand Down Expand Up @@ -1345,15 +1345,15 @@ end

rule Static.component_ref_to_path(cr) => classpath &
Interactive.get_pathed_class_in_program(classpath,p) => class &
Dump.unparse_str(Absyn.PROGRAM([class],Absyn.TOP),true) => str &
Dump.unparse_str(Absyn.PROGRAM([class],Absyn.TOP)(*,true*)) => str &
System.write_file(filename,str)
--------------------------
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("saveModel"),[Exp.SCONST(filename),Exp.CREF(cr,_)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf))
=> (Values.BOOL(true),st)

rule Static.component_ref_to_path(cr) => classpath &
Interactive.get_contained_class_and_file(classpath,p) => (p',filename) &
Dump.unparse_str(p',true) => str &
Dump.unparse_str(p'(*,true*)) => str &
System.write_file(filename,str)
--------------------------
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("save"),[Exp.CREF(cr,_)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf))
Expand All @@ -1362,7 +1362,7 @@ end
axiom ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("save"),[Exp.CREF(cr,_)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf))
=> (Values.BOOL(false),st)

rule Dump.unparse_str(p,true) => str &
rule Dump.unparse_str(p(*,true*)) => str &
System.write_file(filename,str)
--------------------------
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("saveAll"),[Exp.SCONST(filename)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf))
Expand All @@ -1371,7 +1371,7 @@ end
rule (*Error writing to file *)
Static.component_ref_to_path(cr) => classpath &
Interactive.get_pathed_class_in_program(classpath,p) => class &
Dump.unparse_str(Absyn.PROGRAM([class],Absyn.TOP),true) => str &
Dump.unparse_str(Absyn.PROGRAM([class],Absyn.TOP)(*,true*)) => str &
Print.print_error_buf "Error writing to file.\n"
--------------------------
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("saveModel"),[Exp.SCONST(name),Exp.CREF(cr,_)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf))
Expand Down
67 changes: 48 additions & 19 deletions Compiler/DAELow.rml
Expand Up @@ -1137,7 +1137,7 @@ relation remove_simple_equations: (Variables, (* vars *)
rule VarTransform.empty_replacements() => repl &
remove_simple_equations2(eqns,vars,knvars,empty_bintree,states,repl)
=> (eqns',seqns,movedvars',vartransf) &
(* VarTransform.dump_replacements(vartransf) => () & *)
(*VarTransform.dump_replacements(vartransf) => () & *)
VarTransform.replace_equations(eqns',vartransf) => eqns'' &
VarTransform.replace_equations(seqns,vartransf) => seqns' &
move_variables(vars,knvars,movedvars')=> (vars',knvars')
Expand Down Expand Up @@ -1182,7 +1182,7 @@ relation remove_simple_equations2: (Equation list, (* all equations*)
rule (* cr1 is state and cr2 not, remove cr2*)
simple_equation(e) => (cr1,cr2) &
(* is the variable to be removed is output the do not remove it *)
is_cref_for_val_on_top_leve_and_output(cr2,vars) => false &
is_top_level_input_or_output(cr2,vars,knvars) => false &

typeof_equation(e) => t &
VarTransform.apply_replacements(repl,cr1,cr2) => (cr1,cr2) &
Expand All @@ -1199,7 +1199,7 @@ relation remove_simple_equations2: (Equation list, (* all equations*)
rule (* as above but swapped args: cr1 is state and cr2 not, remove cr2*)
simple_equation(e) => (cr2,cr1) &
(* is the variable to be removed is output the do not remove it *)
is_cref_for_val_on_top_leve_and_output(cr2,vars) => false &
is_top_level_input_or_output(cr2,vars,knvars) => false &

typeof_equation(e) => t &
VarTransform.apply_replacements(repl,cr1,cr2) => (cr1,cr2) &
Expand All @@ -1217,7 +1217,7 @@ relation remove_simple_equations2: (Equation list, (* all equations*)
simple_equation(e) => (cr1,cr2) &
typeof_equation(e) => t &
(* is the variable to be removed is output the do not remove it *)
is_cref_for_val_on_top_leve_and_output(cr1,vars) => false &
is_top_level_input_or_output(cr1,vars,knvars) => false &

VarTransform.apply_replacements(repl,cr1,cr2) => (cr1,cr2) &
not VarTransform.get_replacement(repl,cr1) => _ &
Expand All @@ -1235,7 +1235,7 @@ relation remove_simple_equations2: (Equation list, (* all equations*)
simple_equation(e) => (cr2,cr1) &
typeof_equation(e) => t &
(* is the variable to be removed is output the do not remove it *)
is_cref_for_val_on_top_leve_and_output(cr1,vars) => false &
is_top_level_input_or_output(cr1,vars,knvars) => false &

VarTransform.apply_replacements(repl,cr1,cr2) => (cr1,cr2) &
not VarTransform.get_replacement(repl,cr1) => _ &
Expand All @@ -1253,7 +1253,7 @@ relation remove_simple_equations2: (Equation list, (* all equations*)
simple_equation(e) => (cr1,cr2) &
typeof_equation(e) => t &
(* is the variable to be removed is output the do not remove it *)
is_cref_for_val_on_top_leve_and_output(cr1,vars) => false &
is_top_level_input_or_output(cr1,vars,knvars) => false &

VarTransform.apply_replacements(repl,cr1,cr2) => (cr1,cr2) &
not VarTransform.get_replacement(repl,cr1) => _ &
Expand All @@ -1273,7 +1273,7 @@ relation remove_simple_equations2: (Equation list, (* all equations*)
simple_equation(e) => (cr1,cr2) &
typeof_equation(e) => t &
(* is the variable to be removed is output the do not remove it *)
is_cref_for_val_on_top_leve_and_output(cr1,vars) => false &
is_top_level_input_or_output(cr1,vars,knvars) => false &

VarTransform.apply_replacements(repl,cr1,cr2) => (cr1,cr2) &
not VarTransform.get_replacement(repl,cr1) => _ &
Expand All @@ -1297,21 +1297,36 @@ relation remove_simple_equations2: (Equation list, (* all equations*)
=> (e::eqns',seqns',mvars',repl')
end

(** rela-tion is_cref_for_val_on_top_leve_and_output
** this rela-tion checks if the provided cr is from a var that is on top model
** and has the DAE.VarDirection = OUTPUT
(** rela-tion is_top_level_input_or_output
** author: LP
**
** This rela-tion checks if the provided cr is from a var that is on top model
** and is an input or an output, and returns true for such variables.
** It also returns true for input/output connector variables, i.e. variables
** instantiated from a connector class, that are instantiated on the top level.
** The check for top-model is done by spliting the old name at '.' and
** check if the list-lenght is 1
** check if the list-lenght is 1.
** Note: The rela-tion needs the known variables to search for input variables
** on the top level.
**)
relation is_cref_for_val_on_top_leve_and_output:(Exp.ComponentRef, Variables) => bool =
relation is_top_level_input_or_output:(Exp.ComponentRef,
Variables, (* Variables*)
Variables(* Known Variables *))
=> bool =

rule get_var(cr,vars) => (VAR(cr,kind,DAE.OUTPUT,_,_,_,_,_,_,old_name,_,_,_),_) &
Util.string_split_at_char(old_name, #".") => cr_str_lst &
list_length(cr_str_lst) => 1
---------------------------------------------
is_cref_for_val_on_top_leve_and_output(cr,vars) => true
is_top_level_input_or_output(cr,vars,_) => true

axiom is_cref_for_val_on_top_leve_and_output(_,_) => false

rule (* input variables stored in known variables are input on top level *)
get_var(cr,knvars) => (VAR(cr,kind,DAE.INPUT,_,_,_,_,_,_,_,_,_,_),_)
--------------------------------------------------------------------
is_top_level_input_or_output(cr,vars,knvars) => true

axiom is_top_level_input_or_output(_,_,_) => false

end

Expand Down Expand Up @@ -2035,13 +2050,18 @@ end
**)
relation lower_known_var: (DAE.Element) => Var =

rule lower_known_varkind(kind,name,dir,flow) => kind' &
Exp.print_component_ref_str name => origname &
rule Exp.print_component_ref_str name => origname &
let newname = Exp.CREF_IDENT(origname,[]) &
lower_known_varkind(kind,name,dir,flow) => kind' &
lower_binding(bind) => bind' &
lower_binding(start) => start'
----------------------------------------
lower_known_var (DAE.VAR(name,kind,dir,tp,bind,dims,start,flow,class,dae_var_attr,comment))
=> VAR(Exp.CREF_IDENT(origname,[]),kind',dir,tp,bind',NONE,dims,start',-1,origname,class,dae_var_attr,comment)
=> VAR(newname,kind',dir,tp,bind',NONE,dims,start',-1,origname,class,dae_var_attr,comment)

rule print "-lower_known_var failed\n"
-------------------
lower_known_var(_) => fail
end

(** relation: lower_varkind
Expand Down Expand Up @@ -2103,10 +2123,10 @@ relation top_level_input: (Exp.ComponentRef,
--------------------
top_level_input(cr as Exp.CREF_IDENT(name,_), DAE.INPUT,_) => ()

(* Connector input variables at top level*)
(* Connector input variables at top level for crefs that are stringified*)
rule Util.string_split_at_char(name, #".") => cr_str_lst &
list_length(cr_str_lst) => len &
int_eq(len,2) => true
int_eq(len,2) => true
----------------------
top_level_input(Exp.CREF_IDENT(name,_), DAE.INPUT, DAE.NON_FLOW) =>()

Expand All @@ -2115,6 +2135,11 @@ relation top_level_input: (Exp.ComponentRef,
int_eq(len,2) => true
----------------------
top_level_input(Exp.CREF_IDENT(name,_), DAE.INPUT, DAE.FLOW) =>()

(* For crefs that are not yet stringified, e.g. lower_known_var *)
axiom top_level_input(Exp.CREF_QUAL(name,_,Exp.CREF_IDENT(_,_)), DAE.INPUT, DAE.FLOW) =>()
axiom top_level_input(Exp.CREF_QUAL(name,_,Exp.CREF_IDENT(_,_)), DAE.INPUT, DAE.NON_FLOW) =>()

end

(** relation: lower_known_varkind
Expand All @@ -2132,6 +2157,10 @@ relation lower_known_varkind: (DAE.VarKind,
rule top_level_input(cr,dir,flow)
------------------------
lower_known_varkind(DAE.VARIABLE,cr,dir,flow) => VARIABLE

rule print "lower_known_varkind failed\n"
----------------------
lower_known_varkind(_,_,_,_) => fail
end

(** relation: incidence_matrix
Expand Down
2 changes: 2 additions & 0 deletions Compiler/SimCodegen.rml
Expand Up @@ -287,6 +287,8 @@ relation generate_global_data:(Absyn.Path,DAELow.DAELow,int) => string =
"#if NP > 0\n",
"double p[NP];\n",
"#else\n",
"double *p;\n",
"#endif\n",
"#if NO > 0\n",
"double out_y[NO];\n",
"#else\n",
Expand Down

0 comments on commit 0a2fbb8

Please sign in to comment.