Spaces:
Sleeping
Sleeping
Create analysis.py
Browse files- analysis.py +37 -0
analysis.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
|
| 4 |
+
def stress_analysis(force, die_width, die_height, material_strength, temperature_change=50, alpha=1e-5, elastic_modulus=200000, fatigue_strength=150):
|
| 5 |
+
try:
|
| 6 |
+
stress = force / (die_width * die_height)
|
| 7 |
+
safety_factor = material_strength / stress
|
| 8 |
+
thermal_stress = elastic_modulus * alpha * temperature_change
|
| 9 |
+
fatigue_stress = fatigue_strength
|
| 10 |
+
|
| 11 |
+
x = np.linspace(1, 100, 100)
|
| 12 |
+
stress_curve = stress * x / 100
|
| 13 |
+
material_strength_curve = np.full_like(x, material_strength)
|
| 14 |
+
safety_factor_curve = material_strength_curve / stress_curve
|
| 15 |
+
thermal_stress_curve = np.full_like(x, thermal_stress)
|
| 16 |
+
fatigue_strength_curve = np.full_like(x, fatigue_stress)
|
| 17 |
+
|
| 18 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 19 |
+
ax.plot(x, stress_curve, label="Stress (σ)", color="blue")
|
| 20 |
+
ax.plot(x, material_strength_curve, label="Material Strength (σ_y)", color="green")
|
| 21 |
+
ax.plot(x, safety_factor_curve, label="Safety Factor (SF)", color="orange")
|
| 22 |
+
ax.plot(x, thermal_stress_curve, label="Thermal Stress (σ_thermal)", color="purple")
|
| 23 |
+
ax.plot(x, fatigue_strength_curve, label="Fatigue Strength (σ_fatigue)", color="brown")
|
| 24 |
+
ax.axhline(1, color="red", linestyle="--", label="Critical Safety Threshold (SF=1)")
|
| 25 |
+
|
| 26 |
+
ax.set_title("Combined Stress Analysis Parameters")
|
| 27 |
+
ax.set_xlabel("Operational Range (%)")
|
| 28 |
+
ax.set_ylabel("Parameter Value (MPa or Unitless)")
|
| 29 |
+
ax.legend()
|
| 30 |
+
ax.grid()
|
| 31 |
+
|
| 32 |
+
plt.tight_layout()
|
| 33 |
+
plt.close(fig)
|
| 34 |
+
|
| 35 |
+
return f"Safety Factor: {round(safety_factor, 2)}", fig
|
| 36 |
+
except Exception as e:
|
| 37 |
+
return f"Error in stress analysis: {str(e)}", None
|