thermo.utils module

thermo.utils.isobaric_expansion(V, dV_dT)[source]

Calculate the isobaric coefficient of a thermal expansion, given its molar volume at a certain T and P, and its derivative of molar volume with respect to T.

\[\beta = \frac{1}{V}\left(\frac{\partial V}{\partial T} \right)_P\]
Parameters:

V : float

Molar volume at T and P, [m^3/mol]

dV_dT : float

Derivative of molar volume with respect to T, [m^3/mol/K]

Returns:

beta : float

Isobaric coefficient of a thermal expansion, [1/K]

Notes

For an ideal gas, this expression simplified to:

\[\beta = \frac{1}{T}\]

References

[R568]Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000.

Examples

Calculated for hexane from the PR EOS at 299 K and 1 MPa (liquid):

>>> isobaric_expansion(0.000130229900873546, 1.58875261849113e-7)
0.0012199599384121608
thermo.utils.isothermal_compressibility(V, dV_dP)[source]

Calculate the isothermal coefficient of a compressibility, given its molar volume at a certain T and P, and its derivative of molar volume with respect to P.

\[\kappa = -\frac{1}{V}\left(\frac{\partial V}{\partial P} \right)_T\]
Parameters:

V : float

Molar volume at T and P, [m^3/mol]

dV_dP : float

Derivative of molar volume with respect to P, [m^3/mol/Pa]

Returns:

kappa : float

Isothermal coefficient of a compressibility, [1/Pa]

Notes

For an ideal gas, this expression simplified to:

\[\kappa = \frac{1}{P}\]

References

[R569]Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000.

Examples

Calculated for hexane from the PR EOS at 299 K and 1 MPa (liquid):

>>> isothermal_compressibility(0.000130229900873546, -2.72902118209903e-13)
2.095541165119158e-09
thermo.utils.Cp_minus_Cv(T, dP_dT, dP_dV)[source]

Calculate the difference between a real gas’s constant-pressure heat capacity and constant-volume heat capacity, as given in [R570], [R571], and [R572]. The required derivatives should be calculated with an equation of state.

\[C_p - C_v = -T\left(\frac{\partial P}{\partial T}\right)_V^2/ \left(\frac{\partial P}{\partial V}\right)_T\]
Parameters:

T : float

Temperature of fluid [K]

dP_dT : float

Derivative of P with respect to T, [Pa/K]

dP_dV : float

Derivative of P with respect to V, [Pa*mol/m^3]

Returns:

Cp_minus_Cv : float

Cp - Cv for a real gas, [J/mol/K]

Notes

Equivalent expressions are:

\[ \begin{align}\begin{aligned}C_p - C_v= -T\left(\frac{\partial V}{\partial T}\right)_P^2/\left( \frac{\partial V}{\partial P}\right)_T\\C_p - C_v = T\left(\frac{\partial P}{\partial T}\right) \left(\frac{\partial V}{\partial T}\right)\end{aligned}\end{align} \]

Note that these are not second derivatives, only first derivatives, some of which are squared.

References

[R570](1, 2) Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000.
[R571](1, 2) Walas, Stanley M. Phase Equilibria in Chemical Engineering. Butterworth-Heinemann, 1985.
[R572](1, 2) Gmehling, Jurgen, Barbel Kolbe, Michael Kleiber, and Jurgen Rarey. Chemical Thermodynamics for Process Simulation. 1st edition. Weinheim: Wiley-VCH, 2012.

Examples

Calculated for hexane from the PR EOS at 299 K and 1 MPa (liquid):

>>> Cp_minus_Cv(299, 582232.475794113, -3665180614672.253)
27.654681381642394
thermo.utils.speed_of_sound(V, dP_dV, Cp, Cv, MW=None)[source]

Calculate a real fluid’s speed of sound. The required derivatives should be calculated with an equation of state, and Cp and Cv are both the real fluid versions. Expression is given in [R573] and [R574]; a unit conversion is further performed to obtain a result in m/s. If MW is not provided the result is returned in units of m*kg^0.5/s/mol^0.5.

\[w = \left[-V^2 \left(\frac{\partial P}{\partial V}\right)_T \frac{C_p} {C_v}\right]^{1/2}\]
Parameters:

V : float

Molar volume of fluid, [m^3/mol]

dP_dV : float

Derivative of P with respect to V, [Pa*mol/m^3]

Cp : float

Real fluid heat capacity at constant pressure, [J/mol/K]

Cv : float

Real fluid heat capacity at constant volume, [J/mol/K]

MW : float, optional

Molecular weight, [g/mol]

Returns:

w : float

Speed of sound for a real gas, [m/s or m*kg^0.5/s/mol^0.5 or MW missing]

Notes

An alternate expression based on molar density is as follows:

\[w = \left[\left(\frac{\partial P}{\partial \rho}\right)_T \frac{C_p} {C_v}\right]^{1/2}\]

The form with the unit conversion performed inside it is as follows:

\[w = \left[-V^2 \frac{1000}{MW}\left(\frac{\partial P}{\partial V} \right)_T \frac{C_p}{C_v}\right]^{1/2}\]

References

[R573](1, 2) Gmehling, Jurgen, Barbel Kolbe, Michael Kleiber, and Jurgen Rarey. Chemical Thermodynamics for Process Simulation. 1st edition. Weinheim: Wiley-VCH, 2012.
[R574](1, 2, 3) Pratt, R. M. “Thermodynamic Properties Involving Derivatives: Using the Peng-Robinson Equation of State.” Chemical Engineering Education 35, no. 2 (March 1, 2001): 112-115.

Examples

Example from [R574]:

>>> speed_of_sound(V=0.00229754, dP_dV=-3.5459e+08, Cp=153.235, Cv=132.435, MW=67.152)
179.5868138460819
thermo.utils.Joule_Thomson(T, V, Cp, dV_dT=None, beta=None)[source]

Calculate a real fluid’s Joule Thomson coefficient. The required derivative should be calculated with an equation of state, and Cp is the real fluid versions. This can either be calculated with dV_dT directly, or with beta if it is already known.

\[\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)\]
Parameters:

T : float

Temperature of fluid, [K]

V : float

Molar volume of fluid, [m^3/mol]

Cp : float

Real fluid heat capacity at constant pressure, [J/mol/K]

dV_dT : float, optional

Derivative of V with respect to T, [m^3/mol/K]

beta : float, optional

Isobaric coefficient of a thermal expansion, [1/K]

Returns:

mu_JT : float

Joule-Thomson coefficient [K/Pa]

References

[R575]Walas, Stanley M. Phase Equilibria in Chemical Engineering. Butterworth-Heinemann, 1985.
[R576](1, 2) Pratt, R. M. “Thermodynamic Properties Involving Derivatives: Using the Peng-Robinson Equation of State.” Chemical Engineering Education 35, no. 2 (March 1, 2001): 112-115.

Examples

Example from [R576]:

>>> Joule_Thomson(T=390, V=0.00229754, Cp=153.235, dV_dT=1.226396e-05)
1.621956080529905e-05
thermo.utils.phase_identification_parameter(V, dP_dT, dP_dV, d2P_dV2, d2P_dVdT)[source]

Calculate the Phase Identification Parameter developed in [R577] for the accurate and efficient determination of whether a fluid is a liquid or a gas based on the results of an equation of state. For supercritical conditions, this provides a good method for choosing which property correlations to use.

\[\Pi = V \left[\frac{\frac{\partial^2 P}{\partial V \partial T}} {\frac{\partial P }{\partial T}}- \frac{\frac{\partial^2 P}{\partial V^2}}{\frac{\partial P}{\partial V}} \right]\]
Parameters:

V : float

Molar volume at T and P, [m^3/mol]

dP_dT : float

Derivative of P with respect to T, [Pa/K]

dP_dV : float

Derivative of P with respect to V, [Pa*mol/m^3]

d2P_dV2 : float

Second derivative of P with respect to V, [Pa*mol^2/m^6]

d2P_dVdT : float

Second derivative of P with respect to both V and T, [Pa*mol/m^3/K]

Returns:

PIP : float

Phase Identification Parameter, [-]

Notes

Heuristics were used by process simulators before the invent of this parameter.

The criteria for liquid is Pi > 1; for vapor, Pi <= 1.

There is also a solid phase mechanism available. For solids, the Solid Phase Identification Parameter is greater than 1, like liquids; however, unlike liquids, d2P_dVdT is always >0; it is < 0 for liquids and gases.

References

[R577](1, 2) Venkatarathnam, G., and L. R. Oellrich. “Identification of the Phase of a Fluid Using Partial Derivatives of Pressure, Volume, and Temperature without Reference to Saturation Properties: Applications in Phase Equilibria Calculations.” Fluid Phase Equilibria 301, no. 2 (February 25, 2011): 225-33. doi:10.1016/j.fluid.2010.12.001.
[R578]Jayanti, Pranava Chaitanya, and G. Venkatarathnam. “Identification of the Phase of a Substance from the Derivatives of Pressure, Volume and Temperature, without Prior Knowledge of Saturation Properties: Extension to Solid Phase.” Fluid Phase Equilibria 425 (October 15, 2016): 269-277. doi:10.1016/j.fluid.2016.06.001.

Examples

Calculated for hexane from the PR EOS at 299 K and 1 MPa (liquid):

>>> phase_identification_parameter(0.000130229900874, 582169.397484, 
... -3.66431747236e+12, 4.48067893805e+17, -20518995218.2)
11.33428990564796
thermo.utils.phase_identification_parameter_phase(d2P_dVdT, V=None, dP_dT=None, dP_dV=None, d2P_dV2=None)[source]

Uses the Phase Identification Parameter concept developed in [R579] and [R580] to determine if a chemical is a solid, liquid, or vapor given the appropriate thermodynamic conditions.

The criteria for liquid is PIP > 1; for vapor, PIP <= 1.

For solids, PIP(solid) is defined to be d2P_dVdT. If it is larger than 0, the species is a solid. It is less than 0 for all liquids and gases.

Parameters:

d2P_dVdT : float

Second derivative of P with respect to both V and T, [Pa*mol/m^3/K]

V : float, optional

Molar volume at T and P, [m^3/mol]

dP_dT : float, optional

Derivative of P with respect to T, [Pa/K]

dP_dV : float, optional

Derivative of P with respect to V, [Pa*mol/m^3]

d2P_dV2 : float, optionsl

Second derivative of P with respect to V, [Pa*mol^2/m^6]

Returns:

phase : str

Either ‘s’, ‘l’ or ‘g’

Notes

The criteria for being a solid phase is checked first, which only requires d2P_dVdT. All other inputs are optional for this reason. However, an exception will be raised if the other inputs become needed to determine if a species is a liquid or a gas.

References

[R579](1, 2) Venkatarathnam, G., and L. R. Oellrich. “Identification of the Phase of a Fluid Using Partial Derivatives of Pressure, Volume, and Temperature without Reference to Saturation Properties: Applications in Phase Equilibria Calculations.” Fluid Phase Equilibria 301, no. 2 (February 25, 2011): 225-33. doi:10.1016/j.fluid.2010.12.001.
[R580](1, 2) Jayanti, Pranava Chaitanya, and G. Venkatarathnam. “Identification of the Phase of a Substance from the Derivatives of Pressure, Volume and Temperature, without Prior Knowledge of Saturation Properties: Extension to Solid Phase.” Fluid Phase Equilibria 425 (October 15, 2016): 269-277. doi:10.1016/j.fluid.2016.06.001.

Examples

Calculated for hexane from the PR EOS at 299 K and 1 MPa (liquid):

>>> phase_identification_parameter_phase(-20518995218.2, 0.000130229900874, 
... 582169.397484, -3.66431747236e+12, 4.48067893805e+17)
'l'
thermo.utils.isentropic_exponent(Cp, Cv)[source]

Calculate the isentropic coefficient of a gas, given its constant- pressure and constant-volume heat capacity.

\[k = \frac{C_p}{C_v}\]
Parameters:

Cp : float

Gas heat capacity at constant pressure, [J/mol/K]

Cv : float

Gas heat capacity at constant volume, [J/mol/K]

Returns:

k : float

Isentropic exponent, [-]

References

[R581]Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000.

Examples

>>> isentropic_exponent(33.6, 25.27)
1.329639889196676
thermo.utils.Vm_to_rho(Vm, MW)[source]

Calculate the density of a chemical, given its molar volume and molecular weight.

\[\rho = \frac{MW}{1000\cdot VM}\]
Parameters:

Vm : float

Molar volume, [m^3/mol]

MW : float

Molecular weight, [g/mol]

Returns:

rho : float

Density, [kg/m^3]

References

[R582]Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000.

Examples

>>> Vm_to_rho(0.000132, 86.18)
652.8787878787879
thermo.utils.rho_to_Vm(rho, MW)[source]

Calculate the molar volume of a chemical, given its density and molecular weight.

\[V_m = \left(\frac{1000 \rho}{MW}\right)^{-1}\]
Parameters:

rho : float

Density, [kg/m^3]

MW : float

Molecular weight, [g/mol]

Returns:

Vm : float

Molar volume, [m^3/mol]

References

[R583]Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000.

Examples

>>> rho_to_Vm(652.9, 86.18)
0.00013199571144126206
thermo.utils.Z(T, P, V)[source]

Calculates the compressibility factor of a gas, given its temperature, pressure, and molar volume.

\[Z = \frac{PV}{RT}\]
Parameters:

T : float

Temperature, [K]

P : float

Pressure [Pa]

V : float

Molar volume, [m^3/mol]

Returns:

Z : float

Compressibility factor, [-]

References

[R584]Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000.

Examples

>>> Z(600, P=1E6, V=0.00463)
0.9281019876560912
thermo.utils.B_To_Z(B, T, P)[source]

Calculates the compressibility factor of a gas, given its second virial coefficient.

\[Z = 1 + \frac{BP}{RT}\]
Parameters:

B : float

Second virial coefficient, [m^3/mol]

T : float

Temperature, [K]

P : float

Pressure [Pa]

Returns:

Z : float

Compressibility factor, [-]

Notes

Other forms of the virial coefficient exist.

References

[R585]Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000.

Examples

>>> B_To_Z(-0.0015, 300, 1E5)
0.9398638020957176
thermo.utils.B_from_Z(Z, T, P)[source]

Calculates the second virial coefficient of a pure species, given the compressibility factor of the gas.

\[B = \frac{RT(Z-1)}{P}\]
Parameters:

Z : float

Compressibility factor, [-]

T : float

Temperature, [K]

P : float

Pressure [Pa]

Returns:

B : float

Second virial coefficient, [m^3/mol]

Notes

Other forms of the virial coefficient exist.

References

[R586]Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000.

Examples

>>> B_from_Z(0.94, 300, 1E5)
-0.0014966027640000014
thermo.utils.Z_from_virial_density_form(T, P, *args)[source]

Calculates the compressibility factor of a gas given its temperature, pressure, and molar density-form virial coefficients. Any number of coefficients is supported.

\[Z = \frac{PV}{RT} = 1 + \frac{B}{V} + \frac{C}{V^2} + \frac{D}{V^3} + \frac{E}{V^4} \dots\]
Parameters:

T : float

Temperature, [K]

P : float

Pressure, [Pa]

B to Z : float, optional

Virial coefficients, [various]

Returns:

Z : float

Compressibility factor at T, P, and with given virial coefficients, [-]

Notes

For use with B or with B and C or with B and C and D, optimized equations are used to obtain the compressibility factor directly. If more coefficients are provided, uses numpy’s roots function to solve this equation. This takes substantially longer as the solution is numerical.

If no virial coefficients are given, returns 1, as per the ideal gas law.

The units of each virial coefficient are as follows, where for B, n=1, and C, n=2, and so on.

\[\left(\frac{\text{m}^3}{\text{mol}}\right)^n\]

References

[R587]Prausnitz, John M., Rudiger N. Lichtenthaler, and Edmundo Gomes de Azevedo. Molecular Thermodynamics of Fluid-Phase Equilibria. 3rd edition. Upper Saddle River, N.J: Prentice Hall, 1998.
[R588]Walas, Stanley M. Phase Equilibria in Chemical Engineering. Butterworth-Heinemann, 1985.

Examples

>>> Z_from_virial_density_form(300, 122057.233762653, 1E-4, 1E-5, 1E-6, 1E-7)
1.2843496002100001
thermo.utils.Z_from_virial_pressure_form(P, *args)[source]

Calculates the compressibility factor of a gas given its pressure, and pressure-form virial coefficients. Any number of coefficients is supported.

\[Z = \frac{Pv}{RT} = 1 + B'P + C'P^2 + D'P^3 + E'P^4 \dots\]
Parameters:

P : float

Pressure, [Pa]

B to Z : float, optional

Pressure form Virial coefficients, [various]

Returns:

Z : float

Compressibility factor at P, and with given virial coefficients, [-]

Notes

Note that although this function does not require a temperature input, it is still dependent on it because the coefficients themselves normally are regressed in terms of temperature.

The use of this form is less common than the density form. Its coefficients are normally indicated with the “’” suffix.

If no virial coefficients are given, returns 1, as per the ideal gas law.

The units of each virial coefficient are as follows, where for B, n=1, and C, n=2, and so on.

\[\left(\frac{1}{\text{Pa}}\right)^n\]

References

[R589]Prausnitz, John M., Rudiger N. Lichtenthaler, and Edmundo Gomes de Azevedo. Molecular Thermodynamics of Fluid-Phase Equilibria. 3rd edition. Upper Saddle River, N.J: Prentice Hall, 1998.
[R590]Walas, Stanley M. Phase Equilibria in Chemical Engineering. Butterworth-Heinemann, 1985.

Examples

>>> Z_from_virial_pressure_form(102919.99946855308, 4.032286555169439e-09, 1.6197059494442215e-13, 6.483855042486911e-19)
1.00283753944
thermo.utils.zs_to_ws(zs, MWs)[source]

