/[ascend]/trunk/models/johnpye/fprops/cycle_plot.py
ViewVC logotype

Contents of /trunk/models/johnpye/fprops/cycle_plot.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2698 - (show annotations) (download) (as text)
Wed Mar 13 23:24:23 2013 UTC (9 years, 5 months ago) by jpye
File MIME type: text/x-python
File size: 15015 byte(s)
Trying to merge cycle_plot_rachel.py into cycle_plot.py. 
Some improvements to cycle plot of the brayton_regen and brayton_regen_reheat_intercool cycle plots to include heat exchanger dotted lines.
1 # -*- coding: utf8 -*-
2 import extpy, sys
3 from solverreporter import *
4 from __builtin__ import *
5
6 import sys, os, os.path
7 sys.path.append(os.path.expanduser("~/ascend/models/johnpye/fprops/python"))
8 import fprops
9
10 try:
11 from pylab import *
12 except:
13 pass
14
15 #--- for (T,s) plots ---
16
17 def sat_curve(D):
18 Tt = D.T_t
19 Tc = D.T_c
20 TT = []
21 pp = []
22 ssf = []
23 ssg = []
24 for T in linspace(Tt,Tc,100):
25 # TODO this is inefficient because of repeated saturation solutions.
26 SF = D.set_Tx(T,0)
27 SG = D.set_Tx(T,1)
28 TT.append(SF.T - 273.15)
29 pp.append(SF.p)
30 ssf.append(SF.s/1.e3)
31 ssg.append(SG.s/1.e3)
32 plot(ssf,TT,"b--")
33 plot(ssg,TT,"r--")
34
35 class TSPoint:
36 def __init__(self,T,s):
37 self.T = T
38 self.s = s
39
40 def write(msg):
41 extpy.getbrowser().reporter.reportNote(msg)
42
43 def pconst(S1,S2,n):
44 """Return a set of (T,s) points between two states, with pressure held constant."""
45 D = fprops.fluid(str(S1.cd.component.getSymbolValue()))
46 out = []
47 hh = linspace(float(S1.h), float(S2.h), n)
48 for h in hh:
49 S = D.set_ph(float(S1.p), h)
50 out += [TSPoint(S.T,S.s)]
51 return out
52
53
54 def plot_Ts(SS,style='b-'):
55 xx = []
56 yy = []
57 for S in SS:
58 yy.append(float(S.T) - 273.15)
59 xx.append(float(S.s)/1.e3)
60 plot(xx,yy,style)
61
62 #--- for (T,H) plots ---
63
64 class THPoint:
65 def __init__(self,T,h,mdot = 1.):
66 self.T = T
67 self.h = h
68 self.mdot = mdot
69
70 def pconsth(S1,S2,n):
71 """Return a set of (T,H) points between two states, with pressure constant"""
72 D = fprops.fluid(str(S1.cd.component.getSymbolValue()))
73 out = []
74 hh = linspace(float(S1.h), float(S2.h), n)
75 mdot = float(S1.mdot)
76 for h in hh:
77 # TODO add try/except
78 S = D.set_ph(float(S1.p),h)
79 out += [THPoint(S.T,h * mdot)]
80 return out
81
82 def plot_TH(SS,style='b-',Href = 0):
83 xx = []
84 yy = []
85 for S in SS:
86 yy.append(float(S.T) - 273.15)
87 xx.append(((float(S.h)*float(S.mdot)) - Href)/1.e6)
88 plot(xx,yy,style)
89
90 #--- various Rankine cycle configurations ---
91
92 def cycle_plot_rankine(self):
93 """Plot T-s diagram for a simple Rankine cycle"""
94 import loading
95 loading.load_matplotlib(throw=True)
96 ioff()
97 figure()
98 hold(1)
99 D = fprops.fluid(str(self.cd.component.getSymbolValue()))
100 sat_curve(D)
101
102 boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)
103 condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
104 SS = [self.PU.outlet, self.BO.inlet] + boiler_curve + [self.TU.inlet, self.TU.outlet] + condenser_curve + [self.CO.outlet, self.PU.outlet]
105 plot_Ts(SS)
106
107 title(unicode(r"Rankine cycle with %s" % D.name))
108 ylabel(unicode(r"T / [��C]"))
109 aa = axis(); axis([aa[0],aa[1],-100,600])
110 xlabel("s / [kJ/kg/K]")
111
112 extpy.getbrowser().reporter.reportNote("Plotting completed")
113 ion()
114 show()
115 #savefig(os.path.expanduser("~/Desktop/rankine.eps"))
116
117 def cycle_plot_rankine_reheat(self):
118 """Plot T-s diagram for a reheat Rankine cycle"""
119 import loading
120 loading.load_matplotlib(throw=True)
121 ioff()
122 figure()
123 hold(1)
124 D = fprops.fluid(str(self.cd.component.getSymbolValue()))
125 sat_curve(D)
126
127 boiler1_curve = pconst(self.BO1.inlet, self.BO1.outlet,100)
128 boiler2_curve = pconst(self.BO2.inlet, self.BO2.outlet,50)
129 condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
130 SS = [self.PU.outlet, self.BO1.inlet] + \
131 boiler1_curve + [self.TU1.inlet, self.TU1.outlet] + \
132 boiler2_curve + [self.TU2.inlet, self.TU2.outlet] + \
133 condenser_curve + [self.CO.outlet, self.PU.outlet]
134 plot_Ts(SS)
135
136 plot_Ts(
137 [self.PU.inlet, self.BO1.inlet, self.TU1.inlet, self.BO2.inlet
138 ,self.TU2.inlet, self.CO.inlet]
139 ,'bo'
140 )
141
142 title(unicode(r"Reheat Rankine cycle with %s" % D.name))
143 ylabel(unicode(r"T / [��C]"))
144 aa = axis(); axis([aa[0],aa[1],-100,600])
145 xlabel("s / [kJ/kg/K]")
146
147 extpy.getbrowser().reporter.reportNote("Plotting completed")
148 ion()
149 show()
150 #savefig(os.path.expanduser("~/Desktop/rankine-reheat.eps"))
151
152 def cycle_plot_rankine_regen2(self):
153 """Plot T-s diagram for a regenerative Rankine cycle (bleed steam regen)"""
154 import loading
155 loading.load_matplotlib(throw=True)
156 ioff()
157 figure()
158 hold(1)
159 D = fprops.fluid(str(self.cd.component.getSymbolValue()))
160 sat_curve(D)
161
162 boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)
163 condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
164
165 SS = [self.PU1.inlet, self.PU1.outlet] + \
166 pconst(self.HE.inlet, self.HE.outlet, 100) + \
167 [self.PU2.inlet, self.PU2.outlet] + \
168 boiler_curve + \
169 [self.TU1.inlet, self.TU1.outlet, self.TU2.outlet] + \
170 condenser_curve + [self.PU1.inlet]
171
172 plot_Ts(SS)
173 plot_Ts(
174 [self.PU1.inlet, self.PU1.outlet, self.HE.inlet, self.HE.outlet,
175 self.PU2.inlet, self.PU2.outlet, self.TU1.inlet, self.TU1.outlet,
176 self.TU2.outlet, self.PU1.inlet]
177 ,'bo'
178 )
179
180 # line for the heat exchanger
181 plot_Ts(pconst(self.HE.inlet_heat, self.HE.outlet,100),'b:')
182
183 title(unicode(r"Regenerative Rankine cycle with %s" % D.name))
184 ylabel(unicode(r"T / [��C]"))
185 aa = axis(); axis([aa[0],aa[1],-100,600])
186 xlabel("s / [kJ/kg/K]")
187
188 extpy.getbrowser().reporter.reportNote("Plotting completed")
189 ion()
190 show()
191 #savefig(os.path.expanduser("~/Desktop/regen2.eps"))
192
193
194
195 def cycle_plot_rankine_regen1(self):
196 """Plot T-s diagram for a regenerative Rankine cycle"""
197 import loading
198 loading.load_matplotlib(throw=True)
199 ioff()
200 figure()
201 hold(1)
202 D = fprops.fluid(str(self.cd.component.getSymbolValue()))
203 sat_curve(D)
204
205 boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)
206 condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
207 he_hot = pconst(self.HE.inlet_heat, self.HE.outlet_heat,100)
208 he_cold = pconst(self.HE.inlet, self.HE.outlet,100)
209
210 SS = [self.PU.outlet] + he_cold + [self.BO.inlet] + boiler_curve + [self.TU.inlet, self.TU.outlet] + he_hot + condenser_curve + [self.PU.inlet, self.PU.outlet]
211
212 plot_Ts(SS)
213 plot_Ts(
214 [self.PU.outlet,self.BO.inlet,self.TU.inlet, self.TU.outlet
215 ,self.HE.outlet_heat, self.PU.inlet, self.PU.outlet]
216 ,'bo'
217 )
218
219 # dotted lines for the heat exchanger
220 plot_Ts([self.HE.inlet_heat, self.HE.outlet],'b:')
221 plot_Ts([self.HE.outlet_heat, self.HE.inlet],'b:')
222
223 title(unicode(r"Regenerative Rankine cycle with %s" % D.name))
224 ylabel(unicode(r"T / [��C]"))
225 aa = axis(); axis([aa[0],aa[1],-100,600])
226 xlabel("s / [kJ/kg/K]")
227
228 extpy.getbrowser().reporter.reportNote("Plotting completed")
229 ion()
230 show()
231 #savefig(os.path.expanduser("~/Desktop/regen1.eps"))
232
233
234 #--- heat exchange (T,H) plot ---
235
236 def heater_closed_plot(self):
237 """Plot T-H diagram of heat transfer in a heater_closed model"""
238 import loading
239 loading.load_matplotlib(throw=True)
240 ioff()
241 figure()
242 hold(1)
243 D = fprops.fluid(str(self.cd.component.getSymbolValue()))
244 HE = self.HE
245
246 extpy.getbrowser().reporter.reportNote("Fluid is %s" % D.name)
247
248 plot_TH(pconsth(HE.inlet_heat, HE.outlet_heat, 50),'r-',
249 Href = (float(HE.outlet_heat.h)*float(HE.outlet_heat.mdot))\
250 )
251
252 plot_TH(pconsth(HE.inlet, HE.outlet, 50),'b-',
253 Href = (float(HE.inlet.h)*float(HE.inlet.mdot))\
254 )
255
256 title(unicode(r"Closed feedwater heater with %s" % D.name))
257 ylabel(unicode(r"T / [��C]"))
258 xlabel("H / [MW]")
259
260 extpy.getbrowser().reporter.reportNote("Plotting completed")
261 ion()
262 show()
263 #savefig(os.path.expanduser("~/Desktop/heater_closed.eps"))
264
265 #--- the big one: a combined-cycle GT ---
266
267 def cycle_plot_ccgt(self):
268 """Plot T-s diagram for combined-cycle gas turbine"""
269 import loading
270 loading.load_matplotlib(throw=True)
271 ioff()
272 figure()
273
274 D = fprops.fluid(str(self.cd_rankine.component.getSymbolValue()))
275
276 # plot gas turbine cycle
277 SS = [self.GC.inlet, self.GC.outlet, self.GT.inlet, self.GT.outlet, self.HE.inlet, self.HE.outlet, self.GC.inlet]
278 plot_Ts(SS,'g-')
279 plot_Ts(SS,'go')
280 hold(1)
281
282 sat_curve(D)
283
284 boiler_curve = pconst(self.HE.inlet_cold,self.HE.outlet_cold,100)
285 condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
286 SS2 = [self.PU.outlet, self.HE.inlet_cold] + boiler_curve + [self.HE.outlet_cold, self.TU.inlet, self.TU.outlet, self.CO.inlet] + condenser_curve + [self.CO.outlet, self.PU.inlet, self.PU.outlet]
287 plot_Ts(SS2)
288 plot_Ts([self.PU.outlet, self.HE.inlet_cold,self.HE.outlet_cold, self.TU.inlet, self.TU.outlet, self.CO.inlet,self.CO.outlet, self.PU.inlet, self.PU.outlet],'bo')
289
290 title(unicode(r"Combined cycle with air and %s" % D.name))
291 ylabel(unicode(r"T / [��C]"))
292 xlabel("s / [kJ/kg/K]")
293
294 extpy.getbrowser().reporter.reportNote("Plotting completed")
295 ion()
296 show()
297 #savefig(os.path.expanduser("~/Desktop/ccgt.eps"))
298 #savefig(os.path.expanduser("~/Desktop/ccgt.png"))
299
300
301 #--- simple gas turbine models ---
302
303
304 def cycle_plot_brayton_regen(self):
305 """Plot T-s diagran for regenerative gas turbine"""
306 import loading
307 loading.load_matplotlib(throw=True)
308 ioff()
309 figure()
310
311 D = fprops.fluid(str(self.cd.component.getSymbolValue()))
312 sat_curve(D)
313
314 # plot gas turbine cycle
315 regen_cold_curve = pconst(self.RE.inlet, self.RE.outlet, 50)
316 burner_curve = pconst(self.BO.inlet, self.BO.outlet,50)
317 regen_hot_curve = pconst(self.RE.inlet_hot, self.RE.outlet_hot, 50)
318 diss_curve = pconst(self.CO.inlet, self.CO.outlet,50)
319
320 SS = [self.PU.inlet, self.PU.outlet, self.RE.inlet] + regen_cold_curve + [self.RE.outlet, self.BO.inlet] + burner_curve + [self.BO.outlet, self.TU.inlet, self.TU.outlet,self.RE.inlet_hot] + regen_hot_curve + [self.RE.outlet_hot, self.CO.inlet] + diss_curve + [self.CO.outlet,self.PU.inlet]
321
322 plot_Ts(SS,'g-')
323
324 SS2 = [self.PU.inlet, self.PU.outlet, self.RE.inlet, self.RE.outlet, self.BO.inlet, self.BO.outlet, self.TU.inlet, self.TU.outlet,self.RE.inlet_hot, self.RE.outlet_hot, self.CO.inlet, self.CO.outlet,self.PU.inlet]
325 plot_Ts(SS2,'go')
326
327 SS3 = [self.RE.inlet, self.RE.outlet_hot]
328 plot_Ts(SS3,'g--')
329
330 SS4 = [self.RE.outlet, self.RE.inlet_hot]
331 plot_Ts(SS4,'g--')
332
333 hold(1)
334
335 title(unicode(r"Regenerative Brayton cycle"))
336 ylabel(unicode(r"T / [��C]"))
337 xlabel("s / [kJ/kg/K]")
338
339 extpy.getbrowser().reporter.reportNote("Plotting completed")
340 ion()
341 show()
342 #savefig(os.path.expanduser("~/Desktop/brayton_regen.eps"))
343
344
345 def cycle_plot_brayton_reheat_regen_intercool(self):
346 """Plot T-s diagram for reheat-regenerative gas turbine"""
347 import loading
348 loading.load_matplotlib(throw=True)
349 ioff()
350 figure()
351 hold(1)
352 D = fprops.fluid(str(self.cd.component.getSymbolValue()),str(self.cd.type.getSymbolValue()))
353 sat_curve(D)
354
355 # add some dots for the points in the cycle
356 seq = "CO1.inlet DI2.inlet CO2.inlet RE.inlet BU1.inlet BU2.inlet TU1.inlet BU2.inlet TU2.inlet RE.inlet_hot DI1.inlet".split(" ")
357 lalign = "TU2.inlet RE.inlet_hot DI1.inlet DI2.inlet CO1.inlet".split(" ")
358 SS1 = []; SS1a = []
359 for s in seq:
360 print "looking at '%s'"%s
361 p = reduce(getattr,s.split("."),self)
362 SS1.append(p)
363 SS1a.append((p,s))
364 plot_Ts(SS1,'go')
365
366 print "ANNOTATIONS"
367 for s in SS1a:
368 align = "right"
369 if s[1] in lalign:
370 align = "left"
371 annotate(s[1]+" ", xy =(float(s[0].s)/1.e3,float(s[0].T) - 273.15)
372 ,horizontalalignment=align
373 )
374
375 # plot the cycle with smooth curves
376 BU1_curve = pconst(self.BU1.inlet, self.BU1.outlet,30)
377 BU2_curve = pconst(self.BU2.inlet, self.BU2.outlet,20)
378 DI1_curve = pconst(self.DI1.inlet,self.DI1.outlet,20)
379 DI2_curve = pconst(self.DI2.inlet,self.DI2.outlet,20)
380 REH_curve = pconst(self.RE.inlet_hot,self.RE.outlet_hot,50)
381 REL_curve = pconst(self.RE.inlet,self.RE.outlet,50)
382
383 SS2 = [self.CO1.inlet, self.CO1.outlet] + DI2_curve + [self.CO2.inlet, self.CO2.outlet] + REL_curve + BU1_curve + [self.TU1.inlet, self.TU1.outlet] + BU2_curve + [self.TU2.inlet, self.TU2.outlet] + REH_curve + DI1_curve + [self.CO1.inlet]
384 plot_Ts(SS2,'g-')
385
386 SS3 = [self.RE.inlet, self.RE.outlet_hot]
387 plot_Ts(SS3,'g--')
388
389 SS4 = [self.RE.outlet, self.RE.inlet_hot]
390 plot_Ts(SS4,'g--')
391
392 title(unicode(r"Reheat Regenerative Brayton cycle with Intercooling"))
393 ylabel(unicode(r"T / [��C]"))
394 xlabel("s / [kJ/kg/K]")
395
396 extpy.getbrowser().reporter.reportNote("Plotting completed")
397 ion()
398 show()
399
400
401 def cycle_plot_brayton_split(self):
402 """Plot T-s diagran for split-regeneration gas turbine"""
403 import loading
404 loading.load_matplotlib(throw=True)
405 ioff()
406 figure()
407 hold(1)
408 D = fprops.fluid(str(self.cd.component.getSymbolValue()),str(self.cd.type.getSymbolValue()))
409 sat_curve(D)
410
411 # add some dots for the points in the cycle
412 # seq = "CO2.inlet HEL.inlet HEL.outlet HEH.inlet BO.inlet TU.inlet HEH.inlet_hot HEL.inlet_hot CO1.inlet CO1.outlet".split(" ")
413 seq = "CO2.inlet HEL.inlet HEH.inlet BO.inlet TU.inlet HEH.inlet_hot HEH.outlet_hot CO1.inlet".split(" ")
414 lalign = "CO1.inlet HEH.outlet_hot ".split(" ")
415 SS1 = []; SS1a = []
416 for s in seq:
417 print "looking at '%s'"%s
418 p = reduce(getattr,s.split("."),self)
419 SS1.append(p)
420 SS1a.append((p,s))
421 plot_Ts(SS1,'go')
422
423 print "ANNOTATIONS"
424 for s in SS1a:
425 align = "right"
426 if s[1] in lalign:
427 align = "left"
428 annotate(s[1]+" ", xy =(float(s[0].s)/1.e3,float(s[0].T) - 273.15)
429 ,horizontalalignment=align
430 )
431
432 SS2 = pconst(self.DI.inlet, self.DI.outlet, 50) + [self.CO2.inlet,self.CO2.outlet] + pconst(self.HEL.inlet,self.HEH.outlet,50) + pconst(self.BO.inlet,self.BO.outlet,50) + [self.TU.inlet, self.TU.outlet] + pconst(self.HEH.inlet_hot,self.HEL.outlet_hot,50) + [self.CO1.inlet,self.CO1.outlet]
433 plot_Ts(SS2,'g-')
434
435 SS3 = [self.HEL.inlet, self.HEL.outlet_hot]
436 plot_Ts(SS3,'g--')
437 SS4 = [self.HEL.outlet, self.HEL.inlet_hot]
438 plot_Ts(SS4,'g--')
439
440 SS5 = [self.HEH.inlet, self.HEH.outlet_hot]
441 plot_Ts(SS5,'g--')
442 SS6 = [self.HEH.outlet, self.HEH.inlet_hot]
443 plot_Ts(SS6,'g--')
444
445
446 title(unicode(r"Split Regenerative Brayton cycle"))
447 ylabel(unicode(r"T / [��C]"))
448 xlabel("s / [kJ/kg/K]")
449
450 extpy.getbrowser().reporter.reportNote("Plotting completed")
451 ion()
452 show()
453 savefig(os.path.expanduser("~/Desktop/brayton__split_regen.eps"))
454
455
456
457
458 #--- air-to-stream heat exchanger plot ---
459
460 def air_stream_heat_exchanger_plot(self):
461 """Plot T-H diagram of heat transfer in a heater_closed model"""
462 import loading
463 loading.load_matplotlib(throw=True)
464 ioff()
465 figure()
466 hold(1)
467 D = fprops.fluid(str(self.cd_cold.component.getSymbolValue()))
468
469 n = self.n.getIntValue()
470 extpy.getbrowser().reporter.reportNote("Fluid is %s" % D.name)
471
472 # hot side is the air, calculated in the model
473 plot_TH( [self.H[i] for i in range(1+int(n))],'r-',\
474 Href = (float(self.outlet.h)*float(self.outlet.mdot))\
475 )
476
477 plot_TH(pconsth(self.inlet_cold, self.outlet_cold, 50),'b-',
478 Href = (float(self.inlet_cold.h)*float(self.inlet_cold.mdot))\
479 )
480
481 title(unicode(r"Combined-cycle air-%s heat exchanger" % D.name))
482 ylabel(unicode(r"T / [��C]"))
483 xlabel("H / [MW]")
484
485 extpy.getbrowser().reporter.reportNote("Plotting completed")
486 ion()
487 show()
488 #savefig(os.path.expanduser("~/Desktop/air_stream_heatex.eps"))
489
490
491 extpy.registermethod(cycle_plot_rankine)
492 extpy.registermethod(cycle_plot_rankine_reheat)
493 extpy.registermethod(cycle_plot_rankine_regen1)
494 extpy.registermethod(cycle_plot_rankine_regen2)
495 extpy.registermethod(cycle_plot_brayton_regen)
496 extpy.registermethod(cycle_plot_brayton_reheat_regen_intercool)
497 extpy.registermethod(cycle_plot_brayton_split)
498 extpy.registermethod(cycle_plot_ccgt)
499
500 extpy.registermethod(heater_closed_plot)
501 extpy.registermethod(air_stream_heat_exchanger_plot)
502
503 #the above method can be called using "EXTERNAL fourbarplot(SELF)" in ASCEND.

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22