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

Mat*_*abc 3 modelica openmodelica

以下 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;
Run Code Online (Sandbox Code Playgroud)

但是,当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;
Run Code Online (Sandbox Code Playgroud)

Mic*_*ler 5

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

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

请注意,一般来说,如果两个事物是连接器,则它们不应该等同,而应该连接。这将帮助您避免这个问题。所以在你的第一个版本中B

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

结合方程限制的原因与确保组分平衡有关。您可以在规范或Modelica 示例中阅读更多相关信息。通过将其用作绑定方程,可以清楚地看出该方程可用于求解该变量(方程中包含该变量的项不会消失或病态)。