def solids_GUI(compute_strains=False, plot_contours=True): """ Run a complete workflow for a Finite Element Analysis Parameters ---------- compute_strains : Bool (optional) Boolean variable to compute Strains and Stresses at nodes. By default it is False. plot_contours : Bool (optional) Boolean variable to plot contours of the computed variables. By default it is True. Returns ------- UC : ndarray (nnodes, 2) Displacements at nodes. E_nodes : ndarray (nnodes, 3), optional Strains at nodes. It is returned when `compute_strains` is True. S_nodes : ndarray (nnodes, 3), optional Stresses at nodes. It is returned when `compute_strains` is True. """ folder = pre.initial_params() start_time = datetime.now() echo = False #%% PRE-PROCESSING nodes, mats, elements, loads = pre.readin(folder=folder) if echo: pre.echomod(nodes, mats, elements, loads, folder=folder) DME , IBC , neq = ass.DME(nodes, elements) print("Number of nodes: {}".format(nodes.shape[0])) print("Number of elements: {}".format(elements.shape[0])) print("Number of equations: {}".format(neq)) #%% SYSTEM ASSEMBLY KG = ass.assembler(elements, mats, nodes, neq, DME) RHSG = ass.loadasem(loads, IBC, neq) #%% SYSTEM SOLUTION UG = sol.static_sol(KG, RHSG) if not(np.allclose(KG.dot(UG)/KG.max(), RHSG/KG.max())): print("The system is not in equilibrium!") end_time = datetime.now() print('Duration for system solution: {}'.format(end_time - start_time)) #%% POST-PROCESSING start_time = datetime.now() UC = pos.complete_disp(IBC, nodes, UG) E_nodes, S_nodes = None, None if compute_strains: E_nodes, S_nodes = pos.strain_nodes(nodes , elements, mats, UC) if plot_contours: pos.fields_plot(elements, nodes, UC, E_nodes=E_nodes, S_nodes=S_nodes) end_time = datetime.now() print('Duration for post processing: {}'.format(end_time - start_time)) print('Analysis terminated successfully!') return UC, E_nodes, S_nodes if compute_strains else UC
def test_strain_nodes(): """Tests for strain/stress calculation at nodes""" # 2 x 2 mesh with axial load and rollers on the sides mats = np.array([[8 / 3, 1 / 3]]) nodes = np.array([[0, -1, -1], [1, 0, -1], [2, 1, -1], [3, -1, 0], [4, 0, 0], [5, 1, 0], [6, -1, 1], [7, 0, 1], [8, 1, 1]]) elements = np.array([[0, 1, 0, 0, 1, 4, 3], [1, 1, 0, 1, 2, 5, 4], [2, 1, 0, 3, 4, 7, 6], [3, 1, 0, 4, 5, 8, 7]]) UC = np.array([[0, 0], [0, 0], [0, 0], [0, 1], [0, 1], [0, 1], [0, 2], [0, 2], [0, 2]]) E_nodes, S_nodes = pos.strain_nodes(nodes, elements, mats, UC) E_exact = np.zeros((9, 3)) E_exact[:, 1] = 1 S_exact = np.zeros((9, 3)) S_exact[:, 0] = 1 S_exact[:, 1] = 3 assert np.allclose(E_exact, E_nodes) assert np.allclose(S_exact, S_nodes)
def solids_GUI(plot_contours=True, compute_strains=False, folder=None): """ Run a complete workflow for a Finite Element Analysis Parameters ---------- plot_contours : Bool (optional) Boolean variable to plot contours of the computed variables. By default it is True. compute_strains : Bool (optional) Boolean variable to compute Strains and Stresses at nodes. By default it is False. folder : string (optional) String with the path to the input files. If not provided it would ask for it in a pop-up window. Returns ------- UC : ndarray (nnodes, 2) Displacements at nodes. E_nodes : ndarray (nnodes, 3), optional Strains at nodes. It is returned when `compute_strains` is True. S_nodes : ndarray (nnodes, 3), optional Stresses at nodes. It is returned when `compute_strains` is True. """ if folder is None: folder = pre.initial_params() start_time = datetime.now() echo = False # Pre-processing nodes, mats, elements, loads = pre.readin(folder=folder) if echo: pre.echomod(nodes, mats, elements, loads, folder=folder) DME, IBC, neq = ass.DME(nodes, elements) print("Number of nodes: {}".format(nodes.shape[0])) print("Number of elements: {}".format(elements.shape[0])) print("Number of equations: {}".format(neq)) # System assembly KG = ass.assembler(elements, mats, nodes, neq, DME) RHSG = ass.loadasem(loads, IBC, neq) # System solution UG = sol.static_sol(KG, RHSG) if not (np.allclose(KG.dot(UG) / KG.max(), RHSG / KG.max())): print("The system is not in equilibrium!") end_time = datetime.now() print('Duration for system solution: {}'.format(end_time - start_time)) # Post-processing start_time = datetime.now() UC = pos.complete_disp(IBC, nodes, UG) E_nodes, S_nodes = None, None if compute_strains: E_nodes, S_nodes = pos.strain_nodes(nodes, elements, mats, UC) if plot_contours: pos.fields_plot(elements, nodes, UC, E_nodes=E_nodes, S_nodes=S_nodes) end_time = datetime.now() print('Duration for post processing: {}'.format(end_time - start_time)) print('Analysis terminated successfully!') return (UC, E_nodes, S_nodes) if compute_strains else UC
t2=time.time() print("system solution ", t2-t1) end_time = dt.now() #print('Duration for system solution: {}'.format(end_time - start_time)) # Post-processing start_time = dt.now() UC = pos.complete_disp(IBC, nodes, UG) # uc are x and y displacements #UC2 = pos.complete_disp(IBC, nodes, UG2) # uc are x and y displacements E_nodes, S_nodes = None, None if compute_strains: E_nodes, S_nodes = pos.strain_nodes(nodes, elements, mats, UC) #E_nodes2,S_nodes2=pos.strain_nodes(nodes, elements, mats, UC2) if plot_contours: pos.fields_plot(elements, nodes, UC, E_nodes=E_nodes, S_nodes=S_nodes) # some matplotlib internal function to make it look smoother end_time = dt.now() # calculation of principal stresses ## are signes importnatn here??? # chek this and others ## https://wp.optics.arizona.edu/optomech/wp-content/uploads/sites/53/2016/10/OPTI_222_W21.pdf sig_x=S_nodes[:,0] sig_y=S_nodes[:,1] tau_xy=S_nodes[:,2]
def solids_auto(data, plot_contours=True, compute_strains=False): """ Run a complete workflow for a Finite Element Analysis Parameters ---------- data : dict Simulation data composed of nodes, constrains, elements, materials and loads. plot_contours : Bool (optional) Boolean variable to plot contours of the computed variables. By default it is True. compute_strains : Bool (optional) Boolean variable to compute Strains and Stresses at nodes. By default it is False. Returns ------- UC : ndarray (nnodes, 2) Displacements at nodes. E_nodes : ndarray (nnodes, 3), optional Strains at nodes. It is returned when `compute_strains` is True. S_nodes : ndarray (nnodes, 3), optional Stresses at nodes. It is returned when `compute_strains` is True. """ # Retrieving data nodes = data["nodes"] cons = data["cons"] elements = data["elements"] mats = data["mats"] loads = data["loads"] # Pre-processing assem_op, bc_array, neq = ass.DME(cons, elements) print("Number of nodes: {}".format(nodes.shape[0])) print("Number of elements: {}".format(elements.shape[0])) print("Number of equations: {}".format(neq)) # System assembly stiff_mat, _ = ass.assembler(elements, mats, nodes, neq, assem_op) rhs_vec = ass.loadasem(loads, bc_array, neq) # System solution start_time = datetime.now() disp = sol.static_sol(stiff_mat, rhs_vec) if not np.allclose( stiff_mat.dot(disp) / stiff_mat.max(), rhs_vec / stiff_mat.max()): print("The system is not in equilibrium!") end_time = datetime.now() print('Duration for system solution: {}'.format(end_time - start_time)) # Post-processing start_time = datetime.now() disp_complete = pos.complete_disp(bc_array, nodes, disp) strain_nodes, stress_nodes = None, None if compute_strains: strain_nodes, stress_nodes = pos.strain_nodes(nodes, elements, mats, disp_complete) if plot_contours: pos.fields_plot(elements, nodes, disp_complete, E_nodes=strain_nodes, S_nodes=stress_nodes) end_time = datetime.now() print('Duration for post processing: {}'.format(end_time - start_time)) print('Analysis terminated successfully!') if compute_strains: return (disp_complete, strain_nodes, stress_nodes) else: return disp_complete
def solids_GUI(plot_contours=True, compute_strains=False, folder=None): """ Run a complete workflow for a Finite Element Analysis Parameters ---------- plot_contours : Bool (optional) Boolean variable to plot contours of the computed variables. By default it is True. compute_strains : Bool (optional) Boolean variable to compute Strains and Stresses at nodes. By default it is False. folder : string (optional) String with the path to the input files. If not provided it would ask for it in a pop-up window. Returns ------- UC : ndarray (nnodes, 2) Displacements at nodes. E_nodes : ndarray (nnodes, 3), optional Strains at nodes. It is returned when `compute_strains` is True. S_nodes : ndarray (nnodes, 3), optional Stresses at nodes. It is returned when `compute_strains` is True. """ if folder is None: folder = pre.initial_params() start_time = datetime.now() echo = False # Pre-processing nodes, mats, elements, loads = pre.readin(folder=folder) if echo: pre.echomod(nodes, mats, elements, loads, folder=folder) assem_op, bc_array, neq = ass.DME(nodes[:, -2:], elements) print("Number of nodes: {}".format(nodes.shape[0])) print("Number of elements: {}".format(elements.shape[0])) print("Number of equations: {}".format(neq)) # System assembly stiff_mat, _ = ass.assembler(elements, mats, nodes[:, :3], neq, assem_op) rhs_vec = ass.loadasem(loads, bc_array, neq) # System solution disp = sol.static_sol(stiff_mat, rhs_vec) if not np.allclose( stiff_mat.dot(disp) / stiff_mat.max(), rhs_vec / stiff_mat.max()): print("The system is not in equilibrium!") end_time = datetime.now() print('Duration for system solution: {}'.format(end_time - start_time)) # Post-processing start_time = datetime.now() disp_complete = pos.complete_disp(bc_array, nodes, disp) strain_nodes, stress_nodes = None, None if compute_strains: strain_nodes, stress_nodes = pos.strain_nodes(nodes, elements, mats, disp_complete) if plot_contours: pos.fields_plot(elements, nodes, disp_complete, E_nodes=strain_nodes, S_nodes=stress_nodes) end_time = datetime.now() print('Duration for post processing: {}'.format(end_time - start_time)) print('Analysis terminated successfully!') if compute_strains: return (disp_complete, strain_nodes, stress_nodes) else: return disp_complete
UG_sol, rx = custom_solver( KG, RHSG, mask_area, verbose=True ) #solver with constratinst to zero translation and zero rotation #UG=UG_sol[0] #UG = sol.static_sol(KG, RHSG,nodes) #no constraints #UG1,rx = sol.static_sol_cond(KG1, RHSG,mask_area) #solver with constratinst to zero translation and zero rotation #norm1=np.sqrt(np.sum((RHSG-np.dot(KG.toarray(),UG[0]))**2)) # same norm as returned by sparse solver #norm2=np.sqrt(np.sum((RHSG-np.dot(KG1,UG1[0]))**2))# same norm as returned by sparse solver if not (np.allclose(KG.dot(UG_sol) / KG.max(), RHSG / KG.max())): print("The system is not in equilibrium!") UC = pos.complete_disp(IBC, nodes, UG_sol) # uc are x and y displacements E_nodes, S_nodes = pos.strain_nodes(nodes, elements, mats, UC) # stresses and strains stress_tensor = calculate_stress_tensor( S_nodes, nodes, dims=mask_area.shape) # assembling the stress tensor #pos.fields_plot(elements, nodes, UC, E_nodes=E_nodes, S_nodes=S_nodes) ##### # average shear and normal stress on the colony area avg_shear, avg_normal_stress = calculate_mean_stress_measure( mask_area, stress_tensor, ps_new) ### other possible stress measures, just for a nice picture sigma_max, sigma_min, tau_max, phi_n, phi_shear, sigma_avg = all_stress_measures( S_nodes, nodes, dims=mask_area.shape) sigma_max_abs = np.maximum( np.abs(sigma_min), np.abs(sigma_max)) ### highest possible norm of the stress tensor