Modelica Simulation breaks when if condition changes

て烟熏妆下的殇ゞ 提交于 2021-01-05 10:53:26

问题


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;

the simulation stops at the moment T reaches 73.

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

And how can i fix it?

Thank you.


回答1:


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

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. The temperature rises until it reaches 73
  2. Then the temperature starts to fall because the condition in the if-statement turns fall
  3. This causes the if-statement to immediately change to true again, making the temperature rise
  4. This causes the if-statement to change to false again, making the temperature fall
  5. goto 3.

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").

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;

The result of the simulation then looks like:

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



来源:https://stackoverflow.com/questions/53629251/modelica-simulation-breaks-when-if-condition-changes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!