summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThales Lima Oliveira <thaleslima.ufu@gmail.com>2019-01-22 15:06:09 -0200
committerThales Lima Oliveira <thaleslima.ufu@gmail.com>2019-01-22 15:06:09 -0200
commit59c28b89bb2a4eb05a87bb28154442266c35b17d (patch)
treeae65a35f314e55d2527e4cdc8196673cac42bf17
parent5a06bb4424311cbb728af35fe73d259499d7c9bf (diff)
downloadPSP.git-59c28b89bb2a4eb05a87bb28154442266c35b17d.tar.gz
PSP.git-59c28b89bb2a4eb05a87bb28154442266c35b17d.tar.xz
PSP.git-59c28b89bb2a4eb05a87bb28154442266c35b17d.zip
Some code stability optimization
-rw-r--r--Project/Electromechanical.cpp42
-rw-r--r--Project/Electromechanical.h2
-rw-r--r--Project/Project.project2
-rw-r--r--Project/SyncGenerator.cpp13
-rw-r--r--Project/SyncGenerator.h3
-rw-r--r--Project/Workspace.cpp11
-rw-r--r--Project/Workspace.h1
7 files changed, 48 insertions, 26 deletions
diff --git a/Project/Electromechanical.cpp b/Project/Electromechanical.cpp
index 50ce4e5..f74f546 100644
--- a/Project/Electromechanical.cpp
+++ b/Project/Electromechanical.cpp
@@ -70,7 +70,6 @@ bool Electromechanical::RunStabilityCalculation()
wxProgressDialog pbd(_("Running simulation"), _("Initializing..."), 100, m_parent,
wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_SMOOTH);
- PreallocateVectors(); // Reserve the vectors' memory with a estimated size, this can optimize the simulation.
SetSyncMachinesModel();
// Calculate the admittance matrix with the synchronous machines.
@@ -83,6 +82,7 @@ bool Electromechanical::RunStabilityCalculation()
// Get buses voltages.
m_vBus.clear();
+ m_vBus.shrink_to_fit();
m_vBus.resize(m_busList.size());
for(auto it = m_busList.begin(), itEnd = m_busList.end(); it != itEnd; ++it) {
Bus* bus = *it;
@@ -97,6 +97,7 @@ bool Electromechanical::RunStabilityCalculation()
}
if(!InitializeDynamicElements()) return false;
+ PreallocateVectors(); // Reserve the vectors' memory with a estimated size, this can optimize the simulation.
double pbdTime = m_plotTime;
m_currentTime = 0.0;
@@ -109,7 +110,7 @@ bool Electromechanical::RunStabilityCalculation()
}
if(currentPlotTime >= m_plotTime || m_currentTime == 0.0) {
- m_timeVector.push_back(m_currentTime);
+ m_timeVector.emplace_back(m_currentTime);
SaveData();
currentPlotTime = 0.0;
}
@@ -139,10 +140,10 @@ void Electromechanical::SetEventTimeList()
Bus* bus = *it;
auto data = bus->GetElectricalData();
if(data.stabHasFault) {
- m_eventTimeList.push_back(data.stabFaultTime);
- m_eventOccurrenceList.push_back(false);
- m_eventTimeList.push_back(data.stabFaultTime + data.stabFaultLength);
- m_eventOccurrenceList.push_back(false);
+ m_eventTimeList.emplace_back(data.stabFaultTime);
+ m_eventOccurrenceList.emplace_back(false);
+ m_eventTimeList.emplace_back(data.stabFaultTime + data.stabFaultLength);
+ m_eventOccurrenceList.emplace_back(false);
}
}
// Switching
@@ -150,8 +151,8 @@ void Electromechanical::SetEventTimeList()
PowerElement* element = *it;
SwitchingData swData = element->GetSwitchingData();
for(unsigned int i = 0; i < swData.swTime.size(); ++i) {
- m_eventTimeList.push_back(swData.swTime[i]);
- m_eventOccurrenceList.push_back(false);
+ m_eventTimeList.emplace_back(swData.swTime[i]);
+ m_eventOccurrenceList.emplace_back(false);
}
}
}
@@ -462,6 +463,7 @@ bool Electromechanical::InitializeDynamicElements()
Bus* bus = *it;
auto data = bus->GetElectricalData();
data.stabVoltageVector.clear();
+ data.stabVoltageVector.shrink_to_fit();
bus->SetElectricalData(data);
}
// Loads
@@ -492,7 +494,9 @@ bool Electromechanical::InitializeDynamicElements()
data.qp0 = (data.constPowerReactive / 100.0) * reactivePower;
data.voltageVector.clear();
+ data.voltageVector.shrink_to_fit();
data.electricalPowerVector.clear();
+ data.electricalPowerVector.shrink_to_fit();
if(load->IsOnline())
data.electricalPower = std::complex<double>(activePower, reactivePower);
@@ -704,11 +708,17 @@ bool Electromechanical::InitializeDynamicElements()
}
// Reset plot data
data.terminalVoltageVector.clear();
+ data.terminalVoltageVector.shrink_to_fit();
data.electricalPowerVector.clear();
+ data.electricalPowerVector.shrink_to_fit();
data.mechanicalPowerVector.clear();
+ data.mechanicalPowerVector.shrink_to_fit();
data.freqVector.clear();
+ data.freqVector.shrink_to_fit();
data.fieldVoltageVector.clear();
+ data.fieldVoltageVector.shrink_to_fit();
data.deltaVector.clear();
+ data.deltaVector.shrink_to_fit();
syncGenerator->SetElectricalData(data);
}
@@ -1044,20 +1054,14 @@ void Electromechanical::SaveData()
SyncGenerator* syncGenerator = *it;
auto data = syncGenerator->GetElectricalData();
if(data.plotSyncMachine) {
- data.terminalVoltageVector.push_back(data.terminalVoltage);
- data.electricalPowerVector.push_back(data.electricalPower);
- data.mechanicalPowerVector.push_back(data.pm);
- data.freqVector.push_back(data.speed / (2.0f * M_PI));
- data.fieldVoltageVector.push_back(data.fieldVoltage);
- data.deltaVector.push_back(wxRadToDeg(data.delta));
- syncGenerator->SetElectricalData(data);
+ syncGenerator->SavePlotData();
}
}
for(auto it = m_busList.begin(), itEnd = m_busList.end(); it != itEnd; ++it) {
Bus* bus = *it;
auto data = bus->GetElectricalData();
if(data.plotBus) {
- data.stabVoltageVector.push_back(m_vBus[data.number]);
+ data.stabVoltageVector.emplace_back(m_vBus[data.number]);
bus->SetElectricalData(data);
}
}
@@ -1065,12 +1069,12 @@ void Electromechanical::SaveData()
Load* load = *it;
auto data = load->GetElectricalData();
if(data.plotLoad) {
- data.voltageVector.push_back(data.voltage);
- data.electricalPowerVector.push_back(data.electricalPower);
+ data.voltageVector.emplace_back(data.voltage);
+ data.electricalPowerVector.emplace_back(data.electricalPower);
load->SetElectricalData(data);
}
}
- m_iterationsNumVector.push_back(m_iterationsNum);
+ m_iterationsNumVector.emplace_back(m_iterationsNum);
}
void Electromechanical::SetSyncMachinesModel()
diff --git a/Project/Electromechanical.h b/Project/Electromechanical.h
index 573c0c2..65275e5 100644
--- a/Project/Electromechanical.h
+++ b/Project/Electromechanical.h
@@ -126,6 +126,8 @@ class Electromechanical : public ElectricCalculation
double m_tolerance = 1e-8;
int m_maxIterations = 100;
double m_saturationTolerance = 1e-8;
+
+ int m_currentPoint = 0;
std::vector<double> m_eventTimeList;
std::vector<bool> m_eventOccurrenceList;
diff --git a/Project/Project.project b/Project/Project.project
index 882f7a2..728e0b2 100644
--- a/Project/Project.project
+++ b/Project/Project.project
@@ -508,7 +508,7 @@
</Completion>
</Configuration>
<Configuration Name="Release_Windows_x64" CompilerType="MinGW ( TDM-GCC-64 )" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
- <Compiler Options="-O2;-Wall;$(shell wx-config --cflags);-std=gnu++11" C_Options="-O2;-Wall" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
+ <Compiler Options="-O3;-Wall;$(shell wx-config --cflags);-std=gnu++11" C_Options="-O3;-Wall" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
<Preprocessor Value="NDEBUG"/>
<Preprocessor Value="UNICODE"/>
diff --git a/Project/SyncGenerator.cpp b/Project/SyncGenerator.cpp
index 17463e2..c988a7e 100644
--- a/Project/SyncGenerator.cpp
+++ b/Project/SyncGenerator.cpp
@@ -231,11 +231,10 @@ bool SyncGenerator::GetPlotData(ElementPlotData& plotData)
std::vector<double> absTerminalVoltage, activePower, reactivePower;
for(unsigned int i = 0; i < m_electricalData.terminalVoltageVector.size(); ++i) {
- absTerminalVoltage.push_back(std::abs(m_electricalData.terminalVoltageVector[i]));
activePower.push_back(std::real(m_electricalData.electricalPowerVector[i]));
reactivePower.push_back(std::imag(m_electricalData.electricalPowerVector[i]));
}
- plotData.AddData(absTerminalVoltage, _("Terminal voltage"));
+ plotData.AddData(m_electricalData.terminalVoltageVector, _("Terminal voltage"));
plotData.AddData(activePower, _("Active power"));
plotData.AddData(reactivePower, _("Reactive power"));
plotData.AddData(m_electricalData.mechanicalPowerVector, _("Mechanical power"));
@@ -413,3 +412,13 @@ bool SyncGenerator::OpenElement(rapidxml::xml_node<>* elementNode, std::vector<E
m_inserted = true;
return true;
}
+
+void SyncGenerator::SavePlotData()
+{
+ m_electricalData.terminalVoltageVector.emplace_back(std::abs(m_electricalData.terminalVoltage));
+ m_electricalData.electricalPowerVector.emplace_back(m_electricalData.electricalPower);
+ m_electricalData.mechanicalPowerVector.emplace_back(m_electricalData.pm);
+ m_electricalData.freqVector.emplace_back(m_electricalData.speed / (2.0f * M_PI));
+ m_electricalData.fieldVoltageVector.emplace_back(m_electricalData.fieldVoltage);
+ m_electricalData.deltaVector.emplace_back(wxRadToDeg(m_electricalData.delta));
+}
diff --git a/Project/SyncGenerator.h b/Project/SyncGenerator.h
index 4866f8b..980b56b 100644
--- a/Project/SyncGenerator.h
+++ b/Project/SyncGenerator.h
@@ -79,7 +79,7 @@ struct SyncGeneratorElectricalData {
// Machine state variables
std::complex<double> terminalVoltage;
- std::vector<std::complex<double> > terminalVoltageVector;
+ std::vector<double> terminalVoltageVector;
std::complex<double> electricalPower;
std::vector<std::complex<double> > electricalPowerVector;
double pm;
@@ -154,6 +154,7 @@ class SyncGenerator : public Machines
virtual SyncGeneratorElectricalData GetPUElectricalData(double systemPowerBase);
virtual void SetElectricalData(SyncGeneratorElectricalData electricalData) { m_electricalData = electricalData; }
virtual void SetNominalVoltage(std::vector<double> nominalVoltage, std::vector<ElectricalUnit> nominalVoltageUnit);
+ virtual void SavePlotData();
virtual bool GetPlotData(ElementPlotData& plotData);
virtual rapidxml::xml_node<>* SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode);
diff --git a/Project/Workspace.cpp b/Project/Workspace.cpp
index 8a67456..e652f51 100644
--- a/Project/Workspace.cpp
+++ b/Project/Workspace.cpp
@@ -1429,7 +1429,9 @@ bool Workspace::RunStability()
RunPowerFlow();
Electromechanical stability(this, GetElementList(), m_properties->GetSimulationPropertiesData());
+ wxStopWatch sw;
bool result = stability.RunStabilityCalculation();
+ sw.Pause();
if(!result) {
wxMessageDialog msgDialog(this, stability.GetErrorMessage(), _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
msgDialog.ShowModal();
@@ -1440,8 +1442,11 @@ bool Workspace::RunStability()
// Run power flow after stability.
RunPowerFlow();
- wxMessageDialog msgDialog(this, _("Do you wish to open the stability graphics?"), _("Question"),
- wxYES_NO | wxCENTRE | wxICON_QUESTION);
+ wxMessageDialog msgDialog(
+ this,
+ wxString::Format(_("The program took %ld ms to run this system.\nDo you wish to open the stability graphics?"),
+ sw.Time()),
+ _("Question"), wxYES_NO | wxCENTRE | wxICON_QUESTION);
if(msgDialog.ShowModal() == wxID_YES) {
std::vector<ElementPlotData> plotDataList;
for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; ++it) {
@@ -1449,7 +1454,7 @@ bool Workspace::RunStability()
ElementPlotData plotData;
if(element->GetPlotData(plotData)) plotDataList.push_back(plotData);
}
-
+
ElementPlotData plotData;
plotData.SetName(_("Simulation parameters"));
plotData.SetCurveType(ElementPlotData::CT_TEST);
diff --git a/Project/Workspace.h b/Project/Workspace.h
index 83b64e6..c59314a 100644
--- a/Project/Workspace.h
+++ b/Project/Workspace.h
@@ -25,6 +25,7 @@
#include <wx/statusbr.h>
#include <wx/clipbrd.h>
#include <wx/tipwin.h>
+#include <wx/stopwatch.h>
#include "WorkspaceBase.h"
#include "Bus.h"