Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
ElectricCalculation.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Thales Lima Oliveira <thales@ufu.br>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifndef ELECTRICCALCULATION_H
19#define ELECTRICCALCULATION_H
20
21#include <complex>
22#include <vector>
23
24#include "../elements/Element.h"
25#include "../elements/powerElement/Bus.h"
26#include "../elements/powerElement/Capacitor.h"
27#include "../elements/powerElement/HarmCurrent.h"
28#include "../elements/powerElement/IndMotor.h"
29#include "../elements/powerElement/Inductor.h"
30#include "../elements/powerElement/Line.h"
31#include "../elements/powerElement/Load.h"
32#include "../elements/powerElement/PowerElement.h"
33#include "../elements/powerElement/SyncGenerator.h"
34#include "../elements/powerElement/SyncMotor.h"
35#include "../elements/powerElement/Transformer.h"
36#include "../elements/powerElement/EMTElement.h"
37
38#include "../utils/PropertiesData.h"
39
49
62
72
86
92 double qMax;
93 double qMin;
95 bool hasMax;
96 bool hasMin;
98 bool fixed = false;
100 double q = 0.0;
104};
105
116{
117public:
122
127
132 virtual void GetElementsFromList(std::vector<Element*> elementList);
133
142 virtual bool GetYBus(std::vector<std::vector<std::complex<double> > >& yBus,
143 double systemPowerBase,
144 YBusSequence sequence = POSITIVE_SEQ,
145 bool includeSyncMachines = false,
146 bool allLoadsAsImpedances = false,
147 bool usePowerFlowVoltagesOnImpedances = false);
148
155 virtual bool InvertMatrix(std::vector<std::vector<std::complex<double> > > matrix,
156 std::vector<std::vector<std::complex<double> > >& inverse);
157
166 virtual void UpdateElementsPowerFlow(std::vector<std::complex<double> > voltage,
167 std::vector<std::complex<double> > power,
168 std::vector<BusType> busType,
169 std::vector<ReactiveLimits> reactiveLimit,
170 double systemPowerBase);
171
179 void ABCtoDQ0(std::complex<double> complexValue, double angle, double& dValue, double& qValue);
180
188 void DQ0toABC(double dValue, double qValue, double angle, std::complex<double>& complexValue);
189
196 std::vector<std::complex<double> > GaussianElimination(std::vector<std::vector<std::complex<double> > > matrix,
197 std::vector<std::complex<double> > array);
198
205 std::vector<double> GaussianElimination(std::vector<std::vector<double> > matrix, std::vector<double> array);
206
212 Machines::SyncMachineModel GetMachineModel(SyncGenerator* generator);
213
220 std::vector<std::complex<double> > ComplexMatrixTimesVector(std::vector<std::vector<std::complex<double> > > matrix,
221 std::vector<std::complex<double> > vector);
222
229 void GetLUDecomposition(std::vector<std::vector<std::complex<double> > > matrix,
230 std::vector<std::vector<std::complex<double> > >& matrixL,
231 std::vector<std::vector<std::complex<double> > >& matrixU);
232
240 std::vector<std::complex<double> > LUEvaluate(std::vector<std::vector<std::complex<double> > > u,
241 std::vector<std::vector<std::complex<double> > > l,
242 std::vector<std::complex<double> > b);
243
250 bool GetParentBus(Element* childElement, Bus*& parentBus);
251
259 bool GetParentBus(Element* childElement, Bus*& parentBus1, Bus*& parentBus2);
260
267 bool CalculateEMTElementsAdmittance(const double& basePower, wxString& errorMsg);
268
277 bool CalculateEMTElementsPower(const double& basePower, wxString& errorMsg, bool updateCurrent = true);
278
287 double CalculateEMTPowerError(const std::vector< std::complex<double> >& voltage, std::vector< std::complex<double> >& power, const double& basePower, wxString& errorMsg);
288
293 const std::vector<PowerElement*> GetPowerElementList() const { return m_powerElementList; }
298 const std::vector<Bus*> GetBusList() const { return m_busList; }
303 const std::vector<Capacitor*> GetCapacitorList() const { return m_capacitorList; }
308 const std::vector<IndMotor*> GetIndMotorList() const { return m_indMotorList; }
313 const std::vector<Inductor*> GetInductorList() const { return m_inductorList; }
318 const std::vector<Line*> GetLineList() const { return m_lineList; }
323 const std::vector<Load*> GetLoadList() const { return m_loadList; }
328 const std::vector<SyncGenerator*> GetSyncGeneratorList() const { return m_syncGeneratorList; }
333 const std::vector<SyncMotor*> GetSyncMotorList() const { return m_syncMotorList; }
338 const std::vector<Transformer*> GetTransformerList() const { return m_transformerList; }
343 const std::vector<HarmCurrent*> GetHarmCurrentList() const { return m_harmCurrentList; }
348 const std::vector<EMTElement*> GetEMTElementList() const { return m_emtElementList; }
349
350protected:
357 void GetNextConnection(const unsigned int& checkBusNumber, const std::vector< std::vector< std::complex<double> > >& yBus, std::vector<bool>& connToSlack);
358
365 void DistributeReactivePower(std::vector<ReactiveMachine>& machines, double qTotal);
366
368 std::vector<PowerElement*> m_powerElementList;
370 std::vector<Bus*> m_busList;
372 std::vector<Capacitor*> m_capacitorList;
374 std::vector<IndMotor*> m_indMotorList;
376 std::vector<Inductor*> m_inductorList;
378 std::vector<Line*> m_lineList;
380 std::vector<Load*> m_loadList;
382 std::vector<SyncGenerator*> m_syncGeneratorList;
384 std::vector<SyncMotor*> m_syncMotorList;
386 std::vector<Transformer*> m_transformerList;
388 std::vector<HarmCurrent*> m_harmCurrentList;
390 std::vector<EMTElement*> m_emtElementList;
391};
392
393#endif // ELECTRICCALCULATION_H
BusType
Types of buses used in power flow analysis.
@ BUS_SLACK
YBusSequence
Sequence type used when building the system admittance matrix.
@ POSITIVE_SEQ
@ NEGATIVE_SEQ
ReactiveLimitsType
Types of reactive power limit conditions for buses.
@ RL_MAX_REACHED
@ RL_MIN_REACHED
@ RL_NONE_REACHED
@ RL_LIMITED
@ RL_UNLIMITED
@ RL_UNLIMITED_SOURCE
Node for power elements. All others power elements are connected through this.
Definition Bus.h:86
Base class for electrical calculations providing general utility methods.
void DistributeReactivePower(std::vector< ReactiveMachine > &machines, double qTotal)
Distribute reactive power among synchronous machines connected to the same bus.
std::vector< std::complex< double > > ComplexMatrixTimesVector(std::vector< std::vector< std::complex< double > > > matrix, std::vector< std::complex< double > > vector)
Multiply a complex matrix by a complex vector.
std::vector< Line * > m_lineList
List of transmission lines in the system.
std::vector< PowerElement * > m_powerElementList
List of power elements in the system.
std::vector< Bus * > m_busList
List of buses in the system.
const std::vector< IndMotor * > GetIndMotorList() const
Get the induction motors of the system (use GetElementsFromList first).
virtual void UpdateElementsPowerFlow(std::vector< std::complex< double > > voltage, std::vector< std::complex< double > > power, std::vector< BusType > busType, std::vector< ReactiveLimits > reactiveLimit, double systemPowerBase)
Update the elements after the power flow calculation.
const std::vector< PowerElement * > GetPowerElementList() const
Get the power elements of the system (use GetElementsFromList first).
std::vector< Load * > m_loadList
List of load elements in the system.
void ABCtoDQ0(std::complex< double > complexValue, double angle, double &dValue, double &qValue)
Convert a complex phasor in ABC representation to DQ components.
std::vector< Capacitor * > m_capacitorList
List of capacitor elements in the system.
bool CalculateEMTElementsAdmittance(const double &basePower, wxString &errorMsg)
Calculate the admittance of EMT elements.
std::vector< std::complex< double > > LUEvaluate(std::vector< std::vector< std::complex< double > > > u, std::vector< std::vector< std::complex< double > > > l, std::vector< std::complex< double > > b)
Solve a linear system using LU decomposition.
const std::vector< Load * > GetLoadList() const
Get the loads of the system (use GetElementsFromList first).
const std::vector< SyncMotor * > GetSyncMotorList() const
Get the synchronous motors of the system (use GetElementsFromList first).
ElectricCalculation()
Constructor.
double CalculateEMTPowerError(const std::vector< std::complex< double > > &voltage, std::vector< std::complex< double > > &power, const double &basePower, wxString &errorMsg)
Calculate the power mismatch error for EMT simulation.
std::vector< IndMotor * > m_indMotorList
List of induction motors in the system.
bool GetParentBus(Element *childElement, Bus *&parentBus)
Get the parent bus of a given shunt element.
std::vector< Transformer * > m_transformerList
List of transformers in the system.
bool CalculateEMTElementsPower(const double &basePower, wxString &errorMsg, bool updateCurrent=true)
Calculate the power of EMT elements.
const std::vector< SyncGenerator * > GetSyncGeneratorList() const
Get the synchronous generators of the system (use GetElementsFromList first).
std::vector< SyncGenerator * > m_syncGeneratorList
List of synchronous generators in the system.
const std::vector< Transformer * > GetTransformerList() const
Get the transformers of the system (use GetElementsFromList first).
std::vector< EMTElement * > m_emtElementList
List of electromagnetic transient (EMT) elements in the system.
std::vector< std::complex< double > > GaussianElimination(std::vector< std::vector< std::complex< double > > > matrix, std::vector< std::complex< double > > array)
Solve a linear system using Gaussian elimination (complex version).
void GetNextConnection(const unsigned int &checkBusNumber, const std::vector< std::vector< std::complex< double > > > &yBus, std::vector< bool > &connToSlack)
Recursively check if a bus is electrically connected to the slack bus.
const std::vector< Capacitor * > GetCapacitorList() const
Get the capacitors of the system (use GetElementsFromList first).
const std::vector< Inductor * > GetInductorList() const
Get the inductors of the system (use GetElementsFromList first).
virtual bool GetYBus(std::vector< std::vector< std::complex< double > > > &yBus, double systemPowerBase, YBusSequence sequence=POSITIVE_SEQ, bool includeSyncMachines=false, bool allLoadsAsImpedances=false, bool usePowerFlowVoltagesOnImpedances=false)
Get the admittance matrix from the list of elements (use GetElementsFromList first).
std::vector< SyncMotor * > m_syncMotorList
List of synchronous motors in the system.
const std::vector< Line * > GetLineList() const
Get the lines of the system (use GetElementsFromList first).
const std::vector< EMTElement * > GetEMTElementList() const
Get the electromagnetic element list of the system (use GetElementsFromList first).
const std::vector< Bus * > GetBusList() const
Get the buses of the system (use GetElementsFromList first).
std::vector< HarmCurrent * > m_harmCurrentList
List of harmonic current sources in the system.
virtual void GetElementsFromList(std::vector< Element * > elementList)
Separate the power elements from a generic list.
std::vector< Inductor * > m_inductorList
List of inductors in the system.
Machines::SyncMachineModel GetMachineModel(SyncGenerator *generator)
Get the synchronous machine model used by the generator based on user-defined parameters.
void GetLUDecomposition(std::vector< std::vector< std::complex< double > > > matrix, std::vector< std::vector< std::complex< double > > > &matrixL, std::vector< std::vector< std::complex< double > > > &matrixU)
Compute the LU decomposition of a matrix.
void DQ0toABC(double dValue, double qValue, double angle, std::complex< double > &complexValue)
Convert DQ components to a complex phasor in ABC representation.
virtual bool InvertMatrix(std::vector< std::vector< std::complex< double > > > matrix, std::vector< std::vector< std::complex< double > > > &inverse)
Invert a matrix.
const std::vector< HarmCurrent * > GetHarmCurrentList() const
Get the harmonic current source of the system (use GetElementsFromList first).
Base class of all elements of the program. This class is responsible for manage graphical and his dat...
Definition Element.h:112
Abstract class for rotary machines power elements.
Definition Machines.h:34
Synchronous generator power element.
Stores reactive power limits and their status for a bus.
ReactiveLimitsType maxLimitType
ReactiveLimitsType minLimitType
ReactiveLimitsType limitReached
Auxiliary structure used to distribute reactive power among machines connected to a bus.