我正在关注 Claytex 的教程 https://www.claytex.com/blog/dymola-basics-8-dymola-model-inheritance/在部分和扩展模型上。我能够从父(部分)模型创建继承(扩展)模型,并且它允许我在兄弟类之间进行更改。但是,我想为所有兄弟类添加框选择器,如教程中所示
这是我的代码
型号“a”
partial model a
Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a port_a annotation (
Placement(transformation(rotation=0, extent={{-110,-10},{-90,10}})));
Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_b port_b annotation (
Placement(transformation(rotation=0, extent={{90,-10},{110,10}})));
annotation (uses(Modelica(version="3.2.3")), Icon(graphics={Text(
extent={{-100,102},{98,-98}},
lineColor={28,108,200},
textString="A")}));
end a;
型号“b”
model b
extends a;
Modelica.Thermal.HeatTransfer.Components.ThermalResistor thermalResistor(R=3)
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
equation
connect(port_a, thermalResistor.port_a)
annotation (Line(points={{-100,0},{-10,0}}, color={191,0,0}));
connect(port_b, thermalResistor.port_b)
annotation (Line(points={{100,0},{10,0}}, color={191,0,0}));
annotation (Icon(graphics={Text(
extent={{26,96},{98,12}},
lineColor={28,108,200},
textString="B")}));
end b;
模型“装配体”
model assembly
Modelica.Thermal.HeatTransfer.Sources.FixedTemperature fixedTemperature(T=274.15)
annotation (Placement(transformation(extent={{-60,40},{-40,60}})));
Modelica.Thermal.HeatTransfer.Sources.FixedTemperature fixedTemperature1(T=275.15)
annotation (Placement(transformation(extent={{40,40},{20,60}})));
replaceable b a1 constrainedby a annotation (choicesAllMatching=true, Placement(transformation(extent={
{-20,40},{0,60}})));
equation
connect(fixedTemperature.port, a1.port_a)
annotation (Line(points={{-40,50},{-20,50}}, color={191,0,0}));
connect(a1.port_b, fixedTemperature1.port)
annotation (Line(points={{0,50},{20,50}}, color={191,0,0}));
annotation (uses(Modelica(version="3.2.3")));
end assembly;
如果有人能指出我的实现与教程的不同之处,我将不胜感激。提前致谢。
最佳答案
这应该在 Dymola 中本身起作用(假设所有类都是公共(public)的),但是要获取框选择器,您需要在 assemble
图的背景中单击,或者使用它创建一个 TopModel,如教程,然后打开 assemble1
model TopModel
assembly assembly1
annotation (Placement(transformation(extent={{-40,20},{-20,40}})));
annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
coordinateSystem(preserveAspectRatio=false)));
end TopModel;
此外,部分类会从选择器中过滤掉,因此您只能在其中获得 b ,除非您还添加:
model c
extends a;
Modelica.Thermal.HeatTransfer.Components.ThermalResistor thermalResistor(R=3)
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
equation
connect(port_a, thermalResistor.port_a)
annotation (Line(points={{-100,0},{-10,0}}, color={191,0,0}));
connect(port_b, thermalResistor.port_b)
annotation (Line(points={{100,0},{10,0}}, color={191,0,0}));
annotation (Icon(graphics={Text(
extent={{26,96},{98,12}},
lineColor={28,108,200},
textString="C")}));
end c;
我将所有这些类都包含在一个包 P
中。请注意,第一次打开选择器可能需要几秒钟的时间。
关于modelica - 无法为 Dymola 中的所有匹配选项添加选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75377127/