Symbolic Operations and CLBM

Before start, it is assumed that the reader is already familiar with:

We will cover following topics:

  • Symbolic computations (within) TCLB.
  • Heat transfer on D2Q9 lattice using Central Moments (CM) a.k.a. Cascaded LBM. This is an enhancement to the previous tutorial, where the SRT collision was performed.

Notion of moments

The raw and central moments are introduced based on the work of Geier et al. 5 as,

while the central moments are calculated in a moving reference frame i.e., with respect to the fluid velocity:

where is the distribution function of interest (either hydrodynamic or enthalpy).

Note

Raw moments are obtained from distribution functions through . Central moments are derived from raw moments by . It is important to notice that is a fixed matrix while depends on the fluid velocity, .

The form of the matrices can be found here. The resulting order of the central moments is,

The physical interpretation of the raw, zeroth order moments of the hydrodynamic and enthalpy DF corresponds to the values of density, , and enthalpy . For simplicity we take in the remainder of the tutorial.

The macroscopic fluid momentum is the first raw moment of the hydrodynamic DF and has a dependency on the forcing term .

Collision in the Central Moment Space

The collision process and application of forcing terms is conducted in central moment space to improve computational efficiency 23,

The relaxation matrices, and , have a diagonal form specified as,

where and . Following the Chapman-Enskog expansion, the kinematic and bulk viscosities are used to calculate corresponding relaxation frequencies and ,

The bulk relaxation rate is specified as, . Such an approach results in a reduction of non-physical pressure oscillations, giving a bulk equilibrium after each collision and a more stable model. To satisfy conservation laws for density and momentum, the zeroth and first order relaxation constants are set to unity, . For this study, the tunable relaxation frequencies are specified as, .

In the case of the Enthalpy DF, the relaxation frequency, , is replaced by,

Here, is used to relax the first moments only (see 2) while the remainder are conserved by setting the relaxation frequencies to unity, .

streaming

To perform the streaming step, the relaxed, post-collision central moments need to be transformed back into the velocity distribution space and streamed to neighbours,

Model Creation in TCLB

Dynamics.R

Take the one from the basic D2Q9 Heat Transfer tutorial and add a new node type AddNodeType("CM","COLLISION"), since we are going to implement a new collision kernel.

Dynamics.c

First we have to load R symbols.

<?R
    source("conf.R") 
    source("lib/boundary.R")
    c_header();

# Creating variables for symbolic computations
    f = PV(DensityAll$name[DensityAll$group=="f"])
    h = PV(DensityAll$name[DensityAll$group=="h"])
    rho =  PV("rho")
    u = PV(c("ux","uy"))
    rhoT = PV("rhoT")

# Extracting velocity set
    U = d2q9

?>

Macroscopic Quantities

Now we can replace the tedious and error-prone operarions from the previous tutorial with their symbolic equivalents. Using R language:

CudaDeviceFunction real_t getRho(){
    return <?R C(sum(f)) ?>; // compiles to f[8]+f[7]+f[6]+f[5]+f[4]+f[3]+f[2]+f[1]+f[0];
}

CudaDeviceFunction real_t getT(){
    return (<?R C(sum(h)) ?>)/(<?R C(sum(f)) ?>);
}

CudaDeviceFunction vector_t getRawU(){
    real_t d = getRho();
    vector_t u;
<?R C(PV(c("u.x","u.y", "u.z")), f %*% U) ?>
    u.x /= d;
    u.y /= d;
    u.z = 0;
    return u;
}

CudaDeviceFunction vector_t getU()
{
    real_t localTemperature = getT();
    vector_t u = getRawU();
    real_t m00 = getRho();
    vector_t Force = getForce(localTemperature, m00);
    u.x += Force.x/(2*m00);
    u.y += Force.y/(2*m00);
    u.z = 0;
    return u;
}

Collision

CudaDeviceFunction void CollisionCM()
{
    real_t localTemperature = getT();
    real_t m00 = getRho();

    vector_t Force = getForce(localTemperature, m00);
    vector_t u = getRawU();
    u.x += Force.x/(2*m00);
    u.y += Force.y/(2*m00);

    relax_and_collide_hydro_with_F(f, omega_nu, u, Force);
    relax_and_collide_ADE(h, omega_k, u);
}

We are going to implement following functions in Central Moments Space:

CudaDeviceFunction void SetEquilibrium(real_t x_in[9], real_t rho_Xeq, vector_t u){...}
CudaDeviceFunction void relax_and_collide_hydro_with_F(real_t x_in[9], real_t omega_nu, vector_t u, vector_t F){...}
CudaDeviceFunction void relax_and_collide_ADE(real_t x_in[9], real_t omega_ade, vector_t u) {...}

Symbolic Operations with python

Theory

We are going to show how the moments of Force and equilibrium distribution function can be calculated.

The formulas for the discrete equilibrium distribution function from previous tutorials comes from a discretization of continous Maxwell-Boltzmann distribution function. The Maxwell-Boltzmann equilibrium distribution function in a continuous, velocity space is known as:

Where is the quantity of interest (like density or enthalpy) and ( D )is the number of dimensions. The continuous definition of the central moments is:

Now, we will discuss transformation of forcing term.

To compute the continuous transform, a scheme proposed by He et al. 6 was expressed in a continous form by Premnath al. 7.

Practise

Although it is possible to inject python snippets using <?python /> within TCLB code, we will run the symbolic calculations in PyCharm enviroment then copy-paste the output.

Clone the repository containing TCLB tools:

git clone https://github.com/CFD-GO/TCLB_tools.git

Then open the TCLB_tools/Python/symbolic_tools/ directory in PyCharm and create a new pycharm-project. Next, go tutorials folder and open the tutorial_cm_eq_derivation.py script. Run it.

Question

Why the python's timer doesn't work as expected?

It turns out the obtained formulas are simple, thus the numerical effort of Cascaded collision is similar to SRT (~ +10%). As it takes a while to compute the integrals, the result is hardcoded and used afterwards for symbolic code generation.

Collision Kernel

Now, it is time to generate the missing functions:

CudaDeviceFunction void SetEquilibrium(real_t x_in[9], real_t rho_Xeq, vector_t u){...}
CudaDeviceFunction void relax_and_collide_hydro_with_F(real_t x_in[9], real_t omega_nu, vector_t u, vector_t F){...}
CudaDeviceFunction void relax_and_collide_ADE(real_t x_in[9], real_t omega_ade, vector_t u) {...}

To do so, open a prepared tutorial_cm_collision.py script. Fill the missing functionalities #TODO

Hint: After the collision, the central moments have to be back-tranformed to moments, then to density-probability functions - see the streaming step.

Setting up a Simulation

To run the new collision kernel, change the configuration file my_heat_cube.xml from previous tutorial : <BGK><Box /></BGK> to <CM><Box /></CM> and uncomment the corresponding switch //case NODE_CM: ... in Dynamics.c.Rt.

References

Tip

A good starting point explaining the 'zoology' of various LBM models is a modern (2017) book 'The Lattice Boltzmann Method: Principles and Practice' written by T. Krüger, H. Kusumaatmaja, A. Kuzmin, O. Shardt, G. Silva, E.M. Viggen .

The implementation of the cascaded collision kernel is greatly insipered by the work of Linlin Fei, Kai H. Luo et al.


  1. Linlin Fei, Kai Hong Luo, 'Cascaded lattice Boltzmann method for incompressible thermal flows with heat sources and general thermal boundary conditions' Computers and Fluids (2018). 

  2. Linlin Fei, Kai Hong Luo, Chuandong Lin, Qing Li, 'Modeling incompressible thermal flows using a central-moments-based lattice Boltzmann method' International Journal of Heat and Mass Transfer (2017). 

  3. Linlin Fei and Kai Hong Luo, 'Consistent forcing scheme in the cascaded lattice Boltzmann method' Physical Review E 96, 053307 (2017). 

  4. Linlin Fei, Kai H. Luo and Qing Li, 'Three-dimensional cascaded lattice Boltzmann method: Improved implementation and consistent forcing scheme' Physical Review E 97, 053309 (2018) 

  5. M. Geier, A. Greiner, J. G. Korvink, 'Cascaded digital lattice Boltzmann automata for high Reynolds number flow' Physical Review E - Statistical, Nonlinear, and Soft Matter Physics 73 (2006). 

  6. Xiaoyi He, Xiaowen Shan, and Gary D. Doolen, 'Discrete Boltzmann equation model for nonideal gases' in Physical Review E - Statistical Physics, Plasmas, Fluids, and Related Interdisciplinary Topics (1998). 

  7. K. N. Premnath, S. Banerjee, 'Incorporating forcing terms in cascaded lattice Boltzmann approach by method of central moments' in Physical Review E - Statistical, Nonlinear, and Soft Matter Physics 80 (2009).