forked from OpenMDAO/zappy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhendricks_tiltwing.py
308 lines (216 loc) · 15 KB
/
hendricks_tiltwing.py
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
from zappy.LF_elements.line import DCline
from zappy.LF_elements.generator import ACgenerator
from zappy.LF_elements.load import ACload, DCload
from zappy.LF_elements.bus import ACbus, DCbus
from zappy.LF_elements.converter import Converter
from zappy.LF_elements.inverter import Inverter
from zappy.LF_elements.rectifier import Rectifier
import openmdao.api as om
from openmdao.api import DirectSolver, BoundsEnforceLS, NewtonSolver
import time
import math, cmath
# Define scaling values
Vacbase = 540
Powerbase = 2e6
class TiltwingExample(om.Group):
"""
This class is an example to test Zappy implementation, and is from "Load Flow Analysis with Analytic Derivatives for Electric Aircraft Design Optimization" by Hendricks et al.
"""
def initialize(self):
self.options.declare('num_nodes', types=int)
def setup(self):
nn = self.options['num_nodes']
IVC = self.add_subsystem('IVC', om.IndepVarComp(), promotes=['*'])
# INPUTS AND SETUP FOR LINES ----------------------------------------
IVC.add_output('R5_6', 0.0029856, units='ohm')
IVC.add_output('R6_9', 0.0028224, units='ohm')
IVC.add_output('R7_8', 0.0029856, units='ohm')
IVC.add_output('R7_9', 0.0028224, units='ohm')
IVC.add_output('R5_9', 0.00576, units='ohm')
IVC.add_output('R8_9', 0.00576, units='ohm')
IVC.add_output('R6_7', 0.00528, units='ohm')
IVC.add_output('R9_11', 0.0048, units='ohm')
self.add_subsystem('Line5_6', DCline(num_nodes=nn), promotes=[('R','R5_6'), ('V_in', 'V_5'), ('V_out', 'V_6'), ('I_in', 'L5_6:I'), ('I_out', 'L6_5:I')])
self.add_subsystem('Line6_7', DCline(num_nodes=nn), promotes=[('R','R6_7'), ('V_in', 'V_6'), ('V_out', 'V_7'), ('I_in', 'L6_7:I'), ('I_out', 'L7_6:I')])
self.add_subsystem('Line7_8', DCline(num_nodes=nn), promotes=[('R','R7_8'), ('V_in', 'V_7'), ('V_out', 'V_8'), ('I_in', 'L7_8:I'), ('I_out', 'L8_7:I')])
self.add_subsystem('Line5_9', DCline(num_nodes=nn), promotes=[('R','R5_9'), ('V_in', 'V_5'), ('V_out', 'V_9'), ('I_in', 'L5_9:I'), ('I_out', 'L9_5:I')])
self.add_subsystem('Line6_9', DCline(num_nodes=nn), promotes=[('R','R6_9'), ('V_in', 'V_6'), ('V_out', 'V_9'), ('I_in', 'L6_9:I'), ('I_out', 'L9_6:I')])
self.add_subsystem('Line7_9', DCline(num_nodes=nn), promotes=[('R','R7_9'), ('V_in', 'V_7'), ('V_out', 'V_9'), ('I_in', 'L7_9:I'), ('I_out', 'L9_7:I')])
self.add_subsystem('Line8_9', DCline(num_nodes=nn), promotes=[('R','R8_9'), ('V_in', 'V_8'), ('V_out', 'V_9'), ('I_in', 'L8_9:I'), ('I_out', 'L9_8:I')])
self.add_subsystem('Line9_11', DCline(num_nodes=nn), promotes=[('R','R9_11'), ('V_in', 'V_9'), ('V_out', 'V_11'), ('I_in', 'L9_11:I'), ('I_out', 'L11_9:I')])
# INPUTS AND SETUP FOR GENERATORS ----------------------------------
# AC Generator
IVC.add_output('Vm_ac_bus1', 540, units='V')
IVC.add_output('thetaV_ac_bus1', 0, units='deg')
self.add_subsystem('ACGen1', ACgenerator(num_nodes=nn, mode='Slack', Vbase = Vacbase, Sbase=Powerbase),
promotes=[('Vm_bus','Vm_ac_bus1'), ('thetaV_bus','thetaV_ac_bus1'),
('Vr_out','Vr_10'), ('Vi_out','Vi_10'),
('Ir_out','LG1:Ir'), ('Ii_out','LG1:Ii')])
# INPUTS AND SETUP FOR LOADS ------------------------------------------
IVC.add_output('P1', 565000, units='W')
IVC.add_output('Q1', 185706.5, units='W')
IVC.add_output('P2', 565000, units='W')
IVC.add_output('Q2', 185706.5, units='W')
IVC.add_output('P3', 565000, units='W')
IVC.add_output('Q3', 185706.5, units='W')
IVC.add_output('P4', 565000, units='W')
IVC.add_output('Q4', 185706.5, units='W')
IVC.add_output('Paux', 2000, units='W')
self.add_subsystem('Load1', ACload(num_nodes=nn),
promotes=[('P','P1'), ('Q','Q1'), # this has some real and imaginary (reactive) load
('Vr_in','Vr_1'), ('Vi_in','Vi_1'), # This is connected to this bus voltage
('Ir_in','LL1:Ir'),('Ii_in','LL1:Ii')]) # this is connected to the same bus current
self.add_subsystem('Load2', ACload(num_nodes=nn),
promotes=[('P','P2'), ('Q','Q2'),
('Vr_in','Vr_2'), ('Vi_in','Vi_2'),
('Ir_in','LL2:Ir'),('Ii_in','LL2:Ii')])
self.add_subsystem('Load3', ACload(num_nodes=nn),
promotes=[('P','P3'), ('Q','Q3'),
('Vr_in','Vr_3'), ('Vi_in','Vi_3'),
('Ir_in','LL3:Ir'),('Ii_in','LL3:Ii')])
self.add_subsystem('Load4', ACload(num_nodes=nn),
promotes=[('P','P4'), ('Q','Q4'),
('Vr_in','Vr_4'), ('Vi_in','Vi_4'),
('Ir_in','LL4:Ir'),('Ii_in','LL4:Ii')])
self.add_subsystem('AuxLoad', DCload(num_nodes=nn),
promotes=[('P','Paux'), ('V_in','V_11'), ('I_in','LL11dc:I')])
# INPUTS AND SETUP FOR BUSES (note the * is a glob to promote both real and imaginary components for AC lines)
self.add_subsystem('Bus10', ACbus(num_nodes=nn, lines=['LG1', 'LR1'], Vbase=Vacbase, Sbase=Powerbase),
promotes=[('Vr', 'Vr_10'), ('Vi', 'Vi_10'), 'LG1:*', 'LR1:*'])
self.add_subsystem('Bus11', DCbus(num_nodes=nn, lines=['LL11dc', 'L11_9'], Vbase=Vacbase, Sbase=Powerbase),
promotes=[('V', 'V_11'), 'LL11dc:*', 'L11_9:*'])
self.add_subsystem('Bus9', DCbus(num_nodes=nn, lines=['L9_11', 'LR1dc', 'L9_8', 'L9_7', 'L9_6', 'L9_5'],
Vbase=Vacbase, Sbase=Powerbase),
promotes=[('V', 'V_9'), 'LR1dc:*', 'L9_11:*', 'L9_8:*', 'L9_7:*', 'L9_6:*', 'L9_5:*'])
self.add_subsystem('Bus8', DCbus(num_nodes=nn, lines=['L8_9', 'L8_7', 'LI4dc'], Vbase=Vacbase, Sbase=Powerbase),
promotes=[('V', 'V_8'), 'L8_9:*', 'L8_7:*', 'LI4dc:*'])
self.add_subsystem('Bus7', DCbus(num_nodes=nn, lines=['L7_8', 'L7_6', 'LI3dc', 'L7_9'], Vbase=Vacbase, Sbase=Powerbase),
promotes=[('V', 'V_7'), 'L7_8:*', 'L7_6:*', 'LI3dc:*', 'L7_9:*'])
self.add_subsystem('Bus6', DCbus(num_nodes=nn, lines=['L6_7', 'L6_5', 'LI2dc', 'L6_9'], Vbase=Vacbase, Sbase=Powerbase),
promotes=[('V', 'V_6'), 'L6_7:*', 'L6_5:*', 'LI2dc:*', 'L6_9:*'])
self.add_subsystem('Bus5', DCbus(num_nodes=nn, lines=['L5_6', 'L5_9', 'LI1dc'], Vbase=Vacbase, Sbase=Powerbase),
promotes=[('V', 'V_5'), 'L5_6:*', 'L5_9:*', 'LI1dc:*'])
self.add_subsystem('Bus4', ACbus(num_nodes=nn, lines=['LI4', 'LL4'], Vbase=Vacbase, Sbase=Powerbase),
promotes=[('Vr', 'Vr_4'), ('Vi', 'Vi_4'), 'LI4:*', 'LL4:*'])
self.add_subsystem('Bus3', ACbus(num_nodes=nn, lines=['LI3', 'LL3'], Vbase=Vacbase, Sbase=Powerbase),
promotes=[('Vr', 'Vr_3'), ('Vi', 'Vi_3'), 'LI3:*', 'LL3:*'])
self.add_subsystem('Bus2', ACbus(num_nodes=nn, lines=['LI2', 'LL2'], Vbase=Vacbase, Sbase=Powerbase),
promotes=[('Vr', 'Vr_2'), ('Vi', 'Vi_2'), 'LI2:*', 'LL2:*'])
self.add_subsystem('Bus1', ACbus(num_nodes=nn, lines=['LI1', 'LL1'], Vbase=Vacbase, Sbase=Powerbase),
promotes=[('Vr', 'Vr_1'), ('Vi', 'Vi_1'), 'LI1:*', 'LL1:*'])
# INPUTS AND SETUP FOR RECTIFIERS AND INVERTERS -------------------------------------------------
# note: using inverter and rectifier classes instead of converter (which is what the example uses)
IVC.add_output('M_rect', 0.99) # rectifier modulation index
IVC.add_output('eff_rect', 0.98) # rectifier efficiency
IVC.add_output('PF_rect', 0.99) # rectifier power factor
IVC.add_output('M_inv', 0.99) # inverter modulation index
IVC.add_output('eff_inv', 0.98) # inverter efficiency
IVC.add_output('thetaV', 0.0) # output phase angle for inverters
self.add_subsystem('Rect1', Rectifier(num_nodes=nn, Vbase=Vacbase, Sbase=Powerbase), promotes=[('M', 'M_rect'), ('eff', 'eff_inv'), ('PF', 'PF_rect'), ('Vr_ac', 'Vr_10'), ('Vi_ac', 'Vi_10'), ('Ir_ac', 'LR1:Ir'), ('Ii_ac', 'LR1:Ii'), ('V_dc', 'V_9'), ('I_dc', 'LR1dc:I')])
self.add_subsystem('Inv1', Inverter(num_nodes=nn, mode='Phase', Vbase=Vacbase, Sbase=Powerbase), promotes=[('M', 'M_inv'), ('eff', 'eff_inv'), ('thetaV_target', 'thetaV'), ('Vr_ac', 'Vr_1'), ('Vi_ac', 'Vi_1'), ('Ir_ac', 'LI1:Ir'), ('Ii_ac', 'LI1:Ii'), ('V_dc', 'V_5'), ('I_dc', 'LI1dc:I')])
self.add_subsystem('Inv2', Inverter(num_nodes=nn, mode='Phase', Vbase=Vacbase, Sbase=Powerbase), promotes=[('M', 'M_inv'), ('eff', 'eff_inv'), ('thetaV_target', 'thetaV'), ('Vr_ac', 'Vr_2'), ('Vi_ac', 'Vi_2'), ('Ir_ac', 'LI2:Ir'), ('Ii_ac', 'LI2:Ii'), ('V_dc', 'V_6'), ('I_dc', 'LI2dc:I')])
self.add_subsystem('Inv3', Inverter(num_nodes=nn, mode='Phase', Vbase=Vacbase, Sbase=Powerbase), promotes=[('M', 'M_inv'), ('eff', 'eff_inv'), ('thetaV_target', 'thetaV'), ('Vr_ac', 'Vr_3'), ('Vi_ac', 'Vi_3'), ('Ir_ac', 'LI3:Ir'), ('Ii_ac', 'LI3:Ii'), ('V_dc', 'V_7'), ('I_dc', 'LI3dc:I')])
self.add_subsystem('Inv4', Inverter(num_nodes=nn, mode='Phase', Vbase=Vacbase, Sbase=Powerbase), promotes=[('M', 'M_inv'), ('eff', 'eff_inv'), ('thetaV_target', 'thetaV'), ('Vr_ac', 'Vr_4'), ('Vi_ac', 'Vi_4'), ('Ir_ac', 'LI4:Ir'), ('Ii_ac', 'LI4:Ii'), ('V_dc', 'V_8'), ('I_dc', 'LI4dc:I')])
# note: archived below, which was implementation using the converter component structure; did not work, and does not provide the flexibility that inverter/rectifier provide
# note: mode = 'lead' corresponds to rectifier, mode = 'lag' corresponds to inverter
# self.add_subsystem('Rect1', Converter(num_nodes=nn, mode='Lead', Vdcbase=Vacbase, Sbase=Powerbase),
# promotes=[('M', 'M_rect'), ('eff', 'eff_rect'), ('PF', 'PF_rect'),
# ('Vr_ac', 'Vr_10'), ('Vi_ac', 'Vi_10'),
# ('Ir_ac', 'LR1:Ir'), ('Ii_ac', 'LR1:Ii'),
# ('V_dc', 'V_9'),
# ('I_dc', 'LR1dc:I')])
# self.add_subsystem('Inv1', Converter(num_nodes=nn, mode='Lag', Vdcbase=Vacbase, Sbase=Powerbase),
# promotes=[('M', 'M_inv'), ('eff', 'eff_inv'),
# ('Vr_ac', 'Vr_1'), ('Vi_ac', 'Vi_1'),
# ('Ir_ac', 'LI1:Ir'), ('Ii_ac', 'LI1:Ii'),
# ('V_dc', 'V_5'),
# ('I_dc', 'LI1dc:I')])
# self.add_subsystem('Inv2', Converter(num_nodes=nn, mode='Lag', Vdcbase=Vacbase, Sbase=Powerbase),
# promotes=[('M', 'M_inv'), ('eff', 'eff_inv'),
# ('Vr_ac', 'Vr_2'), ('Vi_ac', 'Vi_2'),
# ('Ir_ac', 'LI2:Ir'), ('Ii_ac', 'LI2:Ii'),
# ('V_dc', 'V_6'),
# ('I_dc', 'LI2dc:I')])
# self.add_subsystem('Inv3', Converter(num_nodes=nn, mode='Lag', Vdcbase=Vacbase, Sbase=Powerbase),
# promotes=[('M', 'M_inv'), ('eff', 'eff_inv'),
# ('Vr_ac', 'Vr_3'), ('Vi_ac', 'Vi_3'),
# ('Ir_ac', 'LI3:Ir'), ('Ii_ac', 'LI3:Ii'),
# ('V_dc', 'V_7'),
# ('I_dc', 'LI3dc:I')])
# self.add_subsystem('Inv4', Converter(num_nodes=nn, mode='Lag', Vdcbase=Vacbase, Sbase=Powerbase),
# promotes=[('M', 'M_inv'), ('eff', 'eff_inv'),
# ('Vr_ac', 'Vr_4'), ('Vi_ac', 'Vi_4'),
# ('Ir_ac', 'LI4:Ir'), ('Ii_ac', 'LI4:Ii'),
# ('V_dc', 'V_8'),
# ('I_dc', 'LI4dc:I')])
# SET SOLVER OPTIONS FOR SYSTEM ----------------------------------------------------------------
newton = self.nonlinear_solver = NewtonSolver()
newton.options['atol'] = 1e-4
newton.options['rtol'] = 1e-4
newton.options['iprint'] = 2
newton.options['maxiter'] = 100
newton.options['solve_subsystems'] = True
newton.options['max_sub_solves'] = 3
newton.linesearch = BoundsEnforceLS()
newton.linesearch.options['bound_enforcement'] = 'scalar'
newton.linesearch.options['print_bound_enforce'] = True
newton.linesearch.options['iprint'] = -1
self.linear_solver = DirectSolver(assemble_jac=True)
if __name__ == "__main__":
from openmdao.api import Problem
prob = Problem()
prob.model.add_subsystem('tiltwing', TiltwingExample(num_nodes=1), promotes=['*'])
prob.set_solver_print(level=-1)
prob.set_solver_print(level=2, depth=2)
prob.setup()
prob.final_setup()
Vdcbase = 500
# Initialize guesses for the voltages at each bus
# AC Buses
prob['Vr_1'] = Vacbase
prob['Vi_1'] = 0.0
prob['Vr_2'] = Vacbase
prob['Vi_2'] = 0.0
prob['Vr_3'] = Vacbase
prob['Vi_3'] = 0.0
prob['Vr_4'] = Vacbase
prob['Vi_4'] = 0.0
prob['Vr_10'] = Vacbase
prob['Vi_10'] = 0.0
# DC Buses
prob['V_5'] = Vdcbase
prob['V_6'] = Vdcbase
prob['V_7'] = Vdcbase
prob['V_8'] = Vdcbase
prob['V_9'] = Vdcbase
prob['V_11'] = Vdcbase
# Initialize guesses for the loads at the generator and converters
Gen_guess = 2e6
P_guess = .2e6
prob['ACGen1.P_guess'] = Gen_guess
# Need to make initial guess for DC power leaving the rectifier
prob['Rect1.P_dc'] = -P_guess
# Need to make initial guesses for the AC power leaving the inverter
prob['Inv1.P_ac'] = -P_guess
prob['Inv2.P_ac'] = -P_guess
prob['Inv3.P_ac'] = -P_guess
prob['Inv4.P_ac'] = -P_guess
st = time.time()
prob.run_model()
def print_phasor(name, x, y):
r, phi = cmath.polar(complex(x,y))
print(name, r, '(V) <', math.degrees(phi), '(degrees)')
# AC Buses:
print_phasor('V1:', prob['Vr_1'], prob['Vi_1'])
print_phasor('V2:', prob['Vr_2'], prob['Vi_2'])
print_phasor('V3:', prob['Vr_3'], prob['Vi_3'])
print_phasor('V4:', prob['Vr_4'], prob['Vi_4'])
print_phasor('V10:', prob['Vr_10'], prob['Vi_10'])
# DC Buses:
print('V5:', prob['V_5'][0])
print('V6:', prob['V_6'][0])
print('V7:', prob['V_7'][0])
print('V8:', prob['V_8'][0])
print('V9:', prob['V_9'][0])
print('V11:', prob['V_11'][0])
print("time", time.time() - st)