Skip to content

Commit

Permalink
Use -output-flag instead of val-function
Browse files Browse the repository at this point in the history
because it is not reliable if you change the
value after compilation.
  • Loading branch information
ptaeuber committed Oct 4, 2016
1 parent a7103da commit 8163c35
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 220 deletions.
21 changes: 4 additions & 17 deletions simulation/modelica/parameters/parameterTest.mos
Expand Up @@ -65,14 +65,7 @@ end parameterTest;
"); getErrorString();

setCommandLineOptions("-d=evalParameterDump, --evalConstArgsOnly=false"); getErrorString();
simulate(parameterTest); getErrorString();
val(p1, 0.0);
val(p2, 0.0);
val(p3, 0.0);
val(p4, 0.0);
val(p5, 0.0);
val(b1, 0.0);
val(b2, 0.0);
simulate(parameterTest, simflags="-output=p1,p2,p3,p4,p5,b1,b2"); getErrorString();

// Result:
// true
Expand Down Expand Up @@ -497,15 +490,9 @@ val(b2, 0.0);
//
// record SimulationResult
// resultFile = "parameterTest_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'parameterTest', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = ""
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'parameterTest', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-output=p1,p2,p3,p4,p5,b1,b2'",
// messages = "time=1,p1=1,p2=2,p3=3,p4=-2,p5=5,b1=0,b2=1
// "
// end SimulationResult;
// ""
// 1.0
// 2.0
// 3.0
// -2.0
// 5.0
// 0.0
// 1.0
// endResult
131 changes: 8 additions & 123 deletions simulation/modelica/parameters/parameterTest6.mos
Expand Up @@ -9,15 +9,15 @@ model parameterTest6
Integer y;
Integer z;
parameter Integer p1 = 2;
parameter Integer p2 = if b1 then e1 + p4 elseif b2 then p1 - p3 else e1 - p3;
parameter Integer p2 = if b1 then e1 + p4 elseif b2 then p1 - p3 else e1 - p3; // p2 = p1 - p3
parameter Integer p3 = 5;
parameter Integer p4 = f1 + p1;
parameter Integer p5 = pr1;
final parameter Integer f1 = p1;
final parameter Integer f2 = 10;
parameter Boolean b1 = false annotation(Evaluate=true);
parameter Boolean b2 = true annotation(Evaluate=true);
parameter Integer e1 = if b1 then p3 + p1 else p2 + 7 annotation(Evaluate=true);
parameter Integer e1 = if b1 then p3 + p1 else p2 + 7 annotation(Evaluate=true); // e1 = p2 + 7
parameter Integer s = 3;
parameter Integer a[s] = ones(s) annotation(Evaluate=true);
protected
Expand All @@ -30,49 +30,8 @@ end parameterTest6;
"); getErrorString();

setCommandLineOptions("--preOptModules-=evaluateReplaceProtectedFinalEvaluateParameters --preOptModules+=evaluateReplaceEvaluateParameters -d=evalParameterDump");
simulate(parameterTest6); getErrorString();
print("----p1--"); val(p1, 0.0, "parameterTest6_res.mat");
print("----p2--"); val(p2, 0.0);
print("----p3--"); val(p3, 0.0);
print("----p4--"); val(p4, 0.0);
print("----p5--"); val(p5, 0.0);
print("----f1--"); val(f1, 0.0);
print("----f2--"); val(f2, 0.0);
print("----b1--"); val(b1, 0.0);
print("----b2--"); val(b2, 0.0);
print("----e1--"); val(e1, 0.0);
print("----s---"); val(s, 0.0);
print("----a[1]"); val(a[1], 0.0);
print("----a[2]"); val(a[2], 0.0);
print("----a[3]"); val(a[3], 0.0);
print("----pr1-"); val(pr1, 0.0);
print("----x---"); val(x, 0.0);
print("----y---"); val(y, 0.0);
print("----z---"); val(z, 0.0);

