In this tutorial, we will learn what central moments are, what advantages they have and how we can use them with lbmpy.
%% Cell type:markdown id: tags:
## 1) Theoretical Background
%% Cell type:markdown id: tags:
### What are Central Moments and why use them?
The most common collision operators are the SRT and MRT operators. Both of these operators are based on a second-order approximation of the Maxwell-Boltzmann distribution, where the relaxation is done in either single or multiple steps. However, both approaches have the disadvantage that at relaxation rates that are close to the limit, both methods become unstable. For these kinds of problems, other operators can be used, e.g. the entropic LB operator, which enforces an H-theorem on the lattice and is therefore unconditionally stable. In order to get this feature of unconditional stability, the relaxation time is modulated in dependence of the local entropy, which removes high frequencies from the flux fields. Nevertheless, the method that is presented in this notebook is another one, the Cascaded LBM (= CLBM), which uses central moments. It does not remove any frequencies, but instead tries to deal with the high frequencies with sufficient accuracy, such that these do not threaten the overall stability.
%% Cell type:markdown id: tags:
So CLBM has the goal to remove instabilities which can be traced back to an insufficient level of Galilean invariance (GI). GI describes the independence of physical processes from the speed of the reference system.
%% Cell type:markdown id: tags:
From tutorial 3 we know, that _lbmpy_ is using the following equation for moment based relaxations
$$K(f) = f - C^{-1}S\left(Cf - c^{(eq)}\right)$$
A few things are happening here:
* $Cf$ is transforming the distribution function $f$ into the moment space. The solution of this linear transformation is the moment-vector $c = Cf$.
* $c^{(eq)}$ defines the equilibrium in the moment space (alternatively $Cf^{(eq)}$, but it is more natural to define it directly in the moment space)
* In the moment space, the relaxation is executed by multiplying $S$ from left, to get $\Delta m = S \cdot \left(m - m^{(eq)}\right)$
* then an inverse transformation of the relaxed moments is done by $\Delta f = C^{-1} \Delta m$
* and in the end, the streaming is happening by $K(f) = f - \Delta f$
%% Cell type:markdown id: tags:
Now, in order to restore the Galilean invariance, we will use central moments. For that, we have to perform an additional transformation; we have to transform the raw moments into the central moment space. First, we define the continuous central moments:
The main difference between the transformation to raw moments and the one to central moments is that the first is a linear transformation, while the second is a polynomial transformation. As a consequence, we cannot easily formulate this transformation as a simple matrix-vector multiplication; nevertheless, we can use the fast central moment transformation:
Now we can replace the transformation from the distribution function into the raw moment space with the fast central moment transformation into the central moment space, but because it is not a linear transformation, we are not able to write this as one equation as before, at least not directly. Therefore we have to do computations step by step and put the results together, such that we get the following algorithm:
%% Cell type:markdown id: tags:
* Transform distribution function $f_{ijk}$ with the fast central moment transformation into the central moments $\kappa_{\alpha \beta \gamma}$ $\left(f_{ijk} \Rightarrow \kappa_{\alpha\beta\gamma}\right)$
* Calculate the central equilibrium moments $\kappa_{i}^{(eq)}$ $\left(f_{ijk}^{(eq)} \Rightarrow \kappa_{\alpha\beta\gamma}^{(eq)}\right)$
* Relax the central moments $\kappa_i$ each with the relaxation frequency $\omega_i$ (diagonal elements of $S$) $\left(\kappa^{*} = S \left( \kappa_{\alpha\beta\gamma} - \kappa_{\alpha\beta\gamma}^{(eq)} \right)\right)$
* Transform the relaxed central moments with the inverse central moments transformation into the relaxed distribution function $f_{ijk}^{*}$ $\left(\kappa^{*} \Rightarrow f^{*}\right)$
* Do the update $\left(f(t+\Delta t, x+c_x \Delta t) = f(t, x) - f^{*}(t, x)\right)$ and streaming step
%% Cell type:markdown id: tags:
### Possible Solutions to Fix the Problem
%% Cell type:markdown id: tags:
However, there are two possibilities on how to solve the dilemma and write this again in one equation. One is to modify the above-described approach, and the other one uses features of lbmpy for a workaround:
1. Extract with the help of the fast central moment transformation a shift matrix, which is lower triangular, to transform the moment space into the central moment space.
2. Set up a method directly with the central moments. However, the problem with this approach is, that the transformation matrix which brings the distribution function into the moment space changes, and is not sparse anymore but full. As a consequence, the subexpression elimination is not able to reduce the operation count as much as in the case of the shift matrix (D2Q9, in D3Q27 case the subexpression elimination is not working anymore), which we will later see in an example.
Let us first look at the first possibility. We introduce a little modification to the approach described above. With the help of the fast central moment transformation, we can extract a shift matrix $N$, which transforms the raw moments into the central moment space via matrix multiplication. The shift matrix consists of the coefficients of the moments from the polynomials, which we get from the fast central moment transformation. Furthermore, with this, we can again write the collision equation in a form with matrix-matrix/vector multiplications and do not have to execute multiple things step after step.
%% Cell type:markdown id: tags:
$$K(f) = f - C^{-1}N^{-1}SN\left(Cf - c^{(eq)}\right)$$
%% Cell type:markdown id: tags:
## 2) Using Central Moments with *lbmpy* by Using the Shift Matrix $N$
%% Cell type:markdown id: tags:
First let us define variables which we later need, like the velocity $u$, the distribution function $f$, the relaxation rates $\omega$ and the viscosity $\rho$.
%% Cell type:code id: tags:
``` python
u=sp.Matrix(sp.symbols("u_:2"))# velocity
f=sp.Matrix(sp.symbols("f_:9"))# distribution function
We will show the usage of the central moments in an easy setup, the simulation of a force-driven channel flow. First, we define a method with raw moments.
<lbmpy.methods.momentbased.MomentBasedLbMethod at 0x7f9b5d2683d0>
<lbmpy.methods.momentbased.MomentBasedLbMethod at 0x7f7cb0f67fd0>
%% Cell type:markdown id: tags:
With the help of the method, we can extract specific vectors/matrices, which we will need to define our collision equation (transformation matrix to transform distribution function $f$ into the moment space, the discrete equilibrium values in the moment space). Further, we use the extracted moments and the defined stencil to get the second transformation matrix with `get_shift_matrix`, to get from the moment space to the central moment space.
In order to use this collision equation later on in a predefined scenario, we have to convert it into a collision rule, which we will do below, while introducing three subexpressions for the calculation of $\rho$, $u_0$ and $u_1$.
As we can see, not only is the initial operation count - before the subexpression elimination - much larger than the operation count with the shift matrix (116002 vs 2106 operations), but also the operation count after the common subexpression elimination is larger, and that is already the case for D2Q9, for D3Q27 the difference will get even more extensive.
%% Cell type:markdown id: tags:
## Literature
%% Cell type:markdown id: tags:
- Martin Geier, Andreas Greiner, and Jan G. Korvink. "Cascaded digital lattice Boltzmann automata for high Reynolds number flow". In: _Phys. Rev. E_ 73 (6. June 2006), p. 066705. DOI: 10.1103/PhysRevE.73.066705. URL: https://link.aps.prg/doi/10.1103/PhysRevE.73.066705.
- G. Gruszczyński et al. "A cascaded phase-field lattice Boltzmann model for the simulation of incompressible, immiscible fluids with high density contrast". In: _Computers Mathematics with Applications_ 79.4 (2020), pp. 1049-1071. ISSN:0898-1221. DOI: https://doi.org/10.1016/j.camwa.2019.08.018. URL: http://www.sciencedirect.com/science/article/pii/S0898122119304158
- Markus Muhr. "Kumulanten-basierte Lattice-Boltzmann-Methode". Seminar Ausarbeitung in _Transportprozesse: Mathematische Modellierung und Numerische Methoden_. Technische Universität München Fakultät für Mathematik.