Skip to content

Commit

Permalink
Removed documentation for pr; changed VolumeGas to use EOS
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebBell committed Dec 17, 2016
1 parent 22f3b41 commit b2dae35
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 54 deletions.
7 changes: 0 additions & 7 deletions docs/thermo.pr.rst

This file was deleted.

1 change: 0 additions & 1 deletion docs/thermo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Submodules
thermo.miscdata
thermo.permittivity
thermo.phase_change
thermo.pr
thermo.reaction
thermo.refractivity
thermo.safety
Expand Down
8 changes: 2 additions & 6 deletions tests/test_eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,9 +814,7 @@ def dV_dT(T, P, eos, order=0, phase=True, Tc=507.6, Pc=3025000., omega=0.2975):
continue
x.append(numer)
y.append(ana)
ans = allclose_variable(x, y, limits=[.009, .05, .65, .93],rtols=[1E-5, 1E-6, 1E-9, 1E-10])
if not ans:
raise Exception('dVdT numerical derivative failing!')
assert allclose_variable(x, y, limits=[.009, .05, .65, .93],rtols=[1E-5, 1E-6, 1E-9, 1E-10])


@pytest.mark.slow
Expand Down Expand Up @@ -850,8 +848,6 @@ def dV_dP(P, T, eos, order=0, phase=True, Tc=507.6, Pc=3025000., omega=0.2975):
continue
x.append(numer)
y.append(ana)
ans = allclose_variable(x, y, limits=[.02, .04, .04, .05, .15, .45, .95],
assert allclose_variable(x, y, limits=[.02, .04, .04, .05, .15, .45, .95],
rtols=[1E-2, 1E-3, 1E-4, 1E-5, 1E-6, 1E-7, 1E-9])
if not ans:
raise Exception('Error')

16 changes: 7 additions & 9 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,10 @@ def test_allclose_variable():
x = [2.7244322249597719e-08, 3.0105683900110473e-10, 2.7244124924802327e-08, 3.0105259397637556e-10, 2.7243929226310193e-08, 3.0104990272770901e-10, 2.7243666849384451e-08, 3.0104101821236015e-10, 2.7243433745917367e-08, 3.0103707421519949e-10]
y = [2.7244328304561904e-08, 3.0105753470546008e-10, 2.724412872417824e-08, 3.0105303055834564e-10, 2.7243914341030203e-08, 3.0104819238021998e-10, 2.7243684057561379e-08, 3.0104299541023674e-10, 2.7243436694839306e-08, 3.010374130526363e-10]

ans = allclose_variable(x, y, limits=[.0, .5], rtols=[1E-5, 1E-6])
if not ans:
raise Exception('Failure')
assert allclose_variable(x, y, limits=[.0, .5], rtols=[1E-5, 1E-6])

with pytest.raises(Exception):
ans = allclose_variable(x, y, limits=[.0, .1], rtols=[1E-5, 1E-6])
if not ans:
raise Exception('Failure')
assert allclose_variable(x, y, limits=[.0, .1], rtols=[1E-5, 1E-6])

with pytest.raises(Exception):
allclose_variable(x, y[1:], limits=[.0, .5], rtols=[1E-5, 1E-6])
Expand All @@ -463,6 +459,8 @@ def test_allclose_variable():

x = [1,1,1,1,1,1,1,1,1]
y = [.9,.9,.9,.9,.9,.9,.9,.9, .9]
ans = allclose_variable(x, y, limits=[.0], atols=[.1])
if ans is False:
raise Exception('Failure on a unit test')
assert allclose_variable(x, y, limits=[.0], atols=[.1])


def test_horner():
assert horner([1,2,3], 3) == 18
6 changes: 4 additions & 2 deletions tests/test_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import pytest
import pandas as pd
from thermo.volume import *
from thermo.eos import *
from thermo.utils import Vm_to_rho
from thermo.identifiers import checkCAS

Expand Down Expand Up @@ -270,9 +271,10 @@ def test_ideal_gas():

@pytest.mark.meta_T_dept
def test_VolumeGas():
SO2 = VolumeGas(CASRN='7446-09-5', MW=64.0638, Tc=430.8, Pc=7884098.25, omega=0.251, dipole=1.63)
eos = [PR(T=300, P=1E5, Tc=430.8, Pc=7884098.25, omega=0.251)]
SO2 = VolumeGas(CASRN='7446-09-5', MW=64.0638, Tc=430.8, Pc=7884098.25, omega=0.251, dipole=1.63, eos=eos)
Vm_calcs = [(SO2.set_user_methods_P(i, forced_P=True), SO2.TP_dependent_property(305, 1E5))[1] for i in SO2.all_methods_P]
Vm_exp = [0.025024421772080314, 0.02499978619699621, 0.02499586901117375, 0.02499627309459868, 0.02499978619699621, 0.024971467450477493, 0.02535910239]
Vm_exp = [0.025024302563892417, 0.02499978619699621, 0.02499586901117375, 0.02499627309459868, 0.02499978619699621, 0.024971467450477493, 0.02535910239]
assert_allclose(sorted(Vm_calcs), sorted(Vm_exp))

# Test that methods return None
Expand Down
34 changes: 23 additions & 11 deletions thermo/chemical.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,33 +321,39 @@ def set_eos(self, T, P, eos=PR):
self.eos = eos(T=T, P=P, Tc=self.Tc, Pc=self.Pc, omega=self.omega)
else:
self.eos = GCEOS_DUMMY(T=T, P=P)
@property
def eos(self):
return self.eos_in_a_box[0]
@eos.setter
def eos(self, eos):
if self.eos_in_a_box:
self.eos_in_a_box.pop()
# Pass this mutable list to objects so if it is changed, it gets
# changed in the property method too
self.eos_in_a_box.append(self.eos)
self.eos_in_a_box.append(eos)


def set_TP_sources(self):
# Tempearture and Pressure Denepdence
# Get and choose initial methods
self.VaporPressure = VaporPressure(Tb=self.Tb, Tc=self.Tc, Pc=self.Pc, omega=self.omega, CASRN=self.CAS, eos=self.eos_in_a_box)
self.VaporPressure = VaporPressure(Tb=self.Tb, Tc=self.Tc, Pc=self.Pc,
omega=self.omega, CASRN=self.CAS,
eos=self.eos_in_a_box)
self.Psat_298 = self.VaporPressure.T_dependent_property(298.15)


self.VolumeLiquid = VolumeLiquid(MW=self.MW, Tb=self.Tb, Tc=self.Tc,
Pc=self.Pc, Vc=self.Vc, Zc=self.Zc, omega=self.omega,
dipole=self.dipole, Psat=self.VaporPressure.T_dependent_property, CASRN=self.CAS)
dipole=self.dipole,
Psat=self.VaporPressure.T_dependent_property,
eos=self.eos_in_a_box, CASRN=self.CAS)

