def elast_hex8(coord, params): """Hexaedral element with 8 nodes for classic elasticity Parameters ---------- coord : coord Coordinates of the element. params : list List with material parameters in the following order: [Young modulus, Poisson coefficient, density]. Returns ------- stiff_mat : ndarray (float) Local stifness matrix. mass_mat : ndarray (float) Local mass matrix. """ E, nu, rho = params C = fem.elast_mat((E, nu)) stiff_mat = np.zeros((24, 24)) mass_mat = np.zeros((24, 24)) gpts, gwts = gau.gauss_nd(2, ndim=3) for cont in range(gpts.shape[0]): r = gpts[cont, 0] s = gpts[cont, 1] t = gpts[cont, 2] H, B, det = fem.elast_diff_3d(r, s, t, coord) factor = det * gwts[cont] stiff_mat += factor * (B.T @ C @ B) mass_mat += rho*factor * (H.T @ H) return stiff_mat, mass_mat
def elast_axi_quad9(coord, params): """ Quadrilateral element with 9 nodes for classic elasticity under plane-strain Parameters ---------- coord : coord Coordinates of the element. params : list List with material parameters in the following order: [Young modulus, Poisson coefficient, density]. Returns ------- stiff_mat : ndarray (float) Local stifness matrix. mass_mat : ndarray (float) Local mass matrix. """ E, nu, rho = params C = fem.elast_mat_axi((E, nu)) stiff_mat = np.zeros((18, 18)) mass_mat = np.zeros((18, 18)) gpts, gwts = gau.gauss_nd(3, ndim=2) for cont in range(gpts.shape[0]): r = gpts[cont, 0] s = gpts[cont, 1] H, B, det = fem.elast_diff_axi(r, s, coord, fem.shape_quad9) factor = det * gwts[cont] stiff_mat += factor * (B.T @ C @ B) mass_mat += rho*factor * (H.T @ H) return stiff_mat, mass_mat
def elast_quad9(coord, params): """ Quadrilateral element with 9 nodes for classic elasticity under plane-strain Parameters ---------- coord : coord Coordinates of the element. params : list List with material parameters in the following order: [Young modulus, Poisson coefficient, density]. Returns ------- stiff_mat : ndarray (float) Local stifness matrix. mass_mat : ndarray (float) Local mass matrix. """ stiff_mat = np.zeros((18, 18)) mass_mat = np.zeros((18, 18)) C = fem.umat(params[:2]) if len(params) == 2: dens = 1 else: dens = params[-1] gpts, gwts = gau.gauss_nd(3, ndim=2) for cont in range(gpts.shape[0]): # pylint: disable=E1136 # pylint/issues/3139 r, s = gpts[cont, :] H, B, det = fem.elast_diff_2d(r, s, coord, fem.shape_quad9) factor = det * gwts[cont] stiff_mat += factor * (B.T @ C @ B) mass_mat += dens * factor * (H.T @ H) return stiff_mat, mass_mat
def test_gauss_nd(): """Test for ND Gauss integration""" npts = 4 ndim = 2 pts, wts = gauss.gauss_nd(npts, ndim=ndim) fun = lambda x, y: 3*x*y**2 - x**3 inte = 0.0 for cont, pt in enumerate(pts): x, y = pt inte += wts[cont] * fun(x, y) assert np.isclose(inte, 0) npts = 10 ndim = 2 pts, wts = gauss.gauss_nd(npts, ndim=ndim) fun = lambda x, y: np.exp(-x**2 - y**2) inte = 0.0 for cont, pt in enumerate(pts): x, y = pt inte += wts[cont] * fun(x, y) assert np.isclose(inte, 2.23098514140413)
def elast_quad4(coord, params): """Quadrilateral element with 4 nodes Parameters ---------- coord : ndarray Coordinates for the nodes of the element (4, 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 (8, 8). mass_mat : ndarray Local mass matrix for the element (8, 8). Examples -------- >>> coord = np.array([[-1, -1], [1, -1], [1, 1], [-1, 1]]) >>> params = [8/3, 1/3, 1] >>> stiff, mass = uel4nquad(coord, params) >>> stiff_ex = 1/6 * np.array([ ... [ 8, 3, -5, 0, -4, -3, 1, 0], ... [ 3, 8, 0, 1, -3, -4, 0, -5], ... [-5, 0, 8, -3, 1, 0, -4, 3], ... [ 0, 1, -3, 8, 0, -5, 3, -4], ... [-4, -3, 1, 0, 8, 3, -5, 0], ... [-3, -4, 0, -5, 3, 8, 0, 1], ... [ 1, 0, -4, 3, -5, 0, 8, -3], ... [ 0, -5, 3, -4, 0, 1, -3, 8]]) >>> mass_ex = 1/9 * np.array([ ... [4, 0, 2, 0, 1, 0, 2, 0], ... [0, 4, 0, 2, 0, 1, 0, 2], ... [2, 0, 4, 0, 2, 0, 1, 0], ... [0, 2, 0, 4, 0, 2, 0, 1], ... [1, 0, 2, 0, 4, 0, 2, 0], ... [0, 1, 0, 2, 0, 4, 0, 2], ... [2, 0, 1, 0, 2, 0, 4, 0], ... [0, 2, 0, 1, 0, 2, 0, 4]]) >>> np.allclose(stiff, stiff_ex) True >>> np.allclose(mass, mass_ex) True """ stiff_mat = np.zeros([8, 8]) mass_mat = np.zeros([8, 8]) C = fem.umat(params[:2]) if len(params) == 2: dens = 1 else: dens = params[-1] gpts, gwts = gau.gauss_nd(2) for cont in range(gpts.shape[0]): # pylint: disable=E1136 # pylint/issues/3139 r, s = gpts[cont, :] H, B, det = fem.elast_diff_2d(r, s, coord, fem.shape_quad4) factor = det * gwts[cont] stiff_mat += factor * (B.T @ C @ B) mass_mat += dens*factor* (H.T @ H) return stiff_mat, mass_mat
def uel4nquad(coord, params): """Quadrilateral element with 4 nodes Parameters ---------- coord : ndarray Coordinates for the nodes of the element (4, 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 (8, 8). mass_mat : ndarray Local mass matrix for the element (8, 8). Examples -------- >>> coord = np.array([[-1, -1], [1, -1], [1, 1], [-1, 1]]) >>> params = [8/3, 1/3, 1] >>> stiff, mass = uel4nquad(coord, params) >>> stiff_ex = 1/6 * np.array([ ... [ 8, 3, -5, 0, -4, -3, 1, 0], ... [ 3, 8, 0, 1, -3, -4, 0, -5], ... [-5, 0, 8, -3, 1, 0, -4, 3], ... [ 0, 1, -3, 8, 0, -5, 3, -4], ... [-4, -3, 1, 0, 8, 3, -5, 0], ... [-3, -4, 0, -5, 3, 8, 0, 1], ... [ 1, 0, -4, 3, -5, 0, 8, -3], ... [ 0, -5, 3, -4, 0, 1, -3, 8]]) >>> mass_ex = 1/9 * np.array([ ... [4, 0, 2, 0, 1, 0, 2, 0], ... [0, 4, 0, 2, 0, 1, 0, 2], ... [2, 0, 4, 0, 2, 0, 1, 0], ... [0, 2, 0, 4, 0, 2, 0, 1], ... [1, 0, 2, 0, 4, 0, 2, 0], ... [0, 1, 0, 2, 0, 4, 0, 2], ... [2, 0, 1, 0, 2, 0, 4, 0], ... [0, 2, 0, 1, 0, 2, 0, 4]]) >>> np.allclose(stiff, stiff_ex) True >>> np.allclose(mass, mass_ex) True """ stiff_mat = np.zeros([8, 8]) mass_mat = np.zeros([8, 8]) C = fem.umat(params[:2]) if len(params) == 2: dens = 1 else: dens = params[-1] gpts, gwts = gau.gauss_nd(2) for i in range(gpts.shape[0]): ri = gpts[i, 0] si = gpts[i, 1] ddet, B = fem.stdm4NQ(ri, si, coord) N = fem.sha4(ri, si) factor = ddet * gwts[i] stiff_mat += factor * (B.T @ C @ B) mass_mat += dens * factor * (N.T @ N) return stiff_mat, mass_mat