diff --git a/CHANGELOG.md b/CHANGELOG.md index 35f431c..26e7642 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -216,6 +216,25 @@ All notable changes to CableXSec are recorded in this file. The format follows ### Fixed +- `export_bending_law` keeps the stick stiffness at every tension. Its geometric curvature grid + started at `1e-4 κ_max` whatever the tension, so a slip onset below that floor (66 kV template, + `κ_max` 0.4 1/m: outer armour 7.3e-6 1/m and inner 2.3e-5 1/m at 10 kN) was inside the first + chord, and the law started partly or fully slipped: stick stiffness 5.80e5 instead of the + section's 1.26e6 N m² at 10 kN (1.255e6 at 50 kN). With `slip_scale=True` the default reference + is the smallest tension, so every scaled tension inherited the softened group laws (secant + `M/κ` of the scaled law 0.46–0.65 of `compute_mkappa` below full slip at 50–200 kN). The grid + now extends below its floor at the same ratio until its first point lies under half the + smallest first-slip curvature (the neutral-axis onset times the compression-side factor + `m(λ)`, and the smallest sub-element cap of the uniform progressive density), and carries the + onset and full-slip curvature of every armour layer and of the laid cores at every exported + tension and at the slip-scale reference. On the 66 kV template at 10–200 kN the exported and + the scaled laws start at the section's stick stiffness to round-off and match `compute_mkappa` + between grid points within 5.2e-4 of the moment; the core, progressive, pressure-factor and + solved-contact exports start at `EI_max` too. `kappa_1_m` now holds more than `n_points` + points (the base grid is unchanged); the linear spacing gets one stick point and the slip + 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 slip of the distributed friction model over a full-slip increment (every helix node on its bound) is now unique. The equations fix the forces, the tractions and `u − p` there, but not a slide common to the displacement `u` and the slip `p` of all nodes; the solver left one node diff --git a/doc/global_local_guide.md b/doc/global_local_guide.md index cece7d6..b3aa020 100644 --- a/doc/global_local_guide.md +++ b/doc/global_local_guide.md @@ -394,6 +394,15 @@ export.to_csv("bending_law.csv") # kappa against M at every tension pairs = export.backbone_table_kNm(35e3) # (curvature rad/m, moment kN m) of the backbone ``` +Curvature grid. The backbone is computed on a geometric grid from `1e-4 κ_max` to `κ_max` (`n_points`), extended +below at the same ratio until its first point lies under half the smallest first-slip curvature of any exported +tension, plus the slip onset and full-slip curvature of every armour layer (and of the laid cores) at every tension +and at the slip-scale reference. The first chord of every backbone is then the stick stiffness of the section, and +each stick-to-slip transition is resolved at the grid's density; `kappa_1_m` holds more than `n_points` points. A +low tension moves the onset far down (66 kV template: 7.3e-6 1/m for the outer armour at 10 kN), below a grid that +starts at `1e-4 κ_max`. With `spacing="linear"` the export adds one stick point and the onset and full-slip points +and warns when a transition is narrower than the step. + Checks (targets registered first; [benchmarks.md](benchmarks.md), hysteretic bending law): the Iwan law reproduces `compute_mkappa` within 0.05 % of the moment range and the work within 0.02 % on symmetric cycles and an irregular history, for the Ménard cable at 0 and 50 kN and the 66 kV template at 50 kN; the decomposition diff --git a/src/cablexsec/analysis/bending_law.py b/src/cablexsec/analysis/bending_law.py index 234e6a8..b6ac918 100644 --- a/src/cablexsec/analysis/bending_law.py +++ b/src/cablexsec/analysis/bending_law.py @@ -83,8 +83,10 @@ from __future__ import annotations +import dataclasses import json import math +import warnings from collections.abc import Sequence from dataclasses import dataclass, field from pathlib import Path @@ -95,10 +97,16 @@ from cablexsec.exceptions import CableInputError from cablexsec.mechanics.friction_law import FrictionLaw -from cablexsec.mechanics.papailiou import wire_slip_stress_bounds +from cablexsec.mechanics.papailiou import ( + _compression_onset_factor, + full_slip_curvature, + slip_onset_curvature, + wire_slip_stress_bounds, +) from cablexsec.provenance import Provenance if TYPE_CHECKING: + from cablexsec.api import _MkappaLaw from cablexsec.cables.schema import CableData from cablexsec.mechanics.mkappa import HelicalLayerSpec @@ -122,6 +130,22 @@ #: Relative step of the central differences of the group caps. _DIFFERENCE_STEP = 1e-4 +#: Floor of the base geometric curvature grid, relative to ``kappa_max``. +_GRID_FLOOR = 1e-4 + +#: The first curvature of the grid lies at most this fraction of the smallest +#: first-slip curvature, so that the first chord of every backbone is in stick. +_STICK_MARGIN = 0.5 + +#: Deepest extension of the geometric grid below its base floor [decades]. +_MAX_EXTENSION_DECADES = 6.0 + +#: Grid curvatures closer than this relative gap are merged. +_MERGE_GAP = 1e-9 + +#: Relative tolerance of the exported stick stiffness against the section's. +_STICK_TOLERANCE = 1e-6 + @dataclass(frozen=True) class IwanBendingLaw: @@ -824,10 +848,19 @@ def export_bending_law( Largest curvature of the backbone [1/m]; the full-slip slope continues it beyond. n_points : int, optional - Backbone points including zero (default 200). + Points of the base curvature grid including zero (default 200). The + export adds the slip onset and full-slip curvature of every friction + group (armour layer, laid cores) at every exported tension and at the + slip-scale reference, so ``kappa_1_m`` holds more points. spacing : {"geometric", "linear"}, optional - Point spacing. ``"geometric"`` resolves the stick-to-slip transition at - small curvature (default). + Point spacing. ``"geometric"`` (default) runs from ``1e-4 + kappa_max_1_m`` and is extended below at the same ratio until its + first point lies under half the smallest first-slip curvature, so + every stick-to-slip transition is resolved at the grid's density and + the first chord of every backbone is the stick stiffness. + ``"linear"`` gets one stick point below the smallest first-slip + curvature and the onset and full-slip points; a transition narrower + than its step is resolved by those points alone, which is warned. slip_scale : bool, optional Also export the slip scaling variable (:class:`SlipScaleTable`, ``BendingLawExport.slip_scale``): the law at a reference state split @@ -839,7 +872,9 @@ def export_bending_law( laws use the export's curvature grid, and a group of scale ``rho`` reproduces its law at the state up to ``rho kappa_max_1_m``; beyond, the full-slip slope continues as in every exported law. With caps - that rise with tension the smallest tension gives ``rho >= 1``. + that rise with tension the smallest tension gives ``rho >= 1``. The + grid carries the slip curvatures of the reference, so the group laws + start in stick at any reference. slip_scale_tensions_N : sequence of float, optional Ascending tensions of the table [N] (default ``tensions_N``). slip_scale_external_pressure_Pa : sequence of float, optional @@ -925,14 +960,43 @@ def export_bending_law( or slip_scale_external_pressure_Pa is not None ): raise CableInputError("the slip_scale_* options need slip_scale=True") - if spacing == "geometric": - kappa = np.concatenate( - [[0.0], np.geomspace(kappa_max_1_m * 1e-4, kappa_max_1_m, n_points - 1)] - ) - elif spacing == "linear": - kappa = np.linspace(0.0, kappa_max_1_m, n_points) - else: + if spacing not in ("geometric", "linear"): raise CableInputError("spacing must be 'geometric' or 'linear'") + # compute_mkappa checks the options with its own messages before the slip + # curvatures are read from the same prepared law. + compute_mkappa(cable, np.zeros(2), tension_N=float(t[0]), **mkappa_options) + contact_model, common = _law_options(mkappa_options) + transitions: list[_Transition] = [] + for tension in t: + state = _state_law(cable, float(tension), None, contact_model, common) + transitions += _slip_transitions(state, float(tension), friction_law) + reference_N: float | None = None + if slip_scale: + pressures = ( + None + if slip_scale_external_pressure_Pa is None + else _ascending( + slip_scale_external_pressure_Pa, "slip_scale_external_pressure_Pa" + ) + ) + reference_pressure = ( + None + if pressures is None + else float(cable.initial_state.external_pressure_Pa) + ) + reference_N = _reference_tension( + cable, + slip_scale_reference_N, + t, + reference_pressure, + contact_model, + common, + ) + state = _state_law( + cable, reference_N, reference_pressure, contact_model, common + ) + transitions += _slip_transitions(state, reference_N, None) + kappa = _export_grid(kappa_max_1_m, n_points, spacing, transitions) moments = np.empty((t.size, kappa.size)) ei_slip = np.empty(t.size) laws = [] @@ -944,13 +1008,21 @@ def export_bending_law( moments[i, 0] = 0.0 ei_slip[i] = float(result.EI_min_Nm2) laws.append(IwanBendingLaw.from_backbone(kappa, moments[i], ei_slip[i])) + stick = float(result.EI_max_Nm2) + if abs(laws[-1].ei_stick_Nm2 - stick) > _STICK_TOLERANCE * stick: + warnings.warn( + f"the exported law at {tension:g} N starts at " + f"{laws[-1].ei_stick_Nm2:.6g} N m2, not at the stick stiffness " + f"{stick:.6g} N m2 of the section: its first grid curvature " + f"{kappa[1]:.3g} 1/m is already partly slipped", + UserWarning, + stacklevel=2, + ) table = ( _slip_scale_table( cable, kappa, - reference_N=None - if slip_scale_reference_N is None - else float(slip_scale_reference_N), + reference_N=reference_N, candidates_N=t, tensions_N=t if slip_scale_tensions_N is None else slip_scale_tensions_N, external_pressure_Pa=slip_scale_external_pressure_Pa, @@ -1052,6 +1124,229 @@ def _ascending(values: ArrayLike, label: str) -> FloatArray: return grid +@dataclass(frozen=True) +class _Transition: + """Stick-to-slip transition of one friction group at one state [1/m].""" + + tension_N: float + first_slip: float # lower bound of the curvature of the first slip + onset: float + full_slip: float + + +def _law_options(options: dict[str, Any]) -> tuple[str, dict[str, Any]]: + """Contact model and the law settings of :func:`_prepare_mkappa_law`.""" + from cablexsec.mechanics.core_friction import ( # noqa: PLC0415 + resolve_core_friction, + ) + from cablexsec.mechanics.progressive_friction import ( # noqa: PLC0415 + ProgressiveFriction, + ) + + friction_model = options.get("friction_model", "direction_tied") + common: dict[str, Any] = { + "mu": options.get("mu"), + "phi_bend": 0.0, + "core_spec": resolve_core_friction(options.get("core_friction")), + "progressive": (options.get("progressive") or ProgressiveFriction()) + if friction_model == "progressive" + else None, + } + return options.get("contact_model") or "bounded", common + + +def _state_law( + cable: CableData, + tension: float, + pressure: float | None, + contact_model: str, + common: dict[str, Any], +) -> _MkappaLaw: + """The prepared law at a tension and, optionally, a solved pressure state. + + Without a pressure, the fixed-tension contact state of + :func:`compute_mkappa`; with one, a solved section state + (``solve_section_state``, or ``solve_cable_radial_state`` for the solved + model). + """ + from cablexsec.api import _prepare_mkappa_law # noqa: PLC0415 + from cablexsec.mechanics.radial_cable import ( # noqa: PLC0415 + solve_cable_radial_state, + ) + from cablexsec.mechanics.section_state import ( # noqa: PLC0415 + solve_section_state, + ) + + if pressure is None: + return _prepare_mkappa_law( + cable, + tension, + contact_model=contact_model, + section_state=None, + radial_state=None, + **common, + ) + if contact_model == "solved": + radial = solve_cable_radial_state(cable, tension, external_pressure_Pa=pressure) + return _prepare_mkappa_law( + cable, + radial.tension_N, + contact_model="solved", + section_state=None, + radial_state=radial, + **common, + ) + state = solve_section_state( + cable, tension_N=tension, p_ext_Pa=pressure, contact_model=contact_model + ) + return _prepare_mkappa_law( + cable, + state.tension_N, + contact_model=contact_model, + section_state=state, + radial_state=None, + **common, + ) + + +def _group_caps(law: _MkappaLaw) -> FloatArray: + """Planar full-slip friction moment of every friction group [N m].""" + values = [_friction_cap(spec) for spec in law.layers] + if law.core_model is not None: + values.append(_friction_cap(law.core_model.population)) + return np.asarray(values, dtype=np.float64) + + +def _reference_tension( + cable: CableData, + reference_N: float | None, + candidates_N: FloatArray, + pressure: float | None, + contact_model: str, + common: dict[str, Any], +) -> float: + """The given reference, or the first candidate at which every group has + contact (the last candidate when none has).""" + if reference_N is not None: + value = float(reference_N) + if not (math.isfinite(value) and value >= 0.0): + raise CableInputError("slip_scale_reference_N must be finite and >= 0") + return value + # The smallest exported tension at which every group has contact: with + # caps rising with tension the scales are then >= 1. + return next( + ( + float(value) + for value in candidates_N + if np.all( + _group_caps( + _state_law(cable, float(value), pressure, contact_model, common) + ) + > 0.0 + ) + ), + float(candidates_N[-1]), + ) + + +def _slip_transitions( + law: _MkappaLaw, tension: float, friction_law: FrictionLaw | None +) -> list[_Transition]: + """Slip onset and full-slip curvature of every friction group with friction. + + ``first_slip`` bounds the first slip of a wire from below: the neutral-axis + onset of :func:`~cablexsec.mechanics.papailiou.slip_onset_curvature` times + the compression-side factor ``m(lam)`` and, for the uniform progressive + density, the smallest sub-element cap fraction ``1 - h (1 - 1/N)``. A + pressure-dependent coefficient enters at the state's ``P1+P2``. + """ + spread = 1.0 + if law.progressive is not None and law.progressive.density == "uniform": + n = law.progressive.n_elements + spread = 1.0 - law.progressive.spread * (1.0 - 1.0 / n) + specs = [(spec, spread) for spec in law.layers] + if law.core_model is not None: + specs.append((law.core_model.population, 1.0)) + out = [] + for spec, factor in specs: + if friction_law is not None and friction_law.pressure_dependent: + scale = float(friction_law.pressure_factor_at(spec.contact_pressure_Pa)) + spec = dataclasses.replace(spec, mu=spec.mu * scale) + onset = slip_onset_curvature(spec) + if not (math.isfinite(onset) and onset > 0.0): + continue # no friction: the group is in full slip from zero + lam = spec.mu * abs(math.sin(spec.lay_angle_rad)) + out.append( + _Transition( + tension, + onset * _compression_onset_factor(lam) * factor, + onset, + full_slip_curvature(spec), + ) + ) + return out + + +def _export_grid( + kappa_max: float, + n_points: int, + spacing: str, + transitions: Sequence[_Transition], +) -> FloatArray: + """Zero, the base grid, its extension into stick and the slip curvatures.""" + if spacing == "geometric": + base = np.geomspace(kappa_max * _GRID_FLOOR, kappa_max, n_points - 1) + else: + base = np.linspace(0.0, kappa_max, n_points)[1:] + first = min((tr.first_slip for tr in transitions), default=math.inf) + target = _STICK_MARGIN * first + extra: list[float] = [] + if target < base[0]: + if spacing == "geometric": + ratio = base[1] / base[0] + floor = max(target, base[0] * 10.0**-_MAX_EXTENSION_DECADES) + count = math.ceil(math.log(base[0] / floor) / math.log(ratio)) + extra += (base[0] * ratio ** -np.arange(count, 0, -1)).tolist() + if target < floor: + warnings.warn( + f"the first slip at {first:.3g} 1/m lies more than " + f"{_MAX_EXTENSION_DECADES:g} decades below the grid floor " + f"{base[0]:.3g} 1/m; the exported law starts at the stick " + f"stiffness only from {floor:.3g} 1/m (raise n_points, lower " + "kappa_max_1_m or drop the near-zero tension)", + UserWarning, + stacklevel=3, + ) + else: + extra.append(target) + if spacing == "linear": + narrow = [ + tr + for tr in transitions + if tr.onset < kappa_max and tr.full_slip - tr.onset < base[0] + ] + if narrow: + worst = min(narrow, key=lambda tr: tr.full_slip - tr.onset) + warnings.warn( + f"the linear step {base[0]:.3g} 1/m is wider than the " + f"stick-to-slip transition {worst.onset:.3g}-" + f"{worst.full_slip:.3g} 1/m at {worst.tension_N:g} N, which " + "only its onset and full-slip points resolve; use the " + "geometric spacing", + UserWarning, + stacklevel=3, + ) + for tr in transitions: + extra += [tr.onset, tr.full_slip] + nodes = np.array( + [k for k in extra if math.isfinite(k) and 0.0 < k < kappa_max], + dtype=np.float64, + ) + grid = np.unique(np.concatenate([base, nodes])) + keep = np.concatenate([[True], np.diff(grid) > _MERGE_GAP * grid[1:]]) + return np.concatenate([[0.0], grid[keep]]) + + def _slip_scale_table( cable: CableData, kappa: FloatArray, @@ -1063,24 +1358,13 @@ def _slip_scale_table( options: dict[str, Any], ) -> SlipScaleTable: """Reference group laws and group caps over the table states.""" - from cablexsec.api import _prepare_mkappa_law # noqa: PLC0415 from cablexsec.cable_adapters import structural_armour_layers # noqa: PLC0415 from cablexsec.mechanics.core_friction import ( # noqa: PLC0415 core_friction_history, - resolve_core_friction, ) from cablexsec.mechanics.papailiou import ( # noqa: PLC0415 compute_mkappa_wire_slip_front, ) - from cablexsec.mechanics.progressive_friction import ( # noqa: PLC0415 - ProgressiveFriction, - ) - from cablexsec.mechanics.radial_cable import ( # noqa: PLC0415 - solve_cable_radial_state, - ) - from cablexsec.mechanics.section_state import ( # noqa: PLC0415 - solve_section_state, - ) tensions = _ascending(tensions_N, "slip_scale_tensions_N") pressures = ( @@ -1088,75 +1372,19 @@ def _slip_scale_table( if external_pressure_Pa is None else _ascending(external_pressure_Pa, "slip_scale_external_pressure_Pa") ) - if reference_N is not None and not ( - math.isfinite(reference_N) and reference_N >= 0.0 - ): - raise CableInputError("slip_scale_reference_N must be finite and >= 0") - contact_model = options.get("contact_model") or "bounded" - friction_model = options.get("friction_model", "direction_tied") - common: dict[str, Any] = { - "mu": options.get("mu"), - "phi_bend": 0.0, - "core_spec": resolve_core_friction(options.get("core_friction")), - "progressive": (options.get("progressive") or ProgressiveFriction()) - if friction_model == "progressive" - else None, - } + contact_model, common = _law_options(options) reference_pe = float(cable.initial_state.external_pressure_Pa) - def prepare(tension: float, pressure: float | None) -> Any: - if pressure is None: - return _prepare_mkappa_law( - cable, - tension, - contact_model=contact_model, - section_state=None, - radial_state=None, - **common, - ) - if contact_model == "solved": - radial = solve_cable_radial_state( - cable, tension, external_pressure_Pa=pressure - ) - return _prepare_mkappa_law( - cable, - radial.tension_N, - contact_model="solved", - section_state=None, - radial_state=radial, - **common, - ) - state = solve_section_state( - cable, tension_N=tension, p_ext_Pa=pressure, contact_model=contact_model - ) - return _prepare_mkappa_law( - cable, - state.tension_N, - contact_model=contact_model, - section_state=state, - radial_state=None, - **common, - ) + def prepare(tension: float, pressure: float | None) -> _MkappaLaw: + return _state_law(cable, tension, pressure, contact_model, common) def caps(tension: float, pressure: float | None) -> FloatArray: - law = prepare(tension, pressure) - values = [_friction_cap(spec) for spec in law.layers] - if law.core_model is not None: - values.append(_friction_cap(law.core_model.population)) - return np.asarray(values, dtype=np.float64) + return _group_caps(prepare(tension, pressure)) reference_pressure = None if pressures is None else reference_pe - if reference_N is None: - # The smallest exported tension at which every group has contact: - # with caps rising with tension the scales are then >= 1. - reference_N = next( - ( - float(value) - for value in candidates_N - if np.all(caps(float(value), reference_pressure) > 0.0) - ), - float(candidates_N[-1]), - ) + reference_N = _reference_tension( + cable, reference_N, candidates_N, reference_pressure, contact_model, common + ) reference = prepare(reference_N, reference_pressure) names = [layer.name for layer in structural_armour_layers(cable)] backbones = [ diff --git a/tests/test_bending_law.py b/tests/test_bending_law.py index a67bd29..856f3af 100644 --- a/tests/test_bending_law.py +++ b/tests/test_bending_law.py @@ -58,7 +58,7 @@ def test_export_reproduces_compute_mkappa(menard, tmp_path): ) assert record["hysteresis_rule"] == "masing_iwan" and record["planar_only"] table = export.backbone_table_kNm(10e3) - assert table[0] == (0.0, 0.0) and len(table) == 120 + assert table[0] == (0.0, 0.0) and len(table) == export.kappa_1_m.size with pytest.raises(CableInputError, match="outside"): export.law_at(30e3) assert export.to_csv(tmp_path / "law.csv").read_text().startswith("kappa_1_m,") @@ -120,8 +120,71 @@ def test_export_checks(kwargs, match): def test_single_tension_and_linear_spacing(): cable = cx.load_cable(cx.menard2023_yaml_path(), geometry_override=None) + # The 0.01 1/m step is wider than the stick-to-slip transition at 20 kN: + # the export adds a stick point and the slip points and warns. + with pytest.warns(UserWarning, match="linear step"): + export = export_bending_law( + cable, tensions_N=[2e4], kappa_max_1_m=0.1, n_points=11, spacing="linear" + ) + assert np.isin(np.linspace(0.0, 0.1, 11), export.kappa_1_m).all() + extra = np.setdiff1d(export.kappa_1_m, np.linspace(0.0, 0.1, 11)) + assert extra.size >= 3 and np.all(extra < 0.01) + stick = cx.compute_mkappa(cable, np.zeros(2), tension_N=2e4).EI_max_Nm2 + assert export.laws[0].ei_stick_Nm2 == pytest.approx(stick, rel=1e-12) + assert export.law_at(2e4) is export.laws[0] + + +@pytest.fixture(scope="module") +def iea66_stick(): + """66 kV template at 10-200 kN: its slip onsets at 10 kN (7.3e-6 and + 2.3e-5 1/m) lie below the base grid floor 1e-4 kappa_max = 4e-5 1/m.""" + cable = cx.load_cable(cx.iea_task49_66kv_yaml_path(), geometry_override=None) + tensions = [10e3, 25e3, 50e3, 100e3, 200e3] + props = cx.compute_section_properties( + cable, [cx.SectionLoadCase(f"T{t:g}", tension_N=t) for t in tensions] + ) export = export_bending_law( - cable, tensions_N=[2e4], kappa_max_1_m=0.1, n_points=11, spacing="linear" + cable, + tensions_N=tensions, + kappa_max_1_m=0.4, + n_points=200, + slip_scale=True, ) - np.testing.assert_allclose(np.diff(export.kappa_1_m), 0.01, rtol=1e-12) - assert export.law_at(2e4) is export.laws[0] + return cable, tensions, props, export + + +@pytest.mark.filterwarnings("error:the exported law:UserWarning") +def test_export_starts_at_the_section_stick_stiffness(iea66_stick): + cable, tensions, props, export = iea66_stick + table = export.slip_scale + assert table is not None and table.reference_tension_N == tensions[0] + onsets = [a.onset_curvature_1_m for c in props.cases for a in c.armour] + assert min(onsets) < 0.4 * 1e-4 # below the base grid floor + assert export.kappa_1_m[1] < 0.5 * min(onsets) + for i, case in enumerate(props.cases): + stick = case.ei_stick_Nm2 + assert export.laws[i].ei_stick_Nm2 == pytest.approx(stick, rel=1e-12) + assert table.law_at(tensions[i]).ei_stick_Nm2 == pytest.approx(stick, rel=1e-12) + for slip in case.armour: + for value in (slip.onset_curvature_1_m, slip.full_slip_curvature_1_m): + assert np.min(np.abs(export.kappa_1_m - value)) <= 1e-9 * value + + +def test_exported_and_scaled_laws_match_compute_mkappa_off_the_grid(iea66_stick): + # Before the grid carried the slip curvatures the 10 kN law started at + # 0.46 of the stick stiffness and every scaled tension inherited it. + cable, tensions, _, export = iea66_stick + table = export.slip_scale + assert table is not None + grid = export.kappa_1_m[1:] + between = np.sqrt(grid[:-1] * grid[1:]) + between = between[(between > 1e-6) & (between < 0.05)] + for i, tension in enumerate(tensions): + direct = np.asarray( + cx.compute_mkappa( + cable, np.concatenate([[0.0], between]), tension_N=tension + ).moment_Nm + )[1:] + for law in (export.laws[i], table.law_at(tension)): + error = np.max(np.abs(law.backbone(between) - direct) / direct) + assert error < 2e-3, (tension, error) diff --git a/tests/test_bending_law_slip_scale.py b/tests/test_bending_law_slip_scale.py index 04027a3..0e86447 100644 --- a/tests/test_bending_law_slip_scale.py +++ b/tests/test_bending_law_slip_scale.py @@ -145,14 +145,18 @@ def test_single_scale_reproduces_the_export_when_groups_scale_alike(iea66): table = export.slip_scale assert table is not None and table.reference_tension_N == t1 np.testing.assert_allclose(table.scale[:, 0], [1.0, s], rtol=1e-12) + # The grid carries the slip curvatures of every exported tension: at + # [t2, s t2] it is the reference grid times s. direct = export_bending_law( - iea66, tensions_N=[t2], kappa_max_1_m=s * kappa_max, n_points=120 + iea66, tensions_N=[t2, s * t2], kappa_max_1_m=s * kappa_max, n_points=120 ).laws[0] scaled = table.law_at(t2, per_group=False) np.testing.assert_allclose( scaled.yield_curvature_1_m, direct.yield_curvature_1_m, rtol=1e-12 ) - k_scale = np.max(direct.stiffness_Nm2) + # Element stiffnesses are differences of backbone tangents, whose round-off + # scales with the stick tangent (the stick grid reaches down to 1e-6 1/m). + k_scale = direct.ei_stick_Nm2 assert np.max(np.abs(scaled.stiffness_Nm2 - direct.stiffness_Nm2)) < 1e-12 * k_scale assert scaled.ei_slip_Nm2 == pytest.approx(direct.ei_slip_Nm2, rel=1e-12) # At the reference the merged groups are the exported law. diff --git a/validation/validation_report.md b/validation/validation_report.md index 8bc97e2..0f6ab86 100644 --- a/validation/validation_report.md +++ b/validation/validation_report.md @@ -67,9 +67,9 @@ Every row is computed from published data or closed-form references in this repo ## Test taxonomy (full gate suite) -- analytical_sanity: `1153 passed, 3248 deselected` -- independent_method: `76 passed, 4325 deselected` -- full_scale: `31 passed, 4370 deselected` +- analytical_sanity: `1153 passed, 3250 deselected` +- independent_method: `76 passed, 4327 deselected` +- full_scale: `31 passed, 4372 deselected` Run `pytest -m ` to reproduce each group.