Power System Platform  2026w34a-beta
Loading...
Searching...
No Matches
Bus.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Thales Lima Oliveira <thales@ufu.br>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifndef BUS_H
19#define BUS_H
20
21#include "../../forms/BusForm.h"
22#include "PowerElement.h"
23 // ---------------------------------------------------------------------
24 // Arc Flash — electrode configuration mirrors arcflash::ElectrodeConfig
25 // 1:1 (VCB, VCBB, HCB = enclosed; VOA, HOA = open air).
26 // ---------------------------------------------------------------------
27enum class ArcFlashElectrodeConfig {
28 VCB,
29 VCBB,
30 HCB,
31 VOA,
32 HOA
33};
34
35// Whether an enclosure applies to this electrode configuration. This is
36// NOT a user choice — it is fully derived from electrodeConfig, mirroring
37// arcflash::IsEnclosed().
38inline bool IsEnclosedConfig(ArcFlashElectrodeConfig config)
39{
40 return config == ArcFlashElectrodeConfig::VCB ||
41 config == ArcFlashElectrodeConfig::VCBB ||
42 config == ArcFlashElectrodeConfig::HCB;
43}
44
46 bool enabled = false;
47
48 // --- Input---
49 ArcFlashElectrodeConfig electrodeConfig = ArcFlashElectrodeConfig::VCB;
50 double conductorGap = 100.0; // mm
51 double workingDistance = 100.0; // mm
52
53 // Enclosure dimensions. Only meaningful when IsEnclosedConfig(electrodeConfig) is true
54 double enclosureHeight = 100.0; // mm
55 double enclosureWidth = 100.0; // mm
56 double enclosureDepth = 100.0; // mm
57
58 // --- Result (mirrors arcflash::ArcFlashResult) ---
59 bool calculated = false; // true once Calculate() has run successfully at least once
60 double iarc_kA = 0.0;
61 double iarcMin_kA = 0.0;
62 double incidentEnergy_Jcm2 = 0.0;
63 double incidentEnergy_calcm2 = 0.0;
64 double arcFlashBoundary_mm = 0.0;
65 bool usedReducedCurrent = false;
66 std::vector<wxString> warnings;
67};
68
70 int number = 0;
71 wxString name = "";
72 double nominalVoltage = 138.0;
73 ElectricalUnit nominalVoltageUnit = ElectricalUnit::UNIT_kV;
74 bool isVoltageControlled = false;
75 double controlledVoltage = 1.0;
76 int controlledVoltageUnitChoice = 0; // 0 = p.u., 1 = same as nominalVoltageUnit (ElectricalUnit::UNIT_V or ElectricalUnit::UNIT_kV).
77 bool slackBus = false;
78 bool isConnected = true;
79
80 // Power flow (p.u.)
81 std::complex<double> voltage = std::complex<double>(1.0, 0.0);
82 std::complex<double> power = std::complex<double>(0.0, 0.0);
83 int busType = 2; // PQ
84
85 // Fault
86 bool hasFault = false;
88 FaultData faultLocation = FaultData::FAULT_LINE_A;
89 // p.u. fault data
90 double faultResistance = 0.0;
91 double faultReactance = 0.0;
92 std::complex<double> faultCurrent[3] = { std::complex<double>(0.0, 0.0), std::complex<double>(0.0, 0.0),
93 std::complex<double>(0.0, 0.0) };
94 std::complex<double> faultVoltage[3] = { std::complex<double>(0.0, 0.0), std::complex<double>(0.0, 0.0),
95 std::complex<double>(0.0, 0.0) };
96 double scPower = 0.0;
97
98 // Stability
99 bool plotBus = false;
100 bool stabHasFault = false;
101 double stabFaultTime = 0.0;
102 double stabFaultLength = 0.0;
103 double stabFaultResistance = 0.0;
104 double stabFaultReactance = 0.0;
105 double oldAngle = 0.0; // theta(k-1)
106 double filteredAngle = 0.0; // xt(k-1)
107 double dxt = 0.0; // Derivative of filteredAngle
108 double filteredVelocity = 0.0; // dw(k-1)
109 double ddw = 0.0; // Derivative of filteredVelocity
110 double stabFreq = 60.0;
111 std::vector<std::complex<double> > stabVoltageVector;
112 std::vector<double> stabFreqVector;
113
114 // Power Quality
115 bool plotPQData = false;
116 std::vector<int> harmonicOrder;
117 std::vector< std::complex<double> > harmonicVoltage;
118 double thd = 0.0;
119
120 std::vector<double> absImpedanceVector;
121 std::vector< std::complex<double> > complexImpedanceVector;
122
123 // Arc Flash
124 ArcFlashData arcFlash;
125};
126
134class Bus : public PowerElement
135{
136public:
141 Bus();
147 Bus(wxPoint2DDouble position);
154 Bus(wxPoint2DDouble position, wxString name);
155 ~Bus();
156 virtual Element* GetCopy();
165 virtual bool AddParent(Element* parent, wxPoint2DDouble position, bool isOpening = false) { return true; }
166 virtual bool Contains(wxPoint2DDouble position) const;
167 virtual bool Intersects(wxRect2DDouble rect) const;
168 //virtual void Draw(wxPoint2DDouble translation, double scale) const;
169 virtual void DrawDC(GUIColour* guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext* gc) const;
170 virtual void DrawDC(GUIColour* guiColour, wxPoint2DDouble translation, double scale, wxDC& dc) const;
171 virtual void Rotate(bool clockwise = true);
172 virtual void AlignToGrid(double gridSize = 20.0) override;
173 virtual wxCursor GetBestPickboxCursor() const;
174 virtual void MovePickbox(wxPoint2DDouble position);
175 virtual bool PickboxContains(wxPoint2DDouble position);
176 virtual bool GetContextMenu(wxMenu& menu);
177 virtual wxString GetTipText() const;
178 virtual wxColour GetVoltageColour(GUIColour* guiColour = nullptr) const;
179 virtual BusElectricalData GetElectricalData() const { return m_electricalData; }
180 virtual BusElectricalData& GetElectricalDataRef() { return m_electricalData; }
181 virtual void SetElectricalData(const BusElectricalData& electricalData) { m_electricalData = electricalData; }
182 virtual bool ShowForm(wxWindow* parent, Element* element, wxWindow* workspace = nullptr);
183 virtual bool GetPlotData(ElementPlotData& plotData, PlotStudy study = PlotStudy::STABILITY);
184
185 virtual rapidxml::xml_node<>* SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode);
186 virtual bool OpenElement(rapidxml::xml_node<>* elementNode);
187
188protected:
189 BusElectricalData m_electricalData;
190};
191
192#endif // BUS_H
FaultData
Information about fault (type and location).
PlotStudy
virtual bool PickboxContains(wxPoint2DDouble position)
Check if a pickbox contains a point. If contains the attributes related to pickbox movement will be c...
Definition Bus.cpp:247
virtual wxString GetTipText() const
Get the tip text.
Definition Bus.cpp:432
virtual bool GetPlotData(ElementPlotData &plotData, PlotStudy study=PlotStudy::STABILITY)
Fill the plot data.
Definition Bus.cpp:475
virtual void DrawDC(GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
Draw the element using GDI+.
Definition Bus.cpp:44
virtual Element * GetCopy()
Get a the element copy.
Definition Bus.cpp:365
virtual bool Intersects(wxRect2DDouble rect) const
Check if the element's rect intersects other rect.
Definition Bus.cpp:240
virtual bool AddParent(Element *parent, wxPoint2DDouble position, bool isOpening=false)
Add a parent element to the Bus.
Definition Bus.h:165
Bus()
Default constructor.
Definition Bus.cpp:23
virtual wxCursor GetBestPickboxCursor() const
Get the best cursor to shown to the user when the mouse is above a pickbox.
Definition Bus.cpp:271
virtual void Rotate(bool clockwise=true)
Rotate the element.
Definition Bus.cpp:315
virtual bool Contains(wxPoint2DDouble position) const
Checks if the element contains a position.
Definition Bus.cpp:234
virtual void MovePickbox(wxPoint2DDouble position)
Move the pickbox.
Definition Bus.cpp:288
virtual bool ShowForm(wxWindow *parent, Element *element, wxWindow *workspace=nullptr)
Show element data form.
Definition Bus.cpp:355
virtual bool GetContextMenu(wxMenu &menu)
Get the element contex menu.
Definition Bus.cpp:334
Element()
Constructor.
Definition Element.cpp:28
PowerElement()
Constructor.