Ejemplo n.º 1
0
def testState():
    s1 = FluidState('ParaHydrogen')
    s1.update('P', 700e5, 'T', 288)
    print("p={0}".format(s1.p()))
    print("T={0}".format(s1.T()))
    print("rho={0}".format(s1.rho()))
    print("h={0}".format(s1.h()))
    print("s={0}".format(s1.s()))
    print("cp={0}".format(s1.cp()))
    print("cv={0}".format(s1.cv()))
    print("gamma={0}".format(s1.gamma()))
    print("dpdt_v={0}".format(s1.dpdt_v()))
    print("dpdv_t={0}".format(s1.dpdv_t()))
    print("beta={0}".format(s1.beta()))
    print("mu={0}".format(s1.mu()))
    print("lambfa={0}".format(s1.cond()))
    print("Pr={0}".format(s1.Pr()))

    s2 = FluidState('ParaHydrogen')
    s2.update_Tp(s1.T(), s1.p())
    print("update_Tp rho={0}".format(s2.rho()))
    s3 = FluidState('ParaHydrogen')
    s3.update_Trho(s1.T(), s1.rho())
    print("update_Trho p={0}".format(s3.p()))
    s4 = FluidState('ParaHydrogen')
    s4.update_prho(s1.p(), s1.rho())
    print("update_prho T={0}".format(s4.T()))
    s5 = FluidState('ParaHydrogen')
    s5.update_ph(s1.p(), s1.h())
    print("update_ph ={0}".format(s5.T()))
    s6 = FluidState('ParaHydrogen')
    s6.update_ps(s1.p(), s1.s())
    print("update_ps T={0}".format(s6.T()))
    s7 = FluidState('ParaHydrogen')
    s7.update_pq(1e5, 0)
    print("update_pq T={0}".format(s7.T()))
    s8 = FluidState('ParaHydrogen')
    s8.update_Tq(25, 0)
    print("update_Tq p={0}".format(s8.p()))
    print('--------------------')
    print('Initialize state from fluid')
    h2 = Fluid('ParaHydrogen')
    s9 = FluidState(h2)
    s9.update_Tp(s1.T(), s1.p())
    print("rho={0}".format(s9.rho()))
Ejemplo n.º 2
0
import numpy as np
from smo.media.CoolProp.CoolProp import FluidState, Fluid

fluid = Fluid('Water')

dT = 1e-4
dq = 1e-3

f1 = FluidState(fluid)
f2 = FluidState(fluid)

f1.update_Tq(273.15 + 150, 0.5)

# dqdT_v
f2.update_Trho(f1.T + dT, f1.rho)
dqdT_v = (f2.q - f1.q) / (f2.T - f1.T)
print ("dqdT_v() numerical: {:e}, analytical: {:e}".format(dqdT_v, f1.dqdT_v)) 

# dvdT_q
f2.update_Tq(f1.T + dT, f1.q)
dvdT_q = (f2.v - f1.v) / (f2.T - f1.T)
dvdT_q_1 = f1.q * f1.SatV.dvdT + (1 - f1.q) * f1.SatL.dvdT
print ("dvdT_q() numerical: {:e}, analytical: {:e}, analytical2: {:e}".format(dvdT_q, f1.dvdT_q, dvdT_q_1))

# dvdq_T
f2.update_Tq(f1.T, f1.q + dq) 
dvdq_T = (f2.v - f1.v) / (f2.q - f1.q)
print ("dvdq_T() numerical: {:e}, analytical: {:e}".format(dvdq_T, f1.dvdq_T))

