Ticket #4654: ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.mos

File ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.mos, 16.8 KB (added by Adrian Pop, 9 years ago)
Line 
1// OpenModelica OMCompiler v1.13.0-dev.287+g0e14e98
2// Configured 2017-12-02 05:12:37 using arguments: '--disable-option-checking --prefix=/home/adrpo/testing/newinst/OpenModelica/build --with-cppruntime --without-omc --disable-modelica3d CC=clang CXX=clang++ FC=gfortran CFLAGS=-O2 -march=native --with-omlibrary=all --with-ombuilddir=/home/adrpo/testing/newinst/OpenModelica/build --cache-file=/dev/null --srcdir=.'
3// Ubuntu 16.04.3 LTS x86_64
4"ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array";
5echo(false);
6alarm(3000);
7loadString("
8function cell
9 input Real elapsedTime;
10 input Boolean greenOnOk := false;
11 input String greenColor := \"#00FF00\";
12 input String mdFile := \"\";
13 output String str;
14algorithm
15 str := if mdFile == \"\" then \"\" else \" <a href=\\\"files/mdpad_local.html?\"+mdFile+\"\\\"><img width=\\\"16px\\\" src=\\\"files/Modelica.Icons.Example.svg\\\"></img></a>\";
16 str := if elapsedTime==-1.0 then \"<td bgcolor=\\\"#FF0000\\\">&nbsp;</td>\" else ((if greenOnOk then \"<td bgcolor=\\\"\" + greenColor + \"\\\">\" else \"<td>\") +
17 OpenModelica.Scripting.Internal.Time.readableTime(elapsedTime)+str+\"</td>\");
18end cell;
19function length input String str; output Integer len; external \"C\" len=ModelicaStrings_length(str); end length;
20function substring input String str; input Integer i1,i2; output String out; external \"C\" out=ModelicaStrings_substring(str,i1,i2); end substring;
21function firstPart input String str; input Integer maxLength := 4096; output String out; algorithm out := if length(str) < maxLength then str else (substring(str,1,maxLength) + \"
22... (output truncated, was \" + String(length(str)) + \" bytes)\"); end firstPart;
23function csvFileToVariable
24 input String str;
25 output String out;
26protected
27 String matches[2];
28algorithm
29 (,matches) := OpenModelica.Scripting.regex(str,\"^.*[.]diff[.](.*)$\",2);
30 out := matches[2];
31end csvFileToVariable;
32function testcase
33 input Real elapsedTime;
34 input Boolean success;
35 input String errNoXMLLong;
36 output String str;
37protected
38 String errXML;
39algorithm
40 errXML := OpenModelica.Scripting.escapeXML(firstPart(errNoXMLLong,16*1024)); // 16 kB log per test should be enough; increase if there is a good reason to do so
41 str:=\"<testcase name=\\\"ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array\\\" elapsedTime=\\\"\"+String(elapsedTime)+\"\\\">\"+(
42 if not success then \"<error type=\\\"Failure\\\" />\"
43 else \"\"
44 )+(
45 if errXML <> \"\" then (\"<system-out>\" + errXML + \"</system-out>\")
46 else \"\"
47 )+
48 \"</testcase>
49\";
50end testcase;
51");getErrorString();
52statFile := "ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.stat";
53writeFile("BuildModelRecursive.html","ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array
54",append=true);
55writeFile(statFile,"<tr><td bgcolor=\"#ff0000\">ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array</td></tr>");getErrorString();
56writeFile(statFile + ".flat", testcase(0,false,"killed"));getErrorString();
57writeFile(statFile + ".compile", testcase(0,false,"killed"));getErrorString();
58writeFile(statFile + ".sim", testcase(0,false,"killed"));getErrorString();
59writeFile(statFile + ".verify", testcase(0,false,"killed"));getErrorString();
60writeFile("files/ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.uses", "");getErrorString();
61
62outputFormat:="default";
63javascript:=false;
64mslRegressionOutput:="";
65
66setCommandLineOptions("--daeMode=dynamic -d=execstat,nogen,initialization,backenddaeinfo,discreteinfo,stateselection,newInst"); ulimitExe:="3000"; ulimitOmc:="3000"; sortFiles:=false;
67extraSimFlags := "-mei=4000 -daeMode -s=ida -idaLS=klu";
68
69loadModel(ScalableTestSuite,{"default"});
70
71reference_reltol:=0.003;
72reference_reltolDiffMinMax:=0.003;
73reference_rangeDelta:=0.001;
74simFlags:="-abortSlowSimulation -alarm=3000 -mei=4000 -daeMode -s=ida -idaLS=klu";
75
76referenceOK := false;
77referenceFiles := "";
78referenceCell := if referenceFiles == "" then "" else "<td>&nbsp;</td>";
79reference := "/ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.mat";
80referenceExists := referenceFiles <> "" and regularFileExists(reference);
81if not referenceExists then
82 reference := "/ScalableTestSuite/Electrical/BreakerCircuits/Verification/BreakerNetwork_3_Array/BreakerNetwork_3_Array.mat";
83 referenceExists := referenceFiles <> "" and regularFileExists(reference);
84end if;
85
86// outputFormat can be overridden in CustomCommands.mos, so we set it to 'default' first
87outputFormat := if outputFormat == "default" then (if referenceExists then "mat" else "empty") else outputFormat;
88
89compareVarsUri := "modelica://" + /*libraryString*/ "Buildings" + "/Resources/Scripts/OpenModelica/compareVars/ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.mos";
90(compareVarsFile,compareVarsFileMessages) := uriToFilename(compareVarsUri);
91
92if regularFileExists(compareVarsFile) then
93 runScript(compareVarsFile);
94 vars := compareVars;
95 variableFilter := sum(stringReplace(stringReplace(s,"[","."),"]",".") + "|" for s in vars) + "time";
96 numCompared := size(vars,1);
97 emit_protected := " -emit_protected";
98elseif referenceExists then
99 vars := readSimulationResultVars(reference, readParameters=true, openmodelicaStyle=true);
100 variableFilter := sum(stringReplace(stringReplace(stringReplace(stringReplace(s,"[","."),"]","."),"(","."),")",".") + "|" for s in vars);
101 numCompared := size(vars,1);
102 emit_protected := " -emit_protected";
103 /* print(variableFilter + "
104"); */
105else
106 variableFilter := "";
107 outputFormat := "empty";
108 emit_protected := "";
109end if;
110
111writeFile("files/ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.uses", sum(typeNameString(c) + "
112" for c in OpenModelica.Scripting.getUsedClassNames(ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array)));getErrorString();
113
114// Use twice as many output points as the experiment annotation suggests. Else aim for 5000 points.
115(startTime,stopTime,tolerance,numberOfIntervals,stepSize):=getSimulationOptions(ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array,defaultTolerance=1e-06,defaultNumberOfIntervals=2500);
116numberOfIntervals := 2*numberOfIntervals;
117alarm(3000); // Reset the alarm in case the other parts took a long time (reading simulation results)
118res:=buildModel(ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array,tolerance=tolerance,outputFormat=outputFormat,numberOfIntervals=numberOfIntervals,variableFilter=variableFilter);
119// We built the model fine, so reset the alarm. The simulation executable will also have an alarm, making only result verification a potential to stall.
120alarm(0);
121
122greenColor := "#00FF00";
123errFile:="files/ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.err";
124simFile:="files/ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.sim";
125(nmessage,nerror,nwarning) := countMessages();
126errorLinkClass := if nerror>0 then "messagesError" elseif nwarning>0 then "messagesWarning" else "messagesInfo";
127err:=getErrorString();
128system("rm -f " + errFile);
129writeFile(simFile,"");
130if err <> "" then
131 writeFile(errFile,err);
132end if;
133
134build :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_BUILD_MODEL);
135total :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_SIMULATE_TOTAL);
136templates:=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_TEMPLATES);
137simcode :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_SIMCODE);
138backend :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_BACKEND);
139frontend :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_FRONTEND);
140
141frontend :=if backend <> -1.0 then frontend-backend else frontend;
142backend :=if simcode <> -1.0 then backend-simcode else backend;
143simcode :=if templates <> -1.0 then simcode-templates else simcode;
144templates:=if build <> -1.0 then templates-build else templates;
145timeDiff := -1.0;
146
147OpenModelica.Scripting.Internal.Time.timerTick(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
148buildRes := res[1] <> "";
149simRes := if not buildRes then false else 0 == system("./ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array "+simFlags+emit_protected+" > "+simFile+" 2>&1");
150if buildRes and javascript then
151 system("cp ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.js ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array_info.xml ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array_init.xml ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.md files/");
152end if;
153mdFile := if javascript then "ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.md" else "";
154
155resFile := "ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array_res." + outputFormat;
156
157if mslRegressionOutput <> "" and referenceExists then
158 mslRegressionOutput := mslRegressionOutput + "/ScalableTestSuite/Electrical/BreakerCircuits/Verification/BreakerNetwork_3_Array/";
159 mkdir(mslRegressionOutput);
160 simFailLog := mslRegressionOutput+"simulate_failed.log";
161 simSuccessLog := mslRegressionOutput+"simulate_success.log";
162 buildFailLog := mslRegressionOutput+"translate_failed.log";
163 buildSuccessLog := mslRegressionOutput+"translate_success.log";
164
165 system("rm -f "+(if simRes then simFailLog else simSuccessLog));
166 system("rm -f "+(if buildRes then buildFailLog else buildSuccessLog));
167
168 system("cp "+simFile+" " + simFile + ".tmp");
169 if simRes then
170 system("cp "+resFile+" ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.csv");
171 compareFilesAndMove("ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.csv", mslRegressionOutput+"ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.csv");
172 else
173 system("rm -f " + mslRegressionOutput + "ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.csv");
174 end if;
175 system("cp ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.mos ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.mos.tmp");
176
177 if err == "" then
178 system("echo > " + errFile + ".tmp");
179 else
180 system("cp " + errFile + " " + errFile + ".tmp");
181 end if;
182
183 compareFilesAndMove(errFile + ".tmp", if buildRes then buildSuccessLog else buildFailLog);
184 compareFilesAndMove(simFile + ".tmp", if buildRes then simSuccessLog else simFailLog);
185 compareFilesAndMove("ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.mos.tmp", mslRegressionOutput+"creation.txt");
186end if;
187
188system("sed -i '300,$ d' '" + simFile + "'"); // Only keep the top 300 lines
189timeSim := OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
190
191if simRes then
192 system("touch ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.simsuccess");
193 prefix := "files/ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.diff";
194 if referenceExists then
195 OpenModelica.Scripting.Internal.Time.timerTick(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
196 getErrorString();
197 (referenceOK,diffVars) := diffSimulationResults(resFile,reference,prefix,relTol=reference_reltol,relTolDiffMinMax=reference_reltolDiffMinMax,rangeDelta=reference_rangeDelta);
198 errVerify := getErrorString();
199 if errVerify <> "" then
200 writeFile(errFile, "\nVariables in the reference:"+sum(var+"," for var in OpenModelica.Scripting.readSimulationResultVars(reference, openmodelicaStyle=true)), append=true);
201 writeFile(errFile, "\nVariables in the result:"+sum(var+"," for var in OpenModelica.Scripting.readSimulationResultVars(resFile))+"\n" + errVerify, append=true);
202 end if;
203 if referenceOK then
204 system("touch ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.verifysuccess");
205 end if;
206 timeDiff := OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
207 diffFiles := {prefix + "." + var for var in diffVars};
208 // Create a file containing only the calibrated variables, for easy display
209 if not referenceOK then
210 timeDiff := OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
211 referenceCell := "<td bgcolor=\"#FF0000\">"+OpenModelica.Scripting.Internal.Time.readableTime(timeDiff)+", <a href=\"files/ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.diff.html\">"+String(size(diffFiles,1))+"/"+String(numCompared)+" signals failed</a></td>";
212 writeFile("files/ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array.diff.html","<html><body><h1>ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array differences from the reference file</h1><p>startTime: "+String(startTime)+"</p><p>stopTime: "+String(stopTime)+"</p><p>Simulated using tolerance: "+String(tolerance)+"</p><ul>" + sum("<li>"+csvFileToVariable(file)+" <a href=\""+OpenModelica.Scripting.basename(file)+".html\">(javascript)</a> <a href=\""+OpenModelica.Scripting.basename(file)+".csv\">(csv)</a></li>" for file in diffFiles) + "</ul></body></html>");
213 {writeFile(prefix + "." + var + ".html","<html>
214<head>
215<script type=\"text/javascript\" src=\"dygraph-combined.js\"></script>
216 <style type=\"text/css\">
217 #graphdiv {
218 position: absolute;
219 left: 10px;
220 right: 10px;
221 top: 40px;
222 bottom: 10px;
223 }
224 </style>
225</head>
226<body>
227<div id=\"graphdiv\"></div>
228<p><input type=checkbox id=\"0\" checked onClick=\"change(this)\">
229<label for=\"0\">reference</label>
230<input type=checkbox id=\"1\" checked onClick=\"change(this)\">
231<label for=\"1\">actual</label>
232<input type=checkbox id=\"2\" checked onClick=\"change(this)\">
233<label for=\"2\">high</label>
234<input type=checkbox id=\"3\" checked onClick=\"change(this)\">
235<label for=\"3\">low</label>
236<input type=checkbox id=\"4\" checked onClick=\"change(this)\">
237<label for=\"4\">error</label>
238<input type=checkbox id=\"5\" onClick=\"change(this)\">
239<label for=\"5\">actual (original)</label>
240Parameters used for the comparison: Relative tolerance "+String(reference_reltol)+" (local), "+String(reference_reltolDiffMinMax)+" (relative to max-min). Range delta "+String(reference_rangeDelta)+".</p>
241<script type=\"text/javascript\">
242g = new Dygraph(document.getElementById(\"graphdiv\"),
243 \""+OpenModelica.Scripting.basename(prefix + "." + var+".csv")+"\",{title: '"+var+"',
244 legend: 'always',
245 connectSeparatedPoints: true,
246 xlabel: ['time'],
247 y2label: ['error'],
248 series : { 'error': { axis: 'y2' } },
249 colors: ['blue','red','teal','lightblue','orange','black'],
250 visibility: [true,true,true,true,true,false]
251});
252function change(el) {
253 g.setVisibility(parseInt(el.id), el.checked);
254}
255</script>
256</body>
257</html>") for var in diffVars};
258
259 else
260 referenceCell := "<td bgcolor=\"#00FF00\">"+OpenModelica.Scripting.Internal.Time.readableTime(timeDiff)+" ("+String(numCompared)+" signals)</td>";
261 end if;
262 end if;
263end if;
264
265sim:=readFile(simFile);
266str:="<tr><td>" + (if err <> "" then "<a class=\""+errorLinkClass+"\" href=\""+errFile+"\">ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array</a>" else "ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array") +
267 (if sim <> "" then " (<a href=\""+simFile+"\">sim</a>)" else "") +
268 "</td>" + referenceCell +
269 cell(if simRes then timeSim else -1.0,greenOnOk=true,greenColor=greenColor,mdFile=mdFile) +
270 "<td bgcolor=\""+(if res[1]<>"" then greenColor else "#FF0000")+"\">"+OpenModelica.Scripting.Internal.Time.readableTime(total)+"</td>" +
271 sum(cell(d,greenColor=greenColor) for d in {frontend,backend,simcode,templates,build}) + "</tr>\n";getErrorString();
272writeFile(statFile,str);getErrorString();
273skip:="<testcase name=\"ScalableTestSuite.Electrical.BreakerCircuits.Verification.BreakerNetwork_3_Array\"><skipped /></testcase>";
274str:=testcase(frontend,backend <> -1.0,err);
275writeFile(statFile + ".flat", str);getErrorString();
276str:=if backend <> -1.0 then testcase(total,buildRes,err) else skip;
277writeFile(statFile + ".compile", str);getErrorString();
278str:=if buildRes then testcase(timeSim,simRes,sim) else skip;
279writeFile(statFile + ".sim", str);getErrorString();
280str:=if simRes then testcase(timeDiff,referenceOK,if referenceOK then "" else "See the generated report for details") else skip;
281writeFile(statFile + ".verify", str);getErrorString();