5

文档中指出,该cardinality()功能已被弃用,不应再使用。但是,它仍然在 ThermoSysPro 等库中使用。

例如

if (cardinality(C) == 0) then
 some code
end if;

C在哪里FluidInletFluidOutlet

谁能举一个简单的例子来说明如何替换它?

4

3 回答 3

6

通常的解决方案是使连接器有条件,如果启用,您需要连接它。

对于物理连接器,您可以查看如何处理热端口和支持: Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort Modelica.Mechanics.Rotational.Interfaces.PartialElementaryOneFlangeAndSupport2

对于控制信号,您可以查看如何处理 p_inh_inModelica.Fluid.Sources.Boundary_pT Modelica.Fluid.Sources.Boundary_ph

然而,ThermoSysPro 的连接器不属于这两个类别,理想情况下也应该清理干净。

于 2019-11-22T17:09:00.297 回答
3

我知道的唯一可以在这方面使用的是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;
于 2019-11-21T15:50:32.920 回答
2

cardinality()运算符用于Modelica.Fluid.Sources.BaseClasses.PartialSource,并以类似的方式在其他流体库(、IBSPAAixLib和)中使用Buildings,形式为BuildingSystemsIDEAS

  // 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()有助于捕捉这种情况,否则可能会导致用户无意且难以检测到的流体端口中的混合。

于 2020-01-23T17:27:25.370 回答