Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ Functional kernels operating on arrays; most are not called directly by users.
| `sn_assessment.py` | `ComponentSCF` (axial, friction, normal and lateral bending factors, mean and dynamic) and the corrected Miner sum (`corrected_damage`, `corrected_damage_rows`): stress factor, mean-stress correction and thickness factor per rainflow cycle; used by the armour, conductor, sheath and tape routes |
| `termination.py` | `TerminationSpec` and `termination_friction_increment`: anchored-wire clamp increment of the friction stress for a section near an end fitting or clamped stiffener root (`clamp_layer` solver along the principal, optionally also the minor, curvature direction, or `solver="along_wire"` with `stick`, `capstan` and `lateral_relief`; `curvature_field=` for a non-proportional field; far-field reference from the same discrete solver, so the sectional result is recovered away from the anchor) |
| `fast_rainflow.py` | Compiled rainflow counting and Miner damage for many histories (see below) |
| `fast_field.py` | Compiled one-pass assembly of the fixed-fibre wire stress field of `wire_stress_field` (see below) |
| `long_term.py` | `compute_long_term_fatigue`: probability- and duration-weighted damage at fixed fibres before hotspot selection |
| `sea_state_batch.py` | `run_sea_state_batch`: CableDyn runs with probabilities to weighted annual damage and life per section (reader, `compute_fatigue` with optional clamp, thermal, fretting and user S-N options, `compute_long_term_fatigue`), optional capacity check of every section and run (`CapacityBatchCheck`); spawned workers with one thread each, JSON specification, manifest with input digests; console command `cablexsec-batch` ([doc/global_local_guide.md](doc/global_local_guide.md), stage 1) |
| `critical_plane.py` | `compute_swt_cycle`: sampled SWT critical planes for one closed cycle at one point |
Expand Down Expand Up @@ -303,8 +304,17 @@ kernels of their own, each with a reference path:
`miner_rows` applies the same counter to the bulk Miner sums of
`compute_fatigue` (including a termination stress-range factor) when
`numba` is active; rows where the reference `miner_damage` would raise are
rerun on the reference path. `rainflow_counter="reference"` keeps the
rerun on the reference path. `fibre_miner_damage`, which `compute_fatigue`
uses, gives the same sums at every fixed fibre of a wire stress field
without forming the fibre histories: each history is reduced to its turning
points while it is formed (without branches), the reversal scan feeds the
three-point stack directly, and one count serves the unit and the
termination stress-range factor. `rainflow_counter="reference"` keeps the
reference counter available.
- `analysis/fast_field.py` (`assemble_wire_field`) forms the mean, radial and
edge components of the wire stress field in one pass, with the operations
of the NumPy expressions it replaces in the same order (the trigonometric
factors are evaluated by NumPy and passed in), so the field is unchanged.

`fast_rainflow.rainflow_table` returns the same cycles with their sample
indices (range, mean, count, start, end) for the fretting module, which also
Expand Down
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ All notable changes to CableXSec are recorded in this file. The format follows

### Added

- `validation/scripts/benchmark_throughput.py`: one-core throughput of sea-state fatigue on
the 66 kV template (direction-tied and distributed models, every wire or 12 positions, 4 or
32 fibres), the damage differences from an earlier build, and the sea-state batch time
against the worker count. `tests/test_fast_fatigue_path.py` checks the fused counting and
field assembly against the arithmetic they replace (no wall-clock assertion).
- CableDyn range graphs and VIV lift files are read: `read_cabledyn_range_graph`
(`<root>.Line<L>.range.out`, OpenFAST `<root>.CD.Line<L>.range.out`) and
`read_cabledyn_lift` (`<root>.Line<L>.V.out`), each checked column by column
Expand Down Expand Up @@ -389,6 +394,26 @@ All notable changes to CableXSec are recorded in this file. The format follows

### Changed

- `compute_fatigue` is 2.5–2.8 times faster on the direction-tied model, with every damage
value bit for bit unchanged. One-hour sea state on the 66 kV template (20 000 samples, both
armour layers, numba, one thread, `validation/scripts/benchmark_throughput.py`): all 284
wires 0.73 s → 0.27 s (4 fibres) and 2.34 s → 0.84 s (32 fibres, 12.9 → 4.6 ns per fibre
sample); 12 positions per layer 0.068 s → 0.027 s. The fixed fibres of a layer are counted in
one compiled pass (`fast_rainflow.fibre_miner_damage`): each fibre history is reduced to its
turning points while it is formed, the reversal scan feeds the three-point stack directly,
and one count serves the unit and the termination stress-range factor; entries where the
reference sum would raise are recomputed on the reference path in the former order. The
stress field is assembled in one compiled pass (`fast_field.assemble_wire_field`, the NumPy
operations in the same order); without numba the NumPy path forms the local bending stress
once instead of twice. The distributed model is limited by its increment solver, as before
(29.2 s → 27.5 s on all wires with 4 fibres).
- `SeaStateBatchOptions(workers=...)` and `cablexsec-batch --workers` have no upper limit
(`MAX_WORKERS` is removed); the pool starts at most one worker per run, and the 16
persistent numba cache slots of the workers stay as they were (a worker beyond them gets a
temporary cache). On 48 one-hour runs the batch takes 42.6 s with 1 worker and 26.9 s with
2 (107.6 s and 61.1 s before); the rest of the time at many workers is the start-up of each
worker (about 2 s: imports and loading the compiled kernels).

