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
""" """ from __future__ import division, print_function import numpy as np from datetime import datetime import solidspy.preprocesor as pre import solidspy.postprocesor as pos import solidspy.assemutil as ass import solidspy.solutil as sol start_time = datetime.now() #%% PRE-PROCESSING nodes, mats, elements, loads = pre.readin() 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, sparse=False) 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))
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
np.savetxt(os.path.join(folder,"nodes.txt"),nodes,fmt="%i",delimiter="\t") np.savetxt(os.path.join(folder,"loads.txt"),loads,fmt="%.3f",delimiter="\t") np.savetxt(os.path.join(folder,"eles.txt"),elements,fmt="%i",delimiter="\t") t2=time.time() print("grid assembly ", t2-t1) start_time = dt.now() echo = False compute_strains=True plot_contours=False 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) # boundary conditions asembly?? # DME #IBC list of "equations in x y direction for each node, -1 indicates no equations of movement, as completly fixed --> related to boundary conditions # neq total number of equations # DME is like list of independent equations per element(square, so just rearanged IBC for elements,side node zeros are at the end because of fixed length( for other element shape= # # # print("Number of nodes: {}".format(nodes.shape[0])) print("Number of elements: {}".format(elements.shape[0])) print("Number of equations: {}".format(neq))
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