Exemple #1
0
def elbm_d3q15_equilibrium(grid):
    """
    Form of equilibrium defined in PRL 97, 010201 (2006).
    See also Chikatamarla, PhD Thesis, Eq. (5.7), (5.8).
    """
    rho = S.rho

    prefactor = Symbol('prefactor')
    coeff1 = Symbol('coeff1')
    coeff2 = Symbol('coeff2')
    coeff3 = Symbol('coeff3')
    vsq = Symbol('vsq')
    vx, vy, vz = grid.v

    lvars = []
    lvars.append(Eq(vsq, grid.v.dot(grid.v)))
    lvars.append(Eq(prefactor, poly_factorize(
        rho * (1 - 3 * vsq / 2 + 9 * vsq**2 / 8 +
        Rational(27, 16) * (-vsq**3 + 2 * (vy**2 + vz**2) *
            (vsq * vx**2 + vy**2 * vz**2) +
            20 * vx**2 * vy**2 * vz**2) +
        Rational(81, 128) * vsq**4 +
        Rational(81, 32) * (vx**8 + vy**8 + vz**8
            - 36 * vx**2 * vy**2 * vz**2 * vsq
            - vx**4 * vy**4
            - vy**4 * vz**4
            - vx**4 * vz**4)))))

    cfs = [coeff1, coeff2, coeff3]

    for i, coeff in enumerate(cfs):
        tmp = (1 + 3 * grid.v[i] + 9 * grid.v[i]**2 / 2 +
            9 * grid.v[i]**3 / 2 + 27 * grid.v[i]**4 / 8)

        # Cyclic permutation.
        x = i
        y = (i + 1) % 3
        z = (i + 2) % 3

        tmp += Rational(27, 8) * (grid.v[x]**5
                - 4 * grid.v[x] * grid.v[y]**2 * grid.v[z]**2)
        tmp += Rational(81, 16) * (grid.v[x]**6
                - 8 * grid.v[x]**2 * grid.v[y]**2 * grid.v[z]**2)
        tmp += Rational(81, 16) * (grid.v[x]**7
                - 10 * grid.v[x]**3 * grid.v[y]**2 * grid.v[z]**2
                + 2 * grid.v[x] * grid.v[y]**2 * grid.v[z]**2 * vsq)
        tmp += Rational(243, 128) * (grid.v[x]**8
                + 16 * grid.v[x]**2 * grid.v[y]**2 * grid.v[z]**2
                * (grid.v[y]**2 + grid.v[z]**2))

        lvars.append(Eq(coeff, poly_factorize(tmp)))

    out = []
    for ei, weight in zip(grid.basis, grid.entropic_weights):
        t = prefactor * weight
        for j, comp in enumerate(ei):
            t *= cfs[j]**comp
        out.append(t)

    return EqDef(out, lvars)
Exemple #2
0
def shallow_water_equilibrium(grid, config):
    """Get expressions for the BGK equilibrium distribution for the shallow
    water equation."""

    if grid.dim != 2 or grid.Q != 9:
        raise TypeError('Shallow water equation requires the D2Q9 grid.')

    out = [S.rho - grid.weights[0] * S.rho * (
        Rational(15, 8) * S.gravity * S.rho - 3 * grid.v.dot(grid.v))]

    for ei, weight in zip(grid.basis[1:], grid.weights[1:]):
        out.append(weight * (
                S.rho * poly_factorize(Rational(3,2) * S.rho * S.gravity + 3*ei.dot(grid.v) +
                    Rational(9,2) * (ei.dot(grid.v))**2 - Rational(3, 2) * grid.v.dot(grid.v))))

    return EqDef(out, local_vars=[])
Exemple #3
0
def guo_external_force(grid, grid_num=0):
    """Gets expressions for the external body force correction in the BGK model.

    This implements the external force as in Eq. 20 from PhysRevE 65, 046308.

    :param grid: the grid class to be used

    :rtype: list of sympy expressions (in the same order as the current grid's basis)
    """
    pref = Symbol('pref')

    ea = accel_vector(grid, grid_num)
    ret = []

    for i, ei in enumerate(grid.basis):
        ret.append(pref * grid.weights[i] *
                   poly_factorize((ei - grid.v + ei.dot(grid.v)*ei*3).dot(ea)))
    return ret
Exemple #4
0
def bgk_equilibrium(grid, config, rho=None, rho0=None):
    """Get expressions for the BGK equilibrium distribution.

    :param grid: the grid class to be used
    """
    out = []

    if rho is None:
        rho = S.rho

    if rho0 is None:
        if config.incompressible:
            rho0 = S.rho0
        elif config.minimize_roundoff:
            rho0 = rho + 1.0
        else:
            rho0 = rho

    for ei, weight in zip(grid.basis, grid.weights):
        out.append(weight * (rho + rho0 * poly_factorize(
            3 * ei.dot(grid.v) + Rational(9, 2) * (ei.dot(grid.v))**2 -
            Rational(3, 2) * grid.v.dot(grid.v))))

    return EqDef(out, local_vars=[])