self.Vml_Tb = self.VolumeLiquid.T_dependent_property(self.Tb) if self.Tb else None
self.Vml_Tm = self.VolumeLiquid.T_dependent_property(self.Tm) if self.Tm else None
self.Vml_STP = self.VolumeLiquid.T_dependent_property(298.15)

# set molecular_diameter; depends on Vml_Tb, Vml_Tm
self.molecular_diameter_sources = molecular_diameter(Tc=self.Tc, Pc=self.Pc, Vc=self.Vc, Zc=self.Zc, omega=self.omega, Vm=self.Vml_Tm, Vb=self.Vml_Tb, AvailableMethods=True, CASRN=self.CAS)
self.molecular_diameter_source = self.molecular_diameter_sources[0]
self.molecular_diameter = molecular_diameter(Tc=self.Tc, Pc=self.Pc, Vc=self.Vc, Zc=self.Zc, omega=self.omega, Vm=self.Vml_Tm, Vb=self.Vml_Tb, Method=self.molecular_diameter_source, CASRN=self.CAS)

self.VolumeGas = VolumeGas(MW=self.MW, Tc=self.Tc, Pc=self.Pc, omega=self.omega, dipole=self.dipole, CASRN=self.CAS)
self.VolumeGas = VolumeGas(MW=self.MW, Tc=self.Tc, Pc=self.Pc,
omega=self.omega, dipole=self.dipole,
eos=self.eos_in_a_box, CASRN=self.CAS)

