-
Notifications
You must be signed in to change notification settings - Fork 44
Clarify events in algorithms, and add examples. #3837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -590,6 +590,7 @@ \section{Events and Synchronization}\label{events-and-synchronization} | |
|
|
||
| The integration is halted and an event occurs whenever an event generation expression, e.g., \lstinline!x > 2! or \lstinline!floor(x)!, changes its value. | ||
| An event generating expression has an internal buffer, and the value of the expression can only be changed at event instants. | ||
| In an algorithm in a model or block each expression is compared to the previous value when executing the corresponding statement, where each iteration of statements inside for-loops are seen as different statements. | ||
| If the evaluated expression is inconsistent with the buffer, that will trigger an event and the buffer will be updated with a new value at the event instant. | ||
| During continuous integration event generation expression has the constant value of the expression from the last event instant. | ||
|
|
||
|
|
@@ -610,6 +611,46 @@ \section{Events and Synchronization}\label{events-and-synchronization} | |
| This requirement can be fulfilled if \lstinline!Real! elementary relations are not treated literally but as defined above, because discontinuous changes can only occur at event instants and no longer during continuous integration. | ||
| \end{example} | ||
|
|
||
| \begin{example} | ||
| Demonstrating events for algorithms in models | ||
HansOlsson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| \begin{lstlisting}[language=modelica] | ||
| model AlgorithmEvent1 | ||
| Real x; | ||
| Integer i; | ||
| algorithm | ||
| i := 0; | ||
| x := sin(time); | ||
| if x < 0 then // <-- relation 1 | ||
| x := 0; | ||
| i := 1; | ||
| end if; | ||
| x := cos(time); | ||
| if x < 0 then // <-- relation 2 | ||
| x := 0; | ||
| i := i+2; | ||
| end if; | ||
| x := 3.5; | ||
| annotation (experiment(StopTime=10)); | ||
HansOlsson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end AlgorithmEvent1; | ||
| \end{lstlisting} | ||
| This example works as if the first \lstinline!x < 0! was replaced by \lstinline!sin(time) < 0! and the second by \lstinline!cos(time) < 0!. | ||
|
|
||
| \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. | ||
|
Comment on lines
+641
to
+654
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we really make such a big point of how a
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Split into two example-sections, and add that for-equation text in second example-section.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| \end{example} | ||
|
|
||
| \begin{nonnormative} | ||
| It is a quality of implementation issue that the following special relations | ||
| \begin{lstlisting}[language=modelica] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.