Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Block connection including an array

Block connection including an array

Hello guys,

I have two Blocks, A and B and I want to connect both of them (graphicly) and the data (array) from block A should be transfered to block B.

Here I small example

Code:


block A
  extends Modelica.Blocks.Interfaces.MO;
  parameter Real a[:] = {5.0, 2.0};
  equation
  y = a;
end A;

block B
  extends Modelica.Blocks.Interfaces.MIMO;
  equation
  y = u;
end A;

So far so fine, but now comes the connection (graphical) in the connection editor. I connect A with B, now I have to enter the indices, for A.y[index] to B.u[index]. I am not able to use the hole vector of A to connect to B, only 1 scalar of A can be connected to B (input and output of must set to 1).

Code:

equation

  connect(A.y[2], B.u[1]) annotation(Line(points = {{-63, 40}, {-10, 40}, {-10, 32}, {-10, 32}}, color = {0, 0, 127}));

I solved this problem with a for loop to connect the hole array A to B

Code:


for i in 1:2 loop
  connect(mV_Test1.y[i], pS_Test1.u[i]) annotation(Line(points = {{-63, 40}, {-10, 40}, {-10, 32}, {-10, 32}}, color = {0, 0, 127}));
  end for;

The simulation works fine, the result of Block B is y[1]=5 and y[2]=2
BUT now I have no more graphical connection line in the connection Editor between A and B :-(

Some one who can help?

Re: Block connection including an array

Hi,

     I took your exemple but I rewrote it in anathor way, finally it works well

Code:


block A
extends Modelica.Blocks.Interfaces.MO(nout=2);
  parameter Real a[2] = {5.0, 2.0};
  equation
  for i in 1:2 loop
  y[i] = a[i];
  end for;
end A;

//
block B
extends Modelica.Blocks.Interfaces.MIMO(nin=2);

extends Modelica.Blocks.Interfaces.MIMO(nout=2);
  equation
  // for loop to run out our model
  for i in 1:2 loop
    y[i] = u[i];
  end for;
 
end B;

//
model AB
  A a1 annotation(
    Placement(visible = true, transformation(origin = {-128, 12}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  B b1 annotation(
    Placement(visible = true, transformation(origin = {14, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
for i in 1:2 loop
  connect(a1.y[i], b1.u[i]) annotation(
    Line(points = {{-116, 12}, {2, 12}, {2, 10}, {2, 10}}, color = {0, 0, 127}, thickness = 0.5));
    end for;

end AB;


There are 0 guests and 0 other users also viewing this topic
You are here: