karthikmn commited on
Commit
944acc4
·
verified ·
1 Parent(s): db95985

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -8,8 +8,11 @@ from pycalculix import *
8
 
9
  # Simulation Workflow
10
  def simulation_workflow(use_case, simulator, **kwargs):
 
 
11
  # Generate APDL script based on user inputs
12
  if use_case == "plate":
 
13
  apdl_script = f"""
14
  /PREP7
15
  MP,EX,1,2E11 ! Elastic modulus
@@ -33,6 +36,7 @@ PRNSOL,U,SUM ! Print total deformation results
33
  /EXIT
34
  """
35
  elif use_case == "beam":
 
36
  apdl_script = f"""
37
  /PREP7
38
  MP,EX,1,2E11 ! Elastic modulus
@@ -54,14 +58,18 @@ PRNSOL,U,SUM ! Print total deformation results
54
  /EXIT
55
  """
56
  else:
 
57
  return "Invalid use case selected.", None, None
58
 
59
  # Save APDL script
60
  with open("simulation_input.inp", "w") as file:
61
  file.write(apdl_script)
62
 
 
 
63
  # Run the selected simulator
64
  if simulator == "PyCalculix":
 
65
  model = Model("pycalculix_simulation")
66
  model.set_units("mm")
67
  part = Part("block", model)
@@ -73,6 +81,7 @@ PRNSOL,U,SUM ! Print total deformation results
73
  stress = model.results().max_stress()
74
  deformation = model.results().max_displacement()
75
  elif simulator == "ANSYS":
 
76
  mapdl = launch_mapdl()
77
  mapdl.input("simulation_input.inp")
78
  max_stress = mapdl.get_value("NODE", 0, "S", "EQV")
@@ -80,9 +89,13 @@ PRNSOL,U,SUM ! Print total deformation results
80
  mapdl.exit()
81
  stress, deformation = max_stress, deformation
82
  else:
 
83
  return "Invalid simulator selected.", None, None
84
 
 
 
85
  # Visualize results (both 2D and 3D)
 
86
  fig, ax = plt.subplots()
87
  ax.bar(["Stress", "Deformation"], [stress, deformation], color=["red", "blue"])
88
  ax.set_title(f"Results ({simulator})")
@@ -120,4 +133,5 @@ interface = gr.Interface(
120
  )
121
 
122
  # Launch Gradio interface
 
123
  interface.launch()
 
8
 
9
  # Simulation Workflow
10
  def simulation_workflow(use_case, simulator, **kwargs):
11
+ print(f"Running simulation for use_case={use_case}, simulator={simulator}")
12
+
13
  # Generate APDL script based on user inputs
14
  if use_case == "plate":
15
+ print("Generating APDL script for plate simulation...")
16
  apdl_script = f"""
17
  /PREP7
18
  MP,EX,1,2E11 ! Elastic modulus
 
36
  /EXIT
37
  """
38
  elif use_case == "beam":
39
+ print("Generating APDL script for beam simulation...")
40
  apdl_script = f"""
41
  /PREP7
42
  MP,EX,1,2E11 ! Elastic modulus
 
58
  /EXIT
59
  """
60
  else:
61
+ print("Invalid use case selected.")
62
  return "Invalid use case selected.", None, None
63
 
64
  # Save APDL script
65
  with open("simulation_input.inp", "w") as file:
66
  file.write(apdl_script)
67
 
68
+ print(f"APDL script saved at: simulation_input.inp")
69
+
70
  # Run the selected simulator
71
  if simulator == "PyCalculix":
72
+ print("Running PyCalculix simulation...")
73
  model = Model("pycalculix_simulation")
74
  model.set_units("mm")
75
  part = Part("block", model)
 
81
  stress = model.results().max_stress()
82
  deformation = model.results().max_displacement()
83
  elif simulator == "ANSYS":
84
+ print("Running ANSYS simulation...")
85
  mapdl = launch_mapdl()
86
  mapdl.input("simulation_input.inp")
87
  max_stress = mapdl.get_value("NODE", 0, "S", "EQV")
 
89
  mapdl.exit()
90
  stress, deformation = max_stress, deformation
91
  else:
92
+ print("Invalid simulator selected.")
93
  return "Invalid simulator selected.", None, None
94
 
95
+ print(f"Simulation results - Stress: {stress}, Deformation: {deformation}")
96
+
97
  # Visualize results (both 2D and 3D)
98
+ print("Visualizing results...")
99
  fig, ax = plt.subplots()
100
  ax.bar(["Stress", "Deformation"], [stress, deformation], color=["red", "blue"])
101
  ax.set_title(f"Results ({simulator})")
 
133
  )
134
 
135
  # Launch Gradio interface
136
+ print("Launching Gradio interface...")
137
  interface.launch()