karthikmn commited on
Commit
92ef7be
·
verified ·
1 Parent(s): fba0c90

Update ansys_simulation.py

Browse files
Files changed (1) hide show
  1. 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
- # 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
-
 
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