summaryrefslogtreecommitdiffstats
path: root/Project/PowerFlow.cpp
diff options
context:
space:
mode:
authorThales1330 <thaleslima.ufu@gmail.com>2017-01-09 20:19:58 -0200
committerThales1330 <thaleslima.ufu@gmail.com>2017-01-09 20:19:58 -0200
commit7928eca406f5000aabf202fd393908b097f27449 (patch)
tree86e61fea010a0df2b9e3a6ea1cf33d02287354b8 /Project/PowerFlow.cpp
parent4924742ad16a2818589924e95f570249e31fb5c2 (diff)
downloadPSP.git-7928eca406f5000aabf202fd393908b097f27449.tar.gz
PSP.git-7928eca406f5000aabf202fd393908b097f27449.tar.xz
PSP.git-7928eca406f5000aabf202fd393908b097f27449.zip
Fault calculation implemented
Diffstat (limited to 'Project/PowerFlow.cpp')
-rw-r--r--Project/PowerFlow.cpp55
1 files changed, 34 insertions, 21 deletions
diff --git a/Project/PowerFlow.cpp b/Project/PowerFlow.cpp
index c94d8d8..bfee2af 100644
--- a/Project/PowerFlow.cpp
+++ b/Project/PowerFlow.cpp
@@ -1,12 +1,23 @@
#include "PowerFlow.h"
-PowerFlow::PowerFlow(std::vector<Element*> elementList) : ElectricCalculation() { GetElementsFromList(elementList); }
+PowerFlow::PowerFlow()
+ : ElectricCalculation()
+{
+}
+
+PowerFlow::PowerFlow(std::vector<Element*> elementList)
+ : ElectricCalculation()
+{
+ GetElementsFromList(elementList);
+}
+
PowerFlow::~PowerFlow() {}
+
bool PowerFlow::RunGaussSeidel(double systemPowerBase,
- int maxIteration,
- double error,
- double initAngle,
- double accFactor)
+ int maxIteration,
+ double error,
+ double initAngle,
+ double accFactor)
{
// Calculate the Ybus.
if(!GetYBus(m_yBus, systemPowerBase)) {
@@ -15,13 +26,13 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase,
}
// Number of buses on the system.
- int numberOfBuses = (int)m_busList.size();
+ int numberOfBuses = static_cast<int>(m_busList.size());
- std::vector<BusType> busType; // Bus type
- std::vector<std::complex<double> > voltage; // Voltage of buses
- std::vector<std::complex<double> > power; // Injected power
- std::vector<std::complex<double> > loadPower; // Only the load power
- std::vector<ReactiveLimits> reactiveLimit; // Limit of reactive power on PV buses
+ std::vector<BusType> busType; // Bus type
+ std::vector<std::complex<double> > voltage; // Voltage of buses
+ std::vector<std::complex<double> > power; // Injected power
+ std::vector<std::complex<double> > loadPower; // Only the load power
+ std::vector<ReactiveLimits> reactiveLimit; // Limit of reactive power on PV buses
reactiveLimit.resize(numberOfBuses);
@@ -61,7 +72,7 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase,
}
// Fill the power array
- power.push_back(std::complex<double>(0.0, 0.0)); // Initial value
+ power.push_back(std::complex<double>(0.0, 0.0)); // Initial value
loadPower.push_back(std::complex<double>(0.0, 0.0));
// Synchronous generator
@@ -168,12 +179,12 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase,
}
// Gauss-Seidel method
- std::vector<std::complex<double> > oldVoltage; // Old voltage array.
+ std::vector<std::complex<double> > oldVoltage; // Old voltage array.
oldVoltage.resize(voltage.size());
auto oldBusType = busType;
- int iteration = 0; // Current itaration number.
+ int iteration = 0; // Current itaration number.
while(true) {
// Reach the max number of iterations.
@@ -203,7 +214,7 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase,
// Apply the acceleration factor.
newVolt = std::complex<double>(accFactor * (newVolt.real() - voltage[i].real()) + voltage[i].real(),
- accFactor * (newVolt.imag() - voltage[i].imag()) + voltage[i].imag());
+ accFactor * (newVolt.imag() - voltage[i].imag()) + voltage[i].imag());
voltage[i] = newVolt;
}
@@ -227,15 +238,15 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase,
// Apply the acceleration factor.
newVolt = std::complex<double>(accFactor * (newVolt.real() - voltage[i].real()) + voltage[i].real(),
- accFactor * (newVolt.imag() - voltage[i].imag()) + voltage[i].imag());
+ accFactor * (newVolt.imag() - voltage[i].imag()) + voltage[i].imag());
// Keep the same voltage magnitude.
voltage[i] = std::complex<double>(std::abs(voltage[i]) * std::cos(std::arg(newVolt)),
- std::abs(voltage[i]) * std::sin(std::arg(newVolt)));
+ std::abs(voltage[i]) * std::sin(std::arg(newVolt)));
}
- double busError = std::max(std::abs(voltage[i].real() - oldVoltage[i].real()),
- std::abs(voltage[i].imag() - oldVoltage[i].imag()));
+ double busError = std::max(
+ std::abs(voltage[i].real() - oldVoltage[i].real()), std::abs(voltage[i].imag() - oldVoltage[i].imag()));
if(busError > iterationError) iterationError = busError;
}
@@ -246,7 +257,8 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase,
if(busType[i] == BUS_PV) {
if(reactiveLimit[i].maxLimitType == RL_LIMITED) {
if(power[i].imag() - loadPower[i].imag() > reactiveLimit[i].maxLimit) {
- power[i] = std::complex<double>(power[i].real(), reactiveLimit[i].maxLimit + loadPower[i].imag());
+ power[i] =
+ std::complex<double>(power[i].real(), reactiveLimit[i].maxLimit + loadPower[i].imag());
busType[i] = BUS_PQ;
reactiveLimit[i].limitReached = RL_MAX_REACHED;
limitReach = true;
@@ -254,7 +266,8 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase,
}
if(reactiveLimit[i].minLimitType == RL_LIMITED) {
if(power[i].imag() - loadPower[i].imag() < reactiveLimit[i].minLimit) {
- power[i] = std::complex<double>(power[i].real(), reactiveLimit[i].minLimit + loadPower[i].imag());
+ power[i] =
+ std::complex<double>(power[i].real(), reactiveLimit[i].minLimit + loadPower[i].imag());
busType[i] = BUS_PQ;
reactiveLimit[i].limitReached = RL_MIN_REACHED;
limitReach = true;