def Psat_d(d): def dsv(p): return F.ds(p=p)[1] Ps_d = pmsolve.solve1n('p', f=dsv, param_init=1) try: return Ps_d(d) except pm.utility.PMParamError: print('Selected density does not intersect the steam dome.') return None
def P_d(T, d): P_d = pmsolve.solve1n('p', f=F.ds, param_init=1) return P_d(d, T=T)
T1, x1 = F.T_s(p=p1, s=s1, quality=True) if x1 > 0: #Check if saturated d1 = F.d(T=T1, x=x1) h1 = F.h(T=T1, x=x1) else: d1 = F.d(T=T1, p=p1) h1 = F.h(T=T1, p=p1) v1 = 1 / d1 e1 = F.e(d=d1, p=p1) elif T1 >= -9000 and s1 >= -9000: #T&s # Set the input box labels Tval = T1 sval = s1 #Must find P iteratively P_T = pmsolve.solve1n('p', f=F.T_s, param_init=20) p1 = P_T(T1, s=s1) T1, x1 = F.T_s(p=p1, s=s1, quality=True) if x1 > 0: #check if saturated h1, s1, d1 = F.hsd(T=T1, x=x1) else: h1, s1, d1 = F.hsd(p=p1, T=T1) v1 = 1 / d1 p1 = F.p(T=T1, d=d1) e1 = F.e(d=d1, p=p1) elif T1 >= -9000 and p1 >= -9000: #T&p #set the input box labels Tval = T1 pval = p1 h1, s1, d1 = F.hsd(p=p1, T=T1)
def P_h(T, h): P_h = pmsolve.solve1n('p', f=F.T_h, param_init=100) return P_h(T, h=h)
def Tv(mpobj, fig=None, ax=None, satlines=True, Tlim=None, slines=None, plines=None, hlines=None, size=config['size'], display=True): """Temperature-volume diagram ax = Tv(mpobj) """ # Select a figure if fig is None: if ax is not None: fig = ax.get_figure() else: fig = plt.figure(figsize=size) elif isinstance(fig, matplotlib.figure.Figure): pass else: fig = plt.figure(fig) # Select an axes if ax is None: fig.clf() ax = fig.add_subplot(111) #Critical and Tripe point properties Tc, pc, dc = mpobj.critical(density=True) Tt, pt = mpobj.triple() #auto compute T limits if Tlim is None: Tlim = mpobj.Tlim() #Compute pressure limits plim = mpobj.plim() plim[0] = max(pt, plim[0]) #Get lines of Entropy, pressure and enthalpy if slines is None: SLINES = _slines(mpobj) else: SLINES = np.asarray(slines) if plines is None: PLINES = _plines(mpobj) else: PLINES = np.asarray(plines) if hlines is None: HLINES = _hlines(mpobj,n=5) else: HLINES = np.asarray(hlines) # Generate lines Tn = (Tc - Tt) / 1000. T = np.linspace(Tlim[0] + Tn, Tlim[1] - Tn, 151) #a base temperature vector # Lines of constant pressure PLABELS = {} for p in PLINES: d = mpobj.d(T=T, p=p) ax.semilogx(1/d, T, config['p_style'], color=config['p_color'], lw=config['p_width']) PLABELS[p] = _get_slope(1/d, T, 1, 0.1, 'logx') # Lines of constant entropy SLABELS = {} for s in np.copy(SLINES): try: psp = np.logspace(np.log10(1e-5 * plim[1]), np.log10(0.95 * plim[1]), 20) T, xh = mpobj.T_s(p=psp, s=s, quality=True) v = 1 / mpobj.d(T=T, p=psp) if (max(xh) > 0): v[xh > 0] = 1 / mpobj.d(T=T[xh > 0], x=xh[xh > 0]) ax.plot(v, T, config['d_style'], color=config['d_color'], lw=config['d_width']) SLABELS[s] = _get_slope(v, T, 0, 0.1, 'logx') except pm.utility.PMAnalysisError: try: p_s = pmsolve.solve1n('p', f=mpobj.T_s, param_init=1.5*plim[0]) pmax = p_s(0.95*Tlim[1],s=s) psp2 = np.logspace(np.log10(1e-5 * plim[1]), np.log10(pmax), 20) T, xh = mpobj.T_s(p=psp2, s=s, quality=True) v = 1 / mpobj.d(T=T, p=psp2) if (max(xh) > 0): v[xh > 0] = 1 / mpobj.d(T=T[xh > 0], x=xh[xh > 0]) ax.plot(v, T, config['s_style'], color=config['s_color'], lw=config['s_width']) SLABELS[s] = _get_slope(v, T, 0.75, 0.1, 'logx') except pm.utility.PMAnalysisError as E: SLINES = np.setdiff1d(SLINES,s) #removes s print('s=', s, ' failed due to iter1_() guess error') # Lines of constant enthalpy HLABELS = {} for h in np.copy(HLINES): # Copy HLINES for the iteration, so that we can remove ones that fail try: psp = np.logspace(np.log10(1e-5*plim[1]),np.log10(0.95*plim[1]),25) T, xh = mpobj.T_h(p=psp, h=h, quality=True) v = 1/mpobj.d(T=T, p=psp) if (max(xh) > 0): v[xh > 0] = 1/mpobj.d(T=T[xh > 0], x=xh[xh > 0]) ax.plot(v, T, config['h_style'], color=config['h_color'], lw=config['h_width']) HLABELS[h] = _get_slope(v, T, 1, 0.05, 'logx') except pm.utility.PMAnalysisError: HLINES = np.setdiff1d(HLINES,h) #removes h print('h=',h,' failed due to iter1_() guess error') # Generate the dome T = np.linspace(Tt + Tn, Tc - Tn, 101) dsL, dsV = mpobj.ds(T) ax.semilogx(1/dsL, T, ls=config['sat_style'], color=config['sat_color'], lw=config['sat_width']) ax.semilogx(1/dsV, T, ls=config['sat_style'], color=config['sat_color'], lw=config['sat_width']) # Get the scaling ratio for slopes r = _slope_ratio(ax, scaling='logx') # LABELS of constant pressure units = '%s' % (pm.config['unit_pressure']) loc = ('right','top') color = config['p_color'] numformat = '%.3g' _labellines(ax,PLINES,PLABELS,r,units,numformat,loc,color) # LABELS of constant enthalpy units = '%s/%s' % (pm.config['unit_energy'], pm.config['unit_matter']) loc = ('right','top') color = config['h_color'] numformat = '%d ' _labellines(ax,HLINES,HLABELS,r,units,numformat,loc,color) # LABELS of constant entropy units = '%s/(%s%s)' % (pm.config['unit_energy'], pm.config['unit_matter'],pm.config['unit_temperature']) loc = ('left','top') color = config['s_color'] numformat = '%0.2g' _labellines(ax,SLINES,SLABELS,r,units,numformat,loc,color) # Label the v-axis ax.set_xlabel('v [%s/%s]' % ( pm.config['unit_volume'], pm.config['unit_matter'], )) # Label the T-axis ax.set_ylabel('T [%s]' % ( pm.config['unit_temperature'])) # Label the figure ax.set_title('%s T-v Diagram' % (mpobj.data['id'])) if display: plt.show(block=False) return ax