2015-04-22 96 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中閱讀更多內容。通過使用它作爲一個約束方程,它清楚地表明這個方程可以用來解決這個變量(包含該變量的方程中的項不會消失或者是病態的)。