Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Array in fuction

Array in fuction

Hi,
I am a Windows OpenModelica user and I have the following problem: I have an instance of a class declared with an array (A a[1]). Within the instaciated class I call a function which returns one value of an array of a record. If the array size in the record is smaller or equal than 19, there is no problem. If the array size is greater 19 an unknown error occurs. The model code:

Code:



model FrameTest
// --- MAIN CLASS ---

  Element element[1]; 
end FrameTest;

//############################################################################################################

model Element
  Profile profile;
  Real angle;                             
equation
  angle = funct(alpha=profile.alpha);
end Element;

//############################################################################################################

function funct
  input Real[:] alpha;                     
  output Real cOut;                         
algorithm
  cOut:= alpha[5];
end funct;

//############################################################################################################

record Profile
  parameter Real alpha[20]={1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0};
  //parameter Real alpha[19]={1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0};
end Profile;

Thanks for your help,

Sebastian

Re: Array in fuction

I will have a look at this bug. Note that this is related to the vectorization limit of OpenModelica.
As a workaround, you can run

Code:

omc +v=100

, or setVectorizationLimit(100) in OMShell or OMEdit. But this may have a negative impact on the performance of large models.

Re: Array in fuction

It works!
Thanks!

Re: Array in fuction

In r8597+ it should also work with any vectorization limit:

Code:


size 3: +v=1
  real_array_create(&tmp1018, ((modelica_real*)&($Pelement$lB2$rB$Pprofile$Palpha)), 1, 3);
size 3: +v=100
  array_alloc_scalar_real_array(&tmp1018, 3, (modelica_real)$Pelement$lB2$rB$Pprofile$Palpha$lB1$rB, (modelica_real)$Pelement$lB2$rB$Pprofile$Palpha$lB2$rB, (modelica_real)$Pelement$lB2$rB$Pprofile$Palpha$lB3$rB);

The generated code should be faster with a lower limit since we just use a reference to the array instead of creating a new one...

There are 0 guests and 0 other users also viewing this topic