gpt4 book ai didi

modelica:方程部分与算法部分的不同结果

转载 作者:行者123 更新时间:2023-12-02 21:43:06 24 4
gpt4 key购买 nike

以下简单模型是正确的并且可以在 dymola 中运行:

model new_timer

Modelica.Blocks.Logical.Timer timer;
Real my_time( start=0);

equation
timer.u=true;

my_time=timer.y;

end new_timer;

但是,下面的内容在使用 dymola“检查”时是正确的,但在模拟过程中不起作用:

model new_timer

Modelica.Blocks.Logical.Timer timer;
Real my_time( start=0);

algorithm
timer.u:=true;
my_time:=timer.y;

end new_timer;

我想知道并寻找一种方法来使后者发挥作用。 dymola报错如下:

Failed to generate code for an algebraic loop
involving when equations or algorithms with when parts.
Unknowns:
my_time
timer.entryTime
timer.u
timer.y

Equations:
when timer.u then
timer.entryTime = time;
end when;
timer.y = (if timer.u then time-timer.entryTime else 0.0);
algorithm
timer.u := true;
my_time := timer.y;

You may be able to cut the loop
by putting 'pre' around some of the references to
unknown continuous time variables in when parts or when conditions.

Translation aborted.

最佳答案

嗯。这是一个很好的例子,说明了为什么您应该尽可能使用方程部分。

以下...

algorithm     timer.u:=true;    my_time:=timer.y;

...大致等于:

algorithm     (timer.u,my_time) := f(timer.y);

现在更清楚的是,timer.u 看起来依赖于 timer.y。这样你就得到了一个循环。

下面创建了两个算法部分,这意味着依赖关系更加分散(有点像方程部分):

algorithm     timer.u:=true;algorithm    my_time:=timer.y;

尝试始终使用尽可能短的算法部分。

关于modelica:方程部分与算法部分的不同结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21364255/

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