# Diff of /trunk/models/johnpye/fprops/cycle_plot.py

revision 2659 by jpye, Thu Sep 2 03:36:57 2010 UTC revision 2660 by jpye, Wed Jan 16 05:57:03 2013 UTC
# Line 13  except: Line 13  except:
13
14  #--- for (T,s) plots ---  #--- for (T,s) plots ---
15
16  def sat_curve(d):  def sat_curve(D):
17      Tt = d.T_t      Tt = D.T_t
18      Tc = d.T_c      Tc = D.T_c
19      TT = []      TT = []
20      pp = []      pp = []
21      ssf = []      ssf = []
22      ssg = []      ssg = []
23      for T in linspace(Tt,Tc,100):      for T in linspace(Tt,Tc,100):
24          res,p,rf,rg = fprops.fprops_sat_T(T,d)          # TODO this is inefficient because of repeated saturation solutions.
25          if not res:          SF = D.set_Tx(T,0)
26              TT.append(T - 273.15)          SG = D.set_Tx(T,1)
27              pp.append(p)          TT.append(SF.T - 273.15)
28              ssf.append(fprops.helmholtz_s_raw(T,rf,d)/1.e3)          pp.append(SF.p)
29              ssg.append(fprops.helmholtz_s_raw(T,rg,d)/1.e3)          ssf.append(SF.s/1.e3)
30            ssg.append(SG.s/1.e3)
31      plot(ssf,TT,"b--")      plot(ssf,TT,"b--")
32      plot(ssg,TT,"r--")      plot(ssg,TT,"r--")
33
# Line 40  def write(msg): Line 41  def write(msg):
41
42  def pconst(S1,S2,n):  def pconst(S1,S2,n):
43      """Return a set of (T,s) points between two states, with pressure held constant."""      """Return a set of (T,s) points between two states, with pressure held constant."""
44      D = fprops.fprops_fluid(str(S1.cd.component.getSymbolValue()))        D = fprops.fluid(str(S1.cd.component.getSymbolValue()))
45      out = []      out = []
46      hh = linspace(float(S1.h), float(S2.h), n)      hh = linspace(float(S1.h), float(S2.h), n)
47      for h in hh:      for h in hh:
48          res, T, rho = fprops.fprops_solve_ph(float(S1.p), h, 0, D)          S = D.set_ph(float(S1.p), h)
49          if not res:          out += [TSPoint(S.T,S.s)]
out += [TSPoint(T,fprops.helmholtz_s(T,rho,D))]
50      return out      return out
51
52
# Line 68  class THPoint: Line 68  class THPoint:
68
69  def pconsth(S1,S2,n):  def pconsth(S1,S2,n):
70      """Return a set of (T,H) points between two states, with pressure constant"""      """Return a set of (T,H) points between two states, with pressure constant"""
71      D = fprops.fprops_fluid(str(S1.cd.component.getSymbolValue()))        D = fprops.fluid(str(S1.cd.component.getSymbolValue()))
72      out = []      out = []
73      hh = linspace(float(S1.h), float(S2.h), n)      hh = linspace(float(S1.h), float(S2.h), n)
74      mdot = float(S1.mdot)      mdot = float(S1.mdot)
75      for h in hh:      for h in hh:
76          res, T, rho = fprops.fprops_solve_ph(float(S1.p), h, 0, D)          # TODO add try/except
77          if not res:          S = D.set_ph(float(S1.p),h)
78              out += [THPoint(T,h * mdot)]          out += [THPoint(S.T,h * mdot)]
79      return out      return out
80
81  def plot_TH(SS,style='b-',Href = 0):  def plot_TH(SS,style='b-',Href = 0):
# Line 95  def cycle_plot_rankine(self): Line 95  def cycle_plot_rankine(self):
95      ioff()      ioff()
96      figure()      figure()
97      hold(1)      hold(1)
98      D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue()))      D = fprops.fluid(str(self.cd.component.getSymbolValue()))
99      sat_curve(D)      sat_curve(D)
100
101      boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)      boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)
# Line 163  def cycle_plot_rankine_regen1(self): Line 163  def cycle_plot_rankine_regen1(self):
163      ioff()      ioff()
164      figure()      figure()
165      hold(1)      hold(1)
166      D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue()))      D = fprops.fluid(str(self.cd.component.getSymbolValue()))
167      sat_curve(D)      sat_curve(D)
168
169      boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)      boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100)
# Line 204  def heater_closed_plot(self): Line 204  def heater_closed_plot(self):
204      ioff()      ioff()
205      figure()      figure()
206      hold(1)      hold(1)
207      D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue()))      D = fprops.fluid(str(self.cd.component.getSymbolValue()))
208      HE = self.HE      HE = self.HE
209
210      extpy.getbrowser().reporter.reportNote("Fluid is %s" % D.name)        extpy.getbrowser().reporter.reportNote("Fluid is %s" % D.name)
# Line 235  def cycle_plot_ccgt(self): Line 235  def cycle_plot_ccgt(self):
235      ioff()      ioff()
236      figure()      figure()
237
238      D = fprops.fprops_fluid(str(self.cd_rankine.component.getSymbolValue()))      D = fprops.fluid(str(self.cd_rankine.component.getSymbolValue()))
239
240      # plot gas turbine cycle      # plot gas turbine cycle
241      SS = [self.GC.inlet, self.GC.outlet, self.GT.inlet, self.GT.outlet, self.HE.inlet, self.HE.outlet, self.GC.inlet]      SS = [self.GC.inlet, self.GC.outlet, self.GT.inlet, self.GT.outlet, self.HE.inlet, self.HE.outlet, self.GC.inlet]
# Line 296  def air_stream_heat_exchanger_plot(self) Line 296  def air_stream_heat_exchanger_plot(self)
296      ioff()      ioff()
297      figure()      figure()
298      hold(1)      hold(1)
299      D = fprops.fprops_fluid(str(self.cd_cold.component.getSymbolValue()))      D = fprops.fluid(str(self.cd_cold.component.getSymbolValue()))
300
301      n = self.n.getIntValue()      n = self.n.getIntValue()
302      extpy.getbrowser().reporter.reportNote("Fluid is %s" % D.name)        extpy.getbrowser().reporter.reportNote("Fluid is %s" % D.name)

Legend:
 Removed from v.2659 changed lines Added in v.2660