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
The implementation consists of a single header rainflow.h
and source file rainflow.cpp
and has zero dependencies.
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:
#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:
#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 }
*/
}
Build and run the example using docker
:
docker build -t rainflow .
docker run --rm rainflow
or locally:
cmake -S . -B build
cmake --build build
build/example_rainflow example/samples.txt
Build and run unit tests using docker
:
docker build -t rainflow .
docker run --rm rainflow build/test_rainflow
or locally:
cmake -S . -B build
cmake --build build
build/test_rainflow
To run tests locally the GoogleTest library is required. Under linux it can be installed via package manager eg.:
apt-get install -y libgtest-dev