Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SimCode] update linearization dump languages
- ticket #5927
- Loading branch information
Showing
5 changed files
with
279 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
testsuite/openmodelica/linearization/test_dump_languages.mo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// name: test_04.mo | ||
// keywords: <insert keywords here> | ||
// status: correct | ||
// | ||
// <insert description here> | ||
// | ||
|
||
model simple_test | ||
number x1(x(start=1)); | ||
Real x2(start=2); | ||
parameter Real a=6,b=2,c=4; | ||
input Real u = sin(0); | ||
output Real y; | ||
class number | ||
Real x; | ||
end number; | ||
equation | ||
der(x1.x) = x1.x*(a-b*x1.x-x2); | ||
der(x2) = x2*(c-x1.x-x2); | ||
y = x1.x * u + x2 * u; | ||
end simple_test; | ||
|
||
// Result: | ||
// class simple_test | ||
// Real x1(start = 1.0); | ||
// Real x2(start = 2.0); | ||
// parameter Real a = 6.0; | ||
// parameter Real b = 2.0; | ||
// parameter Real c = 4.0; | ||
// input Real u = 0.0; | ||
// output Real y; | ||
// equation | ||
// der(x1) = x1 * (a - b * x1 - x2); | ||
// der(x2) = x2 * (c - x1 - x2); | ||
// y = x1 * u + x2 * u; | ||
// end simple_test; | ||
// endResult |
178 changes: 178 additions & 0 deletions
178
testsuite/openmodelica/linearization/test_dump_languages.mos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// name: test_dump_languages.mos | ||
// keywords: <...> | ||
// status: correct | ||
// teardown_command: rm -rf *simple_test* output.log | ||
// | ||
// <insert description here> | ||
// | ||
|
||
loadFile("test_dump_languages.mo"); getErrorString(); | ||
|
||
setCommandLineOptions("--linearizationDumpLanguage=modelica"); | ||
linearize(simple_test, stopTime=0); getErrorString(); | ||
readFile("linear_simple_test.mo"); getErrorString(); | ||
|
||
setCommandLineOptions("--linearizationDumpLanguage=matlab"); | ||
linearize(simple_test, stopTime=0); getErrorString(); | ||
readFile("linear_simple_test.mo"); getErrorString(); | ||
|
||
setCommandLineOptions("--linearizationDumpLanguage=julia"); | ||
linearize(simple_test, stopTime=0); getErrorString(); | ||
readFile("linear_simple_test.mo"); getErrorString(); | ||
|
||
setCommandLineOptions("--linearizationDumpLanguage=python"); | ||
linearize(simple_test, stopTime=0); getErrorString(); | ||
readFile("linear_simple_test.mo"); getErrorString(); | ||
|
||
// Result: | ||
// true | ||
// "" | ||
// true | ||
// record SimulationResult | ||
// resultFile = "simple_test_res.mat", | ||
// simulationOptions = "startTime = 0.0, stopTime = 0.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'simple_test', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''", | ||
// messages = "stdout | info | Linearization will performed at point of time: 0.000000 | ||
// LOG_SUCCESS | info | The initialization finished successfully without homotopy method. | ||
// LOG_SUCCESS | info | The simulation finished successfully. | ||
// stdout | info | Linear model is created! | ||
// " | ||
// 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"). | ||
// " | ||
// "model linear_simple__test | ||
// parameter Integer n = 2 \"number of states\"; | ||
// parameter Integer p = 1 \"number of inputs\"; | ||
// parameter Integer q = 1 \"number of outputs\"; | ||
// | ||
// parameter Real x0[n] = {1, 2}; | ||
// parameter Real u0[p] = {0}; | ||
// | ||
// parameter Real A[n, n] = [-2.665600749850023e-07, -1.000000001354202; -2.000000002708404, -1.00000010131423]; | ||
// parameter Real B[n, p] = [0; 0]; | ||
// parameter Real C[q, n] = [0, 0]; | ||
// parameter Real D[q, p] = [3]; | ||
// | ||
// Real x[n](start=x0); | ||
// input Real u[p](start=u0); | ||
// output Real y[q]; | ||
// | ||
// Real 'x_x1.x' = x[1]; | ||
// Real 'x_x2' = x[2]; | ||
// Real 'u_u' = u[1]; | ||
// Real 'y_y' = y[1]; | ||
// equation | ||
// der(x) = A * x + B * u; | ||
// y = C * x + D * u; | ||
// end linear_simple__test; | ||
// " | ||
// "" | ||
// true | ||
// record SimulationResult | ||
// resultFile = "simple_test_res.mat", | ||
// simulationOptions = "startTime = 0.0, stopTime = 0.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'simple_test', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''", | ||
// messages = "stdout | info | Linearization will performed at point of time: 0.000000 | ||
// LOG_SUCCESS | info | The initialization finished successfully without homotopy method. | ||
// LOG_SUCCESS | info | The simulation finished successfully. | ||
// stdout | info | Linear model is created! | ||
// " | ||
// 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"). | ||
// " | ||
// "function [n, p, q, x0, u0, A, B, C, D] = simple_test_GetLinearModel() | ||
// % der(x) = A * x + B * u | ||
// % y = C * x + D * u | ||
// n = 2; % number of states | ||
// p = 1; % number of inputs | ||
// q = 1; % number of outputs | ||
// | ||
// x0 = {1, 2}; | ||
// u0 = {0}; | ||
// | ||
// A = [-2.665600749850023e-07, -1.000000001354202; -2.000000002708404, -1.00000010131423]; | ||
// B = [0; 0]; | ||
// C = [0, 0]; | ||
// D = [3]; | ||
// | ||
// x_x1_x = x[1]; | ||
// x_x2 = x[2]; | ||
// u_u = u[1]; | ||
// y_y = y[1]; | ||
// z_u = z[1]; | ||
// z_y = z[2]; | ||
// end" | ||
// "" | ||
// true | ||
// record SimulationResult | ||
// resultFile = "simple_test_res.mat", | ||
// simulationOptions = "startTime = 0.0, stopTime = 0.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'simple_test', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''", | ||
// messages = "stdout | info | Linearization will performed at point of time: 0.000000 | ||
// LOG_SUCCESS | info | The initialization finished successfully without homotopy method. | ||
// LOG_SUCCESS | info | The simulation finished successfully. | ||
// stdout | info | Linear model is created! | ||
// " | ||
// 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"). | ||
// " | ||
// "function simple_test_GetLinearModel() | ||
// #= der(x) = A * x + B * u =# | ||
// #= y = C * x + D * u =# | ||
// local n = 2 #= number of states =# | ||
// local p = 1 #= number of inputs =# | ||
// local q = 1 #= number of outputs =# | ||
// | ||
// local x0 = {1, 2} | ||
// local u0 = {0} | ||
// | ||
// local A = [-2.665600749850023e-07, -1.000000001354202; -2.000000002708404, -1.00000010131423] | ||
// local B = [0; 0] | ||
// local C = [0, 0] | ||
// local D = [3] | ||
// | ||
// local x_x1_x = x[1]; | ||
// local x_x2 = x[2]; | ||
// local u_u = u[1]; | ||
// local y_y = y[1]; | ||
// local z_u = z[1]; | ||
// local z_y = z[2]; | ||
// | ||
// (n, p, q, x0, u0, A, B, C, D) | ||
// end" | ||
// "" | ||
// true | ||
// record SimulationResult | ||
// resultFile = "simple_test_res.mat", | ||
// simulationOptions = "startTime = 0.0, stopTime = 0.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'simple_test', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''", | ||
// messages = "stdout | info | Linearization will performed at point of time: 0.000000 | ||
// LOG_SUCCESS | info | The initialization finished successfully without homotopy method. | ||
// LOG_SUCCESS | info | The simulation finished successfully. | ||
// stdout | info | Linear model is created! | ||
// " | ||
// 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"). | ||
// " | ||
// "def simple_test_GetLinearModel() | ||
// # der(x) = A * x + B * u | ||
// # y = C * x + D * u | ||
// n = 2 # number of states | ||
// p = 1 # number of inputs | ||
// q = 1 # number of outputs | ||
// | ||
// x0 = {1, 2} | ||
// u0 = {0} | ||
// | ||
// A = [-2.665600749850023e-07, -1.000000001354202; -2.000000002708404, -1.00000010131423]; | ||
// B = [0; 0]; | ||
// C = [0, 0]; | ||
// D = [3]; | ||
// | ||
// x_x1_x = x[1]; | ||
// x_x2 = x[2]; | ||
// u_u = u[1]; | ||
// y_y = y[1]; | ||
// z_u = z[1]; | ||
// z_y = z[2]; | ||
// | ||
// return (n, p, q, x0, u0, A, B, C, D) | ||
// end" | ||
// "" | ||
// endResult |