Modelica中已弃用的函数基数(c)的替换

问题描述 投票:5回答:3

documentation中表明cardinality()功能已被弃用,不应再使用。但是,它仍在ThermoSysPro等库中使用。

例如

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

其中CFluidInletFluidOutlet

有人可以举一个简单的例子说明如何替换它吗?

modelica openmodelica jmodelica
3个回答
5
投票

通常的解决方案是使连接器成为条件连接器,如果启用了连接器,则要求它已连接。

对于物理连接器,您可以通过以下方式查看热口和支撑的处理方式:Modelica.Electrical.Analog.Interfaces.ConditionalHeatPortModelica.Mechanics.Rotational.Interfaces.PartialElementaryOneFlangeAndSupport2

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

但是,ThermoSysPro的连接器不属于这些类别,因此理想情况下也应对其进行清理。


2
投票

我唯一可以在这方面使用的是connectorSizing批注。在MLS第18.7章中对此进行了描述。

在Modelica标准库中多次使用,例如通过参数Modelica.Blocks.Math.MinMaxnu中进行设置。使用时,该工具会根据与它的连接数自动为nu设置修饰符。

  parameter Integer nu(min=0) = 0 "Number of input connections"
    annotation (Dialog(connectorSizing=true));
  Modelica.Blocks.Interfaces.RealVectorInput u[nu];

在下面的示例中,在图形层中创建连接时,Dymola会自动生成nu=2。我删除了图形注释,以使代码更具可读性。

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;

1
投票

cardinality()运算符在Modelica.Fluid.Sources.BaseClasses.PartialSource中使用,并且以类似的方式在其他流体库(IBSPAAixLibBuildingsBuildingSystemsIDEAS)中,格式为

  // 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()可以有效地捕获这种情况,否则会导致用户不打算并且很难发现的流体端口中的混合。

© www.soinside.com 2019 - 2024. All rights reserved.