sn_curve#
The sn_curve module contains the SNCurve class and all the funcitons strictly related to its correct functioning. The function relies on the AbstractSNCurve class, which can be used as a abstract class for the definition of new SN curve models such as smart SN curves.
The SNCurve class#
- 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 (Union[int, float, list, np.ndarray]) – SN curve slope
intercept (Union[int, float, list, np.ndarray]) – Stress axis intercept
endurance (Union[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
Public Data Attributes:
endurance_stress
Calculates the endurance stress, if endurance is defined.
Inherited from
AbstractSNCurve
linear
Preventing attribute modification outside of constructor
slope
Preventing attribute modification outside of constructor
intercept
Preventing attribute modification outside of constructor
endurance
Preventing attribute modification outside of constructor
unit
Preventing attribute modification outside of constructor
endurance_stress
Calculates the endurance stress, if endurance is defined.
Public Methods:
format_name
([html_format])Reformat SNCurve name.
get_knee_stress
([check_knee, significant_digits])Return stress at the knee(s).
get_knee_cycles
([check_knee, significant_digits])Calculate the knee cycles.
get_cycles
(stress_range)Return cycles value(s) for stress range(s).
get_stress
(cycles)Return stress range(s) for the endurance(s) N.
n
(sigma)Equivalent of
get_cycles()
.sigma
(n)Equivalent of
SNCurve.get_stress()
.plotly
([cycles, stress_range, dataset_name, ...])Use plotly to plot the SN curve and a stress-cycles history dataset.
plot
([cycles, stress_range, dataset_name, ...])Use plotly to plot the SN curve and a stress-cycles history dataset.
Inherited from
AbstractSNCurve
__init__
(slope, intercept[, endurance, ...])Define stress-life (SN) curve.
__str__
()SN curve __str__ method
__eq__
(other)Compare different SN curves and assert that they contain same attributes values
format_name
([html_format])Reformat SNCurve name.
get_knee_cycles
([check_knee, significant_digits])Calculate the knee cycles.
get_knee_stress
([check_knee, significant_digits])Return stress at the knee(s).
get_cycles
(stress_range)Return cycles value(s) for stress range(s).
get_stress
(cycles)Return stress range(s) for the endurance(s) N.
Private Data Attributes:
_abc_impl
Inherited from
AbstractSNCurve
_abc_impl
Private Methods:
_repr_svg_
()SVG representation of the SN curve instance
Inherited from
AbstractSNCurve
_repr_svg_
()SVG representation of the SN curve instance
- property endurance_stress: float#
Calculates the endurance stress, if endurance is defined.
- Returns:
endurance stress
- Return type:
- 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).
- 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:
- 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