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