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 variability of functions. #2924

Merged
merged 20 commits into from Nov 10, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
henrikt-ma marked this conversation as resolved.
Show resolved Hide resolved
\begin{nonnormative}
Thus any call of a function that is replaceable will need to be checked after redeclarations.
\end{nonnormative}

henrikt-ma marked this conversation as resolved.
Show resolved Hide resolved
\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;
HansOlsson marked this conversation as resolved.
Show resolved Hide resolved
Modelica.Mechanics.MultiBody.Interface.Frame_a frame_a;
replaceable function gravity = GravityInterface;
constant Real failed[:]=gravity({1,0,0}); // May fail
HansOlsson marked this conversation as resolved.
Show resolved Hide resolved
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);
HansOlsson marked this conversation as resolved.
Show resolved Hide resolved
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