Skip to content

Commit

Permalink
Removed debug prints. Added initial_function call in solvers. Removed…
Browse files Browse the repository at this point in the history
… faulty impl. for functions returning one argument.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1886 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Aug 26, 2005
1 parent a7bfc7a commit 8e34775
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 51 deletions.
29 changes: 0 additions & 29 deletions Compiler/Codegen.rml
Expand Up @@ -711,22 +711,11 @@ end
**
** All Modelica functions translates to a C function returning all
** Modelica ouput parameters in a struct. This relation generates that struct.
** Exception: Functions only returning one value does not need a struct.
**)

relation generate_result_struct : (DAE.Element list, Absyn.Path)
=> string list =

(* functions with one return value *)
rule generate_return_type fpath => ptname &
generate_single_return_type outvar => (type_str) &
Util.string_append_list(["typedef ",ptname," ", type_str, ";\n"])
=> res
-----------------------------------------
generate_result_struct ([outvar], fpath) => [res]


(* functions with several return values *)
rule generate_return_type fpath => ptname &
generate_return_decls outvars => (var_strs,var_names) &
generate_return_defs (ptname,var_names,1) => defs &
Expand Down Expand Up @@ -822,24 +811,6 @@ relation generate_return_decl: DAE.Element => (string, string) =

end

(** relation: generate_single_return_type
**
** Helper relation to generate_result_struct
**)

relation generate_single_return_type: DAE.Element => (string) =

rule is_array var => is_a &
dae_type_str (typ,is_a) => typ_str
---------------------------------------------------
generate_single_return_type (var as DAE.VAR(id, DAE.VARIABLE, DAE.OUTPUT,
typ, initopt, inst_dims,start,
flow,class,dae_var_attr,comment))
=> typ_str

axiom generate_single_return_type (_) => ""
end

