Skip to content

Commit

Permalink
Mainly Hemmis-related MathCore stuff
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1336 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Kaj Nyström committed Nov 8, 2004
1 parent 877953d commit 7c0d84e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 52 deletions.
4 changes: 1 addition & 3 deletions modeq/absyn.rml
Expand Up @@ -188,9 +188,7 @@ module Absyn:

(* Information on one (kind) of equation, different constructors for different
kinds of equations *)
datatype Equation = (* REMOVE - If noone complains, I will remove this 2004-11-01
EQ_EXPR of Exp One sided equations? *)
EQ_IF of Exp (* Conditional expression *)
datatype Equation = EQ_IF of Exp (* Conditional expression *)
* EquationItem list (* true branch *)
* (Exp * EquationItem list) list (* elseif branches *)
* EquationItem list (* else branch *)
Expand Down
11 changes: 1 addition & 10 deletions modeq/dump.rml
Expand Up @@ -1063,11 +1063,7 @@ end

relation print_equation: Absyn.Equation => () =

(* REMOVE - If noone complains, I will remove this 2004-11-01
rule Print.print_buf "EQ_EXPR(" & print_exp(e) & Print.print_buf ")"
-------------------------------------------
print_equation(Absyn.EQ_EXPR(e)) *)


rule Print.print_buf "IF (" & print_exp(e) & Print.print_buf ") THEN " &
print_list_debug("print_equation",tb, print_equationitem, ";") &
print_list_debug("print_equation",eb, print_eq_elseif, " ") &
Expand Down Expand Up @@ -1110,11 +1106,6 @@ end

relation unparse_equation_str: (int, Absyn.Equation) => string =

(* REMOVE - If noone complains, I will remove this 2004-11-01
rule print_exp_str(e) => str
-------------------------------------------
unparse_equation_str(i, Absyn.EQ_EXPR(e)) => str *)

