如果条件发生变化,Modelica Simulation 就会中断 [英] Modelica Simulation breaks when if condition changes

查看:65
本文介绍了如果条件发生变化,Modelica Simulation 就会中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在modelica上使用if尝试了一个简单的代码:

I try a simple code on modelica using if:

model thermostat1
  parameter Real T0=10;
  Real T(start=T0);
equation 
  if T<73 then
    der(T)=-T+80;  
  else
     der(T)=-T+50;
  end if;
end thermostat1;

模拟在 T 达到 73 的时刻停止.

the simulation stops at the moment T reaches 73.

为什么不能用新方程 ( der(T)=-T+50 ) 继续模拟?

Why can't the simulation continue with the new equation ( der(T)=-T+50 )?

我该如何解决?

谢谢.

推荐答案

在您的模型中发生的情况称为喋喋不休.这意味着,有非常频繁的事件发生.

What happens in your model is called chattering. This means, that there are very frequent events happening.

在你的情况下,这是由条件 T<73 与导数的定义相结合引起的.让我试着解释一下你提供的模型会发生什么:

In you case specifically this is caused by the condition T<73 combined with the definitions of the derivatives. Let me try to explain what happens with the model you have provided:

  1. 温度上升到 73 度
  2. 然后温度开始下降,因为 if 语句中的条件开始下降
  3. 这会导致 if 语句立即再次变为 true,从而导致温度升高
  4. 这会导致 if 语句再次变为 false,从而导致温度下降
  5. 转到 3.

这会导致条件 T<73 以非常高的频率变化,进而产生许多必须由求解器处理的事件.这使得时间上的进展非常小(您称之为模拟停止").

This causes the condition T<73 to change at a very high frequency, in turn creating many events, which have to be handled by the solver. This makes the progress in time very little (what you refer to as "the simulation stops").

有多种方法可以解决此问题.一种是向模型添加滞后.我在下面的代码中做到了这一点.为了描述滞后部分,我使用了 Modelica.Blocks.Logical.Hysteresis 中的代码.这将使布尔变量 upperLimit(替换您的 T<73)仅在温度高于 T_high 且低于 时发生变化T_low.我选择了这个解决方案,因为它对于恒温器来说似乎是合理的.

There are multiple ways to solve this problem. One is to add a hysteresis to the model. I did that in code below. To describe the hysteresis part I used the code from Modelica.Blocks.Logical.Hysteresis. This will make the boolean variable upperLimit (which replaces your T<73) change only if temperature gets higher than T_highand lower than T_low. I chose this solution as it seems reasonable for a thermostat.

model thermostat1
  parameter Real T0=10;

  parameter Real T_High=74;
  parameter Real T_Low=72;

  Boolean upperLimit "Output of hysteresis block";
  Real T(start=T0);

equation 
  upperLimit =not pre(upperLimit) and T > T_High or pre(upperLimit) and T >= T_Low;

  if upperLimit then
    der(T)=-T+50;
  else
    der(T)=-T+80;
  end if;

end thermostat1;

模拟结果如下所示:

可以找到更多一般信息,例如在 http://book.xogeny.com/behavior/discrete/decay/

More general information can be found e.g. at http://book.xogeny.com/behavior/discrete/decay/

这篇关于如果条件发生变化,Modelica Simulation 就会中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