Skip to content

Commit

Permalink
Merged R1903 BRANCH into trunk
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1937 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x02lucpo committed Oct 31, 2005
1 parent a943e76 commit 7a6afdf
Show file tree
Hide file tree
Showing 6 changed files with 604 additions and 311 deletions.
158 changes: 101 additions & 57 deletions Compiler/Ceval.rml
Expand Up @@ -94,6 +94,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

end


with "DAELow.rml"
with "SimCodegen.rml"
with "Static.rml"
Expand Down Expand Up @@ -1129,36 +1130,42 @@ end
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("jacobian"),[Exp.CREF(cr,_)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg)
=> (Values.STRING(res),Interactive.SYMBOLTABLE(p,sp,ic',iv,cf))

rule translate_model(env,cr,st) => (ret_val,st',_,_)
rule translate_model(env,cr,st,msg,filenameprefix) => (ret_val,st',_)
-------------------------
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("translateModel"),
[Exp.CREF(cr,_)],_,_),
[Exp.CREF(cr,_),filenameprefix],_,_),
st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg)
=> (ret_val,st')(*(Values.STRING("The model have been translated"),st')*)


rule build_model(env,exp,st',msg) => (cname_str,method_str,st)
rule build_model(env,exp,st',msg) => (executable,method_str,st,initfilename)
-------------------------------
ceval_interactive_functions (env, exp as Exp.CALL(Absyn.IDENT("buildModel"),
[Exp.CREF(cr,_),
starttime,stoptime,interval,method],_,_),
starttime,
stoptime,
interval,
method,
filenameprefix],_,_),
st' as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg)
=> (Values.STRING(cname_str),st)

=> (Values.ARRAY([Values.STRING(executable),
Values.STRING(initfilename)]),st)


rule (* FIXME: Should ceval be called with impl=true here? *)
(* Build and simulate model *)

build_model(env,exp,st',msg) => (cname_str,method_str,st) &
build_model(env,exp,st',msg) => (executable,method_str,st,_) &

win_citation() => cit &
System.path_delimiter => pd &
Util.string_append_list([cit,".", pd, cname_str, " -m ",
Util.string_append_list([cit,".", pd, executable, " -m ",
method_str," >> output.log 2>&1",
cit]) => sim_call &
System.system_call(sim_call) => _ &

Util.string_append_list([cname_str,"_res.plt"]) => result_file &
Util.string_append_list([executable,"_res.plt"]) => result_file &

let simValue = Values.RECORD(Absyn.IDENT("SimulationResult"),[Values.STRING(result_file)],["resultFile"]) &
let simType = (Types.T_COMPLEX(ClassInf.RECORD("SimulationResult")
Expand All @@ -1176,7 +1183,7 @@ end
------------------------------------------------------------------
ceval_interactive_functions (env, exp as Exp.CALL(Absyn.IDENT("simulate"),
[Exp.CREF(cr,_),
starttime,stoptime,interval,method],_,_),
starttime,stoptime,interval,method,filenameprefix],_,_),
st' as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg)
=> (simValue,newst)

Expand Down Expand Up @@ -1524,28 +1531,30 @@ end

end

relation generate_makefilename:(Exp.ComponentRef) => string =
relation generate_makefilename:(string) => string =

rule Static.component_ref_to_path(cr) => classname &
Absyn.path_string(classname) => cname_str &
Util.string_append_list([cname_str,".makefile"]) => makefilename
rule Util.string_append_list([filenameprefix,".makefile"]) => makefilename
----------------------------
generate_makefilename(cr) => makefilename
generate_makefilename(filenameprefix) => makefilename

end

(**relation translate_model
**author: x02lucpo
**
**translates a model into cpp code and writes also a makefile
**)
relation translate_model: (Env.Env,
Exp.ComponentRef, (* component ref for model *)
Interactive.InteractiveSymbolTable)
=> (Values.Value, Interactive.InteractiveSymbolTable,
DAELow.DAELow,Absyn.Path) =
**author: x02lucpo
**
**translates a model into cpp code and writes also a makefile
**)
relation translate_model: (Env.Env,
Exp.ComponentRef, (* component ref for model *)
Interactive.InteractiveSymbolTable,
Msg,
Exp.Exp)

rule Static.component_ref_to_path(cr) => classname &
=> (Values.Value, Interactive.InteractiveSymbolTable,
DAELow.DAELow) =

rule extract_file_prefix(env,fileprefix,st,msg) => filenameprefix &
Static.component_ref_to_path(cr) => classname &
SCode.elaborate(p) => p' &
Inst.instantiate_class(p',classname) => (dae as DAE.DAE(dael),env) &
Interactive.add_instantiated_class(ic,Interactive.INSTCLASS(classname,dael,env))
Expand All @@ -1555,33 +1564,62 @@ relation translate_model: (Env.Env,
DAELow.transpose_matrix(m) => mT &
DAELow.matching_algorithm(dlow,m,mT,(DAELow.INDEX_REDUCTION,DAELow.EXACT))
=> (ass1,ass2,dlow',m,mT) &
DAELow.strong_components(m,mT,ass1,ass2) => (comps) &
DAELow.strong_components(m,mT,ass1,ass2) => (comps) &
DAELow.translate_dae (dlow') => indexed_dlow &
DAELow.calculate_values(indexed_dlow) => indexed_dlow' &
Absyn.path_string(classname) => cname_str &
Util.string_append_list([cname_str,".cpp"]) => filename &
Util.string_append_list([cname_str,"_functions.cpp"]) => funcfilename &
generate_makefilename(cr) => makefilename &
SimCodegen.generate_functions(p',dae,indexed_dlow',classname,funcfilename) &
SimCodegen.generate_simulation_code(dae,indexed_dlow',ass1,ass2,m,mT,comps,classname,filename) &
SimCodegen.generate_makefile(makefilename,classname)
Util.string_append_list([filenameprefix,".cpp"]) => filename &
Util.string_append_list([filenameprefix,"_functions.cpp"]) => funcfilename &
generate_makefilename(filenameprefix) => makefilename &
SimCodegen.generate_functions(p',dae,indexed_dlow',classname,funcfilename) &
SimCodegen.generate_simulation_code(dae,indexed_dlow',ass1,ass2,m,mT,comps,classname,filename,funcfilename) &
SimCodegen.generate_makefile(makefilename,filenameprefix)
(* Util.string_append_list(["make -f ",cname_str, ".makefile\n"]) => s_call &
*)
---------------------------------------------
translate_model (env, cr,
st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf))
---------------------------------------------
translate_model (env,
cr,
st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),
msg,
fileprefix)
=> (Values.STRING("The model have been translated"),st,
indexed_dlow',
classname)

rule
---------------------------------------------
translate_model (env, cr,
st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf))
indexed_dlow')

rule Print.print_error_buf("# translate_model failed\n")
---------------------------------------------
translate_model (env, cr,
st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),
_,
_)
=> fail

end

(** relation extract_file_prefix
** author: x02lucpo
**
** extracts the file_prefix from Exp.Exp as string
**)
relation extract_file_prefix:(Env.Env,
Exp.Exp,
Interactive.InteractiveSymbolTable,
Msg)
=> (string) =

rule ceval(env,filenameprefix,true,SOME(st),NONE,msg)
=> (Values.STRING(prefix_str),SOME(st))
----------------------------------
extract_file_prefix(env,
filenameprefix,
st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),
msg)
=> prefix_str

rule
----------------------------------
extract_file_prefix(_,_,_,_) => fail
end

(**relation calculate_simulation_settings
**author: x02lucpo
**
Expand All @@ -1595,9 +1633,11 @@ relation calculate_simulation_settings: (Env.Env,Exp.Exp,
real, (* start time*)
real, (* stop time *)
real, (* step size *)
string (* method*) ) =
string (* method*)) =

rule ceval(env,starttime,true,SOME(st),NONE,msg)
rule ceval(env,filenameprefix,true,SOME(st),NONE,msg)
=> (Values.STRING(prefix_str),SOME(st)) &
ceval(env,starttime,true,SOME(st),NONE,msg)
=> (Values.REAL(starttime_r),SOME(st)) &
ceval(env,stoptime,true,SOME(st),NONE,msg)
=> (Values.REAL(stoptime_r),SOME(st)) &
Expand All @@ -1608,18 +1648,18 @@ relation calculate_simulation_settings: (Env.Env,Exp.Exp,
real_sub(stoptime_r,starttime_r) => delta_time &
int_real(interval_i) => interval_r &
real_div(delta_time,interval_r) => stepsize_r &
Util.string_append_list([cname_str,"_init.txt"]) => init_filename
Util.string_append_list([prefix_str,"_init.txt"]) => init_filename
---------------------------------
calculate_simulation_settings(env,
Exp.CALL(_,
[Exp.CREF(cr,_),
starttime,stoptime,interval,method],_,_),
starttime,stoptime,interval,method,filenameprefix],_,_),
st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),
msg,
cname_str)
=> (init_filename,starttime_r,stoptime_r,stepsize_r,method_str)

rule
rule Print.print_error_buf("# calculate_simulation_settings failed\n")
----------------------------------
calculate_simulation_settings(_,_,_,_,_) => fail

Expand All @@ -1632,22 +1672,24 @@ end
**)
relation build_model:(Env.Env,
Exp.Exp, (* component ref for model *)
Interactive.InteractiveSymbolTable,Msg)
Interactive.InteractiveSymbolTable,
Msg)
=> (string, (*classname*)
string,
Interactive.InteractiveSymbolTable) (*method*) =
string, (*method*)
Interactive.InteractiveSymbolTable,
string) (*initfilename*) =

rule translate_model(env,cr,st') => (ret_val, st,indexed_dlow',classname) &

rule translate_model(env,cr,st',msg,fileprefix) => (ret_val, st,indexed_dlow') &
Static.component_ref_to_path(cr) => classname &
Absyn.path_string(classname) => cname_str &

calculate_simulation_settings(env,exp,st,msg,cname_str) => (init_filename,starttime_r,
stoptime_r,stepsize_r,method_str) &

SimCodegen.generate_init_data(indexed_dlow',classname,init_filename,
starttime_r,stoptime_r,stepsize_r) &

generate_makefilename(cr) => makefilename &
extract_file_prefix(env,fileprefix,st,msg) => filenameprefix &
generate_makefilename(filenameprefix) => makefilename &
(* Util.string_append_list(["make -f ",cname_str, ".makefile\n"]) => s_call &
*)

Expand All @@ -1662,12 +1704,14 @@ relation build_model:(Env.Env,

System.system_call(s_call) => 0
-------------------------------------------
build_model(env,exp as Exp.CALL(Absyn.IDENT("simulate"),
build_model(env,exp as Exp.CALL(Absyn.IDENT(_),
[Exp.CREF(cr,_),
starttime,stoptime,interval,method],_,_)
,st',msg) => (cname_str,method_str,st)
starttime,stoptime,interval,method,fileprefix],_,_),
st',
msg)
=> (filenameprefix,method_str,st,init_filename)

rule
rule Print.print_error_buf("# build_model failed\n")
-----------------------------------------
build_model(_,_,_,_) => fail
end
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Main.rml
Expand Up @@ -503,9 +503,9 @@ relation simcodegen: (Absyn.Path, (* classname *)
Util.string_append_list([cname_str,"_init.txt"]) => init_filename &
Util.string_append_list([cname_str,".makefile"]) => makefilename &
SimCodegen.generate_functions(p,dae,indexed_dlow',classname,funcfilename) &
SimCodegen.generate_simulation_code(dae,indexed_dlow',ass1,ass2,m,mt,comps,classname,filename) &
SimCodegen.generate_simulation_code(dae,indexed_dlow',ass1,ass2,m,mt,comps,classname,filename,funcfilename) &
SimCodegen.generate_init_data(indexed_dlow',classname,init_filename,0.0,1.0,0.01) &
SimCodegen.generate_makefile(makefilename,classname)
SimCodegen.generate_makefile(makefilename,cname_str)
----------------------------------------------------------------------------------
simcodegen(classname,p,dae,dlow,ass1,ass2,m,mt,comps)

Expand Down

0 comments on commit 7a6afdf

Please sign in to comment.