|
| 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 |
0 commit comments