Harmony
HARMONic stabilitY assessment of PE-penetrated power systems
Loading...
Searching...
No Matches
MMC.h
Go to the documentation of this file.
1#ifndef MMC_H
2#define MMC_H
3
9#include "Converter.h"
10#include "../../Include_control_blocks.h"
11
12// Forward declarations
13class Controller;
14class Filter;
15
21class MMC : public Converter {
22public:
42 MMC(const std::string& symbol, const std::string& location,
43 double omega, double activePower, double reactivePower,
44 double angle, double acVoltage, double Pdc, double dcVoltage,
45 double armInductance, double armResistance, double armCapacitance,
46 int numSubmodules, double reactorInductance, double reactorResistance,
47 double timeDelay);
48
55 MMC(const std::string& symbol, const std::string& location, const std::vector<double>& converter_params);
56
64 MMC(const std::string& symbol, const std::string& location, const std::vector<double>& converter_params, const std::vector<double>& controller_params);
65
74 MMC(const std::string& symbol, const std::string& location, const std::vector<double>& converter_params,
75 const std::vector<double>& controller_params, const std::vector<double>& filter_params);
76
77 // Initialization methods
78 void init_Controller(const std::vector<double>& converter_params);// Method to initialize controllers and Filters in MMC
79 void init_Filter(const std::vector<double>& converter_params);
80 void update_MMC(double Vm, double theta, double Pac, double Qac, double Vdc, double Pdc);
81
82 // Destructor — control blocks are freed by Converter base class
83 ~MMC() override = default;
84
85
86 // Equilibrium point calculation
87 virtual void solveEquilibrium() override;
88 virtual Eigen::MatrixXd computeStateDerivatives(const Eigen::VectorXd& x, const Eigen::VectorXd& u) override;
89 virtual void computeABCD() override;
91 Eigen::MatrixXd computePlantJacobian(
92 double w,
93 double mDd, double mDq, double mDZd, double mDZq,
94 double mSd, double mSq, double mSz) const;
95
98
99 // Y-parameter computation
100 std::vector<std::vector<complex<double>>> compute_y_parameters(double frequency) override;
101
102 // Override to print MMC-specific parameters
103 virtual void printElementValues() override;
104
105 void computePowerFlow(std::map<std::string, double>& data,
106 std::map<std::string, double>& globalParams) const override
107 {
108 for (auto& [key, value] : element_OPF_info)
109 data[key] = value; // Copy OPF info to branch data
110
111 //data["bf"] = 0.0; // conductance of the filter
112 //data["rf"] = 0.0; // Resistance of the filter
113 //data["xf"] = 0.0; // Reactance of the filter
114 data["xc"] = globalParams["omega"] * L_reactor / globalParams["ACZbase"]; // Base voltage for AC
115 data["rc"] = R_reactor / globalParams["ACZbase"]; // Resistance of the phase reactor
116 data["P_g"] = P / 1e6; // Setting of DC p-control value
117 data["Q_g"] = Q / 1e6; // Setting of AC q-control value
118 data["Vtar"] = V_dc / 1e3 / globalParams["DCbaseKV"]; // Seting of DC v-control value
119
120 data["gridac"] = (int)element_location[2] - '0'; // AC grid number
121
122 // DC side type_dc(1 = constant DC power control (i.e. active power), 2 = constant DC voltage control, 3 = DC droop control)
123 if (controls.count("active_power")) {
124 if (!element_OPF_info.count("type_dc"))
125 data["type_dc"] = 1;
126 }
127 else if (controls.count("dc_voltage")) {
128 if (!element_OPF_info.count("type_dc"))
129 data["type_dc"] = 2;
130 }
131 else if (controls.count("droop")) {
132 if (!element_OPF_info.count("type_dc"))
133 data["type_dc"] = 3;
134 }
135
136 // AC side control type_ac (1 = constant AC voltage control, 2 = constant reactive power control)
137 if (controls.count("ac_voltage")) {
138 if (!element_OPF_info.count("type_ac"))
139 data["type_ac"] = 1;
140 }
141 else if (controls.count("reactive_power")) {
142 if (!element_OPF_info.count("type_ac"))
143 data["type_ac"] = 2;
144 }
145
146 if (element_OPF_info.count("type_dc"))
147 data["type_dc"] = element_OPF_info.at("type_dc");
148 if (element_OPF_info.count("type_ac"))
149 data["type_ac"] = element_OPF_info.at("type_ac");
150 }
151
152 // One MMC arm-voltage time step
153 //vector<MatrixXcd> simulateTimeStep(const vector<MatrixXcd>& input, double Ts, int nKeep1, int nKeep2) override;
154
155 // State-space model manipulation - generic MNA stamping
156 void writeMNAmatrix(SymEngine::DenseMatrix&, std::unordered_map<Bus*, int>&, int,
157 std::map<Element*, std::vector<RCP<const Basic>>>&) override;
158
159 std::vector<RCP<const Basic>> getVirtualInputSymbols() const override;
160
161 std::vector<MatrixXcd> simulateInputStep(
162 const std::vector<MatrixXcd>& states, int nKeep) const override;
163
164 int getNumberOfInternalStates() const override { return number_of_states; }
165
166 //add18/5
167 //
168 // // === BEGIN DQsym: expose plant-only state count ===
169 int getNumberOfPlantStates() const override {
170 /*std::cout << "[MMC::getNumberOfPlantStates] returning " << n_plant_states_ << "\n"; */
171 return n_plant_states_; }
172 // === END DQsym: expose plant-only state count ===
173
174 //add18/5[
175
176 // added18/5=== BEGIN DQsym closed-loop control (public interface) ===
177 void stepControllers(double dt,
178 const std::vector<Eigen::MatrixXcd>& states,
179 const Eigen::Vector2d& Vg_dq);
180 // added18/5]=== END DQsym closed-loop control ===
181
182 // added18/5=== BEGIN DQsym closed-loop control (members) ===
183 Eigen::VectorXd x_ctrl_dqsym_; // persistent controller integrator states
184 Eigen::MatrixXcd mD_dqsym_; // current Δ-modulation (set by stepControllers)
185 Eigen::MatrixXcd mS_dqsym_; // current Σ-modulation
186 bool dqsym_initialized_ = false; // first-call init flag
187
188 // Modulation references exposed by computeStateDerivatives (side-channel output).
189 // Written every call; read only by stepControllers.
190 mutable double last_vMDelta_d_ref_ = 0.0;
191 mutable double last_vMDelta_q_ref_ = 0.0;
192 mutable double last_vMSigma_d_ref_ = 0.0;
193 mutable double last_vMSigma_q_ref_ = 0.0;
194 mutable double last_vMSigma_z_ref_ = 0.0;
195 // added18/5=== END DQsym closed-loop control ===
196
197
198
199 map_basic_basic getParameterSubstitutions() const override;
200
201private:
202 double L_arm; // Arm inductance [H]
203 double R_arm; // Arm resistance
204 double C_arm; // Capacitance per submodule [F]
205 int N; // Number of submodules per arm
206
207 // Helper values
208 double L_eq = 0.0, R_eq = 0.0, m_1 = 1.0;
209
210 // State variables
211 int number_of_states = 12;
212 int vdc_index = 0; // Index for DC voltage in state vector
213
214 // add18/5=== BEGIN plant state count (captured at construction, before non-plant states added) ===
215 int n_plant_states_ = 12; // will be overwritten in constructor with actual value
216 // add18/5=== END plant state count ===
217
218 // Open-loop feedforward used when outer controllers (occ/zcc) are absent.
219 bool open_loop_modulation_ = false;
220 double ol_vMDelta_d_ref_ = 0.0;
221 double ol_vMDelta_q_ref_ = 0.0;
222 double ol_vMSigma_z_ref_ = 0.0;
223 Eigen::VectorXd equilibrium_guess_;
224
225 void computeOpenLoopArmRefs(
226 double Id, double Iq, double Vdc, double iSigma_z,
227 double& vMDelta_d, double& vMDelta_q, double& vMSigma_z) const;
228 void initializeDelayStates(
229 Eigen::VectorXd& x0, double Vdc,
230 double vMDelta_d, double vMDelta_q, double vMSigma_z) const;
231 void seedPlantStateGuess(
232 Eigen::VectorXd& x0, double Id, double Iq, double iSigma_z) const;
233
234};
235
236#endif // MMC_H
Base class for power electronic converters with state-space models.
RCP< const Basic > omega
Angular frequency symbol ω.
Definition Symbolic_functions.cpp:10
Abstract controller with per-channel reference values.
Definition Controller.h:17
Abstract power converter with ABCD matrices, controllers, and filters.
Definition Converter.h:17
double R_reactor
Definition Converter.h:129
double Q
Definition Converter.h:119
double L_reactor
Definition Converter.h:128
double theta
Definition Converter.h:125
double P
Definition Converter.h:118
double V_dc
Definition Converter.h:127
std::map< std::string, Controller * > controls
Definition Converter.h:145
Base class for multi-phase network elements with Y-parameters and MNA stamping hooks.
Definition Element.h:29
std::string element_location
Definition Element.h:282
std::map< std::string, double > element_OPF_info
Definition Element.h:286
LTI filter with configurable time constant, damping, and bandwidth.
Definition Filter.h:17
Modular Multilevel Converter with arm dynamics and control loops.
Definition MMC.h:21
double last_vMSigma_z_ref_
Definition MMC.h:194
void stepControllers(double dt, const std::vector< Eigen::MatrixXcd > &states, const Eigen::Vector2d &Vg_dq)
Definition MMC.cpp:1699
Eigen::MatrixXcd mD_dqsym_
Definition MMC.h:184
int getNumberOfInternalStates() const override
Number of internal state variables for dynamic elements.
Definition MMC.h:164
virtual void printElementValues() override
Print MMC element and controller parameter values.
Definition MMC.cpp:1491
Eigen::MatrixXcd mS_dqsym_
Definition MMC.h:185
Eigen::VectorXd x_ctrl_dqsym_
Definition MMC.h:183
double last_vMDelta_q_ref_
Definition MMC.h:191
int getNumberOfPlantStates() const override
Number of plant states exposed for simulation (may differ from internal states).
Definition MMC.h:169
virtual void computeABCD() override
Numerically compute the Jacobian matrices A and B using finite differences.
Definition MMC.cpp:856
virtual Eigen::MatrixXd computeStateDerivatives(const Eigen::VectorXd &x, const Eigen::VectorXd &u) override
Compute the state derivatives for the MMC system.
Definition MMC.cpp:405
void init_Filter(const std::vector< double > &converter_params)
Initialize the filter(s) in MMC using provided parameters.
Definition MMC.cpp:301
void update_MMC(double Vm, double theta, double Pac, double Qac, double Vdc, double Pdc)
Update MMC operating point and controller references.
Definition MMC.cpp:339
double last_vMDelta_d_ref_
Definition MMC.h:190
Eigen::MatrixXd computePlantJacobian(double w, double mDd, double mDq, double mDZd, double mDZq, double mSd, double mSq, double mSz) const
Exact 12×12 plant Jacobian (modulation treated as fixed parameters)
Definition MMC.cpp:912
double last_vMSigma_q_ref_
Definition MMC.h:193
void init_Controller(const std::vector< double > &converter_params)
Initialize the controller(s) in MMC using provided parameters.
Definition MMC.cpp:199
virtual void solveEquilibrium() override
Solve for the steady-state operating point x using Newton-Raphson.
Definition MMC.cpp:1323
std::vector< RCP< const Basic > > getVirtualInputSymbols() const override
Return symbolic names for virtual inputs used in stamping.
Definition MMC.cpp:1527
double last_vMSigma_d_ref_
Definition MMC.h:192
void writeMNAmatrix(SymEngine::DenseMatrix &, std::unordered_map< Bus *, int > &, int, std::map< Element *, std::vector< RCP< const Basic > > > &) override
Stamp this element into the symbolic MNA matrix (override in derived classes).
Definition MMC.cpp:1537
std::vector< std::vector< complex< double > > > compute_y_parameters(double frequency) override
Compute the numerical admittance (Y) parameters for the MMC.
Definition MMC.cpp:1454
std::vector< MatrixXcd > simulateInputStep(const std::vector< MatrixXcd > &states, int nKeep) const override
Simulate a step response given input states (override in dynamic elements).
Definition MMC.cpp:1642
void computeABCD_analytical()
computeABCD variant: exact plant block + numerical controller block
Definition MMC.cpp:1172
void computePowerFlow(std::map< std::string, double > &data, std::map< std::string, double > &globalParams) const override
Compute branch power-flow quantities (override in derived classes).
Definition MMC.h:105
bool dqsym_initialized_
Definition MMC.h:186
~MMC() override=default
map_basic_basic getParameterSubstitutions() const override
Return parameter substitutions for symbolic evaluation.
Definition MMC.cpp:1680