Skip to content

Commit 88836c3

Browse files
committed
Add REPCA phasor dynamics model
1 parent 5f509c0 commit 88836c3

20 files changed

Lines changed: 2201 additions & 0 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
- Added multi-contingency analysis application.
6161
- Added `BusToSignalAdapter` component for communicating bus voltages and injection currents.
6262
- Added `REGCA` converter model implementation for PhasorDynamics.
63+
- Added `REPCA` converter model implementation for PhasorDynamics.
6364

6465
## v0.1
6566

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/BusFault/BusFault.hpp>
66
#include <GridKit/Model/PhasorDynamics/BusToSignalAdapter/BusToSignalAdapter.hpp>
77
#include <GridKit/Model/PhasorDynamics/Converter/REGCA/Regca.hpp>
8+
#include <GridKit/Model/PhasorDynamics/Converter/REPCA/Repca.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>

GridKit/Model/PhasorDynamics/Converter/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
# ]]
55

66
add_subdirectory(REGCA)
7+
add_subdirectory(REPCA)

GridKit/Model/PhasorDynamics/Converter/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ The GridKit converter documentation includes:
1212
- Renewable Energy Generator/Converter Model REGCA (See [REGCA](REGCA/README.md))
1313
- Renewable Energy Generator/Converter Model REGCB (See [REGCB](REGCB/README.md))
1414
- Renewable Energy Electrical Control Model REECA (See [REECA](REECA/README.md))
15+
- Renewable Energy Plant Control Model REPCA (See [REPCA](REPCA/README.md))
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# [[
2+
# Author(s):
3+
# - Luke Lowery <lukel@tamu.edu>
4+
# ]]
5+
6+
set(_install_headers
7+
Repca.hpp
8+
RepcaData.hpp)
9+
10+
if(GRIDKIT_ENABLE_ENZYME)
11+
gridkit_add_library(phasor_dynamics_converter_repca
12+
SOURCES
13+
RepcaEnzyme.cpp
14+
HEADERS
15+
${_install_headers}
16+
INCLUDE_DIRECTORIES
17+
PRIVATE ${GRIDKIT_THIRD_PARTY_DIR}/magic-enum/include
18+
LINK_LIBRARIES
19+
PUBLIC GridKit::phasor_dynamics_core
20+
PUBLIC GridKit::phasor_dynamics_signal
21+
PRIVATE ClangEnzymeFlags
22+
COMPILE_OPTIONS
23+
PRIVATE -mllvm -enzyme-auto-sparsity=1 -fno-math-errno)
24+
else()
25+
gridkit_add_library(phasor_dynamics_converter_repca
26+
SOURCES
27+
Repca.cpp
28+
HEADERS
29+
${_install_headers}
30+
INCLUDE_DIRECTORIES
31+
PRIVATE ${GRIDKIT_THIRD_PARTY_DIR}/magic-enum/include
32+
LINK_LIBRARIES
33+
PUBLIC GridKit::phasor_dynamics_core
34+
PUBLIC GridKit::phasor_dynamics_signal)
35+
endif()
36+
37+
gridkit_add_library(phasor_dynamics_converter_repca_dependency_tracking
38+
SOURCES
39+
RepcaDependencyTracking.cpp
40+
INCLUDE_DIRECTORIES
41+
PRIVATE ${GRIDKIT_THIRD_PARTY_DIR}/magic-enum/include
42+
LINK_LIBRARIES
43+
PUBLIC GridKit::phasor_dynamics_core
44+
PUBLIC GridKit::phasor_dynamics_signal_dependency_tracking)
45+
46+
target_link_libraries(phasor_dynamics_components
47+
INTERFACE GridKit::phasor_dynamics_converter_repca)
48+
target_link_libraries(phasor_dynamics_components_dependency_tracking
49+
INTERFACE GridKit::phasor_dynamics_converter_repca_dependency_tracking)

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

