summaryrefslogtreecommitdiffstats
path: root/Project/SyncGenerator.h
blob: ef4076829a2687aadb38719cf1c0d0e50353ec9a (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
 *  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 SYNCGENERATOR_H
#define SYNCGENERATOR_H

#include "Machines.h"

class SyncMachineForm;

struct SyncGeneratorElectricalData {
    // General
    wxString name = "";
    double nominalPower = 100.0;
    ElectricalUnit nominalPowerUnit = ElectricalUnit::UNIT_MVA;
    double nominalVoltage = 13.8;
    ElectricalUnit nominalVoltageUnit = ElectricalUnit::UNIT_kV;
    double activePower = 100.0;
    ElectricalUnit activePowerUnit = ElectricalUnit::UNIT_MW;
    double reactivePower = 0.0;
    ElectricalUnit reactivePowerUnit = ElectricalUnit::UNIT_Mvar;
    bool haveMaxReactive = false;
    double maxReactive = 9999.0;
    ElectricalUnit maxReactiveUnit = ElectricalUnit::UNIT_Mvar;
    bool haveMinReactive = false;
    double minReactive = -9999.0;
    ElectricalUnit minReactiveUnit = ElectricalUnit::UNIT_Mvar;
    bool useMachineBase = true;

    // Fault
    double positiveResistance = 0.0;
    double positiveReactance = 1.0;
    double negativeResistance = 0.0;
    double negativeReactance = 1.0;
    double zeroResistance = 0.0;
    double zeroReactance = 1.0;
    double groundResistance = 0.0;
    double groundReactance = 0.0;
    bool groundNeutral = true;
    // p.u. fault data
    std::complex<double> faultCurrent[3] = {std::complex<double>(0.0, 0.0), std::complex<double>(0.0, 0.0),
                                            std::complex<double>(0.0, 0.0)};

    // Stability
    bool plotSyncMachine = false;
    double inertia = 1.0;
    double damping = 0.0;
    bool useAVR = false;
    bool useSpeedGovernor = false;

    double armResistance = 0.0;
    double potierReactance = 0.0;
    double satFactor = 0.0;
    double ocFrequency = 60.0;

    double syncXd = 0.0;
    double syncXq = 0.0;
    double transXd = 1.0;
    double transXq = 0.0;
    double transTd0 = 0.0;
    double transTq0 = 0.0;
    double subXd = 0.0;
    double subXq = 0.0;
    double subTd0 = 0.0;
    double subTq0 = 0.0;

    // Machine state variables
    std::complex<double> terminalVoltage;
    std::vector<double> terminalVoltageVector;
    std::complex<double> electricalPower;
    std::vector<std::complex<double> > electricalPowerVector;
    double pm;
    std::vector<double> mechanicalPowerVector;
    double speed;
    std::vector<double> freqVector;
    double fieldVoltage;
    std::vector<double> fieldVoltageVector;
    double delta;
    std::vector<double> deltaVector;

    double initialFieldVoltage;

    // Internal machine variables
    double tranEq;
    double tranEd;
    double subEq;
    double subEd;
    double pe;
    double id;
    double iq;
    double sd;
    double sq;

    // Variables to extrapolate
    double oldId;
    double oldIq;
    double oldPe;
    double oldSd;
    double oldSq;

    // Integration constants
    IntegrationConstant icSpeed;
    IntegrationConstant icDelta;
    IntegrationConstant icTranEq;
    IntegrationConstant icTranEd;
    IntegrationConstant icSubEq;
    IntegrationConstant icSubEd;

    // Control
    ControlElementContainer* avr = nullptr;
    ControlElementContainer* speedGov = nullptr;

    // Control solvers
    ControlElementSolver* avrSolver = nullptr;
    ControlElementSolver* speedGovSolver = nullptr;

    Machines::SyncMachineModel model = Machines::SM_MODEL_1;
};

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

    virtual Element* GetCopy();
    virtual void Init();
    virtual void DrawSymbol() const;
    virtual void DrawDCSymbol(wxGraphicsContext* gc) const;
    virtual bool GetContextMenu(wxMenu& menu);
    virtual bool ShowForm(wxWindow* parent, Element* element);
    virtual wxString GetTipText() const;
    virtual SyncGeneratorElectricalData GetElectricalData() { return m_electricalData; }
    virtual SyncGeneratorElectricalData GetPUElectricalData(double systemPowerBase);
    virtual void SetElectricalData(SyncGeneratorElectricalData electricalData) { m_electricalData = electricalData; }
    virtual void SetNominalVoltage(std::vector<double> nominalVoltage, std::vector<ElectricalUnit> nominalVoltageUnit);
    virtual void SavePlotData();
    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_sinePts;

    SyncGeneratorElectricalData m_electricalData;
};

#endif  // SYNCGENERATOR_H