Ejemplo n.º 1
0
def rotation_to_transformation_matrix(R):
    """
    It converts from 3x3 Rotation matrix to 4x4 Transformation matrix
    """
    R = Matrix(R)
    T = R.col_insert(3, Matrix([0., 0., 0.]))
    T = T.row_insert(3, Matrix([[0., 0., 0., 1.]]))
    return T
Ejemplo n.º 2
0
def get_e_as_in_r(x, y, z):
    yG, zG, xG = np.meshgrid(x, y, z)  # create the actual grid
    xG = xG.flatten()  # make the grid 1d
    yG = yG.flatten()  # same
    zG = zG.flatten()
    ex_D3Q27 = Matrix(xG)
    ey_D3Q27 = Matrix(yG)
    ez_D3Q27 = Matrix(zG)
    e_D3Q27 = ex_D3Q27.col_insert(1, ey_D3Q27)
    e_D3Q27 = e_D3Q27.col_insert(2, ez_D3Q27)
    return ex_D3Q27, ey_D3Q27, ez_D3Q27, e_D3Q27
Ejemplo n.º 3
0
def linear_eq_to_matrix(equations, *symbols):
    r"""
    Converts a given System of Equations into Matrix form.
    Here `equations` must be a linear system of equations in
    `symbols`. The order of symbols in input `symbols` will
    determine the order of coefficients in the returned
    Matrix.

    The Matrix form corresponds to the augmented matrix form.
    For example:

    .. math:: 4x + 2y + 3z  = 1
    .. math:: 3x +  y +  z  = -6
    .. math:: 2x + 4y + 9z  = 2

    This system would return `A` & `b` as given below:

    ::

         [ 4  2  3 ]          [ 1 ]
     A = [ 3  1  1 ]   b  =   [-6 ]
         [ 2  4  9 ]          [ 2 ]

    Examples
    ========

    >>> from sympy import linear_eq_to_matrix, symbols
    >>> x, y, z = symbols('x, y, z')
    >>> eqns = [x + 2*y + 3*z - 1, 3*x + y + z + 6, 2*x + 4*y + 9*z - 2]
    >>> A, b = linear_eq_to_matrix(eqns, [x, y, z])
    >>> A
    Matrix([
    [1, 2, 3],
    [3, 1, 1],
    [2, 4, 9]])
    >>> b
    Matrix([
    [ 1],
    [-6],
    [ 2]])
    >>> eqns = [x + z - 1, y + z, x - y]
    >>> A, b = linear_eq_to_matrix(eqns, [x, y, z])
    >>> A
    Matrix([
    [1,  0, 1],
    [0,  1, 1],
    [1, -1, 0]])
    >>> b
    Matrix([
    [1],
    [0],
    [0]])

    * Symbolic coefficients are also supported

    >>> a, b, c, d, e, f = symbols('a, b, c, d, e, f')
    >>> eqns = [a*x + b*y - c, d*x + e*y - f]
    >>> A, B = linear_eq_to_matrix(eqns, x, y)
    >>> A
    Matrix([
    [a, b],
    [d, e]])
    >>> B
    Matrix([
    [c],
    [f]])

    """

    if not symbols:
        raise ValueError('Symbols must be given, for which coefficients \
                         are to be found.')

    if hasattr(symbols[0], '__iter__'):
        symbols = symbols[0]

    M = Matrix([symbols])
    # initialise Matrix with symbols + 1 columns
    M = M.col_insert(len(symbols), Matrix([1]))
    row_no = 1

    for equation in equations:
        f = sympify(equation)
        if isinstance(f, Equality):
            f = f.lhs - f.rhs

        # Extract coeff of symbols
        coeff_list = []
        for symbol in symbols:
            coeff_list.append(f.coeff(symbol))

        # append constant term (term free from symbols)
        coeff_list.append(-f.as_coeff_add(*symbols)[0])

        # insert equations coeff's into rows
        M = M.row_insert(row_no, Matrix([coeff_list]))
        row_no += 1

    # delete the initialised (Ist) trivial row
    M.row_del(0)
    A, b = M[:, :-1], M[:, -1:]
    return A, b
