Skip to content

Commit be78147

Browse files
crupp2lochel
authored andcommitted
Added numeric tests for all test cases
1 parent 202229e commit be78147

19 files changed

+1138
-92
lines changed

openmodelica/linearization/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ smallValues.mos \
1414
simLotkaVolterra.mos \
1515
simTwoTank.mos \
1616
simNonlinear.mos \
17-
simNonlinear_numeric.mos \
1817
simextfunction.mos \
1918
test_01.mos \
2019
test_02.mos \

openmodelica/linearization/linmodel.mos

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,19 @@ loadFile("linear_linearmodel.mo");
1313
list(linear_linearmodel);
1414
simulate(linear_linearmodel);
1515
getErrorString();
16-
readFile("linear_linearmodel.log"); // Check that output log is emtpy
17-
echo(false); // turns of output
16+
readFile("linear_linearmodel.log"); // Check that output log is empty
17+
18+
//
19+
// Case for numeric linearization of VanDerPol model
20+
//
21+
//linearize with numeric linearization and data recovery
22+
simulate(linearmodel, simflags="-l=0 -l_datarec");
23+
getErrorString();
24+
loadFile("linear_linearmodel.mo");
25+
list(linear_linearmodel);
26+
simulate(linear_linearmodel);
27+
getErrorString();
28+
readFile("linear_linearmodel.log"); // Check that output log is empty
1829

1930
// Result:
2031
// true
@@ -60,4 +71,53 @@ echo(false); // turns of output
6071
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
6172
// "
6273
// ""
74+
// record SimulationResult
75+
// resultFile = "linearmodel_res.mat",
76+
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'linearmodel', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-l=0 -l_datarec'",
77+
// messages = "stdout | info | Linearization will performed at point of time: 0.000000
78+
// stdout | info | Linear model is created!
79+
// "
80+
// end SimulationResult;
81+
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
82+
// "
83+
// true
84+
// "model linear_linearmodel
85+
// parameter Integer n = 4;
86+
// // states
87+
// parameter Integer k = 0;
88+
// // top-level inputs
89+
// parameter Integer l = 0;
90+
// // top-level outputs
91+
// parameter Integer nz = 0;
92+
// // data recovery variables
93+
// parameter Real x0[4] = {1, -2, 3, -5};
94+
// parameter Real u0[0] = {i for i in 1:0};
95+
// parameter Real z0[0] = {i for i in 1:0};
96+
// parameter Real A[4, 4] = [-2.999999997398604, 1.999999993823069, 0, 0; -6.999999996151411, 0, -5.000000006771011, 0.9999999880261984; -0.9999999880261984, 0, -1.000000001354202, 3.999999996531473; 0, 1.000000014682206, -1.000000001354202, 4.999999984557672];
97+
// parameter Real B[4, 0] = zeros(4, 0);
98+
// parameter Real C[0, 4] = zeros(0, 4);
99+
// parameter Real D[0, 0] = zeros(0, 0);
100+
// parameter Real Cz[0, 4] = zeros(0, 4);
101+
// parameter Real Dz[0, 0] = zeros(0, 0);
102+
// Real x[4](start = x0);
103+
// input Real u[0];
104+
// output Real y[0];
105+
// output Real z[0];
106+
// Real x_Px1 = x[1];
107+
// Real x_Px2 = x[2];
108+
// Real x_Px3 = x[3];
109+
// Real x_Px4 = x[4];
110+
// equation
111+
// der(x) = A * x + B * u;
112+
// y = C * x + D * u;
113+
// z = Cz * x + Dz * u;
114+
// end linear_linearmodel;"
115+
// record SimulationResult
116+
// resultFile = "linear_linearmodel_res.mat",
117+
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'linear_linearmodel', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
118+
// messages = ""
119+
// end SimulationResult;
120+
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
121+
// "
122+
// ""
63123
// endResult

openmodelica/linearization/simLotkaVolterra.mos

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@ loadFile("linear_LotkaVolterra.mo");
1313
list(linear_LotkaVolterra);
1414
simulate(linear_LotkaVolterra);
1515
getErrorString();
16-
readFile("linear_LotkaVolterra.log"); // Check that output log is emtpy
16+
readFile("linear_LotkaVolterra.log"); // Check that output log is empty
17+
18+
//
19+
// Case for numeric linearization of LotkaVolterra model
20+
//
21+
//linearize with numeric linearization and data recovery
22+
simulate(LotkaVolterra, simflags="-l=0 -l_datarec");
23+
getErrorString();
24+
loadFile("linear_LotkaVolterra.mo");
25+
list(linear_LotkaVolterra);
26+
simulate(linear_LotkaVolterra);
27+
getErrorString();
28+
readFile("linear_LotkaVolterra.log"); // Check that output log is empty
1729

