关于Dymola运行时ln函数的问题

huangapple go评论141阅读模式
英文:

Problems with the dymola runtime ln function

问题

我最近在编写一个动态模型,但遇到了一些无法解决的问题。

以下是代码的一部分,我想要实现的功能是当Tb2小于饱和温度Tbaohe时,使用对数平均温度差T1进行求解,当Tb2等于饱和温度时,在上述解的基础上继续使用算术平均温度差T2进行求解,其中Tc1等于Tbaohe

但当我尝试求解时,我遇到了以下错误。显然,这里的ln函数存在问题,似乎当Tb2无限接近饱和温度Tbaohe时,运行会自动停止,我无法解决这个问题。

谢谢您提前回复!

英文:

I was writing a dynamic model recently, but I ran into some problems that I couldn't solve.
The following is part of the code, the function I want to implement is that when Tb2 is less than the saturation temperature Tbaohe, the logarithmic average temperature difference T1 is used to solve, and when Tb2 is equal to the saturation temperature, continue to use the arithmetic average temperature difference T2 on the basis of the above solution results to continue the solution, where Tc1 is equal to Tbaohe.

  Kc*Ac*T3 = (Wnjs + Gna)*(hc1 - hb2);
  T1 = ((Te1 - Tbaohe) - (Tc1 - Tb2))/(ln((Te1 - Tbaohe)/(Tc1 - Tb2)));
  T2 = (Te1 + Tbaohe)/2 - (Tc1 + Tb2)/2;
  if Tb2 < Tbaohe then
    T3 = T1;
  else
    T3 = T2;
  end if;

But when I solve, I get the following error. Apparently there is a problem with the ln function here, it seems that when Tb2 is infinitely close to the saturation temperature Tbaohe, the run stops automatically, I can't fix this.

Error: The following error was detected at time: 10.86044238659505

Model error - division by zero: (Te1-Tbaohe) / (Tc1-Tb2) = (104.936) / (0)

First evaluation failed for non-linear solver.

First evaluation failed for non-linear solver.

关于Dymola运行时ln函数的问题

Thanks in advance for your reply!

答案1

得分: 3

我认为这里的根本问题是,您编写的是方程,而不是赋值语句或宏。因此,T1和T2始终是“活动的”,而不仅仅是在if语句的交替分支中。您的模型表示T1和T2的方程始终得到满足。

英文:

I think the fundamental issue here is that your write equations, not assignment statements or macros. So both T1 and T2 are always "active", not just in alternating branches of your if statement. Your model says the equations for T1 and T2 are always satisfied.

答案2

得分: 2

如果两个温度接近,您正在除以零。 Tb2 不应该比 Tc1 大,否则 ln 函数将返回负值。 您可以使用 max(1e-4, (Tc1 - Tb2)) 而不是 (Tc1 - Tb2)。 如果 Tb2 打算变大于 Tc1,那么您的方程可能存在错误。 完整的源代码将有助于识别变量和参数。

英文:

If the two temperatures become close, you are dividing by zero. Tb2 should not become larger than Tc1, otherwise you would get a negative value for the ln function. You could use max(1e-4, (Tc1 - Tb2)) instead of (Tc1 - Tb2). If Tb2 is intended to become larger than Tc1, than there might be an error in your equation. The complete source code would be helpful to identify variables and parameters.

huangapple
  • 本文由 发表于 2023年6月8日 23:25:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76433438.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定