From ef69b726e509131deefc510a7144eeb4a60044b4 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Tue, 17 Nov 2026 20:27:11 +0900 Subject: [PATCH 1/3] fix: friction-model routing of the batch and of 'auto' The sea-state batch set friction_model="direction_tied" explicitly, so DirectionTiedFrictionWarning, which compute_fatigue issues only when the model is left at its default, never fired in the batch or cablexsec-batch, and the batch would not follow the planned change of the default. SeaStateBatchOptions.friction_model now defaults to None and the batch passes it through. The library default is unchanged ("direction_tied", new constant DEFAULT_FRICTION_MODEL), so results are unchanged bit for bit; the manifest and the assessment digests record the model the default resolves to and are unchanged too. Warnings of spawned worker processes, shown only on the workers' standard error before, are issued again in the caller. friction_model="auto" kept the direction-tied law silently (only a provenance limitation) when the distributed model did not cover a layer on a non-planar path: a rate-dependent friction law, a rigid interface or a stick modulus that changes over the record. It now warns once per layer (FrictionModelFallbackWarning) from compute_fatigue and wire_stress_field. curvature_path_out_of_plane_ratio judged the out-of-plane distance against the largest curvature, so a static bend hid cycles normal to it (0.05 1/m with 4e-5 1/m normal cycles: 8e-4, planar). The distance is now judged against the smaller of the largest curvature and the largest distance from the mean curvature, floored at 1e-3 of the largest curvature so that a nearly constant curvature written with six significant digits stays planar: that path is 0.8 out of plane. Paths without a static offset keep their ratio. Over the 1203 tests that reach the planarity test and the shipped fatigue examples and tutorials no verdict changes except in the new checks. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 25 +++++++ doc/glossary.rst | 4 +- doc/local_analysis_guide.md | 28 ++++--- src/cablexsec/__init__.py | 2 + src/cablexsec/analysis/fatigue.py | 53 +++++++++++-- src/cablexsec/analysis/sea_state_batch.py | 55 +++++++++++++- src/cablexsec/api.py | 3 +- src/cablexsec/provenance.py | 16 ++++ tests/test_biaxial_friction_default.py | 90 +++++++++++++++++++++-- tests/test_sea_state_batch.py | 34 +++++++++ 10 files changed, 278 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39649ca..0956067 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -240,6 +240,31 @@ All notable changes to CableXSec are recorded in this file. The format follows points, and warns when a transition is narrower than its step; a law that still misses the stick stiffness warns. The exported laws of the validation and benchmark rows (MX-1, MX-2, MX-scale) do not change at their printed precision. +- The sea-state batch takes the default armour friction model of `compute_fatigue`: + `SeaStateBatchOptions.friction_model` is `None` by default (was an explicit + `"direction_tied"`), so the batch and `cablexsec-batch` follow the planned change of the + default and warn with `DirectionTiedFrictionWarning` on non-planar records, which they never + did. The default is still `"direction_tied"`: results are unchanged, bit for bit, and the + manifest and the assessment digests record the model the default resolves to, so they are + unchanged too (new `cablexsec.analysis.fatigue.DEFAULT_FRICTION_MODEL`). Warnings of the + worker processes (`workers > 1`) were shown on the workers' standard error only; they are now + issued again in the calling process. +- `friction_model="auto"` warns when it keeps the direction-tied law on a non-planar path + (`FrictionModelFallbackWarning`, once per layer, from `compute_fatigue` and + `wire_stress_field`): a rate-dependent friction law, a rigid interface (`ξ ≥ 1`) or a stick + modulus that changes over the record. Before, only the provenance limitations recorded it. +- `curvature_path_out_of_plane_ratio` (the planarity test of `friction_model="auto"` and of the + default-change notice) judged the out-of-plane distance against the largest curvature, so a + static bend hid cycles normal to it: a static 0.05 1/m with ±4e-5 1/m normal cycles was 8e-4 + out of plane (planar) and `"auto"` took the direction-tied law, whose cap follows the static + bending direction. The distance is now judged against the smaller of the largest curvature and + the largest distance from the mean curvature, the latter floored at 1e-3 of the largest + curvature (so a nearly constant curvature written with six significant digits stays planar): + that path is 0.8 out of plane. Paths without a static offset (every bundled check: planar + paths, centred ellipses and circles) keep their ratio; a planar path with a static offset in + its plane stays planar. Over the 1 203 tests that reach the planarity test and the shipped + fatigue examples and tutorials, no path other than the new checks changes its verdict. + - The slip of the distributed friction model over a full-slip increment (every helix node on its bound) is now unique. The equations fix the forces, the tractions and `u − p` there, but not a slide common to the displacement `u` and the slip `p` of all nodes; the solver left one node diff --git a/doc/glossary.rst b/doc/glossary.rst index c340483..ac9601d 100644 --- a/doc/glossary.rst +++ b/doc/glossary.rst @@ -1325,7 +1325,9 @@ Terms and abbreviations Warnings issued when a run succeeds but rests on an assumption or leaves its validated range: :term:`ExtrapolationWarning`, :term:`MissingClampingStateWarning`, ``UnmodelledPolymerSofteningWarning``, ``UnevaluatedFatigueCurveWarning``, - ``UnvalidatedModelWarning`` and ``TransverseMapWarning``; and the ``FutureWarning`` + ``UnvalidatedModelWarning``, ``TransverseMapWarning`` and ``FrictionModelFallbackWarning`` + (``friction_model="auto"`` kept the direction-tied law on a non-planar path); and the + ``FutureWarning`` ``DirectionTiedFrictionWarning`` of a default that changes in the next release. wear diff --git a/doc/local_analysis_guide.md b/doc/local_analysis_guide.md index d6eb22d..1f259c4 100644 --- a/doc/local_analysis_guide.md +++ b/doc/local_analysis_guide.md @@ -1486,19 +1486,27 @@ run uncompiled. (`DirectionTiedFrictionWarning`, a `FutureWarning`, with the measured bias below); the result of this release is unchanged. Pass `friction_model` explicitly to keep the current behaviour (`"direction_tied"`) or to take the - coming one (`"auto"`) without the warning. The sea-state batch passes its - option explicitly and does not warn. + coming one (`"auto"`) without the warning. The sea-state batch takes the + same default (`SeaStateBatchOptions.friction_model=None`) and warns the same + way, from its worker processes too; its manifest records the model the + default resolves to. - `"auto"` (opt-in): the direction-tied law for a planar curvature path and the distributed law for any other. The path is planar when its out-of-plane ratio (`curvature_path_out_of_plane_ratio`: the largest distance of a sample - `(κ_x, κ_y)` from the principal line through the origin, over the largest - curvature) is at most `PLANAR_PATH_TOLERANCE = 1e-3`. A planar path in any - plane gives round-off, the same path written with six significant digits - less than `1e-5`, an ellipse its axis ratio. A layer the distributed law - does not cover (rigid interface `ξ ≥ 1`, a stick modulus that changes over - the record, a rate-dependent friction law) keeps the direction-tied law. The - provenance records the ratio, the model of every layer and the reason for a - fallback. `wire_stress_field` takes `"auto"` too. + `(κ_x, κ_y)` from the principal line through the origin, over the smaller of + the largest curvature and the largest distance of a sample from the mean + curvature, the latter not below `1e-3` of the largest curvature) is at most + `PLANAR_PATH_TOLERANCE = 1e-3`. A planar path in any plane gives round-off, + a static offset in that plane included, the same path written with six + significant digits less than `1e-5`, an ellipse its axis ratio. The second + scale keeps a static bend from hiding cycles normal to it: a static + curvature of 0.05 1/m with cycles of 4e-5 1/m normal to it is 8e-4 out of + plane against the largest curvature, but 0.8 against the floor of its range. + A layer the distributed law does not cover (rigid interface `ξ ≥ 1`, a + stick modulus that changes over the record, a rate-dependent friction law) + keeps the direction-tied law and warns (`FrictionModelFallbackWarning`, once + per layer). The provenance records the ratio, the model of every layer and + the reason for a fallback. `wire_stress_field` takes `"auto"` too. - `"distributed"`: the friction force is solved along one pitch of the helix with interface shear stiffness `k̂ = ξ/(1 − ξ)` and the capstan bound `λ n` on the signed wire force, for any biaxial curvature history and the diff --git a/src/cablexsec/__init__.py b/src/cablexsec/__init__.py index 1da60de..206cf45 100644 --- a/src/cablexsec/__init__.py +++ b/src/cablexsec/__init__.py @@ -308,6 +308,7 @@ from cablexsec.mechanics.thermal_network import ThermalNetwork, thermal_network from cablexsec.provenance import ( DirectionTiedFrictionWarning, + FrictionModelFallbackWarning, MissingClampingStateWarning, UnmodelledPolymerSofteningWarning, ) @@ -572,6 +573,7 @@ "ValidatedRange", "ExtrapolationWarning", "DirectionTiedFrictionWarning", + "FrictionModelFallbackWarning", "UnevaluatedFatigueCurveWarning", "UnvalidatedModelWarning", "MissingClampingStateWarning", diff --git a/src/cablexsec/analysis/fatigue.py b/src/cablexsec/analysis/fatigue.py index 1de82df..8f27c19 100644 --- a/src/cablexsec/analysis/fatigue.py +++ b/src/cablexsec/analysis/fatigue.py @@ -122,6 +122,7 @@ from cablexsec.mechanics.wire_stress import local_bending_fibre_stress from cablexsec.provenance import ( DirectionTiedFrictionWarning, + FrictionModelFallbackWarning, Provenance, real_array, ) @@ -133,11 +134,20 @@ RainflowCounter = Literal["auto", "compiled", "reference"] FrictionModel = Literal["auto", "direction_tied", "distributed", "progressive"] +#: Armour friction model of :func:`compute_fatigue` when ``friction_model`` is +#: left at ``None`` (the planned change to ``"auto"`` is announced by +#: :class:`~cablexsec.provenance.DirectionTiedFrictionWarning`). +DEFAULT_FRICTION_MODEL: FrictionModel = "direction_tied" DistributedBound = Literal["signed", "uniform"] #: Out-of-plane ratio (:func:`curvature_path_out_of_plane_ratio`) at or below #: which ``friction_model="auto"`` treats a curvature path as planar (and above #: which the default direction-tied law warns). PLANAR_PATH_TOLERANCE = 1e-3 +#: Smallest range about the mean, relative to the largest curvature, against +#: which :func:`curvature_path_out_of_plane_ratio` judges a path: a static +#: curvature written with six significant digits (error up to 5e-7 of it) +#: stays planar, and cycles normal to a static bend count from 1e-6 of it. +_PATH_SPREAD_FLOOR = 1e-3 #: Measured bias of the direction-tied law under rotating curvature, quoted by #: :class:`~cablexsec.provenance.DirectionTiedFrictionWarning`. DIRECTION_TIED_ROTATION_BIAS = ( @@ -153,6 +163,7 @@ COPPER_CONTACT_MODELS: tuple[str, ...] = ("slip_cycle", "legacy_gross_sliding") __all__ = [ + "DEFAULT_FRICTION_MODEL", "PLANAR_PATH_TOLERANCE", "FatigueLayer", "FatigueResult", @@ -170,16 +181,24 @@ def curvature_path_out_of_plane_ratio( kappa_x: FloatArray, kappa_y: FloatArray ) -> float: - """Out-of-plane extent of a curvature path, relative to its largest curvature. + """Out-of-plane extent of a curvature path, relative to its curvature range. A planar history keeps one bending plane: every sample ``(kappa_x, kappa_y)`` lies on one line through the origin. The line is the principal axis of the second moment ``sum k k^T`` of the samples about the origin (not about their mean: the bending plane passes through the straight cable). The ratio is the largest distance of a sample from that line over - the largest curvature magnitude: zero for a planar path in any plane, one - for a circle, ``b/a`` for an ellipse of semi-axes ``a >= b`` centred on - the origin. A zero history returns zero. + the smaller of the largest curvature magnitude and the largest distance + of a sample from the mean curvature: zero for a planar path in any plane, + a static offset in the plane included, one for a circle, ``b/a`` for an + ellipse of semi-axes ``a >= b`` centred on the origin. The second scale + keeps a static bend from hiding the cycles about it: a static curvature + with small cycles normal to its plane is as far from planar as the cycles + are large, not as small as they are against the static bend. A range + below ``1e-3`` of the largest curvature is judged against that floor, so + that the rounding of a nearly constant curvature in output files (six + significant digits: at most ``5e-4``) stays planar; cycles normal to a + static bend then count from ``1e-6`` of it. A zero history returns zero. """ kx = np.asarray(kappa_x, dtype=np.float64) ky = np.asarray(kappa_y, dtype=np.float64) @@ -192,8 +211,11 @@ def curvature_path_out_of_plane_ratio( x, y = kx / peak, ky / peak sxx, syy, sxy = float(x @ x), float(y @ y), float(x @ y) angle = 0.5 * math.atan2(2.0 * sxy, sxx - syy) - distance = np.abs(y * math.cos(angle) - x * math.sin(angle)) - return float(np.max(distance)) + distance = float(np.max(np.abs(y * math.cos(angle) - x * math.sin(angle)))) + # The range about the mean (in units of the peak): a static bend with + # cycles normal to its plane is judged against the cycles. + spread = float(np.max(np.hypot(x - np.mean(x), y - np.mean(y)))) + return distance / min(1.0, max(spread, _PATH_SPREAD_FLOOR)) def _distributed_spec( @@ -246,6 +268,18 @@ def _resolve_friction_model( return "distributed", "" +def _warn_auto_fallback(name: str, reason: str, stacklevel: int) -> None: + """Warn that ``friction_model="auto"`` kept the direction-tied law.""" + warnings.warn( + f"friction_model='auto' kept the direction-tied model for {name} on a " + f"non-planar curvature path because {reason}; the distributed model does " + "not cover that case, and the direction-tied cap turns with the bending " + f"direction: {DIRECTION_TIED_ROTATION_BIAS}", + FrictionModelFallbackWarning, + stacklevel=stacklevel + 1, + ) + + def _warn_default_direction_tied(out_of_plane: float, stacklevel: int) -> None: """Warn that the default direction-tied law runs on a non-planar path.""" if out_of_plane <= PLANAR_PATH_TOLERANCE: @@ -1014,13 +1048,15 @@ def wire_stress_field( kx, ky = real_array(kappa_x, "kappa_x"), real_array(kappa_y, "kappa_y") _check_distributed_bound(distributed_bound) if friction_model == "auto": - friction_model, _reason = _resolve_friction_model( # type: ignore[assignment] + friction_model, reason = _resolve_friction_model( # type: ignore[assignment] friction_model, layer.spec, curvature_path_out_of_plane_ratio(kx, ky), stick_modulus_Pa, friction_law, ) + if reason: + _warn_auto_fallback(layer.name, reason, stacklevel=2) if ( active_friction_law(friction_law) is not None and isinstance(termination, TerminationSpec) @@ -1467,7 +1503,7 @@ def compute_fatigue( compiled = _use_compiled_counter(rainflow_counter) default_model = friction_model is None if friction_model is None: - friction_model = "direction_tied" + friction_model = DEFAULT_FRICTION_MODEL _check_friction_model(friction_model) _check_distributed_bound(distributed_bound) if copper_contact_model not in COPPER_CONTACT_MODELS: @@ -1636,6 +1672,7 @@ def compute_fatigue( chosen_model[name] = model if reason: fallback_reason[name] = reason + _warn_auto_fallback(name, reason, stacklevel=2) layer_termination = ( termination if termination is None or isinstance(termination, TerminationSpec) diff --git a/src/cablexsec/analysis/sea_state_batch.py b/src/cablexsec/analysis/sea_state_batch.py index 126eec3..fde4b41 100644 --- a/src/cablexsec/analysis/sea_state_batch.py +++ b/src/cablexsec/analysis/sea_state_batch.py @@ -51,8 +51,10 @@ import json import math import os +import pickle import platform import sys +import warnings from collections.abc import Mapping, Sequence from concurrent.futures import ProcessPoolExecutor from dataclasses import asdict, dataclass, field, fields @@ -69,7 +71,11 @@ check_capacity, gumbel_fit, ) -from cablexsec.analysis.fatigue import FatigueResult, FrictionModel +from cablexsec.analysis.fatigue import ( + DEFAULT_FRICTION_MODEL, + FatigueResult, + FrictionModel, +) from cablexsec.analysis.long_term import ( FatigueLoadCase, LongTermFatigueResult, @@ -175,12 +181,18 @@ def __post_init__(self) -> None: @dataclass(frozen=True) class SeaStateBatchOptions: - """Reader and fatigue options shared by every run and section.""" + """Reader and fatigue options shared by every run and section. + + ``friction_model`` ``None`` (default) takes the default armour friction + model of :func:`cablexsec.compute_fatigue`, with its notice on non-planar + paths (:class:`~cablexsec.provenance.DirectionTiedFrictionWarning`); the + manifest and the assessment digests record the model it resolves to. + """ n_fibres: int = 32 mu: float | None = None contact_model: str | None = None - friction_model: FrictionModel = "direction_tied" + friction_model: FrictionModel | None = None frame: Frame = "arc" curvature_source: CurvatureSource = "auto" reference_vector: tuple[float, float, float] = (0.0, 0.0, 1.0) @@ -433,6 +445,33 @@ def _fretting_summary(result: Any) -> dict[str, dict[str, Any]]: return out +def _evaluate_in_worker(task: _Task) -> dict[str, Any]: + """:func:`_evaluate` in a worker process, with its warnings recorded. + + A spawned worker shows warnings on its own standard error, out of the + caller's reach; they travel back with the outcome (``"warnings"``) and the + caller issues them again. + """ + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter("always") + outcome = _evaluate(task) + outcome["warnings"] = [ + _portable_warning(w.category, str(w.message)) for w in caught + ] + return outcome + + +def _portable_warning( + category: type[Warning], message: str +) -> tuple[type[Warning], str]: + """A warning that survives the return from a worker process.""" + try: + pickle.loads(pickle.dumps(category)) + except Exception: # noqa: BLE001 (a category that does not pickle) + return UserWarning, f"{category.__name__}: {message}" + return category, message + + def _evaluate(task: _Task) -> dict[str, Any]: """Read one run and evaluate every section (worker entry point). @@ -861,7 +900,7 @@ def run_sea_state_batch( mp_context=context, initializer=_limit_threads, ) as pool: - outcomes = list(pool.map(_evaluate, tasks)) + outcomes = list(pool.map(_evaluate_in_worker, tasks)) finally: for name, value in saved.items(): if value is None: @@ -869,9 +908,17 @@ def run_sea_state_batch( else: os.environ[name] = value + for outcome in outcomes: + for category, message in outcome.pop("warnings", ()): + warnings.warn(message, category, stacklevel=2) + digest_cable = cable_digest(cable) option_record = asdict(opts) option_record.pop("workers") # does not change results + if option_record["friction_model"] is None: + # The model the default resolves to: the digests of existing + # assessments are unchanged, and follow a change of the default. + option_record["friction_model"] = DEFAULT_FRICTION_MODEL results: dict[str, SectionBatchResult] = {} histories: dict[str, dict[str, CableDynSectionHistory]] = {} for section in sections: diff --git a/src/cablexsec/api.py b/src/cablexsec/api.py index cb7d9fe..6e7cfcb 100644 --- a/src/cablexsec/api.py +++ b/src/cablexsec/api.py @@ -75,6 +75,7 @@ ) from cablexsec.analysis.electrical_life import LifeResult, compute_electrical_life from cablexsec.analysis.fatigue import ( + DEFAULT_FRICTION_MODEL, CopperContactModel, DistributedBound, FatigueLayer, @@ -2189,7 +2190,7 @@ def compute_fatigue( require_finite(ky, "kappa_y") if friction_model is None: # The default law, with a warning on a non-planar path (once per call). - friction_model = "direction_tied" + friction_model = DEFAULT_FRICTION_MODEL # stacklevel 3: this function, its material-scope wrapper, the caller. _warn_default_direction_tied( curvature_path_out_of_plane_ratio(kx, ky), stacklevel=3 diff --git a/src/cablexsec/provenance.py b/src/cablexsec/provenance.py index 1d5cbf1..e650fbf 100644 --- a/src/cablexsec/provenance.py +++ b/src/cablexsec/provenance.py @@ -47,6 +47,7 @@ __all__ = [ "DirectionTiedFrictionWarning", + "FrictionModelFallbackWarning", "ExtrapolationWarning", "MissingClampingStateWarning", "Provenance", @@ -87,6 +88,21 @@ class DirectionTiedFrictionWarning(FutureWarning): """ +class FrictionModelFallbackWarning(UserWarning): + """``friction_model="auto"`` kept the direction-tied law on a non-planar path. + + Emitted by :func:`cablexsec.analysis.fatigue.compute_fatigue` (and so by + :func:`cablexsec.api.compute_fatigue`) and by + :func:`cablexsec.analysis.fatigue.wire_stress_field` once for every layer + that ``"auto"`` would solve with the distributed helix model on a + non-planar curvature path but cannot: a rigid interface (``xi >= 1``), a + stick modulus that changes over the record or a rate-dependent friction + law. That layer keeps the direction-tied cap, whose friction-stress + ranges fall below the distributed ones under rotating curvature; the + provenance limitations record the same reason. + """ + + class UnevaluatedFatigueCurveWarning(UserWarning): """A cable layer declares an S-N or contact-life curve that is not evaluated. diff --git a/tests/test_biaxial_friction_default.py b/tests/test_biaxial_friction_default.py index a0c32e3..c02e5f1 100644 --- a/tests/test_biaxial_friction_default.py +++ b/tests/test_biaxial_friction_default.py @@ -56,7 +56,10 @@ ) from cablexsec.mechanics.friction_law import FrictionLaw from cablexsec.mechanics.papailiou import slip_onset_curvature, wire_slip_history -from cablexsec.provenance import DirectionTiedFrictionWarning +from cablexsec.provenance import ( + DirectionTiedFrictionWarning, + FrictionModelFallbackWarning, +) compiled = pytest.mark.skipif( not HAVE_NUMBA, reason="long friction histories need the compiled kernels" @@ -136,6 +139,34 @@ def test_out_of_plane_ratio(): assert curvature_path_out_of_plane_ratio(np.sin(th), 2e-3 * np.cos(th)) > ( PLANAR_PATH_TOLERANCE ) + # A static bend with cycles normal to its plane is judged against the + # cycles (or 1e-3 of the bend, if smaller), not against the bend: cycles + # of 8e-4 and 8e-3 of the bend give 0.8 and 1. + static = np.full(th.size, 0.05) + cycles = 4e-5 * np.sin(th) + for factor, expected in ((1.0, 0.8), (10.0, 1.0)): + assert curvature_path_out_of_plane_ratio( + static, factor * cycles + ) == pytest.approx(expected, rel=1e-6) + assert curvature_path_out_of_plane_ratio( + -factor * cycles, static + ) == pytest.approx(expected, rel=1e-6) + # Rounded to six significant digits, a static bend in an oblique plane + # stays planar. + oblique = [float(f"{v:.6g}") for v in (0.05 * math.cos(0.4), 0.05 * math.sin(0.4))] + noisy = np.array([1.0, 1.0 + 1e-6, 1.0 - 1e-6]) * 0.05 + rx = np.array([float(f"{v * math.cos(0.4):.6g}") for v in noisy] + oblique[:1]) + ry = np.array([float(f"{v * math.sin(0.4):.6g}") for v in noisy] + oblique[1:]) + assert curvature_path_out_of_plane_ratio(rx, ry) < PLANAR_PATH_TOLERANCE + # The same cycles in the plane of the bend stay planar, in any plane. + for angle in (0.0, 0.4, 2.0): + s = static + cycles + value = curvature_path_out_of_plane_ratio( + s * math.cos(angle), s * math.sin(angle) + ) + assert value < 1e-10 + # A constant curvature keeps one plane. + assert curvature_path_out_of_plane_ratio(np.full(5, 0.01), np.full(5, 0.02)) < 1e-9 # --------------------------------------------------------------------------- # @@ -283,7 +314,9 @@ def _fallback_case(result, explicit, reason): def test_rigid_interface_keeps_direction_tied(inner): rigid = _with_xi(inner, 1.0) kx, ky = _short_rotation(rigid) - result = compute_fatigue([rigid], kx, ky, friction_model="auto") + with pytest.warns(FrictionModelFallbackWarning, match="rigid") as calls: + result = compute_fatigue([rigid], kx, ky, friction_model="auto") + assert len(calls) == 1 and calls[0].filename == __file__ explicit = compute_fatigue([rigid], kx, ky, friction_model="direction_tied") _fallback_case(result, explicit, "rigid") @@ -292,9 +325,15 @@ def test_rate_dependent_law_keeps_direction_tied(inner): kx, ky = _short_rotation(inner) law = FrictionLaw(rate_coefficient=0.05) time = np.linspace(0.0, 10.0, kx.size) - result = compute_fatigue( - [inner], kx, ky, friction_law=law, time_s=time, friction_model="auto" - ) + with pytest.warns(FrictionModelFallbackWarning, match="rate dependent"): + result = compute_fatigue( + [inner], kx, ky, friction_law=law, time_s=time, friction_model="auto" + ) + with pytest.warns(FrictionModelFallbackWarning, match="rate dependent") as calls: + wire_stress_field( + inner, kx, ky, friction_law=law, time_s=time, friction_model="auto" + ) + assert len(calls) == 1 and calls[0].filename == __file__ explicit = compute_fatigue( [inner], kx, ky, friction_law=law, time_s=time, friction_model="direction_tied" ) @@ -304,9 +343,10 @@ def test_rate_dependent_law_keeps_direction_tied(inner): def test_varying_stick_modulus_keeps_direction_tied(inner): kx, ky = _short_rotation(inner) stick = {"inner_armour": inner.spec.k_f * np.linspace(1.0, 0.9, kx.size)} - result = compute_fatigue( - [inner], kx, ky, stick_modulus_Pa=stick, friction_model="auto" - ) + with pytest.warns(FrictionModelFallbackWarning, match="stick modulus changes"): + result = compute_fatigue( + [inner], kx, ky, stick_modulus_Pa=stick, friction_model="auto" + ) explicit = compute_fatigue( [inner], kx, ky, stick_modulus_Pa=stick, friction_model="direction_tied" ) @@ -338,6 +378,40 @@ def test_constant_stick_modulus_is_the_yun_coefficient(inner): _damage_equal(explicit, reference) +@pytest.mark.filterwarnings("error::cablexsec.provenance.FrictionModelFallbackWarning") +def test_no_fallback_warning_on_planar_paths_or_explicit_models(inner): + on = slip_onset_curvature(inner.spec) + kx, _ = _orbit(3.0 * on, 0.0, revolutions=1) + law = FrictionLaw(rate_coefficient=0.05) + time = np.linspace(0.0, 10.0, kx.size) + # Planar: 'auto' is the direction-tied law, no fallback to report. + compute_fatigue( + [inner], kx, 0.0 * kx, friction_law=law, time_s=time, friction_model="auto" + ) + rx, ry = _short_rotation(inner) + t = np.linspace(0.0, 10.0, rx.size) + compute_fatigue( + [inner], rx, ry, friction_law=law, time_s=t, friction_model="direction_tied" + ) + + +@compiled +def test_auto_sees_cycles_normal_to_a_static_bend(inner): + # Cycles at twice the slip onset normal to a static bend 2500 times + # larger: against the largest curvature they are 8e-4 out of plane (below + # the tolerance), against their own range fully out of plane. + on = slip_onset_curvature(inner.spec) + th = np.linspace(0.0, 4.0 * math.pi, 241) + kx = np.full(th.size, 2500.0 * 2.0 * on) + ky = 2.0 * on * np.sin(th) + assert float(np.max(np.abs(ky))) / float(np.max(np.hypot(kx, ky))) < ( + PLANAR_PATH_TOLERANCE + ) + auto = wire_stress_field(inner, kx, ky, friction_model="auto") + helix = wire_stress_field(inner, kx, ky, friction_model="distributed") + assert np.array_equal(auto.mean_Pa, helix.mean_Pa) + + def test_progressive_settings_still_need_progressive(inner): from cablexsec.mechanics.progressive_friction import ProgressiveFriction diff --git a/tests/test_sea_state_batch.py b/tests/test_sea_state_batch.py index e0340b5..ea61cbc 100644 --- a/tests/test_sea_state_batch.py +++ b/tests/test_sea_state_batch.py @@ -8,6 +8,7 @@ import json import math import os +import warnings from dataclasses import replace import numpy as np @@ -165,6 +166,39 @@ def test_worker_count_does_not_change_results(tmp_path, cable, stiffness): assert one.manifest["inputs_sha256"] == two.manifest["inputs_sha256"] +def test_batch_friction_model_follows_the_library_default(tmp_path, cable, stiffness): + # The default is the library's: its notice on a non-planar path reaches + # the caller (from the worker processes too), the results are those of + # the model it resolves to and the manifest records that model. + assert SeaStateBatchOptions().friction_model is None + runs = _runs(tmp_path, stiffness) + sections = [SectionRequest("a", 2.0)] + with warnings.catch_warnings(): + warnings.simplefilter("error", cx.DirectionTiedFrictionWarning) + explicit = run_sea_state_batch( + cable, + runs, + sections, + options=SeaStateBatchOptions(friction_model="direction_tied"), + ) + for workers in (1, 2): + with pytest.warns(cx.DirectionTiedFrictionWarning, match="'auto'"): + default = run_sea_state_batch( + cable, runs, sections, options=SeaStateBatchOptions(workers=workers) + ) + a, b = default.sections["a"].long_term, explicit.sections["a"].long_term + for layer in a.annual_damage_per_fibre: + np.testing.assert_allclose( + a.annual_damage_per_fibre[layer], + b.annual_damage_per_fibre[layer], + rtol=0.0 if workers == 1 else 1e-10, + atol=0.0, + ) + assert default.manifest["options"]["friction_model"] == "direction_tied" + assert default.manifest["inputs_sha256"] == explicit.manifest["inputs_sha256"] + assert a.assessment_id == b.assessment_id + + def test_in_process_batch_leaves_thread_settings_alone( tmp_path, cable, stiffness, monkeypatch ): From d9b8b926a578cd3b10f85afce90024719b7b9e47 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Tue, 17 Nov 2026 22:20:09 +0900 Subject: [PATCH 2/3] fix: the planarity floor covers six-digit rounding near a mantissa of 1 Six significant digits round each curvature component by up to 5e-6 of the value (half a unit in the last digit of a mantissa near 1), not 5e-7, so a nearly constant curvature written that way could read up to 7e-3 out of plane against a floor of 1e-3 and switch "auto" to the distributed model. The floor of the range is now 1e-2 of the largest curvature: such a path is at most 7.1e-4 out of plane (3.2e-4 over a scan of angles and magnitudes), and cycles normal to a static bend count from 1e-5 of it. The test scans the worst rounding case over angles and magnitudes. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 7 ++++--- doc/local_analysis_guide.md | 6 ++++-- src/cablexsec/analysis/fatigue.py | 17 ++++++++++------- tests/test_biaxial_friction_default.py | 19 ++++++++++++++----- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0956067..4ec6048 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -258,9 +258,10 @@ All notable changes to CableXSec are recorded in this file. The format follows static bend hid cycles normal to it: a static 0.05 1/m with ±4e-5 1/m normal cycles was 8e-4 out of plane (planar) and `"auto"` took the direction-tied law, whose cap follows the static bending direction. The distance is now judged against the smaller of the largest curvature and - the largest distance from the mean curvature, the latter floored at 1e-3 of the largest - curvature (so a nearly constant curvature written with six significant digits stays planar): - that path is 0.8 out of plane. Paths without a static offset (every bundled check: planar + the largest distance from the mean curvature, the latter floored at 1e-2 of the largest + curvature (so a nearly constant curvature written with six significant digits, each component + within 5e-6 of the largest, stays planar at 7.1e-4 or less): that path is 0.08 out of plane, + with ±4e-4 1/m cycles 0.8. Paths without a static offset (every bundled check: planar paths, centred ellipses and circles) keep their ratio; a planar path with a static offset in its plane stays planar. Over the 1 203 tests that reach the planarity test and the shipped fatigue examples and tutorials, no path other than the new checks changes its verdict. diff --git a/doc/local_analysis_guide.md b/doc/local_analysis_guide.md index 1f259c4..6ad03c0 100644 --- a/doc/local_analysis_guide.md +++ b/doc/local_analysis_guide.md @@ -1495,13 +1495,15 @@ run uncompiled. (`curvature_path_out_of_plane_ratio`: the largest distance of a sample `(κ_x, κ_y)` from the principal line through the origin, over the smaller of the largest curvature and the largest distance of a sample from the mean - curvature, the latter not below `1e-3` of the largest curvature) is at most + curvature, the latter not below `1e-2` of the largest curvature) is at most `PLANAR_PATH_TOLERANCE = 1e-3`. A planar path in any plane gives round-off, a static offset in that plane included, the same path written with six significant digits less than `1e-5`, an ellipse its axis ratio. The second scale keeps a static bend from hiding cycles normal to it: a static curvature of 0.05 1/m with cycles of 4e-5 1/m normal to it is 8e-4 out of - plane against the largest curvature, but 0.8 against the floor of its range. + plane against the largest curvature, but 0.08 against the floor of its range + (cycles of 4e-4 1/m: 0.8). The floor keeps a nearly constant curvature + written with six significant digits planar (at most 7.1e-4). A layer the distributed law does not cover (rigid interface `ξ ≥ 1`, a stick modulus that changes over the record, a rate-dependent friction law) keeps the direction-tied law and warns (`FrictionModelFallbackWarning`, once diff --git a/src/cablexsec/analysis/fatigue.py b/src/cablexsec/analysis/fatigue.py index 8f27c19..49349e5 100644 --- a/src/cablexsec/analysis/fatigue.py +++ b/src/cablexsec/analysis/fatigue.py @@ -144,10 +144,13 @@ #: which the default direction-tied law warns). PLANAR_PATH_TOLERANCE = 1e-3 #: Smallest range about the mean, relative to the largest curvature, against -#: which :func:`curvature_path_out_of_plane_ratio` judges a path: a static -#: curvature written with six significant digits (error up to 5e-7 of it) -#: stays planar, and cycles normal to a static bend count from 1e-6 of it. -_PATH_SPREAD_FLOOR = 1e-3 +#: which :func:`curvature_path_out_of_plane_ratio` judges a path. Six +#: significant digits put each component within 5e-6 of the largest +#: curvature (half a unit in the last digit of a mantissa near 1), so a +#: rounded static curvature is at most 7.1e-6 off its line and 7.1e-4 out of +#: plane against this floor; cycles normal to a static bend count from 1e-5 +#: of it. +_PATH_SPREAD_FLOOR = 1e-2 #: Measured bias of the direction-tied law under rotating curvature, quoted by #: :class:`~cablexsec.provenance.DirectionTiedFrictionWarning`. DIRECTION_TIED_ROTATION_BIAS = ( @@ -195,10 +198,10 @@ def curvature_path_out_of_plane_ratio( keeps a static bend from hiding the cycles about it: a static curvature with small cycles normal to its plane is as far from planar as the cycles are large, not as small as they are against the static bend. A range - below ``1e-3`` of the largest curvature is judged against that floor, so + below ``1e-2`` of the largest curvature is judged against that floor, so that the rounding of a nearly constant curvature in output files (six - significant digits: at most ``5e-4``) stays planar; cycles normal to a - static bend then count from ``1e-6`` of it. A zero history returns zero. + significant digits: at most ``7.1e-4``) stays planar; cycles normal to a + static bend then count from ``1e-5`` of it. A zero history returns zero. """ kx = np.asarray(kappa_x, dtype=np.float64) ky = np.asarray(kappa_y, dtype=np.float64) diff --git a/tests/test_biaxial_friction_default.py b/tests/test_biaxial_friction_default.py index c02e5f1..387e42f 100644 --- a/tests/test_biaxial_friction_default.py +++ b/tests/test_biaxial_friction_default.py @@ -140,17 +140,17 @@ def test_out_of_plane_ratio(): PLANAR_PATH_TOLERANCE ) # A static bend with cycles normal to its plane is judged against the - # cycles (or 1e-3 of the bend, if smaller), not against the bend: cycles - # of 8e-4 and 8e-3 of the bend give 0.8 and 1. + # cycles (or 1e-2 of the bend, if larger), not against the bend: cycles + # of 8e-4, 8e-3 and 8e-2 of the bend give 0.08, 0.8 and 1. static = np.full(th.size, 0.05) cycles = 4e-5 * np.sin(th) - for factor, expected in ((1.0, 0.8), (10.0, 1.0)): + for factor, expected in ((1.0, 0.08), (10.0, 0.8), (100.0, 1.0)): assert curvature_path_out_of_plane_ratio( static, factor * cycles - ) == pytest.approx(expected, rel=1e-6) + ) == pytest.approx(expected, rel=1e-4) assert curvature_path_out_of_plane_ratio( -factor * cycles, static - ) == pytest.approx(expected, rel=1e-6) + ) == pytest.approx(expected, rel=1e-4) # Rounded to six significant digits, a static bend in an oblique plane # stays planar. oblique = [float(f"{v:.6g}") for v in (0.05 * math.cos(0.4), 0.05 * math.sin(0.4))] @@ -158,6 +158,15 @@ def test_out_of_plane_ratio(): rx = np.array([float(f"{v * math.cos(0.4):.6g}") for v in noisy] + oblique[:1]) ry = np.array([float(f"{v * math.sin(0.4):.6g}") for v in noisy] + oblique[1:]) assert curvature_path_out_of_plane_ratio(rx, ry) < PLANAR_PATH_TOLERANCE + # Six significant digits round a mantissa near 1 by up to 5e-6 of the + # value: the worst case stays planar too, at any angle. + for angle in np.linspace(0.0, math.pi, 181): + for radius in (0.015, 0.0100001, 0.0999999): + noisy = radius * np.array([1.0, 1.000001, 0.999999]) + rx = np.array([float(f"{v * math.cos(angle):.6g}") for v in noisy]) + ry = np.array([float(f"{v * math.sin(angle):.6g}") for v in noisy]) + value = curvature_path_out_of_plane_ratio(rx, ry) + assert value < PLANAR_PATH_TOLERANCE, (angle, radius, value) # The same cycles in the plane of the bend stay planar, in any plane. for angle in (0.0, 0.4, 2.0): s = static + cycles From 576c7735c96f504bd284164b86bac6b0e79f2582 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Tue, 17 Nov 2026 22:20:57 +0900 Subject: [PATCH 3/3] test: the planarity scan includes the reviewed 0.347 rad case Signed-off-by: Jae Hoon Seo --- tests/test_biaxial_friction_default.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_biaxial_friction_default.py b/tests/test_biaxial_friction_default.py index 387e42f..12148cd 100644 --- a/tests/test_biaxial_friction_default.py +++ b/tests/test_biaxial_friction_default.py @@ -160,7 +160,7 @@ def test_out_of_plane_ratio(): assert curvature_path_out_of_plane_ratio(rx, ry) < PLANAR_PATH_TOLERANCE # Six significant digits round a mantissa near 1 by up to 5e-6 of the # value: the worst case stays planar too, at any angle. - for angle in np.linspace(0.0, math.pi, 181): + for angle in (0.347, *np.linspace(0.0, math.pi, 181)): for radius in (0.015, 0.0100001, 0.0999999): noisy = radius * np.array([1.0, 1.000001, 0.999999]) rx = np.array([float(f"{v * math.cos(angle):.6g}") for v in noisy])