Esempio n. 1
0
 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)
Esempio n. 2
0
    def compute(self):
        f = Fluid(self.fluidName)
        fState = FluidState(self.fluidName)
        numPoints = 100
        pressures = np.logspace(np.log10(f.tripple["p"]), np.log10(f.critical["p"]), numPoints, endpoint=False)
        data = np.zeros((numPoints, 10))
        data[:, 0] = pressures

        for i in range(len(pressures)):
            fState.update_pq(pressures[i], 0)
            satL = fState.SatL
            satV = fState.SatV

            data[i, 1] = fState.T
            data[i, 2] = satL.rho
            data[i, 3] = satV.rho
            data[i, 4] = satL.h
            data[i, 5] = satV.h
            data[i, 7] = satL.s
            data[i, 8] = satV.s
            # Compute evaporation enthalpy
        data[:, 6] = data[:, 5] - data[:, 4]
        # Compute evaporation entropy
        data[:, 9] = data[:, 8] - data[:, 7]

        self.T_p_satPlot = data[:, (0, 1)]
        self.rho_p_satPlot = data[:, (0, 2, 3)]
        self.delta_h_p_satPlot = data[:, (0, 6)]
        self.delta_s_p_satPlot = data[:, (0, 9)]
        self.satTableView = data
Esempio n. 3
0
	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)
Esempio n. 4
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()))
Esempio n. 5
0
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
f2.update_Tq(f1.T + dT, f1.q)
dsdT_q = (f2.s - f1.s) / (f2.T - f1.T)
print ("dsdT_q() numerical: {:e}, analytical: {:e}".format(dsdT_q, f1.dsdT_q))


h2 = FluidState("Water")
h2.update_pq(1e5, 0.5)
print h2.SatV.h

############################
class DerivativeTest:
    def __init__ (self, fluid):
        self.fluid = fluid
        self.fState = FluidState(self.fluid)

    def numerical_derivative(self, stateVarNum,
                                    stateVarDenom, stateVarDenom_val, 
                                    stateVarConst, stateVarConst_val, delta = 1.000001):
        """
        stateVarNum - name of state variable in numerator of the derivative (name is in style of FluidState properties)
        stateVarDenom - name of state variable in denominator of the derivative (name is in style of FluidState.update arguments)
        stateVarConst - name of constant state variable (name is in style of FluidState.update arguments)
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
0
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
f2.update_Tq(f1.T + dT, f1.q)
dsdT_q = (f2.s - f1.s) / (f2.T - f1.T)
print("dsdT_q() numerical: {:e}, analytical: {:e}".format(dsdT_q, f1.dsdT_q))

h2 = FluidState("Water")
h2.update_pq(1e5, 0.5)
print h2.SatV.h


############################
class DerivativeTest:
    def __init__(self, fluid):
        self.fluid = fluid
        self.fState = FluidState(self.fluid)

    def numerical_derivative(self,
                             stateVarNum,
                             stateVarDenom,
                             stateVarDenom_val,
                             stateVarConst,
                             stateVarConst_val,