Skip to content

Commit

Permalink
- Added simulate() option measureTime=false
Browse files Browse the repository at this point in the history
  - Not used for now, but will replace the -mt option of simulation executables


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8072 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Mar 3, 2011
1 parent e0f32bf commit f474946
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 48 deletions.
6 changes: 4 additions & 2 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -442,7 +442,8 @@ uniontype SimulationSettings
String method;
String options;
String outputFormat;
String variableFilter;
String variableFilter;
Boolean measureTime;
end SIMULATION_SETTINGS;
end SimulationSettings;

Expand Down Expand Up @@ -824,6 +825,7 @@ public function createSimulationSettings
input String options;
input String outputFormat;
input String variableFilter;
input Boolean measureTime;
output SimulationSettings simSettings;
protected
Real stepSize;
Expand All @@ -832,7 +834,7 @@ algorithm
stepSize := (stopTime -. startTime) /. intReal(numberOfIntervals);
simSettings := SIMULATION_SETTINGS(
startTime, stopTime, numberOfIntervals, stepSize, tolerance,
method, options, outputFormat, variableFilter);
method, options, outputFormat, variableFilter, measureTime);
end createSimulationSettings;


Expand Down
6 changes: 6 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -411,6 +411,12 @@ function classDirectory "Not standard Modelica"
external "builtin";
end classDirectory;

record SimulationResult
String resultFile;
String simulationOptions;
String messages;
end SimulationResult;

encapsulated package OpenModelica

type Code "Code quoting is not a uniontype yet because that would require enabling MetaModelica extensions in the regular compiler.
Expand Down
23 changes: 10 additions & 13 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -6664,17 +6664,8 @@ algorithm
Absyn.Info info;
String cname_str;
Absyn.Path className;
DAE.Exp startTime "start time, default 0.0";
DAE.Exp stopTime "stop time, default 1.0";
DAE.Exp numberOfIntervals "number of intervals, default 500";
DAE.Exp tolerance "tolerance, default 1e-6";
DAE.Exp method "method, default 'dassl'";
DAE.Exp fileNamePrefix "file name prefix, default ''";
DAE.Exp storeInTemp "store in temp, default false";
DAE.Exp options "options, default ''";
DAE.Exp noClean "no cleaning, default false";
DAE.Exp outputFormat "output format, default 'plt'";
DAE.Exp variableFilter "variable filter, regex does whole string matching, i.e. it becomes ^.*$ in the runtime";
DAE.Exp startTime,stopTime,numberOfIntervals,tolerance,method;
DAE.Exp fileNamePrefix,storeInTemp,options,noClean,outputFormat,variableFilter,measureTime;
CevalScript.SimulationOptions defaulSimOpt;
Env.Cache cache;
Env.Env env;
Expand Down Expand Up @@ -6730,6 +6721,11 @@ algorithm
getOptionalNamedArg(cache, env, SOME(st), impl, "variableFilter", DAE.T_STRING_DEFAULT,
args, CevalScript.getSimulationOption(defaulSimOpt, "variableFilter"),
pre, info);

(cache,measureTime) =
getOptionalNamedArg(cache, env, SOME(st), impl, "measureTime", DAE.T_BOOL_DEFAULT,
args, CevalScript.getSimulationOption(defaulSimOpt, "measureTime"),
pre, info);
then
(cache,
{DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER()),
Expand All @@ -6743,7 +6739,8 @@ algorithm
noClean,
options,
outputFormat,
variableFilter});
variableFilter,
measureTime});

end match;
end getSimulationArguments;
Expand Down Expand Up @@ -6887,7 +6884,7 @@ protected function elabCallInteractive "function: elabCallInteractive
then
(cache,Expression.makeBuiltinCall("timing",{exp_1},DAE.ET_REAL()),DAE.PROP(DAE.T_REAL_DEFAULT,DAE.C_VAR()),st_1);

