您如何在自定义流体系统中定义常见媒介?

发布于 2025-01-21 11:54:21 字数 2257 浏览 0 评论 0原文

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

我已经尝试了以下MWE,但是我遇到了我不知道如何避免的课堂查找问题。 使用当前的OpenModelica,在检查consemmediaclosedvolume时,我会遇到错误

类名称'System.CommonMedium'是通过组件找到的(只能以这种方式访问​​组件和函数调用名称)。

我注意到有一个fluid.system.medium定义了我认为可以有类似目的的定义,但是在OMEdit中的“参数对话框”中不可见(尽管它具有choices> choicesallMatching <<< /code>注释 - 一个OM错误?),并且似乎在其他任何地方都没有使用。无论如何,它显示相同的查找错误消息。

问题:

  • tweakedsystem中,如何定义默认类(从partialmedium)派生,以便我可以扩展模型以默认情况下拾取该模型,以便我可以选择调整系统实例系统中的所需介质?
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;

编辑:在Modelica中,似乎不允许这样的班级: https://stackover.com/a /24209596/599884

I am designing a set of custom components for fluid system modelling. As there will only be one medium throughout the model, I want to be able to define that medium in one place. The system component we need for most Modelica.Fluid systems anyway seems like a good place.

I have tried the following MWE, but I'm running into problems with class lookup that I don't know how to avoid.
Using current OpenModelica, when checking the CommonMediaClosedVolume, I'm getting an error

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

I noticed that there is a Fluid.System.Medium defined which I thought could serve a similar purpose, but it's not visible for changing in the parameter dialog in OMEdit (Although it has a choicesAllMatching annotation -- an OM bug?), and it does not seem to get used anywhere else. In any case, it shows the same lookup error message.

Question:

  • How can I define a default class (derived from PartialMedium) in TweakedSystem so that I can extend my models to pick that up by default, and so that I can select the desired medium in a TweakedSystem instance system?
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;

Edit: It seems that this way I envisioned propagating a class is not allowed in Modelica: https://stackoverflow.com/a/24209596/599884

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花开雨落又逢春i 2025-01-28 11:54:21

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

但是,您可以通过在模拟模型的顶部为单个介质定义内部包来实现全局媒体定义。修改后的组件具有外部包定义的。

最后,用法与您的方法非常相似。您必须使用原始系统并延长提供内部中型包装的基本模型,而不是仅添加修改后的系统。

不幸的是,这种方法遇到了一些麻烦。在Dymola 2022X中,它的工作正常(除非您激活pedantic模式,否则由于中米Modelica.media.air.dryairnasa ...)而产生错误。
但是在OpenModelica 1.18.1中,您必须切换到“旧前端”,因为翻译会失败。而且您必须在组件中定义非派对介质。我不确定这是否会在以后会带来麻烦...

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;

I was not able to add the medium to the system. Maybe someone else knows how to do so.

But you could achieve a global media definition by defining an inner package for your single medium at top of your simulation model. The modified components have an outer package defined.

At the end the usage is quite similar to your approach. Instead of adding just a modified System, you have to use the original System and additionally extend a base model which provides the inner Medium package.

Unfortunately this method makes some troubles. In Dymola 2022x it works fine (unless you activate pedantic mode, which gives an error due to problems in the medium Modelica.Media.Air.DryAirNasa...).
But in OpenModelica 1.18.1 you have to switch to the "Old Frontend", as translation fails otherwise. And you have to define a non-partial medium in the components. I am not sure if this will make troubles later...

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文