Search code examples
modelicadymola

Access package contents from string argument in Modelica


I have a string vector with the names of some substances vec = {"H2","O2"}, and I would like to use these strings to access a record in a package such that

Modelica.Media.IdealGases.Common.SingleGasesData.'vec[1]'

returns the data of H2.

Is this possible in Modelica, or do I have to do it manually?


Solution

  • I ended up doing it manually:

    import d = Modelica.Media.IdealGases.Common.SingleGasesData;
    constant Modelica.Media.IdealGases.Common.DataRecord data[Species]={d.H2,d.O2};
    

    It might be slow and requires some index tracking, but for small sizes it is doable.