/[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 2692 - (show annotations) (download) (as text)
Tue Mar 5 04:45:27 2013 UTC (9 years, 4 months ago) by jpye
File MIME type: text/x-python
File size: 10437 byte(s)
Fix rankine_regen_water model (some initialisation had been omitted).
Update plotting routine for rankine_regen_water.
1 # -*- coding: utf8 -*-
2 import extpy, sys
3 from solverreporter import *
4
5 import sys, os, os.path
6 sys.path.append(os.path.expanduser("~/ascend/models/johnpye/fprops/python"))
7 import fprops
8
9 try:
10 from pylab import *
11 except:
12 pass
13
14 #--- for (T,s) plots ---
15
16 def sat_curve(D):
17 Tt = D.T_t
18 Tc = D.T_c
19 TT = []
20 pp = []
21 ssf = []
22 ssg = []
23 for T in linspace(Tt,Tc,100):
24 # TODO this is inefficient because of repeated saturation solutions.
25 SF = D.set_Tx(T,0)
26 SG = D.set_Tx(T,1)
27 TT.append(SF.T - 273.15)
28 pp.append(SF.p)
29 ssf.append(SF.s/1.e3)
30 ssg.append(SG.s/1.e3)
31 plot(ssf,TT,"b--")
32 plot(ssg,TT,"r--")
33
34 class TSPoint:
35 def __init__(self,T,s):
36 self.T = T
37 self.s = s
38
39 def write(msg):
40 extpy.getbrowser().reporter.reportNote(msg)
41
42 def pconst(S1,S2,n):
43 """Return a set of (T,s) points between two states, with pressure held constant."""
44 D = fprops.fluid(str(S1.cd.component.getSymbolValue()))
45 out = []
46 hh = linspace(float(S1.h), float(S2.h), n)
47 for h in hh:
48 S = D.set_ph(float(S1.p), h)
49 out += [TSPoint(S.T,S.s)]
50 return out
51
52
53 def plot_Ts(SS,style='b-'):
54 xx = []
55 yy = []
56 for S in SS:
57 yy.append(float(S.T) - 273.15)
58 xx.append(float(S.s)/1.e3)
59 plot(xx,yy,style)
60
61 #--- for (T,H) plots ---
62
63 class THPoint:
64 def __init__(self,T,h,mdot = 1.):
65 self.T = T
66 self.h = h
67 self.mdot = mdot
68
69 def pconsth(S1,S2,n):
70 """Return a set of (T,H) points between two states, with pressure constant"""
71 D = fprops.fluid(str(S1.cd.component.getSymbolValue()))
72 out = []
73 hh = linspace(float(S1.h), float(S2.h), n)
74 mdot = float(S1.mdot)
75 for h in hh:
76 # TODO add try/except
77 S = D.set_ph(float(S1.p),h)
78 out += [THPoint(S.T,h * mdot)]
79 return out
80
81 def plot_TH(SS,style='b-',Href = 0):
82 xx = []
83 yy = []
84 for S in SS:
85 yy.append(float(S.T) - 273.15)
86 xx.append(((float(S.h)*float(S.mdot)) - Href)/1.e6)
87 plot(xx,yy,style)
88
89 #--- various Rankine cycle configurations ---
90
91 def cycle_plot_rankine(self):
92 """Plot T-s diagram for a simple Rankine cycle"""
93 import loading
94 loading.load_matplotlib(throw=True)
95 ioff()
96 figure()
97 hold(1)
98 D = fprops.fluid(str(self.cd.component.getSymbolValue()))
99 sat_curve(D)
100
101 boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)
102 condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
103 SS = [self.PU.outlet, self.BO.inlet] + boiler_curve + [self.TU.inlet, self.TU.outlet] + condenser_curve + [self.CO.outlet, self.PU.outlet]
104 plot_Ts(SS)
105
106 title(unicode(r"Rankine cycle with %s" % D.name))
107 ylabel(unicode(r"T / [��C]"))
108 aa = axis(); axis([aa[0],aa[1],-100,600])
109 xlabel("s / [kJ/kg/K]")
110
111 extpy.getbrowser().reporter.reportNote("Plotting completed")
112 ion()
113 show()
114 #savefig(os.path.expanduser("~/Desktop/rankine.eps"))
115
116 def cycle_plot_rankine_reheat(self):
117 """Plot T-s diagram for a reheat Rankine cycle"""
118 import loading
119 loading.load_matplotlib(throw=True)
120 ioff()
121 figure()
122 hold(1)
123 D = fprops.fluid(str(self.cd.component.getSymbolValue()))
124 sat_curve(D)
125
126 boiler1_curve = pconst(self.BO1.inlet, self.BO1.outlet,100)
127 boiler2_curve = pconst(self.BO2.inlet, self.BO2.outlet,50)
128 condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
129 SS = [self.PU.outlet, self.BO1.inlet] + \
130 boiler1_curve + [self.TU1.inlet, self.TU1.outlet] + \
131 boiler2_curve + [self.TU2.inlet, self.TU2.outlet] + \
132 condenser_curve + [self.CO.outlet, self.PU.outlet]
133 plot_Ts(SS)
134
135 plot_Ts(
136 [self.PU.inlet, self.BO1.inlet, self.TU1.inlet, self.BO2.inlet
137 ,self.TU2.inlet, self.CO.inlet]
138 ,'bo'
139 )
140
141 title(unicode(r"Reheat Rankine cycle with %s" % D.name))
142 ylabel(unicode(r"T / [��C]"))
143 aa = axis(); axis([aa[0],aa[1],-100,600])
144 xlabel("s / [kJ/kg/K]")
145
146 extpy.getbrowser().reporter.reportNote("Plotting completed")
147 ion()
148 show()
149 #savefig(os.path.expanduser("~/Desktop/rankine-reheat.eps"))
150
151 def cycle_plot_rankine_regen2(self):
152 """Plot T-s diagram for a regenerative Rankine cycle (bleed steam regen)"""
153 import loading
154 loading.load_matplotlib(throw=True)
155 ioff()
156 figure()
157 hold(1)
158 D = fprops.fluid(str(self.cd.component.getSymbolValue()))
159 sat_curve(D)
160
161 boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)
162 condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
163
164 SS = [self.PU1.inlet, self.PU1.outlet] + \
165 pconst(self.HE.inlet, self.HE.outlet, 100) + \
166 [self.PU2.inlet, self.PU2.outlet] + \
167 boiler_curve + \
168 [self.TU1.inlet, self.TU1.outlet, self.TU2.outlet] + \
169 condenser_curve + [self.PU1.inlet]
170
171 plot_Ts(SS)
172 plot_Ts(
173 [self.PU1.inlet, self.PU1.outlet, self.HE.inlet, self.HE.outlet,
174 self.PU2.inlet, self.PU2.outlet, self.TU1.inlet, self.TU1.outlet,
175 self.TU2.outlet, self.PU1.inlet]
176 ,'bo'
177 )
178
179 # line for the heat exchanger
180 plot_Ts(pconst(self.HE.inlet_heat, self.HE.outlet,100),'b:')
181
182 title(unicode(r"Regenerative Rankine cycle with %s" % D.name))
183 ylabel(unicode(r"T / [��C]"))
184 aa = axis(); axis([aa[0],aa[1],-100,600])
185 xlabel("s / [kJ/kg/K]")
186
187 extpy.getbrowser().reporter.reportNote("Plotting completed")
188 ion()
189 show()
190 #savefig(os.path.expanduser("~/Desktop/regen2.eps"))
191
192
193
194 def cycle_plot_rankine_regen1(self):
195 """Plot T-s diagram for a regenerative Rankine cycle"""
196 import loading
197 loading.load_matplotlib(throw=True)
198 ioff()
199 figure()
200 hold(1)
201 D = fprops.fluid(str(self.cd.component.getSymbolValue()))
202 sat_curve(D)
203
204 boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)
205 condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
206 he_hot = pconst(self.HE.inlet_heat, self.HE.outlet_heat,100)
207 he_cold = pconst(self.HE.inlet, self.HE.outlet,100)
208
209 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]
210
211 plot_Ts(SS)
212 plot_Ts(
213 [self.PU.outlet,self.BO.inlet,self.TU.inlet, self.TU.outlet
214 ,self.HE.outlet_heat, self.PU.inlet, self.PU.outlet]
215 ,'bo'
216 )
217
218 # dotted lines for the heat exchanger
219 plot_Ts([self.HE.inlet_heat, self.HE.outlet],'b:')
220 plot_Ts([self.HE.outlet_heat, self.HE.inlet],'b:')
221
222 title(unicode(r"Regenerative Rankine cycle with %s" % D.name))
223 ylabel(unicode(r"T / [��C]"))
224 aa = axis(); axis([aa[0],aa[1],-100,600])
225 xlabel("s / [kJ/kg/K]")
226
227 extpy.getbrowser().reporter.reportNote("Plotting completed")
228 ion()
229 show()
230 #savefig(os.path.expanduser("~/Desktop/regen1.eps"))
231
232
233 #--- heat exchange (T,H) plot ---
234
235 def heater_closed_plot(self):
236 """Plot T-H diagram of heat transfer in a heater_closed model"""
237 import loading
238 loading.load_matplotlib(throw=True)
239 ioff()
240 figure()
241 hold(1)
242 D = fprops.fluid(str(self.cd.component.getSymbolValue()))
243 HE = self.HE
244
245 extpy.getbrowser().reporter.reportNote("Fluid is %s" % D.name)
246
247 plot_TH(pconsth(HE.inlet_heat, HE.outlet_heat, 50),'r-',
248 Href = (float(HE.outlet_heat.h)*float(HE.outlet_heat.mdot))\
249 )
250
251 plot_TH(pconsth(HE.inlet, HE.outlet, 50),'b-',
252 Href = (float(HE.inlet.h)*float(HE.inlet.mdot))\
253 )
254
255 title(unicode(r"Closed feedwater heater with %s" % D.name))
256 ylabel(unicode(r"T / [��C]"))
257 xlabel("H / [MW]")
258
259 extpy.getbrowser().reporter.reportNote("Plotting completed")
260 ion()
261 show()
262 #savefig(os.path.expanduser("~/Desktop/heater_closed.eps"))
263
264 #--- the big one: a combined-cycle GT ---
265
266 def cycle_plot_ccgt(self):
267 """Plot T-s diagram for combined-cycle gas turbine"""
268 import loading
269 loading.load_matplotlib(throw=True)
270 ioff()
271 figure()
272
273 D = fprops.fluid(str(self.cd_rankine.component.getSymbolValue()))
274
275 # plot gas turbine cycle
276 SS = [self.GC.inlet, self.GC.outlet, self.GT.inlet, self.GT.outlet, self.HE.inlet, self.HE.outlet, self.GC.inlet]
277 plot_Ts(SS,'g-')
278 plot_Ts(SS,'go')
279 hold(1)
280
281 sat_curve(D)
282
283 boiler_curve = pconst(self.HE.inlet_cold,self.HE.outlet_cold,100)
284 condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
285 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]
286 plot_Ts(SS2)
287 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')
288
289 title(unicode(r"Combined cycle with air and %s" % D.name))
290 ylabel(unicode(r"T / [��C]"))
291 xlabel("s / [kJ/kg/K]")
292
293 extpy.getbrowser().reporter.reportNote("Plotting completed")
294 ion()
295 show()
296 #savefig(os.path.expanduser("~/Desktop/ccgt.eps"))
297 #savefig(os.path.expanduser("~/Desktop/ccgt.png"))
298
299
300 #--- simple gas turbine models ---
301
302
303 def cycle_plot_brayton_regen(self):
304 """Plot T-s diagran for regenerative gas turbine"""
305 import loading
306 loading.load_matplotlib(throw=True)
307 ioff()
308 figure()
309
310 # plot gas turbine cycle
311 SS = [self.CO.inlet, self.CO.outlet, self.RE.inlet, self.RE.outlet, self.BU.inlet,self.BU.outlet, self.TU.inlet, self.TU.outlet,self.RE.inlet_hot, self.RE.outlet_hot, self.DI.inlet, self.DI.outlet,self.CO.inlet]
312 plot_Ts(SS,'g-')
313 plot_Ts(SS,'go')
314 hold(1)
315
316 title(unicode(r"Regenerative Brayton cycle"))
317 ylabel(unicode(r"T / [��C]"))
318 xlabel("s / [kJ/kg/K]")
319
320 extpy.getbrowser().reporter.reportNote("Plotting completed")
321 ion()
322 show()
323 #savefig(os.path.expanduser("~/Desktop/brayton_regen.eps"))
324
325 #--- air-to-stream heat exchanger plot ---
326
327 def air_stream_heat_exchanger_plot(self):
328 """Plot T-H diagram of heat transfer in a heater_closed model"""
329 import loading
330 loading.load_matplotlib(throw=True)
331 ioff()
332 figure()
333 hold(1)
334 D = fprops.fluid(str(self.cd_cold.component.getSymbolValue()))
335
336 n = self.n.getIntValue()
337 extpy.getbrowser().reporter.reportNote("Fluid is %s" % D.name)
338
339 # hot side is the air, calculated in the model
340 plot_TH( [self.H[i] for i in range(1+int(n))],'r-',\
341 Href = (float(self.outlet.h)*float(self.outlet.mdot))\
342 )
343
344 plot_TH(pconsth(self.inlet_cold, self.outlet_cold, 50),'b-',
345 Href = (float(self.inlet_cold.h)*float(self.inlet_cold.mdot))\
346 )
347
348 title(unicode(r"Combined-cycle air-%s heat exchanger" % D.name))
349 ylabel(unicode(r"T / [��C]"))
350 xlabel("H / [MW]")
351
352 extpy.getbrowser().reporter.reportNote("Plotting completed")
353 ion()
354 show()
355 #savefig(os.path.expanduser("~/Desktop/air_stream_heatex.eps"))
356
357
358 extpy.registermethod(cycle_plot_rankine)
359 extpy.registermethod(cycle_plot_rankine_reheat)
360 extpy.registermethod(cycle_plot_rankine_regen1)
361 extpy.registermethod(cycle_plot_rankine_regen2)
362 extpy.registermethod(cycle_plot_brayton_regen)
363 extpy.registermethod(cycle_plot_ccgt)
364
365 extpy.registermethod(heater_closed_plot)
366 extpy.registermethod(air_stream_heat_exchanger_plot)
367
368 #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