I need to use a loop to create multiple objects in my model declaration. For loops do not seem to work outside an "equation" or an "algorithm" block. I need to declare my objects in the beggining of the Model. I also need to add different annotation to each object so that the location of each object differs.
As a result i want to create a tank consisting of cellConst subparts (found in Thermocycle package).
I already tried to do so by using the following code:
model MyTank
CellConst [N] cellConstArray = {
CellConst (
Ai=0.53,
Ac=0.88,
Mdotnom=1,
L=0.25, Discretization=ThermoCycle.Functions.Enumerations.Discretizations.upwind_AllowFlowReversal, Vi=0.030, Tstart=293.15)
annotation (Placement(transformation(extent={{-14,22},{-8,28}})))
for i in 1:N
};
end MyTank;
I also tried a simple loop
model MyTank
for i in 1:N loop
end for;
end MyTank;
Though None of these two approaches worked.
Do you have any suggestions?
Thank you in advance.
You do things slightly differently in Modelica: you add modifiers to each element of the vector like this:
model MyTank
CellConst [N] cellConstArray(each Ai=0.53,
each Ac=0.88,
each Mdotnom=1,
each L=0.25,
each Discretization=ThermoCycle.Functions.Enumerations.Discretizations.upwind_AllowFlowReversal,
Vi = fill(0.030, N), // Just to show you can use an array here
each Tstart=293.15)
);
end MyTank;