karthikmn commited on
Commit
3a5b1a4
·
verified ·
1 Parent(s): 14d4c59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -4
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import os
2
  import gradio as gr
 
 
3
 
4
  def generate_apdl_script(step_file_path, material_e, material_nu, mesh_size, load_value):
5
  """
@@ -59,10 +61,51 @@ prnsol, u, comp
59
 
60
  return apdl_file_path
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  # Gradio interface
63
  def process_step_file(step_file, material_e, material_nu, mesh_size, load_value):
64
- apdl_file = generate_apdl_script(step_file.name, material_e, material_nu, mesh_size, load_value)
65
- return apdl_file
 
66
 
67
  # Define Gradio Interface
68
  with gr.Blocks() as app:
@@ -74,12 +117,13 @@ with gr.Blocks() as app:
74
  load_value = gr.Number(label="Load Value (N)", value=1000)
75
 
76
  submit_button = gr.Button("Submit")
77
- output = gr.File(label="Download Generated APDL Script")
 
78
 
79
  submit_button.click(
80
  process_step_file,
81
  inputs=[step_file, material_e, material_nu, mesh_size, load_value],
82
- outputs=output,
83
  )
84
 
85
  if __name__ == "__main__":
 
1
  import os
2
  import gradio as gr
3
+ from ansys.mapdl.core import launch_mapdl
4
+
5
 
6
  def generate_apdl_script(step_file_path, material_e, material_nu, mesh_size, load_value):
7
  """
 
61
 
62
  return apdl_file_path
63
 
64
+
65
+ def run_simulation(step_file, material_e, material_nu, mesh_size, load_value):
66
+ """
67
+ Generate the APDL script, run the simulation, and fetch results.
68
+ """
69
+ # Generate the APDL script
70
+ apdl_file_path = generate_apdl_script(step_file.name, material_e, material_nu, mesh_size, load_value)
71
+
72
+ # Launch ANSYS MAPDL (ensure it's installed and licensed)
73
+ mapdl = launch_mapdl()
74
+
75
+ # Upload STEP file and APDL script to MAPDL
76
+ mapdl.upload(step_file.name)
77
+ mapdl.input(apdl_file_path)
78
+
79
+ # Run the APDL script
80
+ mapdl.run("/SOLU")
81
+ mapdl.solve()
82
+
83
+ # Post-process results
84
+ stress_output = mapdl.result.principal_stress()
85
+ displacement_output = mapdl.result.nodal_displacement()
86
+
87
+ # Save outputs
88
+ stress_file = "/tmp/stress_results.txt"
89
+ with open(stress_file, "w") as f:
90
+ f.write("Principal Stress Results:\n")
91
+ f.write(str(stress_output))
92
+
93
+ displacement_file = "/tmp/displacement_results.txt"
94
+ with open(displacement_file, "w") as f:
95
+ f.write("Nodal Displacement Results:\n")
96
+ f.write(str(displacement_output))
97
+
98
+ # Stop MAPDL
99
+ mapdl.exit()
100
+
101
+ return stress_file, displacement_file
102
+
103
+
104
  # Gradio interface
105
  def process_step_file(step_file, material_e, material_nu, mesh_size, load_value):
106
+ stress_file, displacement_file = run_simulation(step_file, material_e, material_nu, mesh_size, load_value)
107
+ return stress_file, displacement_file
108
+
109
 
110
  # Define Gradio Interface
111
  with gr.Blocks() as app:
 
117
  load_value = gr.Number(label="Load Value (N)", value=1000)
118
 
119
  submit_button = gr.Button("Submit")
120
+ stress_output = gr.File(label="Download Stress Results")
121
+ displacement_output = gr.File(label="Download Displacement Results")
122
 
123
  submit_button.click(
124
  process_step_file,
125
  inputs=[step_file, material_e, material_nu, mesh_size, load_value],
126
+ outputs=[stress_output, displacement_output],
127
  )
128
 
129
  if __name__ == "__main__":