Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

initialising array with unknown size in modelica

I need a little help with initialising arrays in openmodelica. I created a modelica class which should generate an array with variable size. The size is to be set as a parameter and is of type integer. Below is an example of what i want to do. I keep on receiving error messages and would gladly receive any hints! Thanks.

parameter Integer f_min;
parameter Integer f_max;
Integer Freq_steigerung;
Integer array_size;
Integer Freq[:];

equation
array_size = ceil((f_max-f_min)/Freq_steigerung);
Freq[array_size] = f_min: Freq_steigerung: f_max;
like image 561
Gladson Avatar asked Feb 25 '17 15:02

Gladson


1 Answers

You cannot have arrays with variable size at runtime in Modelica. All array sizes need to be known at compile time, so the sizes need to be parameters or constants.

You can have functions (or records) containing components with unknown array sizes but they need to be bound at call time (so still known during compilation).

Something like this will work:

model T
  parameter Integer f_min;
  parameter Integer f_max;
  parameter Integer Freq_steigerung;
  parameter Integer array_size = integer(ceil((f_max-f_min)/Freq_steigerung));
  Integer Freq[array_size];
equation
  Freq = f_min: Freq_steigerung: f_max;
end T;
like image 87
Adrian Pop Avatar answered Sep 20 '22 16:09

Adrian Pop