理解 Dymola 错误消息时遇到问题
谁能告诉我“代数环”的含义 - 以及我应该如何通过添加“预”运算符来应对这种情况?我真的不明白...
Error: Failed to generate code for an algebraic loop
involving when equations or algorithms with when parts.
Unknowns:
pump.Hb_flow
pump.medium.d
pump.medium.h
pump.medium.state.melting
pump.medium.state.T
pump.V_flow
pump.V_flow_single
pump.W_single
Equations:
algorithm
when Modelica.SIunits.Conversions.to_degC(pump.medium.state.T) < 13.9 then
pump.medium.state.melting := true;
elsewhen Modelica.SIunits.Conversions.to_degC(pump.medium.state.T) > 32.8 then
pump.medium.state.melting := false;
end when;
// [removed set of equations that contained no "when"]
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.
提前致谢, 谨致问候
蒂莫。
Can anyone give me a hint what "algebraic loop" means -- and how I am supposed to cope with this situation by adding "pre"-operators? I'm seriously not getting it...
Error: Failed to generate code for an algebraic loop
involving when equations or algorithms with when parts.
Unknowns:
pump.Hb_flow
pump.medium.d
pump.medium.h
pump.medium.state.melting
pump.medium.state.T
pump.V_flow
pump.V_flow_single
pump.W_single
Equations:
algorithm
when Modelica.SIunits.Conversions.to_degC(pump.medium.state.T) < 13.9 then
pump.medium.state.melting := true;
elsewhen Modelica.SIunits.Conversions.to_degC(pump.medium.state.T) > 32.8 then
pump.medium.state.melting := false;
end when;
// [removed set of equations that contained no "when"]
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.
Thanks in advance,
best regards
TIMO.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,这个问题是因为when子句中的方程影响触发它们的条件语句。
对于 Modelica,您需要了解的是,求解器将使用“候选解”作为模拟过程的一部分来评估方程。这些不一定是它最终选择的解决方案,但它仍然需要在接近最终解决方案时对其进行评估。
这有什么关系?在你的例子中,我看到你正在改变“融化”变量的值。但如果该值随后影响介质温度(从而引发“熔化”值的变化),则该工具将检测到方程系统中的不一致。一个工具也许能够迭代找到一致的候选解决方案,但 Dymola 只是“下注”并表示它不支持这种情况。
现在,这里要理解的重要一点是,基本上这通常都是无关的。为什么?因为在大多数情况下,用户确实不希望在这种情况下使用 when 子句的默认语义。大多数用户想要的是将when 子句中的条件视为“原因”,并将when 子句中的方程视为“结果”。从这个意义上说,它们是连续的,结果不应该逆转并影响原因(尽管白条纹写了一首关于这种情况的伟大歌曲;-))。
这里的一般模式是隔离条件,然后在 when 子句中在其周围添加一个“pre”运算符。如果原始模型如下所示:
您只需将模型重构为如下所示:
这里最重要的是,涉及 y 的方程仅在条件为真之后出现。在这种情况下,“pre”基本上是说,如果在当前时间减去一些 epsilon,条件值为 true,则(作为响应)when 子句中的方程启动。
这种情况可能会导致到一个称为“chattering”的条件,其中条件的值随着时间的每一个“epsilon”的过去而翻转,但这意味着问题没有很好地提出。
我希望这有一定道理。我承认,在复杂的情况下,很难准确检测代数环存在的位置(尽管 Dymola 试图为您提供一些诊断)。另外,在某些情况下,您确实需要 Modelica 的默认行为,因此您并不总是想添加无偿的“pre”限定符。
如果您对此解释有任何疑问,请告诉我。
This problem is, in general, because the equations within the when clause impact the conditional statement that triggers them.
The thing that you need to understand with Modelica is that a solver will evaluate equations using "candidate solutions" as part of the simulation process. These are not necessarily the solution it will eventually choose, but it nevertheless needs to evaluate them as it approaches the eventual solution.
How is this related? Well in your case I see that you are changing the value of a "melting" variable. But if that value then influences the medium temperature (which triggered the change in the value of "melting") then the tool will detect an inconsistency in the system of equations. A tool might be able to iterate to find a consistent candidate solution, but Dymola just "punts" and says it doesn't support such situations.
Now, the important thing to understand here is that basically this is usually all irrelevant. Why? Because for the most part user's really don't want the default semantics of when clauses in such cases. What most users want is to treat the condition in the when clause as a "cause" and the equations inside the when clause as an "effect". In this sense, they are sequential and the effect should not turn around and affect the cause (although the White Stripes wrote a great song about such situations ;-)).
The general pattern here is to isolate the condition and then add a "pre" operator around it in the when clause. If the original model looked like this:
You just need to refactor the model into something like this:
The essential thing here is that the equations involving y only come after the condition is true. The 'pre' in this case basically says that if, at current time minus some epsilon, the value of condition was true then (in response) the equations in the when clause kick in.
Such situations can lead to a condition called "chattering" where the value of the condition flips for every "epsilon" of time that passes, but this means that the problem is not well posed.
I hope this makes some sense. I admit that in complex cases, it can be hard to detect exactly where the algebraic loops exist (although Dymola tries to give you some diagnostics). Also, in some cases you do want the default behavior of Modelica so you don't always want to add gratuitous 'pre' qualifiers.
Let me know if you have any questions on this explanation.