print("\n");
system("./parameterTest6 -override s=5");
print("\n");

print("----p1--"); val(p1, 0.0, "parameterTest6_res.mat");
print("----p2--"); val(p2, 0.0);
print("----p3--"); val(p3, 0.0);
print("----p4--"); val(p4, 0.0);
print("----p5--"); val(p5, 0.0);
print("----f1--"); val(f1, 0.0);
print("----f2--"); val(f2, 0.0);
print("----b1--"); val(b1, 0.0);
print("----b2--"); val(b2, 0.0);
print("----e1--"); val(e1, 0.0);
print("----s---"); val(s, 0.0);
print("----a[1]"); val(a[1], 0.0);
print("----a[2]"); val(a[2], 0.0);
print("----a[3]"); val(a[3], 0.0);
print("----pr1-"); val(pr1, 0.0);
print("----x---"); val(x, 0.0);
print("----y---"); val(y, 0.0);
print("----z---"); val(z, 0.0);
getErrorString();
simulate(parameterTest6, simflags="-output=p1,p2,p3,p4,p5,f1,f2,b1,b2,e1,s,a[1],a[2],a[3],pr1,x,y,z"); getErrorString();
system("./parameterTest6 -override s=5 -output=p1,p2,p3,p4,p5,f1,f2,b1,b2,e1,s,a[1],a[2],a[3],pr1,x,y,z"); getErrorString();


// Result:
Expand Down Expand Up @@ -498,86 +457,12 @@ getErrorString();
//
// record SimulationResult
// resultFile = "parameterTest6_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'parameterTest6', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = ""
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'parameterTest6', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-output=p1,p2,p3,p4,p5,f1,f2,b1,b2,e1,s,a[1],a[2],a[3],pr1,x,y,z'",
// messages = "time=1,p1=2,p2=-3,p3=5,p4=4,p5=100,f1=2,f2=10,b1=0,b2=1,e1=4,s=3,a[1]=1,a[2]=1,a[3]=1,pr1=100,x=-1,y=115,z=6
// "
// end SimulationResult;
// ""
// ----p1--
// 2.0
// ----p2--
// -3.0
// ----p3--
// 5.0
// ----p4--
// 4.0
// ----p5--
// 100.0
// ----f1--
// 2.0
// ----f2--
// 10.0
// ----b1--
// 0.0
// ----b2--
// 1.0
// ----e1--
// 4.0
// ----s---
// 3.0
// ----a[1]
// 1.0
// ----a[2]
// 1.0
// ----a[3]
// 1.0
// ----pr1-
// 100.0
// ----x---
// -1.0
// ----y---
// 115.0
// ----z---
// 6.0
//
//
// time=1,p1=2,p2=-3,p3=5,p4=4,p5=100,f1=2,f2=10,b1=0,b2=1,e1=4,s=5,a[1]=1,a[2]=1,a[3]=1,pr1=100,x=-1,y=115,z=8
// 0
//
//
// ----p1--
// 2.0
// ----p2--
// -3.0
// ----p3--
// 5.0
// ----p4--
// 4.0
// ----p5--
// 100.0
// ----f1--
// 2.0
// ----f2--
// 10.0
// ----b1--
// 0.0
// ----b2--
// 1.0
// ----e1--
// 4.0
// ----s---
// 3.0
// ----a[1]
// 1.0
// ----a[2]
// 1.0
// ----a[3]
// 1.0
// ----pr1-
// 100.0
// ----x---
// -1.0
// ----y---
// 115.0
// ----z---
// 6.0
// ""
// endResult
55 changes: 6 additions & 49 deletions simulation/modelica/parameters/parameterTest7.mos
Expand Up @@ -19,25 +19,8 @@ end parameterTest7;
"); getErrorString();

