Skip to content

Commit

Permalink
Added another surface tension predictor and another vapor pressure pr…
Browse files Browse the repository at this point in the history
…edictor
  • Loading branch information
CalebBell committed Jan 31, 2017
1 parent 8abc732 commit 2893c75
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 44 deletions.
12 changes: 12 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: fluids

dependencies:
- python
- numpy
- matplotlib
- pandas
- scipy
- pip:
- fluids
- ht
- thermo
59 changes: 36 additions & 23 deletions tests/test_surface_tension.py → tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ def test_csp():
sigma_calc = Miqueu(300., 340.1, 0.000199, 0.1687)
assert_allclose(sigma_calc, 0.003474099603581931)


def test_Aleem():
st = Aleem(T=90, MW=16.04246, Tb=111.6, rhol=458.7, Hvap_Tb=510870., Cpl=2465.)
assert_allclose(st, 0.01669970221165325)


def test_REFPROP():
sigma = REFPROP(298.15, 647.096, -0.1306, 2.471, 0.2151, 1.233)
assert_allclose(sigma, 0.07205503890847453)
Expand Down Expand Up @@ -106,7 +111,31 @@ def test_data():
assert Somayajulu_data_2.index.is_unique


def test_sigma_mixture_methods():

@pytest.mark.meta_T_dept
def test_SurfaceTension():
# Ethanol, test as many methods as possible at once
EtOH = SurfaceTension(Tb=351.39, Tc=514.0, Pc=6137000.0, Vc=0.000168, Zc=0.24125, omega=0.635, StielPolar=-0.01266, CASRN='64-17-5')
EtOH.T_dependent_property(305.)
sigma_calcs = [(EtOH.set_user_methods(i), EtOH.T_dependent_property(305.))[1] for i in EtOH.sorted_valid_methods]
sigma_exp = [0.021222422444285592, 0.02171156653650729, 0.02171156653650729, 0.021532564572262793, 0.02140008, 0.038055725907414066, 0.03739257387107131, 0.02645171690486362, 0.03905907338532845, 0.03670733205970745]

assert_allclose(sigma_calcs, sigma_exp)

# Test that methods return None
sigma_calcs = [(EtOH.set_user_methods(i, forced=True), EtOH.T_dependent_property(5000))[1] for i in EtOH.sorted_valid_methods]
assert [None]*10 == sigma_calcs

EtOH.set_user_methods('VDI_TABULAR', forced=True)
EtOH.tabular_extrapolation_permitted = False
assert None == EtOH.T_dependent_property(700.)

with pytest.raises(Exception):
EtOH.test_method_validity(300, 'BADMETHOD')



def test_Winterfeld_Scriven_Davis():
# The example is from [2]_; all results agree.
# The original source has not been reviewed.
# 16.06 mol% n-pentane, 83.94 mol% dichloromethane at 298.15 K.
Expand All @@ -118,15 +147,20 @@ def test_sigma_mixture_methods():
with pytest.raises(Exception):
Winterfeld_Scriven_Davis([0.1606, 0.8394, 0.118], [0.01547, 0.02877], [8610., 15530.])

# Same example, with Diguilio Teja. Calculated sigmas at Tbs are

def test_Diguilio_Teja():
# Winterfeld_Scriven_Davis example, with Diguilio Teja. Calculated sigmas at Tbs are
# 0.01424 and 0.02530.
# Checked and edited 2017-01-30

sigma = Diguilio_Teja(T=298.15, xs=[0.1606, 0.8394], sigmas_Tb=[0.01424, 0.02530], Tbs=[309.21, 312.95], Tcs=[469.7, 508.0])
assert_allclose(sigma, 0.025716823875045505)

with pytest.raises(Exception):
Diguilio_Teja(T=298.15, xs=[0.1606, 0.8394, 0.118], sigmas_Tb=[0.01424, 0.02530], Tbs=[309.21, 312.95], Tcs=[469.7, 508.0])

with pytest.raises(Exception):
Diguilio_Teja(T=501.85, xs=[0.1606, 0.8394], sigmas_Tb=[0.01424, 0.02530], Tbs=[309.21, 312.95], Tcs=[469.7, 508.0])


