0% found this document useful (0 votes)
2 views1 page

GRASP Python (19)

The document outlines a procedure for calculating and displaying node displacements and reactions in a structural analysis program. It includes methods for visualizing the deformed shape of the structure and interactive functions for adding nodes and elements through user clicks. The program emphasizes user interaction and visualization in the analysis process.

Uploaded by

Le Fondateur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

GRASP Python (19)

The document outlines a procedure for calculating and displaying node displacements and reactions in a structural analysis program. It includes methods for visualizing the deformed shape of the structure and interactive functions for adding nodes and elements through user clicks. The program emphasizes user interaction and visualization in the analysis process.

Uploaded by

Le Fondateur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

# Calculate reactions

reactions = K_global @ U

# Display results
print("\nAnalysis Results:")
print("Node Displacements:")
for node_id in self.nodes:
ux = U[2*(node_id-1)]
uy = U[2*(node_id-1)+1]
print(f"Node {node_id}: ux = {ux:.6f} m, uy = {uy:.6f} m")

print("\nReactions:")
for node_id in self.supports:
rx = reactions[2*(node_id-1)]
ry = reactions[2*(node_id-1)+1]
print(f"Node {node_id}: Rx = {rx:.2f} N, Ry = {ry:.2f} N")

# Visualize deformed shape


scale_factor = 10 # Scale factor for visualization
deformed_nodes = {}
for node_id, node in self.nodes.items():
deformed_nodes[node_id] = {
'x': node['x'] + scale_factor * U[2*(node_id-1)],
'y': node['y'] + scale_factor * U[2*(node_id-1)+1]
}

# Draw deformed shape


for elem_id, elem in self.elements.items():
node1 = deformed_nodes[elem['nodes'][0]]
node2 = deformed_nodes[elem['nodes'][1]]
self.ax.plot([node1['x'], node2['x']], [node1['y'], node2['y']],
'r--', alpha=0.5)

self.fig.canvas.draw()

def add_node_interactive(self, event):


"""Interactive method to add a node"""
print("Click on the plot to add a node")
self.fig.canvas.mpl_connect('button_press_event',
self.on_click_add_node)

def on_click_add_node(self, event):


"""Handle node addition click"""
if event.inaxes != self.ax:
return

node_id = len(self.nodes) + 1
self.add_node(node_id, event.xdata, event.ydata)
self.fig.canvas.mpl_disconnect(self.fig.canvas.button_press_event)
print(f"Added Node {node_id} at ({event.xdata:.2f},
{event.ydata:.2f})")

def add_element_interactive(self, event):


"""Interactive method to add an element"""
if len(self.nodes) < 2:
print("Need at least 2 nodes to create an element")

P a g e 5 | 62

You might also like