From fdf5bdec34f0ec7a305d6644f344f7bcf35bca48 Mon Sep 17 00:00:00 2001 From: "concha.k.chen" Date: Tue, 14 Jan 2025 14:50:16 +0800 Subject: [PATCH] =?UTF-8?q?gearx=EF=BC=9A=E9=BD=BF=E9=9D=A2=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E5=86=85=E6=B3=95=E5=90=91=E9=87=8F=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/gearx/gear.py | 50 +++++++++++++++++++++++------- app/gearx/test/test_gear_system.py | 31 ++++++++++++++---- 2 files changed, 63 insertions(+), 18 deletions(-) diff --git a/app/gearx/gear.py b/app/gearx/gear.py index 7691b32b9..0f26bf14d 100644 --- a/app/gearx/gear.py +++ b/app/gearx/gear.py @@ -343,8 +343,19 @@ def get_profile_node_index(self, tooth_tag=None): hex_node = hex_mesh.node is_bd_cell = quad_mesh.boundary_cell_flag() - domain_flag_right = quad_mesh.celldata["cell_domain_tag"] == 6 - domain_flag_left = quad_mesh.celldata["cell_domain_tag"] == 5 + if self.gear_type == 1: + if self.is_max_angle: + domain_flag_right = quad_mesh.celldata["cell_domain_tag"] == 7 + domain_flag_left = quad_mesh.celldata["cell_domain_tag"] == 6 + else: + domain_flag_right = quad_mesh.celldata["cell_domain_tag"] == 6 + domain_flag_left = quad_mesh.celldata["cell_domain_tag"] == 5 + elif self.gear_type == 2: + domain_flag_right = quad_mesh.celldata["cell_domain_tag"] == 6 + domain_flag_left = quad_mesh.celldata["cell_domain_tag"] == 8 + else: + raise ValueError('The gear type is not set.') + if tooth_tag is None: folder = self.z cell_flag_right = is_bd_cell & domain_flag_right @@ -358,22 +369,37 @@ def get_profile_node_index(self, tooth_tag=None): # 左侧齿面 # TODO: 考虑是否给单元局部起始节点编号加检测,即不一定从 0 和 2 开始 - cell_idx_left = np.where(cell_flag_left)[0].reshape(folder, -1)[..., 0:n1] - tooth_profile_cell_left = quad_mesh.cell[cell_idx_left] - tooth_profile_node_left = np.zeros((folder, nw + 1, n1 + 1), dtype=np.int32) - tooth_profile_node_left[..., 0, 0:n1] = tooth_profile_cell_left[..., :, 0] - tooth_profile_node_left[..., 0, -1] = tooth_profile_cell_left[..., -1, 1] + if self.gear_type == 1: + cell_idx_left = np.where(cell_flag_left)[0].reshape(folder, -1)[..., 0:n1] + tooth_profile_cell_left = quad_mesh.cell[cell_idx_left] + tooth_profile_node_left = np.zeros((folder, nw + 1, n1 + 1), dtype=np.int32) + tooth_profile_node_left[..., 0, 0:n1] = tooth_profile_cell_left[..., :, 0] + tooth_profile_node_left[..., 0, -1] = tooth_profile_cell_left[..., -1, 1] + elif self.gear_type == 2: + cell_idx_left = np.flip(np.flip(np.where(cell_flag_left)[0])[..., 0:n1].reshape(folder, -1), axis=0) + tooth_profile_cell_left = quad_mesh.cell[cell_idx_left] + tooth_profile_node_left = np.zeros((folder, nw + 1, n1 + 1), dtype=np.int32) + tooth_profile_node_left[..., 0, 0:n1] = tooth_profile_cell_left[..., :, 2] + tooth_profile_node_left[..., 0, -1] = tooth_profile_cell_left[..., -1, 1] # 左侧齿面节点所在单元记录 left_cell_idx = np.zeros_like(tooth_profile_node_left) left_cell_idx[..., 0, 0:n1] = cell_idx_left[..., :] left_cell_idx[..., 0, -1] = cell_idx_left[..., -1] # 右侧齿面 - cell_idx_right = np.flip(np.flip(np.where(cell_flag_right)[0]).reshape(folder, -1)[..., 0:n1], axis=0) - tooth_profile_cell_right = quad_mesh.cell[cell_idx_right] - tooth_profile_node_right = np.zeros((folder, nw + 1, n1 + 1), dtype=np.int32) - tooth_profile_node_right[..., 0, 0:n1] = tooth_profile_cell_right[..., :, 2] - tooth_profile_node_right[..., 0, -1] = tooth_profile_cell_right[..., -1, 1] + if self.gear_type == 1: + cell_idx_right = np.flip(np.flip(np.where(cell_flag_right)[0]).reshape(folder, -1)[..., 0:n1], axis=0) + tooth_profile_cell_right = quad_mesh.cell[cell_idx_right] + tooth_profile_node_right = np.zeros((folder, nw + 1, n1 + 1), dtype=np.int32) + tooth_profile_node_right[..., 0, 0:n1] = tooth_profile_cell_right[..., :, 2] + tooth_profile_node_right[..., 0, -1] = tooth_profile_cell_right[..., -1, 1] + elif self.gear_type == 2: + cell_idx_right = np.where(cell_flag_right)[0].reshape(folder, -1)[..., 0:n1] + tooth_profile_cell_right = quad_mesh.cell[cell_idx_right] + tooth_profile_node_right = np.zeros((folder, nw + 1, n1 + 1), dtype=np.int32) + tooth_profile_node_right[..., 0, 0:n1] = tooth_profile_cell_right[..., :, 0] + tooth_profile_node_right[..., 0, -1] = tooth_profile_cell_right[..., -1, 1] + # 右侧齿面节点所在单元记录 right_cell_idx = np.zeros_like(tooth_profile_node_right) right_cell_idx[..., 0, 0:n1] = cell_idx_right[..., :] diff --git a/app/gearx/test/test_gear_system.py b/app/gearx/test/test_gear_system.py index 90fa89241..d12d29806 100644 --- a/app/gearx/test/test_gear_system.py +++ b/app/gearx/test/test_gear_system.py @@ -35,7 +35,7 @@ def test_external_gear(self): tooth_width = data['tooth_width'] inner_diam = data['inner_diam'] # 轮缘内径 # m_n = 2.25 - # z = 64 + z = 18 # alpha_n = 17.5 # beta = 30 # x_n = 0.4 @@ -50,7 +50,7 @@ def test_external_gear(self): quad_mesh = external_gear.generate_mesh() # quad_mesh.to_vtk(fname='../data/external_quad_mesh.vtu') hex_mesh = external_gear.generate_hexahedron_mesh() - # hex_mesh.to_vtk(fname='../data/test_param_external_hex_mesh.vtu') + hex_mesh.to_vtk(fname='../data/face_normal_test_param_external_hex_mesh.vtu') # # with open('external_gear.pkl', 'wb') as f: # pickle.dump({'quad_mesh': quad_mesh, 'gear': external_gear, 'hex_mesh': hex_mesh}, f) @@ -90,8 +90,12 @@ def test_internal_gear(self): internal_gear = InternalGear(m_n, z, alpha_n, beta, x_n, hac, cc, rcc, jn, n1, n2, n3, na, nf, nw, outer_diam, z_cutter, xn_cutter, tooth_width) + quad_mesh = internal_gear.mesh hex_mesh = internal_gear.generate_hexahedron_mesh() - hex_mesh.to_vtk(fname='../data/test_param_internal_hex_mesh.vtu') + # hex_mesh.to_vtk(fname='../data/test_param_internal_hex_mesh.vtu') + + with open('../data/internal_gear_new.pkl', 'wb') as f: + pickle.dump({'internal_gear': internal_gear, 'hex_mesh': hex_mesh, 'quad_mesh': quad_mesh}, f) t = np.array([0.1, 0.2, 25]) p1 = internal_gear.get_involute_points(t) @@ -490,15 +494,15 @@ def test_get_part_external_gear(self): part_external_gear_mesh.to_vtk(fname='../data/part_external_gear_mesh.vtu') part_external_gear_mesh_wheel.to_vtk(fname='../data/part_external_gear_hex_mesh_wheel.vtu') - def test_get_profile_face_normal(self): + def test_get_profile_face_normal_external(self): with open('../data/external_gear_new.pkl', 'rb') as f: data = pickle.load(f) external_gear = data['external_gear'] hex_mesh = data['hex_mesh'] quad_mesh = data['quad_mesh'] - mesh = external_gear.set_target_tooth([0, 1, 18]) - # mesh.to_vtk(fname='../data/face_normal_target_hex_mesh.vtu') + mesh = external_gear.set_target_tooth([0, 1, 17]) + external_gear.target_quad_mesh.to_vtk(fname='../data/face_normal_target_quad_mesh.vtu') GD = mesh.geo_dimension() NC = mesh.number_of_cells() @@ -515,6 +519,21 @@ def test_get_profile_face_normal(self): print(-1) + def test_get_profile_face_normal_internal(self): + with open('../data/internal_gear_new.pkl', 'rb') as f: + data = pickle.load(f) + internal_gear = data['internal_gear'] + hex_mesh = data['hex_mesh'] + quad_mesh = data['quad_mesh'] + + mesh = internal_gear.set_target_tooth([78, 79, 0, 1, 2]) + internal_gear.target_quad_mesh.to_vtk(fname='../data/face_normal_target_quad_mesh_internal.vtu') + + # 齿面上的节点索引和坐标 + node_indices_tuple, noe_coord_tuple, profile_node_normal = internal_gear.get_profile_node_index(tooth_tag=0) + + print(-1) + if __name__ == "__main__":