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
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,32 @@ 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-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.

- 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
Expand Down
4 changes: 3 additions & 1 deletion doc/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 20 additions & 10 deletions doc/local_analysis_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1486,19 +1486,29 @@ 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-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.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
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
Expand Down
2 changes: 2 additions & 0 deletions src/cablexsec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
from cablexsec.mechanics.thermal_network import ThermalNetwork, thermal_network
from cablexsec.provenance import (
DirectionTiedFrictionWarning,
FrictionModelFallbackWarning,
MissingClampingStateWarning,
UnmodelledPolymerSofteningWarning,
)
Expand Down Expand Up @@ -572,6 +573,7 @@
"ValidatedRange",
"ExtrapolationWarning",
"DirectionTiedFrictionWarning",
"FrictionModelFallbackWarning",
"UnevaluatedFatigueCurveWarning",
"UnvalidatedModelWarning",
"MissingClampingStateWarning",
Expand Down
56 changes: 48 additions & 8 deletions src/cablexsec/analysis/fatigue.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
from cablexsec.mechanics.wire_stress import local_bending_fibre_stress
from cablexsec.provenance import (
DirectionTiedFrictionWarning,
FrictionModelFallbackWarning,
Provenance,
real_array,
)
Expand All @@ -133,11 +134,23 @@

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. 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 = (
Expand All @@ -153,6 +166,7 @@
COPPER_CONTACT_MODELS: tuple[str, ...] = ("slip_cycle", "legacy_gross_sliding")

__all__ = [
"DEFAULT_FRICTION_MODEL",
"PLANAR_PATH_TOLERANCE",
"FatigueLayer",
"FatigueResult",
Expand All @@ -170,16 +184,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-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 ``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)
Expand All @@ -192,8 +214,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))
Comment thread
SMI-Lab-Inha marked this conversation as resolved.
Resolved


def _distributed_spec(
Expand Down Expand Up @@ -246,6 +271,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:
Expand Down Expand Up @@ -1014,13 +1051,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)
Expand Down Expand Up @@ -1467,7 +1506,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:
Expand Down Expand Up @@ -1636,6 +1675,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)
Expand Down
55 changes: 51 additions & 4 deletions src/cablexsec/analysis/sea_state_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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).

Expand Down Expand Up @@ -861,17 +900,25 @@ 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:
os.environ.pop(name, None)
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:
Expand Down
3 changes: 2 additions & 1 deletion src/cablexsec/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/cablexsec/provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

__all__ = [
"DirectionTiedFrictionWarning",
"FrictionModelFallbackWarning",
"ExtrapolationWarning",
"MissingClampingStateWarning",
"Provenance",
Expand Down Expand Up @@ -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.

Expand Down
Loading
Loading