Skip to content

Commit f2b5872

Browse files
committed
Add REGCA Implementation
1 parent 78aec28 commit f2b5872

25 files changed

Lines changed: 2543 additions & 233 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
- Added support for running IDA with fixed time steps
6767
- Added IDA option to suppress algebraic variables in local error tests.
6868
- Removed `COO_Matrix` class.
69+
- Added `REGCA` converter model implementation for PhasorDynamics.
6970

7071
## v0.1
7172

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/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ add_subdirectory(Branch)
3333
add_subdirectory(Bus)
3434
add_subdirectory(BusFault)
3535
add_subdirectory(BusToSignalAdapter)
36+
add_subdirectory(Converter)
3637
add_subdirectory(Exciter)
3738
add_subdirectory(Governor)
3839
add_subdirectory(Load)

GridKit/Model/PhasorDynamics/ComponentLibrary.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <GridKit/Model/PhasorDynamics/Bus/BusInfinite.hpp>
66
#include <GridKit/Model/PhasorDynamics/BusFault/BusFault.hpp>
77
#include <GridKit/Model/PhasorDynamics/BusToSignalAdapter/BusToSignalAdapter.hpp>
8+
#include <GridKit/Model/PhasorDynamics/Converter/REGCA/Regca.hpp>
89
#include <GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1.hpp>
910
#include <GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPti.hpp>
1011
#include <GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1.hpp>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# [[
2+
# Author(s):
3+
# - Luke Lowery <lukel@tamu.edu>
4+
# ]]
5+
6+
add_subdirectory(REGCA)

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} \\
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# [[
2+
# Author(s):
3+
# - Luke Lowery <lukel@tamu.edu>
4+
# ]]
5+
6+
set(_install_headers Regca.hpp RegcaData.hpp)
7+
8+
if(GRIDKIT_ENABLE_ENZYME)
9+
gridkit_add_library(
10+
phasor_dynamics_converter_regca
11+
SOURCES RegcaEnzyme.cpp
12+
HEADERS ${_install_headers}
13+
INCLUDE_DIRECTORIES PRIVATE ${GRIDKIT_THIRD_PARTY_DIR}/magic-enum/include
14+
LINK_LIBRARIES
15+
PUBLIC
16+
GridKit::phasor_dynamics_core
17+
PUBLIC
18+
GridKit::phasor_dynamics_signal
19+
PRIVATE
20+
ClangEnzymeFlags
21+
COMPILE_OPTIONS
22+
PRIVATE
23+
-mllvm
24+
-enzyme-auto-sparsity=1
25+
-fno-math-errno)
26+
else()
27+
gridkit_add_library(
28+
phasor_dynamics_converter_regca
29+
SOURCES Regca.cpp
30+
HEADERS ${_install_headers}
31+
INCLUDE_DIRECTORIES PRIVATE ${GRIDKIT_THIRD_PARTY_DIR}/magic-enum/include
32+
LINK_LIBRARIES
33+
PUBLIC
34+
GridKit::phasor_dynamics_core
35+
PUBLIC
36+
GridKit::phasor_dynamics_signal)
37+
endif()
38+
39+
gridkit_add_library(
40+
phasor_dynamics_converter_regca_dependency_tracking
41+
SOURCES RegcaDependencyTracking.cpp
42+
INCLUDE_DIRECTORIES PRIVATE ${GRIDKIT_THIRD_PARTY_DIR}/magic-enum/include
43+
LINK_LIBRARIES
44+
PUBLIC
45+
GridKit::phasor_dynamics_core
46+
PUBLIC
47+
GridKit::phasor_dynamics_signal_dependency_tracking)
48+
49+
target_link_libraries(
50+
phasor_dynamics_components
51+
INTERFACE GridKit::phasor_dynamics_converter_regca)
52+
target_link_libraries(
53+
phasor_dynamics_components_dependency_tracking
54+
INTERFACE GridKit::phasor_dynamics_converter_regca_dependency_tracking)

0 commit comments

Comments
 (0)