functor#

functor(f=None, var=None, units=None)[source]#

Decorate a function of temperature, or both temperature and pressure to have an attribute, functor, that serves to create its functor counterpart.

Parameters:
  • f (function(T, *args) or function(T, P, *args)) – Function that calculates a thermodynamic property based on temperature, or both temperature and pressure.

  • var (str, optional) – Name of variable returned (useful for bookkeeping).

  • units (dict, optional) – Units of measure for functor signature.

Returns:

f – Same function, but with an attribute functor that can create its Functor counterpart.

Return type:

function(T, *args) or function(T, P, *args)

Notes

The functor decorator checks the signature of the function to find the names of the parameters that should be stored as data.

Examples

Create a functor of temperature that returns the vapor pressure in Pascal:

>>> # Describe the return value with `var`.
>>> # Thermosteam's chemical units of measure are always assumed.
>>> import thermosteam as tmo
>>> @tmo.functor(var='Psat')
... def Antoine(T, a, b, c):
...     return 10.0**(a - b / (T + c))
>>> Antoine(T=373.15, a=10.116, b=1687.5, c=-42.98) # functional
101157.148
>>> f = Antoine.functor(a=10.116, b=1687.5, c=-42.98) # as functor object
>>> f.show()
Functor: Antoine(T, P=None) -> Psat [Pa]
 a: 10.116
 b: 1687.5
 c: -42.98
>>> f(T=373.15)
101157.148

All functors are saved in the functors module:

>>> tmo.functors.Antoine
<class 'thermosteam.functors.Antoine'>