Why I can not use a global parameter in for loop?

309 views Asked by At

I tried use global parameter in code like this:

model testModel
  outer parameter Integer par;
  outer Integer var;
equation
  for i in 1:par loop
    var[i] = 5 * i;
  end for;
end testModel;

model test
  inner parameter Integer par = 3;
  inner Integer var[par];
  testModel mod;
end test;

simulate(test)

And I got the following error:

Error: The iteration range 1:par is not a constant or parameter expression

All works fine if not using global parameter:

model test
  inner parameter Integer par = 3;
  inner Integer var[par];
  testModel mod(par = par);
end test;

How can I use the global parameter in "for", or why can't I? Thank you in advance

1

There are 1 answers

3
lochel On

This should work:

model testModel
  outer parameter Integer par;
  Integer var[par];
equation 
  for i in 1:par loop
    var[i] = 5 * i;
  end for;
end testModel;

model test
  inner parameter Integer par = 3;
  testModel mod;
end test;