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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2303 - (hide annotations) (download) (as text)
Sun Aug 22 01:33:16 2010 UTC (11 years, 11 months ago) by jpye
File MIME type: text/x-python
File size: 7126 byte(s)
Fix minor issue with building FPROPS from ~/ascend.
Added heat-exchanger plopts in cycle_plot.py.
Finished ammonia and toluene regen cycles.
1 jpye 2286 # -*- coding: utf8 -*-
2 jpye 2292 import extpy, sys
3 jpye 2286 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 jpye 2303 #--- for (T,s) plots ---
15    
16 jpye 2291 def sat_curve(d):
17 jpye 2286 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     res,p,rf,rg = fprops.fprops_sat_T(T,d)
25     if not res:
26     TT.append(T - 273.15)
27     pp.append(p)
28 jpye 2292 ssf.append(fprops.helmholtz_s_raw(T,rf,d)/1.e3)
29     ssg.append(fprops.helmholtz_s_raw(T,rg,d)/1.e3)
30 jpye 2286 plot(ssf,TT,"b--")
31     plot(ssg,TT,"r--")
32    
33 jpye 2291 class TSPoint:
34     def __init__(self,T,s):
35     self.T = T
36     self.s = s
37    
38     def write(msg):
39     extpy.getbrowser().reporter.reportNote(msg)
40    
41     def pconst(S1,S2,n):
42     """Return a set of (T,s) points between two states, with pressure held constant."""
43 jpye 2301 D = fprops.fprops_fluid(str(S1.cd.component.getSymbolValue()))
44 jpye 2291 out = []
45     hh = linspace(float(S1.h), float(S2.h), n)
46     for h in hh:
47     res, T, rho = fprops.fprops_solve_ph(float(S1.p), h, 0, D)
48     if not res:
49     out += [TSPoint(T,fprops.helmholtz_s(T,rho,D))]
50     return out
51    
52 jpye 2303
53 jpye 2301 def plot_Ts(SS,style='b-'):
54 jpye 2292 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 jpye 2301 plot(xx,yy,style)
60 jpye 2292
61 jpye 2303 #--- for (T,H) plots ---
62 jpye 2286
63 jpye 2303 class THPoint:
64     def __init__(self,T,H):
65     self.T = T
66     self.H = H
67 jpye 2291
68 jpye 2303 def pconsth(S1,S2,n):
69     """Return a set of (T,H) points between two states, with pressure constant"""
70     D = fprops.fprops_fluid(str(S1.cd.component.getSymbolValue()))
71     out = []
72     hh = linspace(float(S1.h), float(S2.h), n)
73     for h in hh:
74     res, T, rho = fprops.fprops_solve_ph(float(S1.p), h, 0, D)
75     if not res:
76     out += [THPoint(T,h * float(S1.mdot))]
77     return out
78 jpye 2286
79 jpye 2303 def plot_TH(SS,style='b-',Href = 0):
80     xx = []
81     yy = []
82     for S in SS:
83     yy.append(float(S.T) - 273.15)
84     xx.append((float(S.H) - Href)/1.e6)
85     plot(xx,yy,style)
86 jpye 2286
87 jpye 2303 #--- various Rankine cycle configurations ---
88 jpye 2286
89 jpye 2292 def cycle_plot_rankine(self):
90     """Plot T-s diagram for a simple Rankine cycle"""
91     import loading
92     loading.load_matplotlib(throw=True)
93     ioff()
94     figure()
95     hold(1)
96 jpye 2301 D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue()))
97 jpye 2292 sat_curve(D)
98    
99     boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)
100 jpye 2294 condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
101     SS = [self.PU.outlet, self.BO.inlet] + boiler_curve + [self.TU.inlet, self.TU.outlet] + condenser_curve + [self.CO.outlet, self.PU.outlet]
102 jpye 2292 plot_Ts(SS)
103 jpye 2301
104 jpye 2294 title(unicode(r"Rankine cycle with %s" % D.name))
105 jpye 2292 ylabel(unicode(r"T / [��C]"))
106     xlabel("s / [kJ/kg/K]")
107    
108     extpy.getbrowser().reporter.reportNote("Plotting completed")
109     ion()
110     show()
111    
112 jpye 2303
113 jpye 2301 def cycle_plot_rankine_regen2(self):
114     """Plot T-s diagram for a regenerative Rankine cycle (bleed steam regen)"""
115     import loading
116     loading.load_matplotlib(throw=True)
117     ioff()
118     figure()
119     hold(1)
120     D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue()))
121     sat_curve(D)
122 jpye 2292
123 jpye 2301 boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)
124     condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
125    
126     SS = [self.PU1.inlet, self.PU1.outlet] + \
127     pconst(self.HE.inlet, self.HE.outlet, 100) + \
128     [self.PU2.inlet, self.PU2.outlet] + \
129     boiler_curve + \
130     [self.TU1.inlet, self.TU1.outlet, self.TU2.outlet] + \
131     condenser_curve + [self.PU1.inlet]
132    
133     plot_Ts(SS)
134     plot_Ts(
135     [self.PU1.inlet, self.PU1.outlet, self.HE.inlet, self.HE.outlet,
136     self.PU2.inlet, self.PU2.outlet, self.TU1.inlet, self.TU1.outlet,
137     self.TU2.outlet, self.PU1.inlet]
138     ,'bo'
139     )
140    
141     # line for the heat exchanger
142     plot_Ts(pconst(self.HE.inlet_heat, self.HE.outlet,100),'b-')
143    
144     title(unicode(r"Regenerative Rankine cycle with %s" % D.name))
145     ylabel(unicode(r"T / [��C]"))
146     xlabel("s / [kJ/kg/K]")
147    
148     extpy.getbrowser().reporter.reportNote("Plotting completed")
149     ion()
150     show()
151     savefig(os.path.expanduser("~/Desktop/regen2.eps"))
152    
153    
154    
155     def cycle_plot_rankine_regen1(self):
156     """Plot T-s diagram for a regenerative Rankine cycle"""
157     import loading
158     loading.load_matplotlib(throw=True)
159     ioff()
160     figure()
161     hold(1)
162     D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue()))
163     sat_curve(D)
164    
165     boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)
166     condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
167     he_hot = pconst(self.HE.inlet_heat, self.HE.outlet_heat,100)
168     he_cold = pconst(self.HE.inlet, self.HE.outlet,100)
169    
170     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]
171    
172     plot_Ts(SS)
173     plot_Ts(
174     [self.PU.outlet,self.BO.inlet,self.TU.inlet, self.TU.outlet
175     ,self.HE.outlet_heat, self.PU.inlet, self.PU.outlet]
176     ,'bo'
177     )
178    
179     # dotted lines for the heat exchanger
180     plot_Ts([self.HE.inlet_heat, self.HE.outlet],'b:')
181     plot_Ts([self.HE.outlet_heat, self.HE.inlet],'b:')
182    
183     title(unicode(r"Regenerative Rankine cycle with %s" % D.name))
184     ylabel(unicode(r"T / [��C]"))
185     xlabel("s / [kJ/kg/K]")
186    
187     extpy.getbrowser().reporter.reportNote("Plotting completed")
188     ion()
189     show()
190 jpye 2303 savefig(os.path.expanduser("~/Desktop/regen1.eps"))
191 jpye 2301
192    
193 jpye 2303 #--- heat exchange (T,H) plot ---
194    
195     def heater_closed_plot(self):
196     """Plot T-H diagram of heat transfer in a heater_closed model"""
197     import loading
198     loading.load_matplotlib(throw=True)
199     ioff()
200     figure()
201     hold(1)
202     D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue()))
203     HE = self.HE
204    
205     extpy.getbrowser().reporter.reportNote("Fluid is %s" % D.name)
206    
207     plot_TH(pconsth(HE.inlet_heat, HE.outlet_heat, 50),'r-',
208     Href = (float(HE.outlet_heat.h)*float(HE.outlet_heat.mdot))\
209     )
210    
211     plot_TH(pconsth(HE.inlet, HE.outlet, 50),'b-',
212     Href = (float(HE.inlet.h)*float(HE.inlet.mdot))\
213     )
214    
215     title(unicode(r"Closed feedwater heater with %s" % D.name))
216     ylabel(unicode(r"T / [��C]"))
217     xlabel("H / [MW]")
218    
219     extpy.getbrowser().reporter.reportNote("Plotting completed")
220     ion()
221     show()
222     savefig(os.path.expanduser("~/Desktop/heater_closed.eps"))
223    
224     #--- the big one: a combined-cycle GT ---
225    
226     def cycle_plot(self):
227     """Plot T-s diagram for combined-cycle gas turbine"""
228     import loading
229     loading.load_matplotlib(throw=True)
230     ioff()
231     figure()
232    
233     D = fprops.fprops_fluid(str(self.cd_rankine.component.getSymbolValue()))
234    
235     # plot gas turbine cycle
236     SS = [self.GC.inlet, self.GC.outlet, self.GT.inlet, self.GT.outlet, self.HE.inlet, self.HE.outlet, self.GC.inlet]
237     plot_Ts(SS)
238     hold(1)
239    
240     sat_curve(d)
241    
242     boiler_curve = pconst(self.HE.inlet_cold,self.HE.outlet_cold,100)
243     condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
244     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]
245     plot_Ts(SS2)
246    
247     title(unicode(r"With %s bottoming cycle" % d.name))
248     ylabel(unicode(r"T / [��C]"))
249     xlabel("s / [kJ/kg/K]")
250    
251     extpy.getbrowser().reporter.reportNote("Plotting completed")
252     ion()
253     show()
254    
255    
256 jpye 2292 extpy.registermethod(cycle_plot_rankine)
257 jpye 2301 extpy.registermethod(cycle_plot_rankine_regen1)
258     extpy.registermethod(cycle_plot_rankine_regen2)
259 jpye 2303 extpy.registermethod(heater_closed_plot)
260 jpye 2292
261 jpye 2286 extpy.registermethod(cycle_plot)
262     #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