In :
import sympy as sp
from lbmpy.chapman_enskog import ChapmanEnskogAnalysis
from lbmpy.creationfunctions import create_lb_method
sp.init_printing()


# Demo: Automatic Chapman Enskog Analysis¶

First, we create a SRT lattice Boltzmann method. It is defined as the set of moments, together with one relaxation rate per moment.

In :
method = create_lb_method(method='trt', stencil='D3Q19', compressible=False)
method

Out:
Moment Eq. Value Relaxation Rate
$1$ $\rho$ $\omega_{0}$
$x$ $u_{0}$ $\omega_{1}$
$y$ $u_{1}$ $\omega_{1}$
$z$ $u_{2}$ $\omega_{1}$
$x^{2}$ $\frac{\rho}{3} + u_{0}^{2}$ $\omega_{0}$
$y^{2}$ $\frac{\rho}{3} + u_{1}^{2}$ $\omega_{0}$
$z^{2}$ $\frac{\rho}{3} + u_{2}^{2}$ $\omega_{0}$
$x y$ $u_{0} u_{1}$ $\omega_{0}$
$x z$ $u_{0} u_{2}$ $\omega_{0}$
$y z$ $u_{1} u_{2}$ $\omega_{0}$
$x^{2} y$ $\frac{u_{1}}{3}$ $\omega_{1}$
$x^{2} z$ $\frac{u_{2}}{3}$ $\omega_{1}$
$x y^{2}$ $\frac{u_{0}}{3}$ $\omega_{1}$
$x z^{2}$ $\frac{u_{0}}{3}$ $\omega_{1}$
$y^{2} z$ $\frac{u_{2}}{3}$ $\omega_{1}$
$y z^{2}$ $\frac{u_{1}}{3}$ $\omega_{1}$
$x^{2} y^{2}$ $\frac{\rho}{9} + \frac{u_{0}^{2}}{3} + \frac{u_{1}^{2}}{3}$ $\omega_{0}$
$x^{2} z^{2}$ $\frac{\rho}{9} + \frac{u_{0}^{2}}{3} + \frac{u_{2}^{2}}{3}$ $\omega_{0}$
$y^{2} z^{2}$ $\frac{\rho}{9} + \frac{u_{1}^{2}}{3} + \frac{u_{2}^{2}}{3}$ $\omega_{0}$

Next, the Chapman Enskog analysis object is created. This may take a while...

In :
analysis = ChapmanEnskogAnalysis(method)


This object now information about the method, e.g. the relation of relaxation rate to viscosities, if the method approximates the compressible or incompressible continuity equation ...

In :
analysis.compressible

Out:
False
In :
analysis.pressure_equation

Out:
$$\left [ \frac{\rho}{3}\right ]$$
In :
analysis.get_kinematic_viscosity()

Out:
$$- \frac{\omega_{0} - 2}{6 \omega_{0}}$$
In :
analysis.get_bulk_viscosity()

Out:
$$- \frac{1}{9} + \frac{2}{9 \omega_{0}}$$

But also details of the analysis are available:

In :
sp.Matrix(analysis.get_macroscopic_equations())

Out:
$$\left[\begin{matrix}{\partial_{t} \rho} + {\partial_{0} u_{0}} + {\partial_{1} u_{1}} + {\partial_{2} u_{2}}\\- \frac{\epsilon \omega_{0}}{2} {\partial_{2} {\Pi_{02}^{(1)}}} - \frac{\epsilon \omega_{0}}{2} {\partial_{1} {\Pi_{01}^{(1)}}} - \frac{\epsilon \omega_{0}}{2} {\partial_{0} {\Pi_{00}^{(1)}}} + \epsilon {\partial_{2} {\Pi_{02}^{(1)}}} + \epsilon {\partial_{1} {\Pi_{01}^{(1)}}} + \epsilon {\partial_{0} {\Pi_{00}^{(1)}}} + \frac{{\partial_{0} \rho}}{3} + {\partial_{t} u_{0}} + {\partial_{0} (u_{0}^{2}) } + {\partial_{1} (u_{0} u_{1}) } + {\partial_{2} (u_{0} u_{2}) }\\- \frac{\epsilon \omega_{0}}{2} {\partial_{2} {\Pi_{12}^{(1)}}} - \frac{\epsilon \omega_{0}}{2} {\partial_{1} {\Pi_{11}^{(1)}}} - \frac{\epsilon \omega_{0}}{2} {\partial_{0} {\Pi_{01}^{(1)}}} + \epsilon {\partial_{2} {\Pi_{12}^{(1)}}} + \epsilon {\partial_{1} {\Pi_{11}^{(1)}}} + \epsilon {\partial_{0} {\Pi_{01}^{(1)}}} + \frac{{\partial_{1} \rho}}{3} + {\partial_{t} u_{1}} + {\partial_{1} (u_{1}^{2}) } + {\partial_{0} (u_{0} u_{1}) } + {\partial_{2} (u_{1} u_{2}) }\\- \frac{\epsilon \omega_{0}}{2} {\partial_{2} {\Pi_{22}^{(1)}}} - \frac{\epsilon \omega_{0}}{2} {\partial_{1} {\Pi_{12}^{(1)}}} - \frac{\epsilon \omega_{0}}{2} {\partial_{0} {\Pi_{02}^{(1)}}} + \epsilon {\partial_{2} {\Pi_{22}^{(1)}}} + \epsilon {\partial_{1} {\Pi_{12}^{(1)}}} + \epsilon {\partial_{0} {\Pi_{02}^{(1)}}} + \frac{{\partial_{2} \rho}}{3} + {\partial_{t} u_{2}} + {\partial_{2} (u_{2}^{2}) } + {\partial_{0} (u_{0} u_{2}) } + {\partial_{1} (u_{1} u_{2}) }\end{matrix}\right]$$