Power System Platform  2026w23a-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 if (wxSystemSettings::GetAppearance().IsDark())
15 {
16 m_headerColour = wxColour(50, 50, 50);
17 m_oddRowColour = wxColour(70, 70, 70);
18 m_evenRowColour = wxColour(40, 40, 40);
19 m_redColour = wxColour(255, 110, 110);
20 m_blueColour = wxColour(120, 170, 255);
21 }
22 else
23 {
24 m_headerColour = wxColour(191, 223, 255);
25 m_oddRowColour = wxColour(220, 220, 220);
26 m_evenRowColour = wxColour(255, 255, 255);
27 m_redColour = wxColour(210, 35, 35);
28 m_blueColour = wxColour(25, 90, 220);
29 }
30
31 m_time.clear();
32 m_eventType.clear();
33 m_eventDescription.clear();
34 m_eventColour.clear();
35
36 GetTimeEventsList();
37 SortEvents();
38 FillGrid();
39 SetRowsColours(m_gridStabEventList);
40
41 SetSize(GetBestSize());
42}
43
44StabilityEventList::~StabilityEventList() {}
45
46void StabilityEventList::GetTimeEventsList()
47{
49 eCalc.GetElementsFromList(m_elementList);
50 auto busList = eCalc.GetBusList();
51 for(unsigned int i = 0; i < busList.size(); ++i) {
52 Bus* bus = busList[i];
53 auto data = bus->GetElectricalData();
54 if(data.stabHasFault) {
55 AddEvent(data.stabFaultTime, _("Fault"),
56 _("Fault insertion at \"") + data.name + _("\" (Zf = ") +
57 bus->StringFromDouble(data.stabFaultResistance) + wxT(" +j") +
58 bus->StringFromDouble(data.stabFaultReactance) + wxT(" p.u.)"),
59 m_redColour);
60 AddEvent(data.stabFaultTime + data.stabFaultLength, _("Fault"),
61 _("Fault removal at \"") + data.name + _("\" (Zf = ") +
62 bus->StringFromDouble(data.stabFaultResistance) + wxT(" +j") +
63 bus->StringFromDouble(data.stabFaultReactance) + wxT(" p.u.)"),
64 m_blueColour);
65 }
66 }
67 auto capacitorList = eCalc.GetCapacitorList();
68 for(unsigned int i = 0; i < capacitorList.size(); ++i) {
69 Capacitor* capacitor = capacitorList[i];
70 SetPowerElementSwitchingEvent(capacitor, capacitor->GetElectricalData().name);
71 }
72 auto indMotorList = eCalc.GetIndMotorList();
73 for(unsigned int i = 0; i < indMotorList.size(); ++i) {
74 IndMotor* indMotor = indMotorList[i];
75 SetPowerElementSwitchingEvent(indMotor, indMotor->GetElectricalData().name);
76 }
77 auto inductorList = eCalc.GetInductorList();
78 for(unsigned int i = 0; i < inductorList.size(); ++i) {
79 Inductor* inductor = inductorList[i];
80 SetPowerElementSwitchingEvent(inductor, inductor->GetElectricalData().name);
81 }
82 auto lineList = eCalc.GetLineList();
83 for(unsigned int i = 0; i < lineList.size(); ++i) {
84 Line* line = lineList[i];
85 SetPowerElementSwitchingEvent(line, line->GetElectricalData().name);
86 }
87 auto loadList = eCalc.GetLoadList();
88 for(unsigned int i = 0; i < loadList.size(); ++i) {
89 Load* load = loadList[i];
90 SetPowerElementSwitchingEvent(load, load->GetElectricalData().name);
91 }
92 auto syncGeneratorList = eCalc.GetSyncGeneratorList();
93 for(unsigned int i = 0; i < syncGeneratorList.size(); ++i) {
94 SyncGenerator* syncGenerator = syncGeneratorList[i];
95 SetPowerElementSwitchingEvent(syncGenerator, syncGenerator->GetElectricalData().name);
96 }
97 auto syncMotorList = eCalc.GetSyncMotorList();
98 for(unsigned int i = 0; i < syncMotorList.size(); ++i) {
99 SyncMotor* syncMotor = syncMotorList[i];
100 SetPowerElementSwitchingEvent(syncMotor, syncMotor->GetElectricalData().name);
101 }
102 auto transformerList = eCalc.GetTransformerList();
103 for(unsigned int i = 0; i < transformerList.size(); ++i) {
104 Transformer* transformer = transformerList[i];
105 SetPowerElementSwitchingEvent(transformer, transformer->GetElectricalData().name);
106 }
107}
108
109void StabilityEventList::AddEvent(double eventTime, wxString eventType, wxString eventDescription, wxColour eventColour)
110{
111 m_time.emplace_back(eventTime);
112 m_eventType.emplace_back(eventType);
113 m_eventDescription.emplace_back(eventDescription);
114 m_eventColour.emplace_back(eventColour);
115}
116
117void StabilityEventList::FillGrid()
118{
119 wxFont headerFont = m_gridStabEventList->GetLabelFont();
120 headerFont.SetWeight(wxFONTWEIGHT_BOLD);
121
122 // Create Grid
123 // Header
124 m_gridStabEventList->AppendCols(3);
125 m_gridStabEventList->AppendRows();
126 m_gridStabEventList->HideColLabels();
127 m_gridStabEventList->HideRowLabels();
128 for(int i = 0; i < 7; ++i) {
129 m_gridStabEventList->SetCellBackgroundColour(0, i, m_headerColour);
130 m_gridStabEventList->SetCellFont(0, i, headerFont);
131 }
132 m_gridStabEventList->SetDefaultCellAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
133 // Values
134 m_gridStabEventList->AppendRows(m_time.size());
135
136 // Set headers
137 m_gridStabEventList->SetCellValue(0, 0, _("Event time"));
138 m_gridStabEventList->SetCellValue(0, 1, _("Type"));
139 m_gridStabEventList->SetCellValue(0, 2, _("Description"));
140
141 // Fill Values
142 for(unsigned int i = 0; i < m_time.size(); ++i) {
143 m_gridStabEventList->SetCellValue(i + 1, 0, Element::StringFromDouble(m_time[i]) + wxT(" s"));
144 m_gridStabEventList->SetCellValue(i + 1, 1, m_eventType[i]);
145 m_gridStabEventList->SetCellValue(i + 1, 2, m_eventDescription[i]);
146 m_gridStabEventList->SetCellAlignment(i + 1, 2, wxALIGN_LEFT, wxALIGN_CENTRE);
147 for(int j = 0; j < 3; ++j) { m_gridStabEventList->SetCellTextColour(i + 1, j, m_eventColour[i]); }
148 }
149
150 m_gridStabEventList->AutoSize();
151}
152
153void StabilityEventList::SetRowsColours(wxGrid* grid, int rowStart)
154{
155 for(int i = rowStart; i < grid->GetNumberRows(); ++i) {
156 wxGridCellAttr* attr = grid->GetOrCreateCellAttr(i, 0);
157 if((i - rowStart) % 2 == 0)
158 attr->SetBackgroundColour(m_evenRowColour);
159 else
160 attr->SetBackgroundColour(m_oddRowColour);
161 grid->SetRowAttr(i, attr);
162 }
163}
164
165void StabilityEventList::SetPowerElementSwitchingEvent(PowerElement* element, wxString elementName)
166{
167 SwitchingData swData = element->GetSwitchingData();
168 for(unsigned int i = 0; i < swData.swTime.size(); ++i) {
169 if(swData.swType[i] == SwitchingType::SW_INSERT) {
170 AddEvent(swData.swTime[i], _("Switching"), _("Insertion of \"") + elementName + _("\""), m_blueColour);
171 } else {
172 AddEvent(swData.swTime[i], _("Switching"), _("Removal of \"") + elementName + _("\""), m_redColour);
173 }
174 }
175}
176
177void StabilityEventList::SortEvents()
178{
179 for(unsigned int i = 0; i < m_time.size(); ++i) {
180 for(unsigned int j = 0; j < m_time.size(); ++j) {
181 if(m_time[i] < m_time[j]) {
182 double time = m_time[i];
183 wxString type = m_eventType[i];
184 wxString description = m_eventDescription[i];
185 wxColour colour = m_eventColour[i];
186 m_time[i] = m_time[j];
187 m_eventType[i] = m_eventType[j];
188 m_eventDescription[i] = m_eventDescription[j];
189 m_eventColour[i] = m_eventColour[j];
190 m_time[j] = time;
191 m_eventType[j] = type;
192 m_eventDescription[j] = description;
193 m_eventColour[j] = colour;
194 }
195 }
196 }
197}
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:466
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