如何在自定义 Fluid.System 中定义通用媒体?

How can you define a common Medium in a custom Fluid.System?

我正在为流体系统建模设计一组自定义组件。由于整个模型中只有一种媒介,我希望能够在一个地方定义该媒介。大多数 Modelica.Fluid 系统所需的 system 组件似乎是个好地方。

我尝试了以下 MWE,但我 运行 遇到了 class 查找问题,我不知道如何避免。 使用当前的 OpenModelica,在检查 CommonMediaClosedVolume 时出现错误

Class name 'system.CommonMedium' was found via a component (only component and function call names may be accessed in this way).

我注意到有一个 Fluid.System.Medium 定义,我认为它可以用于类似的目的,但是在 OMEdit 的参数对话框中更改它是不可见的(尽管它有一个 choicesAllMatching 注释 - - 一个 OM 错误?),它似乎没有在其他任何地方使用。在任何情况下,它都会显示相同的查找错误消息。

问题:

package CommonMediaDefinition
 
  model TweakedSystem "Extended system featuring a common media definition"
    extends Modelica.Fluid.System(Medium = CommonMedium);
    replaceable package CommonMedium = Modelica.Media.Air.DryAirNasa constrainedby Modelica.Media.Interfaces.PartialMedium annotation(
       choicesAllMatching = true);
    annotation(
      defaultComponentName = "system",
      defaultComponentPrefixes = "inner");
  end TweakedSystem;

  model CommonMediaClosedVolume "ClosedVolume with a default Medium defined in system"
  extends Modelica.Fluid.Vessels.ClosedVolume;
    // Want to define a Medium default choice that is defined in system (a TweakedSystem instance)
    redeclare replaceable package Medium = system.CommonMedium;
    // Errors with Class name 'system.CommonMedium' was found via a component (only component and function call names may be accessed in this way).
  end CommonMediaClosedVolume;

  model SimulationModel
  inner TweakedSystem system 
    annotation(
      Placement(visible = true, transformation(origin = {-60, -56}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  CommonMediaClosedVolume commonMediaClosedVolume(V = 1)
    annotation(
      Placement(visible = true, transformation(origin = {0, -20}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  end SimulationModel;

end CommonMediaDefinition;

编辑:似乎我设想的这种传播 class 的方式在 Modelica 中是不允许的:

我无法将媒体添加到系统中。也许其他人知道该怎么做。

但是您可以通过在模拟模型顶部为您的单一媒体定义 inner package 来实现全局媒体定义。修改后的组件定义了 outer package

最后的用法和你的方法很相似。您必须使用原始系统并另外扩展提供内部 Medium 包的基本模型,而不是仅添加修改后的系统。

不幸的是,这种方法会带来一些麻烦。在 Dymola 2022x 中,它工作正常 (除非您激活迂腐模式,由于介质问题 Modelica.Media.Air.DryAirNasa...)。 但是在 OpenModelica 1.18.1 中你必须切换到“旧前端”,否则翻译会失败。并且您必须在组件中定义 non-partial 媒体。不知道以后会不会出事...

package CommonMediaDefinition

  partial model CommonMediumSelector "Extend to inherit CommonMedium parameter"
    inner replaceable package CommonMedium = Modelica.Media.Air.DryAirNasa
       constrainedby Modelica.Media.Interfaces.PartialMedium
       annotation (choicesAllMatching = true);
  end CommonMediumSelector;

  model CommonMediaClosedVolume "ClosedVolume with Medium defined via outer CommonMedium"
    // I would use this in Dymola, to ensure that a proper medium is selected, but it does not
    // work in OpenModelica...
    // outer replaceable package CommonMedium = Modelica.Media.Interfaces.PartialMedium;
    // ... hence we have to use this: 
    outer replaceable package CommonMedium = Modelica.Media.Air.DryAirNasa;
    extends Modelica.Fluid.Vessels.ClosedVolume(redeclare final package Medium=CommonMedium);
  end CommonMediaClosedVolume;

  model SimulationModel
    inner Modelica.Fluid.System system annotation (Placement(transformation(extent={{-90,70},{-70,90}})));
    extends CommonMediumSelector(redeclare package CommonMedium = Modelica.Media.Air.DryAirNasa);
    CommonMediaClosedVolume commonMediaClosedVolume(V=1) 
      annotation (Placement(visible=true, transformation(origin={0,-20}, extent={{-10,-10},{10,10}}, rotation=0)));
  end SimulationModel;

  annotation (uses(Modelica(version="4.0.0")));
end CommonMediaDefinition;