Skip to content

Count stress cycles

Use the rainflow explanation to interpret ranges, means, and fractional counts.

a. Constant fatigue load

Sample a slowly oscillating stress at 10 Hz for 101 seconds. Plot the weighted range–mean bins to see how the constant-amplitude cycles concentrate at one stress range and one mean.

import numpy as np
from py_fatigue import CycleCount

time = np.arange(1010) / 10
stress = 30 + 25 * np.sin(2 * np.pi * 0.5 * time)
cycles = CycleCount.from_timeseries(stress, time=time)
fig, ax = cycles.plot_histogram(
    plot_type="mean-range", weights=cycles.count_cycle
)
print(cycles.count_cycle.sum())

b. Weibull-distributed signal

Generate one million samples and round-trip the sparse rainflow matrix. Use common bin widths for comparisons. The matrix records binned cycle ranges and means, and carries the residual sequence alongside it.

from py_fatigue import CycleCount
from py_fatigue.testing import get_random_data, get_sampled_time

time = get_sampled_time(duration=100_000, fs=10)
stress = get_random_data(
    time, min_=-30, range_=180, random_type="weibull", a=2.0, seed=42
)
cycles = CycleCount.from_timeseries(
    stress, time=time, range_bin_width=3.0, mean_bin_width=3.0
)
sparse = cycles.as_dict()
restored = CycleCount.from_rainflow(sparse, unit=cycles.unit)
print("Total weights:", cycles.count_cycle.sum(), restored.count_cycle.sum())

Import measured or generated stress histories

Use CycleCount.from_sep005() with records from an SDyPy reader. One record with one-dimensional data returns a count. A list of records or a record with multiple channel rows returns a flat list in input order. The connector accepts stress in Pa, kPa, MPa, or GPa and returns MPa. An omitted quantity means stress and an omitted unit means Pa.

from py_fatigue import CycleCount

record = {
    "name": "Axial stress",
    "data": [0, 20e6, 3e6, 40e6, 0],
    "fs": 50,
    "quantity": "s",
    "unit_str": "Pa",
}
measured = CycleCount.from_sep005(record)

For a synthetic stress history, install pyExSi separately. Its sine sweep returns a unitless waveform. Here the factor of 20 defines a synthetic stress amplitude in MPa.

import numpy as np
import pyExSi
from py_fatigue import CycleCount

fs = 200
time = np.arange(fs * 200) / fs
stress = 20 * pyExSi.sine_sweep(time, freq_start=2, freq_stop=10)
generated = CycleCount.from_pyexsi(stress, fs=fs, unit="MPa")

SignalForge can also generate nonstationary stress histories. If the generator's signal.x samples already represent stress in MPa, use CycleCount.from_timeseries(signal.x, unit="MPa"). Convert measured or generated acceleration or force into stress using your own model before cycle counting.

For crack growth, preserve the sequence and supply tensile stress extrema as explicit load blocks.

Worked notebook