def test_part_sides_skewed(self): # top right point in range, bottom right point out of range # left side perfet (2 found) # top in range but skewed on 2nd line (2 found) # right in range but skewed on 1st line, 2nd out of range (1 found) # bottom 1st out of range, in range but skewed on 2nd line, 2 (1 found) initial_accuracy_val = pyc.geometry.ACC pyc.geometry.ACC = 0.2 offset_in_range = 0.1 offset_too_big = 0.4 proj_name = 'test_part_sides_skewed' model = pyc.FeaModel(proj_name) model.set_units('m') # this sets dist units to meters part = pyc.Part(model) divot_width = 1 corner_width = 2 part.goto(0, 0) left_points = [ (corner_width, 0), (corner_width + divot_width, divot_width), (corner_width + divot_width * 2, 0), (corner_width * 2 + divot_width * 2, 0), ] top_points = [ (corner_width * 2 + divot_width * 2, corner_width), (corner_width * 2 + divot_width, corner_width + divot_width), (corner_width * 2 + divot_width * 2, corner_width + divot_width * 2), (corner_width * 2 + divot_width * 2 - offset_in_range, corner_width * 2 + divot_width * 2 - offset_in_range), ] right_points = [ (corner_width + divot_width * 2, corner_width * 2 + divot_width * 2), (corner_width + divot_width, corner_width * 2 + divot_width), (corner_width, corner_width * 2 + divot_width * 2), (0 + offset_too_big, corner_width * 2 + divot_width * 2 - offset_too_big), ] bottom_points = [ (0, corner_width + divot_width * 2), (divot_width, corner_width + divot_width), (0, corner_width), (0, 0), ] all_points = left_points + top_points + right_points + bottom_points for x, y in all_points: part.draw_line_to(x, y) self.assertEqual([line.get_name() for line in part.left], ['L0', 'L3']) self.assertEqual([line.get_name() for line in part.top], ['L4', 'L7']) self.assertEqual([line.get_name() for line in part.right], ['L8']) self.assertEqual([line.get_name() for line in part.bottom], ['L15']) pyc.geometry.ACC = initial_accuracy_val
def test_part_sides_perfect(self): # a hole with multiple lines for each side sets them correctly proj_name = 'test_part_sides' model = pyc.FeaModel(proj_name) model.set_units('m') # this sets dist units to meters part = pyc.Part(model) divot_width = 1 corner_width = 2 part.goto(0, 0) left_points = [ (corner_width, 0), (corner_width + divot_width, divot_width), (corner_width + divot_width * 2, 0), (corner_width * 2 + divot_width * 2, 0), ] top_points = [ (corner_width * 2 + divot_width * 2, corner_width), (corner_width * 2 + divot_width, corner_width + divot_width), (corner_width * 2 + divot_width * 2, corner_width + divot_width * 2), (corner_width * 2 + divot_width * 2, corner_width * 2 + divot_width * 2), ] right_points = [ (corner_width + divot_width * 2, corner_width * 2 + divot_width * 2), (corner_width + divot_width, corner_width * 2 + divot_width), (corner_width, corner_width * 2 + divot_width * 2), (0, corner_width * 2 + divot_width * 2), ] bottom_points = [ (0, corner_width + divot_width * 2), (divot_width, corner_width + divot_width), (0, corner_width), (0, 0), ] all_points = left_points + top_points + right_points + bottom_points for x, y in all_points: part.draw_line_to(x, y) self.assertEqual([line.get_name() for line in part.left], ['L0', 'L3']) self.assertEqual([line.get_name() for line in part.top], ['L4', 'L7']) self.assertEqual([line.get_name() for line in part.right], ['L8', 'L11']) self.assertEqual([line.get_name() for line in part.bottom], ['L12', 'L15'])
def test_quad_mesh(self, el_shape='quad'): proj_name = 'sample' length = 4.0 # hole diam model = pyc.FeaModel(proj_name) model.set_units('m') # this sets dist units to meters part = pyc.Part(model) part.goto(0, 0) part.draw_line_ax(length) part.draw_line_rad(length) part.draw_line_ax(-length) part.draw_line_rad(-length) # set the element type and mesh database model.set_eshape(el_shape, 2) model.mesh(1.0, 'gmsh') # mesh 1.0 fineness, smaller is finer # model.plot_elements(proj_name+'_elem') # plot part elements self.assertTrue(self.most_are_type(part.elements, el_shape))
show_gui = False # set element shape eshape = 'quad' if '-tri' in sys.argv: eshape = 'tri' # Define variables we'll use to draw part geometry diam = 2.0 # hole diam ratio = 0.45 width = diam / ratio # plate width print('D=%f, H=%f, D/H=%f' % (diam, width, diam / width)) length = 2 * width # plate length # Draw part geometry, you must draw the part CLOCKWISE, # x, y = radial, axial part = pyc.Part(model) part.goto(length * 0.5, -width * 0.5) part.draw_line_ax(width) part.draw_line_rad(-length) part.draw_line_ax(-width) part.draw_line_rad(length) hole_lines = part.draw_hole(0, 0, diam * 0.5, filled=False) model.set_ediv(hole_lines, 10) part.chunk() # view the geometry model.plot_geometry(proj_name + '_geom', display=show_gui) # set loads and constraints pressure = -1000 model.set_load('press', part.top, pressure) model.set_load('press', part.bottom, pressure)
# pin locations pin1 = [0, 0] pin2 = [pin1[0], 4] pin3 = [4, 8] # dimentions for drawing parts pinhole_rad = 0.25 pin_rad = pinhole_rad - .1 width_plate = 1 near_hole_th = 0.5 * width_plate left_y = pin1[1] - near_hole_th left_x = pin1[0] - near_hole_th pinhole_dist = pin2[1] - pin1[1] # make main part part = pyc.Part(model) part.goto(left_x, left_y) part.draw_line_ax(pinhole_dist + width_plate) part.draw_line_rad(width_plate) part.draw_line_ax(-width_plate) part.draw_line_ax(-(pinhole_dist - width_plate)) part.draw_line_rad(pin3[0] - pin1[0] - width_plate) part.draw_line_ax(pin3[1] - pin1[0]) part.draw_line_rad(width_plate) part.draw_line_ax(-width_plate) part.draw_line_ax(-(pin3[1] - pin1[1])) part.draw_line_to(left_x, left_y) fillet_arcs = part.fillet_all(near_hole_th) # make pinholes hole_arcs = [] for pin_point in [pin1, pin2, pin3]:
# Model of a pipe being crushed, quarter-symmetrym plane strain proj_name = 'pipe-crush-elastic' model = pyc.FeaModel(proj_name) model.set_units('m') # this sets dist units to meters # Define variables we'll use to draw part geometry rad_outer = 0.1143 # pipe outer radius pipe_wall_th = .00887 # wall thickness rad_inner = rad_outer - pipe_wall_th pipe_length = 10 * rad_outer wall_elements = 4.0 e_size = pipe_wall_th / wall_elements disp = False # Draw pipe, x, y = radial, axial pipe = pyc.Part(model) pipe.goto(0.0, rad_inner) arc_inner = pipe.draw_arc_angle(90, 0.0, 0.0)[0] pipe.draw_line_to(rad_outer, 0.0) arc_outer = pipe.draw_arc_angle(-90, 0.0, 0.0)[0] pipe.draw_line_to(0.0, rad_inner) num_outer = arc_outer.length() / e_size num_inner = arc_inner.length() / e_size num_arc_eles = int(round(0.5 * (num_outer + num_inner), 0)) # Draw plate, x, y = radial, axial plate = pyc.Part(model) plate.goto(rad_outer, 0.0) plate.draw_line_rad(pipe_wall_th) plate.draw_line_ax(rad_outer) plate.draw_line_rad(-pipe_wall_th)