Jacobians to get derivatives in terms of $\tau$ and $\delta$

Based on the paper "On the Use of Jacobians in Thermodynamics" of Benjamin Carroll, Journal Chemical Education, 1965

Express a partial derivative as $$\left(\frac{\partial T}{\partial P}\right)_H = \frac{\partial(T,H)}{\partial(P,H)} = \left| \begin{array}{cc} \left(\frac{\partial T}{\partial P}\right)_H & \left(\frac{\partial H}{\partial P}\right)_H \\ \left(\frac{\partial T}{\partial H}\right)_P & \left(\frac{\partial H}{\partial H}\right)_P \end{array} \right| = \left(\frac{\partial T}{\partial P}\right)_H\left(\frac{\partial H}{\partial H}\right)_P-\left(\frac{\partial T}{\partial H}\right)_P\left(\frac{\partial H}{\partial P}\right)_H$$

$\left(\frac{\partial H}{\partial P}\right)_H = 0$ and $\left(\frac{\partial H}{\partial H}\right)_P = 1$

If there is a common term and it is in the same column, it is the thing held constant (see above).

If there is a common term and it is in the opposite column, it is the thing held constant, but you need to add a sign change:

$$ \frac{\partial(T,H)}{\partial(H,P)} = -\left(\frac{\partial T}{\partial P}\right)_H$$

You can do a change of variables by applying it to numerator and denominator

$$ \left(\frac{\partial T}{\partial P}\right)_H = \frac{\partial(T,H)}{\partial(P,H)} = \frac{\frac{\partial(T,H)}{\partial(x,y)}}{\frac{\partial(P,H)}{\partial(x,y)}}$$

Where... (drumroll please)... we can use $\tau$ and $\delta$ as the independent variables $x$ and $y$. So we can express the Jacobian in terms of $\tau$ and $\delta$ directly.

$$ \left(\frac{\partial T}{\partial P}\right)_h = \frac{\partial(T,h)}{\partial(P,h)} = \frac{\displaystyle\frac{\partial(T,h)}{\partial(\tau,\delta)}}{\displaystyle\frac{\partial(P,h)}{\partial(\tau,\delta)}} = \displaystyle\frac{\left| \begin{array}{cc} \left(\frac{\partial T}{\partial \tau}\right)_\delta & \left(\frac{\partial h}{\partial \tau}\right)_\delta \\ \left(\frac{\partial T}{\partial \delta}\right)_\tau & \left(\frac{\partial h}{\partial \delta}\right)_\tau \end{array} \right|}{\left| \begin{array}{cc} \left(\frac{\partial P}{\partial \tau}\right)_\delta & \left(\frac{\partial h}{\partial \tau}\right)_\delta \\ \left(\frac{\partial P}{\partial \delta}\right)_\tau & \left(\frac{\partial h}{\partial \delta}\right)_\tau \end{array} \right|} = \frac{\left(\frac{\partial T}{\partial \tau}\right)_\delta\left(\frac{\partial h}{\partial \delta}\right)_\tau-\left(\frac{\partial T}{\partial \delta}\right)_\tau\left(\frac{\partial h}{\partial \tau}\right)_\delta}{\left(\frac{\partial P}{\partial \tau}\right)_\delta\left(\frac{\partial h}{\partial \delta}\right)_\tau-\left(\frac{\partial P}{\partial \delta}\right)_\tau\left(\frac{\partial h}{\partial \tau}\right)_\delta}$$

Or more generally

$$ \left(\frac{\partial A}{\partial B}\right)_C = \frac{\left(\frac{\partial A}{\partial \tau}\right)_\delta\left(\frac{\partial C}{\partial \delta}\right)_\tau-\left(\frac{\partial A}{\partial \delta}\right)_\tau\left(\frac{\partial C}{\partial \tau}\right)_\delta}{\left(\frac{\partial B}{\partial \tau}\right)_\delta\left(\frac{\partial C}{\partial \delta}\right)_\tau-\left(\frac{\partial B}{\partial \delta}\right)_\tau\left(\frac{\partial C}{\partial \tau}\right)_\delta} = \frac{N}{D}$$

The duplicated derivatives should be cached for speed. Anyway, they will be cached since we will use an AbstractState instance. Just need to calculate all partial derivatives of fundamental variables (T,p,$\rho$,h,u,s) with respect to $\tau$ and $\delta$. 12 derivatives, all easy to numerically validate and 2 are trivial ($dT/d\tau$ and $d\rho/d\delta$)

As also derived in "Partial derivatives of thermodynamic state properties for dynamic simulation", Matthis Thorade & Ali Saadat., 2013, DOI 10.1007/s12665-013-2394-z

Second partial