Converts a list of mole fractions to mass fractions. Requires molecular weights for all species.

\[ \begin{align}\begin{aligned}w_i = \frac{z_i MW_i}{MW_{avg}}\\MW_{avg} = \sum_i z_i MW_i\end{aligned}\end{align} \]
Parameters:

zs : iterable

Mole fractions [-]

MWs : iterable

Molecular weights [g/mol]

Returns:

ws : iterable

Mass fractions [-]

Notes

Does not check that the sums add to one. Does not check that inputs are of the same length.

Examples

>>> zs_to_ws([0.5, 0.5], [10, 20])
[0.3333333333333333, 0.6666666666666666]
thermo.utils.ws_to_zs(ws, MWs)[source]

Converts a list of mass fractions to mole fractions. Requires molecular weights for all species.

\[z_i = \frac{\frac{w_i}{MW_i}}{\sum_i \frac{w_i}{MW_i}}\]
Parameters:

ws : iterable

Mass fractions [-]

MWs : iterable

Molecular weights [g/mol]

Returns:

zs : iterable

Mole fractions [-]

Notes

Does not check that the sums add to one. Does not check that inputs are of the same length.

Examples

>>> ws_to_zs([0.3333333333333333, 0.6666666666666666], [10, 20])
[0.5, 0.5]
thermo.utils.zs_to_Vfs(zs, Vms)[source]

Converts a list of mole fractions to volume fractions. Requires molar volumes for all species.

\[\text{Vf}_i = \frac{z_i V_{m,i}}{\sum_i z_i V_{m,i}}\]
Parameters:

zs : iterable

Mole fractions [-]

VMs : iterable

Molar volumes of species [m^3/mol]

Returns:

Vfs : list

Molar volume fractions [-]

Notes

Does not check that the sums add to one. Does not check that inputs are of the same length.

Molar volumes are specified in terms of pure components only. Function works with any phase.

Examples

Acetone and benzene example

>>> zs_to_Vfs([0.637, 0.363], [8.0234e-05, 9.543e-05])
[0.5960229712956298, 0.4039770287043703]
thermo.utils.Vfs_to_zs(Vfs, Vms)[source]

Converts a list of mass fractions to mole fractions. Requires molecular weights for all species.

\[z_i = \frac{\frac{\text{Vf}_i}{V_{m,i}}}{\sum_i \frac{\text{Vf}_i}{V_{m,i}}}\]
Parameters:

Vfs : iterable

Molar volume fractions [-]

VMs : iterable

Molar volumes of species [m^3/mol]

Returns:

zs : list

Mole fractions [-]

Notes

Does not check that the sums add to one. Does not check that inputs are of the same length.

Molar volumes are specified in terms of pure components only. Function works with any phase.

Examples

Acetone and benzene example

>>> Vfs_to_zs([0.596, 0.404], [8.0234e-05, 9.543e-05])
[0.6369779395901142, 0.3630220604098858]
thermo.utils.none_and_length_check(all_inputs, length=None)[source]

Checks inputs for suitability of use by a mixing rule which requires all inputs to be of the same length and non-None. A number of variations were attempted for this function; this was found to be the quickest.

Parameters:

all_inputs : array-like of array-like

list of all the lists of inputs, [-]

length : int, optional

Length of the desired inputs, [-]

Returns:

False/True : bool

Returns True only if all inputs are the same length (or length length) and none of the inputs contain None [-]

Notes

Does not check for nan values.

Examples

>>> none_and_length_check(([1, 1], [1, 1], [1, 30], [10,0]), length=2)
True
thermo.utils.normalize(values)[source]

Simple function which normalizes a series of values to be from 0 to 1, and for their sum to add to 1.

\[x = \frac{x}{sum_i x_i}\]
Parameters:

values : array-like

array of values

Returns:

fractions : array-like

Array of values from 0 to 1

Notes

Does not work on negative values.

Examples

>>> normalize([3, 2, 1])
[0.5, 0.3333333333333333, 0.16666666666666666]
thermo.utils.mixing_simple(fracs, props)[source]

Simple function calculates a property based on weighted averages of properties. Weights could be mole fractions, volume fractions, mass fractions, or anything else.

\[y = \sum_i \text{frac}_i \cdot \text{prop}_i\]
Parameters:

fracs : array-like

Fractions of a mixture

props: array-like

Properties

Returns:

prop : value

Calculated property

Notes

Returns None if any fractions or properties are missing or are not of the same length.

Examples

>>> mixing_simple([0.1, 0.9], [0.01, 0.02])
0.019000000000000003
thermo.utils.mixing_logarithmic(fracs, props)[source]

Simple function calculates a property based on weighted averages of logarithmic properties.

\[y = \sum_i \text{frac}_i \cdot \log(\text{prop}_i)\]
Parameters:

fracs : array-like

Fractions of a mixture

props: array-like

Properties

Returns:

prop : value

Calculated property

Notes

Does not work on negative values. Returns None if any fractions or properties are missing or are not of the same length.

Examples

>>> mixing_logarithmic([0.1, 0.9], [0.01, 0.02])
0.01866065983073615
thermo.utils.to_num(values)[source]

Legacy function to turn a list of strings into either floats (if numeric), stripped strings (if not) or None if the string is empty. Accepts any numeric formatting the float function does.

Parameters:

values : list

list of strings

Returns:

values : list

list of floats, strings, and None values [-]

Examples

>>> to_num(['1', '1.1', '1E5', '0xB4', ''])
[1.0, 1.1, 100000.0, '0xB4', None]
thermo.utils.CAS2int(i)[source]

Converts CAS number of a compounds from a string to an int. This is helpful when storing large amounts of CAS numbers, as their strings take up more memory than their numerical representational. All CAS numbers fit into 64 bit ints.

Parameters:

CASRN : string

CASRN [-]

Returns:

CASRN : int

CASRN [-]

Notes

Accomplishes conversion by removing dashes only, and then converting to an int. An incorrect CAS number will change without exception.

Examples

>>> CAS2int('7704-34-9')
7704349
thermo.utils.int2CAS(i)[source]

Converts CAS number of a compounds from an int to an string. This is helpful when dealing with int CAS numbers.

Parameters:

CASRN : int

CASRN [-]

Returns:

CASRN : string

CASRN [-]

Notes

Handles CAS numbers with an unspecified number of digits. Does not work on floats.

Examples

>>> int2CAS(7704349)
'7704-34-9'
thermo.utils.Parachor(MW, rhol, rhog, sigma)[source]

Calculate Parachor for a pure species, using its density in the liquid and gas phases, surface tension, and molecular weight.

\[P = \frac{\sigma^{0.25} MW}{\rho_L - \rho_V}\]
Parameters:

MW : float

Molecular weight, [g/mol]

rhol : float

Liquid density [kg/m^3]

rhog : float

Gas density [kg/m^3]

sigma : float

Surface tension, [N/m]

Returns:

P : float

Parachor, [N^0.25*m^2.75/mol]

Notes

To convert the output of this function to units of [mN^0.25*m^2.75/kmol], multiply by 5623.4132519.

Values in group contribution tables for Parachor are often listed as dimensionless, in which they are multiplied by 5623413 and the appropriate units to make them dimensionless.

References

[R591]Poling, Bruce E. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000.
[R592]Green, Don, and Robert Perry. Perry’s Chemical Engineers’ Handbook, 8E. McGraw-Hill Professional, 2007.
[R593](1, 2) Danner, Ronald P, and Design Institute for Physical Property Data. Manual for Predicting Chemical Process Design Data. New York, N.Y, 1982.

Examples

Calculating Parachor from a known surface tension for methyl isobutyl ketone at 293.15 K

>>> Parachor(100.15888, 800.8088185536124, 4.97865317223119, 0.02672166960656005)
5.088443542210164e-05

Converting to the dimensionless form:

>>> 5623413*5.088443542210164e-05
286.14419565030687

Compared to 274.9 according to a group contribution method described in [R593].

thermo.utils.property_molar_to_mass(A_molar, MW)[source]
thermo.utils.property_mass_to_molar(A_mass, MW)[source]
thermo.utils.phase_select_property(phase=None, s=None, l=None, g=None, V_over_F=None)[source]

Determines which phase’s property should be set as a default, given the phase a chemical is, and the property values of various phases. For the case of liquid-gas phase, returns None. If the property is not available for the current phase, or if the current phase is not known, returns None.

Parameters:

phase : str

One of {‘s’, ‘l’, ‘g’, ‘two-phase’}

s : float

Solid-phase property

l : float

Liquid-phase property

g : float

Gas-phase property

V_over_F : float

Vapor phase fraction

Returns:

prop : float

The selected/calculated property for the relevant phase

Notes

Could calculate mole-fraction weighted properties for the two phase regime. Could also implement equilibria with solid phases.

Examples

>>> phase_select_property(phase='g', l=1560.14, g=3312.)
3312.0
class thermo.utils.TDependentProperty(CASRN='')[source]

Bases: object