# dsdT_q
Ejemplo n.º 3
0
    def plotIsotherms(self):
        fState = FluidState(self.fluid)
        TArr = np.logspace(np.log10(self.TMin), np.log10(self.TMax), num=20)
        TOrders = np.floor(np.log10(TArr))
        TArr = np.ceil(TArr / 10**(TOrders - 2)) * 10**(TOrders - 2)
        fSatL = FluidState(self.fluidName)
        fSatV = FluidState(self.fluidName)
        f1 = FluidState(self.fluidName)
        for T in TArr:
            if self.temperatureUnit == 'degC':
                T_label = T - 273.15
            else:
                T_label = T
            try:
                f1.update_Tp(T, self.pMax)
                if (T > self.critical.T):
                    rhoArr1 = np.logspace(np.log10(self.rhoMin),
                                          np.log10(self.critical.rho),
                                          num=100)
                    rhoArr2 = np.logspace(np.log10(self.critical.rho),
                                          np.log10(f1.rho),
                                          num=100)
                else:
                    fSatL.update_Tq(T, 0)
                    fSatV.update_Tq(T, 1)
                    rhoArr1 = np.logspace(np.log10(self.rhoMin),
                                          np.log10(fSatV.rho),
                                          num=100)
                    rhoArr2 = np.logspace(np.log10(fSatL.rho),
                                          np.log10(f1.rho),
                                          num=100)
                rhoArr = np.hstack((rhoArr1, rhoArr2))
                hArr = np.zeros(len(rhoArr))
                pArr = np.zeros(len(rhoArr))
                for i in range(len(rhoArr)):
                    fState.update_Trho(T, rhoArr[i])
                    hArr[i] = fState.h
                    pArr[i] = fState.p
                    # Determining label location
                    if (T < self.critical.T):
                        if (i == len(rhoArr1)):
                            self.ax.annotate(formatNumber(T_label, sig=3),
                                             xy=((fSatL.h + fSatV.h) / 2. /
                                                 1e3, pArr[i] / 1e5),
                                             xytext=(0, 3),
                                             textcoords='offset points',
                                             color='r',
                                             size="small")
                    else:
                        if (i > 0):
                            b = np.log10(
                                self.pMin /
                                1e5) - self.minDiagonalSlope * self.hMin / 1e3
                            if (np.log10(pArr[i-1] / 1e5) - self.minDiagonalSlope * hArr[i-1] / 1e3 - b) * \
                             (np.log10(pArr[i] / 1e5) - self.minDiagonalSlope * hArr[i] / 1e3 - b) <= 0:
                                # Getting label rotation angle
                                angle, offset_x, offset_y = self.getLabelPlacement(
                                    x1=hArr[i - 1],
                                    x2=hArr[i],
                                    y1=pArr[i - 1],
                                    y2=pArr[i])
                                self.ax.annotate(formatNumber(T_label, sig=3),
                                                 xy=(hArr[i] / 1e3,
                                                     pArr[i] / 1e5),
                                                 xytext=(offset_x, offset_y),
                                                 textcoords='offset points',
                                                 color='r',
                                                 size="small",
                                                 rotation=angle)

                if (T == TArr[0]):
                    if self.temperatureUnit == 'degC':
                        label = "temperature [C]"
                    else:
                        label = "temperature [K]"
                    self.ax.semilogy(hArr / 1e3, pArr / 1e5, 'r', label=label)
                else:
                    self.ax.semilogy(hArr / 1e3, pArr / 1e5, 'r')
            except RuntimeError, e:
                print '------------------'
                print 'Runtime Warning for T=%e' % T
                print(e)