(** relation: is_array
**
** Returns true if variable is part of an array.
Expand Down
25 changes: 5 additions & 20 deletions Compiler/SimCodegen.rml
Expand Up @@ -732,7 +732,7 @@ relation generate_initial_value_code:(DAELow.DAELow) => string =
generate_ode_blocks(initial_dae',ass1,ass2,blocks)
=> (block_code,extra_funcs) &
Util.string_append_list([extra_funcs,
"\n/*\n*/\nvoid start_function(double *x, double *xd, double *y, double *p,\n",
"\n/*\n*/\nvoid initial_function(double *x, double *xd, double *y, double *p,\n",
" int nx, int ny, int np)\n",
"{\n",
block_code,
Expand Down Expand Up @@ -1456,14 +1456,10 @@ relation generate_functions: (SCode.Program, (* Needed to instantiate functions*

rule get_called_functions(dae, dlow) => funcpaths &
(*debug*) Debug.fprint("info", "Found called functions: ") &
print "found called functions: " &
(*debug*) Util.list_map(funcpaths, Absyn.path_string) => debugpathstrs &
(*debug*) Util.string_delimit_list(debugpathstrs, ", ") => debugpathstr &
print debugpathstr & print "\n" &
(*debug*) Debug.fprintln("info", debugpathstr) &
generate_functions_2(p,funcpaths) => funcelems &
DAE.dump_str DAE.DAE(funcelems) => str &
print "func DAE =" & print str & print "\n" &
Print.get_string => debugstr &
Print.clear_buf &
Codegen.generate_functions(DAE.DAE(funcelems)) &
Expand Down Expand Up @@ -1500,40 +1496,29 @@ relation generate_functions_3: (SCode.Program,

axiom generate_functions_3(_,[],allpaths) => ([])

rule print "entering generate_functions_3\n" &
Inst.instantiate_class_implicit(p,path) => (fdae,_) &
print "insted class\n" &
rule Inst.instantiate_class_implicit(p,path) => (fdae,_) &
let DAE.DAE([DAE.FUNCTION(_,dae,t)]) = fdae &
print "matched DAE function\n" &
let patched_dae = DAE.DAE([DAE.FUNCTION(path,dae,t)]) &
print "instantiated function. about to collect subfuncs\n" &
get_called_functions_in_function(path,patched_dae) => subfuncs &
append_nonpresent_paths(subfuncs,allpaths,paths)
=> (allpaths',paths') &
print "appended paths\n" &
generate_functions_3(p,paths',allpaths') => elts &
print "generated functions\n" &
list_append(elts,[DAE.FUNCTION(path,dae,t)]) => res
---------------------------------------
generate_functions_3(p,path::paths,allpaths) => res

rule print "entering generate_functions_3 external decl\n" &
Inst.instantiate_class_implicit(p,path) => (fdae,_) &
print "insted class\n" &
rule Inst.instantiate_class_implicit(p,path) => (fdae,_) &
let DAE.DAE([DAE.EXTFUNCTION(_,dae,t,extdecl)]) = fdae &
print "matched DAE function\n" &
let patched_dae = DAE.DAE([DAE.EXTFUNCTION(path,dae,t,extdecl)]) &
print "instantiated function. about to collect subfuncs\n" &
get_called_functions_in_function(path,patched_dae) => subfuncs &
append_nonpresent_paths(subfuncs,allpaths,paths)
=> (allpaths',paths') &
print "appended paths\n" &
generate_functions_3(p,paths',allpaths') => elts &
print "generated functions\n" &
list_append(elts,[DAE.EXTFUNCTION(path,dae,t,extdecl)]) => res
---------------------------------------
generate_functions_3(p,path::paths,allpaths) => res
rule print "generaet_functions_3 failed\n"

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

Expand Down
14 changes: 12 additions & 2 deletions c_runtime/simulation_runtime.cpp
Expand Up @@ -105,9 +105,14 @@ int euler_main(int argc,char** argv) {
read_input(argc,argv,x,xd,y,p,nx,ny,np,&start,&stop,&step);

long numpoints = long((stop-start)/step)+2;


// load default initial values.
double *data = initialize_simdata(numpoints,nx,ny);


// Calculate initial values from (fixed) start attributes and intial equation
// sections
initial_function(x,xd,y,p,nx,ny,np);

int npts_per_result=int((stop-start)/(step*(numpoints-2)));
long actual_points =0 ; // the number of actual points saved
int pt=0;
Expand Down Expand Up @@ -194,7 +199,12 @@ int dassl_main(int argc, char **argv)

numpoints = long((stop-start)/step)+2;

// load default initial values.
double *data = initialize_simdata(numpoints,nx,ny);

// Calculate initial values from (fixed) start attributes and intial equation
// sections
initial_function(x,xd,y,p,nx,ny,np);

t=start;
tout = t+step;
Expand Down
9 changes: 9 additions & 0 deletions c_runtime/simulation_runtime.h
Expand Up @@ -82,15 +82,24 @@ functionDAE_output(double *t, double *x, double *xprimne, double *y, double* p);
int
functionDAE_res(double *t, double *x, double *xprime, double *delta, long int *ires, double *rpar, long int* ipar);

// function for calculating states on explicit ODE form
void functionODE(double *x, double *xd, double *y, double *p,
int nx, int ny, int np, double *t);

// function for calculate initial values from initial equations
// and fixed start attibutes
void initial_function(double*x, double *xd, double*y, double*p,
int nx, int ny, int np);

// Adds a result to the simulation result data.
void add_result(double *data, double time,double *nx, double *ndx, double *y,
long nx, long ny, long *actual_points);

// stores the result on file.
void store_result(const char * filename, double*data,
long numpoints, long nx, long ny);

// euler numerical solver
void euler ( double *x, double *xd, double *y, double *p, double *data,
int nx, int ny, int np, double *time, double *step,
void (*f)(double*,// x
Expand Down

0 comments on commit 8e34775

Please sign in to comment.