def test_sigma_mixture():
Expand All @@ -148,24 +182,3 @@ def test_sigma_mixture():
with pytest.raises(Exception):
surface_tension_mixture(xs=[0.1606, 0.8394], sigmas=[0.01547, 0.02877], Method='Fail')


@pytest.mark.meta_T_dept
def test_SurfaceTension():
# Ethanol, test as many methods as possible at once
EtOH = SurfaceTension(Tb=351.39, Tc=514.0, Pc=6137000.0, Vc=0.000168, Zc=0.24125, omega=0.635, StielPolar=-0.01266, CASRN='64-17-5')
EtOH.T_dependent_property(305.)
sigma_calcs = [(EtOH.set_user_methods(i), EtOH.T_dependent_property(305.))[1] for i in EtOH.sorted_valid_methods]
sigma_exp = [0.021222422444285592, 0.02171156653650729, 0.02171156653650729, 0.021532564572262793, 0.02140008, 0.038055725907414066, 0.03739257387107131, 0.02645171690486362, 0.03905907338532845, 0.03670733205970745]

assert_allclose(sigma_calcs, sigma_exp)

# Test that methods return None
sigma_calcs = [(EtOH.set_user_methods(i, forced=True), EtOH.T_dependent_property(5000))[1] for i in EtOH.sorted_valid_methods]
assert [None]*10 == sigma_calcs

EtOH.set_user_methods('VDI_TABULAR', forced=True)
EtOH.tabular_extrapolation_permitted = False
assert None == EtOH.T_dependent_property(700.)

with pytest.raises(Exception):
EtOH.test_method_validity(300, 'BADMETHOD')
9 changes: 7 additions & 2 deletions tests/test_vapor_pressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ def test_Ambrose_Walton():
Psat = Ambrose_Walton(347.25, 617.15, 36.09E5, 0.304)
assert_allclose(Psat, 13278.878504306222)


def test_Edalat():
# No check data, but gives the same results as the other CSP relationships
Psat = Edalat(347.2, 617.1, 36E5, 0.299)
assert_allclose(Psat, 13461.273080743307)

def test_Sanjari():
P = Sanjari(347.2, 617.1, 36E5, 0.299)
Expand Down Expand Up @@ -155,7 +160,7 @@ def test_VaporPressure():
EtOH = VaporPressure(Tb=351.39, Tc=514.0, Pc=6137000.0, omega=0.635, CASRN='64-17-5')
EtOH.T_dependent_property(305.)
Psat_calcs = [(EtOH.set_user_methods(i), EtOH.T_dependent_property(305.))[1] for i in EtOH.sorted_valid_methods]
Psat_exp = [11579.634014300127, 11590.408779316374, 11592.205263631122, 11593.661615921257, 11690.81660829924, 11612.378633936816, 11350.156640503357, 14088.453409816764, 9210.26200064024]
Psat_exp = [11579.634014300127, 11590.408779316374, 11592.205263402893, 11593.661615921257, 11690.81660829924, 11612.378633936816, 11350.156640503357, 12081.738947110121, 14088.453409816764, 9210.26200064024]
assert_allclose(Psat_calcs, Psat_exp)

# Use another chemical to get in ANTOINE_EXTENDED_POLING
Expand All @@ -169,7 +174,7 @@ def test_VaporPressure():
EtOH = VaporPressure(Tb=351.39, Tc=514.0, Pc=6137000.0, omega=0.635, CASRN='64-17-5')
EtOH.T_dependent_property(298.15)
Psat_calcs = [(EtOH.set_user_methods(i, forced=True), EtOH.T_dependent_property(5000))[1] for i in EtOH.sorted_valid_methods]
assert [None]*8 == Psat_calcs
assert [None]*9 == Psat_calcs

# Test interpolation, extrapolation
w = VaporPressure(Tb=373.124, Tc=647.14, Pc=22048320.0, omega=0.344, CASRN='7732-18-5')
Expand Down
14 changes: 11 additions & 3 deletions thermo/chemical.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,8 @@ def set_TP_sources(self):
Cvgm_calc = lambda T : self.HeatCapacityGas.T_dependent_property(T) - R
self.ThermalConductivityGas = ThermalConductivityGas(CASRN=self.CAS, MW=self.MW, Tb=self.Tb, Pc=self.Pc, Vc=self.Vc, Zc=self.Zc, omega=self.omega, dipole=self.dipole, Vmg=Vmg_atm_T_dependent, Cvgm=Cvgm_calc, mug=self.ViscosityGas.T_dependent_property)

