diff options
-rw-r--r-- | PSP.workspace | 4 | ||||
-rw-r--r-- | Project/Electromechanical.cpp | 57 | ||||
-rw-r--r-- | Project/Electromechanical.h | 8 | ||||
-rw-r--r-- | Project/Workspace.cpp | 6 |
4 files changed, 62 insertions, 13 deletions
diff --git a/PSP.workspace b/PSP.workspace index a37d541..95b47db 100644 --- a/PSP.workspace +++ b/PSP.workspace @@ -6,7 +6,7 @@ <Environment/> <Project Name="Project" ConfigName="Release_Windows_x32"/> </WorkspaceConfiguration> - <WorkspaceConfiguration Name="Release_Windows_x64" Selected="no"> + <WorkspaceConfiguration Name="Release_Windows_x64" Selected="yes"> <Environment/> <Project Name="Project" ConfigName="Release_Windows_x64"/> </WorkspaceConfiguration> @@ -14,7 +14,7 @@ <Environment/> <Project Name="Project" ConfigName="Debug_Windows_x64"/> </WorkspaceConfiguration> - <WorkspaceConfiguration Name="Release_Ubuntu_x64" Selected="yes"> + <WorkspaceConfiguration Name="Release_Ubuntu_x64" Selected="no"> <Environment/> <Project Name="Project" ConfigName="Release_Ubuntu_x64"/> </WorkspaceConfiguration> diff --git a/Project/Electromechanical.cpp b/Project/Electromechanical.cpp index ea8b1bb..5bb9a1d 100644 --- a/Project/Electromechanical.cpp +++ b/Project/Electromechanical.cpp @@ -15,8 +15,8 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include "Electromechanical.h" #include "ControlElementSolver.h" +#include "Electromechanical.h" Electromechanical::Electromechanical(wxWindow* parent, std::vector<Element*> elementList, SimulationData data) { @@ -70,6 +70,7 @@ 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. @@ -996,6 +997,7 @@ bool Electromechanical::SolveSynchronousMachines() return false; } } + m_iterationsNum = iterations; // Solve controllers. int ctrlRatio = static_cast<int>(1 / m_ctrlTimeStepMultiplier); @@ -1006,7 +1008,8 @@ bool Electromechanical::SolveSynchronousMachines() data.avrSolver->SetSwitchStatus(syncGenerator->IsOnline()); data.avrSolver->SetCurrentTime(m_currentTime); data.avrSolver->SetTerminalVoltage(std::abs(data.terminalVoltage)); - data.avrSolver->SetDeltaActivePower((data.electricalPower.real() - data.avrSolver->GetActivePower()) / m_timeStep); + data.avrSolver->SetDeltaActivePower((data.electricalPower.real() - data.avrSolver->GetActivePower()) / + m_timeStep); data.avrSolver->SetActivePower(data.electricalPower.real()); data.avrSolver->SetReactivePower(data.electricalPower.imag()); data.avrSolver->SetDeltaVelocity((data.speed - data.avrSolver->GetVelocity()) / m_timeStep); @@ -1066,6 +1069,7 @@ void Electromechanical::SaveData() load->SetElectricalData(data); } } + m_iterationsNumVector.push_back(m_iterationsNum); } void Electromechanical::SetSyncMachinesModel() @@ -1089,9 +1093,7 @@ bool Electromechanical::CalculateSyncMachineNonIntVariables(SyncGenerator* syncG auto data = syncGenerator->GetElectricalData(); int n = static_cast<Bus*>(syncGenerator->GetParentList()[0])->GetElectricalData().number; - if(syncGenerator->IsOnline()) { - data.terminalVoltage = m_vBus[n]; - } + if(syncGenerator->IsOnline()) { data.terminalVoltage = m_vBus[n]; } double vd, vq; ABCtoDQ0(data.terminalVoltage, data.delta, vd, vq); @@ -1287,9 +1289,7 @@ bool Electromechanical::CalculateSyncMachineSaturation(SyncGenerator* syncMachin auto smDataModel = GetSyncMachineModelData(syncMachine); int n = static_cast<Bus*>(syncMachine->GetParentList()[0])->GetElectricalData().number; - if(syncMachine->IsOnline()) { - data.terminalVoltage = m_vBus[n]; - } + if(syncMachine->IsOnline()) { data.terminalVoltage = m_vBus[n]; } double idCalc = id; double iqCalc = iq; double sdCalc = sd; @@ -1394,9 +1394,7 @@ SyncMachineModelData Electromechanical::GetSyncMachineModelData(SyncGenerator* s smModelData.xq = data.transXq * k; if(smModelData.xq == 0.0) { smModelData.xq = data.syncXq * k; - if(smModelData.xq == 0.0) { - smModelData.xq = data.syncXd * k; - } + if(smModelData.xq == 0.0) { smModelData.xq = data.syncXd * k; } } } break; case Machines::SM_MODEL_3: { @@ -1418,3 +1416,40 @@ SyncMachineModelData Electromechanical::GetSyncMachineModelData(SyncGenerator* s } return smModelData; } + +void Electromechanical::PreallocateVectors() +{ + int numPoints = static_cast<unsigned int>(m_simTime / m_plotTime); + + m_timeVector.reserve(numPoints); + for(auto it = m_syncGeneratorList.begin(), itEnd = m_syncGeneratorList.end(); it != itEnd; ++it) { + SyncGenerator* syncGenerator = *it; + auto data = syncGenerator->GetElectricalData(); + if(data.plotSyncMachine) { + data.terminalVoltageVector.reserve(numPoints); + data.electricalPowerVector.reserve(numPoints); + data.mechanicalPowerVector.reserve(numPoints); + data.freqVector.reserve(numPoints); + data.fieldVoltageVector.reserve(numPoints); + data.deltaVector.reserve(numPoints); + syncGenerator->SetElectricalData(data); + } + } + 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.reserve(numPoints); + bus->SetElectricalData(data); + } + } + for(auto it = m_loadList.begin(), itEnd = m_loadList.end(); it != itEnd; ++it) { + Load* load = *it; + auto data = load->GetElectricalData(); + if(data.plotLoad) { + data.voltageVector.reserve(numPoints); + data.electricalPowerVector.reserve(numPoints); + load->SetElectricalData(data); + } + } +} diff --git a/Project/Electromechanical.h b/Project/Electromechanical.h index 4c82bb6..573c0c2 100644 --- a/Project/Electromechanical.h +++ b/Project/Electromechanical.h @@ -57,6 +57,9 @@ class Electromechanical : public ElectricCalculation bool RunStabilityCalculation(); wxString GetErrorMessage() const { return m_errorMsg; } std::vector<double> GetTimeVector() const { return m_timeVector; } + + // For tests + std::vector<double> GetIterationVector() const { return m_iterationsNumVector; } protected: void SetEventTimeList(); @@ -98,6 +101,7 @@ class Electromechanical : public ElectricCalculation double k = 1.0); void SaveData(); + void PreallocateVectors(); wxWindow* m_parent = NULL; wxString m_errorMsg = _("Unknown error"); @@ -127,6 +131,10 @@ class Electromechanical : public ElectricCalculation std::vector<bool> m_eventOccurrenceList; std::vector<double> m_timeVector; + + // For tests + int m_iterationsNum = 0.0; + std::vector<double> m_iterationsNumVector; }; #endif // ELECTROMECHANICAL_H diff --git a/Project/Workspace.cpp b/Project/Workspace.cpp index 45944ab..8a67456 100644 --- a/Project/Workspace.cpp +++ b/Project/Workspace.cpp @@ -1449,6 +1449,12 @@ bool Workspace::RunStability() ElementPlotData plotData; if(element->GetPlotData(plotData)) plotDataList.push_back(plotData); } + + ElementPlotData plotData; + plotData.SetName(_("Simulation parameters")); + plotData.SetCurveType(ElementPlotData::CT_TEST); + plotData.AddData(stability.GetIterationVector(), _("Iterations number")); + plotDataList.push_back(plotData); ChartView* cView = new ChartView(this, plotDataList, m_stabilityTimeVector); cView->Show(); |