Skip to content

Commit 4fe8320

Browse files
committed
Complete REGCA
1 parent f43ae38 commit 4fe8320

12 files changed

Lines changed: 961 additions & 786 deletions

File tree

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/Model/PhasorDynamics/Converter/REGCA/CMakeLists.txt

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,52 @@
33
# - Luke Lowery <lukel@tamu.edu>
44
# ]]
55

6-
set(_install_headers
7-
Regca.hpp
8-
RegcaData.hpp)
6+
set(_install_headers Regca.hpp RegcaData.hpp)
97

108
if(GRIDKIT_ENABLE_ENZYME)
11-
gridkit_add_library(phasor_dynamics_converter_regca
12-
SOURCES
13-
RegcaEnzyme.cpp
14-
HEADERS
15-
${_install_headers}
16-
INCLUDE_DIRECTORIES
17-
PRIVATE ${GRIDKIT_THIRD_PARTY_DIR}/magic-enum/include
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
1814
LINK_LIBRARIES
19-
PUBLIC GridKit::phasor_dynamics_core
20-
PUBLIC GridKit::phasor_dynamics_signal
21-
PRIVATE ClangEnzymeFlags
15+
PUBLIC
16+
GridKit::phasor_dynamics_core
17+
PUBLIC
18+
GridKit::phasor_dynamics_signal
19+
PRIVATE
20+
ClangEnzymeFlags
2221
COMPILE_OPTIONS
23-
PRIVATE -mllvm -enzyme-auto-sparsity=1 -fno-math-errno)
22+
PRIVATE
23+
-mllvm
24+
-enzyme-auto-sparsity=1
25+
-fno-math-errno)
2426
else()
25-
gridkit_add_library(phasor_dynamics_converter_regca
26-
SOURCES
27-
Regca.cpp
28-
HEADERS
29-
${_install_headers}
30-
INCLUDE_DIRECTORIES
31-
PRIVATE ${GRIDKIT_THIRD_PARTY_DIR}/magic-enum/include
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
3232
LINK_LIBRARIES
33-
PUBLIC GridKit::phasor_dynamics_core
34-
PUBLIC GridKit::phasor_dynamics_signal)
33+
PUBLIC
34+
GridKit::phasor_dynamics_core
35+
PUBLIC
36+
GridKit::phasor_dynamics_signal)
3537
endif()
3638

37-
gridkit_add_library(phasor_dynamics_converter_regca_dependency_tracking
38-
SOURCES
39-
RegcaDependencyTracking.cpp
40-
INCLUDE_DIRECTORIES
41-
PRIVATE ${GRIDKIT_THIRD_PARTY_DIR}/magic-enum/include
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
4243
LINK_LIBRARIES
43-
PUBLIC GridKit::phasor_dynamics_core
44-
PUBLIC GridKit::phasor_dynamics_signal_dependency_tracking)
44+
PUBLIC
45+
GridKit::phasor_dynamics_core
46+
PUBLIC
47+
GridKit::phasor_dynamics_signal_dependency_tracking)
4548

