Utilities and Base Classes (thermo.utils)¶
This module contains base classes for temperature T, pressure P, and composition zs dependent properties. These power the various interfaces for each property.
For reporting bugs, adding feature requests, or submitting pull requests, please use the GitHub issue tracker.
Temperature Dependent¶
- class thermo.utils.TDependentProperty(extrapolation, **kwargs)[source]¶
Class for calculating temperature-dependent chemical properties.
On creation, a
TDependentProperty
examines all the possible methods implemented for calculating the property, loads whichever coefficients it needs (unless load_data is set to False), examines its input parameters, and selects the method it prefers. This method will continue to be used for all calculations until the method is changed by setting a new method to the tomethod
attribute.The default list of preferred method orderings is at
ranked_methods
for all properties; the order can be modified there in-place, and this will take effect on all newTDependentProperty
instances created but NOT on existing instances.All methods 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 a specified method will succeed; for example many expressions are not mathematically valid past the critical point, and in some cases there is no easy way to determine the temperature where a property stops being reasonable.
Accordingly, all properties calculated are checked by a sanity function
test_property_validity
, which has basic sanity checks. If the property is not reasonable, None is returned.This framework also supports 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. 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 are set for the variables
interpolation_T
,interpolation_property
, andinterpolation_property_inv
.In order to calculate properties outside of the range of their correlations, a number of extrapolation method are available. Extrapolation is used by default on some properties but not all. The extrapolation methods available are as follows:
‘constant’ - returns the model values as calculated at the temperature limits
‘linear’ - fits the model at its temperature limits to a linear model
‘nolimit’ - attempt to evaluate the model outside of its limits; this will error in most cases and return None
‘interp1d’ - SciPy’s
interp1d
is used to extrapolate‘AntoineAB’ - fits the model to
Antoine
’s equation at the temperature limits using only the A and B coefficient‘DIPPR101_ABC’ - fits the model at its temperature limits to the
EQ101
equation‘Watson’ - fits the model to the Heat of Vaporization model
Watson
‘EXP_POLY_LN_TAU2’ - uses the models’s critical temperature and derivative to fit the model linearly in the equation \(\text{prop} = \exp(a + b\cdot\ln\tau)\), so that it is always zero at the critical point; suitable for surface tension.
‘DIPPR106_AB’ - uses the models’s critical temperature and derivative to fit the model linearly in the equation
EQ106
’s equation at the temperature limits using only the A and B coefficient‘DIPPR106_ABC’ - uses the models’s critical temperature and first two derivatives to fit the model quadratically in the equation
EQ106
’s equation at the temperature limits using only the A, B, and C coefficient.
It is possible to use different extrapolation methods for the low-temperature and the high-temperature region. Specify the extrapolation parameter with the ‘|’ symbols between the two methods; the first method is used for low-temperature, and the second for the high-temperature.
- Attributes
- namestr
The name of the property being calculated, [-]
- unitsstr
The units of the property, [-]
method
strMethod used to set a specific property method or to obtain the name of the method in use.
- interpolation_Tcallable or None
A function or lambda expression to transform the temperatures of tabular data for interpolation; e.g. ‘lambda self, T: 1./T’
- interpolation_T_invcallable or None
A function or lambda expression to invert the transform of temperatures of tabular data for interpolation; e.g. ‘lambda self, x: self.Tc*(1 - x)’
- interpolation_propertycallable or None
A function or lambda expression to transform tabular property values prior to interpolation; e.g. ‘lambda self, P: log(P)’
- interpolation_property_invcallable or None
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)’Tmin
floatMinimum temperature (K) at which the current method can calculate the property.
Tmax
floatMaximum temperature (K) at which the current method can calculate the property.
- property_minfloat
Lowest value expected for a property while still being valid; this is a criteria used by
test_method_validity
.- property_maxfloat
Highest value expected for a property while still being valid; this is a criteria used by
test_method_validity
.- ranked_methodslist
Constant list of ranked methods by default
- tabular_datadict
Stores all user-supplied property data for interpolation in format {name: (Ts, properties)}, [-]
- tabular_data_interpolatorsdict
Stores all interpolation objects, idexed by name and property transform methods with the format {(name, interpolation_T, interpolation_property, interpolation_property_inv): (extrapolator, spline)}, [-]
- all_methodsset
Set of all methods available for a given CASRN and set of properties, [-]
Methods
Method to calculate the property with sanity checking and using the selected
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 the selected method.
Method to calculate the integral of a property over temperature with respect to temperature, using the selected method.
__call__
(T)Convenience method to calculate the property; calls
T_dependent_property
.add_correlation
(name, model, Tmin, Tmax, ...)Method to add a new set of emperical fit equation coefficients to the object and select it for future property calculations.
add_method
(f[, Tmin, Tmax, f_der, f_der2, ...])Define a new method and select it for future property calculations.
add_tabular_data
(Ts, properties[, name, ...])Method to set tabular data to be used for interpolation.
as_json
([references])Method to create a JSON serialization of the property model which can be stored, and reloaded later.
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
(T, method[, in_range])Method to perform extrapolation on a given method according to the
extrapolation
setting.fit_add_model
(name, model, Ts, data, **kwargs)Method to add a new emperical fit equation to the object by fitting its coefficients to specified data.
fit_data_to_model
(Ts, data, model[, ...])Method to fit T-dependent property data to one of the available model correlations.
from_json
(json_repr)Method to create a property model from a JSON serialization of another property model.
interpolate
(T, name)Method to perform interpolation on a given tabular data set previously added via
add_tabular_data
.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.
polynomial_from_method
(method[, n, start_n, ...])Method to fit a T-dependent property to a polynomial.
solve_property
(goal)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.
valid_methods
([T])Method to obtain a sorted list of methods that have data available to be used.
- T_dependent_property(T)[source]¶
Method to calculate the property with sanity checking and using the selected
method
.In the unlikely event the calculation of the property fails, None is returned.
The calculated result is checked with
test_property_validity
and None is returned if the calculated value is nonsensical.- Parameters
- Tfloat
Temperature at which to calculate the property, [K]
- Returns
- propfloat
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.
Calls
calculate_derivative
internally to perform the actual calculation.\[\text{derivative} = \frac{d (\text{property})}{d T} \]- Parameters
- Tfloat
Temperature at which to calculate the derivative, [K]
- orderint
Order of the derivative, >= 1
- Returns
- derivativefloat
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 the selected method.
Calls
calculate_integral
internally to perform the actual calculation.\[\text{integral} = \int_{T_1}^{T_2} \text{property} \; dT \]- Parameters
- T1float
Lower limit of integration, [K]
- T2float
Upper limit of integration, [K]
- Returns
- integralfloat
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 the selected method.
Calls
calculate_integral_over_T
internally to perform the actual calculation.\[\text{integral} = \int_{T_1}^{T_2} \frac{\text{property}}{T} \; dT \]- Parameters
- T1float
Lower limit of integration, [K]
- T2float
Upper limit of integration, [K]
- Returns
- integralfloat
Calculated integral of the property over the given range, [units]
- T_limits = {}¶
Dictionary containing method: (Tmin, Tmax) pairs for all methods applicable to the chemical
- __call__(T)[source]¶
Convenience method to calculate the property; calls
T_dependent_property
. Caches previously calculated value, which is an overhead when calculating many different values of a property. SeeT_dependent_property
for more details as to the calculation procedure.- Parameters
- Tfloat
Temperature at which to calculate the property, [K]
- Returns
- propfloat
Calculated property, [units]
- __repr__()[source]¶
Create and return a string representation of the object. The design of the return string is such that it can be
eval
’d into itself. This is very convinient for creating tests. Note that several methods are not compatible with theeval
’ing principle.- Returns
- reprstr
String representation, [-]
- add_correlation(name, model, Tmin, Tmax, **kwargs)[source]¶
Method to add a new set of emperical fit equation coefficients to the object and select it for future property calculations.
A number of hardcoded model names are implemented; other models are not supported.
- Parameters
- namestr
The name of the coefficient set; user specified, [-]
- modelstr
A string representing the supported models, [-]
- Tminfloat
Minimum temperature to use the method at, [K]
- Tmaxfloat
Maximum temperature to use the method at, [K]
- kwargsdict
Various keyword arguments accepted by the model, [-]
Notes
The correlation models and links to their functions, describing their parameters, are as follows:
“Antoine”:
Antoine
, required parameters (‘A’, ‘B’, ‘C’), optional parameters (‘base’,).“TRC_Antoine_extended”:
TRC_Antoine_extended
, required parameters (‘Tc’, ‘to’, ‘A’, ‘B’, ‘C’, ‘n’, ‘E’, ‘F’).“Wagner_original”:
Wagner_original
, required parameters (‘Tc’, ‘Pc’, ‘a’, ‘b’, ‘c’, ‘d’).“Wagner”:
Wagner
, required parameters (‘Tc’, ‘Pc’, ‘a’, ‘b’, ‘c’, ‘d’).“Yaws_Psat”:
Yaws_Psat
, required parameters (‘A’, ‘B’, ‘C’, ‘D’, ‘E’).“TDE_PVExpansion”:
TDE_PVExpansion
, required parameters (‘a1’, ‘a2’, ‘a3’), optional parameters (‘a4’, ‘a5’, ‘a6’, ‘a7’, ‘a8’).“Alibakhshi”:
Alibakhshi
, required parameters (‘Tc’, ‘C’).“PPDS12”:
PPDS12
, required parameters (‘Tc’, ‘A’, ‘B’, ‘C’, ‘D’, ‘E’).“Watson”:
Watson
, required parameters (‘Hvap_ref’, ‘T_ref’, ‘Tc’), optional parameters (‘exponent’,).“Viswanath_Natarajan_2”:
Viswanath_Natarajan_2
, required parameters (‘A’, ‘B’).“Viswanath_Natarajan_2_exponential”:
Viswanath_Natarajan_2_exponential
, required parameters (‘C’, ‘D’).“Viswanath_Natarajan_3”:
Viswanath_Natarajan_3
, required parameters (‘A’, ‘B’, ‘C’).“PPDS5”:
PPDS5
, required parameters (‘Tc’, ‘a0’, ‘a1’, ‘a2’).“mu_TDE”:
mu_TDE
, required parameters (‘A’, ‘B’, ‘C’, ‘D’).“PPDS9”:
PPDS9
, required parameters (‘A’, ‘B’, ‘C’, ‘D’, ‘E’).“mu_Yaws”:
mu_Yaws
, required parameters (‘A’, ‘B’), optional parameters (‘C’, ‘D’).“Poling”:
Poling
, required parameters (‘a’, ‘b’, ‘c’, ‘d’, ‘e’).“TRCCp”:
TRCCp
, required parameters (‘a0’, ‘a1’, ‘a2’, ‘a3’, ‘a4’, ‘a5’, ‘a6’, ‘a7’).“Zabransky_quasi_polynomial”:
Zabransky_quasi_polynomial
, required parameters (‘Tc’, ‘a1’, ‘a2’, ‘a3’, ‘a4’, ‘a5’, ‘a6’).“Zabransky_cubic”:
Zabransky_cubic
, required parameters (‘a1’, ‘a2’, ‘a3’, ‘a4’).“REFPROP_sigma”:
REFPROP_sigma
, required parameters (‘Tc’, ‘sigma0’, ‘n0’), optional parameters (‘sigma1’, ‘n1’, ‘sigma2’, ‘n2’).“Somayajulu”:
Somayajulu
, required parameters (‘Tc’, ‘A’, ‘B’, ‘C’).“Jasper”:
Jasper
, required parameters (‘a’, ‘b’).“PPDS14”:
PPDS14
, required parameters (‘Tc’, ‘a0’, ‘a1’, ‘a2’).“Watson_sigma”:
Watson_sigma
, required parameters (‘Tc’, ‘a1’, ‘a2’, ‘a3’, ‘a4’, ‘a5’).“ISTExpansion”:
ISTExpansion
, required parameters (‘Tc’, ‘a1’, ‘a2’, ‘a3’, ‘a4’, ‘a5’).“Chemsep_16”:
Chemsep_16
, required parameters (‘A’, ‘B’, ‘C’, ‘D’, ‘E’).“PPDS8”:
PPDS8
, required parameters (‘Tc’, ‘a0’, ‘a1’, ‘a2’, ‘a3’).“PPDS3”:
PPDS3
, required parameters (‘Tc’, ‘a1’, ‘a2’, ‘a3’).“TDE_VDNS_rho”:
TDE_VDNS_rho
, required parameters (‘Tc’, ‘rhoc’, ‘a1’, ‘a2’, ‘a3’, ‘a4’, ‘MW’).“PPDS17”:
PPDS17
, required parameters (‘Tc’, ‘a0’, ‘a1’, ‘a2’, ‘MW’).“volume_VDI_PPDS”:
volume_VDI_PPDS
, required parameters (‘Tc’, ‘rhoc’, ‘a’, ‘b’, ‘c’, ‘d’, ‘MW’).“Rackett_fit”:
Rackett_fit
, required parameters (‘Tc’, ‘rhoc’, ‘b’, ‘n’, ‘MW’).“DIPPR100”:
EQ100
, required parameters (), optional parameters (‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’).“constant”:
EQ100
, required parameters (), optional parameters (‘A’,).“linear”:
EQ100
, required parameters (), optional parameters (‘A’, ‘B’).“quadratic”:
EQ100
, required parameters (), optional parameters (‘A’, ‘B’, ‘C’).“cubic”:
EQ100
, required parameters (), optional parameters (‘A’, ‘B’, ‘C’, ‘D’).“quintic”:
EQ100
, required parameters (), optional parameters (‘A’, ‘B’, ‘C’, ‘D’, ‘E’).“polynomial”:
horner_backwards
, required parameters (‘coeffs’,).“exp_polynomial”:
exp_horner_backwards
, required parameters (‘coeffs’,).“polynomial_ln_tau”:
horner_backwards_ln_tau
, required parameters (‘Tc’, ‘coeffs’).“exp_polynomial_ln_tau”:
exp_horner_backwards_ln_tau
, required parameters (‘Tc’, ‘coeffs’).“DIPPR101”:
EQ101
, required parameters (‘A’, ‘B’), optional parameters (‘C’, ‘D’, ‘E’).“DIPPR102”:
EQ102
, required parameters (‘A’, ‘B’, ‘C’, ‘D’).“DIPPR104”:
EQ104
, required parameters (‘A’, ‘B’), optional parameters (‘C’, ‘D’, ‘E’).“DIPPR105”:
EQ105
, required parameters (‘A’, ‘B’, ‘C’, ‘D’).“DIPPR106”:
EQ106
, required parameters (‘Tc’, ‘A’, ‘B’), optional parameters (‘C’, ‘D’, ‘E’).“YawsSigma”:
EQ106
, required parameters (‘Tc’, ‘A’, ‘B’), optional parameters (‘C’, ‘D’, ‘E’).“DIPPR107”:
EQ107
, required parameters (), optional parameters (‘A’, ‘B’, ‘C’, ‘D’, ‘E’).“DIPPR114”:
EQ114
, required parameters (‘Tc’, ‘A’, ‘B’, ‘C’, ‘D’).“DIPPR115”:
EQ115
, required parameters (‘A’, ‘B’), optional parameters (‘C’, ‘D’, ‘E’).“DIPPR116”:
EQ116
, required parameters (‘Tc’, ‘A’, ‘B’, ‘C’, ‘D’, ‘E’).“DIPPR127”:
EQ127
, required parameters (‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’).“Twu91_alpha_pure”:
Twu91_alpha_pure
, required parameters (‘Tc’, ‘c0’, ‘c1’, ‘c2’).“Heyen_alpha_pure”:
Heyen_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’).“Harmens_Knapp_alpha_pure”:
Harmens_Knapp_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’).“Mathias_Copeman_untruncated_alpha_pure”:
Mathias_Copeman_untruncated_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’, ‘c3’).“Mathias_1983_alpha_pure”:
Mathias_1983_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’).“Soave_1972_alpha_pure”:
Soave_1972_alpha_pure
, required parameters (‘Tc’, ‘c0’).“Soave_1979_alpha_pure”:
Soave_1979_alpha_pure
, required parameters (‘Tc’, ‘M’, ‘N’).“Gibbons_Laughton_alpha_pure”:
Gibbons_Laughton_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’).“Soave_1984_alpha_pure”:
Soave_1984_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’).“Yu_Lu_alpha_pure”:
Yu_Lu_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’, ‘c3’, ‘c4’).“Trebble_Bishnoi_alpha_pure”:
Trebble_Bishnoi_alpha_pure
, required parameters (‘Tc’, ‘c1’).“Melhem_alpha_pure”:
Melhem_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’).“Androulakis_alpha_pure”:
Androulakis_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’, ‘c3’).“Schwartzentruber_alpha_pure”:
Schwartzentruber_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’, ‘c3’, ‘c4’).“Almeida_alpha_pure”:
Almeida_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’, ‘c3’).“Soave_1993_alpha_pure”:
Soave_1993_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’).“Gasem_alpha_pure”:
Gasem_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’, ‘c3’).“Coquelet_alpha_pure”:
Coquelet_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’, ‘c3’).“Haghtalab_alpha_pure”:
Haghtalab_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’, ‘c3’).“Saffari_alpha_pure”:
Saffari_alpha_pure
, required parameters (‘Tc’, ‘c1’, ‘c2’, ‘c3’).“Chen_Yang_alpha_pure”:
Chen_Yang_alpha_pure
, required parameters (‘Tc’, ‘omega’, ‘c1’, ‘c2’, ‘c3’, ‘c4’, ‘c5’, ‘c6’, ‘c7’).“Wagner2,5”:
Wagner
, required parameters (‘Tc’, ‘Pc’, ‘a’, ‘b’, ‘c’, ‘d’).“Wagner3,6”:
Wagner_original
, required parameters (‘Tc’, ‘Pc’, ‘a’, ‘b’, ‘c’, ‘d’).“Andrade”:
Viswanath_Natarajan_2
, required parameters (‘A’, ‘B’).“YawsHvap”:
EQ106
, required parameters (‘Tc’, ‘A’, ‘B’), optional parameters (‘C’, ‘D’, ‘E’).
- add_method(f, Tmin=None, Tmax=None, f_der=None, f_der2=None, f_der3=None, f_int=None, f_int_over_T=None, name=None)[source]¶
Define a new method and select it for future property calculations.
- Parameters
- fcallable
Object which calculates the property given the temperature in K, [-]
- Tminfloat, optional
Minimum temperature to use the method at, [K]
- Tmaxfloat, optional
Maximum temperature to use the method at, [K]
- f_dercallable, optional
If specified, should take as an argument the temperature and return the first derivative of the property, [-]
- f_der2callable, optional
If specified, should take as an argument the temperature and return the second derivative of the property, [-]
- f_der3callable, optional
If specified, should take as an argument the temperature and return the third derivative of the property, [-]
- f_intcallable, optional
If specified, should take T1 and T2 and return the integral of the property from T1 to T2, [-]
- f_int_over_Tcallable, optional
If specified, should take T1 and T2 and return the integral of the property over T from T1 to T2, [-]
- namestr, optional
Name of method.
Notes
Once a custom method has been added to an object, that object can no longer be serialized to json and the
TDependentProperty.__repr__
method can no longer be used to reconstruct the object completely.
- add_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.
After adding the data, this method becomes the selected method.
- Parameters
- Tsarray-like
Increasing array of temperatures at which properties are specified, [K]
- propertiesarray-like
List of properties at Ts, [units]
- namestr, optional
Name assigned to the data
- check_propertiesbool
If True, the properties will be checked for validity with
test_property_validity
and raise an exception if any are not valid
- as_json(references=1)[source]¶
Method to create a JSON serialization of the property model which can be stored, and reloaded later.
- Parameters
- referencesint
How to handle references to other objects; internal parameter, [-]
- Returns
- json_reprdict
JSON-friendly representation, [-]
- 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
- Tfloat
Temperature at which to calculate the property, [K]
- methodstr
Method name to use
- Returns
- propfloat
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
- Tfloat
Temperature at which to calculate the derivative, [K]
- methodstr
Method for which to find the derivative
- orderint
Order of the derivative, >= 1
- Returns
- derivativefloat
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
- T1float
Lower limit of integration, [K]
- T2float
Upper limit of integration, [K]
- methodstr
Method for which to find the integral
- Returns
- integralfloat
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
- T1float
Lower limit of integration, [K]
- T2float
Upper limit of integration, [K]
- methodstr
Method for which to find the integral
- Returns
- integralfloat
Calculated integral of the property over the given range, [units]
- critical_zero = False¶
Whether or not the property is declining and reaching zero at the critical point. This is used by numerical solvers.
- extrapolate(T, method, in_range='error')[source]¶
Method to perform extrapolation on a given method according to the
extrapolation
setting.- Parameters
- Tfloat
Temperature at which to extrapolate the property, [K]
- methodstr
The method to use, [-]
- in_rangestr
How to handle inputs which are not outside the temperature limits; set to ‘low’ to use the low T extrapolation, ‘high’ to use the high T extrapolation, ‘nearest’ to use the nearest value, and ‘error’ or anything else to raise an error in those cases, [-]
- Returns
- propfloat
Calculated property, [units]
- property extrapolation¶
The string setting of the current extrapolation settings. This can be set to a new value to change which extrapolation setting is used.
- fit_add_model(name, model, Ts, data, **kwargs)[source]¶
Method to add a new emperical fit equation to the object by fitting its coefficients to specified data. Once added, the new method is set as the default.
A number of hardcoded model names are implemented; other models are not supported.
This is a wrapper around
TDependentProperty.fit_data_to_model
andTDependentProperty.add_correlation
.The data is also stored in the object as a tabular method with the name name`+’_data’, through :obj:`TDependentProperty.add_tabular_data.
- Parameters
- namestr
The name of the coefficient set; user specified, [-]
- modelstr
A string representing the supported models, [-]
- Tslist[float]
Temperatures of the data points, [K]
- datalist[float]
Data points, [units]
- kwargsdict
Various keyword arguments accepted by fit_data_to_model, [-]
- classmethod fit_data_to_model(Ts, data, model, model_kwargs=None, fit_method='lm', sigma=None, use_numba=False, do_statistics=False, guesses=None, solver_kwargs=None, objective='MeanSquareErr', multiple_tries=False, multiple_tries_max_err=1e-05, multiple_tries_max_objective='MeanRelErr')[source]¶
Method to fit T-dependent property data to one of the available model correlations.
- Parameters
- Tslist[float]
Temperatures of the data points, [K]
- datalist[float]
Data points, [units]
- modelstr
A string representing the supported models, [-]
- model_kwargsdict, optional
Various keyword arguments accepted by the model; not necessary for most models. Parameters which are normally fit, can be specified here as well with a constant value and then that fixed value will be used instead of fitting the parameter. [-]
- fit_methodstr, optional
The fit method to use; one of {lm, trf, dogbox, differential_evolution}, [-]
- sigmaNone or list[float]
Uncertainty parameters used by curve_fit, [-]
- use_numbabool, optional
Whether or not to try to use numba to speed up the computation, [-]
- do_statisticsbool, optional
Whether or not to compute statistical measures on the outputs, [-]
- guessesdict[str: float], optional
Parameter guesses, by name; any number of parameters can be specified, [-]
- solver_kwargsdict
Extra parameters to be passed to the solver chosen, [-]
- objectivestr
The minimimization criteria; supported by differential_evolution. One of:
‘MeanAbsErr’: Mean absolute error
‘MeanRelErr’: Mean relative error
‘MeanSquareErr’: Mean squared absolute error
‘MeanSquareRelErr’: Mean squared relative error
‘MaxAbsErr’: Maximum absolute error
‘MaxRelErr’: Maximum relative error
‘MaxSquareErr’: Maximum squared absolute error
‘MaxSquareRelErr’: Maximum squared relative error
- multiple_triesbool or int
For most solvers, multiple initial guesses are available and the best guess is normally tried. When this is set to True, all guesses are tried until one is found with an error lower than multiple_tries_max_err. If an int is supplied, the best multiple_tries guesses are tried only. [-]
- multiple_tries_max_errfloat
Only used when multiple_tries is true; if a solution is found with lower error than this, no further guesses are tried, [-]
- multiple_tries_max_objectivestr
The error criteria to use for minimization, [-]
- Returns
- coefficientsdict[str: float]
Calculated coefficients, [various]
- statisticsdict[str: float]
Statistics, calculated and returned only if do_statistics is True, [-]
- classmethod from_json(json_repr)[source]¶
Method to create a property model from a JSON serialization of another property model.
- Parameters
- json_reprdict
JSON-friendly representation, [-]
- Returns
- model
TDependentProperty
orTPDependentProperty
Newly created object from the json serialization, [-]
- model
Notes
It is important that the input string be in the same format as that created by
TDependentProperty.as_json
.
- interpolate(T, name)[source]¶
Method to perform interpolation on a given tabular data set previously added via
add_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
, andinterpolation_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
- Tfloat
Temperature at which to interpolate the property, [K]
- namestr
The name assigned to the tabular data set
- Returns
- propfloat
Calculated property, [units]
- interpolation_T = None¶
- interpolation_T_inv = None¶
- interpolation_property = None¶
- interpolation_property_inv = None¶
- property method¶
Method used to set a specific property method or to obtain the name of the method in use.
When setting a method, an exception is raised if the method specified isnt’t available for the chemical with the provided information.
If method is None, no calculations can be performed.
- Parameters
- methodstr
Method to use, [-]
- name = 'Property name'¶
- plot_T_dependent_property(Tmin=None, Tmax=None, methods=[], pts=250, only_valid=True, order=0, show=True, tabular_points=True, axes='semilogy')[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,:obj: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
- Tminfloat
Minimum temperature, to begin calculating the property, [K]
- Tmaxfloat
Maximum temperature, to stop calculating the property, [K]
- methodslist, optional
List of methods to consider
- ptsint, 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_validbool
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
- showbool
If True, displays the plot; otherwise, returns it
- tabular_pointsbool, optional
If True, tabular data will only be shows as the original points; otherwise interpolated values are shown, [-]
- polynomial_from_method(method, n=None, start_n=3, max_n=30, eval_pts=100, fit_form='POLY_FIT', fit_method=None)[source]¶
Method to fit a T-dependent property to a polynomial. The degree of the polynomial can be specified with the n parameter, or it will be automatically selected for maximum accuracy.
- Parameters
- methodstr
Method name to fit, [-]
- nint, optional
The degree of the polynomial, if specified
- start_nint
If n is not specified, all polynomials of degree start_n to max_n will be tried and the highest-accuracy will be selected; [-]
- max_nint
If n is not specified, all polynomials of degree start_n to max_n will be tried and the highest-accuracy will be selected; [-]
- eval_ptsint
The number of points to evaluate the fitted functions at to check for accuracy; more is better but slower, [-]
- fit_formstr
The shape of the polynomial; options are ‘POLY_FIT’, ‘EXP_POLY_FIT’, ‘EXP_POLY_FIT_LN_TAU’, and ‘POLY_FIT_LN_TAU’ [-]
- Returns
- coeffslist[float]
Fit coefficients, [-]
- Tminfloat
The minimum temperature used for the fitting, [K]
- Tmaxfloat
The maximum temperature used for the fitting, [K]
- err_avgfloat
Mean error in the evaluated points, [-]
- err_stdfloat
Standard deviation of errors in the evaluated points, [-]
- min_ratiofloat
Lowest ratio of calc/actual in any found points, [-]
- max_ratiofloat
Highest ratio of calc/actual in any found points, [-]
- property_max = 10000.0¶
- property_min = 0¶
- ranked_methods = []¶
- solve_property(goal)[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.Checks the given property value with
test_property_validity
first and raises an exception if it is not valid.- Parameters
- goalfloat
Propoerty value desired, [units]
- Returns
- Tfloat
Temperature at which the property is the specified value [K]
- 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
- Tfloat
Temperature at which to determine the validity of the method, [K]
- methodstr
Method name to use
- Returns
- validitybool
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
andproperty_max
.- Parameters
- propfloat
property to be tested, [units]
- Returns
- validitybool
Whether or not a specifid method is valid
- units = 'Property units'¶
- valid_methods(T=None)[source]¶
Method to obtain a sorted list of methods that have data available to be used. The methods are ranked in the following order:
The currently selected method is first (if one is selected)
Other available methods are ranked by the attribute
ranked_methods
If T is provided, the methods will be checked against the temperature limits of the correlations as well.
- Parameters
- Tfloat or None
Temperature at which to test methods, [K]
- Returns
- sorted_valid_methodslist
Sorted lists of methods valid at T according to
test_method_validity
, [-]
Temperature and Pressure Dependent¶
- class thermo.utils.TPDependentProperty(extrapolation, **kwargs)[source]¶
Bases:
thermo.utils.t_dependent_property.TDependentProperty
Class for calculating temperature and pressure dependent chemical properties.
On creation, a
TPDependentProperty
examines all the possible methods implemented for calculating the property, loads whichever coefficients it needs (unless load_data is set to False), examines its input parameters, and selects the method it prefers. This method will continue to be used for all calculations until the method is changed by setting a new method to the tomethod
attribute.Because many pressure dependent property methods are implemented as a low-pressure correlation and a high-pressure correlation, this class works essentially the same as
TDependentProperty
but with extra methods that accept pressure as a parameter.The object also selects the pressure-dependent method it prefers. This method will continue to be used for all pressure-dependent calculations until the pressure-dependent method is changed by setting a new method_P to the to
method_P
attribute.The default list of preferred pressure-dependent method orderings is at
ranked_methods_P
for all properties; the order can be modified there in-place, and this will take effect on all newTPDependentProperty
instances created but NOT on existing instances.Tabular data can be provided as either temperature-dependent or pressure-dependent data. The same extrapolation settings as in
TDependentProperty
are implemented here for the low-pressure correlations.In addition to the methods and attributes shown here, all those from
TPDependentProperty
are also available.- Attributes
Methods
TP_dependent_property
(T, P)Method to calculate the property given a temperature and pressure according to the selected
method_P
andmethod
.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, according to the selected
method_P
.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, according to the selected
method_P
.Method to calculate the property given a temperature and pressure according to the selected
method_P
andmethod
.__call__
(T, P)Convenience method to calculate the property; calls
TP_dependent_property
.add_method
(f[, Tmin, Tmax, f_der, f_der2, ...])Define a new method and select it for future property calculations.
add_tabular_data
(Ts, properties[, name, ...])Method to set tabular data to be used for interpolation.
add_tabular_data_P
(Ts, Ps, properties[, ...])Method to set tabular data to be used for interpolation.
calculate
(T, method)Method to calculate a property with a specified method, with no validity checking or error handling.
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.
extrapolate
(T, method[, in_range])Method to perform extrapolation on a given method according to the
extrapolation
setting.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_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.
solve_property
(goal)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.
valid_methods
([T])Method to obtain a sorted list of methods that have data available to be used.
valid_methods_P
([T, P])Method to obtain a sorted list of high-pressure methods that have data available to be used.
- TP_dependent_property(T, P)[source]¶
Method to calculate the property given a temperature and pressure according to the selected
method_P
andmethod
. The pressure-dependent method is always used and required to succeed. The result is checked withtest_property_validity
.If the method does not succeed, returns None.
- Parameters
- Tfloat
Temperature at which to calculate the property, [K]
- Pfloat
Pressure at which to calculate the property, [Pa]
- Returns
- propfloat
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, according to the selected
method_P
.Calls
calculate_derivative_P
internally to perform the actual calculation.\[\text{derivative} = \frac{d (\text{property})}{d P}|_{T} \]- Parameters
- Tfloat
Temperature at which to calculate the derivative, [K]
- Pfloat
Pressure at which to calculate the derivative, [Pa]
- orderint
Order of the derivative, >= 1
- Returns
- dprop_dP_Tfloat
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, according to the selected
method_P
.Calls
calculate_derivative_T
internally to perform the actual calculation.\[\text{derivative} = \frac{d (\text{property})}{d T}|_{P} \]- Parameters
- Tfloat
Temperature at which to calculate the derivative, [K]
- Pfloat
Pressure at which to calculate the derivative, [Pa]
- orderint
Order of the derivative, >= 1
- Returns
- dprop_dT_Pfloat
Calculated derivative property, [units/K^order]
- TP_or_T_dependent_property(T, P)[source]¶
Method to calculate the property given a temperature and pressure according to the selected
method_P
andmethod
. The pressure-dependent method is always tried. The result is checked withtest_property_validity
.If the pressure-dependent method does not succeed, the low-pressure method is tried and its result is returned.
Warning
It can seem like a good idea to switch between a low-pressure and a high-pressure method if the high pressure method is not working, however it can cause discontinuities and prevent numerical methods from converging
- Parameters
- Tfloat
Temperature at which to calculate the property, [K]
- Pfloat
Pressure at which to calculate the property, [Pa]
- Returns
- propfloat
Calculated property, [units]
- T_limits = {}¶
Dictionary containing method: (Tmin, Tmax) pairs for all methods applicable to the chemical
- __call__(T, P)[source]¶
Convenience method to calculate the property; calls
TP_dependent_property
. Caches previously calculated value, which is an overhead when calculating many different values of a property. SeeTP_dependent_property
for more details as to the calculation procedure.- Parameters
- Tfloat
Temperature at which to calculate the property, [K]
- Pfloat
Pressure at which to calculate the property, [Pa]
- Returns
- propfloat
Calculated property, [units]
- add_method(f, Tmin=None, Tmax=None, f_der=None, f_der2=None, f_der3=None, f_int=None, f_int_over_T=None, name=None)¶
Define a new method and select it for future property calculations.
- Parameters
- fcallable
Object which calculates the property given the temperature in K, [-]
- Tminfloat, optional
Minimum temperature to use the method at, [K]
- Tmaxfloat, optional
Maximum temperature to use the method at, [K]
- f_dercallable, optional
If specified, should take as an argument the temperature and return the first derivative of the property, [-]
- f_der2callable, optional
If specified, should take as an argument the temperature and return the second derivative of the property, [-]
- f_der3callable, optional
If specified, should take as an argument the temperature and return the third derivative of the property, [-]
- f_intcallable, optional
If specified, should take T1 and T2 and return the integral of the property from T1 to T2, [-]
- f_int_over_Tcallable, optional
If specified, should take T1 and T2 and return the integral of the property over T from T1 to T2, [-]
- namestr, optional
Name of method.
Notes
Once a custom method has been added to an object, that object can no longer be serialized to json and the
TDependentProperty.__repr__
method can no longer be used to reconstruct the object completely.
- add_tabular_data(Ts, properties, name=None, check_properties=True)¶
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.
After adding the data, this method becomes the selected method.
- Parameters
- Tsarray-like
Increasing array of temperatures at which properties are specified, [K]
- propertiesarray-like
List of properties at Ts, [units]
- namestr, optional
Name assigned to the data
- check_propertiesbool
If True, the properties will be checked for validity with
test_property_validity
and raise an exception if any are not valid
- add_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.
After adding the data, this method becomes the selected high-pressure method.
- Parameters
- Tsarray-like
Increasing array of temperatures at which properties are specified, [K]
- Psarray-like
Increasing array of pressures at which properties are specified, [Pa]
- propertiesarray-like
List of properties at Ts and Ps; the data should be indexed [P][T], [units]
- namestr, optional
Name assigned to the data
- check_propertiesbool
If True, the properties will be checked for validity with
test_property_validity
and raise an exception if any are not valid
- calculate(T, method)¶
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
- Tfloat
Temperature at which to calculate the property, [K]
- methodstr
Method name to use
- Returns
- propfloat
Calculated property, [units]
- 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
- Pfloat
Pressure at which to calculate the derivative, [Pa]
- Tfloat
Temperature at which to calculate the derivative, [K]
- methodstr
Method for which to find the derivative
- orderint
Order of the derivative, >= 1
- Returns
- dprop_dP_Tfloat
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
- Tfloat
Temperature at which to calculate the derivative, [K]
- Pfloat
Pressure at which to calculate the derivative, [Pa]
- methodstr
Method for which to find the derivative
- orderint
Order of the derivative, >= 1
- Returns
- dprop_dT_Pfloat
Calculated derivative property at constant pressure, [units/K^order]
- extrapolate(T, method, in_range='error')¶
Method to perform extrapolation on a given method according to the
extrapolation
setting.- Parameters
- Tfloat
Temperature at which to extrapolate the property, [K]
- methodstr
The method to use, [-]
- in_rangestr
How to handle inputs which are not outside the temperature limits; set to ‘low’ to use the low T extrapolation, ‘high’ to use the high T extrapolation, ‘nearest’ to use the nearest value, and ‘error’ or anything else to raise an error in those cases, [-]
- Returns
- propfloat
Calculated property, [units]
- property extrapolation¶
The string setting of the current extrapolation settings. This can be set to a new value to change which extrapolation setting is used.
- interpolation_T = None¶
- interpolation_T_inv = None¶
- interpolation_property = None¶
- interpolation_property_inv = None¶
- property method¶
Method used to set a specific property method or to obtain the name of the method in use.
When setting a method, an exception is raised if the method specified isnt’t available for the chemical with the provided information.
If method is None, no calculations can be performed.
- Parameters
- methodstr
Method to use, [-]
- property method_P¶
Method used to set or get a specific property method.
An exception is raised if the method specified isnt’t available for the chemical with the provided information.
- Parameters
- methodstr or list
Methods by name to be considered or preferred
- name = 'Property name'¶
- 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,:obj: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
- Tminfloat
Minimum temperature, to begin calculating the property, [K]
- Tmaxfloat
Maximum temperature, to stop calculating the property, [K]
- Pminfloat
Minimum pressure, to begin calculating the property, [Pa]
- Pmaxfloat
Maximum pressure, to stop calculating the property, [Pa]
- methods_Plist, optional
List of methods to plot
- ptsint, optional
A list of points to calculate the property at for both temperature and pressure; pts^2 points will be calculated.
- only_validbool
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, show=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,:obj: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
- Pfloat
Pressure for the isobar, [Pa]
- Tminfloat
Minimum temperature, to begin calculating the property, [K]
- Tmaxfloat
Maximum temperature, to stop calculating the property, [K]
- methods_Plist, optional
List of methods to consider
- ptsint, 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_validbool
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, show=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, andtest_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
- Tfloat
Temperature at which to create the plot, [K]
- Pminfloat
Minimum pressure, to begin calculating the property, [Pa]
- Pmaxfloat
Maximum pressure, to stop calculating the property, [Pa]
- methods_Plist, optional
List of methods to consider
- ptsint, 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_validbool
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
- showbool
If True, displays the plot; otherwise, returns it
- property_max = 10000.0¶
- property_min = 0¶
- ranked_methods = []¶
- solve_property(goal)¶
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.Checks the given property value with
test_property_validity
first and raises an exception if it is not valid.- Parameters
- goalfloat
Propoerty value desired, [units]
- Returns
- Tfloat
Temperature at which the property is the specified value [K]
- test_method_validity(T, method)¶
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
- Tfloat
Temperature at which to determine the validity of the method, [K]
- methodstr
Method name to use
- Returns
- validitybool
Whether or not a specifid method is valid
- classmethod test_property_validity(prop)¶
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
andproperty_max
.- Parameters
- propfloat
property to be tested, [units]
- Returns
- validitybool
Whether or not a specifid method is valid
- units = 'Property units'¶
- valid_methods(T=None)¶
Method to obtain a sorted list of methods that have data available to be used. The methods are ranked in the following order:
The currently selected method is first (if one is selected)
Other available methods are ranked by the attribute
ranked_methods
If T is provided, the methods will be checked against the temperature limits of the correlations as well.
- Parameters
- Tfloat or None
Temperature at which to test methods, [K]
- Returns
- sorted_valid_methodslist
Sorted lists of methods valid at T according to
test_method_validity
, [-]
- valid_methods_P(T=None, P=None)[source]¶
Method to obtain a sorted list of high-pressure methods that have data available to be used. The methods are ranked in the following order:
The currently selected
method_P
is first (if one is selected)Other available pressure-depenent methods are ranked by the attribute
ranked_methods_P
If T and P are provided, the methods will be checked against the temperature and pressure limits of the correlations as well.
- Parameters
- Tfloat
Temperature at which to test methods, [K]
- Pfloat
Pressure at which to test methods, [Pa]
- Returns
- sorted_valid_methods_Plist
Sorted lists of methods valid at T and P according to
test_method_validity_P
Temperature, Pressure, and Composition Dependent¶
- class thermo.utils.MixtureProperty(**kwargs)[source]¶
Bases:
object
- Attributes
correct_pressure_pure
Method to set the pressure-dependence of the model; if set to False, only temperature dependence is used, and if True, temperature and pressure dependence are used.
method
Method to set the T, P, and composition dependent property method desired.
- prop_cached
Methods
__call__
(T, P[, zs, ws])Convenience method to calculate the property; calls
mixture_property
.as_json
([references])Method to create a JSON serialization of the mixture property which can be stored, and reloaded later.
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.
excess_property
(T, P[, zs, ws])Method to calculate the excess property with sanity checking and without specifying a specific method.
from_json
(string)Method to create a MixtureProperty from a JSON serialization of another MixtureProperty.
mixture_property
(T, P[, zs, ws])Method to calculate the property with sanity checking and without specifying a specific method.
partial_property
(T, P, i[, zs, ws])Method to calculate the partial molar property with sanity checking and without specifying a specific method for the specified compound index and composition.
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 the selected method.
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 set method.
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 the selected method.
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.
test_property_validity
(prop)Method to test the validity of a calculated property.
pure_objs
set_poly_fit_coeffs
- RAISE_PROPERTY_CALCULATION_ERROR = False¶
- TP_zs_ws_cached = (None, None, None, None)¶
- Tmax¶
Maximum temperature at which no method can calculate the property above.
- Tmin¶
Minimum temperature at which no method can calculate the property under.
- all_methods¶
Set of all methods available for a given set of information; filled by
load_all_methods
.
- all_poly_fit = False¶
- as_json(references=1)[source]¶
Method to create a JSON serialization of the mixture property which can be stored, and reloaded later.
- Parameters
- referencesint
How to handle references to other objects; internal parameter, [-]
- Returns
- json_reprdict
JSON-friendly representation, [-]
- 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
- Pfloat
Pressure at which to calculate the derivative, [Pa]
- Tfloat
Temperature at which to calculate the derivative, [K]
- zslist[float]
Mole fractions of all species in the mixture, [-]
- wslist[float]
Weight fractions of all species in the mixture, [-]
- methodstr
Method for which to find the derivative
- orderint
Order of the derivative, >= 1
- Returns
- d_prop_d_P_at_Tfloat
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
- Tfloat
Temperature at which to calculate the derivative, [K]
- Pfloat
Pressure at which to calculate the derivative, [Pa]
- zslist[float]
Mole fractions of all species in the mixture, [-]
- wslist[float]
Weight fractions of all species in the mixture, [-]
- methodstr
Method for which to find the derivative
- orderint
Order of the derivative, >= 1
- Returns
- d_prop_d_T_at_Pfloat
Calculated derivative property at constant pressure, [units/K^order]
- property correct_pressure_pure¶
Method to set the pressure-dependence of the model; if set to False, only temperature dependence is used, and if True, temperature and pressure dependence are used.
- excess_property(T, P, zs=None, ws=None)[source]¶
Method to calculate the excess property with sanity checking and without specifying a specific method. This requires the calculation of the property as a function of composition at the limiting concentration of each component. One or both of zs and ws are required.
\[m^E = m_{mixing} = m - \sum_i m_{i, pure}\cdot z_i \]- Parameters
- Tfloat
Temperature at which to calculate the excess property, [K]
- Pfloat
Pressure at which to calculate the excess property, [Pa]
- zslist[float], optional
Mole fractions of all species in the mixture, [-]
- wslist[float], optional
Weight fractions of all species in the mixture, [-]
- Returns
- excess_propfloat
Calculated excess property, [units]
- classmethod from_json(string)[source]¶
Method to create a MixtureProperty from a JSON serialization of another MixtureProperty.
- Parameters
- json_reprdict
JSON-friendly representation, [-]
- Returns
- constants
MixtureProperty
Newly created object from the json serialization, [-]
- constants
Notes
It is important that the input string be in the same format as that created by
MixtureProperty.as_json
.
- property method¶
Method to set the T, P, and composition dependent property method desired. See the
all_methods
attribute for a list of methods valid for the specified chemicals and inputs.
- mixture_property(T, P, zs=None, ws=None)[source]¶
Method to calculate the property with sanity checking and without specifying a specific method.
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 withtest_property_validity
. On success, the used method is stored in the variablemethod
.If
method
is set, this method is first checked for validity withtest_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 withvalid_methods
and attempts them as described above.If no methods are found which succeed, returns None. One or both of zs and ws are required.
- Parameters
- Tfloat
Temperature at which to calculate the property, [K]
- Pfloat
Pressure at which to calculate the property, [Pa]
- zslist[float], optional
Mole fractions of all species in the mixture, [-]
- wslist[float], optional
Weight fractions of all species in the mixture, [-]
- Returns
- propfloat
Calculated property, [units]
- name = 'Test'¶
- partial_property(T, P, i, zs=None, ws=None)[source]¶
Method to calculate the partial molar property with sanity checking and without specifying a specific method for the specified compound index and composition.
\[\bar m_i = \left( \frac{\partial (n_T m)} {\partial n_i} \right)_{T, P, n_{j\ne i}} \]- Parameters
- Tfloat
Temperature at which to calculate the partial property, [K]
- Pfloat
Pressure at which to calculate the partial property, [Pa]
- iint
Compound index, [-]
- zslist[float], optional
Mole fractions of all species in the mixture, [-]
- wslist[float], optional
Weight fractions of all species in the mixture, [-]
- Returns
- partial_propfloat
Calculated partial property, [units]
- plot_isobar(P, zs=None, ws=None, 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 the selected method. User-selectable number of points, and temperature range. If only_valid is set,:obj: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. One or both of zs and ws are required.- Parameters
- Pfloat
Pressure for the isobar, [Pa]
- zslist[float], optional
Mole fractions of all species in the mixture, [-]
- wslist[float], optional
Weight fractions of all species in the mixture, [-]
- Tminfloat
Minimum temperature, to begin calculating the property, [K]
- Tmaxfloat
Maximum temperature, to stop calculating the property, [K]
- methodslist, optional
List of methods to consider
- ptsint, 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_validbool
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=None, ws=None, 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 set method. 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, andtest_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. One or both of zs and ws are required.- Parameters
- Tfloat
Temperature at which to create the plot, [K]
- zslist[float], optional
Mole fractions of all species in the mixture, [-]
- wslist[float], optional
Weight fractions of all species in the mixture, [-]
- Pminfloat
Minimum pressure, to begin calculating the property, [Pa]
- Pmaxfloat
Maximum pressure, to stop calculating the property, [Pa]
- methodslist, optional
List of methods to consider
- ptsint, 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_validbool
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=None, ws=None, 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 the selected method. User-selectable number of points for each variable. If only_valid is set,:obj: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. One or both of zs and ws are required.- Parameters
- zslist[float], optional
Mole fractions of all species in the mixture, [-]
- wslist[float], optional
Weight fractions of all species in the mixture, [-]
- Tminfloat
Minimum temperature, to begin calculating the property, [K]
- Tmaxfloat
Maximum temperature, to stop calculating the property, [K]
- Pminfloat
Minimum pressure, to begin calculating the property, [Pa]
- Pmaxfloat
Maximum pressure, to stop calculating the property, [Pa]
- methodslist, optional
List of methods to consider
- ptsint, optional
A list of points to calculate the property at for both temperature and pressure; pts^2 points will be calculated.
- only_validbool
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=None, ws=None, 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
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
- Tfloat
Temperature at which to calculate the derivative, [K]
- Pfloat
Pressure at which to calculate the derivative, [Pa]
- zslist[float], optional
Mole fractions of all species in the mixture, [-]
- wslist[float], optional
Weight fractions of all species in the mixture, [-]
- orderint
Order of the derivative, >= 1
- Returns
- d_prop_d_P_at_Tfloat
Calculated derivative property, [units/Pa^order]
- property_derivative_T(T, P, zs=None, ws=None, 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
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} \]One or both of zs and ws are required.
- Parameters
- Tfloat
Temperature at which to calculate the derivative, [K]
- Pfloat
Pressure at which to calculate the derivative, [Pa]
- zslist[float], optional
Mole fractions of all species in the mixture, [-]
- wslist[float], optional
Weight fractions of all species in the mixture, [-]
- orderint
Order of the derivative, >= 1
- Returns
- d_prop_d_T_at_Pfloat
Calculated derivative property, [units/K^order]
- property_max = 10.0¶
- property_min = 0.0¶
- pure_reference_types = ()¶
- pure_references = ()¶
- ranked_methods = []¶
- skip_method_validity_check = False¶
Flag to disable checking the validity of the method at the specified conditions. Saves a little time.
- skip_prop_validity_check = False¶
Flag to disable checking the output of the value. Saves a little time.
- 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
andproperty_max
.- Parameters
- propfloat
property to be tested, [units]
- Returns
- validitybool
Whether or not a specifid method is valid
- units = 'test units'¶