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

Arrays in connect command

Arrays in connect command

I am using an array of ten plates and want to simplify my code. When I type in:

{connect(plate[i].V_bottom,plate[i+1].V_top) for i in 1:9};

an error occurs.
I looked through "Principles of Object-oriented mdoeling and simulation with modelica 2.1" but could not find any information on arrays w.r.t. the connect statement.
Is it possible to use arrays in a connect statement? Is there something wrong with my syntax?

When using arrays as below the program works. Only once I try to squeeze it into one line it gives me problems.
---------------------------------------------------------------------------------------------
model InternalBalances
  import Modelica.SIunits.*;
  Plate plate[10];
  CondenserSimple condenser;
  ReboilerSimple reboiler;
  ControlledValveFlow controlValve;
  import Modelica.Blocks.Sources;
  Sources.Step step(startTime = 0, height = 1);
  annotation(Icon());
  MixerSimple mixer;

equation
  connect(step.y,controlValve.u);
  connect(controlValve.outlet,plate[1].Feed);
  connect(condenser.V,plate[1].V_top);
  connect(condenser.L,plate[1].L_top);
  connect(plate[1].V_bottom,plate[2].V_top);
  connect(plate[1].L_bottom,plate[2].L_top);
  connect(plate[2].V_bottom,plate[3].V_top);
  connect(plate[2].L_bottom,plate[3].L_top);
  connect(plate[3].V_bottom,plate[4].V_top);
  connect(plate[3].L_bottom,plate[4].L_top);
  connect(plate[4].V_bottom,plate[5].V_top);
  connect(plate[4].L_bottom,plate[5].L_top);
  connect(plate[5].V_bottom,plate[6].V_top);
  connect(plate[5].L_bottom,plate[6].L_top);
  connect(plate[6].V_bottom,plate[7].V_top);
  connect(plate[6].L_bottom,plate[7].L_top);
  connect(plate[7].V_bottom,plate[8].V_top);
  connect(plate[7].L_bottom,plate[8].L_top);
  connect(plate[8].V_bottom,plate[9].V_top);
  connect(plate[8].L_bottom,plate[9].L_top);
  connect(plate[9].V_bottom,plate[10].V_top);
  connect(plate[9].L_bottom,plate[10].L_top);
  connect(plate[10].V_bottom,reboiler.V);
  connect(plate[10].L_bottom,reboiler.L);
  connect(condenser.D,mixer.streamA);
  connect(reboiler.B,mixer.streamB);
end InternalBalances;

Re: Arrays in connect command

Hello,
I am no great specialist, but this syntax worked for me:

    connect(Vap_in,exchanger[1].Vap_in);
    connect(exchanger[end].Vap_out,Vap_out);
    connect(LN_in,exchanger[1].LN_in);
    connect(exchanger[end].LN_out,LN_out);
  for i in 1: (N-1) loop
    connect(exchanger[i].Vap_out,exchanger[i+1].Vap_in);
    connect(exchanger[i].LN_out,exchanger[i+1].LN_in);
  end for;

Good luck,
JB.

Re: Arrays in connect command

Thanks! The for statement works!

There are 0 guests and 0 other users also viewing this topic