46-
target_link_libraries(phasor_dynamics_components
49+
target_link_libraries(
50+
phasor_dynamics_components
4751
INTERFACE GridKit::phasor_dynamics_converter_regca)
48-
target_link_libraries(phasor_dynamics_components_dependency_tracking
52+
target_link_libraries(
53+
phasor_dynamics_components_dependency_tracking
4954
INTERFACE GridKit::phasor_dynamics_converter_regca_dependency_tracking)

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

Lines changed: 111 additions & 192 deletions
Large diffs are not rendered by default.

GridKit/Model/PhasorDynamics/Converter/REGCA/Regca.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace GridKit
1212
{
1313
namespace Converter
1414
{
15-
template <class ScalarT, typename IdxT>
16-
int Regca<ScalarT, IdxT>::evaluateJacobian()
15+
template <typename scalar_type, typename index_type>
16+
int Regca<scalar_type, index_type>::evaluateJacobian()
1717
{
1818
Log::misc() << "Evaluate Jacobian for Regca..." << std::endl;
1919
Log::misc() << "Jacobian evaluation is not implemented!" << std::endl;

GridKit/Model/PhasorDynamics/Converter/REGCA/Regca.hpp

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ namespace GridKit
1919
{
2020
namespace PhasorDynamics
2121
{
22-
template <class ScalarT, typename IdxT>
22+
template <typename scalar_type, typename index_type>
2323
class BusBase;
2424

25-
template <class ScalarT, typename IdxT>
25+
template <typename scalar_type, typename index_type>
2626
class SignalNode;
2727
} // namespace PhasorDynamics
2828
} // namespace GridKit
@@ -40,10 +40,10 @@ namespace GridKit
4040
IQ, ///< Reactive-current state
4141
IP, ///< Active-current state
4242
VT, ///< Terminal voltage magnitude
43-
II, ///< Imaginary injected current
43+
II, ///< Imaginary injected current on system base
4444
IQEXTRA, ///< HVRCM extra reactive current
4545
IL, ///< LVPL upper-limit current curve
46-
IR, ///< Real injected current
46+
IR, ///< Real injected current on system base
4747
LP, ///< Active-current lower rate bound
4848
UP, ///< Active-current upper rate bound
4949
PBR, ///< Active-power output on system base
@@ -54,49 +54,52 @@ namespace GridKit
5454
/// External variables of a `Regca`
5555
enum class RegcaExternalVariables : size_t
5656
{
57-
IPCMD, ///< Active-current command signal
58-
IQCMD, ///< Reactive-current command signal
57+
IPCMD, ///< Active-current command signal on system base
58+
IQCMD, ///< Reactive-current command signal on system base
5959
MAXIMUM,
6060
};
6161

62-
template <class ScalarT, typename IdxT>
63-
class Regca : public Component<ScalarT, IdxT>
62+
template <typename scalar_type, typename index_type>
63+
class Regca : public Component<scalar_type, index_type>
6464
{
65-
using Component<ScalarT, IdxT>::gridkit_component_id_;
66-
using Component<ScalarT, IdxT>::alpha_;
67-
using Component<ScalarT, IdxT>::f_;
68-
using Component<ScalarT, IdxT>::h_;
69-
using Component<ScalarT, IdxT>::J_;
70-
using Component<ScalarT, IdxT>::J_cols_buffer_;
71-
using Component<ScalarT, IdxT>::J_rows_buffer_;
72-
using Component<ScalarT, IdxT>::J_vals_buffer_;
73-
using Component<ScalarT, IdxT>::nnz_;
74-
using Component<ScalarT, IdxT>::residual_indices_;
75-
using Component<ScalarT, IdxT>::size_;
76-
using Component<ScalarT, IdxT>::tag_;
77-
using Component<ScalarT, IdxT>::time_;
78-
using Component<ScalarT, IdxT>::va_system_base_;
79-
using Component<ScalarT, IdxT>::variable_indices_;
80-
using Component<ScalarT, IdxT>::wb_;
81-
using Component<ScalarT, IdxT>::y_;
82-
using Component<ScalarT, IdxT>::yp_;
65+
using Component<scalar_type, index_type>::gridkit_component_id_;
66+
using Component<scalar_type, index_type>::alpha_;
67+
using Component<scalar_type, index_type>::abs_tol_;
68+
using Component<scalar_type, index_type>::f_;
69+
using Component<scalar_type, index_type>::h_;
70+
using Component<scalar_type, index_type>::J_cols_buffer_;
71+
using Component<scalar_type, index_type>::J_rows_buffer_;
72+
using Component<scalar_type, index_type>::J_vals_buffer_;
73+
using Component<scalar_type, index_type>::nnz_;
74+
using Component<scalar_type, index_type>::residual_indices_;
75+
using Component<scalar_type, index_type>::size_;
76+
using Component<scalar_type, index_type>::tag_;
77+
using Component<scalar_type, index_type>::time_;
78+
using Component<scalar_type, index_type>::va_system_base_;
79+
using Component<scalar_type, index_type>::variable_indices_;
80+
using Component<scalar_type, index_type>::wb_;
81+
using Component<scalar_type, index_type>::y_;
82+
using Component<scalar_type, index_type>::yp_;
8383

8484
public:
85-
using RealT = typename Component<ScalarT, IdxT>::RealT;
86-
using bus_type = BusBase<ScalarT, IdxT>;
87-
using signal_type = SignalNode<ScalarT, IdxT>;
88-
using model_data_type = RegcaData<RealT, IdxT>;
89-
using MonitorT = Model::VariableMonitor<Regca, RegcaData>;
90-
91-
Regca(bus_type* bus);
92-
Regca(bus_type* bus, const model_data_type& data);
85+
using ScalarT = scalar_type;
86+
using IdxT = index_type;
87+
using RealT = typename Component<ScalarT, IdxT>::RealT;
88+
using BusT = BusBase<ScalarT, IdxT>;
89+
using SignalT = SignalNode<ScalarT, IdxT>;
90+
using ModelDataT = RegcaData<RealT, IdxT>;
91+
using MonitorT = Model::VariableMonitor<Regca, RegcaData>;
92+
93+
Regca(BusT* bus);
94+
Regca(BusT* bus, const ModelDataT& data);
9395
~Regca();
9496

9597
int setGridKitComponentID(IdxT) override final;
9698
int allocate() override final;
9799
int verify() const override final;
98100
int initialize() override final;
99101
int tagDifferentiable() override final;
102+
int setAbsoluteTolerance(RealT rel_tol) override final;
100103
int evaluateResidual() override final;
101104
int evaluateJacobian() override final;
102105

@@ -112,12 +115,12 @@ namespace GridKit
112115
const Model::VariableMonitorBase* getMonitor() const override;
113116

114117
__attribute__((always_inline)) inline int evaluateInternalResidual(
115-
ScalarT*, ScalarT*, ScalarT*, ScalarT*, ScalarT*);
118+
const ScalarT*, const ScalarT*, const ScalarT*, const ScalarT*, ScalarT*);
116119
__attribute__((always_inline)) inline int evaluateBusResidual(
117-
ScalarT*, ScalarT*, ScalarT*, ScalarT*);
120+
const ScalarT*, const ScalarT*, const ScalarT*, ScalarT*);
118121

119122
private:
120-
void initializeParameters(const model_data_type& data);
123+
void initializeParameters(const ModelDataT& data);
121124
void initializeMonitor();
122125
void setDerivedParameters();
123126

@@ -131,8 +134,8 @@ namespace GridKit
131134
return value / toComponentBase(static_cast<ScalarT>(ONE<RealT>));
132135
}
133136

134-
ScalarT activeCurrentLowerRateBound(ScalarT ip) const;
135-
ScalarT activeCurrentUpperRateBound(ScalarT ip, ScalarT il) const;
137+
ScalarT lpTarget(ScalarT ip) const;
138+
ScalarT upTarget(ScalarT ip, ScalarT il) const;
136139

137140
ScalarT& Vr()
138141
{
@@ -154,7 +157,7 @@ namespace GridKit
154157
return bus_->Ii();
155158
}
156159

157-
bus_type* bus_{nullptr};
160+
BusT* bus_{nullptr};
158161

159162
RealT P0_{0};
160163
RealT Q0_{0};

GridKit/Model/PhasorDynamics/Converter/REGCA/RegcaData.hpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,15 @@ namespace GridKit
4949
/// Variables available through the monitor interface.
5050
enum class RegcaMonitorableVariables
5151
{
52-
ir, ///< Real current injection on converter base
53-
ii, ///< Imaginary current injection on converter base
54-
p, ///< Active power injection on system base
55-
q, ///< Reactive power injection on system base
56-
vt, ///< Terminal voltage magnitude
57-
vm, ///< Filtered terminal voltage
58-
ip, ///< Active-current state
59-
iq, ///< Reactive-current state
60-
iqextra, ///< HVRCM extra reactive current
61-
il, ///< LVPL upper-limit current curve
62-
lp, ///< Active-current lower rate bound
63-
up ///< Active-current upper rate bound
52+
ir, ///< Real current injection on system base
53+
ii, ///< Imaginary current injection on system base
54+
p, ///< Active power injection on system base
55+
q ///< Reactive power injection on system base
6456
};
6557

66-
template <typename RealT, typename IdxT>
67-
struct RegcaData : public ComponentData<RealT,
68-
IdxT,
58+
template <typename real_type, typename index_type>
59+
struct RegcaData : public ComponentData<real_type,
60+
index_type,
6961
RegcaParameters,
7062
RegcaPorts,
7163
RegcaMonitorableVariables>

GridKit/Model/PhasorDynamics/Converter/REGCA/RegcaDependencyTracking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace GridKit
1212
{
1313
namespace Converter
1414
{
15-
template <class ScalarT, typename IdxT>
16-
int Regca<ScalarT, IdxT>::evaluateJacobian()
15+
template <typename scalar_type, typename index_type>
16+
int Regca<scalar_type, index_type>::evaluateJacobian()
1717
{
1818
Log::misc() << "Evaluate Jacobian for Regca..." << std::endl;
1919
Log::misc() << "Jacobian evaluation is not implemented!" << std::endl;

0 commit comments

Comments
 (0)