Skip to content

Commit

Permalink
- Add numberOfIntervals and stepSize as input/output of getSimulation…
Browse files Browse the repository at this point in the history
…Options

  - OMEdit now respects the Interval experiment annotation in the simulation setup
- Enable output of the statements in the match equation sections (for error messages)


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18715 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 22, 2014
1 parent 0cfe45f commit 9635f1c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
6 changes: 5 additions & 1 deletion Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -2856,12 +2856,16 @@ function getSimulationOptions
input Real defaultStartTime := 0.0;
input Real defaultStopTime := 1.0;
input Real defaultTolerance := 1e-6;
input Integer defaultNumberOfIntervals := 500 "May be overridden by defining defaultInterval instead";
input Real defaultInterval := 0.0 "If = 0.0, then numberOfIntervals is used to calculate the step size";
output Real startTime;
output Real stopTime;
output Real tolerance;
output Real numberOfIntervals;
output Real interval;
external "builtin";
annotation(Documentation(info="<html>
<p>Returns the startTime, stopTime, interval and tolerance based on the experiment annotation.</p>
<p>Returns the startTime, stopTime, tolerance, and interval based on the experiment annotation.</p>
</html>"));
end getSimulationOptions;

Expand Down
25 changes: 13 additions & 12 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -846,7 +846,7 @@ algorithm
list<GlobalScript.CompiledCFunction> cf;
GlobalScript.SimulationOptions simOpt;
Real startTime,stopTime,tolerance,reltol,reltolDiffMinMax,rangeDelta;
DAE.Exp startTimeExp,stopTimeExp,toleranceExp;
DAE.Exp startTimeExp,stopTimeExp,toleranceExp,intervalExp;
DAE.Type tp;
Absyn.Class absynClass;
Absyn.ClassDef cdef;
Expand All @@ -859,7 +859,7 @@ algorithm
Option<list<tuple<Integer, Integer, BackendDAE.Equation>>> jac;
Values.Value ret_val,simValue,value,v,cvar,cvar2,v1,v2;
Absyn.ComponentRef cr_1;
Integer size,resI,i,i1,i2,i3,n,curveStyle;
Integer size,resI,i,i1,i2,i3,n,curveStyle,numberOfIntervals;
Option<Integer> fmiContext, fmiInstance, fmiModelVariablesInstance; /* void* implementation: DO NOT UNBOX THE POINTER AS THAT MIGHT CHANGE IT. Just treat this as an opaque type. */
Integer fmiLogLevel;
list<Integer> is;
Expand Down Expand Up @@ -897,10 +897,8 @@ algorithm
list<Boolean> blst;
list<Error.TotalMessage> messages;
UnitAbsyn.Unit u1,u2;

Real stoptime,starttime,tol,stepsize;
Integer interval;
String stoptime_str,stepsize_str,starttime_str,tol_str,num_intervalls_str;
Real stoptime,starttime,tol,stepsize,interval;
String stoptime_str,stepsize_str,starttime_str,tol_str,num_intervalls_str;
case (cache,env,"parseString",{Values.STRING(str1),Values.STRING(str2)},st,_)
equation
Absyn.PROGRAM(classes=classes,within_=within_) = Parser.parsestring(str1,str2);
Expand Down Expand Up @@ -1418,7 +1416,7 @@ algorithm

exeDir=compileDir;
(cache,simSettings) = calculateSimulationSettings(cache,env,vals,st_1,msg);
SimCode.SIMULATION_SETTINGS(startTime=starttime,stopTime=stoptime,tolerance=tol,numberOfIntervals=interval,stepSize=stepsize,method = method_str, outputFormat = outputFormat_str)
SimCode.SIMULATION_SETTINGS(startTime=starttime,stopTime=stoptime,tolerance=tol,stepSize=stepsize,method = method_str, outputFormat = outputFormat_str)
= simSettings;
result_file = stringAppendList(List.consOnTrue(not Config.getRunningTestsuite(),compileDir,{executable,"_res.",outputFormat_str}));
executableSuffixedExe = stringAppend(executable, getSimulationExtension(Config.simCodeTarget(),System.platform()));
Expand Down Expand Up @@ -1556,7 +1554,7 @@ algorithm
cit = winCitation();
exeDir=compileDir;
(cache,simSettings) = calculateSimulationSettings(cache,env,vals,st_1,msg);
SimCode.SIMULATION_SETTINGS(startTime=starttime,stopTime=stoptime,tolerance=tol,numberOfIntervals=interval,stepSize=stepsize,method = method_str, outputFormat = outputFormat_str) = simSettings;
SimCode.SIMULATION_SETTINGS(startTime=starttime,stopTime=stoptime,tolerance=tol,stepSize=stepsize,method = method_str, outputFormat = outputFormat_str) = simSettings;
result_file = stringAppendList(List.consOnTrue(not Config.getRunningTestsuite(),compileDir,{executable,"_res.",outputFormat_str}));
executableSuffixedExe = stringAppend(executable, getSimulationExtension(Config.simCodeTarget(),System.platform()));
logFile = stringAppend(executable,".log");
Expand Down Expand Up @@ -2333,19 +2331,22 @@ algorithm
then
(cache,Values.BOOL(false),st);

case (cache,env,"getSimulationOptions",{Values.CODE(Absyn.C_TYPENAME(classpath)),Values.REAL(startTime),Values.REAL(stopTime),Values.REAL(tolerance)},st as GlobalScript.SYMBOLTABLE(ast = p),_)
case (cache,env,"getSimulationOptions",{Values.CODE(Absyn.C_TYPENAME(classpath)),Values.REAL(startTime),Values.REAL(stopTime),Values.REAL(tolerance),Values.INTEGER(numberOfIntervals),Values.REAL(interval)},st as GlobalScript.SYMBOLTABLE(ast = p),_)
equation
cr_1 = Absyn.pathToCref(classpath);
// ignore the name of the model
ErrorExt.setCheckpoint("getSimulationOptions");
simOpt = GlobalScript.SIMULATION_OPTIONS(DAE.RCONST(startTime),DAE.RCONST(stopTime),DAE.ICONST(0),DAE.RCONST(0.0),DAE.RCONST(tolerance),DAE.SCONST(""),DAE.SCONST(""),DAE.SCONST(""),DAE.SCONST(""),DAE.SCONST(""),DAE.BCONST(false),DAE.SCONST(""),DAE.SCONST(""));
simOpt = GlobalScript.SIMULATION_OPTIONS(DAE.RCONST(startTime),DAE.RCONST(stopTime),DAE.ICONST(numberOfIntervals),DAE.RCONST(0.0),DAE.RCONST(tolerance),DAE.SCONST(""),DAE.SCONST(""),DAE.SCONST(""),DAE.SCONST(""),DAE.SCONST(""),DAE.BCONST(false),DAE.SCONST(""),DAE.SCONST(""));
ErrorExt.rollBack("getSimulationOptions");
(_, _::startTimeExp::stopTimeExp::_::toleranceExp::_) = StaticScript.getSimulationArguments(Env.emptyCache(), {},{Absyn.CREF(cr_1)},{},false,SOME(st),Prefix.NOPRE(),Absyn.dummyInfo,SOME(simOpt));
(_, _::startTimeExp::stopTimeExp::intervalExp::toleranceExp::_) = StaticScript.getSimulationArguments(Env.emptyCache(), {},{Absyn.CREF(cr_1)},{},false,SOME(st),Prefix.NOPRE(),Absyn.dummyInfo,SOME(simOpt));
startTime = ValuesUtil.valueReal(Util.makeValueOrDefault(Ceval.cevalSimple,startTimeExp,Values.REAL(startTime)));
stopTime = ValuesUtil.valueReal(Util.makeValueOrDefault(Ceval.cevalSimple,stopTimeExp,Values.REAL(stopTime)));
tolerance = ValuesUtil.valueReal(Util.makeValueOrDefault(Ceval.cevalSimple,toleranceExp,Values.REAL(tolerance)));
Values.INTEGER(numberOfIntervals) = Util.makeValueOrDefault(Ceval.cevalSimple,intervalExp,Values.INTEGER(numberOfIntervals)); // number of intervals
interval = Util.if_(numberOfIntervals == 0, interval, realDiv(realSub(stopTime,startTime),intReal(intMax(numberOfIntervals,1))));
numberOfIntervals = Util.if_(numberOfIntervals == 0, realInt(realCeil(realDiv(realSub(stopTime,startTime),interval))), numberOfIntervals);
then
(cache,Values.TUPLE({Values.REAL(startTime),Values.REAL(stopTime),Values.REAL(tolerance)}),st);
(cache,Values.TUPLE({Values.REAL(startTime),Values.REAL(stopTime),Values.REAL(tolerance),Values.INTEGER(numberOfIntervals),Values.REAL(interval)}),st);

case (cache,env,"classAnnotationExists",{Values.CODE(Absyn.C_TYPENAME(classpath)),Values.CODE(Absyn.C_TYPENAME(path))},st as GlobalScript.SYMBOLTABLE(ast=p),_)
equation
Expand Down
2 changes: 0 additions & 2 deletions Compiler/Template/ExpressionDumpTpl.tpl
Expand Up @@ -403,7 +403,6 @@ match mcase
let pat_str = dumpPatterns(patterns)
let res_str = dumpExp(result, "\"")
let body_str = DAEDumpTpl.dumpStatements(body)
let body_str = ""
<<
case (<%pat_str%>)
algorithm
Expand All @@ -414,7 +413,6 @@ match mcase
case CASE(__) then
let pat_str = dumpPatterns(patterns)
let body_str = DAEDumpTpl.dumpStatements(body)
let body_str = ""
<<
case (<%pat_str%>)
algorithm
Expand Down
15 changes: 8 additions & 7 deletions Examples/BuildModelRecursive.mos
Expand Up @@ -105,13 +105,18 @@ writeFile(statFile + \".flat\", testcase(0,false,\"killed\"));getErrorString();
writeFile(statFile + \".compile\", testcase(0,false,\"killed\"));getErrorString();
writeFile(statFile + \".sim\", testcase(0,false,\"killed\"));getErrorString();
writeFile(statFile + \".verify\", testcase(0,false,\"killed\"));getErrorString();
outputFormat:=\"mat\";
referenceFiles := \""+referenceFiles+"\";
reference := \""+referenceFiles+"/"+OpenModelica.Scripting.stringReplace(s,".",referenceFileNameDelimiter)+"."+referenceFileExtension+"\";
referenceExists := referenceFiles <> \"\" and regularFileExists(reference);
outputFormat:=if referenceExists then \"mat\" else \"empty\";
"+loadModelCommand+"
reference_reltol:="+String(reference_reltol)+";
reference_reltolDiffMinMax:="+String(reference_reltolDiffMinMax)+";
reference_rangeDelta:="+String(reference_rangeDelta)+";
(startTime,stopTime,tolerance):=getSimulationOptions("+s+",defaultTolerance="+String(default_tolerance)+");
res:=buildModel("+s+",tolerance=tolerance,outputFormat=outputFormat);
// Use twice as many output points as the experiment annotation suggests. Else aim for 5000 points.
(startTime,stopTime,tolerance,numberOfIntervals,stepSize):=getSimulationOptions("+s+",defaultTolerance="+String(default_tolerance)+",defaultNumberOfIntervals=2500);
numberOfIntervals := 2*numberOfIntervals;
res:=buildModel("+s+",tolerance=tolerance,outputFormat=outputFormat,numberOfIntervals=numberOfIntervals);
greenColor := \"#00FF00\";
errFile:=\"files/"+s+".err\";
simFile:=\"files/"+s+".sim\";
Expand Down Expand Up @@ -139,14 +144,10 @@ buildRes := res[1] <> \"\";
simRes := if not buildRes then false else 0 == system(\"ulimit -t "+ulimitExe+" ; ./"+s+" > \"+simFile+\" 2>&1\");
system(\"sed -i '300,$ d' '\" + simFile + \"'\"); // Only keep the top 300 lines
timeSim := OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
referenceExists := false;
referenceOK := false;
referenceFiles := \""+referenceFiles+"\";
referenceCell := if referenceFiles == \"\" then \"\" else \"<td>&nbsp;</td>\";
if simRes then
system(\"touch "+s+".simsuccess\");
reference := \""+referenceFiles+"/"+OpenModelica.Scripting.stringReplace(s,".",referenceFileNameDelimiter)+"."+referenceFileExtension+"\";
referenceExists := referenceFiles <> \"\" and regularFileExists(reference);
prefix := \"files/"+s+".diff\";
if referenceExists then
OpenModelica.Scripting.Internal.Time.timerTick(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
Expand Down

0 comments on commit 9635f1c

Please sign in to comment.