/* * Copyright (C) 2017 Thales Lima Oliveira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef ELECTRICCALCULATION_H #define ELECTRICCALCULATION_H #include #include #include "Bus.h" #include "Capacitor.h" #include "Element.h" #include "HarmCurrent.h" #include "IndMotor.h" #include "Inductor.h" #include "Line.h" #include "Load.h" #include "PowerElement.h" #include "SyncGenerator.h" #include "SyncMotor.h" #include "Transformer.h" #include "PropertiesData.h" enum BusType { BUS_SLACK = 0, BUS_PV, BUS_PQ }; enum ReactiveLimitsType { RL_UNLIMITED = 0, // The bus can generate any ammount of reactive power. RL_LIMITED, // The bus reactive power generation is limited. RL_UNLIMITED_SOURCE, // The bus have at least one source of infinite reative power. RL_MAX_REACHED, // Max limit reached RL_MIN_REACHED, // Min limit reached RL_NONE_REACHED // No limits reached }; enum YBusSequence { POSITIVE_SEQ = 0, NEGATIVE_SEQ, ZERO_SEQ }; struct ReactiveLimits { double maxLimit = 0.0; double minLimit = 0.0; ReactiveLimitsType maxLimitType = RL_UNLIMITED; ReactiveLimitsType minLimitType = RL_UNLIMITED; ReactiveLimitsType limitReached = RL_NONE_REACHED; }; /** * @class ElectricCalculation * @author Thales Lima Oliveira * @date 09/01/2017 * @brief Base class of electric calculations, with general methods. * @file ElectricCalculation.h */ class ElectricCalculation { public: /** * @brief Constructor. */ ElectricCalculation(); /** * @brief Destructor. */ ~ElectricCalculation(); /** * @brief Separate the power elements from a generic list. * @param elementList List of generic elements. */ virtual void GetElementsFromList(std::vector elementList); /** * @brief Get the admittance matrix from the list of elements (use GetElementsFromList first). * @param yBus Admittance matrix. The previous content will be erased. * @param systemPowerBase Base power of the system. * @param sequence Sequence of admittance matrix (positive, negative and zero). * @param includeSyncMachines Include the synchronous machines on calculation. * @return Return true if was possible to build the admittance matrix. */ virtual bool GetYBus(std::vector > >& yBus, double systemPowerBase, YBusSequence sequence = POSITIVE_SEQ, bool includeSyncMachines = false, bool allLoadsAsImpedances = false, bool usePowerFlowVoltagesOnImpedances = false); /** * @brief Invert a matrix. * @param matrix Matrix to invert. * @param inverse Inverted matrix. The previous content will be erased. * @return Return true if was possible to invert the matrix. */ virtual bool InvertMatrix(std::vector > > matrix, std::vector > >& inverse); /** * @brief Update the elements after the power flow calculation. * @param voltage Array with the buses voltages. * @param power Array with the buses injected power. * @param busType Array with the buses type. * @param reactiveLimit Array with the reactive limit data. * @param systemPowerBase Base power of the system. */ virtual void UpdateElementsPowerFlow(std::vector > voltage, std::vector > power, std::vector busType, std::vector reactiveLimit, double systemPowerBase); void ABCtoDQ0(std::complex complexValue, double angle, double& dValue, double& qValue); void DQ0toABC(double dValue, double qValue, double angle, std::complex& complexValue); std::vector > GaussianElimination(std::vector > > matrix, std::vector > array); std::vector GaussianElimination(std::vector > matrix, std::vector array); Machines::SyncMachineModel GetMachineModel(SyncGenerator* generator); std::vector > ComplexMatrixTimesVector(std::vector > > matrix, std::vector > vector); void GetLUDecomposition(std::vector > > matrix, std::vector > >& matrixL, std::vector > >& matrixU); std::vector > LUEvaluate(std::vector > > u, std::vector > > l, std::vector > b); /** * @brief Get the power elements of the system (use GetElementsFromList first). * @return A list of power elements. */ const std::vector GetPowerElementList() const { return m_powerElementList; } /** * @brief Get the buses of the system (use GetElementsFromList first). * @return A list of bus elements. */ const std::vector GetBusList() const { return m_busList; } /** * @brief Get the capacitors of the system (use GetElementsFromList first). * @return A list of capacitor elements. */ const std::vector GetCapacitorList() const { return m_capacitorList; } /** * @brief Get the induction motors of the system (use GetElementsFromList first). * @return A list of induction motor elements. */ const std::vector GetIndMotorList() const { return m_indMotorList; } /** * @brief Get the inductors of the system (use GetElementsFromList first). * @return A list of inductor elements. */ const std::vector GetInductorList() const { return m_inductorList; } /** * @brief Get the lines of the system (use GetElementsFromList first). * @return A list of line elements. */ const std::vector GetLineList() const { return m_lineList; } /** * @brief Get the loads of the system (use GetElementsFromList first). * @return A list of load elements. */ const std::vector GetLoadList() const { return m_loadList; } /** * @brief Get the synchronous generators of the system (use GetElementsFromList first). * @return A list of synchronous generator elements. */ const std::vector GetSyncGeneratorList() const { return m_syncGeneratorList; } /** * @brief Get the synchronous motors of the system (use GetElementsFromList first). * @return A list of synchronous motor elements. */ const std::vector GetSyncMotorList() const { return m_syncMotorList; } /** * @brief Get the transformers of the system (use GetElementsFromList first). * @return A list of transformer elements. */ const std::vector GetTransformerList() const { return m_transformerList; } /** * @brief Get the harmonic current source of the system (use GetElementsFromList first). * @return A list of harmonic current sources elements. */ const std::vector GetHarmCurrentList() const { return m_harmCurrentList; } protected: std::vector m_powerElementList; std::vector m_busList; std::vector m_capacitorList; std::vector m_indMotorList; std::vector m_inductorList; std::vector m_lineList; std::vector m_loadList; std::vector m_syncGeneratorList; std::vector m_syncMotorList; std::vector m_transformerList; std::vector m_harmCurrentList; }; #endif // ELECTRICCALCULATION_H