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

Question on enumeration in vectors

Question on enumeration in vectors

Hi everyone, thanks for looking at my question.
I'm a beginner in Modelica, and encountered an issue with getting a subset of an enumeration vector:

I've 2 enumerations:

Code:


type TComponent = enumeration(A,B,C,Cost);
type TComponentSubset = enumeration(A,B,C);

and 2 vectors based on the enumeration:

Code:


type TComponentVector = Real[TComponent];
type TComponentSubsetVector = Real[TComponentSubset];

Now in a model, how do I go about multiplying a subset of Out with ComponentPrices in the equation section? I cannot get it to work(last line).

Code:

model test

   parameter TComponentSubsetVector ComponentPrices;
   parameter TComponentVector Out;
equation
   Out[TComponent.Cost] = Out[TComponentSubset] * ComponentPrices; //last line : error = illegal subscript TComponentSubset
end test

Similarly, I tried without success:

Code:

   Out[TComponent.Cost] = Out[TComponentSubset.A:TComponentSubset.C] * ComponentPrices; //last line : error = illegal subscript TComponentSubset

Could anyone tell me what I am doing wrong? Thanks!

Re: Question on enumeration in vectors

Both of the equations work fine for me. I've fixed several issues with enumeration lately, so I would suggest you install the latest nightly build and see if it works for you.

Strictly speaking I don't think that either of the equations should work though. You should only be allowed to index an array dimension with the enumeration type it's declared with, but it seems we don't check that. But the most correct way should be:

Code:


Out[TComponent.Cost] = Out[TComponent.A:TComponent.C] * ComponentPrices;

Re: Question on enumeration in vectors

Thank you perost. I'm getting more understanding of this part of modelica now.
current/smile

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