Ejemplo n.º 4
0
 def plotIsentrops(self):
     fState = FluidState(self.fluid)
     sArr = np.linspace(self.sMin, self.sMax, num=20)
     for s in sArr:
         try:
             hArr = []
             pArr = []
             fState.update_ps(self.pMax, s)
             if (fState.T > self.TMax):
                 fState.update_Ts(self.TMax, s)
             T = fState.T
             hArr.append(fState.h)
             pArr.append(fState.p)
             # Calculated v
             v_res = fState.v
             while (T > self.TMin):
                 _dvdT_s = -fState.dsdT_v / fState.dpdT_v
                 if math.isnan(_dvdT_s):
                     break
                 TStep = -(self.critical.T / 200.) / (np.abs(_dvdT_s) + 1)
                 T = T + TStep
                 if T < self.TMin:
                     break
                 v_res += _dvdT_s * TStep
                 fState.update_Trho(T, 1. / v_res)
                 p = fState.p
                 # If it goes out of the screen through the bottom
                 if (p < self.pMin):
                     break
                 # Calculated s
                 s_res = fState.s
                 # Correcting v
                 ds = s - s_res
                 sigma = ds * fState.dvds_T
                 v = v_res + sigma
                 fState.update_Trho(T, 1. / v)
                 hArr.append(fState.h)
                 pArr.append(fState.p)
                 ##################
                 # Putting labels
                 i = len(hArr) - 1
                 b = np.log10(self.pMax /
                              1e5) - self.majDiagonalSlope * self.hMin / 1e3
                 if (np.log10(pArr[i-1] / 1e5) - self.majDiagonalSlope * hArr[i-1] / 1e3 - b) * \
                  (np.log10(pArr[i] / 1e5) - self.majDiagonalSlope * hArr[i] / 1e3 - b) <= 0:
                     angle, offset_x, offset_y = self.getLabelPlacement(
                         x1=hArr[i - 1],
                         x2=hArr[i],
                         y1=pArr[i - 1],
                         y2=pArr[i])
                     self.ax.annotate(formatNumber(s / 1e3, sig=3),
                                      xy=(hArr[i - 1] / 1e3,
                                          pArr[i - 1] / 1e5),
                                      xytext=(-offset_x, -offset_y),
                                      textcoords='offset points',
                                      color='m',
                                      size="small",
                                      rotation=angle)
                 #######################
             hArr = np.array(hArr)
             pArr = np.array(pArr)
             if (s == sArr[0]):
                 self.ax.semilogy(hArr / 1e3,
                                  pArr / 1e5,
                                  'm',
                                  label="entropy [kJ/kg-K]")
             else:
                 self.ax.semilogy(hArr / 1e3, pArr / 1e5, 'm')
         except RuntimeError, e:
             print '------------------'
             print 'Runtime Warning for s=%e' % s
             print e
Ejemplo n.º 5
0
class PHDiagram(StateDiagram):
    def __init__(self, fluidName, temperatureUnit='K'):
        super(PHDiagram, self).__init__(fluidName)
        self.temperatureUnit = temperatureUnit

    def setLimits(self, pMin=None, pMax=None, hMin=None, hMax=None, TMax=None):
        # Reference points
        self.minLiquid = FluidState(self.fluid)
        self.minVapor = FluidState(self.fluid)
        self.critical = FluidState(self.fluid)
        self.critical.update_Trho(self.fluid.critical['T'],
                                  self.fluid.critical['rho'])

        # For general use
        fState = FluidState(self.fluid)

        # Pressure range
        if (pMin is None):
            pMin = self.fluid.tripple['p'] * 1.05
            if (pMin < 1e3):
                pMin = 1e3
        self.pMin = pMin

        self.minLiquid.update_pq(self.pMin, 0)
        self.minVapor.update_pq(self.pMin, 1)

        if (pMax is None):
            pMax = 3 * self.critical.p
        self.pMax = pMax

        # Enthalpy range
        domeWidth = self.minVapor.h - self.minLiquid.h
        if (hMin is None):
            hMin = self.minLiquid.h
        self.hMin = hMin

        # Determining max enthalpy
        if (TMax is None):
            if (hMax is None):
                # default max enthalpy
                if (self.critical.h > self.minVapor.h):
                    hMax = self.critical.h + domeWidth
                else:
                    hMax = self.minVapor.h + domeWidth
        else:
            fState.update_Tp(TMax, self.pMin)
            hMax = fState.h

        self.hMax = hMax

        # Axes ranges
        self.xMin = self.hMin
        self.xMax = self.hMax
        self.yMin = self.pMin
        self.yMax = self.pMax

        # Density range
        fState.update_ph(self.pMin, self.hMax)
        self.rhoMin = fState.rho
        self.rhoMax = self.minLiquid.rho

        # Temperature range
        self.TMin = self.fluid.saturation_p(self.pMin)["TsatL"]

        if (TMax is None):
            fState.update_ph(self.pMin, self.hMax)
            TMax = fState.T
        self.TMax = TMax

        # Entropy range
        self.sMin = 1.01 * self.minLiquid.s

        fState.update_ph(self.pMin, self.hMax)
        self.sMax = fState.s

        # Minor diagonal coeff
        self.minDiagonalSlope = np.log10(
            self.pMax / self.pMin) / (self.hMax - self.hMin) * 1e3

        # Major diagonal coeff
        self.majDiagonalSlope = -self.minDiagonalSlope

    def plotDome(self):
        fState = FluidState(self.fluid)
        p = np.logspace(np.log10(self.pMin),
                        np.log10(self.critical.p),
                        num=200)
        qLabels = ['0.2', '0.4', '0.6', '0.8']
        for q in np.arange(0, 1.1, 0.1):
            try:
                h = np.zeros(len(p))
                for i in range(len(p) - 1):
                    fState.update_pq(p[i], q)
                    h[i] = fState.h
                # Putting labels
                if '{:1.1f}'.format(q) in qLabels:
                    angle, offset_x, offset_y = self.getLabelPlacement(
                        x1=h[9], x2=h[10], y1=p[9], y2=p[10])
                    self.ax.annotate("{:1.1f}".format(q),
                                     xy=(h[10] / 1e3, p[10] / 1e5),
                                     xytext=(-offset_x, -offset_y),
                                     textcoords='offset points',
                                     color='b',
                                     size="small",
                                     rotation=angle)
                h[-1] = self.critical.h
                if (q == 0):
                    self.ax.semilogy(h / 1e3,
                                     p / 1e5,
                                     'b',
                                     label='vapor quality')
                else:
                    self.ax.semilogy(h / 1e3, p / 1e5, 'b')
            except RuntimeError, e:
                print '------------------'
                print 'Runtime Warning for q=%e' % q
                print(e)
