%22%22%22Compare%20Miner%2C%20Pavlou%2C%20and%20Theil%20under%20ordered%20stress%20blocks.%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%20Nonlinear%20damage%20under%20ordered%20loading%0A%0A%20%20%20%20%20%20%20%20Apply%20three%20blocks%20in%20increasing%20stress%20order%2C%20then%20reverse%20their%0A%20%20%20%20%20%20%20%20order.%20Miner%20sums%20the%20same%20contributions%20in%20both%20cases.%20Compare%20that%0A%20%20%20%20%20%20%20%20with%20the%20Pavlou%20damage%20curve%20approach%2C%20which%20weights%20increments%20using%0A%20%20%20%20%20%20%20%20the%20accumulated%20damage.%0A%0A%20%20%20%20%20%20%20%20The%20second%20panel%20shows%20a%20separate%20calculation%2C%20the%20Theil%20effective%0A%20%20%20%20%20%20%20%20stress%20history%2C%20against%20the%20S%E2%80%93N%20curve.%20The%20blocks%20are%20teaching%20inputs%0A%20%20%20%20%20%20%20%20supplied%20in%20order.%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%20compare(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%20SNCurve%0A%20%20%20%20from%20py_fatigue.damage.stress_life%20import%20(%0A%20%20%20%20%20%20%20%20calc_nonlinear_damage_with_dca%2C%0A%20%20%20%20%20%20%20%20calc_pm%2C%0A%20%20%20%20%20%20%20%20calc_theil_sn_damage%2C%0A%20%20%20%20)%0A%20%20%20%20from%20_examples.charts%20import%20plot_views%0A%0A%20%20%20%20ranges%20%3D%20np.array(%5B50.0%2C%20100.0%2C%20150.0%5D)%0A%20%20%20%20counts%20%3D%20np.array(%5B1000.0%2C%202000.0%2C%203000.0%5D)%0A%20%20%20%20curve%20%3D%20SNCurve(slope%3D%5B3%2C%205%5D%2C%20intercept%3D%5B11.764%2C%2015.606%5D)%0A%20%20%20%20damage_bands%20%3D%20np.array(%0A%20%20%20%20%20%20%20%20%5B0%2C%200.025%2C%200.05%2C%200.1%2C%200.2%2C%200.3%2C%200.4%2C%200.5%2C%200.6%2C%200.7%2C%200.8%2C%201%5D%0A%20%20%20%20)%0A%20%20%20%20fig%2C%20(damage%2C%20history)%20%3D%20plt.subplots(2%2C%201%2C%20layout%3D%22constrained%22)%0A%20%20%20%20end_damage%20%3D%20%5B%5D%0A%20%20%20%20for%20label%2C%20stress%2C%20cycles%20in%20(%0A%20%20%20%20%20%20%20%20(%22Low%20to%20high%22%2C%20ranges%2C%20counts)%2C%0A%20%20%20%20%20%20%20%20(%22High%20to%20low%22%2C%20ranges%5B%3A%3A-1%5D%2C%20counts%5B%3A%3A-1%5D)%2C%0A%20%20%20%20)%3A%0A%20%20%20%20%20%20%20%20cumulative_cycles%20%3D%20np.r_%5B0.0%2C%20np.cumsum(cycles)%5D%0A%20%20%20%20%20%20%20%20miner%20%3D%20np.cumsum(calc_pm(stress%2C%20cycles%2C%20curve))%0A%20%20%20%20%20%20%20%20_%2C%20pavlou%2C%20_%2C%20_%20%3D%20calc_nonlinear_damage_with_dca(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22pavlou%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20stress%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20cycles%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20curve%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20damage_bands%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20ultimate_stress%3D900.0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20base_exponent%3D-0.75%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20damage.plot(%0A%20%20%20%20%20%20%20%20%20%20%20%20cumulative_cycles%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20np.r_%5B0.0%2C%20miner%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22o--%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3Df%22Miner%20%C2%B7%20%7Blabel%7D%22%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20damage.plot(%0A%20%20%20%20%20%20%20%20%20%20%20%20cumulative_cycles%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20np.r_%5B0.0%2C%20pavlou%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22o-%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3Df%22Pavlou%20%C2%B7%20%7Blabel%7D%22%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20end_damage.append(%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Order%22%3A%20label%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Miner%22%3A%20float(miner%5B-1%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Pavlou%22%3A%20float(pavlou%5B-1%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20damage.set(xlabel%3D%22Cumulative%20cycles%22%2C%20ylabel%3D%22Accumulated%20damage%22)%0A%20%20%20%20damage.legend()%0A%0A%20%20%20%20curve.plot(ax%3Dhistory%2C%20scale%3D%22semilogx%22)%0A%20%20%20%20history.lines%5B-1%5D.set_label(%22S%E2%80%93N%20curve%22)%0A%20%20%20%20for%20label%2C%20cycles%2C%20stress%20in%20calc_theil_sn_damage(ranges%2C%20counts%2C%20curve)%3A%0A%20%20%20%20%20%20%20%20history.plot(cycles%2C%20stress%2C%20label%3Dlabel)%0A%20%20%20%20history.set(xlabel%3D%22Cumulative%20cycles%22%2C%20ylabel%3D%22Stress%20range%20(MPa)%22)%0A%20%20%20%20history.legend()%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.ui.table(end_damage)%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20return%20curve%2C%20damage_bands%0A%0A%0A%40app.cell%0Adef%20long_case(curve%2C%20damage_bands)%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.damage.stress_life%20import%20(%0A%20%20%20%20%20%20%20%20calc_nonlinear_damage_with_dca%20as%20_calc_dca%2C%0A%20%20%20%20%20%20%20%20calc_pm%20as%20_calc_pm%2C%0A%20%20%20%20)%0A%0A%20%20%20%20peaks%20%3D%20synthetic_peaks()%0A%20%20%20%20long_ranges%20%3D%20peaks%20-%20MINIMUM_STRESS%0A%20%20%20%20long_counts%20%3D%20_np.ones_like(long_ranges)%0A%20%20%20%20long_fig%2C%20ax%20%3D%20_plt.subplots()%0A%20%20%20%20totals%20%3D%20%5B%5D%0A%20%20%20%20for%20long_label%2C%20ordered_ranges%20in%20(%0A%20%20%20%20%20%20%20%20(%22Generated%20order%22%2C%20long_ranges)%2C%0A%20%20%20%20%20%20%20%20(%22Reverse%20order%22%2C%20long_ranges%5B%3A%3A-1%5D)%2C%0A%20%20%20%20)%3A%0A%20%20%20%20%20%20%20%20long_miner%20%3D%20_np.r_%5B%0A%20%20%20%20%20%20%20%20%20%20%20%200%2C%20_np.cumsum(_calc_pm(ordered_ranges%2C%20long_counts%2C%20curve))%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20_%2C%20cumulative_damage%2C%20_%2C%20_%20%3D%20_calc_dca(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22pavlou%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20ordered_ranges%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20long_counts%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20curve%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20damage_bands%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20ultimate_stress%3D900.0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20base_exponent%3D-0.75%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20long_pavlou%20%3D%20_np.r_%5B0%2C%20cumulative_damage%5D%0A%20%20%20%20%20%20%20%20indices%20%3D%20display_indices(long_miner.size%20-%201)%20%2B%201%0A%20%20%20%20%20%20%20%20ax.plot(%0A%20%20%20%20%20%20%20%20%20%20%20%20indices%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20long_miner%5Bindices%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20linestyle%3D%22--%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3Df%22Miner%20%C2%B7%20%7Blong_label%7D%22%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20ax.plot(indices%2C%20long_pavlou%5Bindices%5D%2C%20label%3Df%22Pavlou%20%C2%B7%20%7Blong_label%7D%22)%0A%20%20%20%20%20%20%20%20totals.append(%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22-%20**%7Blong_label%7D**%20%C2%B7%20Miner%20%7Blong_miner%5B-1%5D%3A.8g%7D%2C%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22Pavlou%20%7Blong_pavlou%5B-1%5D%3A.8g%7D.%22%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20ax.set(%0A%20%20%20%20%20%20%20%20xlabel%3D%22Cumulative%20cycles%22%2C%20ylabel%3D%22Accumulated%20damage%22%2C%20yscale%3D%22log%22%0A%20%20%20%20)%0A%20%20%20%20ax.legend()%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%22Run%20both%20damage%20rules%20over%20**%7Bpeaks.size%3A%2C%7D%20cycles**%2C%20first%20as%20%22%0A%20%20%20%20%20%20%20%20%22generated%20and%20then%20in%20reverse.%20The%20end%20totals%20show%20the%20effect%20of%20%22%0A%20%20%20%20%20%20%20%20%22order.%20The%20logarithmic%20axis%20separates%20the%20two%20damage%20histories.%5Cn%5Cn%22%0A%20%20%20%20%20%20%20%20%2B%20%22%5Cn%22.join(totals)%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
a58cfa32ac679e6422a14d26d98decaa