diff --git a/CHANGELOG.md b/CHANGELOG.md index 789db7d..f3324f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,15 @@ All notable changes to CableXSec are recorded in this file. The format follows `relative_permeability`, and the `compute_thermal` / `thermal_network` options `conductor_resistance_20C_ohm_m`, `k_s`, `k_p` and `include_dielectric_loss` (`thermal_network` also `rating_temperature_C` and `rating_current_A`). +- Rig test: `RigProtocol.cyclic(tension_phase_lag_deg=...)` lets the tension lag the + bending (it could cycle only in phase); `RigProtocol.blocks` with `RigBlock` builds a + programme of constant-tension blocks with linear transitions, as in the block programme of + CIGRE TB 862 (2022) 6.3.4.1, and records each block's interval in + `RigProtocol.block_times_s`; `tb862_specimen_checks` and `component_pitches` check the + specimen lengths of TB 862 6.3.2 (fatigue, template and bend-stiffener set-ups), 6.4.2.2 + (bending stiffness) and 6.6.1.2 (compression) against the cable's lay pitches, tape + windings and single-angle strand lays included; a withheld pitch makes the check an + error. ### Changed diff --git a/doc/rig_test_guide.md b/doc/rig_test_guide.md index f2340cd..a7f79eb 100644 --- a/doc/rig_test_guide.md +++ b/doc/rig_test_guide.md @@ -48,8 +48,29 @@ signed curvature at the reference station or the rotation of the clamp at `x = 0`; optionally a uniform specimen temperature. `retain_from_s` selects the samples over which ranges are taken. `RigProtocol.cyclic(...)` builds the usual test: a tension ramp from zero over one period with the specimen -straight, then `n_cycles` sinusoidal bending cycles (optionally with tension -cycling in phase), ranges over the last cycle. +straight, then `n_cycles` sinusoidal bending cycles, ranges over the last +cycle. The tension may cycle with the bending period (`tension_amplitude_N`), +lagging it by `tension_phase_lag_deg` (0 in phase, 90 in quadrature, 180 in +antiphase); the ramp ends at the tension of the first cycle. + +`RigProtocol.blocks([...])` builds a programme of constant-tension blocks, as +in the block programme of a full-scale fatigue test (CIGRE TB 862, 2022, +6.3.4.1): each `RigBlock(tension_N, amplitude, n_cycles, mean)` holds its +tension while the bending cycles about its mean, and the tension and mean +move linearly between blocks (`transition_s`, default one period). +`n_cycles` is the number of cycles simulated for gauge planning, not the +count of the test. Ranges are taken over the last cycle of the last block; +`protocol.block_times_s` gives each block's interval, so the ranges of one +block follow from `dataclasses.replace(protocol, retain_from_s=start)` on the +protocol cut at the block's end. + +```python +programme = cx.RigProtocol.blocks( + [cx.RigBlock(80e3, 0.029, 2), cx.RigBlock(80e3, 0.085, 2), + cx.RigBlock(110e3, 0.207, 2)], + samples_per_cycle=40, +) +``` **Setup** (`RigSetup`): @@ -267,6 +288,32 @@ Practical consequences for a test plan: fittings (set-back and epoxy length). `setback_variants_m` shows how strongly the near-clamp readings depend on it. +### Specimen length (CIGRE TB 862) + +`cx.tb862_specimen_checks(cable, test, ...)` compares the lengths of a test +specimen with the requirements of CIGRE TB 862 (2022), using the pitches of +the cable's helical components (`cx.component_pitches(cable)`: armour +layers, the core lay, resolved strand rings, stranded sub-conductors and tape +windings). A conductor given by one `strand_lay_angle_deg`, without resolved +`strand_layers`, is listed at its outer radius, an upper bound of its strand +pitch at that angle. `P_a` is the pitch of the outer armour wires and `P_max` +the longest pitch of any component. A check is refused, not passed, when the +pitch it needs is unknown: a withheld `core_lay` pitch, a helical layer without +its radius or lay angle, or a stranded conductor without its outer radius +blocks the `P_max` checks, and a withheld armour blocks the `P_a` checks. + +| `test` | Requirement | Clause | Kind | +|---|---|---|---| +| `"fatigue_template"` | fatigue-loaded section `>= P_max`; `>= P_a` from it to each end fitting (with a uniform-profile `setup`: its free length and clamp set-back) | 6.3.2 | recommended | +| `"fatigue_bend_stiffener"` | top end fitting to stiffener flange `>= P_a` | 6.3.2 | shall | +| | stiffener tip to bottom end fitting `>= P_a` | 6.3.2 | recommended | +| `"bending_stiffness"` | sample `>= P_a` | 6.4.2.2 | recommended | +| `"compression_bending"` | sample `>= 2 P_max` | 6.6.1.2 | recommended | +| `"compression"` | sample between end fittings `>= P_max` | 6.6.1.2 | must | + +Each `SpecimenCheck` holds the requirement, the clause, the required and the +actual length, `mandatory` and `passed`. + ## 6. Limits - Clamp model: diff --git a/src/cablexsec/__init__.py b/src/cablexsec/__init__.py index fb3b69f..adc693e 100644 --- a/src/cablexsec/__init__.py +++ b/src/cablexsec/__init__.py @@ -107,10 +107,14 @@ ) from cablexsec.analysis.rig_test import ( GaugeLocation, + RigBlock, RigProtocol, RigSetup, RigTestResult, + SpecimenCheck, + component_pitches, simulate_rig_test, + tb862_specimen_checks, ) from cablexsec.analysis.sea_state_batch import ( CapacityBatchCheck, @@ -479,9 +483,13 @@ # rig-test simulation and gauge planning "simulate_rig_test", "RigProtocol", + "RigBlock", "RigSetup", "GaugeLocation", "RigTestResult", + "SpecimenCheck", + "component_pitches", + "tb862_specimen_checks", # bending-test arrangements (gap T1) "simulate_bending_test", "BendingProtocol", diff --git a/src/cablexsec/analysis/rig_test.py b/src/cablexsec/analysis/rig_test.py index 4f7c512..ee741cf 100644 --- a/src/cablexsec/analysis/rig_test.py +++ b/src/cablexsec/analysis/rig_test.py @@ -103,13 +103,17 @@ "GaugeRecommendation", "GaugeResult", "LayerScales", + "RigBlock", "RigProtocol", "RigSetup", "RigTestResult", + "SpecimenCheck", "StationLoop", + "component_pitches", "default_gauge_grid", "end_rotation_profile", "simulate_rig_test", + "tb862_specimen_checks", ] FloatArray = NDArray[np.float64] @@ -150,6 +154,11 @@ class RigProtocol: temperature (20 deg C). retain_from_s : float Ranges are taken over samples with ``time_s >= retain_from_s``. + block_times_s : tuple of (float, float) + Start and end of the bending cycles of each block of a + :meth:`blocks` programme (empty otherwise); a block's ranges follow + from ``dataclasses.replace(protocol, retain_from_s=start)`` on the + protocol cut at its end. """ time_s: FloatArray @@ -158,6 +167,7 @@ class RigProtocol: end_rotation_rad: FloatArray | None = None temperature_C: FloatArray | None = None retain_from_s: float = 0.0 + block_times_s: tuple[tuple[float, float], ...] = () def __post_init__(self) -> None: t = real_array(self.time_s, "time_s") @@ -187,6 +197,16 @@ def __post_init__(self) -> None: require_finite(self.retain_from_s, "retain_from_s") if self.retain_from_s > t[-1]: raise CableInputError("retain_from_s lies after the last sample") + blocks = tuple((float(a), float(b)) for a, b in self.block_times_s) + previous = float(t[0]) + for start, end in blocks: + if not (previous <= start < end <= t[-1]): + raise CableInputError( + "block_times_s must be ordered, non-overlapping intervals " + "within time_s" + ) + previous = end + object.__setattr__(self, "block_times_s", blocks) @classmethod def cyclic( @@ -201,12 +221,17 @@ def cyclic( n_cycles: int = 3, samples_per_cycle: int = 80, period_s: float = 10.0, + tension_phase_lag_deg: float = 0.0, ) -> RigProtocol: """Tension ramp from zero (one period), then sinusoidal bending. - Tension may cycle in phase with bending (``tension_amplitude_N``). - Ranges are retained over the last cycle. + Tension may cycle with the bending period (``tension_amplitude_N``), + lagging the bending by ``tension_phase_lag_deg`` (0: in phase, 90: in + quadrature, 180: in antiphase): ``T(t) = T + T_a sin(phi - lag)`` with + the bending ``mean + amplitude sin(phi)``. The ramp ends at the + tension of the first cycle. Ranges are retained over the last cycle. """ + require_finite(tension_phase_lag_deg, "tension_phase_lag_deg") if (curvature_amplitude_1_m is None) == (end_rotation_amplitude_rad is None): raise CableInputError( "give one of curvature_amplitude_1_m or end_rotation_amplitude_rad" @@ -233,10 +258,12 @@ def cyclic( bend_ramp = np.zeros(ramp_t.size) bend_ramp[:] = mean * ramp_t / period_s bend = np.concatenate([bend_ramp, mean + amp * np.sin(phase[ramp_t.size :])]) + lag = math.radians(tension_phase_lag_deg) + start_tension = tension_N + tension_amplitude_N * math.sin(-lag) tension = np.concatenate( [ - tension_N * ramp_t / period_s, - tension_N + tension_amplitude_N * np.sin(phase[ramp_t.size :]), + start_tension * ramp_t / period_s, + tension_N + tension_amplitude_N * np.sin(phase[ramp_t.size :] - lag), ] ) temperature = ( @@ -252,6 +279,76 @@ def cyclic( retain_from_s=retain, ) + @classmethod + def blocks( + cls, + blocks: Sequence[RigBlock], + *, + quantity: str = "curvature", + temperature_C: float | None = None, + samples_per_cycle: int = 40, + period_s: float = 10.0, + transition_s: float | None = None, + ) -> RigProtocol: + """Programme of constant-tension blocks of sinusoidal bending. + + Each block holds its tension while the bending cycles about its mean, + as in the blocks of a full-scale fatigue programme (CIGRE TB 862 + (2022), 6.3.4.1). Between blocks, and from zero before the first, the + tension and the mean bending move linearly over ``transition_s`` + (default one period) without cycling. ``RigBlock.n_cycles`` is the + number of cycles simulated for gauge planning, not the count of the + test. ``quantity`` is ``"curvature"`` (amplitudes in 1/m) or + ``"end_rotation"`` (rad). Ranges are retained over the last cycle of + the last block; ``block_times_s`` gives the cycling interval of each + block. + """ + if quantity not in ("curvature", "end_rotation"): + raise CableInputError("quantity must be 'curvature' or 'end_rotation'") + if not blocks: + raise CableInputError("give at least one RigBlock") + if samples_per_cycle < 8 or not (math.isfinite(period_s) and period_s > 0): + raise CableInputError("need samples_per_cycle >= 8 and period_s > 0") + ramp = period_s if transition_s is None else float(transition_s) + if not (math.isfinite(ramp) and ramp > 0): + raise CableInputError("transition_s must be positive") + n_ramp = max(2, samples_per_cycle // 2) + times, tensions, bends = [np.array([0.0])], [np.array([0.0])], [np.array([0.0])] + t_now, tension_now, mean_now = 0.0, 0.0, 0.0 + intervals: list[tuple[float, float]] = [] + for block in blocks: + if not isinstance(block, RigBlock): + raise CableInputError("blocks must be RigBlock instances") + tau = np.linspace(0.0, ramp, n_ramp + 1)[1:] + times.append(t_now + tau) + tensions.append(tension_now + (block.tension_N - tension_now) * tau / ramp) + bends.append(mean_now + (block.mean - mean_now) * tau / ramp) + t_now += ramp + start = t_now + n = block.n_cycles * samples_per_cycle + tau = np.linspace(0.0, block.n_cycles * period_s, n + 1)[1:] + times.append(t_now + tau) + tensions.append(np.full(n, block.tension_N)) + bends.append( + block.mean + block.amplitude * np.sin(2 * math.pi * tau / period_s) + ) + t_now += block.n_cycles * period_s + intervals.append((start, t_now)) + tension_now, mean_now = block.tension_N, block.mean + time = np.concatenate(times) + bend = np.concatenate(bends) + return cls( + time_s=time, + tension_N=np.concatenate(tensions), + curvature_1_m=bend if quantity == "curvature" else None, + end_rotation_rad=bend if quantity == "end_rotation" else None, + temperature_C=( + None if temperature_C is None else np.full(time.size, temperature_C) + ), + retain_from_s=t_now - period_s, + block_times_s=tuple(intervals), + ) + @classmethod def from_curvature_field( cls, @@ -279,6 +376,38 @@ def from_curvature_field( ) +@dataclass(frozen=True) +class RigBlock: + """One block of a rig programme (:meth:`RigProtocol.blocks`). + + Attributes + ---------- + tension_N : float + Constant tension of the block [N] (non-negative). + amplitude : float + Bending amplitude: curvature [1/m] or end rotation [rad]. + n_cycles : int + Cycles simulated (a representative few; not the test count). + mean : float + Mean curvature or end rotation of the block. + """ + + tension_N: float + amplitude: float + n_cycles: int = 1 + mean: float = 0.0 + + def __post_init__(self) -> None: + for name in ("tension_N", "amplitude", "mean"): + require_finite(getattr(self, name), name) + if self.tension_N < 0: + raise CableInputError("RigBlock tension_N must be non-negative") + if isinstance(self.n_cycles, bool) or int(self.n_cycles) != self.n_cycles: + raise CableInputError("RigBlock n_cycles must be an integer") + if self.n_cycles < 1: + raise CableInputError("RigBlock n_cycles must be at least 1") + + @dataclass(frozen=True) class RigSetup: """Specimen and clamp description. @@ -1716,5 +1845,292 @@ def extreme(g: GaugeResult) -> bool: return tuple(out) +# --------------------------------------------------------------------------- # +# Specimen length (CIGRE TB 862) # +# --------------------------------------------------------------------------- # +@dataclass(frozen=True) +class SpecimenCheck: + """One specimen-length requirement of CIGRE TB 862 (2022) and its check. + + ``mandatory`` is ``True`` where the brochure writes "shall" or "must" + and ``False`` where it recommends ("should", "recommended"). + """ + + requirement: str + clause: str + required_m: float + actual_m: float + mandatory: bool + + @property + def passed(self) -> bool: + return self.actual_m >= self.required_m * (1.0 - 1e-12) + + +def component_pitches(cable: CableData) -> dict[str, float]: + """Lay pitch of every helical component of a cable [m], by name. + + Helical layers ``2 pi r / tan(alpha)``, the common core lay + (``core_lay``), resolved conductor strand rings, the strands and + sub-conductors of ``helical_stranded`` layers, and tape windings + (``tape`` of a cylindrical layer, at its mid radius as in + :func:`cablexsec.analysis.tape.tape_geometry`). A conductor given by a + single ``strand_lay_angle_deg`` (no resolved ``strand_layers``) is listed + at its outer radius ``r_outer_m``: its strands lie inside it, so this is + an upper bound of their pitch at the declared angle. Straight components + (lay angle zero, centre wires) have no pitch and are not listed, nor + are components whose radius, angle or pitch is withheld + (:func:`tb862_specimen_checks` refuses those). + """ + pitches: dict[str, float] = {} + + def add(name: str, radius: float | None, angle_deg: float | None) -> None: + if radius and angle_deg: + angle = math.radians(float(angle_deg)) + if 0.0 < angle < math.pi / 2: + pitches[name] = 2.0 * math.pi * float(radius) / math.tan(angle) + + for layer in cable.layers: + if layer.layer_type == "helical": + add(layer.name, getattr(layer, "r_helix_m", None), layer.lay_angle_deg) + elif layer.layer_type == "helical_stranded": + add( + f"{layer.name} (conductors)", + getattr(layer, "r_cable_m", None), + getattr(layer, "lay_angle_cable_deg", None), + ) + add( + f"{layer.name} (strands)", + getattr(layer, "r_strand_m", None), + getattr(layer, "lay_angle_strand_deg", None), + ) + rings = getattr(layer, "strand_layers", ()) or () + for i, ring in enumerate(rings): + if ring.pitch_m: + pitches[f"{layer.name} ring {i}"] = float(ring.pitch_m) + strand_angle = getattr(layer, "strand_lay_angle_deg", None) + if not rings and strand_angle: + add( + f"{layer.name} (strands, at r_outer)", + getattr(layer, "r_outer_m", None), + abs(strand_angle), + ) + tape = getattr(layer, "tape", None) + r_in, r_out = ( + getattr(layer, "r_inner_m", None), + getattr(layer, "r_outer_m", None), + ) + if tape is not None and r_in is not None and r_out is not None: + add(f"{layer.name} (tape)", 0.5 * (r_in + r_out), tape.lay_angle_deg) + if cable.core_lay is not None and cable.core_lay.pitch_m: + pitches["core lay"] = float(cable.core_lay.pitch_m) + return pitches + + +def _withheld_pitches(cable: CableData) -> list[str]: + """Helical components whose pitch is unknown (a withheld radius, angle or pitch).""" + out: list[str] = [] + for layer in cable.layers: + if layer.layer_type == "helical": + if getattr(layer, "r_helix_m", None) is None or layer.lay_angle_deg is None: + out.append(layer.name) + elif layer.layer_type == "helical_stranded": + for part, r_key, a_key in ( + ("conductors", "r_cable_m", "lay_angle_cable_deg"), + ("strands", "r_strand_m", "lay_angle_strand_deg"), + ): + if ( + getattr(layer, r_key, None) is None + or getattr(layer, a_key, None) is None + ): + out.append(f"{layer.name} ({part})") + if getattr(layer, "tape", None) is not None and ( + getattr(layer, "r_inner_m", None) is None + or getattr(layer, "r_outer_m", None) is None + ): + out.append(f"{layer.name} (tape)") + if ( + not getattr(layer, "strand_layers", ()) + and getattr(layer, "strand_lay_angle_deg", None) + and getattr(layer, "r_outer_m", None) is None + ): + out.append(f"{layer.name} (strands)") + if cable.core_lay is not None and cable.core_lay.pitch_m is None: + out.append("core lay") + return out + + +_TB862_TESTS = ( + "fatigue_template", + "fatigue_bend_stiffener", + "bending_stiffness", + "compression_bending", + "compression", +) + + +def tb862_specimen_checks( + cable: CableData, + test: str, + *, + setup: RigSetup | None = None, + loaded_length_m: float | None = None, + end_distance_m: float | None = None, + top_distance_m: float | None = None, + bottom_distance_m: float | None = None, + sample_length_m: float | None = None, +) -> tuple[SpecimenCheck, ...]: + """Specimen lengths of CIGRE TB 862 (2022) against the cable's pitches. + + ``P_a`` is the pitch of the outer armour wires (the outermost + structural helical layer) and ``P_max`` the longest pitch of any + component (:func:`component_pitches`). + + * ``"fatigue_template"`` (6.3.2, tension and template method): the + fatigue-loaded section (``loaded_length_m``) not shorter than + ``P_max``; at least ``P_a`` between it and each end fitting + (``end_distance_m``, recommended). With a ``setup`` of the uniform + profile they default to its free length and clamp set-back. + * ``"fatigue_bend_stiffener"`` (6.3.2): at least ``P_a`` from the top + end fitting to the bend-stiffener flange (``top_distance_m``, "shall") + and from the stiffener tip to the bottom fitting + (``bottom_distance_m``, recommended). + * ``"bending_stiffness"`` (6.4.2.2): a sample of at least ``P_a``. + * ``"compression_bending"`` (6.6.1.2): a sample of at least ``2 P_max``. + * ``"compression"`` (6.6.1.2, pure compression): at least ``P_max`` + between the end fittings ("must"). + """ + if test not in _TB862_TESTS: + raise CableInputError(f"test must be one of {_TB862_TESTS}") + pitches = component_pitches(cable) + withheld = _withheld_pitches(cable) + armour = [layer for layer in cable.helical_layers if layer.structural] + + def longest_pitch() -> tuple[str, float]: + # An unknown pitch may be the longest: no length can be certified. + if withheld: + raise CableInputError( + f"test {test!r} needs the longest pitch of the cable, but the " + f"pitch of {', '.join(withheld)} is withheld (give its radius " + "and lay angle, or the core_lay pitch)" + ) + if not pitches: + raise CableInputError("the cable has no helical component with a pitch") + name = max(pitches, key=lambda k: pitches[k]) + return name, pitches[name] + + def outer_armour_pitch() -> tuple[str, float]: + unknown = [layer.name for layer in armour if layer.name in withheld] + if unknown: + raise CableInputError( + f"test {test!r} needs the pitch of the outer armour wires, but " + f"the radius or lay angle of {', '.join(unknown)} is withheld" + ) + if not armour: + raise CableInputError( + "this TB 862 check needs the pitch of the outer armour wires; " + "the cable has no structural helical layer" + ) + outer = max(armour, key=lambda layer: float(layer.r_helix_m or 0.0)) + if outer.name not in pitches: + raise CableInputError( + f"the outer armour {outer.name!r} has no lay angle, so no pitch " + "for this TB 862 check" + ) + return outer.name, pitches[outer.name] + + def need(value: float | None, name: str) -> float: + if value is None: + raise CableInputError(f"test {test!r} needs {name}") + require_finite(value, name) + if value < 0: + raise CableInputError(f"{name} must be non-negative") + return float(value) + + checks: list[SpecimenCheck] = [] + if test == "fatigue_template": + if setup is not None and setup.profile == "uniform": + loaded_length_m = ( + setup.free_length_m if loaded_length_m is None else loaded_length_m + ) + end_distance_m = ( + setup.clamp_setback_m if end_distance_m is None else end_distance_m + ) + p_max_name, p_max = longest_pitch() + name_a, p_a = outer_armour_pitch() + checks.append( + SpecimenCheck( + f"fatigue-loaded section >= longest pitch ({p_max_name})", + "6.3.2", + p_max, + need(loaded_length_m, "loaded_length_m"), + False, + ) + ) + checks.append( + SpecimenCheck( + f"loaded section to each end fitting >= outer armour pitch ({name_a})", + "6.3.2", + p_a, + need(end_distance_m, "end_distance_m"), + False, + ) + ) + elif test == "fatigue_bend_stiffener": + name_a, p_a = outer_armour_pitch() + checks.append( + SpecimenCheck( + f"top end fitting to stiffener flange >= outer armour pitch ({name_a})", + "6.3.2", + p_a, + need(top_distance_m, "top_distance_m"), + True, + ) + ) + checks.append( + SpecimenCheck( + f"stiffener tip to bottom end fitting >= outer armour pitch ({name_a})", + "6.3.2", + p_a, + need(bottom_distance_m, "bottom_distance_m"), + False, + ) + ) + elif test == "bending_stiffness": + name_a, p_a = outer_armour_pitch() + checks.append( + SpecimenCheck( + f"sample >= outer armour pitch ({name_a})", + "6.4.2.2", + p_a, + need(sample_length_m, "sample_length_m"), + False, + ) + ) + elif test == "compression_bending": + p_max_name, p_max = longest_pitch() + checks.append( + SpecimenCheck( + f"sample >= twice the longest pitch ({p_max_name})", + "6.6.1.2", + 2.0 * p_max, + need(sample_length_m, "sample_length_m"), + False, + ) + ) + else: + p_max_name, p_max = longest_pitch() + checks.append( + SpecimenCheck( + f"sample between end fittings >= longest pitch ({p_max_name})", + "6.6.1.2", + p_max, + need(sample_length_m, "sample_length_m"), + True, + ) + ) + return tuple(checks) + + # Public entry points read the cable's own materials when called directly. _scope_entry_points(globals(), __all__) diff --git a/tests/test_rig_tb862.py b/tests/test_rig_tb862.py new file mode 100644 index 0000000..d4c640c --- /dev/null +++ b/tests/test_rig_tb862.py @@ -0,0 +1,283 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +"""Rig protocols with a tension phase lag and constant-tension blocks; TB 862 lengths.""" + +from __future__ import annotations + +import dataclasses +import math +import warnings + +import numpy as np +import pytest +import yaml + +import cablexsec as cx +from cablexsec.analysis.rig_test import ( + GaugeLocation, + RigBlock, + RigProtocol, + RigSetup, + component_pitches, + simulate_rig_test, + tb862_specimen_checks, +) +from cablexsec.exceptions import CableInputError + +pytestmark = pytest.mark.analytical_sanity + + +@pytest.fixture(scope="module") +def menard(): + return cx.load_cable(cx.menard2023_yaml_path(), geometry_override=None) + + +@pytest.fixture(scope="module") +def t66(): + return cx.load_cable(cx.iea_task49_66kv_yaml_path(), geometry_override=None) + + +def test_tension_lags_the_bending_by_the_given_phase() -> None: + base = dict( # noqa: C408 + tension_N=5e4, + curvature_amplitude_1_m=0.05, + tension_amplitude_N=1e4, + n_cycles=2, + samples_per_cycle=40, + ) + in_phase = RigProtocol.cyclic(**base) + default = RigProtocol.cyclic(**base, tension_phase_lag_deg=0.0) + assert np.array_equal(in_phase.tension_N, default.tension_N) + lagged = RigProtocol.cyclic(**base, tension_phase_lag_deg=90.0) + assert np.array_equal(lagged.time_s, in_phase.time_s) + assert np.array_equal(lagged.curvature_1_m, in_phase.curvature_1_m) + cyc = lagged.time_s > 10.0 + phase = 2.0 * math.pi * (lagged.time_s[cyc] - 10.0) / 10.0 + assert lagged.tension_N[cyc] == pytest.approx(5e4 - 1e4 * np.cos(phase), abs=1e-6) + # At the bending peak the tension is at its mean (quadrature). + peak = int(np.argmax(lagged.curvature_1_m)) + assert lagged.tension_N[peak] == pytest.approx(5e4, abs=1e-6) + # The ramp ends at the tension of the first cycle (no jump). + n_ramp = int(np.sum(lagged.time_s <= 10.0)) + assert lagged.tension_N[n_ramp - 1] == pytest.approx(5e4 - 1e4, abs=1e-6) + antiphase = RigProtocol.cyclic(**base, tension_phase_lag_deg=180.0) + assert antiphase.tension_N[cyc] == pytest.approx( + 5e4 - 1e4 * np.sin(phase), abs=1e-6 + ) + with pytest.raises(ValueError): + RigProtocol.cyclic(**base, tension_phase_lag_deg=math.nan) + + +def test_constant_tension_blocks_hold_their_tension() -> None: + blocks = [RigBlock(80e3, 0.029, 2), RigBlock(110e3, 0.085, 1, mean=0.01)] + p = RigProtocol.blocks(blocks, samples_per_cycle=20, period_s=10.0) + assert len(p.block_times_s) == 2 + (s1, e1), (s2, e2) = p.block_times_s + assert (s1, e1) == pytest.approx((10.0, 30.0)) + assert (s2, e2) == pytest.approx((40.0, 50.0)) + for (start, end), block in zip(p.block_times_s, blocks, strict=True): + inside = (p.time_s > start) & (p.time_s <= end) + assert np.all(p.tension_N[inside] == block.tension_N) + bend = p.curvature_1_m[inside] + assert bend.max() == pytest.approx(block.mean + block.amplitude, rel=1e-12) + assert bend.min() == pytest.approx(block.mean - block.amplitude, rel=1e-12) + # Linear transitions between the blocks, from zero before the first. + between = (p.time_s > e1) & (p.time_s < s2) + tau = (p.time_s[between] - e1) / 10.0 + assert p.tension_N[between] == pytest.approx(80e3 + 30e3 * tau, rel=1e-12) + assert p.curvature_1_m[between] == pytest.approx(0.01 * tau, abs=1e-15) + assert p.tension_N[0] == 0.0 and p.curvature_1_m[0] == 0.0 + # Ranges over the last cycle of the last block. + assert p.retain_from_s == pytest.approx(e2 - 10.0) + rotation = RigProtocol.blocks(blocks, quantity="end_rotation") + assert rotation.curvature_1_m is None and rotation.end_rotation_rad is not None + + +@pytest.mark.parametrize( + ("kwargs", "match"), + [ + ({"blocks": []}, "at least one"), + ({"blocks": [RigBlock(1e4, 0.01)], "quantity": "strain"}, "quantity"), + ({"blocks": [RigBlock(1e4, 0.01)], "transition_s": 0.0}, "transition"), + ({"blocks": [(1e4, 0.01, 1)]}, "RigBlock instances"), + ], +) +def test_block_programme_inputs_are_checked(kwargs, match) -> None: + with pytest.raises(CableInputError, match=match): + RigProtocol.blocks(**kwargs) + + +@pytest.mark.parametrize( + ("kwargs", "match"), + [ + ({"tension_N": -1.0, "amplitude": 0.01}, "non-negative"), + ({"tension_N": 1.0, "amplitude": 0.01, "n_cycles": 0}, "at least 1"), + ({"tension_N": 1.0, "amplitude": 0.01, "n_cycles": 1.5}, "integer"), + ({"tension_N": 1.0, "amplitude": math.inf}, "finite"), + ], +) +def test_rig_block_inputs_are_checked(kwargs, match) -> None: + with pytest.raises(ValueError, match=match): + RigBlock(**kwargs) + + +def test_block_times_must_lie_in_the_record() -> None: + p = RigProtocol.blocks([RigBlock(1e4, 0.01)]) + with pytest.raises(CableInputError, match="block_times_s"): + dataclasses.replace(p, block_times_s=((0.0, 1.0e6),)) + + +def test_block_programme_runs_through_the_rig_simulation(menard) -> None: + p = RigProtocol.blocks( + [RigBlock(4e4, 0.02), RigBlock(6e4, 0.03)], samples_per_cycle=16 + ) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + result = simulate_rig_test( + menard, + p, + RigSetup(free_length_m=1.5, clamp="none"), + gauges=[GaugeLocation("outer_armour", 90.0, 0.02)], + mu_factors=(), + ) + assert result.gauges[0].ranges["total"] > 0.0 + + +def test_component_pitches_of_the_66kv_template(t66) -> None: + pitches = component_pitches(t66) + outer = t66.get_layer("outer_armour") + expected = 2.0 * math.pi * outer.r_helix_m / math.tan(math.radians(10.0)) + assert pitches["outer_armour"] == pytest.approx(expected, rel=1e-12) + assert pitches["core lay"] == pytest.approx(1.4542, rel=1e-12) + assert set(pitches) >= {"inner_armour", "outer_armour", "core lay"} + + +def test_tb862_specimen_lengths(t66) -> None: + pitches = component_pitches(t66) + p_a = pitches["outer_armour"] + p_max = max(pitches.values()) + setup = RigSetup(free_length_m=p_max + 0.1, clamp_setback_m=p_a - 0.01) + loaded, ends = tb862_specimen_checks(t66, "fatigue_template", setup=setup) + assert loaded.clause == ends.clause == "6.3.2" + assert loaded.required_m == pytest.approx(p_max) and loaded.passed + assert ends.required_m == pytest.approx(p_a) and not ends.passed + assert not loaded.mandatory and not ends.mandatory + top, bottom = tb862_specimen_checks( + t66, "fatigue_bend_stiffener", top_distance_m=p_a, bottom_distance_m=0.5 * p_a + ) + assert top.mandatory and top.passed and not bottom.passed + (stiff,) = tb862_specimen_checks(t66, "bending_stiffness", sample_length_m=p_a) + assert stiff.clause == "6.4.2.2" and stiff.passed + (comp_bend,) = tb862_specimen_checks( + t66, "compression_bending", sample_length_m=1.9 * p_max + ) + assert comp_bend.required_m == pytest.approx(2.0 * p_max) and not comp_bend.passed + (comp,) = tb862_specimen_checks(t66, "compression", sample_length_m=p_max) + assert comp.clause == "6.6.1.2" and comp.mandatory and comp.passed + + +@pytest.mark.parametrize( + ("test", "kwargs", "match"), + [ + ("fatigue", {}, "test must be one of"), + ("fatigue_template", {}, "loaded_length_m"), + ("fatigue_bend_stiffener", {"top_distance_m": 1.0}, "bottom_distance_m"), + ("compression", {"sample_length_m": -1.0}, "non-negative"), + ], +) +def test_tb862_inputs_are_checked(t66, test, kwargs, match) -> None: + with pytest.raises(CableInputError, match=match): + tb862_specimen_checks(t66, test, **kwargs) + + +def _variant(tmp_path, source, edit): + data = yaml.safe_load(source.read_text(encoding="utf-8")) + edit(data) + target = tmp_path / "variant.yaml" + target.write_text(yaml.safe_dump(data, sort_keys=False), encoding="utf-8") + return cx.load_cable(target, geometry_override=None) + + +def _layer(data, name): + return next(x for x in data["layers"] if x["name"] == name) + + +def test_tape_windings_have_a_pitch(tmp_path) -> None: + # 2026-11-28 (PR #67 review): tape windings were left out of P_max. + source = cx.thies2016_yaml_path() + thies = cx.load_cable(source, geometry_override=None) + tape = thies.get_layer("cu_tape") + radius = 0.5 * (tape.r_inner_m + tape.r_outer_m) + expected = 2.0 * math.pi * radius / math.tan(math.radians(tape.tape.lay_angle_deg)) + assert component_pitches(thies)["cu_tape (tape)"] == pytest.approx(expected) + + # A tape laid at 1 deg has the longest pitch and governs the compression length. + def flat_tape(data): + _layer(data, "cu_tape")["tape"]["lay_angle_deg"] = 1.0 + + long_tape = _variant(tmp_path, source, flat_tape) + p_tape = component_pitches(long_tape)["cu_tape (tape)"] + assert p_tape > max( + v for k, v in component_pitches(long_tape).items() if k != "cu_tape (tape)" + ) + (comp,) = tb862_specimen_checks( + long_tape, "compression", sample_length_m=0.9 * p_tape + ) + assert "cu_tape (tape)" in comp.requirement + assert comp.required_m == pytest.approx(p_tape) + assert not comp.passed + + +def test_aggregate_strand_lay_has_a_pitch() -> None: + # 2026-11-28 (PR #67 review): a conductor given by one strand lay angle, + # without resolved strand_layers, was left out of P_max. + cable = cx.load_cable(cx.iea_task49_66kv_yaml_path(), geometry_override=None) + conductor = cable.get_layer("cu_conductor") + name = "cu_conductor (strands, at r_outer)" + assert not any(k.startswith("cu_conductor") for k in component_pitches(cable)) + + for angle in (1.0, -1.0): # the sign of the aggregate angle is no handedness + lay = conductor.model_copy(update={"strand_lay_angle_deg": angle}) + layers = tuple(lay if x.name == "cu_conductor" else x for x in cable.layers) + stranded = cable.model_copy(update={"layers": layers}) + pitches = component_pitches(stranded) + expected = 2.0 * math.pi * conductor.r_outer_m / math.tan(math.radians(1.0)) + assert pitches[name] == pytest.approx(expected) + assert pitches[name] == max(pitches.values()) + (comp,) = tb862_specimen_checks( + stranded, "compression", sample_length_m=0.9 * expected + ) + assert name in comp.requirement + assert not comp.passed + + # Without its outer radius the strand pitch is unknown: refused. + lay = conductor.model_copy(update={"strand_lay_angle_deg": 12.0, "r_outer_m": None}) + layers = tuple(lay if x.name == "cu_conductor" else x for x in cable.layers) + withheld = cable.model_copy(update={"layers": layers}) + with pytest.raises(CableInputError, match=r"cu_conductor \(strands\) is withheld"): + tb862_specimen_checks(withheld, "compression", sample_length_m=100.0) + + +def test_withheld_pitches_are_refused(tmp_path) -> None: + # 2026-11-28 (PR #67 review): a withheld core lay or armour pitch was + # skipped, so P_max or P_a could be too short and a check pass. + source = cx.iea_task49_66kv_yaml_path() + + def no_core_pitch(data): + data["core_lay"].pop("pitch_m") + + cable = _variant(tmp_path, source, no_core_pitch) + assert "core lay" not in component_pitches(cable) + for test in ("compression", "compression_bending"): + with pytest.raises(CableInputError, match="core lay is withheld"): + tb862_specimen_checks(cable, test, sample_length_m=100.0) + # The outer armour pitch is still known: the P_a checks run. + (stiff,) = tb862_specimen_checks(cable, "bending_stiffness", sample_length_m=100.0) + assert stiff.passed + + def no_armour_angle(data): + _layer(data, "outer_armour").pop("lay_angle_deg") + + cable = _variant(tmp_path, source, no_armour_angle) + with pytest.raises(CableInputError, match="outer_armour is withheld"): + tb862_specimen_checks(cable, "bending_stiffness", sample_length_m=100.0) diff --git a/validation/validation_report.md b/validation/validation_report.md index a1068db..52c63f9 100644 --- a/validation/validation_report.md +++ b/validation/validation_report.md @@ -84,7 +84,7 @@ Every row is computed from published data or closed-form references in this repo ## Test taxonomy (full gate suite) -- analytical_sanity: `1326 passed` +- analytical_sanity: `1347 passed` - independent_method: `93 passed` - full_scale: `62 passed`