Package: thermopack
ThermoPackThermopack is a thermodynamics library for multi-component and
multi-phase thermodynamics developed atSINTEF Energy
ResearchandNTNU
Department of
Chemistry. Through
decades of research, we have developed a software that performs
thermodynamic calculations. A large selection of equations of state
has been implemented in this software. Most of these equations of
state have been developed by other research groups around the world,
but some of them have been developed by us. Thermopack has been a
much-appreciated in-house powerhouse.For the full documentation and user guide to ThermoPack, see theThermoPack homepage.If you are running ThermoPack installed viapip, make sure to check the documentation for the correct version by selecting
the version number in the sidebar.Thermopack is available for everybody, free of charge under the
MIT/Apache 2.0 open-source licenses. Thermopack is written in FORTRAN
to handle heavy numerical computations associated with process and
computational fluid dynamics (CFD) simulations. The thermodynamic
framework is easily interfaced from C/C++ and also contains a flexible
Python wrapper to make scripting easy.Table of contentsProgram structurePlease citeAuthors and contact personsLicenseAcknowledgmentsGetting startedInitialising an equation of stateDoing calculationspVT-propertiesPhase diagrams and equilibriaIsolinesCritical pointAdvanced usageInteraction parametersComponent identifiersPlease CiteThermopack has been developed through many projects, and have produced many
articles. If you are writing academic publications, please cite one or more of
the following articles:For general usage:Thermodynamic Modeling with Equations of State: Present Challenges with Established MethodsQuantum cubic:Accurate quantum-corrected cubic equations of state for helium, neon, hydrogen, deuterium and their mixturesSAFT-VR Mie and SAFT-VRQ Mie:Equation of state and force fields for Feynman--Hibbs-corrected Mie fluids. I. Application to pure helium, neon, hydrogen, and deuteriumEquation of state and force fields for Feynman–Hibbs-corrected Mie fluids. II. Application to mixtures of helium, neon, hydrogen, and deuteriumChoice of reference, the influence of non-additivity and challenges in thermodynamic perturbation theory for mixturesCPA, PC-SAFT or cubic models with Wong–Sandler, Huron–Vidal or UNIFAC mixing
rules:Thermodynamic models to accurately describe the PVTxy-behavior of water/carbon dioxide mixturesUsing dry-ice and water-ice model or the tc-PR/tc-RK:Depressurization of CO2-N2and CO2-He in a pipe: Experiments and modelling of pressure and temperature dynamicsEnergy-density and entropy-density flashes:The influence of CO2 mixture composition and equations of state on simulations of transient pipeline decompressionMapping spinodals or critical points:The spinodal of single-and multi-component fluids and its role in the development of modern equations of statePredicting triggering and consequence of delayed LNG RPTPerturbation theories for Lennard-Jones spline fluid:Perturbation theories for fluids with short-ranged attractive forces: A case study of the Lennard-Jones spline fluidThermodynamic properties of the 3D Lennard-Jones/spline modelLicenseThermopack is distributed under theMIT
licenseandApache
2.0.AcknowledgmentsA number of colleagues at SINTEF Energy Research and NTNU have contributed to the
development of thermopack. We gratefully acknowledge their contributions.Program structureThe core of ThermoPack is the Fortran module. For more information on that, see theGitHub page.
This page contains an introduction to the ThermoPack python-wrapper, which is an object-oriented implementation of a variety of equations of state (EoS),
with integrated methods for computing thermodynamic properties.Each EoS in thermopack is a class, which inherits from thethermopackclass found inthermo.py.
This class contains all generic methods used to compute thermodynamic properties, phase equilibria, etc. The inheriting
classes simply ensure that the correct part of the Fortran-module is linked when performing calculations, and provide
some extended functionality for handling EoS parameters and such. See theThermoPack homepagefor more information.Fluid parameters are compiled into the Fortran-module, and are not directly accessible through the Python-wrapper.
The entire fluid parameter database used by thermopack may be found in the/fluidsdirectoryin the GitHub repo. In order to model fluids not currently supported in the module available throughpip, ThermoPack
must be compiled from source with the new parameters. See theThermoPack homepagefor information on how to add new fluids, and a guide on how to compile from source. Please feel free to leave a PR for
new parameter sets such that these can be included in future releases of thermopack.Getting StartedCompatibilityThermoPack v2.2.0 is completely backwards compatible with v2.1.0, such that all examples in theguide for v2.1.0will also work with v2.2.0. This guide primarily aims to demonstrate functionality that is new in v2.2.0.Getting started - PythonThis is a short introduction to thermopack. Once you've gotten started, we recommend a look at theExamplesin the GitHub repo. Comprehensive documentation for the methods available through the python interface can also be found in thedoc page for the thermo class.. For more advanced users, a look at themore advanced pagemay also be useful.Equations of State (EoS's) in ThermoPack are classes. To do calculations for a given mixture an EoS object must first be
initialized for that mixture, as demonstrated in theInitializing an EoS section.
Then, a wide variety of thermodynamic computations can be done, as demonstrated in the remaining sections.ContentsInitialising an equation of statepVT propertiesDifferentialsPhase diagrams and equilibriaFlash calculationsPhase envelopesTp- and Tv- envelopespxy- and txy- envelopesDew- and bubble pointsIsolinesCritical pointInitialising an equation of stateAn overview of available equations of state can be foundhere.An EoS is initialized by passing in thefluid identifiersof the mixture, for examplefromthermopack.saftvrmieimportsaftvrmieeos=saftvrmie('C1,CO2')will initialize a SAFT-VR Mie EoS for a mixture of methane and CO2. The complete list of component identifiers is in theFluid identifiers list. PC-SAFT, SAFT-VRQ Mie and Lee-Kesler EoS are initialized in the same way, asfromthermopackimportsaftvrmie,saftvrqmie,pcsaft,lee_keslersvrm=saftvrmie.saftvrmie('AR,KR')# SAFT-VR Mie EoS for Ar/Kr mixturesvrqm=saftvrqmie.saftvrqmie('HE')# SAFT-VRQ Mie EoS for pure Hepcs=pcsaft.pcsaft('BENZENE,NC6,NC12')# PC-SAFT EoS for ternary benzene/hexane/dodecane mixturelk=lee_kesler.lee_kesler('N2,O2')# Lee-Kesler EoS for nitrogen/oxygen mixtureFor PC-SAFT, both the simplified PC-SAFT (SPC-SAFT) and Polar PC-SAFT (PCP-SAFT) are availablefromthermopack.pcsaftimportSPC_SAFT,PCP_SAFTspcs=SPC_SAFT('NC6,NC12')# Simplified PC-SAFTpcps=PCP_SAFT('H2O,MEOH')# Polar PC-SAFTThe cubic equations of state are found in thecubicmodule. Available cubic EoS's and more information on the individual cubics, mixing rules, etc. can be found on thecubic page.fromthermopack.cubicimportSoaveRedlichKwong,RedlichKwong,PengRobinson,PengRobinson78fromthermopack.cubicimportSchmidtWensel,PatelTeja,VanDerWaalssrk=SoaveRedlichKwong('NH3,C2')# SRK EoS for ammonia/ethane mixturerk=RedlichKwong('NC6,CO2,NC12')# Redlich-Kwong EoSpr=PengRobinson('IC4,NC10')# PR EoS for isobutane/decane mixturepr78=PengRobinson78('N2,O2,CO2')# # PR-78 EoS for isobutane/decane mixturevdw=VanDerWaals('C1,C2,C3,N2,O2')# VdW EoS for methane/ethane/propane/nitrogen/oxygen mixturesw=SchmidtWensel('R11,R12')# Schmidt-Wensel EoS for FCl3C/F2Cl2C mixturept=PatelTeja('PRLN')# Patel-Teja EoS for pure propyleneIn addition to these, the Translated-Consisten Peng-Robinson is avaiable asfromthermopack.tcPRimporttcPRtcpr=tcPR('F6S,SO2')# Translated-Consistent PR EoS for SF6/SO2 mixtureFor more fine-tuned control of the cubic EoS, the parent classcubiccan be initialised directly, to explicitly
set mixing rules, alpha-correlation etc.Cubic-plus association EoS's are available for the SRK and PR EoS through thecpamodule asfromthermopack.cpaimportSRK_CPA,PR_CPAsrk_cpa=SRK_CPA('H2O,ETOH,PROP1OL')# SRK-CPA EoS for water/ethanol/propanol mixtureSeveral multiparameter EoS's can interfaced through themultiparameter.multiparamclass. The available multiparameter EoS's are NIST-MEOS, MBWR16 and MBWR32. These are initialized asfromthermopack.multiparameterimportmultiparamnist=multiparam('C3','NIST_MEOS')# NIST-MEOS EoS for propanembwr19=multiparam('C1','MBWR19')# MBWR19 EoS for methanembwr32=multiparam('C2','MBWR32')# MBWR32 EoS for ethaneplease note that not all fluids are supported for multiparameter equations of state, depending on what parameters are available in the fluid database.Finally, the Extended-corresponding state EoS is available through theextended_csp.ext_cspclass asfromthermopack.extended_cspimportext_cspeos=ext_csp('C1,C2,C3,NC4',sh_eos='SRK',sh_alpha='Classic',sh_mixing='vdW',ref_eos='NIST_MEOS',ref_comp='C3')For more information on the extended-csp EoS please see theExamplesand thememo.Doing calculationsNow that we have an EoS initialized we can start computing stuff. The primary source on how to use individual methods in
thermopack are thespecific documentation of thethermoclass.
Here, a small subset of the functionality is demonstrated.Note that all input/output is in SI units (moles/kelvin/pascal/cubic meters/joule)pVT-propertiesSpecific volume, given temperature, pressure and composition is computed asfromthermopack.saftvrmieimportsaftvrmieeos=saftvrmie('NC6,NC10')# Hexane/decane mixtureT=300# Kelvinp=1e5# Pascalx=[0.2,0.8]# Molar compositionvg,=eos.specific_volume(T,p,x,eos.VAPPH)# Molar volume of gas phase (NB: Notice the comma)vl,=eos.specific_volume(T,p,x,eos.LIQPH)# Molar volume of liquid phase (NB: Notice the comma)whereeos.VAPPHandeos.LIQPHarephase flagsused to identify different phases. The commas are necessary because all output from thermopack methods are as tuples.Similarly, pressure, internal energy, enthalpy, entropy, etc. and associated differentials can be computed via the methodschemical_potential_tv(T, V, n),internal_energy_tv(T, V, n),enthalpy_tv(T, V, n),helmholtz_tv(T, V, n),entropy_tv(T, V, n). For a full overview of the available property calculations see theTV-property interfacesand theTp-property interfacesof thethermoclass.DifferentialsIf we want volume differentials, we use the same method, but set the flags to calculate differentials toTrue:# Continuedvg,dvdp=eos.specific_volume(T,p,x,eos.VAPPH,dvdp=True)# Vapour phase molar volume and pressure differentialvl,dvdT=eos.specific_volume(T,p,x,eos.LIQPH,dvdt=True)# Liquid phase molar volume and temperature differential_,dvdn=eos.specific_volume(T,p,x,eos.LIQPH,dvdn=True)# Liquid phase partial molar volumesDifferentials can be computed as functions of $(T, V, n)$ or as functions of $(T, p, n)$. For an overview of the different methods,
seeAdvanced usage: Different property interfaces. A short example is given here as:# Continuedn_tot=15# Total number of molesn=n_tot*xH,dHdn_TV=eos.enthalpy_tv(T,vg,n,dhdn=True)# Compute enthalpy and derivative of enthalpy wrt. mole numbers at constant (T, V)h_vap,dhvap_dn_Tp=eos.enthalpy(T,p,x,eos.VAPPH,dhdn=True)# Compute molar vapour phase enthalpy and derivative of molar vapour phase enthalpy wrt. mole numbers at constant (T, p)h_liq,dliq_dn_Tp=eos.enthalpy(T,p,x,eos.LIQPH,dhdn=True)# Compute molar liquid phase enthalpy and derivative of molar liquid phase enthalpy wrt. mole numbers at constant (T, p)H,dHdn_Tp=eos.enthalpy_tvp(T,vg,n,dhdn=True)# Compute enthalpy and derivative of enthalpy wrt. mole numbers at constant (T, p)Please note that heat capacities are not available directly, but must be computed as derivatives of enthalpy and internal energy, asfromthermopack.cubicimportcubiceos=cubic('C1,C3,NC6','SRK')# SRK EoS for a mixture of methane, propane and n-hexaneT=300# Kelvinp=1e5# Pascalx=[0.2,0.1,0.7]# Molar composition_,Cp_vap=eos.enthalpy(T,p,x,eos.VAPPH,dhdt=True)# Vapour phase heat capacity at constant pressure, computed as (dH/dT)_{p,n}_,Cp_liq=eos.enthalpy(T,p,x,eos.LIQPH,dhdt=True)# Liquid phase heat capacity at constant pressure, computed as (dH/dT)_{p,n}vg,=eos.specific_volume(T,p,x,eos.VAPPH)# Computing vapour phase specific volumevl,=eos.specific_volume(T,p,x,eos.LIQPH)# Liquid phase specific volume_,Cv_vap=eos.internal_energy_tv(T,vg,x,dedt=True)# Vapour phase heat capacity at constant volume, computed as (dU/dT)_{V,n}_,Cv_liq=eos.internal_energy_tv(T,vl,x,dedt=True)# Liquid phase heat capacity at constant volume, computed as (dU/dT)_{V,n}Phase diagrams and EquilibriaAs with other calculations, the primary source on how available methods for flash- and equilibria calculations and how to
use them is thedocumentation of thethermoclass.. Here we give a short introduction, for more extensive examples see thepyExamplesdirectory.Flash calculationsFlash calculations of several kinds are handled by the methodstwophase_tpflash(),twophase_psflash(),twophase_phflash()andtwophase_uvflash().See theFlash interfacesin thedocumentation of thethermoclassfor the specifics on the different flash routines.The result of a flash calculation is returned in aFlashResultstruct. The specific results of the calculation are
accessed through the attributes of this object.An example calculation usingtwophase_tpflash()may be done asfromthermopack.saftvrqmieimportsaftvrqmie# SAFT-VRQ Mie for Hydrogen/Helium/Neon mixtureeos=saftvrqmie('H2,HE,NE',minimum_temperature=20)# NB: Set minimum temperature low enough when working at very low temperaturesT=35# Kelvinp=3e6# Pascal (30 bar)z=[0.1,0.25,0.65]# Molar compositionflsh=eos.two_phase_tpflash(T,p,z)# flsh is a FlashResult objectprint(flsh)### Output: #### FlashResult object for Tp-flash# Containing the attributes (description, name, value):#   	Flash type                     flash_type : Tp#   	Total composition              z     : [0.1, 0.25, 0.65]#   	Temperature [K]                T     : 35#   	pressure [Pa]                  p     : 3000000.0#   	Liquid phase composition       x     : [0.05407302 0.03859287 0.90733411]#   	Vapour phase composition       y     : [0.14642524 0.46370066 0.3898741 ]#   	Vapour fraction                betaV : 0.497302408174766#   	Liquid fraction                betaL : 0.5026975918252341#   	Phase indentifier index        phase : 0the result of the flash is accessed from the attributes of theFlashResultobject, found inutils.py, as# Continuedx=flsh.x# Liquid compositiony=flsh.y# Vapour compositionbetaL=flsh.betaL## ... etcTheFlashResultobject returned by the different flash routines all contain the same attributes.Phase envelopesThermoPack has interfaces to trace (T,p)-, (T,v)-, (p,x,y)- and (T, x, y)- phase envelopes. For the full documentation,
see thedocs of thethermoclass.
For more comprehensive examples, see theExamples.Tp- and Tv- phase envelopesPhase envelopes can be generated directly with the methodget_envelope_twophase()as# ContinuedT,p=eos.get_envelope_twophase(1e5,x)# arrays of temperature and pressure for phase envelope, starting at 1 bar.plt.plot(p,T)# Tp-projection of phase envelopeT,p,v=eos.get_envelope_twophase(1e5,x,calc_v=True)# Also return the specific volume at each point along the phase envelopeplt.plot(1/v,T)# rho-T projection of the phase envelopepxy- and txy- phase envelopesTo compute pxy-type phase envelopes, we use theget_binary_pxy()method. This method returns aXYDiagramstruct, which
holds the composition and pressure / temperature of each equilibrium phase.TheXYDiagramstruct has the attributeslle,l1veandl2ve, wherelleholds the composition and pressure / temperature of the Liquid 1 - Liquid 2 equilibrialle.x1is the composition of Liquid 1 (mole fraction of species 1)lle.x2is the composition of Liquid 2 (mole fraction of species 1)lle.p/lle.Tis the pressure / temperature along the phase boundaryl1veholds the composition and pressure / temperature of the Liquid 1 - Vapour equilibrial1ve.xis the composition of Liquid 1 (mole fraction of species 1)l1ve.yis the composition of the vapour (mole fraction of species 1)l1ve.p/l1ve.Tis the pressure / temperature along the phase boundaryl2veholds the composition and pressure / temperature of the Liquid 2 - Vapour equilibrial2ve.xis the composition of Liquid 2 (mole fraction of species 1)l2ve.yis the composition of the vapour (mole fraction of species 1)l2ve.p/l2ve.Tis the pressure / temperature along the phase boundaryWe get the phase diagram asfromthermopack.cpaimportSRK_CPAeos=SRK_CPA('NC6,H2O')# CPA-SRK eos for Hexane/water mixtureT=350pxy=eos.get_binary_pxy(T)# Returns a XYDiagram structprint(pxy)# Result:# XYDiagram object with attributes (name : description)# lle  : Liquid 1 - Liquid 2 Equilibrium# 	PxyEquilibrium object with attributes (description, name, value)# 		Type of equilibrium                   type : lle# 		Liquid 1 mole fraction, species 1     x1   : [4.278e-07 ... 4.145e-07], len(x1) = 457# 		Liquid 2 mole fraction, species 1     x2   : [9.969e-01 ... 9.974e-01], len(x2) = 457# 		Pressure                              p    : [1.648e+05 ... 1.500e+07], len(p) = 457## l1ve : Liquid 1 - Vapour Equilibrium# 	PxyEquilibrium object with attributes (description, name, value)# 		Type of equilibrium                   type : lve# 		Liquid mole fraction, species 1       x    : [4.278e-07 ... 2.197e-07], len(x) = 66# 		Vapour mole fraction, species 1       y    : [7.880e-01 ... 6.461e-01], len(y) = 66# 		Pressure                              p    : [1.648e+05 ... 1.000e+05], len(p) = 66## l2ve : Liquid 2 - Vapour Equilibrium# 	PxyEquilibrium object with attributes (description, name, value)# 		Type of equilibrium                   type : lve# 		Liquid mole fraction, species 1       x    : [9.969e-01 ... 1.000e+00], len(x) = 100# 		Vapour mole fraction, species 1       y    : [7.880e-01 ... 1.000e+00], len(y) = 100# 		Pressure                              p    : [1.648e+05 ... 1.289e+05], len(p) = 100For ease of use, theXYDiagramstruct is iterable, such that we can unpack it efficiently aslle, l1ve, l2ve = pxyNow, we can plot the phase diagram as# Continuedimportmatplotlib.pyplotasplt# Liquid-liquid phase boundaries# pxy.lle holds the composition and pressure of the liquid phasesplt.plot(pxy.lle.x1,pxy.lle.p,label='Liquid 1 composition')# lle.x1 is the mole fraction of component 1 (NC12) in Liquid 1 along the phase boundaryplt.plot(pxy.lle.x2,pxy.lle.p,label='Liquid 2 composition')# lle.x2 is the mole fraction of component 1 (NC12) in Liquid 2 along the phase boundary# Liquid 1-vapour phase boundaries# pxy.l2ve holds composition and pressure along the Liquid 1 - Vapour phase boundaryplt.plot(pxy.l1ve.x,pxy.l1ve.p,label='Liquid 1 bubble line')# l1ve.x is the mole fraction of component 1 (NC12) in Liquid 1 along the Liquid 1 - Vapour phase boundaryplt.plot(pxy.l1ve.y,pxy.l1ve.p,label='Liquid 1 dew line')# l1ve.y is the mole fraction of component 1 (NC12) in the Vapour phase along the Liquid 1 - Vapour phase boundary# Liquid 2-vapour phase boundaries# L2VE[2] is the pressure along the Liquid 2 - Vapour phase boundaryplt.plot(pxy.l2ve.x,pxy.l2ve.p,label='Liquid 2 bubble line')# l2ve.x is the mole fraction of component 1 (NC12) in Liquid 2 along the Liquid 2 - Vapour phase boundaryplt.plot(pxy.l2ve.y,pxy.l2ve.p,label='Liquid 2 dew line')# l2ve.y is the mole fraction of component 1 (NC12) in the Vapour phase along the Liquid 2 - Vapour phase boundaryplt.ylabel('Pressure [Pa]')# The third element in each tuple is the pressure along the phase boundaryplt.xlabel('Molar composition')The methodget_binary_txyworks in the same way, only replacing thepattribute withT, such that we can computep=1e5lle,l1ve,l2ve=eos.get_binary_txy(p)# Unpacking the XYDiagram# Liquid-liquid phase boundaries# l1ve holds the composition and pressure of Liquid 1 and Vapour along the phase boundaryplt.plot(l1ve.x,l1ve.T,label='Liquid 1 composition')# l1ve.x is the mole fraction of component 1 (NC12) in Liquid 1 along the phase boundaryplt.plot(l1ve.y,l1ve.T,label='Vapour composition')# l1ve.y is the mole fraction of component 1 (NC12) in Vapour along the phase boundary# ... etc ...In the same way as forv2.1.0, the arrays of values are set toNoneif an equilibrium is not found, such that we may need to check for the presence of an equilibrium before plotting.Dew- and bubble pointsWe can also compute the bubble-temperature, pressure etc. directly using the methodsbubble_temperature(p, z),bubble_pressure(T, z),dew_temperature(p, z)anddew_pressure(T, z), wherezis the composition of the mixture, aseos=cubic('CO2,C1','SRK')x=[0.5,0.5]# Total composition of the mixturep_dew,y_dew=eos.dew_pressure(250,x)# Calculates dew pressure and dew composition at 250 KT_dew,y_dew=eos.dew_temperature(1e5,x)# Calculates dew temperature and dew composition at 1 barp_bub,x_bub=eos.bubble_pressure(230,x)# Calculates bubble pressure and bubble composition at 230 KT_bub,x_bub=eos.bubble_temperature(1e5,x)# Calculates bubble temperature and bubble composition at 1 barIsolinesVarious isolines can be computed using the methodsget_isotherm,get_isobar,get_isentropeandget_isenthalp.
In the following code snippet, the default values of the keyword arguments are indicated.fromthermopack.pcsaftimportpcsafteos=pcsaft('NC6,NC12')x=[0.2,0.8]# Calculate pressure, specific volume, specific entropy and specific enthalpy along the isotherm at 300 K# from p = minimum_pressure to p = maximum_pressure. Compute at most nmax points.p_iso_T,v_iso_T,s_iso_T,h_iso_T=eos.get_isotherm(300,x,minimum_pressure=1e5,maximum_pressure=1.5e7,nmax=100)# Calculate temperature, specific volume, specific entropy and specific enthalpy along the isobar at 1 bar# from T = minimum_temperature to T = maximum_temperature. Compute at most nmax points.T_iso_p,v_iso_p,s_iso_p,h_iso_p=eos.get_isobar(1e5,x,minimum_temperature=200,maximum_temperature=500,nmax=100)# Calculate temperature, pressure, specific volume and specific entropy along the isenthalp at 1 kJ / mol# Start at the upper of (minimum_pressure, minimum_temperature)# End at the lower of (maximum_pressure, maximum_temperature)T_iso_h,p_iso_h,v_iso_h,s_iso_h=eos.get_isenthalp(1e3,x,minimum_pressure=1e5,maximum_pressure=1.5e7,minimum_temperature=200,maximum_temperature=500,nmax=100)# Calculate temperature, pressure, specific volume and specific enthalpy along the isentrope at 5 J / mol K# Start at the upper of (minimum_pressure, minimum_temperature)# End at the lower of (maximum_pressure, maximum_temperature)T_iso_s,p_iso_s,v_iso_s,h_iso_s=eos.get_isentrope(5,x,minimum_pressure=1e5,maximum_pressure=1.5e7,minimum_temperature=200,maximum_temperature=500,nmax=100)In addition to these, we can trace isentropes and isotherms in the metastable region using the methodsmap_meta_isentropeandmap_meta_isotherm.Critical pointThermopack has a critical point solver, which is called aseos=saftvrqmie('HE,NE')# Use FH-corrected Mie potentials for Helium calculations!n=[5,10]Tc,Vc,pc=eos.critical(n)# Compute the critical temperature, pressure and volume given mole numbersvc=Vc/sum(n)# Critical specific volume computed from critical volume and mole numbers.The solver accepts initial guesses for the critical values through thekwargstemp, andv. The error tolerance
can be set via thetolkwarg(default istol=1e-7).To compute only the critical pressure, temperature or molar volume, we can use the methods [critical_pressure]Metastable regionMethods for computing properties in the metastable region are found in thedocumentation for stability interfaces.We can trace the spinodal curve asimportmatplotlib.pyplotaspltfromthermopack.tcPRimporttcPReos=tcPR('CO2,C1')z=[0.2,0.8]Ts,vs,ps=eos.spinodal(z)# Trace the spinodalTe,pe,ve=eos.get_envelope_twophase(1e3,z,calc_v=True)# Trace the phase envelopeplt.plot(Ts,ps,label='Spinodal')plt.plot(Te,pe,label='Phase envelope')plt.xlabel('T [K]')plt.ylabel('p [Pa]')plt.show()plt.plot(1/vs,Ts,label='Spinodal')plt.plot(1/ve,Te,label='Phase envelope')plt.xlabel(r'$\rho$ [mol m$^{-3}$]')plt.ylabel('T [K]')plt.show()We can also find specific points on the spinodal using thespinodal_pointmethod.For density solvers that can be used in the metastable region, refer to thedocumentation for stability interfaces.For methods to trace isolines in the metastable region, refer to thesection on isolines.More advanced usageInteraction parametersIn thermopack we're able to both set and get a wide array of coefficients and parameters depending on the models we are utilizing.Cubic equations of stateSetting and getting the attractive energy interaction parameter $k_{ij}$ and co-volume interaction parameter $l_{ij}$Starting with the attractive energy interaction parameter (kij). The parameter can be set using the functionset_kijafter intialising the equation and state. The function requires that you first write in the number of the components and subsequently the new interaction parameter i.e. (component number 1, component number 2, new kij value). If we're curious as to what parameter the EOS is already using we can see this by using the functionget_kijwhich returns the value as a float given the component numbers as input i.e. (component number 1, component number 2).cs=cubic('CO2,N2',"SRK","Classic","Classic")#We set the interaction parameter to be -0.032cs.set_kij(1,2,-0.032)#We want to see what the interaction parameter is which returns that kij = -0.032kij=cs.get_kij(1,2)The procedure for setting and getting co-volume interaction parameters is analogous to the getting and setting of attractive energy parameters. Simply use the functionsset_lijandget_lijinstead.#We set the parameter to be -0.032cs.set_lij(1,2,-0.032)#We want to see what the parameter is which returns that lij = -0.032lij=cs.get_lij(1,2)The different property interfaces (TV-) (Tp-) and (TVp-)Property calculations in ThermoPack can be done either through theTV-interfaces, theTp-interfacesor theTVp-interfaces.The difference between the TV- and Tp- interface is only what variables the properties are computed as functions of, and what variables are held constant in the derivatives. TV-interface methods compute properties as functions of $(T, V, n)$, while Tp-interface methods compute properties as functions of $(T, p, n)$.TheTVp-interfacemethods on the other hand take $(T, V, n)$ as arguments, and evaluate derivativesas functions of $(T, p, n)$. To demonstrate with an example:importnumpyasnpfromthermopack.cubicimportcubiceos=cubic('O2,N2','PR')# PR EoS for O2/N2 mixtureT=300# Kelvinp=1e5# Pascalx=np.array([0.21,0.79])# Molar composition (of air)n_tot=10# Total number of molesn=n_tot*x# Vector of mole numbersv,=eos.specific_volume(T,p,x,eos.VAPPH)# Compute specific volume of vapour phaseV=v*n_tot# Total volume# Computing the TOTAL Enthalpy (J), given (T, V, n)# The differentials are computed for H = H(T, V, n), with# "subscripts" indicating the variables held constantH_tvn,dHdT_Vn,dHdn_TV=eos.enthalpy_tv(T,V,n,dhdt=True,dhdn=True)# Computing the SPECIFIC VAPOUR phase enthalpy (J / mol), given (T, p, n)# The differentials are computed for h_vap = h_vap(T, p, n), with the# "subscripts" indicating the variables held constanth_vap_tpn,dh_vap_dt_pn,dh_vap_dn_Tp=eos.enthalpy(T,p,n,eos.VAPPH,dhdt=True,dhdn=True)# Computing the SPECIFIC LIQUID phase enthalpy (J / mol), given (T, p, n)# The differentials are computed for h_liq = h_liq(T, p, n), with the# "subscripts" indicating the variables held constanth_liq_tpn,dh_liq_dt_pn,dh_liq_dn_Tp=eos.enthalpy(T,p,n,eos.LIQPH,dhdt=True,dhdn=True)# Computing the TOTAL Enthalpy (J), given (T, V, n)# NOTE : The differentials are computed for H = H(T, p, n)#        NOT for H = H(T, V, n)H_tpn,dHdt_pn,dHdn_Tp=eos.enthalpy_tvp(T,V,n,dhdt=True,dhdn=True)Besidesenthalpy_tvp, there are currently available TVp-interfaces forentropy_tvpandthermo_tvp(logarithm of fugacity coefficients).Component identifiersFluid name to fluid identifier mappingIn order to specify fluids in Thermopack you need to use fluid identifiers as shown in the table below. The 'SAFT-VR', 'PC-SAFT' and 'CPA' columns indicate which fluids SAFT-EoS and CPA parameters are available for.You may have to scroll right to view the whole table.Fluid nameCAS NumberFluid identifyerSAFT-VRPC-SAFTCPA1,1,1,2-Tetrafluoroethane811-97-2R134a1,1,1-Trifluoroethane420-46-2R143a1,1-Difluoroethane75-37-6R152a1,1-Difluoroethylene75-38-7R1132a1,2-Dichlorotetrafluoroethane76-14-2R1141,3-Butadiene106-99-013BD1-Butanol71-36-3BUT1OL✔✔1-Chloro-1,1,2,2-tetrafluoroethane354-25-6R124a1-Chloro-1,1-difluoroethane75-68-3R142b1-Hexanol111-27-3HEX1OL✔✔1-Pentanol71-41-0PENT1OL✔✔1-Propanol71-23-8PROP1OL✔✔2,3,3,3-Tetrafluoropropene754-12-1R1234yf2-Chloro-1,1,1,2-tetrafluoroethane2837-89-0R1242-Methylhexane591-76-42MHX3-Methylpentane96-14-03MPAcetone67-64-1ACETONE✔Acetylene74-86-2ACETYLENE✔Ammonia7664-41-7NH3✔✔✔Argon7440-37-1AR✔✔Benzene71-43-2BENZENE✔Butanal123-72-8BUTANAL✔Carbon dioxide124-38-9CO2✔✔✔Carbon monoxide630-08-0COCarbon tetrafluoride75-73-0R14Chlorine7782-50-5CL2✔Chlorodifluoromethane75-45-6R22Chloropentafluoroethane76-15-3R115Chlorotrifluoromethane75-72-9R13Chlorotrifluorosilane14049-36-6ClF3SiCyclohexane110-82-7CYCLOHEX✔Cyclopropane75-19-4C3_1Deuterium7782-39-0D2✔Di-methyl ether115-10-6DME✔Di-n-hexyl ether112-58-3S434Dichlorodifluoromethane75-71-8R12Dichlorofluoromethane75-43-4R21Difluoromethane75-10-5R32Dinitrogen tetroxide10544-72-6N2O4Equilibrium-hydrogen1333-74-0E-H2Ethane74-84-0C2✔✔Ethanol64-17-5ETOH✔✔✔Ethylbenzene100-41-4EBZNEthylene glycol107-21-1MEGEthylene74-85-1C2_1✔Helium-47440-59-7HE✔Hexafluoroethane76-16-4R116Hydrazine302-01-2N2H4✔Hydrogen peroxide7722-84-1H2O2Hydrogen sulfide7783-06-4H2S✔✔Hydrogen1333-74-0H2✔Isobutane75-28-5IC4✔Isopentane78-78-4IC5✔Krypton7439-90-9KR✔✔Lennard-jones_fluidLJF✔Methane74-82-8C1✔✔Methanol67-56-1MEOH✔✔✔Methyl fluoride593-53-3R41Methylcyclopentane96-37-7MTC5Neon7440-01-9NE✔Nitric oxide10102-43-9NONitrogen7727-37-9N2✔✔Nitrous oxide10024-97-2N2OOctafluoropropane76-19-7R218Ortho-hydrogen1333-74-0O-H2✔Oxygen7782-44-7O2✔✔Para-hydrogen1333-74-0P-H2✔Pentafluoroethane354-33-6R125Propadiene463-49-0ALLENEPropane74-98-6C3✔✔✔Propylene115-07-1PRLNPseudoXXXPSEUDOSulfur dioxide7446-09-5SO2Sulfur hexafluoride2551-62-4F6STetrafluoroethylene116-14-3R1114Tetrafluorohydrazine10036-47-2F4N2Toluene108-88-3TOLU✔Trans-1,3,3,3-tetrafluoropropene29118-24-9R1234zeTrichlorofluoromethane75-69-4R11Trifluoroamine oxide13847-65-9F3NOTrifluoromethane75-46-7R23Water7732-18H2O✔✔✔Xenon7440-63-3XE✔m-Xylene108-38-3MXYLn-Butane106-97-8NC4✔✔✔n-Decane124-18-5NC10✔✔✔n-Docosane629-97-0NC22✔✔n-Dodecane112-40-3NC12✔n-Eicosane112-95-8NC20✔✔n-Heneicosane629-94-7NC21✔n-Heptadecane629-78-7NC17✔n-Heptane142-82-5NC7✔✔✔n-Hexadecane544-76-3NC16✔n-Hexane110-54-3NC6✔✔✔n-Hydrogen1333-74-0N-H2n-Nonadecane629-92-5NC19✔n-Nonane111-84-2NC9✔✔✔n-Octadecane593-45-3NC18✔n-Octane111-65-9NC8✔✔✔n-Pentacosane629-99-2NC25✔n-Pentadecane629-62-9NC15✔✔n-Pentan109-66-0NC5✔✔✔n-Tetracosane646-31-1NC24✔n-Tetradecane629-59-4NC14✔n-Tricosane638-67-5NC23✔n-Tridecane629-50-5NC13✔n-Undecane1120-21-4NC11✔o-Xylene95-47-6OXYLp-Xylene106-42-3PXYL