Class for calculating temperature-dependent chemical properties. Should load all data about a given chemical on creation. As data is often stored in pandas DataFrames, this means that creation is slow. However, the calculation of a property at a given temperature is very fast. As coefficients are stored in every instance, a user could alter them from those loaded by default.

Designed to intelligently select which method to use at a given temperature, according to (1) selections made by the user specifying a list of ordered method preferences and (2) by using a default list of prefered methods.

All methods should have defined criteria for determining if they are valid before calculation, i.e. a minimum and maximum temperature for coefficients to be valid. For constant property values used due to lack of temperature-dependent data, a short range is normally specified as valid. It is not assumed that any given method will succeed; for example many expressions are not mathematically valid past the critical point. If the method raises an exception, the next method is tried until either one method works or all the supposedly valid have been exhausted. Furthermore, all properties returned by the method are checked by a sanity function test_property_validity, which has sanity checks for all properties.

Works nicely with tabular data, which is interpolated from if specified. Interpolation is cubic-spline based if 5 or more points are given, and linearly interpolated with if few points are given. Extrapolation is permitted if tabular_extrapolation_permitted is set to True. For both interpolation and extrapolation, a transform may be applied so that a property such as vapor pressure can be interpolated non-linearly. These are functions or lambda expressions which must be set for the variables interpolation_T, interpolation_property, and interpolation_property_inv.

Attributes

name (str) The name of the property being calculated
units (str) The units of the property
method (str) The method was which was last used successfully to calculate a property; set only after the first property calculation.
forced (bool) If True, only user specified methods will be considered; otherwise all methods will be considered if none of the user specified methods succeed
interpolation_T (function) A function or lambda expression to transform the temperatures of tabular data for interpolation; e.g. ‘lambda self, T: 1./T’
interpolation_property (function) A function or lambda expression to transform tabular property values prior to interpolation; e.g. ‘lambda self, P: log(P)’
interpolation_property_inv (function) A function or property expression to transform interpolated property values from the transform performed by interpolation_property back to their actual form, e.g. ‘lambda self, P: exp(P)’
tabular_extrapolation_permitted (bool) Whether or not to allow extrapolation from tabulated data for a property
Tmin (float) Maximum temperature at which no method can calculate the property above; set based on rough rules for some methods. Used to solve for a particular property value, and as a default minimum for plotting. Often higher than where the property is theoretically higher, i.e. liquid density above the triple point, but this information may still be needed for liquid mixtures with elevated critical points.
Tmax (float) Minimum temperature at which no method can calculate the property under; set based on rough rules for some methods. Used to solve for a particular property value, and as a default minimum for plotting. Often lower than where the property is theoretically higher, i.e. liquid density beneath the triple point, but this information may still be needed for subcooled liquids or mixtures with depressed freezing points.
property_min (float) Lowest value expected for a property while still being valid; this is a criteria used by test_method_validity.
property_max (float) Highest value expected for a property while still being valid; this is a criteria used by test_method_validity.
ranked_methods (list) Constant list of ranked methods by default
tabular_data (dict) Stores all user-supplied property data for interpolation in format {name: (Ts, properties)}
tabular_data_interpolators (dict) Stores all interpolation objects, idexed by name and property transform methods with the format {(name, interpolation_T, interpolation_property, interpolation_property_inv): (extrapolator, spline)}
sorted_valid_methods (list) Sorted and valid methods stored from the last T_dependent_property call
user_methods (list) Sorted methods as specified by the user

Methods

T_dependent_property(T) Method to calculate the property with sanity checking and without specifying a specific method.
T_dependent_property_derivative(T[, order]) Method to obtain a derivative of a property with respect to temperature, of a given order.
T_dependent_property_integral(T1, T2) Method to calculate the integral of a property with respect to temperature, using a specified method.
T_dependent_property_integral_over_T(T1, T2) Method to calculate the integral of a property over temperature with respect to temperature, using a specified method.
__call__(T) Convenience method to calculate the property; calls T_dependent_property.
calculate(T, method) Method to calculate a property with a specified method, with no validity checking or error handling.
calculate_derivative(T, method[, order]) Method to calculate a derivative of a property with respect to temperature, of a given order using a specified method.
calculate_integral(T1, T2, method) Method to calculate the integral of a property with respect to temperature, using a specified method.
calculate_integral_over_T(T1, T2, method) Method to calculate the integral of a property over temperature with respect to temperature, using a specified method.
extrapolate_tabular(T)
interpolate(T, name) Method to perform interpolation on a given tabular data set previously added via set_tabular_data.
load_all_methods() Method to load all data, and set all_methods based on the available data and properties.
plot_T_dependent_property([Tmin, Tmax, ...]) Method to create a plot of the property vs temperature according to either a specified list of methods, or user methods (if set), or all methods.
select_valid_methods(T) Method to obtain a sorted list of methods which are valid at T according to test_method_validity.
set_tabular_data(Ts, properties[, name, ...]) Method to set tabular data to be used for interpolation.
set_user_methods(user_methods[, forced]) Method used to select certain property methods as having a higher priority than were set by default.
solve_prop(goal[, reset_method]) Method to solve for the temperature at which a property is at a specified value.
test_method_validity(T, method) Method to test the validity of a specified method for a given temperature.
test_property_validity(prop) Method to test the validity of a calculated property.
T_cached = None
T_dependent_property(T)[source]

Method to calculate the property with sanity checking and without specifying a specific method. select_valid_methods is used to obtain a sorted list of methods to try. Methods are then tried in order until one succeeds. The methods are allowed to fail, and their results are checked with test_property_validity. On success, the used method is stored in the variable method.

If method is set, this method is first checked for validity with test_method_validity for the specified temperature, and if it is valid, it is then used to calculate the property. The result is checked for validity, and returned if it is valid. If either of the checks fail, the function retrieves a full list of valid methods with select_valid_methods and attempts them as described above.

If no methods are found which succeed, returns None.

Parameters:

T : float

Temperature at which to calculate the property, [K]

Returns:

prop : float

Calculated property, [units]

T_dependent_property_derivative(T, order=1)[source]

Method to obtain a derivative of a property with respect to temperature, of a given order. Methods found valid by select_valid_methods are attempted until a method succeeds. If no methods are valid and succeed, None is returned.

Calls calculate_derivative internally to perform the actual calculation.

\[\text{derivative} = \frac{d (\text{property})}{d T}\]
Parameters:

T : float

Temperature at which to calculate the derivative, [K]

order : int

Order of the derivative, >= 1

Returns:

derivative : float

Calculated derivative property, [units/K^order]

T_dependent_property_integral(T1, T2)[source]

Method to calculate the integral of a property with respect to temperature, using a specified method. Methods found valid by select_valid_methods are attempted until a method succeeds. If no methods are valid and succeed, None is returned.

Calls calculate_integral internally to perform the actual calculation.

\[\text{integral} = \int_{T_1}^{T_2} \text{property} \; dT\]
Parameters:

T1 : float

Lower limit of integration, [K]

T2 : float

Upper limit of integration, [K]

method : str

Method for which to find the integral

Returns:

integral : float

Calculated integral of the property over the given range, [units*K]

T_dependent_property_integral_over_T(T1, T2)[source]

Method to calculate the integral of a property over temperature with respect to temperature, using a specified method. Methods found valid by select_valid_methods are attempted until a method succeeds. If no methods are valid and succeed, None is returned.

Calls calculate_integral_over_T internally to perform the actual calculation.

\[\text{integral} = \int_{T_1}^{T_2} \frac{\text{property}}{T} \; dT\]
Parameters:

T1 : float

Lower limit of integration, [K]

T2 : float

Upper limit of integration, [K]

method : str

Method for which to find the integral

Returns:

integral : float

Calculated integral of the property over the given range, [units]

calculate(T, method)[source]

Method to calculate a property with a specified method, with no validity checking or error handling. Demo function for testing only; must be implemented according to the methods available for each individual method. Include the interpolation call here.

Parameters:

T : float

Temperature at which to calculate the property, [K]

method : str

Method name to use

Returns:

prop : float

Calculated property, [units]

calculate_derivative(T, method, order=1)[source]

Method to calculate a derivative of a property with respect to temperature, of a given order using a specified method. Uses SciPy’s derivative function, with a delta of 1E-6 K and a number of points equal to 2*order + 1.

This method can be overwritten by subclasses who may perfer to add analytical methods for some or all methods as this is much faster.

If the calculation does not succeed, returns the actual error encountered.

Parameters:

T : float

Temperature at which to calculate the derivative, [K]

method : str

Method for which to find the derivative

order : int

Order of the derivative, >= 1

Returns:

derivative : float

Calculated derivative property, [units/K^order]

calculate_integral(T1, T2, method)[source]

Method to calculate the integral of a property with respect to temperature, using a specified method. Uses SciPy’s quad function to perform the integral, with no options.

This method can be overwritten by subclasses who may perfer to add analytical methods for some or all methods as this is much faster.

If the calculation does not succeed, returns the actual error encountered.

Parameters:

T1 : float

