Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
IndMotorForm.cpp
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#include "../elements/powerElement/IndMotor.h"
19#include "IndMotorForm.h"
20#include "SwitchingForm.h"
21
22IndMotorForm::IndMotorForm(wxWindow* parent, IndMotor* indMotor) : IndMotorFormBase(parent)
23{
24 SetSize(GetBestSize());
25 m_staticTextw->SetLabel(static_cast<wxString>(L'\u03C9') + wxT(" +"));
26 m_staticTextw2->SetLabel(static_cast<wxString>(L'\u03C9') + static_cast<wxString>(L'\u00B2'));
27 IndMotorElectricalData data = indMotor->GetElectricalData();
28
29 m_textCtrlName->SetValue(data.name);
30
31 m_textCtrlnominalPower->SetValue(IndMotor::StringFromDouble(data.ratedPower));
32 switch(data.activePowerUnit) {
34 m_choiceNominalPower->SetSelection(0);
35 } break;
37 m_choiceNominalPower->SetSelection(1);
38 } break;
40 m_choiceNominalPower->SetSelection(2);
41 } break;
42 default:
43 break;
44 }
45
46 m_textCtrlActivePower->SetValue(IndMotor::StringFromDouble(data.activePower));
47 switch(data.activePowerUnit) {
49 m_choiceActivePower->SetSelection(0);
50 } break;
52 m_choiceActivePower->SetSelection(1);
53 } break;
55 m_choiceActivePower->SetSelection(2);
56 } break;
58 m_choiceActivePower->SetSelection(3);
59 } break;
60 default:
61 break;
62 }
63
64 m_textCtrlReactivePower->SetValue(IndMotor::StringFromDouble(data.reactivePower));
65 switch(data.reactivePowerUnit) {
67 m_choiceReactivePower->SetSelection(0);
68 } break;
70 m_choiceReactivePower->SetSelection(1);
71 } break;
73 m_choiceReactivePower->SetSelection(2);
74 } break;
76 m_choiceReactivePower->SetSelection(3);
77 } break;
78 default:
79 break;
80 }
81
82 m_checkBoxComputeQ->SetValue(data.calcQInPowerFlow);
83 m_checkBoxUseMachinePower->SetValue(data.useMachinePowerAsBase);
84
85 // Stability
86 m_checkBoxPlotIndMachine->SetValue(data.plotIndMachine);
87 m_textCtrlInertia->SetValue(IndMotor::StringFromDouble(data.inertia));
88 m_textCtrlStatorResistence->SetValue(IndMotor::StringFromDouble(data.r1));
89 m_textCtrlStatorReactance->SetValue(IndMotor::StringFromDouble(data.x1));
90 m_textCtrlRotorResistence->SetValue(IndMotor::StringFromDouble(data.r2));
91 m_textCtrlRotorReactance->SetValue(IndMotor::StringFromDouble(data.x2));
92 m_textCtrlMagnetizingReactance->SetValue(IndMotor::StringFromDouble(data.xm));
93 m_checkBoxUseKf->SetValue(data.useKf);
94 m_textCtrlKf->SetValue(IndMotor::StringFromDouble(data.kf));
95 m_textCtrlKf->Enable(data.useKf);
96
97 m_textCtrlA->SetValue(IndMotor::StringFromDouble(data.aw));
98 m_textCtrlB->SetValue(IndMotor::StringFromDouble(data.bw));
99 m_textCtrlC->SetValue(IndMotor::StringFromDouble(data.cw));
100
101 m_parent = parent;
102 m_indMotor = indMotor;
103
104 UpdateFields();
105}
106
107IndMotorForm::~IndMotorForm() {}
108void IndMotorForm::OnOKButtonClick(wxCommandEvent& event)
109{
110 if(ValidateData()) EndModal(wxID_OK);
111}
112void IndMotorForm::OnStabilityButtonClick(wxCommandEvent& event)
113{
114 if(ValidateData()) {
115 SwitchingForm swForm(m_parent, m_indMotor);
116 swForm.SetTitle(_("Induction motor: Switching"));
117 swForm.ShowModal();
118 EndModal(wxID_OK);
119 }
120}
121
122bool IndMotorForm::ValidateData()
123{
125
126 data.name = m_textCtrlName->GetValue();
127
128 if(!m_indMotor->DoubleFromString(m_parent, m_textCtrlnominalPower->GetValue(), data.ratedPower,
129 _("Value entered incorrectly in the field \"Rated power\".")))
130 return false;
131 switch(m_choiceNominalPower->GetSelection()) {
132 case 0: {
133 data.activePowerUnit = ElectricalUnit::UNIT_VA;
134 } break;
135 case 1: {
136 data.activePowerUnit = ElectricalUnit::UNIT_kVA;
137 } break;
138 case 2: {
139 data.activePowerUnit = ElectricalUnit::UNIT_MVA;
140 } break;
141 }
142
143 if(!m_indMotor->DoubleFromString(m_parent, m_textCtrlActivePower->GetValue(), data.activePower,
144 _("Value entered incorrectly in the field \"Active power\".")))
145 return false;
146 switch(m_choiceActivePower->GetSelection()) {
147 case 0: {
148 data.activePowerUnit = ElectricalUnit::UNIT_PU;
149 } break;
150 case 1: {
151 data.activePowerUnit = ElectricalUnit::UNIT_W;
152 } break;
153 case 2: {
154 data.activePowerUnit = ElectricalUnit::UNIT_kW;
155 } break;
156 case 3: {
157 data.activePowerUnit = ElectricalUnit::UNIT_MW;
158 } break;
159 }
160
161 if(!m_indMotor->DoubleFromString(m_parent, m_textCtrlReactivePower->GetValue(), data.reactivePower,
162 _("Value entered incorrectly in the field \"Reactive power\".")))
163 return false;
164 switch(m_choiceReactivePower->GetSelection()) {
165 case 0: {
166 data.reactivePowerUnit = ElectricalUnit::UNIT_PU;
167 } break;
168 case 1: {
169 data.reactivePowerUnit = ElectricalUnit::UNIT_var;
170 } break;
171 case 2: {
172 data.reactivePowerUnit = ElectricalUnit::UNIT_kvar;
173 } break;
174 case 3: {
175 data.reactivePowerUnit = ElectricalUnit::UNIT_Mvar;
176 } break;
177 }
178
179 data.calcQInPowerFlow = m_checkBoxComputeQ->GetValue();
180 data.useMachinePowerAsBase = m_checkBoxUseMachinePower->GetValue();
181
182 // Stability
183 data.plotIndMachine = m_checkBoxPlotIndMachine->GetValue();
184 if(!m_indMotor->DoubleFromString(m_parent, m_textCtrlInertia->GetValue(), data.inertia,
185 _("Value entered incorrectly in the field \"Inertia\".")))
186 return false;
187 if(!m_indMotor->DoubleFromString(m_parent, m_textCtrlStatorResistence->GetValue(), data.r1,
188 _("Value entered incorrectly in the field \"Stator resistence\".")))
189 return false;
190 if(!m_indMotor->DoubleFromString(m_parent, m_textCtrlStatorReactance->GetValue(), data.x1,
191 _("Value entered incorrectly in the field \"Stator reactance\".")))
192 return false;
193 if(!m_indMotor->DoubleFromString(m_parent, m_textCtrlRotorResistence->GetValue(), data.r2,
194 _("Value entered incorrectly in the field \"Rotor resistence\".")))
195 return false;
196 if(!m_indMotor->DoubleFromString(m_parent, m_textCtrlRotorReactance->GetValue(), data.x2,
197 _("Value entered incorrectly in the field \"Rotor reactance\".")))
198 return false;
199 if(!m_indMotor->DoubleFromString(m_parent, m_textCtrlMagnetizingReactance->GetValue(), data.xm,
200 _("Value entered incorrectly in the field \"Magnetizing reactance\".")))
201 return false;
202 data.useKf = m_checkBoxUseKf->GetValue();
203 if(!m_indMotor->DoubleFromString(m_parent, m_textCtrlKf->GetValue(), data.kf,
204 _("Value entered incorrectly in the field \"Cage factor\".")))
205 return false;
206
207 if(!m_indMotor->DoubleFromString(m_parent, m_textCtrlA->GetValue(), data.aw,
208 _("Value entered incorrectly in the field \"Constant torque\".")))
209 return false;
210 if(!m_indMotor->DoubleFromString(m_parent, m_textCtrlB->GetValue(), data.bw,
211 _("Value entered incorrectly in the field \"Linear torque\".")))
212 return false;
213 if(!m_indMotor->DoubleFromString(m_parent, m_textCtrlC->GetValue(), data.cw,
214 _("Value entered incorrectly in the field \"Quadratic torque\".")))
215 return false;
216
217 double sum = data.aw + data.bw + data.cw;
218 double tolerance = 1e-4;
219 if(sum > (1.0 + tolerance) || sum < (1.0 - tolerance)) {
220 wxString errorMsg = _("The sum of the torque portions must be unitary.\nThe current value is ") +
221 m_indMotor->StringFromDouble(sum);
222 wxMessageDialog msgDialog(m_parent, errorMsg, _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
223 msgDialog.ShowModal();
224 return false;
225 }
226
227 m_indMotor->SetElectricalData(data);
228 return true;
229}
230void IndMotorForm::OnCheckboxUseCageFactorClick(wxCommandEvent& event) { UpdateFields(); }
231void IndMotorForm::OnCalcQInPFClick(wxCommandEvent& event) { UpdateFields(); }
232
233void IndMotorForm::UpdateFields()
234{
235 m_textCtrlKf->Enable(m_checkBoxUseKf->GetValue());
236 m_textCtrlReactivePower->Enable(!m_checkBoxComputeQ->GetValue());
237 m_choiceReactivePower->Enable(!m_checkBoxComputeQ->GetValue());
238}
static bool DoubleFromString(wxWindow *parent, wxString strValue, double &value, wxString errorMsg)
Get a double value from a string. Show a error message if the conversion fail.
Definition Element.cpp:505
static wxString StringFromDouble(double value, int minDecimal=1, int maxDecimals=13)
Convert a double value to string.
Definition Element.cpp:533
Induction motor power element.
Definition IndMotor.h:119
Form to edit the switching data of power elements for electromechanical transient studies.