Opened 6 years ago

Closed 6 years ago

#5206 closed defect (fixed)

Generate residual equation for nonlinear systems with conditional equations

Reported by: Francesco Casella Owned by: Willi Braun
Priority: high Milestone: 1.13.0
Component: Backend Version:
Keywords: Cc: adrien.guironnet@…, marianne.saugier@…, romain.losseau@…

Description

Please consider the following model, which represents the steady-state initialization of a proportional controller with saturation.

If the reference value of y, y_ref, is compatible with the saturation limit of the controller, then the set point value is initialized to produce exactly that output; otherwise, the control variable u before saturation is initialized to a value somewhat higher than the saturation, and then the corresponding set point is computed.

model NonSatIntEq
  Real x;
  Real y;
  Real usat;
  Real u;
  parameter Real y0(fixed = false, start = 8);
  parameter Real T = 1;
  parameter Real k = 10;
  parameter Real uMin = 0;
  parameter Real uMax = 1;
parameter Real y_ref = 8;
initial equation
  der(x) = 0;
  if u > usat then
    u = usat + 1;
  else
    y = y_ref;
  end if;
equation
  T * der(x) = usat - x;
  y = k * x;
  usat = homotopy(actual = smooth(0, if u > uMax then uMax else if u < uMin then uMin else u), simplified = u);
  u = y0 - y;
end NonSatIntEq;

When trying to run this model, the following error is generated:

[1] 01:33:51 Translation Error
Internal error function createNonlinearResidualEquations failed

[2] 01:33:51 Translation Error
[C:/dev/OM64bit/OMCompiler/Compiler/SimCode/SimCodeUtil.mo: 3289:7-3289:48]: Internal error createOdeSystem2 failed for Generic Jacobian via directional derivatives

[3] 01:33:51 Translation Error
[C:/dev/OM64bit/OMCompiler/Compiler/SimCode/SimCodeUtil.mo: 3182:9-3182:50]: Internal error function createOdeSystem failed for component {6, 5, 2, 4:3, 2, 4, 6} Size: 4 Generic Jacobian via directional derivatives

[4] 01:33:51 Translation Error
[C:/dev/OM64bit/OMCompiler/Compiler/SimCode/SimCodeUtil.mo: 1369:5-1369:77]: Internal error createEquationsForSystems failed

[5] 01:33:51 Translation Error
[C:/dev/OM64bit/OMCompiler/Compiler/SimCode/SimCodeUtil.mo: 637:5-637:146]: Internal error function createSimCode failed [Transformation from optimised DAE to simulation code structure failed]

I tested the model in Dymola, and it works fine, producing the expected result.

Change History (8)

comment:1 by Francesco Casella, 6 years ago

For the record, the previous example should initialize in non-saturated state.

This one should initialize in saturated state, since the maximum output that the saturated controller can provide is y = 10.

model SatIntEq
  extends NonSatIntEq(y_ref = 20);
end SatIntEq;

This example also works in Dymola.

comment:2 by Willi Braun, 6 years ago

Component: Code GenerationBackend
Status: newaccepted
Summary: Problems with Jacobians of nonlinear systems with conditional equationsGenerate residual equation for nonlinear systems with conditional equations

The actually issue here is to transform if equations into
one residual equation, here it's the equation:

  if u > usat then
    u = usat + 1;
  else
    y = y_ref;
  end if;

which could not transformed into a if expression.

comment:3 by Francesco Casella, 6 years ago

I guess it should be something like

(if u > usat then u - (usat + 1) else y - y_ref) = 0;

right?

Last edited 6 years ago by Francesco Casella (previous) (diff)

comment:4 by Francesco Casella, 6 years ago

In fact that works nicely :)

comment:5 by Willi Braun, 6 years ago

Fixed in PR2774.

comment:6 by Francesco Casella, 6 years ago

I tried the test model with the new nightly in OMEdit and the transformational debugger.

If I use the equation of comment:3, the back-end solves the system of 4 nonlinear equations in the initialization problem using tearing, using u as tearing variable, and solves the problem correctly.

If I use the original model with the conditional equation, I get a "Matrix singular" warning, then the simulation starts but it's not in steady state, which is quite bad, because it means that a wrong solution of the initialization problem is accepted.

The debugger mentions a system of 4 coupled initial equations in u, usat, x, y which are not torn, but then it only shows me three residuals. The one corresponding to

usat = homotopy(actual = smooth(0, if u > uMax then uMax else if u < uMin then uMin else u), simplified = u);

is missing. I guess there's something wrong in the implementation, can you please double-check?

Thanks!

Last edited 6 years ago by Francesco Casella (previous) (diff)

comment:7 by Willi Braun, 6 years ago

Ah, the issue is, that such equations are not supported by the tearing methods, the "omcTearing" has even StackOverflow on this model. But it gets solved, if you provide for the non-teared system start values. So tearing implementation needs to be checked to support such if equations.

in reply to:  7 comment:8 by Francesco Casella, 6 years ago

Resolution: fixed
Status: acceptedclosed

Replying to wbraun:

Ah, the issue is, that such equations are not supported by the tearing methods, the "omcTearing" has even StackOverflow on this model. But it gets solved, if you provide for the non-teared system start values. So tearing implementation needs to be checked to support such if equations.

Opened new ticket #5226 on this specific topic

Note: See TracTickets for help on using tickets.