Harmony
HARMONic stabilitY assessment of PE-penetrated power systems
Loading...
Searching...
No Matches
Element.h
Go to the documentation of this file.
1
6#ifndef ELEMENT_H
7#define ELEMENT_H
8
9#include "../Constants.h"
10#include "../Solver/Helper_Functions/Helper_Functions.h"
11
12class Bus; // Forward declaration of Bus class
13
29class Element {
30public:
42 Element(const std::string& symbol, const std::string& location, int inputPins, int outputPins)
43 : element_symbol(symbol), element_location(location), input_pins(inputPins), output_pins(outputPins) {
44 Y_matrix = createZeroMatrix(2*inputPins, 2*outputPins);
45 }
46
50 virtual ~Element();
51
56 int getInputPins() const { return input_pins; }
57
62 int getOutputPins() const { return output_pins; }
63
68 void setInputPins(int pins) { input_pins = pins; }
69
74 void setOutputPins(int pins) { output_pins = pins; }
75
80 void setTransformation(bool flag) { transformation = flag; }
81
86 std::string getElementSymbol() const { return element_symbol; }
87
92 std::vector<Bus*> getBuses();
93
99 int getBusIndex(Bus* bus) {
100 auto it = connections.find(bus);
101 if (it != connections.end()) {
102 return it->second; // Return the index of the bus in the connections map
103 }
104 return -1; // Return -1 if the bus is not found
105 }
106
113
118 const std::map<Bus*, int>& getConnections() const { return connections; }
119
124 std::map<Bus*, int> getConnections() { return connections; }
125
130 string getElementLocation() const { return element_location; }
131
132
138 void attachBus(Bus*, int);
139
143 void printElementInfo() const {
144 std::cout << "Element Symbol: " << element_symbol
145 << ", Input Pins: " << input_pins
146 << ", Output Pins: " << output_pins << std::endl;
147 }
148
152 virtual void printElementValues();
153
160 void writeFile(double start_frequency, double end_frequency, int number_of_points);
161
168 void plotYParameters(double start_frequency, double end_frequency, int number_of_points);
169
173 virtual void plotEigenvalues() {
174 cout << "Eigenvalue plotting is not available for the linear element." << endl;
175 };
176
181 cout << "Participation factors plotting is not available for the linear element." << endl;
182 };
183
193 virtual std::vector<std::vector<complex<double>>> compute_y_parameters(double frequency);
194
199 virtual DenseMatrix get_y_parameters() { return Y_matrix; };
200
207 virtual std::vector<std::vector<complex<double>>> apply_transformation(std::vector<std::vector<complex<double>>>& Y1, std::vector<std::vector<complex<double>>>& Y2);
208
216 virtual void writeMNAmatrix(SymEngine::DenseMatrix&, std::unordered_map<Bus*, int>&, int, std::map<Element*, std::vector<RCP<const Basic>>>&) {};
217
222 virtual int getNumberOfInternalStates() const { return 0; }
223
228 virtual int getNumberOfPlantStates() const {
229 return getNumberOfInternalStates(); // default: full state count
230 }
231
238 virtual std::vector<MatrixXcd> simulateInputStep(
239 const std::vector<MatrixXcd>& states, int nKeep) const {
240 return {};
241 }
242
247 virtual std::vector<RCP<const Basic>> getVirtualInputSymbols() const { return {}; }
248
253 virtual map_basic_basic getParameterSubstitutions() const {return {}; }
254
260 virtual void computePowerFlow(std::map<std::string, double>& branchData,
261 std::map<std::string, double>& globalParams) const {
262 }
263
268 std::map<std::string, double> getOPFInfo() const {
269 return element_OPF_info;
270 }
271
276 void setOPFInfo(std::map<std::string, double>& info) { element_OPF_info = info; }
277
278protected:
279 bool transformation = false; // Flag to indicate if a transformation is applied (e.g. three-phase to dq-frame)
280
281 std::string element_symbol; // Element symbol (e.g., R, L, C)
282 std::string element_location; // Element location (it can be AC1,2,... or DC1,2,... or PEC1,2,...)
283 int input_pins; // Number of input pins/phases
284 int output_pins; // Number of output pins/phases
285 std::map<Bus* , int> connections; // Map of bus connections to the element's terminal
286 std::map<std::string, double> element_OPF_info = {};
287
288 DenseMatrix Y_matrix; // Y-parameter matrix representing the admittance of the element
289};
290
// end of elements group
292
293#endif // ELEMENT_H
DenseMatrix createZeroMatrix(int size1, int size2)
Creates a zero-filled SymEngine dense matrix.
Definition Symbolic_functions.cpp:15
A network node connecting one or more element terminals.
Definition Bus.h:21
Base class for multi-phase network elements with Y-parameters and MNA stamping hooks.
Definition Element.h:29
void setInputPins(int pins)
Set the number of input pins/phases.
Definition Element.h:68
int getBusIndex(Bus *bus)
Find the terminal index associated with a given bus.
Definition Element.h:99
virtual ~Element()
Virtual destructor for derived-class cleanup.
Definition Element.cpp:15
bool transformation
Definition Element.h:279
int getInputPins() const
Get the number of input pins/phases.
Definition Element.h:56
int input_pins
Definition Element.h:283
int getOutputPins() const
Get the number of output pins/phases.
Definition Element.h:62
std::string element_symbol
Definition Element.h:281
std::vector< Bus * > getBuses()
Collect all buses connected to this element.
Definition Element.cpp:30
virtual int getNumberOfInternalStates() const
Number of internal state variables for dynamic elements.
Definition Element.h:222
std::string element_location
Definition Element.h:282
std::map< Bus *, int > connections
Definition Element.h:285
virtual std::vector< std::vector< complex< double > > > compute_y_parameters(double frequency)
Compute complex Y-parameters at a single frequency.
Definition Element.cpp:56
virtual std::vector< std::vector< complex< double > > > apply_transformation(std::vector< std::vector< complex< double > > > &Y1, std::vector< std::vector< complex< double > > > &Y2)
Apply a coordinate or coupling transformation to Y-parameter blocks.
Definition Element.cpp:122
virtual void writeMNAmatrix(SymEngine::DenseMatrix &, std::unordered_map< Bus *, int > &, int, std::map< Element *, std::vector< RCP< const Basic > > > &)
Stamp this element into the symbolic MNA matrix (override in derived classes).
Definition Element.h:216
virtual map_basic_basic getParameterSubstitutions() const
Return parameter substitutions for symbolic evaluation.
Definition Element.h:253
virtual void plotParticipationFactors()
Plot participation factors (override in state-space elements).
Definition Element.h:180
void printElementInfo() const
Print basic element metadata (symbol, input/output pin counts).
Definition Element.h:143
virtual int getNumberOfPlantStates() const
Number of plant states exposed for simulation (may differ from internal states).
Definition Element.h:228
virtual void plotEigenvalues()
Plot eigenvalues of the element model (override in state-space elements).
Definition Element.h:173
virtual DenseMatrix get_y_parameters()
Get the symbolic or stored Y-parameter matrix.
Definition Element.h:199
void writeFile(double start_frequency, double end_frequency, int number_of_points)
Write Y-parameter matrix samples over a frequency sweep to a file.
Definition Element.cpp:198
std::map< std::string, double > element_OPF_info
Definition Element.h:286
void plotYParameters(double start_frequency, double end_frequency, int number_of_points)
Plot Y-parameter matrix entries versus frequency.
Definition Element.cpp:231
virtual void computePowerFlow(std::map< std::string, double > &branchData, std::map< std::string, double > &globalParams) const
Compute branch power-flow quantities (override in derived classes).
Definition Element.h:260
void setTransformation(bool flag)
Enable or disable coordinate transformation for this element.
Definition Element.h:80
DenseMatrix Y_matrix
Definition Element.h:288
int output_pins
Definition Element.h:284
Element(const std::string &symbol, const std::string &location, int inputPins, int outputPins)
Construct an element with symbol, location, and pin counts.
Definition Element.h:42
void attachBus(Bus *, int)
Attach a bus to a specific element terminal.
Definition Element.cpp:22
const std::map< Bus *, int > & getConnections() const
Const access to the bus-to-terminal connection map.
Definition Element.h:118
void setOPFInfo(std::map< std::string, double > &info)
Store OPF-related metadata for this element.
Definition Element.h:276
std::map< Bus *, int > getConnections()
Copy of the bus-to-terminal connection map.
Definition Element.h:124
virtual void printElementValues()
Print extended element-specific values (override in derived classes).
Definition Element.cpp:181
Bus * getOtherBus(Bus *)
Get the bus connected at the opposite terminal from a given bus.
Definition Element.cpp:43
std::map< std::string, double > getOPFInfo() const
Get stored OPF-related metadata for this element.
Definition Element.h:268
std::string getElementSymbol() const
Get the element type symbol.
Definition Element.h:86
string getElementLocation() const
Get the element's grid or partition location label.
Definition Element.h:130
virtual std::vector< RCP< const Basic > > getVirtualInputSymbols() const
Return symbolic names for virtual inputs used in stamping.
Definition Element.h:247
virtual std::vector< MatrixXcd > simulateInputStep(const std::vector< MatrixXcd > &states, int nKeep) const
Simulate a step response given input states (override in dynamic elements).
Definition Element.h:238
void setOutputPins(int pins)
Set the number of output pins/phases.
Definition Element.h:74