Skip to content

Commit

Permalink
Cleanup related to 'constant'
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikt-ma committed Oct 12, 2020
1 parent 185f85a commit 8de3652
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 75 deletions.
11 changes: 2 additions & 9 deletions chapters/connectors.tex
Expand Up @@ -835,18 +835,11 @@ \subsection{Overconstrained Equation Operators for Connection Graphs}\label{over
end equalityConstraint;
end Record;
\end{lstlisting}
The \lstinline!residue! output of the \lstinline!equalityConstraint! function shall have
known size, say constant n. The function shall express the equality
between the two type instances \lstinline!T1! and \lstinline!T2! or the record instances
\lstinline!R1! and
\lstinline!R2!, respectively, with a non-redundant number $n \ge 0$ of equations. The
residues of these equations are returned in vector \lstinline!residue! of size
$n$. The set of n non-redundant equations stating that \lstinline!R1 = R2! is given by
the equation (\lstinline!0! represents a vector of zeros of appropriate size):
The \lstinline!residue! output of the \lstinline!equalityConstraint! function shall have known size, say constant $n$. The function shall express the equality between the two type instances \lstinline!T1! and \lstinline!T2! or the record instances \lstinline!R1! and \lstinline!R2!, respectively, with a non-redundant number $n \ge 0$ of equations. The residues of these equations are returned in vector \lstinline!residue! of size $n$. The set of $n$ non-redundant equations stating that \lstinline!R1 = R2! is given by the equation (\lstinline!0! represents a vector of zeros of appropriate size):
\begin{lstlisting}[language=modelica]
Record R1, R2;
equation
0 = Record.equalityConstraint(R1,R2);
0 = Record.equalityConstraint(R1, R2);
\end{lstlisting}
\begin{nonnormative}
If the elements of a record \lstinline!Record! are not independent from each other, the equation \lstinline!R1 = R2! contains redundant equations.
Expand Down
49 changes: 12 additions & 37 deletions chapters/inheritance.tex
Expand Up @@ -624,7 +624,7 @@ \section{Redeclaration}\label{redeclaration}
The groups that are valid for both classes and components:
\begin{itemize}
\item
public, protected
\lstinline!public!, \lstinline!protected!
\item
\lstinline!inner!, \lstinline!outer!
\item
Expand All @@ -634,11 +634,11 @@ \section{Redeclaration}\label{redeclaration}
The groups that are only valid for components:
\begin{itemize}
\item
flow, stream
\lstinline!flow!, \lstinline!stream!
\item
discrete, parameter, constant
\lstinline!discrete!, \lstinline!parameter!, \lstinline!constant!
\item
input, output
\lstinline!input!, \lstinline!output!
\item
array dimensions
\end{itemize}
Expand Down Expand Up @@ -787,7 +787,7 @@ \subsection{The class extends Redeclaration Mechanism}\label{the-class-extends-r
\end{lstlisting}

Note, since \lstinline!MostAir! extends from \lstinline!PartialMedium!,
constant \lstinline!nX!=2 in package \lstinline!MoistAir! and the model
constant \lstinline!nX! = 2 in package \lstinline!MoistAir! and the model
\lstinline!BaseProperties! and the function \lstinline!dynamicViscosity! is present
in \lstinline!MoistAir!. By the following definitions, the available
\lstinline!BaseProperties! model is replaced by another implementation which
Expand Down Expand Up @@ -821,31 +821,9 @@ \subsection{The class extends Redeclaration Mechanism}\label{the-class-extends-r
end MoistAir2;
\end{lstlisting}

Here, the usual approach is used to extend (here from \lstinline!PartialMedium!) and
in the modifier perform all redeclarations. In order to perform these
redeclarations, corresponding implementations of all elements of \lstinline!PartialMedium!
have to be given under a different name, such as \lstinline!MoistAir2.MoistAir_BaseProperties!, since the name
\lstinline!BaseProperties!
already exists due to \lstinline!extends PartialMedium!. Then it is possible in
the modifier to redeclare \lstinline!PartialMedium.BaseProperties! to
\lstinline!MoistAir2.MoistAir_BaseProperties!. Besides the drawback that the
namespace is polluted by elements that have different names but the same
implementation (e.g.\ \lstinline!MoistAir2.BaseProperties! is identical to
\lstinline!MoistAir2.MoistAir_BaseProperties!) the whole construction does not work
if arrays are present that depend on constants in \lstinline!PartialMedium! , such as
\lstinline!X[nX]!: The problem is that \lstinline!MoistAir_BaseProperties! extends from
\lstinline!PartialMedium.BaseProperties! where the constant nX does not yet have a value.
This means that the dimension of array X is undefined and model
\lstinline!MoistAir_BaseProperties! is wrong. With this construction, all constant
definitions have to be repeated whenever these constants shall be used,
especially in \lstinline!MoistAir_BaseProperties! and \lstinline!MoistAir_dynamicViscosity!.
For larger models this is not practical and therefore the only
practically useful definition is the complicated construction in the
previous example with \lstinline!redeclare model extends BaseProperties!.

To detect this issue the rule on lookup of composite names (\cref{composite-name-lookup})
ensures that \lstinline!PartialMedium.dynamicViscosity! is incorrect in a
simulation model.
Here, the usual approach is used to extend (here from \lstinline!PartialMedium!) and in the modifier perform all redeclarations. In order to perform these redeclarations, corresponding implementations of all elements of \lstinline!PartialMedium! have to be given under a different name, such as \lstinline!MoistAir2.MoistAir_BaseProperties!, since the name \lstinline!BaseProperties! already exists due to \lstinline!extends PartialMedium!. Then it is possible in the modifier to redeclare \lstinline!PartialMedium.BaseProperties! to \lstinline!MoistAir2.MoistAir_BaseProperties!. Besides the drawback that the namespace is polluted by elements that have different names but the same implementation (e.g.\ \lstinline!MoistAir2.BaseProperties! is identical to \lstinline!MoistAir2.MoistAir_BaseProperties!) the whole construction does not work if arrays are present that depend on constants in \lstinline!PartialMedium!, such as \lstinline!X[nX]!: The problem is that \lstinline!MoistAir_BaseProperties! extends from \lstinline!PartialMedium.BaseProperties! where the constant \lstinline!nX! does not yet have a value. This means that the dimension of array \lstinline!X! is undefined and model \lstinline!MoistAir_BaseProperties! is wrong. With this construction, all constant definitions have to be repeated whenever these constants shall be used, especially in \lstinline!MoistAir_BaseProperties! and \lstinline!MoistAir_dynamicViscosity!. For larger models this is not practical and therefore the only practically useful definition is the complicated construction in the previous example with \lstinline!redeclare model extends BaseProperties!.

To detect this issue the rule on lookup of composite names (\cref{composite-name-lookup}) ensures that \lstinline!PartialMedium.dynamicViscosity! is incorrect in a simulation model.
\end{nonnormative}

\subsection{Constraining Type}\label{constraining-type}
Expand Down Expand Up @@ -1029,16 +1007,13 @@ \subsection{Restrictions on Redeclarations}\label{restrictions-on-redeclarations
Redeclaration with the same type can be used to restrict variability and/or change array dimensions.
\end{nonnormative}
\item
An element declared as constant cannot be redeclared
An element declared as \lstinline!constant! cannot be redeclared.
\item
An element declared as final shall not be modified, and thus not
redeclared
An element declared as \lstinline!final! shall not be modified, and thus not redeclared.
\item
Modelica does not allow a protected element to be redeclared as
public, or a public element to be redeclared as protected.
Modelica does not allow a protected element to be redeclared as public, or a public element to be redeclared as protected.
\item
Array dimensions may be redeclared; provided the sub-typing rules in
\cref{interface-compatibility-or-subtyping} are satisfied.
Array dimensions may be redeclared; provided the sub-typing rules in \cref{interface-compatibility-or-subtyping} are satisfied.
\begin{nonnormative}
This is one example of redeclare of non-replaceable elements.
\end{nonnormative}
Expand Down
35 changes: 10 additions & 25 deletions chapters/operatorsandexpressions.tex
Expand Up @@ -1388,7 +1388,7 @@ \subsection{Constant Expressions}\label{constant-expressions}
\item
\lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!, \lstinline!String!, and \lstinline!enumeration! literals.
\item
Variables declared as constant.
Variables declared as \lstinline!constant!.
\item
Except for the special built-in operators \lstinline!initial!, \lstinline!terminal!, \lstinline!der!,
\lstinline!edge!, \lstinline!change!, \lstinline!sample!, and \lstinline!pre!, a function or operator with constant
Expand All @@ -1402,13 +1402,7 @@ \subsection{Constant Expressions}\label{constant-expressions}
\end{itemize}
\end{itemize}

Components declared as constant shall have an associated declaration
equation with a constant expression, if the constant is directly in the
simulation model, or used in the simulation model. The value of a
constant can be modified after it has been given a value, unless the
constant is declared final or modified with a final modifier. A constant
without an associated declaration equation can be given one by using a
modifier.
Components declared as \lstinline!constant! shall have an associated declaration equation with a constant expression, if the constant is directly in the simulation model, or used in the simulation model. The value of a constant can be modified after it has been given a value, unless the constant is declared \lstinline!final! or modified with a \lstinline!final! modifier. A constant without an associated declaration equation can be given one by using a modifier.

\subsection{Parameter Expressions}\label{parameter-expressions}

Expand All @@ -1417,7 +1411,7 @@ \subsection{Parameter Expressions}\label{parameter-expressions}
\item
Constant expressions.
\item
Variables declared as parameter.
Variables declared as \lstinline!parameter!.
\item
Input variables in functions behave as though they were parameter expressions.
\item
Expand Down Expand Up @@ -1447,31 +1441,22 @@ \subsection{Discrete-Time Expressions}\label{discrete-time-expressions}
\item
Parameter expressions.
\item
Discrete-time variables, i.e., \lstinline!Integer!, \lstinline!Boolean!, \lstinline!String! variables and
\lstinline!enumeration! variables, as well as \lstinline!Real! variables assigned in
\lstinline!when!-clauses
Discrete-time variables, i.e., \lstinline!Integer!, \lstinline!Boolean!, \lstinline!String! variables and \lstinline!enumeration! variables, as well as \lstinline!Real! variables assigned in \lstinline!when!-clauses.
\item
Function calls where all input arguments of the function are
discrete-time expressions.
Function calls where all input arguments of the function are discrete-time expressions.
\item
Expressions where all the subexpressions are discrete-time
expressions.
Expressions where all the subexpressions are discrete-time expressions.
\item
Expressions in the body of a \lstinline!when!-clause, \lstinline!initial equation!, or \lstinline!initial algorithm!.
\item
Unless inside \lstinline!noEvent!: Ordered relations (\lstinline!>!, \lstinline!<!, \lstinline!>=!, \lstinline!<=!) and the event
generating functions \lstinline!ceil!, \lstinline!floor!, \lstinline!div!, and \lstinline!integer!, if at least one
argument is non-discrete time expression and subtype of \lstinline!Real!.
Unless inside \lstinline!noEvent!: Ordered relations (\lstinline!>!, \lstinline!<!, \lstinline!>=!, \lstinline!<=!) and the event generating functions \lstinline!ceil!, \lstinline!floor!, \lstinline!div!, and \lstinline!integer!, if at least one argument is non-discrete time expression and subtype of \lstinline!Real!.
\begin{nonnormative}
These will generate events, see \cref{events-and-synchronization}. Note that \lstinline!rem! and \lstinline!mod! generate events but are not discrete-time
expressions. In other words, relations inside \lstinline!noEvent!, such as \lstinline!noEvent(x>1)!, are not discrete-time expressions.
These will generate events, see \cref{events-and-synchronization}. Note that \lstinline!rem! and \lstinline!mod! generate events but are not discrete-time expressions. In other words, relations inside \lstinline!noEvent!, such as \lstinline!noEvent(x>1)!, are not discrete-time expressions.
\end{nonnormative}
\item
The functions \lstinline!pre!, \lstinline!edge!, and \lstinline!change! result in discrete-time
expressions.
The functions \lstinline!pre!, \lstinline!edge!, and \lstinline!change! result in discrete-time expressions.
\item
Expressions in functions behave as though they were discrete-time
expressions.
Expressions in functions behave as though they were discrete-time expressions.
\end{itemize}

For an equation \lstinline!expr1 = expr2! where neither expression is of base type
Expand Down
5 changes: 1 addition & 4 deletions chapters/scoping.tex
Expand Up @@ -74,10 +74,7 @@ \subsection{Simple Name Lookup}\label{simple-name-lookup}
the body of a for-loop, \cref{for-equations-repetitive-equation-structures} and \cref{for-statement},
or the body of a reduction expression, \cref{reduction-functions-and-operators}.

Reference to variables successfully looked up in an enclosing class is
only allowed for variables declared as constant. The values of modifiers
are thus resolved in the \emph{instance} scope of which the modifier
appears; if the use is in a modifier on a short class definition, see \cref{short-class-definitions}.
Reference to variables successfully looked up in an enclosing class is only allowed for variables declared as \lstinline!constant!. The values of modifiers are thus resolved in the \emph{instance} scope of which the modifier appears; if the use is in a modifier on a short class definition, see \cref{short-class-definitions}.

This lookup in each \emph{instance} scope is performed as follows:
\begin{itemize}
Expand Down

0 comments on commit 8de3652

Please sign in to comment.