Skip to content

Commit

Permalink
Improve sm (modelica#2735)
Browse files Browse the repository at this point in the history
* Clarify the merging of connections to multiple outputs.
1. It doesn't make sense to require them to connected to one "input", it makes more sense that they combine as one "source".
2. The merging according to previous section doesn't make sense as an explanation:
* The "v" variable is one and not one per state so it doesn't apply.
* The "v" is not even an "outer output".
* And finally I don't see how the first variant simplifies anything.
* The intermediate algorithm will require a start-value even if we are always in one of the states.
* The extra code is an algorithm, and we generally try to avoid that.
3.  List the exception also for connections.

Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
  • Loading branch information
HansOlsson and henrikt-ma committed Nov 25, 2020
1 parent 5106ab1 commit 2c687c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
2 changes: 1 addition & 1 deletion chapters/connectors.tex
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ \section{Restrictions of Connections and Connectors}\label{restrictions-of-conne
The matched primitive components of the two connectors must have the same primitive types, and flow variables may only connect to other flow variables, stream variables only to other stream variables, and causal variables (\lstinline!input!/\lstinline!output!) only to causal variables (\lstinline!input!/\lstinline!output!).
\item
A connection set of causal variables (\lstinline!input!/\lstinline!output!) may at most
contain variables from one inside \lstinline!output! connector or one public
contain variables from one inside \lstinline!output! connector (for state-machines extended as specified in \cref{merging-connections-to-multiple-outputs}) or one public
outside \lstinline!input! connector.
\begin{nonnormative}
I.e., a connection set may at most contain one source of a signal.
Expand Down
37 changes: 13 additions & 24 deletions chapters/statemachines.tex
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ \subsection{Reset Handling}\label{reset-handling}

\subsection{Activation handling}\label{activation-handling}

When a state is suspended its equations should not be executed, and its variables keep their value -- including state-variables in clocked discretized continuous-time equations.
When a state is suspended its equations should not be executed, and its variables keep their values -- including state-variables in clocked discretized continuous-time equations.

The execution of a sub-state machine has to be suspended when its
enclosing state is not active. This activation flag is given as a
Expand Down Expand Up @@ -428,35 +428,24 @@ \subsection{Merging Variable Definitions}\label{merging-variable-definitions}
\subsection{Merging Connections to Multiple Outputs}\label{merging-connections-to-multiple-outputs}

\begin{nonnormative}
Since instances of blocks can be used as states of a state
machine it is natural to extend the connection semantics of Modelica to
allow several outputs to be connected to one input.
The causal connection semantics of Modelica for non-state machines are generalized to states of state machines, using the fact that only one state is active at a time.
\end{nonnormative}

It is possible to connect several outputs to an input if all the outputs
come from states of the same state machine. In such cases, we get the
following constraint equations:
It is possible to connect outputs each coming from different states of state machines together -- and connect this with other causal connectors.
These outputs are combined seen as one source of the signal, and give the following constraint equations,
\begin{lstlisting}[language=modelica,escapechar=!]
u!\textsubscript{1}! = u!\textsubscript{2}! = ... = y!\textsubscript{1}! = y!\textsubscript{2}! = ...
\end{lstlisting}
with u\textsubscript{i} inputs and y\textsubscript{i} outputs. The
semantics is defined as follows. Introduce a variable v representing the
signal flow and rewrite the equation above as a set of equations for
u\textsubscript{i} and a set of assignment equations for v:
with \lstinline!y!\textsubscript{i} being outputs from different states of the state-machine and \lstinline!u!\textsubscript{i} being other causal variables.
The semantics is defined similarly to \cref{merging-variable-definitions}:
\begin{lstlisting}[language=modelica,escapechar=!]
v := if activeState(state!\textsubscript{1}!) then y!\textsubscript{1}! else last(v);
v := if activeState(state!\textsubscript{2}!) then y!\textsubscript{2}! else last(v);
...
u!\textsubscript{1}! = v
u!\textsubscript{2}! = v
...
\end{lstlisting}

The merge of the definitions of v is then made according to \cref{merging-variable-definitions}:
Merging Variable Definitions. The result is after
simplification:
\begin{lstlisting}[language=modelica,escapechar=!]
v := if activeState(state!\textsubscript{1}!) then y!\textsubscript{1}! elseif activeState(state!\textsubscript{2}!) then y!\textsubscript{2}! elseif ... else last(v);
v = if activeState(state!\textsubscript{1}!) then
y!\textsubscript{1}!
elseif activeState(state!\textsubscript{2}!) then
y!\textsubscript{2}!
elseif $\ldots$
else
last(v);
u!\textsubscript{1}! = v
u!\textsubscript{2}! = v
...
Expand Down

0 comments on commit 2c687c4

Please sign in to comment.