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

Creating counters of component instances

Creating counters of component instances

Hello,

I am trying to build a library with counters for the component instances. The naive code would be something of the following style:

class Pipe
    Integer ipipe;        //actual number of the instance
    outer Integer npipe; //global counter for the total number of pipes
  initial algorithm
    npipe := npipe + 1;
    ipipe := npipe;
end Pipe;

model hydro_circuit;
  inner Integer npipe(start=0,fixed=false);  //global counter for the normal number of pipes
  Pipe pa, pb, pc, pd;
end hydro_circuit;

I have been unable to achieve my goal: after initialization I want
     npipe=4
     pa.ipipe=1
     pb.ipipe=2
     pc.ipipe=3
     pd.ipipe = 4.

Apparentely, the initial algorithm blocks are considered as multiple equations assigning the same variable npipe.

Thanks in advance for any help

Edited by: SQX - Mar-24-16 20:28:05
There are 0 guests and 0 other users also viewing this topic
You are here: