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

how to connet array of two different type

how to connet array of two different type

Hello, i am a little bit confused by the for loop:
I try to connect two different component array using for loop, but it dosent work.

model Test
parameter Integer N = 2;
Modelica.Blocks.Sources.Constant const[N](each k = 273.15 + 100);
ThermoCycle.Components.HeatFlow.Sources.Source_T_cell source_T_cell[N]
equation
// it dose not work
  for i in 1: N-1 loop
  connect(const[N].y, source_T_cell[N].Temperature);
    end for;
/* but the following works
  connet(const.y, source_T_cell.Temperature);
*/
end Test;

can some one tell me, how to connet two differnt array of components in Modelica.

best regards

Re: how to connet array of two different type

I guess that should be:

Code:


for i in 1: N-1 loop
  connect(const[i].y, source_T_cell[i].Temperature); // note that you have i instead of N
end for;

You could also do it via he slice operator and without the for loop:

Code:


connect(const[1:N-1].y, source_T_cell[1:N-1].Temperature);

Re: how to connet array of two different type

thanks very much.

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