Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
StabilityEventList.cpp
1#include "StabilityEventList.h"
2
3#include "../simulation/ElectricCalculation.h"
4
5#include "../elements/powerElement/Bus.h"
6#include "../elements/Element.h"
7#include "../elements/powerElement/PowerElement.h"
8
9StabilityEventList::StabilityEventList(wxWindow* parent, std::vector<Element*> elementList)
10 : StabilityEventListBase(parent)
11{
12 m_elementList = elementList;
13
14 m_time.clear();
15 m_eventType.clear();
16 m_eventDescription.clear();
17 m_eventColour.clear();
18
19 GetTimeEventsList();
20 SortEvents();
21 FillGrid();
22 SetRowsColours(m_gridStabEventList);
23
24 SetSize(GetBestSize());
25}
26
27StabilityEventList::~StabilityEventList() {}
28
29void StabilityEventList::GetTimeEventsList()
30{
32 eCalc.GetElementsFromList(m_elementList);
33 auto busList = eCalc.GetBusList();
34 for(unsigned int i = 0; i < busList.size(); ++i) {
35 Bus* bus = busList[i];
36 auto data = bus->GetElectricalData();
37 if(data.stabHasFault) {
38 AddEvent(data.stabFaultTime, _("Fault"),
39 _("Fault insertion at \"") + data.name + _("\" (Zf = ") +
40 bus->StringFromDouble(data.stabFaultResistance) + wxT(" +j") +
41 bus->StringFromDouble(data.stabFaultReactance) + wxT(" p.u.)"),
42 m_redColour);
43 AddEvent(data.stabFaultTime + data.stabFaultLength, _("Fault"),
44 _("Fault removal at \"") + data.name + _("\" (Zf = ") +
45 bus->StringFromDouble(data.stabFaultResistance) + wxT(" +j") +
46 bus->StringFromDouble(data.stabFaultReactance) + wxT(" p.u.)"),
47 m_blueColour);
48 }
49 }
50 auto capacitorList = eCalc.GetCapacitorList();
51 for(unsigned int i = 0; i < capacitorList.size(); ++i) {
52 Capacitor* capacitor = capacitorList[i];
53 SetPowerElementSwitchingEvent(capacitor, capacitor->GetElectricalData().name);
54 }
55 auto indMotorList = eCalc.GetIndMotorList();
56 for(unsigned int i = 0; i < indMotorList.size(); ++i) {
57 IndMotor* indMotor = indMotorList[i];
58 SetPowerElementSwitchingEvent(indMotor, indMotor->GetElectricalData().name);
59 }
60 auto inductorList = eCalc.GetInductorList();
61 for(unsigned int i = 0; i < inductorList.size(); ++i) {
62 Inductor* inductor = inductorList[i];
63 SetPowerElementSwitchingEvent(inductor, inductor->GetElectricalData().name);
64 }
65 auto lineList = eCalc.GetLineList();
66 for(unsigned int i = 0; i < lineList.size(); ++i) {
67 Line* line = lineList[i];
68 SetPowerElementSwitchingEvent(line, line->GetElectricalData().name);
69 }
70 auto loadList = eCalc.GetLoadList();
71 for(unsigned int i = 0; i < loadList.size(); ++i) {
72 Load* load = loadList[i];
73 SetPowerElementSwitchingEvent(load, load->GetElectricalData().name);
74 }
75 auto syncGeneratorList = eCalc.GetSyncGeneratorList();
76 for(unsigned int i = 0; i < syncGeneratorList.size(); ++i) {
77 SyncGenerator* syncGenerator = syncGeneratorList[i];
78 SetPowerElementSwitchingEvent(syncGenerator, syncGenerator->GetElectricalData().name);
79 }
80 auto syncMotorList = eCalc.GetSyncMotorList();
81 for(unsigned int i = 0; i < syncMotorList.size(); ++i) {
82 SyncMotor* syncMotor = syncMotorList[i];
83 SetPowerElementSwitchingEvent(syncMotor, syncMotor->GetElectricalData().name);
84 }
85 auto transformerList = eCalc.GetTransformerList();
86 for(unsigned int i = 0; i < transformerList.size(); ++i) {
87 Transformer* transformer = transformerList[i];
88 SetPowerElementSwitchingEvent(transformer, transformer->GetElectricalData().name);
89 }
90}
91
92void StabilityEventList::AddEvent(double eventTime, wxString eventType, wxString eventDescription, wxColour eventColour)
93{
94 m_time.emplace_back(eventTime);
95 m_eventType.emplace_back(eventType);
96 m_eventDescription.emplace_back(eventDescription);
97 m_eventColour.emplace_back(eventColour);
98}
99
100void StabilityEventList::FillGrid()
101{
102 wxFont headerFont = m_gridStabEventList->GetLabelFont();
103 headerFont.SetWeight(wxFONTWEIGHT_BOLD);
104
105 // Create Grid
106 // Header
107 m_gridStabEventList->AppendCols(3);
108 m_gridStabEventList->AppendRows();
109 m_gridStabEventList->HideColLabels();
110 m_gridStabEventList->HideRowLabels();
111 for(int i = 0; i < 7; ++i) {
112 m_gridStabEventList->SetCellBackgroundColour(0, i, m_headerColour);
113 m_gridStabEventList->SetCellFont(0, i, headerFont);
114 }
115 m_gridStabEventList->SetDefaultCellAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
116 // Values
117 m_gridStabEventList->AppendRows(m_time.size());
118
119 // Set headers
120 m_gridStabEventList->SetCellValue(0, 0, _("Event time"));
121 m_gridStabEventList->SetCellValue(0, 1, _("Type"));
122 m_gridStabEventList->SetCellValue(0, 2, _("Description"));
123
124 // Fill Values
125 for(unsigned int i = 0; i < m_time.size(); ++i) {
126 m_gridStabEventList->SetCellValue(i + 1, 0, Element::StringFromDouble(m_time[i]) + wxT(" s"));
127 m_gridStabEventList->SetCellValue(i + 1, 1, m_eventType[i]);
128 m_gridStabEventList->SetCellValue(i + 1, 2, m_eventDescription[i]);
129 m_gridStabEventList->SetCellAlignment(i + 1, 2, wxALIGN_LEFT, wxALIGN_CENTRE);
130 for(int j = 0; j < 3; ++j) { m_gridStabEventList->SetCellTextColour(i + 1, j, m_eventColour[i]); }
131 }
132
133 m_gridStabEventList->AutoSize();
134}
135
136void StabilityEventList::SetRowsColours(wxGrid* grid, int rowStart)
137{
138 for(int i = rowStart; i < grid->GetNumberRows(); ++i) {
139 wxGridCellAttr* attr = grid->GetOrCreateCellAttr(i, 0);
140 if((i - rowStart) % 2 == 0)
141 attr->SetBackgroundColour(m_evenRowColour);
142 else
143 attr->SetBackgroundColour(m_oddRowColour);
144 grid->SetRowAttr(i, attr);
145 }
146}
147
148void StabilityEventList::SetPowerElementSwitchingEvent(PowerElement* element, wxString elementName)
149{
150 SwitchingData swData = element->GetSwitchingData();
151 for(unsigned int i = 0; i < swData.swTime.size(); ++i) {
152 if(swData.swType[i] == SwitchingType::SW_INSERT) {
153 AddEvent(swData.swTime[i], _("Switching"), _("Insertion of \"") + elementName + _("\""), m_blueColour);
154 } else {
155 AddEvent(swData.swTime[i], _("Switching"), _("Removal of \"") + elementName + _("\""), m_redColour);
156 }
157 }
158}
159
160void StabilityEventList::SortEvents()
161{
162 for(unsigned int i = 0; i < m_time.size(); ++i) {
163 for(unsigned int j = 0; j < m_time.size(); ++j) {
164 if(m_time[i] < m_time[j]) {
165 double time = m_time[i];
166 wxString type = m_eventType[i];
167 wxString description = m_eventDescription[i];
168 wxColour colour = m_eventColour[i];
169 m_time[i] = m_time[j];
170 m_eventType[i] = m_eventType[j];
171 m_eventDescription[i] = m_eventDescription[j];
172 m_eventColour[i] = m_eventColour[j];
173 m_time[j] = time;
174 m_eventType[j] = type;
175 m_eventDescription[j] = description;
176 m_eventColour[j] = colour;
177 }
178 }
179 }
180}
Node for power elements. All others power elements are connected through this.
Definition Bus.h:86
Shunt capactior power element.
Definition Capacitor.h:39
Base class for electrical calculations providing general utility methods.
const std::vector< IndMotor * > GetIndMotorList() const
Get the induction motors of the system (use GetElementsFromList first).
const std::vector< Load * > GetLoadList() const
Get the loads of the system (use GetElementsFromList first).
const std::vector< SyncMotor * > GetSyncMotorList() const
Get the synchronous motors of the system (use GetElementsFromList first).
const std::vector< SyncGenerator * > GetSyncGeneratorList() const
Get the synchronous generators of the system (use GetElementsFromList first).
const std::vector< Transformer * > GetTransformerList() const
Get the transformers of the system (use GetElementsFromList first).
const std::vector< Capacitor * > GetCapacitorList() const
Get the capacitors of the system (use GetElementsFromList first).
const std::vector< Inductor * > GetInductorList() const
Get the inductors of the system (use GetElementsFromList first).
const std::vector< Line * > GetLineList() const
Get the lines of the system (use GetElementsFromList first).
const std::vector< Bus * > GetBusList() const
Get the buses of the system (use GetElementsFromList first).
virtual void GetElementsFromList(std::vector< Element * > elementList)
Separate the power elements from a generic list.
static wxString StringFromDouble(double value, int minDecimal=1, int maxDecimals=13)
Convert a double value to string.
Definition Element.cpp:533
Induction motor power element.
Definition IndMotor.h:119
Inductor shunt power element.
Definition Inductor.h:39
Power line element.
Definition Line.h:64
Loas shunt power element.
Definition Load.h:74
Abstract class of power elements.
virtual SwitchingData GetSwitchingData()
Returns the switching data of the element.
Synchronous generator power element.
Synchronous motor (synchronous compensator) power element.
Definition SyncMotor.h:135
Two-winding transformer power element.
Definition Transformer.h:84
Switching data of power elements.
std::vector< double > swTime
std::vector< SwitchingType > swType