-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatent_solver.py
More file actions
429 lines (332 loc) · 14.9 KB
/
Copy pathpatent_solver.py
File metadata and controls
429 lines (332 loc) · 14.9 KB
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 31 14:34:26 2022
@author: tufanakba
patent solver
"""
import openmdao.api as om
from viewer_patent import viewer_generation, viewer_motoring
from patent import MPgeneration, MPmotoring
from MDAOMetaModel_Opt import surrOpt
from map_plotter3 import comp_map, turb_map
from mail import mail
import time
if __name__ == "__main__":
# Design cond.s
optn=False #Thickness optimization
Q_Solar = 1000.
T_4 = 1000.
pwr_target = 170.
alt = 0.000001
fc_MN = 1e-6
comp_eff = 0.83
turb_eff = 0.86
# Design Param.s start
# s_RPC = 0.01
# s_INS = 0.1
# L = 0.035
# optimized results (old)
# L = 0.07285836023878457
# s_INS = 0.09788381936713199
# s_RPC = 0.009487799245649634
# optimized results (new)
L = 0.07284367071677698
s_INS = 0.0975481552652269
s_RPC = 0.009827702728493431
# mass_flow = 0.000836789005063164 kg/s
prob = om.Problem()
# TODO: set od - change to true when generation below is simulated!..
gen_no_od = True
patent_cycle = prob.model = MPgeneration(No_od=gen_no_od)
prob.setup(check=False)
prob.set_val('DESIGN'+'.rec.rec.s_RPC', s_RPC, units='m')
prob.set_val('DESIGN'+'.rec.rec.s_INS', s_INS, units='m')
prob.set_val('DESIGN'+'.rec.rec.L', L, units='m')
#Define the design point
prob.set_val('DESIGN.fc.alt', alt, units='ft')
prob.set_val('DESIGN.fc.MN', fc_MN)
prob.set_val('DESIGN.balance.pwr_target', pwr_target, units='W')
prob.set_val('DESIGN.balance.T4_target', T_4, units='degC')
prob.set_val('DESIGN.comp.PR', 5.2)
prob.set_val('DESIGN.comp.eff', comp_eff)
prob.set_val('DESIGN.turb.eff', turb_eff)
prob.set_val('DESIGN.gen.eff', turb_eff)
prob.set_val('DESIGN.rec.Q_Solar_In', Q_Solar, units='W')
# initial guesses
prob['DESIGN.balance.W'] = 0.0018 #0.00122811 #147/100000
prob['DESIGN.balance.turb_PR'] = 2.
prob['DESIGN.balance.gen_PR'] = 2.3
# prob['DESIGN.balance.comp_PR'] = 4.489
prob['DESIGN.fc.balance.Pt'] = 14.696
prob['DESIGN.fc.balance.Tt'] = 518.670 #518.665288153
if not gen_no_od:
for i,pt in enumerate(patent_cycle.od_pts):
# initial guesses
prob[pt+'.balance.W'] = 0.0018
prob[pt+'.balance.Gen_Nmech'] = 15000
prob[pt+'.balance.Nmech'] = 25000
prob[pt+'.fc.balance.Pt'] = 14.696
prob[pt+'.fc.balance.Tt'] = 518.670
prob[pt+'.turb.PR'] = 2.
prob[pt+'.gen.PR'] = 2.3
prob[pt+'.comp.PR'] = 5.2
prob[pt+'.comp.map.RlineMap'] = 2.0
prob.set_val(pt+'.rec.rec.s_RPC', s_RPC, units='m')
prob.set_val(pt+'.rec.rec.s_INS', s_INS, units='m')
prob.set_val(pt+'.rec.rec.L', L, units='m')
prob.set_solver_print(level=-1)
prob.set_solver_print(level=2, depth=1)
st = time.time()
prob.run_model()
print("time", time.time() - st)
st = time.time()
w_ini = patent_cycle.get_val('DESIGN.inlet.Fl_O:stat:W', units='kg/s')
T_fluid_in = patent_cycle.get_val('DESIGN.rec.rec.T_fluid_in', units='K')
diff = 1
limit = 0.001
# sankey(prob,'DESIGN')
# viewer_generation(prob, 'DESIGN')
L_log=[]
s_INS_log=[]
s_RPC_log=[]
m_dot_log=[]
diff_log=[]
m_dot=float(w_ini)
L_log.append(L)
s_INS_log.append(s_INS)
s_RPC_log.append(s_RPC)
m_dot_log.append(m_dot)
prob.cleanup()
if optn:
while diff>limit:
p = om.Problem()
p.model.add_subsystem('receiver',
surrOpt(L=L, s_INS=s_INS, s_RPC=s_RPC)
,promotes=['*'])
p.setup()
# p.set_val('receiver.Q_Solar_In', Q_Solar, units='W')
p.set_val('m_dot', m_dot,units='kg/s')
p.set_val('Tfi',T_fluid_in, units='K')
p.final_setup()
p.run_model()
L = float(p.get_val('receiver.L', units='m'))
s_INS=float(p.get_val('receiver.ins', units='m'))
s_RPC=float(p.get_val('receiver.rpc', units='m'))
L_log.append(L)
s_INS_log.append(s_INS)
s_RPC_log.append(s_RPC)
print("time", time.time() - st)
st = time.time()
p.cleanup()
prob = om.Problem()
patent_cycle = prob.model = MPgeneration(No_od=True)
prob.setup(check=False)
prob.set_val('DESIGN'+'.rec.rec.s_RPC', s_RPC, units='m')
prob.set_val('DESIGN'+'.rec.rec.s_INS', s_INS, units='m')
prob.set_val('DESIGN'+'.rec.rec.L', L, units='m')
#Define the design point
prob.set_val('DESIGN.fc.alt', alt, units='ft')
prob.set_val('DESIGN.fc.MN', fc_MN)
prob.set_val('DESIGN.balance.pwr_target', pwr_target, units='W')
prob.set_val('DESIGN.balance.T4_target', T_4, units='degC')
prob.set_val('DESIGN.comp.PR', 5.2)
prob.set_val('DESIGN.comp.eff', comp_eff)
prob.set_val('DESIGN.turb.eff', turb_eff)
prob.set_val('DESIGN.gen.eff', turb_eff)
prob.set_val('DESIGN.rec.Q_Solar_In', Q_Solar, units='W')
# initial guesses
prob['DESIGN.balance.W'] = 0.0018 #0.00122811 #147/100000
prob['DESIGN.balance.turb_PR'] = 2.
prob['DESIGN.balance.gen_PR'] = 2.3
# prob['DESIGN.balance.comp_PR'] = 4.489
prob['DESIGN.fc.balance.Pt'] = 14.696
prob['DESIGN.fc.balance.Tt'] = 518.670 #518.665288153
# for i,pt in enumerate(patent_cycle.od_pts):
# # initial guesses
# prob[pt+'.balance.W'] = 0.00178
# prob[pt+'.balance.Gen_Nmech'] = 15000
# prob[pt+'.balance.Nmech'] = 25000
# prob[pt+'.fc.balance.Pt'] = 14.6955113159
# prob[pt+'.fc.balance.Tt'] = 518.670
# prob[pt+'.turb.PR'] = 1.8
# prob[pt+'.gen.PR'] = 2.3
# prob[pt+'.comp.PR'] = 4.
# prob[pt+'.comp.map.RlineMap'] = 2.0
# prob.set_val(pt+'.rec.rec.s_RPC', s_RPC, units='m')
# prob.set_val(pt+'.rec.rec.s_INS', s_INS, units='m')
# prob.set_val(pt+'.rec.rec.L', L, units='m')
prob.set_solver_print(level=-1)
prob.set_solver_print(level=2, depth=1)
prob.run_model()
m_dot=float(patent_cycle.get_val('DESIGN.inlet.Fl_O:stat:W', units='kg/s'))
m_dot_log.append(m_dot)
print("time", time.time() - st)
st = time.time()
# sankey(prob,'DESIGN')
# viewer_generation(prob, 'DESIGN')
w = m_dot
diff=abs(1-w/w_ini)
w_ini=w
diff_log.append(diff)
print(f"L = {float(prob.get_val('DESIGN.rec.rec.L', units='m'))} m")
print(f"INS = {float(prob.get_val('DESIGN.rec.rec.s_INS', units='m'))} m ")
print(f"RPC = {float(prob.get_val('DESIGN.rec.rec.s_RPC', units='m'))} m")
print(f"mass_flow = {w} kg/s")
if diff>limit:
prob.cleanup()
# Generation after optimization
prob = om.Problem()
# TODO: set od
gen_no_od = False
patent_cycle = prob.model = MPgeneration(No_od=gen_no_od)
prob.setup(check=False)
prob.set_val('DESIGN'+'.rec.rec.s_RPC', s_RPC, units='m')
prob.set_val('DESIGN'+'.rec.rec.s_INS', s_INS, units='m')
prob.set_val('DESIGN'+'.rec.rec.L', L, units='m')
#Define the design point
prob.set_val('DESIGN.fc.alt', alt, units='ft')
prob.set_val('DESIGN.fc.MN', fc_MN)
prob.set_val('DESIGN.balance.pwr_target', pwr_target, units='W')
prob.set_val('DESIGN.balance.T4_target', T_4, units='degC')
prob.set_val('DESIGN.comp.PR', 5.2)
prob.set_val('DESIGN.comp.eff', comp_eff)
prob.set_val('DESIGN.turb.eff', turb_eff)
prob.set_val('DESIGN.gen.eff', turb_eff)
prob.set_val('DESIGN.rec.Q_Solar_In', Q_Solar, units='W')
# initial guesses
prob['DESIGN.balance.W'] = 0.0018 #0.00122811 #147/100000
prob['DESIGN.balance.turb_PR'] = 1.8
prob['DESIGN.balance.gen_PR'] = 2.3
# prob['DESIGN.balance.comp_PR'] = 4.489
prob['DESIGN.fc.balance.Pt'] = 14.696
prob['DESIGN.fc.balance.Tt'] = 518.670 #518.665288153
if not gen_no_od:
for i,pt in enumerate(patent_cycle.od_pts):
# initial guesses
prob[pt+'.balance.W'] = 0.0018
prob[pt+'.balance.Gen_Nmech'] = 15000
prob[pt+'.balance.Nmech'] = 25000
prob[pt+'.fc.balance.Pt'] = 14.696
prob[pt+'.fc.balance.Tt'] = 518.670
prob[pt+'.turb.PR'] = 2.
prob[pt+'.gen.PR'] = 2.3
prob[pt+'.comp.PR'] = 5.2
prob[pt+'.comp.map.RlineMap'] = 2.0
prob.set_val(pt+'.rec.rec.s_RPC', s_RPC, units='m')
prob.set_val(pt+'.rec.rec.s_INS', s_INS, units='m')
prob.set_val(pt+'.rec.rec.L', L, units='m')
prob.set_solver_print(level=-1)
prob.set_solver_print(level=2, depth=1)
st = time.time()
prob.run_model()
print("time", time.time() - st)
st = time.time()
# motoring class
comp_s_PR = float(prob.get_val('DESIGN.comp.s_PR'))
comp_s_Wc = float(prob.get_val('DESIGN.comp.s_Wc'))
comp_s_eff = float(prob.get_val('DESIGN.comp.s_eff'))
comp_s_Nc = float(prob.get_val('DESIGN.comp.s_Nc'))
comp_area = float(prob.get_val('DESIGN.comp.Fl_O:stat:area'))
turb_s_PR = float(prob.get_val('DESIGN.turb.s_PR'))
turb_s_Wp = float(prob.get_val('DESIGN.turb.s_Wp'))
turb_s_eff = float(prob.get_val('DESIGN.turb.s_eff'))
turb_s_Np = float(prob.get_val('DESIGN.turb.s_Np'))
turb_area = float(prob.get_val('DESIGN.turb.Fl_O:stat:area'))
L = float(prob.get_val('DESIGN.rec.rec.L', units='m'))
s_INS=float(prob.get_val('DESIGN.rec.rec.s_INS', units='m'))
s_RPC=float(prob.get_val('DESIGN.rec.rec.s_RPC', units='m'))
rec_area = float(prob.get_val('DESIGN.rec.Fl_O:stat:area'))
prob_m = om.Problem()
# TODO: set od.s
motoring_no_od = True
motoring_cycle = prob_m.model = MPmotoring(No_od=motoring_no_od)
prob_m.setup(check=False)
prob_m.set_val('DESIGN.fc.alt', alt, units='ft')
prob_m.set_val('DESIGN.fc.MN', fc_MN)
motor_power = -50
Q_solar_motor = 1000
# assign generating cycle parameters
prob_m.set_val('DESIGN.balance.pwr_target', motor_power, units='W')
prob_m.set_val('DESIGN.balance.T4_target', T_4, units='degC')
# prob_m.set_val('DESIGN.comp.PR', 2.)
prob_m.set_val('DESIGN.comp.eff', comp_eff)
prob_m.set_val('DESIGN.motor.eff', comp_eff)
prob_m.set_val('DESIGN.turb.eff', turb_eff)
prob_m.set_val('DESIGN.rec.Q_Solar_In', Q_solar_motor, units='W')
# od data
prob_m.set_val('DESIGN.comp.s_PR', comp_s_PR)
prob_m.set_val('DESIGN.comp.s_Wc', comp_s_Wc)
prob_m.set_val('DESIGN.comp.s_eff', comp_s_eff)
prob_m.set_val('DESIGN.comp.s_Nc', comp_s_Nc)
prob_m.set_val('DESIGN.comp.area', comp_area, units='inch**2')
prob_m.set_val('DESIGN.turb.s_PR', turb_s_PR)
prob_m.set_val('DESIGN.turb.s_Wp', turb_s_Wp)
prob_m.set_val('DESIGN.turb.s_eff', turb_s_eff)
prob_m.set_val('DESIGN.turb.s_Np', turb_s_Np)
prob_m.set_val('DESIGN.turb.area', turb_area, units='inch**2')
prob_m.set_val('DESIGN.rec.rec.s_RPC', s_RPC)
prob_m.set_val('DESIGN.rec.rec.s_INS', s_INS)
prob_m.set_val('DESIGN.rec.rec.L', L)
prob_m.set_val('DESIGN.rec.area', rec_area, units='inch**2')
# initial guesses
prob_m['DESIGN.balance.W'] = 0.00118 #0.00122811 #147/100000
prob_m['DESIGN.balance.Nmech'] = 15000
# prob_m['DESIGN.balance.motor_PR'] = 2.0
prob_m['DESIGN.fc.balance.Pt'] = 14.696
prob_m['DESIGN.fc.balance.Tt'] = 518.670 #518.665288153
# od for motoring
if not motoring_no_od:
for i,pt in enumerate(motoring_cycle.od_pts):
# initial guesses
prob_m[pt+'.balance.W'] = 0.0018
prob_m[pt+'.balance.Gen_Nmech'] = 15000
prob_m[pt+'.balance.Nmech'] = 25000
prob_m[pt+'.fc.balance.Pt'] = 14.696
prob_m[pt+'.fc.balance.Tt'] = 518.670
prob_m[pt+'.turb.PR'] = 1.7
prob_m[pt+'.motor.PR'] = 1.7
prob_m[pt+'.comp.PR'] = 3.
prob_m[pt+'.comp.map.RlineMap'] = 2.
prob_m.set_val(pt+'.rec.rec.s_RPC', s_RPC, units='m')
prob_m.set_val(pt+'.rec.rec.s_INS', s_INS, units='m')
prob_m.set_val(pt+'.rec.rec.L', L, units='m')
prob_m.set_val(pt+'.turb.s_PR', turb_s_PR)
prob_m.set_val(pt+'.turb.s_Wp', turb_s_Wp)
prob_m.set_val(pt+'.turb.s_eff', turb_s_eff)
prob_m.set_val(pt+'.turb.s_Np', turb_s_Np)
# prob_m.set_val('DESIGN.turb.Fl_O:stat:area', turb_area)
prob_m.set_val(pt+'.turb.area', turb_area,units='inch**2')
prob_m.set_val(pt+'.comp.s_PR', comp_s_PR)
prob_m.set_val(pt+'.comp.s_Wc', comp_s_Wc)
prob_m.set_val(pt+'.comp.s_eff', comp_s_eff)
prob_m.set_val(pt+'.comp.s_Nc', comp_s_Nc)
# prob_m.set_val('DESIGN.comp.Fl_O:stat:area', comp_area)
prob_m.set_val(pt+'.comp.area', comp_area,units='inch**2')
prob_m.set_val(pt+'.rec.area', rec_area, units='inch**2')
prob_m.set_solver_print(level=-1)
prob_m.set_solver_print(level=2, depth=1)
st = time.time()
prob_m.run_model()
print("time", time.time() - st)
viewer_generation(prob, 'DESIGN')
viewer_motoring(prob_m, 'DESIGN')
if not gen_no_od:
for pt in patent_cycle.od_pts:
viewer_generation(prob, pt)
comp_map(prob,gen=True)
turb_map(prob,gen=True)
if not motoring_no_od:
for pt in motoring_cycle.od_pts:
viewer_motoring(prob_m, pt)
comp_map(prob_m,gen=False)
turb_map(prob_m,gen=False)
print()
print("time", time.time() - st)
mail('')
print('shaft power [W]: ')
print(patent_cycle.get_val('DESIGN.LPshaft.pwr_net', units='W'))
print('receiver outlet temperature [oC]:')
print(patent_cycle.get_val('DESIGN.rec.Fl_O:tot:T', units='degC'))
print('mass flow rate [kg/s]:')
print(patent_cycle.get_val('DESIGN.inlet.Fl_O:stat:W', units='kg/s'))