summaryrefslogtreecommitdiffstats
path: root/Project/Load.h
blob: bc27846f693f777cba2815fa791eefcba6876568 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 *  Copyright (C) 2017  Thales Lima Oliveira <thales@ufu.br>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef LOAD_H
#define LOAD_H

#include "LoadForm.h"
#include "Shunt.h"

enum LoadType { CONST_POWER = 0, CONST_IMPEDANCE };

struct LoadElectricalData {
    wxString name;
    double activePower = 100.0;
    ElectricalUnit activePowerUnit = ElectricalUnit::UNIT_MW;
    double reactivePower = 0.0;
    ElectricalUnit reactivePowerUnit = ElectricalUnit::UNIT_Mvar;
    LoadType loadType = CONST_POWER;

    // Stability
    bool plotLoad = false;
    // ZIP load
    bool useCompLoad = false;
    // The power injected on the "i" bus flollow the quadratic equation:
    // -p(i) = pz0 * (v(i) / v0) ^ 2 + pi0 * (v(i) / v0) + pp0
    double v0 = 1.0;   // Initial load voltage from load flow in p.u.
    double pz0 = 1.0;  // Initial active power modelled as constant impedance from load flow in p.u.
    double pi0 = 0.0;  // Initial active power modelled as constant current from load flow in p.u.
    double pp0 = 0.0;  // Initial active power modelled as constant power from load flow in p.u.
    double qz0 = 1.0;  // Initial reactive power modelled as constant impedance from load flow in p.u.
    double qi0 = 0.0;  // Initial reactive power modelled as constant current from load flow in p.u.
    double qp0 = 0.0;  // Initial reactive power modelled as constant power from load flow in p.u.
    double constImpedanceActive = 100.0;    // Constant impedance portion of active power (%).
    double constCurrentActive = 0.0;        // Constant current portion of active power (%).
    double constPowerActive = 0.0;          // Constant power portion of active power (%).
    double constImpedanceReactive = 100.0;  // Constant impedance portion of reactive power (%).
    double constCurrentReactive = 0.0;      // Constant current portion of reactive power (%).
    double constPowerReactive = 0.0;        // Constant power portion of reactive power (%).
    std::complex<double> y0;                // Steady-state equivalent admittance calculated from power flow.
    // Undervoltage (in p.u.) which the constant current portion will be modelled as constant impedance.
    double constCurrentUV = 0.7;
    // Undervoltage (in p.u.) which the constant power portion will be modelled as constant impedance.
    double constPowerUV = 0.7;

    // Load state variables
    std::complex<double> voltage;
    std::vector<std::complex<double> > voltageVector;
    std::complex<double> electricalPower;
    std::vector<std::complex<double> > electricalPowerVector;
};

/**
 * @class Load
 * @author Thales Lima Oliveira <thales@ufu.br>
 * @date 06/10/2017
 * @brief Loas shunt power element.
 * @file Load.h
 */
class Load : public Shunt
{
   public:
    Load();
    Load(wxString name);
    ~Load();

    virtual Element* GetCopy();
    virtual bool AddParent(Element* parent, wxPoint2DDouble position);
    virtual void Draw(wxPoint2DDouble translation, double scale) const;
    virtual void DrawDC(wxPoint2DDouble translation, double scale, wxGraphicsContext* gc) const;
    virtual void Rotate(bool clockwise = true);
    virtual bool GetContextMenu(wxMenu& menu);
    virtual wxString GetTipText() const;
    virtual bool ShowForm(wxWindow* parent, Element* element);
    LoadElectricalData GetElectricalData() { return m_electricalData; }
    LoadElectricalData GetPUElectricalData(double systemPowerBase);
    void SetElectricalData(const LoadElectricalData& electricalData) { m_electricalData = electricalData; }
    virtual bool GetPlotData(ElementPlotData& plotData, PlotStudy study = PlotStudy::STABILITY);

    virtual rapidxml::xml_node<>* SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode);
    virtual bool OpenElement(rapidxml::xml_node<>* elementNode, std::vector<Element*> parentList);

   protected:
    std::vector<wxPoint2DDouble> m_triangPts;
    LoadElectricalData m_electricalData;
};

#endif  // LOAD_H