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

Class name as variable (string to TypeName)

Class name as variable (string to TypeName)

Hi,
I have several classes with different data sets in a package.
Example

Code:

package comptest

model c1
  parameter Real a = 1;
  parameter Real b = 2;
  parameter Real c = 3;
end c1;
model c2
  parameter Real a = 4;
  parameter Real b = 5;
  parameter Real c = 6;
end c2;
model c3
  parameter Real a = 7;
  parameter Real b = 8;
  parameter Real c = 9;
end c3;
model c4
  parameter Real a = 10;
  parameter Real b = 11;
  parameter Real c = 12;
end c4;
end comptest;

I want to use a parameter (as enum) to select a particular class by defining a Type.

Code:

type compound = enumeration(c1, c2, c3, c4, c5, c6, c7,  c8);

We can get the string from the enumeration item, however I'm not able to use that string to open that class. Any ideas on this?
something like this..

Code:


model enumtest
  parameter compound testcompound1 "compound1" annotation(Dialog(tab = "input", group = "compounds"));
  parameter compound testcompound2 "compound2" annotation(Dialog(tab = "input", group = "compounds"));
//use the values of a,b,c of respective compounds //
end enumtest

Regards,
Swaroop

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