Message Boards Message Boards

0
|
8241 Views
|
9 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to use WSMCreateModel for nonlinear systems?

Friends from SystemModeler Group I am doing optimal control over power electronic systems such as inverters and dc-dc sources. The approach I have adopted is to design the controller in Mathemetica and then passing my equations to system modeler trough WSMCreateModel. I have gone through this process to send linear state space models into SystemModeler without troubles. To do the same for nonlinear systems I believe one has to create the model using the system of differential equations and the to establish the connections. My system of ODEs is

EqnRiccati={Derivative[1][P11][t] == -2.5*10^6 EE^2 P11[t]^2 + 100000. P13[t] + 
   100000. P31[t], 
 Derivative[1][P12][t] == -2.5*10^6 EE^2 P11[t] P12[t] - 
   100000. P13[t] + 100000. P32[t], 
 Derivative[1][P13][t] == -500. P11[t] + 1200.48 P12[t] - 
   2.5*10^6 EE^2 P11[t] P13[t] + 100000. P33[t], 
 Derivative[1][P14][t] == -1200.48 P12[t] - 
   2.5*10^6 EE^2 P11[t] P14[t] - 314.159 P15[t] + 100000. P34[t], 
 Derivative[1][P15][t] == 
  314.159 P14[t] - 2.5*10^6 EE^2 P11[t] P15[t] + 100000. P35[t], 
 Derivative[1][P21][t] == -2.5*10^6 EE^2 P11[t] P12[t] + 
   100000. P23[t] - 100000. P31[t], 
 Derivative[1][P22][t] == 
  1000. - 2.5*10^6 EE^2 P12[t]^2 - 100000. P23[t] - 100000. P32[t], 
 Derivative[1][P23][t] == -2.5*10^6 EE^2 P12[t] P13[t] - 
   500. P21[t] + 1200.48 P22[t] - 100000. P33[t], 
 Derivative[1][P24][t] == -2.5*10^6 EE^2 P12[t] P14[t] - 
   1200.48 P22[t] - 314.159 P25[t] - 100000. P34[t], 
 Derivative[1][P25][t] == -2.5*10^6 EE^2 P12[t] P15[t] + 
   314.159 P24[t] - 100000. P35[t], 
 Derivative[1][P31][t] == -500. P11[t] - 
   2.5*10^6 EE^2 P11[t] P13[t] + 1200.48 P21[t] + 100000. P33[t], 
 Derivative[1][P32][t] == -500. P12[t] - 
   2.5*10^6 EE^2 P12[t] P13[t] + 1200.48 P22[t] - 100000. P33[t], 
 Derivative[1][P33][t] == -500. P13[t] - 2.5*10^6 EE^2 P13[t]^2 + 
   1200.48 P23[t] - 500. P31[t] + 1200.48 P32[t], 
 Derivative[1][P34][t] == -500. P14[t] - 
   2.5*10^6 EE^2 P13[t] P14[t] + 1200.48 P24[t] - 1200.48 P32[t] - 
   314.159 P35[t], 
 Derivative[1][P35][t] == -500. P15[t] - 
   2.5*10^6 EE^2 P13[t] P15[t] + 1200.48 P25[t] + 314.159 P34[t], 
 Derivative[1][P41][t] == -2.5*10^6 EE^2 P11[t] P14[t] - 
   1200.48 P21[t] + 100000. P43[t] - 314.159 P51[t], 
 Derivative[1][P42][t] == -2.5*10^6 EE^2 P12[t] P14[t] - 
   1200.48 P22[t] - 100000. P43[t] - 314.159 P52[t], 
 Derivative[1][P43][t] == -2.5*10^6 EE^2 P13[t] P14[t] - 
   1200.48 P23[t] - 500. P41[t] + 1200.48 P42[t] - 314.159 P53[t], 
 Derivative[1][P44][t] == -2.5*10^6 EE^2 P14[t]^2 - 1200.48 P24[t] - 
   1200.48 P42[t] - 314.159 P45[t] - 314.159 P54[t], 
 Derivative[1][P45][t] == -2.5*10^6 EE^2 P14[t] P15[t] - 
   1200.48 P25[t] + 314.159 P44[t] - 314.159 P55[t], 
 Derivative[1][P51][t] == -2.5*10^6 EE^2 P11[t] P15[t] + 
   314.159 P41[t] + 100000. P53[t], 
 Derivative[1][P52][t] == -2.5*10^6 EE^2 P12[t] P15[t] + 
   314.159 P42[t] - 100000. P53[t], 
 Derivative[1][P53][t] == -2.5*10^6 EE^2 P13[t] P15[t] + 
   314.159 P43[t] - 500. P51[t] + 1200.48 P52[t], 
 Derivative[1][P54][t] == -2.5*10^6 EE^2 P14[t] P15[t] + 
   314.159 P44[t] - 1200.48 P52[t] - 314.159 P55[t], 
 Derivative[1][P55][t] == -2.5*10^6 EE^2 P15[t]^2 + 314.159 P45[t] + 
   314.159 P54[t]}

Then I use the following Mathematica statements

