%22%22%22Interpolate%20an%20S%E2%80%93N%20curve%20and%20calculate%20damage%20by%20stress%20range.%22%22%22%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.26.0%22%0Aapp%20%3D%20marimo.App(css_file%3D%22..%2Fdocs%2Fstylesheets%2Fcustom.css%22)%0A%0A%0A%40app.cell%0Adef%20introduction()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%20%20%20%20%23%20S%E2%80%93N%20and%20Miner%20damage%0A%0A%20%20%20%20%20%20%20%20Build%20a%20piecewise%20S%E2%80%93N%20curve%20from%20three%20points%20in%20the%20user%20guide%20and%0A%20%20%20%20%20%20%20%20give%20it%20a%20finite%20endurance%20limit.%20The%20first%20plot%20marks%20the%20interior%0A%20%20%20%20%20%20%20%20knee%2C%20the%20endurance%20limit%2C%20and%20the%20applied%20ranges%20with%20finite%20lives.%0A%0A%20%20%20%20%20%20%20%20The%20second%20plot%20shows%20the%20Palmgren%E2%80%93Miner%20contribution%20of%20each%20range.%0A%20%20%20%20%20%20%20%20The%2050%20MPa%20range%20falls%20below%20the%20endurance%20stress%2C%20so%20its%20predicted%0A%20%20%20%20%20%20%20%20life%20is%20infinite%20and%20its%20Miner%20contribution%20is%20zero.%0A%20%20%20%20%20%20%20%20%22%22%22)%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell%0Adef%20calculate(mo)%3A%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20from%20py_fatigue%20import%20CycleCount%2C%20SNCurve%0A%20%20%20%20from%20_examples.charts%20import%20plot_views%0A%0A%20%20%20%20cycles%20%3D%20CycleCount(%0A%20%20%20%20%20%20%20%20stress_range%3Dnp.array(%5B50.0%2C%2080.0%2C%20120.0%5D)%2C%0A%20%20%20%20%20%20%20%20mean_stress%3Dnp.zeros(3)%2C%0A%20%20%20%20%20%20%20%20count_cycle%3Dnp.array(%5B1000.0%2C%201000.0%2C%20100.0%5D)%2C%0A%20%20%20%20)%0A%20%20%20%20curve%20%3D%20SNCurve.from_knee_points(%0A%20%20%20%20%20%20%20%20knee_stress%3D%5B150.0%2C%2086.0%2C%2056.0%5D%2C%0A%20%20%20%20%20%20%20%20knee_cycles%3D%5B207_880%2C%20963_397%2C%207_525_202%5D%2C%0A%20%20%20%20%20%20%20%20endurance%3D7_525_202%2C%0A%20%20%20%20)%0A%20%20%20%20damage%20%3D%20cycles.to_df().miner.damage(curve)%0A%20%20%20%20fig%2C%20(ax%2C%20contributions)%20%3D%20plt.subplots(2%2C%201%2C%20layout%3D%22constrained%22)%0A%20%20%20%20curve.plot(ax%3Dax)%0A%20%20%20%20ax.lines%5B-1%5D.set_label(%22Interpolated%20S%E2%80%93N%20curve%22)%0A%20%20%20%20knees%20%3D%20curve.get_knee_cycles()%0A%20%20%20%20ax.scatter(knees%2C%20curve.get_stress(knees)%2C%20label%3D%22Interior%20knee%22%2C%20zorder%3D4)%0A%20%20%20%20ax.axhline(curve.endurance_stress%2C%20linestyle%3D%22--%22%2C%20label%3D%22Endurance%20stress%22)%0A%20%20%20%20finite%20%3D%20np.isfinite(damage.cycles_to_failure)%0A%20%20%20%20ax.scatter(%0A%20%20%20%20%20%20%20%20damage.loc%5Bfinite%2C%20%22cycles_to_failure%22%5D%2C%0A%20%20%20%20%20%20%20%20damage.loc%5Bfinite%2C%20%22stress_range%22%5D%2C%0A%20%20%20%20%20%20%20%20label%3D%22Applied%20ranges%20with%20finite%20life%22%2C%0A%20%20%20%20%20%20%20%20zorder%3D3%2C%0A%20%20%20%20)%0A%20%20%20%20ax.legend()%0A%20%20%20%20damage.miner.plot(ax%3Dcontributions)%0A%0A%20%20%20%20mo.vstack(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20plot_views(fig%2C%20height%3D%22830px%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(f%22**Total%20Miner%20damage**%20%60%7Bdamage.pm_damage.sum()%3A.4g%7D%60%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.table(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20damage%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22stress_range%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22count_cycle%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22cycles_to_failure%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pm_damage%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20return%20(curve%2C)%0A%0A%0A%40app.cell%0Adef%20long_case(curve)%3A%0A%20%20%20%20import%20matplotlib.pyplot%20as%20_plt%0A%20%20%20%20import%20numpy%20as%20_np%0A%20%20%20%20from%20_examples.synthetic%20import%20(%0A%20%20%20%20%20%20%20%20MINIMUM_STRESS%2C%0A%20%20%20%20%20%20%20%20display_indices%2C%0A%20%20%20%20%20%20%20%20long_case_view%2C%0A%20%20%20%20%20%20%20%20synthetic_peaks%2C%0A%20%20%20%20)%0A%20%20%20%20from%20py_fatigue%20import%20SNCurve%20as%20_SNCurve%0A%20%20%20%20from%20py_fatigue.damage%20import%20calc_pm%0A%0A%20%20%20%20peaks%20%3D%20synthetic_peaks()%0A%20%20%20%20ranges%20%3D%20peaks%20-%20MINIMUM_STRESS%0A%20%20%20%20unit_counts%20%3D%20_np.ones_like(ranges)%0A%20%20%20%20long_fig%2C%20long_ax%20%3D%20_plt.subplots()%0A%20%20%20%20for%20sn%2C%20label%20in%20(%0A%20%20%20%20%20%20%20%20(curve%2C%20%22Piecewise%20curve%22)%2C%0A%20%20%20%20%20%20%20%20(_SNCurve(3%2C%2010.493)%2C%20%22W3-C%22)%2C%0A%20%20%20%20)%3A%0A%20%20%20%20%20%20%20%20long_damage%20%3D%20_np.r_%5B0%2C%20_np.cumsum(calc_pm(ranges%2C%20unit_counts%2C%20sn))%5D%0A%20%20%20%20%20%20%20%20indices%20%3D%20display_indices(long_damage.size)%0A%20%20%20%20%20%20%20%20long_ax.plot(indices%2C%20long_damage%5Bindices%5D%2C%20label%3Dlabel)%0A%20%20%20%20long_ax.axhline(1.0%2C%20color%3D%220.4%22%2C%20linestyle%3D%22--%22%2C%20label%3D%22Miner%20limit%22)%0A%20%20%20%20long_ax.set(xlabel%3D%22Cumulative%20cycles%22%2C%20ylabel%3D%22Miner%20damage%22)%0A%20%20%20%20long_ax.legend()%0A%20%20%20%20below_endurance%20%3D%20_np.count_nonzero(ranges%20%3C%3D%20curve.endurance_stress)%0A%20%20%20%20long_case_view(%0A%20%20%20%20%20%20%20%20long_fig%2C%0A%20%20%20%20%20%20%20%20f%22Apply%20**%7Bpeaks.size%3A%2C%7D%20cycles**%20in%20order%20to%20both%20S%E2%80%93N%20curves.%20%22%0A%20%20%20%20%20%20%20%20f%22**%7Bbelow_endurance%3A%2C%7D%20cycles**%20are%20at%20or%20below%20the%20endurance%20stress%20%22%0A%20%20%20%20%20%20%20%20%22of%20the%20piecewise%20curve.%20Compare%20its%20damage%20history%20with%20W3-C.%22%2C%0A%20%20%20%20)%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
24b8a0b09313b8437d14c59b71bcfd63