在文档中指出,该cardinality()
功能已被弃用,不应再使用。但是,它仍然在 ThermoSysPro 等库中使用。
例如
if (cardinality(C) == 0) then
some code
end if;
C
在哪里FluidInlet
或FluidOutlet
谁能举一个简单的例子来说明如何替换它?
在文档中指出,该cardinality()
功能已被弃用,不应再使用。但是,它仍然在 ThermoSysPro 等库中使用。
例如
if (cardinality(C) == 0) then
some code
end if;
C
在哪里FluidInlet
或FluidOutlet
谁能举一个简单的例子来说明如何替换它?
通常的解决方案是使连接器有条件,如果启用,您需要连接它。
对于物理连接器,您可以查看如何处理热端口和支持:
Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort
Modelica.Mechanics.Rotational.Interfaces.PartialElementaryOneFlangeAndSupport2
对于控制信号,您可以查看如何处理
p_in
等h_in
Modelica.Fluid.Sources.Boundary_pT
Modelica.Fluid.Sources.Boundary_ph
然而,ThermoSysPro 的连接器不属于这两个类别,理想情况下也应该清理干净。
我知道的唯一可以在这方面使用的是connectorSizing
注释。它在MLS第 18.7 章中进行了描述。
它在 Modelica 标准库中被多次使用,例如Modelica.Blocks.Math.MinMax
通过参数nu
. 使用它时,该工具会nu
根据与其连接的数量自动设置修饰符。
parameter Integer nu(min=0) = 0 "Number of input connections"
annotation (Dialog(connectorSizing=true));
Modelica.Blocks.Interfaces.RealVectorInput u[nu];
在下面的示例中,nu=2
由 Dymola 在图形层中创建连接时自动生成。我已经删除了图形注释,以使代码更具可读性。
model ExCS
Modelica.Blocks.Math.MinMax minMax(nu=2);
Modelica.Blocks.Sources.Sine sine(freqHz=6.28);
Modelica.Blocks.Sources.Constant const(k=0.5);
equation
connect(sine.y, minMax.u[1]);
connect(const.y, minMax.u[2]);
end ExCS;
cardinality()
运算符用于Modelica.Fluid.Sources.BaseClasses.PartialSource
,并以类似的方式在其他流体库(、IBSPA
、AixLib
和)中使用Buildings
,形式为BuildingSystems
IDEAS
// Only one connection allowed to a port to avoid unwanted ideal mixing
for i in 1:nPorts loop
assert(cardinality(ports[i]) <= 1,"
each ports[i] of boundary shall at most be connected to one component.
If two or more connections are present, ideal mixing takes
place with these connections, which is usually not the intention
of the modeller. Increase nPorts to add an additional port.
");
end for;
我偶尔会收到一些用户的模型,这些用户不知何故最终与ports[i]
. 这是如何发生的还不清楚,但我发现使用cardinality()
有助于捕捉这种情况,否则可能会导致用户无意且难以检测到的流体端口中的混合。