예제 #1
0
def test_gauss_tri():
    # Zero order
    pts, wts = gauss.gauss_tri(order=1)
    fun = lambda x, y: 1
    inte = 0.0
    for cont, pt in enumerate(pts):
        x, y = pt
        inte += 0.5 * wts[cont] * fun(x, y)
    assert np.isclose(inte, 0.5)

    # First order
    pts, wts = gauss.gauss_tri(order=1)
    a, b = np.random.uniform(0, 1, 2)
    fun = lambda x, y: a*x + b*y
    inte = 0.0
    for cont, pt in enumerate(pts):
        x, y = pt
        inte += 0.5 * wts[cont] * fun(x, y)
    assert np.isclose(inte, (a + b)/6)

    # Second order
    pts, wts = gauss.gauss_tri(order=2)
    a, b, c, d, e, f = np.random.uniform(0, 1, 6)
    fun = lambda x, y: a*x**2 + b*y**2 + c*x*y + d*x + e*y + f
    inte = 0.0
    for cont, pt in enumerate(pts):
        x, y = pt
        inte += 0.5 * wts[cont] * fun(x, y)
    assert np.isclose(inte, (2*a + 2*b + c + 4*d + 4*e + 12*f)/24)

    # Third order
    pts, wts = gauss.gauss_tri(order=3)
    a, b, c, d, e, f = np.random.uniform(0, 1, 6)
    fun = lambda x, y: a*x**2 + b*y**2 + c*x*y + d*x + e*y + f
    inte = 0.0
    for cont, pt in enumerate(pts):
        x, y = pt
        inte += 0.5 * wts[cont] * fun(x, y)
    assert np.isclose(inte, (2*a + 2*b + c + 4*d + 4*e + 12*f)/24)

    # Seventh order
    pts, wts = gauss.gauss_tri(order=7)
    a, b, c, d, e, f, g, h = np.random.uniform(0, 1, 8)
    fun = lambda x, y: a*x**7 + b*x**6*y + c*x**5*y**2 + d*x**4*y**3\
                       + e*x**3*y**4 + f*x**2*y**5 + g*x*y**6 + h*y**7   
    inte = 0.0
    for cont, pt in enumerate(pts):
        x, y = pt
        inte += 0.5 * wts[cont] * fun(x, y)
    assert np.isclose(inte, (105*a + 15*b + 5*c + 3*d + 3*e + 5*f + 15*g
                             + 105*h)/7560)
예제 #2
0
def elast_tri3(coord, params):
    """Triangular element with 3 nodes

    Parameters
    ----------
    coord : ndarray
      Coordinates for the nodes of the element (3, 2).
    params : tuple
      Material parameters in the following order:

          young : float
            Young modulus (>0).
          poisson : float
            Poisson coefficient (-1, 0.5).
          dens : float, optional
            Density (>0).

    Returns
    -------
    stiff_mat : ndarray
      Local stiffness matrix for the element (6, 6).
    mass_mat : ndarray
      Local mass matrix for the element (6, 6).

    Examples
    --------

    >>> coord = np.array([
    ...         [0, 0],
    ...         [1, 0],
    ...         [0, 1]])
    >>> params = [8/3, 1/3]
    >>> stiff, mass = uel3ntrian(coord, params)
    >>> stiff_ex = 1/2 * np.array([
    ...            [4, 2, -3, -1, -1, -1],
    ...            [2, 4, -1, -1, -1, -3],
    ...            [-3, -1, 3, 0, 0, 1],
    ...            [-1, -1, 0, 1, 1, 0],
    ...            [-1, -1, 0, 1, 1, 0],
    ...            [-1, -3, 1, 0, 0, 3]])
    >>> np.allclose(stiff, stiff_ex)
    True

    """
    stiff_mat = np.zeros([6, 6])
    mass_mat = np.zeros([6, 6])
    C = fem.umat(params[:2])
    if len(params) == 2:
        dens = 1
    else:
        dens = params[-1]
    gpts, gwts = gau.gauss_tri(order=2)
    for cont in range(gpts.shape[0]):
        r, s = gpts[cont, :]
        H, B, det = fem.elast_diff_2d(r, s, coord, fem.shape_tri3)
        factor = det * gwts[cont]
        stiff_mat += 0.5 * factor * (B.T @ C @ B)
        mass_mat += 0.5 * dens * factor * (H.T @ H)
    return stiff_mat, mass_mat
예제 #3
0
def uel6ntrian(coord, params):
    """Triangular element with 6 nodes

    Parameters
    ----------
    coord : ndarray
        Coordinates for the nodes of the element (6, 2).
    params : tuple
        Material parameters in the following order:

            young : float
                Young modulus (>0).
            poisson : float
                Poisson coefficient (-1, 0.5).
            dens : float, optional
                Density (>0).

    Returns
    -------
    stiff_mat : ndarray
        Local stiffness matrix for the element (12, 12).
    mass_mat : ndarray
        Local mass matrix for the element (12, 12).

    Examples
    --------

    >>> coord = np.array([
    ...         [0, 0],
    ...         [1, 0],
    ...         [0, 1],
    ...         [0.5, 0],
    ...         [0.5, 0.5],
    ...         [0, 0.5]])
    >>> params = [8/3, 1/3]
    >>> stiff, mass = uel6ntrian(coord, params)
    >>> stiff_ex = 1/6 * np.array([
    ...            [12, 6, 3, 1, 1, 1, -12, -4, 0, 0, -4, -4],
    ...            [6, 12, 1, 1, 1, 3, -4, -4, 0, 0, -4, -12],
    ...            [3, 1, 9, 0, 0, -1, -12, -4, 0, 4, 0, 0],
    ...            [1, 1, 0, 3, -1, 0, -4, -4, 4, 0, 0, 0],
    ...            [1, 1, 0, -1, 3, 0, 0, 0, 0, 4, -4, -4],
    ...            [1, 3, -1, 0, 0, 9, 0, 0, 4, 0, -4, -12],
    ...            [-12, -4, -12, -4, 0, 0, 32, 8, -8, -8, 0, 8],
    ...            [-4, -4, -4, -4, 0, 0, 8, 32, -8, -24, 8, 0],
    ...            [0, 0, 0, 4, 0, 4, -8, -8, 32, 8, -24, -8],
    ...            [0, 0, 4, 0, 4, 0, -8, -24, 8, 32, -8, -8],
    ...            [-4, -4, 0, 0, -4, -4, 0, 8, -24, -8, 32, 8],
    ...            [-4, -12, 0, 0, -4, -12, 8, 0, -8, -8, 8, 32]])
    >>> np.allclose(stiff, stiff_ex)
    True

    """
    stiff_mat = np.zeros([12, 12])
    mass_mat = np.zeros([12, 12])
    C = fem.umat(params[:2])
    if len(params) == 2:
        dens = 1
    else:
        dens = params[-1]
    gpts, gwts = gau.gauss_tri(order=3)
    for i in range(gpts.shape[0]):
        ri = gpts[i, 0]
        si = gpts[i, 1]
        ddet, B = fem.stdm6NT(ri, si, coord)
        N = fem.sha6(ri, si)
        factor = gwts[i] * ddet
        stiff_mat += 0.5 * factor * (B.T @ C @ B)
        mass_mat += dens * factor * (N.T @ N)
    return stiff_mat, mass_mat