如何在Modelica中使用多维连接器连接多维组件?

如何在Modelica中使用多维连接器连接多维组件?,modelica,dymola,Modelica,Dymola,我尝试将二维组件阵列连接到包含一维连接器的一维组件阵列,但在检查模型时,显示不匹配的尺寸时出错。 但我可以将一维组件阵列连接到包含一维连接器的组件, 那么,为什么这不能在多维情况下工作呢? 我做错了吗 我查过密码了,好像用不了 连接(管壁、端口b、表面、q端口) 但是如果我使用下面的代码,它可以正常工作 用于1:x循环中的i 对于1:y循环中的j 连接(管壁[i]。端口[b[j],表面[i,j]。q\U端口); 结束于; 结束于 我做了更多的测试,下面是运行良好的测试代码: model Unn

我尝试将二维组件阵列连接到包含一维连接器的一维组件阵列,但在检查模型时,显示不匹配的尺寸时出错。 但我可以将一维组件阵列连接到包含一维连接器的组件, 那么,为什么这不能在多维情况下工作呢? 我做错了吗

我查过密码了,好像用不了

连接(管壁、端口b、表面、q端口)

但是如果我使用下面的代码,它可以正常工作

用于1:x循环中的i
对于1:y循环中的j
连接(管壁[i]。端口[b[j],表面[i,j]。q\U端口);
结束于;
结束于

我做了更多的测试,下面是运行良好的测试代码:

model Unnamed
  gain_1[3] gain_1_1
  Modelica.Blocks.Sources.Sine[3,3] sine
  Modelica.Blocks.Math.Cos[3,3] cos
equation 
  connect(sine.y, gain_1_1.u);
  connect(gain_1_1.y, cos.u);
end Unnamed;

model gain_1

  Modelica.Blocks.Math.Gain[3] gain
  Modelica.Blocks.Interfaces.RealOutput[3] y
  Modelica.Blocks.Interfaces.RealInput[3] u
equation 
  connect(gain.y, y)
  connect(u, gain.u)
end gain_1;
以下是连接的屏幕截图:

看来这个想法是对的,但我不确定为什么它在我的模型中不起作用。希望有人能对我的模型中的不匹配错误给出提示或方向。

引用Fritzon的Modelica 3.3面向对象建模和仿真原理:

connect
construct可用于直接连接 连接器。对于此类阵列连接,以下情况适用:

  • 连接的连接器阵列的阵列尺寸必须匹配
  • 每个对应的元素对作为一对标量连接器连接
也就是说,参考
连接(管壁.端口b,表面.端口q)

  • 它不知道
    表面[:,:]
    的哪个尺寸到
    管壁[:]
    端口b[:]
  • for循环可以工作,因为您正在接管将这对元素作为标量连接器连接的任务
我对建模任务的建议是,创建一个接口块,将其放置在
曲面
管壁
之间,在该接口块中,您可以按照应该的方式实现元素连接。曲面和接口之间的连接可能如下所示:

  • connect(表面、接口、表面端口)

我到处玩,看看能不能找到答案。以下三点可能会让您更接近于一个标准答案,即为什么物理连接(在您的情况下是热连接)和信号连接(在您的情况下是真实输入/输出)之间存在不同的行为:

  • 实际输入/输出是因果关系,并且声明方式与物理连接器不同

    connector RealInput=input Real“'input Real'作为connector”注释(…)

  • 实际输入/输出看起来更像函数而不是连接器。我认为连接的连接器阵列的阵列维度必须匹配的规则不适用/未对它们强制执行。我可以想出不同的原因;其中两个可能是:

    • 有一个普遍接受的框架来处理表格,就像我们大多数人都同意在地理地图的左上角是西北方向一样。因此,连接会根据顺序自动排序:第一个dim、第二个dim、第三个dim,。。。另一方面,多维物理连接可能代表各种场景。最好让模型设计师负责正确地构建模型
    • 实际输入/输出生成一个赋值,而不是一组方程,因此在计算系统的因果关系时,它们不会对排序算法造成太多干扰
  • 最后,我试着测试一个只有一个潜在变量的标准连接器,看看这个问题是否是由于同时存在一个流量变量时生成的两个方程造成的。平面模型显示只生成了一个等式(如预期),但仍然不允许连接
    矩阵[:,:],数组[:]。数组[:]


  • 仅当阵列维度匹配时,“连接”构造才起作用

    • 您可以在“创建连接”窗口上提供索引,以便在管壁和曲面之间建立正确的连接。这正是代码所做的
    • 由于gain_1_1.u是一个尺寸为[3,3]的连接器,因此未命名的模型可以工作。如果更改实例增益_1的大小,您将看到差异
    因此,您可以连接相同大小的数组,也可以在连接过程中显式地提到索引


    希望这有帮助。

    这是Dymola中的一个bug,在下一版本的Dymola中,将支持此功能。
    connector PhysConnector
      Real pt;
      flow Real flw;
      annotation (...);
    end PhysConnector;  
    
        package MultidimConnections
    
            connector RealConnector
                Real r;
            annotation(Icon(coordinateSystem(preserveAspectRatio=false)),Diagram(coordinateSystem(preserveAspectRatio=false)));
            end RealConnector;
    
            partial model RealInterface
                RealConnector realConnector annotation(Placement(transformation(extent={{90,-10},{110,10}})));
            annotation(Icon(coordinateSystem(preserveAspectRatio=false),graphics={Rectangle(extent={{-100,100},{100,-100}},lineColor={28,108,200},fillColor={170,213,255},fillPattern=FillPattern.None)}),Diagram(coordinateSystem(preserveAspectRatio=false)));
            end RealInterface;
    
            model Source
                extends RealInterface;
                parameter Real k = 0;
            equation 
                k = realConnector.r;
            annotation(Icon(coordinateSystem(preserveAspectRatio=false),graphics={Rectangle(extent={{-80,80},{80,-60}},lineColor={28,108,200},fillColor={151,226,75},fillPattern=FillPattern.Solid), Text(extent={{-100,-60},{100,-100}},lineColor={28,108,200},fillColor={151,226,75},fillPattern=FillPattern.Solid,textString="%name")}),Diagram(coordinateSystem(preserveAspectRatio=false)));
            end Source;
    
            model User
                extends RealInterface;
                Real double;
            equation 
                double = 2*realConnector.r;
            annotation(Icon(coordinateSystem(preserveAspectRatio=false), graphics={Rectangle(extent={{-80,80},{80,-60}},lineColor={28,108,200},fillColor={85,170,255},fillPattern=FillPattern.Solid), Text(extent={{-100,-60},{100,-100}},lineColor={28,108,200},fillColor={85,170,255},fillPattern=FillPattern.Solid,textString="%name")}),Diagram(coordinateSystem(preserveAspectRatio=false)));
            end User;
    
            model User_multi
                MultidimConnections.User user annotation(Placement(transformation(extent={{-10,40},{10,60}})));
                MultidimConnections.User user1 annotation(Placement(transformation(extent={{-10,-10},{10,10}})));
                MultidimConnections.User user2 annotation(Placement(transformation(extent={{-10,-60},{10,-40}})));
                RealConnector realConnector[3] annotation(Placement(transformation(extent={{110,-10},{90,10}})));
            equation 
                connect(user.realConnector, realConnector[1]) annotation(Line(points={{10,50},{98,50},{98,-6.66667},{100,-6.66667}}, color={0,0,0}));
                connect(user1.realConnector, realConnector[2]) annotation(Line(points={{10,0},{98,0},{98,4.44089e-16},{100,4.44089e-16}}, color={0,0,0}));
                connect(user2.realConnector, realConnector[3]) annotation(Line(points={{10,-50},{98,-50},{98,6.66667},{100,6.66667}}, color={0,0,0}));
            annotation(Icon(coordinateSystem(preserveAspectRatio=false), graphics={Rectangle(extent={{-80,80},{80,40}},lineColor={28,108,200},fillColor={85,170,255},fillPattern=FillPattern.Solid),Text(extent={{-100,-60},{100,-100}},lineColor={28,108,200},fillColor={85,170,255},fillPattern=FillPattern.Solid,textString="%name"),Rectangle(extent={{-80,28},{80,-12}},lineColor={28,108,200},fillColor={85,170,255},fillPattern=FillPattern.Solid),Rectangle(extent={{-80,-20},{80,-60}},lineColor={28,108,200},fillColor={85,170,255},fillPattern=FillPattern.Solid),Rectangle(extent={{-100,100},{100,-102}}, lineColor={28,108,200})}),Diagram(coordinateSystem(preserveAspectRatio=false)));
            end User_multi;
    
            model TestCustomReal
                extends Modelica.Icons.Example;
                Source source(k=1) annotation(Placement(transformation(extent={{-60,40},{-40,60}})));
                User user annotation(Placement(transformation(extent={{60,40},{40,60}})));
                User_multi user_multi annotation(Placement(transformation(extent={{60,-10},{40,10}})));
                Source source_arr[3](k=1) annotation(Placement(transformation(extent={{-60,-10},{-40,10}})));
                User_multi user_multi_array[3] annotation(Placement(transformation(extent={{60,-60},{40,-40}})));
                Source source_mat[3,3](k=1) annotation(Placement(transformation(extent={{-60,-60},{-40,-40}})));
            equation 
                connect(source.realConnector, user.realConnector) annotation(Line(points={{-40,50},{40,50}}, color={0,0,0}));
                connect(source_arr.realConnector, user_multi.realConnector) annotation(Line(points={{-40,0},{40,0}}, color={0,0,0}));
                connect(source_mat.realConnector, user_multi_array.realConnector) annotation(Line(points={{-40,-50},{40,-50}}, color={0,0,0}));
            end TestCustomReal;
    
        annotation(uses(Modelica(version="3.2.3")));
        end MultidimConnections;