Commit a3556a10 authored by Martin Bauer's avatar Martin Bauer
Browse files

Automatic Chapman Enskog Analysis of moment-based methods

parent 9d35ef5d
This diff is collapsed.
%% Cell type:code id: tags:
``` python
import sympy as sp
# Using operator and kets from quantum module to represent differential operators and pdfs
from sympy.physics.quantum import Ket as Func
from sympy.physics.quantum import Operator
# Disable Ket notation |f> for functions
Func.lbracket_latex =''
Func.rbracket_latex = ''
sp.init_printing()
```
%% Cell type:markdown id: tags:
# Chapman Enskog analysis
Particle distribution function $f$:
%% Cell type:code id: tags:
``` python
c = sp.Symbol("c_x")
dt = sp.Symbol("Delta_t")
t = sp.symbols("t")
f = Func("f")
C = Func("C")
```
%% Cell type:markdown id: tags:
Differential operators (defined simply as non-commutative symbols here)
%% Cell type:code id: tags:
``` python
Dx = Operator("\partial_x")
Dt = Operator("\partial_t")
```
%% Cell type:code id: tags:
``` python
taylorOrder = 2
taylorOperator = sum(dt**k * (Dt + c* Dx)**k / sp.functions.factorial(k)
for k in range(1, taylorOrder+1))
taylorOperator
```
%% Output
$$\frac{\Delta_{t}^{2}}{2} \left(c_{x} \partial_x + \partial_t\right)^{2} + \Delta_{t} \left(c_{x} \partial_x + \partial_t\right)$$
2 2
Δₜ ⋅(cₓ⋅\partialₓ + \partialₜ)
─────────────────────────────── + Δₜ⋅(cₓ⋅\partialₓ + \partialₜ)
2
%% Cell type:markdown id: tags:
As right-hand-side we use the abstract collision operator $C$, which corresponds to (4.5)
%% Cell type:code id: tags:
``` python
eq_4_5 = (taylorOperator * f) - C
eq_4_5
```
%% Output
$$\left(\frac{\Delta_{t}^{2}}{2} \left(c_{x} \partial_x + \partial_t\right)^{2} + \Delta_{t} \left(c_{x} \partial_x + \partial_t\right)\right) {f} - {C}$$
⎛ 2 2 ⎞
⎜Δₜ ⋅(cₓ⋅\partialₓ + \partialₜ) ⎟
⎜─────────────────────────────── + Δₜ⋅(cₓ⋅\partialₓ + \partialₜ)⎟⋅❘f⟩ - ❘C⟩
⎝ 2 ⎠
%% Cell type:markdown id: tags:
Following the same steps as in the book, getting rid of second derivative, and discarding $\Delta_t^3$ we get to (4.7)
%% Cell type:code id: tags:
``` python
eq_4_7 = eq_4_5 - (dt/2)* (Dt + c*Dx) * eq_4_5
eq_4_7 = eq_4_7.expand().subs(dt**3, 0)
eq_4_7
```
%% Cell type:markdown id: tags:
### Chapman Enskog Ansatz
Open Question:
why is not everything expanded equally (derivatives start at 1, spatial terminates one earlier...)
%% Cell type:code id: tags:
``` python
eps = sp.Symbol("epsilon")
ceSymbolsF = [Func("f{}".format(i)) for i in range(3)]
ceSymbolsDt = [Operator("\partial_t^{{ ({}) }}".format(i)) for i in range(1,3)]
ceSymbolsDx = [Operator("\partial_x^{{ ({}) }}".format(i)) for i in range(1,2)]
ceF = sum(eps**k * s for k, s in enumerate(ceSymbolsF, start=0))
ceDt = sum(eps**k * s for k, s in enumerate(ceSymbolsDt, start=1))
ceDx = sum(eps**k * s for k, s in enumerate(ceSymbolsDx, start=1))
ceSubstitutions = {
Dt : ceDt,
Dx : ceDx,
f: ceF
}
ceSubstitutions
```
%% Cell type:markdown id: tags:
Inserting the SRT/BGK collision operator
%% Cell type:code id: tags:
``` python
srtC = -dt / sp.Symbol("tau") * ( ceF - ceSymbolsF[0])
srtC
```
%% Cell type:code id: tags:
``` python
eq_4_7_ce = eq_4_7.subs(ceSubstitutions).subs(C, srtC).expand().collect(eps)
eq_4_7_ce
```
%% Cell type:code id: tags:
``` python
eq_4_9_a = (eq_4_7_ce.coeff(eps) / dt).expand()
eq_4_9_a
```
%% Cell type:code id: tags:
``` python
eq_4_9_b = (eq_4_7_ce.coeff(eps**2) / dt).expand()
eq_4_9_b
```
%% Cell type:markdown id: tags:
Computing moments
%% Cell type:code id: tags:
``` python
import operator
from functools import reduce
def prod(factors):
return reduce(operator.mul, factors, 1)
def getMomentSymbol(idx, order):