An open API service indexing awesome lists of open source software.

https://github.com/pawelkn/rainflow

A C++ implementation of the ASTM E1049-85 rain flow cycle counting algorithm for fatigue analysis
https://github.com/pawelkn/rainflow

astm astm-e1049-85 crack fatigue fatigue-analysis fatigue-crack-growth metal-fatigue rainflow rainflow-counting rainflow-cycles

Last synced: about 1 year ago
JSON representation

A C++ implementation of the ASTM E1049-85 rain flow cycle counting algorithm for fatigue analysis

Awesome Lists containing this project

README

          

Rainflow
========

[![Test rainflow](https://github.com/pawelkn/rainflow/actions/workflows/test.yml/badge.svg)](https://github.com/pawelkn/rainflow/actions/workflows/test.yml)

`rainflow` is a C++ implementation of the ASTM E1049-85 rain flow cycle counting
algorithm for fatigue analysis. It is based on Python library [rainflow](https://github.com/iamlikeme/rainflow)

The implementation consists of a single header `rainflow.h` and source file `rainflow.cpp` and has zero dependencies.

Usage
-----

Function `RainFlow::count_cycles` returns a map of ranges and the corresponding number of cycles.

It takes two arguments:

* `RainFlow::Series series` - an input vector of samples to process,
* `double binSize` - (optional) specifies the width of each cycle-counting bin

Returns a `RainFlow::Counts` map.

Example:

```cpp
#include "rainflow.h"

int main()
{
    RainFlow::Series series { -2, 1, -3, 5, -1, 3, -4, 4, -2 };
    auto counts = RainFlow::count_cycles( series, 2.0 );
    /* counts:
        { 2, 0.0 },
        { 4, 2.0 },
        { 6, 0.5 },
        { 8, 1.0 },
        { 10, 0.5 }
    */
}
```

It is possible to obtain full information about each cycle using an `extract_cycles` function.

It takes a single argument:

* `RainFlow::Series series` - an input vector of samples to process

Returns a `RainFlow::Cycles` vector of `RainFlow::Cycle` structs.
`RainFlow::Cycle` struct has fields: `range`, `mean`, `count`, `start_index` and `end_index`.

Example:

```cpp
#include "rainflow.h"

int main()
{
    RainFlow::Series series { -2, 1, -3, 5, -1, 3, -4, 4, -2 };
    auto cycles = RainFlow::extract_cycles( series );
    /* cycles:
        { 3, -0.5, 0.5, 0, 1 },
        { 4, -1.0, 0.5, 1, 2 },
        { 4, 1.0, 1.0, 4, 5 },
        { 8, 1.0, 0.5, 2, 3 },
        { 9, 0.5, 0.5, 3, 6 },
        { 8, 0.0, 0.5, 6, 7 },
        { 6, 1.0, 0.5, 7, 8 }
    */
}
```

Running example
-----

Build and run the example using `docker`:

```sh
docker build -t rainflow .
docker run --rm rainflow
```

or locally:

```sh
cmake -S . -B build
cmake --build build
build/example_rainflow example/samples.txt
```

Running tests
-----

Build and run unit tests using `docker`:

```sh
docker build -t rainflow .
docker run --rm rainflow build/test_rainflow
```

or locally:

```sh
cmake -S . -B build
cmake --build build
build/test_rainflow
```

To run tests locally the [GoogleTest](https://github.com/google/googletest) library is required. Under linux it can be installed via package manager eg.:

```sh
apt-get install -y libgtest-dev
```