Ejemplo n.º 1
0
def derivative_R(coord, connect, E, v, rho, alpha, beta, omega, p_par, q_par,
                 x_min_k, x_min_m, xval, disp_vector, lam, fvirg, elastic_p,
                 kinetic_e):
    """ calculates the derivative of the kinetic energy function.

    Args:
        coord (:obj:`numpy.array`): Coordinates of the element.
        connect (:obj:`numpy.array`): Element connectivity.
        E (:obj:`float`): Elastic modulus.
        v (:obj:`float`): Poisson's ratio.
        rho (:obj:`float`): Density.
        alpha (:obj:`float`): Damping coefficient proportional to mass.
        beta (:obj:`float`): Damping coefficient proportional to stiffness.
        omega (:obj:`float`): 2 * pi * frequency
        p_par (:obj:`float`): Penalization power to stiffness. 
        q_par (:obj:`float`): Penalization power to mass.
        x_min_k (:obj:`float`): Minimum relative densities to stiffness. 
        x_min_m (:obj:`float`): Minimum relative densities to mass. 
        xval (:obj:`numpy.array`): Indicates where there is mass.
        disp_vector (:obj:`numpy.array`): Displacement.
        lam (:obj:`float`): Lambda parameter.
        fvirg (:obj:`float`): R Ratio function value.
        elastic_p (:obj:`float`): Elastic potential energy function value.
        kinetic_e (:obj:`float`): Kinetic energy function value.

    Returns:
        Derivative values.
    """
    deriv_R = np.zeros((len(connect), 1), dtype=complex)
    dofs = 2
    ind_dofs = (np.array([
        dofs * connect[:, 1] - 1, dofs * connect[:, 1], dofs * connect[:, 2] -
        1, dofs * connect[:, 2], dofs * connect[:, 3] - 1,
        dofs * connect[:, 3], dofs * connect[:, 4] - 1, dofs * connect[:, 4]
    ],
                         dtype=int) - 1).T

    for el in range(len(connect)):

        Ke, Me = fc.matricesQ4(el, coord, connect, E, v, rho)
        ind = ind_dofs[el, :]
        dKe = p_par * (xval[el]**(p_par - 1)) * (1 - x_min_k) * Ke
        dCe = alpha * Me + beta * dKe
        if xval[el] > 0.1:
            dMe = q_par * (xval[el]**(q_par - 1)) * (1 - x_min_m) * Me
        else:
            dMe = ((9 * 3.512e7 * xval[el]**8 - 10 * 2.081e8 * xval[el]**9) *
                   (1 - x_min_m)) * Me
        dKed = dKe + omega * 1j * dCe - (omega**2) * dMe
        #
        deriv_R[el,
                0] = 1 / (4 * kinetic_e) * (disp_vector[ind].conjugate() @ (
                    dKe -
                    (omega**2) * fvirg * dMe) @ disp_vector[ind]).real + (
                        lam[ind] @ dKed @ disp_vector[ind]).real
        #Log Scale
        deriv_R[el, 0] = 10.0 * deriv_R[el, 0] * np.log10(np.exp(1)) / fvirg

    return deriv_R.real
