- Index
- » Programming
- » Modelica Language
- » Question on enumeration in vectors
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;
- perost
-
-
- 114 Posts
- Index
- » Programming
- » Modelica Language
- » Question on enumeration in vectors