conns1 = {EE \[Element] "Modelica.Blocks.Interfaces.RealInput", 
   Table[Symbol["P" <> ToString[FromDigits[{1, i}]]][t], {i, 
      5}] \[Element] "Modelica.Blocks.Interfaces.RealOutput"};
m1 = WSMCreateModel["SmartGrid.Examples.RiccatiSys", EqnRiccati, t, 
   conns1];

Everything seems to be fine up to here but in the SystemModeler I hot the following error messages

Multiple declarations of component P11 found.
Multiple declarations of component P12 found.
Multiple declarations of component P13 found.
Multiple declarations of component P14 found.
Multiple declarations of component P15 found.

Since Mathematica is doing the translation I do not know why is doing multiple declarations. Any ideas?? Thanks Jesus

9 Replies

Glad you got it to work!

POSTED BY: Malte Lenz

Malte, That is absolutely right, things work as expected now. Sorry, if my question was too basic.

Regards

Jesus

If I understand things correctly, the "parameter" prefix is added because somewhere in your equations you have an occurrence of y2d without the [t].

Make sure that you always have the [t] after variables that vary over time, and without for parameters that do not vary over time.

POSTED BY: Malte Lenz

Dear Malte and Patrick,

Here is my model, note that I have declare now EE as a fixed parameter but I still like to have a possible time varying input y2d[t]. After using following your suggestions Mathematica keeps including the modifier parameter that causes the problem.

Anyway, here some elements of my model hoping that may be of any help 1. Parameters

f = 50;
param = {L1 -> 2*10^-3, Lo -> 833*10^-6, 
  Co -> 10*10^-6, \[Omega] -> 2 \[Pi] f, r1 -> 0.1, q2 -> 1000, 
  EE -> 430}
  1. Model creation

    conns = Flatten@{y2d[t] [Element] "Modelica.Blocks.Interfaces.RealInput", Table[Symbol["P" <> ToString[FromDigits[{1, i}]]][t] [Element] "Modelica.Blocks.Interfaces.RealInput", {i, 5}], Table[Subscript[z, i][t] [Element] "Modelica.Blocks.Interfaces.RealOutput", {i, 5}]}

  2. I have attached my model

I do not know what would be the way to avoid the parameter modifier in this case. In a private email Leonardo Laguna has advised my to remove manually (in the modelica text) the modifier parameter and my model is working!

Thanks

Jesus

Attachments:

Hi!

As Malte said, it would be much easier to diagnose the problem if you are able to share the model.

I noticed one thing looking through your Mathematica code. You don't define EE as a function varying with respect to time (using EE rather than EE[t]). As a result, EE has the prefix parameter in your resulting Modelica code in that it is assumed to be constant during the simulation.

parameter Modelica.Blocks.Interfaces.RealInput EE;

This is fine until you try and connect something to the EE connector. Then two separate equations will define the value of a single variable, EE. The constant paramater setting (default equal to 0) and the signal source that EE is connected to.

If this is the problem you are facing, you could remedy it by replacing all instances of EE with EE[t] in your Mathematica code:

