Skip to content

Commit f43ae38

Browse files
committed
REGCA Implementation and Tests
1 parent 20b6fd2 commit f43ae38

13 files changed

Lines changed: 1225 additions & 221 deletions

File tree

GridKit/CommonMath.hpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,31 @@ namespace GridKit
162162
}
163163

164164
/**
165-
* @brief Smooth two-sided deadband function
165+
* @brief Smooth Type 1 no-offset two-sided deadband function
166+
*
167+
* Smooth approximation to a deadband that returns zero inside the band and
168+
* passes the input through unchanged outside the band.
169+
*
170+
* @tparam ScalarT - scalar data type
171+
* @tparam RealT - Real data type (see GridKit::ScalarTraits<ScalarT>::RealT)
172+
*
173+
* @param[in] x - Input signal
174+
* @param[in] lower - Lower breakpoint
175+
* @param[in] upper - Upper breakpoint
176+
* @return Smooth no-offset deadbanded value
177+
*/
178+
template <class ScalarT, typename RealT>
179+
__attribute__((always_inline)) inline ScalarT deadband1(
180+
const ScalarT x,
181+
const RealT lower,
182+
const RealT upper)
183+
{
184+
assert(lower <= upper);
185+
return x * (sigmoid(lower - x) + sigmoid(x - upper));
186+
}
187+
188+
/**
189+
* @brief Smooth Type 2 offset two-sided deadband function
166190
*
167191
* Smooth approximation to x - min(max(x, lower), upper), composed from the
168192
* smooth ramp function.
@@ -173,10 +197,10 @@ namespace GridKit
173197
* @param[in] x - Input signal
174198
* @param[in] lower - Lower breakpoint
175199
* @param[in] upper - Upper breakpoint
176-
* @return Smooth deadbanded value
200+
* @return Smooth offset deadbanded value
177201
*/
178202
template <class ScalarT, typename RealT>
179-
__attribute__((always_inline)) inline ScalarT deadband(
203+
__attribute__((always_inline)) inline ScalarT deadband2(
180204
const ScalarT x,
181205
const RealT lower,
182206
const RealT upper)

GridKit/Model/PhasorDynamics/Converter/REECA/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Symbol | Units | Description |
159159
$V_T$ | [p.u.] | Terminal voltage magnitude |
160160
$V_{\mathrm{meas}}^{\mathrm{safe}}$ | [p.u.] | Safe filtered terminal voltage for divider blocks | Lower bounded by 0.01
161161
$s_{\mathrm{dip}}$ | [binary] | Voltage-dip/overvoltage freeze indicator | 1 when outside voltage thresholds
162-
$V_{\mathrm{err}}$ | [p.u.] | Deadbanded voltage error | Defined by CommonMath `deadband`
162+
$V_{\mathrm{err}}$ | [p.u.] | Deadbanded voltage error | Defined by CommonMath `deadband2`
163163
$I_{\mathrm{qv}}$ | [p.u.] | Reactive-current injection candidate | Converter base
164164
$Q_{\mathrm{ref}}$ | [p.u.] | Selected reactive-power reference | From power-factor or external reactive-power command
165165
$e_Q$ | [p.u.] | Reactive-power control error | Limited $Q_{\mathrm{ref}}$ minus $Q_{\mathrm{gen}}$
@@ -260,7 +260,7 @@ The algebraic targets use CommonMath helper notation where applicable:
260260
0 &= -V_T^2 + V_\mathrm r^2 + V_\mathrm i^2 \\
261261
0 &= -V_\mathrm{meas}^\mathrm{safe} + \max(V_\mathrm{meas}, 0.01) \\
262262
0 &= -s_\mathrm{dip} + \text{outside}(V_T, V_\mathrm{dip}, V_\mathrm{up}) \\
263-
0 &= -V_\mathrm{err} + \text{deadband}(V_\mathrm{ref0} - V_\mathrm{meas}, D_\mathrm{bd1}, D_\mathrm{bd2}) \\
263+
0 &= -V_\mathrm{err} + \text{deadband2}(V_\mathrm{ref0} - V_\mathrm{meas}, D_\mathrm{bd1}, D_\mathrm{bd2}) \\
264264
0 &= -I_\mathrm{qv} + \text{clamp}(K_\mathrm{qv} V_\mathrm{err}, I_\mathrm{qinj}^{\min}, I_\mathrm{qinj}^{\max}) \\
265265
0 &= -Q_\mathrm{ref}
266266
+ s_\mathrm{pf} P_\mathrm{meas}\tan(\phi_\mathrm{pf}^\mathrm{ref})
@@ -288,7 +288,7 @@ The algebraic targets use CommonMath helper notation where applicable:
288288

289289
The $V_T$, $I_{\mathrm{q}}^{\mathrm{circ}}$, and $I_{\mathrm{p}}^{\mathrm{circ}}$ variables use nonnegative branches of squared algebraic residuals. This preserves the $s_{PQ}=0$ Q-priority and $s_{PQ}=1$ P-priority current-circle behavior without explicit square roots; a consistent solution should satisfy the nonnegative branch and nonnegative radicands.
290290

291-
CommonMath defines the helper targets and smooth approximations for [min, max, clamp, deadband, and outside](../../../../CommonMath.md#derived-functions).
291+
CommonMath defines the helper targets and smooth approximations for [min, max, clamp, deadband2, and outside](../../../../CommonMath.md#derived-functions).
292292

293293
## Initialization
294294

@@ -322,7 +322,7 @@ Then evaluate the upstream algebraic chain:
322322
\begin{aligned}
323323
V_{\mathrm{meas},0}^{\mathrm{safe}} &= \text{max}(V_{\mathrm{meas},0}, 0.01) \\
324324
s_{\mathrm{dip},0} &= \text{outside}(V_{T,0}, V_{\mathrm{dip}}, V_{\mathrm{up}}) \\
325-
V_{\mathrm{err},0} &= \text{deadband}(V_{\mathrm{ref0}} - V_{\mathrm{meas},0}, D_{\mathrm{bd1}}, D_{\mathrm{bd2}}) \\
325+
V_{\mathrm{err},0} &= \text{deadband2}(V_{\mathrm{ref0}} - V_{\mathrm{meas},0}, D_{\mathrm{bd1}}, D_{\mathrm{bd2}}) \\
326326
I_{\mathrm{qv},0} &= \text{clamp}(K_{\mathrm{qv}} V_{\mathrm{err},0}, I_{\mathrm{qinj}}^{\min}, I_{\mathrm{qinj}}^{\max}) \\
327327
Q_{\mathrm{ref},0} &= s_{\mathrm{pf}} P_{\mathrm{meas},0}\tan(\phi_{\mathrm{pf},0}^{\mathrm{ref}}) + s_{\mathrm{pf}}^{\mathrm{off}} Q_{\mathrm{ext},0} \\
328328
e_{Q,0} &= \text{clamp}(Q_{\mathrm{ref},0}, Q^{\min}, Q^{\max}) - Q_{\mathrm{gen},0} \\

0 commit comments

Comments
 (0)