// MathCore-specific. Should not be in MathCoreBuiltin.mo :p
// MathCore-specific. Should be in MathCoreBuiltin.mo :p
case (cache,env,Absyn.CREF_IDENT(name = "checkExamplePackages"),{},args,impl,SOME(st),pre,_)
equation
excludeList = getOptionalNamedArgExpList("exclude", args);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Main/Main.mo
Expand Up @@ -896,12 +896,12 @@ algorithm
cname_str = Absyn.pathString(classname);
methodflag = RTOpts.debugFlag("SetOldDassl");
methodbyflag = Util.if_(methodflag,"dasslold","dassl");
simSettings = SimCode.createSimulationSettings(0.0, 1.0, 500, 1e-6,methodbyflag,"","mat",".*");
simSettings = SimCode.createSimulationSettings(0.0, 1.0, 500, 1e-6,methodbyflag,"","mat",".*",false);
(_,_,_,_,_,_) = SimCode.generateModelCode(dlow,functionTree,ap,dae,classname,cname_str,SOME(simSettings),m,mt,ass1,ass2,comps);
then
();
/* If not generating simulation code: Succeed so no error messages are printed */
case (_,_,_,_,_,_,_,_,_,_,_)
else
equation
false = RTOpts.simulationCg();
then
Expand Down
70 changes: 39 additions & 31 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -153,6 +153,7 @@ uniontype SimulationOptions "these are the simulation/buildModel* options"
DAE.Exp options "options, default ''";
DAE.Exp outputFormat "output format, default 'plt'";
DAE.Exp variableFilter "variable filter, regex does whole string matching, i.e. it becomes ^.*$ in the runtime";
DAE.Exp measureTime "Enables time measurements, default false";
end SIMULATION_OPTIONS;
end SimulationOptions;

Expand All @@ -169,6 +170,7 @@ public constant DAE.Exp defaultNoClean = DAE.BCONST(false) "default
public constant DAE.Exp defaultOptions = DAE.SCONST("") "default options";
public constant DAE.Exp defaultOutputFormat = DAE.SCONST("mat") "default outputFormat";
public constant DAE.Exp defaultVariableFilter = DAE.SCONST(".*") "default variableFilter; does whole string matching, i.e. it becomes ^.*$ in the runtime";
public constant DAE.Exp defaultMeasureTime = DAE.BCONST(false) "time measurement disabled by default";

public constant SimulationOptions defaultSimulationOptions =
SIMULATION_OPTIONS(
Expand All @@ -183,7 +185,8 @@ public constant SimulationOptions defaultSimulationOptions =
defaultNoClean,
defaultOptions,
defaultOutputFormat,
defaultVariableFilter
defaultVariableFilter,
defaultMeasureTime
) "default simulation options";

//For testing with dassl2
Expand All @@ -200,7 +203,8 @@ public constant SimulationOptions dassl2SimulationOptions =
defaultNoClean,
defaultOptions,
defaultOutputFormat,
defaultVariableFilter
defaultVariableFilter,
defaultMeasureTime
) "default simulation options";

public constant list<String> simulationOptionsNames =
Expand All @@ -215,7 +219,8 @@ public constant list<String> simulationOptionsNames =
"noClean",
"options",
"outputFormat",
"variableFilter"
"variableFilter",
"measureTime"
} "names of simulation options";

public function getSimulationResultType
Expand Down Expand Up @@ -300,6 +305,7 @@ public function buildSimulationOptions
input DAE.Exp options "options, default ''";
input DAE.Exp outputFormat "output format, default 'plt'";
input DAE.Exp variableFilter;
input DAE.Exp measureTime;
output SimulationOptions outSimulationOptions;
algorithm
outSimulationOptions :=
Expand All @@ -315,7 +321,8 @@ algorithm
noClean,
options,
outputFormat,
variableFilter
variableFilter,
measureTime
);
end buildSimulationOptions;

Expand All @@ -342,6 +349,7 @@ algorithm
case (SIMULATION_OPTIONS(noClean = e), "noClean") then e;
case (SIMULATION_OPTIONS(outputFormat = e), "outputFormat") then e;
case (SIMULATION_OPTIONS(variableFilter = e), "variableFilter") then e;
case (SIMULATION_OPTIONS(measureTime = e), "measureTime") then e;
case (_, name)
equation
msg = "Unknown simulation option: " +& name;
Expand Down Expand Up @@ -413,10 +421,10 @@ protected function setFileNamePrefixInSimulationOptions
input String inFileNamePrefix;
output SimulationOptions outSimOpt;
protected
DAE.Exp startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter;
DAE.Exp startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime;
algorithm
SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, _, storeInTemp, noClean, options, outputFormat, variableFilter) := inSimOpt;
outSimOpt := SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, DAE.SCONST(inFileNamePrefix), storeInTemp, noClean, options, outputFormat, variableFilter);
SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, _, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime) := inSimOpt;
outSimOpt := SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, DAE.SCONST(inFileNamePrefix), storeInTemp, noClean, options, outputFormat, variableFilter, measureTime);
end setFileNamePrefixInSimulationOptions;