- The laid-core and filler-profile contact loads follow the tension history by default:
`compute_neutral_axes(..., core_loads="follow")` with `tension_N` or `contact_tension_N`, and
`compute_mkappa(..., core_loads="follow")` with `contact_tension_history_N`; before, they were
Expand Down
14 changes: 8 additions & 6 deletions doc/global_local_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,15 @@ result.sections["sag"].long_term.annual_damage, result.sections["sag"].life_year
the wider tolerance; a 10-column row gives no `GJ` and is not compared. A
mismatch stops the batch unless `allow_property_mismatch=True` is
declared, and the comparison is written to the manifest either way.
- Workers: `workers` processes (at most `MAX_WORKERS = 8`), one numerical
thread each, spawned; results do not depend on the worker count. Each
worker keeps its compiled kernels in a cache folder of its own, `slot-<i>`
under `cablexsec/numba-batch` in the user cache directory (set
- Workers: `workers` processes, one numerical thread each, spawned, at most
one per run; there is no upper limit, so choose the count for the machine
(the runs are independent and the batch scales with the worker count while
there are runs for every worker). Results do not depend on the worker count.
Each worker keeps its compiled kernels in a cache folder of its own,
`slot-<i>` under `cablexsec/numba-batch` in the user cache directory (set
`CABLEXSEC_BATCH_CACHE_DIR` to move it), so later batches start warm; a
slot is held by one worker at a time, and deleting the folder only costs a
recompilation.
slot is held by one worker at a time, a worker beyond the 16 slots gets a
temporary cache, and deleting the folder only costs a recompilation.
- Output folder (must not exist): `manifest.json` (SHA-256 of every CableDyn
file and deck, the cable definition and YAML file, options, property check,
reader checks per run, results, and `inputs_sha256` over all of them);
Expand Down
11 changes: 7 additions & 4 deletions doc/local_analysis_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1555,10 +1555,13 @@ histories.
On one thread the Step 3 path takes 0.76 s per section-hour for 118 wires × 32
fibres and 42 001 samples (600 s initialisation plus a 3600 s retained hour);
`parallel=True` spreads wires over threads.
`compute_fatigue` uses the compiled slip kernel and, through
`fast_rainflow.miner_rows`, the compiled counter for each fibre; its damage is
bitwise equal to the reference counter, still available with
`rainflow_counter="reference"`.
`compute_fatigue` uses the compiled slip kernel, assembles the stress field in
one compiled pass (`fast_field.assemble_wire_field`) and counts every fixed
fibre with `fast_rainflow.fibre_miner_damage`, the compiled counter applied to
each fibre history as it is formed; its damage is bitwise equal to the
reference counter, still available with `rainflow_counter="reference"`.
`validation/scripts/benchmark_throughput.py` records the one-core throughput
of this route on a one-hour sea state of the 66 kV template.

The pure-Python routines remain the reference implementation.
`tests/test_fast_slip.py` and `tests/test_fast_rainflow.py` require the
Expand Down
1 change: 1 addition & 0 deletions release/check_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"tests/test_fast_rainflow.py",
"tests/test_fast_slip.py",
"tests/test_compiled_counter.py",
"tests/test_fast_fatigue_path.py",
"tests/test_progressive_friction.py",
"tests/test_fretting_regime.py",
"tests/test_strand_slip.py",
Expand Down
151 changes: 151 additions & 0 deletions src/cablexsec/analysis/fast_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University
"""Compiled assembly of the fixed-fibre wire stress field.

:func:`assemble_wire_field` forms the three components of
:class:`cablexsec.analysis.fatigue.WireStressField` (``mean_Pa``,
``radial_Pa``, ``tangential_Pa``) from the friction stress, the per-sample
axial and thermal stress and the curvature history in one pass, with the
arithmetic of the NumPy expressions it replaces, operation for operation:
the local bending stress of
:func:`cablexsec.mechanics.wire_stress.local_bending_fibre_stress` at the
outward radial fibre and at the edge (fibre angle ``pi/2``), the outward
total ``((sigma_A + sigma_B) + sigma_f) + sigma_T`` plus any termination
increment, and ``mean = outward - radial``. The trigonometric factors are
evaluated by NumPy, as in the reference expressions, and passed in. The
results are equal to the NumPy path bit for bit
(``tests/test_fast_fatigue_path.py``).

Without numba (or with ``CABLEXSEC_DISABLE_NUMBA=1``) the NumPy expressions
are used instead (see :mod:`cablexsec._numba`).
"""

from __future__ import annotations

import math

import numpy as np
from numpy.typing import NDArray

from cablexsec._numba import HAVE_NUMBA, njit

__all__ = ["HAVE_NUMBA", "assemble_wire_field"]

FloatArray = NDArray[np.float64]


@njit(cache=True)
def _assemble_kernel(
kx: FloatArray,
ky: FloatArray,
cos_phi: FloatArray,
sin_phi: FloatArray,
coef_radial: FloatArray,
coef_edge: FloatArray,
c_radial: float,
c_tangential: float,
cos_outward: float,
sin_outward: float,
cos_edge: float,
sin_edge: float,
axial: FloatArray,
friction: FloatArray,
thermal: FloatArray,
extra: FloatArray,
has_extra: bool,
) -> tuple[FloatArray, FloatArray, FloatArray]:
n_w, n_t = friction.shape
mean = np.empty((n_w, n_t))
radial = np.empty((n_w, n_t))
edge = np.empty((n_w, n_t))
for w in range(n_w):
cp = cos_phi[w]
sp = sin_phi[w]
for i in range(n_t):
x = kx[i]
y = ky[i]
rb = c_radial * (x * cp + y * sp)
tb = c_tangential * ((-x) * sp + y * cp)
sb = coef_radial[i] * (rb * cos_outward + tb * sin_outward)
out = ((axial[i] + sb) + friction[w, i]) + thermal[i]
if has_extra:
out = out + extra[w, i]
radial[w, i] = sb
edge[w, i] = coef_edge[i] * (rb * cos_edge + tb * sin_edge)
mean[w, i] = out - sb
return mean, radial, edge


def assemble_wire_field(
kappa_x: FloatArray,
kappa_y: FloatArray,
phi: FloatArray,
modulus_Pa: float | FloatArray,
depth_m: float,
width_m: float,
lay_angle_rad: float,
axial_Pa: FloatArray,
friction_Pa: FloatArray,
thermal_Pa: FloatArray,
extra_Pa: FloatArray | None = None,
) -> tuple[FloatArray, FloatArray, FloatArray]:
"""``(mean, radial, tangential)`` of the wire stress field [Pa].

Equal bit for bit to the NumPy expressions ::

radial = local_bending_fibre_stress(kx, ky, phi[:, None], E, depth, a)
tangential = local_bending_fibre_stress(
kx, ky, phi[:, None], E, width, a, pi / 2
)
outward = axial[None, :] + radial + friction + thermal[None, :]
outward = outward + extra # when given
mean = outward - radial

``modulus_Pa`` is a constant or one value per sample; ``axial_Pa`` and
``thermal_Pa`` hold one value per sample, ``friction_Pa`` and
``extra_Pa`` one row per wire.
"""
kx = np.ascontiguousarray(kappa_x, dtype=np.float64)
ky = np.ascontiguousarray(kappa_y, dtype=np.float64)
friction = np.ascontiguousarray(friction_Pa, dtype=np.float64)
n_t = kx.size
angle = np.asarray(phi, dtype=np.float64)[:, None]
cos_phi = np.ascontiguousarray(np.cos(angle)[:, 0])
sin_phi = np.ascontiguousarray(np.sin(angle)[:, 0])
# Factors exactly as local_bending_fibre_stress forms them.
c, s = math.cos(lay_angle_rad), math.sin(lay_angle_rad)
c_radial = c * c * math.cos(2 * lay_angle_rad)
c_tangential = c * (1 + s * s)
modulus = np.asarray(modulus_Pa)
coef_radial = np.ascontiguousarray(
np.broadcast_to(modulus * depth_m / 2, (n_t,)), dtype=np.float64
)
coef_edge = np.ascontiguousarray(
np.broadcast_to(modulus * width_m / 2, (n_t,)), dtype=np.float64
)
outward_theta = np.asarray(0.0)
edge_theta = np.asarray(math.pi / 2)
extra = (
np.zeros((0, 0))
if extra_Pa is None
else np.ascontiguousarray(extra_Pa, dtype=np.float64)
)
return _assemble_kernel(
kx,
ky,
cos_phi,
sin_phi,
coef_radial,
coef_edge,
c_radial,
c_tangential,
float(np.cos(outward_theta)),
float(np.sin(outward_theta)),
float(np.cos(edge_theta)),
float(np.sin(edge_theta)),
np.ascontiguousarray(axial_Pa, dtype=np.float64),
friction,
np.ascontiguousarray(thermal_Pa, dtype=np.float64),
extra,
extra_Pa is not None,
)
Loading
Loading