Skip to content

generic

Overview

Use a flat surface or a table of geometry factors for single-dimension Paris growth.

py_fatigue.geometry.generic

Classes

AbstractCrackGeometry

Bases: CrackGeometryMixin, PlotMixin

Abstract class to initalise and store the crack geometry data.

Source code in py_fatigue/geometry/generic.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class AbstractCrackGeometry(
    CrackGeometryMixin, PlotMixin, metaclass=abc.ABCMeta
):
    """Abstract class to initalise and store the crack geometry data."""

    def __str__(self) -> str:

        str_ = "\n".join(
            [
                f"{self.__class__.__name__}(",
                f"  _id={self._id},",
                f"  initial_depth={self.initial_depth},",
                ")",
            ]
        )
        return str_

    def __repr__(self) -> str:
        return self.__str__()

    @property
    @abc.abstractmethod
    def _id(self) -> property:
        """Get the ID of the crack geometry."""

CrackGeometryMixin

Mixin class to define the abstract methods for the AbstractCrackGeometry class.

Parameters:

Name Type Description Default
initial_depth float

The initial depth of the crack.

required
Source code in py_fatigue/geometry/generic.py
38
39
40
41
42
43
44
45
46
47
48
49
@dataclass(repr=False)
class CrackGeometryMixin:
    """Mixin class to define the abstract methods for the
    AbstractCrackGeometry class.

    Parameters
    ----------
    initial_depth : float
        The initial depth of the crack.
    """

    initial_depth: PositiveFloat

InfiniteSurface

Bases: AbstractCrackGeometry

Class to initalise and store the crack geometry data on a flat infinite surface, as per standard Paris' law.

Attributes:

Name Type Description
initial_depth float

The initial depth of the crack.

Source code in py_fatigue/geometry/generic.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
@dataclass(repr=False)
class InfiniteSurface(AbstractCrackGeometry):
    """Class to initalise and store the crack geometry data on a
    flat infinite surface, as per standard Paris' law.

    Attributes
    ----------
    initial_depth : float
        The initial depth of the crack.
    """

    _id = property(lambda _: "INF_SUR_00")

    def plot(
        self, fig: Figure | None = None, ax: Axes | None = None
    ) -> tuple[Figure, Axes]:
        """Draw a depth-only schematic of the crack at the infinite surface."""
        fig, ax = make_axes(fig, ax)
        ax.plot([0, 0], [0, self.initial_depth], "o-", color="firebrick")
        ax.set(ylabel="Depth from surface", title="Infinite surface crack")
        ax.xaxis.set_visible(False)
        if not ax.yaxis_inverted():
            ax.invert_yaxis()
        return fig, ax
Methods:
plot
plot(fig=None, ax=None)

Draw a depth-only schematic of the crack at the infinite surface.

Source code in py_fatigue/geometry/generic.py
214
215
216
217
218
219
220
221
222
223
224
def plot(
    self, fig: Figure | None = None, ax: Axes | None = None
) -> tuple[Figure, Axes]:
    """Draw a depth-only schematic of the crack at the infinite surface."""
    fig, ax = make_axes(fig, ax)
    ax.plot([0, 0], [0, self.initial_depth], "o-", color="firebrick")
    ax.set(ylabel="Depth from surface", title="Infinite surface crack")
    ax.xaxis.set_visible(False)
    if not ax.yaxis_inverted():
        ax.invert_yaxis()
    return fig, ax

TabulatedGeometryFactor

Bases: AbstractCrackGeometry

One growing crack dimension with measured or computed geometry factors.

Use with get_crack_growth. The solver interpolates the factor linearly, evaluates ΔK = Δσ Y(a) √(πa), and stops at the last depth in the table. Supply depths in the length unit used by the Paris curve.

Parameters:

Name Type Description Default
initial_depth float

Initial crack dimension inside the table, below its last depth.

required
depths array - like

Positive, strictly increasing crack dimensions.

required
factors array - like

Positive, dimensionless geometry factors at the supplied depths.

required
Source code in py_fatigue/geometry/generic.py
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
class TabulatedGeometryFactor(AbstractCrackGeometry):
    """One growing crack dimension with measured or computed geometry factors.

    Use with `get_crack_growth`. The solver interpolates the factor
    linearly, evaluates ΔK = Δσ Y(a) √(πa), and stops at the last depth
    in the table. Supply depths in the length unit used by the Paris curve.

    Parameters
    ----------
    initial_depth : float
        Initial crack dimension inside the table, below its last depth.
    depths : array-like
        Positive, strictly increasing crack dimensions.
    factors : array-like
        Positive, dimensionless geometry factors at the supplied depths.
    """

    _id = property(lambda _: "TABULATED")

    def __init__(
        self, initial_depth: float, depths: ArrayLike, factors: ArrayLike
    ) -> None:
        super().__init__(initial_depth=initial_depth)
        self.depths = np.array(depths, dtype=float, copy=True)
        self.factors = np.array(factors, dtype=float, copy=True)
        if (
            self.depths.ndim != 1
            or self.depths.size < 2
            or self.depths.shape != self.factors.shape
        ):
            raise ValueError("Provide at least two depth and factor pairs.")
        if (
            not np.all(np.isfinite(self.depths) & (self.depths > 0))
            or not np.all(np.isfinite(self.factors) & (self.factors > 0))
            or not np.all(np.diff(self.depths) > 0)
        ):
            raise ValueError(
                "Depths must increase and all values must be "
                "positive and finite."
            )
        if not self.depths[0] <= self.initial_depth < self.depths[-1]:
            raise ValueError(
                "Initial depth must lie below the end of the factor table."
            )
        self.depths.setflags(write=False)
        self.factors.setflags(write=False)

    def plot(
        self, fig: Figure | None = None, ax: Axes | None = None
    ) -> tuple[Figure, Axes]:
        """Plot the supplied geometry factors and mark the initial depth."""
        fig, ax = make_axes(fig, ax)
        ax.plot(self.depths, self.factors, label="Tabulated factor")
        ax.axvline(self.initial_depth, linestyle="--", label="Initial depth")
        ax.set(xlabel="Crack dimension", ylabel="Geometry factor")
        ax.legend()
        return fig, ax
Methods:
plot
plot(fig=None, ax=None)

Plot the supplied geometry factors and mark the initial depth.

Source code in py_fatigue/geometry/generic.py
189
190
191
192
193
194
195
196
197
198
def plot(
    self, fig: Figure | None = None, ax: Axes | None = None
) -> tuple[Figure, Axes]:
    """Plot the supplied geometry factors and mark the initial depth."""
    fig, ax = make_axes(fig, ax)
    ax.plot(self.depths, self.factors, label="Tabulated factor")
    ax.axvline(self.initial_depth, linestyle="--", label="Initial depth")
    ax.set(xlabel="Crack dimension", ylabel="Geometry factor")
    ax.legend()
    return fig, ax

Functions:

kwargs_only

kwargs_only(cls)

Decorator to make a class's init method accept only keyword arguments.

This is useful for dataclasses, which by default accept positional arguments.

Source code in py_fatigue/geometry/generic.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def kwargs_only(cls):
    """Decorator to make a class's __init__ method accept only keyword
    arguments.

    This is useful for dataclasses, which by default accept positional
    arguments.
    """
    old_init = cls.__init__

    @wraps(old_init)
    def new_init(self, *args, **kwargs):
        if args:
            raise TypeError("This class only accepts keyword arguments.")
        old_init(self, **kwargs)

    cls.__init__ = new_init
    return cls