From 20cc44d4cf4da43a6686a40da85fda42cd6fed79 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 27 Aug 2025 08:48:51 +0200 Subject: [PATCH 1/3] Constrain use of 'delay' with zero delay time --- chapters/operatorsandexpressions.tex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index 3be828310..2af544b9b 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -824,9 +824,9 @@ \subsection{Derivative and Special Purpose Operators with Function Syntax}\label \begin{semantics} Evaluates to \lstinline!$\mathit{expr}$(time - $\mathit{delayTime}$)! for $\text{\lstinline!time!} > \text{\lstinline!time.start!} + \mathit{delayTime}$ and \lstinline!$\mathit{expr}$(time.start)! for $\text{\lstinline!time!} \leq \text{\lstinline!time.start!} + \mathit{delayTime}$. The arguments, i.e., $\mathit{expr}$, $\mathit{delayTime}$ and $\mathit{delayMax}$, need to be subtypes of \lstinline!Real!. -$\mathit{delayMax}$ needs to be additionally a parameter expression. -The following relation shall hold: $0 \leq \mathit{delayTime} \leq \mathit{delayMax}$, otherwise an error occurs. -If $\mathit{delayMax}$ is not supplied in the argument list, $\mathit{delayTime}$ needs to be a parameter expression. +$\mathit{delayMax}$ shall be a parameter expression. +If $\mathit{delayMax}$ is not supplied in the argument list, $\mathit{delayTime}$ is required to be evaluable. +It is required that $0 \leq \mathit{delayTime} \leq \mathit{delayMax}$, with $0 = \mathit{delayTime}$ only being allowed when $\mathit{delayMax}$ is not provided (that is, when $\mathit{delayTime}$ is required to be evaluable). The operator is not allowed inside \lstinline!function! classes. For non-scalar arguments the function is vectorized according to \cref{vectorized-calls-of-functions}. For further details, see \cref{delay}. @@ -943,9 +943,9 @@ \subsubsection{delay}\label{delay} For real-time simulation where fixed step size integrators are used, this information is sufficient to allocate the necessary storage for the internal buffer before the simulation starts. For variable step size integrators, the buffer size is dynamic during integration. -In principle, \lstinline!delay! could break algebraic loops. -For simplicity, this is not supported because the minimum delay time has to be given as additional argument to be fixed at compile time. -Furthermore, the maximum step size of the integrator is limited by this minimum delay time in order to avoid extrapolation in the delay buffer. +In order to avoid extrapolation in the delay buffer, the maximum step size of the integrator is limited by the delay time, making delay times close to zero a potential source of poor simulation performance. + +In the form where $\mathit{delayTime}$ is required to be evaluable, a tool can decide to evaluate $\mathit{delayTime}$ only when the value would be zero, and introduce a runtime check that it remains non-zero otherwise. \end{nonnormative} \subsubsection{spatialDistribution}\label{spatialdistribution} From 62d9ab58c0e59e35dfa921df2cb00dcde8a9cb02 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Fri, 5 Sep 2025 15:05:56 +0200 Subject: [PATCH 2/3] Allow zero delayTime whenever it is evaluable and would be zero According to Hans' suggestion. --- chapters/operatorsandexpressions.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index 2af544b9b..7963b96e4 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -825,8 +825,8 @@ \subsection{Derivative and Special Purpose Operators with Function Syntax}\label Evaluates to \lstinline!$\mathit{expr}$(time - $\mathit{delayTime}$)! for $\text{\lstinline!time!} > \text{\lstinline!time.start!} + \mathit{delayTime}$ and \lstinline!$\mathit{expr}$(time.start)! for $\text{\lstinline!time!} \leq \text{\lstinline!time.start!} + \mathit{delayTime}$. The arguments, i.e., $\mathit{expr}$, $\mathit{delayTime}$ and $\mathit{delayMax}$, need to be subtypes of \lstinline!Real!. $\mathit{delayMax}$ shall be a parameter expression. -If $\mathit{delayMax}$ is not supplied in the argument list, $\mathit{delayTime}$ is required to be evaluable. -It is required that $0 \leq \mathit{delayTime} \leq \mathit{delayMax}$, with $0 = \mathit{delayTime}$ only being allowed when $\mathit{delayMax}$ is not provided (that is, when $\mathit{delayTime}$ is required to be evaluable). +If $\mathit{delayMax}$ is not supplied in the argument list, $\mathit{delayTime}$ is required to be a parameter expression. +It is required that $0 \leq \mathit{delayTime} \leq \mathit{delayMax}$, with $0 = \mathit{delayTime}$ only being allowed if $\mathit{delayTime}$ is evaluable and would evaluate to $0$. The operator is not allowed inside \lstinline!function! classes. For non-scalar arguments the function is vectorized according to \cref{vectorized-calls-of-functions}. For further details, see \cref{delay}. From 4ceff1c2dc98c743505749686ad3a9d3b1a446b0 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Fri, 5 Sep 2025 14:58:15 +0200 Subject: [PATCH 3/3] Describe delayTime evaluation as quality of implementation --- chapters/operatorsandexpressions.tex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index 7963b96e4..02edb6033 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -945,7 +945,8 @@ \subsubsection{delay}\label{delay} In order to avoid extrapolation in the delay buffer, the maximum step size of the integrator is limited by the delay time, making delay times close to zero a potential source of poor simulation performance. -In the form where $\mathit{delayTime}$ is required to be evaluable, a tool can decide to evaluate $\mathit{delayTime}$ only when the value would be zero, and introduce a runtime check that it remains non-zero otherwise. +It is a quality of implementation to avoid evaluating $\mathit{delayTime}$ when possible. +A pragmatic approach is to only evaluate $\mathit{delayTime}$ in case the value would be zero, and to check at runtime that it is positive in case it was not evaluated. \end{nonnormative} \subsubsection{spatialDistribution}\label{spatialdistribution}