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

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;

Edited by: Arne - Mar-14-15 01:07:31
Attachments:

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/

Edited by: adrpo - Mar-14-15 01:21:36

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.

Attachments:

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.

There are 0 guests and 0 other users also viewing this topic
You are here: