Modelica 参数作为输入

标签 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) 引发的方程,两者必须相等。

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

最佳答案

您使用的是哪个版本的 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

我正在使用文件: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

关于Modelica 参数作为输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29196465/

相关文章:

modelica - 使用 OpenModelica 进行参数动态和静态优化或灵敏度分析

python - pyFMI Python模拟不同数量的输出点数

python - Dymola Python 接口(interface) - 模拟扩展模型 : How to set up parameters?

arrays - Modelica mos 脚本中数组大小的预分配

interpolation - Modelica 外部表上的 N 维(线性)插值

solver - Modelica 事件和混合建模

git - 使用带有 Dymola/Modelica 的 git 进行版本控制

autohotkey - Dymola 中模拟模型的热键

c - 以读/覆盖模式从 Modelica 访问外部 C 模块中的数据

connector - 实现非常简单的质量流量源时遇到问题