self.VolumeSolid = VolumeSolid(CASRN=self.CAS, MW=self.MW, Tt=self.Tt)

Expand Down Expand Up @@ -383,8 +389,14 @@ def set_TP_sources(self):

self.phase_STP = identify_phase(T=298.15, P=101325., Tm=self.Tm, Tb=self.Tb, Tc=self.Tc, Psat=self.Psat_298)

# set molecular_diameter; depends on Vml_Tb, Vml_Tm
self.molecular_diameter_sources = molecular_diameter(Tc=self.Tc, Pc=self.Pc, Vc=self.Vc, Zc=self.Zc, omega=self.omega, Vm=self.Vml_Tm, Vb=self.Vml_Tb, AvailableMethods=True, CASRN=self.CAS)
self.molecular_diameter_source = self.molecular_diameter_sources[0]
self.molecular_diameter = molecular_diameter(Tc=self.Tc, Pc=self.Pc, Vc=self.Vc, Zc=self.Zc, omega=self.omega, Vm=self.Vml_Tm, Vb=self.Vml_Tb, Method=self.molecular_diameter_source, CASRN=self.CAS)

def set_TP(self):
self.eos.to_TP(T=self.T, P=self.P)
self.eos = self.eos.to_TP(T=self.T, P=self.P)
self.eos_in_a_box[0] = self.eos
self.Psat = self.VaporPressure.T_dependent_property(T=self.T)

