2015-04-22 97 views
1

以下Modelica软件包 - 虽然既不特别有用也不感兴趣 - 不会产生任何警告。Modelica:混合连接器和直接输入

package P 
    connector C 
    Real c; 
    end C; 
    model A 
    input C x; 
    output Real y; 
    equation 
    y = x.c; 
    end A; 
    model B 
    input C inp; 
    output C out; 
    A a; 
    equation 
    a.x = inp; 
    out.c = a.y; 
    end B; 
end P; 

然而,当A不使用连接器,如以下的情况下,还有一个警告:以下输入缺少的结合方程:a.x。显然,对于a.x有一个约束方程。为什么会有这样的警告?

package P 
    connector C 
    Real c; 
    end C; 
    model A 
    input Real x; 
    output Real y; 
    equation 
    y = x; 
    end A; 
    model B 
    input C inp; 
    output C out; 
    A a; 
    equation 
    a.x = inp.c; 
    out.c = a.y; 
    end B; 
end P; 

回答

3

的问题在这里是有具有约束力的方程。只有一个普通的等式。结合方程是作为对元素的修改而应用的方程,

model B 
    input C inp; 
    output C out; 
    A a(x=inp.c) "Binding equation"; 
equation 
    out.c = a.y; 
end B; 

注意,在一般情况下,如果两件事情是连接器,他们不应该相提并论,他们应该被连接。这将帮助你避免这个问题。因此,在您第一个版本的B

model B 
    input C inp; 
    output C out; 
    A a; 
equation 
    connect(a.x, inp); 
    out.c = a.y; 
end B; 

的原因结合方程式限制与确保组件是平衡的事情。您可以在说明书或Modelica by Example中阅读更多内容。通过使用它作为一个约束方程,它清楚地表明这个方程可以用来解决这个变量(包含该变量的方程中的项不会消失或者是病态的)。