gpt4 book ai didi

Modelica 参数作为输入

转载 作者:行者123 更新时间:2023-12-02 21:18:14 25 4
gpt4 key购买 nike

考虑以下简单的包。

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com