|
| 1 | +/** |
| 2 | + * @file Hygov.hpp |
| 3 | + * @author Luke Lowery (lukel@tamu.edu) |
| 4 | + * @brief Declaration of the HYGOV governor model. |
| 5 | + */ |
| 6 | + |
| 7 | +#pragma once |
| 8 | + |
| 9 | +#include <array> |
| 10 | +#include <cstddef> |
| 11 | +#include <memory> |
| 12 | +#include <vector> |
| 13 | + |
| 14 | +#include <GridKit/Model/PhasorDynamics/Component.hpp> |
| 15 | +#include <GridKit/Model/PhasorDynamics/ComponentSignals.hpp> |
| 16 | +#include <GridKit/Model/PhasorDynamics/Governor/HYGOV/HygovData.hpp> |
| 17 | +#include <GridKit/Model/VariableMonitor.hpp> |
| 18 | + |
| 19 | +namespace GridKit |
| 20 | +{ |
| 21 | + namespace PhasorDynamics |
| 22 | + { |
| 23 | + template <typename scalar_type, typename index_type> |
| 24 | + class SignalNode; |
| 25 | + |
| 26 | + namespace Governor |
| 27 | + { |
| 28 | + /// Internal variables of a `Hygov`. |
| 29 | + enum class HygovInternalVariables : size_t |
| 30 | + { |
| 31 | + XN, ///< Speed lead-lag denominator state |
| 32 | + XF, ///< Governor error filter output |
| 33 | + C, ///< Desired-gate position |
| 34 | + G, ///< Gate position |
| 35 | + Q, ///< Turbine flow |
| 36 | + OMEGADB, ///< Deadbanded speed deviation |
| 37 | + YOMEGA, ///< Lead-lag-conditioned speed signal |
| 38 | + EF, ///< Governor error into the filter |
| 39 | + FC, ///< Desired-gate derivative target |
| 40 | + RC, ///< Rate-limited desired-gate derivative target |
| 41 | + PGV, ///< Nonlinear gate-to-power curve output |
| 42 | + PGVSAFE, ///< Safe gate-to-power value |
| 43 | + H, ///< Turbine head |
| 44 | + PMECH, ///< Mechanical-power output |
| 45 | + MAXIMUM, |
| 46 | + }; |
| 47 | + |
| 48 | + /// External variables of a `Hygov`. |
| 49 | + enum class HygovExternalVariables : size_t |
| 50 | + { |
| 51 | + OMEGA, ///< Machine speed deviation |
| 52 | + PREF, ///< Active-power/load reference |
| 53 | + PAUX, ///< Auxiliary power input |
| 54 | + MAXIMUM, |
| 55 | + }; |
| 56 | + |
| 57 | + template <typename scalar_type, typename index_type> |
| 58 | + class Hygov : public Component<scalar_type, index_type> |
| 59 | + { |
| 60 | + using Component<scalar_type, index_type>::alpha_; |
| 61 | + using Component<scalar_type, index_type>::f_; |
| 62 | + using Component<scalar_type, index_type>::gridkit_component_id_; |
| 63 | + using Component<scalar_type, index_type>::J_; |
| 64 | + using Component<scalar_type, index_type>::J_cols_buffer_; |
| 65 | + using Component<scalar_type, index_type>::J_rows_buffer_; |
| 66 | + using Component<scalar_type, index_type>::J_vals_buffer_; |
| 67 | + using Component<scalar_type, index_type>::residual_indices_; |
| 68 | + using Component<scalar_type, index_type>::size_; |
| 69 | + using Component<scalar_type, index_type>::tag_; |
| 70 | + using Component<scalar_type, index_type>::variable_indices_; |
| 71 | + using Component<scalar_type, index_type>::wb_; |
| 72 | + using Component<scalar_type, index_type>::y_; |
| 73 | + using Component<scalar_type, index_type>::yp_; |
| 74 | + |
| 75 | + public: |
| 76 | + using ScalarT = scalar_type; |
| 77 | + using IdxT = index_type; |
| 78 | + using RealT = typename Component<ScalarT, IdxT>::RealT; |
| 79 | + using SignalT = SignalNode<ScalarT, IdxT>; |
| 80 | + using ModelDataT = HygovData<RealT, IdxT>; |
| 81 | + using MonitorT = Model::VariableMonitor<Hygov, HygovData>; |
| 82 | + |
| 83 | + Hygov(); |
| 84 | + Hygov(const ModelDataT& data); |
| 85 | + ~Hygov(); |
| 86 | + |
| 87 | + int setGridKitComponentID(IdxT) override final; |
| 88 | + int allocate() override final; |
| 89 | + int verify() const override final; |
| 90 | + int initialize() override final; |
| 91 | + int tagDifferentiable() override final; |
| 92 | + int evaluateResidual() override final; |
| 93 | + int evaluateJacobian() override final; |
| 94 | + |
| 95 | + auto getSignals() |
| 96 | + -> ComponentSignals<ScalarT, |
| 97 | + IdxT, |
| 98 | + HygovInternalVariables, |
| 99 | + HygovExternalVariables>& |
| 100 | + { |
| 101 | + return signals_; |
| 102 | + } |
| 103 | + |
| 104 | + const Model::VariableMonitorBase* getMonitor() const override; |
| 105 | + |
| 106 | + __attribute__((always_inline)) inline int evaluateInternalResidual( |
| 107 | + ScalarT*, ScalarT*, ScalarT*, ScalarT*, ScalarT*); |
| 108 | + |
| 109 | + private: |
| 110 | + void initModelParams(const ModelDataT& data); |
| 111 | + void initializeMonitor(); |
| 112 | + |
| 113 | + ScalarT gatePower(ScalarT gate) const; |
| 114 | + RealT invertGatePower(RealT pgv) const; |
| 115 | + ScalarT toComponentBase(ScalarT value) const; |
| 116 | + ScalarT toPmechBase(ScalarT value) const; |
| 117 | + |
| 118 | + RealT Trate_{0}; |
| 119 | + RealT pmech_mva_base_{0}; |
| 120 | + RealT Rperm_{0}; |
| 121 | + RealT Rtemp_{0}; |
| 122 | + RealT Tr_{0}; |
| 123 | + RealT Tf_{0}; |
| 124 | + RealT Tg_{0}; |
| 125 | + RealT Velm_{0}; |
| 126 | + RealT Gmax_{0}; |
| 127 | + RealT Gmin_{0}; |
| 128 | + RealT Tw_{0}; |
| 129 | + RealT At_{0}; |
| 130 | + RealT Dturb_{0}; |
| 131 | + RealT Qnl_{0}; |
| 132 | + RealT Tn_{0}; |
| 133 | + RealT Tnp_{0}; |
| 134 | + RealT leadlag_gain_{0}; |
| 135 | + RealT db1_{0}; |
| 136 | + RealT db2_{0}; |
| 137 | + RealT Hdam_{1}; |
| 138 | + std::array<RealT, 6> Gv_{}; |
| 139 | + std::array<RealT, 6> Pgv_{}; |
| 140 | + |
| 141 | + IdxT parameter_error_count_{0}; |
| 142 | + |
| 143 | + ScalarT pref_set_{0}; |
| 144 | + ScalarT paux_set_{0}; |
| 145 | + |
| 146 | + ComponentSignals<ScalarT, IdxT, HygovInternalVariables, HygovExternalVariables> signals_; |
| 147 | + std::unique_ptr<MonitorT> monitor_; |
| 148 | + |
| 149 | + std::vector<ScalarT> ws_; |
| 150 | + std::vector<IdxT> ws_indices_; |
| 151 | + }; |
| 152 | + } // namespace Governor |
| 153 | + } // namespace PhasorDynamics |
| 154 | +} // namespace GridKit |
0 commit comments