1830
// Result:
1931
// true
@@ -57,4 +69,51 @@ readFile("linear_LotkaVolterra.log"); // Check that output log is emtpy
5769
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
5870
// "
5971
// ""
72+
// record SimulationResult
73+
// resultFile = "LotkaVolterra_res.mat",
74+
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'LotkaVolterra', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-l=0 -l_datarec'",
75+
// messages = "stdout | info | Linearization will performed at point of time: 0.000000
76+
// stdout | info | Linear model is created!
77+
// "
78+
// end SimulationResult;
79+
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
80+
// "
81+
// true
82+
// "model linear_LotkaVolterra
83+
// parameter Integer n = 2;
84+
// // states
85+
// parameter Integer k = 0;
86+
// // top-level inputs
87+
// parameter Integer l = 0;
88+
// // top-level outputs
89+
// parameter Integer nz = 0;
90+
// // data recovery variables
91+
// parameter Real x0[2] = {5, 3};
92+
// parameter Real u0[0] = {i for i in 1:0};
93+
// parameter Real z0[0] = {i for i in 1:0};
94+
// parameter Real A[2, 2] = [-3.999999996531473, -15.00000002031303; 3.000000008505274, 3.000000004062607];
95+
// parameter Real B[2, 0] = zeros(2, 0);
96+
// parameter Real C[0, 2] = zeros(0, 2);
97+
// parameter Real D[0, 0] = zeros(0, 0);
98+
// parameter Real Cz[0, 2] = zeros(0, 2);
99+
// parameter Real Dz[0, 0] = zeros(0, 0);
100+
// Real x[2](start = x0);
101+
// input Real u[0];
102+
// output Real y[0];
103+
// output Real z[0];
104+
// Real x_Px = x[1];
105+
// Real x_Py = x[2];
106+
// equation
107+
// der(x) = A * x + B * u;
108+
// y = C * x + D * u;
109+
// z = Cz * x + Dz * u;
110+
// end linear_LotkaVolterra;"
111+
// record SimulationResult
112+
// resultFile = "linear_LotkaVolterra_res.mat",
113+
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'linear_LotkaVolterra', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
114+
// messages = ""
115+
// end SimulationResult;
116+
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
117+
// "
118+
// ""
60119
// endResult

openmodelica/linearization/simNonlinear.mos

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@ loadFile("linear_p.nonlinsys.mo");
1313
list(linear_p_nonlinsys);
1414
simulate(linear_p_nonlinsys);
1515
getErrorString();
16-
readFile("linear_p_nonlinsys.log"); // Check that output log is emtpy
16+
readFile("linear_p_nonlinsys.log"); // Check that output log is empty
17+
18+
//
19+
// Case for numeric linearization of nonlinsys model
20+
//
21+
//linearize with numeric linearization and data recovery
22+
simulate(p.nonlinsys, simflags="-l=0 -l_datarec");
23+
getErrorString();
24+
loadFile("linear_p.nonlinsys.mo");
25+
list(linear_p_nonlinsys);
26+
simulate(linear_p_nonlinsys);
27+
getErrorString();
28+
readFile("linear_p_nonlinsys.log"); // Check that output log is empty
1729

1830
// Result:
1931
// true
@@ -61,4 +73,61 @@ readFile("linear_p_nonlinsys.log"); // Check that output log is emtpy
6173
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
6274
// "
6375
// ""
76+
// record SimulationResult
77+
// resultFile = "p.nonlinsys_res.mat",
78+
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'p.nonlinsys', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-l=0 -l_datarec'",
79+
// messages = "stdout | info | Linearization will performed at point of time: 0.000000
80+
// stdout | info | Linear model is created!
81+
// "
82+
// end SimulationResult;
83+
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
84+
// "
85+
// true
86+
// "model linear_p_nonlinsys
87+
// parameter Integer n = 3;
88+
// // states
89+
// parameter Integer k = 1;
90+
// // top-level inputs
91+
// parameter Integer l = 2;
92+
// // top-level outputs
93+
// parameter Integer nz = 6;
94+
// // data recovery variables
95+
// parameter Real x0[3] = {1, 1, 2};
96+
// parameter Real u0[1] = {0};
97+
// parameter Real z0[6] = {0, -6, -6, 0, 0, 0};
98+
// parameter Real A[3, 3] = [0, 0, 0; 0, 5.999999994797209, -2.000000002708405; 0, 3.999999998752807, -6.000000017010549];
99+
// parameter Real B[3, 1] = [0; 0; 0];
100+
// parameter Real C[2, 3] = [0, 0, 0; 0, 0, 0];
101+
// parameter Real D[2, 1] = [0; 0];
102+
// parameter Real Cz[6, 3] = [0, 0, 0; 0, 9.999999993550016, -8.000000019718954; 0, 9.999999993550016, -8.000000019718954; 0, 0, 0; 0, 0, 0; 0, 0, 0];
103+
// parameter Real Dz[6, 1] = [0; 0; 0; 1; 0; 0];
104+
// Real x[3](start = x0);
105+
// input Real u[1](start = u0);
106+
// output Real y[2];
107+
// output Real z[6];
108+
// Real x_Pb1Px = x[1];
109+
// Real x_Pc1Px1 = x[2];
110+
// Real x_Pc1Px2 = x[3];
111+
// Real u_Pu1 = u[1];
112+
// Real y_Py1 = y[1];
113+
// Real y_Py2 = y[2];
114+
// Real z_Pa1Py = z[1];
115+
// Real z_Pc1Py = z[2];
116+
// Real z_Pc1Py1 = z[3];
117+
// Real z_Pu1 = z[4];
118+
// Real z_Py1 = z[5];
119+
// Real z_Py2 = z[6];
120+
// equation
121+
// der(x) = A * x + B * u;
122+
// y = C * x + D * u;
123+
// z = Cz * x + Dz * u;
124+
// end linear_p_nonlinsys;"
125+
// record SimulationResult
126+
// resultFile = "linear_p_nonlinsys_res.mat",
127+
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'linear_p_nonlinsys', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
128+
// messages = ""
129+
// end SimulationResult;
130+
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
131+
// "
132+
// ""
64133
// endResult

