// Run as mos-script using OpenModelica 1.9.1+dev (r18507) (RML version)
"Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource";
echo(false);
loadString("
function cell
input Real time;
input Boolean greenOnOk := false;
input String greenColor := \"#00FF00\";
output String str;
algorithm
str := if time==-1.0 then \"
\" else ((if greenOnOk then \"\" else \" \") +
OpenModelica.Scripting.Internal.Time.readableTime(if time < 1e-5 then 0 else time)+\" \");
end cell;
function length input String str; output Integer len; external \"C\" len=ModelicaStrings_length(str); end length;
function substring input String str; input Integer i1,i2; output String out; external \"C\" out=ModelicaStrings_substring(str,i1,i2); end substring;
function firstPart input String str; input Integer maxLength := 4096; output String out; algorithm out := if length(str) < maxLength then str else (substring(str,1,maxLength) + \"
... (output truncated, was \" + String(length(str)) + \" bytes)\"); end firstPart;
function csvFileToVariable
input String str;
output String out;
protected
String matches[2];
algorithm
(,matches) := OpenModelica.Scripting.regex(str,\"^.*[.]diff[.](.*)$\",2);
out := matches[2];
end csvFileToVariable;
function testcase
input Real time;
input Boolean success;
input String errXMLLong;
output String str;
protected
String errXML;
algorithm
errXML := firstPart(errXMLLong,16*1024); // 16 kB log per test should be enough; increase if there is a good reason to do so
str:=\"\"+(
if not success then \" \"
else \"\"
)+(
if errXML <> \"\" then (\"\" + errXML + \" \")
else \"\"
)+
\"
\";
end testcase;
");getErrorString();
statFile := "Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource.stat";
writeFile("BuildModelRecursive.html","Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource
",append=true);
writeFile(statFile,"Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource ");getErrorString();
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:="csv";
runScript("CustomCommands.mos");
loadModel(Modelica,{"default"});
reference_reltol:=0.003;
reference_reltolDiffMinMax:=0.003;
reference_rangeDelta:=0.001;
(startTime,stopTime,tolerance):=getSimulationOptions(Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource,defaultTolerance=1e-06);
referenceOK := false;
referenceFiles := "/home/martin/trunk/Examples/tmp2/refs";
referenceCell := if referenceFiles == "" then "" else " ";
reference := "/home/martin/trunk/Examples/tmp2/refs/Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource.csv";
referenceExists := referenceFiles <> "" and regularFileExists(reference);
variableFilter := if referenceExists
then sum((stringReplace(stringReplace(s,"[","."),"]",".") + "|") for s in readSimulationResultVars(reference))
else ".*";
res:=buildModel(Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource,tolerance=tolerance,outputFormat=outputFormat,variableFilter=variableFilter);
greenColor := "#00FF00";
errFile:="files/Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource.err";
simFile:="files/Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource.sim";
err:=getErrorString();
system("rm -f " + errFile);
writeFile(simFile,"");
if err <> "" then
writeFile(errFile,err);
end if;
frontend :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_FRONTEND);
backend :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_BACKEND);
simcode :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_SIMCODE);
templates:=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_TEMPLATES);
total :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_SIMULATE_TOTAL);
build :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_BUILD_MODEL);
frontend :=if backend <> -1.0 then frontend-backend else frontend;
backend :=if simcode <> -1.0 then backend-simcode else backend;
simcode :=if templates <> -1.0 then simcode-templates else simcode;
templates:=if build <> -1.0 then templates-build else templates;
timeDiff := -1.0;
OpenModelica.Scripting.Internal.Time.timerTick(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
buildRes := res[1] <> "";
simRes := if not buildRes then false else 0 == system("ulimit -t 480 ; ./Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource > "+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);
if simRes then
system("touch Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource.simsuccess");
prefix := "files/Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource.diff";
if referenceExists then
OpenModelica.Scripting.Internal.Time.timerTick(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
(referenceOK,diffVars) := diffSimulationResults("Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource_res."+outputFormat,reference,prefix,relTol=reference_reltol,relTolDiffMinMax=reference_reltolDiffMinMax,rangeDelta=reference_rangeDelta);
if referenceOK then
system("touch Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource.verifysuccess");
end if;
timeDiff := OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
diffFiles := {prefix + "." + var for var in diffVars};
// Create a file containing only the calibrated variables, for easy display
if not referenceOK then
timeDiff := OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
referenceCell := ""+OpenModelica.Scripting.Internal.Time.readableTime(timeDiff)+", "+String(size(diffFiles,1))+" failed ";
writeFile("files/Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource.diff.html","Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource differences from the reference file startTime: "+String(startTime)+"
stopTime: "+String(stopTime)+"
Simulated using tolerance: "+String(tolerance)+"
");
{writeFile(prefix + "." + var + ".html","
reference
actual
high
low
error
actual (original)
Parameters used for the comparison: Relative tolerance "+String(reference_reltol)+" (local), "+String(reference_reltolDiffMinMax)+" (relative to max-min). Range delta "+String(reference_rangeDelta)+".
") for var in diffVars};
else
referenceCell := ""+OpenModelica.Scripting.Internal.Time.readableTime(timeDiff)+" ";
end if;
end if;
end if;
sim:=readFile(simFile);
str:="" + (if err <> "" then "Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource " else "Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMPM_CurrentSource") +
(if sim <> "" then " (sim )" else "") +
" " + referenceCell +
cell(if simRes then timeSim else -1.0,greenOnOk=true,greenColor=greenColor) +
""" then greenColor else "#FF0000")+"\">"+OpenModelica.Scripting.Internal.Time.readableTime(total)+" " +
sum(cell(d,greenColor=greenColor) for d in {frontend,backend,simcode,templates,build}) + " \n";getErrorString();
writeFile(statFile,str);getErrorString();
errXML:=escapeXML(err);
skip:=" ";
str:=testcase(frontend,backend <> -1.0,errXML);
writeFile(statFile + ".flat", str);getErrorString();
str:=if backend <> -1.0 then testcase(total,buildRes,errXML) else skip;
writeFile(statFile + ".compile", str);getErrorString();
str:=if buildRes then testcase(timeSim,simRes,escapeXML(sim)) else skip;
writeFile(statFile + ".sim", str);getErrorString();
str:=if simRes then testcase(timeDiff,referenceOK,if referenceOK then "" else "See the generated report for details") else skip;
writeFile(statFile + ".verify", str);getErrorString();