Clarify events in algorithms, and add examples.#3837
Clarify events in algorithms, and add examples.#3837HansOlsson wants to merge 6 commits intomodelica:masterfrom
Conversation
| \begin{lstlisting}[language=modelica] | ||
| model AlgorithmEvent2 | ||
| Real x[n](start = 2:4); | ||
| parameter Integer n = 3 annotation(Evaluate=true); | ||
| Boolean b[n]; | ||
| equation | ||
| der(x) = -2*x; | ||
| algorithm | ||
| for i in 1:n loop | ||
| b[i] := x[i] > 1; | ||
| end for; | ||
| end AlgorithmEvent2; | ||
| \end{lstlisting} | ||
| Here we get one crossing function for each element of \lstinline!x!, three in total. |
There was a problem hiding this comment.
Should we really make such a big point of how a for-statement works when we don't have an example with a for-equation? For me, it would make more sense to just split the example in two, and make the second one primarily about for-equations, possibly also mentioning that for-statements are similar.
There was a problem hiding this comment.
I see reasons for making a big point about for-statements, but I wouldn't mind a for-equation example.
The reason is that traditionally for-equations were normally expanded, and adding crossing functions to expanded equations seems kind of trivial. For-statements are different (as they are not expanded), so one "line" in the source-code leads to multiple crossing functions. Both as a user and implementor I find that significant enough to have a special example.
There was a problem hiding this comment.
Split into two example-sections, and add that for-equation text in second example-section.
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
| i := 0; | ||
| x := sin(time); | ||
| if x < 0 then // <-- relation 1 | ||
| x := 0; |
There was a problem hiding this comment.
What value does this assignment add to the example?
| x := 0; |
| end if; | ||
| x := cos(time); | ||
| if x < 0 then // <-- relation 2 | ||
| x := 0; |
There was a problem hiding this comment.
Similarly:
| x := 0; |
| Real x[n](start = 2:4); | ||
| parameter Integer n = 3 annotation(Evaluate=true); |
There was a problem hiding this comment.
More readable if declared before use, and avoid the distraction from Evaluate = true:
| Real x[n](start = 2:4); | |
| parameter Integer n = 3 annotation(Evaluate=true); | |
| constant Integer n = 3; | |
| Real x[n](start = 2:4); |
| equation | ||
| der(x) = -2*x; | ||
| algorithm | ||
| for i in 1:n loop |
There was a problem hiding this comment.
Cleaner:
| for i in 1:n loop | |
| for i loop |
No description provided.