Skip to content

Commit 2a1e499

Browse files
author
Peter Aronsson
committed
Fixed solving equation systems in output sections.
fixed listVariables bug (not considering builtin variable $echo) git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1953 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 9a90537 commit 2a1e499

File tree

6 files changed

+57
-99
lines changed

6 files changed

+57
-99
lines changed

Compiler/Ceval.rml

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,10 +1094,8 @@ end
10941094
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("typeOf"),[Exp.CREF(Exp.CREF_IDENT(varid,_),_)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg)
10951095
=> (Values.STRING(str),st)
10961096

1097-
rule let newst = Interactive.SYMBOLTABLE(Absyn.PROGRAM([],Absyn.TOP),[],[],[],[])
1098-
-------------------------------
1099-
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("clear"),[],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg)
1100-
=> (Values.BOOL(true),newst)
1097+
axiom ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("clear"),[],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg)
1098+
=> (Values.BOOL(true),Interactive.empty_symboltable)
11011099

11021100
rule let newst = Interactive.SYMBOLTABLE(p,fp,ic,[],cf)
11031101
-------------------------------
@@ -1706,17 +1704,8 @@ relation build_model:(Env.Env,
17061704
generate_makefilename(filenameprefix) => makefilename &
17071705
(* Util.string_append_list(["make -f ",cname_str, ".makefile\n"]) => s_call &
17081706
*)
1709-
1710-
System.path_delimiter => pd &
1711-
System.read_env("OPENMODELICAHOME") => omhome &
1712-
win_citation() => cit &
1713-
Util.string_append_list([cit,omhome, pd, "Compiler",
1714-
pd, "scripts", pd, "Compile ",
1715-
makefilename," > output.log 2>&1",cit
1716-
]) => s_call &
1717-
(*> output.log 2>&1 = redirect stderr to stdout and put it in output.log *)
1718-
1719-
System.system_call(s_call) => 0
1707+
compile_model(makefilename)
1708+
17201709
-------------------------------------------
17211710
build_model(env,exp as Exp.CALL(Absyn.IDENT(_),
17221711
[Exp.CREF(cr,_),
@@ -1730,6 +1719,36 @@ relation build_model:(Env.Env,
17301719
build_model(_,_,_,_) => fail
17311720
end
17321721

1722+
1723+
(** relation: compile_model
1724+
** author: PA
1725+
**
1726+
** Compiles a model given a makefilename, helper relation to build_model.
1727+
**)
1728+
relation compile_model: (string) => () =
1729+
1730+
rule System.path_delimiter => pd &
1731+
System.read_env("OPENMODELICAHOME") => omhome &
1732+
win_citation() => cit &
1733+
Util.string_append_list([cit,omhome, pd, "Compiler",
1734+
pd, "scripts", pd, "Compile ",
1735+
makefilename," > output.log 2>&1",cit
1736+
]) => s_call &
1737+
(*> output.log 2>&1 = redirect stderr to stdout and put it in output.log *)
1738+
1739+
System.system_call(s_call) => 0
1740+
--------------------------
1741+
compile_model(makefilename) => ()
1742+
1743+
(* compilation failed\n *)
1744+
rule System.read_file("output.log") => str &
1745+
Print.print_error_buf ("#Error building simulation code.\n buildlog:\n") &
1746+
Print.print_error_buf (str) &
1747+
Print.print_error_buf "\n"
1748+
--------------------------
1749+
compile_model(makefile_name) => fail
1750+
end
1751+
17331752
(** relation: win_citation
17341753
** author: PA
17351754
**

Compiler/Interactive.rml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ module Interactive:
8484
InteractiveVariable list * (*List of variables with values*)
8585
(Absyn.Path * Types.Type) list (* List of compiled functions, F.Q name + type*)
8686

87+
val empty_symboltable : InteractiveSymbolTable
88+
8789
relation evaluate: (InteractiveStmts, InteractiveSymbolTable, bool)
8890
=> (string,InteractiveSymbolTable)
8991
(* this is exported due to the need of using several interactive modules *)
@@ -163,6 +165,10 @@ with "Print.rml"
163165
with "System.rml"
164166
with "ClassLoader.rml"
165167
with "Ceval.rml"
168+
169+
170+
val empty_symboltable = SYMBOLTABLE(Absyn.PROGRAM([],Absyn.TOP),[],[],[IVAR("$echo",Values.BOOL(true),(Types.T_BOOL([]),NONE))],[])
171+
166172

167173
(** relation: evaluate
168174
**
@@ -372,6 +378,10 @@ end
372378

373379
axiom get_variable_list_str([]) => []
374380

381+
rule get_variable_list_str(vs)=> res
382+
----------------------------
383+
get_variable_list_str(IVAR("$echo",_,_)::vs) => res
384+
375385
rule get_variable_list_str(vs)=> res
376386
----------------------------
377387
get_variable_list_str(IVAR(p,_,_)::vs) => p::res

Compiler/Main.rml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ relation translate_file : string list => () =
346346
(* Modelica script file .mos *)
347347
rule is_modelica_script_file(f) &
348348
Parser.parseexp f => stmts &
349-
Interactive.evaluate(stmts,Interactive.SYMBOLTABLE(Absyn.PROGRAM([],Absyn.TOP),[],[],[],[]),true) => (res,newst) &
349+
Interactive.evaluate(stmts,Interactive.empty_symboltable,true) => (res,newst) &
350350
print res
351351
------------------------------
352352
translate_file [f]
@@ -559,7 +559,7 @@ end
559559
relation interactivemode: string list => () =
560560

561561
rule Socket.waitforconnect 29500 => shandle &
562-
server_loop (shandle, Interactive.SYMBOLTABLE(Absyn.PROGRAM([],Absyn.TOP),[],[],[],[])) => _
562+
server_loop (shandle, Interactive.empty_symboltable) => _
563563
-------------------
564564
interactivemode _
565565
end
@@ -572,7 +572,7 @@ end
572572
relation interactivemode_corba: string list => () =
573573

574574
rule Corba.initialize &
575-
server_loop_corba (Interactive.SYMBOLTABLE(Absyn.PROGRAM([],Absyn.TOP),[],[],[],[])) => _
575+
server_loop_corba (Interactive.empty_symboltable) => _
576576
-------------------
577577
interactivemode_corba _
578578
end

Compiler/SimCodegen.rml

Lines changed: 6 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,9 +2290,9 @@ relation generate_zero_crossing: (string,
22902290

22912291
rule
22922292
generate_zero_crossing2(zc,0,dae,dlow,ass1,ass2,blocks,helpVarInfo) => (zc_str,zc_eq_str) &
2293-
generate_ode_blocks(dlow,ass1,ass2,blocks) => (eqs_str,_) &
2293+
generate_ode_blocks(dlow,ass1,ass2,blocks) => (eqs_str,extra_funcs) &
22942294
generate_helpvar_updates(helpVarInfo) => helpvarUpdateStr &
2295-
Util.string_append_list([
2295+
Util.string_append_list([extra_funcs,
22962296
"\nint\nfunction_zeroCrossing(long *neqm, double *t, double *x, long *ng, double *gout,\n"
22972297
," double *rpar, long* ipar)\n"
22982298
,"{\n"
@@ -2577,9 +2577,10 @@ end
25772577

25782578
rule let func_header = "int\nfunctionDAE_output(double *t, double* x, double* xd, double* y, double* p)\n{\n" &
25792579
let func_footer = "return 0;\n\n}\n" &
2580-
build_solved_blocks(dae,dlow,ass1,ass2,blocks) => eqn_str_lst &
2581-
generate_compute_removed_eqns(dlow) => eqn_str_lst2 &
2582-
Util.list_flatten([[func_header],eqn_str_lst, eqn_str_lst2,
2580+
(*build_solved_blocks(dae,dlow,ass1,ass2,blocks) => eqn_str_lst &*)
2581+
generate_ode_blocks(dlow,ass1,ass2,blocks) => (body,extra_funcs) &
2582+
generate_compute_removed_eqns(dlow) => body2 &
2583+
Util.list_flatten([[extra_funcs],[func_header],[body], body2,
25832584
[func_footer]]) => res &
25842585
Util.string_append_list(res) => coutput
25852586
-------------------------------------------------------------
@@ -2616,78 +2617,6 @@ relation generate_compute_removed_eqns_2: DAELow.Equation list => string list =
26162617
=> s1::res
26172618
end
26182619

2619-
2620-
(** relation: build_solved_blocks
2621-
**
2622-
** This relation generates code for blocks on solved form, i.e.
2623-
** \dot{x} = f(x,y,t)
2624-
**)
2625-
2626-
relation build_solved_blocks:(DAE.DAElist,
2627-
DAELow.DAELow,
2628-
int vector, (* assignments1*)
2629-
int vector, (* assignments2*)
2630-
int list list (* list of blocks *))
2631-
=> string list =
2632-
2633-
axiom build_solved_blocks(_,_,_,_,[]) => []
2634-
2635-
rule (* for single equations *)
2636-
use_zerocrossing => true &
2637-
build_non_discrete_equation(dae,dlow,ass1,ass2,eqn) => eqn_str &
2638-
build_solved_blocks(dae,dlow,ass1,ass2,blocks) => res
2639-
-------------------------------------
2640-
build_solved_blocks(dae,dlow,ass1,ass2,(block as [eqn])::blocks) => eqn_str::res
2641-
2642-
rule (* for single equations *)
2643-
use_zerocrossing => false &
2644-
build_equation(dae,dlow,ass1,ass2,eqn) => eqn_str &
2645-
build_solved_blocks(dae,dlow,ass1,ass2,blocks) => res
2646-
-------------------------------------
2647-
build_solved_blocks(dae,dlow,ass1,ass2,(block as [eqn])::blocks) => eqn_str::res
2648-
2649-
2650-
rule (* for blocks *)
2651-
build_block(dae,dlow,ass1,ass1,block) => block_str &
2652-
build_solved_blocks(dae,dlow,ass1,ass2,blocks) => res
2653-
------------------
2654-
build_solved_blocks(dae,dlow,ass1,ass2,block::blocks) => block_str::res
2655-
2656-
rule print "-build_solved_blocks failed\n"
2657-
-----------------
2658-
build_solved_blocks(_,_,_,_,_) => fail
2659-
end
2660-
2661-
(** relation: build_block
2662-
**
2663-
** This relation returns the code string for solving a block of variables
2664-
** in the dae, i.e. a set of coupled equations.
2665-
** It is used both for state variables and algebraic variables.
2666-
**)
2667-
2668-
relation build_block: (DAE.DAElist,
2669-
DAELow.DAELow,
2670-
int vector, (* assignments1 *)
2671-
int vector, (* assignments2 *)
2672-
int list) (* block of equations*)
2673-
=> string =
2674-
2675-
rule all_same_algorithm(dlow,block) => true &
2676-
int_sub(e,1) => e' &
2677-
DAELow.equation_nth(eqns,e') => DAELow.ALGORITHM(indx,inputs,outputs) &
2678-
array_nth(alg,indx) => alg &
2679-
Codegen.generate_algorithm(DAE.ALGORITHM(alg),1)
2680-
=> (Codegen.CFUNCTION(_,_,_,_,_,_,stmt_strs,_),_) &
2681-
Util.string_delimit_list(stmt_strs,"\n") => res
2682-
---------------
2683-
build_block(dae,dlow as DAELow.DAELOW(_,_,eqns,_,_,alg,_),ass1,as2,block as e::_)
2684-
=> res
2685-
2686-
rule print "#Solving of equation systems not implemented yet.\n"
2687-
--------------------------
2688-
build_block(dae,dlow,ass1,ass2,block) => fail
2689-
end
2690-
26912620
(** relation: all_same_algorithm
26922621
**
26932622
** Checks that a block consists only of one algorithm in different -nodes-

Compiler/Static.rml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ relation elab_builtin_differentiate : (Env.Env, Absyn.Exp list, bool (*impl*))
19791979
Absyn.get_cref_from_exp(s2) => cref_list2 &
19801980
list_append(cref_list1,cref_list2) => cref_list &
19811981
absyn_cref_list_to_interactive_var_list(cref_list,
1982-
Interactive.SYMBOLTABLE(Absyn.PROGRAM([],Absyn.TOP),[],[],[],[]),
1982+
Interactive.empty_symboltable,
19831983
(Types.T_REAL([]),NONE)) => symbol_table &
19841984
Interactive.build_env_from_symboltable(symbol_table) => gen_env &
19851985
elab_exp (gen_env,s1,impl,NONE) => (s1', st,_) &
@@ -2008,7 +2008,7 @@ relation elab_builtin_simplify : (Env.Env, Absyn.Exp list, bool (*impl*))
20082008

20092009
rule Absyn.get_cref_from_exp(s1) => cref_list &
20102010
absyn_cref_list_to_interactive_var_list(cref_list,
2011-
Interactive.SYMBOLTABLE(Absyn.PROGRAM([],Absyn.TOP),[],[],[],[]),
2011+
Interactive.empty_symboltable,
20122012
(Types.T_REAL([]),NONE)) => symbol_table &
20132013
Interactive.build_env_from_symboltable(symbol_table) => gen_env &
20142014
elab_exp (gen_env,s1,impl,NONE) => (s1', st,_)
@@ -2019,7 +2019,7 @@ relation elab_builtin_simplify : (Env.Env, Absyn.Exp list, bool (*impl*))
20192019

20202020
rule Absyn.get_cref_from_exp(s1) => cref_list &
20212021
absyn_cref_list_to_interactive_var_list(cref_list,
2022-
Interactive.SYMBOLTABLE(Absyn.PROGRAM([],Absyn.TOP),[],[],[],[]),
2022+
Interactive.empty_symboltable,
20232023
(Types.T_INTEGER([]),NONE)) => symbol_table &
20242024
Interactive.build_env_from_symboltable(symbol_table) => gen_env &
20252025
elab_exp (gen_env,s1,impl,NONE) => (s1', st,_)

flat_modelica_parser/src/flatmodelicaTokenTypes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// $ANTLR 2.7.4: flat_modelica_lexer.g -> flatmodelicaTokenTypes.txt$
1+
// $ANTLR 2.7.5 (20050213): flat_modelica_lexer.g -> flatmodelicaTokenTypes.txt$
22
flatmodelica // output token vocab name
33
ALGORITHM="algorithm"=4
44
AND="and"=5

0 commit comments

Comments
 (0)