2

Given a model with an array x of connectors where its size is unspecified, e.g.

connector con
...
end con;

model test
con x[:];
end test;

How can x be instantiated with a specific size, e.g. something like this?

test t(x = ?);
...
equation
connect(t.x[1], a);
connect(t.x[2], b);
...
Mathabc
  • 175
  • 9

1 Answers1

2

Why do you need unspecified dimension? You can do something like this:

connector con
...
end con;

model test
 constant Integer dim = 1;
 con x[dim];
end test;

// usage
test(dim = 10);
...
equation
  connect(t.x[1], a);
  connect(t.x[2], b);
...
Adrian Pop
  • 4,034
  • 13
  • 16
  • This is true but I am curious if it is possible to instantiate a model containing an array with unspecified dimension. – Mathabc Mar 21 '15 at 23:44
  • 1
    No. Dimensions need to be known at compile time so somewhere you need to specify them even if they are unknown when you declare them. Maybe it would work if you make con x[:] replaceable and you do test(redeclare con x[10]), but i'm not sure. – Adrian Pop Mar 21 '15 at 23:48
  • It is still interesting that the model test is valid but seemingly unusable because it cannot be instantiated unless x is replaceable. Are you sure it cannot be instantiated when declared as in my question? – Mathabc Mar 21 '15 at 23:57
  • You need to specify the dimension somehow. The only way to do that is via a binding or a redeclare. If you have test(x = y) where y is a con y[known_dim] it might work to give a dimension to x but you will also get new equations x[1] = y[1] ... and so on. – Adrian Pop Mar 22 '15 at 00:07