%22%22%22Calculate%20stress-life%20damage%20from%20a%20tube's%20bending%20history.%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..%2F..%2Fdocs%2Fstylesheets%2Fcustom.css%22)%0A%0A%0A%40app.cell%0Adef%20introduction()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20from%20notebooks._examples.synthetic%20import%20(%0A%20%20%20%20%20%20%20%20count_windows%2C%0A%20%20%20%20%20%20%20%20display_indices%2C%0A%20%20%20%20%20%20%20%20plot_views%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%20import%20CycleCount%2C%20SNCurve%0A%20%20%20%20from%20py_fatigue.damage%20import%20calc_pm%2C%20get_dem%2C%20get_des%2C%20get_pm%0A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%20%20%20%20%23%20Stress-life%20assessment%20of%20a%20tube%20in%20bending%0A%0A%20%20%20%20%20%20%20%20Define%20an%20S%E2%80%93N%20curve%20for%20the%20detail%2C%20convert%20a%20bending-moment%20history%0A%20%20%20%20%20%20%20%20to%20nominal%20stress%2C%20and%20rainflow%20count%20the%20signal%20in%20two%20windows.%0A%20%20%20%20%20%20%20%20Compare%20Miner%20damage%20and%20equivalent%20loads%20with%20and%20without%20a%0A%20%20%20%20%20%20%20%20Smith%E2%80%93Watson%E2%80%93Topper%20(SWT)%20mean-stress%20correction.%0A%0A%20%20%20%20%20%20%20%20The%20section%20and%20moment%20history%20are%20illustrative.%20The%20S%E2%80%93N%20inputs%0A%20%20%20%20%20%20%20%20follow%20the%20W3-C%20demonstration%20in%20lesson%2000.%20Use%20MPa%20for%20stress%0A%20%20%20%20%20%20%20%20and%20metres%20for%20the%20tube%20radii.%0A%20%20%20%20%20%20%20%20%22%22%22)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20CycleCount%2C%0A%20%20%20%20%20%20%20%20SNCurve%2C%0A%20%20%20%20%20%20%20%20calc_pm%2C%0A%20%20%20%20%20%20%20%20count_windows%2C%0A%20%20%20%20%20%20%20%20display_indices%2C%0A%20%20%20%20%20%20%20%20get_dem%2C%0A%20%20%20%20%20%20%20%20get_des%2C%0A%20%20%20%20%20%20%20%20get_pm%2C%0A%20%20%20%20%20%20%20%20mo%2C%0A%20%20%20%20%20%20%20%20np%2C%0A%20%20%20%20%20%20%20%20plot_views%2C%0A%20%20%20%20%20%20%20%20plt%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%0A%0A%40app.cell%0Adef%20material_geometry_and_load(%0A%20%20%20%20SNCurve%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20np%2C%0A%20%20%20%20plot_views%2C%0A%20%20%20%20plt%2C%0A%20%20%20%20synthetic_peaks%2C%0A%20%20%20%20tensile_waveform%2C%0A)%3A%0A%20%20%20%20curve%20%3D%20SNCurve(slope%3D3.0%2C%20intercept%3D10.493)%0A%20%20%20%20outer_radius%2C%20inner_radius%20%3D%200.15%2C%200.13%0A%20%20%20%20section_modulus%20%3D%20(%0A%20%20%20%20%20%20%20%20np.pi%20*%20(outer_radius**4%20-%20inner_radius**4)%20%2F%20(4%20*%20outer_radius)%0A%20%20%20%20)%0A%20%20%20%20%23%20Use%20the%20seeded%20generator's%20values%20as%20moment%20peaks%20in%20kN%20m.%0A%20%20%20%20moment%20%3D%20tensile_waveform(synthetic_peaks())%0A%20%20%20%20stress%20%3D%20moment%20*%201e3%20%2F%20section_modulus%20%2F%201e6%0A%0A%20%20%20%20_fig%2C%20(section%2C%20history%2C%20law)%20%3D%20plt.subplots(%0A%20%20%20%20%20%20%20%203%2C%201%2C%20figsize%3D(8%2C%209)%2C%20layout%3D%22constrained%22%0A%20%20%20%20)%0A%20%20%20%20angle%20%3D%20np.linspace(0%2C%202%20*%20np.pi%2C%20101)%0A%20%20%20%20for%20radius%2C%20label%20in%20(%0A%20%20%20%20%20%20%20%20(outer_radius%2C%20%22Outer%20wall%22)%2C%0A%20%20%20%20%20%20%20%20(inner_radius%2C%20%22Inner%20wall%22)%2C%0A%20%20%20%20)%3A%0A%20%20%20%20%20%20%20%20section.plot(%0A%20%20%20%20%20%20%20%20%20%20%20%20radius%20*%20np.cos(angle)%2C%20radius%20*%20np.sin(angle)%2C%20label%3Dlabel%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20section.set(xlabel%3D%22Section%20x%20(m)%22%2C%20ylabel%3D%22Section%20y%20(m)%22%2C%20aspect%3D%22equal%22)%0A%20%20%20%20section.legend()%0A%20%20%20%20history.plot(stress%5B%3A41%5D)%0A%20%20%20%20history.set(%0A%20%20%20%20%20%20%20%20xlabel%3D%22Sample%20%C2%B7%20first%2020%20cycles%22%2C%20ylabel%3D%22Nominal%20stress%20(MPa)%22%0A%20%20%20%20)%0A%20%20%20%20curve.plot(ax%3Dlaw)%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%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22%23%23%20Section%2C%20material%20and%20load%5Cn%5CnSection%20modulus%20is%20**%7Bsection_modulus%3A.5f%7D%20m%C2%B3**.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22Count%20all%20**%7Bstress.size%3A%2C%7D%20samples**%20using%20the%20elastic%20relation%20%CF%83%20%3D%20M%2FW.%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%20plot_views(_fig)%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20return%20curve%2C%20inner_radius%2C%20outer_radius%2C%20stress%0A%0A%0A%40app.cell%0Adef%20damage_analysis(%0A%20%20%20%20CycleCount%2C%0A%20%20%20%20calc_pm%2C%0A%20%20%20%20count_windows%2C%0A%20%20%20%20curve%2C%0A%20%20%20%20display_indices%2C%0A%20%20%20%20get_dem%2C%0A%20%20%20%20get_des%2C%0A%20%20%20%20get_pm%2C%0A%20%20%20%20inner_radius%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20np%2C%0A%20%20%20%20outer_radius%2C%0A%20%20%20%20plot_views%2C%0A%20%20%20%20plt%2C%0A%20%20%20%20stress%2C%0A)%3A%0A%20%20%20%20combined%20%3D%20count_windows(stress).solve_lffd()%0A%20%20%20%20whole%20%3D%20CycleCount.from_timeseries(stress)%0A%20%20%20%20corrected%20%3D%20combined.mean_stress_correction(%22SWT%22)%0A%20%20%20%20reference_cycles%20%3D%20float(whole.count_cycle.sum())%0A%20%20%20%20slope%20%3D%20float(curve.slope%5B0%5D)%0A%20%20%20%20rows%20%3D%20%5B%5D%0A%20%20%20%20_fig%2C%20(spectrum%2C%20cumulative)%20%3D%20plt.subplots(%0A%20%20%20%20%20%20%20%202%2C%201%2C%20figsize%3D(8%2C%207)%2C%20layout%3D%22constrained%22%0A%20%20%20%20)%0A%20%20%20%20edges%20%3D%20np.histogram_bin_edges(%0A%20%20%20%20%20%20%20%20np.r_%5Bcombined.stress_range%2C%20corrected.stress_range%5D%2C%20bins%3D50%0A%20%20%20%20)%0A%20%20%20%20for%20case%2C%20counted%20in%20((%22Raw%22%2C%20combined)%2C%20(%22SWT%22%2C%20corrected))%3A%0A%20%20%20%20%20%20%20%20damage%20%3D%20get_pm(counted%2C%20curve)%0A%20%20%20%20%20%20%20%20bins%2C%20_%20%3D%20np.histogram(counted.stress_range%2C%20bins%3Dedges%2C%20weights%3Ddamage)%0A%20%20%20%20%20%20%20%20spectrum.plot((edges%5B%3A-1%5D%20%2B%20edges%5B1%3A%5D)%20%2F%202%2C%20bins%2C%20label%3Dcase)%0A%20%20%20%20%20%20%20%20rows.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%22Spectrum%22%3A%20case%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Miner%20damage%22%3A%20float(damage.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(get_des(counted%2C%20slope%2C%20reference_cycles))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22DEM%20(kN%20m)%22%3A%20float(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20get_dem(%0A%20%20%20%20%20%20%20%20%20%20%20%20%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%20%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%20%20%20%20%20%20%20%20%20%20%20%20%20counted%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%20slope%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%20reference_cycles%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%201000%0A%20%20%20%20%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%20%7D%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%23%20This%20waveform%20returns%20to%20the%20same%20minimum%20between%20all%20peaks.%0A%20%20%20%20%23%20Its%20ordered%20peak-to-minimum%20ranges%20give%20a%20separate%20Miner%20history.%0A%20%20%20%20ranges%20%3D%20stress%5B1%3A%3A2%5D%20-%20stress%5B0%5D%0A%20%20%20%20damage_history%20%3D%20np.r_%5B%0A%20%20%20%20%20%20%20%200.0%2C%20np.cumsum(calc_pm(ranges%2C%20np.ones_like(ranges)%2C%20curve))%0A%20%20%20%20%5D%0A%20%20%20%20indices%20%3D%20display_indices(damage_history.size)%0A%20%20%20%20cumulative.plot(%0A%20%20%20%20%20%20%20%20indices%2C%20damage_history%5Bindices%5D%2C%20label%3D%22Raw%20ordered%20cycles%22%0A%20%20%20%20)%0A%20%20%20%20cumulative.axhline(%0A%20%20%20%20%20%20%20%201.0%2C%20color%3D%22firebrick%22%2C%20linestyle%3D%22--%22%2C%20label%3D%22Miner%20D%20%3D%201%22%0A%20%20%20%20)%0A%20%20%20%20spectrum.set(xlabel%3D%22Stress%20range%20(MPa)%22%2C%20ylabel%3D%22Miner%20damage%20per%20bin%22)%0A%20%20%20%20cumulative.set(xlabel%3D%22Applied%20cycles%22%2C%20ylabel%3D%22Cumulative%20Miner%20damage%22)%0A%20%20%20%20spectrum.legend()%0A%20%20%20%20cumulative.legend()%0A%20%20%20%20first_limit%20%3D%20np.searchsorted(damage_history%2C%201.0)%0A%20%20%20%20limit%20%3D%20(%0A%20%20%20%20%20%20%20%20f%22Raw%20Miner%20damage%20reaches%20one%20at%20cycle%20**%7Bfirst_limit%3A%2C%7D**.%22%0A%20%20%20%20%20%20%20%20if%20first_limit%20%3C%20damage_history.size%0A%20%20%20%20%20%20%20%20else%20%22Raw%20Miner%20damage%20stays%20below%20one.%22%0A%20%20%20%20)%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%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22%23%23%20Count%2C%20correct%20and%20assess%5Cn%5CnThe%20full-signal%20count%20gives%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22raw%20damage%20**%7Bget_pm(whole%2C%20curve).sum()%3A.4f%7D**.%20Compare%20it%20with%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22the%20combined%20windows%20below.%20DES%20and%20DEM%20use%20the%20full-signal%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22count%20of%20**%7Breference_cycles%3A%2C.0f%7D%20reference%20cycles**.%20%7Blimit%7D%5Cn%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22For%20the%20SWT%20row%2C%20Py-Fatigue%20uses%20%E2%88%9A(maximum%20stress%20%C3%97%20stress%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22amplitude)%20as%20the%20corrected%20range.%20On%20this%20spectrum%20that%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22reduces%20the%20range%20used%20in%20the%20damage%20calculation.%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(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20rows%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20format_mapping%3D%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Miner%20damage%22%3A%20%22%7B%3A.4f%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22DES%20(MPa)%22%3A%20%22%7B%3A.2f%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22DEM%20(kN%20m)%22%3A%20%22%7B%3A.2f%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%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%20plot_views(_fig)%2C%0A%20%20%20%20%20%20%20%20%5D%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
419d92f21987dea37748d601cfc70870