# Modeling beam structures directly inside Ansys mechanical

Member, Employee Posts: 216
✭✭✭✭
edited May 21

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
Tagged:

• Member, Employee Posts: 216
✭✭✭✭
edited May 21

The below function would create beams based on points

```def create_cir_beams_from_points(points):
with Transaction(True):

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 = 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 part

```beam1_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
return points
# Inputs
length = 10
num_points = 20  # Number of points to define the semi-circular bend
# Generate the 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
return points

# Inputs
length = 2.0
num_points = 10

#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)
z = (pitch / (2 * math.pi)) * t
points.append((x, y, z))
return points

# Inputs
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 structures

```def 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
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)
```

• Member, Employee Posts: 216
✭✭✭✭
edited May 21

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)
helix_points_list = []
z_increment = length / num_points
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
# 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
seat_tube_angle = 73  # degrees
chain_stay_length = 410  # mm
seat_stay_length = 490  # mm
top_tube_length = 525  # mm
bottom_bracket_drop = 70  # mm
# Convert angles from degrees to radians for calculations
# Calculate coordinates
# Bottom bracket (origin)
bb = (0, 0, 0)
# Rear wheel axle
# Front wheel axle
front_axle = (wheelbase, 0, bottom_bracket_drop)
# Top of seat tube
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]])
```

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: