Skip to content

Commit

Permalink
Clean up some constant names
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebBell committed Nov 7, 2024
1 parent 28e1bf6 commit d5712e5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
22 changes: 11 additions & 11 deletions tests/test_vapor_pressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,44 +785,44 @@ def test_VaporPressure_extrapolate_derivatives():

@pytest.mark.meta_T_dept
def test_VaporPressure_weird_signatures():
from thermo.utils import PROPERTY_TRANSFORM_D2_X, PROPERTY_TRANSFORM_D2LN, PROPERTY_TRANSFORM_D_X, PROPERTY_TRANSFORM_DLN, PROPERTY_TRANSFORM_LN
from thermo.utils import TRANSFORM_SECOND_DERIVATIVE_RATIO, TRANSFORM_SECOND_LOG_DERIVATIVE, TRANSFORM_DERIVATIVE_RATIO, TRANSFORM_LOG_DERIVATIVE, TRANSFORM_LOG

obj = VaporPressure(extrapolation='DIPPR101_ABC|AntoineAB', exp_poly_fit=(273.17, 647.086, [-2.8478502840358144e-21, 1.7295186670575222e-17, -4.034229148562168e-14, 5.0588958391215855e-11, -3.861625996277003e-08, 1.886271475957639e-05, -0.005928371869421494, 1.1494956887882308, -96.74302379151317]))

