Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

# -*- coding: utf-8 -*- 

'''Chemical Engineering Design Library (ChEDL). Utilities for process modeling. 

Copyright (C) 2016, Caleb Bell <Caleb.Andrew.Bell@gmail.com> 

 

Permission is hereby granted, free of charge, to any person obtaining a copy 

of this software and associated documentation files (the "Software"), to deal 

in the Software without restriction, including without limitation the rights 

to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 

copies of the Software, and to permit persons to whom the Software is 

furnished to do so, subject to the following conditions: 

 

The above copyright notice and this permission notice shall be included in all 

copies or substantial portions of the Software. 

 

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 

AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 

SOFTWARE.''' 

 

from __future__ import division 

 

__all__ = ['PR_Vm'] 

from scipy.constants import R 

from scipy.optimize import fsolve 

from numpy import roots 

from thermo.utils import log, exp 

 

R = 8.3145 

 

def alpha(omega,Tr): # pragma: no cover 

return (1+(0.37464+1.54226*omega-0.26992*omega**2)*(1-Tr**0.5))**2 

 

def a(Tc, Pc): # pragma: no cover 

a_calc = 0.45724*(R*Tc)**2/Pc 

return a_calc 

 

def b(Tc, Pc): # pragma: no cover 

b_calc = 0.07780*R*Tc/Pc 

return b_calc 

 

def B(T, P, Tc, Pc): # pragma: no cover 

b_calc = b(Tc, Pc) 

B_calc = b_calc*P/R/T 

return B_calc 

 

def a_alpha(T, Tc, Pc, omega): # pragma: no cover 

Tr = T/Tc 

return a(Tc, Pc)*alpha(omega,Tr) 

 

def A(T, P, Tc, Pc, omega): # pragma: no cover 

A_calc = a_alpha(T, Tc, Pc, omega)*P/(R*T)**2 

return A_calc 

 

# This is the function imported by density 

def PR_Vm(T, P, Tc, Pc, omega, phase=''): # pragma: no cover 

A_calc = A(T, P, Tc, Pc, omega) 

B_calc = B(T, P, Tc, Pc) 

coeffs = [1, -(1-B_calc), (A_calc-3*B_calc**2-2*B_calc), -(A_calc*B_calc-B_calc**2-B_calc**3)] 

numpyroots = roots(coeffs) 

liq_z = min(numpyroots) 

gas_z = max(numpyroots) 

liq = float(liq_z*R*T/P) 

gas = float(gas_z*R*T/P) 

if phase=='liquid' or phase.lower( )== 'l': 

soln = liq 

elif phase=='gas' or phase.lower() == 'g' or T >= Tc or P > Pc: 

soln = gas 

else: 

return liq, gas 

return soln