Lower limit of integration, [K]

T2 : float

Upper limit of integration, [K]

method : str

Method for which to find the integral

Returns:

integral : float

Calculated integral of the property over the given range, [units*K]

calculate_integral_over_T(T1, T2, method)[source]

Method to calculate the integral of a property over temperature with respect to temperature, using a specified method. Uses SciPy’s quad function to perform the integral, with no options.

This method can be overwritten by subclasses who may perfer to add analytical methods for some or all methods as this is much faster.

If the calculation does not succeed, returns the actual error encountered.

Parameters:

T1 : float

Lower limit of integration, [K]

T2 : float

Upper limit of integration, [K]

method : str

Method for which to find the integral

Returns:

integral : float

Calculated integral of the property over the given range, [units]

extrapolate_tabular(T)[source]
forced = False
interpolate(T, name)[source]

Method to perform interpolation on a given tabular data set previously added via set_tabular_data. This method will create the interpolators the first time it is used on a property set, and store them for quick future use.

Interpolation is cubic-spline based if 5 or more points are available, and linearly interpolated if not. Extrapolation is always performed linearly. This function uses the transforms interpolation_T, interpolation_property, and interpolation_property_inv if set. If any of these are changed after the interpolators were first created, new interpolators are created with the new transforms. All interpolation is performed via the interp1d function.

Parameters:

T : float

Temperature at which to interpolate the property, [K]

name : str

The name assigned to the tabular data set

Returns:

prop : float

Calculated property, [units]

interpolation_T = None
interpolation_property = None
interpolation_property_inv = None
load_all_methods()[source]

Method to load all data, and set all_methods based on the available data and properties. Demo function for testing only; must be implemented according to the methods available for each individual method.

method = None
name = 'Property name'
plot_T_dependent_property(Tmin=None, Tmax=None, methods=[], pts=50, only_valid=True, order=0)[source]

Method to create a plot of the property vs temperature according to either a specified list of methods, or user methods (if set), or all methods. User-selectable number of points, and temperature range. If only_valid is set,`test_method_validity` will be used to check if each temperature in the specified range is valid, and test_property_validity will be used to test the answer, and the method is allowed to fail; only the valid points will be plotted. Otherwise, the result will be calculated and displayed as-is. This will not suceed if the method fails.

Parameters:

Tmin : float

Minimum temperature, to begin calculating the property, [K]

Tmax : float

Maximum temperature, to stop calculating the property, [K]

methods : list, optional

List of methods to consider

pts : int, optional

A list of points to calculate the property at; if Tmin to Tmax covers a wide range of method validities, only a few points may end up calculated for a given method so this may need to be large

only_valid : bool

If True, only plot successful methods and calculated properties, and handle errors; if False, attempt calculation without any checking and use methods outside their bounds

property_max = 10000.0
property_min = 0
ranked_methods = []
select_valid_methods(T)[source]

Method to obtain a sorted list of methods which are valid at T according to test_method_validity. Considers either only user methods if forced is True, or all methods. User methods are first tested according to their listed order, and unless forced is True, then all methods are tested and sorted by their order in ranked_methods.

Parameters:

T : float

Temperature at which to test methods, [K]

Returns:

sorted_valid_methods : list

Sorted lists of methods valid at T according to test_method_validity

set_tabular_data(Ts, properties, name=None, check_properties=True)[source]

Method to set tabular data to be used for interpolation. Ts must be in increasing order. If no name is given, data will be assigned the name ‘Tabular data series #x’, where x is the number of previously added tabular data series. The name is added to all methods and iserted at the start of user methods,

Parameters:

Ts : array-like

Increasing array of temperatures at which properties are specified, [K]

properties : array-like

List of properties at Ts, [units]

name : str, optional

Name assigned to the data

check_properties : bool

If True, the properties will be checked for validity with test_property_validity and raise an exception if any are not valid

set_user_methods(user_methods, forced=False)[source]

Method used to select certain property methods as having a higher priority than were set by default. If forced is true, then methods which were not specified are excluded from consideration.

As a side effect, method is removed to ensure than the new methods will be used in calculations afterwards.

An exception is raised if any of the methods specified aren’t available for the chemical. An exception is raised if no methods are provided.

Parameters:

user_methods : str or list

Methods by name to be considered or prefered

forced : bool, optional

If True, only the user specified methods will ever be considered; if False other methods will be considered if no user methods suceed

solve_prop(goal, reset_method=True)[source]

Method to solve for the temperature at which a property is at a specified value. T_dependent_property is used to calculate the value of the property as a function of temperature; if reset_method is True, the best method is used at each temperature as the solver seeks a solution. This slows the solution moderately.

Checks the given property value with test_property_validity first and raises an exception if it is not valid. Requires that Tmin and Tmax have been set to know what range to search within.

Search is performed with the brenth solver from SciPy.

Parameters:

goal : float

Propoerty value desired, [units]

reset_method : bool

Whether or not to reset the method as the solver searches

Returns:

T : float

Temperature at which the property is the specified value [K]

tabular_extrapolation_permitted = True
test_method_validity(T, method)[source]

Method to test the validity of a specified method for a given temperature. Demo function for testing only; must be implemented according to the methods available for each individual method. Include the interpolation check here.

Parameters:

T : float

Temperature at which to determine the validity of the method, [K]

method : str

Method name to use

Returns:

validity : bool

Whether or not a specifid method is valid

classmethod test_property_validity(prop)[source]

Method to test the validity of a calculated property. Normally, this method is used by a given property class, and has maximum and minimum limits controlled by the variables property_min and property_max.

Parameters:

prop : float

property to be tested, [units]

Returns:

validity : bool

Whether or not a specifid method is valid

units = 'Property units'
class thermo.utils.TPDependentProperty(CASRN='')[source]

Bases: thermo.utils.TDependentProperty

Class for calculating temperature and pressure dependent chemical properties.

Attributes

TP_cached  
T_cached  
interpolation_P  
interpolation_T  
interpolation_property  
interpolation_property_inv  
method  
method_P  

Methods

TP_dependent_property(T, P) Method to calculate the property with sanity checking and without specifying a specific method.
TP_dependent_property_derivative_P(T, P[, order]) Method to calculate a derivative of a temperature and pressure dependent property with respect to pressure at constant temperature, of a given order.
TP_dependent_property_derivative_T(T, P[, order]) Method to calculate a derivative of a temperature and pressure dependent property with respect to temperature at constant pressure, of a given order.
TP_or_T_dependent_property(T, P)
T_dependent_property(T) Method to calculate the property with sanity checking and without specifying a specific method.
T_dependent_property_derivative(T[, order]) Method to obtain a derivative of a property with respect to temperature, of a given order.
T_dependent_property_integral(T1, T2) Method to calculate the integral of a property with respect to temperature, using a specified method.
T_dependent_property_integral_over_T(T1, T2) Method to calculate the integral of a property over temperature with respect to temperature, using a specified method.
__call__(T, P) Convenience method to calculate the property; calls TP_dependent_property.
calculate(T, method) Method to calculate a property with a specified method, with no validity checking or error handling.
calculate_derivative(T, method[, order]) Method to calculate a derivative of a property with respect to temperature, of a given order using a specified method.
calculate_derivative_P(P, T, method[, order]) Method to calculate a derivative of a temperature and pressure dependent property with respect to pressure at constant temperature, of a given order using a specified method.
calculate_derivative_T(T, P, method[, order]) Method to calculate a derivative of a temperature and pressure dependent property with respect to temperature at constant pressure, of a given order using a specified method.
calculate_integral(T1, T2, method) Method to calculate the integral of a property with respect to temperature, using a specified method.
calculate_integral_over_T(T1, T2, method) Method to calculate the integral of a property over temperature with respect to temperature, using a specified method.
extrapolate_tabular(T)
interpolate(T, name) Method to perform interpolation on a given tabular data set previously added via set_tabular_data.
interpolate_P(T, P, name) Method to perform interpolation on a given tabular data set previously added via set_tabular_data_P.
load_all_methods() Method to load all data, and set all_methods based on the available data and properties.
plot_TP_dependent_property([Tmin, Tmax, ...]) Method to create a plot of the property vs temperature and pressure according to either a specified list of methods, or user methods (if set), or all methods.
plot_T_dependent_property([Tmin, Tmax, ...]) Method to create a plot of the property vs temperature according to either a specified list of methods, or user methods (if set), or all methods.
plot_isobar(P[, Tmin, Tmax, methods_P, pts, ...]) Method to create a plot of the property vs temperature at a specific pressure according to either a specified list of methods, or user methods (if set), or all methods.
plot_isotherm(T[, Pmin, Pmax, methods_P, ...]) Method to create a plot of the property vs pressure at a specified temperature according to either a specified list of methods, or the user methods (if set), or all methods.
select_valid_methods(T) Method to obtain a sorted list of methods which are valid at T according to test_method_validity.
select_valid_methods_P(T, P) Method to obtain a sorted list methods which are valid at T according to test_method_validity.
set_tabular_data(Ts, properties[, name, ...]) Method to set tabular data to be used for interpolation.
set_tabular_data_P(Ts, Ps, properties[, ...]) Method to set tabular data to be used for interpolation.
set_user_methods(user_methods[, forced]) Method used to select certain property methods as having a higher priority than were set by default.
set_user_methods_P(user_methods_P[, forced_P]) Method to set the pressure-dependent property methods desired for consideration by the user.
solve_prop(goal[, reset_method]) Method to solve for the temperature at which a property is at a specified value.
test_method_validity(T, method) Method to test the validity of a specified method for a given temperature.
test_property_validity(prop) Method to test the validity of a calculated property.
TP_cached = None
TP_dependent_property(T, P)[source]

