%22%22%22Compare%20mean-stress%20corrections%20and%20their%20effect%20on%20equivalent%20loads.%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%20Mean%20stress%20and%20equivalent%20loads%0A%0A%20%20%20%20%20%20%20%20Add%20two%20windows%20of%20a%20synthetic%20stress%20history%20and%20resolve%20the%0A%20%20%20%20%20%20%20%20residuals.%20Apply%20two%20mean-stress%20corrections%20independently%20to%20that%0A%20%20%20%20%20%20%20%20combined%20spectrum.%20Use%20one%20S%E2%80%93N%20curve%20to%20compute%20Miner%20damage%20for%20the%0A%20%20%20%20%20%20%20%20original%20and%20both%20corrected%20spectra.%0A%0A%20%20%20%20%20%20%20%20The%20equivalent%20stress%20ranges%20and%20moments%20use%20the%20same%20S%E2%80%93N%20slope%20and%0A%20%20%20%20%20%20%20%20reference%20cycle%20count.%20The%20moment%20example%20uses%20a%20hollow%20circular%0A%20%20%20%20%20%20%20%20section%20with%20radii%20specified%20in%20metres.%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%20from%20datetime%20import%20datetime%2C%20timedelta%2C%20timezone%0A%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%20py_fatigue.damage%20import%20get_dem%2C%20get_des%2C%20get_pm%0A%20%20%20%20from%20_examples.charts%20import%20plot_views%0A%0A%20%20%20%20stress%20%3D%20(%0A%20%20%20%20%20%20%20%2010%0A%20%20%20%20%20%20%20%20*%20np.array(%0A%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%204%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%207%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%202%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2010%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%205%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%209%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%203%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%204%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%202%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2012%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%205%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2011%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%201%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%204%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%203%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2010%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%206%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2012%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%204%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%208%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%201%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%209%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%204%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%206%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20dtype%3Dfloat%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20-%2030%0A%20%20%20%20)%0A%20%20%20%20split%20%3D%20len(stress)%20%2F%2F%202%0A%20%20%20%20start%20%3D%20datetime(2024%2C%201%2C%201%2C%20tzinfo%3Dtimezone.utc)%0A%20%20%20%20first%20%3D%20CycleCount.from_timeseries(stress%5B%3Asplit%5D%2C%20timestamp%3Dstart)%0A%20%20%20%20second%20%3D%20CycleCount.from_timeseries(%0A%20%20%20%20%20%20%20%20stress%5Bsplit%3A%5D%2C%20timestamp%3Dstart%20%2B%20timedelta(seconds%3Dsplit)%0A%20%20%20%20)%0A%20%20%20%20spectrum%20%3D%20(first%20%2B%20second).solve_lffd()%0A%20%20%20%20corrections%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22Original%22%3A%20spectrum%2C%0A%20%20%20%20%20%20%20%20%22DNVGL-RP-C203%22%3A%20spectrum.mean_stress_correction(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22DNVGL-RP-C203%22%2C%20detail_factor%3D0.8%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%22Smith%E2%80%93Watson%E2%80%93Topper%22%3A%20spectrum.mean_stress_correction(%22SWT%22)%2C%0A%20%20%20%20%7D%0A%20%20%20%20sn%20%3D%20SNCurve(slope%3D3%2C%20intercept%3D12)%0A%20%20%20%20reference_cycles%20%3D%20spectrum.count_cycle.sum()%0A%20%20%20%20outer_radius%2C%20inner_radius%20%3D%200.5%2C%200.4%0A%0A%20%20%20%20fig%2C%20(ranges%2C%20damage)%20%3D%20plt.subplots(2%2C%201%2C%20layout%3D%22constrained%22)%0A%20%20%20%20summary%20%3D%20%5B%5D%0A%20%20%20%20for%20label%2C%20cc%20in%20corrections.items()%3A%0A%20%20%20%20%20%20%20%20contributions%20%3D%20get_pm(cc%2C%20sn)%0A%20%20%20%20%20%20%20%20ranges.plot(spectrum.stress_range%2C%20cc.stress_range%2C%20%22o%22%2C%20label%3Dlabel)%0A%20%20%20%20%20%20%20%20damage.plot(spectrum.stress_range%2C%20contributions%2C%20%22o%22%2C%20label%3Dlabel)%0A%20%20%20%20%20%20%20%20des%20%3D%20get_des(cc%2C%20sn.slope%5B0%5D%2C%20reference_cycles)%0A%20%20%20%20%20%20%20%20dem%20%3D%20get_dem(%0A%20%20%20%20%20%20%20%20%20%20%20%20outer_radius%2C%20inner_radius%2C%20cc%2C%20sn.slope%5B0%5D%2C%20reference_cycles%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20summary.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%22Correction%22%3A%20label%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Miner%20damage%22%3A%20float(contributions.sum())%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22DES%20(MPa)%22%3A%20float(des)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22DEM%20(kNm)%22%3A%20float(dem%20%2F%201000)%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%0A%20%20%20%20ranges.set(%0A%20%20%20%20%20%20%20%20xlabel%3D%22Original%20range%20(MPa)%22%2C%20ylabel%3D%22Range%20after%20correction%20(MPa)%22%0A%20%20%20%20)%0A%20%20%20%20damage.set(%0A%20%20%20%20%20%20%20%20xlabel%3D%22Original%20range%20(MPa)%22%2C%20ylabel%3D%22Miner%20damage%20contribution%22%0A%20%20%20%20)%0A%20%20%20%20ranges.legend()%0A%20%20%20%20damage.legend()%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(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22DES%20and%20DEM%20use%20**%7Breference_cycles%3Ag%7D%20reference%20cycles**.%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.table(summary)%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20return%20inner_radius%2C%20outer_radius%2C%20sn%0A%0A%0A%40app.cell%0Adef%20long_case(inner_radius%2C%20outer_radius%2C%20sn)%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%20count_windows%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%20%20%20%20tensile_waveform%2C%0A%20%20%20%20)%0A%20%20%20%20from%20py_fatigue.damage%20import%20(%0A%20%20%20%20%20%20%20%20get_dem%20as%20_get_dem%2C%0A%20%20%20%20%20%20%20%20get_des%20as%20_get_des%2C%0A%20%20%20%20%20%20%20%20get_pm%20as%20_get_pm%2C%0A%20%20%20%20)%0A%0A%20%20%20%20peaks%20%3D%20synthetic_peaks()%0A%20%20%20%20combined%20%3D%20count_windows(tensile_waveform(peaks)).solve_lffd()%0A%20%20%20%20corrected%20%3D%20combined.mean_stress_correction(%22SWT%22)%0A%20%20%20%20edges%20%3D%20_np.histogram_bin_edges(%0A%20%20%20%20%20%20%20%20_np.r_%5Bcombined.stress_range%2C%20corrected.stress_range%5D%2C%20bins%3D60%0A%20%20%20%20)%0A%20%20%20%20centres%20%3D%20(edges%5B%3A-1%5D%20%2B%20edges%5B1%3A%5D)%20%2F%202%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%20long_reference_cycles%20%3D%20combined.count_cycle.sum()%0A%20%20%20%20for%20long_label%2C%20long_spectrum%20in%20(%0A%20%20%20%20%20%20%20%20(%22Original%22%2C%20combined)%2C%0A%20%20%20%20%20%20%20%20(%22SWT%22%2C%20corrected)%2C%0A%20%20%20%20)%3A%0A%20%20%20%20%20%20%20%20long_damage%20%3D%20_get_pm(long_spectrum%2C%20sn)%0A%20%20%20%20%20%20%20%20by_range%2C%20_%20%3D%20_np.histogram(%0A%20%20%20%20%20%20%20%20%20%20%20%20long_spectrum.stress_range%2C%20bins%3Dedges%2C%20weights%3Dlong_damage%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20ax.plot(centres%2C%20by_range%2C%20label%3Dlong_label)%0A%20%20%20%20%20%20%20%20long_des%20%3D%20_get_des(long_spectrum%2C%20sn.slope%5B0%5D%2C%20long_reference_cycles)%0A%20%20%20%20%20%20%20%20long_dem%20%3D%20_get_dem(%0A%20%20%20%20%20%20%20%20%20%20%20%20outer_radius%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20inner_radius%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20long_spectrum%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20sn.slope%5B0%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20long_reference_cycles%2C%0A%20%20%20%20%20%20%20%20)%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%20damage%20%7Blong_damage.sum()%3A.4g%7D%2C%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22DES%20%7Blong_des%3A.2f%7D%20MPa%2C%20DEM%20%7Blong_dem%20%2F%201000%3A.2f%7D%20kNm.%22%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20ax.set(xlabel%3D%22Stress%20range%20(MPa)%22%2C%20ylabel%3D%22Miner%20damage%20per%20range%20bin%22)%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%22Combine%20and%20resolve%20the%20**%7Bpeaks.size%3A%2C%7D-cycle**%20waveform%2C%20then%20%22%0A%20%20%20%20%20%20%20%20%22apply%20SWT%20to%20the%20resulting%20spectrum.%20Compare%20damage%20and%20equivalent%20%22%0A%20%20%20%20%20%20%20%20%22loads%20with%20the%20same%20S%E2%80%93N%20curve%20and%20reference%20cycle%20count.%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
68349e746645bc33d9248a9333766979