- Index
- » Developer
- » OpenModelica development
- » For loop bug
For loop bug
For loop bug
ForLoopBug.mo
Hello,
If I'm not very mistaken this should just run:
model ForLoopBug
parameter Integer N = 1;
parameter Real p_in = 2e5;
Real[N + 1] p;
Real[N] dp;
algorithm
p[1] := p_in;
for i in 1:N loop
dp[i] := 10;
p[i + 1] := p[i] - dp[i];
end for;
end ForLoopBug;
Re: For loop bug
Thanks for reporting this. I added a bug ticket about it:
https://trac.openmodelica.org/OpenModelica/ticket/3220
As a workaround for now until we fix it you can use equation instead of algorithm ( and replace := with = ).
Cheers,
Adrian Pop/
- adrpo
- 885 Posts
Re: For loop bug
TestForLoop.mo
Sorry to bother your tennis game again... ;-)
If I 'wrap' the working code into a function and then call this function from the model than it does run as it should.
Re: For loop bug
No problem.
Yes, if you put it in a function then is treated differently and it works.
In a model algorithm section we need to find the inputs and outputs of the algorithm,
sort the statements as we do with equations, etc. and it seems there is an error in
that handling.
- adrpo
- 885 Posts
- Index
- » Developer
- » OpenModelica development
- » For loop bug