2

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?

Priyanka
  • 559
  • 3
  • 13

1 Answers1

3

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

Rene Just Nielsen
  • 3,023
  • 12
  • 15
  • Thanks, that is what I tried and why I mentioned mediumName. I also edited my question to make it more clear I used that existing constant. Some problems: Not all media have mediumName defined; mediumName may be ambiguous (DryAir and Moist Air might both use mediumName="Air"; and even if the Boolean value is calculated correctly, I failed to successfully use it in the parameter dialog enable=Boolean. – Priyanka Jun 09 '20 at 14:08
  • 1
    The enable-attribute works best with parameter-expressions. I noticed that "isWater" isn't declared as parameter More importantly generally using expressions in the enable attribute works better than indirectly referring to a parameter with that expression, so enable=Modelica... - but Medium.mediumName might be problematic anyway. – Hans Olsson Jun 09 '20 at 16:15