Search is not available for this dataset
text
stringlengths
75
104k
def K_value(P=None, Psat=None, phi_l=None, phi_g=None, gamma=None, Poynting=1): r'''Calculates the equilibrium K-value assuming Raoult's law, or an equation of state model, or an activity coefficient model, or a combined equation of state-activity model. The calculation procedure will use the most advanced approach with the provided inputs: * If `P`, `Psat`, `phi_l`, `phi_g`, and `gamma` are provided, use the combined approach. * If `P`, `Psat`, and `gamma` are provided, use the modified Raoult's law. * If `phi_l` and `phi_g` are provided, use the EOS only method. * If `P` and `Psat` are provided, use Raoult's law. Definitions: .. math:: K_i=\frac{y_i}{x_i} Raoult's law: .. math:: K_i = \frac{P_{i}^{sat}}{P} Activity coefficient, no EOS (modified Raoult's law): .. math:: K_i = \frac{\gamma_i P_{i}^{sat}}{P} Equation of state only: .. math:: K_i = \frac{\phi_i^l}{\phi_i^v} = \frac{f_i^l}{f_i^v} Combined approach (liquid reference fugacity coefficient is normally calculated the saturation pressure for it as a pure species; vapor fugacity coefficient calculated normally): .. math:: K_i = \frac{\gamma_i P_i^{sat} \phi_i^{l,ref}}{\phi_i^v P} Combined approach, with Poynting Correction Factor (liquid molar volume in the integral is for i as a pure species only): .. math:: K_i = \frac{\gamma_i P_i^{sat} \phi_i^{l, ref} \exp\left[\frac{ \int_{P_i^{sat}}^P V_i^l dP}{RT}\right]}{\phi_i^v P} Parameters ---------- P : float System pressure, optional Psat : float Vapor pressure of species i, [Pa] phi_l : float Fugacity coefficient of species i in the liquid phase, either at the system conditions (EOS-only case) or at the saturation pressure of species i as a pure species (reference condition for the combined approach), optional [-] phi_g : float Fugacity coefficient of species i in the vapor phase at the system conditions, optional [-] gamma : float Activity coefficient of species i in the liquid phase, optional [-] Poynting : float Poynting correction factor, optional [-] Returns ------- K : float Equilibrium K value of component i, calculated with an approach depending on the provided inputs [-] Notes ----- The Poynting correction factor is normally simplified as follows, due to a liquid's low pressure dependency: .. math:: K_i = \frac{\gamma_i P_i^{sat} \phi_i^{l, ref} \exp\left[\frac{V_l (P-P_i^{sat})}{RT}\right]}{\phi_i^v P} Examples -------- Raoult's law: >>> K_value(101325, 3000.) 0.029607698001480384 Modified Raoult's law: >>> K_value(P=101325, Psat=3000, gamma=0.9) 0.026646928201332347 EOS-only approach: >>> K_value(phi_l=1.6356, phi_g=0.88427) 1.8496613025433408 Gamma-phi combined approach: >>> K_value(P=1E6, Psat=1938800, phi_l=1.4356, phi_g=0.88427, gamma=0.92) 2.8958055544121137 Gamma-phi combined approach with a Poynting factor: >>> K_value(P=1E6, Psat=1938800, phi_l=1.4356, phi_g=0.88427, gamma=0.92, ... Poynting=0.999) 2.8929097488577016 References ---------- .. [1] Gmehling, Jurgen, Barbel Kolbe, Michael Kleiber, and Jurgen Rarey. Chemical Thermodynamics for Process Simulation. 1st edition. Weinheim: Wiley-VCH, 2012. .. [2] Skogestad, Sigurd. Chemical and Energy Process Engineering. 1st edition. Boca Raton, FL: CRC Press, 2008. ''' try: if gamma: if phi_l: return gamma*Psat*phi_l*Poynting/(phi_g*P) return gamma*Psat*Poynting/P elif phi_l: return phi_l/phi_g return Psat/P except TypeError: raise Exception('Input must consist of one set from (P, Psat, phi_l, \ phi_g, gamma), (P, Psat, gamma), (phi_l, phi_g), (P, Psat)')
def Rachford_Rice_flash_error(V_over_F, zs, Ks): r'''Calculates the objective function of the Rachford-Rice flash equation. This function should be called by a solver seeking a solution to a flash calculation. The unknown variable is `V_over_F`, for which a solution must be between 0 and 1. .. math:: \sum_i \frac{z_i(K_i-1)}{1 + \frac{V}{F}(K_i-1)} = 0 Parameters ---------- V_over_F : float Vapor fraction guess [-] zs : list[float] Overall mole fractions of all species, [-] Ks : list[float] Equilibrium K-values, [-] Returns ------- error : float Deviation between the objective function at the correct V_over_F and the attempted V_over_F, [-] Notes ----- The derivation is as follows: .. math:: F z_i = L x_i + V y_i x_i = \frac{z_i}{1 + \frac{V}{F}(K_i-1)} \sum_i y_i = \sum_i K_i x_i = 1 \sum_i(y_i - x_i)=0 \sum_i \frac{z_i(K_i-1)}{1 + \frac{V}{F}(K_i-1)} = 0 Examples -------- >>> Rachford_Rice_flash_error(0.5, zs=[0.5, 0.3, 0.2], ... Ks=[1.685, 0.742, 0.532]) 0.04406445591174976 References ---------- .. [1] Rachford, H. H. Jr, and J. D. Rice. "Procedure for Use of Electronic Digital Computers in Calculating Flash Vaporization Hydrocarbon Equilibrium." Journal of Petroleum Technology 4, no. 10 (October 1, 1952): 19-3. doi:10.2118/952327-G. ''' return sum([zi*(Ki-1.)/(1.+V_over_F*(Ki-1.)) for Ki, zi in zip(Ks, zs)])
def Rachford_Rice_solution(zs, Ks): r'''Solves the objective function of the Rachford-Rice flash equation. Uses the method proposed in [2]_ to obtain an initial guess. .. math:: \sum_i \frac{z_i(K_i-1)}{1 + \frac{V}{F}(K_i-1)} = 0 Parameters ---------- zs : list[float] Overall mole fractions of all species, [-] Ks : list[float] Equilibrium K-values, [-] Returns ------- V_over_F : float Vapor fraction solution [-] xs : list[float] Mole fractions of each species in the liquid phase, [-] ys : list[float] Mole fractions of each species in the vapor phase, [-] Notes ----- The initial guess is the average of the following, as described in [2]_. .. math:: \left(\frac{V}{F}\right)_{min} = \frac{(K_{max}-K_{min})z_{of\;K_{max}} - (1-K_{min})}{(1-K_{min})(K_{max}-1)} \left(\frac{V}{F}\right)_{max} = \frac{1}{1-K_{min}} Another algorithm for determining the range of the correct solution is given in [3]_; [2]_ provides a narrower range however. For both cases, each guess should be limited to be between 0 and 1 as they are often negative or larger than 1. .. math:: \left(\frac{V}{F}\right)_{min} = \frac{1}{1-K_{max}} \left(\frac{V}{F}\right)_{max} = \frac{1}{1-K_{min}} If the `newton` method does not converge, a bisection method (brenth) is used instead. However, it is somewhat slower, especially as newton will attempt 50 iterations before giving up. Examples -------- >>> Rachford_Rice_solution(zs=[0.5, 0.3, 0.2], Ks=[1.685, 0.742, 0.532]) (0.6907302627738542, [0.3394086969663436, 0.3650560590371706, 0.2955352439964858], [0.571903654388289, 0.27087159580558057, 0.15722474980613044]) References ---------- .. [1] Rachford, H. H. Jr, and J. D. Rice. "Procedure for Use of Electronic Digital Computers in Calculating Flash Vaporization Hydrocarbon Equilibrium." Journal of Petroleum Technology 4, no. 10 (October 1, 1952): 19-3. doi:10.2118/952327-G. .. [2] Li, Yinghui, Russell T. Johns, and Kaveh Ahmadi. "A Rapid and Robust Alternative to Rachford-Rice in Flash Calculations." Fluid Phase Equilibria 316 (February 25, 2012): 85-97. doi:10.1016/j.fluid.2011.12.005. .. [3] Whitson, Curtis H., and Michael L. Michelsen. "The Negative Flash." Fluid Phase Equilibria, Proceedings of the Fifth International Conference, 53 (December 1, 1989): 51-71. doi:10.1016/0378-3812(89)80072-X. ''' Kmin = min(Ks) Kmax = max(Ks) z_of_Kmax = zs[Ks.index(Kmax)] V_over_F_min = ((Kmax-Kmin)*z_of_Kmax - (1.-Kmin))/((1.-Kmin)*(Kmax-1.)) V_over_F_max = 1./(1.-Kmin) V_over_F_min2 = max(0., V_over_F_min) V_over_F_max2 = min(1., V_over_F_max) x0 = (V_over_F_min2 + V_over_F_max2)*0.5 try: # Newton's method is marginally faster than brenth V_over_F = newton(Rachford_Rice_flash_error, x0=x0, args=(zs, Ks)) # newton skips out of its specified range in some cases, finding another solution # Check for that with asserts, and use brenth if it did assert V_over_F >= V_over_F_min2 assert V_over_F <= V_over_F_max2 except: V_over_F = brenth(Rachford_Rice_flash_error, V_over_F_max-1E-7, V_over_F_min+1E-7, args=(zs, Ks)) # Cases not covered by the above solvers: When all components have K > 1, or all have K < 1 # Should get a solution for all other cases. xs = [zi/(1.+V_over_F*(Ki-1.)) for zi, Ki in zip(zs, Ks)] ys = [Ki*xi for xi, Ki in zip(xs, Ks)] return V_over_F, xs, ys
def Li_Johns_Ahmadi_solution(zs, Ks): r'''Solves the objective function of the Li-Johns-Ahmadi flash equation. Uses the method proposed in [1]_ to obtain an initial guess. .. math:: 0 = 1 + \left(\frac{K_{max}-K_{min}}{K_{min}-1}\right)x_1 + \sum_{i=2}^{n-1}\frac{K_i-K_{min}}{K_{min}-1}\left[\frac{z_i(K_{max} -1)x_{max}}{(K_i-1)z_{max} + (K_{max}-K_i)x_{max}}\right] Parameters ---------- zs : list[float] Overall mole fractions of all species, [-] Ks : list[float] Equilibrium K-values, [-] Returns ------- V_over_F : float Vapor fraction solution [-] xs : list[float] Mole fractions of each species in the liquid phase, [-] ys : list[float] Mole fractions of each species in the vapor phase, [-] Notes ----- The initial guess is the average of the following, as described in [1]_. Each guess should be limited to be between 0 and 1 as they are often negative or larger than 1. `max` refers to the corresponding mole fractions for the species with the largest K value. .. math:: \left(\frac{1-K_{min}}{K_{max}-K_{min}}\right)z_{max}\le x_{max} \le \left(\frac{1-K_{min}}{K_{max}-K_{min}}\right) If the `newton` method does not converge, a bisection method (brenth) is used instead. However, it is somewhat slower, especially as newton will attempt 50 iterations before giving up. This method does not work for problems of only two components. K values are sorted internally. Has not been found to be quicker than the Rachford-Rice equation. Examples -------- >>> Li_Johns_Ahmadi_solution(zs=[0.5, 0.3, 0.2], Ks=[1.685, 0.742, 0.532]) (0.6907302627738544, [0.33940869696634357, 0.3650560590371706, 0.2955352439964858], [0.5719036543882889, 0.27087159580558057, 0.15722474980613044]) References ---------- .. [1] Li, Yinghui, Russell T. Johns, and Kaveh Ahmadi. "A Rapid and Robust Alternative to Rachford-Rice in Flash Calculations." Fluid Phase Equilibria 316 (February 25, 2012): 85-97. doi:10.1016/j.fluid.2011.12.005. ''' # Re-order both Ks and Zs by K value, higher coming first p = sorted(zip(Ks,zs), reverse=True) Ks_sorted, zs_sorted = [K for (K,z) in p], [z for (K,z) in p] # Largest K value and corresponding overall mole fraction k1 = Ks_sorted[0] z1 = zs_sorted[0] # Smallest K value kn = Ks_sorted[-1] x_min = (1. - kn)/(k1 - kn)*z1 x_max = (1. - kn)/(k1 - kn) x_min2 = max(0., x_min) x_max2 = min(1., x_max) x_guess = (x_min2 + x_max2)*0.5 length = len(zs)-1 kn_m_1 = kn-1. k1_m_1 = (k1-1.) t1 = (k1-kn)/(kn-1.) objective = lambda x1: 1. + t1*x1 + sum([(ki-kn)/(kn_m_1) * zi*k1_m_1*x1 /( (ki-1.)*z1 + (k1-ki)*x1) for ki, zi in zip(Ks_sorted[1:length], zs_sorted[1:length])]) try: x1 = newton(objective, x_guess) # newton skips out of its specified range in some cases, finding another solution # Check for that with asserts, and use brenth if it did # Must also check that V_over_F is right. assert x1 >= x_min2 assert x1 <= x_max2 V_over_F = (-x1 + z1)/(x1*(k1 - 1.)) assert 0 <= V_over_F <= 1 except: x1 = brenth(objective, x_min, x_max) V_over_F = (-x1 + z1)/(x1*(k1 - 1.)) xs = [zi/(1.+V_over_F*(Ki-1.)) for zi, Ki in zip(zs, Ks)] ys = [Ki*xi for xi, Ki in zip(xs, Ks)] return V_over_F, xs, ys
def flash_inner_loop(zs, Ks, AvailableMethods=False, Method=None): r'''This function handles the solution of the inner loop of a flash calculation, solving for liquid and gas mole fractions and vapor fraction based on specified overall mole fractions and K values. As K values are weak functions of composition, this should be called repeatedly by an outer loop. Will automatically select an algorithm to use if no Method is provided. Should always provide a solution. The automatic algorithm selection will try an analytical solution, and use the Rachford-Rice method if there are 4 or more components in the mixture. Parameters ---------- zs : list[float] Overall mole fractions of all species, [-] Ks : list[float] Equilibrium K-values, [-] Returns ------- V_over_F : float Vapor fraction solution [-] xs : list[float] Mole fractions of each species in the liquid phase, [-] ys : list[float] Mole fractions of each species in the vapor phase, [-] methods : list, only returned if AvailableMethods == True List of methods which can be used to obtain a solution with the given inputs Other Parameters ---------------- Method : string, optional The method name to use. Accepted methods are 'Analytical', 'Rachford-Rice', and 'Li-Johns-Ahmadi'. All valid values are also held in the list `flash_inner_loop_methods`. AvailableMethods : bool, optional If True, function will determine which methods can be used to obtain a solution for the desired chemical, and will return methods instead of `V_over_F`, `xs`, and `ys`. Notes ----- A total of three methods are available for this function. They are: * 'Analytical', an exact solution derived with SymPy, applicable only only to mixtures of two or three components * 'Rachford-Rice', which numerically solves an objective function described in :obj:`Rachford_Rice_solution`. * 'Li-Johns-Ahmadi', which numerically solves an objective function described in :obj:`Li_Johns_Ahmadi_solution`. Examples -------- >>> flash_inner_loop(zs=[0.5, 0.3, 0.2], Ks=[1.685, 0.742, 0.532]) (0.6907302627738537, [0.3394086969663437, 0.36505605903717053, 0.29553524399648573], [0.5719036543882892, 0.2708715958055805, 0.1572247498061304]) ''' l = len(zs) def list_methods(): methods = [] if l in [2,3]: methods.append('Analytical') if l >= 2: methods.append('Rachford-Rice') if l >= 3: methods.append('Li-Johns-Ahmadi') return methods if AvailableMethods: return list_methods() if not Method: Method = 'Analytical' if l < 4 else 'Rachford-Rice' if Method == 'Analytical': if l == 2: z1, z2 = zs K1, K2 = Ks V_over_F = (-K1*z1 - K2*z2 + z1 + z2)/(K1*K2*z1 + K1*K2*z2 - K1*z1 - K1*z2 - K2*z1 - K2*z2 + z1 + z2) elif l == 3: z1, z2, z3 = zs K1, K2, K3 = Ks V_over_F = (-K1*K2*z1/2 - K1*K2*z2/2 - K1*K3*z1/2 - K1*K3*z3/2 + K1*z1 + K1*z2/2 + K1*z3/2 - K2*K3*z2/2 - K2*K3*z3/2 + K2*z1/2 + K2*z2 + K2*z3/2 + K3*z1/2 + K3*z2/2 + K3*z3 - z1 - z2 - z3 - (K1**2*K2**2*z1**2 + 2*K1**2*K2**2*z1*z2 + K1**2*K2**2*z2**2 - 2*K1**2*K2*K3*z1**2 - 2*K1**2*K2*K3*z1*z2 - 2*K1**2*K2*K3*z1*z3 + 2*K1**2*K2*K3*z2*z3 - 2*K1**2*K2*z1*z2 + 2*K1**2*K2*z1*z3 - 2*K1**2*K2*z2**2 - 2*K1**2*K2*z2*z3 + K1**2*K3**2*z1**2 + 2*K1**2*K3**2*z1*z3 + K1**2*K3**2*z3**2 + 2*K1**2*K3*z1*z2 - 2*K1**2*K3*z1*z3 - 2*K1**2*K3*z2*z3 - 2*K1**2*K3*z3**2 + K1**2*z2**2 + 2*K1**2*z2*z3 + K1**2*z3**2 - 2*K1*K2**2*K3*z1*z2 + 2*K1*K2**2*K3*z1*z3 - 2*K1*K2**2*K3*z2**2 - 2*K1*K2**2*K3*z2*z3 - 2*K1*K2**2*z1**2 - 2*K1*K2**2*z1*z2 - 2*K1*K2**2*z1*z3 + 2*K1*K2**2*z2*z3 + 2*K1*K2*K3**2*z1*z2 - 2*K1*K2*K3**2*z1*z3 - 2*K1*K2*K3**2*z2*z3 - 2*K1*K2*K3**2*z3**2 + 4*K1*K2*K3*z1**2 + 4*K1*K2*K3*z1*z2 + 4*K1*K2*K3*z1*z3 + 4*K1*K2*K3*z2**2 + 4*K1*K2*K3*z2*z3 + 4*K1*K2*K3*z3**2 + 2*K1*K2*z1*z2 - 2*K1*K2*z1*z3 - 2*K1*K2*z2*z3 - 2*K1*K2*z3**2 - 2*K1*K3**2*z1**2 - 2*K1*K3**2*z1*z2 - 2*K1*K3**2*z1*z3 + 2*K1*K3**2*z2*z3 - 2*K1*K3*z1*z2 + 2*K1*K3*z1*z3 - 2*K1*K3*z2**2 - 2*K1*K3*z2*z3 + K2**2*K3**2*z2**2 + 2*K2**2*K3**2*z2*z3 + K2**2*K3**2*z3**2 + 2*K2**2*K3*z1*z2 - 2*K2**2*K3*z1*z3 - 2*K2**2*K3*z2*z3 - 2*K2**2*K3*z3**2 + K2**2*z1**2 + 2*K2**2*z1*z3 + K2**2*z3**2 - 2*K2*K3**2*z1*z2 + 2*K2*K3**2*z1*z3 - 2*K2*K3**2*z2**2 - 2*K2*K3**2*z2*z3 - 2*K2*K3*z1**2 - 2*K2*K3*z1*z2 - 2*K2*K3*z1*z3 + 2*K2*K3*z2*z3 + K3**2*z1**2 + 2*K3**2*z1*z2 + K3**2*z2**2)**0.5/2)/(K1*K2*K3*z1 + K1*K2*K3*z2 + K1*K2*K3*z3 - K1*K2*z1 - K1*K2*z2 - K1*K2*z3 - K1*K3*z1 - K1*K3*z2 - K1*K3*z3 + K1*z1 + K1*z2 + K1*z3 - K2*K3*z1 - K2*K3*z2 - K2*K3*z3 + K2*z1 + K2*z2 + K2*z3 + K3*z1 + K3*z2 + K3*z3 - z1 - z2 - z3) else: raise Exception('Only solutions of one or two variables are available analytically') xs = [zi/(1.+V_over_F*(Ki-1.)) for zi, Ki in zip(zs, Ks)] ys = [Ki*xi for xi, Ki in zip(xs, Ks)] return V_over_F, xs, ys elif Method == 'Rachford-Rice': return Rachford_Rice_solution(zs=zs, Ks=Ks) elif Method == 'Li-Johns-Ahmadi': return Li_Johns_Ahmadi_solution(zs=zs, Ks=Ks) else: raise Exception('Incorrect Method input')
def NRTL(xs, taus, alphas): r'''Calculates the activity coefficients of each species in a mixture using the Non-Random Two-Liquid (NRTL) method, given their mole fractions, dimensionless interaction parameters, and nonrandomness constants. Those are normally correlated with temperature in some form, and need to be calculated separately. .. math:: \ln(\gamma_i)=\frac{\displaystyle\sum_{j=1}^{n}{x_{j}\tau_{ji}G_{ji}}} {\displaystyle\sum_{k=1}^{n}{x_{k}G_{ki}}}+\sum_{j=1}^{n} {\frac{x_{j}G_{ij}}{\displaystyle\sum_{k=1}^{n}{x_{k}G_{kj}}}} {\left ({\tau_{ij}-\frac{\displaystyle\sum_{m=1}^{n}{x_{m}\tau_{mj} G_{mj}}}{\displaystyle\sum_{k=1}^{n}{x_{k}G_{kj}}}}\right )} G_{ij}=\text{exp}\left ({-\alpha_{ij}\tau_{ij}}\right ) Parameters ---------- xs : list[float] Liquid mole fractions of each species, [-] taus : list[list[float]] Dimensionless interaction parameters of each compound with each other, [-] alphas : list[list[float]] Nonrandomness constants of each compound interacting with each other, [-] Returns ------- gammas : list[float] Activity coefficient for each species in the liquid mixture, [-] Notes ----- This model needs N^2 parameters. One common temperature dependence of the nonrandomness constants is: .. math:: \alpha_{ij}=c_{ij}+d_{ij}T Most correlations for the interaction parameters include some of the terms shown in the following form: .. math:: \tau_{ij}=A_{ij}+\frac{B_{ij}}{T}+\frac{C_{ij}}{T^{2}}+D_{ij} \ln{\left ({T}\right )}+E_{ij}T^{F_{ij}} Examples -------- Ethanol-water example, at 343.15 K and 1 MPa: >>> NRTL(xs=[0.252, 0.748], taus=[[0, -0.178], [1.963, 0]], ... alphas=[[0, 0.2974],[.2974, 0]]) [1.9363183763514304, 1.1537609663170014] References ---------- .. [1] Renon, Henri, and J. M. Prausnitz. "Local Compositions in Thermodynamic Excess Functions for Liquid Mixtures." AIChE Journal 14, no. 1 (1968): 135-144. doi:10.1002/aic.690140124. .. [2] Gmehling, Jurgen, Barbel Kolbe, Michael Kleiber, and Jurgen Rarey. Chemical Thermodynamics for Process Simulation. 1st edition. Weinheim: Wiley-VCH, 2012. ''' gammas = [] cmps = range(len(xs)) Gs = [[exp(-alphas[i][j]*taus[i][j]) for j in cmps] for i in cmps] for i in cmps: tn1, td1, total2 = 0., 0., 0. for j in cmps: # Term 1, numerator and denominator tn1 += xs[j]*taus[j][i]*Gs[j][i] td1 += xs[j]*Gs[j][i] # Term 2 tn2 = xs[j]*Gs[i][j] td2 = td3 = sum([xs[k]*Gs[k][j] for k in cmps]) tn3 = sum([xs[m]*taus[m][j]*Gs[m][j] for m in cmps]) total2 += tn2/td2*(taus[i][j] - tn3/td3) gamma = exp(tn1/td1 + total2) gammas.append(gamma) return gammas
def Wilson(xs, params): r'''Calculates the activity coefficients of each species in a mixture using the Wilson method, given their mole fractions, and dimensionless interaction parameters. Those are normally correlated with temperature, and need to be calculated separately. .. math:: \ln \gamma_i = 1 - \ln \left(\sum_j^N \Lambda_{ij} x_j\right) -\sum_j^N \frac{\Lambda_{ji}x_j}{\displaystyle\sum_k^N \Lambda_{jk}x_k} Parameters ---------- xs : list[float] Liquid mole fractions of each species, [-] params : list[list[float]] Dimensionless interaction parameters of each compound with each other, [-] Returns ------- gammas : list[float] Activity coefficient for each species in the liquid mixture, [-] Notes ----- This model needs N^2 parameters. The original model correlated the interaction parameters using the standard pure-component molar volumes of each species at 25°C, in the following form: .. math:: \Lambda_{ij} = \frac{V_j}{V_i} \exp\left(\frac{-\lambda_{i,j}}{RT}\right) However, that form has less flexibility and offered no advantage over using only regressed parameters. Most correlations for the interaction parameters include some of the terms shown in the following form: .. math:: \ln \Lambda_{ij} =a_{ij}+\frac{b_{ij}}{T}+c_{ij}\ln T + d_{ij}T + \frac{e_{ij}}{T^2} + h_{ij}{T^2} The Wilson model is not applicable to liquid-liquid systems. Examples -------- Ethanol-water example, at 343.15 K and 1 MPa: >>> Wilson([0.252, 0.748], [[1, 0.154], [0.888, 1]]) [1.8814926087178843, 1.1655774931125487] References ---------- .. [1] Wilson, Grant M. "Vapor-Liquid Equilibrium. XI. A New Expression for the Excess Free Energy of Mixing." Journal of the American Chemical Society 86, no. 2 (January 1, 1964): 127-130. doi:10.1021/ja01056a002. .. [2] Gmehling, Jurgen, Barbel Kolbe, Michael Kleiber, and Jurgen Rarey. Chemical Thermodynamics for Process Simulation. 1st edition. Weinheim: Wiley-VCH, 2012. ''' gammas = [] cmps = range(len(xs)) for i in cmps: tot1 = log(sum([params[i][j]*xs[j] for j in cmps])) tot2 = 0. for j in cmps: tot2 += params[j][i]*xs[j]/sum([params[j][k]*xs[k] for k in cmps]) gamma = exp(1. - tot1 - tot2) gammas.append(gamma) return gammas
def UNIQUAC(xs, rs, qs, taus): r'''Calculates the activity coefficients of each species in a mixture using the Universal quasi-chemical (UNIQUAC) equation, given their mole fractions, `rs`, `qs`, and dimensionless interaction parameters. The interaction parameters are normally correlated with temperature, and need to be calculated separately. .. math:: \ln \gamma_i = \ln \frac{\Phi_i}{x_i} + \frac{z}{2} q_i \ln \frac{\theta_i}{\Phi_i}+ l_i - \frac{\Phi_i}{x_i}\sum_j^N x_j l_j - q_i \ln\left( \sum_j^N \theta_j \tau_{ji}\right)+ q_i - q_i\sum_j^N \frac{\theta_j \tau_{ij}}{\sum_k^N \theta_k \tau_{kj}} \theta_i = \frac{x_i q_i}{\displaystyle\sum_{j=1}^{n} x_j q_j} \Phi_i = \frac{x_i r_i}{\displaystyle\sum_{j=1}^{n} x_j r_j} l_i = \frac{z}{2}(r_i - q_i) - (r_i - 1) Parameters ---------- xs : list[float] Liquid mole fractions of each species, [-] rs : list[float] Van der Waals volume parameters for each species, [-] qs : list[float] Surface area parameters for each species, [-] taus : list[list[float]] Dimensionless interaction parameters of each compound with each other, [-] Returns ------- gammas : list[float] Activity coefficient for each species in the liquid mixture, [-] Notes ----- This model needs N^2 parameters. The original expression for the interaction parameters is as follows: .. math:: \tau_{ji} = \exp\left(\frac{-\Delta u_{ij}}{RT}\right) However, it is seldom used. Most correlations for the interaction parameters include some of the terms shown in the following form: .. math:: \ln \tau{ij} =a_{ij}+\frac{b_{ij}}{T}+c_{ij}\ln T + d_{ij}T + \frac{e_{ij}}{T^2} This model is recast in a slightly more computationally efficient way in [2]_, as shown below: .. math:: \ln \gamma_i = \ln \gamma_i^{res} + \ln \gamma_i^{comb} \ln \gamma_i^{res} = q_i \left(1 - \ln\frac{\sum_j^N q_j x_j \tau_{ji}} {\sum_j^N q_j x_j}- \sum_j \frac{q_k x_j \tau_{ij}}{\sum_k q_k x_k \tau_{kj}}\right) \ln \gamma_i^{comb} = (1 - V_i + \ln V_i) - \frac{z}{2}q_i\left(1 - \frac{V_i}{F_i} + \ln \frac{V_i}{F_i}\right) V_i = \frac{r_i}{\sum_j^N r_j x_j} F_i = \frac{q_i}{\sum_j q_j x_j} Examples -------- Ethanol-water example, at 343.15 K and 1 MPa: >>> UNIQUAC(xs=[0.252, 0.748], rs=[2.1055, 0.9200], qs=[1.972, 1.400], ... taus=[[1.0, 1.0919744384510301], [0.37452902779205477, 1.0]]) [2.35875137797083, 1.2442093415968987] References ---------- .. [1] Abrams, Denis S., and John M. Prausnitz. "Statistical Thermodynamics of Liquid Mixtures: A New Expression for the Excess Gibbs Energy of Partly or Completely Miscible Systems." AIChE Journal 21, no. 1 (January 1, 1975): 116-28. doi:10.1002/aic.690210115. .. [2] Gmehling, Jurgen, Barbel Kolbe, Michael Kleiber, and Jurgen Rarey. Chemical Thermodynamics for Process Simulation. 1st edition. Weinheim: Wiley-VCH, 2012. .. [3] Maurer, G., and J. M. Prausnitz. "On the Derivation and Extension of the Uniquac Equation." Fluid Phase Equilibria 2, no. 2 (January 1, 1978): 91-99. doi:10.1016/0378-3812(78)85002-X. ''' cmps = range(len(xs)) rsxs = sum([rs[i]*xs[i] for i in cmps]) phis = [rs[i]*xs[i]/rsxs for i in cmps] qsxs = sum([qs[i]*xs[i] for i in cmps]) vs = [qs[i]*xs[i]/qsxs for i in cmps] Ss = [sum([vs[j]*taus[j][i] for j in cmps]) for i in cmps] loggammacs = [log(phis[i]/xs[i]) + 1 - phis[i]/xs[i] - 5*qs[i]*(log(phis[i]/vs[i]) + 1 - phis[i]/vs[i]) for i in cmps] loggammars = [qs[i]*(1 - log(Ss[i]) - sum([taus[i][j]*vs[j]/Ss[j] for j in cmps])) for i in cmps] return [exp(loggammacs[i] + loggammars[i]) for i in cmps]
def bubble_at_T(zs, Psats, fugacities=None, gammas=None): ''' >>> bubble_at_T([0.5, 0.5], [1400, 7000]) 4200.0 >>> bubble_at_T([0.5, 0.5], [1400, 7000], gammas=[1.1, .75]) 3395.0 >>> bubble_at_T([0.5, 0.5], [1400, 7000], gammas=[1.1, .75], fugacities=[.995, 0.98]) 3452.440775305097 ''' if not fugacities: fugacities = [1 for i in range(len(Psats))] if not gammas: gammas = [1 for i in range(len(Psats))] if not none_and_length_check((zs, Psats, fugacities, gammas)): raise Exception('Input dimentions are inconsistent or some input parameters are missing.') P = sum(zs[i]*Psats[i]*gammas[i]/fugacities[i] for i in range(len(zs))) return P
def identify_phase(T, P, Tm=None, Tb=None, Tc=None, Psat=None): r'''Determines the phase of a one-species chemical system according to basic rules, using whatever information is available. Considers only the phases liquid, solid, and gas; does not consider two-phase scenarios, as should occurs between phase boundaries. * If the melting temperature is known and the temperature is under or equal to it, consider it a solid. * If the critical temperature is known and the temperature is greater or equal to it, consider it a gas. * If the vapor pressure at `T` is known and the pressure is under or equal to it, consider it a gas. If the pressure is greater than the vapor pressure, consider it a liquid. * If the melting temperature, critical temperature, and vapor pressure are not known, attempt to use the boiling point to provide phase information. If the pressure is between 90 kPa and 110 kPa (approximately normal), consider it a liquid if it is under the boiling temperature and a gas if above the boiling temperature. * If the pressure is above 110 kPa and the boiling temperature is known, consider it a liquid if the temperature is under the boiling temperature. * Return None otherwise. Parameters ---------- T : float Temperature, [K] P : float Pressure, [Pa] Tm : float, optional Normal melting temperature, [K] Tb : float, optional Normal boiling point, [K] Tc : float, optional Critical temperature, [K] Psat : float, optional Vapor pressure of the fluid at `T`, [Pa] Returns ------- phase : str Either 's', 'l', 'g', or None if the phase cannot be determined Notes ----- No special attential is paid to any phase transition. For the case where the melting point is not provided, the possibility of the fluid being solid is simply ignored. Examples -------- >>> identify_phase(T=280, P=101325, Tm=273.15, Psat=991) 'l' ''' if Tm and T <= Tm: return 's' elif Tc and T >= Tc: # No special return value for the critical point return 'g' elif Psat: # Do not allow co-existence of phases; transition to 'l' directly under if P <= Psat: return 'g' elif P > Psat: return 'l' elif Tb: # Crude attempt to model phases without Psat # Treat Tb as holding from 90 kPa to 110 kPa if 9E4 < P < 1.1E5: if T < Tb: return 'l' else: return 'g' elif P > 1.1E5 and T <= Tb: # For the higher-pressure case, it is definitely liquid if under Tb # Above the normal boiling point, impossible to say - return None return 'l' else: return None else: return None
def identify_phase_mixture(T=None, P=None, zs=None, Tcs=None, Pcs=None, Psats=None, CASRNs=None, AvailableMethods=False, Method=None): # pragma: no cover ''' >>> identify_phase_mixture(T=280, P=5000., zs=[0.5, 0.5], Psats=[1400, 7000]) ('l', [0.5, 0.5], None, 0) >>> identify_phase_mixture(T=280, P=3000., zs=[0.5, 0.5], Psats=[1400, 7000]) ('two-phase', [0.7142857142857143, 0.2857142857142857], [0.33333333333333337, 0.6666666666666666], 0.5625000000000001) >>> identify_phase_mixture(T=280, P=800., zs=[0.5, 0.5], Psats=[1400, 7000]) ('g', None, [0.5, 0.5], 1) >>> identify_phase_mixture(T=280, P=800., zs=[0.5, 0.5]) (None, None, None, None) ''' def list_methods(): methods = [] if Psats and none_and_length_check((Psats, zs)): methods.append('IDEAL_VLE') if Tcs and none_and_length_check([Tcs]) and all([T >= i for i in Tcs]): methods.append('SUPERCRITICAL_T') if Pcs and none_and_length_check([Pcs]) and all([P >= i for i in Pcs]): methods.append('SUPERCRITICAL_P') if Tcs and none_and_length_check([zs, Tcs]) and any([T > Tc for Tc in Tcs]): methods.append('IDEAL_VLE_SUPERCRITICAL') 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 xs, ys, phase, V_over_F = None, None, None, None if Method == 'IDEAL_VLE': Pdew = dew_at_T(zs, Psats) Pbubble = bubble_at_T(zs, Psats) if P >= Pbubble: phase = 'l' ys = None xs = zs V_over_F = 0 elif P <= Pdew: phase = 'g' ys = zs xs = None V_over_F = 1 elif Pdew < P < Pbubble: xs, ys, V_over_F = flash(P, zs, Psats) phase = 'two-phase' elif Method == 'SUPERCRITICAL_T': if all([T >= i for i in Tcs]): phase = 'g' else: # The following is nonsensical phase = 'two-phase' elif Method == 'SUPERCRITICAL_P': if all([P >= i for i in Pcs]): phase = 'g' else: # The following is nonsensical phase = 'two-phase' elif Method == 'IDEAL_VLE_SUPERCRITICAL': Psats = list(Psats) for i in range(len(Psats)): if not Psats[i] and Tcs[i] and Tcs[i] <= T: Psats[i] = 1E8 Pdew = dew_at_T(zs, Psats) Pbubble = 1E99 if P >= Pbubble: phase = 'l' ys = None xs = zs V_over_F = 0 elif P <= Pdew: phase = 'g' ys = zs xs = None V_over_F = 1 elif Pdew < P < Pbubble: xs, ys, V_over_F = flash(P, zs, Psats) phase = 'two-phase' elif Method == 'NONE': pass else: raise Exception('Failure in in function') return phase, xs, ys, V_over_F
def Pbubble_mixture(T=None, zs=None, Psats=None, CASRNs=None, AvailableMethods=False, Method=None): # pragma: no cover ''' >>> Pbubble_mixture(zs=[0.5, 0.5], Psats=[1400, 7000]) 4200.0 ''' def list_methods(): methods = [] if none_and_length_check((Psats, zs)): methods.append('IDEAL_VLE') 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 == 'IDEAL_VLE': Pbubble = bubble_at_T(zs, Psats) elif Method == 'NONE': Pbubble = None else: raise Exception('Failure in in function') return Pbubble
def bubble_at_P(P, zs, vapor_pressure_eqns, fugacities=None, gammas=None): '''Calculates bubble point for a given pressure Parameters ---------- P : float Pressure, [Pa] zs : list[float] Overall mole fractions of all species, [-] vapor_pressure_eqns : list[functions] Temperature dependent function for each specie, Returns Psat, [Pa] fugacities : list[float], optional fugacities of each species, defaults to list of ones, [-] gammas : list[float], optional gammas of each species, defaults to list of ones, [-] Returns ------- Tbubble : float, optional Temperature of bubble point at pressure `P`, [K] ''' def bubble_P_error(T): Psats = [VP(T) for VP in vapor_pressure_eqns] Pcalc = bubble_at_T(zs, Psats, fugacities, gammas) return P - Pcalc T_bubble = newton(bubble_P_error, 300) return T_bubble
def Pdew_mixture(T=None, zs=None, Psats=None, CASRNs=None, AvailableMethods=False, Method=None): # pragma: no cover ''' >>> Pdew_mixture(zs=[0.5, 0.5], Psats=[1400, 7000]) 2333.3333333333335 ''' def list_methods(): methods = [] if none_and_length_check((Psats, zs)): methods.append('IDEAL_VLE') 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 == 'IDEAL_VLE': Pdew = dew_at_T(zs, Psats) elif Method == 'NONE': Pdew = None else: raise Exception('Failure in in function') return Pdew
def draw_2d(self, width=300, height=300, Hs=False): # pragma: no cover r'''Interface for drawing a 2D image of the molecule. Requires an HTML5 browser, and the libraries RDKit and IPython. An exception is raised if either of these libraries is absent. Parameters ---------- width : int Number of pixels wide for the view height : int Number of pixels tall for the view Hs : bool Whether or not to show hydrogen Examples -------- >>> Chemical('decane').draw_2d() # doctest: +ELLIPSIS <PIL.Image.Image image mode=RGBA size=300x300 at 0x...> ''' try: from rdkit.Chem import Draw from rdkit.Chem.Draw import IPythonConsole if Hs: mol = self.rdkitmol_Hs else: mol = self.rdkitmol return Draw.MolToImage(mol, size=(width, height)) except: return 'Rdkit is required for this feature.'
def draw_3d(self, width=300, height=500, style='stick', Hs=True): # pragma: no cover r'''Interface for drawing an interactive 3D view of the molecule. Requires an HTML5 browser, and the libraries RDKit, pymol3D, and IPython. An exception is raised if all three of these libraries are not installed. Parameters ---------- width : int Number of pixels wide for the view height : int Number of pixels tall for the view style : str One of 'stick', 'line', 'cross', or 'sphere' Hs : bool Whether or not to show hydrogen Examples -------- >>> Chemical('cubane').draw_3d() <IPython.core.display.HTML object> ''' try: import py3Dmol from IPython.display import display if Hs: mol = self.rdkitmol_Hs else: mol = self.rdkitmol AllChem.EmbedMultipleConfs(mol) mb = Chem.MolToMolBlock(mol) p = py3Dmol.view(width=width,height=height) p.addModel(mb,'sdf') p.setStyle({style:{}}) p.zoomTo() display(p.show()) except: return 'py3Dmol, RDKit, and IPython are required for this feature.'
def Um(self): r'''Internal energy of the chemical at its current temperature and pressure, in units of [J/mol]. This property requires that :obj:`thermo.chemical.set_thermo` ran successfully to be accurate. It also depends on the molar volume of the chemical at its current conditions. ''' return self.Hm - self.P*self.Vm if (self.Vm and self.Hm is not None) else None
def Am(self): r'''Helmholtz energy of the chemical at its current temperature and pressure, in units of [J/mol]. This property requires that :obj:`thermo.chemical.set_thermo` ran successfully to be accurate. It also depends on the molar volume of the chemical at its current conditions. ''' return self.Um - self.T*self.Sm if (self.Um is not None and self.Sm is not None) else None
def A(self): r'''Helmholtz energy of the chemical at its current temperature and pressure, in units of [J/kg]. This property requires that :obj:`thermo.chemical.set_thermo` ran successfully to be accurate. It also depends on the molar volume of the chemical at its current conditions. ''' return self.U - self.T*self.S if (self.U is not None and self.S is not None) else None
def charge(self): r'''Charge of a chemical, computed with RDKit from a chemical's SMILES. If RDKit is not available, holds None. Examples -------- >>> Chemical('sodium ion').charge 1 ''' try: if not self.rdkitmol: return charge_from_formula(self.formula) else: return Chem.GetFormalCharge(self.rdkitmol) except: return charge_from_formula(self.formula)
def rdkitmol(self): r'''RDKit object of the chemical, without hydrogen. If RDKit is not available, holds None. For examples of what can be done with RDKit, see `their website <http://www.rdkit.org/docs/GettingStartedInPython.html>`_. ''' if self.__rdkitmol: return self.__rdkitmol else: try: self.__rdkitmol = Chem.MolFromSmiles(self.smiles) return self.__rdkitmol except: return None
def rdkitmol_Hs(self): r'''RDKit object of the chemical, with hydrogen. If RDKit is not available, holds None. For examples of what can be done with RDKit, see `their website <http://www.rdkit.org/docs/GettingStartedInPython.html>`_. ''' if self.__rdkitmol_Hs: return self.__rdkitmol_Hs else: try: self.__rdkitmol_Hs = Chem.AddHs(self.rdkitmol) return self.__rdkitmol_Hs except: return None
def Hill(self): r'''Hill formula of a compound. For a description of the Hill system, see :obj:`thermo.elements.atoms_to_Hill`. Examples -------- >>> Chemical('furfuryl alcohol').Hill 'C5H6O2' ''' if self.__Hill: return self.__Hill else: self.__Hill = atoms_to_Hill(self.atoms) return self.__Hill
def atom_fractions(self): r'''Dictionary of atom:fractional occurence of the elements in a chemical. Useful when performing element balances. For mass-fraction occurences, see :obj:`mass_fractions`. Examples -------- >>> Chemical('Ammonium aluminium sulfate').atom_fractions {'H': 0.25, 'S': 0.125, 'Al': 0.0625, 'O': 0.5, 'N': 0.0625} ''' if self.__atom_fractions: return self.__atom_fractions else: self.__atom_fractions = atom_fractions(self.atoms) return self.__atom_fractions
def mass_fractions(self): r'''Dictionary of atom:mass-weighted fractional occurence of elements. Useful when performing mass balances. For atom-fraction occurences, see :obj:`atom_fractions`. Examples -------- >>> Chemical('water').mass_fractions {'H': 0.11189834407236524, 'O': 0.8881016559276347} ''' if self.__mass_fractions: return self.__mass_fractions else: self.__mass_fractions = mass_fractions(self.atoms, self.MW) return self.__mass_fractions
def legal_status(self): r'''Dictionary of legal status indicators for the chemical. Examples -------- >>> pprint(Chemical('benzene').legal_status) {'DSL': 'LISTED', 'EINECS': 'LISTED', 'NLP': 'UNLISTED', 'SPIN': 'LISTED', 'TSCA': 'LISTED'} ''' if self.__legal_status: return self.__legal_status else: self.__legal_status = legal_status(self.CAS, Method='COMBINED') return self.__legal_status
def economic_status(self): r'''Dictionary of economic status indicators for the chemical. Examples -------- >>> pprint(Chemical('benzene').economic_status) ["US public: {'Manufactured': 6165232.1, 'Imported': 463146.474, 'Exported': 271908.252}", u'1,000,000 - 10,000,000 tonnes per annum', u'Intermediate Use Only', 'OECD HPV Chemicals'] ''' if self.__economic_status: return self.__economic_status else: self.__economic_status = economic_status(self.CAS, Method='Combined') return self.__economic_status
def UNIFAC_groups(self): r'''Dictionary of UNIFAC subgroup: count groups for the original UNIFAC subgroups, as determined by `DDBST's online service <http://www.ddbst.com/unifacga.html>`_. Examples -------- >>> pprint(Chemical('Cumene').UNIFAC_groups) {1: 2, 9: 5, 13: 1} ''' if self.__UNIFAC_groups: return self.__UNIFAC_groups else: load_group_assignments_DDBST() if self.InChI_Key in DDBST_UNIFAC_assignments: self.__UNIFAC_groups = DDBST_UNIFAC_assignments[self.InChI_Key] return self.__UNIFAC_groups else: return None
def UNIFAC_Dortmund_groups(self): r'''Dictionary of Dortmund UNIFAC subgroup: count groups for the Dortmund UNIFAC subgroups, as determined by `DDBST's online service <http://www.ddbst.com/unifacga.html>`_. Examples -------- >>> pprint(Chemical('Cumene').UNIFAC_Dortmund_groups) {1: 2, 9: 5, 13: 1} ''' if self.__UNIFAC_Dortmund_groups: return self.__UNIFAC_Dortmund_groups else: load_group_assignments_DDBST() if self.InChI_Key in DDBST_MODIFIED_UNIFAC_assignments: self.__UNIFAC_Dortmund_groups = DDBST_MODIFIED_UNIFAC_assignments[self.InChI_Key] return self.__UNIFAC_Dortmund_groups else: return None
def PSRK_groups(self): r'''Dictionary of PSRK subgroup: count groups for the PSRK subgroups, as determined by `DDBST's online service <http://www.ddbst.com/unifacga.html>`_. Examples -------- >>> pprint(Chemical('Cumene').PSRK_groups) {1: 2, 9: 5, 13: 1} ''' if self.__PSRK_groups: return self.__PSRK_groups else: load_group_assignments_DDBST() if self.InChI_Key in DDBST_PSRK_assignments: self.__PSRK_groups = DDBST_PSRK_assignments[self.InChI_Key] return self.__PSRK_groups else: return None
def Hvap(self): r'''Enthalpy of vaporization of the chemical at its current temperature, in units of [J/kg]. This property uses the object-oriented interface :obj:`thermo.phase_change.EnthalpyVaporization`, but converts its results from molar to mass units. Examples -------- >>> Chemical('water', T=320).Hvap 2389540.219347256 ''' Hvamp = self.Hvapm if Hvamp: return property_molar_to_mass(Hvamp, self.MW) return None
def Cps(self): r'''Solid-phase heat capacity of the chemical at its current temperature, in units of [J/kg/K]. For calculation of this property at other temperatures, or specifying manually the method used to calculate it, and more - see the object oriented interface :obj:`thermo.heat_capacity.HeatCapacitySolid`; each Chemical instance creates one to actually perform the calculations. Note that that interface provides output in molar units. Examples -------- >>> Chemical('palladium', T=400).Cps 241.63563239992484 >>> Pd = Chemical('palladium', T=400) >>> Cpsms = [Pd.HeatCapacitySolid.T_dependent_property(T) for T in np.linspace(300,500, 5)] >>> [property_molar_to_mass(Cps, Pd.MW) for Cps in Cpsms] [234.40150347679008, 238.01856793835751, 241.63563239992484, 245.25269686149224, 248.86976132305958] ''' Cpsm = self.HeatCapacitySolid(self.T) if Cpsm: return property_molar_to_mass(Cpsm, self.MW) return None
def Cpl(self): r'''Liquid-phase heat capacity of the chemical at its current temperature, in units of [J/kg/K]. For calculation of this property at other temperatures, or specifying manually the method used to calculate it, and more - see the object oriented interface :obj:`thermo.heat_capacity.HeatCapacityLiquid`; each Chemical instance creates one to actually perform the calculations. Note that that interface provides output in molar units. Examples -------- >>> Chemical('water', T=320).Cpl 4177.518996988284 Ideal entropy change of water from 280 K to 340 K, output converted back to mass-based units of J/kg/K. >>> dSm = Chemical('water').HeatCapacityLiquid.T_dependent_property_integral_over_T(280, 340) >>> property_molar_to_mass(dSm, Chemical('water').MW) 812.1024585274956 ''' Cplm = self.HeatCapacityLiquid(self.T) if Cplm: return property_molar_to_mass(Cplm, self.MW) return None
def Cpg(self): r'''Gas-phase heat capacity of the chemical at its current temperature, in units of [J/kg/K]. For calculation of this property at other temperatures, or specifying manually the method used to calculate it, and more - see the object oriented interface :obj:`thermo.heat_capacity.HeatCapacityGas`; each Chemical instance creates one to actually perform the calculations. Note that that interface provides output in molar units. Examples -------- >>> w = Chemical('water', T=520) >>> w.Cpg 1967.6698314620658 ''' Cpgm = self.HeatCapacityGas(self.T) if Cpgm: return property_molar_to_mass(Cpgm, self.MW) return None
def Cvgm(self): r'''Gas-phase ideal-gas contant-volume heat capacity of the chemical at its current temperature, in units of [J/mol/K]. Subtracts R from the ideal-gas heat capacity; does not include pressure-compensation from an equation of state. Examples -------- >>> w = Chemical('water', T=520) >>> w.Cvgm 27.13366316134193 ''' Cpgm = self.HeatCapacityGas(self.T) if Cpgm: return Cpgm - R return None
def Cvg(self): r'''Gas-phase ideal-gas contant-volume heat capacity of the chemical at its current temperature, in units of [J/kg/K]. Subtracts R from the ideal-gas heat capacity; does not include pressure-compensation from an equation of state. Examples -------- >>> w = Chemical('water', T=520) >>> w.Cvg 1506.1471795798861 ''' Cvgm = self.Cvgm if Cvgm: return property_molar_to_mass(Cvgm, self.MW) return None
def isentropic_exponent(self): r'''Gas-phase ideal-gas isentropic exponent of the chemical at its current temperature, [dimensionless]. Does not include pressure-compensation from an equation of state. Examples -------- >>> Chemical('hydrogen').isentropic_exponent 1.405237786321222 ''' Cp, Cv = self.Cpg, self.Cvg if all((Cp, Cv)): return isentropic_exponent(Cp, Cv) return None
def rhos(self): r'''Solid-phase mass density of the chemical at its current temperature, in units of [kg/m^3]. For calculation of this property at other temperatures, or specifying manually the method used to calculate it, and more - see the object oriented interface :obj:`thermo.volume.VolumeSolid`; each Chemical instance creates one to actually perform the calculations. Note that that interface provides output in molar units. Examples -------- >>> Chemical('iron').rhos 7869.999999999994 ''' Vms = self.Vms if Vms: return Vm_to_rho(Vms, self.MW) return None
def rhol(self): r'''Liquid-phase mass density of the chemical at its current temperature and pressure, in units of [kg/m^3]. For calculation of this property at other temperatures and pressures, or specifying manually the method used to calculate it, and more - see the object oriented interface :obj:`thermo.volume.VolumeLiquid`; each Chemical instance creates one to actually perform the calculations. Note that that interface provides output in molar units. Examples -------- >>> Chemical('o-xylene', T=297).rhol 876.9946785618097 ''' Vml = self.Vml if Vml: return Vm_to_rho(Vml, self.MW) return None
def rhog(self): r'''Gas-phase mass density of the chemical at its current temperature and pressure, in units of [kg/m^3]. For calculation of this property at other temperatures or pressures, or specifying manually the method used to calculate it, and more - see the object oriented interface :obj:`thermo.volume.VolumeGas`; each Chemical instance creates one to actually perform the calculations. Note that that interface provides output in molar units. Examples -------- Estimate the density of the core of the sun, at 15 million K and 26.5 PetaPascals, assuming pure helium (actually 68% helium): >>> Chemical('helium', T=15E6, P=26.5E15).rhog 8329.27226509739 Compared to a result on `Wikipedia <https://en.wikipedia.org/wiki/Solar_core>`_ of 150000 kg/m^3, the fundamental equation of state performs poorly. >>> He = Chemical('helium', T=15E6, P=26.5E15) >>> He.VolumeGas.set_user_methods_P(['IDEAL']); He.rhog 850477.8065477367 The ideal-gas law performs somewhat better, but vastly overshoots the density prediction. ''' Vmg = self.Vmg if Vmg: return Vm_to_rho(Vmg, self.MW) return None
def Zs(self): r'''Compressibility factor of the chemical in the solid phase at the current temperature and pressure, [dimensionless]. Utilizes the object oriented interface and :obj:`thermo.volume.VolumeSolid` to perform the actual calculation of molar volume. Examples -------- >>> Chemical('palladium').Z 0.00036248477437931853 ''' Vms = self.Vms if Vms: return Z(self.T, self.P, Vms) return None
def Zl(self): r'''Compressibility factor of the chemical in the liquid phase at the current temperature and pressure, [dimensionless]. Utilizes the object oriented interface and :obj:`thermo.volume.VolumeLiquid` to perform the actual calculation of molar volume. Examples -------- >>> Chemical('water').Zl 0.0007385375470263454 ''' Vml = self.Vml if Vml: return Z(self.T, self.P, Vml) return None
def Zg(self): r'''Compressibility factor of the chemical in the gas phase at the current temperature and pressure, [dimensionless]. Utilizes the object oriented interface and :obj:`thermo.volume.VolumeGas` to perform the actual calculation of molar volume. Examples -------- >>> Chemical('sulfur hexafluoride', T=700, P=1E9).Zg 11.140084184207813 ''' Vmg = self.Vmg if Vmg: return Z(self.T, self.P, Vmg) return None
def SGg(self): r'''Specific gravity of the gas phase of the chemical, [dimensionless]. The reference condition is air at 15.6 °C (60 °F) and 1 atm (rho=1.223 kg/m^3). The definition for gases uses the compressibility factor of the reference gas and the chemical both at the reference conditions, not the conditions of the chemical. Examples -------- >>> Chemical('argon').SGg 1.3795835970877504 ''' Vmg = self.VolumeGas(T=288.70555555555552, P=101325) if Vmg: rho = Vm_to_rho(Vmg, self.MW) return SG(rho, rho_ref=1.2231876628642968) # calculated with Mixture return None
def API(self): r'''API gravity of the liquid phase of the chemical, [degrees]. The reference condition is water at 15.6 °C (60 °F) and 1 atm (rho=999.016 kg/m^3, standardized). Examples -------- >>> Chemical('water').API 9.999752435378895 ''' Vml = self.VolumeLiquid(T=288.70555555555552, P=101325) if Vml: rho = Vm_to_rho(Vml, self.MW) sg = SG(rho, rho_ref=999.016) return SG_to_API(sg)
def Bvirial(self): r'''Second virial coefficient of the gas phase of the chemical at its current temperature and pressure, in units of [mol/m^3]. This property uses the object-oriented interface :obj:`thermo.volume.VolumeGas`, converting its result with :obj:`thermo.utils.B_from_Z`. Examples -------- >>> Chemical('water').Bvirial -0.0009596286322838357 ''' if self.Vmg: return B_from_Z(self.Zg, self.T, self.P) return None
def isobaric_expansion_l(self): r'''Isobaric (constant-pressure) expansion of the liquid phase of the chemical at its current temperature and pressure, in units of [1/K]. .. math:: \beta = \frac{1}{V}\left(\frac{\partial V}{\partial T} \right)_P Utilizes the temperature-derivative method of :obj:`thermo.volume.VolumeLiquid` to perform the actual calculation. The derivatives are all numerical. Examples -------- >>> Chemical('dodecane', T=400).isobaric_expansion_l 0.0011617555762469477 ''' dV_dT = self.VolumeLiquid.TP_dependent_property_derivative_T(self.T, self.P) Vm = self.Vml if dV_dT and Vm: return isobaric_expansion(V=Vm, dV_dT=dV_dT)
def isobaric_expansion_g(self): r'''Isobaric (constant-pressure) expansion of the gas phase of the chemical at its current temperature and pressure, in units of [1/K]. .. math:: \beta = \frac{1}{V}\left(\frac{\partial V}{\partial T} \right)_P Utilizes the temperature-derivative method of :obj:`thermo.VolumeGas` to perform the actual calculation. The derivatives are all numerical. Examples -------- >>> Chemical('Hexachlorobenzene', T=900).isobaric_expansion_g 0.001151869741981048 ''' dV_dT = self.VolumeGas.TP_dependent_property_derivative_T(self.T, self.P) Vm = self.Vmg if dV_dT and Vm: return isobaric_expansion(V=Vm, dV_dT=dV_dT)
def JTl(self): r'''Joule Thomson coefficient of the chemical in the liquid phase at its current temperature and pressure, in units of [K/Pa]. .. math:: \mu_{JT} = \left(\frac{\partial T}{\partial P}\right)_H = \frac{1}{C_p} \left[T \left(\frac{\partial V}{\partial T}\right)_P - V\right] = \frac{V}{C_p}\left(\beta T-1\right) Utilizes the temperature-derivative method of :obj:`thermo.volume.VolumeLiquid` and the temperature-dependent heat capacity method :obj:`thermo.heat_capacity.HeatCapacityLiquid` to obtain the properties required for the actual calculation. Examples -------- >>> Chemical('dodecane', T=400).JTl -3.0827160465192742e-07 ''' Vml, Cplm, isobaric_expansion_l = self.Vml, self.Cplm, self.isobaric_expansion_l if all((Vml, Cplm, isobaric_expansion_l)): return Joule_Thomson(T=self.T, V=Vml, Cp=Cplm, beta=isobaric_expansion_l) return None
def JTg(self): r'''Joule Thomson coefficient of the chemical in the gas phase at its current temperature and pressure, in units of [K/Pa]. .. math:: \mu_{JT} = \left(\frac{\partial T}{\partial P}\right)_H = \frac{1}{C_p} \left[T \left(\frac{\partial V}{\partial T}\right)_P - V\right] = \frac{V}{C_p}\left(\beta T-1\right) Utilizes the temperature-derivative method of :obj:`thermo.volume.VolumeGas` and the temperature-dependent heat capacity method :obj:`thermo.heat_capacity.HeatCapacityGas` to obtain the properties required for the actual calculation. Examples -------- >>> Chemical('dodecane', T=400, P=1000).JTg 5.4089897835384913e-05 ''' Vmg, Cpgm, isobaric_expansion_g = self.Vmg, self.Cpgm, self.isobaric_expansion_g if all((Vmg, Cpgm, isobaric_expansion_g)): return Joule_Thomson(T=self.T, V=Vmg, Cp=Cpgm, beta=isobaric_expansion_g) return None
def nul(self): r'''Kinematic viscosity of the liquid phase of the chemical at its current temperature and pressure, in units of [m^2/s]. .. math:: \nu = \frac{\mu}{\rho} Utilizes the temperature and pressure dependent object oriented interfaces :obj:`thermo.volume.VolumeLiquid`, :obj:`thermo.viscosity.ViscosityLiquid` to calculate the actual properties. Examples -------- >>> Chemical('methane', T=110).nul 2.858088468937331e-07 ''' mul, rhol = self.mul, self.rhol if all([mul, rhol]): return nu_mu_converter(mu=mul, rho=rhol) return None
def nug(self): r'''Kinematic viscosity of the gas phase of the chemical at its current temperature and pressure, in units of [m^2/s]. .. math:: \nu = \frac{\mu}{\rho} Utilizes the temperature and pressure dependent object oriented interfaces :obj:`thermo.volume.VolumeGas`, :obj:`thermo.viscosity.ViscosityGas` to calculate the actual properties. Examples -------- >>> Chemical('methane', T=115).nug 2.5056924327995865e-06 ''' mug, rhog = self.mug, self.rhog if all([mug, rhog]): return nu_mu_converter(mu=mug, rho=rhog) return None
def alphal(self): r'''Thermal diffusivity of the liquid phase of the chemical at its current temperature and pressure, in units of [m^2/s]. .. math:: \alpha = \frac{k}{\rho Cp} Utilizes the temperature and pressure dependent object oriented interfaces :obj:`thermo.volume.VolumeLiquid`, :obj:`thermo.thermal_conductivity.ThermalConductivityLiquid`, and :obj:`thermo.heat_capacity.HeatCapacityLiquid` to calculate the actual properties. Examples -------- >>> Chemical('nitrogen', T=70).alphal 9.444949636299626e-08 ''' kl, rhol, Cpl = self.kl, self.rhol, self.Cpl if all([kl, rhol, Cpl]): return thermal_diffusivity(k=kl, rho=rhol, Cp=Cpl) return None
def alphag(self): r'''Thermal diffusivity of the gas phase of the chemical at its current temperature and pressure, in units of [m^2/s]. .. math:: \alpha = \frac{k}{\rho Cp} Utilizes the temperature and pressure dependent object oriented interfaces :obj:`thermo.volume.VolumeGas`, :obj:`thermo.thermal_conductivity.ThermalConductivityGas`, and :obj:`thermo.heat_capacity.HeatCapacityGas` to calculate the actual properties. Examples -------- >>> Chemical('ammonia').alphag 1.6931865425158556e-05 ''' kg, rhog, Cpg = self.kg, self.rhog, self.Cpg if all([kg, rhog, Cpg]): return thermal_diffusivity(k=kg, rho=rhog, Cp=Cpg) return None
def Prl(self): r'''Prandtl number of the liquid phase of the chemical at its current temperature and pressure, [dimensionless]. .. math:: Pr = \frac{C_p \mu}{k} Utilizes the temperature and pressure dependent object oriented interfaces :obj:`thermo.viscosity.ViscosityLiquid`, :obj:`thermo.thermal_conductivity.ThermalConductivityLiquid`, and :obj:`thermo.heat_capacity.HeatCapacityLiquid` to calculate the actual properties. Examples -------- >>> Chemical('nitrogen', T=70).Prl 2.7828214501488886 ''' Cpl, mul, kl = self.Cpl, self.mul, self.kl if all([Cpl, mul, kl]): return Prandtl(Cp=Cpl, mu=mul, k=kl) return None
def Prg(self): r'''Prandtl number of the gas phase of the chemical at its current temperature and pressure, [dimensionless]. .. math:: Pr = \frac{C_p \mu}{k} Utilizes the temperature and pressure dependent object oriented interfaces :obj:`thermo.viscosity.ViscosityGas`, :obj:`thermo.thermal_conductivity.ThermalConductivityGas`, and :obj:`thermo.heat_capacity.HeatCapacityGas` to calculate the actual properties. Examples -------- >>> Chemical('NH3').Prg 0.847263731933008 ''' Cpg, mug, kg = self.Cpg, self.mug, self.kg if all([Cpg, mug, kg]): return Prandtl(Cp=Cpg, mu=mug, k=kg) return None
def solubility_parameter(self): r'''Solubility parameter of the chemical at its current temperature and pressure, in units of [Pa^0.5]. .. math:: \delta = \sqrt{\frac{\Delta H_{vap} - RT}{V_m}} Calculated based on enthalpy of vaporization and molar volume. Normally calculated at STP. For uses of this property, see :obj:`thermo.solubility.solubility_parameter`. Examples -------- >>> Chemical('NH3').solubility_parameter 24766.329043856073 ''' return solubility_parameter(T=self.T, Hvapm=self.Hvapm, Vml=self.Vml, Method=self.solubility_parameter_method, CASRN=self.CAS)
def Parachor(self): r'''Parachor of the chemical at its current temperature and pressure, in units of [N^0.25*m^2.75/mol]. .. math:: P = \frac{\sigma^{0.25} MW}{\rho_L - \rho_V} Calculated based on surface tension, density of the liquid and gas phase, and molecular weight. For uses of this property, see :obj:`thermo.utils.Parachor`. Examples -------- >>> Chemical('octane').Parachor 6.291693072841486e-05 ''' sigma, rhol, rhog = self.sigma, self.rhol, self.rhog if all((sigma, rhol, rhog, self.MW)): return Parachor(sigma=sigma, MW=self.MW, rhol=rhol, rhog=rhog) return None
def Cp(self): r'''Mass heat capacity of the chemical at its current phase and temperature, in units of [J/kg/K]. Utilizes the object oriented interfaces :obj:`thermo.heat_capacity.HeatCapacitySolid`, :obj:`thermo.heat_capacity.HeatCapacityLiquid`, and :obj:`thermo.heat_capacity.HeatCapacityGas` to perform the actual calculation of each property. Note that those interfaces provide output in molar units (J/mol/K). Examples -------- >>> w = Chemical('water') >>> w.Cp, w.phase (4180.597021827336, 'l') >>> Chemical('palladium').Cp 234.26767209171211 ''' return phase_select_property(phase=self.phase, s=self.Cps, l=self.Cpl, g=self.Cpg)
def Cpm(self): r'''Molar heat capacity of the chemical at its current phase and temperature, in units of [J/mol/K]. Utilizes the object oriented interfaces :obj:`thermo.heat_capacity.HeatCapacitySolid`, :obj:`thermo.heat_capacity.HeatCapacityLiquid`, and :obj:`thermo.heat_capacity.HeatCapacityGas` to perform the actual calculation of each property. Examples -------- >>> Chemical('cubane').Cpm 137.05489206785944 >>> Chemical('ethylbenzene', T=550, P=3E6).Cpm 294.18449553310046 ''' return phase_select_property(phase=self.phase, s=self.Cpsm, l=self.Cplm, g=self.Cpgm)
def Vm(self): r'''Molar volume of the chemical at its current phase and temperature and pressure, in units of [m^3/mol]. Utilizes the object oriented interfaces :obj:`thermo.volume.VolumeSolid`, :obj:`thermo.volume.VolumeLiquid`, and :obj:`thermo.volume.VolumeGas` to perform the actual calculation of each property. Examples -------- >>> Chemical('ethylbenzene', T=550, P=3E6).Vm 0.00017758024401627633 ''' return phase_select_property(phase=self.phase, s=self.Vms, l=self.Vml, g=self.Vmg)
def rho(self): r'''Mass density of the chemical at its current phase and temperature and pressure, in units of [kg/m^3]. Utilizes the object oriented interfaces :obj:`thermo.volume.VolumeSolid`, :obj:`thermo.volume.VolumeLiquid`, and :obj:`thermo.volume.VolumeGas` to perform the actual calculation of each property. Note that those interfaces provide output in units of m^3/mol. Examples -------- >>> Chemical('decane', T=550, P=2E6).rho 498.67008448640604 ''' return phase_select_property(phase=self.phase, s=self.rhos, l=self.rhol, g=self.rhog)
def Z(self): r'''Compressibility factor of the chemical at its current phase and temperature and pressure, [dimensionless]. Examples -------- >>> Chemical('MTBE', T=900, P=1E-2).Z 0.9999999999079768 ''' Vm = self.Vm if Vm: return Z(self.T, self.P, Vm) return None
def SG(self): r'''Specific gravity of the chemical, [dimensionless]. For gas-phase conditions, this is calculated at 15.6 °C (60 °F) and 1 atm for the chemical and the reference fluid, air. For liquid and solid phase conditions, this is calculated based on a reference fluid of water at 4°C at 1 atm, but the with the liquid or solid chemical's density at the currently specified conditions. Examples -------- >>> Chemical('MTBE').SG 0.7428160596603596 ''' phase = self.phase if phase == 'l': return self.SGl elif phase == 's': return self.SGs elif phase == 'g': return self.SGg rho = self.rho if rho is not None: return SG(rho) return None
def isobaric_expansion(self): r'''Isobaric (constant-pressure) expansion of the chemical at its current phase and temperature, in units of [1/K]. .. math:: \beta = \frac{1}{V}\left(\frac{\partial V}{\partial T} \right)_P Examples -------- Radical change in value just above and below the critical temperature of water: >>> Chemical('water', T=647.1, P=22048320.0).isobaric_expansion 0.34074205839222449 >>> Chemical('water', T=647.2, P=22048320.0).isobaric_expansion 0.18143324022215077 ''' return phase_select_property(phase=self.phase, l=self.isobaric_expansion_l, g=self.isobaric_expansion_g)
def JT(self): r'''Joule Thomson coefficient of the chemical at its current phase and temperature, in units of [K/Pa]. .. math:: \mu_{JT} = \left(\frac{\partial T}{\partial P}\right)_H = \frac{1}{C_p} \left[T \left(\frac{\partial V}{\partial T}\right)_P - V\right] = \frac{V}{C_p}\left(\beta T-1\right) Examples -------- >>> Chemical('water').JT -2.2150394958666407e-07 ''' return phase_select_property(phase=self.phase, l=self.JTl, g=self.JTg)
def mu(self): r'''Viscosity of the chemical at its current phase, temperature, and pressure in units of [Pa*s]. Utilizes the object oriented interfaces :obj:`thermo.viscosity.ViscosityLiquid` and :obj:`thermo.viscosity.ViscosityGas` to perform the actual calculation of each property. Examples -------- >>> Chemical('ethanol', T=300).mu 0.001044526538460911 >>> Chemical('ethanol', T=400).mu 1.1853097849748217e-05 ''' return phase_select_property(phase=self.phase, l=self.mul, g=self.mug)
def k(self): r'''Thermal conductivity of the chemical at its current phase, temperature, and pressure in units of [W/m/K]. Utilizes the object oriented interfaces :obj:`thermo.thermal_conductivity.ThermalConductivityLiquid` and :obj:`thermo.thermal_conductivity.ThermalConductivityGas` to perform the actual calculation of each property. Examples -------- >>> Chemical('ethanol', T=300).kl 0.16313594741877802 >>> Chemical('ethanol', T=400).kg 0.026019924109310026 ''' return phase_select_property(phase=self.phase, s=None, l=self.kl, g=self.kg)
def nu(self): r'''Kinematic viscosity of the the chemical at its current temperature, pressure, and phase in units of [m^2/s]. .. math:: \nu = \frac{\mu}{\rho} Examples -------- >>> Chemical('argon').nu 1.3846930410865003e-05 ''' return phase_select_property(phase=self.phase, l=self.nul, g=self.nug)
def alpha(self): r'''Thermal diffusivity of the chemical at its current temperature, pressure, and phase in units of [m^2/s]. .. math:: \alpha = \frac{k}{\rho Cp} Examples -------- >>> Chemical('furfural').alpha 8.696537158635412e-08 ''' return phase_select_property(phase=self.phase, l=self.alphal, g=self.alphag)
def Pr(self): r'''Prandtl number of the chemical at its current temperature, pressure, and phase; [dimensionless]. .. math:: Pr = \frac{C_p \mu}{k} Examples -------- >>> Chemical('acetone').Pr 4.183039103542709 ''' return phase_select_property(phase=self.phase, l=self.Prl, g=self.Prg)
def Poynting(self): r'''Poynting correction factor [dimensionless] for use in phase equilibria methods based on activity coefficients or other reference states. Performs the shortcut calculation assuming molar volume is independent of pressure. .. math:: \text{Poy} = \exp\left[\frac{V_l (P-P^{sat})}{RT}\right] The full calculation normally returns values very close to the approximate ones. This property is defined in terms of pure components only. Examples -------- >>> Chemical('pentane', T=300, P=1E7).Poynting 1.5743051250679803 Notes ----- The full equation shown below can be used as follows: .. math:: \text{Poy} = \exp\left[\frac{\int_{P_i^{sat}}^P V_i^l dP}{RT}\right] >>> from scipy.integrate import quad >>> c = Chemical('pentane', T=300, P=1E7) >>> exp(quad(lambda P : c.VolumeLiquid(c.T, P), c.Psat, c.P)[0]/R/c.T) 1.5821826990975127 ''' Vml, Psat = self.Vml, self.Psat if Vml and Psat: return exp(Vml*(self.P-Psat)/R/self.T) return None
def ITS90_68_difference(T): r'''Calculates the difference between ITS-90 and ITS-68 scales using a series of models listed in [1]_, [2]_, and [3]_. The temperature difference is given by the following equations: From 13.8 K to 73.15 K: .. math:: T_{90} - T_{68} = a_0 + \sum_{i=1}^{12} a_i[(T_{90}/K-40)/40]^i From 83.8 K to 903.75 K: .. math:: T_{90} - T_{68} = \sum_{i=1}^8 b_i[(T_{90}/K - 273.15)/630]^i From 903.75 K to 1337.33 K: .. math:: T_{90} - T_{68} = \sum_{i=0}^5 c_i[T_{90}/^\circ C]^i Above 1337.33 K: .. math:: T_{90} - T_{68} = -1.398\cdot 10^{-7}\left(\frac{T_{90}}{K}\right)^2 Parameters ---------- T : float Temperature, ITS-90, or approximately ITS-68 [K] Returns ------- dT : float Temperature, difference between ITS-90 and ITS-68 at T [K] Notes ----- The conversion is straightforward when T90 is known. Theoretically, the model should be solved numerically to convert the reverse way. However, according to [4]_, the difference is under 0.05 mK from 73.15 K to 903.15 K, and under 0.26 mK up to 1337.33 K. For temperatures under 13.8 K, no conversion is performed. The first set of coefficients are: -0.005903, 0.008174, -0.061924, -0.193388, 1.490793, 1.252347, -9.835868, 1.411912, 25.277595, -19.183815, -18.437089, 27.000895, -8.716324. The second set of coefficients are: 0, -0.148759, -0.267408, 1.08076, 1.269056, -4.089591, -1.871251, 7.438081, -3.536296. The third set of coefficients are: 7.8687209E1, -4.7135991E-1, 1.0954715E-3, -1.2357884E-6, 6.7736583E-10, -1.4458081E-13. These last coefficients use the temperature in degrees Celcius. A slightly older model used the following coefficients but a different equation over the same range: -0.00317, -0.97737, 1.2559, 2.03295, -5.91887, -3.23561, 7.23364, 5.04151. The model for these coefficients was: .. math:: T_{90} - T_{68} = c_0 + \sum_{i=1}^7 c_i[(T_{90}/K - 1173.15)/300]^i For temperatures larger than several thousand K, the differences have no meaning and grows quadratically. Examples -------- >>> ITS90_68_difference(1000.) 0.01231818956580355 References ---------- .. [1] Bedford, R. E., G. Bonnier, H. Maas, and F. Pavese. "Techniques for Approximating the International Temperature Scale of 1990." Bureau International Des Poids et Mesures, Sfievres, 1990. .. [2] Wier, Ron D., and Robert N. Goldberg. "On the Conversion of Thermodynamic Properties to the Basis of the International Temperature Scale of 1990." The Journal of Chemical Thermodynamics 28, no. 3 (March 1996): 261-76. doi:10.1006/jcht.1996.0026. .. [3] Goldberg, Robert N., and R. D. Weir. "Conversion of Temperatures and Thermodynamic Properties to the Basis of the International Temperature Scale of 1990 (Technical Report)." Pure and Applied Chemistry 64, no. 10 (1992): 1545-1562. doi:10.1351/pac199264101545. .. [4] Code10.info. "Conversions among International Temperature Scales." Accessed May 22, 2016. http://www.code10.info/index.php%3Foption%3Dcom_content%26view%3Darticle%26id%3D83:conversions-among-international-temperature-scales%26catid%3D60:temperature%26Itemid%3D83. ''' ais = [-0.005903, 0.008174, -0.061924, -0.193388, 1.490793, 1.252347, -9.835868, 1.411912, 25.277595, -19.183815, -18.437089, 27.000895, -8.716324] bis = [0, -0.148759, -0.267408, 1.08076, 1.269056, -4.089591, -1.871251, 7.438081, -3.536296] # cis = [-0.00317, -0.97737, 1.2559, 2.03295, -5.91887, -3.23561, 7.23364, # 5.04151] new_cs = [7.8687209E1, -4.7135991E-1, 1.0954715E-3, -1.2357884E-6, 6.7736583E-10, -1.4458081E-13] dT = 0 if T < 13.8: dT = 0 elif T >= 13.8 and T <= 73.15: for i in range(13): dT += ais[i]*((T - 40.)/40.)**i elif T > 73.15 and T < 83.8: dT = 0 elif T >= 83.8 and T <= 903.75: for i in range(9): dT += bis[i]*((T - 273.15)/630.)**i elif T > 903.75 and T <= 1337.33: # Revised function exists, but does not match the tabulated data # for i in range(8): # dT += cis[i]*((T - 1173.15)/300.)**i for i in range(6): dT += new_cs[i]*(T-273.15)**i elif T > 1337.33: dT = -1.398E-7*T**2 return dT
def T_converter(T, current, desired): r'''Converts the a temperature reading made in any of the scales 'ITS-90', 'ITS-68','ITS-48', 'ITS-76', or 'ITS-27' to any of the other scales. Not all temperature ranges can be converted to other ranges; for instance, 'ITS-76' is purely for low temperatures, and 5 K on it has no conversion to 'ITS-90' or any other scale. Both a conversion to ITS-90 and to the desired scale must be possible for the conversion to occur. The conversion uses cubic spline interpolation. ITS-68 conversion is valid from 14 K to 4300 K. ITS-48 conversion is valid from 93.15 K to 4273.15 K ITS-76 conversion is valid from 5 K to 27 K. ITS-27 is valid from 903.15 K to 4273.15 k. Parameters ---------- T : float Temperature, on `current` scale [K] current : str String representing the scale T is in, 'ITS-90', 'ITS-68', 'ITS-48', 'ITS-76', or 'ITS-27'. desired : str String representing the scale T will be returned in, 'ITS-90', 'ITS-68', 'ITS-48', 'ITS-76', or 'ITS-27'. Returns ------- T : float Temperature, on scale `desired` [K] Notes ----- Because the conversion is performed by spline functions, a re-conversion of a value will not yield exactly the original value. However, it is quite close. The use of splines is quite quick (20 micro seconds/calculation). While just a spline for one-way conversion could be used, a numerical solver would have to be used to obtain an exact result for the reverse conversion. This was found to take approximately 1 ms/calculation, depending on the region. Examples -------- >>> T_converter(500, 'ITS-68', 'ITS-48') 499.9470092992346 References ---------- .. [1] Wier, Ron D., and Robert N. Goldberg. "On the Conversion of Thermodynamic Properties to the Basis of the International Temperature Scale of 1990." The Journal of Chemical Thermodynamics 28, no. 3 (March 1996): 261-76. doi:10.1006/jcht.1996.0026. .. [2] Goldberg, Robert N., and R. D. Weir. "Conversion of Temperatures and Thermodynamic Properties to the Basis of the International Temperature Scale of 1990 (Technical Report)." Pure and Applied Chemistry 64, no. 10 (1992): 1545-1562. doi:10.1351/pac199264101545. ''' def range_check(T, Tmin, Tmax): if T < Tmin or T > Tmax: raise Exception('Temperature conversion is outside one or both scales') try: if current == 'ITS-90': pass elif current == 'ITS-68': range_check(T, 13.999, 4300.0001) T = T68_to_T90(T) elif current == 'ITS-76': range_check(T, 4.9999, 27.0001) T = T76_to_T90(T) elif current == 'ITS-48': range_check(T, 93.149999, 4273.15001) T = T48_to_T90(T) elif current == 'ITS-27': range_check(T, 903.15, 4273.15) T = T27_to_T90(T) else: raise Exception('Current scale not supported') # T should be in ITS-90 now if desired == 'ITS-90': pass elif desired == 'ITS-68': range_check(T, 13.999, 4300.0001) T = T90_to_T68(T) elif desired == 'ITS-76': range_check(T, 4.9999, 27.0001) T = T90_to_T76(T) elif desired == 'ITS-48': range_check(T, 93.149999, 4273.15001) T = T90_to_T48(T) elif desired == 'ITS-27': range_check(T, 903.15, 4273.15) T = T90_to_T27(T) else: raise Exception('Desired scale not supported') except ValueError: raise Exception('Temperature could not be converted to desired scale') return float(T)
def GWP(CASRN, AvailableMethods=False, Method=None): r'''This function handles the retrieval of a chemical's Global Warming Potential, relative to CO2. 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. Returns the GWP for the 100yr outlook by default. Parameters ---------- CASRN : string CASRN [-] Returns ------- GWP : float Global warming potential, [(impact/mass chemical)/(impact/mass CO2)] methods : list, only returned if AvailableMethods == True List of methods which can be used to obtain GWP with the given inputs Other Parameters ---------------- Method : string, optional The method name to use. Accepted methods are IPCC (2007) 100yr', 'IPCC (2007) 100yr-SAR', 'IPCC (2007) 20yr', and 'IPCC (2007) 500yr'. All valid values are also held in the list GWP_methods. AvailableMethods : bool, optional If True, function will determine which methods can be used to obtain the GWP for the desired chemical, and will return methods instead of the GWP Notes ----- All data is from [1]_, the official source. Several chemicals are available in [1]_ are not included here as they do not have a CAS. Methods are 'IPCC (2007) 100yr', 'IPCC (2007) 100yr-SAR', 'IPCC (2007) 20yr', and 'IPCC (2007) 500yr'. Examples -------- Methane, 100-yr outlook >>> GWP(CASRN='74-82-8') 25.0 References ---------- .. [1] IPCC. "2.10.2 Direct Global Warming Potentials - AR4 WGI Chapter 2: Changes in Atmospheric Constituents and in Radiative Forcing." 2007. https://www.ipcc.ch/publications_and_data/ar4/wg1/en/ch2s2-10-2.html. ''' def list_methods(): methods = [] if CASRN in GWP_data.index: methods.append(IPCC100) if not pd.isnull(GWP_data.at[CASRN, 'SAR 100yr']): methods.append(IPCC100SAR) methods.append(IPCC20) methods.append(IPCC500) methods.append(NONE) return methods if AvailableMethods: return list_methods() if not Method: Method = list_methods()[0] if Method == IPCC100: return float(GWP_data.at[CASRN, '100yr GWP']) elif Method == IPCC100SAR: return float(GWP_data.at[CASRN, 'SAR 100yr']) elif Method == IPCC20: return float(GWP_data.at[CASRN, '20yr GWP']) elif Method == IPCC500: return float(GWP_data.at[CASRN, '500yr GWP']) elif Method == NONE: return None else: raise Exception('Failure in in function')
def ODP(CASRN, AvailableMethods=False, Method=None): r'''This function handles the retrieval of a chemical's Ozone Depletion Potential, relative to CFC-11 (trichlorofluoromethane). 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. Returns the ODP of a chemical according to [2]_ when a method is not specified. If a range is provided in [2]_, the highest value is returned. Parameters ---------- CASRN : string CASRN [-] Returns ------- ODP : float or str Ozone Depletion potential, [(impact/mass chemical)/(impact/mass CFC-11)]; if method selected has `string` in it, this will be returned as a string regardless of if a range is given or a number methods : list, only returned if AvailableMethods == True List of methods which can be used to obtain ODP with the given inputs Other Parameters ---------------- Method : string, optional The method name to use. Accepted methods are 'ODP2 Max', 'ODP2 Min', 'ODP2 string', 'ODP2 logarithmic average', and methods for older values are 'ODP1 Max', 'ODP1 Min', 'ODP1 string', and 'ODP1 logarithmic average'. All valid values are also held in the list ODP_methods. Method : string, optional A string for the method name to use, as defined by constants in ODP_methods AvailableMethods : bool, optional If True, function will determine which methods can be used to obtain the ODP for the desired chemical, and will return methods instead of the ODP Notes ----- Values are tabulated only for a small number of halogenated hydrocarbons, responsible for the largest impact. The original values of ODP as defined in the Montreal Protocol are also available, as methods with the `ODP1` prefix. All values are somewhat emperical, as actual reaction rates of chemicals with ozone depend on temperature which depends on latitude, longitude, time of day, weather, and the concentrations of other pollutants. All data is from [1]_. Several mixtures listed in [1]_ are not included here as they are not pure species. Methods for values in [2]_ are 'ODP2 Max', 'ODP2 Min', 'ODP2 string', 'ODP2 logarithmic average', and methods for older values are 'ODP1 Max', 'ODP1 Min', 'ODP1 string', and 'ODP1 logarithmic average'. Examples -------- Dichlorotetrafluoroethane, according to [2]_. >>> ODP(CASRN='76-14-2') 0.58 References ---------- .. [1] US EPA, OAR. "Ozone-Depleting Substances." Accessed April 26, 2016. https://www.epa.gov/ozone-layer-protection/ozone-depleting-substances. .. [2] WMO (World Meteorological Organization), 2011: Scientific Assessment of Ozone Depletion: 2010. Global Ozone Research and Monitoring Project-Report No. 52, Geneva, Switzerland, 516 p. https://www.wmo.int/pages/prog/arep/gaw/ozone_2010/documents/Ozone-Assessment-2010-complete.pdf ''' def list_methods(): methods = [] if CASRN in ODP_data.index: if not pd.isnull(ODP_data.at[CASRN, 'ODP2 Max']): methods.append(ODP2MAX) if not pd.isnull(ODP_data.at[CASRN, 'ODP1 Max']): methods.append(ODP1MAX) if not pd.isnull(ODP_data.at[CASRN, 'ODP2 Design']): methods.append(ODP2LOG) if not pd.isnull(ODP_data.at[CASRN, 'ODP1 Design']): methods.append(ODP1LOG) if not pd.isnull(ODP_data.at[CASRN, 'ODP2 Min']): methods.append(ODP2MIN) if not pd.isnull(ODP_data.at[CASRN, 'ODP1 Min']): methods.append(ODP1MIN) if not pd.isnull(ODP_data.at[CASRN, 'ODP2']): methods.append(ODP2STR) if not pd.isnull(ODP_data.at[CASRN, 'ODP1']): methods.append(ODP1STR) methods.append(NONE) return methods if AvailableMethods: return list_methods() if not Method: Method = list_methods()[0] if Method == ODP2MAX: return float(ODP_data.at[CASRN, 'ODP2 Max']) elif Method == ODP1MAX: return float(ODP_data.at[CASRN, 'ODP1 Max']) elif Method == ODP2MIN: return float(ODP_data.at[CASRN, 'ODP2 Min']) elif Method == ODP1MIN: return float(ODP_data.at[CASRN, 'ODP1 Min']) elif Method == ODP2LOG: return float(ODP_data.at[CASRN, 'ODP2 Design']) elif Method == ODP1LOG: return float(ODP_data.at[CASRN, 'ODP1 Design']) elif Method == ODP2STR: return str(ODP_data.at[CASRN, 'ODP2']) elif Method == ODP1STR: return str(ODP_data.at[CASRN, 'ODP1']) elif Method == NONE: return None else: raise Exception('Failure in in function')
def logP(CASRN, AvailableMethods=False, Method=None): r'''This function handles the retrieval of a chemical's octanol-water partition coefficient. 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. Parameters ---------- CASRN : string CASRN [-] Returns ------- logP : float Octanol-water partition coefficient, [-] methods : list, only returned if AvailableMethods == True List of methods which can be used to obtain logP with the given inputs Other Parameters ---------------- Method : string, optional The method name to use. Accepted methods are 'SYRRES', or 'CRC', All valid values are also held in the list logP_methods. AvailableMethods : bool, optional If True, function will determine which methods can be used to obtain the logP for the desired chemical, and will return methods instead of the logP Notes ----- .. math:: \log P_{ oct/wat} = \log\left(\frac{\left[{solute} \right]_{ octanol}^{un-ionized}}{\left[{solute} \right]_{ water}^{ un-ionized}}\right) Examples -------- >>> logP('67-56-1') -0.74 References ---------- .. [1] Syrres. 2006. KOWWIN Data, SrcKowData2.zip. http://esc.syrres.com/interkow/Download/SrcKowData2.zip .. [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 CRClogPDict.index: methods.append(CRC) if CASRN in SyrresDict2.index: methods.append(SYRRES) methods.append(NONE) return methods if AvailableMethods: return list_methods() if not Method: Method = list_methods()[0] if Method == CRC: return float(CRClogPDict.at[CASRN, 'logP']) elif Method == SYRRES: return float(SyrresDict2.at[CASRN, 'logP']) elif Method == NONE: return None else: raise Exception('Failure in in function')
def Antoine(T, A, B, C, base=10.0): r'''Calculates vapor pressure of a chemical using the Antoine equation. Parameters `A`, `B`, and `C` are chemical-dependent. Parameters can be found in numerous sources; however units of the coefficients used vary. Originally proposed by Antoine (1888) [2]_. .. math:: \log_{\text{base}} P^{\text{sat}} = A - \frac{B}{T+C} Parameters ---------- T : float Temperature of fluid, [K] A, B, C : floats Regressed coefficients for Antoine equation for a chemical Returns ------- Psat : float Vapor pressure calculated with coefficients [Pa] Other Parameters ---------------- Base : float Optional base of logarithm; 10 by default Notes ----- Assumes coefficients are for calculating vapor pressure in Pascal. Coefficients should be consistent with input temperatures in Kelvin; however, if both the given temperature and units are specific to degrees Celcius, the result will still be correct. **Converting units in input coefficients:** * **ln to log10**: Divide A and B by ln(10)=2.302585 to change parameters for a ln equation to a log10 equation. * **log10 to ln**: Multiply A and B by ln(10)=2.302585 to change parameters for a log equation to a ln equation. * **mmHg to Pa**: Add log10(101325/760)= 2.1249 to A. * **kPa to Pa**: Add log_{base}(1000)= 6.908 to A for log(base) * **°C to K**: Subtract 273.15 from C only! Examples -------- Methane, coefficients from [1]_, at 100 K: >>> Antoine(100.0, 8.7687, 395.744, -6.469) 34478.367349639906 Tetrafluoromethane, coefficients from [1]_, at 180 K >>> Antoine(180, A=8.95894, B=510.595, C=-15.95) 702271.0518579542 Oxygen at 94.91 K, with coefficients from [3]_ in units of °C, mmHg, log10, showing the conversion of coefficients A (mmHg to Pa) and C (°C to K) >>> Antoine(94.91, 6.83706+2.1249, 339.2095, 268.70-273.15) 162978.88655572367 References ---------- .. [1] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000. .. [2] Antoine, C. 1888. Tensions des Vapeurs: Nouvelle Relation Entre les Tensions et les Tempé. Compt.Rend. 107:681-684. .. [3] Yaws, Carl L. The Yaws Handbook of Vapor Pressure: Antoine Coefficients. 1 edition. Houston, Tex: Gulf Publishing Company, 2007. ''' return base**(A-B/(T+C))
def TRC_Antoine_extended(T, Tc, to, A, B, C, n, E, F): r'''Calculates vapor pressure of a chemical using the TRC Extended Antoine equation. Parameters are chemical dependent, and said to be from the Thermodynamics Research Center (TRC) at Texas A&M. Coefficients for various chemicals can be found in [1]_. .. math:: \log_{10} P^{sat} = A - \frac{B}{T + C} + 0.43429x^n + Ex^8 + Fx^{12} x = \max \left(\frac{T-t_o-273.15}{T_c}, 0 \right) Parameters ---------- T : float Temperature of fluid, [K] A, B, C, n, E, F : floats Regressed coefficients for the Antoine Extended (TRC) equation, specific for each chemical, [-] Returns ------- Psat : float Vapor pressure calculated with coefficients [Pa] Notes ----- Assumes coefficients are for calculating vapor pressure in Pascal. Coefficients should be consistent with input temperatures in Kelvin; Examples -------- Tetrafluoromethane, coefficients from [1]_, at 180 K: >>> TRC_Antoine_extended(180.0, 227.51, -120., 8.95894, 510.595, -15.95, ... 2.41377, -93.74, 7425.9) 706317.0898414153 References ---------- .. [1] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000. ''' x = max((T - to - 273.15)/Tc, 0.) return 10.**(A - B/(T+C) + 0.43429*x**n + E*x**8 + F*x**12)
def Wagner_original(T, Tc, Pc, a, b, c, d): r'''Calculates vapor pressure using the Wagner equation (3, 6 form). Requires critical temperature and pressure as well as four coefficients specific to each chemical. .. math:: \ln P^{sat}= \ln P_c + \frac{a\tau + b \tau^{1.5} + c\tau^3 + d\tau^6} {T_r} \tau = 1 - \frac{T}{T_c} Parameters ---------- T : float Temperature of fluid, [K] Tc : float Critical temperature, [K] Pc : float Critical pressure, [Pa] a, b, c, d : floats Parameters for wagner equation. Specific to each chemical. [-] Returns ------- Psat : float Vapor pressure at T [Pa] Notes ----- Warning: Pc is often treated as adjustable constant. Examples -------- Methane, coefficients from [2]_, at 100 K. >>> Wagner_original(100.0, 190.53, 4596420., a=-6.00435, b=1.1885, ... c=-0.834082, d=-1.22833) 34520.44601450496 References ---------- .. [1] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000. .. [2] McGarry, Jack. "Correlation and Prediction of the Vapor Pressures of Pure Liquids over Large Pressure Ranges." Industrial & Engineering Chemistry Process Design and Development 22, no. 2 (April 1, 1983): 313-22. doi:10.1021/i200021a023. ''' Tr = T/Tc tau = 1.0 - Tr return Pc*exp((a*tau + b*tau**1.5 + c*tau**3 + d*tau**6)/Tr)
def boiling_critical_relation(T, Tb, Tc, Pc): r'''Calculates vapor pressure of a fluid at arbitrary temperatures using a CSP relationship as in [1]_; requires a chemical's critical temperature and pressure as well as boiling point. The vapor pressure is given by: .. math:: \ln P^{sat}_r = h\left( 1 - \frac{1}{T_r}\right) h = T_{br} \frac{\ln(P_c/101325)}{1-T_{br}} Parameters ---------- T : float Temperature of fluid [K] Tb : float Boiling temperature of fluid [K] Tc : float Critical temperature of fluid [K] Pc : float Critical pressure of fluid [Pa] Returns ------- Psat : float Vapor pressure at T [Pa] Notes ----- Units are Pa. Formulation makes intuitive sense; a logarithmic form of interpolation. Examples -------- Example as in [1]_ for ethylbenzene >>> boiling_critical_relation(347.2, 409.3, 617.1, 36E5) 15209.467273093938 References ---------- .. [1] Reid, Robert C..; Prausnitz, John M.;; Poling, Bruce E. The Properties of Gases and Liquids. McGraw-Hill Companies, 1987. ''' Tbr = Tb/Tc Tr = T/Tc h = Tbr*log(Pc/101325.)/(1 - Tbr) return exp(h*(1-1/Tr))*Pc
def Lee_Kesler(T, Tc, Pc, omega): r'''Calculates vapor pressure of a fluid at arbitrary temperatures using a CSP relationship by [1]_; requires a chemical's critical temperature and acentric factor. The vapor pressure is given by: .. math:: \ln P^{sat}_r = f^{(0)} + \omega f^{(1)} f^{(0)} = 5.92714-\frac{6.09648}{T_r}-1.28862\ln T_r + 0.169347T_r^6 f^{(1)} = 15.2518-\frac{15.6875}{T_r} - 13.4721 \ln T_r + 0.43577T_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 [-] Returns ------- Psat : float Vapor pressure at T [Pa] Notes ----- This equation appears in [1]_ in expanded form. The reduced pressure form of the equation ensures predicted vapor pressure cannot surpass the critical pressure. Examples -------- Example from [2]_; ethylbenzene at 347.2 K. >>> Lee_Kesler(347.2, 617.1, 36E5, 0.299) 13078.694162949312 References ---------- .. [1] Lee, Byung Ik, and Michael G. Kesler. "A Generalized Thermodynamic Correlation Based on Three-Parameter Corresponding States." AIChE Journal 21, no. 3 (1975): 510-527. doi:10.1002/aic.690210313. .. [2] Reid, Robert C..; Prausnitz, John M.;; Poling, Bruce E. The Properties of Gases and Liquids. McGraw-Hill Companies, 1987. ''' Tr = T/Tc f0 = 5.92714 - 6.09648/Tr - 1.28862*log(Tr) + 0.169347*Tr**6 f1 = 15.2518 - 15.6875/Tr - 13.4721*log(Tr) + 0.43577*Tr**6 return exp(f0 + omega*f1)*Pc
def Ambrose_Walton(T, Tc, Pc, omega): r'''Calculates vapor pressure of a fluid at arbitrary temperatures using a CSP relationship by [1]_; requires a chemical's critical temperature and acentric factor. The vapor pressure is given by: .. math:: \ln P_r=f^{(0)}+\omega f^{(1)}+\omega^2f^{(2)} f^{(0)}=\frac{-5.97616\tau + 1.29874\tau^{1.5}- 0.60394\tau^{2.5} -1.06841\tau^5}{T_r} f^{(1)}=\frac{-5.03365\tau + 1.11505\tau^{1.5}- 5.41217\tau^{2.5} -7.46628\tau^5}{T_r} f^{(2)}=\frac{-0.64771\tau + 2.41539\tau^{1.5}- 4.26979\tau^{2.5} +3.25259\tau^5}{T_r} \tau = 1-T_{r} 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 [-] Returns ------- Psat : float Vapor pressure at T [Pa] Notes ----- Somewhat more accurate than the :obj:`Lee_Kesler` formulation. Examples -------- Example from [2]_; ethylbenzene at 347.25 K. >>> Ambrose_Walton(347.25, 617.15, 36.09E5, 0.304) 13278.878504306222 References ---------- .. [1] Ambrose, D., and J. Walton. "Vapour Pressures up to Their Critical Temperatures of Normal Alkanes and 1-Alkanols." Pure and Applied Chemistry 61, no. 8 (1989): 1395-1403. doi:10.1351/pac198961081395. .. [2] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000. ''' Tr = T/Tc tau = 1 - T/Tc f0 = (-5.97616*tau + 1.29874*tau**1.5 - 0.60394*tau**2.5 - 1.06841*tau**5)/Tr f1 = (-5.03365*tau + 1.11505*tau**1.5 - 5.41217*tau**2.5 - 7.46628*tau**5)/Tr f2 = (-0.64771*tau + 2.41539*tau**1.5 - 4.26979*tau**2.5 + 3.25259*tau**5)/Tr return Pc*exp(f0 + omega*f1 + omega**2*f2)
def Sanjari(T, Tc, Pc, omega): r'''Calculates vapor pressure of a fluid at arbitrary temperatures using a CSP relationship by [1]_. Requires a chemical's critical temperature, pressure, and acentric factor. Although developed for refrigerants, this model should have some general predictive ability. The vapor pressure of a chemical at `T` is given by: .. math:: P^{sat} = P_c\exp(f^{(0)} + \omega f^{(1)} + \omega^2 f^{(2)}) f^{(0)} = a_1 + \frac{a_2}{T_r} + a_3\ln T_r + a_4 T_r^{1.9} f^{(1)} = a_5 + \frac{a_6}{T_r} + a_7\ln T_r + a_8 T_r^{1.9} f^{(2)} = a_9 + \frac{a_{10}}{T_r} + a_{11}\ln T_r + a_{12} T_r^{1.9} 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 [-] Returns ------- Psat : float Vapor pressure, [Pa] Notes ----- a[1-12] are as follows: 6.83377, -5.76051, 0.90654, -1.16906, 5.32034, -28.1460, -58.0352, 23.57466, 18.19967, 16.33839, 65.6995, -35.9739. For a claimed fluid not included in the regression, R128, the claimed AARD was 0.428%. A re-calculation using 200 data points from 125.45 K to 343.90225 K evenly spaced by 1.09775 K as generated by NIST Webbook April 2016 produced an AARD of 0.644%. It is likely that the author's regression used more precision in its coefficients than was shown here. Nevertheless, the function is reproduced as shown in [1]_. For Tc=808 K, Pc=1100000 Pa, omega=1.1571, this function actually declines after 770 K. Examples -------- >>> Sanjari(347.2, 617.1, 36E5, 0.299) 13651.916109552498 References ---------- .. [1] Sanjari, Ehsan, Mehrdad Honarmand, Hamidreza Badihi, and Ali Ghaheri. "An Accurate Generalized Model for Predict Vapor Pressure of Refrigerants." International Journal of Refrigeration 36, no. 4 (June 2013): 1327-32. doi:10.1016/j.ijrefrig.2013.01.007. ''' Tr = T/Tc f0 = 6.83377 + -5.76051/Tr + 0.90654*log(Tr) + -1.16906*Tr**1.9 f1 = 5.32034 + -28.1460/Tr + -58.0352*log(Tr) + 23.57466*Tr**1.9 f2 = 18.19967 + 16.33839/Tr + 65.6995*log(Tr) + -35.9739*Tr**1.9 return Pc*exp(f0 + omega*f1 + omega**2*f2)
def Edalat(T, Tc, Pc, omega): r'''Calculates vapor pressure of a fluid at arbitrary temperatures using a CSP relationship by [1]_. Requires a chemical's critical temperature, pressure, and acentric factor. Claimed to have a higher accuracy than the Lee-Kesler CSP relationship. The vapor pressure of a chemical at `T` is given by: .. math:: \ln(P^{sat}/P_c) = \frac{a\tau + b\tau^{1.5} + c\tau^3 + d\tau^6} {1-\tau} a = -6.1559 - 4.0855\omega b = 1.5737 - 1.0540\omega - 4.4365\times 10^{-3} d c = -0.8747 - 7.8874\omega d = \frac{1}{-0.4893 - 0.9912\omega + 3.1551\omega^2} \tau = 1 - \frac{T}{T_c} 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 [-] Returns ------- Psat : float Vapor pressure, [Pa] Notes ----- [1]_ found an average error of 6.06% on 94 compounds and 1106 data points. Examples -------- >>> Edalat(347.2, 617.1, 36E5, 0.299) 13461.273080743307 References ---------- .. [1] Edalat, M., R. B. Bozar-Jomehri, and G. A. Mansoori. "Generalized Equation Predicts Vapor Pressure of Hydrocarbons." Oil and Gas Journal; 91:5 (February 1, 1993). ''' tau = 1. - T/Tc a = -6.1559 - 4.0855*omega c = -0.8747 - 7.8874*omega d = 1./(-0.4893 - 0.9912*omega + 3.1551*omega**2) b = 1.5737 - 1.0540*omega - 4.4365E-3*d lnPr = (a*tau + b*tau**1.5 + c*tau**3 + d*tau**6)/(1.-tau) return exp(lnPr)*Pc
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 self.CASRN in WagnerMcGarry.index: methods.append(WAGNER_MCGARRY) _, A, B, C, D, self.WAGNER_MCGARRY_Pc, self.WAGNER_MCGARRY_Tc, self.WAGNER_MCGARRY_Tmin = _WagnerMcGarry_values[WagnerMcGarry.index.get_loc(self.CASRN)].tolist() self.WAGNER_MCGARRY_coefs = [A, B, C, D] Tmins.append(self.WAGNER_MCGARRY_Tmin); Tmaxs.append(self.WAGNER_MCGARRY_Tc) if self.CASRN in WagnerPoling.index: methods.append(WAGNER_POLING) _, A, B, C, D, self.WAGNER_POLING_Tc, self.WAGNER_POLING_Pc, Tmin, self.WAGNER_POLING_Tmax = _WagnerPoling_values[WagnerPoling.index.get_loc(self.CASRN)].tolist() # Some Tmin values are missing; Arbitrary choice of 0.1 lower limit self.WAGNER_POLING_Tmin = Tmin if not np.isnan(Tmin) else self.WAGNER_POLING_Tmax*0.1 self.WAGNER_POLING_coefs = [A, B, C, D] Tmins.append(Tmin); Tmaxs.append(self.WAGNER_POLING_Tmax) if self.CASRN in AntoineExtended.index: methods.append(ANTOINE_EXTENDED_POLING) _, A, B, C, Tc, to, n, E, F, self.ANTOINE_EXTENDED_POLING_Tmin, self.ANTOINE_EXTENDED_POLING_Tmax = _AntoineExtended_values[AntoineExtended.index.get_loc(self.CASRN)].tolist() self.ANTOINE_EXTENDED_POLING_coefs = [Tc, to, A, B, C, n, E, F] Tmins.append(self.ANTOINE_EXTENDED_POLING_Tmin); Tmaxs.append(self.ANTOINE_EXTENDED_POLING_Tmax) if self.CASRN in AntoinePoling.index: methods.append(ANTOINE_POLING) _, A, B, C, self.ANTOINE_POLING_Tmin, self.ANTOINE_POLING_Tmax = _AntoinePoling_values[AntoinePoling.index.get_loc(self.CASRN)].tolist() self.ANTOINE_POLING_coefs = [A, B, C] Tmins.append(self.ANTOINE_POLING_Tmin); Tmaxs.append(self.ANTOINE_POLING_Tmax) if self.CASRN in Perrys2_8.index: methods.append(DIPPR_PERRY_8E) _, C1, C2, C3, C4, C5, self.Perrys2_8_Tmin, self.Perrys2_8_Tmax = _Perrys2_8_values[Perrys2_8.index.get_loc(self.CASRN)].tolist() self.Perrys2_8_coeffs = [C1, C2, C3, C4, C5] Tmins.append(self.Perrys2_8_Tmin); Tmaxs.append(self.Perrys2_8_Tmax) if has_CoolProp and self.CASRN in coolprop_dict: methods.append(COOLPROP) self.CP_f = coolprop_fluids[self.CASRN] Tmins.append(self.CP_f.Tmin); Tmaxs.append(self.CP_f.Tc) if self.CASRN in _VDISaturationDict: methods.append(VDI_TABULAR) Ts, props = VDI_tabular_data(self.CASRN, 'P') 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 VDI_PPDS_3.index: _, Tm, Tc, Pc, A, B, C, D = _VDI_PPDS_3_values[VDI_PPDS_3.index.get_loc(self.CASRN)].tolist() self.VDI_PPDS_coeffs = [A, B, C, D] self.VDI_PPDS_Tc = Tc self.VDI_PPDS_Tm = Tm self.VDI_PPDS_Pc = Pc methods.append(VDI_PPDS) Tmins.append(self.VDI_PPDS_Tm); Tmaxs.append(self.VDI_PPDS_Tc) if all((self.Tb, self.Tc, self.Pc)): methods.append(BOILING_CRITICAL) Tmins.append(0.01); Tmaxs.append(self.Tc) if all((self.Tc, self.Pc, self.omega)): methods.append(LEE_KESLER_PSAT) methods.append(AMBROSE_WALTON) methods.append(SANJARI) methods.append(EDALAT) if self.eos: methods.append(EOS) Tmins.append(0.01); Tmaxs.append(self.Tc) self.all_methods = set(methods) if Tmins and Tmaxs: self.Tmin = min(Tmins) self.Tmax = max(Tmaxs)
def calculate(self, T, method): r'''Method to calculate vapor pressure of a fluid at temperature `T` with a given method. This method has no exception handling; see `T_dependent_property` for that. Parameters ---------- T : float Temperature at calculate vapor pressure, [K] method : str Name of the method to use Returns ------- Psat : float Vapor pressure at T, [pa] ''' if method == WAGNER_MCGARRY: Psat = Wagner_original(T, self.WAGNER_MCGARRY_Tc, self.WAGNER_MCGARRY_Pc, *self.WAGNER_MCGARRY_coefs) elif method == WAGNER_POLING: Psat = Wagner(T, self.WAGNER_POLING_Tc, self.WAGNER_POLING_Pc, *self.WAGNER_POLING_coefs) elif method == ANTOINE_EXTENDED_POLING: Psat = TRC_Antoine_extended(T, *self.ANTOINE_EXTENDED_POLING_coefs) elif method == ANTOINE_POLING: A, B, C = self.ANTOINE_POLING_coefs Psat = Antoine(T, A, B, C, base=10.0) elif method == DIPPR_PERRY_8E: Psat = EQ101(T, *self.Perrys2_8_coeffs) elif method == VDI_PPDS: Psat = Wagner(T, self.VDI_PPDS_Tc, self.VDI_PPDS_Pc, *self.VDI_PPDS_coeffs) elif method == COOLPROP: Psat = PropsSI('P','T', T,'Q',0, self.CASRN) elif method == BOILING_CRITICAL: Psat = boiling_critical_relation(T, self.Tb, self.Tc, self.Pc) elif method == LEE_KESLER_PSAT: Psat = Lee_Kesler(T, self.Tc, self.Pc, self.omega) elif method == AMBROSE_WALTON: Psat = Ambrose_Walton(T, self.Tc, self.Pc, self.omega) elif method == SANJARI: Psat = Sanjari(T, self.Tc, self.Pc, self.omega) elif method == EDALAT: Psat = Edalat(T, self.Tc, self.Pc, self.omega) elif method == EOS: Psat = self.eos[0].Psat(T) elif method in self.tabular_data: Psat = self.interpolate(T, method) return Psat
def TWU_a_alpha_common(T, Tc, omega, a, full=True, quick=True, method='PR'): r'''Function to calculate `a_alpha` and optionally its first and second derivatives for the TWUPR or TWUSRK EOS. Returns 'a_alpha', and optionally 'da_alpha_dT' and 'd2a_alpha_dT2'. Used by `TWUPR` and `TWUSRK`; has little purpose on its own. See either class for the correct reference, and examples of using the EOS. Parameters ---------- T : float Temperature, [K] Tc : float Critical temperature, [K] omega : float Acentric factor, [-] a : float Coefficient calculated by EOS-specific method, [J^2/mol^2/Pa] full : float Whether or not to return its first and second derivatives quick : bool, optional Whether to use a SymPy cse-derived expression (3x faster) or individual formulas method : str Either 'PR' or 'SRK' Notes ----- The derivatives are somewhat long and are not described here for brevity; they are obtainable from the following SymPy expression. >>> from sympy import * >>> T, Tc, omega, N1, N0, M1, M0, L1, L0 = symbols('T, Tc, omega, N1, N0, M1, M0, L1, L0') >>> Tr = T/Tc >>> alpha0 = Tr**(N0*(M0-1))*exp(L0*(1-Tr**(N0*M0))) >>> alpha1 = Tr**(N1*(M1-1))*exp(L1*(1-Tr**(N1*M1))) >>> alpha = alpha0 + omega*(alpha1-alpha0) >>> # diff(alpha, T) >>> # diff(alpha, T, T) ''' Tr = T/Tc if method == 'PR': if Tr < 1: L0, M0, N0 = 0.125283, 0.911807, 1.948150 L1, M1, N1 = 0.511614, 0.784054, 2.812520 else: L0, M0, N0 = 0.401219, 4.963070, -0.2 L1, M1, N1 = 0.024955, 1.248089, -8. elif method == 'SRK': if Tr < 1: L0, M0, N0 = 0.141599, 0.919422, 2.496441 L1, M1, N1 = 0.500315, 0.799457, 3.291790 else: L0, M0, N0 = 0.441411, 6.500018, -0.20 L1, M1, N1 = 0.032580, 1.289098, -8.0 else: raise Exception('Only `PR` and `SRK` are accepted as method') if not full: alpha0 = Tr**(N0*(M0-1.))*exp(L0*(1.-Tr**(N0*M0))) alpha1 = Tr**(N1*(M1-1.))*exp(L1*(1.-Tr**(N1*M1))) alpha = alpha0 + omega*(alpha1 - alpha0) return a*alpha else: if quick: x0 = T/Tc x1 = M0 - 1 x2 = N0*x1 x3 = x0**x2 x4 = M0*N0 x5 = x0**x4 x6 = exp(-L0*(x5 - 1.)) x7 = x3*x6 x8 = M1 - 1. x9 = N1*x8 x10 = x0**x9 x11 = M1*N1 x12 = x0**x11 x13 = x2*x7 x14 = L0*M0*N0*x3*x5*x6 x15 = x13 - x14 x16 = exp(-L1*(x12 - 1)) x17 = -L1*M1*N1*x10*x12*x16 + x10*x16*x9 - x13 + x14 x18 = N0*N0 x19 = x18*x3*x6 x20 = x1**2*x19 x21 = M0**2 x22 = L0*x18*x3*x5*x6 x23 = x21*x22 x24 = 2*M0*x1*x22 x25 = L0**2*x0**(2*x4)*x19*x21 x26 = N1**2 x27 = x10*x16*x26 x28 = M1**2 x29 = L1*x10*x12*x16*x26 a_alpha = a*(-omega*(-x10*exp(L1*(-x12 + 1)) + x3*exp(L0*(-x5 + 1))) + x7) da_alpha_dT = a*(omega*x17 + x15)/T d2a_alpha_dT2 = a*(-(omega*(-L1**2*x0**(2.*x11)*x27*x28 + 2.*M1*x29*x8 + x17 + x20 - x23 - x24 + x25 - x27*x8**2 + x28*x29) + x15 - x20 + x23 + x24 - x25)/T**2) else: a_alpha = TWU_a_alpha_common(T=T, Tc=Tc, omega=omega, a=a, full=False, quick=quick, method=method) da_alpha_dT = a*(-L0*M0*N0*(T/Tc)**(M0*N0)*(T/Tc)**(N0*(M0 - 1))*exp(L0*(-(T/Tc)**(M0*N0) + 1))/T + N0*(T/Tc)**(N0*(M0 - 1))*(M0 - 1)*exp(L0*(-(T/Tc)**(M0*N0) + 1))/T + omega*(L0*M0*N0*(T/Tc)**(M0*N0)*(T/Tc)**(N0*(M0 - 1))*exp(L0*(-(T/Tc)**(M0*N0) + 1))/T - L1*M1*N1*(T/Tc)**(M1*N1)*(T/Tc)**(N1*(M1 - 1))*exp(L1*(-(T/Tc)**(M1*N1) + 1))/T - N0*(T/Tc)**(N0*(M0 - 1))*(M0 - 1)*exp(L0*(-(T/Tc)**(M0*N0) + 1))/T + N1*(T/Tc)**(N1*(M1 - 1))*(M1 - 1)*exp(L1*(-(T/Tc)**(M1*N1) + 1))/T)) d2a_alpha_dT2 = a*((L0**2*M0**2*N0**2*(T/Tc)**(2*M0*N0)*(T/Tc)**(N0*(M0 - 1))*exp(-L0*((T/Tc)**(M0*N0) - 1)) - L0*M0**2*N0**2*(T/Tc)**(M0*N0)*(T/Tc)**(N0*(M0 - 1))*exp(-L0*((T/Tc)**(M0*N0) - 1)) - 2*L0*M0*N0**2*(T/Tc)**(M0*N0)*(T/Tc)**(N0*(M0 - 1))*(M0 - 1)*exp(-L0*((T/Tc)**(M0*N0) - 1)) + L0*M0*N0*(T/Tc)**(M0*N0)*(T/Tc)**(N0*(M0 - 1))*exp(-L0*((T/Tc)**(M0*N0) - 1)) + N0**2*(T/Tc)**(N0*(M0 - 1))*(M0 - 1)**2*exp(-L0*((T/Tc)**(M0*N0) - 1)) - N0*(T/Tc)**(N0*(M0 - 1))*(M0 - 1)*exp(-L0*((T/Tc)**(M0*N0) - 1)) - omega*(L0**2*M0**2*N0**2*(T/Tc)**(2*M0*N0)*(T/Tc)**(N0*(M0 - 1))*exp(-L0*((T/Tc)**(M0*N0) - 1)) - L0*M0**2*N0**2*(T/Tc)**(M0*N0)*(T/Tc)**(N0*(M0 - 1))*exp(-L0*((T/Tc)**(M0*N0) - 1)) - 2*L0*M0*N0**2*(T/Tc)**(M0*N0)*(T/Tc)**(N0*(M0 - 1))*(M0 - 1)*exp(-L0*((T/Tc)**(M0*N0) - 1)) + L0*M0*N0*(T/Tc)**(M0*N0)*(T/Tc)**(N0*(M0 - 1))*exp(-L0*((T/Tc)**(M0*N0) - 1)) - L1**2*M1**2*N1**2*(T/Tc)**(2*M1*N1)*(T/Tc)**(N1*(M1 - 1))*exp(-L1*((T/Tc)**(M1*N1) - 1)) + L1*M1**2*N1**2*(T/Tc)**(M1*N1)*(T/Tc)**(N1*(M1 - 1))*exp(-L1*((T/Tc)**(M1*N1) - 1)) + 2*L1*M1*N1**2*(T/Tc)**(M1*N1)*(T/Tc)**(N1*(M1 - 1))*(M1 - 1)*exp(-L1*((T/Tc)**(M1*N1) - 1)) - L1*M1*N1*(T/Tc)**(M1*N1)*(T/Tc)**(N1*(M1 - 1))*exp(-L1*((T/Tc)**(M1*N1) - 1)) + N0**2*(T/Tc)**(N0*(M0 - 1))*(M0 - 1)**2*exp(-L0*((T/Tc)**(M0*N0) - 1)) - N0*(T/Tc)**(N0*(M0 - 1))*(M0 - 1)*exp(-L0*((T/Tc)**(M0*N0) - 1)) - N1**2*(T/Tc)**(N1*(M1 - 1))*(M1 - 1)**2*exp(-L1*((T/Tc)**(M1*N1) - 1)) + N1*(T/Tc)**(N1*(M1 - 1))*(M1 - 1)*exp(-L1*((T/Tc)**(M1*N1) - 1))))/T**2) return a_alpha, da_alpha_dT, d2a_alpha_dT2
def check_sufficient_inputs(self): '''Method to an exception if none of the pairs (T, P), (T, V), or (P, V) are given. ''' if not ((self.T and self.P) or (self.T and self.V) or (self.P and self.V)): raise Exception('Either T and P, or T and V, or P and V are required')
def solve(self): '''First EOS-generic method; should be called by all specific EOSs. For solving for `T`, the EOS must provide the method `solve_T`. For all cases, the EOS must provide `a_alpha_and_derivatives`. Calls `set_from_PT` once done. ''' self.check_sufficient_inputs() if self.V: if self.P: self.T = self.solve_T(self.P, self.V) self.a_alpha, self.da_alpha_dT, self.d2a_alpha_dT2 = self.a_alpha_and_derivatives(self.T) else: self.a_alpha, self.da_alpha_dT, self.d2a_alpha_dT2 = self.a_alpha_and_derivatives(self.T) self.P = R*self.T/(self.V-self.b) - self.a_alpha/(self.V*self.V + self.delta*self.V + self.epsilon) Vs = [self.V, 1j, 1j] else: self.a_alpha, self.da_alpha_dT, self.d2a_alpha_dT2 = self.a_alpha_and_derivatives(self.T) Vs = self.volume_solutions(self.T, self.P, self.b, self.delta, self.epsilon, self.a_alpha) self.set_from_PT(Vs)
def set_from_PT(self, Vs): '''Counts the number of real volumes in `Vs`, and determines what to do. If there is only one real volume, the method `set_properties_from_solution` is called with it. If there are two real volumes, `set_properties_from_solution` is called once with each volume. The phase is returned by `set_properties_from_solution`, and the volumes is set to either `V_l` or `V_g` as appropriate. Parameters ---------- Vs : list[float] Three possible molar volumes, [m^3/mol] ''' # All roots will have some imaginary component; ignore them if > 1E-9 good_roots = [] bad_roots = [] for i in Vs: j = i.real if abs(i.imag) > 1E-9 or j < 0: bad_roots.append(i) else: good_roots.append(j) if len(bad_roots) == 2: V = good_roots[0] self.phase = self.set_properties_from_solution(self.T, self.P, V, self.b, self.delta, self.epsilon, self.a_alpha, self.da_alpha_dT, self.d2a_alpha_dT2) if self.phase == 'l': self.V_l = V else: self.V_g = V else: # Even in the case of three real roots, it is still the min/max that make sense self.V_l, self.V_g = min(good_roots), max(good_roots) [self.set_properties_from_solution(self.T, self.P, V, self.b, self.delta, self.epsilon, self.a_alpha, self.da_alpha_dT, self.d2a_alpha_dT2) for V in [self.V_l, self.V_g]] self.phase = 'l/g'
def set_properties_from_solution(self, T, P, V, b, delta, epsilon, a_alpha, da_alpha_dT, d2a_alpha_dT2, quick=True): r'''Sets all interesting properties which can be calculated from an EOS alone. Determines which phase the fluid is on its own; for details, see `phase_identification_parameter`. The list of properties set is as follows, with all properties suffixed with '_l' or '_g'. dP_dT, dP_dV, dV_dT, dV_dP, dT_dV, dT_dP, d2P_dT2, d2P_dV2, d2V_dT2, d2V_dP2, d2T_dV2, d2T_dP2, d2V_dPdT, d2P_dTdV, d2T_dPdV, H_dep, S_dep, beta, kappa, Cp_minus_Cv, V_dep, U_dep, G_dep, A_dep, fugacity, phi, and PIP. Parameters ---------- T : float Temperature, [K] P : float Pressure, [Pa] V : float Molar volume, [m^3/mol] b : float Coefficient calculated by EOS-specific method, [m^3/mol] delta : float Coefficient calculated by EOS-specific method, [m^3/mol] epsilon : float Coefficient calculated by EOS-specific method, [m^6/mol^2] a_alpha : float Coefficient calculated by EOS-specific method, [J^2/mol^2/Pa] da_alpha_dT : float Temperature derivative of coefficient calculated by EOS-specific method, [J^2/mol^2/Pa/K] d2a_alpha_dT2 : float Second temperature derivative of coefficient calculated by EOS-specific method, [J^2/mol^2/Pa/K**2] quick : bool, optional Whether to use a SymPy cse-derived expression (3x faster) or individual formulas Returns ------- phase : str Either 'l' or 'g' Notes ----- The individual formulas for the derivatives and excess properties are as follows. For definitions of `beta`, see `isobaric_expansion`; for `kappa`, see isothermal_compressibility; for `Cp_minus_Cv`, see `Cp_minus_Cv`; for `phase_identification_parameter`, see `phase_identification_parameter`. First derivatives; in part using the Triple Product Rule [2]_, [3]_: .. math:: \left(\frac{\partial P}{\partial T}\right)_V = \frac{R}{V - b} - \frac{a \frac{d \alpha{\left (T \right )}}{d T}}{V^{2} + V \delta + \epsilon} \left(\frac{\partial P}{\partial V}\right)_T = - \frac{R T}{\left( V - b\right)^{2}} - \frac{a \left(- 2 V - \delta\right) \alpha{ \left (T \right )}}{\left(V^{2} + V \delta + \epsilon\right)^{2}} \left(\frac{\partial V}{\partial T}\right)_P =-\frac{ \left(\frac{\partial P}{\partial T}\right)_V}{ \left(\frac{\partial P}{\partial V}\right)_T} \left(\frac{\partial V}{\partial P}\right)_T =-\frac{ \left(\frac{\partial V}{\partial T}\right)_P}{ \left(\frac{\partial P}{\partial T}\right)_V} \left(\frac{\partial T}{\partial V}\right)_P = \frac{1} {\left(\frac{\partial V}{\partial T}\right)_P} \left(\frac{\partial T}{\partial P}\right)_V = \frac{1} {\left(\frac{\partial P}{\partial T}\right)_V} Second derivatives with respect to one variable; those of `T` and `V` use identities shown in [1]_ and verified numerically: .. math:: \left(\frac{\partial^2 P}{\partial T^2}\right)_V = - \frac{a \frac{d^{2} \alpha{\left (T \right )}}{d T^{2}}}{V^{2} + V \delta + \epsilon} \left(\frac{\partial^2 P}{\partial V^2}\right)_T = 2 \left(\frac{ R T}{\left(V - b\right)^{3}} - \frac{a \left(2 V + \delta\right)^{ 2} \alpha{\left (T \right )}}{\left(V^{2} + V \delta + \epsilon \right)^{3}} + \frac{a \alpha{\left (T \right )}}{\left(V^{2} + V \delta + \epsilon\right)^{2}}\right) \left(\frac{\partial^2 T}{\partial P^2}\right)_V = -\left(\frac{ \partial^2 P}{\partial T^2}\right)_V \left(\frac{\partial P}{ \partial T}\right)^{-3}_V \left(\frac{\partial^2 V}{\partial P^2}\right)_T = -\left(\frac{ \partial^2 P}{\partial V^2}\right)_T \left(\frac{\partial P}{ \partial V}\right)^{-3}_T \left(\frac{\partial^2 T}{\partial V^2}\right)_P = -\left[ \left(\frac{\partial^2 P}{\partial V^2}\right)_T \left(\frac{\partial P}{\partial T}\right)_V - \left(\frac{\partial P}{\partial V}\right)_T \left(\frac{\partial^2 P}{\partial T \partial V}\right) \right] \left(\frac{\partial P}{\partial T}\right)^{-2}_V + \left[\left(\frac{\partial^2 P}{\partial T\partial V}\right) \left(\frac{\partial P}{\partial T}\right)_V - \left(\frac{\partial P}{\partial V}\right)_T \left(\frac{\partial^2 P}{\partial T^2}\right)_V\right] \left(\frac{\partial P}{\partial T}\right)_V^{-3} \left(\frac{\partial P}{\partial V}\right)_T \left(\frac{\partial^2 V}{\partial T^2}\right)_P = -\left[ \left(\frac{\partial^2 P}{\partial T^2}\right)_V \left(\frac{\partial P}{\partial V}\right)_T - \left(\frac{\partial P}{\partial T}\right)_V \left(\frac{\partial^2 P}{\partial T \partial V}\right) \right] \left(\frac{\partial P}{\partial V}\right)^{-2}_T + \left[\left(\frac{\partial^2 P}{\partial T\partial V}\right) \left(\frac{\partial P}{\partial V}\right)_T - \left(\frac{\partial P}{\partial T}\right)_V \left(\frac{\partial^2 P}{\partial V^2}\right)_T\right] \left(\frac{\partial P}{\partial V}\right)_T^{-3} \left(\frac{\partial P}{\partial T}\right)_V Second derivatives with respect to the other two variables; those of `T` and `V` use identities shown in [1]_ and verified numerically: .. math:: \left(\frac{\partial^2 P}{\partial T \partial V}\right) = - \frac{ R}{\left(V - b\right)^{2}} + \frac{a \left(2 V + \delta\right) \frac{d \alpha{\left (T \right )}}{d T}}{\left(V^{2} + V \delta + \epsilon\right)^{2}} \left(\frac{\partial^2 T}{\partial P\partial V}\right) = - \left[\left(\frac{\partial^2 P}{\partial T \partial V}\right) \left(\frac{\partial P}{\partial T}\right)_V - \left(\frac{\partial P}{\partial V}\right)_T \left(\frac{\partial^2 P}{\partial T^2}\right)_V \right]\left(\frac{\partial P}{\partial T}\right)_V^{-3} \left(\frac{\partial^2 V}{\partial T\partial P}\right) = - \left[\left(\frac{\partial^2 P}{\partial T \partial V}\right) \left(\frac{\partial P}{\partial V}\right)_T - \left(\frac{\partial P}{\partial T}\right)_V \left(\frac{\partial^2 P}{\partial V^2}\right)_T \right]\left(\frac{\partial P}{\partial V}\right)_T^{-3} Excess properties .. math:: H_{dep} = \int_{\infty}^V \left[T\frac{\partial P}{\partial T}_V - P\right]dV + PV - RT= P V - R T + \frac{2}{\sqrt{ \delta^{2} - 4 \epsilon}} \left(T a \frac{d \alpha{\left (T \right )}}{d T} - a \alpha{\left (T \right )}\right) \operatorname{atanh} {\left (\frac{2 V + \delta}{\sqrt{\delta^{2} - 4 \epsilon}} \right)} S_{dep} = \int_{\infty}^V\left[\frac{\partial P}{\partial T} - \frac{R}{V}\right] dV + R\log\frac{PV}{RT} = - R \log{\left (V \right )} + R \log{\left (\frac{P V}{R T} \right )} + R \log{\left (V - b \right )} + \frac{2 a \frac{d\alpha{\left (T \right )}}{d T} }{\sqrt{\delta^{2} - 4 \epsilon}} \operatorname{atanh}{\left (\frac {2 V + \delta}{\sqrt{\delta^{2} - 4 \epsilon}} \right )} V_{dep} = V - \frac{RT}{P} U_{dep} = H_{dep} - P V_{dep} G_{dep} = H_{dep} - T S_{dep} A_{dep} = U_{dep} - T S_{dep} \text{fugacity} = P\exp\left(\frac{G_{dep}}{RT}\right) \phi = \frac{\text{fugacity}}{P} C_{v, dep} = T\int_\infty^V \left(\frac{\partial^2 P}{\partial T^2}\right) dV = - T a \left(\sqrt{\frac{1}{\delta^{2} - 4 \epsilon}} \log{\left (V - \frac{\delta^{2}}{2} \sqrt{\frac{1}{ \delta^{2} - 4 \epsilon}} + \frac{\delta}{2} + 2 \epsilon \sqrt{ \frac{1}{\delta^{2} - 4 \epsilon}} \right )} - \sqrt{\frac{1}{ \delta^{2} - 4 \epsilon}} \log{\left (V + \frac{\delta^{2}}{2} \sqrt{\frac{1}{\delta^{2} - 4 \epsilon}} + \frac{\delta}{2} - 2 \epsilon \sqrt{\frac{1}{\delta^{2} - 4 \epsilon}} \right )} \right) \frac{d^{2} \alpha{\left (T \right )} }{d T^{2}} C_{p, dep} = (C_p-C_v)_{\text{from EOS}} + C_{v, dep} - R References ---------- .. [1] Thorade, Matthis, and Ali Saadat. "Partial Derivatives of Thermodynamic State Properties for Dynamic Simulation." Environmental Earth Sciences 70, no. 8 (April 10, 2013): 3497-3503. doi:10.1007/s12665-013-2394-z. .. [2] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000. .. [3] Walas, Stanley M. Phase Equilibria in Chemical Engineering. Butterworth-Heinemann, 1985. ''' ([dP_dT, dP_dV, dV_dT, dV_dP, dT_dV, dT_dP], [d2P_dT2, d2P_dV2, d2V_dT2, d2V_dP2, d2T_dV2, d2T_dP2], [d2V_dPdT, d2P_dTdV, d2T_dPdV], [H_dep, S_dep, Cv_dep]) = self.derivatives_and_departures(T, P, V, b, delta, epsilon, a_alpha, da_alpha_dT, d2a_alpha_dT2, quick=quick) beta = dV_dT/V # isobaric_expansion(V, dV_dT) kappa = -dV_dP/V # isothermal_compressibility(V, dV_dP) Cp_m_Cv = -T*dP_dT*dP_dT/dP_dV # Cp_minus_Cv(T, dP_dT, dP_dV) Cp_dep = Cp_m_Cv + Cv_dep - R V_dep = (V - R*T/P) U_dep = H_dep - P*V_dep G_dep = H_dep - T*S_dep A_dep = U_dep - T*S_dep fugacity = P*exp(G_dep/(R*T)) phi = fugacity/P PIP = V*(d2P_dTdV/dP_dT - d2P_dV2/dP_dV) # phase_identification_parameter(V, dP_dT, dP_dV, d2P_dV2, d2P_dTdV) phase = 'l' if PIP > 1 else 'g' # phase_identification_parameter_phase(PIP) if phase == 'l': self.Z_l = self.P*V/(R*self.T) self.beta_l, self.kappa_l = beta, kappa self.PIP_l, self.Cp_minus_Cv_l = PIP, Cp_m_Cv self.dP_dT_l, self.dP_dV_l, self.dV_dT_l = dP_dT, dP_dV, dV_dT self.dV_dP_l, self.dT_dV_l, self.dT_dP_l = dV_dP, dT_dV, dT_dP self.d2P_dT2_l, self.d2P_dV2_l = d2P_dT2, d2P_dV2 self.d2V_dT2_l, self.d2V_dP2_l = d2V_dT2, d2V_dP2 self.d2T_dV2_l, self.d2T_dP2_l = d2T_dV2, d2T_dP2 self.d2V_dPdT_l, self.d2P_dTdV_l, self.d2T_dPdV_l = d2V_dPdT, d2P_dTdV, d2T_dPdV self.H_dep_l, self.S_dep_l, self.V_dep_l = H_dep, S_dep, V_dep, self.U_dep_l, self.G_dep_l, self.A_dep_l = U_dep, G_dep, A_dep, self.fugacity_l, self.phi_l = fugacity, phi self.Cp_dep_l, self.Cv_dep_l = Cp_dep, Cv_dep else: self.Z_g = self.P*V/(R*self.T) self.beta_g, self.kappa_g = beta, kappa self.PIP_g, self.Cp_minus_Cv_g = PIP, Cp_m_Cv self.dP_dT_g, self.dP_dV_g, self.dV_dT_g = dP_dT, dP_dV, dV_dT self.dV_dP_g, self.dT_dV_g, self.dT_dP_g = dV_dP, dT_dV, dT_dP self.d2P_dT2_g, self.d2P_dV2_g = d2P_dT2, d2P_dV2 self.d2V_dT2_g, self.d2V_dP2_g = d2V_dT2, d2V_dP2 self.d2T_dV2_g, self.d2T_dP2_g = d2T_dV2, d2T_dP2 self.d2V_dPdT_g, self.d2P_dTdV_g, self.d2T_dPdV_g = d2V_dPdT, d2P_dTdV, d2T_dPdV self.H_dep_g, self.S_dep_g, self.V_dep_g = H_dep, S_dep, V_dep, self.U_dep_g, self.G_dep_g, self.A_dep_g = U_dep, G_dep, A_dep, self.fugacity_g, self.phi_g = fugacity, phi self.Cp_dep_g, self.Cv_dep_g = Cp_dep, Cv_dep return phase
def solve_T(self, P, V, quick=True): '''Generic method to calculate `T` from a specified `P` and `V`. Provides SciPy's `newton` solver, and iterates to solve the general equation for `P`, recalculating `a_alpha` as a function of temperature using `a_alpha_and_derivatives` each iteration. 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 - not applicable where a numerical solver is used. Returns ------- T : float Temperature, [K] ''' def to_solve(T): a_alpha = self.a_alpha_and_derivatives(T, full=False) P_calc = R*T/(V-self.b) - a_alpha/(V*V + self.delta*V + self.epsilon) return P_calc - P return newton(to_solve, self.Tc*0.5)
def volume_solutions(T, P, b, delta, epsilon, a_alpha, quick=True): r'''Solution of this form of the cubic EOS in terms of volumes. Returns three values, all with some complex part. Parameters ---------- T : float Temperature, [K] P : float Pressure, [Pa] b : float Coefficient calculated by EOS-specific method, [m^3/mol] delta : float Coefficient calculated by EOS-specific method, [m^3/mol] epsilon : float Coefficient calculated by EOS-specific method, [m^6/mol^2] a_alpha : float Coefficient calculated by EOS-specific method, [J^2/mol^2/Pa] quick : bool, optional Whether to use a SymPy cse-derived expression (3x faster) or individual formulas Returns ------- Vs : list[float] Three possible molar volumes, [m^3/mol] Notes ----- Using explicit formulas, as can be derived in the following example, is faster than most numeric root finding techniques, and finds all values explicitly. It takes several seconds. >>> from sympy import * >>> P, T, V, R, b, a, delta, epsilon, alpha = symbols('P, T, V, R, b, a, delta, epsilon, alpha') >>> Tc, Pc, omega = symbols('Tc, Pc, omega') >>> CUBIC = R*T/(V-b) - a*alpha/(V*V + delta*V + epsilon) - P >>> #solve(CUBIC, V) ''' if quick: x0 = 1./P x1 = P*b x2 = R*T x3 = P*delta x4 = x1 + x2 - x3 x5 = x0*x4 x6 = a_alpha*b x7 = epsilon*x1 x8 = epsilon*x2 x9 = x0*x0 x10 = P*epsilon x11 = delta*x1 x12 = delta*x2 x13 = 3.*a_alpha x14 = 3.*x10 x15 = 3.*x11 x16 = 3.*x12 x17 = -x1 - x2 + x3 x18 = x0*x17*x17 x19 = ((-13.5*x0*(x6 + x7 + x8) - 4.5*x4*x9*(-a_alpha - x10 + x11 + x12) + ((x9*(-4.*x0*(-x13 - x14 + x15 + x16 + x18)**3 + (-9.*x0*x17*(a_alpha + x10 - x11 - x12) + 2.*x17*x17*x17*x9 - 27.*(x6 + x7 + x8))**2))+0j)**0.5*0.5 - x4**3*x9*x0)+0j)**(1./3.) x20 = x13 + x14 - x15 - x16 - x18 x22 = 2.*x5 x24 = 1.7320508075688772j + 1. x25 = 4.*x0*x20/x19 x26 = -1.7320508075688772j + 1. return [(x0*x20/x19 - x19 + x5)/3., (x19*x24 + x22 - x25/x24)/6., (x19*x26 + x22 - x25/x26)/6.] else: return [-(-3*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/P + (-P*b + P*delta - R*T)**2/P**2)/(3*(sqrt(-4*(-3*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/P + (-P*b + P*delta - R*T)**2/P**2)**3 + (27*(-P*b*epsilon - R*T*epsilon - a_alpha*b)/P - 9*(-P*b + P*delta - R*T)*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/P**2 + 2*(-P*b + P*delta - R*T)**3/P**3)**2)/2 + 27*(-P*b*epsilon - R*T*epsilon - a_alpha*b)/(2*P) - 9*(-P*b + P*delta - R*T)*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/(2*P**2) + (-P*b + P*delta - R*T)**3/P**3)**(1/3)) - (sqrt(-4*(-3*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/P + (-P*b + P*delta - R*T)**2/P**2)**3 + (27*(-P*b*epsilon - R*T*epsilon - a_alpha*b)/P - 9*(-P*b + P*delta - R*T)*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/P**2 + 2*(-P*b + P*delta - R*T)**3/P**3)**2)/2 + 27*(-P*b*epsilon - R*T*epsilon - a_alpha*b)/(2*P) - 9*(-P*b + P*delta - R*T)*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/(2*P**2) + (-P*b + P*delta - R*T)**3/P**3)**(1/3)/3 - (-P*b + P*delta - R*T)/(3*P), -(-3*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/P + (-P*b + P*delta - R*T)**2/P**2)/(3*(-1/2 - sqrt(3)*1j/2)*(sqrt(-4*(-3*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/P + (-P*b + P*delta - R*T)**2/P**2)**3 + (27*(-P*b*epsilon - R*T*epsilon - a_alpha*b)/P - 9*(-P*b + P*delta - R*T)*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/P**2 + 2*(-P*b + P*delta - R*T)**3/P**3)**2)/2 + 27*(-P*b*epsilon - R*T*epsilon - a_alpha*b)/(2*P) - 9*(-P*b + P*delta - R*T)*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/(2*P**2) + (-P*b + P*delta - R*T)**3/P**3)**(1/3)) - (-1/2 - sqrt(3)*1j/2)*(sqrt(-4*(-3*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/P + (-P*b + P*delta - R*T)**2/P**2)**3 + (27*(-P*b*epsilon - R*T*epsilon - a_alpha*b)/P - 9*(-P*b + P*delta - R*T)*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/P**2 + 2*(-P*b + P*delta - R*T)**3/P**3)**2)/2 + 27*(-P*b*epsilon - R*T*epsilon - a_alpha*b)/(2*P) - 9*(-P*b + P*delta - R*T)*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/(2*P**2) + (-P*b + P*delta - R*T)**3/P**3)**(1/3)/3 - (-P*b + P*delta - R*T)/(3*P), -(-3*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/P + (-P*b + P*delta - R*T)**2/P**2)/(3*(-1/2 + sqrt(3)*1j/2)*(sqrt(-4*(-3*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/P + (-P*b + P*delta - R*T)**2/P**2)**3 + (27*(-P*b*epsilon - R*T*epsilon - a_alpha*b)/P - 9*(-P*b + P*delta - R*T)*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/P**2 + 2*(-P*b + P*delta - R*T)**3/P**3)**2)/2 + 27*(-P*b*epsilon - R*T*epsilon - a_alpha*b)/(2*P) - 9*(-P*b + P*delta - R*T)*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/(2*P**2) + (-P*b + P*delta - R*T)**3/P**3)**(1/3)) - (-1/2 + sqrt(3)*1j/2)*(sqrt(-4*(-3*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/P + (-P*b + P*delta - R*T)**2/P**2)**3 + (27*(-P*b*epsilon - R*T*epsilon - a_alpha*b)/P - 9*(-P*b + P*delta - R*T)*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/P**2 + 2*(-P*b + P*delta - R*T)**3/P**3)**2)/2 + 27*(-P*b*epsilon - R*T*epsilon - a_alpha*b)/(2*P) - 9*(-P*b + P*delta - R*T)*(-P*b*delta + P*epsilon - R*T*delta + a_alpha)/(2*P**2) + (-P*b + P*delta - R*T)**3/P**3)**(1/3)/3 - (-P*b + P*delta - R*T)/(3*P)]
def Psat(self, T, polish=False): r'''Generic method to calculate vapor pressure for a specified `T`. From Tc to 0.32Tc, uses a 10th order polynomial of the following form: .. math:: \ln\frac{P_r}{T_r} = \sum_{k=0}^{10} C_k\left(\frac{\alpha}{T_r} -1\right)^{k} If `polish` is True, SciPy's `newton` solver is launched with the calculated vapor pressure as an initial guess in an attempt to get more accuracy. This may not converge however. Results above the critical temperature are meaningless. A first-order polynomial is used to extrapolate under 0.32 Tc; however, there is normally not a volume solution to the EOS which can produce that low of a pressure. Parameters ---------- T : float Temperature, [K] polish : bool, optional Whether to attempt to use a numerical solver to make the solution more precise or not Returns ------- Psat : float Vapor pressure, [Pa] Notes ----- EOSs sharing the same `b`, `delta`, and `epsilon` have the same coefficient sets. All coefficients were derived with numpy's polyfit. The intersection between the polynomials is continuous, but there is a step change in its derivative. Form for the regression is inspired from [1]_. References ---------- .. [1] Soave, G. "Direct Calculation of Pure-Compound Vapour Pressures through Cubic Equations of State." Fluid Phase Equilibria 31, no. 2 (January 1, 1986): 203-7. doi:10.1016/0378-3812(86)90013-0. ''' alpha = self.a_alpha_and_derivatives(T, full=False)/self.a Tr = T/self.Tc x = alpha/Tr - 1. c = self.Psat_coeffs_limiting if Tr < 0.32 else self.Psat_coeffs y = horner(c, x) try: Psat = exp(y)*Tr*self.Pc except OverflowError: # coefficients sometimes overflow before T is lowered to 0.32Tr polish = False Psat = 0 if polish: def to_solve(P): # For use by newton. Only supports initialization with Tc, Pc and omega # ~200x slower and not guaranteed to converge e = self.__class__(Tc=self.Tc, Pc=self.Pc, omega=self.omega, T=T, P=P) err = e.fugacity_l - e.fugacity_g return err Psat = newton(to_solve, Psat) return Psat
def dPsat_dT(self, T): r'''Generic method to calculate the temperature derivative of vapor pressure for a specified `T`. Implements the analytical derivative of the two polynomials described in `Psat`. As with `Psat`, results above the critical temperature are meaningless. The first-order polynomial which is used to calculate it under 0.32 Tc may not be physicall meaningful, due to there normally not being a volume solution to the EOS which can produce that low of a pressure. Parameters ---------- T : float Temperature, [K] Returns ------- dPsat_dT : float Derivative of vapor pressure with respect to temperature, [Pa/K] Notes ----- There is a small step change at 0.32 Tc for all EOS due to the two switch between polynomials at that point. Useful for calculating enthalpy of vaporization with the Clausius Clapeyron Equation. Derived with SymPy's diff and cse. ''' a_alphas = self.a_alpha_and_derivatives(T) alpha, d_alpha_dT = a_alphas[0]/self.a, a_alphas[1]/self.a Tr = T/self.Tc if Tr >= 0.32: c = self.Psat_coeffs x0 = alpha/T x1 = -self.Tc*x0 + 1 x2 = c[0]*x1 x3 = c[2] - x1*(c[1] - x2) x4 = c[3] - x1*x3 x5 = c[4] - x1*x4 x6 = c[5] - x1*x5 x7 = c[6] - x1*x6 x8 = c[7] - x1*x7 x9 = c[8] - x1*x8 return self.Pc*(-(d_alpha_dT - x0)*(-c[9] + x1*x9 + x1*(-x1*(-x1*(-x1*(-x1*(-x1*(-x1*(-x1*(c[1] - 2*x2) + x3) + x4) + x5) + x6) + x7) + x8) + x9)) + 1./self.Tc)*exp(c[10] - x1*(c[9] - x1*(c[8] - x1*(c[7] - x1*(c[6] - x1*(c[5] - x1*(c[4] - x1*(c[3] - x1*(c[2] + x1*(-c[1] + x2)))))))))) else: c = self.Psat_coeffs_limiting return self.Pc*T*c[0]*(self.Tc*d_alpha_dT/T - self.Tc*alpha/(T*T))*exp(c[0]*(-1. + self.Tc*alpha/T) + c[1])/self.Tc + self.Pc*exp(c[0]*(-1. + self.Tc*alpha/T) + c[1])/self.Tc
def V_l_sat(self, T): r'''Method to calculate molar volume of the liquid phase along the saturation line. Parameters ---------- T : float Temperature, [K] Returns ------- V_l_sat : float Liquid molar volume along the saturation line, [m^3/mol] Notes ----- Computers `Psat`, and then uses `volume_solutions` to obtain the three possible molar volumes. The lowest value is returned. ''' Psat = self.Psat(T) a_alpha = self.a_alpha_and_derivatives(T, full=False) Vs = self.volume_solutions(T, Psat, self.b, self.delta, self.epsilon, a_alpha) # Assume we can safely take the Vmax as gas, Vmin as l on the saturation line return min([i.real for i in Vs])
def V_g_sat(self, T): r'''Method to calculate molar volume of the vapor phase along the saturation line. Parameters ---------- T : float Temperature, [K] Returns ------- V_g_sat : float Gas molar volume along the saturation line, [m^3/mol] Notes ----- Computers `Psat`, and then uses `volume_solutions` to obtain the three possible molar volumes. The highest value is returned. ''' Psat = self.Psat(T) a_alpha = self.a_alpha_and_derivatives(T, full=False) Vs = self.volume_solutions(T, Psat, self.b, self.delta, self.epsilon, a_alpha) # Assume we can safely take the Vmax as gas, Vmin as l on the saturation line return max([i.real for i in Vs])
def Hvap(self, T): r'''Method to calculate enthalpy of vaporization for a pure fluid from an equation of state, without iteration. .. math:: \frac{dP^{sat}}{dT}=\frac{\Delta H_{vap}}{T(V_g - V_l)} Results above the critical temperature are meaningless. A first-order polynomial is used to extrapolate under 0.32 Tc; however, there is normally not a volume solution to the EOS which can produce that low of a pressure. Parameters ---------- T : float Temperature, [K] Returns ------- Hvap : float Increase in enthalpy needed for vaporization of liquid phase along the saturation line, [J/mol] Notes ----- Calculates vapor pressure and its derivative with `Psat` and `dPsat_dT` as well as molar volumes of the saturation liquid and vapor phase in the process. Very near the critical point this provides unrealistic results due to `Psat`'s polynomials being insufficiently accurate. References ---------- .. [1] Walas, Stanley M. Phase Equilibria in Chemical Engineering. Butterworth-Heinemann, 1985. ''' Psat = self.Psat(T) dPsat_dT = self.dPsat_dT(T) a_alpha = self.a_alpha_and_derivatives(T, full=False) Vs = self.volume_solutions(T, Psat, self.b, self.delta, self.epsilon, a_alpha) # Assume we can safely take the Vmax as gas, Vmin as l on the saturation line Vs = [i.real for i in Vs] V_l, V_g = min(Vs), max(Vs) return dPsat_dT*T*(V_g-V_l)
def Heyen(self, T, full=True, quick=True): r'''Method to calculate `a_alpha` and its first and second derivatives according to Heyen (1980) [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 = e^{c_{1} \left(- \left(\frac{T}{Tc}\right)^{c_{2}} + 1\right)} References ---------- .. [1] Heyen, G. Liquid and Vapor Properties from a Cubic Equation of State. In "Proceedings of the 2nd International Conference on Phase Equilibria and Fluid Properties in the Chemical Industry". DECHEMA: Frankfurt, 1980; p 9-13. ''' c1, c2 = self.alpha_function_coeffs T, Tc, a = self.T, self.Tc, self.a a_alpha = a*exp(c1*(1 -(T/Tc)**c2)) if not full: return a_alpha else: da_alpha_dT = -a*c1*c2*(T/Tc)**c2*exp(c1*(-(T/Tc)**c2 + 1))/T d2a_alpha_dT2 = a*c1*c2*(T/Tc)**c2*(c1*c2*(T/Tc)**c2 - c2 + 1)*exp(-c1*((T/Tc)**c2 - 1))/T**2 return a_alpha, da_alpha_dT, d2a_alpha_dT2