Modelica:混合连接器和直接输入

Modelica: Mixing connectors and direct inputs

以下 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;

这里的问题是没有约束方程。只有一个普通的方程。绑定方程是作为对元素的修改而应用的方程,例如

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 中阅读更多相关信息。通过将其用作绑定方程,可以清楚地表明该方程可用于求解该变量(方程中包含该变量的项不会消失或消失病态)。