"When it comes to mixture thermodynamics, as soon as you add another component to a pure component to form a binary mixture, the complexity of the thermodynamics entirely changes. For that reason, mixture iterative calculations for mixtures are orders of magnitude more difficult to carry out. Asymmetric mixtures can do all sorts of interesting things that are entirely unlike those of pure fluids, and the algorithms are therefore much, much more complicated. Formulating phase equilibrium problems for pure fluids is not much more complicated, but the most challenging aspect is to obtain good guess values from which to start an iterative routine\n",
"When it comes to mixture thermodynamics, as soon as you add another component to a pure component to form a binary mixture, the complexity of the thermodynamics entirely changes. For that reason, mixture iterative calculations for mixtures are orders of magnitude more difficult to carry out. Asymmetric mixtures can do all sorts of interesting things that are entirely unlike those of pure fluids, and the algorithms are therefore much, much more complicated. Formulating phase equilibrium problems is not much more complicated than for pure fluids, but the most challenging aspect is to obtain good guess values from which to start an iterative routine, and the difficulty of this problem increases with the complexity of the mixture thermodynamics.\n",
"\n",
"Ulrich Deiters and Ian Bell have developed a number of algorithms for tracing phase equilibrium solutions as the solution of ordinary differential equations rather than carrying out iterative routines for a given state point. The advantage of the tracing calculations is that they can be often initiated at a state point that is entirely known, perhaps the pure fluid endpoint for a subcritical isotherm."
"Ulrich Deiters and Ian Bell have developed a number of algorithms for tracing phase equilibrium solutions as the solution of ordinary differential equations rather than carrying out iterative routines for a given state point. The advantage of the tracing calculations is that they can often be initiated at a state point that is entirely known, for instance the pure fluid endpoint for a subcritical isotherm or isobar."
"As of version 0.10.0, isobar tracing has been added to ``teqp``. It operates in fundamentally the same fashion as the isotherm tracing and the same recommendations about starting at a pure fluid apply"
]
},
{
"cell_type": "raw",
"id": "81eacaf0",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
"source": [
"The tracer function class is here: :py:meth:`trace_VLE_isobar_binary <teqp.teqp.trace_VLE_isobar_binary>`"
* Tracing along iso-curves (constant temperature, etc.) powered by the isochoric thermodynamics formalism
%% Cell type:code id:c0b4e863 tags:
``` python
importteqp
importnumpyasnp
importpandas
importmatplotlib.pyplotasplt
teqp.__version__
```
%% Output
'0.9.4.dev0'
%% Cell type:markdown id:e57e532b tags:
## Iterative Phase Equilibria
%% Cell type:markdown id:1baf38e1 tags:
### Pure fluid
For a pure fluid, phase equilibrium between two phases is defined by equating the pressures and Gibbs energies in the two phases. This represents a 2D non-linear rootfinding problem. Newton's method can be used for the rootfinding, and in teqp, automatic differentiation is used to obtain the necessary Jacobian matrix so the implementation is quite efficient.
The method requires guess values, which are the densities of the liquid and vapor densities. In some cases, ancillary or superancillary equations have been developed which provide curves of guess densities as a function of temperature.
For a pure fluid, you can use the ``pure_VLE_T`` method to carry out the iteration.
%% Cell type:raw id:f0ca0b22 tags:
The Python method is here: :py:meth:`pure_VLE_T <teqp.teqp.pure_VLE_T>`
%% Cell type:code id:2674227c tags:
``` python
# Instantiate the model
model=teqp.canonical_PR([300],[4e6],[0.1])
T=250# [K], Temperature to be used
# Here we use the superancillary to get guess values (actually these are more
# accurate than the results we will obtain from iteration!)
rhoL0,rhoV0=model.superanc_rhoLV(T)
display('guess:',[rhoL0,rhoV0])
# Carry out the iteration, return the liquid and vapor densities
# The guess values are perturbed to make sure the iteration is actually
# changing the values
teqp.pure_VLE_T(model,T,rhoL0*0.98,rhoV0*1.02,10)
```
%% Output
array([12735.31117341, 752.40823031])
%% Cell type:markdown id:f8805ae1 tags:
### Binary Mixture
%% Cell type:markdown id:76bccf19 tags:
For a binary mixture, the approach is roughly similar to that of a pure fluid. The pressure is equated between phases, and the chemical potentials of each component in each phase are forced to be the same.
Again, the user is required to provide guess values, in this case molar concentrations in each phase, and a Newton method is implemented to solve for the phase equilibrium. The analytical Jacobian is obtained from automatic differentiation.
The ``mix_VLE_Tx`` function is the binary mixture analog to ``pure_VLE_T`` for pure fluids.
%% Cell type:raw id:eef189fd tags:
The Python method is here: :py:meth:`mix_VLE_Tx <teqp.teqp.mix_VLE_Tx>`
You can (and should) check the value of the return code to make sure the iteration succeeded. Do not rely on the numerical value of the enumerated return codes!
%% Cell type:markdown id:f4e3f914 tags:
# Tracing
# Tracing (isobars and isotherms)
When it comes to mixture thermodynamics, as soon as you add another component to a pure component to form a binary mixture, the complexity of the thermodynamics entirely changes. For that reason, mixture iterative calculations for mixtures are orders of magnitude more difficult to carry out. Asymmetric mixtures can do all sorts of interesting things that are entirely unlike those of pure fluids, and the algorithms are therefore much, much more complicated. Formulating phase equilibrium problems for pure fluids is not much more complicated, but the most challenging aspect is to obtain good guess values from which to start an iterative routine
When it comes to mixture thermodynamics, as soon as you add another component to a pure component to form a binary mixture, the complexity of the thermodynamics entirely changes. For that reason, mixture iterative calculations for mixtures are orders of magnitude more difficult to carry out. Asymmetric mixtures can do all sorts of interesting things that are entirely unlike those of pure fluids, and the algorithms are therefore much, much more complicated. Formulating phase equilibrium problems is not much more complicated than for pure fluids, but the most challenging aspect is to obtain good guess values from which to start an iterative routine, and the difficulty of this problem increases with the complexity of the mixture thermodynamics.
Ulrich Deiters and Ian Bell have developed a number of algorithms for tracing phase equilibrium solutions as the solution of ordinary differential equations rather than carrying out iterative routines for a given state point. The advantage of the tracing calculations is that they can be often initiated at a state point that is entirely known, perhaps the pure fluid endpoint for a subcritical isotherm.
Ulrich Deiters and Ian Bell have developed a number of algorithms for tracing phase equilibrium solutions as the solution of ordinary differential equations rather than carrying out iterative routines for a given state point. The advantage of the tracing calculations is that they can often be initiated at a state point that is entirely known, for instance the pure fluid endpoint for a subcritical isotherm or isobar.
%% Cell type:raw id:e0097771 tags:
The Python method is here: :py:meth:`trace_VLE_isotherm_binary <teqp.teqp.trace_VLE_isotherm_binary>`
%% Cell type:markdown id:63902dba tags:
The C++ implementation returns a string in JSON format, which can be conveniently operated upon, for instance after converting the returned data structure to a ``pandas.DataFrame``. A simple example of plotting a subcritical isotherm for a "boring" mixture is presented here:
You can also provide an optional set of flags to the function to control other behaviors of the function, and switch between simple Euler and adaptive RK45 integration (the default)
%% Cell type:raw id:264c5123 tags:
The options class is here: :py:meth:`TVLEOptions <teqp.teqp.TVLEOptions>`
%% Cell type:markdown id:d4193110 tags:
Supercritical isotherms should work approximately in the same manner
Supercritical isotherms work approximately in the same manner
As of version 0.10.0, isobar tracing has been added to ``teqp``. It operates in fundamentally the same fashion as the isotherm tracing and the same recommendations about starting at a pure fluid apply
%% Cell type:raw id:81eacaf0 tags:
The tracer function class is here: :py:meth:`trace_VLE_isobar_binary <teqp.teqp.trace_VLE_isobar_binary>`