Skip to content

Commit

Permalink
Merge branch 'qss'
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel committed May 20, 2015
2 parents e4416ea + efc65e1 commit d798361
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 5 deletions.
9 changes: 8 additions & 1 deletion simulation/modelica/qss/Makefile
Expand Up @@ -2,11 +2,18 @@ TEST = ../../../rtest -v

TESTFILES = \
qss_example1.mos \
qss_example2.mos \
qss_example3.mos \
qss_example4.mos \
qss_example5.mos \
qss_example6.mos \
qss_example7.mos \
qss_example8.mos \
qss_example9.mos \

# test that currently fail. Move up when fixed.
# Run make failingtest
FAILINGTESTFILES = \
qss_example2.mos \

# Dependency files that are not .mo .mos or Makefile
# Add them here or they will be cleaned.
Expand Down
5 changes: 3 additions & 2 deletions simulation/modelica/qss/qss_example1.mos
Expand Up @@ -13,7 +13,7 @@ end qssTests;
"); getErrorString();

simulate(qssTests.example1, startTime=0.0, stopTime=10.0, method="qss"); getErrorString();
val(x, {0.0, 0.5, 1.0}); getErrorString();
val(x, {0.0, 2.5, 5.0, 10.0}); getErrorString();

// Result:
// true
Expand All @@ -22,9 +22,10 @@ val(x, {0.0, 0.5, 1.0}); getErrorString();
// resultFile = "qssTests.example1_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 10.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'qss', fileNamePrefix = 'qssTests.example1', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = "stdout | warning | This QSS method is under development and should not be used yet.
// stdout | warning | All derivatives are zero at time 9.787606!.
// "
// end SimulationResult;
// ""
// {1.0,0.606,0.368}
// {1.0,0.08203911233500524,0.006688299312076621,0.0}
// ""
// endResult
15 changes: 13 additions & 2 deletions simulation/modelica/qss/qss_example2.mos
@@ -1,22 +1,29 @@
// name: qss_example2
// status: correct

// Quantization-Based New Integration Methods for Stiff ODEs
// Migoni, Kofman, Cellier
// May 2010, p. 5

