2

下面的 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;
4

1 回答 1

4

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

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

于 2015-04-23T02:36:57.933 回答