Lines changed: 378 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @file Repca.cpp
3+
* @author Luke Lowery (lukel@tamu.edu)
4+
* @brief Non-Enzyme instantiation for the REPCA plant-control model.
5+
*/
6+
7+
#include "RepcaImpl.hpp"
8+
9+
namespace GridKit
10+
{
11+
namespace PhasorDynamics
12+
{
13+
namespace Converter
14+
{
15+
template <class ScalarT, typename IdxT>
16+
int Repca<ScalarT, IdxT>::evaluateJacobian()
17+
{
18+
Log::misc() << "Evaluate Jacobian for Repca..." << std::endl;
19+
Log::misc() << "Jacobian evaluation is not implemented!" << std::endl;
20+
return 0;
21+
}
22+
23+
template class Repca<double, long int>;
24+
template class Repca<double, size_t>;
25+
} // namespace Converter
26+
} // namespace PhasorDynamics
27+
} // namespace GridKit
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
/**
2+
* @file Repca.hpp
3+
* @author Luke Lowery (lukel@tamu.edu)
4+
* @brief Declaration of the REPCA plant-control model.
5+
*/
6+
7+
#pragma once
8+
9+
#include <cstddef>
10+
#include <memory>
11+
#include <vector>
12+
13+
#include <GridKit/Model/PhasorDynamics/Component.hpp>
14+
#include <GridKit/Model/PhasorDynamics/ComponentSignals.hpp>
15+
#include <GridKit/Model/PhasorDynamics/Converter/REPCA/RepcaData.hpp>
16+
#include <GridKit/Model/VariableMonitor.hpp>
17+
18+
namespace GridKit
19+
{
20+
namespace PhasorDynamics
21+
{
22+
template <class ScalarT, typename IdxT>
23+
class BusBase;
24+
25+
template <class ScalarT, typename IdxT>
26+
class SignalNode;
27+
28+
namespace Converter
29+
{
30+
/// Internal variables of a `Repca`.
31+
enum class RepcaInternalVariables : size_t
32+
{
33+
VMEAS, ///< Filtered regulated voltage
34+
QMEAS, ///< Filtered reactive-power signal
35+
XQ, ///< Reactive PI state
36+
XQEXT, ///< Reactive-command lead-lag state
37+
PMEAS, ///< Filtered active-power signal
38+
XP, ///< Active-power PI state
39+
PREF, ///< Active-power command lag state
40+
VREG, ///< Regulated-bus voltage magnitude
41+
VLDC, ///< Line-drop compensated voltage magnitude
42+
VDROOP, ///< Reactive-droop-compensated voltage
43+
VCTRL, ///< Selected voltage-measurement input
44+
SFRZ, ///< Reactive PI voltage-enable indicator
45+
ERQ, ///< Selected reactive-loop error
46+
ERQDB, ///< Deadbanded reactive-loop error
47+
ERQLIM, ///< Limited reactive-loop error
48+
QPI, ///< Reactive PI output
49+
QEXT, ///< Reactive-power command output
50+
EF, ///< Frequency error after deadband
51+
EP, ///< Active-power control error
52+
EPLIM, ///< Limited active-power control error
53+
PPI, ///< Active-power PI output
54+
PEXT, ///< Active-power command output
55+
MAXIMUM,
56+
};
57+
58+
/// External variables of a `Repca`.
59+
enum class RepcaExternalVariables : size_t
60+
{
61+
IBRANCHR, ///< Branch current real component on component base
62+
IBRANCHI, ///< Branch current imaginary component on component base
63+
QBRANCH, ///< Branch reactive-power signal on system base
64+
PBRANCH, ///< Branch active-power signal on system base
65+
VREF, ///< Voltage reference
66+
QREF, ///< Reactive-power reference
67+
PPLANTREF, ///< Plant active-power reference
68+
FREQ, ///< Frequency input
69+
FREQREF, ///< Frequency reference
70+
MAXIMUM,
71+
};
72+
73+
template <class ScalarT, typename IdxT>
74+
class Repca : public Component<ScalarT, IdxT>
75+
{
76+
using Component<ScalarT, IdxT>::alpha_;
77+
using Component<ScalarT, IdxT>::f_;
78+
using Component<ScalarT, IdxT>::gridkit_component_id_;
79+
using Component<ScalarT, IdxT>::J_;
80+
using Component<ScalarT, IdxT>::J_cols_buffer_;
81+
using Component<ScalarT, IdxT>::J_rows_buffer_;
82+
using Component<ScalarT, IdxT>::J_vals_buffer_;
83+
using Component<ScalarT, IdxT>::residual_indices_;
84+
using Component<ScalarT, IdxT>::size_;
85+
using Component<ScalarT, IdxT>::tag_;
86+
using Component<ScalarT, IdxT>::va_system_base_;
87+
using Component<ScalarT, IdxT>::variable_indices_;
88+
using Component<ScalarT, IdxT>::wb_;
89+
using Component<ScalarT, IdxT>::y_;
90+
using Component<ScalarT, IdxT>::yp_;
91+
92+
public:
93+
using RealT = typename Component<ScalarT, IdxT>::RealT;
94+
using bus_type = BusBase<ScalarT, IdxT>;
95+
using signal_type = SignalNode<ScalarT, IdxT>;
96+
using model_data_type = RepcaData<RealT, IdxT>;
97+
using MonitorT = Model::VariableMonitor<Repca, RepcaData>;
98+
99+
Repca(bus_type* bus);
100+
Repca(bus_type* bus, const model_data_type& data);
101+
~Repca();
102+
103+
int setGridKitComponentID(IdxT) override final;
104+
int allocate() override final;
105+
int verify() const override final;
106+
int initialize() override final;
107+
int tagDifferentiable() override final;
108+
int evaluateResidual() override final;
109+
int evaluateJacobian() override final;
110+
111+
auto getSignals()
112+
-> ComponentSignals<ScalarT,
113+
IdxT,
114+
RepcaInternalVariables,
115+
RepcaExternalVariables>&
116+
{
117+
return signals_;
118+
}
119+
120+
const Model::VariableMonitorBase* getMonitor() const override;
121+
122+
__attribute__((always_inline)) inline int evaluateInternalResidual(
123+
ScalarT*, ScalarT*, ScalarT*, ScalarT*, ScalarT*);
124+
125+
private:
126+
void initModelParams(const model_data_type& data);
127+
void initializeMonitor();
128+
129+
int verifyBranchSignalPorts() const;
130+
ScalarT readExternalOrDefault(RepcaExternalVariables variable, ScalarT default_value) const;
131+
void setDerivedParameters();
132+
ScalarT toComponentBase(ScalarT value) const;
133+
134+
ScalarT& Vr();
135+
ScalarT& Vi();
136+
137+
bus_type* bus_{nullptr};
138+
139+
RealT P0_{0};
140+
RealT Q0_{0};
141+
RealT mva_base_{0};
142+
RealT VcompFlag_{0};
143+
RealT RefFlag_{0};
144+
RealT Freqflag_{0};
145+
RealT Tfltr_{0};
146+
RealT Tft_{0};
147+
RealT Tfv_{0};
148+
RealT Tp_{0};
149+
RealT Tlag_{0};
150+
RealT Vfrz_{0};
151+
RealT Rc_{0};
152+
RealT Xc_{0};
153+
RealT Kc_{0};
154+
RealT dbdlow_{0};
155+
RealT dbdupper_{0};
156+
RealT emax_{0};
157+
RealT emin_{0};
158+
RealT Kp_{0};
159+
RealT Ki_{0};
160+
RealT Qmax_{0};
161+
RealT Qmin_{0};
162+
RealT fdbd1_{0};
163+
RealT fdbd2_{0};
164+
RealT Ddn_{0};
165+
RealT Dup_{0};
166+
RealT femax_{0};
167+
RealT femin_{0};
168+
RealT Kpg_{0};
169+
RealT Kig_{0};
170+
RealT Pmax_{0};
171+
RealT Pmin_{0};
172+
173+
IdxT parameter_error_count_{0};
174+
RealT system_to_component_base_{1};
175+
176+
ScalarT vref_set_{0};
177+
ScalarT qref_set_{0};
178+
ScalarT pplantref_set_{0};
179+
ScalarT freq_set_{1};
180+
ScalarT freqref_set_{1};
181+
182+
ComponentSignals<ScalarT, IdxT, RepcaInternalVariables, RepcaExternalVariables> signals_;
183+
std::unique_ptr<MonitorT> monitor_;
184+
185+
std::vector<ScalarT> ws_;
186+
std::vector<IdxT> ws_indices_;
187+
};
188+
} // namespace Converter
189+
} // namespace PhasorDynamics
190+
} // namespace GridKit
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* @file RepcaData.hpp
3+
* @author Luke Lowery (lukel@tamu.edu)
4+
* @brief Modeling data for the REPCA plant-control model.
5+
*/
6+
7+
#pragma once
8+
9+
#include <GridKit/Model/PhasorDynamics/ComponentData.hpp>
10+
11+
namespace GridKit
12+
{
13+
namespace PhasorDynamics
14+
{
15+
namespace Converter
16+
{
17+
/// Parameter keys for the REPCA plant-control model.
18+
enum class RepcaParameters
19+
{
20+
P0, ///< Local active-power branch input used when pbranch/qbranch are omitted
21+
Q0, ///< Local reactive-power branch input used when pbranch/qbranch are omitted
22+
mva, ///< Component MVA base; zero uses system base
23+
VcompFlag, ///< Voltage-compensation mode flag
24+
RefFlag, ///< Reactive-loop reference flag
25+
Freqflag, ///< Active-power output flag
26+
Tfltr, ///< Voltage and reactive-power filter time constant
27+
Tft, ///< Reactive-command lead time constant
28+
Tfv, ///< Reactive-command lag time constant
29+
Tp, ///< Active-power measurement filter time constant
30+
Tlag, ///< Active-power command lag time constant
31+
Vfrz, ///< Reactive PI freeze voltage threshold
32+
Rc, ///< Line-drop compensation resistance
33+
Xc, ///< Line-drop compensation reactance
34+
Kc, ///< Reactive-current compensation gain
35+
dbdlow, ///< Lower reactive-loop deadband threshold
36+
dbdupper, ///< Upper reactive-loop deadband threshold
37+
emax, ///< Maximum reactive-loop error limit
38+
emin, ///< Minimum reactive-loop error limit
39+
Kp, ///< Reactive controller proportional gain
40+
Ki, ///< Reactive controller integral gain
41+
Qmax, ///< Maximum reactive-power command
42+
Qmin, ///< Minimum reactive-power command
43+
fdbd1, ///< Lower frequency-error deadband threshold
44+
fdbd2, ///< Upper frequency-error deadband threshold
45+
Ddn, ///< Down-frequency droop response gain
46+
Dup, ///< Up-frequency droop response gain
47+
femax, ///< Maximum active-power error limit
48+
femin, ///< Minimum active-power error limit
49+
Kpg, ///< Active-power proportional gain
50+
Kig, ///< Active-power integral gain
51+
Pmax, ///< Maximum active-power command
52+
Pmin ///< Minimum active-power command
53+
};
54+
55+
/// Ports for the REPCA plant-control model.
56+
enum class RepcaPorts
57+
{
58+
bus, ///< Regulated bus ID
59+
ibranchr, ///< Branch current real signal ID
60+
ibranchi, ///< Branch current imaginary signal ID
61+
qbranch, ///< Branch reactive-power signal ID
62+
pbranch, ///< Branch active-power signal ID
63+
vref, ///< Optional voltage reference signal ID
64+
qref, ///< Optional reactive-power reference signal ID
65+
pplantref, ///< Optional plant active-power reference signal ID
66+
freq, ///< Frequency input signal ID
67+
freqref, ///< Optional frequency reference signal ID
68+
qext, ///< Reactive-power command output signal ID
69+
pext ///< Active-power command output signal ID
70+
};
71+
72+
/// Variables available through the monitor interface.
73+
enum class RepcaMonitorableVariables
74+
{
75+
qext, ///< Reactive-power command output
76+
pext, ///< Active-power command output
77+
vmeas, ///< Filtered regulated voltage
78+
qmeas, ///< Filtered reactive-power signal
79+
pmeas, ///< Filtered active-power signal
80+
pref, ///< Active-power command lag state
81+
vctrl, ///< Selected voltage-measurement input
82+
sfrz, ///< Reactive PI voltage-enable indicator
83+
qpi, ///< Reactive PI output
84+
pfreq, ///< Frequency droop active-power correction
85+
ppi ///< Active-power PI output
86+
};
87+
88+
template <typename RealT, typename IdxT>
89+
struct RepcaData : public ComponentData<RealT,
90+
IdxT,
91+
RepcaParameters,
92+
RepcaPorts,
93+
RepcaMonitorableVariables>
94+
{
95+
RepcaData() = default;
96+
97+
using Parameters = RepcaParameters;
98+
using Ports = RepcaPorts;
99+
using MonitorableVariables = RepcaMonitorableVariables;
100+
};
101+
} // namespace Converter
102+
} // namespace PhasorDynamics
103+
} // namespace GridKit

0 commit comments

Comments
 (0)