loadString("
within ;
package qssTests
model example2
Real x1, x2;
// dQ = nominal * 10^-4
Real x1(nominal=10^4), x2(nominal=10^4);
initial equation
x1 = 0;
x2 = 20;
equation
der(x1) = 0.01*x2;
der(x2) = -100*x1 - 100*x2 + 2020;
der(x2) = -100*x1-100*x2+2020;
end example2;
end qssTests;
"); getErrorString();

simulate(qssTests.example2, startTime=0.0, stopTime=500.0, method="qss"); getErrorString();
val(x1, {0.0, 250.0, 500.0}); getErrorString();
val(x2, {0.0, 250.0, 500.0}); getErrorString();

// Result:
// true
Expand All @@ -28,4 +35,8 @@ simulate(qssTests.example2, startTime=0.0, stopTime=500.0, method="qss"); getErr
// "
// end SimulationResult;
// ""
// {0.0,19.01725738678988,20.33630337525792}
// ""
// {20.0,1.774584926419772,0.5913039968093946}
// ""
// endResult
43 changes: 43 additions & 0 deletions simulation/modelica/qss/qss_example3.mos
@@ -0,0 +1,43 @@
// name: qss_example3
// status: correct

// Quantization-Based New Integration Methods for Stiff ODEs
// Migoni, Kofman, Cellier
// May 2010, p. 16

loadString("
within ;
package qssTests
model example3
Real x1(nominal=1), x2(nominal=1);
parameter Real a=0;
parameter Real w=1;
initial equation
x1 = 4;
x2 = 0;
equation
der(x1) = a * x1 + w * x2;
der(x2) = -w * x1 + a * x2;
end example3;
end qssTests;
"); getErrorString();

simulate(qssTests.example3, stopTime=60, method="qss"); getErrorString();
val(x1, {0.0, 60.0}); getErrorString();
val(x2, {0.0, 60.0}); getErrorString();

// Result:
// true
// ""
// record SimulationResult
// resultFile = "qssTests.example3_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 60.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'qss', fileNamePrefix = 'qssTests.example3', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = "stdout | warning | This QSS method is under development and should not be used yet.
// "
// end SimulationResult;
// ""
// {4.0,-3.813295511112654}
// ""
// {0.0,1.220381953186809}
// ""
// endResult
47 changes: 47 additions & 0 deletions simulation/modelica/qss/qss_example4.mos
@@ -0,0 +1,47 @@
// name: qss_example4
// status: correct

// Quantization-Based New Integration Methods for Stiff ODEs
// Migoni, Kofman, Cellier
// May 2010, p. 21

loadString("
within ;
package qssTests
model example4
Real x1(nominal=100), x2(nominal=100), x3(nominal=5e-4);
initial equation
x1 = 1;
x2 = 1;
x3 = 0;
equation
der(x1) = -0.013 * x1 - 1000 * x1 * x3;
der(x2) = -2500 * x2 * x3;
der(x3) = -0.013 * x1 - 1000 * x1 * x3 - 2500 * x2 * x3;
end example4;
end qssTests;
"); getErrorString();

simulate(qssTests.example4, stopTime=500, method="qss"); getErrorString();
val(x1, {0.0, 500.0}); getErrorString();
val(x2, {0.0, 500.0}); getErrorString();
val(x3, {0.0, 500.0}); getErrorString();

// Result:
// true
// ""
// record SimulationResult
// resultFile = "qssTests.example4_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 500.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'qss', fileNamePrefix = 'qssTests.example4', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = "stdout | warning | This QSS method is under development and should not be used yet.
// stdout | warning | All derivatives are zero at time 420.433938!.
// "
// end SimulationResult;
// ""
// {1.0,0.0}
// ""
// {1.0,1.999999999988223}
// ""
// {0.0,0.0}
// ""
// endResult
45 changes: 45 additions & 0 deletions simulation/modelica/qss/qss_example5.mos
@@ -0,0 +1,45 @@
// name: qss_example5
// status: correct

loadString("
within ;
package qssTests
model example5
Real x1(nominal=1), x2(nominal=1e2), x3(nominal=1);
initial equation
x1=1;
x2=1;
x3=1;
equation
der(x1) = x3;
der(x2) = x2 * sin(x3);
der(x3) = x1 * sin(x2) * cos(x3);
end example5;
end qssTests;
"); getErrorString();

setCommandLineOptions("--indexReductionMethod=uode");getErrorString();
simulate(qssTests.example5, stopTime=5, method="qss"); getErrorString();
val(x1, {0.0, 5.0}); getErrorString();
val(x2, {0.0, 5.0}); getErrorString();
val(x3, {0.0, 5.0}); getErrorString();

// Result:
// true
// ""
// true
// ""
// record SimulationResult
// resultFile = "qssTests.example5_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 5.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'qss', fileNamePrefix = 'qssTests.example5', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = "stdout | warning | This QSS method is under development and should not be used yet.
// "
// end SimulationResult;
// ""
// {1.0,7.438837369532695}
// ""
// {1.0,118.3274783548923}
// ""
// {1.0,1.288486633956759}
// ""
// endResult
44 changes: 44 additions & 0 deletions simulation/modelica/qss/qss_example6.mos
@@ -0,0 +1,44 @@
// name: qss_example6
// status: correct

loadString("
within ;
package qssTests
model example6 \"RLC Circuit\"
Real x1(nominal=0.01), x2(nominal=1);
parameter Real L=0.01;
parameter Real U=100;
parameter Real C=0.01;
parameter Real R=100.01;
initial equation
x1 = 0;
x2 = 0;
equation
der(x1) = x2 / L;
der(x2) = U - x1 / C - R / L * x2;
end example6;
end qssTests;
"); getErrorString();

setCommandLineOptions("--indexReductionMethod=uode");getErrorString();
simulate(qssTests.example6, stopTime=6, method="qss"); getErrorString();
val(x1, {0.0, 6.0}); getErrorString();
val(x2, {0.0, 6.0}); getErrorString();

// Result:
// true
// ""
// true
// ""
// record SimulationResult
// resultFile = "qssTests.example6_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 6.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'qss', fileNamePrefix = 'qssTests.example6', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = "stdout | warning | This QSS method is under development and should not be used yet.
// "
// end SimulationResult;
// ""
// {0.0,0.9975217565500376}
// ""
// {0.0,4.146597733702257e-06}
// ""
// endResult
51 changes: 51 additions & 0 deletions simulation/modelica/qss/qss_example7.mos
@@ -0,0 +1,51 @@
// name: qss_example7
// status: correct

loadString("
within ;
package qssTests
model example7
Real x1(nominal=3), x2(nominal=3);
Real dx1(start=0, fixed=true, nominal=3), dx2(start=0, fixed=true, nominal=3);
parameter Real m=1;
parameter Real g=9.81;
parameter Real L=0.5;
parameter Real epsi=1e-6;
Real F(nominal=30);
initial equation
// x1 = sqrt(epsi*(2-epsi));
// x2 = 0.5-epsi;
x1 = 0.5;
x2 = 0;
equation
der(x1) = dx1;
der(x2) = dx2;
m * der(dx1) = -(x1/L)*F;
m * der(dx2) = -(x2/L)*F-m*g;
(x1)^2+(x2)^2=L^2;
end example7;
end qssTests;
"); getErrorString();

setCommandLineOptions("--indexReductionMethod=uode");getErrorString();
simulate(qssTests.example7, stopTime=4.41636511, method="qss"); getErrorString();
val(x1, {0.0, 4.0}); getErrorString();
val(x2, {0.0, 4.0}); getErrorString();

// Result:
// true
// ""
// true
// ""
// record SimulationResult
// resultFile = "qssTests.example7_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 4.41636511, numberOfIntervals = 500, tolerance = 1e-06, method = 'qss', fileNamePrefix = 'qssTests.example7', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = "stdout | warning | This QSS method is under development and should not be used yet.
// "
// end SimulationResult;
// ""
// {0.5,-0.4707135376128905}
// ""
// {0.0,-0.1776113445770274}
// ""
// endResult
68 changes: 68 additions & 0 deletions simulation/modelica/qss/qss_example8.mos
@@ -0,0 +1,68 @@
// name: qss_example8
// status: correct

loadString("
within ;
package qssTests
model example8
Real x1(nominal=1), x2(nominal=1), x3(nominal=1); // deflexion
Real x4(nominal=1), x5(nominal=1), x6(nominal=1); // velocity
parameter Real m1=1;
parameter Real m2=2;
parameter Real m3=3;
parameter Real c1=1;
parameter Real c2=10;
parameter Real c3=5;
parameter Real c4=15;
parameter Real d1=0.5;
parameter Real d2=0.4;
parameter Real d3=0.45;
initial equation
x1 = 0.1;
x2 = 0;
x3 = 0;
x4 = 0;
x5 = 0;
x6 = 0;
equation
der(x1) = x4;
der(x2) = x5;
der(x3) = x6;
der(x4) = -(c1+c2)/m1*x1 + c2/m1*x2 - d1/m1*x4;
der(x5) = c2/m2*x1 - (c2+c3)/m2*x2 + c3/m2*x3 - d2/m2*x5;
der(x6) = c3/m3*x2 - (c3+c4)/m3*x3 - d3/m3*x6;
end example8;
end qssTests;
"); getErrorString();

simulate(qssTests.example8, stopTime=20, method="qss"); getErrorString();
val(x1, {0.0, 20.0}); getErrorString();
val(x2, {0.0, 20.0}); getErrorString();
val(x3, {0.0, 20.0}); getErrorString();
val(x4, {0.0, 20.0}); getErrorString();
val(x5, {0.0, 20.0}); getErrorString();
val(x6, {0.0, 20.0}); getErrorString();

// Result:
// true
// ""
// record SimulationResult
// resultFile = "qssTests.example8_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 20.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'qss', fileNamePrefix = 'qssTests.example8', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = "stdout | warning | This QSS method is under development and should not be used yet.
// "
// end SimulationResult;
// ""
// {0.1,0.001077030775611781}
// ""
// {0.0,-0.001775288784157483}
// ""
// {0.0,0.003171398458016391}
// ""
// {0.0,0.0007}
// ""
// {0.0,4.61667547513319e-05}
// ""
// {0.0,0.0065}
// ""
// endResult

0 comments on commit d798361

Please sign in to comment.