use asserts for debugging Modelica

自古美人都是妖i 提交于 2019-12-23 05:11:20

问题


In Modelica, one could define a protected final constant Boolean debug and then use that in an assert statement to print out some values while debugging, similar to the code shown below (or as seen on github).

In the final version, debug would then be set to false. Would that slow down the simulation or does the assert get eliminated, because debug is a constant?

model debugexample
  parameter Real a;
  parameter Real b;
  Real sum;

protected 
  final constant Boolean debug = false "set to true while debugging";

equation 
  assert(not debug, "a=" + String(a), level=AssertionLevel.warning);
  sum = a+b;
end debugexample;

回答1:


The assert would be eliminated because debug is constant. If debug is a parameter however the assert might (depending on the tool) still only be called once rather than every timestep, because the Boolean input to assert is not changing.



来源:https://stackoverflow.com/questions/51650920/use-asserts-for-debugging-modelica

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