Spaces:
Sleeping
Sleeping
Update ansys_simulation.py
Browse files- 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 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 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 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|