File size: 1,501 Bytes
3f7c1e8
92ef7be
3f7c1e8
fba0c90
3f7c1e8
d037932
3f7c1e8
 
92ef7be
3f7c1e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fba0c90
 
3f7c1e8
 
1
2
3
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
33
34
35
36
37
38
39
# ansys_simulation.py

import ansys.mapdl.core as pymapdl

def run_ansys_simulation(thickness, hole_diameter, force):
    try:
        # Launch ANSYS Mapdl instance
        mapdl = pymapdl.launch_mapdl()

        # Set the parameters for the simulation
        print(f"Running ANSYS simulation with Thickness: {thickness}, Hole Diameter: {hole_diameter}, Force: {force}")

        # Define some simple simulation commands for the sake of example
        mapdl.clear()  # Clear any previous simulations or settings
        mapdl.prep7()  # Switch to preprocessor module

        # Example of setting up a material, geometry, and boundary conditions
        mapdl.et(1, 183)  # Define element type (e.g., solid)
        mapdl.keyopt(1, 3, 3)  # Some element option (example)

        # Setup the geometry (creating a simple solid object based on input parameters)
        mapdl.blk(0, thickness, 0, hole_diameter, 0, force)  # Example block based on input

        # Solve the problem
        mapdl.solve()

        # Get results
        result = mapdl.result
        max_stress = result.stress().max()  # Get maximum stress
        max_deformation = result.deformation().max()  # Get maximum deformation

        print(f"Max Stress: {max_stress} Pa, Max Deformation: {max_deformation} mm")
        
        return max_stress, max_deformation

    except Exception as e:
        print(f"Error during ANSYS simulation: {str(e)}")
        raise  # Re-raise the error to be handled by the calling function