karthikmn commited on
Commit
71602b2
·
verified ·
1 Parent(s): 8a33f4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -48
app.py CHANGED
@@ -1,15 +1,14 @@
1
  from ansys.mapdl.core import launch_mapdl
2
- import numpy as np
3
  import gradio as gr
4
 
5
- # Function to generate progressive die design using ANSYS MAPDL
6
- def generate_progressive_die_ANSYS(length, width, thickness, num_stations, punch_diameter, punch_depth, die_shape):
7
  try:
8
- if length <= 0 or width <= 0 or thickness <= 0 or num_stations <= 0:
9
- return "Dimensions and number of stations must be greater than zero."
10
 
11
- # Launch ANSYS MAPDL session in non-interactive mode
12
- mapdl = launch_mapdl(interactive=False)
13
  mapdl.clear() # Clear any previous settings
14
 
15
  # Preprocessing
@@ -17,56 +16,40 @@ def generate_progressive_die_ANSYS(length, width, thickness, num_stations, punch
17
 
18
  # Die shape logic
19
  if die_shape == "Rectangle":
20
- mapdl.block(0, length, 0, width, 0, thickness) # Create a rectangular block (base die)
21
  elif die_shape == "Circle":
22
- mapdl.cylind(0, 0, width / 2, 0, thickness) # Create a cylindrical block (base die)
23
-
24
- # Create punch shapes for each station
25
- punch_spacing = length / (num_stations + 1) # Space punches evenly along length
26
-
27
- for station in range(1, num_stations + 1):
28
- punch_center_x = station * punch_spacing
29
- punch_center_y = width / 2 # Center the punch along the width
30
-
31
- # Create cylindrical punches (holes in the die)
32
- mapdl.cylind(punch_center_x, punch_center_y, punch_diameter / 2, 0, punch_depth)
33
 
34
  # Save the geometry as a STEP file
35
- filename = f"progressive_die_{die_shape}_{length}x{width}x{thickness}_{num_stations}_stations.step"
36
- mapdl.save_as(filename)
37
- mapdl.exit() # Close the session
38
-
39
- # Return success message with station info
40
- return f"Progressive Die design saved successfully as {filename}. The die has {num_stations} punch stations."
41
 
 
 
 
42
  except Exception as e:
43
- return f"Error generating progressive die design: {str(e)}"
44
 
45
- # Gradio interface function
46
- def progressive_die_interface(length, width, thickness, num_stations, punch_diameter, punch_depth, die_shape):
47
- return generate_progressive_die_ANSYS(length, width, thickness, num_stations, punch_diameter, punch_depth, die_shape)
48
 
49
  # Create the Gradio Interface
50
  with gr.Blocks() as app:
51
- gr.Markdown("## Progressive Die Design with ANSYS MAPDL")
52
- gr.Markdown("### Enter the parameters for the die design")
53
-
54
- with gr.Tabs():
55
- # Tab for Progressive Die Design
56
- with gr.Tab("Progressive Die Design"):
57
- gr.Markdown("### Enter Dimensions and Punch Parameters")
58
- length = gr.Number(label="Die Length (mm)", value=500)
59
- width = gr.Number(label="Die Width (mm)", value=200)
60
- thickness = gr.Number(label="Die Thickness (mm)", value=50)
61
- num_stations = gr.Number(label="Number of Stations", value=5)
62
- punch_diameter = gr.Number(label="Punch Diameter (mm)", value=20)
63
- punch_depth = gr.Number(label="Punch Depth (mm)", value=10)
64
- die_shape = gr.Dropdown(label="Die Shape", choices=["Rectangle", "Circle"], value="Rectangle")
65
- die_output = gr.Textbox(label="Output", interactive=False)
66
- die_button = gr.Button("Generate Die")
67
- die_button.click(progressive_die_interface, inputs=[length, width, thickness, num_stations, punch_diameter, punch_depth, die_shape], outputs=die_output)
68
 
69
  # Launch the app
70
  app.launch()
71
-
72
-
 
1
  from ansys.mapdl.core import launch_mapdl
 
2
  import gradio as gr
3
 
4
+ # Function to generate die design using ANSYS MAPDL
5
+ def generate_die_ANSYS(length, width, thickness, die_shape):
6
  try:
7
+ if length <= 0 or width <= 0 or thickness <= 0:
8
+ return "Dimensions must be greater than zero."
9
 
10
+ # Launch ANSYS MAPDL session (without interactive argument)
11
+ mapdl = launch_mapdl() # Start MAPDL session
12
  mapdl.clear() # Clear any previous settings
13
 
14
  # Preprocessing
 
16
 
17
  # Die shape logic
18
  if die_shape == "Rectangle":
19
+ mapdl.block(0, length, 0, width, 0, thickness) # Create a rectangular block
20
  elif die_shape == "Circle":
21
+ mapdl.cylind(0, 0, width / 2, 0, thickness) # Create a cylindrical block
 
 
 
 
 
 
 
 
 
 
22
 
23
  # Save the geometry as a STEP file
24
+ filename = f"generated_die_{die_shape}_{length}x{width}x{thickness}.step"
25
+ mapdl.save_as(filename) # Save the design as STEP file
26
+ mapdl.exit() # Exit the MAPDL session
 
 
 
27
 
28
+ # Return success message with the file path
29
+ return f"Die design saved successfully as {filename}. You can download the file."
30
+
31
  except Exception as e:
32
+ return f"Error generating die design: {str(e)}"
33
 
34
+ # Gradio interface functions for Progressive Die Design
35
+ def progressive_die_interface(length, width, thickness, die_shape):
36
+ return generate_die_ANSYS(length, width, thickness, die_shape)
37
 
38
  # Create the Gradio Interface
39
  with gr.Blocks() as app:
40
+ gr.Markdown("## Progressive Die Design Tool with ANSYS")
41
+ gr.Markdown("Select the dimensions and shape for the progressive die below:")
42
+
43
+ # Tab for Progressive Die Design
44
+ with gr.Tab("Progressive Die Design"):
45
+ gr.Markdown("### Enter Dimensions and Shape for Progressive Die")
46
+ length = gr.Number(label="Length (mm)", value=100)
47
+ width = gr.Number(label="Width (mm)", value=50)
48
+ thickness = gr.Number(label="Thickness (mm)", value=10)
49
+ die_shape = gr.Dropdown(label="Die Shape", choices=["Rectangle", "Circle"], value="Rectangle")
50
+ die_output = gr.Textbox(label="Output", interactive=False)
51
+ die_button = gr.Button("Generate Die")
52
+ die_button.click(progressive_die_interface, inputs=[length, width, thickness, die_shape], outputs=die_output)
 
 
 
 
53
 
54
  # Launch the app
55
  app.launch()