Skip to content
Snippets Groups Projects
Commit 09ba625b authored by Ian Bell's avatar Ian Bell
Browse files

Fix comment

parent b3fd35eb
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:1afc4517 tags: %% Cell type:markdown id:1afc4517 tags:
# Thermodynamic Derivatives # Thermodynamic Derivatives
## Helmholtz energy derivatives ## Helmholtz energy derivatives
Thermodynamic derivatives are at the very heart of teqp. All models are defined in the form $\alpha^r(T, \rho, z)$, where $\rho$ is the molar density, and z are mole fractions. There are exceptions for models for which the independent variables are in simulation units (Lennard-Jones and its ilk). Thermodynamic derivatives are at the very heart of teqp. All models are defined in the form $\alpha^r(T, \rho, z)$, where $\rho$ is the molar density, and z are mole fractions. There are exceptions for models for which the independent variables are in simulation units (Lennard-Jones and its ilk).
Thereofore, to obtain the residual pressure, it is obtained as a derivative: Thereofore, to obtain the residual pressure, it is obtained as a derivative:
$$ p^r = \rho R T \left( \rho \left(\frac{\partial \alpha^r}{\partial \rho}\right)_{T}\right)$$ $$ p^r = \rho R T \left( \rho \left(\frac{\partial \alpha^r}{\partial \rho}\right)_{T}\right)$$
and other residual thermodynamic properties are defined likewise. and other residual thermodynamic properties are defined likewise.
We can define the concise derivative We can define the concise derivative
$$ \Lambda^r_{xy} = (1/T)^x(\rho)^y\left(\frac{\partial^{x+y}(\alpha^r)}{\partial (1/T)^x\partial \rho^y}\right)$$ $$ \Lambda^r_{xy} = (1/T)^x(\rho)^y\left(\frac{\partial^{x+y}(\alpha^r)}{\partial (1/T)^x\partial \rho^y}\right)$$
so we can re-write the derivative above as so we can re-write the derivative above as
$$ p^r = \rho R T \Lambda^r_{01}$$ $$ p^r = \rho R T \Lambda^r_{01}$$
Similar definitions apply for all the other residual thermodynamic properties Similar definitions apply for all the other residual thermodynamic properties
%% Cell type:code id:ca35cc29 tags: %% Cell type:code id:ca35cc29 tags:
``` python ``` python
import teqp import teqp
import numpy as np import numpy as np
``` ```
%% Cell type:code id:8d254c40 tags: %% Cell type:code id:8d254c40 tags:
``` python ``` python
Tc_K = [300] Tc_K = [300]
pc_Pa = [4e6] pc_Pa = [4e6]
acentric = [0.01] acentric = [0.01]
model = teqp.canonical_PR(Tc_K, pc_Pa, acentric) model = teqp.canonical_PR(Tc_K, pc_Pa, acentric)
``` ```
%% Cell type:code id:49ee3453 tags: %% Cell type:code id:49ee3453 tags:
``` python ``` python
z = np.array([1.0]) z = np.array([1.0])
model.get_Ar01(300,300,z) model.get_Ar01(300,300,z)
``` ```
%% Output %% Output
-0.06836660379313926 -0.06836660379313926
%% Cell type:markdown id:498a2350 tags: %% Cell type:markdown id:498a2350 tags:
And there are additional methods to obtain all the derivatives up to a given order: And there are additional methods to obtain all the derivatives up to a given order:
%% Cell type:code id:3ae755e1 tags: %% Cell type:code id:3ae755e1 tags:
``` python ``` python
model.get_Ar06n(300,300,z) # derivatives 00, 01, 02, ... 06 model.get_Ar06n(300,300,z) # derivatives 00, 01, 02, ... 06
``` ```
%% Output %% Output
[-0.06966138343515413, [-0.06966138343515413,
-0.06836660379313926, -0.06836660379313926,
0.0025357822532378147, 0.0025357822532378147,
-0.00015701162203571184, -0.00015701162203571184,
1.6818628788290574e-05, 1.6818628788290574e-05,
-2.2305940927885907e-06, -2.2305940927885907e-06,
3.8259258513417917e-07] 3.8259258513417917e-07]
%% Cell type:markdown id:cd644a3e tags: %% Cell type:markdown id:cd644a3e tags:
But more derivatives are slower than fewer: But more derivatives are slower than fewer:
%% Cell type:code id:4e0609ae tags: %% Cell type:code id:4e0609ae tags:
``` python ``` python
%timeit model.get_Ar01(300,300,z) %timeit model.get_Ar01(300,300,z)
%timeit model.get_Ar04n(300,300,z) %timeit model.get_Ar04n(300,300,z)
``` ```
%% Output %% Output
1.9 µs ± 38.5 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each) 1.9 µs ± 38.5 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
2.07 µs ± 24.8 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each) 2.07 µs ± 24.8 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
%% Cell type:markdown id:d05e9070 tags: %% Cell type:markdown id:d05e9070 tags:
Note: calling overhead is usually on the order of 1 microsecond Note: calling overhead is usually on the order of 1 microsecond
%% Cell type:markdown id:502e9830 tags: %% Cell type:markdown id:502e9830 tags:
## Virial coefficients ## Virial coefficients
Virial coefficients represent the thermodynamics of the interaction of two-, three-, ... bodies interacting with each other. They can be obtained rigorously if the potential energy surface of interaction is fully known. In general, such a surface can only be constructed for small rigid molecules. Many simple thermodynamic models do a poor job of predicting the thermodynamics captured by the virial coefficients. Virial coefficients represent the thermodynamics of the interaction of two-, three-, ... bodies interacting with each other. They can be obtained rigorously if the potential energy surface of interaction is fully known. In general, such a surface can only be constructed for small rigid molecules. Many simple thermodynamic models do a poor job of predicting the thermodynamics captured by the virial coefficients.
The i-th virial coefficient is defined by The i-th virial coefficient is defined by
$$ $$
B_i = \frac{(\alpha^r)^{(i-1)}}{(i-2)!} B_i = \frac{(\alpha^r)^{(i-1)}}{(i-2)!}
$$ $$
with the concise derivative term with the concise derivative term
$$ $$
(\alpha^r)^{(i)} = \lim_{\rho \to 0} \left(\frac{\partial^{i}\alpha^r}{\partial \rho^{i}}\right)_{T,\vec{x}} (\alpha^r)^{(i)} = \lim_{\rho \to 0} \left(\frac{\partial^{i}\alpha^r}{\partial \rho^{i}}\right)_{T,\vec{x}}
$$ $$
teqp supports the virial coefficient directly, there is the ``get_B2vir`` method for the second virial coefficient: teqp supports the virial coefficient directly, there is the ``get_B2vir`` method for the second virial coefficient:
%% Cell type:code id:720e120c tags: %% Cell type:code id:720e120c tags:
``` python ``` python
model.get_B2vir(300, z) model.get_B2vir(300, z)
``` ```
%% Output %% Output
-0.00023661263734465424 -0.00023661263734465424
%% Cell type:markdown id:2fba4369 tags: %% Cell type:markdown id:2fba4369 tags:
And the ``get_Bnvir`` method that allows for the calculation of higher virial coefficients: And the ``get_Bnvir`` method that allows for the calculation of higher virial coefficients:
%% Cell type:code id:92d01992 tags: %% Cell type:code id:92d01992 tags:
``` python ``` python
model.get_Bnvir(7, 300, z) model.get_Bnvir(7, 300, z)
``` ```
%% Output %% Output
{2: -0.0002366126373446542, {2: -0.0002366126373446542,
3: 3.001768410777936e-08, 3: 3.001768410777936e-08,
4: -3.2409760373816355e-12, 4: -3.2409760373816355e-12,
5: 3.9617816466337214e-16, 5: 3.9617816466337214e-16,
6: -4.552923983836698e-20, 6: -4.552923983836698e-20,
7: 5.3759278511184914e-24} 7: 5.3759278511184914e-24}
%% Cell type:markdown id:d50998b1 tags: %% Cell type:markdown id:d50998b1 tags:
The ``get_Bnvir`` method was implemented because when doing automatic differentiation, all the intermediate derivatives are also retained. The ``get_Bnvir`` method was implemented because when doing automatic differentiation, all the intermediate derivatives are also retained.
There is also a method to calculate temperature derivatives of a given virial coefficient There is also a method to calculate temperature derivatives of a given virial coefficient
%% Cell type:code id:fa4ff386 tags: %% Cell type:code id:fa4ff386 tags:
``` python ``` python
model.get_dmBnvirdTm(2, 3, 300, z) # third temperature derivative of the model.get_dmBnvirdTm(2, 3, 300, z) # third temperature derivative of the second virial coefficient
``` ```
%% Output %% Output
1.0095625628421257e-10 1.0095625628421257e-10
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment