Solution (source code)

= Solution

The logarithmic density term is the <barotropic fluid> energy for $p=c_s^2\rho$, rather than the thermodynamic heat content of an isolated gas. Define
$$
e(\rho)=c_s^2\ln(\rho/\rho_0),\qquad
E_h=\rho\left(\frac{v^2}{2}+\Phi+e\right),\qquad
E_B=\frac{B^2}{2\mu_0}.
$$
For any scalar $q$, the <continuity equation> implies $\partial_t(\rho q)+\partial_z(\rho wq)=\rho Dq$. Therefore $De=-c_s^2w'$, $D\Phi=wg$, and dotting the momentum equations with $\rho\mathbf v$ gives
$$
\partial_tE_h+\partial_z(wE_h)
=-\partial_z(wp)
+\frac{B_z}{\mu_0}(v_xB_x'+v_yB_y')
-wE_B'-a\rho v_xv_y.
$$
The <MHD induction equation> gives the complementary <magnetic energy> balance
$$
\partial_tE_B+\partial_z(wE_B)
=\frac{B_z}{\mu_0}(B_xv_x'+B_yv_y')
-\left(E_B-\frac{B_z^2}{\mu_0}\right)w'
+\frac{aB_xB_y}{\mu_0}.
$$
Adding these two identities, and collecting the product derivatives, yields the <barotropic magnetic energy equation>
$$
\boxed{\partial_tE+\partial_zF=S,\qquad
F=w\left(E+p+\frac{B^2}{2\mu_0}\right)
-\frac{B_z}{\mu_0}(\mathbf v\cdot\mathbf B),\qquad
S=a\left(\frac{B_xB_y}{\mu_0}-\rho v_xv_y\right).}
$$
Here $E=E_h+E_B$. The two stress terms in $S$ describe <magnetohydrodynamic shear work>: the maintained background <shear flow> can supply energy to, or remove energy from, the perturbation flow and <magnetic field>. The sign depends on the off-diagonal total stress; this is why the energy excluding the background <shear flow> is not generally conserved. Changing $\rho_0$ merely adds a constant multiple of the conserved density to $E$ and the corresponding mass flux to $F$, leaving $S$ unchanged.