From e148d18e03f06444894f5388c0228dc6829120d3 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Thu, 19 Nov 2026 17:31:09 +0900 Subject: [PATCH 1/4] fix: fallbacks and skipped checks are an error or a warning, never silent - fretting_regime.range_at_cycles bisected on [1e-6, 1e6] MPa and returned the bound when the life lay outside it (1e12 Pa for a life shorter than the curve's at 1e6 MPa, 1 Pa for a NaN life). It refuses a life that is not finite and positive, or outside its bracket. - The wire-yield guard of compute_mkappa swallowed every ValueError, so a bound that could not be evaluated left no trace. It warns; a cable without a yield-stressed armour layer, which has no bound, is skipped as before. - The bending-test inversion returned its closest cached point as converged when it had no new point to try. It raises CableSolverError with the miss. - A kinematic history whose laid cores have no friction law held them to the cable axis silently. It warns and records it in the provenance. - compute_sheave and the rig-test M-kappa loops ran their internal calls under simplefilter("ignore"), dropping a wire-yield or clamping warning about the caller's own curvature. Each distinct warning is relayed once (provenance.relayed_warnings). Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 16 +++ src/cablexsec/analysis/beam_test.py | 11 +- src/cablexsec/analysis/fretting_regime.py | 14 +++ src/cablexsec/analysis/kinematics.py | 17 ++- src/cablexsec/analysis/rig_test.py | 14 ++- src/cablexsec/analysis/sheave.py | 5 +- src/cablexsec/api.py | 61 ++++++----- src/cablexsec/provenance.py | 23 +++- tests/test_silent_fallbacks.py | 128 ++++++++++++++++++++++ 9 files changed, 250 insertions(+), 39 deletions(-) create mode 100644 tests/test_silent_fallbacks.py diff --git a/CHANGELOG.md b/CHANGELOG.md index a038d82..08a67e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -430,6 +430,22 @@ All notable changes to CableXSec are recorded in this file. The format follows ### Fixed +- Fallbacks are an error or a warning, never silent (`tests/test_silent_fallbacks.py`). + `fretting_regime.range_at_cycles` bisected on [1e-6, 1e6] MPa and returned the bound when the + life lay outside it (1e12 Pa for a life shorter than the curve's at 1e6 MPa, 1 Pa for a NaN + life); it refuses a life that is not finite and positive or outside its bracket. The + wire-yield guard of `compute_mkappa` swallowed every `ValueError`, so a bound that could not + be evaluated left no trace; it now warns (`ExtrapolationWarning`), and a cable without a + yield-stressed armour layer, which has no bound, is skipped as before. The bending-test + inversion returned its closest cached point as converged when it had no new point to try; it + raises `CableSolverError` with the miss. A kinematic history whose laid cores have no + friction law held them to the cable axis silently; it warns and records it in the + provenance. +- `compute_sheave` and the rig-test M-kappa loops ran their internal calls under + `warnings.simplefilter("ignore")`, dropping a wire-yield or clamping warning about the + caller's own curvature; each distinct warning is now relayed once + (`provenance.relayed_warnings`). + - `SectionLaw.from_cable` reads the cable's own materials (its `materials:` block) when the law is built and every time it is evaluated. Outside `simulate_bending_test` it read the library instead, and a layer whose material the library lacks silently dropped out of the stiffness diff --git a/src/cablexsec/analysis/beam_test.py b/src/cablexsec/analysis/beam_test.py index 0684f02..fa5a6f6 100644 --- a/src/cablexsec/analysis/beam_test.py +++ b/src/cablexsec/analysis/beam_test.py @@ -933,8 +933,15 @@ def solve(self, targets: FloatArray) -> tuple[FloatArray, FloatArray]: before = self.v.size self._add(np.concatenate(cands)) if self.v.size == before: - # no new point: accept the closest cached point - return sol_v, sol_u + # No new point to try: the open targets are not reached within + # the tolerance, so the closest cached point would be a wrong + # answer returned as a converged one. + worst = float(np.max(np.minimum(r_hi, r_lo)[open_])) + raise CableSolverError( + "bending-test inversion stalled: no new curvature point to try, " + f"{int(np.count_nonzero(open_))} target(s) missed by up to " + f"{worst:.3g} (tolerance {self.tol:.3g})" + ) raise CableSolverError("bending-test inversion did not converge") diff --git a/src/cablexsec/analysis/fretting_regime.py b/src/cablexsec/analysis/fretting_regime.py index e894587..34aa667 100644 --- a/src/cablexsec/analysis/fretting_regime.py +++ b/src/cablexsec/analysis/fretting_regime.py @@ -750,7 +750,21 @@ def range_at_cycles(sn_curve: SNcurve, cycles: float) -> float: """ if sn_curve.stress_unit != "MPa": raise CableInputError("a stress-range S-N curve in MPa is required") + if isinstance(cycles, bool) or not (math.isfinite(cycles) and cycles > 0.0): + raise CableInputError(f"cycles must be finite and positive: {cycles!r}") lo, hi = -6.0, 6.0 # log10 of the range in MPa + # The bisection holds the range inside [1e-6, 1e6] MPa; a root outside it + # would come back as the bound. + if not sn_curve.cycles_to_failure(10.0**hi) <= cycles: + raise CableInputError( + f"the S-N curve gives more than {cycles:g} cycles even at 1e6 MPa: " + "no stress range of that life" + ) + if not sn_curve.cycles_to_failure(10.0**lo) > cycles: + raise CableInputError( + f"the S-N curve gives at most {cycles:g} cycles even at 1e-6 MPa: " + "no stress range of that life" + ) for _ in range(200): mid = 0.5 * (lo + hi) if sn_curve.cycles_to_failure(10.0**mid) > cycles: diff --git a/src/cablexsec/analysis/kinematics.py b/src/cablexsec/analysis/kinematics.py index 7a86ea2..43c0d12 100644 --- a/src/cablexsec/analysis/kinematics.py +++ b/src/cablexsec/analysis/kinematics.py @@ -96,6 +96,7 @@ import dataclasses import math +import warnings from collections.abc import Mapping, Sequence from dataclasses import dataclass from typing import TYPE_CHECKING, Any, Literal @@ -123,7 +124,7 @@ from cablexsec.mechanics.tendon_bending import TransverseSlipModel from cablexsec.mechanics.tendon_section import WireSection, round_section from cablexsec.mechanics.wire_stress import local_bending_fibre_stress -from cablexsec.provenance import Provenance, real_array +from cablexsec.provenance import ExtrapolationWarning, Provenance, real_array if TYPE_CHECKING: from cablexsec.analysis.stress import FrictionField @@ -979,6 +980,7 @@ def kinematic_history( if core_spec is None else _core_field(cable, core_spec, reference, contact_model, drive, strain) ) + core_note = "" if cores is None and core_utilisation and _has_cores(cable): # Without the core lay stage the cores do not move, but they carry # the utilisation of their components, as in the component response: @@ -994,8 +996,17 @@ def kinematic_history( strain, moving=False, ) - except (CableInputError, CableSchemaError): + except (CableInputError, CableSchemaError) as error: cores = _held_core_field(cable, drive, strain) + if cable.core_lay is not None: + # Laid cores whose friction law cannot be built: said, not + # silent, since their utilisation then comes from the section + # strain at their axes, not from the law. + core_note = ( + f"core friction law unavailable ({error}): the laid cores are " + "held to the cable axis for their utilisation" + ) + warnings.warn(core_note, ExtrapolationWarning, stacklevel=2) limitations = [ "uniform curvature along the cable: the state of a wire depends on its " "azimuth only, and the stations round the section are read along the helix", @@ -1005,6 +1016,8 @@ def kinematic_history( "force over the axial stiffness with the twist held", "mean clamping prescribed per sample, as in the stress route", ] + if core_note: + limitations.append(core_note) return KinematicHistory( samples=kept, time_s=times[kept], diff --git a/src/cablexsec/analysis/rig_test.py b/src/cablexsec/analysis/rig_test.py index 4610860..df00ac3 100644 --- a/src/cablexsec/analysis/rig_test.py +++ b/src/cablexsec/analysis/rig_test.py @@ -48,7 +48,6 @@ from __future__ import annotations import math -import warnings from collections.abc import Callable, Mapping, Sequence from dataclasses import dataclass, field, replace @@ -89,7 +88,12 @@ ) from cablexsec.mechanics.stiffness import xi_for_layer from cablexsec.mechanics.wire_stress import local_bending_fibre_stress -from cablexsec.provenance import Provenance, real_array, require_finite +from cablexsec.provenance import ( + Provenance, + real_array, + relayed_warnings, + require_finite, +) __all__ = [ "DEFAULT_GAUGE_RESOLUTION_MICROSTRAIN", @@ -905,8 +909,7 @@ def _secant_stiffness( core_friction: bool | CoreFrictionSpec | None = None, ) -> float: history = kappa_amp * np.sin(np.linspace(0, 4 * math.pi, 161)) - with warnings.catch_warnings(): - warnings.simplefilter("ignore") + with relayed_warnings(): if normal.contact_model == "solved": loop = compute_mkappa( cable, @@ -1526,8 +1529,7 @@ def bending( if np.ptp(kap) == 0: m_sec = np.zeros(time.size) else: - with warnings.catch_warnings(): - warnings.simplefilter("ignore") + with relayed_warnings(): if normal.contact_model == "solved": loop = compute_mkappa( cable, diff --git a/src/cablexsec/analysis/sheave.py b/src/cablexsec/analysis/sheave.py index 158821d..6a5fbd6 100644 --- a/src/cablexsec/analysis/sheave.py +++ b/src/cablexsec/analysis/sheave.py @@ -57,7 +57,7 @@ import numpy as np from cablexsec.exceptions import CableInputError -from cablexsec.provenance import Provenance +from cablexsec.provenance import Provenance, relayed_warnings if TYPE_CHECKING: from cablexsec.analysis.capacity_check import CapacityEnvelope @@ -324,8 +324,7 @@ def compute_sheave( q0 = 2.0 * tension_N / D p0 = q0 / d - with warnings.catch_warnings(): - warnings.simplefilter("ignore") + with relayed_warnings(): loop = compute_mkappa( cable, np.linspace(0.0, kappa, 50), diff --git a/src/cablexsec/api.py b/src/cablexsec/api.py index b8d9cc7..067946e 100644 --- a/src/cablexsec/api.py +++ b/src/cablexsec/api.py @@ -49,6 +49,7 @@ from cablexsec.analysis.capacity import ( BirdcageDetail, CapacityResult, + _armour_layers, birdcage_buckling_detail, compute_capacity, wire_yield_curvature, @@ -949,32 +950,42 @@ def compute_mkappa( # Soft guard: the linear-elastic wire-stress assumption holds below the # armour yield curvature (where the capacity envelope's wire-yield mechanism - # is reached). Beyond it the elastic M-κ is unconservative. - try: - kappa_yield = wire_yield_curvature( - cable, - float(np.max(tension_history)) - if tension_history is not None - else tension_N - if section_state is None - else 0.0, - mu=mu, - section_state=section_state, - contact_model=contact_model, - phi_bend=phi_bend, - ) - if math.isfinite(kappa_yield) and kappa_yield > 0.0: - check_range( - float(np.max(np.abs(kappa))), - ValidatedRange( - "peak |curvature| [1/m]", - 0.0, - kappa_yield, - "armour wire-yield curvature (capacity wire-yield mechanism)", - ), + # is reached). Beyond it the elastic M-κ is unconservative. A cable without + # an armour layer of published yield stress has no bound to check; a bound + # that cannot be evaluated for another reason is said so, not skipped. + if _armour_layers(cable): + try: + kappa_yield = wire_yield_curvature( + cable, + float(np.max(tension_history)) + if tension_history is not None + else tension_N + if section_state is None + else 0.0, + mu=mu, + section_state=section_state, + contact_model=contact_model, + phi_bend=phi_bend, + ) + except (CableSchemaError, ValueError, KeyError) as error: + warnings.warn( + "the armour wire-yield curvature, the bound of the elastic M-kappa " + f"law, could not be evaluated ({error}); the curvature history is " + "not checked against it", + ExtrapolationWarning, + stacklevel=3, ) - except (ValueError, KeyError): - pass # no yield-strength armour: no curvature bound to check + else: + if math.isfinite(kappa_yield) and kappa_yield > 0.0: + check_range( + float(np.max(np.abs(kappa))), + ValidatedRange( + "peak |curvature| [1/m]", + 0.0, + kappa_yield, + "armour wire-yield curvature (capacity wire-yield mechanism)", + ), + ) run = mkappa_law.run( kappa, diff --git a/src/cablexsec/provenance.py b/src/cablexsec/provenance.py index 5344309..fbd2242 100644 --- a/src/cablexsec/provenance.py +++ b/src/cablexsec/provenance.py @@ -36,7 +36,8 @@ import math import warnings -from collections.abc import Iterable +from collections.abc import Iterable, Iterator +from contextlib import contextmanager from dataclasses import dataclass, field from typing import cast @@ -57,6 +58,7 @@ "UnvalidatedModelWarning", "ValidatedRange", "check_range", + "relayed_warnings", "require_finite", ] @@ -244,6 +246,25 @@ def check_range(value: float, vr: ValidatedRange, *, stacklevel: int = 3) -> boo return False +@contextmanager +def relayed_warnings(*, stacklevel: int = 3) -> Iterator[None]: + """Gather the warnings of internal calls and pass each distinct one on once. + + For a function that evaluates other entry points on its own sweeps: their + warnings (a curvature beyond the wire-yield bound, an undeclared clamping + state) concern the caller's input too, so they are relayed, not silenced. + """ + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter("always") + yield + seen: set[tuple[type[Warning], str]] = set() + for item in caught: + key = (item.category, str(item.message)) + if key not in seen: + seen.add(key) + warnings.warn(str(item.message), item.category, stacklevel=stacklevel) + + def require_finite(value: float | Iterable[float], name: str) -> None: """Raise :class:`PhysicalRangeError` if any element of ``value`` is non-finite. diff --git a/tests/test_silent_fallbacks.py b/tests/test_silent_fallbacks.py new file mode 100644 index 0000000..8af8f0e --- /dev/null +++ b/tests/test_silent_fallbacks.py @@ -0,0 +1,128 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +"""Fallbacks, clamps and skipped checks are explicit: an error or a warning. + +Each case is one that used to return a value silently: a bisection that hit +its bracket, or a guard that was skipped on any error. +""" + +from __future__ import annotations + +import math +import warnings + +import numpy as np +import pytest +from _bundled import bundled + +import cablexsec as cx +from cablexsec.analysis import fretting_regime as fr +from cablexsec.exceptions import CableInputError +from cablexsec.materials.sn_curves import get_sn_curve +from cablexsec.provenance import ExtrapolationWarning + + +@pytest.mark.parametrize( + ("cycles", "match"), + [ + (math.nan, "cycles must be finite and positive"), + (0.0, "cycles must be finite and positive"), + (-5.0, "cycles must be finite and positive"), + (math.inf, "cycles must be finite and positive"), + (1e-30, "even at 1e6 MPa"), + ], +) +def test_range_at_cycles_refuses_a_life_outside_its_bracket(cycles, match): + """The bisection on [1e-6, 1e6] MPa returned its bound (1e12 Pa for a + life below the curve's at 1e6 MPa, 1 Pa for NaN) instead of a range.""" + curve = get_sn_curve("dnv_rpc203_t_curve") + with pytest.raises(CableInputError, match=match): + fr.range_at_cycles(curve, cycles) + + +def test_range_at_cycles_inside_the_bracket_is_unchanged(): + curve = get_sn_curve("dnv_rpc203_t_curve") + value = fr.range_at_cycles(curve, 2e6) + assert curve.cycles_to_failure(value / 1e6) == pytest.approx(2e6, rel=1e-9) + + +def test_mkappa_yield_guard_is_evaluated_or_said_to_be_skipped(monkeypatch): + """The wire-yield guard of compute_mkappa swallowed every ValueError, so + a bound that could not be evaluated left no trace. It now warns.""" + cable = bundled("inter_array_single_core_33kv") + kappa = np.linspace(0.0, 0.02, 20) + with warnings.catch_warnings(): + warnings.simplefilter("error", ExtrapolationWarning) + cx.compute_mkappa(cable, kappa, tension_N=1e5) # inside the bound + + def refuse(*args, **kwargs): + raise CableInputError("no bound for this state") + + monkeypatch.setattr("cablexsec.api.wire_yield_curvature", refuse) + with pytest.warns(ExtrapolationWarning, match="could not be evaluated .no bound"): + cx.compute_mkappa(cable, kappa, tension_N=1e5) + + +def test_stalled_bending_test_inversion_is_refused(): + """With no new point to try, the inversion returned the closest cached + point (here u = 0 for a target of 1) as if it had converged.""" + from cablexsec.analysis.beam_test import _MonotoneInverse + from cablexsec.exceptions import CableSolverError + + flat = _MonotoneInverse( + lambda v: np.zeros_like(v), slope_min=math.inf, slope_max=math.inf, tol=1e-9 + ) + with pytest.raises(CableSolverError, match="inversion stalled"): + flat.solve(np.array([1.0])) + linear = _MonotoneInverse( + lambda v: 2.0 * v, slope_min=1.0, slope_max=3.0, tol=1e-12 + ) + v, u = linear.solve(np.array([0.5, 1.0])) + np.testing.assert_allclose(u, [0.5, 1.0], atol=1e-12) + np.testing.assert_allclose(v, [0.25, 0.5], atol=1e-12) + + +def test_laid_cores_without_a_friction_law_are_said_to_be_held(monkeypatch): + """The kinematic history fell back to cores held to the cable axis on any + error of the core friction law, without a trace.""" + from cablexsec.analysis import kinematics + + cable = bundled("inter_array_three_core_33kv") + + def refuse(*args, **kwargs): + raise CableInputError("no core friction for this cable") + + monkeypatch.setattr(kinematics, "_core_field", refuse) + kx = 0.01 * np.sin(np.linspace(0.0, 6.0, 12)) + with pytest.warns(ExtrapolationWarning, match="core friction law unavailable"): + history = kinematics.kinematic_history( + cable, kx, 0.0 * kx, tension_N=1e5, core_friction=False + ) + assert any( + "core friction law unavailable" in note + for note in history.provenance.limitations + ) + + +def test_sheave_relays_the_warnings_of_its_internal_calls(monkeypatch): + """compute_sheave evaluated its M-kappa loop, stress and capacity under + ``simplefilter("ignore")``: a wire-yield or clamping warning about the + caller's own sheave curvature was dropped. Each distinct one is relayed.""" + from cablexsec import api + from cablexsec.analysis import sheave + from cablexsec.provenance import MissingClampingStateWarning + + real = api.compute_mkappa + + def noisy(*args, **kwargs): + warnings.warn("inner notice", MissingClampingStateWarning, stacklevel=2) + warnings.warn("inner notice", MissingClampingStateWarning, stacklevel=2) + return real(*args, **kwargs) + + monkeypatch.setattr(api, "compute_mkappa", noisy) + cable = cx.load_cable(cx.iea_task49_66kv_yaml_path()) + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter("always") + sheave.compute_sheave(cable, sheave_diameter_m=6.4, tension_N=50e3, n_ramp=10) + relayed = [w for w in caught if str(w.message) == "inner notice"] + assert len(relayed) == 1 and relayed[0].category is MissingClampingStateWarning From ab81e37a30b51e00d4ceb1beb75ceefbc0747e7d Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Thu, 19 Nov 2026 17:36:51 +0900 Subject: [PATCH 2/4] fix: range_at_cycles compares log10 lives The new bracket check evaluated the life at 1e-6 MPa, which overflows for a steep curve (m 40, log C 80) whose root at 1e6 cycles is representable, and refused the curve. The bisection and its bracket now compare log10 lives (SNcurve.log10_life), which stay representable. Signed-off-by: Jae Hoon Seo --- src/cablexsec/analysis/fretting_regime.py | 14 +++++++++++--- tests/test_silent_fallbacks.py | 10 ++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/cablexsec/analysis/fretting_regime.py b/src/cablexsec/analysis/fretting_regime.py index 34aa667..1a52c92 100644 --- a/src/cablexsec/analysis/fretting_regime.py +++ b/src/cablexsec/analysis/fretting_regime.py @@ -753,21 +753,29 @@ def range_at_cycles(sn_curve: SNcurve, cycles: float) -> float: if isinstance(cycles, bool) or not (math.isfinite(cycles) and cycles > 0.0): raise CableInputError(f"cycles must be finite and positive: {cycles!r}") lo, hi = -6.0, 6.0 # log10 of the range in MPa + target = math.log10(cycles) + + def longer(log_range: float) -> bool: + # Compared as log10 lives, which a steep curve keeps representable + # where the life itself would overflow. + life = float(sn_curve.log10_life(np.array([10.0**log_range]))[0]) + return life > target + # The bisection holds the range inside [1e-6, 1e6] MPa; a root outside it # would come back as the bound. - if not sn_curve.cycles_to_failure(10.0**hi) <= cycles: + if longer(hi): raise CableInputError( f"the S-N curve gives more than {cycles:g} cycles even at 1e6 MPa: " "no stress range of that life" ) - if not sn_curve.cycles_to_failure(10.0**lo) > cycles: + if not longer(lo): raise CableInputError( f"the S-N curve gives at most {cycles:g} cycles even at 1e-6 MPa: " "no stress range of that life" ) for _ in range(200): mid = 0.5 * (lo + hi) - if sn_curve.cycles_to_failure(10.0**mid) > cycles: + if longer(mid): lo = mid else: hi = mid diff --git a/tests/test_silent_fallbacks.py b/tests/test_silent_fallbacks.py index 8af8f0e..612da0a 100644 --- a/tests/test_silent_fallbacks.py +++ b/tests/test_silent_fallbacks.py @@ -46,6 +46,16 @@ def test_range_at_cycles_inside_the_bracket_is_unchanged(): assert curve.cycles_to_failure(value / 1e6) == pytest.approx(2e6, rel=1e-9) +def test_range_at_cycles_of_a_steep_curve(): + """A steep curve's life overflows at the bracket's low end (1e-6 MPa) + while its root is representable: compared as log10 lives.""" + from cablexsec.materials.sn_curves import SNcurve + + steep = SNcurve(name="steep", stress_unit="MPa", m1=40.0, log_C1=80.0) + value = fr.range_at_cycles(steep, 1e6) + assert value == pytest.approx(1e6 * 10.0 ** ((80.0 - 6.0) / 40.0), rel=1e-9) + + def test_mkappa_yield_guard_is_evaluated_or_said_to_be_skipped(monkeypatch): """The wire-yield guard of compute_mkappa swallowed every ValueError, so a bound that could not be evaluated left no trace. It now warns.""" From 6944fc01b1406e5fb2f63e3a191fcd95a8daa8bb Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Thu, 19 Nov 2026 20:49:56 +0900 Subject: [PATCH 3/4] fix: range_at_cycles accepts a root on the lower bracket end A life equal to the curve's life at 1e-6 MPa (to 1e-12 in log10) has its root on the bracket's lower end; it was refused as outside it. Signed-off-by: Jae Hoon Seo --- src/cablexsec/analysis/fretting_regime.py | 12 ++++++++---- tests/test_silent_fallbacks.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/cablexsec/analysis/fretting_regime.py b/src/cablexsec/analysis/fretting_regime.py index 1a52c92..9549ea0 100644 --- a/src/cablexsec/analysis/fretting_regime.py +++ b/src/cablexsec/analysis/fretting_regime.py @@ -755,11 +755,13 @@ def range_at_cycles(sn_curve: SNcurve, cycles: float) -> float: lo, hi = -6.0, 6.0 # log10 of the range in MPa target = math.log10(cycles) + def log_life(log_range: float) -> float: + # log10 lives, which a steep curve keeps representable where the life + # itself would overflow. + return float(sn_curve.log10_life(np.array([10.0**log_range]))[0]) + def longer(log_range: float) -> bool: - # Compared as log10 lives, which a steep curve keeps representable - # where the life itself would overflow. - life = float(sn_curve.log10_life(np.array([10.0**log_range]))[0]) - return life > target + return log_life(log_range) > target # The bisection holds the range inside [1e-6, 1e6] MPa; a root outside it # would come back as the bound. @@ -768,6 +770,8 @@ def longer(log_range: float) -> bool: f"the S-N curve gives more than {cycles:g} cycles even at 1e6 MPa: " "no stress range of that life" ) + if math.isclose(log_life(lo), target, rel_tol=1e-12, abs_tol=1e-12): + return float(10.0**lo * 1.0e6) # the root on the bracket's lower end if not longer(lo): raise CableInputError( f"the S-N curve gives at most {cycles:g} cycles even at 1e-6 MPa: " diff --git a/tests/test_silent_fallbacks.py b/tests/test_silent_fallbacks.py index 612da0a..947bae7 100644 --- a/tests/test_silent_fallbacks.py +++ b/tests/test_silent_fallbacks.py @@ -56,6 +56,16 @@ def test_range_at_cycles_of_a_steep_curve(): assert value == pytest.approx(1e6 * 10.0 ** ((80.0 - 6.0) / 40.0), rel=1e-9) +def test_range_at_cycles_on_the_lower_bracket_end(): + """A root exactly at 1e-6 MPa (1 Pa) lies on the bracket, not outside.""" + from cablexsec.materials.sn_curves import SNcurve + + edge = SNcurve(name="edge", stress_unit="MPa", m1=1.0, log_C1=0.0) + assert fr.range_at_cycles(edge, 1e6) == pytest.approx(1.0, rel=1e-12) + with pytest.raises(CableInputError, match="even at 1e-6 MPa"): + fr.range_at_cycles(edge, 2e6) + + def test_mkappa_yield_guard_is_evaluated_or_said_to_be_skipped(monkeypatch): """The wire-yield guard of compute_mkappa swallowed every ValueError, so a bound that could not be evaluated left no trace. It now warns.""" From 6342104977bd54a60975d19bdf4da4578a7a53e9 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Thu, 19 Nov 2026 22:26:55 +0900 Subject: [PATCH 4/4] fix: the bending-test inversion bisects before it calls a stall After dev 7e14481, test_leg_property_and_energy[kw3] (distributed friction, three-point, 24 stations per segment) raised "bending-test inversion stalled: 1 target(s) missed by up to 6.26e-08 (tolerance 1.92e-09)". The inverted quantity steps by 2.3e-7 over a few ulps of the curvature there, the target lies inside the step, and both interpolants rounded onto cached points, so no new point was added; bisection had not been tried at that iteration. On a stall the open brackets are now bisected; a bracket with no float inside is already closed as tiny, so a stall is raised only when no point is left. On a step 2.3e-7 high, 1600 targets inside it: 429 stalls before, none now, each resolved to the step within 4e-16 relative. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 8 +++++--- src/cablexsec/analysis/beam_test.py | 6 ++++++ tests/test_silent_fallbacks.py | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d4aedb..1db128f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -449,9 +449,11 @@ All notable changes to CableXSec are recorded in this file. The format follows be evaluated left no trace; it now warns (`ExtrapolationWarning`), and a cable without a yield-stressed armour layer, which has no bound, is skipped as before. The bending-test inversion returned its closest cached point as converged when it had no new point to try; it - raises `CableSolverError` with the miss. A kinematic history whose laid cores have no - friction law held them to the cable axis silently; it warns and records it in the - provenance. + bisects the bracket first (a target inside a step a few ulps wide, where the + interpolants round onto cached points, is resolved to the step) and raises + `CableSolverError` with the miss only when no point is left. A kinematic history whose + laid cores have no friction law held them to the cable axis silently; it warns and records + it in the provenance. - `compute_sheave` and the rig-test M-kappa loops ran their internal calls under `warnings.simplefilter("ignore")`, dropping a wire-yield or clamping warning about the caller's own curvature; each distinct warning is now relayed once diff --git a/src/cablexsec/analysis/beam_test.py b/src/cablexsec/analysis/beam_test.py index 510b322..9b44f94 100644 --- a/src/cablexsec/analysis/beam_test.py +++ b/src/cablexsec/analysis/beam_test.py @@ -945,6 +945,12 @@ def solve(self, targets: FloatArray) -> tuple[FloatArray, FloatArray]: cands.append(0.5 * (vl + vh)) before = self.v.size self._add(np.concatenate(cands)) + if self.v.size == before and inside.any(): + # The interpolants rounded onto cached points (a target inside + # a step of u a few ulps of v wide, as the distributed friction + # model gives): bisect. A bracket with no float inside it is + # closed above (tiny). + self._add(0.5 * (V[lo[inside]] + V[hi[inside]])) if self.v.size == before: # No new point to try: the open targets are not reached within # the tolerance, so the closest cached point would be a wrong diff --git a/tests/test_silent_fallbacks.py b/tests/test_silent_fallbacks.py index 947bae7..50b1510 100644 --- a/tests/test_silent_fallbacks.py +++ b/tests/test_silent_fallbacks.py @@ -102,6 +102,29 @@ def test_stalled_bending_test_inversion_is_refused(): np.testing.assert_allclose(v, [0.25, 0.5], atol=1e-12) +@pytest.mark.parametrize("frac", [0.1, 0.27, 0.5, 0.9]) +def test_inversion_resolves_a_target_inside_a_round_off_step(frac): + """A target inside a step of u (2.3e-7 against a tolerance of 1.9e-9 over a + few ulps of v, as the distributed friction model gave on the three-point + test) is resolved to the step: the interpolants round onto cached points + there, and that stall was refused although bisection closes the bracket.""" + from cablexsec.analysis.beam_test import _MonotoneInverse + + rng = np.random.default_rng(1) + step = 2.3e-7 + for c in rng.uniform(0.001, 0.01, 100): + inv = _MonotoneInverse( + lambda v, c=c: 86000.0 * v + step * (v >= c), + slope_min=5.0e4, + slope_max=9.0e4, + tol=1.9e-9, + ) + target = 86000.0 * c + frac * step + v, u = inv.solve(np.array([target])) + assert abs(v[0] - c) <= 4e-16 * c + assert abs(u[0] - target) <= step + + def test_laid_cores_without_a_friction_law_are_said_to_be_held(monkeypatch): """The kinematic history fell back to cores held to the cable axis on any error of the core friction law, without a trace."""