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
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ All notable changes to CableXSec are recorded in this file. The format follows

## [Unreleased]

### Fixed

- The distributed friction model (`friction_model="distributed"`, and `"auto"` on a non-planar
path) no longer runs without end at a contact pressure near zero. It subdivides every sample
step in units of the slip-onset curvature, which is proportional to the reference pressure;
an unclamped layer at zero tension (the 66 kV template, which has no manufacturing clamping,
under the solved contact model) returns a pressure of round-off size (about 5e-10 Pa), and
a 50-sample record would have taken some 1e17 substeps. A reference pressure at or below
`PRESSURE_ROUNDOFF_FRACTION` (1e-14) of the wire modulus now counts as zero (no friction, as
an exact zero and the direction-tied law); a record that would take more substeps than its
budget, `MAX_SUBSTEPS_PER_SAMPLE` (10 000) per sample and at least `MIN_SUBSTEP_BUDGET`
(1 000 000), is refused with a `CableInputError` that names the slip-onset curvature, and
`"auto"` keeps the direction-tied law for such a layer with a `FrictionModelFallbackWarning`.
`distributed_substep_count` and `distributed_substep_budget` return the count and the budget.
Every record within its budget gives the same result as before, bit for bit.

## [0.2.4] - 2026-12-04

The Python interfaces are versioned but may change before `1.0.0`. The evidence for
Expand Down
11 changes: 10 additions & 1 deletion doc/local_analysis_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,16 @@ cable, `examples/demo_05_fatigue_damage.py`, the long-term examples and the
release profile) and 13 to 16 times on the 66 kV template (an hour sampled at
10 Hz at 0.004 1/m: 43.6 s against 3.2 s; the 2000 s record of
[template_66kv.md](template_66kv.md): 36 s against 2.2 s). Planar records keep
the direction-tied cost under `"auto"`.
the direction-tied cost under `"auto"`. `κ_on` is proportional to the contact
pressure, so a layer with almost no pressure has almost no slip onset. A
reference pressure at round-off (at most `1e-14` of the wire modulus, as an
unclamped layer at zero tension returns) is zero pressure: no friction, as in
the direction-tied law. A record that would need more substeps than its
budget, 10 000 per sample (`MAX_SUBSTEPS_PER_SAMPLE`) and at least a million
(`MIN_SUBSTEP_BUDGET`), is refused (its wires slide in gross slip over the
record), and `"auto"` keeps the direction-tied law for that layer with a
`FrictionModelFallbackWarning`; `distributed_substep_count` and
`distributed_substep_budget` give the count and the budget of a record.

