-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSurr_opt.py
250 lines (183 loc) · 7.58 KB
/
Surr_opt.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 8 22:20:41 2022
@author: tufanakba
surrogate model integration to Brayton cycle model
"""
import openmdao.api as om
# import pycycle.api as pyc
# from py_Receiver import py_Receiver
# from components.comp_map import AXI5
# from components.MG3 import MG
from viewer import viewer, viewer2, map_plots, sankey
# from receiver import ReceiverSubProblem
from MDAOMetaModel_Opt import surrOpt
from MPComplex import MPComplex
import time
if __name__ == "__main__":
# Design conditions
# fn = 0.01
Q_Solar = 1000.
T_4 = 1000.
pwr_target = 170.
# generator = 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
# Design Param.s final
# L = 0.06644631131737304# m
# s_INS = 0.08473123540881979# m
# s_RPC = 0.00876963671886617# m
# # mass_flow = 0.0008255348001645682 #kg/s
prob = om.Problem()
mp_complex = prob.model = MPComplex()
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.Fn_target', fn, units='lbf')
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) #critical 2.15
prob.set_val('DESIGN.comp.eff', comp_eff)
prob.set_val('DESIGN.rec.Q_Solar_In', Q_Solar, units='W')
prob.set_val('DESIGN.turb.eff', turb_eff)
# prob.set_val('DESIGN.MG.P_el', -generator, units='W')
# Set initial guesses for balances
prob['DESIGN.balance.W'] = 0.00177#0.00122811 #147/100000
prob['DESIGN.balance.turb_PR'] = 4.463
# prob['DESIGN.balance.comp_PR'] = 4.489
prob['DESIGN.fc.balance.Pt'] = 14.6955113159
prob['DESIGN.fc.balance.Tt'] = 518.670 #518.665288153
for i,pt in enumerate(mp_complex.od_pts):
# initial guesses
prob[pt+'.balance.W'] = 0.00177
prob[pt+'.balance.Nmech'] = 15000
prob[pt+'.fc.balance.Pt'] = 14.6955113159
prob[pt+'.fc.balance.Tt'] = 518.670
prob[pt+'.turb.PR'] = 4.5
prob[pt+'.comp.PR'] = 4.5
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')
st = time.time()
prob.set_solver_print(level=-1)
prob.set_solver_print(level=2, depth=1)
prob.run_model()
print("time", time.time() - st)
st = time.time()
w_ini = mp_complex.get_val('DESIGN.inlet.Fl_O:stat:W', units='kg/s')
T_fluid_in = mp_complex.get_val('DESIGN.rec.rec.T_fluid_in', units='K')
diff = 1
limit = 0.001
sankey(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()
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()
# TODO: You shoul set the DESIGN vals in prob to p variables
# 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()
mp_complex = prob.model = MPComplex()
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.comp.PR', 5.2) #critical 2.15
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) #critical 2.15
prob.set_val('DESIGN.comp.eff', comp_eff)
prob.set_val('DESIGN.rec.Q_Solar_In', Q_Solar, units='W')
prob.set_val('DESIGN.turb.eff', turb_eff)
# Set initial guesses for balances
# prob['DESIGN.balance.FAR'] = 0.0175506829934
prob['DESIGN.balance.W'] = 0.00177#0.00122811 #147/100000
prob['DESIGN.balance.turb_PR'] = 4.463
# prob['DESIGN.balance.comp_PR'] = 5
prob['DESIGN.fc.balance.Pt'] = 14.6955113159
prob['DESIGN.fc.balance.Tt'] = 518.670 #518.665288153
for i,pt in enumerate(mp_complex.od_pts):
# initial guesses
prob[pt+'.balance.W'] = 0.00177
prob[pt+'.balance.Nmech'] = 15000
prob[pt+'.fc.balance.Pt'] = 14.6955113159
prob[pt+'.fc.balance.Tt'] = 518.670
prob[pt+'.turb.PR'] = 4.5
prob[pt+'.comp.PR'] = 4.5
prob[pt+'.comp.map.RlineMap'] = 2.0
# TODO: check this line
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(mp_complex.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(prob, 'DESIGN')
viewer2(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()
for pt in ['DESIGN']+mp_complex.od_pts:
viewer(prob, pt)
viewer2(prob, pt)
map_plots(prob, pt)
print()
print("time", time.time() - st)
print('shaft power [W]: ')
print(mp_complex.get_val('DESIGN.shaft.pwr_net', units='W'))
print('receiver outlet temperature [oC]:')
print(mp_complex.get_val('DESIGN.rec.Fl_O:tot:T', units='degC'))
print('mass flow rate [kg/s]:')
print(mp_complex.get_val('DESIGN.inlet.Fl_O:stat:W', units='kg/s'))