Spaces:
Sleeping
Sleeping
Update ansys_simulation.py
Browse files- ansys_simulation.py +23 -16
ansys_simulation.py
CHANGED
|
@@ -1,29 +1,36 @@
|
|
|
|
|
|
|
|
| 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 |
-
#
|
| 9 |
-
|
| 10 |
-
print(f"Running ANSYS simulation with thickness={thickness}, hole_diameter={hole_diameter}, force={force}")
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
#
|
| 14 |
-
mapdl.
|
| 15 |
-
mapdl.run('! Further simulation commands')
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
|
|
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
return max_stress, max_deformation
|
| 25 |
|
| 26 |
except Exception as e:
|
| 27 |
print(f"Error during ANSYS simulation: {str(e)}")
|
| 28 |
-
raise #
|
| 29 |
-
|
|
|
|
| 1 |
+
import ansys.mapdl.core as pymapdl
|
| 2 |
+
|
| 3 |
def run_ansys_simulation(thickness, hole_diameter, force):
|
| 4 |
try:
|
|
|
|
|
|
|
| 5 |
# Launch ANSYS Mapdl instance
|
| 6 |
mapdl = pymapdl.launch_mapdl()
|
| 7 |
|
| 8 |
+
# Set the parameters for the simulation
|
| 9 |
+
print(f"Running ANSYS simulation with Thickness: {thickness}, Hole Diameter: {hole_diameter}, Force: {force}")
|
|
|
|
| 10 |
|
| 11 |
+
# Define some simple simulation commands for the sake of example
|
| 12 |
+
mapdl.clear() # Clear any previous simulations or settings
|
| 13 |
+
mapdl.prep7() # Switch to preprocessor module
|
|
|
|
| 14 |
|
| 15 |
+
# Example of setting up a material, geometry, and boundary conditions
|
| 16 |
+
mapdl.et(1, 183) # Define element type (e.g., solid)
|
| 17 |
+
mapdl.keyopt(1, 3, 3) # Some element option (example)
|
| 18 |
+
|
| 19 |
+
# Setup the geometry (creating a simple solid object based on input parameters)
|
| 20 |
+
mapdl.blk(0, thickness, 0, hole_diameter, 0, force) # Example block based on input
|
| 21 |
|
| 22 |
+
# Solve the problem
|
| 23 |
+
mapdl.solve()
|
| 24 |
|
| 25 |
+
# Get results
|
| 26 |
+
result = mapdl.result
|
| 27 |
+
max_stress = result.stress().max() # Get maximum stress
|
| 28 |
+
max_deformation = result.deformation().max() # Get maximum deformation
|
| 29 |
+
|
| 30 |
+
print(f"Max Stress: {max_stress} Pa, Max Deformation: {max_deformation} mm")
|
| 31 |
+
|
| 32 |
return max_stress, max_deformation
|
| 33 |
|
| 34 |
except Exception as e:
|
| 35 |
print(f"Error during ANSYS simulation: {str(e)}")
|
| 36 |
+
raise # Re-raise the error to be handled by the calling function
|
|
|