Ejemplo n.º 2
0
def solution2D(coord, connect, ind_rows, ind_cols, nelx, nely, ngl, E, v, rho,
               alpha, beta, eta, omega, xval, x_min_k, x_min_m, p_par, q_par):
    """ Assembly matrices.

    Args:
        coord (:obj:`numpy.array`): Coordinates of the element.
        connect (:obj:`numpy.array`): Element connectivity.
        ind_rows (:obj:`numpy.array`): Node indexes to make the assembly.
        ind_cols (:obj:`numpy.array`): Node indexes to make the assembly.
        nelx (:obj:`int`): Number of elements on the X-axis.
        nely (:obj:`int`): Number of elements on the Y-axis.
        ngl (:obj:`int`): Degrees of freedom.
        E (:obj:`float`): Elastic modulus.
        v (:obj:`float`): Poisson's ratio.  
        rho (:obj:`float`): Density.  
        alpha (:obj:`float`): Damping coefficient proportional to mass. 
        beta (:obj:`float`): Damping coefficient proportional to stiffness.  
        eta (:obj:`float`): Damping coefficient. 
        omega (:obj:`float`): 2 pi frequency
        xval (:obj:`numpy.array`): Indicates where there is mass.
        x_min_k (:obj:`float`): Minimum relative densities to stiffness. 
        x_min_m (:obj:`float`): Minimum relative densities to mass. 
        p_par (:obj:`int`): Penalization power to stiffness.
        q_par (:obj:`int`): Penalization power to mass. 

    Returns:
        A tuple with stiffnes, mass and dynamic matrices and time to assembly the matrices.
    """
    #
    t01 = time()
    data_k = np.zeros((nelx * nely, 64), dtype=complex)
    data_m = np.zeros((nelx * nely, 64), dtype=complex)
    #
    for el in range(nelx * nely):
        Ke, Me = fc.matricesQ4(el, coord, connect, E, v, rho)
        data_k[el, :] = (x_min_k + (xval[el]**p_par) *
                         (1 - x_min_k)) * Ke.flatten()
        if xval[el] > 0.1:
            data_m[el, :] = (x_min_m + (xval[el]**q_par) *
                             (1 - x_min_m)) * Me.flatten()
        else:
            data_m[el, :] = (x_min_m +
                             (3.512e7 * xval[el]**9 - 2.081e8 * xval[el]**10) *
                             (1 - x_min_m)) * Me.flatten()
    #
    data_k = data_k.flatten()
    data_m = data_m.flatten()
    stif_matrix = csc_matrix((data_k, (ind_rows, ind_cols)), shape=(ngl, ngl))
    mass_matrix = csc_matrix((data_m, (ind_rows, ind_cols)), shape=(ngl, ngl))
    damp_matrix = alpha * mass_matrix + (beta) * stif_matrix
    dyna_stif = -(omega**
                  2) * mass_matrix + 1j * omega * damp_matrix + stif_matrix

    tf1 = time()
    t_assembly = str(round((tf1 - t01), 6))

    return stif_matrix, mass_matrix, dyna_stif, t_assembly
Ejemplo n.º 3
0
def derivative_input_power(coord, connect, E, v, rho, alpha, beta, omega,
                           p_par, q_par, x_min_k, x_min_m, xval, disp_vector,
                           fvirg):
    """ calculates the derivative of the input power function.
    
    Args:
        coord (:obj:`numpy.array`): Coordinates of the element.
        connect (:obj:`numpy.array`): Element connectivity.
        E (:obj:`float`): Elastic modulus.
        v (:obj:`float`): Poisson's ratio.
        rho (:obj:`float`): Density.
        alpha (:obj:`float`): Damping coefficient proportional to mass.
        beta (:obj:`float`): Damping coefficient proportional to stiffness.
        omega (:obj:`float`): 2 * pi * frequency
        p_par (:obj:`float`): Penalization power to stiffness. 
        q_par (:obj:`float`): Penalization power to mass.
        x_min_k (:obj:`float`): Minimum relative densities to stiffness. 
        x_min_m (:obj:`float`): Minimum relative densities to mass. 
        xval (:obj:`numpy.array`): Indicates where there is mass.
        disp_vector (:obj:`numpy.array`): Displacement.
        fvirg (:obj:`float`): Input power function value.

    Returns:
        Derivative values.

    """
    deriv_f = np.zeros((len(connect), 1))
    dofs = 2
    ind_dofs = (np.array([
        dofs * connect[:, 1] - 1, dofs * connect[:, 1], dofs * connect[:, 2] -
        1, dofs * connect[:, 2], dofs * connect[:, 3] - 1,
        dofs * connect[:, 3], dofs * connect[:, 4] - 1, dofs * connect[:, 4]
    ],
                         dtype=int) - 1).T
    for el in range(len(connect)):
        Ke, Me = fc.matricesQ4(el, coord, connect, E, v, rho)
        ind = ind_dofs[el, :]
        dKe = p_par * (xval[el]**(p_par - 1)) * (1 - x_min_k) * Ke
        dCe = alpha * Me + beta * dKe
        if xval[el] > 0.1:
            dMe = q_par * (xval[el]**(q_par - 1)) * (1 - x_min_m) * Me
        else:
            dMe = ((9 * 3.512e7 * xval[el]**8 - 10 * 2.081e8 * xval[el]**9) *
                   (1 - x_min_m)) * Me
        dKed = dKe + omega * 1j * dCe - (omega**2) * dMe
        a = 1j * (disp_vector[ind].reshape(1, 8) @ dKed
                  @ disp_vector[ind].reshape(8, 1))[0, 0]
        deriv_f[el, 0] = -0.5 * omega * a.real
        #Log Scale
        deriv_f[el, 0] = 10.0 * deriv_f[el, 0] * np.log10(np.exp(1)) / fvirg
    return deriv_f