Modelica参数作为输入

时间:2015-03-22 15:53:47

标签: 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;

这样可以正常工作,但只要我在模拟中更改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.

变量p.kc.p.k不会相互混淆。因此,当我仅更改p.k时,会检测到一个不允许的差异,因为由于connect(p, c.p)引起的等式,两者必须相等。

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

1 个答案:

答案 0 :(得分:2)

您使用的是哪个版本的OpenModelica? 对我来说,这并没有发生。 模拟工作正常:

adrpo@ida-liu050 ~/dev/OpenModelica/build/bin/
$ ./omc TestConnectionParameter.mos
true
""
record SimulationResult
    resultFile = "c:/bin/cygwin/home/adrpo/dev/OpenModelica/build/bin/media/TestConnectionParameter.System_res.mat",
    simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-006, method = 'dassl', fileNamePrefix = 'TestConnectionParameter.System', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
    messages = "",
    timeFrontend = 0.01857038093533281,
    timeBackend = 0.009237455657633623,
    timeSimCode = 0.002007941686540131,
    timeTemplates = 0.06294835594000042,
    timeCompile = 2.89228755603547,
    timeSimulation = 0.463245543628269,
    timeTotal = 3.4489112421252
end SimulationResult;
"Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
"
true
1.5
1.5
1.5
1.5
1.5
1.5

我正在使用file:TestConnectionParameter.mo:

package TestConnectionParameter

  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 TestConnectionParameter;

和脚本:TestConnectionParameter.mos

loadFile("TestConnectionParameter.mo"); getErrorString();
simulate(TestConnectionParameter.System); getErrorString();
plot({c.x, p.k, c.p.k});
val(p.k, 0);
val(p.k, 0.5);
val(p.k, 1);
val(c.p.k, 0);
val(c.p.k, 0.5);
val(c.p.k, 1);

获得: enter image description here