From 58520fb4531a120797b54593087bc99a2b190aca Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Thu, 19 Nov 2026 13:49:11 +0900 Subject: [PATCH 1/4] doc: register the group-law checks of the exported bending law (MX-group) Targets registered before any run: summed per-group laws against the exported backbone (0.5 %) and loop work (+-1 %) on the 66 kV template with laid cores, filler profiles and armour clamping; the zero-tension row of the default scale table. Signed-off-by: Jae Hoon Seo --- doc/benchmarks.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/benchmarks.md b/doc/benchmarks.md index 9687765..451136f 100644 --- a/doc/benchmarks.md +++ b/doc/benchmarks.md @@ -1196,6 +1196,10 @@ guide [global_local_guide.md](global_local_guide.md), Section 8. | MX-5 | MM | Hysteretic bending of a global program with the exported table | not run | open | | MX-scale | I | Slip scaling variable (`slip_scale=True`): bound homogeneity of `compute_mkappa` (66 kV, 20 → 70 kN, cores); group elements at 60 kN against the 10 kN elements with yield curvatures times `ρ_g` (Ménard); tension cycle 10–70 kN inside ±0.03 1/m bending, scaled law against the contact-tension history over the fixed-tension residual | 6.9e-16; 1.2e-13; 1.21 (1.02 before the support-cut shear stack; symmetric wire bounds on a breakpoint grid: 8e-15, work 7e-15) | PASS | | MX-scale-1 | I | One scale for all groups against the per-group law, 10–150 kN (reference 10 kN), backbone and cycles to 1.5 times full slip | 66 kV 0; 33 kV three-core 0.10 % (0.29 % with cores); Ménard 12 %; with p_e 0–2 MPa: 66 kV 21 %, 33 kV 12 %, Ménard 19 % | reported | +| MX-group-B | I | One law per friction group, each with its own scale table (`BendingLawExport.slip_group_laws`): sum over the groups of `s_g M_g(κ/s_g)` (the backbone table of the group at the reference, scaled by its own `s_g(T)`) against the exported backbone at the same tension (case below) | registered: at every grid curvature κ > 0 and every exported tension, within 0.5 % of the exported moment | registered | +| MX-group-E | I | Same laws, Masing replay: work of three symmetric cycles of amplitude 1e-3, 3e-3, 0.01, 0.03, 0.1 and 0.3 1/m, summed group laws against the exported law at the same tension | registered: within ±1 % | registered | +| MX-group-0 | A | The default scale table starts at zero tension: `s_g(0)` is the group cap of the contact model at zero tension over its reference cap | registered: without clamping `s_g(0) = 0` to 1e-12; with clamping the zero row equals the direct cap ratio at 0 N to 1e-12 rel., and the table scale at 5 kN equals the direct cap ratio at 5 kN to 1e-9 rel. (bounded chain, affine in tension) | registered | +| MX-group-1 | I | One cap-weighted scale for all groups (`per_group=False`) on the same case and measures | reported | reported | The armour laws are parallel spring–sliders at fixed contact pressure, so the Iwan law follows Masing's rules; it is exact when every wire's slip interval is symmetric. The signed capstan bound makes the interval asymmetric (the @@ -1205,6 +1209,14 @@ symmetric bounds). The interpolation in tension is the other approximation; the exact scaling of the friction caps (MX-scale; guide Section 8.1). Biaxial bending is outside it (per-wire, direction-tied response in CableXSec). +**Group laws (MX-group), registered on 2026-11-19 before any run.** Case: the 66 kV IEA Task 49 template, +bounded contact, armour friction of the template, laid-core law with the wedged trefoil and the filler profiles, +μ 0.46 on every core and profile contact ([Janocha2024] Table 2), armour winding stress 0, 20 and 40 MPa on both +armour layers (assumed clamping states, the 0 MPa case without manufacturing clamping); export at 10, 25, 50, 100, +150 and 200 kN, `kappa_max_1_m = 0.4`, 200 base points, `slip_scale=True` with the default reference and table. +The elastic full-slip part `EI_slip κ` is carried by the first group (scaling leaves it unchanged). Tests: +`tests/test_bending_law_groups.py`. + ## Cable over a sheave (gap SH) Code `cablexsec/analysis/sheave.py` (`compute_sheave`, `sheave_contact`, `groove_pressure`); From 3b8f7b476cf7ab41b58e355816e14c58a3ddab9a Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Thu, 19 Nov 2026 15:10:47 +0900 Subject: [PATCH 2/4] feat: one exported bending law per friction group, each with its own scale table A global model that carries one slip scale per law cannot follow groups that scale differently with tension; with armour clamping the laid cores do (66 kV template, 20 MPa: cores 0.39, armour and profiles 0.46 of their 100 kN cap at 10 kN). BendingLawExport.slip_group_laws() returns one SlipGroupLaw per friction group: the group's backbone at the reference with its own scale s_g(T), so that the global model sums s_g B_g(kappa / s_g); the first group carries EI_slip. to_group_csv writes a backbone and a scale table per group. The default slip-scale table now starts at zero tension with the caps of the contact model there (zero without clamping), so the scale runs to zero instead of ending at the lowest exported tension. Checks MX-group, registered before the run (66 kV template, cores and profiles, 0/20/40 MPa winding stress, 10-200 kN): summed group laws within 4.4e-4 of the exported backbone (target 0.5 %) and 0.13 % of the cycle work (target 1 %); one scale for all groups misses by up to 5.3 % and 7 %. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 14 ++ doc/benchmarks.md | 15 +- doc/file_formats.md | 26 ++- doc/global_local_guide.md | 23 +- src/cablexsec/__init__.py | 2 + src/cablexsec/analysis/bending_law.py | 282 +++++++++++++++++++++++- tests/test_bending_law_groups.py | 294 ++++++++++++++++++++++++++ tests/test_bending_law_slip_scale.py | 3 +- validation/validation_report.md | 2 +- 9 files changed, 650 insertions(+), 11 deletions(-) create mode 100644 tests/test_bending_law_groups.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 52bf622..da227b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,15 @@ All notable changes to CableXSec are recorded in this file. The format follows ### Added +- One exported bending law per friction group, each with its own scale table + (`BendingLawExport.slip_group_laws()`, `SlipGroupLaw`, `to_group_csv`), for a global model + that sums the group laws `s_g(T) B_g(κ / s_g(T))` instead of carrying one scale. Rows + MX-group-B and MX-group-E (targets registered before the run): on the 66 kV template with + laid cores, filler profiles and 0 / 20 / 40 MPa armour winding stress, 10–200 kN, the summed + group laws reproduce the exported backbone within 4.4e-4 (target 0.5 %) and the cycle work + within 0.13 % (target ±1 %); one scale for all groups misses by up to 5.3 % and 7 % with + clamping (MX-group-1, reported). + - Reported rows SV11-SPLIT, SV11-REACH and SV11-EQ88: where the SV11 termination increment comes from. With the bellmouth curvature imposed uniformly from the end-fitting face the end-fitting anchor alone moves the SV11-PLANE median from 1.00 to 1.01 and SV11-GJ from 1.24 @@ -339,6 +348,11 @@ All notable changes to CableXSec are recorded in this file. The format follows ### Changed +- The default slip-scale table of `export_bending_law(..., slip_scale=True)` starts at zero + tension, with the caps of the contact model there (zero without clamping, the clamping caps + otherwise; row MX-group-0), so the scale runs to zero instead of ending at the lowest + exported tension. An explicit `slip_scale_tensions_N` is used as given. + - CI runs the tests in parallel: the test matrix, the NumPy reference path and both coverage passes run on one pytest-xdist worker per core (`pytest-xdist` joins the `dev` extra). Every concurrent process writes its own numba cache: numba numbers a new cache entry from diff --git a/doc/benchmarks.md b/doc/benchmarks.md index 451136f..e36741c 100644 --- a/doc/benchmarks.md +++ b/doc/benchmarks.md @@ -116,7 +116,7 @@ model) is the full construction. | Gap T2 against Sævik (2011), Gjøsteen et al. (2027), Hu, Ménard and Witz | M | Not explained (former capstan bound throughout): Sævik near-bellmouth median ratio 3.36 (2.12 in the clamp convention) against 1.65 for the clamp correction and 1.03 sectional; Hu area +65%, share 11%; Ménard work −3 to +3 points by range; end conditions immaterial | | Two-way anchored termination: Sævik rig beam solved with the anchored along-wire chains of both armours | M | FAIL as registered (former capstan bound): median ratio 1.18 (9 of 14 in band), absolute 1.46; anchored over-prediction falls from 3.09 one-way (same stick setting) and 1.65 (clamp correction); curvature redistributes along the bellmouth instead of falling (TC-3 fails); hang-off rule stays sectional | | Anchored wire at uniform curvature against published FE: Dong et al. (2025), Zhu and Tan (2014) (AW-DONG25, AW-ZT14) | MM | Reported: Dong et al. verification case reproduced (anchor 156.4 against 156.9 MPa, peak +1.6 %); Zhu and Tan not reproduced (1.70 against 2.2 normalised at the neutral-axis anchor): their FE far field is in stick and their analytical field breaks the Coulomb flow rule | -| Hysteretic bending law for global analysis (gap MX): Iwan law from the exported backbone against `compute_mkappa` | I | MX-1 PASS (≤ 0.05 % of the moment range, work ≤ 0.02 %), MX-3 PASS, MX-scale PASS (slip scaling variable); MX-2 FAIL (tension interpolation 3.9 % at 100 kN spacing; 0.27 % at 20 kN); MX-5 (global program) open | +| Hysteretic bending law for global analysis (gap MX): Iwan law from the exported backbone against `compute_mkappa` | I | MX-1 PASS (≤ 0.05 % of the moment range, work ≤ 0.02 %), MX-3 PASS, MX-scale PASS (slip scaling variable), MX-group PASS (one law per friction group); MX-2 FAIL (tension interpolation 3.9 % at 100 kN spacing; 0.27 % at 20 kN); MX-5 (global program) open | | Cable over a sheave (gap SH): Feyrer (2015) Examples 3.2 and 3.4, groove factors, consistency with the section analyses | A, I | SH-1, SH-2, SH-3 PASS; no measured cable-over-sheave data held | | Gap T1, benchmarks in their published arrangements | M | Hu three-point: transition share in its band (32.8–39.4% against 33.8%), loop area FAIL (+37% Papailiou cap, +64% Karlsen-Husøy; +4.9%/+28% at uniform curvature compared a different quantity); Ménard four-point unchanged; Witz arrangement not documented, basis unchanged | | Torque balance (gap 3.5): Feyrer (2015) and Knapp (1981) closed forms, mirror lay, `xsec_stiffness` consistency | A, I | PASS | @@ -1196,10 +1196,10 @@ guide [global_local_guide.md](global_local_guide.md), Section 8. | MX-5 | MM | Hysteretic bending of a global program with the exported table | not run | open | | MX-scale | I | Slip scaling variable (`slip_scale=True`): bound homogeneity of `compute_mkappa` (66 kV, 20 → 70 kN, cores); group elements at 60 kN against the 10 kN elements with yield curvatures times `ρ_g` (Ménard); tension cycle 10–70 kN inside ±0.03 1/m bending, scaled law against the contact-tension history over the fixed-tension residual | 6.9e-16; 1.2e-13; 1.21 (1.02 before the support-cut shear stack; symmetric wire bounds on a breakpoint grid: 8e-15, work 7e-15) | PASS | | MX-scale-1 | I | One scale for all groups against the per-group law, 10–150 kN (reference 10 kN), backbone and cycles to 1.5 times full slip | 66 kV 0; 33 kV three-core 0.10 % (0.29 % with cores); Ménard 12 %; with p_e 0–2 MPa: 66 kV 21 %, 33 kV 12 %, Ménard 19 % | reported | -| MX-group-B | I | One law per friction group, each with its own scale table (`BendingLawExport.slip_group_laws`): sum over the groups of `s_g M_g(κ/s_g)` (the backbone table of the group at the reference, scaled by its own `s_g(T)`) against the exported backbone at the same tension (case below) | registered: at every grid curvature κ > 0 and every exported tension, within 0.5 % of the exported moment | registered | -| MX-group-E | I | Same laws, Masing replay: work of three symmetric cycles of amplitude 1e-3, 3e-3, 0.01, 0.03, 0.1 and 0.3 1/m, summed group laws against the exported law at the same tension | registered: within ±1 % | registered | -| MX-group-0 | A | The default scale table starts at zero tension: `s_g(0)` is the group cap of the contact model at zero tension over its reference cap | registered: without clamping `s_g(0) = 0` to 1e-12; with clamping the zero row equals the direct cap ratio at 0 N to 1e-12 rel., and the table scale at 5 kN equals the direct cap ratio at 5 kN to 1e-9 rel. (bounded chain, affine in tension) | registered | -| MX-group-1 | I | One cap-weighted scale for all groups (`per_group=False`) on the same case and measures | reported | reported | +| MX-group-B | I | One law per friction group, each with its own scale table (`BendingLawExport.slip_group_laws`): sum over the groups of `s_g M_g(κ/s_g)` (the backbone table of the group at the reference, scaled by its own `s_g(T)`) against the exported backbone at the same tension (case below) | target (registered): at every grid curvature κ > 0 and every exported tension, within 0.5 % of the exported moment. Result: 4.4e-4, 4.3e-4, 4.3e-4 at 0, 20, 40 MPa (the interpolation of the reference backbone between grid points) | PASS | +| MX-group-E | I | Same laws, Masing replay: work of three symmetric cycles of amplitude 1e-3, 3e-3, 0.01, 0.03, 0.1 and 0.3 1/m, summed group laws against the exported law at the same tension | target (registered): within ±1 %. Result: 0.99986–1.00019, 0.99997–1.00056, 0.99876–1.00084 at 0, 20, 40 MPa | PASS | +| MX-group-0 | A | The default scale table starts at zero tension: `s_g(0)` is the group cap of the contact model at zero tension over its reference cap | registered: without clamping `s_g(0) = 0` to 1e-12; with clamping the zero row equals the direct cap ratio at 0 N to 1e-12 rel., and the table scale at 5 kN equals the direct cap ratio at 5 kN to 1e-9 rel. (bounded chain, affine in tension). Result: 0 without clamping; `s_g(0)` 0.82–0.87 (20 MPa) and 0.90–0.93 (40 MPa) of the 10 kN reference, laid cores lowest; both identities to round-off | PASS | +| MX-group-1 | I | One cap-weighted scale for all groups (`per_group=False`) on the same case and measures | backbone 0.044 % (0 MPa), 5.3 % (20 MPa), 4.6 % (40 MPa); work 0.9999–1.0002, 0.938–1.073, 0.954–1.072 | reported | The armour laws are parallel spring–sliders at fixed contact pressure, so the Iwan law follows Masing's rules; it is exact when every wire's slip interval is symmetric. The signed capstan bound makes the interval asymmetric (the @@ -1217,6 +1217,11 @@ armour layers (assumed clamping states, the 0 MPa case without manufacturing cla The elastic full-slip part `EI_slip κ` is carried by the first group (scaling leaves it unchanged). Tests: `tests/test_bending_law_groups.py`. +With clamping the laid cores scale unlike the armour (at 10 kN and 20 MPa the cores sit at 0.39 of their 100 kN +cap, the armour and the profiles at 0.46), which is why one scale for all groups misses the backbone by 5 % (MX-group-1) +while the summed group laws stay within 4.4e-4: the residual is the linear interpolation of each reference backbone +between its grid points, not the scaling. + ## Cable over a sheave (gap SH) Code `cablexsec/analysis/sheave.py` (`compute_sheave`, `sheave_contact`, `groove_pressure`); diff --git a/doc/file_formats.md b/doc/file_formats.md index eaf315b..3b7419d 100644 --- a/doc/file_formats.md +++ b/doc/file_formats.md @@ -683,7 +683,31 @@ tension_N,external_pressure_Pa,s,ds_dT_1_per_N,s_inner_armour,ds_dT_inner_armour ``` With a pressure axis the columns `ds_dpe_1_per_Pa` and -`ds_dpe__1_per_Pa` follow each `ds_dT` column. `Project` files store the +`ds_dpe__1_per_Pa` follow each `ds_dT` column. By default the table +starts at zero tension (guide Section 8.1). + +`BendingLawExport.to_group_csv(directory)` writes one law per friction group +for a global model that sums them: `_backbone.csv` (the backbone of the +group at the reference state on the export grid, after two comment lines that +name the group and give the slope beyond the last point) and +`_slip_scale.csv` (the group's own scale `s_g`): + +```text +# friction group laid_cores (laid_cores); scale s_laid_cores(T) in the group's scale table; M_g(kappa, T) = s B(kappa / s) +# beyond the last point the backbone continues with slope 0.000000000e+00 N m2 +kappa_1_m,M_Nm +0.000000000e+00,0.000000000e+00 +... +``` + +```text +tension_N,external_pressure_Pa,s,ds_dT_1_per_N +0.000000000e+00,0.000000000e+00,0.000000000e+00,1.000000000e-04 +... +``` + +The law of group `g` at tension `T` is `s_g(T) B_g(κ / s_g(T))`; the first +group carries the elastic full-slip part, the others none. `Project` files store the table with the law; project files written before it existed still load. `cablexsec.io.global_export` also writes the section properties of a set of diff --git a/doc/global_local_guide.md b/doc/global_local_guide.md index 1ea5f15..64e5c8e 100644 --- a/doc/global_local_guide.md +++ b/doc/global_local_guide.md @@ -556,6 +556,12 @@ capstan bound included, and its Iwan elements keep their stiffnesses `k_i` while `s = Σ R_g / Σ R_g,ref`, and their derivatives `∂/∂T` and `∂/∂p_e` (central differences of the contact model, one-sided at zero; the bounded chain is affine, so they are its slopes). +By default the table runs over the exported tensions with zero tension in front. At zero tension the caps are those +of the contact model: zero without manufacturing clamping (every contact load then comes from the tension, so +`s → 0` and the law tends to its elastic part), the clamping caps otherwise (66 kV template with cores and profiles +at 20 MPa winding stress: `ρ_g(0)` 0.82–0.87 of the 10 kN reference). A global model then interpolates the scale +down to zero tension instead of holding its lowest value. An explicit `slip_scale_tensions_N` is used as given. + ```python export = cx.export_bending_law( cable, tensions_N=[10e3, 70e3], kappa_max_1_m=0.036, n_points=300, @@ -566,8 +572,19 @@ table = export.slip_scale law = table.law_at(35e3, 0.5e6) # scaled law at one state moment = table.moment(kappa, tension, pressure) # sliders follow the changing caps table.to_csv("slip_scale.csv") # s, rho_g and derivatives per state +groups = export.slip_group_laws() # one law per friction group +moment = sum(g.backbone_at(kappa, 35e3) for g in groups) # sum of s_g B_g(kappa / s_g) +export.to_group_csv("groups") # _backbone.csv, _slip_scale.csv ``` +One law per group. A global model that takes one scale per law can still carry the per-group scaling: it takes one +law per friction group, `M_g(κ; T) = s_g(T) B_g(κ / s_g(T))`, with `B_g` the backbone of the group at the reference +(`SlipGroupLaw`, from `BendingLawExport.slip_group_laws()`) and `s_g = ρ_g` its own scale, and sums the group laws. +The first group carries the elastic part `EI_slip κ` (the scaling leaves it unchanged); the others end on the +plateau of their full-slip friction moment. `to_group_csv` writes each backbone (`kappa_1_m,M_Nm`, with two `# ` +lines that name the group and the slope beyond the last point) and each scale table (`tension_N, +external_pressure_Pa, s, ds_dT_1_per_N`, plus `ds_dpe_1_per_Pa` with a pressure axis). + Slider update. When the state changes, every element follows the return map with the new cap, `e_i ← clip(e_i + Δκ, −ρ_g κ_y,i, ρ_g κ_y,i)` and `M = EI_slip κ + Σ k_i e_i`: the slip state is carried across, a falling cap clips a sticking or slipping element at fixed curvature (friction work, `k_i |e_1| |e_0 − e_1|` in the @@ -587,7 +604,11 @@ Checks (`tests/test_bending_law_slip_scale.py`; row MX-scale of the [benchmark r 43 %. One scale or one per group. The single scale `s` keeps the stick stiffness and the full-slip moment exact and is -exact when every group scales alike. Otherwise it misplaces the transition. Largest error of the single-scale law +exact when every group scales alike. Otherwise it misplaces the transition. With armour clamping the laid cores +scale unlike the armour: on the 66 kV template with cores and filler profiles (μ 0.46) at 20 and 40 MPa winding +stress, 10–200 kN, one scale misses the exported backbone by up to 5.3 % and the cycle work by up to 7 %, while the +summed group laws stay within 4.4e-4 and 0.13 % (rows MX-group-B, MX-group-E and MX-group-1 of the +[benchmark register](benchmarks.md)). Largest error of the single-scale law against the per-group law over 10–150 kN, reference 10 kN, on the virgin backbone and on cycles up to 1.5 times the full-slip curvature (moment in % of the range; work per cycle at 1.5 times full slip): diff --git a/src/cablexsec/__init__.py b/src/cablexsec/__init__.py index 998c8df..98ae03e 100644 --- a/src/cablexsec/__init__.py +++ b/src/cablexsec/__init__.py @@ -52,6 +52,7 @@ from cablexsec.analysis.bending_law import ( BendingLawExport, IwanBendingLaw, + SlipGroupLaw, SlipScaleTable, export_bending_law, ) @@ -334,6 +335,7 @@ __all__ = [ "BendingLawExport", "IwanBendingLaw", + "SlipGroupLaw", "SlipScaleTable", "export_bending_law", "LayerSlipCurvatures", diff --git a/src/cablexsec/analysis/bending_law.py b/src/cablexsec/analysis/bending_law.py index 164b6ac..de66a8d 100644 --- a/src/cablexsec/analysis/bending_law.py +++ b/src/cablexsec/analysis/bending_law.py @@ -115,6 +115,7 @@ "FILLER_GROUP", "BendingLawExport", "IwanBendingLaw", + "SlipGroupLaw", "SlipScaleTable", "export_bending_law", ] @@ -735,6 +736,227 @@ def to_csv(self, path: str | Path) -> Path: out.write_text(self.csv_text(), encoding="utf-8") return out + def group_law(self, index: int, kappa_1_m: ArrayLike) -> SlipGroupLaw: + """Friction group ``index`` as a law of its own (:class:`SlipGroupLaw`). + + ``kappa_1_m`` is the curvature grid of the export (the grid the group + laws were decomposed on). The first group carries the elastic + full-slip part ``EI_slip kappa``. + """ + if not 0 <= index < len(self.group_names): + raise CableInputError( + f"group index {index} outside 0-{len(self.group_names) - 1}" + ) + kappa = np.asarray(kappa_1_m, dtype=np.float64) + law = self.group_laws[index] + if kappa.ndim != 1 or kappa.size != law.stiffness_Nm2.size + 1: + raise CableInputError( + "the curvature grid must be the export grid of the group laws" + ) + elastic = self.ei_slip_Nm2 if index == 0 else 0.0 + name = self.group_names[index] + return SlipGroupLaw( + name=name, + kind=name if name in (CORE_GROUP, FILLER_GROUP) else "armour_layer", + kappa_1_m=kappa, + law=IwanBendingLaw(elastic, law.stiffness_Nm2, law.yield_curvature_1_m), + table=self, + index=index, + ) + + +@dataclass(frozen=True) +class SlipGroupLaw: + r"""One friction group of a slip-scaled law, as a law of its own. + + The global model sums the group laws. Group ``g`` is the backbone + ``B_g(kappa)`` of the group at the reference state (``law``, on the + export's curvature grid) with its own scale ``s_g`` over the table states + (the ``rho_g`` of :class:`SlipScaleTable`): + + .. math:: + + M_g(\kappa; T) = s_g(T)\, B_g(\kappa / s_g(T)), \qquad + M = \sum_g M_g , + + and under a changing state every element follows the return map with the + cap of the current sample (:meth:`moment`). The first group carries the + elastic full-slip part ``EI_slip kappa`` (``law.ei_slip_Nm2``), which the + scaling leaves unchanged; every other group has no elastic part, so its + backbone ends on the plateau of its full-slip friction moment. A group of + zero scale (no contact) carries its elastic part only. + + Attributes + ---------- + name, kind : str + Group name (the armour layer, :data:`CORE_GROUP` or + :data:`FILLER_GROUP`) and kind (``"armour_layer"``, ``"laid_cores"`` + or ``"filler_profiles"``). + kappa_1_m : numpy.ndarray + Curvature grid of the backbone [1/m], from zero. + law : IwanBendingLaw + Elements of the group at the reference state. + table : SlipScaleTable + The table the group belongs to. + index : int + Position of the group in ``table.group_names``. + """ + + name: str + kind: str + kappa_1_m: FloatArray + law: IwanBendingLaw + table: SlipScaleTable + index: int + + @property + def moment_Nm(self) -> FloatArray: + """Backbone ``B_g`` at the reference state on ``kappa_1_m`` [N m].""" + return self.law.backbone(self.kappa_1_m) + + @property + def tension_N(self) -> FloatArray: + """Table tensions [N].""" + return self.table.tension_N + + @property + def scale(self) -> FloatArray: + """``s_g`` at the table states, shape (tensions, pressures).""" + return np.asarray(self.table.group_scale[self.index]) + + @property + def scale_dT_1_per_N(self) -> FloatArray: + """``d s_g / dT`` [1/N] at the table states.""" + return np.asarray(self.table.group_scale_dT_1_per_N[self.index]) + + def scale_at( + self, tension_N: ArrayLike, external_pressure_Pa: ArrayLike | None = None + ) -> FloatArray: + """``s_g`` at states (linear interpolation in the table), shape (samples,).""" + return np.asarray( + self.table.group_scales(tension_N, external_pressure_Pa)[self.index] + ) + + def law_at( + self, tension_N: float, external_pressure_Pa: float | None = None + ) -> IwanBendingLaw: + """The group law at one state: yield curvatures times ``s_g``. + + Elements of a zero scale are dropped (the group has no friction). + """ + rho = float( + self.scale_at( + [tension_N], + None if external_pressure_Pa is None else [external_pressure_Pa], + )[0] + ) + keep = (self.law.yield_curvature_1_m * rho) > 0.0 + return IwanBendingLaw( + self.law.ei_slip_Nm2, + self.law.stiffness_Nm2[keep], + self.law.yield_curvature_1_m[keep] * rho, + ) + + def backbone_at( + self, + kappa_1_m: ArrayLike, + tension_N: float, + external_pressure_Pa: float | None = None, + ) -> FloatArray: + """Virgin backbone at one state, ``s_g B_g(kappa / s_g)`` [N m]. + + The table form a global model applies: the reference backbone + (piecewise linear through the grid points, continued by its tail + slope) at the curvature divided by the scale, times the scale. + """ + k = np.asarray(kappa_1_m, dtype=np.float64) + rho = float( + self.scale_at( + [tension_N], + None if external_pressure_Pa is None else [external_pressure_Pa], + )[0] + ) + if rho <= 0.0: + return np.asarray(self.law.ei_slip_Nm2 * k) + return np.asarray(rho * self.law.backbone(k / rho)) + + def moment( + self, + kappa_history: ArrayLike, + tension_history_N: ArrayLike, + external_pressure_history_Pa: ArrayLike | None = None, + ) -> FloatArray: + """Moment history of the group [N m] under curvature and state histories. + + From the virgin state; every element follows the return map with the + cap ``s_g kappa_y,i`` of the current sample, as in + :meth:`SlipScaleTable.moment`. + """ + kappa = np.asarray(kappa_history, dtype=np.float64) + if kappa.ndim != 1 or not np.isfinite(kappa).all(): + raise CableInputError("curvature history must be a finite 1-D array") + tension = np.asarray(tension_history_N, dtype=np.float64) + if tension.shape != kappa.shape: + raise CableInputError("tension history must match the curvature history") + pressure = None + if external_pressure_history_Pa is not None: + pressure = np.asarray(external_pressure_history_Pa, dtype=np.float64) + if pressure.shape != kappa.shape: + raise CableInputError( + "external-pressure history must match the curvature history" + ) + rho = self.scale_at(tension, pressure) + k, y = self.law.stiffness_Nm2, self.law.yield_curvature_1_m + e = np.zeros_like(k) + out = np.empty_like(kappa) + previous = 0.0 + for n, value in enumerate(kappa): + bound = y * rho[n] + e = np.clip(e + (value - previous), -bound, bound) + previous = value + out[n] = self.law.ei_slip_Nm2 * value + float(e @ k) + return out + + def backbone_csv_text(self) -> str: + """``kappa_1_m,M_Nm``: the reference backbone ``B_g`` on the grid. + + Two comment lines (``# ``) name the group and the slope that continues + the backbone beyond its last point. + """ + rows = [ + f"# friction group {self.name} ({self.kind}); scale s_{self.name}(T) in " + f"the group's scale table; M_g(kappa, T) = s B(kappa / s)", + f"# beyond the last point the backbone continues with slope " + f"{self.law.ei_slip_Nm2:.9e} N m2", + "kappa_1_m,M_Nm", + ] + rows += [ + f"{float(k):.9e},{float(m):.9e}" + for k, m in zip(self.kappa_1_m, self.moment_Nm, strict=True) + ] + return "\n".join(rows) + "\n" + + def scale_csv_text(self) -> str: + """One row per table state: tension, pressure, ``s_g`` and derivatives.""" + table = self.table + pressures = ( + np.array([table.reference_external_pressure_Pa]) + if table.external_pressure_Pa is None + else table.external_pressure_Pa + ) + header = ["tension_N", "external_pressure_Pa", "s", "ds_dT_1_per_N"] + rho_p = table.group_scale_dpe_1_per_Pa + if rho_p is not None: + header.append("ds_dpe_1_per_Pa") + rows = [",".join(header)] + for i, tension in enumerate(table.tension_N): + for j, pressure in enumerate(pressures): + row = [tension, pressure, self.scale[i, j], self.scale_dT_1_per_N[i, j]] + if rho_p is not None: + row.append(rho_p[self.index, i, j]) + rows.append(",".join(f"{float(v):.9e}" for v in row)) + return "\n".join(rows) + "\n" + @dataclass(frozen=True) class BendingLawExport: @@ -769,6 +991,40 @@ def law_at(self, tension_N: float) -> IwanBendingLaw: ei = (1 - w) * self.ei_slip_Nm2[j] + w * self.ei_slip_Nm2[j + 1] return IwanBendingLaw.from_backbone(self.kappa_1_m, moment, float(ei)) + def slip_group_laws(self) -> tuple[SlipGroupLaw, ...]: + """One law per friction group, each with its own scale table. + + The global model sums them (:class:`SlipGroupLaw`); needs the export's + slip scale (``slip_scale=True``). + """ + if self.slip_scale is None: + raise CableInputError( + "the group laws need the slip scale: export with slip_scale=True" + ) + table = self.slip_scale + return tuple( + table.group_law(g, self.kappa_1_m) for g in range(len(table.group_names)) + ) + + def to_group_csv(self, directory: str | Path) -> list[Path]: + """Write ``_backbone.csv`` and ``_slip_scale.csv`` per group. + + The backbone files hold the reference backbone of every group + (:meth:`SlipGroupLaw.backbone_csv_text`), the scale files its own + ``s_g(T)`` (:meth:`SlipGroupLaw.scale_csv_text`). Returns the paths in + group order, backbone before scale. + """ + folder = Path(directory) + folder.mkdir(parents=True, exist_ok=True) + paths: list[Path] = [] + for group in self.slip_group_laws(): + backbone = folder / f"{group.name}_backbone.csv" + backbone.write_text(group.backbone_csv_text(), encoding="utf-8") + scale = folder / f"{group.name}_slip_scale.csv" + scale.write_text(group.scale_csv_text(), encoding="utf-8") + paths += [backbone, scale] + return paths + def to_csv(self, path: str | Path) -> Path: """Backbones as columns ``kappa_1_m, M_N_Nm, ...``.""" out = Path(path) @@ -883,7 +1139,13 @@ def export_bending_law( 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``). + Ascending tensions of the table [N]. The default is ``tensions_N`` + with zero tension in front (when the lowest exported tension is + positive): the table runs to zero with the caps of the contact model + at zero tension, which are zero without clamping (every contact load + then comes from the tension, and ``s -> 0``) and the clamping caps + otherwise, so a global model need not hold the lowest scale below + the lowest exported tension. slip_scale_external_pressure_Pa : sequence of float, optional Ascending external pressures of the table [Pa]. ``None`` (default) runs the table over tension only, at the cable's initial external @@ -1031,7 +1293,11 @@ def export_bending_law( kappa, reference_N=reference_N, candidates_N=t, - tensions_N=t if slip_scale_tensions_N is None else slip_scale_tensions_N, + tensions_N=( + _default_table_tensions(t) + if slip_scale_tensions_N is None + else slip_scale_tensions_N + ), external_pressure_Pa=slip_scale_external_pressure_Pa, options=mkappa_options, ) @@ -1118,6 +1384,18 @@ def _friction_cap(spec: HelicalLayerSpec) -> float: ) +def _default_table_tensions(tensions: FloatArray) -> FloatArray: + """The exported tensions with zero tension in front. + + The scale table then runs to zero tension with the caps of the contact + model there (zero without clamping, where every contact load comes from + the tension), instead of ending at the lowest exported tension. + """ + if tensions[0] > 0.0: + return np.concatenate([[0.0], tensions]) + return tensions + + def _ascending(values: ArrayLike, label: str) -> FloatArray: grid = np.asarray(values, dtype=np.float64) if ( diff --git a/tests/test_bending_law_groups.py b/tests/test_bending_law_groups.py new file mode 100644 index 0000000..83bf698 --- /dev/null +++ b/tests/test_bending_law_groups.py @@ -0,0 +1,294 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +"""One exported law per friction group, each with its own scale table. + +Rows MX-group-B, MX-group-E and MX-group-0 of ``doc/benchmarks.md`` (gap MX), +registered before the run: the 66 kV template with the laid cores, the +filler profiles and armour clamping, whose groups scale differently with +tension. The global model sums the group laws ``s_g B_g(kappa / s_g)``. +""" + +from __future__ import annotations + +import math + +import numpy as np +import pytest + +import cablexsec as cx +import cablexsec.analysis.bending_law as bending_law +from cablexsec.analysis.bending_law import ( + CORE_GROUP, + FILLER_GROUP, + SlipGroupLaw, + export_bending_law, +) +from cablexsec.api import CoreFrictionSpec +from cablexsec.exceptions import CableInputError + +pytestmark = [ + pytest.mark.analytical_sanity, + pytest.mark.filterwarnings( + "ignore::cablexsec.provenance.MissingClampingStateWarning" + ), +] + +TENSIONS = (1.0e4, 2.5e4, 5.0e4, 1.0e5, 1.5e5, 2.0e5) +AMPLITUDES = (1.0e-3, 3.0e-3, 1.0e-2, 3.0e-2, 0.1, 0.3) +CORES = CoreFrictionSpec( + mu_core_filler=0.46, mu_core_core=0.46, mu_core_sheath=0.46, filler_profiles=True +) +#: Registered targets (doc/benchmarks.md, MX-group). +BACKBONE_TOLERANCE = 5e-3 +ENERGY_TOLERANCE = 1e-2 + + +@pytest.fixture(scope="module") +def iea66(): + return cx.load_cable(cx.iea_task49_66kv_yaml_path(), geometry_override=None) + + +def _wound(cable, sigma_Pa): + """The cable with an armour winding stress on both armour layers.""" + layers = tuple( + x.model_copy(update={"winding_stress_Pa": sigma_Pa}) + if x.name in {"inner_armour", "outer_armour"} + else x + for x in cable.layers + ) + return cable.model_copy(update={"layers": layers}) + + +@pytest.fixture( + scope="module", params=[0.0, 20.0e6, 40.0e6], ids=["0MPa", "20MPa", "40MPa"] +) +def case(request, iea66): + cable = _wound(iea66, request.param) if request.param else iea66 + export = export_bending_law( + cable, + tensions_N=TENSIONS, + kappa_max_1_m=0.4, + n_points=200, + slip_scale=True, + core_friction=CORES, + ) + return request.param, cable, export + + +def _cycles(amplitude, per_cycle=200, cycles=3): + t = np.linspace(0.0, 2.0 * math.pi * cycles, per_cycle * cycles + 1) + return amplitude * np.sin(t) + + +def test_groups_and_their_scales_differ_with_clamping(case): + sigma, _, export = case + groups = export.slip_group_laws() + assert [g.name for g in groups] == [ + "inner_armour", + "outer_armour", + CORE_GROUP, + FILLER_GROUP, + ] + assert [g.kind for g in groups] == [ + "armour_layer", + "armour_layer", + CORE_GROUP, + FILLER_GROUP, + ] + # The first group carries the elastic full-slip part; the others none. + assert groups[0].law.ei_slip_Nm2 == export.slip_scale.ei_slip_Nm2 + assert all(g.law.ei_slip_Nm2 == 0.0 for g in groups[1:]) + high = np.array([g.scale_at([TENSIONS[-1]])[0] for g in groups]) + if sigma == 0.0: + np.testing.assert_allclose(high, TENSIONS[-1] / TENSIONS[0], rtol=1e-9) + else: + # With clamping the laid-core group scales unlike the armour. + assert np.ptp(high) / np.min(high) > 0.05 + + +def test_mx_group_b_summed_backbones_reproduce_the_export(case): + """MX-group-B: within 0.5 % of the exported moment at every curvature.""" + _, _, export = case + groups = export.slip_group_laws() + kappa = export.kappa_1_m[1:] + worst = 0.0 + for i, tension in enumerate(export.tension_N): + total = sum(g.backbone_at(kappa, float(tension)) for g in groups) + reference = export.moment_Nm[i, 1:] + worst = max(worst, float(np.max(np.abs(total / reference - 1.0)))) + assert worst <= BACKBONE_TOLERANCE + + +def test_mx_group_e_summed_loop_work_reproduces_the_export(case): + """MX-group-E: work of three symmetric cycles within +-1 %.""" + _, _, export = case + groups = export.slip_group_laws() + for i, tension in enumerate(export.tension_N): + laws = [g.law_at(float(tension)) for g in groups] + for amplitude in AMPLITUDES: + history = _cycles(amplitude) + reference = export.laws[i].dissipated_energy(history) + summed = sum(law.dissipated_energy(history) for law in laws) + assert summed == pytest.approx(reference, rel=ENERGY_TOLERANCE) + + +def test_mx_group_0_table_runs_to_zero_tension(case): + """MX-group-0: the default table starts at zero with the contact model's caps.""" + sigma, cable, export = case + table = export.slip_scale + assert table.tension_N[0] == 0.0 + np.testing.assert_array_equal(table.tension_N[1:], export.tension_N) + contact, common = bending_law._law_options({"core_friction": CORES}) + reference = table.reference_cap_Nm + + def direct(tension): + state = bending_law._state_law(cable, tension, None, contact, common) + return bending_law._group_caps(state) / reference + + if sigma == 0.0: + assert np.max(np.abs(table.group_scale[:, 0, 0])) <= 1e-12 + else: + zero = direct(0.0) + assert np.all(zero > 0.0) + np.testing.assert_allclose(table.group_scale[:, 0, 0], zero, rtol=1e-12) + np.testing.assert_allclose( + table.group_scales([5.0e3])[:, 0], direct(5.0e3), rtol=1e-9, atol=1e-12 + ) + + +def test_single_scale_is_reported_beside_the_groups(case): + """MX-group-1 (reported): one cap-weighted scale for all groups.""" + sigma, _, export = case + table = export.slip_scale + kappa = export.kappa_1_m[1:] + worst = 0.0 + for i, tension in enumerate(export.tension_N): + single = table.law_at(float(tension), per_group=False).backbone(kappa) + worst = max(worst, float(np.max(np.abs(single / export.moment_Nm[i, 1:] - 1)))) + if sigma == 0.0: + assert worst <= BACKBONE_TOLERANCE + else: + assert worst > BACKBONE_TOLERANCE + + +def test_group_moment_history_and_zero_scale(iea66): + export = export_bending_law( + iea66, + tensions_N=[2.0e4, 6.0e4], + kappa_max_1_m=2e-3, + n_points=40, + slip_scale=True, + ) + groups = export.slip_group_laws() + table = export.slip_scale + t = np.arange(400) + kappa = 1.5e-3 * np.sin(2 * math.pi * t / 100 + 0.1) + tension = 2.0e4 + 4.0e4 * np.sin(math.pi * t / 170) ** 2 + total = sum(g.moment(kappa, tension) for g in groups) + np.testing.assert_allclose( + total, table.moment(kappa, tension), rtol=0, atol=1e-12 * np.ptp(total) + ) + # Zero tension: no contact without clamping, the elastic part alone. + k = np.linspace(0.0, 2e-3, 11) + np.testing.assert_allclose( + groups[0].backbone_at(k, 0.0), table.ei_slip_Nm2 * k, rtol=1e-15 + ) + assert np.all(groups[1].backbone_at(k, 0.0) == 0.0) + assert groups[1].law_at(0.0).stiffness_Nm2.size == 0 + # Virgin backbone at a table state is the merged law at that state. + merged = table.law_at(6.0e4) + np.testing.assert_allclose( + sum(g.backbone_at(k, 6.0e4) for g in groups), + merged.backbone(k), + rtol=1e-12, + ) + np.testing.assert_allclose( + groups[0].moment_Nm, groups[0].law.backbone(export.kappa_1_m) + ) + np.testing.assert_array_equal(groups[0].tension_N, table.tension_N) + with pytest.raises(CableInputError, match="tension history"): + groups[0].moment(kappa, tension[:-1]) + with pytest.raises(CableInputError, match="curvature history"): + groups[0].moment(np.array([[0.0]]), np.array([[0.0]])) + with pytest.raises(CableInputError, match="external-pressure"): + groups[0].moment(kappa, tension, np.zeros(3)) + + +def test_group_csv_files(iea66, tmp_path): + export = export_bending_law( + iea66, + tensions_N=[2.0e4, 6.0e4], + kappa_max_1_m=2e-3, + n_points=20, + slip_scale=True, + slip_scale_tensions_N=[2.0e4, 6.0e4], + slip_scale_external_pressure_Pa=[0.0, 1.0e6], + ) + paths = export.to_group_csv(tmp_path / "groups") + names = [p.name for p in paths] + assert names == [ + "inner_armour_backbone.csv", + "inner_armour_slip_scale.csv", + "outer_armour_backbone.csv", + "outer_armour_slip_scale.csv", + ] + lines = paths[0].read_text("utf-8").splitlines() + assert lines[0].startswith("# friction group inner_armour (armour_layer)") + assert lines[2] == "kappa_1_m,M_Nm" + data = np.loadtxt(paths[0], delimiter=",", skiprows=3) + group = export.slip_group_laws()[0] + np.testing.assert_allclose(data[:, 0], export.kappa_1_m, rtol=1e-8) + np.testing.assert_allclose(data[:, 1], group.moment_Nm, rtol=1e-8, atol=1e-12) + scale = paths[3].read_text("utf-8").splitlines() + assert scale[0] == "tension_N,external_pressure_Pa,s,ds_dT_1_per_N,ds_dpe_1_per_Pa" + assert len(scale) == 1 + 2 * 2 + row = np.array(scale[2].split(","), dtype=float) + outer = export.slip_group_laws()[1] + assert row[:2].tolist() == [2.0e4, 1.0e6] + assert row[2] == pytest.approx(outer.scale[0, 1], rel=1e-8) + assert row[4] == pytest.approx( + export.slip_scale.group_scale_dpe_1_per_Pa[1, 0, 1], rel=1e-8 + ) + tension_only = export_bending_law( + iea66, tensions_N=[2.0e4], kappa_max_1_m=2e-3, n_points=20, slip_scale=True + ) + text = tension_only.slip_group_laws()[0].scale_csv_text().splitlines() + assert text[0] == "tension_N,external_pressure_Pa,s,ds_dT_1_per_N" + assert [float(x.split(",")[0]) for x in text[1:]] == [0.0, 2.0e4] + + +def test_group_law_checks(iea66): + plain = export_bending_law( + iea66, tensions_N=[2.0e4], kappa_max_1_m=2e-3, n_points=20 + ) + with pytest.raises(CableInputError, match="slip_scale=True"): + plain.slip_group_laws() + export = export_bending_law( + iea66, tensions_N=[2.0e4], kappa_max_1_m=2e-3, n_points=20, slip_scale=True + ) + table = export.slip_scale + with pytest.raises(CableInputError, match="group index"): + table.group_law(5, export.kappa_1_m) + with pytest.raises(CableInputError, match="export grid"): + table.group_law(0, export.kappa_1_m[:-1]) + group = table.group_law(1, export.kappa_1_m) + assert isinstance(group, SlipGroupLaw) and group.index == 1 + # An explicit table axis is used as given (no zero row added). + explicit = export_bending_law( + iea66, + tensions_N=[2.0e4], + kappa_max_1_m=2e-3, + n_points=20, + slip_scale=True, + slip_scale_tensions_N=[2.0e4, 4.0e4], + ) + np.testing.assert_array_equal(explicit.slip_scale.tension_N, [2.0e4, 4.0e4]) + # A table that already starts at zero keeps one zero row. + from_zero = export_bending_law( + iea66, + tensions_N=[0.0, 2.0e4], + kappa_max_1_m=2e-3, + n_points=20, + slip_scale=True, + ) + np.testing.assert_array_equal(from_zero.slip_scale.tension_N, [0.0, 2.0e4]) diff --git a/tests/test_bending_law_slip_scale.py b/tests/test_bending_law_slip_scale.py index 0c26409..81d66d2 100644 --- a/tests/test_bending_law_slip_scale.py +++ b/tests/test_bending_law_slip_scale.py @@ -153,7 +153,8 @@ 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 default table starts at zero tension: no clamping, no contact. + np.testing.assert_allclose(table.scale[:, 0], [0.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( diff --git a/validation/validation_report.md b/validation/validation_report.md index 45f5579..decac77 100644 --- a/validation/validation_report.md +++ b/validation/validation_report.md @@ -80,7 +80,7 @@ Every row is computed from published data or closed-form references in this repo ## Test taxonomy (full gate suite) -- analytical_sanity: `1200 passed` +- analytical_sanity: `RECOUNT passed` - independent_method: `77 passed` - full_scale: `58 passed` From e9cfd79e84093556d730d051e22784f99e363762 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Thu, 19 Nov 2026 16:47:11 +0900 Subject: [PATCH 3/4] fix: group CSV file names are safe file-name components A friction group is named after its armour layer, a free string: a name with a slash or "../" made to_group_csv fail or write outside the directory. The file stem now keeps letters, digits, ".", "-" and "_", turns every other character into "_", gives a dots-only or empty stem the name "group" and numbers stems that would meet (case-insensitive); the backbone file's comment line keeps the group name itself. Signed-off-by: Jae Hoon Seo --- doc/file_formats.md | 5 ++- src/cablexsec/analysis/bending_law.py | 48 ++++++++++++++++++++++++--- tests/test_bending_law_groups.py | 35 +++++++++++++++++++ 3 files changed, 82 insertions(+), 6 deletions(-) diff --git a/doc/file_formats.md b/doc/file_formats.md index 3b7419d..6d904b0 100644 --- a/doc/file_formats.md +++ b/doc/file_formats.md @@ -690,7 +690,10 @@ starts at zero tension (guide Section 8.1). for a global model that sums them: `_backbone.csv` (the backbone of the group at the reference state on the export grid, after two comment lines that name the group and give the slope beyond the last point) and -`_slip_scale.csv` (the group's own scale `s_g`): +`_slip_scale.csv` (the group's own scale `s_g`). `` is the group name +with every character other than a letter, a digit, `.`, `-` or `_` replaced by +`_` (a numbered suffix where two names would meet); the comment line keeps the +name itself: ```text # friction group laid_cores (laid_cores); scale s_laid_cores(T) in the group's scale table; M_g(kappa, T) = s B(kappa / s) diff --git a/src/cablexsec/analysis/bending_law.py b/src/cablexsec/analysis/bending_law.py index de66a8d..737009c 100644 --- a/src/cablexsec/analysis/bending_law.py +++ b/src/cablexsec/analysis/bending_law.py @@ -1011,16 +1011,24 @@ def to_group_csv(self, directory: str | Path) -> list[Path]: The backbone files hold the reference backbone of every group (:meth:`SlipGroupLaw.backbone_csv_text`), the scale files its own - ``s_g(T)`` (:meth:`SlipGroupLaw.scale_csv_text`). Returns the paths in - group order, backbone before scale. + ``s_g(T)`` (:meth:`SlipGroupLaw.scale_csv_text`). ```` is the + group name made a safe file name (:func:`_file_stem`: letters, + digits, ``.``, ``-`` and ``_`` kept, anything else ``_``, a numbered + suffix where two names would meet); the first comment line of the + backbone file keeps the name itself. Every file lies in + ``directory``. Returns the paths in group order, backbone before + scale. """ folder = Path(directory) folder.mkdir(parents=True, exist_ok=True) + groups = self.slip_group_laws() paths: list[Path] = [] - for group in self.slip_group_laws(): - backbone = folder / f"{group.name}_backbone.csv" + for group, stem in zip( + groups, _file_stems([g.name for g in groups]), strict=True + ): + backbone = folder / f"{stem}_backbone.csv" backbone.write_text(group.backbone_csv_text(), encoding="utf-8") - scale = folder / f"{group.name}_slip_scale.csv" + scale = folder / f"{stem}_slip_scale.csv" scale.write_text(group.scale_csv_text(), encoding="utf-8") paths += [backbone, scale] return paths @@ -1384,6 +1392,36 @@ def _friction_cap(spec: HelicalLayerSpec) -> float: ) +def _file_stem(name: str) -> str: + """A group name as one safe file-name component. + + Letters, digits, ``.``, ``-`` and ``_`` are kept and every other + character becomes ``_``; a stem of dots only (``.``, ``..``) or an empty + one becomes ``group``, so the component never leaves its directory. + """ + stem = "".join( + c if (c.isascii() and c.isalnum()) or c in "._-" else "_" for c in name + ) + if not stem.strip("."): + return "group" + return stem + + +def _file_stems(names: Sequence[str]) -> list[str]: + """Distinct safe stems (case-insensitive) of the group names, in order.""" + stems: list[str] = [] + taken: set[str] = set() + for name in names: + base = stem = _file_stem(name) + count = 1 + while stem.lower() in taken: + count += 1 + stem = f"{base}_{count}" + taken.add(stem.lower()) + stems.append(stem) + return stems + + def _default_table_tensions(tensions: FloatArray) -> FloatArray: """The exported tensions with zero tension in front. diff --git a/tests/test_bending_law_groups.py b/tests/test_bending_law_groups.py index 83bf698..ba1eefd 100644 --- a/tests/test_bending_law_groups.py +++ b/tests/test_bending_law_groups.py @@ -257,6 +257,41 @@ def test_group_csv_files(iea66, tmp_path): assert [float(x.split(",")[0]) for x in text[1:]] == [0.0, 2.0e4] +def test_group_csv_file_names_stay_in_the_directory(iea66, tmp_path): + from cablexsec.analysis.bending_law import _file_stem, _file_stems + + assert _file_stem("armour/inner") == "armour_inner" + assert _file_stem("../../etc") == ".._.._etc" + assert _file_stem("..") == "group" and _file_stem("") == "group" + assert _file_stem("C:\\x y") == "C__x_y" + assert _file_stems(["a/b", "a_b", "A_B", "laid_cores"]) == [ + "a_b", + "a_b_2", + "A_B_3", + "laid_cores", + ] + names = {"inner_armour": "armour/inner", "outer_armour": "../outer"} + layers = tuple( + x.model_copy(update={"name": names[x.name]}) if x.name in names else x + for x in iea66.layers + ) + renamed = iea66.model_copy(update={"layers": layers}) + export = export_bending_law( + renamed, tensions_N=[2.0e4], kappa_max_1_m=2e-3, n_points=20, slip_scale=True + ) + folder = tmp_path / "out" + paths = export.to_group_csv(folder) + assert [p.name for p in paths] == [ + "armour_inner_backbone.csv", + "armour_inner_slip_scale.csv", + ".._outer_backbone.csv", + ".._outer_slip_scale.csv", + ] + assert all(p.parent == folder and p.is_file() for p in paths) + first = paths[0].read_text("utf-8").splitlines()[0] + assert first.startswith("# friction group armour/inner (armour_layer)") + + def test_group_law_checks(iea66): plain = export_bending_law( iea66, tensions_N=[2.0e4], kappa_max_1_m=2e-3, n_points=20 From ea16a3ce8b0158a46338321cf3a7dc419228a412 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Thu, 19 Nov 2026 20:15:49 +0900 Subject: [PATCH 4/4] doc: MX-group results after the Yun shear-stack fix The armour stick coefficient of the 66 kV template changed with #39; the registered MX-group checks were rerun on the rebased branch: summed group laws within 4.6e-4 of the exported backbone and 0.06 % of the cycle work (all PASS); one scale for all groups 5.5 % and 7 %. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 4 ++-- doc/benchmarks.md | 10 +++++----- doc/global_local_guide.md | 4 ++-- validation/validation_report.md | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da227b2..b261ac9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,8 +15,8 @@ All notable changes to CableXSec are recorded in this file. The format follows that sums the group laws `s_g(T) B_g(κ / s_g(T))` instead of carrying one scale. Rows MX-group-B and MX-group-E (targets registered before the run): on the 66 kV template with laid cores, filler profiles and 0 / 20 / 40 MPa armour winding stress, 10–200 kN, the summed - group laws reproduce the exported backbone within 4.4e-4 (target 0.5 %) and the cycle work - within 0.13 % (target ±1 %); one scale for all groups misses by up to 5.3 % and 7 % with + group laws reproduce the exported backbone within 4.6e-4 (target 0.5 %) and the cycle work + within 0.06 % (target ±1 %); one scale for all groups misses by up to 5.5 % and 7 % with clamping (MX-group-1, reported). - Reported rows SV11-SPLIT, SV11-REACH and SV11-EQ88: where the SV11 termination increment diff --git a/doc/benchmarks.md b/doc/benchmarks.md index e36741c..a136e9e 100644 --- a/doc/benchmarks.md +++ b/doc/benchmarks.md @@ -1196,10 +1196,10 @@ guide [global_local_guide.md](global_local_guide.md), Section 8. | MX-5 | MM | Hysteretic bending of a global program with the exported table | not run | open | | MX-scale | I | Slip scaling variable (`slip_scale=True`): bound homogeneity of `compute_mkappa` (66 kV, 20 → 70 kN, cores); group elements at 60 kN against the 10 kN elements with yield curvatures times `ρ_g` (Ménard); tension cycle 10–70 kN inside ±0.03 1/m bending, scaled law against the contact-tension history over the fixed-tension residual | 6.9e-16; 1.2e-13; 1.21 (1.02 before the support-cut shear stack; symmetric wire bounds on a breakpoint grid: 8e-15, work 7e-15) | PASS | | MX-scale-1 | I | One scale for all groups against the per-group law, 10–150 kN (reference 10 kN), backbone and cycles to 1.5 times full slip | 66 kV 0; 33 kV three-core 0.10 % (0.29 % with cores); Ménard 12 %; with p_e 0–2 MPa: 66 kV 21 %, 33 kV 12 %, Ménard 19 % | reported | -| MX-group-B | I | One law per friction group, each with its own scale table (`BendingLawExport.slip_group_laws`): sum over the groups of `s_g M_g(κ/s_g)` (the backbone table of the group at the reference, scaled by its own `s_g(T)`) against the exported backbone at the same tension (case below) | target (registered): at every grid curvature κ > 0 and every exported tension, within 0.5 % of the exported moment. Result: 4.4e-4, 4.3e-4, 4.3e-4 at 0, 20, 40 MPa (the interpolation of the reference backbone between grid points) | PASS | -| MX-group-E | I | Same laws, Masing replay: work of three symmetric cycles of amplitude 1e-3, 3e-3, 0.01, 0.03, 0.1 and 0.3 1/m, summed group laws against the exported law at the same tension | target (registered): within ±1 %. Result: 0.99986–1.00019, 0.99997–1.00056, 0.99876–1.00084 at 0, 20, 40 MPa | PASS | +| MX-group-B | I | One law per friction group, each with its own scale table (`BendingLawExport.slip_group_laws`): sum over the groups of `s_g M_g(κ/s_g)` (the backbone table of the group at the reference, scaled by its own `s_g(T)`) against the exported backbone at the same tension (case below) | target (registered): at every grid curvature κ > 0 and every exported tension, within 0.5 % of the exported moment. Result: 4.6e-4, 4.4e-4, 4.5e-4 at 0, 20, 40 MPa (the interpolation of the reference backbone between grid points) | PASS | +| MX-group-E | I | Same laws, Masing replay: work of three symmetric cycles of amplitude 1e-3, 3e-3, 0.01, 0.03, 0.1 and 0.3 1/m, summed group laws against the exported law at the same tension | target (registered): within ±1 %. Result: 0.99973–1.00003, 0.99997–1.00054, 0.99973–1.00003 at 0, 20, 40 MPa | PASS | | MX-group-0 | A | The default scale table starts at zero tension: `s_g(0)` is the group cap of the contact model at zero tension over its reference cap | registered: without clamping `s_g(0) = 0` to 1e-12; with clamping the zero row equals the direct cap ratio at 0 N to 1e-12 rel., and the table scale at 5 kN equals the direct cap ratio at 5 kN to 1e-9 rel. (bounded chain, affine in tension). Result: 0 without clamping; `s_g(0)` 0.82–0.87 (20 MPa) and 0.90–0.93 (40 MPa) of the 10 kN reference, laid cores lowest; both identities to round-off | PASS | -| MX-group-1 | I | One cap-weighted scale for all groups (`per_group=False`) on the same case and measures | backbone 0.044 % (0 MPa), 5.3 % (20 MPa), 4.6 % (40 MPa); work 0.9999–1.0002, 0.938–1.073, 0.954–1.072 | reported | +| MX-group-1 | I | One cap-weighted scale for all groups (`per_group=False`) on the same case and measures | backbone 0.046 % (0 MPa), 5.5 % (20 MPa), 4.8 % (40 MPa); work 0.9997–1.0000, 0.961–1.074, 0.944–1.073 | reported | The armour laws are parallel spring–sliders at fixed contact pressure, so the Iwan law follows Masing's rules; it is exact when every wire's slip interval is symmetric. The signed capstan bound makes the interval asymmetric (the @@ -1218,8 +1218,8 @@ The elastic full-slip part `EI_slip κ` is carried by the first group (scaling l `tests/test_bending_law_groups.py`. With clamping the laid cores scale unlike the armour (at 10 kN and 20 MPa the cores sit at 0.39 of their 100 kN -cap, the armour and the profiles at 0.46), which is why one scale for all groups misses the backbone by 5 % (MX-group-1) -while the summed group laws stay within 4.4e-4: the residual is the linear interpolation of each reference backbone +cap, the armour and the profiles at 0.46), which is why one scale for all groups misses the backbone by 5.5 % (MX-group-1) +while the summed group laws stay within 4.6e-4: the residual is the linear interpolation of each reference backbone between its grid points, not the scaling. ## Cable over a sheave (gap SH) diff --git a/doc/global_local_guide.md b/doc/global_local_guide.md index 64e5c8e..9961517 100644 --- a/doc/global_local_guide.md +++ b/doc/global_local_guide.md @@ -606,8 +606,8 @@ Checks (`tests/test_bending_law_slip_scale.py`; row MX-scale of the [benchmark r One scale or one per group. The single scale `s` keeps the stick stiffness and the full-slip moment exact and is exact when every group scales alike. Otherwise it misplaces the transition. With armour clamping the laid cores scale unlike the armour: on the 66 kV template with cores and filler profiles (μ 0.46) at 20 and 40 MPa winding -stress, 10–200 kN, one scale misses the exported backbone by up to 5.3 % and the cycle work by up to 7 %, while the -summed group laws stay within 4.4e-4 and 0.13 % (rows MX-group-B, MX-group-E and MX-group-1 of the +stress, 10–200 kN, one scale misses the exported backbone by up to 5.5 % and the cycle work by up to 7 %, while the +summed group laws stay within 4.6e-4 and 0.06 % (rows MX-group-B, MX-group-E and MX-group-1 of the [benchmark register](benchmarks.md)). Largest error of the single-scale law against the per-group law over 10–150 kN, reference 10 kN, on the virgin backbone and on cycles up to 1.5 times the full-slip curvature (moment in % of the range; work per cycle at 1.5 times full slip): diff --git a/validation/validation_report.md b/validation/validation_report.md index decac77..f9ee5b9 100644 --- a/validation/validation_report.md +++ b/validation/validation_report.md @@ -80,7 +80,7 @@ Every row is computed from published data or closed-form references in this repo ## Test taxonomy (full gate suite) -- analytical_sanity: `RECOUNT passed` +- analytical_sanity: `1219 passed` - independent_method: `77 passed` - full_scale: `58 passed`