protected function getConst
Expand Down Expand Up @@ -468,64 +476,64 @@ algorithm
DAE.Exp noClean;
DAE.Exp options;
DAE.Exp outputFormat;
DAE.Exp variableFilter;
DAE.Exp variableFilter, measureTime;
Real rStepSize, rStopTime, rStartTime;
Integer iNumberOfIntervals;
String name,msg;

case (inSimOpt, {}) then inSimOpt;

case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter),
case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime),
Absyn.NAMEDARG(argName = "Tolerance", argValue = exp)::rest)
equation
tolerance = getConst(exp, DAE.ET_REAL());
simOpt = populateSimulationOptions(
SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter),
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime),
rest);
then
simOpt;

case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter),
case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime),
Absyn.NAMEDARG(argName = "StartTime", argValue = exp)::rest)
equation
startTime = getConst(exp, DAE.ET_REAL());
simOpt = populateSimulationOptions(
SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter),
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime),
rest);
then
simOpt;

case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter),
case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime),
Absyn.NAMEDARG(argName = "StopTime", argValue = exp)::rest)
equation
stopTime = getConst(exp, DAE.ET_REAL());
simOpt = populateSimulationOptions(
SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter),
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime),
rest);
then
simOpt;

case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter),
case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime),
Absyn.NAMEDARG(argName = "NumberOfIntervals", argValue = exp)::rest)
equation
numberOfIntervals = getConst(exp, DAE.ET_INT());
simOpt = populateSimulationOptions(
SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter),
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime),
rest);
then
simOpt;

case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter),
case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime),
Absyn.NAMEDARG(argName = "Interval", argValue = exp)::rest)
equation
DAE.RCONST(rStepSize) = getConst(exp, DAE.ET_REAL());
// a bit different for Interval, handle it LAST!!!!
SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter) =
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime) =
populateSimulationOptions(inSimOpt, rest);

DAE.RCONST(rStartTime) = startTime;
Expand All @@ -537,11 +545,11 @@ algorithm
stepSize = DAE.RCONST(rStepSize);

simOpt = SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter);
fileNamePrefix,storeInTemp,noClean,options,outputFormat,variableFilter,measureTime);
then
simOpt;

case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter),
case (SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, storeInTemp, noClean, options, outputFormat, variableFilter, measureTime),
Absyn.NAMEDARG(argName = name, argValue = exp)::rest)
equation
msg = "Ignoring unknown experiment annotation option: " +& name +& " = " +& Dump.printExpStr(exp);
Expand Down Expand Up @@ -991,7 +999,6 @@ algorithm
case (cache,env,"simulate",vals as Values.CODE(Absyn.C_TYPENAME(className))::_,st_1,msg)
equation
System.realtimeTick(RT_CLOCK_SIMULATE_TOTAL);

(cache,executable,method_str,outputFormat_str,st,_,resultValues) = buildModel(cache,env,vals,st_1,msg);

