简体   繁体   English

Modelica:检查可替换 package 或 model 的相等性

[英]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).在我的 Modelica 系统 model 中,我有一个可更换的 package(介质,流体特性)和一个可更换的 model(压力损失模型)。 Can I somehow check whether a certain model or package is selected?我可以以某种方式检查是否选择了某个 model 或 package 吗? 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) .我在想类似 python 的东西,你可以使用type(variable)还是isinstance(object, class) This approach seems to be doable in many languages, but is it possible in Modelica?这种方法似乎在许多语言中都可行,但在 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, eg constant String mediumName or constant Integer correlationID , but I would see that as a workaround.我想到的一种解决方法是在可替换模型/包中添加一些(或使用现有)常量并在比较中使用它,例如constant String mediumNameconstant Integer correlationID ,但我认为这是一种解决方法。

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.通过比较常数 Integer,我可以计算出 Boolean 的正确值,但我遇到了另一个问题(至少在 Dymola 中):当我使用 Boolean 时,注释启用时不起作用。 Is there a rule when the value of the Boolean gets evaluated?评估 Boolean 的值时是否有规则?

The medium packages already have a property mediumName that you can compare, for instance using the code:媒体包已经有一个可以比较的属性mediumName ,例如使用代码:

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

Best regards, Rene Just Nielsen最好的问候, Rene Just Nielsen

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM