def _analyze_common_structural_geometry(step, geometry, mesh_sizes, N, Vx, Vy, Mxx, Myy, Mzz): mesh = geometry.create_mesh(mesh_sizes=[mesh_sizes]) section = CrossSection(geometry, mesh) finite_elements_number = len(section.mesh_elements) if finite_elements_number > MAX_FINITE_ELEMENTS_NUMBER: return False, None, None, None, None, None, None, None, None, None, None elif finite_elements_number < MAX_FINITE_ELEMENTS_NUMBER and step == 'checking': return True, None, None, None, None, None, None, None, None, None, None else: section.calculate_geometric_properties() section.calculate_warping_properties() loadcase = section.calculate_stress(N=N, Vx=Vx, Vy=Vy, Mxx=Mxx, Myy=Myy, Mzz=Mzz) nodes = section.mesh_nodes stresses = loadcase.get_stress()[0] area = section.get_area() ixx_c, iyy_c, ixy_c = section.get_ic() torsion_constant = section.get_j() warping_constant = section.get_gamma() elastic_centroid = section.get_c() centroidal_shear_center = section.get_sc() return True, nodes, stresses, area, ixx_c, iyy_c, ixy_c, torsion_constant, warping_constant, \ elastic_centroid, centroidal_shear_center
mesh = geometry.create_mesh(mesh_sizes=[5, 20]) # create a CrossSection object - take care to list the materials in the same order as entered into # the MergedSection section = CrossSection(geometry, mesh, materials=[steel, timber]) section.display_mesh_info() # display the mesh information # plot the mesh with coloured materials and a line transparency of 0.5 section.plot_mesh(materials=True, alpha=0.5) # perform a geometric, warping and plastic analysis section.calculate_geometric_properties(time_info=True) section.calculate_warping_properties(time_info=True) section.calculate_plastic_properties(time_info=True, verbose=True) # perform a stress analysis with N = 100 kN, Mxx = 120 kN.m and Vy = 75 kN stress_post = section.calculate_stress(N=-100e3, Mxx=-120e6, Vy=-75e3, time_info=True) # print the results to the terminal section.display_results() # plot the centroids section.plot_centroids() stress_post.plot_stress_n_zz(pause=False) # plot the axial stress stress_post.plot_stress_m_zz(pause=False) # plot the bending stress stress_post.plot_stress_v_zxy() # plot the shear stress
def process_geometry(geometry, mesh_sizes, loadcases): # update this to receive the geometry, mesh info, material and loads # generate a finite element mesh mesh = geometry.create_mesh(mesh_sizes=mesh_sizes) # generate material - can be overwritten if needed --all in N and cm # create a CrossSection object for analysis section = CrossSection(geometry, mesh) # calculate various cross-section properties section.calculate_geometric_properties() section.calculate_warping_properties() section.calculate_plastic_properties() # Area area = section.get_area() sheararea = section.get_As() asx = sheararea[0] asy = sheararea[1] # Second Moment of Area about centroid (ixx, iyy, ixy) = section.get_ic() # Centroid (xg, yg) = section.get_c() # Radii of Gyration (rxx, ryy) = section.get_rc() # Principal bending axis angle phi = section.get_phi() # St. Venant torsion constant ipp = section.get_j() # Warping Constant cw = section.get_gamma() # Elastic Section Moduli (welx_top, welx_bottom, wely_top, wely_bottom) = section.get_z() # Plastic Section Moduli (wplx, wply) = section.get_s() # plot centroid to image section.plot_centroids(pause=False) buf = io.BytesIO() plt.savefig(buf, format='png', bbox_inches='tight') buf.seek(0) plot_centroid = base64.b64encode(buf.getvalue()).decode() plt.close() # calculate torsion resistance from stress and torque #from the below can also return torsional stress if wanted stress_post = section.calculate_stress(Mzz=10) unit_mzz_zxy = [] maxstress = [] for group in stress_post.material_groups: maxstress.append(max(group.stress_result.sig_zxy_mzz)) unit_mzz_zxy.append(group.stress_result.sig_zxy_mzz.tolist()) #there should be only one maxstress value therefore: wt = 10 / maxstress[0] #plot this image stress_post.plot_stress_mzz_zxy(pause=False) buf = io.BytesIO() plt.savefig(buf, format='png', bbox_inches='tight') buf.seek(0) plot_unittorsionstress = base64.b64encode(buf.getvalue()).decode() plt.close() #foreach load case submitted calculate vm stress state and create image vmStressImages = {} vmStressStates = {} for loadcase in loadcases: lc_name = loadcase[0] s_n = loadcase[1] s_vx = loadcase[2] s_vy = loadcase[3] s_mxx = loadcase[4] s_myy = loadcase[5] s_mzz = loadcase[6] stress_post = section.calculate_stress(N=s_n, Vx=s_vx, Vy=s_vy, Mxx=s_mxx, Myy=s_myy, Mzz=s_mzz) stress_state = [] for group in stress_post.material_groups: stress_state.append(group.stress_result.sig_vm.tolist()) vmStressStates['lc_' + str(lc_name) + '_vm_stress'] = stress_state #plot this image stress_post.plot_stress_vm(pause=False) buf = io.BytesIO() plt.savefig(buf, format='png', bbox_inches='tight') buf.seek(0) vmStressImages['lc_' + str(lc_name) + '_vm_stress'] = base64.b64encode( buf.getvalue()).decode() plt.close() # create rhino mesh rmesh = rhino_mesh_from_meshpy(mesh) # return send_file(path, as_attachment=True) # get some of the calculated section properties return_data = {} return_data['properties'] = { 'area': area, 'Avx': asx, 'Avy': asy, 'xg': xg, 'yg': yg, 'rxx': rxx, 'ryy': ryy, 'phi': phi, 'ixx': ixx, 'iyy': iyy, 'ipp': ipp, 'cw': cw, 'welx+': welx_top, 'welx-': welx_bottom, 'wely+': wely_top, 'wely-': wely_bottom, 'wplx': wplx, 'wply': wply, 'wt': wt, } return_data['geometry'] = { 'mesh': rhino.CommonObject.Encode(rmesh), } return_data['images'] = { 'centroids': plot_centroid, 'unittorsion_vxy_stress': plot_unittorsionstress, } return_data['images'].update(vmStressImages) return_data['stress_results'] = { 'unittorsion_vxy_stress': unit_mzz_zxy, } return_data['stress_results'].update(vmStressStates) return return_data
import sectionproperties.pre.sections as sections from sectionproperties.analysis.cross_section import CrossSection # create a 150x100x6 RHS on its side geometry = sections.Rhs(d=100, b=150, t=6, r_out=15, n_r=8) # create a mesh with a maximum area of 2 mesh = geometry.create_mesh(mesh_sizes=[2]) # create a CrossSection object section = CrossSection(geometry, mesh) # perform a geometry and warping analysis section.calculate_geometric_properties() section.calculate_warping_properties() # perform a stress analysis with Mx = 5 kN.m; Vx = 10 kN and Mzz = 3 kN.m case1 = section.calculate_stress(Mxx=5e6, Vx=10e3, Mzz=3e6) # perform a stress analysis with My = 15 kN.m; Vy = 30 kN and Mzz = 1.5 kN.m case2 = section.calculate_stress(Myy=15e6, Vy=30e3, Mzz=1.5e6) case1.plot_stress_m_zz(pause=False) # plot the bending stress for case1 case1.plot_vector_mzz_zxy(pause=False) # plot the torsion vectors for case1 case2.plot_stress_v_zxy(pause=False) # plot the shear stress for case1 case1.plot_stress_vm(pause=False) # plot the von mises stress for case1 case2.plot_stress_vm() # plot the von mises stress for case2
class OneSec: """表示一个截面""" def __init__(self, pls): """ 单独截面 :param pls: 多条 cad 多段线对象组成的列表,其中应有一根指示控制点的线 """ # 原始线和控制点 self.pls_origin = [] self.points = [] for i in pls: if i.area == 0: self.points = i.id else: self.pls_origin.append(i) # 对线段进行排序,得到分离节点和完整节点 self.areas = np.array([i.area for i in self.pls_origin]) self.pls = np.array(self.pls_origin)[np.argsort(self.areas)][::-1] self.ids_sep = [i.id for i in self.pls] self.ids = [j.tolist() for i in self.ids_sep for j in i] # 获取节点连接方式 self.faces = [] id_num = 0 for i in self.ids_sep: id_num_0 = id_num for j in i: connect = [ id_num, id_num_0 ] if id_num + 1 == id_num_0 + len(i) else [id_num, id_num + 1] self.faces.append(connect) id_num += 1 # 定义其他所需值 self.geo = 0 self.mesh = 0 self.sec = 0 self.prop = {} self.stress = 0 self.corner = [] self.ids_to_c = [] def sec_cal(self, mesh=0.01, d=0.03): """ 对单个截面进行属性计算 :param mesh: 截面划分单元尺寸 :param d: 截取形心附近应力范围 :return: 无 """ self.geo = sections.CustomSection(self.ids, self.faces, self.points[1:], [self.points[0]]) self.mesh = self.geo.create_mesh(mesh_sizes=[mesh]) self.sec = CrossSection(self.geo, self.mesh) self.sec.plot_mesh() self.sec.calculate_geometric_properties() self.sec.calculate_warping_properties() # 获取截面属性 prop = self.sec.section_props self.prop['center'] = self.sec.get_c() self.ids_to_c = [i - self.prop['center'] for i in self.ids_sep] self.prop['area'] = prop.area self.prop['as'] = [prop.A_s22, prop.A_s11] self.prop['i'] = [prop.j, prop.ixx_c, prop.iyy_c] pts = np.array(self.ids) left = prop.cx - pts[:, 0].min() right = pts[:, 0].max() - prop.cx top = pts[:, 1].max() - prop.cy bot = prop.cy - pts[:, 1].min() self.prop['c'] = [right, left, top, bot] self.stress = self.sec.calculate_stress(Vx=1, Vy=1) stresses = self.stress.get_stress() dy = self.sec.get_c()[1] - self.sec.mesh_nodes[:, 1] dx = self.sec.get_c()[0] - self.sec.mesh_nodes[:, 0] qyb = stresses[0]['sig_zy_vy'][dx < d].max() * prop.ixx_c qzb = stresses[0]['sig_zx_vx'][dy < d].max() * prop.iyy_c self.prop['q'] = [qyb, qzb] self.prop['p'] = [ self.pls[0].length, sum([i.length for i in self.pls[1:]]) ] # 获取角点 pt_all = self.ids_to_c[0] pt_1 = pt_all[(pt_all[:, 0] < 0) & (pt_all[:, 1] > 0)] pt_2 = pt_all[(pt_all[:, 0] > 0) & (pt_all[:, 1] > 0)] pt_3 = pt_all[(pt_all[:, 0] < 0) & (pt_all[:, 1] < 0)] pt_4 = pt_all[(pt_all[:, 0] > 0) & (pt_all[:, 1] < 0)] pt_1 = find_pt(pt_1, relation='max') pt_2 = find_pt(pt_2, relation='max') pt_3 = find_pt(pt_3, relation='max') pt_4 = find_pt(pt_4, relation='max') self.corner = [pt_1, pt_2, pt_4, pt_3]