Skip to content

Commit

Permalink
Fixes for SMEE_Rectifier
Browse files Browse the repository at this point in the history
- Use the original reference file, filtered for the expected variables
  as well as as reduced number of intervals (=1500)
- Add support for diffSimulationResults in ModelTesting.mos
  - Use diffSimulationResults for SMEE_Rectifier
  - Change SMEE_Rectifier to verified results
  • Loading branch information
sjoelund committed May 18, 2015
1 parent c5ab20c commit f9fa946
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
Binary file not shown.
2 changes: 2 additions & 0 deletions simulation/libraries/common/ModelTesting.mo
Expand Up @@ -11,4 +11,6 @@ type Kind = enumeration(Instantiation "Like instantiateModel()",
type SimulationRuntime = enumeration(C "C Runtime",
Cpp "Cpp Runtime");

type DiffAlgorithm = enumeration(compareSimulationResults, diffSimulationResults);

end OpenModelicaModelTesting;
34 changes: 27 additions & 7 deletions simulation/libraries/common/ModelTesting.mos
Expand Up @@ -177,23 +177,43 @@ elseif (modelTestingType == OpenModelicaModelTesting.Kind.VerifiedSimulation) or
// support for csv result files
resultFile:= if regularFileExists(resultFile) then resultFile else modelNameStr+"_res.csv";
csvFile := modelNameStr + ".csv";
print(if debug then "try to compare results " + resultFile + " " + referenceFile + " " + csvFile + " " + String(relTol) + " " + String(absTol) + sum(" " + v + "," for v in compareVars) + "\n" else "");
res := OpenModelica.Scripting.compareSimulationResults(resultFile,referenceFile,csvFile,relTol,absTol,compareVars);
print(if debug then "compareSimulationResults finished: "+sum(r for r in res)+"\n" else "");
if size(res,1) == 1 and res[1] == "Files Equal!" and modelTestingType <> OpenModelicaModelTesting.Kind.VerifiedSimulation and modelTestingType <> OpenModelicaModelTesting.Kind.SuppressedVerifiedSimulation then

if diffAlgorithm == OpenModelicaModelTesting.DiffAlgorithm.compareSimulationResults then
print(if debug then "try to compare results " + resultFile + " " + referenceFile + " " + csvFile + " " + String(relTol) + " " + String(absTol) + sum(" " + v + "," for v in compareVars) + "\n" else "");
res := OpenModelica.Scripting.compareSimulationResults(resultFile,referenceFile,csvFile,relTol,absTol,compareVars);
print(if debug then "compareSimulationResults finished: "+sum(r for r in res)+"\n" else "");
if size(res,1)==1 and res[1] == "Files Equal!" then
res := true;
else
failVars := res[2:size(res,1)];
res := false;
end if;
elseif diffAlgorithm == OpenModelicaModelTesting.DiffAlgorithm.diffSimulationResults then
print(if debug then "Trying diffSimulationResults.\n" else "");
(res,ignore,failVars) := OpenModelica.Scripting.diffSimulationResults(resultFile,referenceFile,csvFile+"diff.",relTol,vars=compareVars);
print(if debug then "diffSimulationResults returns "+String(res)+".\n" else "");
else
print("Unknown diff algorithm!\n");
exit(1);
end if;

if res and modelTestingType <> OpenModelicaModelTesting.Kind.VerifiedSimulation and modelTestingType <> OpenModelicaModelTesting.Kind.SuppressedVerifiedSimulation then
print("Note: Result files are now equal. Please update the test to do verified simulation!\n");
exit(1);
elseif modelTestingType == OpenModelicaModelTesting.Kind.VerifiedSimulation or modelTestingType == OpenModelicaModelTesting.Kind.SuppressedVerifiedSimulation then
print(sum(r + "\n" for r in res));
if size(res,1) <> 1 then
if res then
print("Files Equal!\n");
end if;
if not res then
print("Failed variables: " + sum(var for var in failVars));
print(error);
print(getErrorString());
info:=checkSettings();
os:=info.OS;
dateCmd := if os=="Windows_NT" then "date /T" else "date";
system(dateCmd); // In case people somehow try to fool their tests, add some non-determinism
system("cp \"" + getInstallationDirectoryPath() + "/share/doc/omc/testmodels/dygraph-combined.js\" .");
for v in res[2:size(res,1)] loop
for v in failVars[2:size(failVars,1)] loop
// Write some html files with the diffs
curFile := modelNameStr + "." + v + ".html";
writeFile(curFile, diffSimulationResultsHtml(v,resultFile,referenceFile));
Expand Down
1 change: 1 addition & 0 deletions simulation/libraries/common/ModelTestingDefaults.mos
Expand Up @@ -6,6 +6,7 @@ packageVersion := "3.2.1";
setCommandLineOptions("+d=nogen"); // Use and so I don't need to baseline the tests again...
modelTestingType := OpenModelicaModelTesting.Kind.VerifiedSimulation;
simulationRuntime := OpenModelicaModelTesting.SimulationRuntime.C;
diffAlgorithm := OpenModelicaModelTesting.DiffAlgorithm.compareSimulationResults;
stopTime := 0.0; // 0.0 means to read the stopTime from the experiment annotation, or use the OpenModelica default
relTol := 0.01; // Tolerance for the simulation comparison
absTol := 0.0001; // Tolerance for the simulation comparison
Expand Down
Expand Up @@ -8,7 +8,8 @@

runScript("../common/ModelTestingDefaults.mos"); getErrorString();

modelTestingType := OpenModelicaModelTesting.Kind.SimpleSimulation;
modelTestingType := OpenModelicaModelTesting.Kind.VerifiedSimulation;
diffAlgorithm := OpenModelicaModelTesting.DiffAlgorithm.diffSimulationResults;
modelName := $TypeName(Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMEE_Rectifier);
compareVars :=
{
Expand All @@ -32,11 +33,13 @@ runScript(modelTesting);getErrorString();
// "true
// "
// ""
// OpenModelicaModelTesting.Kind.SimpleSimulation
// OpenModelicaModelTesting.Kind.VerifiedSimulation
// OpenModelicaModelTesting.DiffAlgorithm.diffSimulationResults
// Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMEE_Rectifier
// {"capacitor1.v","capacitor2.v","filter.x[1]","filter.x[2]","smee.idq_dr[1]","smee.idq_rr[2]","smee.idq_sr[1]","smee.idq_sr[2]","smee.lesigma.i","speed.phi","speed.w","voltageController.I.y"}
// Simulation options: startTime = 0.0, stopTime = 1.1, numberOfIntervals = 11000, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMEE_Rectifier', options = '', outputFormat = 'mat', variableFilter = 'time|capacitor1.v|capacitor2.v|filter.x.1.|filter.x.2.|smee.idq_dr.1.|smee.idq_rr.2.|smee.idq_sr.1.|smee.idq_sr.2.|smee.lesigma.i|speed.phi|speed.w|voltageController.I.y', cflags = '', simflags = ' -abortSlowSimulation -alarm=360 -emit_protected'
// Result file: Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMEE_Rectifier_res.mat
// Files Equal!
// "true
// "
// ""
Expand Down

0 comments on commit f9fa946

Please sign in to comment.