karthikmn commited on
Commit
fba0c90
·
verified ·
1 Parent(s): 2bfeaf1

Update ansys_simulation.py

Browse files
Files changed (1) hide show
  1. ansys_simulation.py +28 -39
ansys_simulation.py CHANGED
@@ -1,40 +1,29 @@
1
- from ansys.mapdl.core import launch_mapdl
2
-
3
  def run_ansys_simulation(thickness, hole_diameter, force):
4
- mapdl = launch_mapdl()
5
- mapdl.clear()
6
- mapdl.prep7()
7
-
8
- # Material properties
9
- mapdl.mp("EX", 1, 2e11)
10
- mapdl.mp("PRXY", 1, 0.3)
11
-
12
- # Geometry
13
- mapdl.block(0, 100, 0, 50, 0, thickness)
14
- mapdl.cylind(0, hole_diameter / 2, 50, 25, 0, thickness)
15
- mapdl.vsubtract("ALL")
16
-
17
- # Meshing
18
- mapdl.et(1, "SOLID185")
19
- mapdl.esize(5)
20
- mapdl.vmesh("ALL")
21
-
22
- # Boundary conditions and force
23
- mapdl.nsel("S", "LOC", "X", 0)
24
- mapdl.d("ALL", "ALL")
25
- mapdl.nsel("S", "LOC", "X", 100)
26
- mapdl.f("ALL", "FY", -force)
27
-
28
- # Solve
29
- mapdl.run("/SOLU")
30
- mapdl.antype("STATIC")
31
- mapdl.solve()
32
- mapdl.finish()
33
-
34
- # Post-process
35
- mapdl.post1()
36
- max_stress = mapdl.get_value("NODE", 0, "S", "EQV")
37
- max_deformation = mapdl.get_value("NODE", 0, "U", "SUM")
38
- mapdl.exit()
39
-
40
- return max_stress, max_deformation
 
 
 
1
  def run_ansys_simulation(thickness, hole_diameter, force):
2
+ try:
3
+ import ansys.mapdl.core as pymapdl
4
+
5
+ # Launch ANSYS Mapdl instance
6
+ mapdl = pymapdl.launch_mapdl()
7
+
8
+ # Define the commands to run ANSYS simulation
9
+ # (Insert specific ANSYS commands as needed)
10
+ print(f"Running ANSYS simulation with thickness={thickness}, hole_diameter={hole_diameter}, force={force}")
11
+
12
+ # Example of running a simulation
13
+ # The commands here will depend on your specific ANSYS simulation setup
14
+ mapdl.run(f'! Set parameters for simulation: Thickness={thickness}, Hole_Diameter={hole_diameter}, Force={force}')
15
+ mapdl.run('! Further simulation commands')
16
+
17
+ # Ensure output is being captured
18
+ result = mapdl.result
19
+ max_stress = result.stress().max() # Example result fetching
20
+ max_deformation = result.deformation().max()
21
+
22
+ print(f"Max Stress: {max_stress}, Max Deformation: {max_deformation}")
23
+
24
+ return max_stress, max_deformation
25
+
26
+ except Exception as e:
27
+ print(f"Error during ANSYS simulation: {str(e)}")
28
+ raise # Reraise the error for further handling
29
+