cit = winCitation();
Expand Down Expand Up @@ -1926,9 +1933,9 @@ protected function calculateSimulationSettings "function calculateSimulationSett
output SimCode.SimulationSettings outSimSettings;
algorithm
(outCache,outSimSettings):=
matchcontinue (inCache,inEnv,vals,inInteractiveSymbolTable,inMsg)
match (inCache,inEnv,vals,inInteractiveSymbolTable,inMsg)
local
String method_str,options_str,outputFormat_str,variableFilter_str;
String method_str,options_str,outputFormat_str,variableFilter_str,s;
Interactive.InteractiveSymbolTable st;
Values.Value starttime_v,stoptime_v,tolerance_v;
Integer interval_i;
Expand All @@ -1937,22 +1944,23 @@ algorithm
DAE.Exp starttime,stoptime,interval,toleranceExp,method,options,outputFormat;
Ceval.Msg msg;
Env.Cache cache;
case (cache,env,{Values.CODE(Absyn.C_TYPENAME(_)),starttime_v,stoptime_v,Values.INTEGER(interval_i),tolerance_v,Values.STRING(method_str),_,_,_,Values.STRING(options_str),Values.STRING(outputFormat_str),Values.STRING(variableFilter_str)},
Boolean measureTime;
case (cache,env,{Values.CODE(Absyn.C_TYPENAME(_)),starttime_v,stoptime_v,Values.INTEGER(interval_i),tolerance_v,Values.STRING(method_str),_,_,_,Values.STRING(options_str),Values.STRING(outputFormat_str),Values.STRING(variableFilter_str),Values.BOOL(measureTime)},
(st as Interactive.SYMBOLTABLE(ast = _)),msg)
equation
starttime_r = ValuesUtil.valueReal(starttime_v);
stoptime_r = ValuesUtil.valueReal(stoptime_v);
tolerance_r = ValuesUtil.valueReal(tolerance_v);
outSimSettings = SimCode.createSimulationSettings(starttime_r,stoptime_r,interval_i,tolerance_r,method_str,options_str,outputFormat_str,variableFilter_str);
outSimSettings = SimCode.createSimulationSettings(starttime_r,stoptime_r,interval_i,tolerance_r,method_str,options_str,outputFormat_str,variableFilter_str,measureTime);
then
(cache, outSimSettings);
else
equation
print("abc " +& intString(listLength(vals)));
Error.addMessage(Error.INTERNAL_ERROR, {"CevalScript.calculateSimulationSettings failed"});
s = "CevalScript.calculateSimulationSettings failed: " +& ValuesUtil.valString(Values.TUPLE(vals));
Error.addMessage(Error.INTERNAL_ERROR, {s});
then
fail();
end matchcontinue;
end match;
end calculateSimulationSettings;

protected function buildModel "function buildModel
Expand Down Expand Up @@ -1993,11 +2001,11 @@ algorithm
list<Interactive.InteractiveVariable> iv;
Ceval.Msg msg;
Env.Cache cache;
Boolean cdToTemp,existFile;
Boolean cdToTemp,existFile;
Absyn.TimeStamp ts;

// do not recompile.
case (cache,env,{Values.CODE(Absyn.C_TYPENAME(classname)),starttime,stoptime,interval,tolerance,Values.STRING(method_str),Values.STRING(filenameprefix),Values.BOOL(cdToTemp),_,options,Values.STRING(outputFormat_str)},
case (cache,env,{Values.CODE(Absyn.C_TYPENAME(classname)),starttime,stoptime,interval,tolerance,Values.STRING(method_str),Values.STRING(filenameprefix),Values.BOOL(cdToTemp),_,options,Values.STRING(outputFormat_str),_},
(st 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.
equation
Expand All @@ -2017,7 +2025,7 @@ algorithm
(cache,filenameprefix,method_str,outputFormat_str,st,init_filename,zeroAdditionalSimulationResultValues);

// compile the model
case (cache,env,vals as {Values.CODE(Absyn.C_TYPENAME(classname)),starttime,stoptime,interval,tolerance,method,Values.STRING(filenameprefix),Values.BOOL(cdToTemp),noClean,options,outputFormat,variableFilter},(st_1 as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
case (cache,env,vals as {Values.CODE(Absyn.C_TYPENAME(classname)),starttime,stoptime,interval,tolerance,method,Values.STRING(filenameprefix),Values.BOOL(cdToTemp),noClean,options,outputFormat,variableFilter,_},(st_1 as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
equation
(cdef as Absyn.CLASS(info = Absyn.INFO(buildTimes=ts as Absyn.TIMESTAMP(_,globalEdit)))) = Interactive.getPathedClassInProgram(classname,p);
Absyn.PROGRAM(_,_,Absyn.TIMESTAMP(globalBuild,_)) = p;
Expand Down
3 changes: 3 additions & 0 deletions c_runtime/simulation_runtime.cpp
Expand Up @@ -317,6 +317,9 @@ startNonInteractiveSimulation(int argc, char**argv)

/* mesure time option is set : -mt */
measure_time_flag = (int) flagSet("mt", argc, argv);
if (measure_time_flag) {
fprintf(stderr, "Warning: The -mt is going to be replaced by the simulate option measureTime.\n");
}

double start = 0.0;
double stop = 5.0;
Expand Down

0 comments on commit f474946

Please sign in to comment.