Ejemplo n.º 6
0
    def plotIsochores(self):
        fState = FluidState(self.fluid)
        rhoArr1 = np.logspace(np.log10(self.rhoMin),
                              np.log10(self.critical.rho),
                              num=20,
                              endpoint=False)
        rhoArr2 = np.logspace(np.log10(self.critical.rho),
                              np.log10(self.rhoMax),
                              num=5)
        rhoArr = np.zeros(len(rhoArr1) + len(rhoArr2))
        rhoArr[:len(rhoArr1)] = rhoArr1[:]
        rhoArr[len(rhoArr1):] = rhoArr2[:]
        TArr = np.logspace(np.log10(self.TMin), np.log10(self.TMax), num=100)
        # For label location purposes
        h_level_low = self.hMin + (self.critical.h - self.hMin) * 3 / 4.
        h_level_high = self.critical.h + (self.hMax - self.critical.h) * 1 / 2.
        for rho in rhoArr:
            try:
                hArr = np.zeros(len(TArr))
                pArr = np.zeros(len(TArr))
                for i in range(len(TArr)):
                    fState.update_Trho(TArr[i], rho)
                    hArr[i] = fState.h
                    pArr[i] = fState.p
                    # Putting labels
                    # Determining annotated point and label text offest

                    if (pArr[i - 1] < self.pMax and pArr[i] > self.pMax):
                        if (hArr[i] < h_level_low):
                            angle, offset_x, offset_y = self.getLabelPlacement(
                                x1=hArr[i - 1],
                                x2=hArr[i],
                                y1=pArr[i - 1],
                                y2=pArr[i])
                            self.ax.annotate(formatNumber(rho, sig=2),
                                             xy=(hArr[i - 1] / 1e3,
                                                 pArr[i - 1] / 1e5),
                                             xytext=(0, -10),
                                             textcoords='offset points',
                                             color='g',
                                             size="small",
                                             rotation=angle)
                        elif (hArr[i] > h_level_low
                              and hArr[i] < h_level_high):
                            angle, offset_x, offset_y = self.getLabelPlacement(
                                x1=hArr[i - 2],
                                x2=hArr[i - 1],
                                y1=pArr[i - 2],
                                y2=pArr[i - 1])
                            self.ax.annotate(formatNumber(rho, sig=2),
                                             xy=(hArr[i - 2] / 1e3,
                                                 pArr[i - 2] / 1e5),
                                             xytext=(5, -5),
                                             textcoords='offset points',
                                             color='g',
                                             size="small",
                                             rotation=angle)
                        elif (hArr[i] > h_level_high):
                            angle, offset_x, offset_y = self.getLabelPlacement(
                                x1=hArr[i - 10],
                                x2=hArr[i - 9],
                                y1=pArr[i - 10],
                                y2=pArr[i - 9])
                            self.ax.annotate(formatNumber(rho, sig=2),
                                             xy=(hArr[i - 10] / 1e3,
                                                 pArr[i - 10] / 1e5),
                                             xytext=(0, -5),
                                             textcoords='offset points',
                                             color='g',
                                             size="small",
                                             rotation=angle)
                    elif (i == len(TArr) - 1 and pArr[i] < self.pMax
                          and pArr[i - 1] > self.pMin):
                        angle, offset_x, offset_y = self.getLabelPlacement(
                            x1=hArr[i - 1],
                            x2=hArr[i],
                            y1=pArr[i - 1],
                            y2=pArr[i])
                        self.ax.annotate(formatNumber(rho, sig=2),
                                         xy=(hArr[i] / 1e3, pArr[i] / 1e5),
                                         xytext=(-30, -12),
                                         textcoords='offset points',
                                         color='g',
                                         size="small",
                                         rotation=angle)
                if (rho == rhoArr[0]):
                    self.ax.semilogy(hArr / 1e3,
                                     pArr / 1e5,
                                     'g',
                                     label='density [kg/m3]')
                else:
                    self.ax.semilogy(hArr / 1e3, pArr / 1e5, 'g')
            except RuntimeError, e:
                print '------------------'
                print 'Runtime Warning for rho=%e' % rho
                print(e)