self.SurfaceTension = SurfaceTension(CASRN=self.CAS, Tb=self.Tb, Tc=self.Tc, Pc=self.Pc, Vc=self.Vc, Zc=self.Zc, omega=self.omega, StielPolar=self.StielPolar)
Cpl_calc = lambda T : property_molar_to_mass(self.HeatCapacityLiquid.T_dependent_property(T), self.MW)
self.SurfaceTension = SurfaceTension(CASRN=self.CAS, MW=self.MW, Tb=self.Tb, Tc=self.Tc, Pc=self.Pc, Vc=self.Vc, Zc=self.Zc, omega=self.omega, StielPolar=self.StielPolar, Hvap_Tb=self.Hvap_Tb, Vml=self.VolumeLiquid.T_dependent_property, Cpl=Cpl_calc)

self.Permittivity = Permittivity(CASRN=self.CAS)

Expand Down Expand Up @@ -2554,7 +2555,11 @@ def set_TP_sources(self):
# Constant properties obtained from TP
self.Vml_STPs = [i.Vml_STP for i in self.Chemicals]
self.Vmg_STPs = [i.Vmg_STP for i in self.Chemicals]
self.Vml_STP = volume_liquid_mixture(xs=self.zs, ws=self.ws, Vms=self.Vml_STPs, T=298.15, MWs=self.MWs, MW=self.MW, Tcs=self.Tcs, Pcs=self.Pcs, Vcs=self.Vcs, Zcs=self.Zcs, omegas=self.omegas, Tc=self.Tc, Pc=self.Pc, Vc=self.Vc, Zc=self.Zc, omega=self.omega, CASRNs=self.CASs, Molar=True, Method=self.Vl_method)
try:
self.Vml_STP = volume_liquid_mixture(xs=self.zs, ws=self.ws, Vms=self.Vml_STPs, T=298.15, MWs=self.MWs, MW=self.MW, Tcs=self.Tcs, Pcs=self.Pcs, Vcs=self.Vcs, Zcs=self.Zcs, omegas=self.omegas, Tc=self.Tc, Pc=self.Pc, Vc=self.Vc, Zc=self.Zc, omega=self.omega, CASRNs=self.CASs, Molar=True, Method=self.Vl_method)
except:
self.Vml_STP = None

self.Vmg_STP = volume_gas_mixture(ys=self.zs, Vms=self.Vmg_STPs, T=298.15, P=101325, Tc=self.Tc, Pc=self.Pc, omega=self.omega, MW=self.MW, CASRNs=self.CASs, Method=self.Vg_method)

self.rhol_STP = Vm_to_rho(self.Vml_STP, self.MW) if self.Vml_STP else None
Expand All @@ -2572,7 +2577,10 @@ def set_TP(self, T=None, P=None):
self.P = P
self.set_chemical_TP()

self.Vml = volume_liquid_mixture(xs=self.zs, ws=self.ws, Vms=self.Vmls, T=self.T, MWs=self.MWs, MW=self.MW, Tcs=self.Tcs, Pcs=self.Pcs, Vcs=self.Vcs, Zcs=self.Zcs, omegas=self.omegas, Tc=self.Tc, Pc=self.Pc, Vc=self.Vc, Zc=self.Zc, omega=self.omega, CASRNs=self.CASs, Molar=True, Method=self.Vl_method)
try:
self.Vml = volume_liquid_mixture(xs=self.zs, ws=self.ws, Vms=self.Vmls, T=self.T, MWs=self.MWs, MW=self.MW, Tcs=self.Tcs, Pcs=self.Pcs, Vcs=self.Vcs, Zcs=self.Zcs, omegas=self.omegas, Tc=self.Tc, Pc=self.Pc, Vc=self.Vc, Zc=self.Zc, omega=self.omega, CASRNs=self.CASs, Molar=True, Method=self.Vl_method)
except:
self.Vml = None
self.rhol = Vm_to_rho(self.Vml, self.MW) if self.Vml else None
self.Zl = Z(self.T, self.P, self.Vml) if self.Vml else None
self.rholm = 1./self.Vml if self.Vml else None
Expand Down
Loading

0 comments on commit 2893c75

Please sign in to comment.