CommonMath
Smooth, autodiff-friendly approximations of piecewise functions used across
GridKit component models. In model equations, these functions act as smooth
activation functions for saturation, limits, deadbands, and antiwindup behavior. See
CommonMath.hpp for implementation details.
Primitives
Symbol |
Name |
API |
Description |
|---|---|---|---|
\(\sigma\) |
Logistic Function |
|
Smooth approximation to the Heaviside step function |
\(\rho\) |
Ramp |
|
Smooth approximation to the ramp function |
\(q\) |
Quadratic Ramp |
|
Smooth approximation to the quadratic ramp function |
The default scale \(\mu\) of these functions is chosen such that \(\sigma'(0)=f_{\text{sync}}\), where \(f_{\text{sync}}\) is the fundamental frequency of the PhasorDynamics model. As \(\mu\to\infty\), \(\rho\) and \(q\) converge to \(\text{ReLU}\) and \(\text{ReQU}\) everywhere, while \(\sigma\) converges to \(H\) for \(x\ne0\).
Logistic Function
The Heaviside function \(H\) is a unit step, defined as:
We use the logistic function as a smooth approximation to the Heaviside function. This approximation is evaluated using the equivalent hyperbolic-tangent form below to avoid overflow when evaluating the exponential form directly.
Ramp
The rectified linear unit \(\text{ReLU}\) is a one-sided ramp:
We implement the Ramp function as the \(\text{softplus}(x)\), non-negative approximation of \(\text{ReLU}(x)\). We do not use \(x\,\sigma(x)\) because it introduces a negative tail for \(x \lt 0\), while \(\text{softplus}(x)\) stays nonnegative.
Although \(\rho(x)\) is real-analytic, the implemented form is an overflow-safe representation of the function:
Evaluating the absolute value by sign gives the piecewise form:
For the positive branch, rewrite the original definition as
Hence, the implemented form is equivalent to the softplus definition and avoids overflow by evaluating the exponential only at nonpositive arguments.
Quadratic Ramp
The rectified quadratic unit \(\text{ReQU}\) is a one-sided quadratic ramp:
We implement an approximation to \(\text{ReQU}\) using the logistic function.
Derived Functions
Name |
API |
Description |
|---|---|---|
Maximum |
|
Smooth binary maximum |
Minimum |
|
Smooth binary minimum |
Clamp |
|
Bounded saturation |
Type I Deadband |
|
No-offset signed two-sided deadband |
Type II Deadband |
|
Offset signed two-sided deadband |
Slew |
|
Symmetric slew-rate limiter |
Linear Segment |
|
Saturated linear segment contribution |
Above |
|
Above-lower-limit indicator |
Below |
|
Below-upper-limit indicator |
Inside |
|
Interior pulse indicator |
Outside |
|
Outside-band indicator |
Antiwindup |
|
Anti-windup limited derivative |
Maximum
Minimum
Clamp
The limits satisfy \(\ell\le u\).
Type I Deadband
The limits satisfy \(\ell\le u\).
Type II Deadband
The limits satisfy \(\ell\le u\).
Slew
The rate limit satisfies \(r\ge0\).
Linear Segment
The breakpoints satisfy \(a<b\).
Above
Below
Inside
The limits satisfy \(\ell\le u\).
Outside
The limits satisfy \(\ell\le u\).
Antiwindup
The limits satisfy \(\ell\le u\).