def cycle_plot_brayton_reheat_regen(self): """Plot T-s diagram for reheat-regenerative gas turbine""" import loading loading.load_matplotlib(throw=True) ioff() figure() """hold(1) D = fprops.fluid(str(self.cd.component.getSymbolValue())) sat_curve(D)""" # plot gas turbine cycle boiler1_curve = pconst(self.BO1.inlet, self.BO1.outlet,100) boiler2_curve = pconst(self.BO2.inlet, self.BO2.outlet,100) condenser_curve = pconst(self.CO.inlet,self.CO.outlet,1000) SS = [self.PU.inlet, self.PU.outlet] + boiler1_curve + [self.TU1.inlet, self.TU1.outlet] + boiler2_curve + [self.TU2.inlet, self.TU2.outlet, self.CO.inlet, self.CO.outlet, self.PU.inlet] plot_Ts(SS) hold(1) title(unicode(r"Reheat Regenerative Brayton cycle")) ylabel(unicode(r"T / [°C]")) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def cycle_plot_brayton_split_regen(self): """Plot T-s diagran for regenerative gas turbine""" import loading loading.load_matplotlib(throw=True) ioff() figure() hold(1) D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue())) sat_curve(D) # plot gas turbine cycle boiler_curve = pconst(self.BO.inlet, self.BO.outlet, 100) condenser_curve = pconst(self.CO.inlet, self.CO.outlet, 100) SS = [ self.PU2.inlet, self.PU2.outlet, self.HEL.inlet, self.HEL.outlet, self.HEH.inlet, self.HEH.outlet ] + boiler_curve + [ self.TU.inlet, self.TU.outlet, self.HEH.inlet_hot, self.HEH.outlet_hot, self.HEL.inlet_hot, self.HEL.outlet_hot, self.CO.inlet, self.CO.outlet, self.PU2.inlet ] plot_Ts(SS) hold(1) title(unicode(r"Split Regenerative Brayton cycle")) ylabel(unicode(r"T / [°C]")) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show() savefig(os.path.expanduser("~/Desktop/brayton__split_regen.eps"))
def regenerator_plot_fprops(self): """Plot T-H diagram of regenerator""" import loading loading.load_matplotlib(throw=True) ioff() figure() hold(1) FH = fprops.fluid(str(self.hxd.component_hot.getSymbolValue()), str(self.hxd.type_hot.getSymbolValue())) FC = fprops.fluid(str(self.hxd.component.getSymbolValue()), str(self.hxd.type.getSymbolValue())) extpy.getbrowser().reporter.reportNote( "Hot fluid is %s, cold fluid is %s" % (FH.name, FC.name)) plot_TH(pconsth(self.inlet_hot, self.outlet_hot, 50),'r-', Href = (float(self.outlet_hot.h)*float(self.outlet_hot.mdot))\ ) plot_TH(pconsth(self.inlet, self.outlet, 50),'b-', Href = (float(self.inlet.h)*float(self.inlet.mdot))\ ) title(unicode(r"%s-%s heat exchanger" % (FH.name, FC.name))) ylabel(unicode(r"T / [°C]")) xlabel("H / [MW]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def cycle_plot_brayton_reheat_regen(self): """Plot T-s diagram for reheat-regenerative gas turbine""" import loading loading.load_matplotlib(throw=True) ioff() figure() """hold(1) D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue())) sat_curve(D)""" # plot gas turbine cycle boiler1_curve = pconst(self.BO1.inlet, self.BO1.outlet, 100) boiler2_curve = pconst(self.BO2.inlet, self.BO2.outlet, 100) condenser_curve = pconst(self.CO.inlet, self.CO.outlet, 1000) SS = [self.PU.inlet, self.PU.outlet] + boiler1_curve + [ self.TU1.inlet, self.TU1.outlet ] + boiler2_curve + [ self.TU2.inlet, self.TU2.outlet, self.CO.inlet, self.CO.outlet, self.PU.inlet ] plot_Ts(SS) hold(1) title(unicode(r"Reheat Regenerative Brayton cycle")) ylabel(unicode(r"T / [°C]")) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def air_stream_heat_exchanger_plot(self): """Plot T-H diagram of heat transfer in a heater_closed model""" import loading loading.load_matplotlib(throw=True) ioff() figure() hold(1) D = fprops.fluid(str(self.cd_cold.component.getSymbolValue())) n = self.n.getIntValue() extpy.getbrowser().reporter.reportNote("Fluid is %s" % D.name) # hot side is the air, calculated in the model plot_TH( [self.H[i] for i in range(1+int(n))],'r-',\ Href = (float(self.outlet.h)*float(self.outlet.mdot))\ ) plot_TH(pconsth(self.inlet_cold, self.outlet_cold, 50),'b-', Href = (float(self.inlet_cold.h)*float(self.inlet_cold.mdot))\ ) title(unicode(r"Combined-cycle air-%s heat exchanger" % D.name)) ylabel(unicode(r"T / [°C]")) xlabel("H / [MW]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def cycle_plot_rankine_reheat(self): """Plot T-s diagram for a reheat Rankine cycle""" import loading loading.load_matplotlib(throw=True) ioff() figure() hold(1) D = fprops.fluid(str(self.cd.component.getSymbolValue())) sat_curve(D) boiler1_curve = pconst(self.BO1.inlet, self.BO1.outlet,100) boiler2_curve = pconst(self.BO2.inlet, self.BO2.outlet,50) condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100) SS = [self.PU.outlet, self.BO1.inlet] + \ boiler1_curve + [self.TU1.inlet, self.TU1.outlet] + \ boiler2_curve + [self.TU2.inlet, self.TU2.outlet] + \ condenser_curve + [self.CO.outlet, self.PU.outlet] plot_Ts(SS) plot_Ts( [self.PU.inlet, self.BO1.inlet, self.TU1.inlet, self.BO2.inlet ,self.TU2.inlet, self.CO.inlet] ,'bo' ) title(unicode(r"Reheat Rankine cycle with %s" % D.name)) ylabel(unicode(r"T / [°C]")) aa = axis(); axis([aa[0],aa[1],-100,600]) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def cycle_plot_brayton_split_regen(self): """Plot T-s diagran for regenerative gas turbine""" import loading loading.load_matplotlib(throw=True) ioff() figure() hold(1) D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue())) sat_curve(D) # plot gas turbine cycle boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100) condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100) SS = [self.PU2.inlet, self.PU2.outlet, self.HEL.inlet, self.HEL.outlet, self.HEH.inlet, self.HEH.outlet] + boiler_curve + [self.TU.inlet, self.TU.outlet,self.HEH.inlet_hot, self.HEH.outlet_hot, self.HEL.inlet_hot, self.HEL.outlet_hot, self.CO.inlet, self.CO.outlet, self.PU2.inlet] plot_Ts(SS) hold(1) title(unicode(r"Split Regenerative Brayton cycle")) ylabel(unicode(r"T / [°C]")) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show() savefig(os.path.expanduser("~/Desktop/brayton__split_regen.eps"))
def heater_closed_plot(self): """Plot T-H diagram of heat transfer in a heater_closed model""" import loading loading.load_matplotlib(throw=True) ioff() figure() hold(1) D = fprops.fluid(str(self.cd.component.getSymbolValue())) HE = self.HE extpy.getbrowser().reporter.reportNote("Fluid is %s" % D.name) plot_TH(pconsth(HE.inlet_heat, HE.outlet_heat, 50),'r-', Href = (float(HE.outlet_heat.h)*float(HE.outlet_heat.mdot))\ ) plot_TH(pconsth(HE.inlet, HE.outlet, 50),'b-', Href = (float(HE.inlet.h)*float(HE.inlet.mdot))\ ) title(unicode(r"Closed feedwater heater with %s" % D.name)) ylabel(unicode(r"T / [°C]")) xlabel("H / [MW]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def cycle_plot_brayton_split_rachel(self): """Plot T-s diagram for a split Brayton cycle""" import loading loading.load_matplotlib(throw=True) ioff() figure() hold(1) D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue())) sat_curve(D) boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100) condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100) heh_hot_curve = pconst (self.HEH.inlet_hot, self.HEH.outlet_hot,100) hel_hot_curve = pconst (self.HEL.inlet_hot, self.HEL.outlet_hot,100) hel_curve = pconst(self.HEL.inlet, self.HEL.outlet,100) heh_curve = pconst(self.HEH.inlet, self,HEH.outlet,100) SS = boiler_curve + [self.TU.inlet, self.TU.outlet] + heh_hot_curve + hel_hot_curve + condenser_curve + [self.PU2.inlet, self.PU2.outlet]+ hel_curve + heh_curve plot_Ts(SS) title(unicode(r"Brayton cycle with %s" % D.name)) ylabel(unicode(r"T / [°C]")) aa = axis(); axis([aa[0],aa[1],-100,600]) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show() savefig(os.path.expanduser("~/Desktop/brayton.eps"))
def fourbarplot(self): """Plot the geometry of the four-bar linkage""" # following is an unfortunate necessity in the current system architecture: import loading loading.load_matplotlib(throw=True) browser = extpy.getbrowser() browser.do_solve() ioff() figure() gca().set_aspect('equal', adjustable='datalim') hold(True) for alpha in range(10, 74, 4): self.alpha.setRealValueWithUnits(alpha, "deg") try: browser.sim.solve(browser.solver, SimpleSolverReporter(browser)) except: browser.reporter.reportError('Failed to solve for alpha = %d' % alpha) continue x = [float(x) for x in [self.x_A, self.x_B, self.x_C, self.x_D]] y = [float(y) for y in [self.y_A, self.y_B, self.y_C, self.y_D]] plot(x, y, "y-") plot(x[0:2], y[0:2], "ro") plot(x[2:4], y[2:4], "bo") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def fourbarplot(self): """Plot the geometry of the four-bar linkage""" # following is an unfortunate necessity in the current system architecture: import loading loading.load_matplotlib(throw=True) browser = extpy.getbrowser() browser.do_solve() ioff() figure() gca().set_aspect('equal', adjustable='datalim') hold(True) for alpha in range(10,74,4): self.alpha.setRealValueWithUnits(alpha,"deg") try: browser.sim.solve(browser.solver,SimpleSolverReporter(browser)) except: browser.reporter.reportError('Failed to solve for alpha = %d' % alpha) continue x = [float(x) for x in [self.x_A, self.x_B, self.x_C, self.x_D]] y = [float(y) for y in [self.y_A, self.y_B, self.y_C, self.y_D]] plot(x,y,"y-") plot(x[0:2],y[0:2],"ro") plot(x[2:4],y[2:4],"bo") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def cycle_plot_brayton_split_rachel(self): """Plot T-s diagram for a split Brayton cycle""" import loading loading.load_matplotlib(throw=True) ioff() figure() hold(1) D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue())) sat_curve(D) boiler_curve = pconst(self.BO.inlet, self.BO.outlet, 100) condenser_curve = pconst(self.CO.inlet, self.CO.outlet, 100) heh_hot_curve = pconst(self.HEH.inlet_hot, self.HEH.outlet_hot, 100) hel_hot_curve = pconst(self.HEL.inlet_hot, self.HEL.outlet_hot, 100) hel_curve = pconst(self.HEL.inlet, self.HEL.outlet, 100) heh_curve = pconst(self.HEH.inlet, self, HEH.outlet, 100) SS = boiler_curve + [ self.TU.inlet, self.TU.outlet ] + heh_hot_curve + hel_hot_curve + condenser_curve + [ self.PU2.inlet, self.PU2.outlet ] + hel_curve + heh_curve plot_Ts(SS) title(unicode(r"Brayton cycle with %s" % D.name)) ylabel(unicode(r"T / [°C]")) aa = axis() axis([aa[0], aa[1], -100, 600]) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show() savefig(os.path.expanduser("~/Desktop/brayton.eps"))
def cycle_plot_ccgt(self): """Plot T-s diagram for combined-cycle gas turbine""" import loading loading.load_matplotlib(throw=True) ioff() figure() D = fprops.fluid(str(self.cd_rankine.component.getSymbolValue())) # plot gas turbine cycle SS = [self.GC.inlet, self.GC.outlet, self.GT.inlet, self.GT.outlet, self.HE.inlet, self.HE.outlet, self.GC.inlet] plot_Ts(SS,'g-') plot_Ts(SS,'go') hold(1) sat_curve(D) boiler_curve = pconst(self.HE.inlet_cold,self.HE.outlet_cold,100) condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100) 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] plot_Ts(SS2) 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') title(unicode(r"Combined cycle with air and %s" % D.name)) ylabel(unicode(r"T / [°C]")) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def cycle_plot_brayton_reheat_regen_intercool(self): """Plot T-s diagram for reheat-regenerative gas turbine""" import loading loading.load_matplotlib(throw=True) ioff() figure() hold(1) D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue())) sat_curve(D) # add some dots for the points in the cycle seq = "CO1.inlet DI2.inlet CO2.inlet RE.inlet BU1.inlet TU1.inlet BU2.inlet TU2.inlet RE.inlet_hot DI1.inlet".split( " ") lalign = "TU2.inlet RE.inlet_hot BU2.inlet DI1.inlet DI2.inlet CO1.inlet".split( " ") SS1 = [] SS1a = [] for s in seq: print "looking at '%s'" % s p = reduce(getattr, s.split("."), self) SS1.append(p) SS1a.append((p, s)) plot_Ts(SS1, 'bo') print "ANNOTATIONS" for s in SS1a: align = "right" if s[1] in lalign: align = "left" annotate(s[1] + " ", xy=(float(s[0].s) / 1.e3, float(s[0].T) - 273.15), horizontalalignment=align) # plot the cycle with smooth curves BU1_curve = pconst(self.BU1.inlet, self.BU1.outlet, 30) BU2_curve = pconst(self.BU2.inlet, self.BU2.outlet, 20) DI1_curve = pconst(self.DI1.inlet, self.DI1.outlet, 20) DI2_curve = pconst(self.DI2.inlet, self.DI2.outlet, 20) REH_curve = pconst(self.RE.inlet_hot, self.RE.outlet_hot, 50) REL_curve = pconst(self.RE.inlet, self.RE.outlet, 50) 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] plot_Ts(SS2) title(unicode(r"Reheat Regenerative Brayton cycle with Intercooling")) ylabel(unicode(r"T / [°C]")) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def cycle_plot_brayton_reheat_regen_intercool(self): """Plot T-s diagram for reheat-regenerative gas turbine""" import loading loading.load_matplotlib(throw=True) ioff() figure() hold(1) D = fprops.fluid(str(self.cd.component.getSymbolValue()),str(self.cd.type.getSymbolValue())) sat_curve(D) # add some dots for the points in the cycle 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(" ") lalign = "TU2.inlet RE.inlet_hot DI1.inlet DI2.inlet CO1.inlet".split(" ") SS1 = []; SS1a = [] for s in seq: print "looking at '%s'"%s p = reduce(getattr,s.split("."),self) SS1.append(p) SS1a.append((p,s)) plot_Ts(SS1,'go') print "ANNOTATIONS" for s in SS1a: align = "right" if s[1] in lalign: align = "left" annotate(s[1]+" ", xy =(float(s[0].s)/1.e3,float(s[0].T) - 273.15) ,horizontalalignment=align ) # plot the cycle with smooth curves BU1_curve = pconst(self.BU1.inlet, self.BU1.outlet,30) BU2_curve = pconst(self.BU2.inlet, self.BU2.outlet,20) DI1_curve = pconst(self.DI1.inlet,self.DI1.outlet,20) DI2_curve = pconst(self.DI2.inlet,self.DI2.outlet,20) REH_curve = pconst(self.RE.inlet_hot,self.RE.outlet_hot,50) REL_curve = pconst(self.RE.inlet,self.RE.outlet,50) 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] plot_Ts(SS2,'g-') SS3 = [self.RE.inlet, self.RE.outlet_hot] plot_Ts(SS3,'g--') SS4 = [self.RE.outlet, self.RE.inlet_hot] plot_Ts(SS4,'g--') title(unicode(r"Reheat Regenerative Brayton cycle with Intercooling")) ylabel(unicode(r"T / [°C]")) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def cycle_plot_brayton_split(self): """Plot T-s diagran for split-regeneration gas turbine""" import loading loading.load_matplotlib(throw=True) ioff() figure() hold(1) D = fprops.fluid(str(self.cd.component.getSymbolValue()),str(self.cd.type.getSymbolValue())) sat_curve(D) # add some dots for the points in the cycle # seq = "CO2.inlet HEL.inlet HEL.outlet HEH.inlet BO.inlet TU.inlet HEH.inlet_hot HEL.inlet_hot CO1.inlet CO1.outlet".split(" ") seq = "CO2.inlet HEL.inlet HEH.inlet BO.inlet TU.inlet HEH.inlet_hot HEH.outlet_hot CO1.inlet".split(" ") lalign = "CO1.inlet HEH.outlet_hot ".split(" ") SS1 = []; SS1a = [] for s in seq: print "looking at '%s'"%s p = reduce(getattr,s.split("."),self) SS1.append(p) SS1a.append((p,s)) plot_Ts(SS1,'go') print "ANNOTATIONS" for s in SS1a: align = "right" if s[1] in lalign: align = "left" annotate(s[1]+" ", xy =(float(s[0].s)/1.e3,float(s[0].T) - 273.15) ,horizontalalignment=align ) 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] plot_Ts(SS2,'g-') SS3 = [self.HEL.inlet, self.HEL.outlet_hot] plot_Ts(SS3,'g--') SS4 = [self.HEL.outlet, self.HEL.inlet_hot] plot_Ts(SS4,'g--') SS5 = [self.HEH.inlet, self.HEH.outlet_hot] plot_Ts(SS5,'g--') SS6 = [self.HEH.outlet, self.HEH.inlet_hot] plot_Ts(SS6,'g--') title(unicode(r"Split Regenerative Brayton cycle")) ylabel(unicode(r"T / [°C]")) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show() savefig(os.path.expanduser("~/Desktop/brayton__split_regen.eps"))
def txyplot(self): browser = extpy.getbrowser() ioff() figure() for P in [70000.0]: self.P.setRealValue(P) XX1 = [] TT1 = [] XX2 = [] TT2 = [] for x1 in [0.01,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.40,0.45,0.50,0.55,0.60,0.65,0.7,0.75,0.8,0.85,0.9,0.95,0.99]: self.x1.setRealValue(x1) try: browser.sim.solve(browser.solver,SimpleSolverReporter(browser,message="P = %f, x1 = %f" % (P,x1))) XX1.append(float(self.x1)) TT1.append(float(self.TdegC)) XX2.append(float(self.y1)) TT2.append(float(self.TdegC)) except: browser.reporter.reportError('Failed to solve for x1 = %f' % x1) continue xlabel("Mole Fraction (x or y)") ylabel("Temperature in degrees C") title("Txy plot") plot(XX1,TT1) plot(XX2,TT2) hold(1) ion() show()
def solve(self): """ run the active solver on the current model (reporting to the status bar only) """ assert self.__class__.__name__=="Instance" assert self.isModel() print "SELF IS A MODEL" browser = extpy.getbrowser() if browser: print "Using browser.solver" solver = browser.solver else: print "Using hardwired default solver, QRSlv" solver = ascpy.Solver("QRSlv") if browser and have_solverreporter: reporter = SimpleSolverReporter(browser) else: print "Using console solver reporter" reporter = ascpy.SolverReporter() # the 'sim' object is registered in simulation.cpp each time a method is to be run # (an exception is thrown if not available (eg if C++ not being used) sim = ascpy.Registry().getSimulation("sim") sim.solve(solver,reporter)
def solve(self): """ run the active solver on the current model (reporting to the status bar only) """ assert self.__class__.__name__ == "Instance" assert self.isModel() print "SELF IS A MODEL" browser = extpy.getbrowser() if browser: print "Using browser.solver" solver = browser.solver else: print "Using hardwired default solver, QRSlv" solver = ascpy.Solver("QRSlv") if browser and have_solverreporter: reporter = SimpleSolverReporter(browser) else: print "Using console solver reporter" reporter = ascpy.SolverReporter() # the 'sim' object is registered in simulation.cpp each time a method is to be run # (an exception is thrown if not available (eg if C++ not being used) sim = ascpy.Registry().getSimulation("sim") sim.solve(solver, reporter)
def pxyplot(self): browser = extpy.getbrowser() ioff() figure() for T in [340]: self.T.setRealValue(T) XX1 = [] PP1 = [] XX2 = [] PP2 = [] for x1 in [0.01,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.40,0.45,0.50,0.55,0.60,0.65,0.7,0.75,0.8,0.85,0.9,0.95,0.99]: self.x1.setRealValue(x1) try: browser.sim.solve(browser.solver,SimpleSolverReporter(browser,message="T = %f, x1 = %f" % (T,x1))) XX1.append(float(self.x1)) PP1.append(float(self.P)) XX2.append(float(self.y1)) PP2.append(float(self.P)) except: browser.reporter.reportError('Failed to solve for x1 = %f' % x1) continue xlabel("Mole Fraction (x or y)") ylabel("Pressure in pascals") title("Pxy plot") plot(XX1,PP1) plot(XX2,PP2) hold(1) ion() show()
def zplot(self): browser = extpy.getbrowser() ioff() figure() axes([0.1, 0.1, 0.71, 0.8]) # # I have chosen three temperatures # TT = [190, 210, 230, 250, 270, 290, 310, 330, 350, 370] for T in TT: self.T.setRealValue(T) # # collect the data for plotting in two sets of arrays (one for X, one for Y) # I have two sets here - one for P versus y and other for P versus x # PPr1 = [] ZZ1 = [] # # change x1 from 0 to 1.0 # there has to be a space between "in" and "[" # for P in [ 10, 11, 12, 13, 15, 20, 25, 30, 40, 50, 60, 70, 80, 100, 120, 140, 150, 170, 175, 180, 185, 190 ]: self.P.setRealValueWithUnits(P, "bar") # # send the pair of values T x1 to the solver # and append the Pressure and y1 (from the solver) to the arrays # the x's are also appended try: browser.sim.solve( browser.solver, SimpleSolverReporter(browser, message="T = %f, P = %f" % (T, P))) PPr1.append(float(self.Pr)) ZZ1.append(float(self.Z)) except: browser.reporter.reportError('Failed to solve for P = %f' % P) continue ## plot the data plot(PPr1, ZZ1, label="%d K" % T) hold(1) # after all the plots are done, add some labels and a legend xlabel("Reduced pressure, p/p_crit") ylabel("Generalised compressibility, z") legend(loc=(1.03, 0.2)) ion() show()
def pvplot(self): browser = extpy.getbrowser() ioff() figure() # # I have chosen several temperatures # TT = [190, 210, 230, 250, 270, 290, 310, 330, 350, 370, 400, 420] for T in TT: self.T.setRealValue(T) # # collect the data for plotting in two sets of arrays (one for X, one for Y) # I have one set here - for P versus V at different T's # XX1 = [] YY1 = [] # # there has to be a space between "in" and "[" # for P in [ 8, 9, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 100, 120, 140, 150, 170, 190 ]: self.P.setRealValueWithUnits(P, "bar") # # send the pair of values P, T to the solver # and append the Volume and Pressure from the solver to the arrays try: browser.sim.solve( browser.solver, SimpleSolverReporter(browser, message="T = %f, P = %f" % (T, P))) XX1.append(float(self.V)) YY1.append(float(self.P)) except: browser.reporter.reportError('Failed to solve for P = %f' % P) continue ## plot the data plot(XX1, YY1, label=("%d K" % T)) hold(1) legend() xlabel("Molar volume") ylabel("Presure (Pa)") title("p-V curves at varying temperatures") ion() show()
def cycle_plot_rankine_regen2(self): """Plot T-s diagram for a regenerative Rankine cycle (bleed steam regen)""" import loading loading.load_matplotlib(throw=True) ioff() figure() hold(1) D = fprops.fluid(str(self.cd.component.getSymbolValue()),str(self.cd.type.getSymbolValue())) sat_curve(D) boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100) condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100) SS = [self.PU1.inlet, self.PU1.outlet] + \ pconst(self.HE.inlet, self.HE.outlet, 100) + \ [self.PU2.inlet, self.PU2.outlet] + \ boiler_curve + \ [self.TU1.inlet, self.TU1.outlet, self.TU2.outlet] + \ condenser_curve + [self.PU1.inlet] plot_Ts(SS) plot_Ts( [self.PU1.inlet, self.PU1.outlet, self.HE.inlet, self.HE.outlet, self.PU2.inlet, self.PU2.outlet, self.TU1.inlet, self.TU1.outlet, self.TU2.outlet, self.PU1.inlet] ,'bo' ) # line for the heat exchanger plot_Ts(pconst(self.HE.inlet_heat, self.HE.outlet,100),'b-') title(unicode(r"Regenerative Rankine cycle with %s" % D.name)) ylabel(unicode(r"T / [°C]")) aa = axis(); axis([aa[0],aa[1],-100,600]) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show() savefig(os.path.expanduser("~/Desktop/regen2.eps"))
def cycle_plot_rankine_regen2(self): """Plot T-s diagram for a regenerative Rankine cycle (bleed steam regen)""" import loading loading.load_matplotlib(throw=True) ioff() figure() hold(1) D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue())) sat_curve(D) boiler_curve = pconst(self.BO.inlet, self.BO.outlet, 100) condenser_curve = pconst(self.CO.inlet, self.CO.outlet, 100) SS = [self.PU1.inlet, self.PU1.outlet] + \ pconst(self.HE.inlet, self.HE.outlet, 100) + \ [self.PU2.inlet, self.PU2.outlet] + \ boiler_curve + \ [self.TU1.inlet, self.TU1.outlet, self.TU2.outlet] + \ condenser_curve + [self.PU1.inlet] plot_Ts(SS) plot_Ts([ self.PU1.inlet, self.PU1.outlet, self.HE.inlet, self.HE.outlet, self.PU2.inlet, self.PU2.outlet, self.TU1.inlet, self.TU1.outlet, self.TU2.outlet, self.PU1.inlet ], 'bo') # line for the heat exchanger plot_Ts(pconst(self.HE.inlet_heat, self.HE.outlet, 100), 'b-') title(unicode(r"Regenerative Rankine cycle with %s" % D.name)) ylabel(unicode(r"T / [°C]")) aa = axis() axis([aa[0], aa[1], -100, 600]) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show() savefig(os.path.expanduser("~/Desktop/regen2.eps"))
def regenerator_plot_fprops(self): """Plot T-H diagram of regenerator""" import loading; loading.load_matplotlib(throw=True) ioff(); figure(); hold(1) D = fprops.fprops_fluid(str(self.cd.component.getSymbolValue())) extpy.getbrowser().reporter.reportNote("Fluid is %s" % D.name) plot_TH(pconsth(self.inlet_hot, self.outlet_hot, 50),'r-', Href = (float(self.outlet_hot.h)*float(self.outlet_hot.mdot))\ ) plot_TH(pconsth(self.inlet, self.outlet, 50),'b-', Href = (float(self.inlet.h)*float(self.inlet.mdot))\ ) title(unicode(r"%s heat exchanger" % D.name)) ylabel(unicode(r"T / [°C]")) xlabel("H / [MW]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def cycle_plot_brayton_regen(self): """Plot T-s diagran for regenerative gas turbine""" import loading loading.load_matplotlib(throw=True) ioff() figure() D = fprops.fluid(str(self.cd.component.getSymbolValue())) sat_curve(D) # plot gas turbine cycle regen_cold_curve = pconst(self.RE.inlet, self.RE.outlet, 50) burner_curve = pconst(self.BO.inlet, self.BO.outlet,50) regen_hot_curve = pconst(self.RE.inlet_hot, self.RE.outlet_hot, 50) diss_curve = pconst(self.CO.inlet, self.CO.outlet,50) 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] plot_Ts(SS,'g-') 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] plot_Ts(SS2,'go') SS3 = [self.RE.inlet, self.RE.outlet_hot] plot_Ts(SS3,'g--') SS4 = [self.RE.outlet, self.RE.inlet_hot] plot_Ts(SS4,'g--') hold(1) title(unicode(r"Regenerative Brayton cycle")) ylabel(unicode(r"T / [°C]")) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def leastsq_plot(self): """Plot a least-squares fit, no added intermediate points though.""" import loading loading.load_matplotlib(throw=True) ioff() figure() n = self.n.getIntValue() x = [] y = [] ye = [] for i in range(n): x.append(float(self.x[i + 1])) y.append(float(self.y[i + 1])) ye.append(float(self.f[i + 1].y)) plot(x, y, 'bo') plot(x, ye, 'b-') extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def leastsq_plot(self): """Plot a least-squares fit, no added intermediate points though.""" import loading loading.load_matplotlib(throw=True) ioff() figure() n = self.n.getIntValue() x = [] y = [] ye = [] for i in range(n): x.append(float(self.x[i+1])) y.append(float(self.y[i+1])) ye.append(float(self.f[i+1].y)) plot(x,y,'bo') plot(x,ye,'b-') extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def cycle_plot_brayton_regen(self): """Plot T-s diagran for regenerative gas turbine""" import loading loading.load_matplotlib(throw=True) ioff() figure() hold(1) D = fprops.fluid(str(self.cd.component.getSymbolValue()),str(self.cd.type.getSymbolValue())) sat_curve(D) # plot gas turbine cycle SS = [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] plot_Ts(SS,'g-') plot_Ts(SS,'go') hold(1) title(unicode(r"Regenerative Brayton cycle")) ylabel(unicode(r"T / [°C]")) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show() savefig(os.path.expanduser("~/Desktop/brayton_regen.eps"))
def cycle_plot_rankine_regen1(self): """Plot T-s diagram for a regenerative Rankine cycle""" import loading loading.load_matplotlib(throw=True) ioff() figure() hold(1) D = fprops.fluid(str(self.cd.component.getSymbolValue())) sat_curve(D) boiler_curve = pconst(self.BO.inlet, self.BO.outlet,100) condenser_curve = pconst(self.CO.inlet,self.CO.outlet,100) he_hot = pconst(self.HE.inlet_heat, self.HE.outlet_heat,100) he_cold = pconst(self.HE.inlet, self.HE.outlet,100) 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] plot_Ts(SS) plot_Ts( [self.PU.outlet,self.BO.inlet,self.TU.inlet, self.TU.outlet ,self.HE.outlet_heat, self.PU.inlet, self.PU.outlet] ,'bo' ) # dotted lines for the heat exchanger plot_Ts([self.HE.inlet_heat, self.HE.outlet],'b:') plot_Ts([self.HE.outlet_heat, self.HE.inlet],'b:') title(unicode(r"Regenerative Rankine cycle with %s" % D.name)) ylabel(unicode(r"T / [°C]")) aa = axis(); axis([aa[0],aa[1],-100,600]) xlabel("s / [kJ/kg/K]") extpy.getbrowser().reporter.reportNote("Plotting completed") ion() show()
def zplot(self): browser = extpy.getbrowser() ioff() figure() axes([0.1,0.1,0.71,0.8]) # # I have chosen three temperatures # TT = [190,210,230,250,270,290,310,330,350,370] for T in TT: self.T.setRealValue(T) # # collect the data for plotting in two sets of arrays (one for X, one for Y) # I have two sets here - one for P versus y and other for P versus x # PPr1 = [] ZZ1 = [] # # change x1 from 0 to 1.0 # there has to be a space between "in" and "[" # for P in [10,11,12,13,15,20,25,30,40,50,60,70,80,100,120,140,150,170,175,180,185,190]: self.P.setRealValueWithUnits(P,"bar") # # send the pair of values T x1 to the solver # and append the Pressure and y1 (from the solver) to the arrays # the x's are also appended try: browser.sim.solve(browser.solver,SimpleSolverReporter(browser,message="T = %f, P = %f" % (T,P))) PPr1.append(float(self.Pr)) ZZ1.append(float(self.Z)) except: browser.reporter.reportError('Failed to solve for P = %f' % P) continue ## plot the data plot(PPr1,ZZ1,label="%d K" % T) hold(1) # after all the plots are done, add some labels and a legend xlabel("Reduced pressure, p/p_crit") ylabel("Generalised compressibility, z") legend(loc=(1.03,0.2)) ion() show()
def pvplot(self): browser = extpy.getbrowser() ioff() figure() # # I have chosen several temperatures # TT = [190,210,230,250,270,290,310,330,350,370,400,420] for T in TT: self.T.setRealValue(T) # # collect the data for plotting in two sets of arrays (one for X, one for Y) # I have one set here - for P versus V at different T's # XX1 = [] YY1 = [] # # there has to be a space between "in" and "[" # for P in [8,9,10,15,20,25,30,40,50,60,70,80,100,120,140,150,170,190]: self.P.setRealValueWithUnits(P,"bar") # # send the pair of values P, T to the solver # and append the Volume and Pressure from the solver to the arrays try: browser.sim.solve(browser.solver,SimpleSolverReporter(browser,message="T = %f, P = %f" % (T,P))) XX1.append(float(self.V)) YY1.append(float(self.P)) except: browser.reporter.reportError('Failed to solve for P = %f' % P) continue ## plot the data plot(XX1,YY1,label=("%d K" % T)) hold(1) legend() xlabel("Molar volume") ylabel("Presure (Pa)") title("p-V curves at varying temperatures") ion() show()
def framevis(self): """Visualise the frame using OpenGL and GtkGlExt""" browser = extpy.getbrowser() if not browser: print "no 'browser'" return 1 if not gtkgl_deps: browser.reporter.reportError("Unable to load PyGtkGlExt") return 1 REP = browser.reporter.reportNote frame = AscFrame(self) win = ModelWindow(frame) win.run()
def roots(self): """Plot the complex eigenvalues of a DAE system""" # the following is an unfortunate necessity in the current system architecture: browser = extpy.getbrowser() M = browser.sim M.setSolver(ascpy.Solver('QRSlv')) # get IDA to analyse the DAE structure I = ascpy.Integrator(M) I.setEngine('IDA') I.setReporter(ascpy.IntegratorReporterConsole(I)) I.analyse() # write the results of analysis to some tempfiles fff = createfiles() for k,v in fff.iteritems(): F = file(v,'w') I.writeMatrix(F,k) print "WROTE MATRICES TO FILE. NOW PROCESSING..." # we can't import scipy here due to a crash. so we must use a subprocess... script = os.path.expanduser('~/ascend/models/johnpye/roots_subproc.py') if os.path.exists(script): P = subprocess.Popen(['python',script]+[fff[d] for d in derivs],stdout=subprocess.PIPE,close_fds=True) ret = P.wait() if ret: print "GOT ERROR CODE FROM roots_subproc.py" browser.reporter.reportError(P.stdout.read()) deletefiles(fff) return 1 print "OK" else: browser.reporter.reportError("Couldn't find script '%s'" % script) deletefiles(fff) return 1 deletefiles(fff) return 0
def txyplot(self): browser = extpy.getbrowser() ioff() figure() for P in [70000.0]: self.P.setRealValue(P) XX1 = [] TT1 = [] XX2 = [] TT2 = [] for x1 in [ 0.01, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.40, 0.45, 0.50, 0.55, 0.60, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.99 ]: self.x1.setRealValue(x1) try: browser.sim.solve( browser.solver, SimpleSolverReporter(browser, message="P = %f, x1 = %f" % (P, x1))) XX1.append(float(self.x1)) TT1.append(float(self.TdegC)) XX2.append(float(self.y1)) TT2.append(float(self.TdegC)) except: browser.reporter.reportError('Failed to solve for x1 = %f' % x1) continue xlabel("Mole Fraction (x or y)") ylabel("Temperature in degrees C") title("Txy plot") plot(XX1, TT1) plot(XX2, TT2) hold(1) ion() show()
def pxyplot(self): browser = extpy.getbrowser() ioff() figure() for T in [340]: self.T.setRealValue(T) XX1 = [] PP1 = [] XX2 = [] PP2 = [] for x1 in [ 0.01, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.40, 0.45, 0.50, 0.55, 0.60, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.99 ]: self.x1.setRealValue(x1) try: browser.sim.solve( browser.solver, SimpleSolverReporter(browser, message="T = %f, x1 = %f" % (T, x1))) XX1.append(float(self.x1)) PP1.append(float(self.P)) XX2.append(float(self.y1)) PP2.append(float(self.P)) except: browser.reporter.reportError('Failed to solve for x1 = %f' % x1) continue xlabel("Mole Fraction (x or y)") ylabel("Pressure in pascals") title("Pxy plot") plot(XX1, PP1) plot(XX2, PP2) hold(1) ion() show()
def timestudy(self): # following is an unfortunate necessity in the current system architecture: browser = extpy.getbrowser() # just check that all is ok browser.do_solve() # set up figure ioff() figure() # calculate time points in advance tvalue = float(self.t); tincr = 1800 # seconds tt = [] for i in range(1*24*3600/tincr): tt.append(tvalue); tvalue += tincr series = [unicode('G [W/m²]'), unicode('Gbn [W/m²]'), unicode('Gd [W/m²]'),'T [K]', 'v_wind [m/s]'] xdata = [] ydata = [[], [], [], [], []] for t in tt: self.t.setRealValueWithUnits(t,"s") try: browser.sim.solve(browser.solver,SimpleSolverReporter(browser,"t = %f"%(t))) except: browser.reporter.reportError('Failed to solve for t = %f' % t) continue xdata.append(t / 3600.) # ydata[0].append(self.G.as("W/m^2")) # ydata[1].append(self.Gbn.as("W/m^2")) # ydata[2].append(self.Gd.as("W/m^2")) # ydata[3].append(self.T.as("K") - 273.15) # ydata[4].append(self.v_wind.as("m/s")) ydata[0].append(self.G("W/m^2")) ydata[1].append(self.Gbn("W/m^2")) ydata[2].append(self.Gd("W/m^2")) ydata[3].append(self.T("K") - 273.15) ydata[4].append(self.v_wind("m/s")) subplot(311) plot(xdata,ydata[0]) title("Weather data vs Time") ylabel(unicode("Radiation / [W/m²]")) hold(1) plot(xdata,ydata[1]) plot(xdata,ydata[2]) legend(series[0:3]) grid(1) subplot(312) plot(xdata,ydata[3]) ylabel('Temperature [K]') grid(1) subplot(313) plot(xdata,ydata[4]) ylabel('Wind speed [m/s]') grid(1) xlabel("Time / [h]") ion() show()
def solvernotes(self): """ use the NOTES DB to set parameters applicable to the current active solver """ print "SETUP_SOLVER..." sim = ascpy.Registry().getSimulation('sim') browser = extpy.getbrowser() if browser: reporter = browser.reporter else: print "Using console solver reporter" reporter = ascpy.getReporter() if browser: print "Using browser.solver" solver = browser.solver else: print "Using hardwired default solver, QRSlv" solver = ascpy.Solver("QRSlv") db = ascpy.Library().getAnnotationDatabase() print "GOT SIM..." if not sim: reporter.reportError("No simulation present yet") return if not solver: reporter.reportError("No solver yet") return # the simulation needs to be built at this point, else solver could not # be selected, and hence solver params could not be assigned. sim.build() # use the solver selected in the browser sim.setSolver(solver) solvername = solver.getName() reporter.reportNote("Active solver is '%s'" % solvername) notes = db.getNotes(self.getType(),ascpy.SymChar(solvername)) print "GETTING SOLVER PARAMS..." params = sim.getParameters() print "DONE SOLVER PARAMS" print params paramnames = [p.getName() for p in params] print "DONE PARAMS" for i in range(0,len(notes)): note = notes[i] if note.getId()==None: browser.reporter.reportNote("Empty note ID...") continue n = note.getId() param = None for p in params: if p.getName()==n: param = p if param: if param.isInt(): v = int( note.getText() ) param.setIntValue(v) elif param.isReal(): v = float( note.getText() ) param.setRealValue(v) elif param.isStr(): v = note.getText() param.setStrValue(v) elif param.isBool(): v = bool( note.getText() ) param.setBoolValue(v) else: raise Exception("unknown parameter type") reporter.reportNote("Set %s = %s" % (param.getName(),v)) else: reporter.reportWarning("Ignoring unrecognised parameter '%s' for solver '%s' (from solver notes)\n%s:%d" % (n,solvername,note.getFilename(),note.getLineNumber()))
def write(msg): extpy.getbrowser().reporter.reportNote(msg)
def timestudy(self): # following is an unfortunate necessity in the current system architecture: browser = extpy.getbrowser() # just check that all is ok browser.do_solve() # set up figure ioff() figure() # calculate time points in advance tvalue = float(self.t) tincr = 1800 # seconds tt = [] for i in range(1 * 24 * 3600 / tincr): tt.append(tvalue) tvalue += tincr series = [ unicode('G [W/m²]'), unicode('Gbn [W/m²]'), unicode('Gd [W/m²]'), 'T [K]', 'v_wind [m/s]' ] xdata = [] ydata = [[], [], [], [], []] for t in tt: self.t.setRealValueWithUnits(t, "s") try: browser.sim.solve(browser.solver, SimpleSolverReporter(browser, "t = %f" % (t))) except: browser.reporter.reportError('Failed to solve for t = %f' % t) continue xdata.append(t / 3600.) # ydata[0].append(self.G.as("W/m^2")) # ydata[1].append(self.Gbn.as("W/m^2")) # ydata[2].append(self.Gd.as("W/m^2")) # ydata[3].append(self.T.as("K") - 273.15) # ydata[4].append(self.v_wind.as("m/s")) ydata[0].append(self.G("W/m^2")) ydata[1].append(self.Gbn("W/m^2")) ydata[2].append(self.Gd("W/m^2")) ydata[3].append(self.T("K") - 273.15) ydata[4].append(self.v_wind("m/s")) subplot(311) plot(xdata, ydata[0]) title("Weather data vs Time") ylabel(unicode("Radiation / [W/m²]")) hold(1) plot(xdata, ydata[1]) plot(xdata, ydata[2]) legend(series[0:3]) grid(1) subplot(312) plot(xdata, ydata[3]) ylabel('Temperature [K]') grid(1) subplot(313) plot(xdata, ydata[4]) ylabel('Wind speed [m/s]') grid(1) xlabel("Time / [h]") ion() show()
import ascpy import extpy browser = extpy.getbrowser() def listnotes(self): """ make a list of NOTES for the present model """ self = ascpy.Registry().getInstance('context') db = browser.library.getAnnotationDatabase() notes = db.getNotes(self.getType(),ascpy.SymChar("solver")) for i in range(1,len(notes)): mm = notes[i].getMethod() ll = notes[i].getLanguage() ii = notes[i].getId() tt = notes[i].getText() s = "type = %s, method = %s, lang = %s, id = %s, text = %s" % (notes[i].getType(), mm, ll, ii, tt) print "NOTES:",s browser.reporter.reportNote(s) # note: 'setup_solver' moved to 'solvernotes.py' (and renamed) extpy.registermethod(listnotes)