$$\left(\frac{\partial N}{\partial \delta}\right)_{\tau} = \left(\frac{\partial A}{\partial \tau}\right)_\delta\left(\frac{\partial^2 C}{\partial \delta^2}\right)_{\tau}+\left(\frac{\partial^2 A}{\partial \tau\partial\delta}\right)\left(\frac{\partial C}{\partial \delta}\right)_{\tau}-\left(\frac{\partial A}{\partial \delta}\right)_\tau\left(\frac{\partial^2 C}{\partial \tau\partial\delta}\right)-\left(\frac{\partial^2 A}{\partial \delta^2}\right)_{\tau}\left(\frac{\partial C}{\partial \tau}\right)_\delta$$$$\left(\frac{\partial D}{\partial \delta}\right)_{\tau} = \left(\frac{\partial B}{\partial \tau}\right)_\delta\left(\frac{\partial^2 C}{\partial \delta^2}\right)_{\tau}+\left(\frac{\partial^2 B}{\partial \tau\partial\delta}\right)\left(\frac{\partial C}{\partial \delta}\right)_{\tau}-\left(\frac{\partial B}{\partial \delta}\right)_\tau\left(\frac{\partial^2 C}{\partial \tau\partial\delta}\right)-\left(\frac{\partial^2 B}{\partial \delta^2}\right)_{\tau}\left(\frac{\partial C}{\partial \tau}\right)_\delta$$
$$\left(\frac{\partial N}{\partial \tau}\right)_{\delta} = \left(\frac{\partial A}{\partial \tau}\right)_\delta\left(\frac{\partial^2 C}{\partial \delta\partial\tau}\right)+\left(\frac{\partial^2 A}{\partial \tau^2}\right)_\delta\left(\frac{\partial C}{\partial \delta}\right)_{\tau}-\left(\frac{\partial A}{\partial \delta}\right)_\tau\left(\frac{\partial^2 C}{\partial \tau^2}\right)_\delta-\left(\frac{\partial^2 A}{\partial \delta\partial\tau}\right)\left(\frac{\partial C}{\partial \tau}\right)_\delta$$$$\left(\frac{\partial D}{\partial \tau}\right)_{\delta} = \left(\frac{\partial B}{\partial \tau}\right)_\delta\left(\frac{\partial^2 C}{\partial \delta\partial\tau}\right)+\left(\frac{\partial^2 B}{\partial \tau^2}\right)_\delta\left(\frac{\partial C}{\partial \delta}\right)_{\tau}-\left(\frac{\partial B}{\partial \delta}\right)_\tau\left(\frac{\partial^2 C}{\partial \tau^2}\right)_\delta-\left(\frac{\partial^2 B}{\partial \delta\partial\tau}\right)\left(\frac{\partial C}{\partial \tau}\right)_\delta$$
$$\frac{\partial}{\partial \tau}\left( \left(\frac{\partial A}{\partial B}\right)_C \right)_\delta = \frac{D\left(\frac{\partial N}{\partial \tau}\right)_{\delta}-N\left(\frac{\partial D}{\partial \tau}\right)_{\delta}}{D^2}$$$$\frac{\partial}{\partial \delta}\left( \left(\frac{\partial A}{\partial B}\right)_C \right)_\tau = \frac{D\left(\frac{\partial N}{\partial \delta}\right)_{\tau}-N\left(\frac{\partial D}{\partial \delta}\right)_{\tau}}{D^2}$$
$$ \frac{\partial}{\partial D}\left(\left(\frac{\partial A}{\partial B}\right)_C\right)_E = \frac{\frac{\partial}{\partial \tau}\left( \left(\frac{\partial A}{\partial B}\right)_C \right)_\delta\left(\frac{\partial E}{\partial \delta}\right)_\tau-\frac{\partial}{\partial \delta}\left(\left(\frac{\partial A}{\partial B}\right)_C\right)_\tau\left(\frac{\partial E}{\partial \tau}\right)_\delta}{\left(\frac{\partial D}{\partial \tau}\right)_\delta\left(\frac{\partial E}{\partial \delta}\right)_\tau-\left(\frac{\partial D}{\partial \delta}\right)_\tau\left(\frac{\partial E}{\partial \tau}\right)_\delta}$$

Converting second derivatives w.r.t. T and rho to tau and delta

$$\frac{\partial^2 p}{\partial \rho^2} = \frac{\partial }{\partial \rho}\left(\frac{\partial p}{\partial \rho}\right) = \frac{\partial }{\partial \rho}\left(\frac{\partial \delta}{\partial \rho}\frac{\partial p}{\partial \delta}\right) = \frac{\partial \delta}{\partial \rho}\frac{\partial^2 p}{\partial \delta^2} + \frac{\partial^2 \delta}{\partial \rho^2}\frac{\partial p}{\partial \delta}$$

Now to solve for $$\frac{\partial^2 p}{\partial \delta^2}$$ we can re-arrange to get

$$\frac{\partial^2 p}{\partial \delta^2} = \frac{\frac{\partial^2 p}{\partial \rho^2} -\frac{\partial^2 \delta}{\partial \rho^2}\frac{\partial p}{\partial \delta}}{\frac{\partial \delta}{\partial \rho}} $$

In [ ]: