From b6d4815859b494cc6e5e1f1718a3b410fdd6037a Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Mon, 7 Nov 2016 17:23:07 -0200 Subject: Reactive limits under implementation --- .codelite/.tern-port | 2 +- .codelite/PSP.session | 51 ++---------- .codelite/PSP.tags | Bin 83365888 -> 83373056 bytes .codelite/compilation.db | Bin 59392 -> 59392 bytes .codelite/compile_commands.json | 48 +---------- .codelite/refactoring.db | Bin 1992704 -> 2006016 bytes Project/ElectricCalculation.cpp | 133 ++++++++++++++++-------------- Project/ElectricCalculation.h | 8 +- Project/PowerFlow.cpp | 91 ++++++++++++++------ Project/PowerFlow.h | 13 +++ Project/Project.mk | 2 +- Project/Release/ElectricCalculation.cpp.o | Bin 65799 -> 66771 bytes Project/Release/PSP-UFU.exe | Bin 4075084 -> 4076970 bytes Project/Release/PowerFlow.cpp.o | Bin 39066 -> 41283 bytes 14 files changed, 168 insertions(+), 180 deletions(-) diff --git a/.codelite/.tern-port b/.codelite/.tern-port index 7ce4b11..092b19f 100644 --- a/.codelite/.tern-port +++ b/.codelite/.tern-port @@ -1 +1 @@ -50042 \ No newline at end of file +50233 \ No newline at end of file diff --git a/.codelite/PSP.session b/.codelite/PSP.session index 0656946..fb0bd0a 100644 --- a/.codelite/PSP.session +++ b/.codelite/PSP.session @@ -1,6 +1,6 @@ - + @@ -41,14 +41,14 @@ - + - - + + @@ -61,50 +61,15 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + diff --git a/.codelite/PSP.tags b/.codelite/PSP.tags index 99fb8f4..3ac5e12 100644 Binary files a/.codelite/PSP.tags and b/.codelite/PSP.tags differ diff --git a/.codelite/compilation.db b/.codelite/compilation.db index df31f08..a51ecdd 100644 Binary files a/.codelite/compilation.db and b/.codelite/compilation.db differ diff --git a/.codelite/compile_commands.json b/.codelite/compile_commands.json index 17dd53e..c846c88 100644 --- a/.codelite/compile_commands.json +++ b/.codelite/compile_commands.json @@ -1,53 +1,9 @@ [{ "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", - "command": "C:/TDM-GCC-64/bin/g++.exe -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -I. -I. -MG -MP -MT./Release/SyncGenerator.cpp.o -MF./Release/SyncGenerator.cpp.o.d -MM SyncGenerator.cpp", - "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\SyncGenerator.cpp" - }, { - "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", - "command": "C:/TDM-GCC-64/bin/g++.exe -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -I. -I. -MG -MP -MT./Release/Machines.cpp.o -MF./Release/Machines.cpp.o.d -MM Machines.cpp", - "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\Machines.cpp" - }, { - "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", - "command": "C:/TDM-GCC-64/bin/g++.exe -c C:/Users/Thales/Documents/GitHub/PSP/Project/MainFrame.cpp -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -o ./Release/MainFrame.cpp.o -I. -I.", - "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\MainFrame.cpp" - }, { - "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", - "command": "C:/TDM-GCC-64/bin/g++.exe -c C:/Users/Thales/Documents/GitHub/PSP/Project/Workspace.cpp -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -o ./Release/Workspace.cpp.o -I. -I.", - "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\Workspace.cpp" - }, { - "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", - "command": "C:/TDM-GCC-64/bin/g++.exe -c C:/Users/Thales/Documents/GitHub/PSP/Project/Machines.cpp -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -o ./Release/Machines.cpp.o -I. -I.", - "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\Machines.cpp" - }, { - "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", - "command": "C:/TDM-GCC-64/bin/g++.exe -c C:/Users/Thales/Documents/GitHub/PSP/Project/SyncGenerator.cpp -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -o ./Release/SyncGenerator.cpp.o -I. -I.", - "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\SyncGenerator.cpp" - }, { - "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", - "command": "C:/TDM-GCC-64/bin/g++.exe -c C:/Users/Thales/Documents/GitHub/PSP/Project/ElectricCalculation.cpp -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -o ./Release/ElectricCalculation.cpp.o -I. -I.", - "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\ElectricCalculation.cpp" + "command": "C:/TDM-GCC-64/bin/g++.exe -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -I. -I. -MG -MP -MT./Release/PowerFlow.cpp.o -MF./Release/PowerFlow.cpp.o.d -MM PowerFlow.cpp", + "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\PowerFlow.cpp" }, { "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", "command": "C:/TDM-GCC-64/bin/g++.exe -c C:/Users/Thales/Documents/GitHub/PSP/Project/PowerFlow.cpp -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -o ./Release/PowerFlow.cpp.o -I. -I.", "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\PowerFlow.cpp" - }, { - "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", - "command": "C:/TDM-GCC-64/bin/g++.exe -c C:/Users/Thales/Documents/GitHub/PSP/Project/SyncMotor.cpp -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -o ./Release/SyncMotor.cpp.o -I. -I.", - "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\SyncMotor.cpp" - }, { - "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", - "command": "C:/TDM-GCC-64/bin/g++.exe -c C:/Users/Thales/Documents/GitHub/PSP/Project/IndMotor.cpp -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -o ./Release/IndMotor.cpp.o -I. -I.", - "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\IndMotor.cpp" - }, { - "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", - "command": "C:/TDM-GCC-64/bin/g++.exe -c C:/Users/Thales/Documents/GitHub/PSP/Project/GeneratorStabForm.cpp -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -o ./Release/GeneratorStabForm.cpp.o -I. -I.", - "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\GeneratorStabForm.cpp" - }, { - "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", - "command": "C:/TDM-GCC-64/bin/g++.exe -c C:/Users/Thales/Documents/GitHub/PSP/Project/IndMotorForm.cpp -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -o ./Release/IndMotorForm.cpp.o -I. -I.", - "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\IndMotorForm.cpp" - }, { - "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", - "command": "C:/TDM-GCC-64/bin/g++.exe -c C:/Users/Thales/Documents/GitHub/PSP/Project/SyncMachineForm.cpp -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -o ./Release/SyncMachineForm.cpp.o -I. -I.", - "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\SyncMachineForm.cpp" }] \ No newline at end of file diff --git a/.codelite/refactoring.db b/.codelite/refactoring.db index f071aeb..11d2cfc 100644 Binary files a/.codelite/refactoring.db and b/.codelite/refactoring.db differ diff --git a/Project/ElectricCalculation.cpp b/Project/ElectricCalculation.cpp index 3cda1af..a68cc19 100644 --- a/Project/ElectricCalculation.cpp +++ b/Project/ElectricCalculation.cpp @@ -156,10 +156,10 @@ bool ElectricCalculation::GetYBus(std::vector > return true; } -void ElectricCalculation::ValidateElementsPowerFlow(std::vector > voltage, - std::vector > power, - std::vector busType, - double systemPowerBase) +void ElectricCalculation::UpdateElementsPowerFlow(std::vector > voltage, + std::vector > power, + std::vector busType, + double systemPowerBase) { // Buses voltages for(int i = 0; i < (int)m_busList.size(); i++) { @@ -262,6 +262,11 @@ void ElectricCalculation::ValidateElementsPowerFlow(std::vectorGetPUElectricalData(systemPowerBase); if(childData.loadType == CONST_POWER) loadPower += std::complex(childData.activePower, childData.reactivePower); + + if(childData.activePower >= 0.0) + load->SetPowerFlowDirection(PF_TO_ELEMENT); + else + load->SetPowerFlowDirection(PF_TO_BUS); } } for(auto itim = m_indMotorList.begin(); itim != m_indMotorList.end(); itim++) { @@ -269,72 +274,75 @@ void ElectricCalculation::ValidateElementsPowerFlow(std::vectorGetParentList()[0] && indMotor->IsOnline()) { IndMotorElectricalData childData = indMotor->GetPUElectricalData(systemPowerBase); loadPower += std::complex(childData.activePower, childData.reactivePower); + + if(childData.activePower >= 0.0) + indMotor->SetPowerFlowDirection(PF_TO_ELEMENT); + else + indMotor->SetPowerFlowDirection(PF_TO_BUS); } } // Set the sync generator power - if(busType[i] == BUS_SLACK || busType[i] == BUS_PV) { - for(auto itsg = syncGeneratorsOnBus.begin(); itsg != syncGeneratorsOnBus.end(); itsg++) { - SyncGenerator* generator = *itsg; - if(generator->IsOnline()) { - SyncGeneratorElectricalData childData = generator->GetElectricalData(); - - if(busType[i] == BUS_SLACK) { - double activePower = (power[i].real() + loadPower.real()) * systemPowerBase / - (double)(syncGeneratorsOnBus.size()); - - switch(childData.activePowerUnit) { - case UNIT_PU: { - activePower /= systemPowerBase; - } break; - case UNIT_kW: { - activePower /= 1e3; - } break; - case UNIT_MW: { - activePower /= 1e6; - } break; - default: - break; - } - - if(activePower >= 0.0) - generator->SetPowerFlowDirection(PF_TO_BUS); - else - generator->SetPowerFlowDirection(PF_TO_ELEMENT); - - childData.activePower = activePower; - } - if(busType[i] == BUS_PV || busType[i] == BUS_SLACK) { - double reactivePower = (power[i].imag() + loadPower.imag()) * systemPowerBase / - (double)(syncGeneratorsOnBus.size() + syncMotorsOnBus.size()); - switch(childData.reactivePowerUnit) { - case UNIT_PU: { - reactivePower /= systemPowerBase; - } break; - case UNIT_kVAr: { - reactivePower /= 1e3; - } break; - case UNIT_MVAr: { - reactivePower /= 1e6; - } break; - default: - break; - } - childData.reactivePower = reactivePower; + for(auto itsg = syncGeneratorsOnBus.begin(); itsg != syncGeneratorsOnBus.end(); itsg++) { + SyncGenerator* generator = *itsg; + if(generator->IsOnline()) { + SyncGeneratorElectricalData childData = generator->GetElectricalData(); + + if(busType[i] == BUS_SLACK) { + double activePower = + (power[i].real() + loadPower.real()) * systemPowerBase / (double)(syncGeneratorsOnBus.size()); + + switch(childData.activePowerUnit) { + case UNIT_PU: { + activePower /= systemPowerBase; + } break; + case UNIT_kW: { + activePower /= 1e3; + } break; + case UNIT_MW: { + activePower /= 1e6; + } break; + default: + break; } - generator->SetElectricalData(childData); + childData.activePower = activePower; } + if(busType[i] == BUS_PV || busType[i] == BUS_SLACK) { + double reactivePower = (power[i].imag() + loadPower.imag()) * systemPowerBase / + (double)(syncGeneratorsOnBus.size() + syncMotorsOnBus.size()); + switch(childData.reactivePowerUnit) { + case UNIT_PU: { + reactivePower /= systemPowerBase; + } break; + case UNIT_kVAr: { + reactivePower /= 1e3; + } break; + case UNIT_MVAr: { + reactivePower /= 1e6; + } break; + default: + break; + } + childData.reactivePower = reactivePower; + } + + if(childData.activePower >= 0.0) + generator->SetPowerFlowDirection(PF_TO_BUS); + else + generator->SetPowerFlowDirection(PF_TO_ELEMENT); + + generator->SetElectricalData(childData); } } // Set the sync motor reactive power - if(busType[i] == BUS_PV) { - for(auto itmg = syncMotorsOnBus.begin(); itmg != syncMotorsOnBus.end(); itmg++) { - SyncMotor* syncMotor = *itmg; - if(syncMotor->IsOnline()) { - SyncMotorElectricalData childData = syncMotor->GetElectricalData(); + for(auto itmg = syncMotorsOnBus.begin(); itmg != syncMotorsOnBus.end(); itmg++) { + SyncMotor* syncMotor = *itmg; + if(syncMotor->IsOnline()) { + SyncMotorElectricalData childData = syncMotor->GetElectricalData(); + if(busType[i] == BUS_PV || busType[i] == BUS_SLACK) { double reactivePower = (power[i].imag() + loadPower.imag()) * systemPowerBase / (double)(syncGeneratorsOnBus.size() + syncMotorsOnBus.size()); switch(childData.reactivePowerUnit) { @@ -351,9 +359,14 @@ void ElectricCalculation::ValidateElementsPowerFlow(std::vectorSetElectricalData(childData); } + + if(childData.activePower > 0.0) + syncMotor->SetPowerFlowDirection(PF_TO_ELEMENT); + else + syncMotor->SetPowerFlowDirection(PF_TO_BUS); + + syncMotor->SetElectricalData(childData); } } } diff --git a/Project/ElectricCalculation.h b/Project/ElectricCalculation.h index 02a45e0..ac573cd 100644 --- a/Project/ElectricCalculation.h +++ b/Project/ElectricCalculation.h @@ -24,10 +24,10 @@ class ElectricCalculation ~ElectricCalculation(); virtual void GetElementsFromList(std::vector elementList); virtual bool GetYBus(std::vector > >& yBus, double systemPowerBase); - virtual void ValidateElementsPowerFlow(std::vector > voltage, - std::vector > power, - std::vector busType, - double systemPowerBase); + virtual void UpdateElementsPowerFlow(std::vector > voltage, + std::vector > power, + std::vector busType, + double systemPowerBase); protected: std::vector m_busList; diff --git a/Project/PowerFlow.cpp b/Project/PowerFlow.cpp index ff79722..8d8850f 100644 --- a/Project/PowerFlow.cpp +++ b/Project/PowerFlow.cpp @@ -20,6 +20,9 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase, std::vector busType; // Bus type std::vector > voltage; // Voltage of buses std::vector > power; // Injected power + std::vector reactiveLimit; // Limit of reactive power on PV buses + + reactiveLimit.resize(numberOfBuses); int busNumber = 0; for(auto itb = m_busList.begin(); itb != m_busList.end(); itb++) { @@ -66,6 +69,20 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase, if(bus == syncGenerator->GetParentList()[0]) { SyncGeneratorElectricalData childData = syncGenerator->GetPUElectricalData(systemPowerBase); power[busNumber] += std::complex(childData.activePower, childData.reactivePower); + + if(busType[busNumber] == BUS_PV) { + if(childData.haveMaxReactive && reactiveLimit[busNumber].maxLimitType != RL_UNLIMITED_SOURCE) { + reactiveLimit[busNumber].maxLimitType = RL_LIMITED; + reactiveLimit[busNumber].maxLimit += childData.maxReactive; + } else if(!childData.haveMaxReactive) + reactiveLimit[busNumber].maxLimitType = RL_UNLIMITED_SOURCE; + + if(childData.haveMinReactive && reactiveLimit[busNumber].minLimitType != RL_UNLIMITED_SOURCE) { + reactiveLimit[busNumber].minLimitType = RL_LIMITED; + reactiveLimit[busNumber].minLimit += childData.minReactive; + } else if(!childData.haveMinReactive) + reactiveLimit[busNumber].minLimitType = RL_UNLIMITED_SOURCE; + } } } } @@ -76,6 +93,20 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase, if(bus == syncMotor->GetParentList()[0]) { SyncMotorElectricalData childData = syncMotor->GetPUElectricalData(systemPowerBase); power[busNumber] += std::complex(-childData.activePower, childData.reactivePower); + + if(busType[busNumber] == BUS_PV) { + if(childData.haveMaxReactive && reactiveLimit[busNumber].maxLimitType != RL_UNLIMITED_SOURCE) { + reactiveLimit[busNumber].maxLimitType = RL_LIMITED; + reactiveLimit[busNumber].maxLimit += childData.maxReactive; + } else if(!childData.haveMaxReactive) + reactiveLimit[busNumber].maxLimitType = RL_UNLIMITED_SOURCE; + + if(childData.haveMinReactive && reactiveLimit[busNumber].minLimitType != RL_UNLIMITED_SOURCE) { + reactiveLimit[busNumber].minLimitType = RL_LIMITED; + reactiveLimit[busNumber].minLimit += childData.minReactive; + } else if(!childData.haveMinReactive) + reactiveLimit[busNumber].minLimitType = RL_UNLIMITED_SOURCE; + } } } } @@ -120,22 +151,24 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase, } haveSlackBus = true; } - if(!haveSlackBus) { - m_errorMsg = _("There is no slack bus on the system."); - return false; - } - if(!slackBusHaveGeneration) { - m_errorMsg = _("The slack bus don't have generation."); - return false; - } + } + if(!haveSlackBus) { + m_errorMsg = _("There is no slack bus on the system."); + return false; + } + if(!slackBusHaveGeneration) { + m_errorMsg = _("The slack bus don't have generation."); + return false; } // Gauss-Seidel method std::vector > oldVoltage; // Old voltage array. oldVoltage.resize(voltage.size()); + + auto oldBusType = busType; int iteration = 0; // Current itaration number. - + while(true) { // Reach the max number of iterations. if(iteration >= maxIteration) { @@ -201,7 +234,28 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase, if(busError > iterationError) iterationError = busError; } - if(iterationError < error) break; + if(iterationError < error) { + bool limitReach = false; + for(int i = 0; i < numberOfBuses; i++) { + if(busType[i] == BUS_PV) { + if(reactiveLimit[i].maxLimitType == RL_LIMITED) { + if(power[i].imag() > reactiveLimit[i].maxLimit) { + power[i] = std::complex(power[i].real(), reactiveLimit[i].maxLimit); + busType[i] = BUS_PQ; + limitReach = true; + } + } + if(reactiveLimit[i].minLimitType == RL_LIMITED) { + if(power[i].imag() < reactiveLimit[i].minLimit) { + power[i] = std::complex(power[i].real(), reactiveLimit[i].minLimit); + busType[i] = BUS_PQ; + limitReach = true; + } + } + } + } + if(!limitReach) break; + } iteration++; } @@ -214,22 +268,9 @@ bool PowerFlow::RunGaussSeidel(double systemPowerBase, power[i] = sBus; } - wxString str = ""; - /*for(int i = 0; i < numberOfBuses; i++) { - str += wxString::Format("%.5f/_%.2f\n", std::abs(voltage[i]), wxRadToDeg(std::arg(voltage[i]))); - } - wxLogMessage(str); + UpdateElementsPowerFlow(voltage, power, oldBusType, systemPowerBase); - str = ""; - for(int i = 0; i < numberOfBuses; i++) { - str += wxString::Format("%.5f + j%.5f\n", power[i].real(), power[i].imag()); - } - wxLogMessage(str); - - wxLogMessage(wxString::Format("Num iteracoes = %d", iteration));*/ - - ValidateElementsPowerFlow(voltage, power, busType, systemPowerBase); - + wxString str = ""; for(auto itb = m_busList.begin(); itb != m_busList.end(); itb++) { Bus* bus = *itb; BusElectricalData data = bus->GetEletricalData(); diff --git a/Project/PowerFlow.h b/Project/PowerFlow.h index 1e5c621..0ead448 100644 --- a/Project/PowerFlow.h +++ b/Project/PowerFlow.h @@ -7,6 +7,19 @@ #include //_() #include //temp +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. +}; + +struct ReactiveLimits { + double maxLimit = 0.0; + double minLimit = 0.0; + ReactiveLimitsType maxLimitType = RL_UNLIMITED; + ReactiveLimitsType minLimitType = RL_UNLIMITED; +}; + class PowerFlow : public ElectricCalculation { public: diff --git a/Project/Project.mk b/Project/Project.mk index 09c2818..79121dc 100644 --- a/Project/Project.mk +++ b/Project/Project.mk @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=Thales -Date :=04/11/2016 +Date :=07/11/2016 CodeLitePath :="C:/Program Files/CodeLite" LinkerName :=C:/TDM-GCC-64/bin/g++.exe SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC diff --git a/Project/Release/ElectricCalculation.cpp.o b/Project/Release/ElectricCalculation.cpp.o index 91c3101..0586bd9 100644 Binary files a/Project/Release/ElectricCalculation.cpp.o and b/Project/Release/ElectricCalculation.cpp.o differ diff --git a/Project/Release/PSP-UFU.exe b/Project/Release/PSP-UFU.exe index dceb0d5..7f37d30 100644 Binary files a/Project/Release/PSP-UFU.exe and b/Project/Release/PSP-UFU.exe differ diff --git a/Project/Release/PowerFlow.cpp.o b/Project/Release/PowerFlow.cpp.o index 0827969..64f5719 100644 Binary files a/Project/Release/PowerFlow.cpp.o and b/Project/Release/PowerFlow.cpp.o differ -- cgit