**Rotating curvature.** The direction-tied cap is the friction stress
accumulated from the current neutral axis, so it turns with the bending
Expand Down
56 changes: 53 additions & 3 deletions src/cablexsec/analysis/fatigue.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
DEFAULT_MAX_INCREMENT,
DEFAULT_NODES_PER_WIRE,
FRICTION_MODELS,
distributed_substep_budget,
distributed_substep_count,
distributed_wire_friction_stress,
)
from cablexsec.mechanics.fast_slip import wire_friction_stress
Expand Down Expand Up @@ -314,8 +316,21 @@ def _resolve_friction_model(
out_of_plane: float,
stick_modulus_Pa: FloatArray | None,
friction_law: FrictionLaw | None,
kappa_x: FloatArray,
kappa_y: FloatArray,
contact_pressure_Pa: FloatArray | None,
max_increment: float,
) -> tuple[str, str]:
"""Friction model of one layer and, for ``"auto"``, why it fell back."""
"""Friction model of one layer and, for ``"auto"``, why it fell back.

The distributed model is not taken for a record whose curvature steps
are too large against its slip-onset curvature (a contact pressure near
zero): it would take more substeps than
:func:`~cablexsec.mechanics.distributed_friction.distributed_substep_budget`
allows, which
:func:`~cablexsec.mechanics.distributed_friction.distributed_friction_history`
refuses.
"""
_check_friction_model(friction_model)
if friction_model != "auto":
return friction_model, ""
Expand All @@ -324,6 +339,22 @@ def _resolve_friction_model(
usable, reason = _distributed_spec(spec, stick_modulus_Pa, friction_law)
if usable is None:
return "direction_tied", reason
substeps = distributed_substep_count(
usable,
kappa_x,
kappa_y,
contact_pressure_Pa=contact_pressure_Pa,
max_increment=max_increment,
friction_law=friction_law,
)
samples = max(int(np.asarray(kappa_x).size), 1)
budget = distributed_substep_budget(samples)
if substeps > budget:
return "direction_tied", (
"its slip-onset curvature is too small for the curvature steps of the "
f"record (a contact pressure near zero): {substeps:.3g} substeps, "
f"{substeps / samples:.3g} per sample, above the budget {budget:.3g}"
)
return "distributed", ""


Expand Down Expand Up @@ -981,6 +1012,10 @@ def _wire_stress_parts(
else 0.0,
stick_modulus_Pa,
friction_law,
kappa_x,
kappa_y,
contact_pressure_Pa,
distributed_max_increment,
)
if progressive is not None and friction_model != "progressive":
raise CableInputError(
Expand Down Expand Up @@ -1324,6 +1359,10 @@ def wire_stress_field(
curvature_path_out_of_plane_ratio(kx, ky),
stick_modulus_Pa,
friction_law,
kx,
ky,
contact_pressure_Pa,
distributed_max_increment,
)
if reason:
_warn_auto_fallback(layer.name, reason, stacklevel=2)
Expand Down Expand Up @@ -2093,8 +2132,19 @@ def compute_fatigue(
spec = layer.spec
name = layer.name
layer_stick = None if stick_modulus_Pa is None else stick_modulus_Pa[name]
layer_pressure = (
None if contact_pressure_Pa is None else contact_pressure_Pa.get(name)
)
model, reason = _resolve_friction_model(
friction_model, spec, out_of_plane, layer_stick, friction_law
friction_model,
spec,
out_of_plane,
layer_stick,
friction_law,
kx,
ky,
layer_pressure,
distributed_max_increment,
)
chosen_model[name] = model
if reason:
Expand All @@ -2112,7 +2162,7 @@ def compute_fatigue(
tension_N,
EA_full_N,
None if thermal_stress_Pa is None else thermal_stress_Pa.get(name),
None if contact_pressure_Pa is None else contact_pressure_Pa.get(name),
layer_pressure,
axial_strain=axial_strain,
normal_stress_Pa=None
if normal_stress_Pa is None
Expand Down
18 changes: 16 additions & 2 deletions src/cablexsec/analysis/neutral_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def _layer_models(
kx: FloatArray,
ky: FloatArray,
friction_model: str,
pressures: Mapping[str, FloatArray],
) -> list[str]:
"""Friction model of every layer; ``"auto"`` resolved as in the fatigue route."""
if friction_model != "auto":
Expand All @@ -352,11 +353,24 @@ def _layer_models(
_warn_auto_fallback,
curvature_path_out_of_plane_ratio,
)
from cablexsec.mechanics.distributed_friction import ( # noqa: PLC0415
DEFAULT_MAX_INCREMENT,
)

ratio = curvature_path_out_of_plane_ratio(kx, ky)
models = []
for name, spec in layers:
model, reason = _resolve_friction_model("auto", spec, ratio, None, None)
model, reason = _resolve_friction_model(
"auto",
spec,
ratio,
None,
None,
kx,
ky,
pressures.get(name),
DEFAULT_MAX_INCREMENT,
)
if reason:
_warn_auto_fallback(name, reason, 4)
models.append(model)
Expand Down Expand Up @@ -427,7 +441,7 @@ def neutral_axes(
if strain.shape != kx.shape or not np.isfinite(strain).all():
raise CableInputError("axial strain must be finite and match the curvature")
pressures = dict(contact_pressure_Pa or {})
models = _layer_models(layers, kx, ky, friction_model)
models = _layer_models(layers, kx, ky, friction_model, pressures)
armour = tuple(
_layer_axes(name, spec, kx, ky, pressures.get(name), model, share) # type: ignore[arg-type]
for (name, spec), model in zip(layers, models, strict=True)
Expand Down
154 changes: 151 additions & 3 deletions src/cablexsec/mechanics/distributed_friction.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@
"DEFAULT_NODES_PER_WIRE",
"FRICTION_MODELS",
"HAVE_NUMBA",
"MAX_SUBSTEPS_PER_SAMPLE",
"MIN_SUBSTEP_BUDGET",
"PRESSURE_ROUNDOFF_FRACTION",
"DistributedFrictionHistory",
"distributed_friction_history",
"distributed_substep_budget",
"distributed_substep_count",
"distributed_wire_friction_stress",
]

Expand All @@ -150,6 +155,23 @@
DEFAULT_NODES_PER_WIRE = 4
#: Default largest curvature increment per substep, in units of ``kappa_on``.
DEFAULT_MAX_INCREMENT = 0.1
#: A reference contact pressure at or below this fraction of the wire modulus
#: (2 mPa for steel) is the round-off of a contact solve, not a clamping: an
#: unclamped layer at zero tension returns about 1e-9 Pa. The model treats it
#: as zero pressure (no friction), as it treats an exact zero, instead of
#: scaling the record by a slip-onset curvature of round-off size.
PRESSURE_ROUNDOFF_FRACTION = 1e-14
#: Substep budget of a record: ``MAX_SUBSTEPS_PER_SAMPLE`` per sample (a record
#: of moderate curvature steps takes about a hundred at the default
#: ``max_increment``), and never less than ``MIN_SUBSTEP_BUDGET`` in all (a
#: few coarse samples, such as a rig-test load path, may take more per
#: sample; a million substeps take about ten seconds per layer). A slip-onset
#: curvature so small against the record's curvature steps that the
#: subdivision would exceed the budget (a contact pressure near zero) is
#: refused: :func:`distributed_friction_history` raises, and
#: ``friction_model="auto"`` keeps the direction-tied law for the layer.
MAX_SUBSTEPS_PER_SAMPLE = 10_000
MIN_SUBSTEP_BUDGET = 1_000_000

_MAX_NEWTON = 60
_MAX_FIXED_POINT = 100
Expand Down Expand Up @@ -2097,6 +2119,118 @@ def _validated_increment(max_increment: float) -> float:
return value


def _reference_pressure(spec: HelicalLayerSpec, pressure: FloatArray) -> float:
"""Reference clamping ``P_ref`` [Pa]: the layer's, else the largest of the
history; zero when both are at round-off (``PRESSURE_ROUNDOFF_FRACTION``
of the wire modulus)."""
floor = PRESSURE_ROUNDOFF_FRACTION * float(spec.E_wire_Pa)
p_ref = float(spec.contact_pressure_Pa)
if p_ref <= floor:
p_ref = float(pressure.max()) if pressure.size else 0.0
return p_ref if p_ref > floor else 0.0


def _onset_scales(spec: HelicalLayerSpec, p_ref: float) -> tuple[float, float]:
"""Stress unit ``sigma_0 lam`` [Pa] and slip-onset curvature ``kappa_on``
[1/m]; ``(0, inf)`` where the bound is zero (no interface stiffness, no
friction coefficient, a lay angle of zero or no reference pressure)."""
xi = float(spec.xi)
alpha = float(spec.lay_angle_rad)
sin_a = abs(math.sin(alpha))
mu = float(spec.mu)
if xi == 0.0 or mu == 0.0 or sin_a < 1.0e-12 or p_ref <= 0.0:
return 0.0, math.inf
width = 2.0 * math.pi * spec.r_helix_m / int(spec.n_wires)
sigma0 = (
spec.r_helix_m * p_ref * width * math.cos(alpha) / (spec.A_wire_m2 * sin_a**2)
)
stress_unit = sigma0 * (mu * sin_a)
if stress_unit == 0.0:
return 0.0, math.inf
return stress_unit, stress_unit / (float(spec.k_f) * spec.r_helix_m)


def _substep_count(
kx: FloatArray,
ky: FloatArray,
rho: FloatArray,
kappa_on: float,
xi: float,
increment: float,
solve_repeats: bool,
) -> int:
"""Substeps of the kernels' rule: each sample step (the first from zero),
in units of ``kappa_on``, split into ``ceil(step / increment)`` when it
exceeds ``increment``; a sample that repeats the last one (curvature and
pressure ratio ``rho``) takes none unless a friction law is active
(``solve_repeats``). The step is formed as the kernels form it, so the
count is theirs (a lower bound only where an increment fails to converge
and is halved)."""
if not math.isfinite(kappa_on) or xi <= 0.0:
return 0
kappa_c = xi * kappa_on
with np.errstate(over="ignore", invalid="ignore"):
ax = kx / kappa_c
ay = ky / kappa_c
dx = np.diff(ax, prepend=0.0)
dy = np.diff(ay, prepend=0.0)
step = np.sqrt(dx**2 + dy**2) * xi
split = np.where(step > increment, np.ceil(step / increment), 1.0)
if not solve_repeats:
still = (
(ax == np.r_[0.0, ax[:-1]])
& (ay == np.r_[0.0, ay[:-1]])
& (rho == np.r_[rho[:1], rho[:-1]])
)
split = np.where(still, 0.0, split)
total = float(split.sum())
return int(total) if total < 2.0**62 else 2**62


def distributed_substep_budget(samples: int) -> int:
"""Largest substep count the model takes for a record of ``samples``:
``max(MAX_SUBSTEPS_PER_SAMPLE * samples, MIN_SUBSTEP_BUDGET)``."""
return max(MAX_SUBSTEPS_PER_SAMPLE * int(samples), MIN_SUBSTEP_BUDGET)


def distributed_substep_count(
spec: HelicalLayerSpec,
kappa_x: FloatArray,
kappa_y: FloatArray,
*,
contact_pressure_Pa: FloatArray | None = None,
max_increment: float = DEFAULT_MAX_INCREMENT,
friction_law: FrictionLaw | None = None,
) -> int:
"""Substeps that :func:`distributed_friction_history` takes for a record.

The count of the kernels' subdivision rule (a lower bound: an increment
that fails to converge is halved). Zero where the bound is zero, which
the model returns without solving. A count above
:func:`distributed_substep_budget` is refused by the model.
"""
kx = np.asarray(kappa_x, dtype=np.float64)
ky = np.asarray(kappa_y, dtype=np.float64)
pressure = (
np.full(kx.size, float(spec.contact_pressure_Pa))
if contact_pressure_Pa is None
else np.asarray(contact_pressure_Pa, dtype=np.float64)
)
p_ref = _reference_pressure(spec, pressure)
_unit, kappa_on = _onset_scales(spec, p_ref)
if not math.isfinite(kappa_on):
return 0
return _substep_count(
kx,
ky,
pressure / p_ref,
kappa_on,
float(spec.xi),
_validated_increment(max_increment),
active_friction_law(friction_law) is not None,
)


def distributed_friction_history(
spec: HelicalLayerSpec,
kappa_x: FloatArray,
Expand Down Expand Up @@ -2226,9 +2360,8 @@ def distributed_friction_history(
alpha = float(spec.lay_angle_rad)
sin_a = abs(math.sin(alpha))
mu = float(spec.mu)
p_ref = float(spec.contact_pressure_Pa)
if p_ref <= 0.0:
p_ref = float(pressure.max()) if pressure.size else 0.0
# Round-off pressures count as zero (PRESSURE_ROUNDOFF_FRACTION).
p_ref = _reference_pressure(spec, pressure)
n_w = int(spec.n_wires)
width = 2.0 * math.pi * spec.r_helix_m / n_w
lam = mu * sin_a
Expand Down Expand Up @@ -2276,6 +2409,21 @@ def distributed_friction_history(
k_f = float(spec.k_f)
kappa_on = stress_unit / (k_f * spec.r_helix_m)
kappa_c = xi * kappa_on
substeps = _substep_count(
kx, ky, pressure / p_ref, kappa_on, xi, increment, law is not None
)
budget = distributed_substep_budget(count)
if substeps > budget:
raise CableInputError(
f"the slip-onset curvature {kappa_on:.3g} 1/m (reference contact "
f"pressure {p_ref:.3g} Pa) is too small for the curvature steps of "
f"this record: the distributed model would take {substeps:.3g} "
f"substeps, {substeps / count:.3g} per sample (budget {budget:.3g}: "
f"{MAX_SUBSTEPS_PER_SAMPLE} per sample, at least "
f"{MIN_SUBSTEP_BUDGET:.0e}); the wires slide in gross slip over the "
"record. Use friction_model='direction_tied' (friction_model='auto' "
"keeps it for such a layer)"
)
shape = np.ones(n_w) if spec.shape_g is None else np.asarray(spec.shape_g, float)
if shape.shape != (n_w,) or not np.isfinite(shape).all() or np.any(shape < 0):
raise CableInputError("shape_g must be finite, nonnegative and one per wire")
Expand Down
Loading
Loading