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
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,23 @@ All notable changes to CableXSec are recorded in this file. The format follows
`ValueError`, `IndexError` or `UnicodeDecodeError`; NaN or negative curvature
check tolerances, a non-integer `line_id` and non-numeric section arcs are
refused.
- 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
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
(`provenance.relayed_warnings`).
- The series shear stack of the armour stick coefficient ξ (`xi_for_layer`, Yun et al. 2020)
stops at the layer's support. Walking inward, it adds each concentric cylindrical layer with
a modulus (interstitial fillers still skipped) and stops at the first helical layer inside and
Expand Down
17 changes: 15 additions & 2 deletions src/cablexsec/analysis/beam_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,9 +954,22 @@ 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: 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")


Expand Down
28 changes: 27 additions & 1 deletion src/cablexsec/analysis/fretting_regime.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,36 @@ 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
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:
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.
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 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):
Comment thread
SMI-Lab-Inha marked this conversation as resolved.
Resolved
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
Expand Down
17 changes: 15 additions & 2 deletions src/cablexsec/analysis/kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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",
Expand All @@ -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],
Expand Down
14 changes: 8 additions & 6 deletions src/cablexsec/analysis/rig_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions src/cablexsec/analysis/sheave.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
61 changes: 36 additions & 25 deletions src/cablexsec/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from cablexsec.analysis.capacity import (
BirdcageDetail,
CapacityResult,
_armour_layers,
birdcage_buckling_detail,
compute_capacity,
wire_yield_curvature,
Expand Down Expand Up @@ -971,32 +972,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)",
),
)

core_load_states = (
core_load_history(
Expand Down
23 changes: 22 additions & 1 deletion src/cablexsec/provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -57,6 +58,7 @@
"UnvalidatedModelWarning",
"ValidatedRange",
"check_range",
"relayed_warnings",
"require_finite",
]

Expand Down Expand Up @@ -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.

Expand Down
Loading
Loading