Modelica Evaluation Order

无人久伴 提交于 2019-12-11 03:34:17

问题


I can't really find any answer in the Modelica specification so ill ask you guys. The specification states that A tool is free to solve equations, reorder expressions and to not evaluate expressions if their values do not influence the result (e.g. short-circuit evaluation of Boolean expressions). If-statements and if-expressions guarantee that their clauses are only evaluated if the appropriate condition is true, but relational operators generating state or time events will during continuous integration have the value from the most recent event. If a numeric operation overflows the result is undefined. For literals it is recommended to automatically convert the number to another type with greater precision. Now, I wonder, can the tool choose to evaluate an expression several time in an integrator step? For example (probably not an valid example, just to give you guys an idea of what I was wondering :) )

Real x;

equation
  der(x) = -t;
  Modelica.Utilities.Streams.print(String(time));

This will print the same time for several times, so I figured that there is some kind of iteration going on. But I would really like to have it confirmed by some source.


回答1:


That is normal. Variable step size solvers (like dassl) can go back and forth in time to find the direction of the curve. Also, if you have events more values can be generated at the same time.

If you want to print time or values just at exact time instants you need when equations:

when sample(0, 1) then
  Modelica.Utilities.Streams.print(String(time));
end when;

Read more in the Modelica Spec about sample.

Is also possible to use fixed step size solvers like Euler or so.



来源:https://stackoverflow.com/questions/22063836/modelica-evaluation-order

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