在Modelica中预先初始化变量

时间:2014-12-23 17:32:40

标签: initialization pre modelica

我在Modelica中编写了如下代码:

model TestIniitial
  extends Modelica.Icons.Example;
  parameter Integer nWri= 2;
  Real u[nWri](each start= 10, fixed=false);
  Real uPre[nWri];
  parameter Real _uStart[nWri] = fill(10, nWri);
  parameter Modelica.SIunits.Time startTime = 0;
  parameter Modelica.SIunits.Time samplePeriod = 1;
  Boolean sampleTrigger "True, if sample time instant";
initial equation 
  u[1] = 1;
  u[2] = 2;
equation 
   sampleTrigger = sample(startTime, samplePeriod);

  when sampleTrigger then
    for i in 1: nWri loop
      uPre[i] = pre(u[i]);
    end for;
  end when;

  for i in 1:nWri loop
    u[i] = (i+1)*time;
  end for;

end TestIniitial;

基本上我想在模拟之前初始化你。但是,我从翻译中得到了以下投诉(u的初始化过度指定):

The Modelica Language Specification 3.2.1 specifies that if a real variable, v,
is appearing in an expression as pre(v), but not assigned by a when equation,
then the equation v = pre(v) should be added to the initialization problem.

For this problem the following equations were added:
u[1] = pre(u[1]);
u[2] = pre(u[2]);

我无法理解这些投诉,因为pre(v)已在方程式中分配。如果我想在上面的代码中初始化你,我该怎么办?

感谢。

1 个答案:

答案 0 :(得分:0)

看着这个,我的猜测是错误消息试图为您提供一些诊断信息,但是关于源代码是不正确的。我怀疑(再次,我不确定)它看到pre(u)出现在模型中并且存在初始化问题并假定特定问题。

我的猜测是,问题源于您fixed=true设置u的事实。我认为没有理由这样做,我的猜测是它会导致对初始化问题的太多限制。摆脱fixed=true,看看会发生什么。如果没有解决问题,请回报。

祝你好运。

相关问题