From 9bace1dd278e3be9cae9a3e66da75c0dbc964abb Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Mon, 30 Nov 2026 19:13:16 +0900 Subject: [PATCH] feat: TB 862 block programme of a full-scale fatigue test BlockProgramme and FatigueTestBlock hold the blocks of a full-scale fatigue test (CIGRE TB 862 6.3.4): cycles, constant tension, curvature range and damage per cycle from the service fatigue calculation. The programme gives block and accumulated damage and damage shares, checks the Table 6-4 requirements it can check by itself (test damage and block tension against the service values), builds the test sequence with the switching of 6.3.4.3 and converts the blocks to RigBlocks. The sequence cuts each block into ceil(1/max_fraction) parts and orders them so that no two parts of one block follow each other (the next part of the block with the most parts left, other than the block just run; with equal part counts this is the 1A..8A, 1B..8B rounds of Table D.3). A programme whose largest block cannot be separated by the others (one block alone, or three parts against a single other part) raises CableInputError, since no sequence meets 6.3.4.3. TB 862 Tables D.1 to D.3 are regression cases. Table D.3 prints 6.05e-4 for blocks 3A and 3B; 61 116 cycles at 9.90e-10 give 6.05e-5, which its total uses. Its Appendix D.3 gives a service mean tension of 82 kN but runs the Table D.2 blocks at 80 kN, so the strict tension check fails on its own example (recorded in a test). Docs: ThermalResult.resistances, the CHANGELOG and the local analysis guide still described the T2/T3 split at the innermost armour; since #69 each annulus is split by its armour-loss share k/m. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 11 +- doc/local_analysis_guide.md | 4 +- doc/rig_test_guide.md | 48 ++++ src/cablexsec/__init__.py | 8 + src/cablexsec/analysis/block_programme.py | 310 ++++++++++++++++++++++ src/cablexsec/mechanics/thermal.py | 11 +- tests/test_block_programme.py | 189 +++++++++++++ validation/validation_report.md | 2 +- 8 files changed, 575 insertions(+), 8 deletions(-) create mode 100644 src/cablexsec/analysis/block_programme.py create mode 100644 tests/test_block_programme.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 7742661..8c9ae3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,8 +11,10 @@ All notable changes to CableXSec are recorded in this file. The format follows ### Added - `ThermalResult.resistances`: the `T1`, `T2`, `T3` and `T4` of IEC 60287-1-1 Formula (1) that - `compute_thermal` used, split at the innermost armour (`T2` counts a per-core jacket `1/n`, as - CIGRE TB 880 Guidance Point 45 does). + `compute_thermal` used (`T2` counts a per-core jacket `1/n`, as CIGRE TB 880 Guidance Point 45 + does). An annulus outside `k` of `m` armour layers goes `(1 - k/m)` to `T2` and `k/m` to `T3`, + its share of the armour loss, so Formula (1) reproduces the solver for any number of armour + layers (with one layer, the split at the armour). - Rows TB880-C2 and TB880-C8 (registered before the first run): CIGRE TB 880 (2022) Case studies 2 (3x630 mm2 18/30 kV, lead sheaths, steel wire armour) and 8 (3x1000 mm2 220 kV, lead sheaths, stainless armour) against `compute_thermal`, from cables built on the brochure's datasheets @@ -20,6 +22,11 @@ All notable changes to CableXSec are recorded in this file. The format follows `W_d` by +0.136 % (TB 880's `eps0 = 1e-9/(36 pi)` against IEC's 8.854e-12); `T2` (-5.1 %, +0.43 %) and the ratings at 90 degC with TB 880's loss factors (841.50 A against 838.34 A, 1134.95 A against 1134.82 A) are stated. +- `BlockProgramme` and `FatigueTestBlock`: the block programme of a full-scale fatigue test (CIGRE + TB 862 6.3.4): block and accumulated damage, damage shares, the Table 6-4 checks of test damage + and mean tension against the service values, the test sequence with switching of 6.3.4.3 + (Table D.3) and conversion to `RigBlock`s. TB 862 Tables D.1 to D.3 are regression cases; Table + D.3's damage of blocks 3A and 3B is 6.05e-5, not the printed 6.05e-4. - Reported rows SV11-LK, SV11-SIDE, SV11-SUB and SV11-NORM (registered before the runs): what the SV11 measurements are. Lukassen's (2019) thesis plots both narrow sides of the tendon at stations 3.1-3.5 for LC 14 (digitised from the native PDF paths, diff --git a/doc/local_analysis_guide.md b/doc/local_analysis_guide.md index 676375f..69e43b7 100644 --- a/doc/local_analysis_guide.md +++ b/doc/local_analysis_guide.md @@ -1309,7 +1309,9 @@ as CIGRE TB 880 does; a metal tape over the wires is left out (TB 880 Guidance Point 29). A single-core cable gets no proximity or sheath loss (they depend on the circuit): pass `y_p` and `lambda1`. `result.losses` holds the values used, `result.resistances` the `T1` to `T4` of IEC 60287-1-1 Formula (1) -(split at the innermost armour), and the provenance their basis. The ladder is the +(each annulus outside the sheath split between `T2` and `T3` by its share of the +armour loss; with one armour layer, the split at the armour), and the provenance +their basis. The ladder is the IEC single-core-equivalent model, which can read a three-core cable's conductor temperature up to 8 °C low (Chatzipetros and Pilgrim 2018; Section 2). The section state applies each layer's free thermal strain and the registered diff --git a/doc/rig_test_guide.md b/doc/rig_test_guide.md index a7f79eb..3c7a5fc 100644 --- a/doc/rig_test_guide.md +++ b/doc/rig_test_guide.md @@ -314,6 +314,54 @@ blocks the `P_max` checks, and a withheld armour blocks the `P_a` checks. Each `SpecimenCheck` holds the requirement, the clause, the required and the actual length, `mandatory` and `passed`. +### Block programme of the test (CIGRE TB 862) + +`cx.BlockProgramme` holds the blocks of a full-scale fatigue test (TB 862 +6.3.4): each `cx.FatigueTestBlock(n_cycles, tension_N, curvature_range_1_m, +damage_per_cycle, label)` gives its test cycles, constant tension, curvature +range and the damage of one cycle from the same fatigue calculation as the +service analysis (TB 862 6.3.4.1). + +```python +blocks = [ + cx.FatigueTestBlock(973_459, 80e3, 0.029, 4.58e-12, label="1"), + cx.FatigueTestBlock(122_231, 80e3, 0.085, 9.90e-10, label="3"), + cx.FatigueTestBlock(61, 110e3, 0.341, 1.11e-6, label="8"), +] +programme = cx.BlockProgramme(tuple(blocks)) +programme.total_damage, programme.damage_shares +programme.check(2.85e-4, service_mean_tension_N=10e3) # Table 6-4 +sequence = programme.test_sequence() # 6.3.4.3: 1A, 3A, 8A, 1B, 3B, 8B +rig = cx.RigProtocol.blocks(programme.to_rig_blocks(simulated_cycles=2)) +``` + +- `check(service_damage, service_mean_tension_N=...)` returns the + requirements of TB 862 Table 6-4 that the programme can check by itself: + accumulated test damage at least the service damage (a safety factor is a + matter of agreement; include it in `service_damage`), and every block's + tension at least the service mean tension. Compare `damage_shares` with + the service damage distribution for the third requirement. +- `test_sequence()` applies the switching of TB 862 6.3.4.3: a block with more + than 1 % of all cycles is not run in one row, and at most half of a block's + cycles is applied before switching. Each block is cut into + `ceil(1/max_fraction)` parts, ordered so that no two parts of one block + follow each other (with equal part counts: the rounds of TB 862 Table D.3). + A programme whose largest block cannot be separated by the others (one + block alone, or three parts against one other part) raises an error, since + no sequence meets 6.3.4.3. + `rounding="exact"` (default) keeps the cycles of every block, so a part of + an odd block can be one cycle over half; `rounding="up"` gives every part + `ceil(n/parts)` cycles, as Table D.3 does. +- `to_rig_blocks()` gives `RigBlock`s of amplitude `range/2` for the rig + simulation above. + +TB 862 Tables D.1 to D.3 are the regression cases +(`tests/test_block_programme.py`). Table D.3 prints 6.05e-4 for the damage of +blocks 3A and 3B; 61 116 cycles at 9.90e-10 give 6.05e-5, which its total +4.68e-4 uses. Its Appendix D.3 states a service mean tension of 82 kN at the +bend stiffener but runs the blocks of Table D.2 at 80 kN, so the strict +tension check does not pass on its own example. + ## 6. Limits - Clamp model: diff --git a/src/cablexsec/__init__.py b/src/cablexsec/__init__.py index 1a58aaf..0f127f2 100644 --- a/src/cablexsec/__init__.py +++ b/src/cablexsec/__init__.py @@ -56,6 +56,11 @@ SlipScaleTable, export_bending_law, ) +from cablexsec.analysis.block_programme import ( + BlockProgramme, + FatigueTestBlock, + ProgrammeCheck, +) from cablexsec.analysis.capacity_check import ( ISO_13628_5_UTILISATION_FACTORS, CapacityCheckResult, @@ -490,6 +495,9 @@ "SpecimenCheck", "component_pitches", "tb862_specimen_checks", + "BlockProgramme", + "FatigueTestBlock", + "ProgrammeCheck", # bending-test arrangements (gap T1) "simulate_bending_test", "BendingProtocol", diff --git a/src/cablexsec/analysis/block_programme.py b/src/cablexsec/analysis/block_programme.py new file mode 100644 index 0000000..a2fa7a7 --- /dev/null +++ b/src/cablexsec/analysis/block_programme.py @@ -0,0 +1,310 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +r"""Block programmes of full-scale fatigue tests (CIGRE TB 862 (2022) 6.3.4). + +A full-scale fatigue test of a dynamic cable runs a few blocks of constant +tension and constant curvature range, with far fewer cycles than in service but +an accumulated damage at least the service damage and a similar distribution of +damage between small and large cycles (TB 862 6.3.4.1). This module holds the +bookkeeping of such a programme: + +* :class:`FatigueTestBlock`: cycles, tension, curvature range and the damage + per cycle of one block. The damage per cycle comes from the same fatigue + calculation as the service analysis (TB 862 6.3.4.1), for instance a + CableXSec stress and S-N chain at the block's tension and curvature range. +* :class:`BlockProgramme`: totals, the damage share of each block, the + requirements of TB 862 Table 6-4 that a programme can check by itself + (accumulated damage and mean tension against the service values), and the + test sequence of TB 862 6.3.4.3: a block holding more than 1 % of all cycles + is not run in one row and at most half of a block's cycles are applied before + switching to another block (TB 862 Appendix D.4). + +TB 862 Appendix D Tables D.1 to D.3 are reproduced in the tests; Table D.3 +prints 6.05e-4 for the damage of blocks 3A and 3B, where 61 116 cycles at +9.90e-10 give 6.05e-5 (its total, 4.68e-4, uses 6.05e-5). +""" + +from __future__ import annotations + +import math +from dataclasses import dataclass +from typing import Literal + +from cablexsec.analysis.rig_test import RigBlock +from cablexsec.exceptions import CableInputError +from cablexsec.provenance import require_finite + +__all__ = ["BlockProgramme", "FatigueTestBlock", "ProgrammeCheck"] + + +@dataclass(frozen=True) +class FatigueTestBlock: + """One block of a full-scale fatigue test (TB 862 Tables 6-1, 6-2, D.1). + + Attributes + ---------- + n_cycles : int + Test cycles of the block (at least 1). + tension_N : float + Constant tension of the block [N] (TB 862 6.3.4.1). + curvature_range_1_m : float + Curvature range of the cycles [1/m] (maximum minus minimum). + damage_per_cycle : float + Fatigue damage of one cycle at this tension and curvature range, from + the fatigue calculation of the service analysis. + label : str + Name of the block in tables and sequences (``"1"``, ``"3A"``). + """ + + n_cycles: int + tension_N: float + curvature_range_1_m: float + damage_per_cycle: float + label: str = "" + + def __post_init__(self) -> None: + if isinstance(self.n_cycles, bool) or int(self.n_cycles) != self.n_cycles: + raise CableInputError("FatigueTestBlock n_cycles must be an integer") + if self.n_cycles < 1: + raise CableInputError("FatigueTestBlock n_cycles must be at least 1") + object.__setattr__(self, "n_cycles", int(self.n_cycles)) + for name in ("tension_N", "curvature_range_1_m", "damage_per_cycle"): + require_finite(getattr(self, name), name) + if getattr(self, name) < 0.0: + raise CableInputError(f"FatigueTestBlock {name} must be non-negative") + + @property + def damage(self) -> float: + """Damage of the block, ``n_cycles * damage_per_cycle``.""" + return self.n_cycles * self.damage_per_cycle + + +@dataclass(frozen=True) +class ProgrammeCheck: + """One requirement of TB 862 Table 6-4 checked on a block programme. + + ``required`` and ``given`` are in the unit of the requirement (damage or + N); ``passed`` is ``given >= required``. + """ + + requirement: str + clause: str + required: float + given: float + + @property + def passed(self) -> bool: + return self.given >= self.required + + +@dataclass(frozen=True) +class BlockProgramme: + """The blocks of a full-scale fatigue test, in programme order. + + Attributes + ---------- + blocks : tuple of FatigueTestBlock + The blocks (at least one). + """ + + blocks: tuple[FatigueTestBlock, ...] + + def __post_init__(self) -> None: + if not self.blocks: + raise CableInputError("a block programme needs at least one block") + if not all(isinstance(b, FatigueTestBlock) for b in self.blocks): + raise CableInputError("BlockProgramme blocks must be FatigueTestBlock") + object.__setattr__(self, "blocks", tuple(self.blocks)) + + @property + def total_cycles(self) -> int: + """Cycles of all blocks.""" + return sum(b.n_cycles for b in self.blocks) + + @property + def total_damage(self) -> float: + """Accumulated damage of all blocks (Miner sum).""" + return math.fsum(b.damage for b in self.blocks) + + @property + def damage_shares(self) -> tuple[float, ...]: + """Share of each block in the total damage (TB 862 Fig. D.12).""" + total = self.total_damage + if total == 0.0: + raise CableInputError("the programme has no damage") + return tuple(b.damage / total for b in self.blocks) + + @property + def accumulated_damage(self) -> tuple[float, ...]: + """Damage accumulated after each block (TB 862 Tables 6-1 and 6-2).""" + out: list[float] = [] + running = 0.0 + for b in self.blocks: + running += b.damage + out.append(running) + return tuple(out) + + def check( + self, + service_damage: float, + *, + service_mean_tension_N: float | None = None, + ) -> tuple[ProgrammeCheck, ...]: + """Requirements of TB 862 Table 6-4 that the programme can check. + + The accumulated test damage must be at least the damage expected in + service at the location (TB 862 6.3.4.1: equal or greater; a safety + factor is a matter of agreement, so pass it in ``service_damage``). + With ``service_mean_tension_N`` every block must have at least that + tension, so that the radial contact of the armour onto the core in the + test is at least that in service (TB 862 Appendix D.3, Table 6-4). The + similarity of the damage distribution with the service distribution + is not checked here: compare :attr:`damage_shares` with it. + """ + require_finite(service_damage, "service_damage") + if service_damage < 0.0: + raise CableInputError("service_damage must be non-negative") + checks = [ + ProgrammeCheck( + "accumulated test damage >= service damage", + "TB 862 6.3.4.1, Table 6-4", + service_damage, + self.total_damage, + ) + ] + if service_mean_tension_N is not None: + require_finite(service_mean_tension_N, "service_mean_tension_N") + checks.append( + ProgrammeCheck( + "block tension >= service mean tension (lowest block)", + "TB 862 Table 6-4, Appendix D.3", + service_mean_tension_N, + min(b.tension_N for b in self.blocks), + ) + ) + return tuple(checks) + + def test_sequence( + self, + *, + max_fraction: float = 0.5, + row_fraction: float = 0.01, + rounding: Literal["exact", "up"] = "exact", + ) -> tuple[FatigueTestBlock, ...]: + """The order of running the blocks, with switching (TB 862 6.3.4.3). + + A block holding more than ``row_fraction`` of all cycles is not run in + one row, and at most ``max_fraction`` of a block's cycles is applied + before switching to another block. Each block is cut into + ``ceil(1 / max_fraction)`` parts (two at the default 50 %). A block at + or below ``row_fraction`` of all cycles is cut the same way when it has + as many cycles as parts, as in Table D.3; one with fewer cycles runs + whole. Labels get ``A``, ``B``, ... + + The parts are ordered so that no two parts of one block follow each + other: each step runs the next part of the block with the most parts + left, other than the block just run, ties going to programme order. + With equal part counts this is the rounds of TB 862 Table D.3 (1A to + 8A, then 1B to 8B). If a block that must be split has too many parts + to be separated by the others (one block alone, or three parts against + a single other part), no sequence meets 6.3.4.3 and + :class:`~cablexsec.exceptions.CableInputError` is raised. + + ``rounding="exact"`` keeps every block's cycles: the parts differ by at + most one cycle, the larger ones first, so a part of an odd block can be + one cycle over the fraction. ``rounding="up"`` gives every part + ``ceil(n / parts)`` cycles, as Table D.3 does (it adds up to + ``parts - 1`` cycles to a block and never applies fewer cycles than the + programme). + """ + require_finite(max_fraction, "max_fraction") + require_finite(row_fraction, "row_fraction") + if not 0.0 < max_fraction <= 1.0: + raise CableInputError("max_fraction must lie in (0, 1]") + if not 0.0 <= row_fraction < 1.0: + raise CableInputError("row_fraction must lie in [0, 1)") + if rounding not in ("exact", "up"): + raise CableInputError("rounding must be 'exact' or 'up'") + parts = math.ceil(1.0 / max_fraction - 1e-12) + total = self.total_cycles + split: list[list[FatigueTestBlock]] = [] + names: list[str] = [] + must: list[bool] = [] + for index, block in enumerate(self.blocks): + name = block.label or str(index + 1) + must_split = block.n_cycles > row_fraction * total + k = parts if (must_split or block.n_cycles >= parts) else 1 + if must_split and block.n_cycles < parts: + raise CableInputError( + f"block {name!r} holds more than {row_fraction:.0%} of the cycles " + f"but fewer than the {parts} parts its switching needs" + ) + names.append(name) + must.append(must_split and k > 1) + if k == 1: + split.append([_relabel(block, block.n_cycles, name)]) + continue + if rounding == "up": + counts = [math.ceil(block.n_cycles / k)] * k + else: + base, extra = divmod(block.n_cycles, k) + counts = [base + (1 if i < extra else 0) for i in range(k)] + split.append( + [ + _relabel(block, n, f"{name}{chr(ord('A') + i)}") + for i, n in enumerate(counts) + ] + ) + nxt = [0] * len(split) + order: list[int] = [] + previous = -1 + for _ in range(sum(len(s) for s in split)): + left = [ + (len(s) - nxt[i], -i) + for i, s in enumerate(split) + if nxt[i] < len(s) and i != previous + ] + # Only the block just run can have parts left when ``left`` is empty. + i = previous if not left else -max(left)[1] + if i == previous and must[i]: + raise CableInputError( + f"block {names[i]!r} cannot be split into {parts} parts with " + "another block between every two of them (TB 862 6.3.4.3): " + "the programme has too few other blocks" + ) + order.append(i) + nxt[i] += 1 + previous = i + seen = [0] * len(split) + out: list[FatigueTestBlock] = [] + for i in order: + out.append(split[i][seen[i]]) + seen[i] += 1 + return tuple(out) + + def to_rig_blocks(self, *, simulated_cycles: int = 1) -> list[RigBlock]: + """The blocks as :class:`~cablexsec.analysis.rig_test.RigBlock` of curvature. + + Each block becomes a rig block of its tension and of the curvature + amplitude ``range / 2`` about zero mean, with ``simulated_cycles`` + cycles for :meth:`RigProtocol.blocks` (``quantity="curvature"``); the + rig simulation runs a few representative cycles, not the test count. + """ + return [ + RigBlock( + tension_N=b.tension_N, + amplitude=0.5 * b.curvature_range_1_m, + n_cycles=simulated_cycles, + ) + for b in self.blocks + ] + + +def _relabel(block: FatigueTestBlock, n_cycles: int, label: str) -> FatigueTestBlock: + return FatigueTestBlock( + n_cycles=n_cycles, + tension_N=block.tension_N, + curvature_range_1_m=block.curvature_range_1_m, + damage_per_cycle=block.damage_per_cycle, + label=label, + ) diff --git a/src/cablexsec/mechanics/thermal.py b/src/cablexsec/mechanics/thermal.py index 970005a..83acba6 100644 --- a/src/cablexsec/mechanics/thermal.py +++ b/src/cablexsec/mechanics/thermal.py @@ -242,11 +242,14 @@ class ThermalResult: resistances : dict or None The thermal resistances of [IEC60287-1-1] 4.2.1, Formula (1), from :func:`compute_thermal` [K m/W]: ``T1_Km_W`` (conductor to sheath, per - core), ``T2_Km_W`` (sheath to the innermost armour, per core of the + core), ``T2_Km_W`` and ``T3_Km_W`` (outside the sheath, per core of the ``n`` loaded cores: a per-core jacket counts ``1/n``, as in CIGRE TB - 880 Guidance Point 45), ``T3_Km_W`` (outside the innermost armour) and - ``T4_Km_W``. Without a structural armour ``T3`` is zero and ``T2`` - holds everything outside the sheath. + 880 Guidance Point 45) and ``T4_Km_W``. A cable-level annulus outside + ``k`` of ``m`` structural armour layers goes ``(1 - k/m)`` to ``T2`` + and ``k/m`` to ``T3``, its share of the armour loss, so Formula (1) + reproduces the solver; with one armour layer this is the split at the + armour. Without a structural armour ``T3`` is zero and ``T2`` holds + everything outside the sheath. """ r_m: FloatArray diff --git a/tests/test_block_programme.py b/tests/test_block_programme.py new file mode 100644 index 0000000..50c89a6 --- /dev/null +++ b/tests/test_block_programme.py @@ -0,0 +1,189 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +"""Block programmes of full-scale fatigue tests against CIGRE TB 862 Appendix D. + +Tables D.1 to D.3 of TB 862 (2022) as regression cases. The damage per cycle +is printed to three significant figures, so the block damages are compared +within 0.5 % (2.57e-9 +- 0.005e-9 alone is +-0.19 %). Table D.3 prints 6.05e-4 +for blocks 3A and 3B; 61 116 cycles at 9.90e-10 give 6.05e-5, which its total +4.68e-4 uses. +""" + +from __future__ import annotations + +import pytest + +import cablexsec as cx +from cablexsec.exceptions import CableInputError + +pytestmark = pytest.mark.analytical_sanity + +_PRINTED = 5e-3 # printed to three significant figures + +_D1_CYCLES = (973_459, 370_043, 122_231, 25_979, 6_623, 1_815, 253) +_D1_CURVATURE = (0.029, 0.057, 0.085, 0.11, 0.135, 0.16, 0.207) +_D1_DPC = (3.27e-12, 9.59e-11, 7.08e-10, 2.57e-9, 7.16e-9, 1.67e-8, 6.05e-8) +_D1_DAMAGE = (3.18e-6, 3.55e-5, 8.65e-5, 6.67e-5, 4.74e-5, 3.03e-5, 1.53e-5) + +_D2_CYCLES = (*_D1_CYCLES, 61) +_D2_TENSION_KN = (80,) * 7 + (110,) +_D2_CURVATURE = (*_D1_CURVATURE, 0.341) +_D2_DPC = (4.58e-12, 1.34e-10, 9.90e-10, 3.60e-9, 1.00e-8, 2.34e-8, 8.49e-8, 1.11e-6) +_D2_DAMAGE = (4.46e-6, 4.97e-5, 1.21e-4, 9.34e-5, 6.63e-5, 4.25e-5, 2.15e-5, 6.76e-5) + +# Table D.3, with 6.05e-5 for blocks 3A and 3B (printed 6.05e-4). +_D3_HALF = (486_730, 185_022, 61_116, 12_990, 3_312, 908, 127, 31) +_D3_DAMAGE = (2.23e-6, 2.48e-5, 6.05e-5, 4.68e-5, 3.31e-5, 2.12e-5, 1.08e-5, 3.44e-5) + + +def _d1() -> cx.BlockProgramme: + return cx.BlockProgramme( + tuple( + cx.FatigueTestBlock(n, 10e3, k, d, label=str(i + 1)) + for i, (n, k, d) in enumerate( + zip(_D1_CYCLES, _D1_CURVATURE, _D1_DPC, strict=True) + ) + ) + ) + + +def _d2() -> cx.BlockProgramme: + return cx.BlockProgramme( + tuple( + cx.FatigueTestBlock(n, t * 1e3, k, d, label=str(i + 1)) + for i, (n, t, k, d) in enumerate( + zip(_D2_CYCLES, _D2_TENSION_KN, _D2_CURVATURE, _D2_DPC, strict=True) + ) + ) + ) + + +def test_table_d1() -> None: + prog = _d1() + assert prog.total_cycles == 1_500_403 + for block, printed in zip(prog.blocks, _D1_DAMAGE, strict=True): + assert block.damage == pytest.approx(printed, rel=_PRINTED) + assert prog.total_damage == pytest.approx(2.85e-4, rel=_PRINTED) + assert sum(prog.damage_shares) == pytest.approx(1.0, rel=1e-14) + assert prog.accumulated_damage[-1] == pytest.approx(prog.total_damage, rel=1e-14) + # The test damage equals the 25-year damage at the sag bend (TB 862 D.2). + (damage,) = prog.check(25 * 1.14e-5) + assert damage.given == pytest.approx(damage.required, rel=_PRINTED) + + +def test_table_d2() -> None: + prog = _d2() + assert prog.total_cycles == 1_500_464 + for block, printed in zip(prog.blocks, _D2_DAMAGE, strict=True): + assert block.damage == pytest.approx(printed, rel=_PRINTED) + assert prog.total_damage == pytest.approx(4.67e-4, rel=_PRINTED) + # Larger than the damage at both hot spots: 2.85e-4 at 62.5 m (and about + # half of it at 1.75 m), TB 862 D.3. + damage, tension = prog.check(2.85e-4, service_mean_tension_N=10e3) + assert damage.passed and tension.passed + # TB 862 D.3 gives the mean tension at 1.75 m as 82 kN but runs the blocks + # at 80 kN: the strict Table 6-4 check does not pass on its own example. + _, tension_175 = prog.check(2.85e-4, service_mean_tension_N=82e3) + assert not tension_175.passed and tension_175.given == 80e3 + + +def test_table_d3_sequence() -> None: + prog = _d2() + seq = prog.test_sequence(rounding="up") + labels = [b.label for b in seq] + assert labels == [f"{i}A" for i in range(1, 9)] + [f"{i}B" for i in range(1, 9)] + assert [b.n_cycles for b in seq] == list(_D3_HALF) * 2 + for block, printed in zip(seq, _D3_DAMAGE * 2, strict=True): + assert block.damage == pytest.approx(printed, rel=_PRINTED) + assert seq[2].damage == pytest.approx(6.05e-5, rel=_PRINTED) # not 6.05e-4 + assert cx.BlockProgramme(seq).total_cycles == 1_500_472 + assert cx.BlockProgramme(seq).total_damage == pytest.approx(4.68e-4, rel=_PRINTED) + + +def test_exact_split_keeps_the_cycles() -> None: + prog = _d2() + seq = prog.test_sequence() + assert cx.BlockProgramme(seq).total_cycles == prog.total_cycles + assert [b.n_cycles for b in seq[:8]] == [ + 486_730, + 185_022, + 61_116, + 12_990, + 3_312, + 908, + 127, + 31, + ] + assert [b.n_cycles for b in seq[8:]] == [ + 486_729, + 185_021, + 61_115, + 12_989, + 3_311, + 907, + 126, + 30, + ] + # No part above half its block, except one cycle of an odd block. + for part in seq: + whole = prog.blocks[int(part.label[:-1]) - 1].n_cycles + assert part.n_cycles <= whole // 2 + whole % 2 + + +def test_three_parts_and_small_blocks() -> None: + prog = cx.BlockProgramme( + ( + cx.FatigueTestBlock(1000, 1e3, 0.1, 1e-9, label="big"), + cx.FatigueTestBlock(2, 1e3, 0.3, 1e-6, label="tiny"), + cx.FatigueTestBlock(2, 1e3, 0.4, 2e-6, label="tiny2"), + ) + ) + seq = prog.test_sequence(max_fraction=0.34) + # Every two parts of the big block have another block between them, + # which a plain round order (bigA, tiny, tiny2, bigB, bigC) misses. + assert [b.label for b in seq] == ["bigA", "tiny", "bigB", "tiny2", "bigC"] + assert [b.n_cycles for b in seq] == [334, 2, 333, 2, 333] + + +def test_switching_impossible_raises() -> None: + # Three parts of the big block need two other parts between them. + prog = cx.BlockProgramme( + ( + cx.FatigueTestBlock(1000, 1e3, 0.1, 1e-9, label="big"), + cx.FatigueTestBlock(2, 1e3, 0.3, 1e-6, label="tiny"), + ) + ) + with pytest.raises(CableInputError, match="6.3.4.3"): + prog.test_sequence(max_fraction=0.34) + single = cx.BlockProgramme((cx.FatigueTestBlock(1000, 1e3, 0.1, 1e-9),)) + with pytest.raises(CableInputError, match="6.3.4.3"): + single.test_sequence() + + +def test_float_cycle_count_is_stored_as_int() -> None: + block = cx.FatigueTestBlock(10.0, 1e3, 0.1, 1e-9) # type: ignore[arg-type] + assert isinstance(block.n_cycles, int) and block.n_cycles == 10 + + +def test_to_rig_blocks() -> None: + rig = _d2().to_rig_blocks(simulated_cycles=3) + assert rig[0].amplitude == pytest.approx(0.0145) + assert rig[-1].tension_N == 110e3 and rig[-1].n_cycles == 3 + protocol = cx.RigProtocol.blocks(rig, quantity="curvature", temperature_C=20.0) + assert len(protocol.block_times_s) == 8 + + +def test_input_errors() -> None: + with pytest.raises(CableInputError): + cx.BlockProgramme(()) + with pytest.raises(CableInputError): + cx.FatigueTestBlock(0, 1e3, 0.1, 1e-9) + with pytest.raises(CableInputError): + cx.FatigueTestBlock(10, 1e3, -0.1, 1e-9) + with pytest.raises(CableInputError): + _d1().test_sequence(max_fraction=0.0) + with pytest.raises(CableInputError): + _d1().test_sequence(rounding="down") # type: ignore[arg-type] + big_one = cx.BlockProgramme((cx.FatigueTestBlock(1, 1e3, 0.1, 1e-9),)) + with pytest.raises(CableInputError, match="fewer than the 2 parts"): + big_one.test_sequence() diff --git a/validation/validation_report.md b/validation/validation_report.md index 3414054..112853c 100644 --- a/validation/validation_report.md +++ b/validation/validation_report.md @@ -86,7 +86,7 @@ Every row is computed from published data or closed-form references in this repo ## Test taxonomy (full gate suite) -- analytical_sanity: `1347 passed` +- analytical_sanity: `1356 passed` - independent_method: `105 passed` - full_scale: `62 passed`