y2 = np.sin(x2) / np.cos(1) - x2 plt.plot(x2, y2, 'k--') plt.title('1D FEM') plt.xlabel('x') plt.ylabel('u') #plt.savefig("1D_Fig3.png") plt.show() if __name__ == '__main__': # Preprocessor nodes, elements = preprocessor() # Solver numberOfNodes = nodes.shape[0] K, b = totalmatrices(nodes, elements) # Take account of Dirichlet boundary condition. # Assumption Dirichlet boundary condition u0 = 0 # Assumption diri = [[node number, value]] example: diri = [[0, 0]] diris = [[0, 0]] #K, b = fem.dis_to_force(diris, numberOfNodes, K, b) K, b = fem.dis_to_force2(diris, K, b) u = solve(K, b) # Postprocessor postprocessor(nodes) # Visualize solution.
""" # Solver: Method 1 K = array([[9, 5, -2, -3, -7, -2, 0, 0], [5, 9, -2, -7, -3, -2, 0, 0], [-2, -2, 9, 0, 0, 5, -7, -3], [-3, -7, 0, 9, 5, 0, -2, -2], [-7, -3, 0, 5, 9, 0, -2, -2], [-2, -2, 5, 0, 0, 9, -3, -7], [0, 0, -7, -2, -2, -3, 9, 5], [0, 0, -3, -2, -2, -7, 5, 9] ]) * 50000 / 2.6 unval = 100 # unknown value f = array([unval, unval, unval, 0, 10, unval, 10, 0]) # "discon" is a list of displcement constraint. # discon = [[index number in the K matrix, value], ...] discon = [[0, 0], [1, 0], [2, 0], [5, 0]] K, f = fem.dis_to_force2(discon, K, f) d1 = solve(K, f) d1 = d1.reshape((4, 2)) new_nodes1 = nodes + d1 * 500 """ # Solver: Method 2 # Convert displacement constraint into force constraint. # NewK is a converted matrix. newK = array([[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 9, 5, 0, -2, -2], [0, 0, 0, 5, 9, 0, -2, -2], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, -2, -2, 0, 9, 5], [0, 0, 0, -2, -2, 0, 5, 9]])*50000/2.6
plt.plot(x2, y2, 'k--') plt.title('1D FEM') plt.xlabel('x') plt.ylabel('u') #plt.savefig("1D_Fig3.png") plt.show() if __name__ == '__main__': # Preprocessor nodes, elements = preprocessor() # Solver numberOfNodes = nodes.shape[0] K, b = totalmatrices(nodes, elements) # Take account of Dirichlet boundary condition. # Assumption Dirichlet boundary condition u0 = 0 # Assumption diri = [[node number, value]] example: diri = [[0, 0]] diris = [[0, 0]] #K, b = fem.dis_to_force(diris, numberOfNodes, K, b) K, b = fem.dis_to_force2(diris, K, b) u = solve(K, b) # Postprocessor postprocessor(nodes) # Visualize solution.
# Solver # Young's modulus and Poisson's ration of soft iron Young = 200*10**3 # MPa Poisson = 0.3 D = createDmatrix() K, B = totalmatrices(nodes, elements) unval = 100 # unkown value f = array([unval, unval, unval, 0, 10, unval, 10, 0]) # "discon" is a list of displcement constraint. # ex) discon = [[index number in the K matrix, value], ...] discon = [[0, 0], [1, 0], [2, 0], [5, 0]] K, f = fem.dis_to_force2(discon, K, f) d = solve(K, f) d = d.reshape((d.shape[0]/2, 2)) dis_scale = 500 # displacement scale new_nodes = nodes + d * dis_scale #eps = total_strain() # Print Debug #print "matrixK\n", K #print "displacement\n", d # Postprocessor #plot_displacement(nodes, new_nodes)