Search is not available for this dataset
text
stringlengths
75
104k
def Soave_1984(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives according to Soave (1984) [1]_. Returns `a_alpha`, `da_alpha_dT`, and `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more documentation. Two coefficients needed. .. math:: \alpha = c_{1} \left(- \frac{T}{Tc} + 1\right) + c_{2} \left(-1 + \frac{Tc}{T}\right) + 1 References ---------- .. [1] Soave, G. "Improvement of the Van Der Waals Equation of State." Chemical Engineering Science 39, no. 2 (January 1, 1984): 357-69. doi:10.1016/0009-2509(84)80034-2. ''' c1, c2 = self.alpha_function_coeffs T, Tc, a = self.T, self.Tc, self.a a_alpha = a*(c1*(-T/Tc + 1) + c2*(-1 + Tc/T) + 1) if not full: return a_alpha else: da_alpha_dT = a*(-c1/Tc - Tc*c2/T**2) d2a_alpha_dT2 = a*(2*Tc*c2/T**3) return a_alpha, da_alpha_dT, d2a_alpha_dT2
def Yu_Lu(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives according to Yu and Lu (1987) [1]_. Returns `a_alpha`, `da_alpha_dT`, and `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more documentation. Four coefficients needed. .. math:: \alpha = 10^{c_{4} \left(- \frac{T}{Tc} + 1\right) \left( \frac{T^{2} c_{3}}{Tc^{2}} + \frac{T c_{2}}{Tc} + c_{1}\right)} References ---------- .. [1] Yu, Jin-Min, and Benjamin C. -Y. Lu. "A Three-Parameter Cubic Equation of State for Asymmetric Mixture Density Calculations." Fluid Phase Equilibria 34, no. 1 (January 1, 1987): 1-19. doi:10.1016/0378-3812(87)85047-1. ''' c1, c2, c3, c4 = self.alpha_function_coeffs T, Tc, a = self.T, self.Tc, self.a a_alpha = a*10**(c4*(-T/Tc + 1)*(T**2*c3/Tc**2 + T*c2/Tc + c1)) if not full: return a_alpha else: da_alpha_dT = a*(10**(c4*(-T/Tc + 1)*(T**2*c3/Tc**2 + T*c2/Tc + c1))*(c4*(-T/Tc + 1)*(2*T*c3/Tc**2 + c2/Tc) - c4*(T**2*c3/Tc**2 + T*c2/Tc + c1)/Tc)*log(10)) d2a_alpha_dT2 = a*(10**(-c4*(T/Tc - 1)*(T**2*c3/Tc**2 + T*c2/Tc + c1))*c4*(-4*T*c3/Tc - 2*c2 - 2*c3*(T/Tc - 1) + c4*(T**2*c3/Tc**2 + T*c2/Tc + c1 + (T/Tc - 1)*(2*T*c3/Tc + c2))**2*log(10))*log(10)/Tc**2) return a_alpha, da_alpha_dT, d2a_alpha_dT2
def Trebble_Bishnoi(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives according to Trebble and Bishnoi (1987) [1]_. Returns `a_alpha`, `da_alpha_dT`, and `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more documentation. One coefficient needed. .. math:: \alpha = e^{c_{1} \left(- \frac{T}{Tc} + 1\right)} References ---------- .. [1] Trebble, M. A., and P. R. Bishnoi. "Development of a New Four- Parameter Cubic Equation of State." Fluid Phase Equilibria 35, no. 1 (September 1, 1987): 1-18. doi:10.1016/0378-3812(87)80001-8. ''' c1 = self.alpha_function_coeffs T, Tc, a = self.T, self.Tc, self.a a_alpha = a*exp(c1*(-T/Tc + 1)) if not full: return a_alpha else: da_alpha_dT = a*-c1*exp(c1*(-T/Tc + 1))/Tc d2a_alpha_dT2 = a*c1**2*exp(-c1*(T/Tc - 1))/Tc**2 return a_alpha, da_alpha_dT, d2a_alpha_dT2
def Androulakis(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives according to Androulakis et al. (1989) [1]_. Returns `a_alpha`, `da_alpha_dT`, and `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more documentation. Three coefficients needed. .. math:: \alpha = c_{1} \left(- \left(\frac{T}{Tc}\right)^{\frac{2}{3}} + 1\right) + c_{2} \left(- \left(\frac{T}{Tc}\right)^{\frac{2}{3}} + 1\right)^{2} + c_{3} \left(- \left(\frac{T}{Tc}\right)^{ \frac{2}{3}} + 1\right)^{3} + 1 References ---------- .. [1] Androulakis, I. P., N. S. Kalospiros, and D. P. Tassios. "Thermophysical Properties of Pure Polar and Nonpolar Compounds with a Modified VdW-711 Equation of State." Fluid Phase Equilibria 45, no. 2 (April 1, 1989): 135-63. doi:10.1016/0378-3812(89)80254-7. ''' c1, c2, c3 = self.alpha_function_coeffs T, Tc, a = self.T, self.Tc, self.a a_alpha = a*(c1*(-(T/Tc)**(2/3) + 1) + c2*(-(T/Tc)**(2/3) + 1)**2 + c3*(-(T/Tc)**(2/3) + 1)**3 + 1) if not full: return a_alpha else: da_alpha_dT = a*(-2*c1*(T/Tc)**(2/3)/(3*T) - 4*c2*(T/Tc)**(2/3)*(-(T/Tc)**(2/3) + 1)/(3*T) - 2*c3*(T/Tc)**(2/3)*(-(T/Tc)**(2/3) + 1)**2/T) d2a_alpha_dT2 = a*(2*(T/Tc)**(2/3)*(c1 + 4*c2*(T/Tc)**(2/3) - 2*c2*((T/Tc)**(2/3) - 1) - 12*c3*(T/Tc)**(2/3)*((T/Tc)**(2/3) - 1) + 3*c3*((T/Tc)**(2/3) - 1)**2)/(9*T**2)) return a_alpha, da_alpha_dT, d2a_alpha_dT2
def Schwartzentruber(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives according to Schwartzentruber et al. (1990) [1]_. Returns `a_alpha`, `da_alpha_dT`, and `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more documentation. Three coefficients needed. .. math:: \alpha = \left(c_{4} \left(- \sqrt{\frac{T}{Tc}} + 1\right) - \left(- \sqrt{\frac{T}{Tc}} + 1\right) \left(\frac{T^{2} c_{3}} {Tc^{2}} + \frac{T c_{2}}{Tc} + c_{1}\right) + 1\right)^{2} References ---------- .. [1] J. Schwartzentruber, H. Renon, and S. Watanasiri, "K-values for Non-Ideal Systems:An Easier Way," Chem. Eng., March 1990, 118-124. ''' c1, c2, c3 = self.alpha_function_coeffs T, Tc, a = self.T, self.Tc, self.a a_alpha = a*((c4*(-sqrt(T/Tc) + 1) - (-sqrt(T/Tc) + 1)*(T**2*c3/Tc**2 + T*c2/Tc + c1) + 1)**2) if not full: return a_alpha else: da_alpha_dT = a*((c4*(-sqrt(T/Tc) + 1) - (-sqrt(T/Tc) + 1)*(T**2*c3/Tc**2 + T*c2/Tc + c1) + 1)*(-2*(-sqrt(T/Tc) + 1)*(2*T*c3/Tc**2 + c2/Tc) - c4*sqrt(T/Tc)/T + sqrt(T/Tc)*(T**2*c3/Tc**2 + T*c2/Tc + c1)/T)) d2a_alpha_dT2 = a*(((-c4*(sqrt(T/Tc) - 1) + (sqrt(T/Tc) - 1)*(T**2*c3/Tc**2 + T*c2/Tc + c1) + 1)*(8*c3*(sqrt(T/Tc) - 1)/Tc**2 + 4*sqrt(T/Tc)*(2*T*c3/Tc + c2)/(T*Tc) + c4*sqrt(T/Tc)/T**2 - sqrt(T/Tc)*(T**2*c3/Tc**2 + T*c2/Tc + c1)/T**2) + (2*(sqrt(T/Tc) - 1)*(2*T*c3/Tc + c2)/Tc - c4*sqrt(T/Tc)/T + sqrt(T/Tc)*(T**2*c3/Tc**2 + T*c2/Tc + c1)/T)**2)/2) return a_alpha, da_alpha_dT, d2a_alpha_dT2
def Almeida(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives according to Almeida et al. (1991) [1]_. Returns `a_alpha`, `da_alpha_dT`, and `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more documentation. Three coefficients needed. .. math:: \alpha = e^{c_{1} \left(- \frac{T}{Tc} + 1\right) \left|{ \frac{T}{Tc} - 1}\right|^{c_{2} - 1} + c_{3} \left(-1 + \frac{Tc}{T}\right)} References ---------- .. [1] Almeida, G. S., M. Aznar, and A. S. Telles. "Uma Nova Forma de Dependência Com a Temperatura Do Termo Atrativo de Equações de Estado Cúbicas." RBE, Rev. Bras. Eng., Cad. Eng. Quim 8 (1991): 95. ''' # Note: For the second derivative, requires the use a CAS which can # handle the assumption that Tr-1 != 0. c1, c2, c3 = self.alpha_function_coeffs T, Tc, a = self.T, self.Tc, self.a a_alpha = a*exp(c1*(-T/Tc + 1)*abs(T/Tc - 1)**(c2 - 1) + c3*(-1 + Tc/T)) if not full: return a_alpha else: da_alpha_dT = a*((c1*(c2 - 1)*(-T/Tc + 1)*abs(T/Tc - 1)**(c2 - 1)*copysign(1, T/Tc - 1)/(Tc*Abs(T/Tc - 1)) - c1*abs(T/Tc - 1)**(c2 - 1)/Tc - Tc*c3/T**2)*exp(c1*(-T/Tc + 1)*abs(T/Tc - 1)**(c2 - 1) + c3*(-1 + Tc/T))) d2a_alpha_dT2 = a*exp(c3*(Tc/T - 1) - c1*abs(T/Tc - 1)**(c2 - 1)*(T/Tc - 1))*((c1*abs(T/Tc - 1)**(c2 - 1))/Tc + (Tc*c3)/T**2 + (c1*abs(T/Tc - 1)**(c2 - 2)*copysign(1, T/Tc - 1)*(c2 - 1)*(T/Tc - 1))/Tc)**2 - exp(c3*(Tc/T - 1) - c1*abs(T/Tc - 1)**(c2 - 1)*(T/Tc - 1))*((2*c1*abs(T/Tc - 1)**(c2 - 2)*copysign(1, T/Tc - 1)*(c2 - 1))/Tc**2 - (2*Tc*c3)/T**3 + (c1*abs(T/Tc - 1)**(c2 - 3)*copysign(1, T/Tc - 1)**2*(c2 - 1)*(c2 - 2)*(T/Tc - 1))/Tc**2) return a_alpha, da_alpha_dT, d2a_alpha_dT2
def Coquelet(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives according to Coquelet et al. (2004) [1]_. Returns `a_alpha`, `da_alpha_dT`, and `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more documentation. Three coefficients needed. .. math:: \alpha = e^{c_{1} \left(- \frac{T}{Tc} + 1\right) \left(c_{2} \left(- \sqrt{\frac{T}{Tc}} + 1\right)^{2} + c_{3} \left(- \sqrt{\frac{T}{Tc}} + 1\right)^{3} + 1\right)^{2}} References ---------- .. [1] Coquelet, C., A. Chapoy, and D. Richon. "Development of a New Alpha Function for the Peng–Robinson Equation of State: Comparative Study of Alpha Function Models for Pure Gases (Natural Gas Components) and Water-Gas Systems." International Journal of Thermophysics 25, no. 1 (January 1, 2004): 133-58. doi:10.1023/B:IJOT.0000022331.46865.2f. ''' c1, c2, c3 = self.alpha_function_coeffs T, Tc, a = self.T, self.Tc, self.a a_alpha = a*(exp(c1*(-T/Tc + 1)*(c2*(-sqrt(T/Tc) + 1)**2 + c3*(-sqrt(T/Tc) + 1)**3 + 1)**2)) if not full: return a_alpha else: da_alpha_dT = a*((c1*(-T/Tc + 1)*(-2*c2*sqrt(T/Tc)*(-sqrt(T/Tc) + 1)/T - 3*c3*sqrt(T/Tc)*(-sqrt(T/Tc) + 1)**2/T)*(c2*(-sqrt(T/Tc) + 1)**2 + c3*(-sqrt(T/Tc) + 1)**3 + 1) - c1*(c2*(-sqrt(T/Tc) + 1)**2 + c3*(-sqrt(T/Tc) + 1)**3 + 1)**2/Tc)*exp(c1*(-T/Tc + 1)*(c2*(-sqrt(T/Tc) + 1)**2 + c3*(-sqrt(T/Tc) + 1)**3 + 1)**2)) d2a_alpha_dT2 = a*(c1*(c1*(-(c2*(sqrt(T/Tc) - 1)**2 - c3*(sqrt(T/Tc) - 1)**3 + 1)/Tc + sqrt(T/Tc)*(-2*c2 + 3*c3*(sqrt(T/Tc) - 1))*(sqrt(T/Tc) - 1)*(T/Tc - 1)/T)**2*(c2*(sqrt(T/Tc) - 1)**2 - c3*(sqrt(T/Tc) - 1)**3 + 1)**2 - ((T/Tc - 1)*(c2*(sqrt(T/Tc) - 1)**2 - c3*(sqrt(T/Tc) - 1)**3 + 1)*(2*c2/Tc - 6*c3*(sqrt(T/Tc) - 1)/Tc - 2*c2*sqrt(T/Tc)*(sqrt(T/Tc) - 1)/T + 3*c3*sqrt(T/Tc)*(sqrt(T/Tc) - 1)**2/T) + 4*sqrt(T/Tc)*(2*c2 - 3*c3*(sqrt(T/Tc) - 1))*(sqrt(T/Tc) - 1)*(c2*(sqrt(T/Tc) - 1)**2 - c3*(sqrt(T/Tc) - 1)**3 + 1)/Tc + (2*c2 - 3*c3*(sqrt(T/Tc) - 1))**2*(sqrt(T/Tc) - 1)**2*(T/Tc - 1)/Tc)/(2*T))*exp(-c1*(T/Tc - 1)*(c2*(sqrt(T/Tc) - 1)**2 - c3*(sqrt(T/Tc) - 1)**3 + 1)**2)) return a_alpha, da_alpha_dT, d2a_alpha_dT2
def Chen_Yang(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives according to Hamid and Yang (2017) [1]_. Returns `a_alpha`, `da_alpha_dT`, and `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more documentation. Seven coefficients needed. .. math:: \alpha = e^{\left(- c_{3}^{\log{\left (\frac{T}{Tc} \right )}} + 1\right) \left(- \frac{T c_{2}}{Tc} + c_{1}\right)} References ---------- .. [1] Chen, Zehua, and Daoyong Yang. "Optimization of the Reduced Temperature Associated with Peng–Robinson Equation of State and Soave-Redlich-Kwong Equation of State To Improve Vapor Pressure Prediction for Heavy Hydrocarbon Compounds." Journal of Chemical & Engineering Data, August 31, 2017. doi:10.1021/acs.jced.7b00496. ''' c1, c2, c3, c4, c5, c6, c7 = self.alpha_function_coeffs T, Tc, a = self.T, self.Tc, self.a a_alpha = a*exp(c4*log((-sqrt(T/Tc) + 1)*(c5 + c6*omega + c7*omega**2) + 1)**2 + (-T/Tc + 1)*(c1 + c2*omega + c3*omega**2)) if not full: return a_alpha else: da_alpha_dT = a*(-(c1 + c2*omega + c3*omega**2)/Tc - c4*sqrt(T/Tc)*(c5 + c6*omega + c7*omega**2)*log((-sqrt(T/Tc) + 1)*(c5 + c6*omega + c7*omega**2) + 1)/(T*((-sqrt(T/Tc) + 1)*(c5 + c6*omega + c7*omega**2) + 1)))*exp(c4*log((-sqrt(T/Tc) + 1)*(c5 + c6*omega + c7*omega**2) + 1)**2 + (-T/Tc + 1)*(c1 + c2*omega + c3*omega**2)) d2a_alpha_dT2 = a*(((c1 + c2*omega + c3*omega**2)/Tc - c4*sqrt(T/Tc)*(c5 + c6*omega + c7*omega**2)*log(-(sqrt(T/Tc) - 1)*(c5 + c6*omega + c7*omega**2) + 1)/(T*((sqrt(T/Tc) - 1)*(c5 + c6*omega + c7*omega**2) - 1)))**2 - c4*(c5 + c6*omega + c7*omega**2)*((c5 + c6*omega + c7*omega**2)*log(-(sqrt(T/Tc) - 1)*(c5 + c6*omega + c7*omega**2) + 1)/(Tc*((sqrt(T/Tc) - 1)*(c5 + c6*omega + c7*omega**2) - 1)) - (c5 + c6*omega + c7*omega**2)/(Tc*((sqrt(T/Tc) - 1)*(c5 + c6*omega + c7*omega**2) - 1)) + sqrt(T/Tc)*log(-(sqrt(T/Tc) - 1)*(c5 + c6*omega + c7*omega**2) + 1)/T)/(2*T*((sqrt(T/Tc) - 1)*(c5 + c6*omega + c7*omega**2) - 1)))*exp(c4*log(-(sqrt(T/Tc) - 1)*(c5 + c6*omega + c7*omega**2) + 1)**2 - (T/Tc - 1)*(c1 + c2*omega + c3*omega**2)) return a_alpha, da_alpha_dT, d2a_alpha_dT2
def a_alpha_and_derivatives(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives for this EOS. Returns `a_alpha`, `da_alpha_dT`, and `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more documentation. Uses the set values of `Tc`, `kappa`, and `a`. For use in `solve_T`, returns only `a_alpha` if full is False. .. math:: a\alpha = a \left(\kappa \left(- \frac{T^{0.5}}{Tc^{0.5}} + 1\right) + 1\right)^{2} \frac{d a\alpha}{dT} = - \frac{1.0 a \kappa}{T^{0.5} Tc^{0.5}} \left(\kappa \left(- \frac{T^{0.5}}{Tc^{0.5}} + 1\right) + 1\right) \frac{d^2 a\alpha}{dT^2} = 0.5 a \kappa \left(- \frac{1}{T^{1.5} Tc^{0.5}} \left(\kappa \left(\frac{T^{0.5}}{Tc^{0.5}} - 1\right) - 1\right) + \frac{\kappa}{T^{1.0} Tc^{1.0}}\right) ''' if not full: return self.a*(1 + self.kappa*(1-(T/self.Tc)**0.5))**2 else: if quick: Tc, kappa = self.Tc, self.kappa x0 = T**0.5 x1 = Tc**-0.5 x2 = kappa*(x0*x1 - 1.) - 1. x3 = self.a*kappa a_alpha = self.a*x2*x2 da_alpha_dT = x1*x2*x3/x0 d2a_alpha_dT2 = x3*(-0.5*T**-1.5*x1*x2 + 0.5/(T*Tc)*kappa) else: a_alpha = self.a*(1 + self.kappa*(1-(T/self.Tc)**0.5))**2 da_alpha_dT = -self.a*self.kappa*sqrt(T/self.Tc)*(self.kappa*(-sqrt(T/self.Tc) + 1.) + 1.)/T d2a_alpha_dT2 = self.a*self.kappa*(self.kappa/self.Tc - sqrt(T/self.Tc)*(self.kappa*(sqrt(T/self.Tc) - 1.) - 1.)/T)/(2.*T) return a_alpha, da_alpha_dT, d2a_alpha_dT2
def solve_T(self, P, V, quick=True): r'''Method to calculate `T` from a specified `P` and `V` for the PR EOS. Uses `Tc`, `a`, `b`, and `kappa` as well, obtained from the class's namespace. Parameters ---------- P : float Pressure, [Pa] V : float Molar volume, [m^3/mol] quick : bool, optional Whether to use a SymPy cse-derived expression (3x faster) or individual formulas Returns ------- T : float Temperature, [K] Notes ----- The exact solution can be derived as follows, and is excluded for breviety. >>> from sympy import * >>> P, T, V = symbols('P, T, V') >>> Tc, Pc, omega = symbols('Tc, Pc, omega') >>> R, a, b, kappa = symbols('R, a, b, kappa') >>> a_alpha = a*(1 + kappa*(1-sqrt(T/Tc)))**2 >>> PR_formula = R*T/(V-b) - a_alpha/(V*(V+b)+b*(V-b)) - P >>> #solve(PR_formula, T) ''' Tc, a, b, kappa = self.Tc, self.a, self.b, self.kappa if quick: x0 = V*V x1 = R*Tc x2 = x0*x1 x3 = kappa*kappa x4 = a*x3 x5 = b*x4 x6 = 2.*V*b x7 = x1*x6 x8 = b*b x9 = x1*x8 x10 = V*x4 x11 = (-x10 + x2 + x5 + x7 - x9)**2 x12 = x0*x0 x13 = R*R x14 = Tc*Tc x15 = x13*x14 x16 = x8*x8 x17 = a*a x18 = x3*x3 x19 = x17*x18 x20 = x0*V x21 = 2.*R*Tc*a*x3 x22 = x8*b x23 = 4.*V*x22 x24 = 4.*b*x20 x25 = a*x1 x26 = x25*x8 x27 = x26*x3 x28 = x0*x25 x29 = x28*x3 x30 = 2.*x8 x31 = 6.*V*x27 - 2.*b*x29 + x0*x13*x14*x30 + x0*x19 + x12*x15 + x15*x16 - x15*x23 + x15*x24 - x19*x6 + x19*x8 - x20*x21 - x21*x22 x32 = V - b x33 = 2.*(R*Tc*a*kappa) x34 = P*x2 x35 = P*x5 x36 = x25*x3 x37 = P*x10 x38 = P*R*Tc x39 = V*x17 x40 = 2.*kappa*x3 x41 = b*x17 x42 = P*a*x3 return -Tc*(2.*a*kappa*x11*sqrt(x32**3*(x0 + x6 - x8)*(P*x7 - P*x9 + x25 + x33 + x34 + x35 + x36 - x37))*(kappa + 1.) - x31*x32*((4.*V)*(R*Tc*a*b*kappa) + x0*x33 - x0*x35 + x12*x38 + x16*x38 + x18*x39 - x18*x41 - x20*x42 - x22*x42 - x23*x38 + x24*x38 + x25*x6 - x26 - x27 + x28 + x29 + x3*x39 - x3*x41 + x30*x34 - x33*x8 + x36*x6 + 3*x37*x8 + x39*x40 - x40*x41))/(x11*x31) else: return Tc*(-2*a*kappa*sqrt((V - b)**3*(V**2 + 2*V*b - b**2)*(P*R*Tc*V**2 + 2*P*R*Tc*V*b - P*R*Tc*b**2 - P*V*a*kappa**2 + P*a*b*kappa**2 + R*Tc*a*kappa**2 + 2*R*Tc*a*kappa + R*Tc*a))*(kappa + 1)*(R*Tc*V**2 + 2*R*Tc*V*b - R*Tc*b**2 - V*a*kappa**2 + a*b*kappa**2)**2 + (V - b)*(R**2*Tc**2*V**4 + 4*R**2*Tc**2*V**3*b + 2*R**2*Tc**2*V**2*b**2 - 4*R**2*Tc**2*V*b**3 + R**2*Tc**2*b**4 - 2*R*Tc*V**3*a*kappa**2 - 2*R*Tc*V**2*a*b*kappa**2 + 6*R*Tc*V*a*b**2*kappa**2 - 2*R*Tc*a*b**3*kappa**2 + V**2*a**2*kappa**4 - 2*V*a**2*b*kappa**4 + a**2*b**2*kappa**4)*(P*R*Tc*V**4 + 4*P*R*Tc*V**3*b + 2*P*R*Tc*V**2*b**2 - 4*P*R*Tc*V*b**3 + P*R*Tc*b**4 - P*V**3*a*kappa**2 - P*V**2*a*b*kappa**2 + 3*P*V*a*b**2*kappa**2 - P*a*b**3*kappa**2 + R*Tc*V**2*a*kappa**2 + 2*R*Tc*V**2*a*kappa + R*Tc*V**2*a + 2*R*Tc*V*a*b*kappa**2 + 4*R*Tc*V*a*b*kappa + 2*R*Tc*V*a*b - R*Tc*a*b**2*kappa**2 - 2*R*Tc*a*b**2*kappa - R*Tc*a*b**2 + V*a**2*kappa**4 + 2*V*a**2*kappa**3 + V*a**2*kappa**2 - a**2*b*kappa**4 - 2*a**2*b*kappa**3 - a**2*b*kappa**2))/((R*Tc*V**2 + 2*R*Tc*V*b - R*Tc*b**2 - V*a*kappa**2 + a*b*kappa**2)**2*(R**2*Tc**2*V**4 + 4*R**2*Tc**2*V**3*b + 2*R**2*Tc**2*V**2*b**2 - 4*R**2*Tc**2*V*b**3 + R**2*Tc**2*b**4 - 2*R*Tc*V**3*a*kappa**2 - 2*R*Tc*V**2*a*b*kappa**2 + 6*R*Tc*V*a*b**2*kappa**2 - 2*R*Tc*a*b**3*kappa**2 + V**2*a**2*kappa**4 - 2*V*a**2*b*kappa**4 + a**2*b**2*kappa**4))
def solve_T(self, P, V, quick=True): r'''Method to calculate `T` from a specified `P` and `V` for the PRSV EOS. Uses `Tc`, `a`, `b`, `kappa0` and `kappa` as well, obtained from the class's namespace. Parameters ---------- P : float Pressure, [Pa] V : float Molar volume, [m^3/mol] quick : bool, optional Whether to use a SymPy cse-derived expression (somewhat faster) or individual formulas. Returns ------- T : float Temperature, [K] Notes ----- Not guaranteed to produce a solution. There are actually two solution, one much higher than normally desired; it is possible the solver could converge on this. ''' Tc, a, b, kappa0, kappa1 = self.Tc, self.a, self.b, self.kappa0, self.kappa1 if quick: x0 = V - b R_x0 = R/x0 x3 = (100.*(V*(V + b) + b*x0)) x4 = 10.*kappa0 kappa110 = kappa1*10. kappa17 = kappa1*7. def to_solve(T): x1 = T/Tc x2 = x1**0.5 return (T*R_x0 - a*((x4 - (kappa110*x1 - kappa17)*(x2 + 1.))*(x2 - 1.) - 10.)**2/x3) - P else: def to_solve(T): P_calc = R*T/(V - b) - a*((kappa0 + kappa1*(sqrt(T/Tc) + 1)*(-T/Tc + 7/10))*(-sqrt(T/Tc) + 1) + 1)**2/(V*(V + b) + b*(V - b)) return P_calc - P return newton(to_solve, Tc*0.5)
def a_alpha_and_derivatives(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives for this EOS. Returns `a_alpha`, `da_alpha_dT`, and `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more documentation. Uses the set values of `Tc`, `kappa0`, `kappa1`, and `a`. For use in root-finding, returns only `a_alpha` if full is False. The `a_alpha` function is shown below; its first and second derivatives are long available through the SymPy expression under it. .. math:: a\alpha = a \left(\left(\kappa_{0} + \kappa_{1} \left(\sqrt{\frac{ T}{Tc}} + 1\right) \left(- \frac{T}{Tc} + \frac{7}{10}\right) \right) \left(- \sqrt{\frac{T}{Tc}} + 1\right) + 1\right)^{2} >>> from sympy import * >>> P, T, V = symbols('P, T, V') >>> Tc, Pc, omega = symbols('Tc, Pc, omega') >>> R, a, b, kappa0, kappa1 = symbols('R, a, b, kappa0, kappa1') >>> kappa = kappa0 + kappa1*(1 + sqrt(T/Tc))*(Rational(7, 10)-T/Tc) >>> a_alpha = a*(1 + kappa*(1-sqrt(T/Tc)))**2 >>> # diff(a_alpha, T) >>> # diff(a_alpha, T, 2) ''' Tc, a, kappa0, kappa1 = self.Tc, self.a, self.kappa0, self.kappa1 if not full: return a*((kappa0 + kappa1*(sqrt(T/Tc) + 1)*(-T/Tc + 0.7))*(-sqrt(T/Tc) + 1) + 1)**2 else: if quick: x1 = T/Tc x2 = x1**0.5 x3 = x2 - 1. x4 = 10.*x1 - 7. x5 = x2 + 1. x6 = 10.*kappa0 - kappa1*x4*x5 x7 = x3*x6 x8 = x7*0.1 - 1. x10 = x6/T x11 = kappa1*x3 x12 = x4/T x13 = 20./Tc*x5 + x12*x2 x14 = -x10*x2 + x11*x13 a_alpha = a*x8*x8 da_alpha_dT = -a*x14*x8*0.1 d2a_alpha_dT2 = a*(x14*x14 - x2/T*(x7 - 10.)*(2.*kappa1*x13 + x10 + x11*(40./Tc - x12)))/200. else: a_alpha = a*((kappa0 + kappa1*(sqrt(T/Tc) + 1)*(-T/Tc + 0.7))*(-sqrt(T/Tc) + 1) + 1)**2 da_alpha_dT = a*((kappa0 + kappa1*(sqrt(T/Tc) + 1)*(-T/Tc + 0.7))*(-sqrt(T/Tc) + 1) + 1)*(2*(-sqrt(T/Tc) + 1)*(-kappa1*(sqrt(T/Tc) + 1)/Tc + kappa1*sqrt(T/Tc)*(-T/Tc + 0.7)/(2*T)) - sqrt(T/Tc)*(kappa0 + kappa1*(sqrt(T/Tc) + 1)*(-T/Tc + 0.7))/T) d2a_alpha_dT2 = a*((kappa1*(sqrt(T/Tc) - 1)*(20*(sqrt(T/Tc) + 1)/Tc + sqrt(T/Tc)*(10*T/Tc - 7)/T) - sqrt(T/Tc)*(10*kappa0 - kappa1*(sqrt(T/Tc) + 1)*(10*T/Tc - 7))/T)**2 - sqrt(T/Tc)*((10*kappa0 - kappa1*(sqrt(T/Tc) + 1)*(10*T/Tc - 7))*(sqrt(T/Tc) - 1) - 10)*(kappa1*(40/Tc - (10*T/Tc - 7)/T)*(sqrt(T/Tc) - 1) + 2*kappa1*(20*(sqrt(T/Tc) + 1)/Tc + sqrt(T/Tc)*(10*T/Tc - 7)/T) + (10*kappa0 - kappa1*(sqrt(T/Tc) + 1)*(10*T/Tc - 7))/T)/T)/200 return a_alpha, da_alpha_dT, d2a_alpha_dT2
def a_alpha_and_derivatives(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives for this EOS. Returns `a_alpha`, `da_alpha_dT`, and `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more documentation. Uses the set values of `Tc`, `kappa0`, `kappa1`, `kappa2`, `kappa3`, and `a`. For use in `solve_T`, returns only `a_alpha` if full is False. The first and second derivatives of `a_alpha` are available through the following SymPy expression. >>> from sympy import * >>> P, T, V = symbols('P, T, V') >>> Tc, Pc, omega = symbols('Tc, Pc, omega') >>> R, a, b, kappa0, kappa1, kappa2, kappa3 = symbols('R, a, b, kappa0, kappa1, kappa2, kappa3') >>> Tr = T/Tc >>> kappa = kappa0 + (kappa1 + kappa2*(kappa3-Tr)*(1-sqrt(Tr)))*(1+sqrt(Tr))*(Rational('0.7')-Tr) >>> a_alpha = a*(1 + kappa*(1-sqrt(T/Tc)))**2 >>> # diff(a_alpha, T) >>> # diff(a_alpha, T, 2) ''' Tc, a, kappa0, kappa1, kappa2, kappa3 = self.Tc, self.a, self.kappa0, self.kappa1, self.kappa2, self.kappa3 if not full: Tr = T/Tc kappa = kappa0 + ((kappa1 + kappa2*(kappa3 - Tr)*(1 - Tr**0.5))*(1 + Tr**0.5)*(0.7 - Tr)) return a*(1 + kappa*(1-sqrt(T/Tc)))**2 else: if quick: x1 = T/Tc x2 = sqrt(x1) x3 = x2 - 1. x4 = x2 + 1. x5 = 10.*x1 - 7. x6 = -kappa3 + x1 x7 = kappa1 + kappa2*x3*x6 x8 = x5*x7 x9 = 10.*kappa0 - x4*x8 x10 = x3*x9 x11 = x10*0.1 - 1. x13 = x2/T x14 = x7/Tc x15 = kappa2*x4*x5 x16 = 2.*(-x2 + 1.)/Tc + x13*(kappa3 - x1) x17 = -x13*x8 - x14*(20.*x2 + 20.) + x15*x16 x18 = x13*x9 + x17*x3 x19 = x2/(T*T) x20 = 2.*x2/T a_alpha = a*x11*x11 da_alpha_dT = a*x11*x18*0.1 d2a_alpha_dT2 = a*(x18*x18 + (x10 - 10.)*(x17*x20 - x19*x9 + x3*(40.*kappa2/Tc*x16*x4 + kappa2*x16*x20*x5 - 40./T*x14*x2 - x15/T*x2*(4./Tc - x6/T) + x19*x8)))/200. else: a_alpha = a*(1 + self.kappa*(1-sqrt(T/Tc)))**2 da_alpha_dT = a*((kappa0 + (kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))*(sqrt(T/Tc) + 1)*(-T/Tc + 7/10))*(-sqrt(T/Tc) + 1) + 1)*(2*(-sqrt(T/Tc) + 1)*((sqrt(T/Tc) + 1)*(-T/Tc + 7/10)*(-kappa2*(-sqrt(T/Tc) + 1)/Tc - kappa2*sqrt(T/Tc)*(-T/Tc + kappa3)/(2*T)) - (kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))*(sqrt(T/Tc) + 1)/Tc + sqrt(T/Tc)*(kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))*(-T/Tc + 7/10)/(2*T)) - sqrt(T/Tc)*(kappa0 + (kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))*(sqrt(T/Tc) + 1)*(-T/Tc + 7/10))/T) d2a_alpha_dT2 = a*((kappa0 + (kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))*(sqrt(T/Tc) + 1)*(-T/Tc + 7/10))*(-sqrt(T/Tc) + 1) + 1)*(2*(-sqrt(T/Tc) + 1)*((sqrt(T/Tc) + 1)*(-T/Tc + 7/10)*(kappa2*sqrt(T/Tc)/(T*Tc) + kappa2*sqrt(T/Tc)*(-T/Tc + kappa3)/(4*T**2)) - 2*(sqrt(T/Tc) + 1)*(-kappa2*(-sqrt(T/Tc) + 1)/Tc - kappa2*sqrt(T/Tc)*(-T/Tc + kappa3)/(2*T))/Tc + sqrt(T/Tc)*(-T/Tc + 7/10)*(-kappa2*(-sqrt(T/Tc) + 1)/Tc - kappa2*sqrt(T/Tc)*(-T/Tc + kappa3)/(2*T))/T - sqrt(T/Tc)*(kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))/(T*Tc) - sqrt(T/Tc)*(kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))*(-T/Tc + 7/10)/(4*T**2)) - 2*sqrt(T/Tc)*((sqrt(T/Tc) + 1)*(-T/Tc + 7/10)*(-kappa2*(-sqrt(T/Tc) + 1)/Tc - kappa2*sqrt(T/Tc)*(-T/Tc + kappa3)/(2*T)) - (kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))*(sqrt(T/Tc) + 1)/Tc + sqrt(T/Tc)*(kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))*(-T/Tc + 7/10)/(2*T))/T + sqrt(T/Tc)*(kappa0 + (kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))*(sqrt(T/Tc) + 1)*(-T/Tc + 7/10))/(2*T**2)) + a*((-sqrt(T/Tc) + 1)*((sqrt(T/Tc) + 1)*(-T/Tc + 7/10)*(-kappa2*(-sqrt(T/Tc) + 1)/Tc - kappa2*sqrt(T/Tc)*(-T/Tc + kappa3)/(2*T)) - (kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))*(sqrt(T/Tc) + 1)/Tc + sqrt(T/Tc)*(kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))*(-T/Tc + 7/10)/(2*T)) - sqrt(T/Tc)*(kappa0 + (kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))*(sqrt(T/Tc) + 1)*(-T/Tc + 7/10))/(2*T))*(2*(-sqrt(T/Tc) + 1)*((sqrt(T/Tc) + 1)*(-T/Tc + 7/10)*(-kappa2*(-sqrt(T/Tc) + 1)/Tc - kappa2*sqrt(T/Tc)*(-T/Tc + kappa3)/(2*T)) - (kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))*(sqrt(T/Tc) + 1)/Tc + sqrt(T/Tc)*(kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))*(-T/Tc + 7/10)/(2*T)) - sqrt(T/Tc)*(kappa0 + (kappa1 + kappa2*(-sqrt(T/Tc) + 1)*(-T/Tc + kappa3))*(sqrt(T/Tc) + 1)*(-T/Tc + 7/10))/T) return a_alpha, da_alpha_dT, d2a_alpha_dT2
def a_alpha_and_derivatives(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives for this EOS. Returns `a_alpha`, `da_alpha_dT`, and `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more documentation. Uses the set values of `a`. .. math:: a\alpha = a \frac{d a\alpha}{dT} = 0 \frac{d^2 a\alpha}{dT^2} = 0 ''' if not full: return self.a else: a_alpha = self.a da_alpha_dT = 0.0 d2a_alpha_dT2 = 0.0 return a_alpha, da_alpha_dT, d2a_alpha_dT2
def solve_T(self, P, V): r'''Method to calculate `T` from a specified `P` and `V` for the VDW EOS. Uses `a`, and `b`, obtained from the class's namespace. .. math:: T = \frac{1}{R V^{2}} \left(P V^{2} \left(V - b\right) + V a - a b\right) Parameters ---------- P : float Pressure, [Pa] V : float Molar volume, [m^3/mol] Returns ------- T : float Temperature, [K] ''' return (P*V**2*(V - self.b) + V*self.a - self.a*self.b)/(R*V**2)
def main_derivatives_and_departures(T, P, V, b, delta, epsilon, a_alpha, da_alpha_dT, d2a_alpha_dT2, quick=True): '''Re-implementation of derivatives and excess property calculations, as ZeroDivisionError errors occur with the general solution. The following derivation is the source of these formulas. >>> from sympy import * >>> P, T, V, R, b, a = symbols('P, T, V, R, b, a') >>> P_vdw = R*T/(V-b) - a/(V*V) >>> vdw = P_vdw - P >>> >>> dP_dT = diff(vdw, T) >>> dP_dV = diff(vdw, V) >>> d2P_dT2 = diff(vdw, T, 2) >>> d2P_dV2 = diff(vdw, V, 2) >>> d2P_dTdV = diff(vdw, T, V) >>> H_dep = integrate(T*dP_dT - P_vdw, (V, oo, V)) >>> H_dep += P*V - R*T >>> S_dep = integrate(dP_dT - R/V, (V,oo,V)) >>> S_dep += R*log(P*V/(R*T)) >>> Cv_dep = T*integrate(d2P_dT2, (V,oo,V)) >>> >>> dP_dT, dP_dV, d2P_dT2, d2P_dV2, d2P_dTdV, H_dep, S_dep, Cv_dep (R/(V - b), -R*T/(V - b)**2 + 2*a/V**3, 0, 2*(R*T/(V - b)**3 - 3*a/V**4), -R/(V - b)**2, P*V - R*T - a/V, R*(-log(V) + log(V - b)) + R*log(P*V/(R*T)), 0) ''' dP_dT = R/(V - b) dP_dV = -R*T/(V - b)**2 + 2*a_alpha/V**3 d2P_dT2 = 0 d2P_dV2 = 2*(R*T/(V - b)**3 - 3*a_alpha/V**4) d2P_dTdV = -R/(V - b)**2 H_dep = P*V - R*T - a_alpha/V S_dep = R*(-log(V) + log(V - b)) + R*log(P*V/(R*T)) Cv_dep = 0 return [dP_dT, dP_dV, d2P_dT2, d2P_dV2, d2P_dTdV, H_dep, S_dep, Cv_dep]
def solve_T(self, P, V, quick=True): r'''Method to calculate `T` from a specified `P` and `V` for the RK EOS. Uses `a`, and `b`, obtained from the class's namespace. Parameters ---------- P : float Pressure, [Pa] V : float Molar volume, [m^3/mol] quick : bool, optional Whether to use a SymPy cse-derived expression (3x faster) or individual formulas Returns ------- T : float Temperature, [K] Notes ----- The exact solution can be derived as follows; it is excluded for breviety. >>> from sympy import * >>> P, T, V, R = symbols('P, T, V, R') >>> Tc, Pc = symbols('Tc, Pc') >>> a, b = symbols('a, b') >>> RK = Eq(P, R*T/(V-b) - a/sqrt(T)/(V*V + b*V)) >>> # solve(RK, T) ''' a, b = self.a, self.b if quick: x1 = -1.j*1.7320508075688772 + 1. x2 = V - b x3 = x2/R x4 = V + b x5 = (1.7320508075688772*(x2*x2*(-4.*P*P*P*x3 + 27.*a*a/(V*V*x4*x4))/(R*R))**0.5 - 9.*a*x3/(V*x4) +0j)**(1./3.) return (3.3019272488946263*(11.537996562459266*P*x3/(x1*x5) + 1.2599210498948732*x1*x5)**2/144.0).real else: return ((-(-1/2 + sqrt(3)*1j/2)*(sqrt(729*(-V*a + a*b)**2/(R*V**2 + R*V*b)**2 + 108*(-P*V + P*b)**3/R**3)/2 + 27*(-V*a + a*b)/(2*(R*V**2 + R*V*b))+0j)**(1/3)/3 + (-P*V + P*b)/(R*(-1/2 + sqrt(3)*1j/2)*(sqrt(729*(-V*a + a*b)**2/(R*V**2 + R*V*b)**2 + 108*(-P*V + P*b)**3/R**3)/2 + 27*(-V*a + a*b)/(2*(R*V**2 + R*V*b))+0j)**(1/3)))**2).real
def a_alpha_and_derivatives(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives for this EOS. Returns `a_alpha`, `da_alpha_dT`, and `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more documentation. Uses the set values of `Tc`, `m`, and `a`. .. math:: a\alpha = a \left(m \left(- \sqrt{\frac{T}{Tc}} + 1\right) + 1\right)^{2} \frac{d a\alpha}{dT} = \frac{a m}{T} \sqrt{\frac{T}{Tc}} \left(m \left(\sqrt{\frac{T}{Tc}} - 1\right) - 1\right) \frac{d^2 a\alpha}{dT^2} = \frac{a m \sqrt{\frac{T}{Tc}}}{2 T^{2}} \left(m + 1\right) ''' a, Tc, m = self.a, self.Tc, self.m sqTr = (T/Tc)**0.5 a_alpha = a*(m*(1. - sqTr) + 1.)**2 if not full: return a_alpha else: da_alpha_dT = -a*m*sqTr*(m*(-sqTr + 1.) + 1.)/T d2a_alpha_dT2 = a*m*sqTr*(m + 1.)/(2.*T*T) return a_alpha, da_alpha_dT, d2a_alpha_dT2
def solve_T(self, P, V, quick=True): r'''Method to calculate `T` from a specified `P` and `V` for the SRK EOS. Uses `a`, `b`, and `Tc` obtained from the class's namespace. Parameters ---------- P : float Pressure, [Pa] V : float Molar volume, [m^3/mol] quick : bool, optional Whether to use a SymPy cse-derived expression (3x faster) or individual formulas Returns ------- T : float Temperature, [K] Notes ----- The exact solution can be derived as follows; it is excluded for breviety. >>> from sympy import * >>> P, T, V, R, a, b, m = symbols('P, T, V, R, a, b, m') >>> Tc, Pc, omega = symbols('Tc, Pc, omega') >>> a_alpha = a*(1 + m*(1-sqrt(T/Tc)))**2 >>> SRK = R*T/(V-b) - a_alpha/(V*(V+b)) - P >>> # solve(SRK, T) ''' a, b, Tc, m = self.a, self.b, self.Tc, self.m if quick: x0 = R*Tc x1 = V*b x2 = x0*x1 x3 = V*V x4 = x0*x3 x5 = m*m x6 = a*x5 x7 = b*x6 x8 = V*x6 x9 = (x2 + x4 + x7 - x8)**2 x10 = x3*x3 x11 = R*R*Tc*Tc x12 = a*a x13 = x5*x5 x14 = x12*x13 x15 = b*b x16 = x3*V x17 = a*x0 x18 = x17*x5 x19 = 2.*b*x16 x20 = -2.*V*b*x14 + 2.*V*x15*x18 + x10*x11 + x11*x15*x3 + x11*x19 + x14*x15 + x14*x3 - 2*x16*x18 x21 = V - b x22 = 2*m*x17 x23 = P*x4 x24 = P*x8 x25 = x1*x17 x26 = P*R*Tc x27 = x17*x3 x28 = V*x12 x29 = 2.*m*m*m x30 = b*x12 return -Tc*(2.*a*m*x9*(V*x21*x21*x21*(V + b)*(P*x2 + P*x7 + x17 + x18 + x22 + x23 - x24))**0.5*(m + 1.) - x20*x21*(-P*x16*x6 + x1*x22 + x10*x26 + x13*x28 - x13*x30 + x15*x23 + x15*x24 + x19*x26 + x22*x3 + x25*x5 + x25 + x27*x5 + x27 + x28*x29 + x28*x5 - x29*x30 - x30*x5))/(x20*x9) else: return Tc*(-2*a*m*sqrt(V*(V - b)**3*(V + b)*(P*R*Tc*V**2 + P*R*Tc*V*b - P*V*a*m**2 + P*a*b*m**2 + R*Tc*a*m**2 + 2*R*Tc*a*m + R*Tc*a))*(m + 1)*(R*Tc*V**2 + R*Tc*V*b - V*a*m**2 + a*b*m**2)**2 + (V - b)*(R**2*Tc**2*V**4 + 2*R**2*Tc**2*V**3*b + R**2*Tc**2*V**2*b**2 - 2*R*Tc*V**3*a*m**2 + 2*R*Tc*V*a*b**2*m**2 + V**2*a**2*m**4 - 2*V*a**2*b*m**4 + a**2*b**2*m**4)*(P*R*Tc*V**4 + 2*P*R*Tc*V**3*b + P*R*Tc*V**2*b**2 - P*V**3*a*m**2 + P*V*a*b**2*m**2 + R*Tc*V**2*a*m**2 + 2*R*Tc*V**2*a*m + R*Tc*V**2*a + R*Tc*V*a*b*m**2 + 2*R*Tc*V*a*b*m + R*Tc*V*a*b + V*a**2*m**4 + 2*V*a**2*m**3 + V*a**2*m**2 - a**2*b*m**4 - 2*a**2*b*m**3 - a**2*b*m**2))/((R*Tc*V**2 + R*Tc*V*b - V*a*m**2 + a*b*m**2)**2*(R**2*Tc**2*V**4 + 2*R**2*Tc**2*V**3*b + R**2*Tc**2*V**2*b**2 - 2*R*Tc*V**3*a*m**2 + 2*R*Tc*V*a*b**2*m**2 + V**2*a**2*m**4 - 2*V*a**2*b*m**4 + a**2*b**2*m**4))
def a_alpha_and_derivatives(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives for this EOS. Returns `a_alpha`, `da_alpha_dT`, and `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more documentation. Uses the set values of `Tc`, `a`, `S1`, and `S2`. .. math:: a\alpha(T) = a\left[1 + S_1\left(1-\sqrt{T_r}\right) + S_2\frac{1 - \sqrt{T_r}}{\sqrt{T_r}}\right]^2 \frac{d a\alpha}{dT} = a\frac{Tc}{T^{2}} \left(- S_{2} \left(\sqrt{ \frac{T}{Tc}} - 1\right) + \sqrt{\frac{T}{Tc}} \left(S_{1} \sqrt{ \frac{T}{Tc}} + S_{2}\right)\right) \left(S_{2} \left(\sqrt{\frac{ T}{Tc}} - 1\right) + \sqrt{\frac{T}{Tc}} \left(S_{1} \left(\sqrt{ \frac{T}{Tc}} - 1\right) - 1\right)\right) \frac{d^2 a\alpha}{dT^2} = a\frac{1}{2 T^{3}} \left(S_{1}^{2} T \sqrt{\frac{T}{Tc}} - S_{1} S_{2} T \sqrt{\frac{T}{Tc}} + 3 S_{1} S_{2} Tc \sqrt{\frac{T}{Tc}} + S_{1} T \sqrt{\frac{T}{Tc}} - 3 S_{2}^{2} Tc \sqrt{\frac{T}{Tc}} + 4 S_{2}^{2} Tc + 3 S_{2} Tc \sqrt{\frac{T}{Tc}}\right) ''' a, Tc, S1, S2 = self.a, self.Tc, self.S1, self.S2 if not full: return a*(S1*(-(T/Tc)**0.5 + 1.) + S2*(-(T/Tc)**0.5 + 1)*(T/Tc)**-0.5 + 1)**2 else: if quick: x0 = (T/Tc)**0.5 x1 = x0 - 1. x2 = x1/x0 x3 = S2*x2 x4 = S1*x1 + x3 - 1. x5 = S1*x0 x6 = S2 - x3 + x5 x7 = 3.*S2 a_alpha = a*x4*x4 da_alpha_dT = a*x4*x6/T d2a_alpha_dT2 = a*(-x4*(-x2*x7 + x5 + x7) + x6*x6)/(2.*T*T) else: a_alpha = a*(S1*(-sqrt(T/Tc) + 1) + S2*(-sqrt(T/Tc) + 1)/sqrt(T/Tc) + 1)**2 da_alpha_dT = a*((S1*(-sqrt(T/Tc) + 1) + S2*(-sqrt(T/Tc) + 1)/sqrt(T/Tc) + 1)*(-S1*sqrt(T/Tc)/T - S2/T - S2*(-sqrt(T/Tc) + 1)/(T*sqrt(T/Tc)))) d2a_alpha_dT2 = a*(((S1*sqrt(T/Tc) + S2 - S2*(sqrt(T/Tc) - 1)/sqrt(T/Tc))**2 - (S1*sqrt(T/Tc) + 3*S2 - 3*S2*(sqrt(T/Tc) - 1)/sqrt(T/Tc))*(S1*(sqrt(T/Tc) - 1) + S2*(sqrt(T/Tc) - 1)/sqrt(T/Tc) - 1))/(2*T**2)) return a_alpha, da_alpha_dT, d2a_alpha_dT2
def solve_T(self, P, V, quick=True): r'''Method to calculate `T` from a specified `P` and `V` for the API SRK EOS. Uses `a`, `b`, and `Tc` obtained from the class's namespace. Parameters ---------- P : float Pressure, [Pa] V : float Molar volume, [m^3/mol] quick : bool, optional Whether to use a SymPy cse-derived expression (3x faster) or individual formulas Returns ------- T : float Temperature, [K] Notes ----- If S2 is set to 0, the solution is the same as in the SRK EOS, and that is used. Otherwise, newton's method must be used to solve for `T`. There are 8 roots of T in that case, six of them real. No guarantee can be made regarding which root will be obtained. ''' if self.S2 == 0: self.m = self.S1 return SRK.solve_T(self, P, V, quick=quick) else: # Previously coded method is 63 microseconds vs 47 here # return super(SRK, self).solve_T(P, V, quick=quick) Tc, a, b, S1, S2 = self.Tc, self.a, self.b, self.S1, self.S2 if quick: x2 = R/(V-b) x3 = (V*(V + b)) def to_solve(T): x0 = (T/Tc)**0.5 x1 = x0 - 1. return (x2*T - a*(S1*x1 + S2*x1/x0 - 1.)**2/x3) - P else: def to_solve(T): P_calc = R*T/(V - b) - a*(S1*(-sqrt(T/Tc) + 1) + S2*(-sqrt(T/Tc) + 1)/sqrt(T/Tc) + 1)**2/(V*(V + b)) return P_calc - P return newton(to_solve, Tc*0.5)
def a_alpha_and_derivatives(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives for this EOS. Returns `a_alpha`, `da_alpha_dT`, and `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more documentation. Uses the set values of `Tc`, `omega`, and `a`. Because of its similarity for the TWUPR EOS, this has been moved to an external `TWU_a_alpha_common` function. See it for further documentation. ''' return TWU_a_alpha_common(T, self.Tc, self.omega, self.a, full=full, quick=quick, method='SRK')
def Tb(CASRN, AvailableMethods=False, Method=None, IgnoreMethods=[PSAT_DEFINITION]): r'''This function handles the retrieval of a chemical's boiling point. Lookup is based on CASRNs. Will automatically select a data source to use if no Method is provided; returns None if the data is not available. Prefered sources are 'CRC Physical Constants, organic' for organic chemicals, and 'CRC Physical Constants, inorganic' for inorganic chemicals. Function has data for approximately 13000 chemicals. Parameters ---------- CASRN : string CASRN [-] Returns ------- Tb : float Boiling temperature, [K] methods : list, only returned if AvailableMethods == True List of methods which can be used to obtain Tb with the given inputs Other Parameters ---------------- Method : string, optional A string for the method name to use, as defined by constants in Tb_methods AvailableMethods : bool, optional If True, function will determine which methods can be used to obtain Tb for the desired chemical, and will return methods instead of Tb IgnoreMethods : list, optional A list of methods to ignore in obtaining the full list of methods, useful for for performance reasons and ignoring inaccurate methods Notes ----- A total of four methods are available for this function. They are: * 'CRC_ORG', a compillation of data on organics as published in [1]_. * 'CRC_INORG', a compillation of data on inorganic as published in [1]_. * 'YAWS', a large compillation of data from a variety of sources; no data points are sourced in the work of [2]_. * 'PSAT_DEFINITION', calculation of boiling point from a vapor pressure calculation. This is normally off by a fraction of a degree even in the best cases. Listed in IgnoreMethods by default for performance reasons. Examples -------- >>> Tb('7732-18-5') 373.124 References ---------- .. [1] Haynes, W.M., Thomas J. Bruno, and David R. Lide. CRC Handbook of Chemistry and Physics, 95E. Boca Raton, FL: CRC press, 2014. .. [2] Yaws, Carl L. Thermophysical Properties of Chemicals and Hydrocarbons, Second Edition. Amsterdam Boston: Gulf Professional Publishing, 2014. ''' def list_methods(): methods = [] if CASRN in CRC_inorganic_data.index and not np.isnan(CRC_inorganic_data.at[CASRN, 'Tb']): methods.append(CRC_INORG) if CASRN in CRC_organic_data.index and not np.isnan(CRC_organic_data.at[CASRN, 'Tb']): methods.append(CRC_ORG) if CASRN in Yaws_data.index: methods.append(YAWS) if PSAT_DEFINITION not in IgnoreMethods: try: # For some chemicals, vapor pressure range will exclude Tb VaporPressure(CASRN=CASRN).solve_prop(101325.) methods.append(PSAT_DEFINITION) except: # pragma: no cover pass if IgnoreMethods: for Method in IgnoreMethods: if Method in methods: methods.remove(Method) methods.append(NONE) return methods if AvailableMethods: return list_methods() if not Method: Method = list_methods()[0] if Method == CRC_INORG: return float(CRC_inorganic_data.at[CASRN, 'Tb']) elif Method == CRC_ORG: return float(CRC_organic_data.at[CASRN, 'Tb']) elif Method == YAWS: return float(Yaws_data.at[CASRN, 'Tb']) elif Method == PSAT_DEFINITION: return VaporPressure(CASRN=CASRN).solve_prop(101325.) elif Method == NONE: return None else: raise Exception('Failure in in function')
def Tm(CASRN, AvailableMethods=False, Method=None, IgnoreMethods=[]): r'''This function handles the retrieval of a chemical's melting point. Lookup is based on CASRNs. Will automatically select a data source to use if no Method is provided; returns None if the data is not available. Prefered sources are 'Open Notebook Melting Points', with backup sources 'CRC Physical Constants, organic' for organic chemicals, and 'CRC Physical Constants, inorganic' for inorganic chemicals. Function has data for approximately 14000 chemicals. Parameters ---------- CASRN : string CASRN [-] Returns ------- Tm : float Melting temperature, [K] methods : list, only returned if AvailableMethods == True List of methods which can be used to obtain Tm with the given inputs Other Parameters ---------------- Method : string, optional A string for the method name to use, as defined by constants in Tm_methods AvailableMethods : bool, optional If True, function will determine which methods can be used to obtain Tm for the desired chemical, and will return methods instead of Tm IgnoreMethods : list, optional A list of methods to ignore in obtaining the full list of methods Notes ----- A total of three sources are available for this function. They are: * 'OPEN_NTBKM, a compillation of data on organics as published in [1]_ as Open Notebook Melting Points; Averaged (median) values were used when multiple points were available. For more information on this invaluable and excellent collection, see http://onswebservices.wikispaces.com/meltingpoint. * 'CRC_ORG', a compillation of data on organics as published in [2]_. * 'CRC_INORG', a compillation of data on inorganic as published in [2]_. Examples -------- >>> Tm(CASRN='7732-18-5') 273.15 References ---------- .. [1] Bradley, Jean-Claude, Antony Williams, and Andrew Lang. "Jean-Claude Bradley Open Melting Point Dataset", May 20, 2014. https://figshare.com/articles/Jean_Claude_Bradley_Open_Melting_Point_Datset/1031637. .. [2] Haynes, W.M., Thomas J. Bruno, and David R. Lide. CRC Handbook of Chemistry and Physics, 95E. Boca Raton, FL: CRC press, 2014. ''' def list_methods(): methods = [] if CASRN in Tm_ON_data.index: methods.append(OPEN_NTBKM) if CASRN in CRC_inorganic_data.index and not np.isnan(CRC_inorganic_data.at[CASRN, 'Tm']): methods.append(CRC_INORG) if CASRN in CRC_organic_data.index and not np.isnan(CRC_organic_data.at[CASRN, 'Tm']): methods.append(CRC_ORG) if IgnoreMethods: for Method in IgnoreMethods: if Method in methods: methods.remove(Method) methods.append(NONE) return methods if AvailableMethods: return list_methods() if not Method: Method = list_methods()[0] if Method == OPEN_NTBKM: return float(Tm_ON_data.at[CASRN, 'Tm']) elif Method == CRC_INORG: return float(CRC_inorganic_data.at[CASRN, 'Tm']) elif Method == CRC_ORG: return float(CRC_organic_data.at[CASRN, 'Tm']) elif Method == NONE: return None else: raise Exception('Failure in in function')
def Clapeyron(T, Tc, Pc, dZ=1, Psat=101325): r'''Calculates enthalpy of vaporization at arbitrary temperatures using the Clapeyron equation. The enthalpy of vaporization is given by: .. math:: \Delta H_{vap} = RT \Delta Z \frac{\ln (P_c/Psat)}{(1-T_{r})} Parameters ---------- T : float Temperature of fluid [K] Tc : float Critical temperature of fluid [K] Pc : float Critical pressure of fluid [Pa] dZ : float Change in compressibility factor between liquid and gas, [] Psat : float Saturation pressure of fluid [Pa], optional Returns ------- Hvap : float Enthalpy of vaporization, [J/mol] Notes ----- No original source is available for this equation. [1]_ claims this equation overpredicts enthalpy by several percent. Under Tr = 0.8, dZ = 1 is a reasonable assumption. This equation is most accurate at the normal boiling point. Internal units are bar. WARNING: I believe it possible that the adjustment for pressure may be incorrect Examples -------- Problem from Perry's examples. >>> Clapeyron(T=294.0, Tc=466.0, Pc=5.55E6) 26512.354585061985 References ---------- .. [1] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000. ''' Tr = T/Tc return R*T*dZ*log(Pc/Psat)/(1. - Tr)
def Pitzer(T, Tc, omega): r'''Calculates enthalpy of vaporization at arbitrary temperatures using a fit by [2]_ to the work of Pitzer [1]_; requires a chemical's critical temperature and acentric factor. The enthalpy of vaporization is given by: .. math:: \frac{\Delta_{vap} H}{RT_c}=7.08(1-T_r)^{0.354}+10.95\omega(1-T_r)^{0.456} Parameters ---------- T : float Temperature of fluid [K] Tc : float Critical temperature of fluid [K] omega : float Acentric factor [-] Returns ------- Hvap : float Enthalpy of vaporization, [J/mol] Notes ----- This equation is listed in [3]_, page 2-487 as method #2 for estimating Hvap. This cites [2]_. The recommended range is 0.6 to 1 Tr. Users should expect up to 5% error. T must be under Tc, or an exception is raised. The original article has been reviewed and found to have a set of tabulated values which could be used instead of the fit function to provide additional accuracy. Examples -------- Example as in [3]_, p2-487; exp: 37.51 kJ/mol >>> Pitzer(452, 645.6, 0.35017) 36696.736640106414 References ---------- .. [1] Pitzer, Kenneth S. "The Volumetric and Thermodynamic Properties of Fluids. I. Theoretical Basis and Virial Coefficients." Journal of the American Chemical Society 77, no. 13 (July 1, 1955): 3427-33. doi:10.1021/ja01618a001 .. [2] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000. .. [3] Green, Don, and Robert Perry. Perry's Chemical Engineers' Handbook, Eighth Edition. McGraw-Hill Professional, 2007. ''' Tr = T/Tc return R*Tc * (7.08*(1. - Tr)**0.354 + 10.95*omega*(1. - Tr)**0.456)
def SMK(T, Tc, omega): r'''Calculates enthalpy of vaporization at arbitrary temperatures using a the work of [1]_; requires a chemical's critical temperature and acentric factor. The enthalpy of vaporization is given by: .. math:: \frac{\Delta H_{vap}} {RT_c} = \left( \frac{\Delta H_{vap}} {RT_c} \right)^{(R1)} + \left( \frac{\omega - \omega^{(R1)}} {\omega^{(R2)} - \omega^{(R1)}} \right) \left[\left( \frac{\Delta H_{vap}} {RT_c} \right)^{(R2)} - \left( \frac{\Delta H_{vap}} {RT_c} \right)^{(R1)} \right] \left( \frac{\Delta H_{vap}} {RT_c} \right)^{(R1)} = 6.537 \tau^{1/3} - 2.467 \tau^{5/6} - 77.251 \tau^{1.208} + 59.634 \tau + 36.009 \tau^2 - 14.606 \tau^3 \left( \frac{\Delta H_{vap}} {RT_c} \right)^{(R2)} - \left( \frac{\Delta H_{vap}} {RT_c} \right)^{(R1)}=-0.133 \tau^{1/3} - 28.215 \tau^{5/6} - 82.958 \tau^{1.208} + 99.00 \tau + 19.105 \tau^2 -2.796 \tau^3 \tau = 1-T/T_c Parameters ---------- T : float Temperature of fluid [K] Tc : float Critical temperature of fluid [K] omega : float Acentric factor [-] Returns ------- Hvap : float Enthalpy of vaporization, [J/mol] Notes ----- The original article has been reviewed and found to have coefficients with slightly more precision. Additionally, the form of the equation is slightly different, but numerically equivalent. The refence fluids are: :math:`\omega_0` = benzene = 0.212 :math:`\omega_1` = carbazole = 0.461 A sample problem in the article has been verified. The numerical result presented by the author requires high numerical accuracy to obtain. Examples -------- Problem in [1]_: >>> SMK(553.15, 751.35, 0.302) 39866.17647797959 References ---------- .. [1] Sivaraman, Alwarappa, Joe W. Magee, and Riki Kobayashi. "Generalized Correlation of Latent Heats of Vaporization of Coal-Liquid Model Compounds between Their Freezing Points and Critical Points." Industrial & Engineering Chemistry Fundamentals 23, no. 1 (February 1, 1984): 97-100. doi:10.1021/i100013a017. ''' omegaR1, omegaR2 = 0.212, 0.461 A10 = 6.536924 A20 = -2.466698 A30 = -77.52141 B10 = 59.63435 B20 = 36.09887 B30 = -14.60567 A11 = -0.132584 A21 = -28.21525 A31 = -82.95820 B11 = 99.00008 B21 = 19.10458 B31 = -2.795660 tau = 1. - T/Tc L0 = A10*tau**(1/3.) + A20*tau**(5/6.) + A30*tau**(1-1/8. + 1/3.) + \ B10*tau + B20*tau**2 + B30*tau**3 L1 = A11*tau**(1/3.) + A21*tau**(5/6.0) + A31*tau**(1-1/8. + 1/3.) + \ B11*tau + B21*tau**2 + B31*tau**3 domega = (omega - omegaR1)/(omegaR2 - omegaR1) return R*Tc*(L0 + domega*L1)
def MK(T, Tc, omega): r'''Calculates enthalpy of vaporization at arbitrary temperatures using a the work of [1]_; requires a chemical's critical temperature and acentric factor. The enthalpy of vaporization is given by: .. math:: \Delta H_{vap} = \Delta H_{vap}^{(0)} + \omega \Delta H_{vap}^{(1)} + \omega^2 \Delta H_{vap}^{(2)} \frac{\Delta H_{vap}^{(i)}}{RT_c} = b^{(j)} \tau^{1/3} + b_2^{(j)} \tau^{5/6} + b_3^{(j)} \tau^{1.2083} + b_4^{(j)}\tau + b_5^{(j)} \tau^2 + b_6^{(j)} \tau^3 \tau = 1-T/T_c Parameters ---------- T : float Temperature of fluid [K] Tc : float Critical temperature of fluid [K] omega : float Acentric factor [-] Returns ------- Hvap : float Enthalpy of vaporization, [J/mol] Notes ----- The original article has been reviewed. A total of 18 coefficients are used: WARNING: The correlation has been implemented as described in the article, but its results seem different and with some error. Its results match with other functions however. Has poor behavior for low-temperature use. Examples -------- Problem in article for SMK function. >>> MK(553.15, 751.35, 0.302) 38727.993546377205 References ---------- .. [1] Morgan, David L., and Riki Kobayashi. "Extension of Pitzer CSP Models for Vapor Pressures and Heats of Vaporization to Long-Chain Hydrocarbons." Fluid Phase Equilibria 94 (March 15, 1994): 51-87. doi:10.1016/0378-3812(94)87051-9. ''' bs = [[5.2804, 0.080022, 7.2543], [12.8650, 273.23, -346.45], [1.1710, 465.08, -610.48], [-13.1160, -638.51, 839.89], [0.4858, -145.12, 160.05], [-1.0880, 74.049, -50.711]] tau = 1. - T/Tc H0 = (bs[0][0]*tau**(0.3333) + bs[1][0]*tau**(0.8333) + bs[2][0]*tau**(1.2083) + bs[3][0]*tau + bs[4][0]*tau**(2) + bs[5][0]*tau**(3))*R*Tc H1 = (bs[0][1]*tau**(0.3333) + bs[1][1]*tau**(0.8333) + bs[2][1]*tau**(1.2083) + bs[3][1]*tau + bs[4][1]*tau**(2) + bs[5][1]*tau**(3))*R*Tc H2 = (bs[0][2]*tau**(0.3333) + bs[1][2]*tau**(0.8333) + bs[2][2]*tau**(1.2083) + bs[3][2]*tau + bs[4][2]*tau**(2) + bs[5][2]*tau**(3))*R*Tc return H0 + omega*H1 + omega**2*H2
def Velasco(T, Tc, omega): r'''Calculates enthalpy of vaporization at arbitrary temperatures using a the work of [1]_; requires a chemical's critical temperature and acentric factor. The enthalpy of vaporization is given by: .. math:: \Delta_{vap} H = RT_c(7.2729 + 10.4962\omega + 0.6061\omega^2)(1-T_r)^{0.38} Parameters ---------- T : float Temperature of fluid [K] Tc : float Critical temperature of fluid [K] omega : float Acentric factor [-] Returns ------- Hvap : float Enthalpy of vaporization, [J/mol] Notes ----- The original article has been reviewed. It is regressed from enthalpy of vaporization values at 0.7Tr, from 121 fluids in REFPROP 9.1. A value in the article was read to be similar, but slightly too low from that calculated here. Examples -------- From graph, in [1]_ for perfluoro-n-heptane. >>> Velasco(333.2, 476.0, 0.5559) 33299.41734936356 References ---------- .. [1] Velasco, S., M. J. Santos, and J. A. White. "Extended Corresponding States Expressions for the Changes in Enthalpy, Compressibility Factor and Constant-Volume Heat Capacity at Vaporization." The Journal of Chemical Thermodynamics 85 (June 2015): 68-76. doi:10.1016/j.jct.2015.01.011. ''' return (7.2729 + 10.4962*omega + 0.6061*omega**2)*(1-T/Tc)**0.38*R*Tc
def Riedel(Tb, Tc, Pc): r'''Calculates enthalpy of vaporization at the boiling point, using the Ridel [1]_ CSP method. Required information are critical temperature and pressure, and boiling point. Equation taken from [2]_ and [3]_. The enthalpy of vaporization is given by: .. math:: \Delta_{vap} H=1.093 T_b R\frac{\ln P_c-1.013}{0.930-T_{br}} Parameters ---------- Tb : float Boiling temperature of fluid [K] Tc : float Critical temperature of fluid [K] Pc : float Critical pressure of fluid [Pa] Returns ------- Hvap : float Enthalpy of vaporization at the normal boiling point, [J/mol] Notes ----- This equation has no example calculation in any source. The source has not been verified. It is equation 4-144 in Perry's. Perry's also claims that errors seldom surpass 5%. [2]_ is the source of example work here, showing a calculation at 0.0% error. Internal units of pressure are bar. Examples -------- Pyridine, 0.0% err vs. exp: 35090 J/mol; from Poling [2]_. >>> Riedel(388.4, 620.0, 56.3E5) 35089.78989646058 References ---------- .. [1] Riedel, L. "Eine Neue Universelle Dampfdruckformel Untersuchungen Uber Eine Erweiterung Des Theorems Der Ubereinstimmenden Zustande. Teil I." Chemie Ingenieur Technik 26, no. 2 (February 1, 1954): 83-89. doi:10.1002/cite.330260206. .. [2] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000. .. [3] Green, Don, and Robert Perry. Perry's Chemical Engineers' Handbook, Eighth Edition. McGraw-Hill Professional, 2007. ''' Pc = Pc/1E5 # Pa to bar Tbr = Tb/Tc return 1.093*Tb*R*(log(Pc) - 1.013)/(0.93 - Tbr)
def Chen(Tb, Tc, Pc): r'''Calculates enthalpy of vaporization using the Chen [1]_ correlation and a chemical's critical temperature, pressure and boiling point. The enthalpy of vaporization is given by: .. math:: \Delta H_{vb} = RT_b \frac{3.978 T_r - 3.958 + 1.555 \ln P_c}{1.07 - T_r} Parameters ---------- Tb : float Boiling temperature of the fluid [K] Tc : float Critical temperature of fluid [K] Pc : float Critical pressure of fluid [Pa] Returns ------- Hvap : float Enthalpy of vaporization, [J/mol] Notes ----- The formulation presented in the original article is similar, but uses units of atm and calorie instead. The form in [2]_ has adjusted for this. A method for estimating enthalpy of vaporization at other conditions has also been developed, but the article is unclear on its implementation. Based on the Pitzer correlation. Internal units: bar and K Examples -------- Same problem as in Perry's examples. >>> Chen(294.0, 466.0, 5.55E6) 26705.893506174052 References ---------- .. [1] Chen, N. H. "Generalized Correlation for Latent Heat of Vaporization." Journal of Chemical & Engineering Data 10, no. 2 (April 1, 1965): 207-10. doi:10.1021/je60025a047 .. [2] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000. ''' Tbr = Tb/Tc Pc = Pc/1E5 # Pa to bar return R*Tb*(3.978*Tbr - 3.958 + 1.555*log(Pc))/(1.07 - Tbr)
def Liu(Tb, Tc, Pc): r'''Calculates enthalpy of vaporization at the normal boiling point using the Liu [1]_ correlation, and a chemical's critical temperature, pressure and boiling point. The enthalpy of vaporization is given by: .. math:: \Delta H_{vap} = RT_b \left[ \frac{T_b}{220}\right]^{0.0627} \frac{ (1-T_{br})^{0.38} \ln(P_c/P_A)}{1-T_{br} + 0.38 T_{br} \ln T_{br}} Parameters ---------- Tb : float Boiling temperature of the fluid [K] Tc : float Critical temperature of fluid [K] Pc : float Critical pressure of fluid [Pa] Returns ------- Hvap : float Enthalpy of vaporization, [J/mol] Notes ----- This formulation can be adjusted for lower boiling points, due to the use of a rationalized pressure relationship. The formulation is taken from the original article. A correction for alcohols and organic acids based on carbon number, which only modifies the boiling point, is available but not implemented. No sample calculations are available in the article. Internal units: Pa and K Examples -------- Same problem as in Perry's examples >>> Liu(294.0, 466.0, 5.55E6) 26378.566319606754 References ---------- .. [1] LIU, ZHI-YONG. "Estimation of Heat of Vaporization of Pure Liquid at Its Normal Boiling Temperature." Chemical Engineering Communications 184, no. 1 (February 1, 2001): 221-28. doi:10.1080/00986440108912849. ''' Tbr = Tb/Tc return R*Tb*(Tb/220.)**0.0627*(1. - Tbr)**0.38*log(Pc/101325.) \ / (1 - Tbr + 0.38*Tbr*log(Tbr))
def Vetere(Tb, Tc, Pc, F=1): r'''Calculates enthalpy of vaporization at the boiling point, using the Vetere [1]_ CSP method. Required information are critical temperature and pressure, and boiling point. Equation taken from [2]_. The enthalpy of vaporization is given by: .. math:: \frac {\Delta H_{vap}}{RT_b} = \frac{\tau_b^{0.38} \left[ \ln P_c - 0.513 + \frac{0.5066}{P_cT_{br}^2}\right]} {\tau_b + F(1-\tau_b^{0.38})\ln T_{br}} Parameters ---------- Tb : float Boiling temperature of fluid [K] Tc : float Critical temperature of fluid [K] Pc : float Critical pressure of fluid [Pa] F : float, optional Constant for a fluid, [-] Returns ------- Hvap : float Enthalpy of vaporization at the boiling point, [J/mol] Notes ----- The equation cannot be found in the original source. It is believed that a second article is its source, or that DIPPR staff have altered the formulation. Internal units of pressure are bar. Examples -------- Example as in [2]_, p2-487; exp: 25.73 >>> Vetere(294.0, 466.0, 5.55E6) 26363.430021286465 References ---------- .. [1] Vetere, Alessandro. "Methods to Predict the Vaporization Enthalpies at the Normal Boiling Temperature of Pure Compounds Revisited." Fluid Phase Equilibria 106, no. 1-2 (May 1, 1995): 1–10. doi:10.1016/0378-3812(94)02627-D. .. [2] Green, Don, and Robert Perry. Perry's Chemical Engineers' Handbook, Eighth Edition. McGraw-Hill Professional, 2007. ''' Tbr = Tb/Tc taub = 1-Tb/Tc Pc = Pc/1E5 term = taub**0.38*(log(Pc)-0.513 + 0.5066/Pc/Tbr**2) / (taub + F*(1-taub**0.38)*log(Tbr)) return R*Tb*term
def Watson(T, Hvap_ref, T_Ref, Tc, exponent=0.38): ''' Adjusts enthalpy of vaporization of enthalpy for another temperature, for one temperature. ''' Tr = T/Tc Trefr = T_Ref/Tc H2 = Hvap_ref*((1-Tr)/(1-Trefr))**exponent return H2
def Hfus(T=298.15, P=101325, MW=None, AvailableMethods=False, Method=None, CASRN=''): # pragma: no cover '''This function handles the calculation of a chemical's enthalpy of fusion. Generally this, is used by the chemical class, as all parameters are passed. Calling the function directly works okay. Enthalpy of fusion is a weak function of pressure, and its effects are neglected. This API is considered experimental, and is expected to be removed in a future release in favor of a more complete object-oriented interface. ''' def list_methods(): methods = [] if CASRN in CRCHfus_data.index: methods.append('CRC, at melting point') methods.append('None') return methods if AvailableMethods: return list_methods() if not Method: Method = list_methods()[0] # This is the calculate, given the method section if Method == 'CRC, at melting point': _Hfus = CRCHfus_data.at[CASRN, 'Hfus'] elif Method == 'None' or not MW: _Hfus = None else: raise Exception('Failure in in function') _Hfus = property_molar_to_mass(_Hfus, MW) return _Hfus
def Hsub(T=298.15, P=101325, MW=None, AvailableMethods=False, Method=None, CASRN=''): # pragma: no cover '''This function handles the calculation of a chemical's enthalpy of sublimation. Generally this, is used by the chemical class, as all parameters are passed. This API is considered experimental, and is expected to be removed in a future release in favor of a more complete object-oriented interface. ''' def list_methods(): methods = [] # if Hfus(T=T, P=P, MW=MW, CASRN=CASRN) and Hvap(T=T, P=P, MW=MW, CASRN=CASRN): # methods.append('Hfus + Hvap') if CASRN in GharagheiziHsub_data.index: methods.append('Ghazerati Appendix, at 298K') methods.append('None') return methods if AvailableMethods: return list_methods() if not Method: Method = list_methods()[0] # This is the calculate, given the method section # if Method == 'Hfus + Hvap': # p1 = Hfus(T=T, P=P, MW=MW, CASRN=CASRN) # p2 = Hvap(T=T, P=P, MW=MW, CASRN=CASRN) # if p1 and p2: # _Hsub = p1 + p2 # else: # _Hsub = None if Method == 'Ghazerati Appendix, at 298K': _Hsub = float(GharagheiziHsub_data.at[CASRN, 'Hsub']) elif Method == 'None' or not _Hsub or not MW: return None else: raise Exception('Failure in in function') _Hsub = property_molar_to_mass(_Hsub, MW) return _Hsub
def Tliquidus(Tms=None, ws=None, xs=None, CASRNs=None, AvailableMethods=False, Method=None): # pragma: no cover '''This function handles the retrival of a mixtures's liquidus point. This API is considered experimental, and is expected to be removed in a future release in favor of a more complete object-oriented interface. >>> Tliquidus(Tms=[250.0, 350.0], xs=[0.5, 0.5]) 350.0 >>> Tliquidus(Tms=[250, 350], xs=[0.5, 0.5], Method='Simple') 300.0 >>> Tliquidus(Tms=[250, 350], xs=[0.5, 0.5], AvailableMethods=True) ['Maximum', 'Simple', 'None'] ''' def list_methods(): methods = [] if none_and_length_check([Tms]): methods.append('Maximum') methods.append('Simple') methods.append('None') return methods if AvailableMethods: return list_methods() if not Method: Method = list_methods()[0] # This is the calculate, given the method section if Method == 'Maximum': _Tliq = max(Tms) elif Method == 'Simple': _Tliq = mixing_simple(xs, Tms) elif Method == 'None': return None else: raise Exception('Failure in in function') return _Tliq
def load_all_methods(self): r'''Method which picks out coefficients for the specified chemical from the various dictionaries and DataFrames storing it. All data is stored as attributes. This method also sets :obj:`Tmin`, :obj:`Tmax`, and :obj:`all_methods` as a set of methods for which the data exists for. Called on initialization only. See the source code for the variables at which the coefficients are stored. The coefficients can safely be altered once the class is initialized. This method can be called again to reset the parameters. ''' methods = [] Tmins, Tmaxs = [], [] if has_CoolProp and self.CASRN in coolprop_dict: methods.append(COOLPROP) self.CP_f = coolprop_fluids[self.CASRN] Tmins.append(self.CP_f.Tt); Tmaxs.append(self.CP_f.Tc) if self.CASRN in _VDISaturationDict: methods.append(VDI_TABULAR) Ts, props = VDI_tabular_data(self.CASRN, 'Hvap') self.VDI_Tmin = Ts[0] self.VDI_Tmax = Ts[-1] self.tabular_data[VDI_TABULAR] = (Ts, props) Tmins.append(self.VDI_Tmin); Tmaxs.append(self.VDI_Tmax) if self.CASRN in Alibakhshi_Cs.index and self.Tc: methods.append(ALIBAKHSHI) self.Alibakhshi_C = float(Alibakhshi_Cs.at[self.CASRN, 'C']) Tmaxs.append( max(self.Tc-100., 0) ) if self.CASRN in CRCHvap_data.index and not np.isnan(CRCHvap_data.at[self.CASRN, 'HvapTb']): methods.append(CRC_HVAP_TB) self.CRC_HVAP_TB_Tb = float(CRCHvap_data.at[self.CASRN, 'Tb']) self.CRC_HVAP_TB_Hvap = float(CRCHvap_data.at[self.CASRN, 'HvapTb']) if self.CASRN in CRCHvap_data.index and not np.isnan(CRCHvap_data.at[self.CASRN, 'Hvap298']): methods.append(CRC_HVAP_298) self.CRC_HVAP_298 = float(CRCHvap_data.at[self.CASRN, 'Hvap298']) if self.CASRN in GharagheiziHvap_data.index: methods.append(GHARAGHEIZI_HVAP_298) self.GHARAGHEIZI_HVAP_298_Hvap = float(GharagheiziHvap_data.at[self.CASRN, 'Hvap298']) if all((self.Tc, self.omega)): methods.extend(self.CSP_methods) Tmaxs.append(self.Tc); Tmins.append(0) if all((self.Tc, self.Pc)): methods.append(CLAPEYRON) Tmaxs.append(self.Tc); Tmins.append(0) if all((self.Tb, self.Tc, self.Pc)): methods.extend(self.boiling_methods) Tmaxs.append(self.Tc); Tmins.append(0) if self.CASRN in Perrys2_150.index: methods.append(DIPPR_PERRY_8E) _, Tc, C1, C2, C3, C4, self.Perrys2_150_Tmin, self.Perrys2_150_Tmax = _Perrys2_150_values[Perrys2_150.index.get_loc(self.CASRN)].tolist() self.Perrys2_150_coeffs = [Tc, C1, C2, C3, C4] Tmins.append(self.Perrys2_150_Tmin); Tmaxs.append(self.Perrys2_150_Tmax) if self.CASRN in VDI_PPDS_4.index: _, MW, Tc, A, B, C, D, E = _VDI_PPDS_4_values[VDI_PPDS_4.index.get_loc(self.CASRN)].tolist() self.VDI_PPDS_coeffs = [A, B, C, D, E] self.VDI_PPDS_Tc = Tc self.VDI_PPDS_MW = MW methods.append(VDI_PPDS) Tmaxs.append(self.VDI_PPDS_Tc); self.all_methods = set(methods) if Tmins and Tmaxs: self.Tmin, self.Tmax = min(Tmins), max(Tmaxs)
def calculate(self, T, method): r'''Method to calculate heat of vaporization of a liquid at temperature `T` with a given method. This method has no exception handling; see `T_dependent_property` for that. Parameters ---------- T : float Temperature at which to calculate heat of vaporization, [K] method : str Name of the method to use Returns ------- Hvap : float Heat of vaporization of the liquid at T, [J/mol] ''' if method == COOLPROP: Hvap = PropsSI('HMOLAR', 'T', T, 'Q', 1, self.CASRN) - PropsSI('HMOLAR', 'T', T, 'Q', 0, self.CASRN) elif method == DIPPR_PERRY_8E: Hvap = EQ106(T, *self.Perrys2_150_coeffs) # CSP methods elif method == VDI_PPDS: A, B, C, D, E = self.VDI_PPDS_coeffs tau = 1. - T/self.VDI_PPDS_Tc Hvap = R*self.VDI_PPDS_Tc*(A*tau**(1/3.) + B*tau**(2/3.) + C*tau + D*tau**2 + E*tau**6) elif method == ALIBAKHSHI: Hvap = (4.5*pi*N_A)**(1/3.)*4.2E-7*(self.Tc-6.) - R/2.*T*log(T) + self.Alibakhshi_C*T elif method == MORGAN_KOBAYASHI: Hvap = MK(T, self.Tc, self.omega) elif method == SIVARAMAN_MAGEE_KOBAYASHI: Hvap = SMK(T, self.Tc, self.omega) elif method == VELASCO: Hvap = Velasco(T, self.Tc, self.omega) elif method == PITZER: Hvap = Pitzer(T, self.Tc, self.omega) elif method == CLAPEYRON: Zg = self.Zg(T) if hasattr(self.Zg, '__call__') else self.Zg Zl = self.Zl(T) if hasattr(self.Zl, '__call__') else self.Zl Psat = self.Psat(T) if hasattr(self.Psat, '__call__') else self.Psat if Zg: if Zl: dZ = Zg-Zl else: dZ = Zg Hvap = Clapeyron(T, self.Tc, self.Pc, dZ=dZ, Psat=Psat) # CSP methods at Tb only elif method == RIEDEL: Hvap = Riedel(self.Tb, self.Tc, self.Pc) elif method == CHEN: Hvap = Chen(self.Tb, self.Tc, self.Pc) elif method == VETERE: Hvap = Vetere(self.Tb, self.Tc, self.Pc) elif method == LIU: Hvap = Liu(self.Tb, self.Tc, self.Pc) # Individual data point methods elif method == CRC_HVAP_TB: Hvap = self.CRC_HVAP_TB_Hvap elif method == CRC_HVAP_298: Hvap = self.CRC_HVAP_298 elif method == GHARAGHEIZI_HVAP_298: Hvap = self.GHARAGHEIZI_HVAP_298_Hvap elif method in self.tabular_data: Hvap = self.interpolate(T, method) # Adjust with the watson equation if estimated at Tb or Tc only if method in self.boiling_methods or (self.Tc and method in [CRC_HVAP_TB, CRC_HVAP_298, GHARAGHEIZI_HVAP_298]): if method in self.boiling_methods: Tref = self.Tb elif method == CRC_HVAP_TB: Tref = self.CRC_HVAP_TB_Tb elif method in [CRC_HVAP_298, GHARAGHEIZI_HVAP_298]: Tref = 298.15 Hvap = Watson(T, Hvap, Tref, self.Tc, self.Watson_exponent) return Hvap
def solubility_parameter(T=298.15, Hvapm=None, Vml=None, CASRN='', AvailableMethods=False, Method=None): r'''This function handles the calculation of a chemical's solubility parameter. Calculation is a function of temperature, but is not always presented as such. No lookup values are available; either `Hvapm`, `Vml`, and `T` are provided or the calculation cannot be performed. .. math:: \delta = \sqrt{\frac{\Delta H_{vap} - RT}{V_m}} Parameters ---------- T : float Temperature of the fluid [k] Hvapm : float Heat of vaporization [J/mol/K] Vml : float Specific volume of the liquid [m^3/mol] CASRN : str, optional CASRN of the fluid, not currently used [-] Returns ------- delta : float Solubility parameter, [Pa^0.5] methods : list, only returned if AvailableMethods == True List of methods which can be used to obtain the solubility parameter with the given inputs Other Parameters ---------------- Method : string, optional A string for the method name to use, as defined by constants in solubility_parameter_methods AvailableMethods : bool, optional If True, function will determine which methods can be used to obtain the solubility parameter for the desired chemical, and will return methods instead of the solubility parameter Notes ----- Undefined past the critical point. For convenience, if Hvap is not defined, an error is not raised; None is returned instead. Also for convenience, if Hvapm is less than RT, None is returned to avoid taking the root of a negative number. This parameter is often given in units of cal/ml, which is 2045.48 times smaller than the value returned here. Examples -------- Pentane at STP >>> solubility_parameter(T=298.2, Hvapm=26403.3, Vml=0.000116055) 14357.681538173534 References ---------- .. [1] Barton, Allan F. M. CRC Handbook of Solubility Parameters and Other Cohesion Parameters, Second Edition. CRC Press, 1991. ''' def list_methods(): methods = [] if T and Hvapm and Vml: methods.append(DEFINITION) methods.append(NONE) return methods if AvailableMethods: return list_methods() if not Method: Method = list_methods()[0] if Method == DEFINITION: if (not Hvapm) or (not T) or (not Vml): delta = None else: if Hvapm < R*T or Vml < 0: # Prevent taking the root of a negative number delta = None else: delta = ((Hvapm - R*T)/Vml)**0.5 elif Method == NONE: delta = None else: raise Exception('Failure in in function') return delta
def solubility_eutectic(T, Tm, Hm, Cpl=0, Cps=0, gamma=1): r'''Returns the maximum solubility of a solute in a solvent. .. math:: \ln x_i^L \gamma_i^L = \frac{\Delta H_{m,i}}{RT}\left( 1 - \frac{T}{T_{m,i}}\right) - \frac{\Delta C_{p,i}(T_{m,i}-T)}{RT} + \frac{\Delta C_{p,i}}{R}\ln\frac{T_m}{T} \Delta C_{p,i} = C_{p,i}^L - C_{p,i}^S Parameters ---------- T : float Temperature of the system [K] Tm : float Melting temperature of the solute [K] Hm : float Heat of melting at the melting temperature of the solute [J/mol] Cpl : float, optional Molar heat capacity of the solute as a liquid [J/mol/K] Cpls: float, optional Molar heat capacity of the solute as a solid [J/mol/K] gamma : float, optional Activity coefficient of the solute as a liquid [-] Returns ------- x : float Mole fraction of solute at maximum solubility [-] Notes ----- gamma is of the solute in liquid phase Examples -------- From [1]_, matching example >>> solubility_eutectic(T=260., Tm=278.68, Hm=9952., Cpl=0, Cps=0, gamma=3.0176) 0.24340068761677464 References ---------- .. [1] Gmehling, Jurgen. Chemical Thermodynamics: For Process Simulation. Weinheim, Germany: Wiley-VCH, 2012. ''' dCp = Cpl-Cps x = exp(- Hm/R/T*(1-T/Tm) + dCp*(Tm-T)/R/T - dCp/R*log(Tm/T))/gamma return x
def Tm_depression_eutectic(Tm, Hm, x=None, M=None, MW=None): r'''Returns the freezing point depression caused by a solute in a solvent. Can use either the mole fraction of the solute or its molality and the molecular weight of the solvent. Assumes ideal system behavior. .. math:: \Delta T_m = \frac{R T_m^2 x}{\Delta H_m} \Delta T_m = \frac{R T_m^2 (MW) M}{1000 \Delta H_m} Parameters ---------- Tm : float Melting temperature of the solute [K] Hm : float Heat of melting at the melting temperature of the solute [J/mol] x : float, optional Mole fraction of the solute [-] M : float, optional Molality [mol/kg] MW: float, optional Molecular weight of the solvent [g/mol] Returns ------- dTm : float Freezing point depression [K] Notes ----- MW is the molecular weight of the solvent. M is the molality of the solute. Examples -------- From [1]_, matching example. >>> Tm_depression_eutectic(353.35, 19110, .02) 1.0864594900639515 References ---------- .. [1] Gmehling, Jurgen. Chemical Thermodynamics: For Process Simulation. Weinheim, Germany: Wiley-VCH, 2012. ''' if x: dTm = R*Tm**2*x/Hm elif M and MW: MW = MW/1000. #g/mol to kg/mol dTm = R*Tm**2*MW*M/Hm else: raise Exception('Either molality or mole fraction of the solute must be specified; MW of the solvent is required also if molality is provided') return dTm
def Yen_Woods_saturation(T, Tc, Vc, Zc): r'''Calculates saturation liquid volume, using the Yen and Woods [1]_ CSP method and a chemical's critical properties. The molar volume of a liquid is given by: .. math:: Vc/Vs = 1 + A(1-T_r)^{1/3} + B(1-T_r)^{2/3} + D(1-T_r)^{4/3} D = 0.93-B A = 17.4425 - 214.578Z_c + 989.625Z_c^2 - 1522.06Z_c^3 B = -3.28257 + 13.6377Z_c + 107.4844Z_c^2-384.211Z_c^3 \text{ if } Zc \le 0.26 B = 60.2091 - 402.063Z_c + 501.0 Z_c^2 + 641.0 Z_c^3 \text{ if } Zc \ge 0.26 Parameters ---------- T : float Temperature of fluid [K] Tc : float Critical temperature of fluid [K] Vc : float Critical volume of fluid [m^3/mol] Zc : float Critical compressibility of fluid, [-] Returns ------- Vs : float Saturation liquid volume, [m^3/mol] Notes ----- Original equation was in terms of density, but it is converted here. No example has been found, nor are there points in the article. However, it is believed correct. For compressed liquids with the Yen-Woods method, see the `YenWoods_compressed` function. Examples -------- >>> Yen_Woods_saturation(300, 647.14, 55.45E-6, 0.245) 1.7695330765295693e-05 References ---------- .. [1] Yen, Lewis C., and S. S. Woods. "A Generalized Equation for Computer Calculation of Liquid Densities." AIChE Journal 12, no. 1 (1966): 95-99. doi:10.1002/aic.690120119 ''' Tr = T/Tc A = 17.4425 - 214.578*Zc + 989.625*Zc**2 - 1522.06*Zc**3 if Zc <= 0.26: B = -3.28257 + 13.6377*Zc + 107.4844*Zc**2 - 384.211*Zc**3 else: B = 60.2091 - 402.063*Zc + 501.0*Zc**2 + 641.0*Zc**3 D = 0.93 - B Vm = Vc/(1 + A*(1-Tr)**(1/3.) + B*(1-Tr)**(2/3.) + D*(1-Tr)**(4/3.)) return Vm
def Rackett(T, Tc, Pc, Zc): r'''Calculates saturation liquid volume, using Rackett CSP method and critical properties. The molar volume of a liquid is given by: .. math:: V_s = \frac{RT_c}{P_c}{Z_c}^{[1+(1-{T/T_c})^{2/7} ]} Units are all currently in m^3/mol - this can be changed to kg/m^3 Parameters ---------- T : float Temperature of fluid [K] Tc : float Critical temperature of fluid [K] Pc : float Critical pressure of fluid [Pa] Zc : float Critical compressibility of fluid, [-] Returns ------- Vs : float Saturation liquid volume, [m^3/mol] Notes ----- Units are dependent on gas constant R, imported from scipy According to Reid et. al, underpredicts volume for compounds with Zc < 0.22 Examples -------- Propane, example from the API Handbook >>> Vm_to_rho(Rackett(272.03889, 369.83, 4248000.0, 0.2763), 44.09562) 531.3223212651092 References ---------- .. [1] Rackett, Harold G. "Equation of State for Saturated Liquids." Journal of Chemical & Engineering Data 15, no. 4 (1970): 514-517. doi:10.1021/je60047a012 ''' return R*Tc/Pc*Zc**(1 + (1 - T/Tc)**(2/7.))
def Yamada_Gunn(T, Tc, Pc, omega): r'''Calculates saturation liquid volume, using Yamada and Gunn CSP method and a chemical's critical properties and acentric factor. The molar volume of a liquid is given by: .. math:: V_s = \frac{RT_c}{P_c}{(0.29056-0.08775\omega)}^{[1+(1-{T/T_c})^{2/7}]} Units are in m^3/mol. Parameters ---------- T : float Temperature of fluid [K] Tc : float Critical temperature of fluid [K] Pc : float Critical pressure of fluid [Pa] omega : float Acentric factor for fluid, [-] Returns ------- Vs : float saturation liquid volume, [m^3/mol] Notes ----- This equation is an improvement on the Rackett equation. This is often presented as the Rackett equation. The acentric factor is used here, instead of the critical compressibility A variant using a reference fluid also exists Examples -------- >>> Yamada_Gunn(300, 647.14, 22048320.0, 0.245) 2.1882836429895796e-05 References ---------- .. [1] Gunn, R. D., and Tomoyoshi Yamada. "A Corresponding States Correlation of Saturated Liquid Volumes." AIChE Journal 17, no. 6 (1971): 1341-45. doi:10.1002/aic.690170613 .. [2] Yamada, Tomoyoshi, and Robert D. Gunn. "Saturated Liquid Molar Volumes. Rackett Equation." Journal of Chemical & Engineering Data 18, no. 2 (1973): 234-36. doi:10.1021/je60057a006 ''' return R*Tc/Pc*(0.29056 - 0.08775*omega)**(1 + (1 - T/Tc)**(2/7.))
def Townsend_Hales(T, Tc, Vc, omega): r'''Calculates saturation liquid density, using the Townsend and Hales CSP method as modified from the original Riedel equation. Uses chemical critical volume and temperature, as well as acentric factor The density of a liquid is given by: .. math:: Vs = V_c/\left(1+0.85(1-T_r)+(1.692+0.986\omega)(1-T_r)^{1/3}\right) Parameters ---------- T : float Temperature of fluid [K] Tc : float Critical temperature of fluid [K] Vc : float Critical volume of fluid [m^3/mol] omega : float Acentric factor for fluid, [-] Returns ------- Vs : float Saturation liquid volume, [m^3/mol] Notes ----- The requirement for critical volume and acentric factor requires all data. Examples -------- >>> Townsend_Hales(300, 647.14, 55.95E-6, 0.3449) 1.8007361992619923e-05 References ---------- .. [1] Hales, J. L, and R Townsend. "Liquid Densities from 293 to 490 K of Nine Aromatic Hydrocarbons." The Journal of Chemical Thermodynamics 4, no. 5 (1972): 763-72. doi:10.1016/0021-9614(72)90050-X ''' Tr = T/Tc return Vc/(1 + 0.85*(1-Tr) + (1.692 + 0.986*omega)*(1-Tr)**(1/3.))
def Bhirud_normal(T, Tc, Pc, omega): r'''Calculates saturation liquid density using the Bhirud [1]_ CSP method. Uses Critical temperature and pressure and acentric factor. The density of a liquid is given by: .. math:: &\ln \frac{P_c}{\rho RT} = \ln U^{(0)} + \omega\ln U^{(1)} &\ln U^{(0)} = 1.396 44 - 24.076T_r+ 102.615T_r^2 -255.719T_r^3+355.805T_r^4-256.671T_r^5 + 75.1088T_r^6 &\ln U^{(1)} = 13.4412 - 135.7437 T_r + 533.380T_r^2- 1091.453T_r^3+1231.43T_r^4 - 728.227T_r^5 + 176.737T_r^6 Parameters ---------- T : float Temperature of fluid [K] Tc : float Critical temperature of fluid [K] Pc : float Critical pressure of fluid [Pa] omega : float Acentric factor for fluid, [-] Returns ------- Vm : float Saturated liquid molar volume, [mol/m^3] Notes ----- Claimed inadequate by others. An interpolation table for ln U values are used from Tr = 0.98 - 1.000. Has terrible behavior at low reduced temperatures. Examples -------- Pentane >>> Bhirud_normal(280.0, 469.7, 33.7E5, 0.252) 0.00011249654029488583 References ---------- .. [1] Bhirud, Vasant L. "Saturated Liquid Densities of Normal Fluids." AIChE Journal 24, no. 6 (November 1, 1978): 1127-31. doi:10.1002/aic.690240630 ''' Tr = T/Tc if Tr <= 0.98: lnU0 = 1.39644 - 24.076*Tr + 102.615*Tr**2 - 255.719*Tr**3 \ + 355.805*Tr**4 - 256.671*Tr**5 + 75.1088*Tr**6 lnU1 = 13.4412 - 135.7437*Tr + 533.380*Tr**2-1091.453*Tr**3 \ + 1231.43*Tr**4 - 728.227*Tr**5 + 176.737*Tr**6 elif Tr > 1: raise Exception('Critical phase, correlation does not apply') else: lnU0 = Bhirud_normal_lnU0_interp(Tr) lnU1 = Bhirud_normal_lnU1_interp(Tr) Unonpolar = exp(lnU0 + omega*lnU1) Vm = Unonpolar*R*T/Pc return Vm
def COSTALD(T, Tc, Vc, omega): r'''Calculate saturation liquid density using the COSTALD CSP method. A popular and accurate estimation method. If possible, fit parameters are used; alternatively critical properties work well. The density of a liquid is given by: .. math:: V_s=V^*V^{(0)}[1-\omega_{SRK}V^{(\delta)}] V^{(0)}=1-1.52816(1-T_r)^{1/3}+1.43907(1-T_r)^{2/3} - 0.81446(1-T_r)+0.190454(1-T_r)^{4/3} V^{(\delta)}=\frac{-0.296123+0.386914T_r-0.0427258T_r^2-0.0480645T_r^3} {T_r-1.00001} Units are that of critical or fit constant volume. Parameters ---------- T : float Temperature of fluid [K] Tc : float Critical temperature of fluid [K] Vc : float Critical volume of fluid [m^3/mol]. This parameter is alternatively a fit parameter omega : float (ideally SRK) Acentric factor for fluid, [-] This parameter is alternatively a fit parameter. Returns ------- Vs : float Saturation liquid volume Notes ----- 196 constants are fit to this function in [1]_. Range: 0.25 < Tr < 0.95, often said to be to 1.0 This function has been checked with the API handbook example problem. Examples -------- Propane, from an example in the API Handbook >>> Vm_to_rho(COSTALD(272.03889, 369.83333, 0.20008161E-3, 0.1532), 44.097) 530.3009967969841 References ---------- .. [1] Hankinson, Risdon W., and George H. Thomson. "A New Correlation for Saturated Densities of Liquids and Their Mixtures." AIChE Journal 25, no. 4 (1979): 653-663. doi:10.1002/aic.690250412 ''' Tr = T/Tc V_delta = (-0.296123 + 0.386914*Tr - 0.0427258*Tr**2 - 0.0480645*Tr**3)/(Tr - 1.00001) V_0 = 1 - 1.52816*(1-Tr)**(1/3.) + 1.43907*(1-Tr)**(2/3.) \ - 0.81446*(1-Tr) + 0.190454*(1-Tr)**(4/3.) return Vc*V_0*(1-omega*V_delta)
def Campbell_Thodos(T, Tb, Tc, Pc, M, dipole=None, hydroxyl=False): r'''Calculate saturation liquid density using the Campbell-Thodos [1]_ CSP method. An old and uncommon estimation method. .. math:: V_s = \frac{RT_c}{P_c}{Z_{RA}}^{[1+(1-T_r)^{2/7}]} Z_{RA} = \alpha + \beta(1-T_r) \alpha = 0.3883-0.0179s s = T_{br} \frac{\ln P_c}{(1-T_{br})} \beta = 0.00318s-0.0211+0.625\Lambda^{1.35} \Lambda = \frac{P_c^{1/3}} { M^{1/2} T_c^{5/6}} For polar compounds: .. math:: \theta = P_c \mu^2/T_c^2 \alpha = 0.3883 - 0.0179s - 130540\theta^{2.41} \beta = 0.00318s - 0.0211 + 0.625\Lambda^{1.35} + 9.74\times 10^6 \theta^{3.38} Polar Combounds with hydroxyl groups (water, alcohols) .. math:: \alpha = \left[0.690T_{br} -0.3342 + \frac{5.79\times 10^{-10}} {T_{br}^{32.75}}\right] P_c^{0.145} \beta = 0.00318s - 0.0211 + 0.625 \Lambda^{1.35} + 5.90\Theta^{0.835} Parameters ---------- T : float Temperature of fluid [K] Tb : float Boiling temperature of the fluid [K] Tc : float Critical temperature of fluid [K] Pc : float Critical pressure of fluid [Pa] M : float Molecular weight of the fluid [g/mol] dipole : float, optional Dipole moment of the fluid [debye] hydroxyl : bool, optional Swith to use the hydroxyl variant for polar fluids Returns ------- Vs : float Saturation liquid volume Notes ----- If a dipole is provided, the polar chemical method is used. The paper is an excellent read. Pc is internally converted to atm. Examples -------- Ammonia, from [1]_. >>> Campbell_Thodos(T=405.45, Tb=239.82, Tc=405.45, Pc=111.7*101325, M=17.03, dipole=1.47) 7.347363635885525e-05 References ---------- .. [1] Campbell, Scott W., and George Thodos. "Prediction of Saturated Liquid Densities and Critical Volumes for Polar and Nonpolar Substances." Journal of Chemical & Engineering Data 30, no. 1 (January 1, 1985): 102-11. doi:10.1021/je00039a032. ''' Tr = T/Tc Tbr = Tb/Tc Pc = Pc/101325. s = Tbr * log(Pc)/(1-Tbr) Lambda = Pc**(1/3.)/(M**0.5*Tc**(5/6.)) alpha = 0.3883 - 0.0179*s beta = 0.00318*s - 0.0211 + 0.625*Lambda**(1.35) if dipole: theta = Pc*dipole**2/Tc**2 alpha -= 130540 * theta**2.41 beta += 9.74E6 * theta**3.38 if hydroxyl: beta = 0.00318*s - 0.0211 + 0.625*Lambda**(1.35) + 5.90*theta**0.835 alpha = (0.69*Tbr - 0.3342 + 5.79E-10/Tbr**32.75)*Pc**0.145 Zra = alpha + beta*(1-Tr) Vs = R*Tc/(Pc*101325)*Zra**(1+(1-Tr)**(2/7.)) return Vs
def SNM0(T, Tc, Vc, omega, delta_SRK=None): r'''Calculates saturated liquid density using the Mchaweh, Moshfeghian model [1]_. Designed for simple calculations. .. math:: V_s = V_c/(1+1.169\tau^{1/3}+1.818\tau^{2/3}-2.658\tau+2.161\tau^{4/3} \tau = 1-\frac{(T/T_c)}{\alpha_{SRK}} \alpha_{SRK} = [1 + m(1-\sqrt{T/T_C}]^2 m = 0.480+1.574\omega-0.176\omega^2 If the fit parameter `delta_SRK` is provided, the following is used: .. math:: V_s = V_C/(1+1.169\tau^{1/3}+1.818\tau^{2/3}-2.658\tau+2.161\tau^{4/3}) /\left[1+\delta_{SRK}(\alpha_{SRK}-1)^{1/3}\right] Parameters ---------- T : float Temperature of fluid [K] Tc : float Critical temperature of fluid [K] Vc : float Critical volume of fluid [m^3/mol] omega : float Acentric factor for fluid, [-] delta_SRK : float, optional Fitting parameter [-] Returns ------- Vs : float Saturation liquid volume, [m^3/mol] Notes ----- 73 fit parameters have been gathered from the article. Examples -------- Argon, without the fit parameter and with it. Tabulated result in Perry's is 3.4613e-05. The fit increases the error on this occasion. >>> SNM0(121, 150.8, 7.49e-05, -0.004) 3.4402256402733416e-05 >>> SNM0(121, 150.8, 7.49e-05, -0.004, -0.03259620) 3.493288100008123e-05 References ---------- .. [1] Mchaweh, A., A. Alsaygh, Kh. Nasrifar, and M. Moshfeghian. "A Simplified Method for Calculating Saturated Liquid Densities." Fluid Phase Equilibria 224, no. 2 (October 1, 2004): 157-67. doi:10.1016/j.fluid.2004.06.054 ''' Tr = T/Tc m = 0.480 + 1.574*omega - 0.176*omega*omega alpha_SRK = (1. + m*(1. - Tr**0.5))**2 tau = 1. - Tr/alpha_SRK rho0 = 1. + 1.169*tau**(1/3.) + 1.818*tau**(2/3.) - 2.658*tau + 2.161*tau**(4/3.) V0 = 1./rho0 if not delta_SRK: return Vc*V0 else: return Vc*V0/(1. + delta_SRK*(alpha_SRK - 1.)**(1/3.))
def COSTALD_compressed(T, P, Psat, Tc, Pc, omega, Vs): r'''Calculates compressed-liquid volume, using the COSTALD [1]_ CSP method and a chemical's critical properties. The molar volume of a liquid is given by: .. math:: V = V_s\left( 1 - C \ln \frac{B + P}{B + P^{sat}}\right) \frac{B}{P_c} = -1 + a\tau^{1/3} + b\tau^{2/3} + d\tau + e\tau^{4/3} e = \exp(f + g\omega_{SRK} + h \omega_{SRK}^2) C = j + k \omega_{SRK} Parameters ---------- T : float Temperature of fluid [K] P : float Pressure of fluid [Pa] Psat : float Saturation pressure of the fluid [Pa] Tc : float Critical temperature of fluid [K] Pc : float Critical pressure of fluid [Pa] omega : float (ideally SRK) Acentric factor for fluid, [-] This parameter is alternatively a fit parameter. Vs : float Saturation liquid volume, [m^3/mol] Returns ------- V_dense : float High-pressure liquid volume, [m^3/mol] Notes ----- Original equation was in terms of density, but it is converted here. The example is from DIPPR, and exactly correct. This is DIPPR Procedure 4C: Method for Estimating the Density of Pure Organic Liquids under Pressure. Examples -------- >>> COSTALD_compressed(303., 9.8E7, 85857.9, 466.7, 3640000.0, 0.281, 0.000105047) 9.287482879788506e-05 References ---------- .. [1] Thomson, G. H., K. R. Brobst, and R. W. Hankinson. "An Improved Correlation for Densities of Compressed Liquids and Liquid Mixtures." AIChE Journal 28, no. 4 (July 1, 1982): 671-76. doi:10.1002/aic.690280420 ''' a = -9.070217 b = 62.45326 d = -135.1102 f = 4.79594 g = 0.250047 h = 1.14188 j = 0.0861488 k = 0.0344483 tau = 1 - T/Tc e = exp(f + g*omega + h*omega**2) C = j + k*omega B = Pc*(-1 + a*tau**(1/3.) + b*tau**(2/3.) + d*tau + e*tau**(4/3.)) return Vs*(1 - C*log((B + P)/(B + Psat)))
def Amgat(xs, Vms): r'''Calculate mixture liquid density using the Amgat mixing rule. Highly inacurate, but easy to use. Assumes idea liquids with no excess volume. Average molecular weight should be used with it to obtain density. .. math:: V_{mix} = \sum_i x_i V_i or in terms of density: .. math:: \rho_{mix} = \sum\frac{x_i}{\rho_i} Parameters ---------- xs : array Mole fractions of each component, [] Vms : array Molar volumes of each fluids at conditions [m^3/mol] Returns ------- Vm : float Mixture liquid volume [m^3/mol] Notes ----- Units are that of the given volumes. It has been suggested to use this equation with weight fractions, but the results have been less accurate. Examples -------- >>> Amgat([0.5, 0.5], [4.057e-05, 5.861e-05]) 4.9590000000000005e-05 ''' if not none_and_length_check([xs, Vms]): raise Exception('Function inputs are incorrect format') return mixing_simple(xs, Vms)
def Rackett_mixture(T, xs, MWs, Tcs, Pcs, Zrs): r'''Calculate mixture liquid density using the Rackett-derived mixing rule as shown in [2]_. .. math:: V_m = \sum_i\frac{x_i T_{ci}}{MW_i P_{ci}} Z_{R,m}^{(1 + (1 - T_r)^{2/7})} R \sum_i x_i MW_i Parameters ---------- T : float Temperature of liquid [K] xs: list Mole fractions of each component, [] MWs : list Molecular weights of each component [g/mol] Tcs : list Critical temperatures of each component [K] Pcs : list Critical pressures of each component [Pa] Zrs : list Rackett parameters of each component [] Returns ------- Vm : float Mixture liquid volume [m^3/mol] Notes ----- Model for pure compounds in [1]_ forms the basis for this model, shown in [2]_. Molecular weights are used as weighing by such has been found to provide higher accuracy in [2]_. The model can also be used without molecular weights, but results are somewhat different. As with the Rackett model, critical compressibilities may be used if Rackett parameters have not been regressed. Critical mixture temperature, and compressibility are all obtained with simple mixing rules. Examples -------- Calculation in [2]_ for methanol and water mixture. Result matches example. >>> Rackett_mixture(T=298., xs=[0.4576, 0.5424], MWs=[32.04, 18.01], Tcs=[512.58, 647.29], Pcs=[8.096E6, 2.209E7], Zrs=[0.2332, 0.2374]) 2.625288603174508e-05 References ---------- .. [1] Rackett, Harold G. "Equation of State for Saturated Liquids." Journal of Chemical & Engineering Data 15, no. 4 (1970): 514-517. doi:10.1021/je60047a012 .. [2] Danner, Ronald P, and Design Institute for Physical Property Data. Manual for Predicting Chemical Process Design Data. New York, N.Y, 1982. ''' if not none_and_length_check([xs, MWs, Tcs, Pcs, Zrs]): raise Exception('Function inputs are incorrect format') Tc = mixing_simple(xs, Tcs) Zr = mixing_simple(xs, Zrs) MW = mixing_simple(xs, MWs) Tr = T/Tc bigsum = sum(xs[i]*Tcs[i]/Pcs[i]/MWs[i] for i in range(len(xs))) return (R*bigsum*Zr**(1. + (1. - Tr)**(2/7.)))*MW
def COSTALD_mixture(xs, T, Tcs, Vcs, omegas): r'''Calculate mixture liquid density using the COSTALD CSP method. A popular and accurate estimation method. If possible, fit parameters are used; alternatively critical properties work well. The mixing rules giving parameters for the pure component COSTALD equation are: .. math:: T_{cm} = \frac{\sum_i\sum_j x_i x_j (V_{ij}T_{cij})}{V_m} V_m = 0.25\left[ \sum x_i V_i + 3(\sum x_i V_i^{2/3})(\sum_i x_i V_i^{1/3})\right] V_{ij}T_{cij} = (V_iT_{ci}V_{j}T_{cj})^{0.5} \omega = \sum_i z_i \omega_i Parameters ---------- xs: list Mole fractions of each component T : float Temperature of fluid [K] Tcs : list Critical temperature of fluids [K] Vcs : list Critical volumes of fluids [m^3/mol]. This parameter is alternatively a fit parameter omegas : list (ideally SRK) Acentric factor of all fluids, [-] This parameter is alternatively a fit parameter. Returns ------- Vs : float Saturation liquid mixture volume Notes ----- Range: 0.25 < Tr < 0.95, often said to be to 1.0 No example has been found. Units are that of critical or fit constant volume. Examples -------- >>> COSTALD_mixture([0.4576, 0.5424], 298., [512.58, 647.29],[0.000117, 5.6e-05], [0.559,0.344] ) 2.706588773271354e-05 References ---------- .. [1] Hankinson, Risdon W., and George H. Thomson. "A New Correlation for Saturated Densities of Liquids and Their Mixtures." AIChE Journal 25, no. 4 (1979): 653-663. doi:10.1002/aic.690250412 ''' cmps = range(len(xs)) if not none_and_length_check([xs, Tcs, Vcs, omegas]): raise Exception('Function inputs are incorrect format') sum1 = sum([xi*Vci for xi, Vci in zip(xs, Vcs)]) sum2 = sum([xi*Vci**(2/3.) for xi, Vci in zip(xs, Vcs)]) sum3 = sum([xi*Vci**(1/3.) for xi, Vci in zip(xs, Vcs)]) Vm = 0.25*(sum1 + 3.*sum2*sum3) VijTcij = [[(Tcs[i]*Tcs[j]*Vcs[i]*Vcs[j])**0.5 for j in cmps] for i in cmps] omega = mixing_simple(xs, omegas) Tcm = sum([xs[i]*xs[j]*VijTcij[i][j]/Vm for j in cmps for i in cmps]) return COSTALD(T, Tcm, Vm, omega)
def load_all_methods(self): r'''Method which picks out coefficients for the specified chemical from the various dictionaries and DataFrames storing it. All data is stored as attributes. This method also sets :obj:`Tmin`, :obj:`Tmax`, :obj:`all_methods` and obj:`all_methods_P` as a set of methods for which the data exists for. Called on initialization only. See the source code for the variables at which the coefficients are stored. The coefficients can safely be altered once the class is initialized. This method can be called again to reset the parameters. ''' methods = [] methods_P = [] Tmins, Tmaxs = [], [] if has_CoolProp and self.CASRN in coolprop_dict: methods.append(COOLPROP); methods_P.append(COOLPROP) self.CP_f = coolprop_fluids[self.CASRN] Tmins.append(self.CP_f.Tt); Tmaxs.append(self.CP_f.Tc) if self.CASRN in CRC_inorg_l_data.index: methods.append(CRC_INORG_L) _, self.CRC_INORG_L_MW, self.CRC_INORG_L_rho, self.CRC_INORG_L_k, self.CRC_INORG_L_Tm, self.CRC_INORG_L_Tmax = _CRC_inorg_l_data_values[CRC_inorg_l_data.index.get_loc(self.CASRN)].tolist() Tmins.append(self.CRC_INORG_L_Tm); Tmaxs.append(self.CRC_INORG_L_Tmax) if self.CASRN in Perry_l_data.index: methods.append(PERRYDIPPR) _, C1, C2, C3, C4, self.DIPPR_Tmin, self.DIPPR_Tmax = _Perry_l_data_values[Perry_l_data.index.get_loc(self.CASRN)].tolist() self.DIPPR_coeffs = [C1, C2, C3, C4] Tmins.append(self.DIPPR_Tmin); Tmaxs.append(self.DIPPR_Tmax) if self.CASRN in VDI_PPDS_2.index: methods.append(VDI_PPDS) _, MW, Tc, rhoc, A, B, C, D = _VDI_PPDS_2_values[VDI_PPDS_2.index.get_loc(self.CASRN)].tolist() self.VDI_PPDS_coeffs = [A, B, C, D] self.VDI_PPDS_MW = MW self.VDI_PPDS_Tc = Tc self.VDI_PPDS_rhoc = rhoc Tmaxs.append(self.VDI_PPDS_Tc) if self.CASRN in _VDISaturationDict: methods.append(VDI_TABULAR) Ts, props = VDI_tabular_data(self.CASRN, 'Volume (l)') self.VDI_Tmin = Ts[0] self.VDI_Tmax = Ts[-1] self.tabular_data[VDI_TABULAR] = (Ts, props) Tmins.append(self.VDI_Tmin); Tmaxs.append(self.VDI_Tmax) if self.Tc and self.CASRN in COSTALD_data.index: methods.append(HTCOSTALDFIT) self.COSTALD_Vchar = float(COSTALD_data.at[self.CASRN, 'Vchar']) self.COSTALD_omega_SRK = float(COSTALD_data.at[self.CASRN, 'omega_SRK']) Tmins.append(0); Tmaxs.append(self.Tc) if self.Tc and self.Pc and self.CASRN in COSTALD_data.index and not np.isnan(COSTALD_data.at[self.CASRN, 'Z_RA']): methods.append(RACKETTFIT) self.RACKETT_Z_RA = float(COSTALD_data.at[self.CASRN, 'Z_RA']) Tmins.append(0); Tmaxs.append(self.Tc) if self.CASRN in CRC_inorg_l_const_data.index: methods.append(CRC_INORG_L_CONST) self.CRC_INORG_L_CONST_Vm = float(CRC_inorg_l_const_data.at[self.CASRN, 'Vm']) # Roughly data at STP; not guaranteed however; not used for Trange if all((self.Tc, self.Vc, self.Zc)): methods.append(YEN_WOODS_SAT) Tmins.append(0); Tmaxs.append(self.Tc) if all((self.Tc, self.Pc, self.Zc)): methods.append(RACKETT) Tmins.append(0); Tmaxs.append(self.Tc) if all((self.Tc, self.Pc, self.omega)): methods.append(YAMADA_GUNN) methods.append(BHIRUD_NORMAL) Tmins.append(0); Tmaxs.append(self.Tc) if all((self.Tc, self.Vc, self.omega)): methods.append(TOWNSEND_HALES) methods.append(HTCOSTALD) methods.append(MMSNM0) if self.CASRN in SNM0_data.index: methods.append(MMSNM0FIT) self.SNM0_delta_SRK = float(SNM0_data.at[self.CASRN, 'delta_SRK']) Tmins.append(0); Tmaxs.append(self.Tc) if all((self.Tc, self.Vc, self.omega, self.Tb, self.MW)): methods.append(CAMPBELL_THODOS) Tmins.append(0); Tmaxs.append(self.Tc) if all((self.Tc, self.Pc, self.omega)): methods_P.append(COSTALD_COMPRESSED) if self.eos: methods_P.append(EOS) if Tmins and Tmaxs: self.Tmin, self.Tmax = min(Tmins), max(Tmaxs) self.all_methods = set(methods) self.all_methods_P = set(methods_P)
def calculate(self, T, method): r'''Method to calculate low-pressure liquid molar volume at tempearture `T` with a given method. This method has no exception handling; see `T_dependent_property` for that. Parameters ---------- T : float Temperature at which to calculate molar volume, [K] method : str Name of the method to use Returns ------- Vm : float Molar volume of the liquid at T and a low pressure, [m^3/mol] ''' if method == RACKETT: Vm = Rackett(T, self.Tc, self.Pc, self.Zc) elif method == YAMADA_GUNN: Vm = Yamada_Gunn(T, self.Tc, self.Pc, self.omega) elif method == BHIRUD_NORMAL: Vm = Bhirud_normal(T, self.Tc, self.Pc, self.omega) elif method == TOWNSEND_HALES: Vm = Townsend_Hales(T, self.Tc, self.Vc, self.omega) elif method == HTCOSTALD: Vm = COSTALD(T, self.Tc, self.Vc, self.omega) elif method == YEN_WOODS_SAT: Vm = Yen_Woods_saturation(T, self.Tc, self.Vc, self.Zc) elif method == MMSNM0: Vm = SNM0(T, self.Tc, self.Vc, self.omega) elif method == MMSNM0FIT: Vm = SNM0(T, self.Tc, self.Vc, self.omega, self.SNM0_delta_SRK) elif method == CAMPBELL_THODOS: Vm = Campbell_Thodos(T, self.Tb, self.Tc, self.Pc, self.MW, self.dipole) elif method == HTCOSTALDFIT: Vm = COSTALD(T, self.Tc, self.COSTALD_Vchar, self.COSTALD_omega_SRK) elif method == RACKETTFIT: Vm = Rackett(T, self.Tc, self.Pc, self.RACKETT_Z_RA) elif method == PERRYDIPPR: A, B, C, D = self.DIPPR_coeffs Vm = 1./EQ105(T, A, B, C, D) elif method == CRC_INORG_L: rho = CRC_inorganic(T, self.CRC_INORG_L_rho, self.CRC_INORG_L_k, self.CRC_INORG_L_Tm) Vm = rho_to_Vm(rho, self.CRC_INORG_L_MW) elif method == VDI_PPDS: A, B, C, D = self.VDI_PPDS_coeffs tau = 1. - T/self.VDI_PPDS_Tc rho = self.VDI_PPDS_rhoc + A*tau**0.35 + B*tau**(2/3.) + C*tau + D*tau**(4/3.) Vm = rho_to_Vm(rho, self.VDI_PPDS_MW) elif method == CRC_INORG_L_CONST: Vm = self.CRC_INORG_L_CONST_Vm elif method == COOLPROP: Vm = 1./CoolProp_T_dependent_property(T, self.CASRN, 'DMOLAR', 'l') elif method in self.tabular_data: Vm = self.interpolate(T, method) return Vm
def calculate_P(self, T, P, method): r'''Method to calculate pressure-dependent liquid molar volume at temperature `T` and pressure `P` with a given method. This method has no exception handling; see `TP_dependent_property` for that. Parameters ---------- T : float Temperature at which to calculate molar volume, [K] P : float Pressure at which to calculate molar volume, [K] method : str Name of the method to use Returns ------- Vm : float Molar volume of the liquid at T and P, [m^3/mol] ''' if method == COSTALD_COMPRESSED: Vm = self.T_dependent_property(T) Psat = self.Psat(T) if hasattr(self.Psat, '__call__') else self.Psat Vm = COSTALD_compressed(T, P, Psat, self.Tc, self.Pc, self.omega, Vm) elif method == COOLPROP: Vm = 1./PropsSI('DMOLAR', 'T', T, 'P', P, self.CASRN) elif method == EOS: self.eos[0] = self.eos[0].to_TP(T=T, P=P) Vm = self.eos[0].V_l elif method in self.tabular_data: Vm = self.interpolate_P(T, P, method) return Vm
def load_all_methods(self): r'''Method to initialize the object by precomputing any values which may be used repeatedly and by retrieving mixture-specific variables. All data are stored as attributes. This method also sets :obj:`Tmin`, :obj:`Tmax`, and :obj:`all_methods` as a set of methods which should work to calculate the property. Called on initialization only. See the source code for the variables at which the coefficients are stored. The coefficients can safely be altered once the class is initialized. This method can be called again to reset the parameters. ''' methods = [SIMPLE] if none_and_length_check([self.Tcs, self.Vcs, self.omegas, self.CASs]): methods.append(COSTALD_MIXTURE) if all([i in COSTALD_data.index for i in self.CASs]): self.COSTALD_Vchars = [COSTALD_data.at[CAS, 'Vchar'] for CAS in self.CASs] self.COSTALD_omegas = [COSTALD_data.at[CAS, 'omega_SRK'] for CAS in self.CASs] methods.append(COSTALD_MIXTURE_FIT) if none_and_length_check([self.MWs, self.Tcs, self.Pcs, self.Zcs, self.CASs]): methods.append(RACKETT) if all([CAS in COSTALD_data.index for CAS in self.CASs]): Z_RAs = [COSTALD_data.at[CAS, 'Z_RA'] for CAS in self.CASs] if not any(np.isnan(Z_RAs)): self.Z_RAs = Z_RAs methods.append(RACKETT_PARAMETERS) if len(self.CASs) > 1 and '7732-18-5' in self.CASs: wCASs = [i for i in self.CASs if i != '7732-18-5'] if all([i in _Laliberte_Density_ParametersDict for i in wCASs]): methods.append(LALIBERTE) self.wCASs = wCASs self.index_w = self.CASs.index('7732-18-5') self.all_methods = set(methods)
def calculate(self, T, P, zs, ws, method): r'''Method to calculate molar volume of a liquid mixture at temperature `T`, pressure `P`, mole fractions `zs` and weight fractions `ws` with a given method. This method has no exception handling; see `mixture_property` for that. Parameters ---------- T : float Temperature at which to calculate the property, [K] P : float Pressure at which to calculate the property, [Pa] zs : list[float] Mole fractions of all species in the mixture, [-] ws : list[float] Weight fractions of all species in the mixture, [-] method : str Name of the method to use Returns ------- Vm : float Molar volume of the liquid mixture at the given conditions, [m^3/mol] ''' if method == SIMPLE: Vms = [i(T, P) for i in self.VolumeLiquids] return Amgat(zs, Vms) elif method == COSTALD_MIXTURE: return COSTALD_mixture(zs, T, self.Tcs, self.Vcs, self.omegas) elif method == COSTALD_MIXTURE_FIT: return COSTALD_mixture(zs, T, self.Tcs, self.COSTALD_Vchars, self.COSTALD_omegas) elif method == RACKETT: return Rackett_mixture(T, zs, self.MWs, self.Tcs, self.Pcs, self.Zcs) elif method == RACKETT_PARAMETERS: return Rackett_mixture(T, zs, self.MWs, self.Tcs, self.Pcs, self.Z_RAs) elif method == LALIBERTE: ws = list(ws) ; ws.pop(self.index_w) rho = Laliberte_density(T, ws, self.wCASs) MW = mixing_simple(zs, self.MWs) return rho_to_Vm(rho, MW) else: raise Exception('Method not valid')
def load_all_methods(self): r'''Method which picks out coefficients for the specified chemical from the various dictionaries and DataFrames storing it. All data is stored as attributes. This method also sets obj:`all_methods_P` as a set of methods for which the data exists for. Called on initialization only. See the source code for the variables at which the coefficients are stored. The coefficients can safely be altered once the class is initialized. This method can be called again to reset the parameters. ''' methods_P = [IDEAL] # no point in getting Tmin, Tmax if all((self.Tc, self.Pc, self.omega)): methods_P.extend([TSONOPOULOS_EXTENDED, TSONOPOULOS, ABBOTT, PITZER_CURL]) if self.eos: methods_P.append(EOS) if self.CASRN in CRC_virial_data.index: methods_P.append(CRC_VIRIAL) self.CRC_VIRIAL_coeffs = _CRC_virial_data_values[CRC_virial_data.index.get_loc(self.CASRN)].tolist()[1:] if has_CoolProp and self.CASRN in coolprop_dict: methods_P.append(COOLPROP) self.CP_f = coolprop_fluids[self.CASRN] self.all_methods_P = set(methods_P)
def calculate_P(self, T, P, method): r'''Method to calculate pressure-dependent gas molar volume at temperature `T` and pressure `P` with a given method. This method has no exception handling; see `TP_dependent_property` for that. Parameters ---------- T : float Temperature at which to calculate molar volume, [K] P : float Pressure at which to calculate molar volume, [K] method : str Name of the method to use Returns ------- Vm : float Molar volume of the gas at T and P, [m^3/mol] ''' if method == EOS: self.eos[0] = self.eos[0].to_TP(T=T, P=P) Vm = self.eos[0].V_g elif method == TSONOPOULOS_EXTENDED: B = BVirial_Tsonopoulos_extended(T, self.Tc, self.Pc, self.omega, dipole=self.dipole) Vm = ideal_gas(T, P) + B elif method == TSONOPOULOS: B = BVirial_Tsonopoulos(T, self.Tc, self.Pc, self.omega) Vm = ideal_gas(T, P) + B elif method == ABBOTT: B = BVirial_Abbott(T, self.Tc, self.Pc, self.omega) Vm = ideal_gas(T, P) + B elif method == PITZER_CURL: B = BVirial_Pitzer_Curl(T, self.Tc, self.Pc, self.omega) Vm = ideal_gas(T, P) + B elif method == CRC_VIRIAL: a1, a2, a3, a4, a5 = self.CRC_VIRIAL_coeffs t = 298.15/T - 1. B = (a1 + a2*t + a3*t**2 + a4*t**3 + a5*t**4)/1E6 Vm = ideal_gas(T, P) + B elif method == IDEAL: Vm = ideal_gas(T, P) elif method == COOLPROP: Vm = 1./PropsSI('DMOLAR', 'T', T, 'P', P, self.CASRN) elif method in self.tabular_data: Vm = self.interpolate_P(T, P, method) return Vm
def load_all_methods(self): r'''Method to initialize the object by precomputing any values which may be used repeatedly and by retrieving mixture-specific variables. All data are stored as attributes. This method also sets :obj:`Tmin`, :obj:`Tmax`, and :obj:`all_methods` as a set of methods which should work to calculate the property. Called on initialization only. See the source code for the variables at which the coefficients are stored. The coefficients can safely be altered once the class is initialized. This method can be called again to reset the parameters. ''' methods = [SIMPLE, IDEAL] if self.eos: methods.append(EOS) self.all_methods = set(methods)
def calculate(self, T, P, zs, ws, method): r'''Method to calculate molar volume of a gas mixture at temperature `T`, pressure `P`, mole fractions `zs` and weight fractions `ws` with a given method. This method has no exception handling; see `mixture_property` for that. Parameters ---------- T : float Temperature at which to calculate the property, [K] P : float Pressure at which to calculate the property, [Pa] zs : list[float] Mole fractions of all species in the mixture, [-] ws : list[float] Weight fractions of all species in the mixture, [-] method : str Name of the method to use Returns ------- Vm : float Molar volume of the gas mixture at the given conditions, [m^3/mol] ''' if method == SIMPLE: Vms = [i(T, P) for i in self.VolumeGases] return mixing_simple(zs, Vms) elif method == IDEAL: return ideal_gas(T, P) elif method == EOS: self.eos[0] = self.eos[0].to_TP_zs(T=T, P=P, zs=zs) return self.eos[0].V_g else: raise Exception('Method not valid')
def load_all_methods(self): r'''Method which picks out coefficients for the specified chemical from the various dictionaries and DataFrames storing it. All data is stored as attributes. This method also sets :obj:`Tmin`, :obj:`Tmax`, and :obj:`all_methods` as a set of methods for which the data exists for. Called on initialization only. See the source code for the variables at which the coefficients are stored. The coefficients can safely be altered once the class is initialized. This method can be called again to reset the parameters. ''' methods = [] if self.CASRN in CRC_inorg_s_const_data.index: methods.append(CRC_INORG_S) self.CRC_INORG_S_Vm = float(CRC_inorg_s_const_data.at[self.CASRN, 'Vm']) # if all((self.Tt, self.Vml_Tt, self.MW)): # self.rhol_Tt = Vm_to_rho(self.Vml_Tt, self.MW) # methods.append(GOODMAN) self.all_methods = set(methods)
def calculate(self, T, method): r'''Method to calculate the molar volume of a solid at tempearture `T` with a given method. This method has no exception handling; see `T_dependent_property` for that. Parameters ---------- T : float Temperature at which to calculate molar volume, [K] method : str Name of the method to use Returns ------- Vms : float Molar volume of the solid at T, [m^3/mol] ''' if method == CRC_INORG_S: Vms = self.CRC_INORG_S_Vm # elif method == GOODMAN: # Vms = Goodman(T, self.Tt, self.rhol_Tt) elif method in self.tabular_data: Vms = self.interpolate(T, method) return Vms
def calculate(self, T, P, zs, ws, method): r'''Method to calculate molar volume of a solid mixture at temperature `T`, pressure `P`, mole fractions `zs` and weight fractions `ws` with a given method. This method has no exception handling; see `mixture_property` for that. Parameters ---------- T : float Temperature at which to calculate the property, [K] P : float Pressure at which to calculate the property, [Pa] zs : list[float] Mole fractions of all species in the mixture, [-] ws : list[float] Weight fractions of all species in the mixture, [-] method : str Name of the method to use Returns ------- Vm : float Molar volume of the solid mixture at the given conditions, [m^3/mol] ''' if method == SIMPLE: Vms = [i(T, P) for i in self.VolumeSolids] return mixing_simple(zs, Vms) else: raise Exception('Method not valid')
def enthalpy_Cpg_Hvap(self): r'''Method to calculate the enthalpy of an ideal mixture (no pressure effects). This routine is based on "route A", where only the gas heat capacity and enthalpy of vaporization are used. The reference temperature is a property of the class; it defaults to 298.15 K. For a pure gas mixture: .. math:: H = \sum_i z_i \cdot \int_{T_{ref}}^T C_{p}^{ig}(T) dT For a pure liquid mixture: .. math:: H = \sum_i z_i \left( \int_{T_{ref}}^T C_{p}^{ig}(T) dT + H_{vap, i}(T) \right) For a vapor-liquid mixture: .. math:: H = \sum_i z_i \cdot \int_{T_{ref}}^T C_{p}^{ig}(T) dT + \sum_i x_i\left(1 - \frac{V}{F}\right)H_{vap, i}(T) Returns ------- H : float Enthalpy of the mixture with respect to the reference temperature, [J/mol] Notes ----- The object must be flashed before this routine can be used. It depends on the properties T, zs, xs, V_over_F, HeatCapacityGases, EnthalpyVaporizations, and. ''' H = 0 T = self.T if self.phase == 'g': for i in self.cmps: H += self.zs[i]*self.HeatCapacityGases[i].T_dependent_property_integral(self.T_REF_IG, T) elif self.phase == 'l': for i in self.cmps: # No further contribution needed Hg298_to_T = self.HeatCapacityGases[i].T_dependent_property_integral(self.T_REF_IG, T) Hvap = self.EnthalpyVaporizations[i](T) # Do the transition at the temperature of the liquid if Hvap is None: Hvap = 0 # Handle the case of a package predicting a transition past the Tc H += self.zs[i]*(Hg298_to_T - Hvap) elif self.phase == 'l/g': for i in self.cmps: Hg298_to_T_zi = self.zs[i]*self.HeatCapacityGases[i].T_dependent_property_integral(self.T_REF_IG, T) Hvap = self.EnthalpyVaporizations[i](T) if Hvap is None: Hvap = 0 # Handle the case of a package predicting a transition past the Tc Hvap_contrib = -self.xs[i]*(1-self.V_over_F)*Hvap H += (Hg298_to_T_zi + Hvap_contrib) return H
def entropy_Cpg_Hvap(self): r'''Method to calculate the entropy of an ideal mixture. This routine is based on "route A", where only the gas heat capacity and enthalpy of vaporization are used. The reference temperature and pressure are properties of the class; it defaults to 298.15 K and 101325 Pa. There is a contribution due to mixing: .. math:: \Delta S_{mixing} = -R\sum_i z_i \log(z_i) The ideal gas pressure contribution is: .. math:: \Delta S_{P} = -R\log\left(\frac{P}{P_{ref}}\right) For a liquid mixture or a partially liquid mixture, the entropy contribution is not so strong - all such pressure effects find that expression capped at the vapor pressure, as shown in [1]_. .. math:: \Delta S_{P} = - \sum_i x_i\left(1 - \frac{V}{F}\right) R\log\left(\frac{P_{sat, i}}{P_{ref}}\right) - \sum_i y_i\left( \frac{V}{F}\right) R\log\left(\frac{P}{P_{ref}}\right) These expressions are combined with the standard heat capacity and enthalpy of vaporization expressions to calculate the total entropy: For a pure gas mixture: .. math:: S = \Delta S_{mixing} + \Delta S_{P} + \sum_i z_i \cdot \int_{T_{ref}}^T \frac{C_{p}^{ig}(T)}{T} dT For a pure liquid mixture: .. math:: S = \Delta S_{mixing} + \Delta S_{P} + \sum_i z_i \left( \int_{T_{ref}}^T \frac{C_{p}^{ig}(T)}{T} dT + \frac{H_{vap, i} (T)}{T} \right) For a vapor-liquid mixture: .. math:: S = \Delta S_{mixing} + \Delta S_{P} + \sum_i z_i \cdot \int_{T_{ref}}^T \frac{C_{p}^{ig}(T)}{T} dT + \sum_i x_i\left(1 - \frac{V}{F}\right)\frac{H_{vap, i}(T)}{T} Returns ------- S : float Entropy of the mixture with respect to the reference temperature, [J/mol/K] Notes ----- The object must be flashed before this routine can be used. It depends on the properties T, P, zs, V_over_F, HeatCapacityGases, EnthalpyVaporizations, VaporPressures, and xs. References ---------- .. [1] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000. ''' S = 0 T = self.T P = self.P S -= R*sum([zi*log(zi) for zi in self.zs if zi > 0]) # ideal composition entropy composition; chemsep checked # Both of the mixing and vapor pressure terms have negative signs # Equation 6-4.4b in Poling for the vapor pressure component # For liquids above their critical temperatures, Psat is equal to the system P (COCO). if self.phase == 'g': S -= R*log(P/101325.) # Gas-phase ideal pressure contribution (checked repeatedly) for i in self.cmps: S += self.HeatCapacityGases[i].T_dependent_property_integral_over_T(298.15, T) elif self.phase == 'l': Psats = self._Psats(T) for i in self.cmps: Sg298_to_T = self.HeatCapacityGases[i].T_dependent_property_integral_over_T(298.15, T) Hvap = self.EnthalpyVaporizations[i](T) if Hvap is None: Hvap = 0 # Handle the case of a package predicting a transition past the Tc Svap = -Hvap/T # Do the transition at the temperature of the liquid S_P = -R*log(Psats[i]/101325.) S += self.zs[i]*(Sg298_to_T + Svap + S_P) elif self.phase == 'l/g': Psats = self._Psats(T) S_P_vapor = -R*log(P/101325.) # Gas-phase ideal pressure contribution (checked repeatedly) for i in self.cmps: Sg298_to_T_zi = self.zs[i]*self.HeatCapacityGases[i].T_dependent_property_integral_over_T(298.15, T) Hvap = self.EnthalpyVaporizations[i](T) if Hvap is None: Hvap = 0 # Handle the case of a package predicting a transition past the Tc Svap_contrib = -self.xs[i]*(1-self.V_over_F)*Hvap/T # Pressure contributions from both phases S_P_vapor_i = self.V_over_F*self.ys[i]*S_P_vapor S_P_liquid_i = -R*log(Psats[i]/101325.)*(1-self.V_over_F)*self.xs[i] S += (Sg298_to_T_zi + Svap_contrib + S_P_vapor_i + S_P_liquid_i) return S
def legal_status(CASRN, Method=None, AvailableMethods=False, CASi=None): r'''Looks up the legal status of a chemical according to either a specifc method or with all methods. Returns either the status as a string for a specified method, or the status of the chemical in all available data sources, in the format {source: status}. Parameters ---------- CASRN : string CASRN [-] Returns ------- status : str or dict Legal status information [-] methods : list, only returned if AvailableMethods == True List of methods which can be used to obtain legal status with the given inputs Other Parameters ---------------- Method : string, optional A string for the method name to use, as defined by constants in legal_status_methods AvailableMethods : bool, optional If True, function will determine which methods can be used to obtain the legal status for the desired chemical, and will return methods instead of the status CASi : int, optional CASRN as an integer, used internally [-] Notes ----- Supported methods are: * **DSL**: Canada Domestic Substance List, [1]_. As extracted on Feb 11, 2015 from a html list. This list is updated continuously, so this version will always be somewhat old. Strictly speaking, there are multiple lists but they are all bundled together here. A chemical may be 'Listed', or be on the 'Non-Domestic Substances List (NDSL)', or be on the list of substances with 'Significant New Activity (SNAc)', or be on the DSL but with a 'Ministerial Condition pertaining to this substance', or have been removed from the DSL, or have had a Ministerial prohibition for the substance. * **TSCA**: USA EPA Toxic Substances Control Act Chemical Inventory, [2]_. This list is as extracted on 2016-01. It is believed this list is updated on a periodic basis (> 6 month). A chemical may simply be 'Listed', or may have certain flags attached to it. All these flags are described in the dict TSCA_flags. * **EINECS**: European INventory of Existing Commercial chemical Substances, [3]_. As extracted from a spreadsheet dynamically generated at [1]_. This list was obtained March 2015; a more recent revision already exists. * **NLP**: No Longer Polymers, a list of chemicals with special regulatory exemptions in EINECS. Also described at [3]_. * **SPIN**: Substances Prepared in Nordic Countries. Also a boolean data type. Retrieved 2015-03 from [4]_. Other methods which could be added are: * Australia: AICS Australian Inventory of Chemical Substances * China: Inventory of Existing Chemical Substances Produced or Imported in China (IECSC) * Europe: REACH List of Registered Substances * India: List of Hazardous Chemicals * Japan: ENCS: Inventory of existing and new chemical substances * Korea: Existing Chemicals Inventory (KECI) * Mexico: INSQ National Inventory of Chemical Substances in Mexico * New Zealand: Inventory of Chemicals (NZIoC) * Philippines: PICCS Philippines Inventory of Chemicals and Chemical Substances Examples -------- >>> pprint(legal_status('64-17-5')) {'DSL': 'LISTED', 'EINECS': 'LISTED', 'NLP': 'UNLISTED', 'SPIN': 'LISTED', 'TSCA': 'LISTED'} References ---------- .. [1] Government of Canada.. "Substances Lists" Feb 11, 2015. https://www.ec.gc.ca/subsnouvelles-newsubs/default.asp?n=47F768FE-1. .. [2] US EPA. "TSCA Chemical Substance Inventory." Accessed April 2016. https://www.epa.gov/tsca-inventory. .. [3] ECHA. "EC Inventory". Accessed March 2015. http://echa.europa.eu/information-on-chemicals/ec-inventory. .. [4] SPIN. "SPIN Substances in Products In Nordic Countries." Accessed March 2015. http://195.215.202.233/DotNetNuke/default.aspx. ''' load_law_data() if not CASi: CASi = CAS2int(CASRN) methods = [COMBINED, DSL, TSCA, EINECS, NLP, SPIN] if AvailableMethods: return methods if not Method: Method = methods[0] if Method == DSL: if CASi in DSL_data.index: status = CAN_DSL_flags[DSL_data.at[CASi, 'Registry']] else: status = UNLISTED elif Method == TSCA: if CASi in TSCA_data.index: data = TSCA_data.loc[CASi].to_dict() if any(data.values()): status = sorted([TSCA_flags[i] for i in data.keys() if data[i]]) else: status = LISTED else: status = UNLISTED elif Method == EINECS: if CASi in EINECS_data.index: status = LISTED else: status = UNLISTED elif Method == NLP: if CASi in NLP_data.index: status = LISTED else: status = UNLISTED elif Method == SPIN: if CASi in SPIN_data.index: status = LISTED else: status = UNLISTED elif Method == COMBINED: status = {} for method in methods[1:]: status[method] = legal_status(CASRN, Method=method, CASi=CASi) else: raise Exception('Failure in in function') return status
def load_economic_data(): global HPV_data if HPV_data is not None: return None global _EPACDRDict, _ECHATonnageDict '''OECD are chemicals produced by and OECD members in > 1000 tonnes/year.''' HPV_data = pd.read_csv(os.path.join(folder, 'HPV 2015 March 3.csv'), sep='\t', index_col=0) # 13061-29-2 not valid and removed _ECHATonnageDict = {} with zipfile.ZipFile(os.path.join(folder, 'ECHA Tonnage Bands.csv.zip')) as z: with z.open(z.namelist()[0]) as f: for line in f.readlines(): # for some reason, the file must be decoded to UTF8 first CAS, band = line.decode("utf-8").strip('\n').split('\t') if CAS in _ECHATonnageDict: if band in _ECHATonnageDict[CAS]: pass else: _ECHATonnageDict[CAS].append(band) else: _ECHATonnageDict[CAS] = [band] _EPACDRDict = {} with open(os.path.join(folder, 'EPA 2012 Chemical Data Reporting.csv')) as f: '''EPA summed reported chemical usages. In metric tonnes/year after conversion. Many producers keep their date confidential. This was originally in terms of lb/year, but rounded to the nearest kg. ''' next(f) for line in f: values = line.rstrip().split('\t') CAS, manufactured, imported, exported = to_num(values) _EPACDRDict[CAS] = {"Manufactured": manufactured/1000., "Imported": imported/1000., "Exported": exported/1000.}
def economic_status(CASRN, Method=None, AvailableMethods=False): # pragma: no cover '''Look up the economic status of a chemical. This API is considered experimental, and is expected to be removed in a future release in favor of a more complete object-oriented interface. >>> pprint(economic_status(CASRN='98-00-0')) ["US public: {'Manufactured': 0.0, 'Imported': 10272.711, 'Exported': 184.127}", u'10,000 - 100,000 tonnes per annum', 'OECD HPV Chemicals'] >>> economic_status(CASRN='13775-50-3') # SODIUM SESQUISULPHATE [] >>> economic_status(CASRN='98-00-0', Method='OECD high production volume chemicals') 'OECD HPV Chemicals' >>> economic_status(CASRN='98-01-1', Method='European Chemicals Agency Total Tonnage Bands') [u'10,000 - 100,000 tonnes per annum'] ''' load_economic_data() CASi = CAS2int(CASRN) def list_methods(): methods = [] methods.append('Combined') if CASRN in _EPACDRDict: methods.append(EPACDR) if CASRN in _ECHATonnageDict: methods.append(ECHA) if CASi in HPV_data.index: methods.append(OECD) methods.append(NONE) return methods if AvailableMethods: return list_methods() if not Method: Method = list_methods()[0] # This is the calculate, given the method section if Method == EPACDR: status = 'US public: ' + str(_EPACDRDict[CASRN]) elif Method == ECHA: status = _ECHATonnageDict[CASRN] elif Method == OECD: status = 'OECD HPV Chemicals' elif Method == 'Combined': status = [] if CASRN in _EPACDRDict: status += ['US public: ' + str(_EPACDRDict[CASRN])] if CASRN in _ECHATonnageDict: status += _ECHATonnageDict[CASRN] if CASi in HPV_data.index: status += ['OECD HPV Chemicals'] elif Method == NONE: status = None else: raise Exception('Failure in in function') return status
def BVirial_Pitzer_Curl(T, Tc, Pc, omega, order=0): r'''Calculates the second virial coefficient using the model in [1]_. Designed for simple calculations. .. math:: B_r=B^{(0)}+\omega B^{(1)} B^{(0)}=0.1445-0.33/T_r-0.1385/T_r^2-0.0121/T_r^3 B^{(1)} = 0.073+0.46/T_r-0.5/T_r^2 -0.097/T_r^3 - 0.0073/T_r^8 Parameters ---------- T : float Temperature of fluid [K] Tc : float Critical temperature of fluid [K] Pc : float Critical pressure of the fluid [Pa] omega : float Acentric factor for fluid, [-] order : int, optional Order of the calculation. 0 for the calculation of B itself; for 1/2/3, the first/second/third derivative of B with respect to temperature; and for -1/-2, the first/second indefinite integral of B with respect to temperature. No other integrals or derivatives are implemented, and an exception will be raised if any other order is given. Returns ------- B : float Second virial coefficient in density form or its integral/derivative if specified, [m^3/mol or m^3/mol/K^order] Notes ----- Analytical models for derivatives and integrals are available for orders -2, -1, 1, 2, and 3, all obtained with SymPy. For first temperature derivative of B: .. math:: \frac{d B^{(0)}}{dT} = \frac{33 Tc}{100 T^{2}} + \frac{277 Tc^{2}}{1000 T^{3}} + \frac{363 Tc^{3}}{10000 T^{4}} \frac{d B^{(1)}}{dT} = - \frac{23 Tc}{50 T^{2}} + \frac{Tc^{2}}{T^{3}} + \frac{291 Tc^{3}}{1000 T^{4}} + \frac{73 Tc^{8}}{1250 T^{9}} For the second temperature derivative of B: .. math:: \frac{d^2 B^{(0)}}{dT^2} = - \frac{3 Tc}{5000 T^{3}} \left(1100 + \frac{1385 Tc}{T} + \frac{242 Tc^{2}}{T^{2}}\right) \frac{d^2 B^{(1)}}{dT^2} = \frac{Tc}{T^{3}} \left(\frac{23}{25} - \frac{3 Tc}{T} - \frac{291 Tc^{2}}{250 T^{2}} - \frac{657 Tc^{7}}{1250 T^{7}}\right) For the third temperature derivative of B: .. math:: \frac{d^3 B^{(0)}}{dT^3} = \frac{3 Tc}{500 T^{4}} \left(330 + \frac{554 Tc}{T} + \frac{121 Tc^{2}}{T^{2}}\right) \frac{d^3 B^{(1)}}{dT^3} = \frac{3 Tc}{T^{4}} \left(- \frac{23}{25} + \frac{4 Tc}{T} + \frac{97 Tc^{2}}{50 T^{2}} + \frac{219 Tc^{7}}{125 T^{7}}\right) For the first indefinite integral of B: .. math:: \int{B^{(0)}} dT = \frac{289 T}{2000} - \frac{33 Tc}{100} \log{\left (T \right )} + \frac{1}{20000 T^{2}} \left(2770 T Tc^{2} + 121 Tc^{3}\right) \int{B^{(1)}} dT = \frac{73 T}{1000} + \frac{23 Tc}{50} \log{\left (T \right )} + \frac{1}{70000 T^{7}} \left(35000 T^{6} Tc^{2} + 3395 T^{5} Tc^{3} + 73 Tc^{8}\right) For the second indefinite integral of B: .. math:: \int\int B^{(0)} dT dT = \frac{289 T^{2}}{4000} - \frac{33 T}{100} Tc \log{\left (T \right )} + \frac{33 T}{100} Tc + \frac{277 Tc^{2}}{2000} \log{\left (T \right )} - \frac{121 Tc^{3}}{20000 T} \int\int B^{(1)} dT dT = \frac{73 T^{2}}{2000} + \frac{23 T}{50} Tc \log{\left (T \right )} - \frac{23 T}{50} Tc + \frac{Tc^{2}}{2} \log{\left (T \right )} - \frac{1}{420000 T^{6}} \left(20370 T^{5} Tc^{3} + 73 Tc^{8}\right) Examples -------- Example matching that in BVirial_Abbott, for isobutane. >>> BVirial_Pitzer_Curl(510., 425.2, 38E5, 0.193) -0.0002084535541385102 References ---------- .. [1] Pitzer, Kenneth S., and R. F. Curl. "The Volumetric and Thermodynamic Properties of Fluids. III. Empirical Equation for the Second Virial Coefficient1." Journal of the American Chemical Society 79, no. 10 (May 1, 1957): 2369-70. doi:10.1021/ja01567a007. ''' Tr = T/Tc if order == 0: B0 = 0.1445 - 0.33/Tr - 0.1385/Tr**2 - 0.0121/Tr**3 B1 = 0.073 + 0.46/Tr - 0.5/Tr**2 - 0.097/Tr**3 - 0.0073/Tr**8 elif order == 1: B0 = Tc*(3300*T**2 + 2770*T*Tc + 363*Tc**2)/(10000*T**4) B1 = Tc*(-2300*T**7 + 5000*T**6*Tc + 1455*T**5*Tc**2 + 292*Tc**7)/(5000*T**9) elif order == 2: B0 = -3*Tc*(1100*T**2 + 1385*T*Tc + 242*Tc**2)/(5000*T**5) B1 = Tc*(1150*T**7 - 3750*T**6*Tc - 1455*T**5*Tc**2 - 657*Tc**7)/(1250*T**10) elif order == 3: B0 = 3*Tc*(330*T**2 + 554*T*Tc + 121*Tc**2)/(500*T**6) B1 = 3*Tc*(-230*T**7 + 1000*T**6*Tc + 485*T**5*Tc**2 + 438*Tc**7)/(250*T**11) elif order == -1: B0 = 289*T/2000 - 33*Tc*log(T)/100 + (2770*T*Tc**2 + 121*Tc**3)/(20000*T**2) B1 = 73*T/1000 + 23*Tc*log(T)/50 + (35000*T**6*Tc**2 + 3395*T**5*Tc**3 + 73*Tc**8)/(70000*T**7) elif order == -2: B0 = 289*T**2/4000 - 33*T*Tc*log(T)/100 + 33*T*Tc/100 + 277*Tc**2*log(T)/2000 - 121*Tc**3/(20000*T) B1 = 73*T**2/2000 + 23*T*Tc*log(T)/50 - 23*T*Tc/50 + Tc**2*log(T)/2 - (20370*T**5*Tc**3 + 73*Tc**8)/(420000*T**6) else: raise Exception('Only orders -2, -1, 0, 1, 2 and 3 are supported.') Br = B0 + omega*B1 return Br*R*Tc/Pc
def BVirial_Abbott(T, Tc, Pc, omega, order=0): r'''Calculates the second virial coefficient using the model in [1]_. Simple fit to the Lee-Kesler equation. .. math:: B_r=B^{(0)}+\omega B^{(1)} B^{(0)}=0.083+\frac{0.422}{T_r^{1.6}} B^{(1)}=0.139-\frac{0.172}{T_r^{4.2}} Parameters ---------- T : float Temperature of fluid [K] Tc : float Critical temperature of fluid [K] Pc : float Critical pressure of the fluid [Pa] omega : float Acentric factor for fluid, [-] order : int, optional Order of the calculation. 0 for the calculation of B itself; for 1/2/3, the first/second/third derivative of B with respect to temperature; and for -1/-2, the first/second indefinite integral of B with respect to temperature. No other integrals or derivatives are implemented, and an exception will be raised if any other order is given. Returns ------- B : float Second virial coefficient in density form or its integral/derivative if specified, [m^3/mol or m^3/mol/K^order] Notes ----- Analytical models for derivatives and integrals are available for orders -2, -1, 1, 2, and 3, all obtained with SymPy. For first temperature derivative of B: .. math:: \frac{d B^{(0)}}{dT} = \frac{0.6752}{T \left(\frac{T}{Tc}\right)^{1.6}} \frac{d B^{(1)}}{dT} = \frac{0.7224}{T \left(\frac{T}{Tc}\right)^{4.2}} For the second temperature derivative of B: .. math:: \frac{d^2 B^{(0)}}{dT^2} = - \frac{1.75552}{T^{2} \left(\frac{T}{Tc}\right)^{1.6}} \frac{d^2 B^{(1)}}{dT^2} = - \frac{3.75648}{T^{2} \left(\frac{T}{Tc}\right)^{4.2}} For the third temperature derivative of B: .. math:: \frac{d^3 B^{(0)}}{dT^3} = \frac{6.319872}{T^{3} \left(\frac{T}{Tc}\right)^{1.6}} \frac{d^3 B^{(1)}}{dT^3} = \frac{23.290176}{T^{3} \left(\frac{T}{Tc}\right)^{4.2}} For the first indefinite integral of B: .. math:: \int{B^{(0)}} dT = 0.083 T + \frac{\frac{211}{300} Tc}{\left(\frac{T}{Tc}\right)^{0.6}} \int{B^{(1)}} dT = 0.139 T + \frac{0.05375 Tc}{\left(\frac{T}{Tc}\right)^{3.2}} For the second indefinite integral of B: .. math:: \int\int B^{(0)} dT dT = 0.0415 T^{2} + \frac{211}{120} Tc^{2} \left(\frac{T}{Tc}\right)^{0.4} \int\int B^{(1)} dT dT = 0.0695 T^{2} - \frac{\frac{43}{1760} Tc^{2}}{\left(\frac{T}{Tc}\right)^{2.2}} Examples -------- Example is from [1]_, p. 93, and matches the result exactly, for isobutane. >>> BVirial_Abbott(510., 425.2, 38E5, 0.193) -0.00020570178037383633 References ---------- .. [1] Smith, H. C. Van Ness Joseph M. Introduction to Chemical Engineering Thermodynamics 4E 1987. ''' Tr = T/Tc if order == 0: B0 = 0.083 - 0.422/Tr**1.6 B1 = 0.139 - 0.172/Tr**4.2 elif order == 1: B0 = 0.6752*Tr**(-1.6)/T B1 = 0.7224*Tr**(-4.2)/T elif order == 2: B0 = -1.75552*Tr**(-1.6)/T**2 B1 = -3.75648*Tr**(-4.2)/T**2 elif order == 3: B0 = 6.319872*Tr**(-1.6)/T**3 B1 = 23.290176*Tr**(-4.2)/T**3 elif order == -1: B0 = 0.083*T + 211/300.*Tc*(Tr)**(-0.6) B1 = 0.139*T + 0.05375*Tc*Tr**(-3.2) elif order == -2: B0 = 0.0415*T**2 + 211/120.*Tc**2*Tr**0.4 B1 = 0.0695*T**2 - 43/1760.*Tc**2*Tr**(-2.2) else: raise Exception('Only orders -2, -1, 0, 1, 2 and 3 are supported.') Br = B0 + omega*B1 return Br*R*Tc/Pc
def BVirial_Tsonopoulos_extended(T, Tc, Pc, omega, a=0, b=0, species_type='', dipole=0, order=0): r'''Calculates the second virial coefficient using the comprehensive model in [1]_. See the notes for the calculation of `a` and `b`. .. math:: \frac{BP_c}{RT_c} = B^{(0)} + \omega B^{(1)} + a B^{(2)} + b B^{(3)} B^{(0)}=0.1445-0.33/T_r-0.1385/T_r^2-0.0121/T_r^3 B^{(1)} = 0.0637+0.331/T_r^2-0.423/T_r^3 -0.423/T_r^3 - 0.008/T_r^8 B^{(2)} = 1/T_r^6 B^{(3)} = -1/T_r^8 Parameters ---------- T : float Temperature of fluid [K] Tc : float Critical temperature of fluid [K] Pc : float Critical pressure of the fluid [Pa] omega : float Acentric factor for fluid, [-] a : float, optional Fit parameter, calculated based on species_type if a is not given and species_type matches on of the supported chemical classes. b : float, optional Fit parameter, calculated based on species_type if a is not given and species_type matches on of the supported chemical classes. species_type : str, optional One of . dipole : float dipole moment, optional, [Debye] order : int, optional Order of the calculation. 0 for the calculation of B itself; for 1/2/3, the first/second/third derivative of B with respect to temperature; and for -1/-2, the first/second indefinite integral of B with respect to temperature. No other integrals or derivatives are implemented, and an exception will be raised if any other order is given. Returns ------- B : float Second virial coefficient in density form or its integral/derivative if specified, [m^3/mol or m^3/mol/K^order] Notes ----- Analytical models for derivatives and integrals are available for orders -2, -1, 1, 2, and 3, all obtained with SymPy. To calculate `a` or `b`, the following rules are used: For 'simple' or 'normal' fluids: .. math:: a = 0 b = 0 For 'ketone', 'aldehyde', 'alkyl nitrile', 'ether', 'carboxylic acid', or 'ester' types of chemicals: .. math:: a = -2.14\times 10^{-4} \mu_r - 4.308 \times 10^{-21} (\mu_r)^8 b = 0 For 'alkyl halide', 'mercaptan', 'sulfide', or 'disulfide' types of chemicals: .. math:: a = -2.188\times 10^{-4} (\mu_r)^4 - 7.831 \times 10^{-21} (\mu_r)^8 b = 0 For 'alkanol' types of chemicals (except methanol): .. math:: a = 0.0878 b = 0.00908 + 0.0006957 \mu_r For methanol: .. math:: a = 0.0878 b = 0.0525 For water: .. math:: a = -0.0109 b = 0 If required, the form of dipole moment used in the calculation of some types of `a` and `b` values is as follows: .. math:: \mu_r = 100000\frac{\mu^2(Pc/101325.0)}{Tc^2} For first temperature derivative of B: .. math:: \frac{d B^{(0)}}{dT} = \frac{33 Tc}{100 T^{2}} + \frac{277 Tc^{2}}{1000 T^{3}} + \frac{363 Tc^{3}}{10000 T^{4}} + \frac{607 Tc^{8}}{125000 T^{9}} \frac{d B^{(1)}}{dT} = - \frac{331 Tc^{2}}{500 T^{3}} + \frac{1269 Tc^{3}}{1000 T^{4}} + \frac{8 Tc^{8}}{125 T^{9}} \frac{d B^{(2)}}{dT} = - \frac{6 Tc^{6}}{T^{7}} \frac{d B^{(3)}}{dT} = \frac{8 Tc^{8}}{T^{9}} For the second temperature derivative of B: .. math:: \frac{d^2 B^{(0)}}{dT^2} = - \frac{3 Tc}{125000 T^{3}} \left(27500 + \frac{34625 Tc}{T} + \frac{6050 Tc^{2}}{T^{2}} + \frac{1821 Tc^{7}}{T^{7}}\right) \frac{d^2 B^{(1)}}{dT^2} = \frac{3 Tc^{2}}{500 T^{4}} \left(331 - \frac{846 Tc}{T} - \frac{96 Tc^{6}}{T^{6}}\right) \frac{d^2 B^{(2)}}{dT^2} = \frac{42 Tc^{6}}{T^{8}} \frac{d^2 B^{(3)}}{dT^2} = - \frac{72 Tc^{8}}{T^{10}} For the third temperature derivative of B: .. math:: \frac{d^3 B^{(0)}}{dT^3} = \frac{3 Tc}{12500 T^{4}} \left(8250 + \frac{13850 Tc}{T} + \frac{3025 Tc^{2}}{T^{2}} + \frac{1821 Tc^{7}}{T^{7}}\right) \frac{d^3 B^{(1)}}{dT^3} = \frac{3 Tc^{2}}{250 T^{5}} \left(-662 + \frac{2115 Tc}{T} + \frac{480 Tc^{6}}{T^{6}}\right) \frac{d^3 B^{(2)}}{dT^3} = - \frac{336 Tc^{6}}{T^{9}} \frac{d^3 B^{(3)}}{dT^3} = \frac{720 Tc^{8}}{T^{11}} For the first indefinite integral of B: .. math:: \int{B^{(0)}} dT = \frac{289 T}{2000} - \frac{33 Tc}{100} \log{\left (T \right )} + \frac{1}{7000000 T^{7}} \left(969500 T^{6} Tc^{2} + 42350 T^{5} Tc^{3} + 607 Tc^{8}\right) \int{B^{(1)}} dT = \frac{637 T}{10000} - \frac{1}{70000 T^{7}} \left(23170 T^{6} Tc^{2} - 14805 T^{5} Tc^{3} - 80 Tc^{8}\right) \int{B^{(2)}} dT = - \frac{Tc^{6}}{5 T^{5}} \int{B^{(3)}} dT = \frac{Tc^{8}}{7 T^{7}} For the second indefinite integral of B: .. math:: \int\int B^{(0)} dT dT = \frac{289 T^{2}}{4000} - \frac{33 T}{100} Tc \log{\left (T \right )} + \frac{33 T}{100} Tc + \frac{277 Tc^{2}}{2000} \log{\left (T \right )} - \frac{1}{42000000 T^{6}} \left(254100 T^{5} Tc^{3} + 607 Tc^{8}\right) \int\int B^{(1)} dT dT = \frac{637 T^{2}}{20000} - \frac{331 Tc^{2}}{1000} \log{\left (T \right )} - \frac{1}{210000 T^{6}} \left(44415 T^{5} Tc^{3} + 40 Tc^{8}\right) \int\int B^{(2)} dT dT = \frac{Tc^{6}}{20 T^{4}} \int\int B^{(3)} dT dT = - \frac{Tc^{8}}{42 T^{6}} Examples -------- Example from Perry's Handbook, 8E, p2-499. Matches to a decimal place. >>> BVirial_Tsonopoulos_extended(430., 405.65, 11.28E6, 0.252608, a=0, b=0, species_type='ketone', dipole=1.469) -9.679715056695323e-05 References ---------- .. [1] Tsonopoulos, C., and J. L. Heidman. "From the Virial to the Cubic Equation of State." Fluid Phase Equilibria 57, no. 3 (1990): 261-76. doi:10.1016/0378-3812(90)85126-U .. [2] Tsonopoulos, Constantine, and John H. Dymond. "Second Virial Coefficients of Normal Alkanes, Linear 1-Alkanols (and Water), Alkyl Ethers, and Their Mixtures." Fluid Phase Equilibria, International Workshop on Vapour-Liquid Equilibria and Related Properties in Binary and Ternary Mixtures of Ethers, Alkanes and Alkanols, 133, no. 1-2 (June 1997): 11-34. doi:10.1016/S0378-3812(97)00058-7. ''' Tr = T/Tc if order == 0: B0 = 0.1445 - 0.33/Tr - 0.1385/Tr**2 - 0.0121/Tr**3 - 0.000607/Tr**8 B1 = 0.0637 + 0.331/Tr**2 - 0.423/Tr**3 - 0.008/Tr**8 B2 = 1./Tr**6 B3 = -1./Tr**8 elif order == 1: B0 = 33*Tc/(100*T**2) + 277*Tc**2/(1000*T**3) + 363*Tc**3/(10000*T**4) + 607*Tc**8/(125000*T**9) B1 = -331*Tc**2/(500*T**3) + 1269*Tc**3/(1000*T**4) + 8*Tc**8/(125*T**9) B2 = -6.0*Tc**6/T**7 B3 = 8.0*Tc**8/T**9 elif order == 2: B0 = -3*Tc*(27500 + 34625*Tc/T + 6050*Tc**2/T**2 + 1821*Tc**7/T**7)/(125000*T**3) B1 = 3*Tc**2*(331 - 846*Tc/T - 96*Tc**6/T**6)/(500*T**4) B2 = 42.0*Tc**6/T**8 B3 = -72.0*Tc**8/T**10 elif order == 3: B0 = 3*Tc*(8250 + 13850*Tc/T + 3025*Tc**2/T**2 + 1821*Tc**7/T**7)/(12500*T**4) B1 = 3*Tc**2*(-662 + 2115*Tc/T + 480*Tc**6/T**6)/(250*T**5) B2 = -336.0*Tc**6/T**9 B3 = 720.0*Tc**8/T**11 elif order == -1: B0 = 289*T/2000. - 33*Tc*log(T)/100. + (969500*T**6*Tc**2 + 42350*T**5*Tc**3 + 607*Tc**8)/(7000000.*T**7) B1 = 637*T/10000. - (23170*T**6*Tc**2 - 14805*T**5*Tc**3 - 80*Tc**8)/(70000.*T**7) B2 = -Tc**6/(5*T**5) B3 = Tc**8/(7*T**7) elif order == -2: B0 = 289*T**2/4000. - 33*T*Tc*log(T)/100. + 33*T*Tc/100. + 277*Tc**2*log(T)/2000. - (254100*T**5*Tc**3 + 607*Tc**8)/(42000000.*T**6) B1 = 637*T**2/20000. - 331*Tc**2*log(T)/1000. - (44415*T**5*Tc**3 + 40*Tc**8)/(210000.*T**6) B2 = Tc**6/(20*T**4) B3 = -Tc**8/(42*T**6) else: raise Exception('Only orders -2, -1, 0, 1, 2 and 3 are supported.') if a == 0 and b == 0 and species_type != '': if species_type == 'simple' or species_type == 'normal': a, b = 0, 0 elif species_type == 'methyl alcohol': a, b = 0.0878, 0.0525 elif species_type == 'water': a, b = -0.0109, 0 elif dipole != 0 and Tc != 0 and Pc != 0: dipole_r = 1E5*dipole**2*(Pc/101325.0)/Tc**2 if (species_type == 'ketone' or species_type == 'aldehyde' or species_type == 'alkyl nitrile' or species_type == 'ether' or species_type == 'carboxylic acid' or species_type == 'ester'): a, b = -2.14E-4*dipole_r-4.308E-21*dipole_r**8, 0 elif (species_type == 'alkyl halide' or species_type == 'mercaptan' or species_type == 'sulfide' or species_type == 'disulfide'): a, b = -2.188E-4*dipole_r**4-7.831E-21*dipole_r**8, 0 elif species_type == 'alkanol': a, b = 0.0878, 0.00908+0.0006957*dipole_r Br = B0 + omega*B1 + a*B2 + b*B3 return Br*R*Tc/Pc
def smarts_fragment(catalog, rdkitmol=None, smi=None): r'''Fragments a molecule into a set of unique groups and counts as specified by the `catalog`. The molecule can either be an rdkit molecule object, or a smiles string which will be parsed by rdkit. Returns a dictionary of groups and their counts according to the indexes of the catalog provided. Parameters ---------- catalog : dict Dictionary indexed by keys pointing to smarts strings, [-] rdkitmol : mol, optional Molecule as rdkit object, [-] smi : str, optional Smiles string representing a chemical, [-] Returns ------- counts : dict Dictionaty of integer counts of the found groups only, indexed by the same keys used by the catalog [-] success : bool Whether or not molecule was fully and uniquely fragmented, [-] status : str A string holding an explanation of why the molecule failed to be fragmented, if it fails; 'OK' if it suceeds. Notes ----- Raises an exception if rdkit is not installed, or `smi` or `rdkitmol` is not defined. Examples -------- Acetone: >>> smarts_fragment(catalog=J_BIGGS_JOBACK_SMARTS_id_dict, smi='CC(=O)C') ({24: 1, 1: 2}, True, 'OK') Sodium sulfate, (Na2O4S): >>> smarts_fragment(catalog=J_BIGGS_JOBACK_SMARTS_id_dict, smi='[O-]S(=O)(=O)[O-].[Na+].[Na+]') ({29: 4}, False, 'Did not match all atoms present') Propionic anhydride (C6H10O3): >>> smarts_fragment(catalog=J_BIGGS_JOBACK_SMARTS_id_dict, smi='CCC(=O)OC(=O)CC') ({1: 2, 2: 2, 28: 2}, False, 'Matched some atoms repeatedly: [4]') ''' if not hasRDKit: # pragma: no cover raise Exception(rdkit_missing) if rdkitmol is None and smi is None: raise Exception('Either an rdkit mol or a smiles string is required') if smi is not None: rdkitmol = Chem.MolFromSmiles(smi) if rdkitmol is None: status = 'Failed to construct mol' success = False return {}, success, status atom_count = len(rdkitmol.GetAtoms()) status = 'OK' success = True counts = {} all_matches = {} for key, smart in catalog.items(): patt = Chem.MolFromSmarts(smart) hits = rdkitmol.GetSubstructMatches(patt) if hits: all_matches[smart] = hits counts[key] = len(hits) matched_atoms = set() for i in all_matches.values(): for j in i: matched_atoms.update(j) if len(matched_atoms) != atom_count: status = 'Did not match all atoms present' success = False # Check the atom aount again, this time looking for duplicate matches (only if have yet to fail) if success: matched_atoms = [] for i in all_matches.values(): for j in i: matched_atoms.extend(j) if len(matched_atoms) < atom_count: status = 'Matched %d of %d atoms only' %(len(matched_atoms), atom_count) success = False elif len(matched_atoms) > atom_count: status = 'Matched some atoms repeatedly: %s' %( [i for i, c in Counter(matched_atoms).items() if c > 1]) success = False return counts, success, status
def estimate(self): '''Method to compute all available properties with the Joback method; returns their results as a dict. For the tempearture dependent values Cpig and mul, both the coefficients and objects to perform calculations are returned. ''' # Pre-generate the coefficients or they will not be returned self.mul(300) self.Cpig(300) estimates = {'Tb': self.Tb(self.counts), 'Tm': self.Tm(self.counts), 'Tc': self.Tc(self.counts, self.Tb_estimated), 'Pc': self.Pc(self.counts, self.atom_count), 'Vc': self.Vc(self.counts), 'Hf': self.Hf(self.counts), 'Gf': self.Gf(self.counts), 'Hfus': self.Hfus(self.counts), 'Hvap': self.Hvap(self.counts), 'mul': self.mul, 'mul_coeffs': self.calculated_mul_coeffs, 'Cpig': self.Cpig, 'Cpig_coeffs': self.calculated_Cpig_coeffs} return estimates
def Tb(counts): r'''Estimates the normal boiling temperature of an organic compound using the Joback method as a function of chemical structure only. .. math:: T_b = 198.2 + \sum_i {T_{b,i}} For 438 compounds tested by Joback, the absolute average error was 12.91 K and standard deviation was 17.85 K; the average relative error was 3.6%. Parameters ---------- counts : dict Dictionary of Joback groups present (numerically indexed) and their counts, [-] Returns ------- Tb : float Estimated normal boiling temperature, [K] Examples -------- >>> Joback.Tb({1: 2, 24: 1}) 322.11 ''' tot = 0.0 for group, count in counts.items(): tot += joback_groups_id_dict[group].Tb*count Tb = 198.2 + tot return Tb
def Tm(counts): r'''Estimates the melting temperature of an organic compound using the Joback method as a function of chemical structure only. .. math:: T_m = 122.5 + \sum_i {T_{m,i}} For 388 compounds tested by Joback, the absolute average error was 22.6 K and standard deviation was 24.68 K; the average relative error was 11.2%. Parameters ---------- counts : dict Dictionary of Joback groups present (numerically indexed) and their counts, [-] Returns ------- Tm : float Estimated melting temperature, [K] Examples -------- >>> Joback.Tm({1: 2, 24: 1}) 173.5 ''' tot = 0.0 for group, count in counts.items(): tot += joback_groups_id_dict[group].Tm*count Tm = 122.5 + tot return Tm
def Tc(counts, Tb=None): r'''Estimates the critcal temperature of an organic compound using the Joback method as a function of chemical structure only, or optionally improved by using an experimental boiling point. If the experimental boiling point is not provided it will be estimated with the Joback method as well. .. math:: T_c = T_b \left[0.584 + 0.965 \sum_i {T_{c,i}} - \left(\sum_i {T_{c,i}}\right)^2 \right]^{-1} For 409 compounds tested by Joback, the absolute average error was 4.76 K and standard deviation was 6.94 K; the average relative error was 0.81%. Appendix BI of Joback's work lists 409 estimated critical temperatures. Parameters ---------- counts : dict Dictionary of Joback groups present (numerically indexed) and their counts, [-] Tb : float, optional Experimental normal boiling temperature, [K] Returns ------- Tc : float Estimated critical temperature, [K] Examples -------- >>> Joback.Tc({1: 2, 24: 1}, Tb=322.11) 500.5590049525365 ''' if Tb is None: Tb = Joback.Tb(counts) tot = 0.0 for group, count in counts.items(): tot += joback_groups_id_dict[group].Tc*count Tc = Tb/(0.584 + 0.965*tot - tot*tot) return Tc
def Pc(counts, atom_count): r'''Estimates the critcal pressure of an organic compound using the Joback method as a function of chemical structure only. This correlation was developed using the actual number of atoms forming the molecule as well. .. math:: P_c = \left [0.113 + 0.0032N_A - \sum_i {P_{c,i}}\right ]^{-2} In the above equation, critical pressure is calculated in bar; it is converted to Pa here. 392 compounds were used by Joback in this determination, with an absolute average error of 2.06 bar, standard devaition 3.2 bar, and AARE of 5.2%. Parameters ---------- counts : dict Dictionary of Joback groups present (numerically indexed) and their counts, [-] atom_count : int Total number of atoms (including hydrogens) in the molecule, [-] Returns ------- Pc : float Estimated critical pressure, [Pa] Examples -------- >>> Joback.Pc({1: 2, 24: 1}, 10) 4802499.604994407 ''' tot = 0.0 for group, count in counts.items(): tot += joback_groups_id_dict[group].Pc*count Pc = (0.113 + 0.0032*atom_count - tot)**-2 return Pc*1E5
def Vc(counts): r'''Estimates the critcal volume of an organic compound using the Joback method as a function of chemical structure only. .. math:: V_c = 17.5 + \sum_i {V_{c,i}} In the above equation, critical volume is calculated in cm^3/mol; it is converted to m^3/mol here. 310 compounds were used by Joback in this determination, with an absolute average error of 7.54 cm^3/mol, standard devaition 13.16 cm^3/mol, and AARE of 2.27%. Parameters ---------- counts : dict Dictionary of Joback groups present (numerically indexed) and their counts, [-] Returns ------- Vc : float Estimated critical volume, [m^3/mol] Examples -------- >>> Joback.Vc({1: 2, 24: 1}) 0.0002095 ''' tot = 0.0 for group, count in counts.items(): tot += joback_groups_id_dict[group].Vc*count Vc = 17.5 + tot return Vc*1E-6
def Hf(counts): r'''Estimates the ideal-gas enthalpy of formation at 298.15 K of an organic compound using the Joback method as a function of chemical structure only. .. math:: H_{formation} = 68.29 + \sum_i {H_{f,i}} In the above equation, enthalpy of formation is calculated in kJ/mol; it is converted to J/mol here. 370 compounds were used by Joback in this determination, with an absolute average error of 2.2 kcal/mol, standard devaition 2.0 kcal/mol, and AARE of 15.2%. Parameters ---------- counts : dict Dictionary of Joback groups present (numerically indexed) and their counts, [-] Returns ------- Hf : float Estimated ideal-gas enthalpy of formation at 298.15 K, [J/mol] Examples -------- >>> Joback.Hf({1: 2, 24: 1}) -217829.99999999997 ''' tot = 0.0 for group, count in counts.items(): tot += joback_groups_id_dict[group].Hform*count Hf = 68.29 + tot return Hf*1000
def Gf(counts): r'''Estimates the ideal-gas Gibbs energy of formation at 298.15 K of an organic compound using the Joback method as a function of chemical structure only. .. math:: G_{formation} = 53.88 + \sum {G_{f,i}} In the above equation, Gibbs energy of formation is calculated in kJ/mol; it is converted to J/mol here. 328 compounds were used by Joback in this determination, with an absolute average error of 2.0 kcal/mol, standard devaition 4.37 kcal/mol, and AARE of 15.7%. Parameters ---------- counts : dict Dictionary of Joback groups present (numerically indexed) and their counts, [-] Returns ------- Gf : float Estimated ideal-gas Gibbs energy of formation at 298.15 K, [J/mol] Examples -------- >>> Joback.Gf({1: 2, 24: 1}) -154540.00000000003 ''' tot = 0.0 for group, count in counts.items(): tot += joback_groups_id_dict[group].Gform*count Gf = 53.88 + tot return Gf*1000
def Hfus(counts): r'''Estimates the enthalpy of fusion of an organic compound at its melting point using the Joback method as a function of chemical structure only. .. math:: \Delta H_{fus} = -0.88 + \sum_i H_{fus,i} In the above equation, enthalpy of fusion is calculated in kJ/mol; it is converted to J/mol here. For 155 compounds tested by Joback, the absolute average error was 485.2 cal/mol and standard deviation was 661.4 cal/mol; the average relative error was 38.7%. Parameters ---------- counts : dict Dictionary of Joback groups present (numerically indexed) and their counts, [-] Returns ------- Hfus : float Estimated enthalpy of fusion of the compound at its melting point, [J/mol] Examples -------- >>> Joback.Hfus({1: 2, 24: 1}) 5125.0 ''' tot = 0.0 for group, count in counts.items(): tot += joback_groups_id_dict[group].Hfus*count Hfus = -0.88 + tot return Hfus*1000
def Hvap(counts): r'''Estimates the enthalpy of vaporization of an organic compound at its normal boiling point using the Joback method as a function of chemical structure only. .. math:: \Delta H_{vap} = 15.30 + \sum_i H_{vap,i} In the above equation, enthalpy of fusion is calculated in kJ/mol; it is converted to J/mol here. For 368 compounds tested by Joback, the absolute average error was 303.5 cal/mol and standard deviation was 429 cal/mol; the average relative error was 3.88%. Parameters ---------- counts : dict Dictionary of Joback groups present (numerically indexed) and their counts, [-] Returns ------- Hvap : float Estimated enthalpy of vaporization of the compound at its normal boiling point, [J/mol] Examples -------- >>> Joback.Hvap({1: 2, 24: 1}) 29018.0 ''' tot = 0.0 for group, count in counts.items(): tot += joback_groups_id_dict[group].Hvap*count Hvap = 15.3 + tot return Hvap*1000
def Cpig_coeffs(counts): r'''Computes the ideal-gas polynomial heat capacity coefficients of an organic compound using the Joback method as a function of chemical structure only. .. math:: C_p^{ig} = \sum_i a_i - 37.93 + \left[ \sum_i b_i + 0.210 \right] T + \left[ \sum_i c_i - 3.91 \cdot 10^{-4} \right] T^2 + \left[\sum_i d_i + 2.06 \cdot 10^{-7}\right] T^3 288 compounds were used by Joback in this determination. No overall error was reported. The ideal gas heat capacity values used in developing the heat capacity polynomials used 9 data points between 298 K and 1000 K. Parameters ---------- counts : dict Dictionary of Joback groups present (numerically indexed) and their counts, [-] Returns ------- coefficients : list[float] Coefficients which will result in a calculated heat capacity in in units of J/mol/K, [-] Examples -------- >>> c = Joback.Cpig_coeffs({1: 2, 24: 1}) >>> c [7.520000000000003, 0.26084, -0.0001207, 1.545999999999998e-08] >>> Cp = lambda T : c[0] + c[1]*T + c[2]*T**2 + c[3]*T**3 >>> Cp(300) 75.32642000000001 ''' a, b, c, d = 0.0, 0.0, 0.0, 0.0 for group, count in counts.items(): a += joback_groups_id_dict[group].Cpa*count b += joback_groups_id_dict[group].Cpb*count c += joback_groups_id_dict[group].Cpc*count d += joback_groups_id_dict[group].Cpd*count a -= 37.93 b += 0.210 c -= 3.91E-4 d += 2.06E-7 return [a, b, c, d]
def mul_coeffs(counts): r'''Computes the liquid phase viscosity Joback coefficients of an organic compound using the Joback method as a function of chemical structure only. .. math:: \mu_{liq} = \text{MW} \exp\left( \frac{ \sum_i \mu_a - 597.82}{T} + \sum_i \mu_b - 11.202 \right) 288 compounds were used by Joback in this determination. No overall error was reported. The liquid viscosity data used was specified to be at "several temperatures for each compound" only. A small and unspecified number of compounds were used in this estimation. Parameters ---------- counts : dict Dictionary of Joback groups present (numerically indexed) and their counts, [-] Returns ------- coefficients : list[float] Coefficients which will result in a liquid viscosity in in units of Pa*s, [-] Examples -------- >>> mu_ab = Joback.mul_coeffs({1: 2, 24: 1}) >>> mu_ab [839.1099999999998, -14.99] >>> MW = 58.041864812 >>> mul = lambda T : MW*exp(mu_ab[0]/T + mu_ab[1]) >>> mul(300) 0.0002940378347162687 ''' a, b = 0.0, 0.0 for group, count in counts.items(): a += joback_groups_id_dict[group].mua*count b += joback_groups_id_dict[group].mub*count a -= 597.82 b -= 11.202 return [a, b]
def Cpig(self, T): r'''Computes ideal-gas heat capacity at a specified temperature of an organic compound using the Joback method as a function of chemical structure only. .. math:: C_p^{ig} = \sum_i a_i - 37.93 + \left[ \sum_i b_i + 0.210 \right] T + \left[ \sum_i c_i - 3.91 \cdot 10^{-4} \right] T^2 + \left[\sum_i d_i + 2.06 \cdot 10^{-7}\right] T^3 Parameters ---------- T : float Temperature, [K] Returns ------- Cpig : float Ideal-gas heat capacity, [J/mol/K] Examples -------- >>> J = Joback('CC(=O)C') >>> J.Cpig(300) 75.32642000000001 ''' if self.calculated_Cpig_coeffs is None: self.calculated_Cpig_coeffs = Joback.Cpig_coeffs(self.counts) return horner(reversed(self.calculated_Cpig_coeffs), T)
def mul(self, T): r'''Computes liquid viscosity at a specified temperature of an organic compound using the Joback method as a function of chemical structure only. .. math:: \mu_{liq} = \text{MW} \exp\left( \frac{ \sum_i \mu_a - 597.82}{T} + \sum_i \mu_b - 11.202 \right) Parameters ---------- T : float Temperature, [K] Returns ------- mul : float Liquid viscosity, [Pa*s] Examples -------- >>> J = Joback('CC(=O)C') >>> J.mul(300) 0.0002940378347162687 ''' if self.calculated_mul_coeffs is None: self.calculated_mul_coeffs = Joback.mul_coeffs(self.counts) a, b = self.calculated_mul_coeffs return self.MW*exp(a/T + b)
def Laliberte_viscosity_i(T, w_w, v1, v2, v3, v4, v5, v6): r'''Calculate the viscosity of a solute using the form proposed by [1]_ Parameters are needed, and a temperature. Units are Kelvin and Pa*s. .. math:: \mu_i = \frac{\exp\left( \frac{v_1(1-w_w)^{v_2}+v_3}{v_4 t +1}\right)} {v_5(1-w_w)^{v_6}+1} Parameters ---------- T : float Temperature of fluid [K] w_w : float Weight fraction of water in the solution v1-v6 : floats Function fit parameters Returns ------- mu_i : float Solute partial viscosity, Pa*s Notes ----- Temperature range check is outside of this function. Check is performed using NaCl at 5 degC from the first value in [1]_'s spreadsheet. Examples -------- >>> d = _Laliberte_Viscosity_ParametersDict['7647-14-5'] >>> Laliberte_viscosity_i(273.15+5, 1-0.005810, d["V1"], d["V2"], d["V3"], d["V4"], d["V5"], d["V6"] ) 0.004254025533308794 References ---------- .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of Aqueous Solutions, with Updated Density and Viscosity Data." Journal of Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60. doi:10.1021/je8008123 ''' t = T-273.15 mu_i = exp((v1*(1-w_w)**v2 + v3)/(v4*t+1))/(v5*(1-w_w)**v6 + 1) return mu_i/1000.
def Laliberte_viscosity(T, ws, CASRNs): r'''Calculate the viscosity of an aqueous mixture using the form proposed by [1]_. Parameters are loaded by the function as needed. Units are Kelvin and Pa*s. .. math:: \mu_m = \mu_w^{w_w} \Pi\mu_i^{w_i} Parameters ---------- T : float Temperature of fluid [K] ws : array Weight fractions of fluid components other than water CASRNs : array CAS numbers of the fluid components other than water Returns ------- mu_i : float Solute partial viscosity, Pa*s Notes ----- Temperature range check is not used here. Check is performed using NaCl at 5 degC from the first value in [1]_'s spreadsheet. Examples -------- >>> Laliberte_viscosity(273.15+5, [0.005810], ['7647-14-5']) 0.0015285828581961414 References ---------- .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of Aqueous Solutions, with Updated Density and Viscosity Data." Journal of Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60. doi:10.1021/je8008123 ''' mu_w = Laliberte_viscosity_w(T)*1000. w_w = 1 - sum(ws) mu = mu_w**(w_w) for i in range(len(CASRNs)): d = _Laliberte_Viscosity_ParametersDict[CASRNs[i]] mu_i = Laliberte_viscosity_i(T, w_w, d["V1"], d["V2"], d["V3"], d["V4"], d["V5"], d["V6"])*1000. mu = mu_i**(ws[i])*mu return mu/1000.
def Laliberte_density_w(T): r'''Calculate the density of water using the form proposed by [1]_. No parameters are needed, just a temperature. Units are Kelvin and kg/m^3h. .. math:: \rho_w = \frac{\left\{\left([(-2.8054253\times 10^{-10}\cdot t + 1.0556302\times 10^{-7})t - 4.6170461\times 10^{-5}]t -0.0079870401\right)t + 16.945176 \right\}t + 999.83952} {1 + 0.01687985\cdot t} Parameters ---------- T : float Temperature of fluid [K] Returns ------- rho_w : float Water density, [kg/m^3] Notes ----- Original source not cited No temperature range is used. Examples -------- >>> Laliberte_density_w(298.15) 997.0448954179155 >>> Laliberte_density_w(273.15 + 50) 988.0362916114763 References ---------- .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of Aqueous Solutions, with Updated Density and Viscosity Data." Journal of Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60. doi:10.1021/je8008123 ''' t = T-273.15 rho_w = (((((-2.8054253E-10*t + 1.0556302E-7)*t - 4.6170461E-5)*t - 0.0079870401)*t + 16.945176)*t + 999.83952) \ / (1 + 0.01687985*t) return rho_w
def Laliberte_density_i(T, w_w, c0, c1, c2, c3, c4): r'''Calculate the density of a solute using the form proposed by Laliberte [1]_. Parameters are needed, and a temperature, and water fraction. Units are Kelvin and Pa*s. .. math:: \rho_{app,i} = \frac{(c_0[1-w_w]+c_1)\exp(10^{-6}[t+c_4]^2)} {(1-w_w) + c_2 + c_3 t} Parameters ---------- T : float Temperature of fluid [K] w_w : float Weight fraction of water in the solution c0-c4 : floats Function fit parameters Returns ------- rho_i : float Solute partial density, [kg/m^3] Notes ----- Temperature range check is TODO Examples -------- >>> d = _Laliberte_Density_ParametersDict['7647-14-5'] >>> Laliberte_density_i(273.15+0, 1-0.0037838838, d["C0"], d["C1"], d["C2"], d["C3"], d["C4"]) 3761.8917585699983 References ---------- .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of Aqueous Solutions, with Updated Density and Viscosity Data." Journal of Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60. doi:10.1021/je8008123 ''' t = T - 273.15 return ((c0*(1 - w_w)+c1)*exp(1E-6*(t + c4)**2))/((1 - w_w) + c2 + c3*t)
def Laliberte_density(T, ws, CASRNs): r'''Calculate the density of an aqueous electrolyte mixture using the form proposed by [1]_. Parameters are loaded by the function as needed. Units are Kelvin and Pa*s. .. math:: \rho_m = \left(\frac{w_w}{\rho_w} + \sum_i \frac{w_i}{\rho_{app_i}}\right)^{-1} Parameters ---------- T : float Temperature of fluid [K] ws : array Weight fractions of fluid components other than water CASRNs : array CAS numbers of the fluid components other than water Returns ------- rho_i : float Solution density, [kg/m^3] Notes ----- Temperature range check is not used here. Examples -------- >>> Laliberte_density(273.15, [0.0037838838], ['7647-14-5']) 1002.6250120185854 References ---------- .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of Aqueous Solutions, with Updated Density and Viscosity Data." Journal of Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60. doi:10.1021/je8008123 ''' rho_w = Laliberte_density_w(T) w_w = 1 - sum(ws) rho = w_w/rho_w for i in range(len(CASRNs)): d = _Laliberte_Density_ParametersDict[CASRNs[i]] rho_i = Laliberte_density_i(T, w_w, d["C0"], d["C1"], d["C2"], d["C3"], d["C4"]) rho = rho + ws[i]/rho_i return 1./rho
def Laliberte_heat_capacity_i(T, w_w, a1, a2, a3, a4, a5, a6): r'''Calculate the heat capacity of a solute using the form proposed by [1]_ Parameters are needed, and a temperature, and water fraction. .. math:: Cp_i = a_1 e^\alpha + a_5(1-w_w)^{a_6} \alpha = a_2 t + a_3 \exp(0.01t) + a_4(1-w_w) Parameters ---------- T : float Temperature of fluid [K] w_w : float Weight fraction of water in the solution a1-a6 : floats Function fit parameters Returns ------- Cp_i : float Solute partial heat capacity, [J/kg/K] Notes ----- Units are Kelvin and J/kg/K. Temperature range check is TODO Examples -------- >>> d = _Laliberte_Heat_Capacity_ParametersDict['7647-14-5'] >>> Laliberte_heat_capacity_i(1.5+273.15, 1-0.00398447, d["A1"], d["A2"], d["A3"], d["A4"], d["A5"], d["A6"]) -2930.7353945880477 References ---------- .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of Aqueous Solutions, with Updated Density and Viscosity Data." Journal of Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60. doi:10.1021/je8008123 ''' t = T - 273.15 alpha = a2*t + a3*exp(0.01*t) + a4*(1. - w_w) Cp_i = a1*exp(alpha) + a5*(1. - w_w)**a6 return Cp_i*1000.
def Laliberte_heat_capacity(T, ws, CASRNs): r'''Calculate the heat capacity of an aqueous electrolyte mixture using the form proposed by [1]_. Parameters are loaded by the function as needed. .. math:: TODO Parameters ---------- T : float Temperature of fluid [K] ws : array Weight fractions of fluid components other than water CASRNs : array CAS numbers of the fluid components other than water Returns ------- Cp : float Solution heat capacity, [J/kg/K] Notes ----- Temperature range check is not implemented. Units are Kelvin and J/kg/K. Examples -------- >>> Laliberte_heat_capacity(273.15+1.5, [0.00398447], ['7647-14-5']) 4186.569908672113 References ---------- .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of Aqueous Solutions, with Updated Density and Viscosity Data." Journal of Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60. doi:10.1021/je8008123 ''' Cp_w = Laliberte_heat_capacity_w(T) w_w = 1 - sum(ws) Cp = w_w*Cp_w for i in range(len(CASRNs)): d = _Laliberte_Heat_Capacity_ParametersDict[CASRNs[i]] Cp_i = Laliberte_heat_capacity_i(T, w_w, d["A1"], d["A2"], d["A3"], d["A4"], d["A5"], d["A6"]) Cp = Cp + ws[i]*Cp_i return Cp
def dilute_ionic_conductivity(ionic_conductivities, zs, rhom): r'''This function handles the calculation of the electrical conductivity of a dilute electrolytic aqueous solution. Requires the mole fractions of each ion, the molar density of the whole mixture, and ionic conductivity coefficients for each ion. .. math:: \lambda = \sum_i \lambda_i^\circ z_i \rho_m Parameters ---------- ionic_conductivities : list[float] Ionic conductivity coefficients of each ion in the mixture [m^2*S/mol] zs : list[float] Mole fractions of each ion in the mixture, [-] rhom : float Overall molar density of the solution, [mol/m^3] Returns ------- kappa : float Electrical conductivity of the fluid, [S/m] Notes ----- The ionic conductivity coefficients should not be `equivalent` coefficients; for example, 0.0053 m^2*S/mol is the equivalent conductivity coefficient of Mg+2, but this method expects twice its value - 0.0106. Both are reported commonly in literature. Water can be included in this caclulation by specifying a coefficient of 0. The conductivity of any electrolyte eclipses its own conductivity by many orders of magnitude. Any other solvents present will affect the conductivity extensively and there are few good methods to predict this effect. Examples -------- Complex mixture of electrolytes ['Cl-', 'HCO3-', 'SO4-2', 'Na+', 'K+', 'Ca+2', 'Mg+2']: >>> ionic_conductivities = [0.00764, 0.00445, 0.016, 0.00501, 0.00735, 0.0119, 0.01061] >>> zs = [0.03104, 0.00039, 0.00022, 0.02413, 0.0009, 0.0024, 0.00103] >>> dilute_ionic_conductivity(ionic_conductivities=ionic_conductivities, zs=zs, rhom=53865.9) 22.05246783663 References ---------- .. [1] Haynes, W.M., Thomas J. Bruno, and David R. Lide. CRC Handbook of Chemistry and Physics, 95E. Boca Raton, FL: CRC press, 2014. ''' return sum([ci*(zi*rhom) for zi, ci in zip(zs, ionic_conductivities)])
def conductivity_McCleskey(T, M, lambda_coeffs, A_coeffs, B, multiplier, rho=1000.): r'''This function handles the calculation of the electrical conductivity of an electrolytic aqueous solution with one electrolyte in solution. It handles temperature dependency and concentrated solutions. Requires the temperature of the solution; its molality, and four sets of coefficients `lambda_coeffs`, `A_coeffs`, `B`, and `multiplier`. .. math:: \Lambda = \frac{\kappa}{C} \Lambda = \Lambda^0(t) - A(t) \frac{m^{1/2}}{1+Bm^{1/2}} \Lambda^\circ(t) = c_1 t^2 + c_2 t + c_3 A(t) = d_1 t^2 + d_2 t + d_3 In the above equations, `t` is temperature in degrees Celcius; `m` is molality in mol/kg, and C is the concentration of the elctrolytes in mol/m^3, calculated as the product of density and molality. Parameters ---------- T : float Temperature of the solution, [K] M : float Molality of the solution with respect to one electrolyte (mol solute / kg solvent), [mol/kg] lambda_coeffs : list[float] List of coefficients for the polynomial used to calculate `lambda`; length-3 coefficients provided in [1]_, [-] A_coeffs : list[float] List of coefficients for the polynomial used to calculate `A`; length-3 coefficients provided in [1]_, [-] B : float Empirical constant for an electrolyte, [-] multiplier : float The multiplier to obtain the absolute conductivity from the equivalent conductivity; ex 2 for CaCl2, [-] rho : float, optional The mass density of the aqueous mixture, [kg/m^3] Returns ------- kappa : float Electrical conductivity of the solution at the specified molality and temperature [S/m] Notes ----- Coefficients provided in [1]_ result in conductivity being calculated in units of mS/cm; they are converted to S/m before returned. Examples -------- A 0.5 wt% solution of CaCl2, conductivity calculated in mS/cm >>> conductivity_McCleskey(T=293.15, M=0.045053, A_coeffs=[.03918, 3.905, ... 137.7], lambda_coeffs=[0.01124, 2.224, 72.36], B=3.8, multiplier=2) 0.8482584585108555 References ---------- .. [1] McCleskey, R. Blaine. "Electrical Conductivity of Electrolytes Found In Natural Waters from (5 to 90) °C." Journal of Chemical & Engineering Data 56, no. 2 (February 10, 2011): 317-27. doi:10.1021/je101012n. ''' t = T - 273.15 lambda_coeff = horner(lambda_coeffs, t) A = horner(A_coeffs, t) M_root = M**0.5 param = lambda_coeff - A*M_root/(1. + B*M_root) C = M*rho/1000. # convert to mol/L to get concentration return param*C*multiplier*0.1
def conductivity(CASRN=None, AvailableMethods=False, Method=None, full_info=True): r'''This function handles the retrieval of a chemical's conductivity. Lookup is based on CASRNs. Will automatically select a data source to use if no Method is provided; returns None if the data is not available. Function has data for approximately 100 chemicals. Parameters ---------- CASRN : string CASRN [-] Returns ------- kappa : float Electrical conductivity of the fluid, [S/m] T : float, only returned if full_info == True Temperature at which conductivity measurement was made methods : list, only returned if AvailableMethods == True List of methods which can be used to obtain RI with the given inputs Other Parameters ---------------- Method : string, optional A string for the method name to use, as defined by constants in conductivity_methods AvailableMethods : bool, optional If True, function will determine which methods can be used to obtain conductivity for the desired chemical, and will return methods instead of conductivity full_info : bool, optional If True, function will return the temperature at which the conductivity reading was made Notes ----- Only one source is available in this function. It is: * 'LANGE_COND' which is from Lange's Handbook, Table 8.34 Electrical Conductivity of Various Pure Liquids', a compillation of data in [1]_. Examples -------- >>> conductivity('7732-18-5') (4e-06, 291.15) References ---------- .. [1] Speight, James. Lange's Handbook of Chemistry. 16 edition. McGraw-Hill Professional, 2005. ''' def list_methods(): methods = [] if CASRN in Lange_cond_pure.index: methods.append(LANGE_COND) methods.append(NONE) return methods if AvailableMethods: return list_methods() if not Method: Method = list_methods()[0] if Method == LANGE_COND: kappa = float(Lange_cond_pure.at[CASRN, 'Conductivity']) if full_info: T = float(Lange_cond_pure.at[CASRN, 'T']) elif Method == NONE: kappa, T = None, None else: raise Exception('Failure in in function') if full_info: return kappa, T else: return kappa
def thermal_conductivity_Magomedov(T, P, ws, CASRNs, k_w=None): r'''Calculate the thermal conductivity of an aqueous mixture of electrolytes using the form proposed by Magomedov [1]_. Parameters are loaded by the function as needed. Function will fail if an electrolyte is not in the database. .. math:: \lambda = \lambda_w\left[ 1 - \sum_{i=1}^n A_i (w_i + 2\times10^{-4} w_i^3)\right] - 2\times10^{-8} PT\sum_{i=1}^n w_i Parameters ---------- T : float Temperature of liquid [K] P : float Pressure of the liquid [Pa] ws : array Weight fractions of liquid components other than water CASRNs : array CAS numbers of the liquid components other than water k_w : float Liquid thermal condiuctivity or pure water at T and P, [W/m/K] Returns ------- kl : float Liquid thermal condiuctivity, [W/m/K] Notes ----- Range from 273 K to 473 K, P from 0.1 MPa to 100 MPa. C from 0 to 25 mass%. Internal untis are MPa for pressure and weight percent. An example is sought for this function. It is not possible to reproduce the author's values consistently. Examples -------- >>> thermal_conductivity_Magomedov(293., 1E6, [.25], ['7758-94-3'], k_w=0.59827) 0.548654049375 References ---------- .. [1] Magomedov, U. B. "The Thermal Conductivity of Binary and Multicomponent Aqueous Solutions of Inorganic Substances at High Parameters of State." High Temperature 39, no. 2 (March 1, 2001): 221-26. doi:10.1023/A:1017518731726. ''' P = P/1E6 ws = [i*100 for i in ws] if not k_w: raise Exception('k_w correlation must be provided') sum1 = 0 for i, CASRN in enumerate(CASRNs): Ai = float(Magomedovk_thermal_cond.at[CASRN, 'Ai']) sum1 += Ai*(ws[i] + 2E-4*ws[i]**3) return k_w*(1 - sum1) - 2E-8*P*T*sum(ws)