【问题标题】:Using units/components in Modelica based on a Boolean condition基于布尔条件在 Modelica 中使用单位/组件
【发布时间】:2013-08-07 07:10:14
【问题描述】:

假设我也许想根据某些条件导入组件,假设是一个布尔变量。我已经尝试过了,但它给了我一条错误消息。例如,考虑以下代码:

model myNewModel
    parameter Boolean use_Something;
    myLibrary.myComponent component[if use_Something then 1 else 0];
    // In other words (pseudo):
    // if use_Something then 'Import The Component' else 'Do Nothing At All';
end myNewModel;

直观地说,这是一个安全的语句,只要布尔变量为真,它就会按预期工作。对于某些单元,例如 Modelica 标准库的流体端口,它也适用于 [0] 大小。但是,一旦我将变量设置为 false,就会遇到许多组件与“零大小”不兼容的错误。例如,Modelica 标准库中的 MassFlowSources 就遇到过这个问题。有没有一种流畅/优雅的方式来解决这个问题?提前致谢!

【问题讨论】:

    标签: modelica


    【解决方案1】:

    您可以在 Modelica 中使用条件组件。

    模型 myNewModel
        参数布尔值 use_Something;
        myLibrary.myComponent 组件 if use_Something;
    结束 myNewModel;

    这个组件只能在连接语句中使用。如果条件为假,则工具会忽略这些连接。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-24
      相关资源
      最近更新 更多