Skip to content

Commit 20b6fd2

Browse files
committed
REGCA skeleton
1 parent 78aec28 commit 20b6fd2

19 files changed

Lines changed: 1073 additions & 1 deletion

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)
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+
Regca.hpp
8+
RegcaData.hpp)
9+
10+
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
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_regca
26+
SOURCES
27+
Regca.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_regca_dependency_tracking
38+
SOURCES
39+
RegcaDependencyTracking.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_regca)
48+
target_link_libraries(phasor_dynamics_components_dependency_tracking
49+
INTERFACE GridKit::phasor_dynamics_converter_regca_dependency_tracking)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @file Regca.cpp
3+
* @author Luke Lowery (lukel@tamu.edu)
4+
* @brief Non-Enzyme instantiation for the REGCA converter model.
5+
*/
6+
7+
#include "RegcaImpl.hpp"
8+
9+
namespace GridKit
10+
{
11+
namespace PhasorDynamics
12+
{
13+
namespace Converter
14+
{
15+
template <class ScalarT, typename IdxT>
16+
int Regca<ScalarT, IdxT>::evaluateJacobian()
17+
{
18+
Log::misc() << "Evaluate Jacobian for Regca..." << std::endl;
19+
Log::misc() << "Jacobian evaluation is not implemented!" << std::endl;
20+
return 0;
21+
}
22+
23+
template class Regca<double, long int>;
24+
template class Regca<double, size_t>;
25+
} // namespace Converter
26+
} // namespace PhasorDynamics
27+
} // namespace GridKit
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/**
2+
* @file Regca.hpp
3+
* @author Luke Lowery (lukel@tamu.edu)
4+
* @brief Declaration of the REGCA phasor-dynamics converter 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/REGCA/RegcaData.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+
} // namespace PhasorDynamics
28+
} // namespace GridKit
29+
30+
namespace GridKit
31+
{
32+
namespace PhasorDynamics
33+
{
34+
namespace Converter
35+
{
36+
/// Internal variables of a `Regca`
37+
enum class RegcaInternalVariables : size_t
38+
{
39+
VM, ///< Filtered terminal voltage
40+
IQ, ///< Reactive-current state
41+
IP, ///< Active-current state
42+
VT, ///< Terminal voltage magnitude
43+
II, ///< Imaginary injected current
44+
IQEXTRA, ///< HVRCM extra reactive current
45+
IL, ///< LVPL upper-limit current curve
46+
IR, ///< Real injected current
47+
LP, ///< Active-current lower rate bound
48+
UP, ///< Active-current upper rate bound
49+
MAXIMUM,
50+
};
51+
52+
/// External variables of a `Regca`
53+
enum class RegcaExternalVariables : size_t
54+
{
55+
IPCMD, ///< Active-current command signal
56+
IQCMD, ///< Reactive-current command signal
57+
MAXIMUM,
58+
};
59+
60+
template <class ScalarT, typename IdxT>
61+
class Regca : public Component<ScalarT, IdxT>
62+
{
63+
using Component<ScalarT, IdxT>::gridkit_component_id_;
64+
using Component<ScalarT, IdxT>::alpha_;
65+
using Component<ScalarT, IdxT>::f_;
66+
using Component<ScalarT, IdxT>::h_;
67+
using Component<ScalarT, IdxT>::J_;
68+
using Component<ScalarT, IdxT>::J_cols_buffer_;
69+
using Component<ScalarT, IdxT>::J_rows_buffer_;
70+
using Component<ScalarT, IdxT>::J_vals_buffer_;
71+
using Component<ScalarT, IdxT>::mva_system_base_;
72+
using Component<ScalarT, IdxT>::nnz_;
73+
using Component<ScalarT, IdxT>::residual_indices_;
74+
using Component<ScalarT, IdxT>::size_;
75+
using Component<ScalarT, IdxT>::tag_;
76+
using Component<ScalarT, IdxT>::time_;
77+
using Component<ScalarT, IdxT>::variable_indices_;
78+
using Component<ScalarT, IdxT>::wb_;
79+
using Component<ScalarT, IdxT>::y_;
80+
using Component<ScalarT, IdxT>::yp_;
81+
82+
public:
83+
using RealT = typename Component<ScalarT, IdxT>::RealT;
84+
using bus_type = BusBase<ScalarT, IdxT>;
85+
using signal_type = SignalNode<ScalarT, IdxT>;
86+
using model_data_type = RegcaData<RealT, IdxT>;
87+
using MonitorT = Model::VariableMonitor<Regca, RegcaData>;
88+
89+
Regca(bus_type* bus);
90+
Regca(bus_type* bus, const model_data_type& data);
91+
~Regca();
92+
93+
int setGridKitComponentID(IdxT) override final;
94+
int allocate() override final;
95+
int verify() const override final;
96+
int initialize() override final;
97+
int tagDifferentiable() override final;
98+
int evaluateResidual() override final;
99+
int evaluateJacobian() override final;
100+
101+
auto getSignals()
102+
-> ComponentSignals<ScalarT,
103+
IdxT,
104+
RegcaInternalVariables,
105+
RegcaExternalVariables>&
106+
{
107+
return signals_;
108+
}
109+
110+
const Model::VariableMonitorBase* getMonitor() const override;
111+
112+
__attribute__((always_inline)) inline int evaluateInternalResidual(
113+
ScalarT*, ScalarT*, ScalarT*, ScalarT*, ScalarT*);
114+
__attribute__((always_inline)) inline int evaluateBusResidual(
115+
ScalarT*, ScalarT*, ScalarT*, ScalarT*);
116+
117+
private:
118+
void initializeParameters(const model_data_type& data);
119+
void initializeMonitor();
120+
121+
ScalarT& Vr()
122+
{
123+
return bus_->Vr();
124+
}
125+
126+
ScalarT& Vi()
127+
{
128+
return bus_->Vi();
129+
}
130+
131+
ScalarT& Ir()
132+
{
133+
return bus_->Ir();
134+
}
135+
136+
ScalarT& Ii()
137+
{
138+
return bus_->Ii();
139+
}
140+
141+
bus_type* bus_{nullptr};
142+
143+
RealT P0_{0};
144+
RealT Q0_{0};
145+
RealT Sconv_{0};
146+
RealT Tg_{0};
147+
RealT TM_{0};
148+
RealT Rqmax_{0};
149+
RealT Rqmin_{0};
150+
RealT Rpmax_{0};
151+
bool sL_{false};
152+
RealT IL1_{0};
153+
RealT VL0_{0};
154+
RealT VL1_{0};
155+
RealT VA0_{0};
156+
RealT VA1_{0};
157+
RealT Vhvmax_{0};
158+
IdxT bus_id_{0};
159+
160+
ComponentSignals<ScalarT, IdxT, RegcaInternalVariables, RegcaExternalVariables> signals_;
161+
std::unique_ptr<MonitorT> monitor_;
162+
163+
std::vector<ScalarT> ws_;
164+
std::vector<IdxT> ws_indices_;
165+
};
166+
} // namespace Converter
167+
} // namespace PhasorDynamics
168+
} // namespace GridKit
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* @file RegcaData.hpp
3+
* @author Luke Lowery (lukel@tamu.edu)
4+
* @brief Modeling data for the REGCA converter 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 REGCA converter model.
18+
enum class RegcaParameters
19+
{
20+
P0, ///< Initial active power injection on system base
21+
Q0, ///< Initial reactive power injection on system base
22+
Sconv, ///< Converter/model power base
23+
Tg, ///< Converter current-control lag time constant
24+
TM, ///< Terminal voltage sensor time constant
25+
Rqmax, ///< Reactive-current recovery positive rate limit
26+
Rqmin, ///< Reactive-current recovery negative rate limit
27+
Rpmax, ///< Active-current magnitude recovery rate limit
28+
sL, ///< LVPL switch
29+
IL1, ///< LVPL upper-current ceiling
30+
VL0, ///< LVPL zero-crossing voltage
31+
VL1, ///< LVPL upper breakpoint voltage
32+
VA0, ///< LVACM lower breakpoint voltage
33+
VA1, ///< LVACM upper breakpoint voltage
34+
Vhvmax ///< Terminal-voltage ceiling for HV reactive management
35+
};
36+
37+
/// Ports for the REGCA converter model.
38+
enum class RegcaPorts
39+
{
40+
bus, ///< Terminal bus ID
41+
ipcmd, ///< Optional active-current command signal ID
42+
iqcmd ///< Optional reactive-current command signal ID
43+
};
44+
45+
/// Variables available through the monitor interface.
46+
enum class RegcaMonitorableVariables
47+
{
48+
ir, ///< Real current injection on converter base
49+
ii, ///< Imaginary current injection on converter base
50+
p, ///< Active power injection on system base
51+
q, ///< Reactive power injection on system base
52+
vt, ///< Terminal voltage magnitude
53+
vm, ///< Filtered terminal voltage
54+
ip, ///< Active-current state
55+
iq, ///< Reactive-current state
56+
iqextra, ///< HVRCM extra reactive current
57+
il, ///< LVPL upper-limit current curve
58+
lp, ///< Active-current lower rate bound
59+
up ///< Active-current upper rate bound
60+
};
61+
62+
template <typename RealT, typename IdxT>
63+
struct RegcaData : public ComponentData<RealT,
64+
IdxT,
65+
RegcaParameters,
66+
RegcaPorts,
67+
RegcaMonitorableVariables>
68+
{
69+
RegcaData() = default;
70+
71+
using Parameters = RegcaParameters;
72+
using Ports = RegcaPorts;
73+
using MonitorableVariables = RegcaMonitorableVariables;
74+
};
75+
} // namespace Converter
76+
} // namespace PhasorDynamics
77+
} // namespace GridKit
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @file RegcaDependencyTracking.cpp
3+
* @author Luke Lowery (lukel@tamu.edu)
4+
* @brief Dependency-tracking instantiations for the REGCA converter model.
5+
*/
6+
7+
#include "RegcaImpl.hpp"
8+
9+
namespace GridKit
10+
{
11+
namespace PhasorDynamics
12+
{
13+
namespace Converter
14+
{
15+
template <class ScalarT, typename IdxT>
16+
int Regca<ScalarT, IdxT>::evaluateJacobian()
17+
{
18+
Log::misc() << "Evaluate Jacobian for Regca..." << std::endl;
19+
Log::misc() << "Jacobian evaluation is not implemented!" << std::endl;
20+
return 0;
21+
}
22+
23+
template class Regca<DependencyTracking::Variable, long int>;
24+
template class Regca<DependencyTracking::Variable, size_t>;
25+
} // namespace Converter
26+
} // namespace PhasorDynamics
27+
} // namespace GridKit

0 commit comments

Comments
 (0)