小编Mat*_*abc的帖子

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

modelica openmodelica

3
推荐指数
1
解决办法
480
查看次数

Modelica 参数作为输入

考虑下面的简单包。

package Test

  connector Param
    parameter Real k = 1.5;
  end Param;

  model Component
    input Param p;
    Real x;
  equation 
    der(x) = p.k;
  end Component;

  model System
    Param p;
    Component c;
  equation 
    connect(p, c.p);
  end System;

end Test;
Run Code Online (Sandbox Code Playgroud)

这工作正常,但一旦我System.p.k在模拟中更改,我就会收到以下错误:

abs(p.k-c.p.k) <= 0.0
The following error was detected at time: 0
Parameters in connected connectors must be equal
Error: Failed to start model.
Run Code Online (Sandbox Code Playgroud)

不知何故,变量p.kc.p.k不互相别名。因此,当我只更改 时p.k,会检测到不允许的差异,因为由于由 引起的方程,两者必须相等connect(p, c.p)

如何正确使用参数作为输入并避免这些影响?

modelica

1
推荐指数
1
解决办法
1668
查看次数

标签 统计

modelica ×2

openmodelica ×1