Ejemplo n.º 7
0
	def plotIsentrops(self):
		fState = FluidState(self.fluid)
		sArr = np.linspace(self.sMin, self.sMax, num = 20)
		for s in sArr:
			try:
				hArr = []
				pArr = []
				fState.update_ps(self.pMax, s)
				if (fState.T > self.TMax):
					fState.update_Ts(self.TMax, s)
				T = fState.T
				hArr.append(fState.h)
				pArr.append(fState.p)
				# Calculated v
				v_res = fState.v
				while (T > self.TMin):
					_dvdT_s = - fState.dsdT_v / fState.dpdT_v
					if math.isnan(_dvdT_s ):
						break
					TStep = - (self.critical.T / 200.) / (np.abs(_dvdT_s) + 1) 
					T = T + TStep
					if T < self.TMin:
						break
					v_res += _dvdT_s * TStep
					fState.update_Trho(T, 1. / v_res)
					p = fState.p
					# If it goes out of the screen through the bottom
					if (p < self.pMin):
						break
					# Calculated s
					s_res = fState.s
					# Correcting v
					ds = s - s_res
					sigma = ds * fState.dvds_T
					v = v_res + sigma
					fState.update_Trho(T, 1. / v)
					hArr.append(fState.h)
					pArr.append(fState.p)
					##################
					# Putting labels
					i = len(hArr) - 1
					b = np.log10(self.pMax / 1e5) - self.majDiagonalSlope * self.hMin / 1e3
					if (np.log10(pArr[i-1] / 1e5) - self.majDiagonalSlope * hArr[i-1] / 1e3 - b) * \
						(np.log10(pArr[i] / 1e5) - self.majDiagonalSlope * hArr[i] / 1e3 - b) <= 0:
						angle, offset_x, offset_y = self.getLabelPlacement(x1 = hArr[i-1], x2 = hArr[i],
																			y1 = pArr[i-1], y2 = pArr[i])
						self.ax.annotate(formatNumber(s/1e3, sig = 3), 
											xy = (hArr[i-1]/1e3, pArr[i-1]/1e5),
											xytext=(-offset_x, -offset_y),
											textcoords='offset points',
											color='m', size="small", rotation = angle)
					#######################
				hArr = np.array(hArr)
				pArr = np.array(pArr)
				if (s == sArr[0]):
					self.ax.semilogy(hArr/1e3, pArr/1e5, 'm', label = "entropy [kJ/kg-K]")
				else:
					self.ax.semilogy(hArr/1e3, pArr/1e5, 'm')
			except RuntimeError, e:
				print '------------------'
				print 'Runtime Warning for s=%e'%s 
				print e