self.Vms = self.VolumeSolid.T_dependent_property(T=self.T)
Expand Down
26 changes: 25 additions & 1 deletion thermo/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class GCEOS(object):
the liquid or gas phase with the convention of adding on `_l` or `_g` to
the variable names.
'''
kwargs = {}
def check_sufficient_inputs(self):
'''Method to an exception if none of the pairs (T, P), (T, V), or
(P, V) are given. '''
Expand Down Expand Up @@ -643,6 +644,23 @@ def Psat(self, T, polish=False):
-------
Psat : float
Vapor pressure, [Pa]
Notes
-----
Equations of state derived from another but using the same form and
`a` and `b` values work with the former's coefficients.
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
Expand All @@ -664,7 +682,10 @@ def to_solve(P):

def to_TP(self, T, P):
if T != self.T or P != self.P:
self.__init__(T=T, P=P, Tc=self.Tc, Pc=self.Pc, omega=self.omega)
return self.__class__(T=T, P=P, Tc=self.Tc, Pc=self.Pc, omega=self.omega, **self.kwargs)
else:
return self


class GCEOS_DUMMY(GCEOS):
def __init__(self, T=None, P=None, **kwargs):
Expand Down Expand Up @@ -1694,6 +1715,7 @@ def __init__(self, Tc, Pc, omega, T=None, P=None, V=None, kappa1=0):
self.T = T
self.P = P
self.V = V
self.kwargs = {'kappa1': kappa1}

self.a = self.c1*R*R*Tc*Tc/Pc
self.b = self.c2*R*Tc/Pc
Expand Down Expand Up @@ -1890,6 +1912,7 @@ def __init__(self, Tc, Pc, omega, T=None, P=None, V=None, kappa1=0, kappa2=0, ka
self.P = P
self.V = V
self.check_sufficient_inputs()
self.kwargs = {'kappa1': kappa1, 'kappa2': kappa2, 'kappa3': kappa3}

self.a = self.c1*R*R*Tc*Tc/Pc
self.b = self.c2*R*Tc/Pc
Expand Down Expand Up @@ -2576,6 +2599,7 @@ def __init__(self, Tc, Pc, omega=None, T=None, P=None, V=None, S1=None, S2=0):
self.T = T
self.P = P
self.V = V
self.kwargs = {'S1': S1, 'S2': S2}
self.check_sufficient_inputs()

if S1 is None and omega is None:
Expand Down
4 changes: 4 additions & 0 deletions thermo/pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
from scipy.optimize import fsolve
from numpy import roots
from thermo.utils import log, exp
'''
THIS FILE IS EXTREMELY DEPRECATED! CURRENTLY ONLY USED FOR THE CASE OF GAS
MIXTURE VOLUMES.
'''

R = 8.3145

Expand Down
2 changes: 1 addition & 1 deletion thermo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
'Z_from_virial_pressure_form', 'zs_to_ws', 'ws_to_zs', 'zs_to_Vfs',
'Vfs_to_zs', 'none_and_length_check', 'normalize', 'mixing_simple',
'mixing_logarithmic', 'phase_set_property', 'TDependentProperty',
'TPDependentProperty', 'allclose_variable']
'TPDependentProperty', 'allclose_variable', 'horner']

from cmath import sqrt as csqrt
import numpy as np
Expand Down
10 changes: 7 additions & 3 deletions thermo/vapor_pressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def TRC_Antoine_extended(T, Tc, to, A, B, C, n, E, F):

vapor_pressure_methods = [WAGNER_MCGARRY, WAGNER_POLING, ANTOINE_EXTENDED_POLING,
COOLPROP, ANTOINE_POLING, VDI_TABULAR, AMBROSE_WALTON,
LEE_KESLER_PSAT, BOILING_CRITICAL, SANJARI]
LEE_KESLER_PSAT, EOS, BOILING_CRITICAL, SANJARI]
'''Holds all methods available for the VaporPressure class, for use in
iterating over them.'''

Expand Down Expand Up @@ -292,7 +292,7 @@ class VaporPressure(TDependentProperty):

ranked_methods = [WAGNER_MCGARRY, WAGNER_POLING, ANTOINE_EXTENDED_POLING,
COOLPROP, ANTOINE_POLING, VDI_TABULAR, AMBROSE_WALTON,
LEE_KESLER_PSAT, BOILING_CRITICAL, SANJARI]
LEE_KESLER_PSAT, BOILING_CRITICAL, EOS, SANJARI]
'''Default rankings of the available methods.'''

def __init__(self, Tb=None, Tc=None, Pc=None, omega=None, CASRN='',
Expand Down Expand Up @@ -393,6 +393,8 @@ def load_all_methods(self):
methods.append(LEE_KESLER_PSAT)
methods.append(AMBROSE_WALTON)
methods.append(SANJARI)
if self.eos:
methods.append(EOS)
Tmins.append(0.01); Tmaxs.append(self.Tc)
self.all_methods = set(methods)
if Tmins and Tmaxs:
Expand Down Expand Up @@ -440,6 +442,8 @@ def calculate(self, T, method):
Psat = Ambrose_Walton(T, self.Tc, self.Pc, self.omega)
elif method == SANJARI:
Psat = Sanjari(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
Expand Down Expand Up @@ -482,7 +486,7 @@ def test_method_validity(self, T, method):
elif method == COOLPROP:
if T < self.CP_f.Tmin or T < self.CP_f.Tt or T > self.CP_f.Tmax or T > self.CP_f.Tc:
return False
elif method in [BOILING_CRITICAL, LEE_KESLER_PSAT, AMBROSE_WALTON, SANJARI]:
elif method in [BOILING_CRITICAL, LEE_KESLER_PSAT, AMBROSE_WALTON, SANJARI, EOS]:
if T > self.Tc or T < 0:
return False
# No lower limit
Expand Down

0 comments on commit b2dae35

Please sign in to comment.