Ejemplo n.º 4
0
F_phi_x = Symbol(Force_str + '.x')
F_phi_y = Symbol(Force_str + '.y')
F_phi_z = Symbol(Force_str + '.z')

omega_ade = Symbol('omega_ade', positive=True)
omega_v = Symbol('omega_nu', positive=True)
omega_b = Symbol('omega_bulk',
                 positive=True)  # omega_bulk='1.0/(3*bulk_visc+0.5)'

####################################################### END OF SYMBOLS #######################################################
# D2Q9 notation from TCLB
ex_D2Q9 = Matrix([0, 1, 0, -1, 0, 1, -1, -1, 1])
ey_D2Q9 = Matrix([0, 0, 1, 0, -1, 1, 1, -1, -1])
ez_D2Q9 = Matrix([0, 0, 0, 0, 0, 0, 0, 0, 0])
e_D2Q9 = ex_D2Q9.col_insert(1, ey_D2Q9)

# D3Q7 notation from TCLB
ex_D3Q7 = Matrix([0, 1, -1, 0, 0, 0, 0])
ey_D3Q7 = Matrix([0, 0, 0, 1, -1, 0, 0])
ez_D3Q7 = Matrix([0, 0, 0, 0, 0, 1, -1])

e_D3Q7 = ex_D3Q7.col_insert(1, ey_D3Q7)
e_D3Q7 = e_D3Q7.col_insert(2, ez_D3Q7)

S_relax_ADE_D3Q7 = diag(1, omega_ade, omega_ade, omega_ade, 1, 1, 1)

# D3Q15 - notation from 'LBM Principles and Practise' Book p. 89
# ex_D3Q15 = Matrix([0, 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, -1, 1])
# ey_D3Q15 = Matrix([0, 0, 0, 1, -1, 0, 0, 1, -1, 1, -1, -1, 1, 1, -1])
# ez_D3Q15 = Matrix([0, 0, 0, 0, 0, 1, -1, 1, -1, -1, 1, 1, -1, 1, -1])
Ejemplo n.º 5
0
F2D = Matrix([Fx, Fy])
F3D = Matrix([Fx, Fy, Fz])

Force_str = "F"
F_phi_x = Symbol(Force_str + '.x')
F_phi_y = Symbol(Force_str + '.y')
F_phi_z = Symbol(Force_str + '.z')

omega_ade = Symbol('omega_ade')
omega_v = Symbol('omega_nu')  # omega_nu = s_nu = 1 /(tau + 0.5)
omega_b = Symbol('omega_bulk')  # results in bulk viscosity = 1/6 since : zeta = (1/sb - 0.5)*cs^2*dt

ex_D2Q9 = Matrix([0, 1, 0, -1, 0, 1, -1, -1, 1])
ey_D2Q9 = Matrix([0, 0, 1, 0, -1, 1, 1, -1, -1])
e_D2Q9 = ex_D2Q9.col_insert(1, ey_D2Q9)

# D3Q7 notation from TCLB
ex_D3Q7 = Matrix([0, 1, -1, 0, 0, 0, 0])
ey_D3Q7 = Matrix([0, 0, 0, 1, -1, 0, 0])
ez_D3Q7 = Matrix([0, 0, 0, 0, 0, 1, -1])


# D3Q15 - notation from 'LBM Principles and Practise' Book p. 89
ex_D3Q15 = Matrix([0, 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, -1, 1])
ey_D3Q15 = Matrix([0, 0, 0, 1, -1, 0, 0, 1, -1, 1, -1, -1, 1, 1, -1])
ez_D3Q15 = Matrix([0, 0, 0, 0, 0, 1, -1, 1, -1, -1, 1, 1, -1, 1, -1])

S_relax_ADE_D3Q15 = diag(1, omega_ade, omega_ade, omega_ade, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)