Skip to content

Commit

Permalink
- Added arument to simulate: outputFormat=<string>
Browse files Browse the repository at this point in the history
  - Default is "plt", which is the old format. It's the only format currently capable of using simulation results within OMC. Other formats need external tools.
  - "csv" is another textual format. It's roughly twice as fast and uses no additional memory (plt uses several GB for large simulations).
  - "empty" does the same thing as interactive simulations - it disables result file generation. Useful for benchmarking.
  - "bin" is experimental and should not be used. It basically measures the overhead of converting doubles to strings (speed is 50x times faster than CSV)
- Model_init.txt has a new field for the output format
- The c_runtime contains the interface used for result file generation.
- Added testcases for "csv", "plt" and "empty" simulation results.
- Added these options to OMNotebook/OMShell commands.xml.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5737 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jun 28, 2010
1 parent 89eca8e commit 787f3b4
Show file tree
Hide file tree
Showing 25 changed files with 759 additions and 429 deletions.
96 changes: 29 additions & 67 deletions Compiler/CevalScript.mo
Expand Up @@ -115,7 +115,7 @@ algorithm
list<SCode.Class> p_1,sp,fp;
list<Env.Frame> env;
SCode.Class c;
String s1,str,varid,res,cmd,executable,method_str,initfilename,cit,pd,executableSuffixedExe,sim_call,result_file,
String s1,str,varid,res,cmd,executable,method_str,outputFormat_str,initfilename,cit,pd,executableSuffixedExe,sim_call,result_file,
omhome,pwd,filename_1,filename,omhome_1,plotCmd,tmpPlotFile,call,str_1,scriptstr,res_1,mp,pathstr,name,cname;
DAE.ComponentRef cr,fcr,cref,classname;
Interactive.InteractiveSymbolTable st,newst,st_1,st_2;
Expand Down Expand Up @@ -474,42 +474,22 @@ algorithm
case (cache,env,(exp as
DAE.CALL(
path = Absyn.IDENT(name = "buildModel"),
expLst =
{DAE.CODE(Absyn.C_TYPENAME(className),_),
starttime,
stoptime,
interval,
tolerance,
method,
filenameprefix,
storeInTemp,
noClean,
options})),
expLst = DAE.CODE(Absyn.C_TYPENAME(className),_)::_)),
(st_1 as Interactive.SYMBOLTABLE(
ast = p,
explodedAst = sp,
instClsLst = ic,
lstVarVal = iv,
compiledFunctions = cf)),msg)
equation
(cache,executable,method_str,st,initfilename) = buildModel(cache,env, exp, st_1, msg);
(cache,executable,method_str,outputFormat_str,st,initfilename) = buildModel(cache,env, exp, st_1, msg);
then
(cache,ValuesUtil.makeArray({Values.STRING(executable),Values.STRING(initfilename)}),st);

