boundaryconditions.py 1.94 KB
Newer Older
Martin Bauer's avatar
Martin Bauer committed
1
2
3
4
import sympy as sp
from lbmpy.boundaries.boundaryhandling import offsetFromDir, weightOfDirection, invDir


5
6
def noSlip(pdfField, direction, lbmMethod):
    neighbor = offsetFromDir(direction, lbmMethod.dim)
Martin Bauer's avatar
Martin Bauer committed
7
8
9
10
    inverseDir = invDir(direction)
    return [sp.Eq(pdfField[neighbor](inverseDir), pdfField(direction))]


11
12
def ubb(pdfField, direction, lbmMethod, velocity):
    neighbor = offsetFromDir(direction, lbmMethod.dim)
Martin Bauer's avatar
Martin Bauer committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    inverseDir = invDir(direction)

    velTerm = 6 * sum([d_i * v_i for d_i, v_i in zip(neighbor, velocity)]) * weightOfDirection(direction)
    return [sp.Eq(pdfField[neighbor](inverseDir),
                  pdfField(direction) - velTerm)]


def fixedDensity(pdfField, direction, latticeModel, density):
    from lbmpy_old.equilibria import standardDiscreteEquilibrium
    neighbor = offsetFromDir(direction, latticeModel.dim)
    inverseDir = invDir(direction)
    stencil = latticeModel.stencil

    if not latticeModel.compressible:
        density -= 1

    eqParams = {'stencil': stencil,
                'order': 2,
                'c_s_sq': sp.Rational(1, 3),
                'compressible': latticeModel.compressible,
                'rho': density}

    u = sp.Matrix(latticeModel.symbolicVelocity)
    symmetricEq = (standardDiscreteEquilibrium(u=u, **eqParams) + standardDiscreteEquilibrium(u=-u, **eqParams)) / 2

    subExpr1, rhoExpr, subExpr2, uExprs = getDensityVelocityExpressions(stencil,
                                                                        [pdfField(i) for i in range(len(stencil))],
                                                                        latticeModel.compressible)
    subExprs = subExpr1 + [rhoExpr] + subExpr2 + uExprs

    conditions = [(eq_i, sp.Equality(direction, i)) for i, eq_i in enumerate(symmetricEq)] + [(0, True)]
    eq_component = sp.Piecewise(*conditions)

    return subExprs + [sp.Eq(pdfField[neighbor](inverseDir),
                             2 * eq_component - pdfField(direction))]