Ejemplo n.º 8
0
	def plotIsotherms(self):
		fState = FluidState(self.fluid)
		TArr = np.logspace(np.log10(self.TMin), np.log10(self.TMax), num = 20)
		TOrders = np.floor(np.log10(TArr))
		TArr = np.ceil(TArr / 10**(TOrders - 2)) * 10**(TOrders - 2)
		fSatL = FluidState(self.fluidName)
		fSatV = FluidState(self.fluidName)
		f1 = FluidState(self.fluidName)
		for T in TArr:
			if self.temperatureUnit == 'degC':
				T_label = T  - 273.15
			else:
				T_label = T
			try:
				f1.update_Tp(T, self.pMax)
				if (T > self.critical.T):
					rhoArr1 = np.logspace(np.log10(self.rhoMin), np.log10(self.critical.rho), num = 100)
					rhoArr2 = np.logspace(np.log10(self.critical.rho), np.log10(f1.rho), num = 100)
				else:
					fSatL.update_Tq(T, 0)
					fSatV.update_Tq(T, 1)
					rhoArr1 = np.logspace(np.log10(self.rhoMin), np.log10(fSatV.rho), num = 100)
					rhoArr2 = np.logspace(np.log10(fSatL.rho), np.log10(f1.rho), num = 100)
				rhoArr = np.hstack((rhoArr1, rhoArr2))
				hArr = np.zeros(len(rhoArr))
				pArr = np.zeros(len(rhoArr))
				for i in range(len(rhoArr)):
					fState.update_Trho(T, rhoArr[i])
					hArr[i] = fState.h
					pArr[i] = fState.p
					# Determining label location
					if (T < self.critical.T):
						if (i == len(rhoArr1)):
							self.ax.annotate(formatNumber(T_label, sig = 3), 
											xy = ((fSatL.h + fSatV.h) / 2. / 1e3, pArr[i] / 1e5),
											xytext=(0, 3),
											textcoords='offset points',
											color='r', size="small")
					else:
						if (i>0):
							b = np.log10(self.pMin / 1e5) - self.minDiagonalSlope * self.hMin / 1e3
							if (np.log10(pArr[i-1] / 1e5) - self.minDiagonalSlope * hArr[i-1] / 1e3 - b) * \
								(np.log10(pArr[i] / 1e5) - self.minDiagonalSlope * hArr[i] / 1e3 - b) <= 0:
								# Getting label rotation angle
								angle, offset_x, offset_y = self.getLabelPlacement(x1 = hArr[i-1], x2 = hArr[i],
																					y1 = pArr[i-1], y2 = pArr[i])
								self.ax.annotate(formatNumber(T_label, sig = 3), 
												xy = (hArr[i]/1e3, pArr[i]/1e5),
												xytext=(offset_x, offset_y),
												textcoords='offset points',
												color='r', size="small", rotation = angle)
				
				if (T == TArr[0]):
					if self.temperatureUnit == 'degC':
						label = "temperature [C]"
					else:
						label = "temperature [K]"
					self.ax.semilogy(hArr/1e3, pArr/1e5, 'r', label = label)
				else:
					self.ax.semilogy(hArr/1e3, pArr/1e5, 'r')
			except RuntimeError, e:
				print '------------------'
				print 'Runtime Warning for T=%e'%T 
				print(e)
