karthikmn commited on
Commit
b9fe5f2
·
verified ·
1 Parent(s): f4275b2

Delete ansys_script.py

Browse files
Files changed (1) hide show
  1. ansys_script.py +0 -61
ansys_script.py DELETED
@@ -1,61 +0,0 @@
1
- import pyansys
2
- import numpy as np
3
- import matplotlib.pyplot as plt
4
-
5
- def run_beam_analysis():
6
- # Initialize ANSYS session
7
- ansys = pyansys.Mapdl()
8
-
9
- # Clear previous session data
10
- ansys.clear()
11
-
12
- # Preprocessing section
13
- ansys.prep7()
14
-
15
- # Define material properties (for steel)
16
- ansys.mp('EX', 1, 210E9) # Young's modulus (Pa)
17
- ansys.mp('NUXY', 1, 0.3) # Poisson's ratio
18
- ansys.mp('DENS', 1, 7800) # Density (kg/m³)
19
-
20
- # Define geometry (a simple beam with length 1m, width 0.1m, height 0.1m)
21
- ansys.block(0, 1, 0, 0.1, 0, 0.1) # Define a solid block (beam)
22
-
23
- # Meshing
24
- ansys.et(1, 185) # Solid element type (tetrahedron)
25
- ansys.vmesh('ALL') # Mesh all volumes
26
-
27
- # Apply boundary conditions (fixed support at one end)
28
- ansys.nsel('S', 'LOC', 'X', 0) # Select nodes at x=0
29
- ansys.d('ALL', 'UX', 0) # Fix displacement in X direction
30
- ansys.d('ALL', 'UY', 0) # Fix displacement in Y direction
31
- ansys.d('ALL', 'UZ', 0) # Fix displacement in Z direction
32
-
33
- # Apply load (a force at the free end of the beam)
34
- ansys.nsel('S', 'LOC', 'X', 1) # Select nodes at x=1 (free end)
35
- ansys.sf('ALL', 1, 'F', 1000) # Apply force of 1000N in Z direction
36
-
37
- # Solve the model
38
- ansys.solve()
39
-
40
- # Post-processing to extract results (stress distribution)
41
- ansys.post1()
42
- ansys.set(1, 1) # Set result set
43
- stress = ansys.prnsol('S', 'ALL') # Extract stress at all nodes/elements
44
-
45
- # Convert stress values to numpy array for easier manipulation
46
- stress_values = np.array(stress)
47
-
48
- # Now let's plot the stress distribution
49
- fig, ax = plt.subplots()
50
- ax.plot(np.linspace(0, 1, len(stress_values)), stress_values, label='Stress Distribution')
51
- ax.set_xlabel('Position along the Beam (m)')
52
- ax.set_ylabel('Stress (Pa)')
53
- ax.set_title('Stress Distribution in Beam')
54
- ax.legend()
55
-
56
- # Save the plot to a file
57
- plot_path = "/tmp/stress_distribution.png"
58
- plt.savefig(plot_path)
59
-
60
- # Return plot path for visualization in Gradio
61
- return plot_path