/[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 2301 - (show annotations) (download) (as text)
Sat Aug 21 13:28:35 2010 UTC (13 years, 9 months ago) by jpye
File MIME type: text/x-python
File size: 5475 byte(s)
Regen toluene model working, next 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 def sat_curve(d):
15 Tt = d.T_t
16 Tc = d.T_c
17 TT = []
18 pp = []
19 ssf = []
20 ssg = []
21 for T in linspace(Tt,Tc,100):
22 res,p,rf,rg = fprops.fprops_sat_T(T,d)
23 if not res:
24 TT.append(T - 273.15)
25 pp.append(p)
26 ssf.append(fprops.helmholtz_s_raw(T,rf,d)/1.e3)
27 ssg.append(fprops.helmholtz_s_raw(T,rg,d)/1.e3)
28 plot(ssf,TT,"b--")
29 plot(ssg,TT,"r--")
30
31 class TSPoint:
32 def __init__(self,T,s):
33 self.T = T
34 self.s = s
35
36 def write(msg):
37 extpy.getbrowser().reporter.reportNote(msg)
38
39 def pconst(S1,S2,n):
40 """Return a set of (T,s) points between two states, with pressure held constant."""
41 D = fprops.fprops_fluid(str(S1.cd.component.getSymbolValue()))
42 out = []
43 hh = linspace(float(S1.h), float(S2.h), n)
44 for h in hh:
45 res, T, rho = fprops.fprops_solve_ph(float(S1.p), h, 0, D)
46 if not res:
47 out += [TSPoint(T,fprops.helmholtz_s(T,rho,D))]
48 return out
49
50 def plot_Ts(SS,style='b-'):
51 xx = []
52 yy = []
53 for S in SS:
54 yy.append(float(S.T) - 273.15)
55 xx.append(float(S.s)/1.e3)
56 plot(xx,yy,style)
57
58 def cycle_plot(self):
59 """Plot T-s diagram for combined-cycle gas turbine"""
60 import loading
61 loading.load_matplotlib(throw=True)
62 ioff()
63 figure()
64
65 D = fprops.fprops_fluid(str(self.cd_rankine.component.getSymbolValue()))
66
67 # plot gas turbine cycle
68 SS = [self.GC.inlet, self.GC.outlet, self.GT.inlet, self.GT.outlet, self.HE.inlet, self.HE.outlet, self.GC.inlet]
69 plot_Ts(SS)
70 hold(1)
71
72 sat_curve(d)
73
74 boiler_curve = pconst(self.HE.inlet_cold,self.HE.outlet_cold,100)
75 condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
76 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]
77 plot_Ts(SS2)
78
79 title(unicode(r"With %s bottoming cycle" % d.name))
80 ylabel(unicode(r"T / [��C]"))
81 xlabel("s / [kJ/kg/K]")
82
83 extpy.getbrowser().reporter.reportNote("Plotting completed")
84 ion()
85 show()
86
87 def cycle_plot_rankine(self):
88 """Plot T-s diagram for a simple Rankine cycle"""
89 import loading
90 loading.load_matplotlib(throw=True)
91 ioff()
92 figure()
93 hold(1)
94 D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue()))
95 sat_curve(D)
96
97 boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)
98 condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
99 SS = [self.PU.outlet, self.BO.inlet] + boiler_curve + [self.TU.inlet, self.TU.outlet] + condenser_curve + [self.CO.outlet, self.PU.outlet]
100 plot_Ts(SS)
101
102 title(unicode(r"Rankine cycle with %s" % D.name))
103 ylabel(unicode(r"T / [��C]"))
104 xlabel("s / [kJ/kg/K]")
105
106 extpy.getbrowser().reporter.reportNote("Plotting completed")
107 ion()
108 show()
109
110 def cycle_plot_rankine_regen2(self):
111 """Plot T-s diagram for a regenerative Rankine cycle (bleed steam regen)"""
112 import loading
113 loading.load_matplotlib(throw=True)
114 ioff()
115 figure()
116 hold(1)
117 D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue()))
118 sat_curve(D)
119
120 boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)
121 condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
122
123 SS = [self.PU1.inlet, self.PU1.outlet] + \
124 pconst(self.HE.inlet, self.HE.outlet, 100) + \
125 [self.PU2.inlet, self.PU2.outlet] + \
126 boiler_curve + \
127 [self.TU1.inlet, self.TU1.outlet, self.TU2.outlet] + \
128 condenser_curve + [self.PU1.inlet]
129
130 plot_Ts(SS)
131 plot_Ts(
132 [self.PU1.inlet, self.PU1.outlet, self.HE.inlet, self.HE.outlet,
133 self.PU2.inlet, self.PU2.outlet, self.TU1.inlet, self.TU1.outlet,
134 self.TU2.outlet, self.PU1.inlet]
135 ,'bo'
136 )
137
138 # line for the heat exchanger
139 plot_Ts(pconst(self.HE.inlet_heat, self.HE.outlet,100),'b-')
140
141 title(unicode(r"Regenerative Rankine cycle with %s" % D.name))
142 ylabel(unicode(r"T / [��C]"))
143 xlabel("s / [kJ/kg/K]")
144
145 extpy.getbrowser().reporter.reportNote("Plotting completed")
146 ion()
147 show()
148 import os.path
149 savefig(os.path.expanduser("~/Desktop/regen2.eps"))
150
151
152
153 def cycle_plot_rankine_regen1(self):
154 """Plot T-s diagram for a regenerative Rankine cycle"""
155 import loading
156 loading.load_matplotlib(throw=True)
157 ioff()
158 figure()
159 hold(1)
160 D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue()))
161 sat_curve(D)
162
163 boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)
164 condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100)
165 he_hot = pconst(self.HE.inlet_heat, self.HE.outlet_heat,100)
166 he_cold = pconst(self.HE.inlet, self.HE.outlet,100)
167
168 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]
169
170 plot_Ts(SS)
171 plot_Ts(
172 [self.PU.outlet,self.BO.inlet,self.TU.inlet, self.TU.outlet
173 ,self.HE.outlet_heat, self.PU.inlet, self.PU.outlet]
174 ,'bo'
175 )
176
177 # dotted lines for the heat exchanger
178 plot_Ts([self.HE.inlet_heat, self.HE.outlet],'b:')
179 plot_Ts([self.HE.outlet_heat, self.HE.inlet],'b:')
180
181 title(unicode(r"Regenerative Rankine cycle with %s" % D.name))
182 ylabel(unicode(r"T / [��C]"))
183 xlabel("s / [kJ/kg/K]")
184
185 extpy.getbrowser().reporter.reportNote("Plotting completed")
186 ion()
187 show()
188
189
190 extpy.registermethod(cycle_plot_rankine)
191 extpy.registermethod(cycle_plot_rankine_regen1)
192 extpy.registermethod(cycle_plot_rankine_regen2)
193
194 extpy.registermethod(cycle_plot)
195 #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