Modeling beam structures directly inside Ansys mechanical

Member, Employee Posts: 222
100 Comments 100 Likes Second Anniversary Name Dropper
✭✭✭✭
edited May 2024 in Structures

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:

  1. straight beams or pipes ,
  2. L-shape pipes,
  3. U-shape pipes,
  4. Helix structures
  5. simple representation of real life cases like crane machine

Welcome!

It looks like you're new here. Sign in or register to get started.

Comments

  • Member, Employee Posts: 222
    100 Comments 100 Likes Second Anniversary Name Dropper
    ✭✭✭✭
    edited May 2024

    The below function would create beams based on points

    1. def create_cir_beams_from_points(points):
    2. with Transaction(True):
    3. ExtAPI.DataModel.Project.Model.AddConstructionGeometry()
    4. construction_line = ExtAPI.DataModel.Project.Model.ConstructionGeometry.AddConstructionLine()
    5.  
    6. for pointlist in points:
    7. points = construction_line.CreatePoints(pointlist)
    8. for i in range(0, len(points) - 1):
    9. edge = construction_line.CreateStraightLines([points[i], points[i + 1]], [(0, 1)])
    10.  
    11. part_geo = construction_line.AddToGeometry()
    12. part = ExtAPI.DataModel.Project.Model.Geometry.GetPart(part_geo)
    13. geo_bodies = part_geo.Bodies
    14. 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 part

    1. beam1_points = [[0,0,0],[100,0,0]]
    2. beam2_points = [[100,0,0],[50,50,0]]
    3. beam3_points = [[50,50,0],[0,0,0]]
    4. 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:

    1. beam1_points = [[0,0,0],[100,0,0],[50,50,0],[0,0,0]]
    2. create_cir_beams_from_points([beam1_points])

    lets look at an example of creating a U-shape pipe structure

    1. def generate_u_bend_points(radius, length, num_points):
    2. points = []
    3. # Straight section before the bend
    4. points.append([0, 0, 0])
    5. points.append([0, length, 0])
    6. # Semi-circular bend
    7. for i in range(num_points + 1):
    8. angle = math.pi * i / num_points
    9. x = radius * (1 - math.cos(angle))
    10. y = length + radius * math.sin(angle)
    11. points.append([x, y, 0])
    12. # Straight section after the bend
    13. points.append([2 * radius, length, 0])
    14. points.append([2 * radius, 0, 0])
    15. return points
    16. # Inputs
    17. radius = 5
    18. length = 10
    19. num_points = 20 # Number of points to define the semi-circular bend
    20. # Generate the points
    21. points = generate_u_bend_points(radius, length, num_points)
    22.  
    23. # Create beams
    24. create_cir_beams_from_points([points])

    Let us create an L-Shape pipe now:

    1. def generate_l_bend_points(radius, length, num_points):
    2. points = []
    3. # Straight section before the bend
    4. points.append([0, 0, 0])
    5. points.append([0, length, 0])
    6.  
    7. # Quarter-circular bend (90 degrees)
    8. for i in range(num_points + 1):
    9. angle = (math.pi / 2) * i / num_points
    10. x = radius * (1 - math.cos(angle))
    11. y = length + radius * math.sin(angle)
    12. points.append([x, y, 0])
    13. # Straight section after the bend
    14. points.append([radius, length + radius, 0])
    15. points.append([radius + length, length + radius, 0])
    16. return points
    17.  
    18. # Inputs
    19. radius = 1.0
    20. length = 2.0
    21. num_points = 10
    22. points = generate_l_bend_points(radius, length, num_points)
    23.  
    24. #create beams
    25. create_cir_beams_from_points([points])

    let us look at how you can create a single helical strand or coil:

    1. def generate_helix_points(radius, pitch, turns, num_points):
    2. points = []
    3. total_points = num_points * turns
    4. for i in range(total_points):
    5. t = i * (2 * math.pi / num_points)
    6. x = radius * math.cos(t)
    7. y = radius * math.sin(t)
    8. z = (pitch / (2 * math.pi)) * t
    9. points.append((x, y, z))
    10. return points
    11.  
    12. # Inputs
    13. radius = 5
    14. pitch = 2
    15. turns = 10
    16. num_points = 100
    17.  
    18. # Generate points for the helix
    19. helix_points = generate_helix_points(radius, pitch, turns, num_points)
    20.  
    21. #Create beams
    22. 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 structures

    1. def generate_multiple_helix_points(radius, pitch, length, num_points, num_strands):
    2. helix_points_list = []
    3. angle_increment = 2 * math.pi / num_strands
    4. z_increment = length / num_points
    5. for strand in range(num_strands):
    6. points = []
    7. start_angle = strand * angle_increment
    8.  
    9. for i in range(num_points):
    10. t = i * (2 * math.pi / num_points)
    11. x = radius * math.cos(t + start_angle)
    12. y = radius * math.sin(t + start_angle)
    13. z = i * z_increment
    14. points.append((x, y, z))
    15. helix_points_list.append(points)
    16. return helix_points_list
    17. #Inputs
    18. radius = 5
    19. pitch = 20
    20. length = 100
    21. num_points = 100
    22. num_strands = 50
    23.  
    24. # Generate points for helix
    25. multiple_helix_points = generate_multiple_helix_points(radius, pitch, length, num_points, num_strands)
    26.  
    27. #create beams
    28. create_cir_beams_from_points(multiple_helix_points)

  • Member, Employee Posts: 222
    100 Comments 100 Likes Second Anniversary Name Dropper
    ✭✭✭✭
    edited October 2024

    lets now create wire strands , like copper wire strands used in cables:

    1. import math
    2. def max_wires(circumference, wire_diameter):
    3. return int(circumference / wire_diameter)
    4. def generate_multiple_helix_points(radius, pitch, length, num_points, wire_radius):
    5. helix_points_list = []
    6. z_increment = length / num_points
    7. max_rad = int(radius / wire_radius)
    8. for rad in range(max_rad, 0, -1):
    9. current_radius = rad * wire_radius
    10. circumference = 2 * math.pi * current_radius
    11. num_strands = max_wires(circumference, 2 * wire_radius)
    12. angle_increment = 2 * math.pi / max(num_strands, 1) # Avoid division by zero
    13. for strand in range(num_strands):
    14. points = []
    15. angle = strand * angle_increment
    16. for i in range(num_points):
    17. t = i * (2 * math.pi / num_points)
    18. x = current_radius * math.cos(t + angle)
    19. y = current_radius * math.sin(t + angle)
    20. z = i * z_increment
    21. points.append((x, y, z))
    22. helix_points_list.append(points)
    23. return helix_points_list
    24. # Inputs
    25. radius = 5 # in mm
    26. pitch = 20
    27. length = 100
    28. num_points = 100
    29. wire_radius = 1 # in mm
    30. # Generate points for helix
    31. multiple_helix_points = generate_multiple_helix_points(radius, pitch, length, num_points, wire_radius)
    32. # Create beams
    33. create_cir_beams_from_points(multiple_helix_points)

    lets look at a realistic example, lets create a simple crane machine representation now:

    1. def generate_base_points(base_length, base_width):
    2. points = []
    3. # Base points
    4. points.append([0, 0, 0])
    5. points.append([base_length, 0, 0])
    6. points.append([base_length, base_width, 0])
    7. points.append([0, base_width, 0])
    8. return points
    9.  
    10. def generate_mast_pillars(base_length, base_width, mast_height, num_points):
    11. points = []
    12. # Four vertical mast pillars
    13. for i in range(num_points + 1):
    14. z = mast_height * i / num_points
    15. points.append([0, 0, z])
    16. points.append([base_length, 0, z])
    17. points.append([base_length, base_width, z])
    18. points.append([0, base_width, z])
    19. return points
    20.  
    21. def generate_cross_bars_for_mast(base_length, base_width, mast_height, num_points):
    22. points = []
    23. # Cross bars for the mast in the x-y plane
    24. for i in range(1, num_points):
    25. z = mast_height * i / num_points
    26. points.append([0, 0, z])
    27. points.append([base_length, 0, z])
    28. points.append([base_length, base_width, z])
    29. points.append([0, base_width, z])
    30. return points
    31.  
    32. def generate_jib_points(base_length, base_width, mast_height, jib_length, num_points):
    33. points = []
    34. # Jib points (horizontal structure extending from the top of the mast)
    35. for i in range(num_points + 1):
    36. x = jib_length * i / num_points
    37. points.append([base_length / 2 + x, base_width / 2, mast_height])
    38. return points
    39.  
    40. def generate_cross_bars_for_jib(base_length, base_width, mast_height, jib_length, num_points):
    41. points = []
    42. # Cross bars for the jib in the x-y plane
    43. for i in range(1, num_points):
    44. x = jib_length * i / num_points
    45. points.append([base_length / 2 + x, base_width / 2, mast_height - 0.5])
    46. points.append([base_length / 2 + x, base_width / 2, mast_height + 0.5])
    47. return points
    48.  
    49. def generate_counterweight_points(base_length, base_width, mast_height, counterweight_length, num_points):
    50. points = []
    51. # Counterweight points (opposite side of the jib)
    52. for i in range(num_points + 1):
    53. x = -counterweight_length * i / num_points
    54. points.append([base_length / 2 + x, base_width / 2, mast_height])
    55. return points
    56.  
    57. def generate_diagonal_braces(base_length, base_width, mast_height, num_points):
    58. points = []
    59. # Diagonal braces for the mast
    60. for i in range(1, num_points):
    61. z = mast_height * i / num_points
    62. points.append([0, 0, z])
    63. points.append([base_length, base_width, z])
    64. points.append([base_length, 0, z])
    65. points.append([0, base_width, z])
    66. return points
    67.  
    68. # Inputs
    69. base_length = 5.0
    70. base_width = 5.0
    71. mast_height = 30.0
    72. jib_length = 50.0
    73. counterweight_length = 10.0
    74. num_points = 20
    75.  
    76. base_points = generate_base_points(base_length, base_width)
    77. mast_pillars_points = generate_mast_pillars(base_length, base_width, mast_height, num_points)
    78. cross_bars_mast_points = generate_cross_bars_for_mast(base_length, base_width, mast_height, num_points)
    79. jib_points = generate_jib_points(base_length, base_width, mast_height, jib_length, num_points)
    80. cross_bars_jib_points = generate_cross_bars_for_jib(base_length, base_width, mast_height, jib_length, num_points)
    81. counterweight_points = generate_counterweight_points(base_length, base_width, mast_height, counterweight_length, num_points)
    82. diagonal_braces_points = generate_diagonal_braces(base_length, base_width, mast_height, num_points)
    83.  
    84.  
    85. # Create the crane structure beams
    86. create_cir_beams_from_points([base_points])
    87. create_cir_beams_from_points([mast_points])
    88. create_cir_beams_from_points([cross_bars_mast_points])
    89. create_cir_beams_from_points([jib_points])
    90. create_cir_beams_from_points([cross_bars_jib_points])
    91. create_cir_beams_from_points([counterweight_points])
    92. create_cir_beams_from_points([diagonal_braces_points])
    93. create_cir_beams_from_points([[[0,0,0],[0,0,mast_height]]])
    94. create_cir_beams_from_points([[[0,base_width,0],[0,base_width,mast_height]]])
    95. create_cir_beams_from_points([[[base_length,base_width,0],[base_length,base_width,mast_height]]])
    96. create_cir_beams_from_points([[[base_length,0,0],[base_length,0,mast_height]]])

    Let us finally create a bike frame

    1. # Inputs
    2. wheelbase = 995 # mm
    3. head_tube_angle = 74.5 # degrees
    4. seat_tube_angle = 73 # degrees
    5. chain_stay_length = 410 # mm
    6. seat_stay_length = 490 # mm
    7. top_tube_length = 525 # mm
    8. head_tube_length = 150 # mm
    9. bottom_bracket_drop = 70 # mm
    10. # Convert angles from degrees to radians for calculations
    11. head_tube_angle_rad = math.radians(head_tube_angle)
    12. seat_tube_angle_rad = math.radians(seat_tube_angle)
    13. # Calculate coordinates
    14. # Bottom bracket (origin)
    15. bb = (0, 0, 0)
    16. # Rear wheel axle
    17. rear_axle = (-chain_stay_length * math.cos(seat_tube_angle_rad), 0, chain_stay_length * math.sin(seat_tube_angle_rad))
    18. # Front wheel axle
    19. front_axle = (wheelbase, 0, bottom_bracket_drop)
    20. # Bottom of head tube
    21. head_tube_bottom = (wheelbase, 0, bottom_bracket_drop)
    22. # Top of head tube
    23. head_tube_top = (wheelbase, 0, bottom_bracket_drop + head_tube_length)
    24. # Top of seat tube
    25. seat_tube_top = (top_tube_length * math.cos(seat_tube_angle_rad), 0, top_tube_length * math.sin(seat_tube_angle_rad))
    26. create_cir_beams_from_points([[bb, rear_axle]])
    27. create_cir_beams_from_points([[bb, front_axle]])
    28. create_cir_beams_from_points([[bb, seat_tube_top]])
    29. create_cir_beams_from_points([[head_tube_bottom, head_tube_top]])
    30. create_cir_beams_from_points([[head_tube_top, seat_tube_top]])

  • Member, Employee Posts: 222
    100 Comments 100 Likes Second Anniversary Name Dropper
    ✭✭✭✭
    edited October 2024

    You can also create a beam with cross-sections and material assignments like below example:

    1. #creating Inputs
    2. number_of_points = 100#assuming
    3. beam_lengths = list(map(lambda i: 100 + (2 * i), range(number_of_points)))#assuming a list
    4. 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
    5. names = map(lambda x: "Station "+str(x+1), range(number_of_points))#assuming a list
    6. cs_radius = map(lambda i: i*2+1, range(number_of_points))#assuming a list
    7. materials = ["Structural Steel"] * number_of_points#assuming a list
    8.  
    9. def compute_time(func):
    10. def wrapper(*args, **kwargs):
    11. import time
    12. start = time.time()
    13. result = func(*args, **kwargs)
    14. end = time.time()
    15. print ("Total time taken for executing function: '%s' --> = %s"%(func.__name__,end-start))
    16. return result
    17. return wrapper
    18.  
    19. @compute_time
    20. def create_crosssections():
    21. with Transaction(True):
    22. cs = map(lambda x: Model.CrossSections.AddCircularCrossSection(), range(number_of_points))
    23. with Transaction(True):
    24. map(lambda c,x: setattr(c, 'Radius', Quantity(str(x)+" [mm]")), cs,cs_radius)
    25. return cs
    26.  
    27. @compute_time
    28. def create_cir_beams_from_points(points,material,cs,names):
    29. with Transaction(True):
    30. ExtAPI.DataModel.Project.Model.AddConstructionGeometry()
    31. construction_line = ExtAPI.DataModel.Project.Model.ConstructionGeometry.AddConstructionLine()
    32.  
    33. points_list = list(map(construction_line.CreatePoints, points))
    34. edges = [construction_line.CreateStraightLines([p[i], p[i+1]], [(0, 1)])
    35. for p in points_list
    36. for i in range(len(p) - 1)]
    37.  
    38. part_geo = construction_line.AddToGeometry()
    39. part = ExtAPI.DataModel.Project.Model.Geometry.GetPart(part_geo)
    40. geo_bodies = part_geo.Bodies
    41. treebodies = map(lambda x: ExtAPI.DataModel.Project.Model.Geometry.GetBody(x), geo_bodies)
    42.  
    43. list(map(lambda x, m: setattr(x, 'Material', m), treebodies, materials))
    44.  
    45. list(map(lambda x, n: setattr(x, 'Name', n), treebodies, names))
    46.  
    47. list(map(lambda x, c: setattr(x, 'CrossSectionSelection', c), treebodies, cs))
    48. return treebodies
    49.  
    50. cs = create_crosssections()
    51. create_cir_beams_from_points(points,materials,cs,names)

Welcome!

It looks like you're new here. Sign in or register to get started.