case (cache,env,(exp as
DAE.CALL(
path = Absyn.IDENT(name = "buildModel"),
expLst =
{
DAE.CODE(Absyn.C_TYPENAME(className),_),
starttime,
stoptime,
interval,
tolerance,
method,
filenameprefix,
storeInTemp,
noClean,options})),
expLst = DAE.CODE(Absyn.C_TYPENAME(className),_)::_)),
(st_1 as Interactive.SYMBOLTABLE(
ast = p,
explodedAst = sp,
Expand All @@ -519,8 +499,7 @@ algorithm
then (cache,ValuesUtil.makeArray({Values.STRING(""),Values.STRING("")}),st_1);

case (cache,env,(exp as
DAE.CALL( path = Absyn.IDENT(name = "buildModelBeast"), expLst = {DAE.CODE(Absyn.C_TYPENAME(className),_), starttime,
stoptime, interval, tolerance, method, filenameprefix, storeInTemp,noClean,options})),
DAE.CALL( path = Absyn.IDENT(name = "buildModelBeast"), expLst = DAE.CODE(Absyn.C_TYPENAME(className),_)::_)),
(st_1 as Interactive.SYMBOLTABLE( ast = p, explodedAst = sp, instClsLst = ic, lstVarVal = iv, compiledFunctions = cf)),msg)
equation
(cache,executable,method_str,st,initfilename) = buildModelBeast(cache,env, exp, st_1, msg);
Expand All @@ -530,8 +509,7 @@ algorithm
/* adrpo: see if the model exists before simulation! */
case (cache,env,(exp as
DAE.CALL(path = Absyn.IDENT(name = "simulate"),
expLst = {DAE.CODE(Absyn.C_TYPENAME(className),_),starttime,stoptime,interval,tolerance,method,filenameprefix,
storeInTemp,noClean,options})),
expLst = DAE.CODE(Absyn.C_TYPENAME(className),_)::_)),
(st_1 as Interactive.SYMBOLTABLE(
ast = p, explodedAst = sp, instClsLst = ic, lstVarVal = iv, compiledFunctions = cf)),msg)
local
Expand All @@ -550,17 +528,7 @@ algorithm
case (cache,env,(exp as
DAE.CALL(
path = Absyn.IDENT(name = "simulate"),
expLst =
{
DAE.CODE(Absyn.C_TYPENAME(className),_),
starttime,
stoptime,
interval,
tolerance,
method,
filenameprefix,
storeInTemp,
noClean,options})),
expLst = DAE.CODE(Absyn.C_TYPENAME(className),_)::_)),
(st_1 as Interactive.SYMBOLTABLE(
ast = p,
explodedAst = sp,
Expand All @@ -569,7 +537,7 @@ algorithm
compiledFunctions = cf)),msg)
local String s1; Absyn.ComponentRef cr_name;
equation
(cache,executable,method_str,st,_) = buildModel(cache,env, exp, st_1, msg) "Build and simulate model" ;
(cache,executable,method_str,outputFormat_str,st,_) = buildModel(cache,env, exp, st_1, msg) "Build and simulate model" ;
cit = winCitation();
pwd = System.pwd();
pd = System.pathDelimiter();
Expand All @@ -583,7 +551,7 @@ algorithm
sim_call = Util.stringAppendList({cit,executableSuffixedExe,cit," > output_" , s1 , ".log 2>&1"});
*/
0 = System.systemCall(sim_call);
result_file = Util.stringAppendList({executable,"_res.plt"});
result_file = Util.stringAppendList({executable,"_res.",outputFormat_str});
simValue = Values.RECORD(Absyn.IDENT("SimulationResult"),
{Values.STRING(result_file)},
{"resultFile"},-1);
Expand All @@ -600,17 +568,7 @@ algorithm
case (cache,env,
DAE.CALL(
path = Absyn.IDENT(name = "simulate"),
expLst =
{
DAE.CODE(Absyn.C_TYPENAME(className),_),
starttime,
stoptime,
interval,
tolerance,
method,
filenameprefix,
storeInTemp,
noClean,options}),
expLst = DAE.CODE(Absyn.C_TYPENAME(className),_)::_),
(st as Interactive.SYMBOLTABLE(
ast = p,
explodedAst = sp,
Expand All @@ -629,7 +587,7 @@ algorithm
(cache,simValue,st);

case (cache,env,DAE.CALL(path = Absyn.IDENT(name = "simulate"),
expLst = {DAE.CODE(Absyn.C_TYPENAME(className),_),starttime,stoptime,interval,tolerance,method,filenameprefix,noClean,options}),
expLst = DAE.CODE(Absyn.C_TYPENAME(className),_)::_),
(st as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
equation
simValue = Values.RECORD(Absyn.IDENT("SimulationResult"),
Expand Down Expand Up @@ -2420,6 +2378,7 @@ protected function calculateSimulationSettings "function calculateSimulationSett
output Real tolerance "tolerance";
output String outString5 "method";
output String optionsStr;
output String outputFormat_str;
algorithm
(outCache,outString1,outReal2,outReal3,outReal4,tolerance,outString5,optionsStr):=
matchcontinue (inCache,inEnv,inExp,inInteractiveSymbolTable,inMsg,inString)
Expand All @@ -2431,7 +2390,7 @@ algorithm
Real starttime_r,stoptime_r,interval_r,tolerance_r;
list<Env.Frame> env;
DAE.ComponentRef cr;
DAE.Exp starttime,stoptime,interval,toleranceExp,method,options,filenameprefix;
DAE.Exp starttime,stoptime,interval,toleranceExp,method,options,filenameprefix,outputFormat;
Absyn.Program p;
list<SCode.Class> sp;
list<Interactive.InstantiatedClass> ic;
Expand All @@ -2440,7 +2399,7 @@ algorithm
Ceval.Msg msg;
Env.Cache cache;
Absyn.Path className;
case (cache,env,DAE.CALL(expLst = {DAE.CODE(Absyn.C_TYPENAME(className),_),starttime,stoptime,interval,toleranceExp,method,filenameprefix,_,_,options}),
case (cache,env,DAE.CALL(expLst = {DAE.CODE(Absyn.C_TYPENAME(className),_),starttime,stoptime,interval,toleranceExp,method,filenameprefix,_,_,options,outputFormat}),
(st as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg,cname_str)
equation
(cache,Values.STRING(prefix_str),SOME(st)) = Ceval.ceval(cache,env, filenameprefix, true, SOME(st), NONE, msg);
Expand All @@ -2450,13 +2409,14 @@ algorithm
(cache,tolerance_v,SOME(st)) = Ceval.ceval(cache,env, toleranceExp, true, SOME(st), NONE, msg);
(cache,Values.STRING(method_str),SOME(st)) = Ceval.ceval(cache,env, method, true, SOME(st), NONE, msg);
(cache,Values.STRING(options_str),SOME(st)) = Ceval.ceval(cache,env, options, true, SOME(st), NONE, msg);
(cache,Values.STRING(outputFormat_str),SOME(st)) = Ceval.ceval(cache,env, outputFormat, true, SOME(st), NONE, msg);
starttime_r = ValuesUtil.valueReal(starttime_v);
stoptime_r = ValuesUtil.valueReal(stoptime_v);
interval_r = intReal(interval_i);
tolerance_r = ValuesUtil.valueReal(tolerance_v);
init_filename = Util.stringAppendList({prefix_str,"_init.txt"});
then
(cache,init_filename,starttime_r,stoptime_r,interval_r,tolerance_r,method_str,options_str);
(cache,init_filename,starttime_r,stoptime_r,interval_r,tolerance_r,method_str,options_str,outputFormat_str);
case (_,_,_,_,_,_)
equation
Print.printErrorBuf("#- Ceval.calculateSimulationSettings failed\n");
Expand All @@ -2476,10 +2436,11 @@ public function buildModel "function buildModel
output Env.Cache outCache;
output String outString1 "className";
output String outString2 "method";
output String outputFormat_str;
output Interactive.InteractiveSymbolTable outInteractiveSymbolTable3;
output String outString4 "initFileName";
algorithm
(outCache,outString1,outString2,outInteractiveSymbolTable3,outString4):=
(outCache,outString1,outString2,outputFormat_str,outInteractiveSymbolTable3,outString4):=
matchcontinue (inCache,inEnv,inExp,inInteractiveSymbolTable,inMsg)
local
Values.Value ret_val;
Expand All @@ -2493,7 +2454,7 @@ algorithm
list<Interactive.CompiledCFunction> cf;
Real starttime_r,stoptime_r,interval_r,tolerance_r;
list<Env.Frame> env;
DAE.Exp exp,starttime,stoptime,interval,tolerance,method,fileprefix,storeInTemp,noClean,options;
DAE.Exp exp,starttime,stoptime,interval,tolerance,method,fileprefix,storeInTemp,noClean,options,outputFormat;
DAE.ComponentRef cr;
list<SCode.Class> sp;
AbsynDep.Depends aDep;
Expand All @@ -2505,7 +2466,7 @@ algorithm
Boolean cdToTemp,existFile;
// do not recompile.
case (cache,env,(exp as DAE.CALL(path = Absyn.IDENT(name = _),
expLst = {DAE.CODE(Absyn.C_TYPENAME(classname),_),starttime,stoptime,interval,tolerance,method,fileprefix,storeInTemp,_,options})),
expLst = {DAE.CODE(Absyn.C_TYPENAME(classname),_),starttime,stoptime,interval,tolerance,method,fileprefix,storeInTemp,_,options,outputFormat})),
(st_1 as Interactive.SYMBOLTABLE(ast = p as Absyn.PROGRAM(globalBuildTimes=Absyn.TIMESTAMP(_,edit)),explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
// If we already have an up-to-date version of the binary file, we don't need to recompile.
local String exeFile;
Expand All @@ -2524,14 +2485,15 @@ algorithm
(cache,Values.STRING(prefix_str),SOME(st2)) = Ceval.ceval(cache,env, fileprefix, true, SOME(st_1), NONE, msg);
init_filename = Util.stringAppendList({prefix_str,"_init.txt"});
(cache,Values.STRING(method_str),SOME(st2)) = Ceval.ceval(cache,env, method, true, SOME(st2), NONE, msg);
(cache,Values.STRING(outputFormat_str),SOME(st2)) = Ceval.ceval(cache, env, outputFormat, true, SOME(st2), NONE, msg);
exeFile = Util.stringAppendList({filenameprefix, ".exe"});
existFile = System.regularFileExists(exeFile);
_ = System.cd(oldDir);
true = existFile;
then
(cache,filenameprefix,method_str,st2,init_filename);
(cache,filenameprefix,method_str,outputFormat_str,st2,init_filename);
// compile the model
case (cache,env,(exp as DAE.CALL(path = Absyn.IDENT(name = _),expLst = ({DAE.CODE(Absyn.C_TYPENAME(classname),_),starttime,stoptime,interval,tolerance,method,fileprefix,storeInTemp,noClean,options}))),(st_1 as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
case (cache,env,(exp as DAE.CALL(path = Absyn.IDENT(name = _),expLst = ({DAE.CODE(Absyn.C_TYPENAME(classname),_),starttime,stoptime,interval,tolerance,method,fileprefix,storeInTemp,noClean,options,outputFormat}))),(st_1 as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
local Absyn.TimeStamp ts,ts2;
Real r1,r2,globalEdit,globalBuild;
String s1,s2,s3;
Expand All @@ -2545,10 +2507,10 @@ algorithm
changeToTempDirectory(cdToTemp);
(cache,ret_val,st,indexed_dlow_1,libs,file_dir) = translateModel(cache,env, classname, st_1, msg, fileprefix,true);
cname_str = Absyn.pathString(classname);
(cache,init_filename,starttime_r,stoptime_r,interval_r,tolerance_r,method_str,options_str) = calculateSimulationSettings(cache,env, exp, st, msg, cname_str);
(cache,init_filename,starttime_r,stoptime_r,interval_r,tolerance_r,method_str,options_str,outputFormat_str) = calculateSimulationSettings(cache,env, exp, st, msg, cname_str);
(cache,filenameprefix) = extractFilePrefix(cache,env, fileprefix, st, msg);
SimCode.generateInitData(indexed_dlow_1, classname, filenameprefix, init_filename,
starttime_r, stoptime_r, interval_r, tolerance_r, method_str,options_str);
starttime_r, stoptime_r, interval_r, tolerance_r, method_str,options_str,outputFormat_str);
win1 = getWithinStatement(classname);
s3 = extractNoCleanCommand(noClean);
makefilename = generateMakefilename(filenameprefix);
Expand All @@ -2559,7 +2521,7 @@ algorithm
p = setBuildTime(p,classname);
st2 = st;// Interactive.replaceSymbolTableProgram(st,p);
then
(cache,filenameprefix,method_str,st2,init_filename);
(cache,filenameprefix,method_str,outputFormat_str,st2,init_filename);
case (_,_,_,_,_)
then
fail();
Expand Down Expand Up @@ -3919,7 +3881,7 @@ algorithm
Interactive.InteractiveSymbolTable st,st_1,st2;
DAELow.DAELow indexed_dlow_1;
list<String> libs;
String prefix_str,file_dir,cname_str,init_filename,method_str,filenameprefix,makefilename,oldDir,tempDir,options_str;
String prefix_str,file_dir,cname_str,init_filename,method_str,filenameprefix,makefilename,oldDir,tempDir,options_str,outputFormat_str;
Absyn.Path classname,w;
Absyn.Program p,p2;
Absyn.Class cdef;
Expand Down Expand Up @@ -3948,9 +3910,9 @@ algorithm
changeToTempDirectory(cdToTemp);
(cache,ret_val,st,indexed_dlow_1,libs,file_dir) = translateModel(cache,env, classname, st_1, msg, fileprefix,true);
cname_str = Absyn.pathString(classname);
(cache,init_filename,starttime_r,stoptime_r,interval_r,tolerance_r,method_str,options_str) = calculateSimulationSettings(cache,env, exp, st, msg, cname_str);
(cache,init_filename,starttime_r,stoptime_r,interval_r,tolerance_r,method_str,options_str,outputFormat_str) = calculateSimulationSettings(cache,env, exp, st, msg, cname_str);
(cache,filenameprefix) = extractFilePrefix(cache,env, fileprefix, st, msg);
SimCode.generateInitData(indexed_dlow_1, classname, filenameprefix, init_filename, starttime_r, stoptime_r, interval_r,tolerance_r,method_str,options_str);
SimCode.generateInitData(indexed_dlow_1, classname, filenameprefix, init_filename, starttime_r, stoptime_r, interval_r,tolerance_r,method_str,options_str,outputFormat_str);
makefilename = generateMakefilename(filenameprefix);
Debug.fprintln("dynload", "buildModel: about to compile model " +& filenameprefix +& ", " +& file_dir);
compileModel(filenameprefix, libs, file_dir, "");
Expand Down
6 changes: 3 additions & 3 deletions Compiler/Main.mo
Expand Up @@ -834,7 +834,7 @@ algorithm
();
case (dae,ass1,ass2,comps)
equation
indexed_dae = DAELow.translateDae(dae,NONE);
indexed_dae = DAELow.translateDae(dae,NONE());
indexed_dae_1 = DAELow.calculateValues(indexed_dae);
TaskGraph.buildTaskgraph(indexed_dae_1, ass1, ass2, comps);
TaskGraphExt.dumpGraph("model.viz");
Expand Down Expand Up @@ -908,7 +908,7 @@ algorithm
Print.clearErrorBuf();
Print.clearBuf();
Debug.fcall("execstat",print, "*** Main -> simcodgen -> translateDae: " +& realString(clock()) +& "\n" );
indexed_dlow = DAELow.translateDae(dlow,NONE);
indexed_dlow = DAELow.translateDae(dlow,NONE());
indexed_dlow_1 = DAELow.calculateValues(indexed_dlow);
Debug.fcall("dumpindxdae", DAELow.dump, indexed_dlow_1);
cname_str = Absyn.pathString(classname);
Expand All @@ -920,7 +920,7 @@ algorithm
file_dir = CevalScript.getFileDir(a_cref, ap);
Debug.fcall("execstat",print, "*** Main -> simcodgen -> generateFunctions: " +& realString(clock()) +& "\n" );
(_, _) = SimCode.generateModelCode(p, dae, indexed_dlow_1, classname, cname_str, file_dir, ass1, ass2, m, mt, comps);
SimCode.generateInitData(indexed_dlow_1, classname, cname_str, init_filename, 0.0, 1.0, 500.0,1e-6,"dassl","");
SimCode.generateInitData(indexed_dlow_1, classname, cname_str, init_filename, 0.0, 1.0, 500.0,1e-6,"dassl","","plt");
then
();
case (_,_,_,_,_,_,_,_,_,_,_,_) /* If something above failed. fail so Main can print errors */
Expand Down
8 changes: 5 additions & 3 deletions Compiler/SimCode.mo
Expand Up @@ -7083,8 +7083,9 @@ public function generateInitData
input Real inTolerance;
input String method;
input String options;
input String outputFormat;
algorithm
_ := matchcontinue (inDAELow1,inPath2,inString3,inString4,inReal5,inReal6,inReal7,inTolerance,method,options)
_ := matchcontinue (inDAELow1,inPath2,inString3,inString4,inReal5,inReal6,inReal7,inTolerance,method,options,outputFormat)
local
Real delta_time,step,start,stop,intervals,tolerance;
String start_str,stop_str,step_str,tolerance_str,nx_str,ny_str,np_str,init_str,str,exe,filename;
Expand All @@ -7093,7 +7094,7 @@ algorithm
DAELow.DAELow dlow;
Absyn.Path class_;

case (dlow,class_,exe,filename,start,stop,intervals,tolerance,method,_) /* classname executable file name filename start time stop time intervals */
case (dlow,class_,exe,filename,start,stop,intervals,tolerance,method,_,outputFormat) /* classname executable file name filename start time stop time intervals */
equation
delta_time = stop -. start;
step = delta_time/.intervals;
Expand All @@ -7114,6 +7115,7 @@ algorithm
step_str," // step value\n",
tolerance_str, " // tolerance\n",
"\"",method,"\" // method\n",
"\"",outputFormat,"\" // outputFormat\n",
nx_str," // n states\n",
ny_str," // n alg vars\n",
np_str," //n parameters\n",
Expand All @@ -7124,7 +7126,7 @@ algorithm
then
();

case (_,_,_,_,_,_,_,_,_,_)
case (_,_,_,_,_,_,_,_,_,_,_)
equation
print("-SimCodegen.generateInitData failed\n");
then
Expand Down

0 comments on commit 787f3b4

Please sign in to comment.