Py-Fatigue¶
Count stress cycles, estimate fatigue damage, and predict crack growth with Python.
Choose a workflow¶
-
Cycle-count time series and combine counting windows.
-
Perform (non)linear damage accumulation analysis.
-
Perform complex crack propagation analysis.
-
Run complete analyses and compare results with AFGROW examples.
-
Run fatigue calculations through an MCP client using inline data or local CSV files.
Run a cycle count¶
Pass a stress history to CycleCount and inspect the stress range and count of each cycle.
from py_fatigue import CycleCount
stress = [0, 50, -20, 45, -10, 0]
cycles = CycleCount.from_timeseries(stress)
print(cycles.stress_range)
print(cycles.count_cycle)
Run a stress-life analysis¶
Count cycles in a stress history and use an illustrative S–N curve to sum the Palmgren–Miner damage.
from py_fatigue import CycleCount, SNCurve
from py_fatigue.damage.stress_life import calc_pm
cycles = CycleCount.from_timeseries([0, 75, -15, 50, 0])
curve = SNCurve(slope=3, intercept=12)
damage = calc_pm(
cycles.stress_range, cycles.count_cycle, curve
)
print(f"Total Miner damage: {damage.sum():.3g}")
Run a crack growth analysis¶
Grow a through crack in a plate under repeated tensile loading. This example uses an illustrative NASGRO fit and returns the final crack half-length in mm.
from math import ceil
from py_fatigue.crack_growth import (
CenterThroughCrack, LoadBlock, NasgroCurve,
simulate_crack_growth,
)
plate = CenterThroughCrack(half_width=50, half_length=4)
curve = NasgroCurve(
coefficient=1e-10, exponent=2.0, p=0.5, q=1.0,
threshold_zero=25.0, threshold_fanning=0.0,
toughness=500.0, constraint=2.0, peak_to_flow=0.3,
)
load = LoadBlock(minimum=10, maximum=70, cycles=50_000)
step = 10.0 # cycles
result = simulate_crack_growth(
plate, curve, [load],
max_cycle_step=step,
length_tolerance=1e-6,
cycle_tolerance=1e-4,
max_trials=2 * ceil(load.cycles / step),
)
print(f"Final crack half-length: {result.history[-1].sizes[0]:.3f} mm")
Run py-fatigue via MCP client¶
Use the companion package to count cycles, calculate Miner damage, recover cycles across windows, or simulate ordered crack growth.
Use rainflow_count on these samples in MPa:
[27, 43, 54, 54, 27, 15, 30, 46, 70, 83, 57,
27, 15, 9, 28, 53]. Report the number of cycle
rows and the total cycle weight.