Skip to content
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

Clarify elsewhen initial #2647

Merged
merged 2 commits into from Sep 8, 2020
Merged

Conversation

HansOlsson
Copy link
Collaborator

Closes #2636

Copy link
Collaborator

@henrikt-ma henrikt-ma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing major, just some comments.

chapters/equations.tex Outdated Show resolved Hide resolved
@@ -748,7 +748,7 @@ \section{Initialization, initial equation, and initial algorithm}\label{initiali
(such as simulation or linearization).

The equations of a when-clause are active during initialization, if and only if they are explicitly enabled with \lstinline!initial()!, and only in one of the two forms
\lstinline!when initial() then! or \lstinline!when {$\ldots$, initial(), $\ldots$} then! (and similarly for algorithms see below). In this case, the when-clause equations remain active during the
\lstinline!when initial() then! or \lstinline!when {$\ldots$, initial(), $\ldots$} then! (and similarly for \lstinline!elsewhen! and algorithms see below). In this case, the when-clause equations remain active during the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps when-statements would be more to the point, and the see below probably only refers to these?

Suggested change
\lstinline!when initial() then! or \lstinline!when {$\ldots$, initial(), $\ldots$} then! (and similarly for \lstinline!elsewhen! and algorithms see below). In this case, the when-clause equations remain active during the
(where \lstinline!when! may be replaced by \lstinline!elsewhen!) \lstinline!when initial() then! or \lstinline!when {$\ldots$, initial(), $\ldots$} then! (and similarly for when-statements, see below). In this case, the when-clause equations remain active during the

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I first considered a text like that, but I didn't like it since there is a slight difference between elsewhen and when, in that when is always first - and I wanted to delay those obscure cases. The elsewhen-part below handles both.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it just seems unfortunate that when/elsewhen causes a lack of symmetry that is only syntactical. This is why I ended up with the formulation suggested below (if and only if they are the first clause…) that captures the symmetry of the semantics.

Comment on lines +770 to +771
That means that any subsequent \lstinline!elsewhen initial()! has no effect,
similarly as \lstinline!when false then!.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we go as far as to speak of warnings?

Suggested change
That means that any subsequent \lstinline!elsewhen initial()! has no effect,
similarly as \lstinline!when false then!.
A tool may warn in case an \lstinline!initial()! condition cannot activate its when-clause due to an earlier when-clause already being active during initialization.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered it, but there are (as indicated) other similar cases as well, and to me it looks odd if we discuss warnings for the obscure cases - and not for the simple ones; and thought it sufficed to say that it has no effect.

@@ -762,6 +762,15 @@ \section{Initialization, initial equation, and initial algorithm}\label{initiali
\lstinline!when initial() then! or \lstinline!when {$\ldots$, initial(), $\ldots$} then!. In this case, the algorithmic statements within the when-statement remain active during the whole
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose there should be an elsewhen clarification here as well, preserving the symmetry with the when-equations?

Comment on lines +765 to +767
An active when-clause inactivates the following \lstinline!elsewhen! (similarly as for when-clauses during simulation), but apart from that
the first \lstinline!elsewhen initial() then! or \lstinline!elsewhen {$\ldots$, initial(), $\ldots$} then! is similarly active during initialization as
\lstinline!when initial() then! or \lstinline!when {$\ldots$, initial(), $\ldots$} then!.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, maybe this was also included among the intended references of the see below above?

I think we can say this more directly, if we go back to the first sentence:

The equations of a when-clause are active during initialization, if and only if they are the first clause of the when-equation explicitly enabled with \lstinline!initial()!, …

Remove double space.

Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
@HansOlsson
Copy link
Collaborator Author

I'll merge it for now and we can then later improve the formulation.

@HansOlsson HansOlsson merged commit c491fae into modelica:master Sep 8, 2020
@HansOlsson HansOlsson deleted the ElseWhenInitial branch September 8, 2020 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Does initial() have to be in the condition of the first when-clause?
2 participants