Ejemplo n.º 9
0
	def plotIsochores(self):
		fState = FluidState(self.fluid)
		rhoArr1 = np.logspace(np.log10(self.rhoMin), np.log10(self.critical.rho), num = 20, endpoint = False)
		rhoArr2 = np.logspace(np.log10(self.critical.rho), np.log10(self.rhoMax), num = 5)
		rhoArr = np.zeros(len(rhoArr1) + len(rhoArr2))
		rhoArr[:len(rhoArr1)] = rhoArr1[:]
		rhoArr[len(rhoArr1):] = rhoArr2[:]
		TArr = np.logspace(np.log10(self.TMin), np.log10(self.TMax), num = 100)
		# For label location purposes
		h_level_low = self.hMin + (self.critical.h - self.hMin) * 3 / 4.
		h_level_high = self.critical.h + (self.hMax - self.critical.h) * 1 / 2. 
		for rho in rhoArr:
			try:
				hArr = np.zeros(len(TArr))
				pArr = np.zeros(len(TArr))
				for i in range(len(TArr)):
					fState.update_Trho(TArr[i], rho)
					hArr[i] = fState.h
					pArr[i] = fState.p
					# Putting labels
					# Determining annotated point and label text offest
					
					if (pArr[i-1] < self.pMax and pArr[i] > self.pMax):
						if (hArr[i] < h_level_low):
							angle, offset_x, offset_y = self.getLabelPlacement(x1 = hArr[i-1], x2 = hArr[i],
																				y1 = pArr[i-1], y2 = pArr[i])
							self.ax.annotate(formatNumber(rho, sig = 2), 
											xy = (hArr[i-1] / 1e3, pArr[i-1] / 1e5),
											xytext=(0, -10),
											textcoords='offset points',
											color='g', size="small", rotation = angle)
						elif (hArr[i] > h_level_low and hArr[i] < h_level_high):
							angle, offset_x, offset_y = self.getLabelPlacement(x1 = hArr[i-2], x2 = hArr[i-1],
																				y1 = pArr[i-2], y2 = pArr[i-1])
							self.ax.annotate(formatNumber(rho, sig = 2), 
											xy = (hArr[i-2] / 1e3, pArr[i-2] / 1e5),
											xytext=(5, -5),
											textcoords='offset points',
											color='g', size="small", rotation = angle)
						elif (hArr[i] > h_level_high):
							angle, offset_x, offset_y = self.getLabelPlacement(x1 = hArr[i-10], x2 = hArr[i-9],
																				y1 = pArr[i-10], y2 = pArr[i-9])
							self.ax.annotate(formatNumber(rho, sig = 2), 
											xy = (hArr[i-10] / 1e3, pArr[i-10] / 1e5),
											xytext=(0, -5),
											textcoords='offset points',
											color='g', size="small", rotation = angle)
					elif (i == len(TArr) - 1 and pArr[i] < self.pMax and pArr[i-1] > self.pMin):
						angle, offset_x, offset_y = self.getLabelPlacement(x1 = hArr[i-1], x2 = hArr[i],
																			y1 = pArr[i-1], y2 = pArr[i])
						self.ax.annotate(formatNumber(rho, sig = 2), 
										xy = (hArr[i] / 1e3, pArr[i] / 1e5),
										xytext=(-30, -12),
										textcoords='offset points',
										color='g', size="small", rotation = angle)
				if (rho == rhoArr[0]):
					self.ax.semilogy(hArr/1e3, pArr/1e5, 'g', label = 'density [kg/m3]')
				else:
					self.ax.semilogy(hArr/1e3, pArr/1e5, 'g')
			except RuntimeError, e:
				print '------------------'
				print 'Runtime Warning for rho=%e'%rho 
				print(e)