setCommandLineOptions("--preOptModules-=evaluateReplaceProtectedFinalEvaluateParameters --preOptModules+=evaluateReplaceEvaluateParameters -d=evalParameterDump");
simulate(parameterTest7); getErrorString();
print("----p1--"); val(p1, 0.0, "parameterTest7_res.mat");
print("----p2--"); val(p2, 0.0);
print("----s---"); val(s, 0.0);
print("----a[1]"); val(a[1], 0.0);
print("----a[2]"); val(a[2], 0.0);
print("----a[3]"); val(a[3], 0.0);

print("\n");
system("./parameterTest7 -override p2=10");
print("\n");

print("----p1--"); val(p1, 0.0, "parameterTest7_res.mat");
print("----p2--"); val(p2, 0.0);
print("----s---"); val(s, 0.0);
print("----a[1]"); val(a[1], 0.0);
print("----a[2]"); val(a[2], 0.0);
print("----a[3]"); val(a[3], 0.0);
getErrorString();
simulate(parameterTest7, simflags="-output=p1,p2,s,a[1],a[2],a[3]"); getErrorString();
system("./parameterTest7 -override p2=10 -output=p1,p2,s,a[1],a[2],a[3]"); getErrorString();

// Result:
// true
Expand Down Expand Up @@ -486,38 +469,12 @@ getErrorString();
//
// record SimulationResult
// resultFile = "parameterTest7_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'parameterTest7', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = ""
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'parameterTest7', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-output=p1,p2,s,a[1],a[2],a[3]'",
// messages = "time=1,p1=3,p2=3,s=3,a[1]=1,a[2]=2,a[3]=3
// "
// end SimulationResult;
// ""
// ----p1--
// 3.0
// ----p2--
// 3.0
// ----s---
// 3.0
// ----a[1]
// 1.0
// ----a[2]
// 2.0
// ----a[3]
// 3.0
//
//
// time=1,p1=10,p2=10,s=10,a[1]=1,a[2]=2,a[3]=3
// 0
//
//
// ----p1--
// 3.0
// ----p2--
// 3.0
// ----s---
// 3.0
// ----a[1]
// 1.0
// ----a[2]
// 2.0
// ----a[3]
// 3.0
// ""
// endResult
37 changes: 6 additions & 31 deletions simulation/modelica/parameters/parameterTest8.mos
Expand Up @@ -21,19 +21,8 @@ end parameterTest8;
"); getErrorString();

setCommandLineOptions("--preOptModules-=evaluateReplaceProtectedFinalEvaluateParameters --preOptModules+=evaluateReplaceEvaluateParameters -d=evalParameterDump");
simulate(parameterTest8); getErrorString();
print("--state--"); val(state, 0.0, "parameterTest8_res.mat");
print("-----v---"); val(v, 0.0);
print("-----r---"); val(r, 0.0);

print("\n");
system("./parameterTest8 -override state=false");
print("\n");

print("--state--"); val(state, 0.0, "parameterTest8_res.mat");
print("-----v---"); val(v, 0.0);
print("-----r---"); val(r, 0.0);
getErrorString();
simulate(parameterTest8, simflags="-output=state,v,r"); getErrorString();
system("./parameterTest8 -override state=false -output=state,v,r"); getErrorString();


// Result:
Expand Down Expand Up @@ -299,27 +288,13 @@ getErrorString();
//
// record SimulationResult
// resultFile = "parameterTest8_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'parameterTest8', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = ""
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'parameterTest8', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-output=state,v,r'",
// messages = "time=1,state=1,v=1,r=2
// "
// end SimulationResult;
// "Warning: The initial conditions are not fully specified. For more information set -d=initialization. In OMEdit Tools->Options->Simulation->OMCFlags, in OMNotebook call setCommandLineOptions("-d=initialization").
// "
// --state--
// 1.0
// -----v---
// 0.0
// -----r---
// 0.0
//
//
// time=1,state=0,v=1,r=2
// 0
//
//
// --state--
// 1.0
// -----v---
// 0.0
// -----r---
// 0.0
// ""
// endResult

0 comments on commit 8163c35

Please sign in to comment.