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

Connect each i to each j, cohabitation of for and if statement

Connect each i to each j, cohabitation of for and if statement

Hey, I want to connect each cell[i] to each cell[j] but I don't want to connect a cell to itself :

Code:


for i in 1:n loop
  for j in 1:n loop
    if not(i==j) then
      connect(cell[i].port, cell[j].port);
    end if;
  end for;
end for;

That's a minimal code, you see the idea. When I check, I get the following error :

Code:



[1] 17:39:21 Translation Error
[/var/lib/jenkins3/ws/LINUX_BUILDS/tmp.build/openmodelica-1.15.0~dev-46-g9d99fda/OMCompiler/Compiler/NFFrontEnd/NFCeval.mo: 1702:9-1703:93]: Internal error NFCeval.evalRelationEqual failed to evaluate ‘i == j‘

I guess this is because for statement is evaluated during instanciation of the model whereas if statement is evaluated during simulation. Is it right ? Is it only possible to do such a thing with OpenModelica presently ?

Thanks,

Re: Connect each i to each j, cohabitation of for and if statement

If "n" is a parameter then it should work fine and this seems like a bug.
We should do loop unroll to generated all the statements but maybe the evaluation of the if condition during that is failing.

As a workaround until we fix this, you can remove the if statement and connect the cell to itself as connect(A, A) is ignored and a warning is given.


Re: Connect each i to each j, cohabitation of for and if statement

This does indeed look like a bug, but I can't reproduce it based on the code fragment you've given (I tried to extrapolate a complete model, but the model I ended up with worked just fine).

It looks like you're using an old nightly build, so you might want to try it with the latest nightly build in case the issue has already been fixed. Otherwise you can open a new ticket on our bug tracker, or just provide a complete model here that can be used to reproduce the issue.

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