EqnRiccati = {Derivative[1][P11][t] == -2.5*10^6 EE[t]^2 P11[t]^2 + 
    100000. P13[t] + 100000. P31[t], 
  Derivative[1][P12][t] == -2.5*10^6 EE[t]^2 P11[t] P12[t] - 
    100000. P13[t] + 100000. P32[t], 
  Derivative[1][P13][t] == -500. P11[t] + 1200.48 P12[t] - 
    2.5*10^6 EE[t]^2 P11[t] P13[t] + 100000. P33[t], 
  Derivative[1][P14][t] == -1200.48 P12[t] - 
    2.5*10^6 EE[t]^2 P11[t] P14[t] - 314.159 P15[t] + 100000. P34[t], 
  Derivative[1][P15][t] == 
   314.159 P14[t] - 2.5*10^6 EE[t] P11[t] P15[t] + 100000. P35[t], 
  Derivative[1][P21][t] == -2.5*10^6 EE[t]^2 P11[t] P12[t] + 
    100000. P23[t] - 100000. P31[t], 
  Derivative[1][P22][t] == 
   1000. - 2.5*10^6 EE[t]^2 P12[t]^2 - 100000. P23[t] - 
    100000. P32[t], 
  Derivative[1][P23][t] == -2.5*10^6 EE[t]^2 P12[t] P13[t] - 
    500. P21[t] + 1200.48 P22[t] - 100000. P33[t], 
  Derivative[1][P24][t] == -2.5*10^6 EE[t]^2 P12[t] P14[t] - 
    1200.48 P22[t] - 314.159 P25[t] - 100000. P34[t], 
  Derivative[1][P25][t] == -2.5*10^6 EE[t]^2 P12[t] P15[t] + 
    314.159 P24[t] - 100000. P35[t], 
  Derivative[1][P31][t] == -500. P11[t] - 
    2.5*10^6 EE[t]^2 P11[t] P13[t] + 1200.48 P21[t] + 100000. P33[t], 
  Derivative[1][P32][t] == -500. P12[t] - 
    2.5*10^6 EE[t]^2 P12[t] P13[t] + 1200.48 P22[t] - 100000. P33[t], 
  Derivative[1][P33][t] == -500. P13[t] - 2.5*10^6 EE[t]^2 P13[t]^2 + 
    1200.48 P23[t] - 500. P31[t] + 1200.48 P32[t], 
  Derivative[1][P34][t] == -500. P14[t] - 
    2.5*10^6 EE[t]^2 P13[t] P14[t] + 1200.48 P24[t] - 
    1200.48 P32[t] - 314.159 P35[t], 
  Derivative[1][P35][t] == -500. P15[t] - 
    2.5*10^6 EE[t]^2 P13[t] P15[t] + 1200.48 P25[t] + 314.159 P34[t], 
  Derivative[1][P41][t] == -2.5*10^6 EE[t]^2 P11[t] P14[t] - 
    1200.48 P21[t] + 100000. P43[t] - 314.159 P51[t], 
  Derivative[1][P42][t] == -2.5*10^6 EE[t]^2 P12[t] P14[t] - 
    1200.48 P22[t] - 100000. P43[t] - 314.159 P52[t], 
  Derivative[1][P43][t] == -2.5*10^6 EE[t]^2 P13[t] P14[t] - 
    1200.48 P23[t] - 500. P41[t] + 1200.48 P42[t] - 314.159 P53[t], 
  Derivative[1][P44][t] == -2.5*10^6 EE[t]^2 P14[t]^2 - 
    1200.48 P24[t] - 1200.48 P42[t] - 314.159 P45[t] - 314.159 P54[t],
   Derivative[1][P45][t] == -2.5*10^6 EE[t]^2 P14[t] P15[t] - 
    1200.48 P25[t] + 314.159 P44[t] - 314.159 P55[t], 
  Derivative[1][P51][t] == -2.5*10^6 EE[t]^2 P11[t] P15[t] + 
    314.159 P41[t] + 100000. P53[t], 
  Derivative[1][P52][t] == -2.5*10^6 EE[t]^2 P12[t] P15[t] + 
    314.159 P42[t] - 100000. P53[t], 
  Derivative[1][P53][t] == -2.5*10^6 EE[t]^2 P13[t] P15[t] + 
    314.159 P43[t] - 500. P51[t] + 1200.48 P52[t], 
  Derivative[1][P54][t] == -2.5*10^6 EE[t]^2 P14[t] P15[t] + 
    314.159 P44[t] - 1200.48 P52[t] - 314.159 P55[t], 
  Derivative[1][P55][t] == -2.5*10^6 EE[t]^2 P15[t]^2 + 
    314.159 P45[t] + 314.159 P54[t]}
POSTED BY: Patrik Ekenberg

It seems unlikely the problem is multiple declarations, given that it finds to many equations, not to many variables.

Are you willing to share the model it considers over-determined, or the WSMCreateModel call(s) that created it? It would make it easier to find what the problem is.

POSTED BY: Malte Lenz

Thanks,

It seems to work but when I include my model into another that is already working I get the message --Too many equations, over-determined system. The model has 121 equation(s) and 120 variable(s)--- The same happens with other models that I have built with WSMCreateModel, is this somehow related to possible multiple declarations??

Jesus

Patrik is right, the form

{v1, v2, ...} \[Element] type

is not documented, and therefore not thoroughly tested and to be relied on.

This case will work in the next version of SystemModeler though.

POSTED BY: Malte Lenz

Hi Jesus!

When you write:

Table[Symbol["P" <> ToString[FromDigits[{1, i}]]][t], {i, 5}] \[Element] "Modelica.Blocks.Interfaces.RealOutput"}

It expands to:

{P11[t], P12[t], P13[t], P14[t], P15[t]} \[Element] "Modelica.Blocks.Interfaces.RealOutput"

I.e the whole list is instanced as a RealOutput. What you want to have instead is that each individual P11, P12 etc. should be and instance of RealOutput:

{P11[t] \[Element] "Modelica.Blocks.Interfaces.RealOutput", 
 P12[t] \[Element] "Modelica.Blocks.Interfaces.RealOutput", 
 P13[t] \[Element] "Modelica.Blocks.Interfaces.RealOutput", 
 P14[t] \[Element] "Modelica.Blocks.Interfaces.RealOutput", 
 P15[t] \[Element] "Modelica.Blocks.Interfaces.RealOutput"}

To accomplish this, write:

conns1 = {EE \[Element] "Modelica.Blocks.Interfaces.RealInput", 
   Table[Symbol["P" <> ToString[FromDigits[{1, i}]]][t] \[Element] 
     "Modelica.Blocks.Interfaces.RealOutput", {i, 5}]};
m1 = WSMCreateModel["SmartGrid.Examples.RiccatiSys", EqnRiccati, t, 
   conns1];

The \ [Element] "Modelica.Blocks.Interfaces.RealOutput" part has been moved to inside the Table function in the above piece of code.

Hope that helps!

POSTED BY: Patrik Ekenberg
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract