PYF
PYF

Reputation: 29

How to assign some components value to a vector with a loop or for each loop

I would like to know if it is possible to link some components of an object into a vector via a modelica loop or if I should pass through a python script.

I have two applications cases to share :

  1. I would like to write inside a vector all the value of a component (based on the hypothesis that all data type match etc.)

For example :

Vector[1] = Model.P1

Vector[2] = Model.P2

...

Vector[i] = Model.Pi

in my mind, this could be achieve by a loop which looks like :

i=1 
for each component in Model
        Vector[i] = Model.component
        i = i+1 
end for

But the for each loop does not seem to exist in pure modelica

  1. this example is an extension of the first one :
Vector[1] = Model.Submodel1.P

Vector[2] = Model.Submodel2.P

...

Vector[i] = Model.Subdmodeli.P

in the same way as the 1st example:

i=1
for each Submodel in Model
    Vector[i] = Model.Submodel.P
    i = i+1
end for

An idea I had was to use a loop like:

Loop

Vector[i] = Model.Subdmodel+string("i").P

end loop

But it is not a success too...

Upvotes: 0

Views: 64

Answers (1)

Hans Olsson
Hans Olsson

Reputation: 12507

That is currently not possible in Modelica.

However, there exists a proposal along those lines https://github.com/modelica/ModelicaSpecification/tree/MCP/0021/RationaleMCP/0021

It is preliminarily implemented in Dymola (although the examples are horribly outdated, and some examples may fail badly in some Dymola versions), and may have been implemented in OpenModelica as well.

The key difference are:

  • Instead of iterating over every component it only handles components of certain classes, which makes it safer.
  • It finds nested components as well.

Upvotes: 1

Related Questions