Power System Platform  2026w23a-beta
Loading...
Searching...
No Matches
EMTElement.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 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 EMTELEMENT_H
19#define EMTELEMENT_H
20
21#include "Shunt.h"
22#include "../../utils/ATPPSPBridge.h"
23#include <map>
24#include <array>
25
26class wxTextFile;
27class PropertiesData;
28
30{
31 double t;
32 std::array<double, 3> current;
33 std::array<double, 3> mag;
34 std::array<double, 3> angle;
35};
36
38 wxString name = "";
39 wxFileName atpFile;
40 wxString atpNodeName = "";
41 double stepSize = 1e-6;
42 double pspStepSize = 1e-3;
43 int cyclesToSS = 1;
44 int recordFrequency = 1;
45 bool useMedianFilter = true;
46 std::complex<double> puVoltage = std::complex<double>(1.0, 0.0);
47 double baseVoltage = 138.0e3;
48 double frequency = 60.0;
49 wxString atpWorkFolder = "";
50 wxFileName atpPath;
51
52 // Last phasor current calculated inn ATP
53 std::complex<double> current = std::complex<double>(0.0, 0.0);
54
55 // Power Flow
56 std::complex<double> y0 = std::complex<double>(0.0, 0.0); // Base admittance
57 std::complex<double> power = std::complex<double>(0.0, 0.0);
58 std::complex<double> powerDiff = std::complex<double>(0.0, 0.0);
59
60 // Harmonics
61 int numMaxHarmonics = 15;
62 double harmonicsThreshold = 0.3;
63 //std::vector< std::complex<double> > currHarmonics;
64 //std::vector<int> currHarmonicsOrder;
65 std::map<int, std::complex<double> > currHarmonics;
66 //std::vector< std::pair<double, double> > atpData;
67
68 // Sample data
69 std::vector<ATPSample> atpSampleData;
70 double nPhases = 3;
71 std::vector< std::pair<double, double> > inFFTData;
72 std::vector< std::pair<double ,std::complex<double> > > outFFTData;
73};
74
82class EMTElement : public Shunt
83{
84public:
85 EMTElement();
86 EMTElement(wxString name);
88
89 virtual Element* GetCopy();
90 virtual bool AddParent(Element* parent, wxPoint2DDouble position);
91 virtual void DrawDC(GUIColour* guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext* gc) const;
92 virtual void DrawDC(GUIColour* guiColour, wxPoint2DDouble translation, double scale, wxDC& dc) const;
93 virtual bool Contains(wxPoint2DDouble position) const { return m_rect.Contains(position); }
94 virtual bool Intersects(wxRect2DDouble rect) const { return m_rect.Intersects(rect); }
95 virtual void Rotate(bool clockwise = true);
96 virtual bool GetContextMenu(wxMenu& menu);
97 virtual wxString GetTipText() const;
98 virtual bool ShowForm(wxWindow* parent, Element* element, wxWindow* workspace = nullptr);
99
100 virtual rapidxml::xml_node<>* SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode);
101 virtual bool OpenElement(rapidxml::xml_node<>* elementNode, std::vector<Element*> parentList);
102
103 virtual EMTElementData GetEMTElementData() { return m_data; }
104 virtual void SetEMTElementData(EMTElementData data) { m_data = data; }
105
106 wxArrayString GetATPNodes(wxArrayString atpFile);
107 bool SetATPParameter(wxTextFile& atpFile, const wxString& card, const int& line, const int& initPos, const int& size, const wxString& value);
108 bool AddConnectionToNode(wxTextFile& atpFile, const wxString& node);
109 void MedianFilter(std::vector<double>& data);
110 bool CalculateCurrent( wxString& errorMsg, const Mode& mode = Mode::Phasor, const bool& saveRawData = false, const bool& saveFFTData = false);
111 void UpdateData(const PropertiesData* properties = nullptr, bool updateVoltageBase = false);
112 void SetNominalVoltage(std::vector<double> nominalVoltage, std::vector<ElectricalUnit> nominalVoltageUnit);
113
114protected:
115 void DoMedianFilter(double* extension, std::vector<double>& result, const int& n);
116 wxString ATPField(double value, size_t width);
117 bool CheckLISFile(wxFileName fileName, wxString& errorMsg) const;
118 EMTElementData m_data;
119};
120
121#endif // EMTELEMENT_H
122
Element to connect ATP-EMTP.
Definition EMTElement.h:83
virtual void Rotate(bool clockwise=true)
Rotate the element.
virtual bool GetContextMenu(wxMenu &menu)
Get the element contex menu.
virtual bool Intersects(wxRect2DDouble rect) const
Check if the element's rect intersects other rect.
Definition EMTElement.h:94
virtual bool ShowForm(wxWindow *parent, Element *element, wxWindow *workspace=nullptr)
Show element data form.
virtual bool Contains(wxPoint2DDouble position) const
Checks if the element contains a position.
Definition EMTElement.h:93
virtual wxString GetTipText() const
Get the tip text.
virtual void DrawDC(GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
Draw the element using GDI+.
virtual bool AddParent(Element *parent, wxPoint2DDouble position)
Add a parent to the element. This method must be used on power elements that connect to a bus,...
virtual Element * GetCopy()
Get a the element copy.
void SetNominalVoltage(std::vector< double > nominalVoltage, std::vector< ElectricalUnit > nominalVoltageUnit)
Set nominal voltage of the element.
Base class of all elements of the program. This class is responsible for manage graphical and his dat...
Definition Element.h:114
General and simulation data manager.
Abstract class for shunt power elements.
Definition Shunt.h:32