openmodelica/linearization/simNonlinear_numeric.mos

Lines changed: 0 additions & 78 deletions
This file was deleted.

openmodelica/linearization/simTwoTank.mos

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@ loadFile("linear_twoflattankmodel.mo");
1313
list(linear_twoflattankmodel);
1414
simulate(linear_twoflattankmodel,method="dassl");
1515
getErrorString();
16-
readFile("linear_twoflattankmodel.log"); // Check that output log is emtpy
16+
readFile("linear_twoflattankmodel.log"); // Check that output log is empty
17+
18+
//
19+
// Case for numeric linearization of twoflattankmodel model
20+
//
21+
//linearize with numeric linearization and data recovery
22+
simulate(twoflattankmodel, simflags="-l=0 -l_datarec");
23+
getErrorString();
24+
loadFile("linear_twoflattankmodel.mo");
25+
list(linear_twoflattankmodel);
26+
simulate(linear_twoflattankmodel);
27+
getErrorString();
28+
readFile("linear_twoflattankmodel.log"); // Check that output log is empty
1729

1830
// Result:
1931
// true
@@ -59,4 +71,56 @@ readFile("linear_twoflattankmodel.log"); // Check that output log is emtpy
5971
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
6072
// "
6173
// ""
74+
// record SimulationResult
75+
// resultFile = "twoflattankmodel_res.mat",
76+
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'twoflattankmodel', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-l=0 -l_datarec'",
77+
// messages = "stdout | info | Linearization will performed at point of time: 0.000000
78+
// stdout | info | Linear model is created!
79+
// "
80+
// end SimulationResult;
81+
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
82+
// "
83+
// true
84+
// "model linear_twoflattankmodel
85+
// parameter Integer n = 2;
86+
// // states
87+
// parameter Integer k = 1;
88+
// // top-level inputs
89+
// parameter Integer l = 1;
90+
// // top-level outputs
91+
// parameter Integer nz = 3;
92+
// // data recovery variables
93+
// parameter Real x0[2] = {2, 1};
94+
// parameter Real u0[1] = {0};
95+
// parameter Real z0[3] = {0, 2, 1};
96+
// parameter Real A[2, 2] = [-0.4999999873490973, 0.5000000165041055; 1.999999949396389, -3.000000034050615];
97+
// parameter Real B[2, 1] = [0.500000000677101; 0];
98+
// parameter Real C[1, 2] = [0, 0.4999999840170964];
99+
// parameter Real D[1, 1] = [0];
100+
// parameter Real Cz[3, 2] = [0, 0; 0.9999999746981947, -1.000000033008211; 0, 0.4999999840170964];
101+
// parameter Real Dz[3, 1] = [1; 0; 0];
102+
// Real x[2](start = x0);
103+
// input Real u[1](start = u0);
104+
// output Real y[1];
105+
// output Real z[3];
106+
// Real x_Ph1 = x[1];
107+
// Real x_Ph2 = x[2];
108+
// Real u_PF = u[1];
109+
// Real y_PF2 = y[1];
110+
// Real z_PF = z[1];
111+
// Real z_PF1 = z[2];
112+
// Real z_PF2 = z[3];
113+
// equation
114+
// der(x) = A * x + B * u;
115+
// y = C * x + D * u;
116+
// z = Cz * x + Dz * u;
117+
// end linear_twoflattankmodel;"
118+
// record SimulationResult
119+
// resultFile = "linear_twoflattankmodel_res.mat",
120+
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'linear_twoflattankmodel', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
121+
// messages = ""
122+
// end SimulationResult;
123+
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
124+
// "
125+
// ""
62126
// endResult

0 commit comments

Comments
 (0)