Method to calculate the property with sanity checking and without specifying a specific method. select_valid_methods_P is used to obtain a sorted list of methods to try. Methods are then tried in order until one succeeds. The methods are allowed to fail, and their results are checked with test_property_validity. On success, the used method is stored in the variable method_P.

If method_P is set, this method is first checked for validity with test_method_validity_P for the specified temperature, and if it is valid, it is then used to calculate the property. The result is checked for validity, and returned if it is valid. If either of the checks fail, the function retrieves a full list of valid methods with select_valid_methods_P and attempts them as described above.

If no methods are found which succeed, returns None.

Parameters:

T : float

Temperature at which to calculate the property, [K]

P : float

Pressure at which to calculate the property, [Pa]

Returns:

prop : float

Calculated property, [units]

TP_dependent_property_derivative_P(T, P, order=1)[source]

Method to calculate a derivative of a temperature and pressure dependent property with respect to pressure at constant temperature, of a given order. Methods found valid by select_valid_methods_P are attempted until a method succeeds. If no methods are valid and succeed, None is returned.

Calls calculate_derivative_P internally to perform the actual calculation.

\[\text{derivative} = \frac{d (\text{property})}{d P}|_{T}\]
Parameters:

T : float

Temperature at which to calculate the derivative, [K]

P : float

Pressure at which to calculate the derivative, [Pa]

order : int

Order of the derivative, >= 1

Returns:

d_prop_d_P_at_T : float

Calculated derivative property, [units/Pa^order]

TP_dependent_property_derivative_T(T, P, order=1)[source]

Method to calculate a derivative of a temperature and pressure dependent property with respect to temperature at constant pressure, of a given order. Methods found valid by select_valid_methods_P are attempted until a method succeeds. If no methods are valid and succeed, None is returned.

Calls calculate_derivative_T internally to perform the actual calculation.

\[\text{derivative} = \frac{d (\text{property})}{d T}|_{P}\]
Parameters:

T : float

Temperature at which to calculate the derivative, [K]

P : float

Pressure at which to calculate the derivative, [Pa]

order : int

Order of the derivative, >= 1

Returns:

d_prop_d_T_at_P : float

Calculated derivative property, [units/K^order]

TP_or_T_dependent_property(T, P)[source]
calculate_derivative_P(P, T, method, order=1)[source]

Method to calculate a derivative of a temperature and pressure dependent property with respect to pressure at constant temperature, of a given order using a specified method. Uses SciPy’s derivative function, with a delta of 0.01 Pa and a number of points equal to 2*order + 1.

This method can be overwritten by subclasses who may perfer to add analytical methods for some or all methods as this is much faster.

If the calculation does not succeed, returns the actual error encountered.

Parameters:

P : float

Pressure at which to calculate the derivative, [Pa]

T : float

Temperature at which to calculate the derivative, [K]

method : str

Method for which to find the derivative

order : int

Order of the derivative, >= 1

Returns:

d_prop_d_P_at_T : float

Calculated derivative property at constant temperature, [units/Pa^order]

calculate_derivative_T(T, P, method, order=1)[source]

Method to calculate a derivative of a temperature and pressure dependent property with respect to temperature at constant pressure, of a given order using a specified method. Uses SciPy’s derivative function, with a delta of 1E-6 K and a number of points equal to 2*order + 1.

This method can be overwritten by subclasses who may perfer to add analytical methods for some or all methods as this is much faster.

If the calculation does not succeed, returns the actual error encountered.

Parameters:

T : float

Temperature at which to calculate the derivative, [K]

P : float

Pressure at which to calculate the derivative, [Pa]

method : str

Method for which to find the derivative

order : int

Order of the derivative, >= 1

Returns:

d_prop_d_T_at_P : float

Calculated derivative property at constant pressure, [units/K^order]

forced_P = False
interpolate_P(T, P, name)[source]

Method to perform interpolation on a given tabular data set previously added via set_tabular_data_P. This method will create the interpolators the first time it is used on a property set, and store them for quick future use.

Interpolation is cubic-spline based if 5 or more points are available, and linearly interpolated if not. Extrapolation is always performed linearly. This function uses the transforms interpolation_T, interpolation_P, interpolation_property, and interpolation_property_inv if set. If any of these are changed after the interpolators were first created, new interpolators are created with the new transforms. All interpolation is performed via the interp2d function.

Parameters:

T : float

Temperature at which to interpolate the property, [K]

T : float

Pressure at which to interpolate the property, [Pa]

name : str

The name assigned to the tabular data set

Returns:

prop : float

Calculated property, [units]

interpolation_P = None
method_P = None
plot_TP_dependent_property(Tmin=None, Tmax=None, Pmin=None, Pmax=None, methods_P=[], pts=15, only_valid=True)[source]

Method to create a plot of the property vs temperature and pressure according to either a specified list of methods, or user methods (if set), or all methods. User-selectable number of points for each variable. If only_valid is set,`test_method_validity_P` will be used to check if each condition in the specified range is valid, and test_property_validity will be used to test the answer, and the method is allowed to fail; only the valid points will be plotted. Otherwise, the result will be calculated and displayed as-is. This will not suceed if the any method fails for any point.

Parameters:

Tmin : float

Minimum temperature, to begin calculating the property, [K]

Tmax : float

Maximum temperature, to stop calculating the property, [K]

Pmin : float

Minimum pressure, to begin calculating the property, [Pa]

Pmax : float

Maximum pressure, to stop calculating the property, [Pa]

methods_P : list, optional

List of methods to consider

pts : int, optional

A list of points to calculate the property at for both temperature and pressure; pts^2 points will be calculated.

only_valid : bool

If True, only plot successful methods and calculated properties, and handle errors; if False, attempt calculation without any checking and use methods outside their bounds

plot_isobar(P, Tmin=None, Tmax=None, methods_P=[], pts=50, only_valid=True)[source]

Method to create a plot of the property vs temperature at a specific pressure according to either a specified list of methods, or user methods (if set), or all methods. User-selectable number of points, and temperature range. If only_valid is set,`test_method_validity_P` will be used to check if each condition in the specified range is valid, and test_property_validity will be used to test the answer, and the method is allowed to fail; only the valid points will be plotted. Otherwise, the result will be calculated and displayed as-is. This will not suceed if the method fails.

Parameters:

P : float

Pressure for the isobar, [Pa]

Tmin : float

Minimum temperature, to begin calculating the property, [K]

Tmax : float

Maximum temperature, to stop calculating the property, [K]

methods_P : list, optional

List of methods to consider

pts : int, optional

A list of points to calculate the property at; if Tmin to Tmax covers a wide range of method validities, only a few points may end up calculated for a given method so this may need to be large

only_valid : bool

If True, only plot successful methods and calculated properties, and handle errors; if False, attempt calculation without any checking and use methods outside their bounds

plot_isotherm(T, Pmin=None, Pmax=None, methods_P=[], pts=50, only_valid=True)[source]

Method to create a plot of the property vs pressure at a specified temperature according to either a specified list of methods, or the user methods (if set), or all methods. User-selectable number of points, and pressure range. If only_valid is set, test_method_validity_P will be used to check if each condition in the specified range is valid, and test_property_validity will be used to test the answer, and the method is allowed to fail; only the valid points will be plotted. Otherwise, the result will be calculated and displayed as-is. This will not suceed if the method fails.

Parameters:

T : float

Temperature at which to create the plot, [K]

Pmin : float

Minimum pressure, to begin calculating the property, [Pa]

Pmax : float

Maximum pressure, to stop calculating the property, [Pa]

methods_P : list, optional

List of methods to consider

pts : int, optional

A list of points to calculate the property at; if Pmin to Pmax covers a wide range of method validities, only a few points may end up calculated for a given method so this may need to be large

only_valid : bool

If True, only plot successful methods and calculated properties, and handle errors; if False, attempt calculation without any checking and use methods outside their bounds

select_valid_methods_P(T, P)[source]

Method to obtain a sorted list methods which are valid at T according to test_method_validity. Considers either only user methods if forced is True, or all methods. User methods are first tested according to their listed order, and unless forced is True, then all methods are tested and sorted by their order in ranked_methods.

Parameters:

T : float

Temperature at which to test methods, [K]

P : float

Pressure at which to test methods, [Pa]

Returns:

sorted_valid_methods_P : list

Sorted lists of methods valid at T and P according to test_method_validity

