jithenderchoudary commited on
Commit
2346db9
·
verified ·
1 Parent(s): 6561c7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -87
app.py CHANGED
@@ -1,88 +1,46 @@
1
- import numpy as np
2
- import matplotlib.pyplot as plt
3
- from ansys.mapdl.core import launch_mapdl
4
- # Launch ANSYS MAPDL instance
5
- mapdl = launch_mapdl()
6
- # Clear any previous session
7
- mapdl.clear()
8
- mapdl.prep7() # Enter preprocessor
9
- # Function to define and simulate the boring machine attachment
10
- def simulate_attachment(thickness):
11
- # Define material properties
12
- mapdl.mp("EX", 1, 2e11) # Elastic modulus (Pa)
13
- mapdl.mp("PRXY", 1, 0.3) # Poisson's ratio
14
- # Create geometry
15
- mapdl.block(0, 200, 0, 100, 0, thickness) # Rectangular block
16
- mapdl.cylind(0, 10, 50, 50, 0, thickness) # Cylindrical hole
17
- mapdl.vsubtract("ALL") # Subtract cylinder from block
18
- # Define element type and mesh
19
- mapdl.et(1, "SOLID185") # 3D structural element
20
- mapdl.esize(5) # Element size
21
- mapdl.vmesh("ALL") # Mesh all volumes
22
- # Apply boundary conditions
23
- mapdl.nsel("S", "LOC", "X", 0) # Select nodes on one end
24
- 38/112
25
- mapdl.d("ALL", "ALL") # Fix all degrees of freedom
26
- mapdl.nsel("S", "LOC", "X", 200) # Select nodes on the other end
27
- mapdl.f("ALL", "FY", -5000) # Apply force
28
- # Solve
29
- mapdl.run("/SOLU") # Enter solution phase
30
- mapdl.antype("STATIC") # Static analysis
31
- mapdl.solve()
32
- mapdl.finish() # Finish solution
33
- # Post-process
34
- mapdl.post1()
35
- max_stress = mapdl.get_value("NODE", 0, "S", "EQV") # Equivalent stress
36
- max_def = mapdl.get_value("NODE", 0, "U", "SUM") # Total deformation
37
- # Save plots
38
- mapdl.post_processing.plot_nodal_solution(
39
- "S", "EQV", title=f"Stress Distribution (Thickness={thickness} mm)",
40
- savefig=f"stress_{thickness}.png"
41
- )
42
- mapdl.post_processing.plot_nodal_solution(
43
- "U", "SUM", title=f"Deformation (Thickness={thickness} mm)",
44
- savefig=f"deformation_{thickness}.png"
45
- )
46
- return max_stress, max_def
47
- # Parameter sweep for different thicknesses
48
- thickness_values = [20, 25, 30]
49
- results = []
50
- for thickness in thickness_values:
51
- max_stress, max_def = simulate_attachment(thickness)
52
- results.append({"Thickness (mm)": thickness, "Max Stress (Pa)": max_stress, "Max
53
- Deformation (mm)": max_def})
54
- # Visualize results
55
  import pandas as pd
56
- results_df = pd.DataFrame(results)
57
- print(results_df)
58
- 39/112
59
- Key Features
60
- 1. Geometry Creation:
61
- Python creates the geometry of the attachment, including a rectangular block with a
62
- cylindrical hole.
63
- 2. Material Properties:
64
- Elastic modulus and Poisson's ratio are assigned programmatically.
65
- 3. Meshing:
66
- Element type SOLID185 and ne mesh control are applied.
67
- 4. Boundary Conditions and Loading:
68
- Fixes one side and applies a distributed load on the opposite side.
69
- 5. Result Extraction:
70
- Maximum stress and deformation are retrieved for each thickness.
71
- Results are saved as plots for stress distribution and deformation.
72
- 6. Parameter Sweep:
73
- Thickness is varied (20 mm, 25 mm, 30 mm), and simulations are run for each case.
74
- # Plot results
75
- plt.figure(figsize=(10, 5))
76
- plt.plot(results_df["Thickness (mm)"], results_df["Max Stress (Pa)"], marker="o",
77
- label="Max Stress")
78
- plt.plot(results_df["Thickness (mm)"], results_df["Max Deformation (mm)"],
79
- marker="o", label="Max Deformation")
80
- plt.xlabel("Thickness (mm)")
81
- plt.ylabel("Value")
82
- plt.title("Effect of Thickness on Stress and Deformation")
83
- plt.legend()
84
- plt.grid()
85
- plt.savefig("results_plot.png")
86
- plt.show()
87
- # Exit MAPDL
88
- mapdl.exit()
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import pandas as pd
3
+ import pickle
4
+ from models.optimizer import optimize_design
5
+
6
+ # Load pre-trained model
7
+ def load_model():
8
+ with open("models/defect_model.pkl", "rb") as file:
9
+ model = pickle.load(file)
10
+ return model
11
+
12
+ # Predict defects
13
+ def predict_defects(model, data):
14
+ predictions = model.predict(data)
15
+ return predictions
16
+
17
+ st.title("Press Tool AI: Defect Prediction and Optimization")
18
+
19
+ # File upload
20
+ uploaded_file = st.file_uploader("Upload Design Parameters (CSV)", type="csv")
21
+ if uploaded_file:
22
+ data = pd.read_csv(uploaded_file)
23
+ st.write("Uploaded Data:")
24
+ st.dataframe(data)
25
+
26
+ # Load AI model
27
+ model = load_model()
28
+
29
+ # Predict defects
30
+ st.subheader("Defect Predictions:")
31
+ predictions = predict_defects(model, data)
32
+ data['Predicted Defects'] = predictions
33
+ st.dataframe(data)
34
+
35
+ # Optimize design
36
+ st.subheader("Optimized Parameters:")
37
+ optimized_data = optimize_design(data)
38
+ st.dataframe(optimized_data)
39
+
40
+ # Download results
41
+ st.download_button(
42
+ label="Download Results",
43
+ data=optimized_data.to_csv(index=False),
44
+ file_name="optimized_design.csv",
45
+ mime="text/csv",
46
+ )