stiffness = assembly_quads_stress_strain(nodes=nodes, elements=elements, thickness=1.0, elasticity_matrix=d) print("Evaluating force...") def force_func(node): if abs(node[0]) < 0.0000001: return array([0.0, -q / m]) else: return array([0.0, 0.0]) force = nodal_force(nodes=nodes, freedom=2, force_function=force_func) print("Evaluating boundary conditions...") for i in range(len(nodes)): if abs(l - nodes[i, 0]) < 0.0000001: assembly_initial_value(stiffness, force, 2 * i, 0.0) assembly_initial_value(stiffness, force, 2 * i + 1, 0.0) print("Solving a system of linear equations") x = spsolve(stiffness, force) u = x[0::2] v = x[1::2] print(min(u), " <= u <= ", max(u)) print(min(v), " <= Y <= ", max(v)) draw_vtk(nodes, elements, u, title="u", show_labels=True) draw_vtk(nodes, elements, v, title="v", show_labels=True)
d = plane_strain_isotropic(e, nu) print(d) (nodes, elements) = rectangular_triangles(x_count=n, y_count=m, x_origin=0.0, y_origin=-c, width=l, height=2.0 * c) stiffness = assembly_triangles_stress_strain(nodes, elements, d) dimension = stiffness.shape[0] force = zeros(dimension) for i in range(len(nodes)): if abs(nodes[i, 0]) < 0.0000001: force[2 * i + 1] = -q / m for i in range(len(nodes)): if abs(l - nodes[i, 0]) < 0.0000001: for j in range(dimension): if stiffness[2 * i, j] != 0.0: stiffness[2 * i, j] = 0.0 if stiffness[j, 2 * i] != 0.0: stiffness[j, 2 * i] = 0.0 if stiffness[2 * i + 1, j] != 0.0: stiffness[2 * i + 1, j] = 0.0 if stiffness[j, 2 * i + 1] != 0.0: stiffness[j, 2 * i + 1] = 0.0 stiffness[2 * i, 2 * i] = 1.0 force[2 * i] = 0.0 stiffness[2 * i + 1, 2 * i + 1] = 1.0 force[2 * i + 1] = 0.0 stiffness = stiffness.tocsr() x = spsolve(stiffness, force) print(min(x[0::2]), " <= X <= ", max(x[0::2])) print(min(x[1::2]), " <= Y <= ", max(x[1::2])) draw_vtk(nodes, elements, x[0::2], title="u", show_labels=True) draw_vtk(nodes, elements, x[1::2], title="v", show_labels=True)
], [ 0.0, shape_dy[0], 0.0, shape_dy[1], 0.0, shape_dy[2], 0.0, shape_dy[3] ], [ shape_dy[0], shape_dx[0], shape_dy[1], shape_dx[1], shape_dy[2], shape_dx[2], shape_dy[3], shape_dx[3] ]]) sigma = d.dot(b).dot(displacement) sigma_x[element[i]] += sigma[0] sigma_y[element[i]] += sigma[1] tau_xy[element[i]] += sigma[2] adjacent[element[i]] += 1.0 sigma_x /= adjacent sigma_y /= adjacent tau_xy /= adjacent print(min(u), " <= u <= ", max(u)) print(min(v), " <= v <= ", max(v)) print(min(sigma_x), " <= sigma x <= ", max(sigma_x)) print(min(sigma_y), " <= sigma y <= ", max(sigma_y)) print(min(tau_xy), " <= tau xy <= ", max(tau_xy)) print("Analytical sigma: " + str(e * alpha / (1 - nu))) draw_vtk(nodes, elements, u, title="u", show_labels=True) draw_vtk(nodes, elements, v, title="v", show_labels=True) draw_vtk(nodes, elements, sigma_x, title="sigma x", show_labels=True) draw_vtk(nodes, elements, sigma_y, title="sigma y", show_labels=True) draw_vtk(nodes, elements, tau_xy, title="tau xy", show_labels=True)
elements=elements, thickness=1.0, freedom=3, force_function=force_func, gauss_order=3) print("Evaluating boundary conditions...") for i in range(len(nodes)): if (abs(nodes[i, 0] - 0) < 0.0000001) or (abs(nodes[i, 0] - a) < 0.0000001) or ( abs(nodes[i, 1] - 0) < 0.0000001) or (abs(nodes[i, 1] - a) < 0.0000001): assembly_initial_value(stiffness, force, 3 * i, 0.0) assembly_initial_value(stiffness, force, 3 * i + 1, 0.0) assembly_initial_value(stiffness, force, 3 * i + 2, 0.0) print("Solving a system of linear equations") x = spsolve(stiffness, force) w = x[0::3] theta_x = x[1::3] theta_y = x[2::3] print(min(w), " <= w <= ", max(w)) print(min(theta_x), " <= theta x <= ", max(theta_x)) print(min(theta_y), " <= theta y <= ", max(theta_y)) print("Analytical bending: ", 0.00126 * q * a**4.0 * 12.0 * (1.0 - nu**2.0) / (e * h**3.0)) draw_vtk(nodes, elements, w, title="w", show_labels=True) draw_vtk(nodes, elements, theta_x, title="theta x", show_labels=True) draw_vtk(nodes, elements, theta_y, title="theta y", show_labels=True)
n = 51 # nodes in the first direction of computational domain m = 11 # nodes in the second direction of computational domain d = plane_strain_isotropic(e, nu) print(d) (nodes, elements) = rectangular_quads(x_count=n, y_count=m, x_origin=-l, y_origin=-c, width=2.0 * l, height=2.0 * c) stiffness = assembly_quads_stress_strain(nodes, elements, d) dimension = stiffness.shape[0] force = zeros(dimension) for i in range(len(nodes)): if abs(c - nodes[i, 1]) < 0.0000001: force[2 * i + 1] = -(q * 2.0 * l / (n - 1)) if (abs(l - nodes[i, 0]) < 0.0000001) or (abs(-l - nodes[i, 0]) < 0.0000001): force[2 * i + 1] = -(q * 2.0 * l / (n - 1)) / 2.0 for i in range(len(nodes)): if abs(-c - nodes[i, 1]) < 0.0000001 and (abs(l - nodes[i, 0]) < 0.0000001 or abs(-l - nodes[i, 0]) < 0.0000001): for j in range(dimension): if stiffness[2 * i + 1, j] != 0.0: stiffness[2 * i + 1, j] = 0.0 if stiffness[j, 2 * i + 1] != 0.0: stiffness[j, 2 * i + 1] = 0.0 stiffness[2 * i + 1, 2 * i + 1] = 1.0 force[2 * i + 1] = 0.0 stiffness = stiffness.tocsr() x, info = cg(stiffness, force, tol=1e-8) print(min(x[0::2]), " <= X <= ", max(x[0::2])) print(min(x[1::2]), " <= Y <= ", max(x[1::2])) draw_vtk(nodes, elements, x[0::2], title="u") draw_vtk(nodes, elements, x[1::2], title="v")
sigma_x /= adjacent sigma_y /= adjacent tau_xy /= adjacent mises /= adjacent print(min(u), " <= u <= ", max(u)) print(min(v), " <= v <= ", max(v)) print(min(sigma_x), " <= sigma x <= ", max(sigma_x)) print(min(sigma_y), " <= sigma y <= ", max(sigma_y)) print(min(tau_xy), " <= tau xy <= ", max(tau_xy)) # draw_vtk(nodes, elements, u, title="u", show_labels=True) # draw_vtk(nodes, elements, v, title="v", show_labels=True) draw_vtk(nodes, elements, sigma_x, title="sigma x", show_labels=False, use_gray=True, contours_count=0, colors_count=5) draw_vtk(nodes, elements, sigma_y, title="sigma y", show_labels=False, use_gray=True, contours_count=0, colors_count=5) draw_vtk(nodes, elements, tau_xy, title="tau xy",
for i in range(element_dimension): ii = element[int(i / freedom)] * freedom + i % freedom for j in range(i, element_dimension): jj = element[int(j / freedom)] * freedom + j % freedom geometric[ii, jj] += kg[i, j] if ii != jj: geometric[jj, ii] = geometric[ii, jj] print("Assembly is done") active = range(dimension) for i in range(len(nodes)): if (abs(nodes[i, 0] + a/2.0) < 0.0000001) or (abs(nodes[i, 0] - a/2.0) < 0.0000001) or (abs(nodes[i, 1] + a/2.0) < 0.0000001) or (abs(nodes[i, 1] - a/2.0) < 0.0000001): active.remove(freedom * i) print ("Boundary conditions are processed") geometric = lil_matrix(geometric.tocsr()[:, active]) geometric = lil_matrix(geometric.tocsc()[active, :]) geometric = geometric.tocsr() stiffness = lil_matrix(stiffness.tocsr()[:, active]) stiffness = lil_matrix(stiffness.tocsc()[active, :]) stiffness = stiffness.tocsr() print ("Matrices are converted") vals, vecs = eigsh(A=stiffness, M=geometric, sigma=0.0, which='LM') print(vals) for i in range(len(vals)): x = zeros(dimension) x[active] = vecs[:, i] w = array(x[0::freedom]) draw_vtk(nodes=hstack((nodes, w.reshape(len(w), 1) / 50.0)), elements=elements, values=w, title="w, T = " + str(vals[i]), show_labels=False, show_axes=True, use_gray=True, contours_count=0, colors_count=5)
# active.remove(freedom * i + 1) # active.remove(freedom * i + 2) # active.remove(freedom * i + 3) active.remove(freedom * i + 4) if (abs(nodes[i, 1] - 0) < 0.0000001) or (abs(nodes[i, 1] - b) < 0.0000001): # active.remove(freedom * i) active.remove(freedom * i + 1) # active.remove(freedom * i + 2) active.remove(freedom * i + 3) # active.remove(freedom * i + 4) if (abs(nodes[i, 0] - 0) < 0.0000001) or (abs(nodes[i, 0] - a) < 0.0000001) or ( abs(nodes[i, 1] - 0) < 0.0000001) or (abs(nodes[i, 1] - b) < 0.0000001): active.remove(freedom * i + 2) geometric = lil_matrix(geometric.tocsr()[:, active]) geometric = lil_matrix(geometric.tocsc()[active, :]) geometric = geometric.tocsr() stiffness = lil_matrix(stiffness.tocsr()[:, active]) stiffness = lil_matrix(stiffness.tocsc()[active, :]) stiffness = stiffness.tocsr() vals, vecs = eigsh(A=stiffness, M=geometric, sigma=0.0, which='LM') print(vals) for i in range(6): x = zeros(dimension) x[active] = vecs[:, i] w = x[2::freedom] draw_vtk(nodes, elements, w, title="w", show_labels=True)
geometric[jj, ii] = geometric[ii, jj] print("Assembly is done") active = range(dimension) for i in range(len(nodes)): if (abs(nodes[i, 0] - 0) < 0.0000001) or (abs(nodes[i, 0] - a) < 0.0000001) or ( abs(nodes[i, 1] - 0) < 0.0000001) or (abs(nodes[i, 1] - a / factor) < 0.0000001): active.remove(freedom * i) print("Boundary conditions are processed") # print (active) geometric = lil_matrix(geometric.tocsr()[:, active]) geometric = lil_matrix(geometric.tocsc()[active, :]) geometric = geometric.tocsr() stiffness = lil_matrix(stiffness.tocsr()[:, active]) stiffness = lil_matrix(stiffness.tocsc()[active, :]) stiffness = stiffness.tocsr() print("Matrices are converted") vals, vecs = eigsh(A=stiffness, M=geometric, sigma=0.0, which='LM') print(vals) x = zeros(dimension) x[active] = vecs[:, 0] w = array(x[0::freedom]) draw_vtk(nodes=hstack((nodes, w.reshape(len(w), 1) / 100.0)), elements=elements, values=w, title="w", show_labels=True, show_axes=True)