# Within range
assert_close(obj.T_dependent_property_transform(300, PROPERTY_TRANSFORM_LN),
assert_close(obj.T_dependent_property_transform(300, TRANSFORM_LOG),
log(obj.T_dependent_property(300)))

assert_close(obj.T_dependent_property_transform(300, PROPERTY_TRANSFORM_D_X),
assert_close(obj.T_dependent_property_transform(300, TRANSFORM_DERIVATIVE_RATIO),
obj.T_dependent_property_derivative(300)/obj.T_dependent_property(300))

assert_close(obj.T_dependent_property_transform(300, PROPERTY_TRANSFORM_D2_X),
assert_close(obj.T_dependent_property_transform(300, TRANSFORM_SECOND_DERIVATIVE_RATIO),
obj.T_dependent_property_derivative(300, 2)/obj.T_dependent_property(300))

dln = derivative(lambda T: log(obj(T)), 300, dx=300*1e-6)
assert_close(dln, obj.T_dependent_property_transform(300, PROPERTY_TRANSFORM_DLN))
assert_close(dln, obj.T_dependent_property_transform(300, TRANSFORM_LOG_DERIVATIVE))

dln = derivative(lambda T: log(obj(T)), 300, n=2, dx=300*1e-5)
assert_close(dln, obj.T_dependent_property_transform(300, PROPERTY_TRANSFORM_D2LN), rtol=1e-5)
assert_close(dln, obj.T_dependent_property_transform(300, TRANSFORM_SECOND_LOG_DERIVATIVE), rtol=1e-5)

# Extrapolations
for extrapolation in ('Arrhenius', 'DIPPR101_ABC', 'AntoineAB'):
obj.extrapolation = extrapolation
for T in (100, 1000):
assert_close(obj.T_dependent_property_transform(T, PROPERTY_TRANSFORM_LN),
assert_close(obj.T_dependent_property_transform(T, TRANSFORM_LOG),
log(obj.T_dependent_property(T)))

assert_close(obj.T_dependent_property_transform(T, PROPERTY_TRANSFORM_D_X),
assert_close(obj.T_dependent_property_transform(T, TRANSFORM_DERIVATIVE_RATIO),
obj.T_dependent_property_derivative(T)/obj.T_dependent_property(T))

assert_close(obj.T_dependent_property_transform(T, PROPERTY_TRANSFORM_D2_X),
assert_close(obj.T_dependent_property_transform(T, TRANSFORM_SECOND_DERIVATIVE_RATIO),
obj.T_dependent_property_derivative(T, 2)/obj.T_dependent_property(T))

dln = derivative(lambda T: log(obj(T)), T, dx=T*1e-6)
assert_close(dln, obj.T_dependent_property_transform(T, PROPERTY_TRANSFORM_DLN))
assert_close(dln, obj.T_dependent_property_transform(T, TRANSFORM_LOG_DERIVATIVE))

dln = derivative(lambda T: log(obj(T)), T, n=2, dx=T*1e-5)
assert_close(dln, obj.T_dependent_property_transform(T, PROPERTY_TRANSFORM_D2LN), rtol=4e-4)
assert_close(dln, obj.T_dependent_property_transform(T, TRANSFORM_SECOND_LOG_DERIVATIVE), rtol=4e-4)

@pytest.mark.meta_T_dept
def test_VaporPressure_WebBook():
Expand Down
12 changes: 6 additions & 6 deletions thermo/phases/gibbs_excess.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from thermo.nrtl import nrtl_taus as ln_henries
from thermo.phase_change import EnthalpySublimation, EnthalpyVaporization
from thermo.phases.phase import Phase
from thermo.utils import POLY_FIT, PROPERTY_TRANSFORM_D2_X, PROPERTY_TRANSFORM_D2LN, PROPERTY_TRANSFORM_D_X, PROPERTY_TRANSFORM_DLN, PROPERTY_TRANSFORM_LN
from thermo.utils import POLY_FIT, TRANSFORM_SECOND_DERIVATIVE_RATIO, TRANSFORM_SECOND_LOG_DERIVATIVE, TRANSFORM_DERIVATIVE_RATIO, TRANSFORM_LOG_DERIVATIVE, TRANSFORM_LOG
from thermo.vapor_pressure import SublimationPressure, VaporPressure
from thermo.volume import VolumeLiquid, VolumeSolid

Expand Down Expand Up @@ -1083,7 +1083,7 @@ def lnPsats(self):
self._lnPsats = lnPsats
return lnPsats

self._lnPsats = lnPsats = [VaporPressure.T_dependent_property_transform(T, PROPERTY_TRANSFORM_LN)
self._lnPsats = lnPsats = [VaporPressure.T_dependent_property_transform(T, TRANSFORM_LOG)
for VaporPressure in self.VaporPressures]
if self.has_henry_components:
Hs, henry_components = self.Henry_constants(), self.henry_components
Expand Down Expand Up @@ -1114,7 +1114,7 @@ def dlnPsats_dT(self):
dPsat_dT = dPsat_dT*T + c
dlnPsats_dT.append(dPsat_dT)
return dlnPsats_dT
dlnPsats_dT = [VaporPressure.T_dependent_property_transform(T, PROPERTY_TRANSFORM_DLN) for VaporPressure in self.VaporPressures]
dlnPsats_dT = [VaporPressure.T_dependent_property_transform(T, TRANSFORM_LOG_DERIVATIVE) for VaporPressure in self.VaporPressures]
if self.has_henry_components:
Hs, dHs, henry_components = self.Henry_constants(), self.dHenry_constants_dT(), self.henry_components
for i in range(N):
Expand Down Expand Up @@ -1146,7 +1146,7 @@ def d2lnPsats_dT2(self):
d2lnPsat_dT2 = d2lnPsat_dT2*T + c
d2lnPsats_dT2.append(d2lnPsat_dT2)
return d2lnPsats_dT2
d2lnPsats_dT2 = [VaporPressure.T_dependent_property_transform(T, PROPERTY_TRANSFORM_D2LN) for VaporPressure in self.VaporPressures]
d2lnPsats_dT2 = [VaporPressure.T_dependent_property_transform(T, TRANSFORM_SECOND_LOG_DERIVATIVE) for VaporPressure in self.VaporPressures]
if self.has_henry_components:
Hs, dHs, d2Hs, henry_components = self.Henry_constants(), self.dHenry_constants_dT(), self.d2Henry_constants_dT2(), self.henry_components
for i in range(N):
Expand Down Expand Up @@ -1182,7 +1182,7 @@ def dPsats_dT_over_Psats(self):
return dPsat_dT_over_Psats

# dPsat_dT_over_Psats = [i/j for i, j in zip(self.dPsats_dT(), self.Psats())]
dPsat_dT_over_Psats = [VaporPressure.T_dependent_property_transform(T, PROPERTY_TRANSFORM_D_X) for VaporPressure in self.VaporPressures]
dPsat_dT_over_Psats = [VaporPressure.T_dependent_property_transform(T, TRANSFORM_DERIVATIVE_RATIO) for VaporPressure in self.VaporPressures]

if self.has_henry_components:
Hs, dHenry_constants_dT, henry_components = self.Henry_constants(), self.dHenry_constants_dT(), self.henry_components
Expand Down Expand Up @@ -1230,7 +1230,7 @@ def d2Psats_dT2_over_Psats(self):
return d2Psat_dT2_over_Psats

# d2Psat_dT2_over_Psats = [i/j for i, j in zip(self.d2Psats_dT2(), self.Psats())]
d2Psat_dT2_over_Psats = [VaporPressure.T_dependent_property_transform(T, PROPERTY_TRANSFORM_D2_X) for VaporPressure in self.VaporPressures]
d2Psat_dT2_over_Psats = [VaporPressure.T_dependent_property_transform(T, TRANSFORM_SECOND_DERIVATIVE_RATIO) for VaporPressure in self.VaporPressures]
if self.has_henry_components:
Hs, d2Henry_constants_dT2, henry_components = self.Henry_constants(), self.d2Henry_constants_dT2(), self.henry_components
for i in range(N):
Expand Down
44 changes: 22 additions & 22 deletions thermo/utils/t_dependent_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
'''


__all__ = ['TDependentProperty', 'PROPERTY_TRANSFORM_LN', 'PROPERTY_TRANSFORM_DLN',
'PROPERTY_TRANSFORM_D2LN', 'PROPERTY_TRANSFORM_D_X', 'PROPERTY_TRANSFORM_D2_X']
__all__ = ['TDependentProperty', 'TRANSFORM_LOG', 'TRANSFORM_LOG_DERIVATIVE',
'TRANSFORM_SECOND_LOG_DERIVATIVE', 'TRANSFORM_DERIVATIVE_RATIO', 'TRANSFORM_SECOND_DERIVATIVE_RATIO']

import os

Expand Down Expand Up @@ -489,12 +489,12 @@ def f_int(self, Ta, Tb):
def f_int_over_T(self, Ta, Tb):
return self.value * log(Tb/Ta)

# Intended for internal use only; should be interned
PROPERTY_TRANSFORM_LN = 'lnx'
PROPERTY_TRANSFORM_DLN = 'dlnxoverdT'
PROPERTY_TRANSFORM_D2LN = 'd2lnxdT2'
PROPERTY_TRANSFORM_D_X = 'dxdToverx'
PROPERTY_TRANSFORM_D2_X = 'd2xdT2overx'
# Intended for internal use only
TRANSFORM_LOG = 'log_transform'
TRANSFORM_LOG_DERIVATIVE = 'logarithmic_derivative'
TRANSFORM_SECOND_LOG_DERIVATIVE = 'second_logarithmic_derivative'
TRANSFORM_DERIVATIVE_RATIO = 'derivative_over_value'
TRANSFORM_SECOND_DERIVATIVE_RATIO = 'second_derivative_over_value'

skipped_parameter_combinations = {'REFPROP_sigma': {('sigma1',), ('sigma1', 'n1', 'sigma2')}}

Expand Down Expand Up @@ -2864,21 +2864,21 @@ def T_dependent_property(self, T):


def calculate_transform(self, T, method, transform):
if transform == PROPERTY_TRANSFORM_LN:
if transform == TRANSFORM_LOG:
if method == EXP_POLY_FIT:
return horner(self.exp_poly_fit_coeffs, T)
return log(self.calculate(T, method))
elif transform == PROPERTY_TRANSFORM_D2LN:
elif transform == TRANSFORM_SECOND_LOG_DERIVATIVE:
if method == EXP_POLY_FIT:
return horner_and_der2(self.exp_poly_fit_coeffs, T)[2]
return derivative(lambda T: log(self.calculate(T, method)), T, n=2, dx=T*1e-6)
elif transform == PROPERTY_TRANSFORM_D_X or transform == PROPERTY_TRANSFORM_DLN:
elif transform == TRANSFORM_DERIVATIVE_RATIO or transform == TRANSFORM_LOG_DERIVATIVE:
if method == EXP_POLY_FIT:
return horner_and_der(self.exp_poly_fit_coeffs, T)[1]
v = self.calculate(T, method)
der = self.calculate_derivative(T, method)
return der/v
elif transform == PROPERTY_TRANSFORM_D2_X:
elif transform == TRANSFORM_SECOND_DERIVATIVE_RATIO:
v = self.calculate(T, method)
der = self.calculate_derivative(T, method, order=2)
return der/v
Expand Down Expand Up @@ -2921,36 +2921,36 @@ def extrapolate_transform(self, T, method, transform, in_range='error'):
else:
extrapolation_coeffs[key] = coeffs = self._get_extrapolation_coeffs(*key)

if transform == PROPERTY_TRANSFORM_LN:
if transform == TRANSFORM_LOG:
if extrapolation == 'AntoineAB':
A, B = coeffs
return A - B/T
elif extrapolation == 'DIPPR101_ABC':
A, B, C = coeffs
return A + B/T + C*trunc_log(T)
elif transform == PROPERTY_TRANSFORM_DLN:
elif transform == TRANSFORM_LOG_DERIVATIVE:
if extrapolation == 'DIPPR101_ABC':
A, B, C = coeffs
return (-B/T + C)/T
if extrapolation == 'AntoineAB':
A, B = coeffs
return B/(T*T)
elif transform == PROPERTY_TRANSFORM_D2LN:
elif transform == TRANSFORM_SECOND_LOG_DERIVATIVE:
if extrapolation == 'DIPPR101_ABC':
A, B, C = coeffs
T_inv = 1.0/T
return (2.0*B*T_inv - C)*T_inv*T_inv
if extrapolation == 'AntoineAB':
A, B = coeffs
return -2.0*B/(T*T*T)
elif transform == PROPERTY_TRANSFORM_D_X:
elif transform == TRANSFORM_DERIVATIVE_RATIO:
if extrapolation == 'DIPPR101_ABC':
A, B, C = coeffs
return (-B + C*T)/(T*T)
if extrapolation == 'AntoineAB':
A, B = coeffs
return B/(T*T)
elif transform ==PROPERTY_TRANSFORM_D2_X:
elif transform ==TRANSFORM_SECOND_DERIVATIVE_RATIO:
if extrapolation == 'DIPPR101_ABC':
A, B, C = coeffs
T2 = T*T
Expand All @@ -2963,17 +2963,17 @@ def extrapolate_transform(self, T, method, transform, in_range='error'):



if transform == PROPERTY_TRANSFORM_LN:
if transform == TRANSFORM_LOG:
return log(self.extrapolate(T, method))
elif transform == PROPERTY_TRANSFORM_DLN:
elif transform == TRANSFORM_LOG_DERIVATIVE:
return derivative(lambda T: log(self.extrapolate(T, method)), T, dx=T*1e-6)
elif transform == PROPERTY_TRANSFORM_D2LN:
elif transform == TRANSFORM_SECOND_LOG_DERIVATIVE:
return derivative(lambda T: log(self.extrapolate(T, method)), T, n=2, dx=T*1e-6)
elif transform == PROPERTY_TRANSFORM_D_X:
elif transform == TRANSFORM_DERIVATIVE_RATIO:
v = self.extrapolate(T, method)
der = self.extrapolate_derivative(T, method, order=1)
return der/v
elif transform == PROPERTY_TRANSFORM_D2_X:
elif transform == TRANSFORM_SECOND_DERIVATIVE_RATIO:
v = self.extrapolate(T, method)
der = self.extrapolate_derivative(T, method, order=2)
return der/v
Expand Down

0 comments on commit d5712e5

Please sign in to comment.