%22%22%22Evaluate%20fatigue%20and%20crack-growth%20limits%20under%20a%20long%20synthetic%20signal.%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%20From%20a%20synthetic%20signal%20to%20failure%0A%0A%20%20%20%20%20%20%20%20Use%20Py-Fatigue's%20signal%20generator%20to%20draw%20a%20peak%20stress%20for%20each%0A%20%20%20%20%20%20%20%20cycle.%20Return%20to%20the%20same%20tensile%20minimum%20between%20peaks%20so%20the%0A%20%20%20%20%20%20%20%20cycle%20order%20is%20known.%20This%20gives%20one%20history%20for%20two%20separate%0A%20%20%20%20%20%20%20%20predictions%20with%20teaching%20inputs.%0A%0A%20%20%20%20%20%20%20%20**Stress%20life**%20uses%20an%20S%E2%80%93N%20curve%20and%20marks%20the%20first%20cycle%20where%0A%20%20%20%20%20%20%20%20cumulative%20Miner%20damage%20reaches%201.%20Rainflow%20counting%20the%20complete%0A%20%20%20%20%20%20%20%20waveform%20provides%20a%20check%20on%20the%20final%20damage%20sum.%0A%0A%20%20%20%20%20%20%20%20**Crack%20growth**%20applies%20the%20generated%20peaks%20in%20order%20to%20a%20plate%0A%20%20%20%20%20%20%20%20crack.%20The%20final%20plotted%20markers%20show%20the%20last%20accepted%20crack%20state.%0A%20%20%20%20%20%20%20%20Inspect%20the%20termination%20reason%20to%20see%20which%20limit%20the%20solver%20reached.%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%20generate_signal()%3A%0A%20%20%20%20import%20numpy%20as%20np%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%20synthetic_peaks%2C%0A%20%20%20%20%20%20%20%20tensile_waveform%2C%0A%20%20%20%20)%0A%0A%20%20%20%20minimum%20%3D%20MINIMUM_STRESS%0A%20%20%20%20peaks%20%3D%20synthetic_peaks()%0A%20%20%20%20stress%20%3D%20tensile_waveform(peaks)%0A%20%20%20%20return%20minimum%2C%20np%2C%20peaks%2C%20stress%0A%0A%0A%40app.cell%0Adef%20count_damage(minimum%2C%20np%2C%20peaks%2C%20stress)%3A%0A%20%20%20%20from%20py_fatigue%20import%20CycleCount%2C%20SNCurve%0A%20%20%20%20from%20py_fatigue.damage%20import%20calc_pm%2C%20get_pm%0A%0A%20%20%20%20%23%20The%20W3-C%20curve%20from%20lesson%2000.%0A%20%20%20%20sn%20%3D%20SNCurve(slope%3D3.0%2C%20intercept%3D10.493)%0A%20%20%20%20counted%20%3D%20CycleCount.from_timeseries(stress%2C%20unit%3D%22MPa%22)%0A%20%20%20%20rainflow_damage%20%3D%20get_pm(counted%2C%20sn).sum()%0A%20%20%20%20increments%20%3D%20calc_pm(peaks%20-%20minimum%2C%20np.ones_like(peaks)%2C%20sn)%0A%20%20%20%20damage%20%3D%20np.r_%5B0.0%2C%20np.cumsum(increments)%5D%0A%20%20%20%20crossings%20%3D%20np.flatnonzero(damage%20%3E%3D%201.0)%0A%20%20%20%20fatigue_failure%20%3D%20int(crossings%5B0%5D)%20if%20crossings.size%20else%20None%0A%20%20%20%20return%20damage%2C%20fatigue_failure%2C%20rainflow_damage%0A%0A%0A%40app.cell%0Adef%20propagate(minimum%2C%20peaks)%3A%0A%20%20%20%20from%20py_fatigue.crack_growth%20import%20(%0A%20%20%20%20%20%20%20%20SemiEllipticalSurfaceCrack%2C%0A%20%20%20%20%20%20%20%20CenterThroughCrack%2C%0A%20%20%20%20%20%20%20%20LoadBlock%2C%0A%20%20%20%20%20%20%20%20NasgroCurve%2C%0A%20%20%20%20%20%20%20%20simulate_crack_growth%2C%0A%20%20%20%20)%0A%0A%20%20%20%20geometry%20%3D%20CenterThroughCrack(half_width%3D50.0%2C%20half_length%3D5.0)%0A%20%20%20%20geometry%20%3D%20SemiEllipticalSurfaceCrack(%0A%20%20%20%20%20%20%20%20half_length%3D10%2C%20half_width%3D100%2C%20thickness%3D10%2C%20depth%3D2%0A%20%20%20%20)%0A%20%20%20%20curve%20%3D%20NasgroCurve(%0A%20%20%20%20%20%20%20%20coefficient%3D1e-10%2C%0A%20%20%20%20%20%20%20%20exponent%3D2.0%2C%0A%20%20%20%20%20%20%20%20p%3D0.5%2C%0A%20%20%20%20%20%20%20%20q%3D1.0%2C%0A%20%20%20%20%20%20%20%20threshold_zero%3D25.0%2C%0A%20%20%20%20%20%20%20%20threshold_fanning%3D0.0%2C%0A%20%20%20%20%20%20%20%20toughness%3D500.0%2C%0A%20%20%20%20%20%20%20%20constraint%3D2.0%2C%0A%20%20%20%20%20%20%20%20peak_to_flow%3D0.3%2C%0A%20%20%20%20)%0A%20%20%20%20loads%20%3D%20%5BLoadBlock(minimum%2C%20float(peak)%2C%201.0)%20for%20peak%20in%20peaks%5D%0A%20%20%20%20result%20%3D%20simulate_crack_growth(%0A%20%20%20%20%20%20%20%20geometry%2C%0A%20%20%20%20%20%20%20%20curve%2C%0A%20%20%20%20%20%20%20%20loads%2C%0A%20%20%20%20%20%20%20%20max_cycle_step%3D1.0%2C%0A%20%20%20%20%20%20%20%20length_tolerance%3D1e-6%2C%0A%20%20%20%20%20%20%20%20cycle_tolerance%3D1e-4%2C%0A%20%20%20%20%20%20%20%20max_trials%3Dlen(loads)%2C%0A%20%20%20%20)%0A%20%20%20%20return%20curve%2C%20result%0A%0A%0A%40app.cell%0Adef%20show_results(%0A%20%20%20%20damage%2C%0A%20%20%20%20fatigue_failure%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20np%2C%0A%20%20%20%20peaks%2C%0A%20%20%20%20rainflow_damage%2C%0A%20%20%20%20result%2C%0A%20%20%20%20stress%2C%0A)%3A%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20from%20_examples.synthetic%20import%20display_indices%0A%20%20%20%20from%20py_fatigue.crack_growth%20import%20GrowthResult%0A%20%20%20%20from%20_examples.charts%20import%20plot_views%0A%0A%20%20%20%20fig%2C%20(signal%2C%20miner%2C%20growth)%20%3D%20plt.subplots(%0A%20%20%20%20%20%20%20%203%2C%201%2C%20figsize%3D(7%2C%209)%2C%20layout%3D%22constrained%22%0A%20%20%20%20)%0A%20%20%20%20preview%20%3D%20stress%5B%3A51%5D%0A%20%20%20%20signal.plot(np.arange(preview.size)%20%2F%202%2C%20preview%2C%20%22o-%22)%0A%20%20%20%20signal.set(%0A%20%20%20%20%20%20%20%20xlabel%3D%22Cycle%20position%22%2C%0A%20%20%20%20%20%20%20%20ylabel%3D%22Stress%20(MPa)%22%2C%0A%20%20%20%20%20%20%20%20title%3Df%22First%20%7B(preview.size%20-%201)%20%2F%2F%202%7D%20cycles%22%2C%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Thin%20the%20histories%20for%20display%20and%20retain%20the%20failure%20markers.%0A%20%20%20%20samples%20%3D%20display_indices(damage.size)%0A%20%20%20%20if%20fatigue_failure%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20samples%20%3D%20np.union1d(samples%2C%20fatigue_failure)%0A%20%20%20%20miner.plot(samples%2C%20damage%5Bsamples%5D%2C%20label%3D%22Cumulative%20Miner%20damage%22)%0A%20%20%20%20miner.axhline(1.0%2C%20linestyle%3D%22--%22%2C%20color%3D%220.4%22%2C%20label%3D%22Damage%20limit%22)%0A%20%20%20%20if%20fatigue_failure%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20miner.scatter(%0A%20%20%20%20%20%20%20%20%20%20%20%20fatigue_failure%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20damage%5Bfatigue_failure%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20color%3D%22firebrick%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22First%20cycle%20at%20the%20limit%22%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20miner.set(xlabel%3D%22Cycles%22%2C%20ylabel%3D%22Miner%20damage%22%2C%20xlim%3D(0%2C%20peaks.size))%0A%20%20%20%20miner.legend()%0A%0A%20%20%20%20indices%20%3D%20display_indices(len(result.history))%0A%20%20%20%20display_growth%20%3D%20GrowthResult(%0A%20%20%20%20%20%20%20%20tuple(result.history%5Bindex%5D%20for%20index%20in%20indices)%2C%20result.termination%0A%20%20%20%20)%0A%20%20%20%20display_growth.plot(ax%3Dgrowth)%0A%20%20%20%20if%20result.history%3A%0A%20%20%20%20%20%20%20%20last%20%3D%20result.history%5B-1%5D%0A%20%20%20%20%20%20%20%20growth.scatter(%0A%20%20%20%20%20%20%20%20%20%20%20%20%5Blast.cycles%5D%20*%20len(last.sizes)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20last.sizes%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20color%3D%22firebrick%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22Last%20accepted%20state%22%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20growth.legend()%0A%20%20%20%20growth.set_xlim(0%2C%20peaks.size)%0A%0A%20%20%20%20fatigue_summary%20%3D%20(%0A%20%20%20%20%20%20%20%20f%22Miner%20reached%201%20at%20cycle%20**%7Bfatigue_failure%3A%2C%7D**.%22%0A%20%20%20%20%20%20%20%20if%20fatigue_failure%20is%20not%20None%0A%20%20%20%20%20%20%20%20else%20%22Miner%20damage%20stayed%20below%201%20over%20the%20supplied%20history.%22%0A%20%20%20%20)%0A%20%20%20%20termination%20%3D%20result.termination.replace(%22_%22%2C%20%22%20%22)%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(f%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20The%20waveform%20has%20**%7Bstress.size%3A%2C%7D%20samples**%20over%0A%20%20%20%20%20%20%20%20%20%20%20%20**%7Bpeaks.size%3A%2C%7D%20cycles**.%0A%20%20%20%20%20%20%20%20%20%20%20%20%7Bfatigue_summary%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20Full-record%20damage%20is%20**%7Bdamage%5B-1%5D%3A.5f%7D**%20by%20cycle%20and%0A%20%20%20%20%20%20%20%20%20%20%20%20**%7Brainflow_damage%3A.5f%7D**%20by%20rainflow%20counting.%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20**Crack%20growth**%20%C2%B7%20%7Btermination%7D.%20The%20last%20accepted%20state%20was%0A%20%20%20%20%20%20%20%20%20%20%20%20at%20**%7Bresult.final_cycles%3A%2C.2f%7D%20cycles**.%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20plot_views(fig%2C%20height%3D%221240px%22)%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%0A%0A%40app.cell%0Adef%20_(curve)%3A%0A%20%20%20%20from%20_examples.charts%20import%20plot_views%20as%20_plot_views%0A%0A%20%20%20%20_plot_views(curve.plot()%5B0%5D)%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
ab12be0727f13cebee17857ec97faaf6