Modeling beam structures directly inside Ansys mechanical
Note : No CAD tool is used here for creation of beams (its created directly in mechanical)
you could model beams using construction geometry in Ansys mechanical.
Below is an example how you could create beams directly inside mechanical having known a list of x,y,z points.
the example shows creation of below:
- straight beams or pipes ,
- L-shape pipes,
- U-shape pipes,
- Helix structures
- simple representation of real life cases like crane machine
Comments
-
The below function would create beams based on points
def create_cir_beams_from_points(points): with Transaction(True): ExtAPI.DataModel.Project.Model.AddConstructionGeometry() construction_line = ExtAPI.DataModel.Project.Model.ConstructionGeometry.AddConstructionLine() for pointlist in points: points = construction_line.CreatePoints(pointlist) for i in range(0, len(points) - 1): edge = construction_line.CreateStraightLines([points[i], points[i + 1]], [(0, 1)]) part_geo = construction_line.AddToGeometry() part = ExtAPI.DataModel.Project.Model.Geometry.GetPart(part_geo) geo_bodies = part_geo.Bodies treebodies = map(lambda x: ExtAPI.DataModel.Project.Model.Geometry.GetBody(x), geo_bodies)
now let us look at how you can use the above functions to create various structures
for example:
create_cir_beams_from_points([[[0,0,0],[100,0,0]],[[100,0,0],[200,0,0]]])
should create beams on a straight line(multi-body-part) like below:
lets look at another example where we create a triangle shape using 3 beams
as a single partbeam1_points = [[0,0,0],[100,0,0]] beam2_points = [[100,0,0],[50,50,0]] beam3_points = [[50,50,0],[0,0,0]] create_cir_beams_from_points([beam1_points,beam2_points,beam3_points])
similarly, you could as well create triangle shape as a single beam like below:
beam1_points = [[0,0,0],[100,0,0],[50,50,0],[0,0,0]] create_cir_beams_from_points([beam1_points])
lets look at an example of creating a U-shape pipe structure
def generate_u_bend_points(radius, length, num_points): points = [] # Straight section before the bend points.append([0, 0, 0]) points.append([0, length, 0]) # Semi-circular bend for i in range(num_points + 1): angle = math.pi * i / num_points x = radius * (1 - math.cos(angle)) y = length + radius * math.sin(angle) points.append([x, y, 0]) # Straight section after the bend points.append([2 * radius, length, 0]) points.append([2 * radius, 0, 0]) return points # Inputs radius = 5 length = 10 num_points = 20 # Number of points to define the semi-circular bend # Generate the points points = generate_u_bend_points(radius, length, num_points) # Create beams create_cir_beams_from_points([points])
Let us create an L-Shape pipe now:
def generate_l_bend_points(radius, length, num_points): points = [] # Straight section before the bend points.append([0, 0, 0]) points.append([0, length, 0]) # Quarter-circular bend (90 degrees) for i in range(num_points + 1): angle = (math.pi / 2) * i / num_points x = radius * (1 - math.cos(angle)) y = length + radius * math.sin(angle) points.append([x, y, 0]) # Straight section after the bend points.append([radius, length + radius, 0]) points.append([radius + length, length + radius, 0]) return points # Inputs radius = 1.0 length = 2.0 num_points = 10 points = generate_l_bend_points(radius, length, num_points) #create beams create_cir_beams_from_points([points])
let us look at how you can create a single helical strand or coil:
def generate_helix_points(radius, pitch, turns, num_points): points = [] total_points = num_points * turns for i in range(total_points): t = i * (2 * math.pi / num_points) x = radius * math.cos(t) y = radius * math.sin(t) z = (pitch / (2 * math.pi)) * t points.append((x, y, z)) return points # Inputs radius = 5 pitch = 2 turns = 10 num_points = 100 # Generate points for the helix helix_points = generate_helix_points(radius, pitch, turns, num_points) #Create beams create_cir_beams_from_points([helix_points])
now let us look at an example of how you can create multiple helix , typically used in braded hoses or wires.
You can create multiple layers of this helix for multi layered helical structuresdef generate_multiple_helix_points(radius, pitch, length, num_points, num_strands): helix_points_list = [] angle_increment = 2 * math.pi / num_strands z_increment = length / num_points for strand in range(num_strands): points = [] start_angle = strand * angle_increment for i in range(num_points): t = i * (2 * math.pi / num_points) x = radius * math.cos(t + start_angle) y = radius * math.sin(t + start_angle) z = i * z_increment points.append((x, y, z)) helix_points_list.append(points) return helix_points_list #Inputs radius = 5 pitch = 20 length = 100 num_points = 100 num_strands = 50 # Generate points for helix multiple_helix_points = generate_multiple_helix_points(radius, pitch, length, num_points, num_strands) #create beams create_cir_beams_from_points(multiple_helix_points)
0 -
lets now create wire strands , like copper wire strands used in cables:
import math def max_wires(circumference, wire_diameter): return int(circumference / wire_diameter) def generate_multiple_helix_points(radius, pitch, length, num_points, wire_radius): helix_points_list = [] z_increment = length / num_points max_rad = int(radius / wire_radius) for rad in range(max_rad, 0, -1): current_radius = rad * wire_radius circumference = 2 * math.pi * current_radius num_strands = max_wires(circumference, 2 * wire_radius) angle_increment = 2 * math.pi / max(num_strands, 1) # Avoid division by zero for strand in range(num_strands): points = [] angle = strand * angle_increment for i in range(num_points): t = i * (2 * math.pi / num_points) x = current_radius * math.cos(t + angle) y = current_radius * math.sin(t + angle) z = i * z_increment points.append((x, y, z)) helix_points_list.append(points) return helix_points_list # Inputs radius = 5 # in mm pitch = 20 length = 100 num_points = 100 wire_radius = 1 # in mm # Generate points for helix multiple_helix_points = generate_multiple_helix_points(radius, pitch, length, num_points, wire_radius) # Create beams create_cir_beams_from_points(multiple_helix_points)
lets look at a realistic example, lets create a simple crane machine representation now:
def generate_base_points(base_length, base_width): points = [] # Base points points.append([0, 0, 0]) points.append([base_length, 0, 0]) points.append([base_length, base_width, 0]) points.append([0, base_width, 0]) return points def generate_mast_pillars(base_length, base_width, mast_height, num_points): points = [] # Four vertical mast pillars for i in range(num_points + 1): z = mast_height * i / num_points points.append([0, 0, z]) points.append([base_length, 0, z]) points.append([base_length, base_width, z]) points.append([0, base_width, z]) return points def generate_cross_bars_for_mast(base_length, base_width, mast_height, num_points): points = [] # Cross bars for the mast in the x-y plane for i in range(1, num_points): z = mast_height * i / num_points points.append([0, 0, z]) points.append([base_length, 0, z]) points.append([base_length, base_width, z]) points.append([0, base_width, z]) return points def generate_jib_points(base_length, base_width, mast_height, jib_length, num_points): points = [] # Jib points (horizontal structure extending from the top of the mast) for i in range(num_points + 1): x = jib_length * i / num_points points.append([base_length / 2 + x, base_width / 2, mast_height]) return points def generate_cross_bars_for_jib(base_length, base_width, mast_height, jib_length, num_points): points = [] # Cross bars for the jib in the x-y plane for i in range(1, num_points): x = jib_length * i / num_points points.append([base_length / 2 + x, base_width / 2, mast_height - 0.5]) points.append([base_length / 2 + x, base_width / 2, mast_height + 0.5]) return points def generate_counterweight_points(base_length, base_width, mast_height, counterweight_length, num_points): points = [] # Counterweight points (opposite side of the jib) for i in range(num_points + 1): x = -counterweight_length * i / num_points points.append([base_length / 2 + x, base_width / 2, mast_height]) return points def generate_diagonal_braces(base_length, base_width, mast_height, num_points): points = [] # Diagonal braces for the mast for i in range(1, num_points): z = mast_height * i / num_points points.append([0, 0, z]) points.append([base_length, base_width, z]) points.append([base_length, 0, z]) points.append([0, base_width, z]) return points # Inputs base_length = 5.0 base_width = 5.0 mast_height = 30.0 jib_length = 50.0 counterweight_length = 10.0 num_points = 20 base_points = generate_base_points(base_length, base_width) mast_pillars_points = generate_mast_pillars(base_length, base_width, mast_height, num_points) cross_bars_mast_points = generate_cross_bars_for_mast(base_length, base_width, mast_height, num_points) jib_points = generate_jib_points(base_length, base_width, mast_height, jib_length, num_points) cross_bars_jib_points = generate_cross_bars_for_jib(base_length, base_width, mast_height, jib_length, num_points) counterweight_points = generate_counterweight_points(base_length, base_width, mast_height, counterweight_length, num_points) diagonal_braces_points = generate_diagonal_braces(base_length, base_width, mast_height, num_points) # Create the crane structure beams create_cir_beams_from_points([base_points]) create_cir_beams_from_points([mast_points]) create_cir_beams_from_points([cross_bars_mast_points]) create_cir_beams_from_points([jib_points]) create_cir_beams_from_points([cross_bars_jib_points]) create_cir_beams_from_points([counterweight_points]) create_cir_beams_from_points([diagonal_braces_points]) create_cir_beams_from_points([[[0,0,0],[0,0,mast_height]]]) create_cir_beams_from_points([[[0,base_width,0],[0,base_width,mast_height]]]) create_cir_beams_from_points([[[base_length,base_width,0],[base_length,base_width,mast_height]]]) create_cir_beams_from_points([[[base_length,0,0],[base_length,0,mast_height]]])
Let us finally create a bike frame
# Inputs wheelbase = 995 # mm head_tube_angle = 74.5 # degrees seat_tube_angle = 73 # degrees chain_stay_length = 410 # mm seat_stay_length = 490 # mm top_tube_length = 525 # mm head_tube_length = 150 # mm bottom_bracket_drop = 70 # mm # Convert angles from degrees to radians for calculations head_tube_angle_rad = math.radians(head_tube_angle) seat_tube_angle_rad = math.radians(seat_tube_angle) # Calculate coordinates # Bottom bracket (origin) bb = (0, 0, 0) # Rear wheel axle rear_axle = (-chain_stay_length * math.cos(seat_tube_angle_rad), 0, chain_stay_length * math.sin(seat_tube_angle_rad)) # Front wheel axle front_axle = (wheelbase, 0, bottom_bracket_drop) # Bottom of head tube head_tube_bottom = (wheelbase, 0, bottom_bracket_drop) # Top of head tube head_tube_top = (wheelbase, 0, bottom_bracket_drop + head_tube_length) # Top of seat tube seat_tube_top = (top_tube_length * math.cos(seat_tube_angle_rad), 0, top_tube_length * math.sin(seat_tube_angle_rad)) create_cir_beams_from_points([[bb, rear_axle]]) create_cir_beams_from_points([[bb, front_axle]]) create_cir_beams_from_points([[bb, seat_tube_top]]) create_cir_beams_from_points([[head_tube_bottom, head_tube_top]]) create_cir_beams_from_points([[head_tube_top, seat_tube_top]])
1 -
You can also create a beam with cross-sections and material assignments like below example:
#creating Inputs number_of_points = 100#assuming beam_lengths = list(map(lambda i: 100 + (2 * i), range(number_of_points)))#assuming a list points = list(map(lambda i: [[sum(beam_lengths[:i]), 0, 0], [sum(beam_lengths[:i + 1]), 0, 0]], range(number_of_points)))#creating a list from assumed lengths names = map(lambda x: "Station "+str(x+1), range(number_of_points))#assuming a list cs_radius = map(lambda i: i*2+1, range(number_of_points))#assuming a list materials = ["Structural Steel"] * number_of_points#assuming a list def compute_time(func): def wrapper(*args, **kwargs): import time start = time.time() result = func(*args, **kwargs) end = time.time() print ("Total time taken for executing function: '%s' --> = %s"%(func.__name__,end-start)) return result return wrapper @compute_time def create_crosssections(): with Transaction(True): cs = map(lambda x: Model.CrossSections.AddCircularCrossSection(), range(number_of_points)) with Transaction(True): map(lambda c,x: setattr(c, 'Radius', Quantity(str(x)+" [mm]")), cs,cs_radius) return cs @compute_time def create_cir_beams_from_points(points,material,cs,names): with Transaction(True): ExtAPI.DataModel.Project.Model.AddConstructionGeometry() construction_line = ExtAPI.DataModel.Project.Model.ConstructionGeometry.AddConstructionLine() points_list = list(map(construction_line.CreatePoints, points)) edges = [construction_line.CreateStraightLines([p[i], p[i+1]], [(0, 1)]) for p in points_list for i in range(len(p) - 1)] part_geo = construction_line.AddToGeometry() part = ExtAPI.DataModel.Project.Model.Geometry.GetPart(part_geo) geo_bodies = part_geo.Bodies treebodies = map(lambda x: ExtAPI.DataModel.Project.Model.Geometry.GetBody(x), geo_bodies) list(map(lambda x, m: setattr(x, 'Material', m), treebodies, materials)) list(map(lambda x, n: setattr(x, 'Name', n), treebodies, names)) list(map(lambda x, c: setattr(x, 'CrossSectionSelection', c), treebodies, cs)) return treebodies cs = create_crosssections() create_cir_beams_from_points(points,materials,cs,names)
0 -
remember once you have your scripts ready you can create a user button so all your scrips are embedded in a button and can be distributed easily by export/import of buttons:
please refer below link on how you could do them:How to create User Buttons in mechanical
Other useful posts for reference:
https://discuss.ansys.com/discussion/1019/how-to-create-construction-line-in-mechanical#latest
0