set_tabular_data_P(Ts, Ps, properties, name=None, check_properties=True)[source]

Method to set tabular data to be used for interpolation. Ts and Psmust be in increasing order. If no name is given, data will be assigned the name ‘Tabular data series #x’, where x is the number of previously added tabular data series. The name is added to all methods and is inserted at the start of user methods,

Parameters:

Ts : array-like

Increasing array of temperatures at which properties are specified, [K]

Ps : array-like

Increasing array of pressures at which properties are specified, [Pa]

properties : array-like

List of properties at Ts, [units]

name : str, optional

Name assigned to the data

check_properties : bool

If True, the properties will be checked for validity with test_property_validity and raise an exception if any are not valid

set_user_methods_P(user_methods_P, forced_P=False)[source]

Method to set the pressure-dependent property methods desired for consideration by the user. Can be used to exclude certain methods which might have unacceptable accuracy.

As a side effect, the previously selected method is removed when this method is called to ensure user methods are tried in the desired order.

Parameters:

user_methods_P : str or list

Methods by name to be considered or preferred for pressure effect.

forced : bool, optional

If True, only the user specified methods will ever be considered; if False other methods will be considered if no user methods suceed.

class thermo.utils.MixtureProperty[source]

Bases: object

Attributes

TP_zs_ws_cached  
method  
prop_cached  

Methods

__call__(T, P, zs, ws) Convenience method to calculate the property; calls mixture_property.
calculate_derivative_P(P, T, zs, ws, method) Method to calculate a derivative of a mixture property with respect to pressure at constant temperature and composition of a given order using a specified method.
calculate_derivative_T(T, P, zs, ws, method) Method to calculate a derivative of a mixture property with respect to temperature at constant pressure and composition of a given order using a specified method.
mixture_property(T, P, zs, ws) Method to calculate the property with sanity checking and without specifying a specific method.
plot_isobar(P, zs, ws[, Tmin, Tmax, ...]) Method to create a plot of the property vs temperature at a specific pressure and composition according to either a specified list of methods, or user methods (if set), or all methods.
plot_isotherm(T, zs, ws[, Pmin, Pmax, ...]) Method to create a plot of the property vs pressure at a specified temperature and composition according to either a specified list of methods, or the user methods (if set), or all methods.
plot_property(zs, ws[, Tmin, Tmax, Pmin, ...]) Method to create a plot of the property vs temperature and pressure according to either a specified list of methods, or user methods (if set), or all methods.
property_derivative_P(T, P, zs, ws[, order]) Method to calculate a derivative of a mixture property with respect to pressure at constant temperature and composition, of a given order.
property_derivative_T(T, P, zs, ws[, order]) Method to calculate a derivative of a mixture property with respect to temperature at constant pressure and composition, of a given order.
select_valid_methods(T, P, zs, ws) Method to obtain a sorted list of methods which are valid at T, P, zs, ws, and possibly Vfls, according to test_method_validity.
set_user_method(user_methods[, forced]) Method to set the T, P, and composition dependent property methods desired for consideration by the user.
test_property_validity(prop) Method to test the validity of a calculated property.
TP_zs_ws_cached = None
calculate_derivative_P(P, T, zs, ws, method, order=1)[source]

Method to calculate a derivative of a mixture property with respect to pressure at constant temperature and composition of a given order using a specified method. Uses SciPy’s derivative function, with a delta of 0.01 Pa and a number of points equal to 2*order + 1.

This method can be overwritten by subclasses who may perfer to add analytical methods for some or all methods as this is much faster.

If the calculation does not succeed, returns the actual error encountered.

Parameters:

P : float

Pressure at which to calculate the derivative, [Pa]

T : float

Temperature at which to calculate the derivative, [K]

zs : list[float]

Mole fractions of all species in the mixture, [-]

ws : list[float]

Weight fractions of all species in the mixture, [-]

method : str

Method for which to find the derivative

order : int

Order of the derivative, >= 1

Returns:

d_prop_d_P_at_T : float

Calculated derivative property at constant temperature, [units/Pa^order]

calculate_derivative_T(T, P, zs, ws, method, order=1)[source]

Method to calculate a derivative of a mixture property with respect to temperature at constant pressure and composition of a given order using a specified method. Uses SciPy’s derivative function, with a delta of 1E-6 K and a number of points equal to 2*order + 1.

This method can be overwritten by subclasses who may perfer to add analytical methods for some or all methods as this is much faster.

If the calculation does not succeed, returns the actual error encountered.

Parameters:

T : float

Temperature at which to calculate the derivative, [K]

P : float

Pressure at which to calculate the derivative, [Pa]

zs : list[float]

Mole fractions of all species in the mixture, [-]

ws : list[float]

Weight fractions of all species in the mixture, [-]

method : str

Method for which to find the derivative

order : int

Order of the derivative, >= 1

Returns:

d_prop_d_T_at_P : float

Calculated derivative property at constant pressure, [units/K^order]

forced = False
method = None
mixture_property(T, P, zs, ws)[source]

Method to calculate the property with sanity checking and without specifying a specific method. select_valid_methods is used to obtain a sorted list of methods to try. Methods are then tried in order until one succeeds. The methods are allowed to fail, and their results are checked with test_property_validity. On success, the used method is stored in the variable method.

If method is set, this method is first checked for validity with test_method_validity for the specified temperature, and if it is valid, it is then used to calculate the property. The result is checked for validity, and returned if it is valid. If either of the checks fail, the function retrieves a full list of valid methods with select_valid_methods and attempts them as described above.

If no methods are found which succeed, returns None.

Parameters:

T : float

Temperature at which to calculate the property, [K]

P : float

Pressure at which to calculate the property, [Pa]

zs : list[float]

Mole fractions of all species in the mixture, [-]

ws : list[float]

Weight fractions of all species in the mixture, [-]

Returns:

prop : float

Calculated property, [units]

name = 'Test'
plot_isobar(P, zs, ws, Tmin=None, Tmax=None, methods=[], pts=50, only_valid=True)[source]

Method to create a plot of the property vs temperature at a specific pressure and composition according to either a specified list of methods, or user methods (if set), or all methods. User-selectable number of points, and temperature range. If only_valid is set,`test_method_validity` will be used to check if each condition in the specified range is valid, and test_property_validity will be used to test the answer, and the method is allowed to fail; only the valid points will be plotted. Otherwise, the result will be calculated and displayed as-is. This will not suceed if the method fails.

Parameters:

P : float

Pressure for the isobar, [Pa]

zs : list[float]

Mole fractions of all species in the mixture, [-]

ws : list[float]

Weight fractions of all species in the mixture, [-]

Tmin : float

Minimum temperature, to begin calculating the property, [K]

Tmax : float

Maximum temperature, to stop calculating the property, [K]

methods : list, optional

List of methods to consider

pts : int, optional

A list of points to calculate the property at; if Tmin to Tmax covers a wide range of method validities, only a few points may end up calculated for a given method so this may need to be large

only_valid : bool

If True, only plot successful methods and calculated properties, and handle errors; if False, attempt calculation without any checking and use methods outside their bounds

plot_isotherm(T, zs, ws, Pmin=None, Pmax=None, methods=[], pts=50, only_valid=True)[source]

Method to create a plot of the property vs pressure at a specified temperature and composition according to either a specified list of methods, or the user methods (if set), or all methods. User-selectable

number of points, and pressure range. If only_valid is set,

test_method_validity will be used to check if each condition in the specified range is valid, and test_property_validity will be used to test the answer, and the method is allowed to fail; only the valid points will be plotted. Otherwise, the result will be calculated and displayed as-is. This will not suceed if the method fails.

Parameters:

T : float

Temperature at which to create the plot, [K]

zs : list[float]

Mole fractions of all species in the mixture, [-]

ws : list[float]

Weight fractions of all species in the mixture, [-]

Pmin : float

Minimum pressure, to begin calculating the property, [Pa]

Pmax : float

Maximum pressure, to stop calculating the property, [Pa]

methods : list, optional

List of methods to consider

pts : int, optional

A list of points to calculate the property at; if Pmin to Pmax covers a wide range of method validities, only a few points may end up calculated for a given method so this may need to be large

only_valid : bool

If True, only plot successful methods and calculated properties, and handle errors; if False, attempt calculation without any checking and use methods outside their bounds

plot_property(zs, ws, Tmin=None, Tmax=None, Pmin=100000.0, Pmax=1000000.0, methods=[], pts=15, only_valid=True)[source]

Method to create a plot of the property vs temperature and pressure according to either a specified list of methods, or user methods (if set), or all methods. User-selectable number of points for each variable. If only_valid is set,`test_method_validity` will be used to check if each condition in the specified range is valid, and test_property_validity will be used to test the answer, and the method is allowed to fail; only the valid points will be plotted. Otherwise, the result will be calculated and displayed as-is. This will not suceed if the any method fails for any point.

Parameters:

Tmin : float

Minimum temperature, to begin calculating the property, [K]

Tmax : float

