Skip to content

Commit

Permalink
ExplainVariability
Browse files Browse the repository at this point in the history
  • Loading branch information
HansOlsson committed May 7, 2021
1 parent c8b5039 commit 548ef1d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion chapters/interface.tex
Expand Up @@ -540,6 +540,11 @@ \section{Function-Compatibility or Function-Subtyping for Functions}\label{funct
constraining interface of the function being redeclared.
\end{itemize}

Note that function-compatibilty does currently not ensure that the function call has the correct variability, and that must then be checked after re-declaration.
\begin{nonnormative}
Thus any call of a function that is replaceable will need to be checked after redeclarations.
\end{nonnormative}

\begin{example}
Demonstrating a redeclaration using a function-compatible function
\begin{lstlisting}[language=modelica]
Expand All @@ -562,14 +567,16 @@ \section{Function-Compatibility or Function-Subtyping for Functions}\label{funct
end UseDriveLine;
Modelica.Mechanics.MultiBody.Interface.Frame_a frame_a;
replaceable function gravity = GravityInterface;
constant Real failed[:]=gravity({1,0,0}); // May fail
equation
frame_a.f = gravity(frame_a.r0);
// or gravity(position=frame_a.r0);
frame_a.t = zeros(3);
end Body;

model PlanetSimulation
function sunGravity = PointMassGravity (m=2e30);
parameter Modelica.Units.SI.Mass mSun=2e30;
function sunGravity = PointMassGravity (m=mSun);
Body planet1(redeclare function gravity = sunGravity);
Body planet2(redeclare function gravity = PointMassGravity (m=2e30));
$\ldots$
Expand All @@ -580,6 +587,9 @@ \section{Function-Compatibility or Function-Subtyping for Functions}\label{funct
\lstinline!GravityInterface! (no default for \lstinline!m!), but \lstinline!sunGravity!
inside \lstinline!PlanetSimulation! is function-compatible with
\lstinline!GravityInterface!.

The constant failed in \lstinline!planet1!, will violate variability constraints, whereas it will work in \lstinline!planet2!.
The call \lstinline!gravity(frame_a.r0)! will work in both of them.
\end{example}

\section{Type Compatible Expressions}\label{type-compatible-expressions}
Expand Down

0 comments on commit 548ef1d

Please sign in to comment.