- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » array assignment probably not working
array assignment probably not working
array assignment probably not working
Hello!
I am working with arrays of the type: Real exampleArray[2,3]
I am calculating the values of the array in a modelica function and then assign the return value (output value) of that function to a corresponding array parameter. But, that does not work.
I get the following error message:
base_array.c: the number of array dimensions are < 0!
ArrayTestModel: real_array.c:280: indexed_assign_real_array: Assertion `base_array_ok(source)' failed.
Aborted
Thats the model:
model ArrayTestModel
public
parameter Integer dimensionOne = 2;
parameter Real exampleArray[:,:] = {{0.4572,0.3556,0.2032}};
protected
function ArrayExampleFunction
input Integer dimensionOne;
input Real valuesList[:,:];
output Real outputList[dimensionOne,:];
protected
Integer listSize;
Integer aux;
algorithm
listSize:=size(valuesList, 1);
for i in 1:dimensionOne loop
aux:=min(i, listSize);
outputList[i]:=valuesList[aux];
end for;
end ArrayExampleFunction;
parameter Real exampleArrayList[dimensionOne,:] = ArrayExampleFunction(dimensionOne, exampleArray);
end ArrayTestModel;
Does anybody have an idea why?
Thanks,
Fritz
Re: array assignment probably not working
OpenModelica crashes because the runtime makes certain assumptions about integers. Such as if you have unknown dimensions, you assign to the whole array at once and not just a slice. It would be good to make this return an error message though
The Dymola 7.4 demo says:
Code:
Check of ArrayTestModel:
Error: For equation
for i in (1:dimensionOne) loop
aux = min(i, listSize);
outputList[i] = valuesList[aux];
end for;
found in class ArrayTestModel.ArrayExampleFunction, declaration window at line 15.
Error: Wrong number of indices in outputList[i].
There should be 2 indices.
Error: Wrong number of indices in valuesList[aux].
There should be 2 indices.
Errors detected in functions.
Check aborted.
ERROR: 3 errors were found
- sjoelund.se
- 1700 Posts
Re: array assignment probably not working
Hello, thanks for the dymola message!
I added an additional for loop and defined the 2nd dimension of the output array in advance.
This works!
function ArrayExampleFunction
input Integer dimensionOne;
input Real valuesList[:,:];
output Real outputList[dimensionOne,size(valuesList,2)];
protected
Integer listSize;
Integer listSize2;
Integer aux;
algorithm
listSize:=size(valuesList, 1);
listSize2:=size(valuesList,2);
for i in 1:dimensionOne loop
aux:=min(i, listSize);
for j in 1:listSize2 loop
outputList[i,j]:=valuesList[aux,j];
end for;
end for;
end ArrayExampleFunction;
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » array assignment probably not working