Opened 8 years ago

Closed 7 years ago

#4289 closed defect (fixed)

In OMPython the linearization doesn't result correct results

Reported by: arun3688 Owned by: arun3688
Priority: high Milestone: Future
Component: OMPython Version:
Keywords: Cc: Bernt.Lie@…

Description

Below, I summarize the linearization results for a standard reactor model from the literature. The model has 4 inputs, one output and 2 states. The order of the inputs, outputs and states have been read from the resulting file of the OM linearization routine.

The “theoretical calculation” result is the correct result. This result has been found by analytic computation of the Jacobians using Waterloo Maple (similar to Mathematica), and by subsequent insertion of values for the operating point of the system. I have also computed the Jacobians *numerically* using MATLAB, and the result is identical to the “exact” result. So there can be no doubt that the “theoretical” result is the correct result.

A comment on the theoretical result: the A matrix contains one positive and one negative eigenvalue. The positive eigenvalue indicates that the system in fact is unstable at the operating point. (Something similar would be found for an inverted pendulum…) However, I have used very accurate values for the initial states, and in my simulations using OM, there is no problem in simulating the system for 10 minutes with no observed drift in the operating point.

The A and B matrices found using linearization in OM are very different from the exact values. The C and D matrices are correct, though.

Result from OM Linearization:

A= [-2.092050209205021,5.653416094580654e-077;

-6.134270952087974e-075,-2.702332893209552e-077];

B= [2.092050209205021,0,-0.4346639552067547,0;

0,0,-0.4901435697186606,0];

C= [0,0.01];

D= [0,0,0,0];

Results from Handmade calculation and from matlab

A =[4.3796 ,2.0921;

-3.5715 ,-2.0000]

B = [2.0921 ,1.0000 , 0, 0;

0 ,0 ,0.5000, 100.0000]

C= [0,0.01];

D= [0,0,0,0];

Attachments (1)

Reactor.mo (2.4 KB) - added by arun3688 8 years ago.

Download all attachments as: .zip

Change History (5)

Changed 8 years ago by arun3688

comment:1 Changed 8 years ago by arun3688

  • Cc Bernt.Lie@… added
  • Status changed from new to accepted

comment:2 Changed 8 years ago by wbraun

  • Component changed from Build Environment to OMPython
  • Summary changed from Erroneous result by linearization in OM to In OMPython the linearization doesn't result correct results

The issue here is to pass all options and the inputs correctly from OMPython to the model.
With the following script:

setCommandLineOptions("--generateSymbolicLinearization");
loadFile("Reactor.mo");
getErrorString();
linearize(Reactor.ModReactor, stopTime=0.0);
system("cat linear_Reactor.ModReactor.mo");

one can obtain the expected results:

record SimulationResult
    resultFile = "/home/wbraun/tmp/Reactor.ModReactor_res.mat",
    simulationOptions = "startTime = 0.0, stopTime = 0.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'Reactor.ModReactor', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
    messages = "stdout            | info    | Linearization will performed at point of time: 0.000000
stdout            | info    | Linear model is created!
",
    timeFrontend = 0.012609492,
    timeBackend = 0.02501393,
    timeSimCode = 0.002201676,
    timeTemplates = 0.004963270000000001,
    timeCompile = 0.449201582,
    timeSimulation = 0.007827599000000001,
    timeTotal = 0.5020091240000001
end SimulationResult;
model linear_Reactor_ModReactor
  parameter Integer n = 2; // states
  parameter Integer k = 4; // top-level inputs
  parameter Integer l = 1; // top-level outputs
  parameter Real x0[2] = {350,50};
  parameter Real u0[4] = {300,350,100,1};
  parameter Real A[2,2] = [4.379557680812913,2.092050209205021;-3.571428571428572,-2];
  parameter Real B[2,4] = [2.092050209205021,1,0,0;0,0,0.5,100];
  parameter Real C[1,2] = [0,0.01];
  parameter Real D[1,4] = [0,0,0,0];
  Real x[2](start=x0);
  input Real u[4](start= u0);
  output Real y[1];

  Real 'x_T' = x[1];
Real 'x_nA' = x[2];
Real 'u_Tci' = u[1];
Real 'u_Ti' = u[2];
Real 'u_Vd' = u[3];
Real 'u_cAi' = u[4];
Real 'y_cA' = y[1];

equation
  der(x) = A * x + B * u;
  y = C * x + D * u;
end linear_Reactor_ModReactor;

To get the desired matrix B, of course one have to set the inputs correct.

As far as I see OMPython doesn't pass the stopTime, which is the point in time where the linearization is desired. Also the inputs are not passed to the model, so the values above are calculated with u ={0}, and than the solution starts to drifting.

comment:3 Changed 7 years ago by dietmarw

I've just talked to Bernt, the reporter, and this is already fixed,

comment:4 Changed 7 years ago by lochel

  • Resolution set to fixed
  • Status changed from accepted to closed
Note: See TracTickets for help on using tickets.