Search code examples
user-interfacetypesparametersmodelicaisinstance

Modelica: check equality of replaceable package or model


In my Modelica system model, I have a replaceable package (medium, fluid properties) and a replaceable model (pressure loss model). Can I somehow check whether a certain model or package is selected? The following approach does not work, but maybe explains what I want to achieve:

replaceable package Medium = Modelica.Media.Water.WaterIF97_ph;
Boolean isWater = (Medium == Modelica.Media.Water.WaterIF97_ph);

I was thinking of something similar like in python, were you can use type(variable) or isinstance(object, class). This approach seems to be doable in many languages, but is it possible in Modelica?

One workaround I thought of was to add some (or use an existing) constant inside the replaceable model/package and use that in the comparison, e.g. constant String mediumName or constant Integer correlationID, but I would see that as a workaround.

The workaround seems to work when using Integers, but not when using Strings. Any comment?

With comparison of constant Integer, I can calculate the correct value for the Boolean, but I hit another problem (in Dymola at least): When I use the Boolean in the annotation Dialog enable, it does not work. Is there a rule when the value of the Boolean gets evaluated?


Solution

  • The medium packages already have a property mediumName that you can compare, for instance using the code:

    Boolean isWater = Modelica.Utilities.Strings.isEqual("WaterIF97", Medium.mediumName);
    

    Best regards, Rene Just Nielsen