sn_curve#

The py_fatigue.material.sn_curve module contains the py_fatigue.SNCurve class and the helpers used to evaluate S-N curves.

class py_fatigue.SNCurve(slope: int | float | list | ndarray, intercept: int | float | list | ndarray, endurance: int | float = inf, environment: str | None = None, curve: str | None = None, norm: str | None = None, unit_string: str = 'MPa', color: str | None = None)#

Define an SN curve that can have an arbitrary number of slopes/intercepts and an endurance. For example:

>>> #
>>> #         ^                log N - log S
>>> # log(a1) +
>>> #         │*
>>> #         │ *
>>> #         │  *
>>> #         │   *  m1
>>> #         │    *---+
>>> # log(a2) +     *  |
>>> #         │  .   * | 1
>>> #     S   │     . *|
>>> #     t   │        *       m2
>>> #     r   │           *--------+
>>> #     e   │              *     | 1
>>> #     s   │                 *  |
>>> #     s   │                    *
>>> #         │                        *  *  *  *  *  *  *  *
>>> #         │
>>> #         │
>>> #         │────────────────────────|────────────────────────>
>>> #                                  Ne
>>> #                          Number of cycles

The slope-intercept couples ((m1, log_a1), (m2, log_a2)), and the endurance value (Ne) are the parameters necessary to fully describe this trilinear SN curve. If the endurance is not set, it defaults to Inf.

Example

>>> from py_fatigue import SNCurve
>>> import numpy as np

First we create an SN curve with the following properties:

>>> w3a = SNCurve(
>>>     [3, 5],
>>>     [10.970, 13.617],
>>>     norm='DNVGL-RP-C203',
>>>     curve='W3',
>>>     environment='Air',
>>> )

Then we can plot the SN curve defined using plotly

>>> data, layout = w3a.plotly()
>>> fig = go.Figure(data=data, layout=layout)
>>> fig.show

Define stress-life (SN) curve. See class docstring for more information.

Parameters:
  • slope (int | float | list | np.ndarray) – SN curve slope

  • intercept (int | float | list | np.ndarray) – Stress axis intercept

  • endurance (float | np.ndarray[int, float], optional) – endurance number of cycles, by default np.inf

  • environment (str, optional) – SN curve envirnoment, by default None

  • curve (str, optional) – SN curve category, by default None

  • norm (str, optional) – SN curve norm, by default None

  • unit_string (str, optional) – units, by default “MPa”

  • color (str, optional) – RGBS or HEX string for color, by default None

_repr_svg_() str#

SVG representation of the SN curve instance

Returns:

the SVG object

Return type:

str

classmethod from_knee_points(knee_stress: list[float] | ndarray, knee_cycles: list[float] | ndarray, endurance: float = inf, environment: str | None = None, curve: str | None = None, norm: str | None = None, unit_string: str = 'MPa', color: str | None = None) SNCurve#

Create an SN curve from knee points. The first and last pairs of knee stress and knee cycles are used to set y-intercept and endurance respectively.

property endurance_stress: float#

Calculates the endurance stress, if endurance is defined.

Returns:

endurance stress

Return type:

float

Raises:

ValueError – Endurance (XXX cycles) is not compatible with SN curve knees (list). Consider changing params

format_name(html_format: bool = False) None#

Reformat SNCurve name.

Parameters:

html_format (bool, optional) – Choose whether the name format shall be HTML or not, by default True

get_knee_stress(check_knee: Collection | None = None, significant_digits: int = 2) ndarray#

Return stress at the knee(s).

Parameters:
  • check_knee (int or float or list or 1darray, optional) – Cycles value(s) to check against, defaults to Inf

  • significant_digits (int, optional) – Assertion accuracy, defaults to 2

Returns:

Stress at the knee(s)

Return type:

1darray

get_knee_cycles(check_knee: Collection | None = None, significant_digits: int = 2) ndarray#

Calculate the knee cycles.

Parameters:
  • check_knee (Collection, optional) – Collection of knee stress values, by default None

  • significant_digits (int, optional) – Number of significant digits, by default 2

Returns:

Knee cycles

Return type:

1darray

get_cycles(stress_range: int | float | list | ndarray) float | ndarray#

Return cycles value(s) for stress range(s).

Parameters:

stress_range (int or float or list or 1darray) – stress range(s) to find the corresponding number of cycles value(s) for.

Returns:

number of cycles value(s) for the stress range(s) stress_range.

Return type:

float or 1darray

get_stress(cycles: int | float | list | ndarray) float | ndarray#

Return stress range(s) for the endurance(s) N.

Parameters:

cycles (int or float or list or 1darray) – number of cycles value(s) to find the corresponding stress range(s) for.

Returns:

Stress range(s) for number of cycles value(s) cycles.

Return type:

float or 1darray

n(sigma: int | float | list | ndarray) float | ndarray#

Equivalent of get_cycles(). Added for backwards compatibility. It will be removed in a future release.

Parameters:

sigma (int or float or list or 1darray) – stress range(s) to find the corresponding number of cycles value(s) for.

Returns:

number of cycles value(s) for the stress range(s) sigma.

Return type:

float or 1darray

sigma(n: int | float | list | ndarray) float | ndarray#

Equivalent of SNCurve.get_stress(). Added for backwards compatibility. It will be removed in a future release

Parameters:

n (int or float or list or 1darray) – number of cycles value(s) to find the corresponding stress range(s) for.

Returns:

stress range(s) for the number of cycles value(s) n.

Return type:

float or 1darray

plotly(cycles: list | None = None, stress_range: list | None = None, dataset_name: str | None = None, dataset_color: str = '#000') Tuple[list, dict]#

Use plotly to plot the SN curve and a stress-cycles history dataset.

Example

Use plotly to plot the SN curve

>>> data, layout = sncurve.plotly()
>>> fig = go.Figure(data=data, layout=layout)
>>> fig.show
Parameters:
  • cycles (list, optional) – number of cycles value(s) in the dataset, by default None

  • stress_range (list, optional) – Stress range(s) in the dataset, by default None

  • dataset_name (str, optional) – history dataset name, by default None

  • dataset_color (str, optional) – history dataset color, by default “#000”

Returns:

data, layout

Return type:

Tuple[list, dict]

plot(cycles: list | None = None, stress_range: list | None = None, dataset_name: str | None = None, dataset_color: str = '#000', fig: Figure | None = None, ax: Axes | None = None, **kwargs: Any) Tuple[Figure, Axes]#

Use plotly to plot the SN curve and a stress-cycles history dataset.

Example

Use plotly to plot the SN curve

>>> fig, ax = sncurve.plot()
Parameters:
  • cycles (list, optional) – number of cycles value(s) in the dataset, by default None

  • stress_range (list, optional) – Stress range(s) in the dataset, by default None

  • dataset_name (str, optional) – history dataset name, by default None

  • dataset_color (str, optional) – history dataset color, by default “#000”

  • fig (matplotlib.figure.Figure, optional) – figure object, by default None

  • ax (matplotlib.axes.Axes, optional) – axis object, by default None

  • **kwargs (Any, optional) – additional keyword arguments

Returns:

The figure and axes.

Return type:

matplotlib.figure.Figure, matplotlib.axes.Axes