How-to recipes
Each recipe does one job. It states the goal, gives the code, shows what the code prints and names the assumption that matters most.
The code is the script under doc/howto/scripts/, from its # [recipe]
marker on. Run a script from a source checkout with
python doc/howto/scripts/<script>.py. Every recipe uses bundled cables and
the public data under tests/data, and tests/test_howto_recipes.py checks
that each script prints exactly the output shown here. The
user guide places these functions in a project workflow.
Section properties and contact
Load sharing and mass properties
Goal: the mass and weight in water of a cable, and the share of the tension each layer carries with the twist held or free.
import cablexsec as cx
cable = cx.load_cable(cx.iea_task49_66kv_yaml_path())
mass = cx.compute_mass_properties(cable)
print(f"outer diameter {mass.outer_diameter_m * 1e3:7.1f} mm")
print(f"mass {mass.mass_kg_per_m:7.2f} kg/m")
print(f"weight in water {mass.submerged_weight_flooded_voids_N_per_m:7.1f} N/m")
print(f" (voids sealed) {mass.submerged_weight_dry_voids_N_per_m:7.1f} N/m")
for twist in ("held", "free"):
sharing = cx.compute_load_sharing(cable, 200e3, n_tensions=3, twist=twist)
share = sharing.share()
print(f"share of 200 kN, twist {twist} ({sharing.route} route)")
for name in sharing.layers:
if abs(share[name][-1]) >= 0.005:
print(f" {name:<18} {share[name][-1]:6.3f}")
print(f" {'sum of all layers':<18} {sharing.total_N[-1] / 200e3:6.3f}")
outer diameter 184.0 mm
mass 76.33 kg/m
weight in water 491.7 N/m
(voids sealed) 481.2 N/m
share of 200 kN, twist held (solved route)
cu_conductor 0.312
mdpe_filler 0.006
inner_armour 0.319
outer_armour 0.349
sum of all layers 1.000
share of 200 kN, twist free (solved route)
cu_conductor 0.301
mdpe_filler 0.006
inner_armour 0.357
outer_armour 0.322
sum of all layers 1.000
Layers below half a percent of the tension are left out of the printout but
counted in the sum. The masses use the densities of the material library. The
shares come from the solved radial section (route is "solved"), or from
equal axial strain of every layer ("fixed_radius") where that solver does not
accept the cable.
Radial contact state
Goal: the contact pressures, open gaps and wire stresses of the solved radial section, from a cable definition or from layers given directly.
import math
import numpy as np
import cablexsec as cx
# 1. Full cable, trefoil cores included: tension and external pressure.
cable = cx.load_cable(cx.iea_task49_66kv_yaml_path())
for tension, pressure in ((100e3, 0.0), (100e3, 2e6)):
state = cx.solve_cable_radial_state(cable, tension, external_pressure_Pa=pressure)
contact = state.armour_contact_pressure()
wire = state.result.wire_stress_Pa
print(
f"T {tension / 1e3:.0f} kN, sealed p_ext {pressure / 1e6:.0f} MPa: "
f"strain {state.result.axial_strain * 1e6:.0f} ue, "
f"open gaps {int(np.count_nonzero(state.result.interface_gap_m > 1e-9))}"
)
for name in contact:
print(
f" {name:<13} P1+P2 {contact[name] / 1e6:6.3f} MPa, "
f"wire stress {wire[name] / 1e6:6.1f} MPa"
)
# 2. Concentric cable from its definition (offset cores are refused).
single = cx.load_cable(cx.inter_array_single_core_yaml_path())
qp = cx.solve_contact_qp(single, 200e3)
print(f"single-core cable at 200 kN: {qp.n_active} contacts closed")
for radius, pressure in zip(qp.interface_radii_m, qp.contact_pressure_Pa, strict=True):
print(f" r = {radius * 1e3:5.1f} mm: {pressure / 1e6:6.3f} MPa")
# 3. Layers given directly: polymer core, two counter-wound armour layers.
alpha = math.radians(15.0)
layers = [
cx.ElasticAnnulus("core", 0.0, 0.030, 1.0e9, 0.45),
cx.ElasticHelicalRing("inner", 0.0325, 0.005, 36, alpha, 207e9),
cx.ElasticAnnulus("bedding", 0.035, 0.037, 0.9e9, 0.45),
cx.ElasticHelicalRing("outer", 0.0395, 0.005, 44, -alpha, 207e9),
cx.ElasticAnnulus("sheath", 0.042, 0.047, 0.9e9, 0.45),
]
for twist in (0.0, None): # twist held, then torque-free
section = cx.solve_concentric_section(
layers, tension_N=100e3, prescribed_twist_per_m=twist
)
held = "held" if twist is not None else "free"
print(
f"twist {held}: strain {section.axial_strain * 1e6:.0f} ue, "
f"twist {section.twist_per_m * 1e3:.2f} mrad/m, "
f"torque {round(section.torque_resultant_Nm, 1) + 0.0:.1f} N m"
)
print(
" contact "
+ ", ".join(f"{p / 1e6:.3f}" for p in section.contact_pressure_Pa)
+ " MPa"
)
T 100 kN, sealed p_ext 0 MPa: strain 114 ue, open gaps 1
inner_armour P1+P2 0.062 MPa, wire stress 21.0 MPa
outer_armour P1+P2 0.016 MPa, wire stress 21.7 MPa
T 100 kN, sealed p_ext 2 MPa: strain 177 ue, open gaps 0
inner_armour P1+P2 4.329 MPa, wire stress 27.9 MPa
outer_armour P1+P2 4.107 MPa, wire stress 31.0 MPa
single-core cable at 200 kN: 7 contacts closed
r = 9.8 mm: 2.110 MPa
r = 10.8 mm: 2.074 MPa
r = 18.8 mm: 1.961 MPa
r = 19.8 mm: 1.955 MPa
r = 20.5 mm: 8.622 MPa
r = 22.5 mm: 8.687 MPa
r = 26.5 mm: 3.798 MPa
r = 30.5 mm: 0.000 MPa
twist held: strain 365 ue, twist 0.00 mrad/m, torque -196.6 N m
contact 1.038, 0.435, 0.437, 0.000 MPa
twist free: strain 378 ue, twist 6.91 mrad/m, torque 0.0 N m
contact 1.062, 0.358, 0.361, 0.000 MPa
solve_cable_radial_state takes trefoil cores and the declared manufacturing
clamping. Here the external pressure acts on the outer sheath with the
annulus sealed; flooded_pressure_Pa floods it. solve_contact_qp and
solve_concentric_section accept concentric layers only and leave out the
manufacturing clamping. All three solve a state of tension, twist,
pressure and temperature without bending, as the
radial model notes explain.
Neutral axes under a turning curvature
Goal: the bending direction, moment direction, stress neutral axis and stick zone of the armour as the curvature vector turns.
import numpy as np
import cablexsec as cx
cable = cx.load_cable(cx.inter_array_three_core_yaml_path())
# Bend in x to 0.05 1/m, then turn the curvature vector through 180 degrees.
ramp = np.linspace(0.0, 0.05, 21)
turn = np.deg2rad(np.linspace(0.0, 180.0, 37))[1:]
kappa_x = np.concatenate([ramp, 0.05 * np.cos(turn)])
kappa_y = np.concatenate([np.zeros_like(ramp), 0.05 * np.sin(turn)])
tension = np.full(kappa_x.size, 100e3) # force on the armour [N]
result = cx.compute_neutral_axes(cable, kappa_x, kappa_y, tension_N=tension)
outer = result.layers[-1]
def deg(angle_rad: float) -> float:
return round(float(np.rad2deg(angle_rad)), 1) + 0.0
print(f"strain axis offset {result.strain_axis_offset_m[20] * 1e3:.2f} mm")
print(f"{'kappa':>6} {'theta':>6} {'psi':>6} {'delta':>6} {'psi_L':>6} {'stick':>6}")
for i in (2, 6, 10, 20, 26, 44, 56):
print(
f"{result.curvature_1_m[i]:6.3f}"
f" {deg(result.bending_direction_rad[i]):6.1f}"
f" {deg(result.moment_direction_rad[i]):6.1f}"
f" {deg(result.moment_angle_rad[i]):6.1f}"
f" {deg(outer.stress_direction_rad[i]):6.1f}"
f" {deg(outer.stick_arc_rad[i]):6.0f}"
)
strain axis offset -3.82 mm
kappa theta psi delta psi_L stick
0.005 0.0 0.0 0.0 0.0 360
0.015 0.0 0.0 0.0 0.0 242
0.025 0.0 0.0 0.0 0.0 0
0.050 0.0 0.0 0.0 0.0 0
0.050 30.0 34.0 4.0 43.0 145
0.050 120.0 124.1 4.1 133.4 145
0.050 180.0 -175.9 4.1 -166.6 145
Angles are in degrees from the section x axis. theta is the bending
direction, psi the moment direction and delta the lead of the moment.
psi_L is the direction of the outer armour’s first stress harmonic; its
stress neutral axis is perpendicular to it. stick is the arc of wires in
stick.
The stick zone is given for the direction-tied friction law only. Under a
turning curvature the stress neutral axis depends on the friction law
(friction_model).
Stress and installation
Stress over the whole cross-section
Goal: the longitudinal stress at points over every component at one tension and curvature, for a section stress map.
cable = cx.load_cable(cx.inter_array_three_core_yaml_path())
field = cx.compute_section_stress(
cable, 0.10, 0.0, tension_N=100e3, n_points=72, rotation_rad=np.pi / 2
)
print(f"core state: {field.core_state}")
print(f"{'layer':<18} {'kind':<8} {'min MPa':>8} {'max MPa':>8} {'use':>6} limit")
for layer in field.layers:
if not layer.has_values:
continue
usage = layer.utilisation
peak = f"{np.nanmax(usage):6.3f}" if np.isfinite(usage).any() else " -"
limit = "follows the section" if layer.kinematic else layer.failure_mode
print(
f"{layer.name:<18} {layer.kind:<8}"
f" {layer.sigma_min_Pa.min() / 1e6:8.1f} {layer.sigma_max_Pa.max() / 1e6:8.1f}"
f" {peak} {limit}"
)
# Wire fields alone, from a wire-stress result at the same load.
stress = cx.compute_stress(cable, 0.10, 0.0, tension_N=100e3)
for wires in cx.armour_stress_fields(cable, stress, rotation_rad=np.pi / 2):
centre = wires.sigma_Pa[:, 0, 0]
print(
f"{wires.name}: {centre.size} wires, centre line "
f"{centre.min() / 1e6:.1f} to {centre.max() / 1e6:.1f} MPa"
)
core state: frictional
layer kind min MPa max MPa use limit
cu_conductor annulus -28.7 107.1 0.893 yielding
conductor_screen annulus -0.2 0.3 - no limit given
xlpe_insulation annulus -0.3 0.4 - no limit given
insulation_screen annulus -0.3 0.4 - no limit given
cu_screen annulus -243.1 309.0 - follows the section
hdpe_core_sheath annulus -2.0 2.5 0.037 strain limit
pp_filler annulus -7.0 7.6 - no limit given
hdpe_bedding annulus -4.3 4.6 0.068 strain limit
inner_armour wires -71.4 152.2 0.221 yielding
outer_armour wires -25.7 97.8 0.142 yielding
hdpe_outer_sheath annulus -5.5 5.9 0.086 strain limit
inner_armour: 61 wires, centre line -38.9 to 119.7 MPa
outer_armour: 67 wires, centre line 7.9 to 65.3 MPa
Longitudinal stress over the section; the plotting code is in the script.
The fields reproduce the extremes and utilisations of
compute_component_response at the same inputs, in one core slip state
(core_state). The copper wire screen is outside the load path of the model.
Its stress is its modulus times the strain it follows.
Coiling into a tank
Goal: the armour stresses, bird-caging and first-yield checks of a cable coiled into a static tank with one twist per turn.
import cablexsec as cx
cable = cx.load_cable(cx.chae2023_yaml_path())
for diameter in (14.4, 8.0): # tank diameter [m]
result = cx.compute_coiling(cable, tank_diameter_m=diameter, n_per_turn=72)
armour = result.layers["armour"]
print(
f"D = {diameter:4.1f} m: kappa = twist = {result.curvature_per_m:.4f} 1/m, "
f"torque {result.torque_Nm / 1e3:.2f} kN m"
)
print(
f" armour wire centre {armour.centre_min_Pa / 1e6:7.1f} to "
f"{armour.centre_max_Pa / 1e6:6.1f} MPa, "
f"surface {armour.fibre_min_Pa / 1e6:7.1f} to "
f"{armour.fibre_max_Pa / 1e6:6.1f} MPa"
)
print(
f" bird-caging capacity {armour.sigma_cr_Pa / 1e6:.1f} MPa, "
f"buckling {armour.buckling_utilisation:.3f}, "
f"yield {armour.yield_utilisation:.3f}"
)
print(
f" governing: {result.governing} ({armour.governing_mode}), "
f"utilisation {result.utilisation:.3f}, elastic {result.elastic_valid}"
)
D = 14.4 m: kappa = twist = 0.1389 1/m, torque 14.79 kN m
armour wire centre -244.0 to -205.4 MPa, surface -299.8 to -150.6 MPa
bird-caging capacity 231.7 MPa, buckling 1.053, yield 0.750
governing: armour (radial), utilisation 1.053, elastic True
D = 8.0 m: kappa = twist = 0.2500 1/m, torque 26.62 kN m
armour wire centre -439.1 to -369.7 MPa, surface -539.7 to -271.1 MPa
bird-caging capacity 231.7 MPa, buckling 1.895, yield 1.349
governing: armour (radial), utilisation 1.895, elastic False
The check is elastic. When the wires yield (elastic False) the stresses are
not capped, and the buckling check no longer applies. Lateral buckling of the
armour is reported (sigma_lateral_Pa) but not counted in the utilisation.
Fatigue
Fatigue utilities on a load record
Goal: armour damage at fixed fibres, strain-life damage of a copper fibre, a Gumbel fit of block maxima and the slip of the wires along their helix, all from one record.
import numpy as np
import cablexsec as cx
cable = cx.load_cable(cx.inter_array_three_core_yaml_path())
series = cx.jonswap_series(
hs_m=3.0,
tp_s=9.0,
duration_s=600.0,
dt_s=0.5,
rms_curvature_1_m=0.02,
mean_tension_N=80e3,
dynamic_tension_rms_N=5e3,
out_of_plane_fraction=0.3,
tension_kind="true",
seed=1,
)
# Armour fatigue at fixed fibres of every wire (rainflow and Miner).
result = cx.fatigue_from_series(cable, series, n_fibres=16)
worst = {name: float(d.max()) for name, d in result.D_total_per_wire.items()}
print(
f"armour: critical layer {result.critical_layer}, "
f"wire at {result.phi_critical_deg:.0f} deg, "
f"fibre at {result.fibre_critical_deg:.0f} deg"
)
for name, damage in worst.items():
print(f" {name:<13} damage in 600 s {damage:.3e}")
# Strain-life damage of a copper fibre 25 mm from the neutral axis.
strain = series.curvature_x_1_m * 0.025
copper = cx.strain_life_damage(strain, "copper_poon2022", correction="swt")
print(
f"copper fibre: {copper.n_cycles:.0f} cycles, "
f"max amplitude {copper.strain_amplitude_max * 1e6:.0f} ue, "
f"damage {copper.damage:.3e}"
)
# Gumbel fit of ten 60 s block maxima of the curvature magnitude.
magnitude = np.hypot(series.curvature_x_1_m, series.curvature_y_1_m)
maxima = magnitude.reshape(10, -1).max(axis=1)
fit = cx.gumbel_fit(maxima, fractile=0.9, duration_ratio=60.0)
print(
f"curvature: mean 60 s maximum {maxima.mean():.4f} 1/m, "
f"1 h most probable {fit.most_probable:.4f}, "
f"90 % fractile {fit.fractile_value:.4f} 1/m"
)
# Wire slip along the helix over the first 60 s.
window = slice(0, 120)
kinematics = cx.kinematic_history(
cable,
series.curvature_x_1_m[window],
series.curvature_y_1_m[window],
time_s=series.time_s[window],
tension_N=series.tension_N[window],
)
for layer in kinematics.layers:
slip = layer.slip_m
print(
f"{layer.name:<13} slip range {np.ptp(slip, axis=1).max() * 1e6:.1f} um, "
f"slipping share {layer.slipping.mean():.2f}"
)
armour: critical layer inner_armour, wire at 0 deg, fibre at 0 deg
inner_armour damage in 600 s 5.859e-06
outer_armour damage in 600 s 2.245e-06
copper fibre: 122 cycles, max amplitude 1568 ue, damage 3.647e-05
curvature: mean 60 s maximum 0.0479 1/m, 1 h most probable 0.0761, 90 % fractile 0.0941 1/m
inner_armour slip range 0.0 um, slipping share 0.00
outer_armour slip range 284.7 um, slipping share 0.26
jonswap_series makes a synthetic screening record. fatigue_from_series
refuses effective or undeclared tension. The copper_poon2022 constants are a
fit to copper conductor wire, and the fibre strain here is bending alone.
SWT critical plane of a multiaxial cycle
Goal: the Smith–Watson–Topper critical plane and life of one closed stress and strain cycle at a material point.
import numpy as np
import cablexsec as cx
from cablexsec.materials.sn_curves import get_swt_life
material = get_swt_life("copper_poon2022")
young, poisson = material.E_Pa, 0.34
# One closed cycle at one material point: axial stress with an out-of-phase shear.
phase = np.linspace(0.0, 2.0 * np.pi, 361)
stress = np.zeros((phase.size, 3, 3))
stress[:, 0, 0] = 40e6 + 60e6 * np.sin(phase)
stress[:, 0, 1] = stress[:, 1, 0] = 25e6 * np.sin(phase + 0.5)
stress[-1] = stress[0]
trace = np.trace(stress, axis1=1, axis2=2)[:, None, None]
strain = ((1 + poisson) * stress - poisson * trace * np.eye(3)) / young
# Candidate planes: normals in the x-y plane every 2 degrees.
angles = np.deg2rad(np.arange(0.0, 180.0, 2.0))
normals = np.column_stack((np.cos(angles), np.sin(angles), np.zeros_like(angles)))
result = cx.compute_swt_cycle(
stress, strain, normals, material, material_point_id="wire surface point"
)
critical = np.rad2deg(angles[result.critical_plane_index])
print(f"critical plane normal at {critical:.0f} deg to the wire axis")
print(f"sampled SWT {result.sampled_max_swt_Pa / 1e3:.1f} kPa")
print(f"life {result.life_cycles:.3e} cycles")
x_plane = cx.compute_swt_cycle(
stress, strain, normals[:1], material, material_point_id="wire surface point"
)
print(f"plane normal along the axis only: life {x_plane.life_cycles:.3e} cycles")
critical plane normal at 16 deg to the wire axis
sampled SWT 75.3 kPa
life 1.189e+06 cycles
plane normal along the axis only: life 1.932e+06 cycles
The critical plane is the largest of the supplied normals, so refine the angles and the time samples until it settles. The record must be one closed, repeated cycle. Variable-amplitude histories are not counted.
Thermal and electrical
Frictional heating in cyclic bending
Goal: the temperatures of an energised cable bent cyclically, with and without the heat of armour friction.
import math
import numpy as np
import cablexsec as cx
from cablexsec.analysis.frictional_heating import (
CyclicBending,
simulate_frictional_heating,
)
cable = cx.load_cable(cx.iea_task49_66kv_yaml_path())
network = cx.thermal_network(
cable,
630e-6, # conductor area [m^2]
T4_external_Km_W=1.0 / (math.pi * 0.184 * 8.0), # in water, h = 8 W/(m^2 K)
ambient_C=20.0,
)
bending = CyclicBending(
tension_N=80e3,
amplitude_1_m=0.05, # reversed bending about a straight cable
frequency_Hz=0.2,
points_per_cycle=48,
)
time_s = np.linspace(0.0, 6 * 3600.0, 7) # six hours, hourly output
for coupling in ("none", "two_way"):
result = simulate_frictional_heating(
cable,
network,
bending,
time_s,
current_A=600.0,
coupling=coupling,
update_interval_s=1800.0,
max_step_s=600.0,
)
armour = result.layer_temperature_C["outer_armour"]
conductor = result.node_temperature_C[:, 0]
print(f"coupling {coupling}")
print(
f" friction heat {result.total_friction_heat_W_m[0]:.2f} W/m at start, "
f"{result.total_friction_heat_W_m[-1]:.2f} W/m at 6 h"
)
print(
f" after 6 h: conductor {conductor[-1]:.1f} C, outer armour {armour[-1]:.1f} C"
)
coupling none
friction heat 0.00 W/m at start, 0.00 W/m at 6 h
after 6 h: conductor 30.3 C, outer armour 24.7 C
coupling two_way
friction heat 7.89 W/m at start, 11.62 W/m at 6 h
after 6 h: conductor 32.1 C, outer armour 26.6 C
This cable declares no manufacturing clamping, so the friction rests on the
tension alone and the run warns with MissingClampingStateWarning. The heat is
the sectional value, away from clamps and terminations. anchoring_factor in
CyclicBending raises it near them.
Relative insulation life
Goal: the electro-thermal ageing factor of the insulation at operating temperatures.
import numpy as np
import cablexsec as cx
cable = cx.load_cable(cx.iea_task49_66kv_yaml_path())
curvature = np.zeros(10) # curvature history [1/m]; used only with mechanical_beta
for temperature in (50.0, 70.0, 90.0):
life = cx.compute_electrical_life(
cable, curvature, T_conductor_C=temperature, T0_C=90.0
)
print(
f"T = {temperature:4.1f} C: field {life.E_field_Vm / 1e6:.2f} kV/mm, "
f"L/L0 = {life.life_factor:.3g}"
)
T = 50.0 C: field 4.23 kV/mm, L/L0 = 1.11e+03
T = 70.0 C: field 4.23 kV/mm, L/L0 = 103
T = 90.0 C: field 4.23 kV/mm, L/L0 = 12.4
The result is a screening factor of the Mazzanti (2007) model against the
reference at the threshold field and T0_C. It is not a calibrated lifetime.
The field of this cable is below the threshold of 5 kV/mm, so the factor
exceeds one even at the reference temperature.
Global analysis results
Reading CableDyn and RIFLEX results
Goal: load series at named sections of a CableDyn run and from a RIFLEX ASCII time history.
import math
from pathlib import Path
import numpy as np
import cablexsec as cx
DATA = Path(__file__).resolve().parents[3] / "tests" / "data"
# CableDyn: a lazy-wave run, two material sections by arc length from End A.
read = cx.read_cabledyn_sections(
DATA / "cabledyn" / "lw128", # output root
DATA / "cabledyn" / "lw128.dat", # deck of the run
{"hangoff": 0.25, "sag": 58.4},
frame="section",
)
print(f"curvature from {read.checks['curvature_source']} channels")
outer_area = math.pi * 0.160**2 / 4.0 # outer diameter of the deck line type
for name, history in read.histories.items():
series = history.to_load_case_series(outer_area)
kx, ky = series.curvature_x_1_m, series.curvature_y_1_m
print(
f"{name:<8} {series.time_s.size} samples, dt {series.time_s[1]:.1f} s, "
f"Te mean {history.effective_tension_N.mean() / 1e3:.2f} kN, "
f"true mean {series.tension_N.mean() / 1e3:.2f} kN, "
f"|kappa| max {np.hypot(kx, ky).max():.4f} 1/m"
)
# RIFLEX ASCII: positional columns; declare the tension and curvature basis.
series = cx.read_riflex_ascii(
DATA / "histories" / "synthetic_riflex.asc",
time_col=1,
curvature_x_col=2,
tension_col=3,
curvature_y_col=4,
tension_kind="effective",
curvature_convention="strain_gradient",
)
print(
f"riflex {series.time_s.size} samples, {series.time_s[-1]:.1f} s, "
f"{series.tension_kind} tension {series.tension_N.mean() / 1e3:.2f} kN mean, "
f"kappa_x {series.curvature_x_1_m.min():.4f} to "
f"{series.curvature_x_1_m.max():.4f} 1/m"
)
curvature from tangent channels
hangoff 201 samples, dt 0.1 s, Te mean 9.28 kN, true mean 6.40 kN, |kappa| max 0.0084 1/m
sag 201 samples, dt 0.1 s, Te mean 1.75 kN, true mean -11.20 kN, |kappa| max 0.0984 1/m
riflex 240 samples, 59.8 s, effective tension 65.25 kN mean, kappa_x -0.0155 to 0.0156 1/m
The true wall force is the effective tension less the hydrostatic pressure
times the outer area. At the sag bend it is compressive while the effective
tension is positive. RIFLEX columns are positional, so declare the tension
kind and the curvature convention, and convert effective tension with
with_true_tension before fatigue. The
global–local guide covers both readers.