Ejemplo n.º 10
0
class PHDiagram(StateDiagram):
	def __init__(self, fluidName, temperatureUnit = 'K'):
		super(PHDiagram, self).__init__(fluidName)
		self.temperatureUnit = temperatureUnit
	
	def setLimits(self, pMin = None, pMax = None,  hMin = None, hMax = None, TMax = None):
		# Reference points
		self.minLiquid = FluidState(self.fluid)
		self.minVapor = FluidState(self.fluid)
		self.critical = FluidState(self.fluid)
		self.critical.update_Trho(self.fluid.critical['T'], self.fluid.critical['rho'])

		# For general use
		fState = FluidState(self.fluid)

		# Pressure range
		if (pMin is None):
			pMin = self.fluid.tripple['p'] * 1.05
			if (pMin < 1e3):
				pMin = 1e3
		self.pMin = pMin
		
		self.minLiquid.update_pq(self.pMin, 0)		
		self.minVapor.update_pq(self.pMin, 1)
		
		if (pMax is None):
			pMax = 3 * self.critical.p
		self.pMax = pMax
		
		
		# Enthalpy range
		domeWidth = self.minVapor.h - self.minLiquid.h		
		if (hMin is None):
			hMin = self.minLiquid.h
		self.hMin = hMin
		
		# Determining max enthalpy
		if (TMax is None):
			if (hMax is None):
				# default max enthalpy	
				if (self.critical.h > self.minVapor.h):
					hMax = self.critical.h + domeWidth
				else:
					hMax = self.minVapor.h + domeWidth
		else:
			fState.update_Tp(TMax, self.pMin)
			hMax = fState.h
			
		self.hMax = hMax
		
		# Axes ranges
		self.xMin = self.hMin
		self.xMax = self.hMax
		self.yMin = self.pMin
		self.yMax = self.pMax
		
		# Density range
		fState.update_ph(self.pMin, self.hMax)
		self.rhoMin = fState.rho
		self.rhoMax = self.minLiquid.rho
		
		# Temperature range
		self.TMin = self.fluid.saturation_p(self.pMin)["TsatL"]
		
		if (TMax is None):
			fState.update_ph(self.pMin, self.hMax)
			TMax = fState.T
		self.TMax = TMax
		
		# Entropy range
		self.sMin = 1.01 * self.minLiquid.s
		
		fState.update_ph(self.pMin, self.hMax)
		self.sMax = fState.s
		
		# Minor diagonal coeff
		self.minDiagonalSlope = np.log10(self.pMax/self.pMin) / (self.hMax - self.hMin) * 1e3
		
		# Major diagonal coeff
		self.majDiagonalSlope = - self.minDiagonalSlope
	
	def plotDome(self):
		fState = FluidState(self.fluid)
		p = np.logspace(np.log10(self.pMin), np.log10(self.critical.p), num = 200)
		qLabels = ['0.2', '0.4', '0.6', '0.8']
		for q in np.arange(0, 1.1, 0.1):
			try:
				h = np.zeros(len(p))
				for i in range(len(p) - 1):
					fState.update_pq(p[i], q)
					h[i] = fState.h
				# Putting labels
				if '{:1.1f}'.format(q) in qLabels:
					angle, offset_x, offset_y = self.getLabelPlacement(x1 = h[9], x2 = h[10],
											y1 = p[9], y2 = p[10])
					self.ax.annotate("{:1.1f}".format(q), 
									xy = (h[10]/ 1e3, p[10] / 1e5),
									xytext=(-offset_x, -offset_y),
									textcoords='offset points',
									color='b', size="small", rotation = angle)
				h[-1] = self.critical.h
				if (q == 0):			
					self.ax.semilogy(h/1e3, p/1e5, 'b', label = 'vapor quality')
				else:
					self.ax.semilogy(h/1e3, p/1e5, 'b')
			except RuntimeError, e:
				print '------------------'
				print 'Runtime Warning for q=%e'%q 
				print(e)
Ejemplo n.º 11
0
import numpy as np
from smo.media.CoolProp.CoolProp import FluidState, Fluid

fluid = Fluid('Water')

dT = 1e-4
dq = 1e-3

f1 = FluidState(fluid)
f2 = FluidState(fluid)

f1.update_Tq(273.15 + 150, 0.5)

# dqdT_v
f2.update_Trho(f1.T + dT, f1.rho)
dqdT_v = (f2.q - f1.q) / (f2.T - f1.T)
print("dqdT_v() numerical: {:e}, analytical: {:e}".format(dqdT_v, f1.dqdT_v))

# dvdT_q
f2.update_Tq(f1.T + dT, f1.q)
dvdT_q = (f2.v - f1.v) / (f2.T - f1.T)
dvdT_q_1 = f1.q * f1.SatV.dvdT + (1 - f1.q) * f1.SatL.dvdT
print("dvdT_q() numerical: {:e}, analytical: {:e}, analytical2: {:e}".format(
    dvdT_q, f1.dvdT_q, dvdT_q_1))

# dvdq_T
f2.update_Tq(f1.T, f1.q + dq)
dvdq_T = (f2.v - f1.v) / (f2.q - f1.q)
print("dvdq_T() numerical: {:e}, analytical: {:e}".format(dvdq_T, f1.dvdq_T))