- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Array/algorithm problems
Array/algorithm problems
Array/algorithm problems
Hello everyone.
I've got a modelica package I'm trying to get to work. To replicate an error, I'm trying a reduced model. I haven't been able to replicate the problem, but I'm running into other issues. Here's my reduced model:
model mod2
constant Integer n=3;
output Real Z[n, n];
Real V[n], I[n];
Integer i=1, k=1;
algorithm
for i in 1:n loop
for k in 1:n loop
Z[i,k] := i * k;
end for;
end for;
equation
I = fill(1.0,n);
V = Z * I;
end mod2;
Here are the issues:
(*) I needed to add the "=1" to i and k to make the equations and variables balance (17 of each according to omc). I'm not sure why. The model looks balanced without that.
(*) The model flattens, but it fails during simulation. Here are the errors:
mod2.cpp: In function `int functionDAE_output()':
mod2.cpp:663: error: expected initializer before '->' token
mod2.cpp:667: error: expected initializer before '->' token
mod2.cpp: In function `int function_updateDependents()':
mod2.cpp:837: error: expected initializer before '->' token
mod2.cpp:841: error: expected initializer before '->' token
mod2.cpp: In function `int function_updateDepend(int&)':
mod2.cpp:882: error: expected initializer before '->' token
mod2.cpp:886: error: expected initializer before '->' token
mingw32-make: *** [mod2] Error 1
The code generated looks like this:
663 for(modelica_integer $Pi = 1; in_range_integer($Pi, tmp6, tmp8); $Pi += tmp7) {
664 tmp5 = get_memory_state();
665 tmp2 = 1; tmp3 = (1); tmp4 = 3;
666 {
667 for(modelica_integer $Pk = 1; in_range_integer($Pk, tmp2, tmp4); $Pk += tmp3) {
668 tmp1 = get_memory_state();
I'm wondering if I'm somehow getting the wrong compiler version or something.
If I change the algorithm part to the following, it simulates correctly. Also, if I move the algorithm part to a separate function and call it from the model, it simulates correctly.
Z := {{1,2,3},{4,5,6},{7,8,9}};
I'm on windows XP. These results are on a fairly recently downloaded daily (OpenModelica-revision-6338.msi).
- Tom
Re: Array/algorithm problems
The problem with code generation is that you have a name conflict with the implicit for iterator variables and the globally defined ones.
You can just remove Integer i=1, k=1; and the model simulates correctly.
- sjoelund.se
- 1700 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Array/algorithm problems