Maximum temperature, to stop calculating the property, [K]

Pmin : float

Minimum pressure, to begin calculating the property, [Pa]

Pmax : float

Maximum pressure, to stop calculating the property, [Pa]

methods : list, optional

List of methods to consider

pts : int, optional

A list of points to calculate the property at for both temperature and pressure; pts^2 points will be calculated.

only_valid : bool

If True, only plot successful methods and calculated properties, and handle errors; if False, attempt calculation without any checking and use methods outside their bounds

prop_cached = None
property_derivative_P(T, P, zs, ws, order=1)[source]

Method to calculate a derivative of a mixture property with respect to pressure at constant temperature and composition, of a given order. Methods found valid by select_valid_methods are attempted until a method succeeds. If no methods are valid and succeed, None is returned.

Calls calculate_derivative_P internally to perform the actual calculation.

\[\text{derivative} = \frac{d (\text{property})}{d P}|_{T, z}\]
Parameters:

T : float

Temperature at which to calculate the derivative, [K]

P : float

Pressure at which to calculate the derivative, [Pa]

zs : list[float]

Mole fractions of all species in the mixture, [-]

ws : list[float]

Weight fractions of all species in the mixture, [-]

order : int

Order of the derivative, >= 1

Returns:

d_prop_d_P_at_T : float

Calculated derivative property, [units/Pa^order]

property_derivative_T(T, P, zs, ws, order=1)[source]

Method to calculate a derivative of a mixture property with respect to temperature at constant pressure and composition, of a given order. Methods found valid by select_valid_methods are attempted until a method succeeds. If no methods are valid and succeed, None is returned.

Calls calculate_derivative_T internally to perform the actual calculation.

\[\text{derivative} = \frac{d (\text{property})}{d T}|_{P, z}\]
Parameters:

T : float

Temperature at which to calculate the derivative, [K]

P : float

Pressure at which to calculate the derivative, [Pa]

zs : list[float]

Mole fractions of all species in the mixture, [-]

ws : list[float]

Weight fractions of all species in the mixture, [-]

order : int

Order of the derivative, >= 1

Returns:

d_prop_d_T_at_P : float

Calculated derivative property, [units/K^order]

property_max = 10
property_min = 0
ranked_methods = []
select_valid_methods(T, P, zs, ws)[source]

Method to obtain a sorted list of methods which are valid at T, P, zs, ws, and possibly Vfls, according to test_method_validity. Considers either only user methods if forced is True, or all methods. User methods are first tested according to their listed order, and unless forced is True, then all methods are tested and sorted by their order in ranked_methods.

Parameters:

T : float

Temperature at which to test the methods, [K]

P : float

Pressure at which to test the methods, [Pa]

zs : list[float]

Mole fractions of all species in the mixture, [-]

ws : list[float]

Weight fractions of all species in the mixture, [-]

Returns:

sorted_valid_methods : list

Sorted lists of methods valid at the given conditions according to test_method_validity

set_user_method(user_methods, forced=False)[source]

Method to set the T, P, and composition dependent property methods desired for consideration by the user. Can be used to exclude certain methods which might have unacceptable accuracy.

As a side effect, the previously selected method is removed when this method is called to ensure user methods are tried in the desired order.

Parameters:

user_methods : str or list

Methods by name to be considered for calculation of the mixture property, ordered by preference.

forced : bool, optional

If True, only the user specified methods will ever be considered; if False, other methods will be considered if no user methods suceed.

classmethod test_property_validity(prop)[source]

Method to test the validity of a calculated property. Normally, this method is used by a given property class, and has maximum and minimum limits controlled by the variables property_min and property_max.

Parameters:

prop : float

property to be tested, [units]

Returns:

validity : bool

Whether or not a specifid method is valid

units = 'test units'
thermo.utils.allclose_variable(a, b, limits, rtols=None, atols=None)[source]

Returns True if two arrays are element-wise equal within several different tolerances. Tolerance values are always positive, usually very small. Based on numpy’s allclose function.

Only atols or rtols needs to be specified; both are used if given.

Parameters:

a, b : array_like

Input arrays to compare.

limits : array_like

Fractions of elements allowed to not match to within each tolerance.

rtols : array_like

The relative tolerance parameters.

atols : float

The absolute tolerance parameters.

Returns:

allclose : bool

Returns True if the two arrays are equal within the given tolerances; False otherwise.

Examples

10 random similar variables, all of them matching to within 1E-5, allowing up to half to match up to 1E-6.

>>> 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]
>>> allclose_variable(x, y, limits=[.0, .5], rtols=[1E-5, 1E-6])
True
thermo.utils.horner(coeffs, x)[source]

Simple function to calculate the value of a polynomial at a specific value of x, using the Horner evaluation scheme

Parameters:

coeffs : array-like

Coefficients, where coeffs[0] is multiplied by the largest power of x, and coeffs[-1] is added to the sum with no multiplication.

x : float

Value to evaluate the polynomial at

Returns:

y : float

Evaluated result

Notes

Efficient. Faster than numpy.polyval.

Examples

>>> horner([1,2,3], 3)
18
thermo.utils.polylog2(x)[source]

Simple function to calculate PolyLog(2, x) from ranges 0 <= x <= 1, with relative error guaranteed to be < 1E-7 from 0 to 0.99999. This is a Pade approximation, with three coefficient sets with splits at 0.7 and 0.99. An exception is raised if x is under 0 or above 1.

Parameters:

x : float

Value to evaluate PolyLog(2, x) T

Returns:

y : float

Evaluated result

Notes

Efficient (2-4 microseconds). No implementation of this function exists in SciPy. Derived with mpmath’s pade approximation. Required for the entropy integral of thermo.heat_capacity.Zabransky_quasi_polynomial.

Examples

>>> polylog2(0.5)
0.5822405264516294
thermo.utils.acos(x)

Return the arc cosine (measured in radians) of x.

thermo.utils.acosh(x)

Return the inverse hyperbolic cosine of x.

thermo.utils.asin(x)

Return the arc sine (measured in radians) of x.

thermo.utils.asinh(x)

Return the inverse hyperbolic sine of x.

thermo.utils.atan(x)

Return the arc tangent (measured in radians) of x.

thermo.utils.atan2(y, x)

Return the arc tangent (measured in radians) of y/x. Unlike atan(y/x), the signs of both x and y are considered.

thermo.utils.atanh(x)

Return the inverse hyperbolic tangent of x.

thermo.utils.ceil(x)

Return the ceiling of x as an Integral. This is the smallest integer >= x.

thermo.utils.copysign(x, y)

Return a float with the magnitude (absolute value) of x but the sign of y. On platforms that support signed zeros, copysign(1.0, -0.0) returns -1.0.

thermo.utils.cos(x)

Return the cosine of x (measured in radians).

thermo.utils.cosh(x)

Return the hyperbolic cosine of x.

thermo.utils.degrees(x)

Convert angle x from radians to degrees.

thermo.utils.exp(x)

Return e raised to the power of x.

thermo.utils.fabs(x)

Return the absolute value of the float x.

thermo.utils.factorial(x) → Integral

Find x!. Raise a ValueError if x is negative or non-integral.

thermo.utils.floor(x)

Return the floor of x as an Integral. This is the largest integer <= x.

thermo.utils.fmod(x, y)

Return fmod(x, y), according to platform C. x % y may differ.

thermo.utils.frexp(x)

Return the mantissa and exponent of x, as pair (m, e). m is a float and e is an int, such that x = m * 2.**e. If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0.

thermo.utils.fsum(iterable)

Return an accurate floating point sum of values in the iterable. Assumes IEEE-754 floating point arithmetic.

thermo.utils.hypot(x, y)

Return the Euclidean distance, sqrt(x*x + y*y).

thermo.utils.isinf(x) → bool

Return True if x is a positive or negative infinity, and False otherwise.

thermo.utils.isnan(x) → bool

Return True if x is a NaN (not a number), and False otherwise.

thermo.utils.ldexp(x, i)

Return x * (2**i).

thermo.utils.log(x[, base])

Return the logarithm of x to the given base. If the base not specified, returns the natural logarithm (base e) of x.

thermo.utils.log10(x)

Return the base 10 logarithm of x.

thermo.utils.log1p(x)

Return the natural logarithm of 1+x (base e). The result is computed in a way which is accurate for x near zero.

thermo.utils.modf(x)

Return the fractional and integer parts of x. Both results carry the sign of x and are floats.

thermo.utils.pow(x, y)

Return x**y (x to the power of y).

thermo.utils.radians(x)

Convert angle x from degrees to radians.

thermo.utils.sin(x)

Return the sine of x (measured in radians).

thermo.utils.sinh(x)

Return the hyperbolic sine of x.

thermo.utils.sqrt(x)

Return the square root of x.

thermo.utils.tan(x)

Return the tangent of x (measured in radians).

thermo.utils.tanh(x)

Return the hyperbolic tangent of x.

thermo.utils.trunc(x:Real) → Integral

Truncates x to the nearest Integral toward 0. Uses the __trunc__ magic method.