您如何在自定义流体系统中定义常见媒介?
我正在设计一组用于流体系统建模的自定义组件。由于整个模型中只有一种媒介,我希望能够在一个地方定义该媒介。无论如何,我们对大多数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
) inTweakedSystem
so that I can extend my models to pick that up by default, and so that I can select the desired medium in aTweakedSystem
instancesystem
?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法将介质添加到系统中。也许其他人知道该怎么做。
但是,您可以通过在模拟模型的顶部为单个介质定义
内部包
来实现全局媒体定义。修改后的组件具有外部包
定义的。最后,用法与您的方法非常相似。您必须使用原始系统并延长提供内部中型包装的基本模型,而不是仅添加修改后的系统。
不幸的是,这种方法遇到了一些麻烦。在Dymola 2022X中,它的工作正常(除非您激活pedantic模式,否则由于中米Modelica.media.air.dryairnasa ...)而产生错误。
但是在OpenModelica 1.18.1中,您必须切换到“旧前端”,因为翻译会失败。而且您必须在组件中定义非派对介质。我不确定这是否会在以后会带来麻烦...
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 anouter 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...