From bc5a3e8923cb8efedbbd5b88e212eb0e9009cf87 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Thu, 5 Oct 2017 20:02:59 -0300 Subject: Add copyright on files and documentation update --- Project/PowerFlow.cpp | 65 ++++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 29 deletions(-) (limited to 'Project/PowerFlow.cpp') diff --git a/Project/PowerFlow.cpp b/Project/PowerFlow.cpp index fe59067..4a2b7c9 100644 --- a/Project/PowerFlow.cpp +++ b/Project/PowerFlow.cpp @@ -1,23 +1,30 @@ -#include "PowerFlow.h" - -PowerFlow::PowerFlow() - : ElectricCalculation() -{ -} +/* + * 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 . + */ -PowerFlow::PowerFlow(std::vector elementList) - : ElectricCalculation() -{ - GetElementsFromList(elementList); -} +#include "PowerFlow.h" +PowerFlow::PowerFlow() : ElectricCalculation() {} +PowerFlow::PowerFlow(std::vector 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)) { @@ -28,11 +35,11 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase, // Number of buses on the system. int numberOfBuses = static_cast(m_busList.size()); - std::vector busType; // Bus type - std::vector > voltage; // Voltage of buses - std::vector > power; // Injected power - std::vector > loadPower; // Only the load power - std::vector reactiveLimit; // Limit of reactive power on PV buses + std::vector busType; // Bus type + std::vector > voltage; // Voltage of buses + std::vector > power; // Injected power + std::vector > loadPower; // Only the load power + std::vector reactiveLimit; // Limit of reactive power on PV buses reactiveLimit.resize(numberOfBuses); @@ -72,7 +79,7 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase, } // Fill the power array - power.push_back(std::complex(0.0, 0.0)); // Initial value + power.push_back(std::complex(0.0, 0.0)); // Initial value loadPower.push_back(std::complex(0.0, 0.0)); // Synchronous generator @@ -179,12 +186,12 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase, } // Gauss-Seidel method - std::vector > oldVoltage; // Old voltage array. + std::vector > 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. @@ -214,7 +221,7 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase, // Apply the acceleration factor. newVolt = std::complex(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; } @@ -238,15 +245,15 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase, // Apply the acceleration factor. newVolt = std::complex(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(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; } -- cgit