Skip to content

Commit

Permalink
Cleanup related to 'Boolean'
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikt-ma committed Oct 13, 2020
1 parent 03b72e8 commit 6f66309
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 148 deletions.
13 changes: 2 additions & 11 deletions chapters/annotations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -902,20 +902,11 @@ \subsection{Variable Graphics and Schematic Animation}\label{variable-graphics-a

\subsection{User input}\label{user-input}

It is possible to interactively modify variables during a simulation.
The variables may either be parameters, discrete-time variables or states.
New numeric values can be given, a mouse click can change a Boolean
variable or a mouse movement can change a Real variable. Input fields
may be associated with a \lstinline!GraphicItem! or a component as an array named
\lstinline!interaction!. The \lstinline!interaction! array may occur as an attribute of a
graphic primitive, an attribute of a component annotation or as an
attribute of the layer annotation of a class.
It is possible to interactively modify variables during a simulation. The variables may either be parameters, discrete-time variables or states. New numeric values can be given, a mouse click can change a \lstinline!Boolean! variable or a mouse movement can change a \lstinline!Real! variable. Input fields may be associated with a \lstinline!GraphicItem! or a component as an array named \lstinline!interaction!. The \lstinline!interaction! array may occur as an attribute of a graphic primitive, an attribute of a component annotation or as an attribute of the layer annotation of a class.

\subsubsection{Mouse input}\label{mouse-input}

A Boolean variable can be changed when the cursor is held over a
graphical item or component and the selection button is pressed if the
interaction annotation contains \lstinline!OnMouseDownSetBoolean!:
A \lstinline!Boolean! variable can be changed when the cursor is held over a graphical item or component and the selection button is pressed if the interaction annotation contains \lstinline!OnMouseDownSetBoolean!:
\begin{lstlisting}[language=modelica]
record OnMouseDownSetBoolean
Boolean variable "Name of variable to change when mouse button pressed";
Expand Down
5 changes: 1 addition & 4 deletions chapters/classes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ \subsection{Component Declaration Static Semantics}\label{component-declaration-
\end{itemize}
in that order.

Array dimensions shall be scalar non-negative parameter expressions of type Integer,
a reference to a type (which must an enumeration type or Boolean, see \cref{enumeration-types}),
or the colon operator denoting that the array dimension is left unspecified (see \cref{array-declarations}).
All variants can also be part of short class definitions.
Array dimensions shall be scalar non-negative parameter expressions of type \lstinline!Integer!, a reference to a type (which must an enumeration type or \lstinline!Boolean!, see \cref{enumeration-types}), or the colon operator denoting that the array dimension is left unspecified (see \cref{array-declarations}). All variants can also be part of short class definitions.

\begin{nonnormative}
Example of variables with array dimensions.
Expand Down
28 changes: 4 additions & 24 deletions chapters/dae.tex
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ \chapter{Modelica DAE Representation}\label{modelica-dae-representation}
time are usually treated in a special way, because this allows
determining the time instant of the next event in advance.
\item
At an event instant, \eqref{eq:hydrid-dae} is a mixed set of algebraic equations which
is solved for the Real, Boolean and Integer unknowns.
At an event instant, \eqref{eq:hydrid-dae} is a mixed set of algebraic equations which is solved for the \lstinline!Real!, \lstinline!Boolean! and \lstinline!Integer! unknowns.
\item
After an event is processed, the integration is restarted with 1.
\end{enumerate}
Expand Down Expand Up @@ -117,28 +116,9 @@ \chapter{Modelica DAE Representation}\label{modelica-dae-representation}
pre(m) := m
end loop
\end{lstlisting}
Solving \eqref{eq:hydrid-dae} for the unknowns is non-trivial, because this set of
equations contains not only Real, but also Boolean and Integer unknowns.
Usually, in a first step these equations are sorted and in many cases
the Boolean and Integer unknowns can be just computed by a forward
evaluation sequence. In some cases, there remain systems of equations
(e.g.\ for ideal diodes, Coulomb friction elements) and specialized
algorithms have to be used to solve them.

Due to the construction of the equations by \emph{flattening} a Modelica
model, the hybrid DAE \eqref{eq:hydrid-dae} contains a huge number of sparse equations.
Therefore, direct simulation of \eqref{eq:hydrid-dae} requires sparse matrix methods.
However, solving this initial set of equations directly with a numerical
method is both unreliable and inefficient. One reason is that many
Modelica models, like the mechanical ones, have a DAE index of 2 or 3,
i.e., the overall number of states of the model is less than the sum of
the states of the sub-components. In such a case, every direct numerical
method has the difficulty that the numerical condition becomes worse, if
the integrator step size is reduced and that a step size of zero leads
to a singularity. Another problem is the handling of idealized elements,
such as ideal diodes or Coulomb friction. These elements lead to mixed
systems of equations having both Real and Boolean unknowns. Specialized
algorithms are needed to solve such systems.
Solving \eqref{eq:hydrid-dae} for the unknowns is non-trivial, because this set of equations contains not only \lstinline!Real!, but also \lstinline!Boolean! and \lstinline!Integer! unknowns. Usually, in a first step these equations are sorted and in many cases the \lstinline!Boolean! and \lstinline!Integer! unknowns can be just computed by a forward evaluation sequence. In some cases, there remain systems of equations (e.g.\ for ideal diodes, Coulomb friction elements) and specialized algorithms have to be used to solve them.

Due to the construction of the equations by \emph{flattening} a Modelica model, the hybrid DAE \eqref{eq:hydrid-dae} contains a huge number of sparse equations. Therefore, direct simulation of \eqref{eq:hydrid-dae} requires sparse matrix methods. However, solving this initial set of equations directly with a numerical method is both unreliable and inefficient. One reason is that many Modelica models, like the mechanical ones, have a DAE index of 2 or 3, i.e., the overall number of states of the model is less than the sum of the states of the sub-components. In such a case, every direct numerical method has the difficulty that the numerical condition becomes worse, if the integrator step size is reduced and that a step size of zero leads to a singularity. Another problem is the handling of idealized elements, such as ideal diodes or Coulomb friction. These elements lead to mixed systems of equations having both \lstinline!Real! and \lstinline!Boolean! unknowns. Specialized algorithms are needed to solve such systems.

To summarize, symbolic transformation techniques are needed to transform
(1) in a set of equations which can be numerically solved reliably. Most
Expand Down
32 changes: 6 additions & 26 deletions chapters/equations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,8 @@ \subsection{For-Equations -- Repetitive Equation Structures}\label{for-equations
\end{lstlisting}

\subsubsection{Explicit Iteration Ranges of For-Equations}\label{explicit-iteration-ranges-of-for-equations}
The \lstinline!expression! of a for-equation shall be a vector expression,
where more general array expressions are treated as vector of vectors or vector of matrices.
It is evaluated once for each for-equation, and is evaluated in the scope
immediately enclosing the for-equation. The expression of a for-equation
shall be a parameter expression. The iteration range of a for-equation
can also be specified as Boolean or as an enumeration type, see
\cref{types-as-iteration-ranges} for more information. The loop-variable (\lstinline!IDENT!) is in scope
inside the loop-construct and shall not be assigned to.
For each element of the evaluated vector expression, in the normal order, the loop-variable
gets the value of that element and that is used to evaluate the body of the for-loop.

The \lstinline!expression! of a for-equation shall be a vector expression, where more general array expressions are treated as vector of vectors or vector of matrices. It is evaluated once for each for-equation, and is evaluated in the scope immediately enclosing the for-equation. The expression of a for-equation shall be a parameter expression. The iteration range of a for-equation can also be specified as \lstinline!Boolean! or as an enumeration type, see \cref{types-as-iteration-ranges} for more information. The loop-variable (\lstinline!IDENT!) is in scope inside the loop-construct and shall not be assigned to. For each element of the evaluated vector expression, in the normal order, the loop-variable gets the value of that element and that is used to evaluate the body of the for-loop.

\begin{example}
\begin{lstlisting}[language=modelica]
Expand All @@ -123,15 +115,13 @@ \subsubsection{Explicit Iteration Ranges of For-Equations}\label{explicit-iterat
// for TwoEnums = enumeration(one,two)
\end{lstlisting}

The loop-variable may hide other variables as in the following
example. Using another name for the loop-variable is, however, strongly
recommended.
The loop-variable may hide other variables as in the following example. Using another name for the loop-variable is, however, strongly recommended.
\begin{lstlisting}[language=modelica]
constant Integer j=4;
constant Integer j = 4;
Real x[j]
equation
for j in 1:j loop // The loop-variable j takes the values 1,2,3,4
x[j]=j; // Uses the loop-variable j
x[j] = j; // Uses the loop-variable j
end for;
\end{lstlisting}
\end{example}
Expand Down Expand Up @@ -175,17 +165,7 @@ \subsection{If-Equations}\label{if-equations}
end if ";"
\end{lstlisting}

The \lstinline!expression! of an if- or elseif-clause must be a scalar Boolean
expression. One if-clause, and zero or more elseif-clauses, and an
optional else-clause together form a list of branches. One or zero of
the bodies of these if-, elseif- and else-clauses is selected, by
evaluating the conditions of the if- and elseif-clauses sequentially
until a condition that evaluates to true is found. If none of the
conditions evaluate to true the body of the else-clause is selected (if
an else-clause exists, otherwise no body is selected). In an equation
section, the equations in the body are seen as equations that must be
satisfied. The bodies that are not selected have no effect on that model
evaluation.
The \lstinline!expression! of an if- or elseif-clause must be a scalar \lstinline!Boolean! expression. One if-clause, and zero or more elseif-clauses, and an optional else-clause together form a list of branches. One or zero of the bodies of these if-, elseif- and else-clauses is selected, by evaluating the conditions of the if- and elseif-clauses sequentially until a condition that evaluates to true is found. If none of the conditions evaluate to true the body of the else-clause is selected (if an else-clause exists, otherwise no body is selected). In an equation section, the equations in the body are seen as equations that must be satisfied. The bodies that are not selected have no effect on that model evaluation.

If-equations in equation sections which do not have exclusively
parameter expressions as switching conditions shall have the same number
Expand Down
4 changes: 1 addition & 3 deletions chapters/functions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1740,9 +1740,7 @@ \subsubsection{Simple Types}\label{simple-types}
facilitate calling of C functions. When returning a non-literal string,
see \cref{utility-functions-for-allocating-strings} for details on memory allocation.

Boolean values are mapped to C such that \lstinline!false! in Modelica is 0 in C and
\lstinline!true! in Modelica is 1 in C. If the returned value from C
is 0 it is treated as \lstinline!false! in Modelica; otherwise as \lstinline!true!.
\lstinline!Boolean! values are mapped to C such that \lstinline!false! in Modelica is 0 in C and \lstinline!true! in Modelica is 1 in C. If the returned value from C is 0 it is treated as \lstinline!false! in Modelica; otherwise as \lstinline!true!.

\begin{nonnormative}
It is recommended that the C function should interpret any non-zero value as true.
Expand Down
8 changes: 1 addition & 7 deletions chapters/glossary.tex
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,7 @@ \chapter{Glossary}\label{glossary}
by a component declaration. Special kinds of components are scalar,
array, and attribute. (See \cref{component-declarations}.)

\glossaryitem{component declaration}: an element of a class definition that
generates a component. A component declaration specifies (1) a component
name, i.e., an identifier, (2) the class to be flattened in order to
generate the component, and (3) an optional Boolean parameter
expression. Generation of the component is suppressed if this parameter
expression evaluates to false. A component declaration may be overridden
by an element-redeclaration. (See \cref{component-declarations}.)
\glossaryitem{component declaration}: an element of a class definition that generates a component. A component declaration specifies (1) a component name, i.e., an identifier, (2) the class to be flattened in order to generate the component, and (3) an optional \lstinline!Boolean! parameter expression. Generation of the component is suppressed if this parameter expression evaluates to false. A component declaration may be overridden by an element-redeclaration. (See \cref{component-declarations}.)

\glossaryitem{component reference}: An expression containing a sequence of
identifiers and indices. A component reference is equivalent to the
Expand Down
4 changes: 1 addition & 3 deletions chapters/inheritance.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1035,10 +1035,8 @@ \subsection{Annotation Choices for Suggested Redeclarations and Modifications}\l
A a(x=3 "PID");
\end{lstlisting}

It can also be applied to Boolean variables to define a check
box.
It can also be applied to \lstinline!Boolean! variables to define a check box.
\begin{lstlisting}[language=modelica]
parameter Boolean useHeatPort=false annotation(choices(checkBox=true));
\end{lstlisting}

\end{example}
2 changes: 1 addition & 1 deletion chapters/operatorsandexpressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ \section{Operator Precedence and Associativity}\label{operator-precedence-and-as
\section{Evaluation Order}\label{evaluation-order}

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,
evaluation of \lstinline!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
Expand Down
5 changes: 2 additions & 3 deletions chapters/revisions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,8 @@ \subsection{Main changes in Modelica 3.4}\label{main-changes-in-modelica-3-4}
Clarified input/output to external functions, \cref{external-function-interface}. Ticket
\href{https://github.com/modelica/ModelicaSpecification/issues/775}{\#775}.
\item
Clarified handling of Boolean variables for external C,
\cref{simple-types}. Ticket
\href{https://github.com/modelica/ModelicaSpecification/issues/1846}{\#1846}.
Clarified handling of \lstinline!Boolean! variables for external C, \cref{simple-types}.
Ticket \href{https://github.com/modelica/ModelicaSpecification/issues/1846}{\#1846}.
\item
Added that strings can be sent to FORTRAN~77, \cref{simple-types}. Ticket
\href{https://github.com/modelica/ModelicaSpecification/issues/1971}{\#1971}.
Expand Down

0 comments on commit 6f66309

Please sign in to comment.