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;
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With