rule print_exp_str(e) => s1 &
int_add(i,1) => i' &
unparse_equationitem_str_lst(i',tb,";\n") => s2 &
Expand Down
5 changes: 0 additions & 5 deletions modeq/dumpgraphviz.rml
Expand Up @@ -271,11 +271,6 @@ end

relation print_equation: Absyn.Equation => Node =

(* REMOVE - If noone complains, I will remove this 2004-11-01
rule Dump.print_exp_str e => s
------------------
print_equation (Absyn.EQ_EXPR(e)) => Graphviz.LNODE("EQ_EXPR",[s],[],[]) *)

rule Dump.print_exp_str e1 => s1 &
Dump.print_exp_str e2 => s2 &
string_append (s1, " = ") => s &
Expand Down
4 changes: 1 addition & 3 deletions modeq/explode.rml
Expand Up @@ -101,9 +101,7 @@ module SCode :
(* - Equations *)
datatype Equation = EQUATION of EEquation
* Absyn.Path option (*baseclassname if in bclass*)
datatype EEquation = (*REMOVE - If noone complains, I will remove this 2004-11-01
EQ_EXPR of Absyn.Exp (* more later? *)
| *)EQ_IF of Absyn.Exp (* conditional *)
datatype EEquation = EQ_IF of Absyn.Exp (* conditional *)
* EEquation list (* true branch *)
* EEquation list (* false branch *)
| EQ_EQUALS of Absyn.Exp * Absyn.Exp
Expand Down
22 changes: 0 additions & 22 deletions modeq/inst.rml
Expand Up @@ -3430,28 +3430,6 @@ relation inst_equation_common : (Env,Mod, Prefix, Connect.Sets, ClassInf.State,
initial)
=> (dae,env,csets',ci_state')

(** assert
**)

(* REMOVE - If noone complains, I will remove this 2004-11-01
rule Static.elab_exp(env,e,false,NONE) => (e', Types.PROP(t, c),_) &
inst_assertion (env, e', t, c, d, pre) => dae &
inst_equation_common_ci_trans (ci_state, initial) => ci_state'
--------------------------------------------------------------
inst_equation_common(env,mods,pre,csets, ci_state,
SCode.EQ_EXPR(Absyn.CALL(Absyn.CREF_IDENT("assert",[]),
Absyn.FUNCTIONARGS([e,Absyn.STRING(d)],[]))),
initial)
=> (dae,env,csets,ci_state') *)

(** Normal equations *)

(* REMOVE - If noone complains, I will remove this 2004-11-01
rule Print.print_buf "- No expression equations yet\n" &
inst_equation_common_ci_trans (ci_state, initial) => ci_state' (* but fail? *)
-------------------------------------
inst_equation_common(env,mods,pre,csets,ci_state,SCode.EQ_EXPR(_),initial) => fail *)

(** The following rule handles shadowed (replaced) equations. *)
(** If an equation has a simple name on the left-hand side, *)
(** and that component has an equation modifier, this equation *)
Expand Down
67 changes: 58 additions & 9 deletions modeq/tornado.rml
Expand Up @@ -50,7 +50,7 @@ relation generate_code: (Absyn.Program, DAE.DAElist, Absyn.Path) => () =
generate_var_defines(dae') => defines &
generate_compute_methods(cname,dae',p) => cmethods &
Util.string_append_list([implheader,constr,defines,cmethods]) => impl &
string_append(cname,".hpp") => headerfile &
string_append(cname,".h") => headerfile &
string_append(cname,".cpp") => implfile &
System.write_file(headerfile,header) &
System.write_file(implfile,impl)
Expand Down Expand Up @@ -196,6 +196,7 @@ relation generate_constructor_outputvars2:(DAELow.Var list,int) => string list =
--------------------
generate_constructor_outputvars2(DAELow.VAR(cr,VARIABLE,DAE.OUTPUT,_,_,_,_,start,_,_)::rest,i)
=> r1::res

rule generate_constructor_outputvars2(rest,i) => res
-----------------------------------------------
generate_constructor_outputvars2(_::rest,i)
Expand Down Expand Up @@ -265,15 +266,65 @@ end

relation generate_var_defines: (DAELow.DAELow) => string =

rule Util.string_append_list(["/*generate var defines here*/\n"]) => vdefs
rule generate_var_defines2(vars,0,0) => vdefs1list &
list_length(vdefs1list) => len &
int_sub(len,1) => len' &
Util.string_append_list(vdefs1list) => vdefs1 &
generate_var_defines2(knvars,0,0) => vdefs2list &
Util.string_append_list(vdefs2list) => vdefs2 &
Util.string_append_list(["#define _t_ m_IndepVarValues[0]\n",vdefs1,vdefs2,"\n"]) => vdefs
---------------------
generate_var_defines(dae) => vdefs
generate_var_defines(DAELow.DAELOW(vars,knvars,eqn,seqn)) => vdefs

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


(** Helper function for generate_var_defines
** Recursively traverses the list of variables and generates the defines
** in the tornado format for them.
** Arg1 is the list of variables
** Arg2 is the counter for Output variables
** Arg3 is the counter for DerState and derivative variables
**)
relation generate_var_defines2: (DAELow.Var list,int,int) => string list =

axiom generate_var_defines2([],_,_) => []

rule int_string(outputCounter) => outputCounterString &
Exp.cref_modelica_str(cr) => crs &
Util.string_append_list(["#define _",crs,"_ m_OutputVarValues[",outputCounterString,"]\n"]) => r1 &
int_add(outputCounter,1) => outputCounter' &
generate_var_defines2(rest,outputCounter',derStateCounter) => res
----------------------------------------------
generate_var_defines2(DAELow.VAR(cr,DAELow.VARIABLE,dir,_,_,_,_,_,_,_)::rest,
outputCounter,derStateCounter)
=> r1::res

rule int_string(derStateCounter) => derStateCounterString &
Exp.cref_modelica_str(cr) => crs &
Util.string_append_list(["#define _",crs,"_ m_DerStateVarValues[",derStateCounterString,"]\n",
"#define _D_",crs,"_ m_Derivatives[",derStateCounterString,"]\n"]) => r1 &
int_add(derStateCounter,1) => derStateCounter' &
generate_var_defines2(rest,outputCounter,derStateCounter') => res
----------------------------------------------
generate_var_defines2(DAELow.VAR(cr,DAELow.STATE,dir,_,_,_,_,_,_,_)::rest,
outputCounter,derStateCounter)
=> r1::res

rule generate_var_defines2(rest,outputCounter,derStateCounter) => res
-----------------------------------------------
generate_var_defines2(_::rest,outputCounter,derStateCounter) => res

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



(** relation: generate_compute_methods
** This relation generates the code for the computation of the equations
** They are separated into four parts.
Expand Down Expand Up @@ -373,15 +424,15 @@ relation generate_state_partition:(int list list,DAELow.DAELow) =>
int_string(state_component_number) => state_component_number_string &
print state_component_number_string &
print "\n" &
list_length(blt) => nr_of_components &
list_length(blt) => nr_of_components (*&
int_sub(nr_of_components,state_component_number) => component_offset &
print "(non-reversed): " &
int_string(component_offset) => component_offset_string &
print component_offset_string &
print "\n" &
Util.list_split(blt,component_offset) => (blt_states,blt_no_states)
Util.list_split(blt,component_offset) => (blt_states,blt_no_states) *)
-----------------------------------------
generate_state_partition(blt,dae) => (blt_states,blt_no_states)
generate_state_partition(blt,dae) => (reversed_blt,reversed_blt)

rule print "-generate_state_partition failed\n"
-----------------------------------------
Expand All @@ -404,9 +455,7 @@ relation has_state_var:(int, int list list, DAELow.DAELow) => int =
has_state_var(index,element::reversed_blt,dae) => index

(* If we have no more components return 0 *)
rule
-----------------------------------------
has_state_var(_,[],_) => 0
axiom has_state_var(_,[],_) => 0

rule (* If no statevars found in this component, continue with the next one*)
int_add(1,index) => next_index &
Expand Down

0 comments on commit 7c0d84e

Please sign in to comment.