Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ All notable changes to CableXSec are recorded in this file. The format follows

## [Unreleased]

### Changed

- **Figures use a MATLAB-style look** (`cablexsec.plotting.style`):
- MATLAB's default line colours in MATLAB's order (`MATLAB_ORDER`; `COLORS` maps the names to those hues);
- a Helvetica or Arial face at 10 pt;
- a closed box with inward ticks on all sides and no grid;
- a square, opaque legend.
- **Labels carry true Greek letters and sub- and superscripts** in the same face (κ, EI_min, σ_A, m⁻¹), with numerals upright. The new `style.LABELS` holds the standard axis labels.
- **The tutorial and how-to scripts apply the style.** Their figures were plain matplotlib defaults before; they are regenerated. The examples follow the same labels.

### Added

- `bonded_face: outer` on the outermost helical layer (gap G8): the outer face
Expand Down
Binary file modified doc/howto/figures/howto_04_section_stress.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 8 additions & 6 deletions doc/howto/scripts/howto_04_section_stress.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import numpy as np

import cablexsec as cx
from cablexsec.plotting.style import LABELS, SIGNED_CMAP, apply_style

apply_style() # the MATLAB-style figures of every CableXSec plot
FIGURES = (
Path(sys.argv[1])
if len(sys.argv) > 1
Expand Down Expand Up @@ -62,15 +64,15 @@
xy[:, 1],
c=layer.sigma_Pa.reshape(-1) / 1e6,
s=4 if layer.kind != "wires" else 10,
cmap="coolwarm",
cmap=SIGNED_CMAP,
vmin=-300,
vmax=300,
)
fig.colorbar(marks, ax=ax, label="longitudinal stress [MPa]")
fig.colorbar(marks, ax=ax, label=r"Longitudinal stress $\sigma_{zz}$ [MPa]")
ax.set_aspect("equal")
ax.set_xlabel("x [mm]")
ax.set_ylabel("y [mm]")
ax.set_title("T = 100 kN, curvature 0.1 1/m towards +y", fontsize=9)
ax.set_xlabel(LABELS["x_mm"])
ax.set_ylabel(LABELS["y_mm"])
ax.set_title(r"$T$ = 100 kN, $\kappa$ = 0.1 m$^{\mathrm{-1}}$ towards $+y$", fontsize=9)
fig.tight_layout()
FIGURES.mkdir(parents=True, exist_ok=True)
fig.savefig(FIGURES / "howto_04_section_stress.png", dpi=150)
fig.savefig(FIGURES / "howto_04_section_stress.png", dpi=200)
Binary file modified doc/tutorials/figures/tutorial_01_first_cable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/tutorials/figures/tutorial_02_measured_loop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/tutorials/figures/tutorial_02_sensitivity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/tutorials/figures/tutorial_03_damage_circumference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/tutorials/figures/tutorial_03_governing_fibre_stress.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/tutorials/figures/tutorial_04_slip_amplitude.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/tutorials/figures/tutorial_04_swt_depth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 29 additions & 11 deletions doc/tutorials/scripts/tutorial_01_first_cable.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
slip_onset_curvature,
)
from cablexsec.mechanics.radial_cable import solve_cable_radial_states
from cablexsec.plotting.style import COLORS, LABELS, apply_style

apply_style() # the MATLAB-style figures of every CableXSec plot
FIGURES = (
Path(sys.argv[1])
if len(sys.argv) > 1
Expand Down Expand Up @@ -97,33 +99,49 @@
radial = solve_cable_radial_states(cable, sweep)
fig, (ax_contact, ax_bending) = plt.subplots(1, 2, figsize=(9.0, 3.8))
for i, (layer, colour) in enumerate(
zip(cable.helical_layers, ("C0", "C1"), strict=True)
zip(cable.helical_layers, (COLORS["BLUE"], COLORS["ORANGE"]), strict=True)
):
p_bounded = [specs[i].contact_pressure_Pa / 1e6 for specs in bounded]
p_solved = [s.armour_contact_pressure()[layer.name] / 1e6 for s in radial]
ax_contact.plot(sweep / 1e3, p_bounded, "-", c=colour, label=f"{layer.name}")
label = layer.name.replace("_", " ")
ax_contact.plot(sweep / 1e3, p_bounded, "-", c=colour, label=label)
ax_contact.plot(sweep / 1e3, p_solved, "--", c=colour)
ax_contact.set_xlabel("tension [kN]")
ax_contact.set_ylabel("armour contact pressure P1 + P2 [MPa]")
ax_contact.set_xlabel(LABELS["tension_kN"])
ax_contact.set_ylabel(r"Armour contact pressure $P_\mathrm{1} + P_\mathrm{2}$ [MPa]")
ax_contact.set_title("Solid: bounded chain; dashed: solved")
ax_contact.legend(loc="upper left")
kappa = np.linspace(0.0, 0.02, 401)
for tension, colour in ((0.0, "black"), (100e3, "tab:red")):
for tension, colour in ((0.0, COLORS["BLUE"]), (100e3, COLORS["ORANGE"])):
loop = cx.compute_mkappa(cable, kappa, tension_N=tension)
ax_bending.plot(
kappa, loop.moment_Nm, color=colour, label=f"T = {tension / 1e3:.0f} kN"
kappa, loop.moment_Nm, color=colour, label=rf"$T$ = {tension / 1e3:.0f} kN"
)
for spec in cx.cable_to_mkappa_specs(cable, tension, contact_model="bounded"):
onset = slip_onset_curvature(spec)
ax_bending.plot(onset, np.interp(onset, kappa, loop.moment_Nm), "o", c=colour)
ax_bending.plot(kappa, stiffness.ei_min_Nm2 * kappa, "--", c="grey", label="full slip")
ax_bending.plot(kappa, stiffness.ei_max_Nm2 * kappa, ":", c="grey", label="no slip")
ax_bending.plot(
kappa,
stiffness.ei_min_Nm2 * kappa,
"--",
c=COLORS["GREY"],
lw=1.0,
label=r"full slip, $EI_\mathrm{min}$",
)
ax_bending.plot(
kappa,
stiffness.ei_max_Nm2 * kappa,
":",
c=COLORS["GREY"],
lw=1.0,
label=r"no slip, $EI_\mathrm{max}$",
)
ax_bending.set_ylim(0.0, 700.0)
ax_bending.set_xlabel("curvature [1/m]")
ax_bending.set_ylabel("bending moment [N m]")
ax_bending.set_xticks(np.linspace(0.0, 0.02, 5))
ax_bending.set_xlabel(LABELS["curvature"])
ax_bending.set_ylabel(LABELS["moment_Nm"])
ax_bending.set_title("First loading; dots: slip onset")
ax_bending.legend(loc="lower right")
fig.tight_layout()
FIGURES.mkdir(parents=True, exist_ok=True)
fig.savefig(FIGURES / "tutorial_01_first_cable.png", dpi=150)
fig.savefig(FIGURES / "tutorial_01_first_cable.png", dpi=200)
print(f"wrote {(FIGURES / 'tutorial_01_first_cable.png').name}")
35 changes: 23 additions & 12 deletions doc/tutorials/scripts/tutorial_02_bending_hysteresis.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import cablexsec as cx
from cablexsec.analysis.curve_comparison import cycle_work, insert_cycle_crossings
from cablexsec.mechanics.papailiou import slip_onset_curvature
from cablexsec.plotting.style import COLORS, LABELS, apply_style

apply_style() # the MATLAB-style figures of every CableXSec plot
REPOSITORY = Path(__file__).resolve().parents[3]
MEASURED = REPOSITORY / "validation" / "paper_data" / "menard_fig16b_ordered.csv"
FIGURES = (
Expand Down Expand Up @@ -97,30 +99,39 @@ def describe(label, result, spec):
# [step-figures]
FIGURES.mkdir(parents=True, exist_ok=True)
fig, ax = plt.subplots(figsize=(5.0, 4.0))
ax.plot(kappa_test, moment_test, "o", ms=3, mfc="none", c="grey", label="measured")
ax.plot(path, loop.moment_Nm[second], c="black", label="CableXSec")
ax.set_xlabel("curvature [1/m]")
ax.plot(
kappa_test,
moment_test,
"o",
ms=3,
mfc="none",
c=COLORS["BLACK"],
mew=0.6,
label="measured",
)
ax.plot(path, loop.moment_Nm[second], c=COLORS["BLUE"], label="CableXSec")
ax.set_xlabel(LABELS["curvature"])
ax.set_xticks([-0.1, -0.05, 0.0, 0.05, 0.1])
ax.set_ylabel("bending moment [N m]")
ax.set_ylabel(LABELS["moment_Nm"])
ax.set_title("Ménard and Cartraud (2023), range (b)")
ax.legend(loc="upper left")
fig.tight_layout()
fig.savefig(FIGURES / "tutorial_02_measured_loop.png", dpi=150)
fig.savefig(FIGURES / "tutorial_02_measured_loop.png", dpi=200)
print(f"wrote {(FIGURES / 'tutorial_02_measured_loop.png').name}")

fig, (ax_mu, ax_p) = plt.subplots(1, 2, figsize=(9.0, 3.8), sharey=True)
for mu, result in friction_loops.items():
ax_mu.plot(kappa[cycle], result.moment_Nm[cycle], label=f"mu = {mu}")
ax_mu.plot(kappa[cycle], result.moment_Nm[cycle], label=rf"$\mu$ = {mu}")
for pressure, result in clamping_loops.items():
label = f"p0 = {pressure / 1e6:.2f} MPa"
label = rf"$p_\mathrm{{0}}$ = {pressure / 1e6:.2f} MPa"
ax_p.plot(kappa[cycle], result.moment_Nm[cycle], label=label)
ax_mu.set_title("Friction coefficient (p0 = 0.30 MPa)")
ax_p.set_title("Initial pressure p0 (mu = 0.2)")
ax_mu.set_ylabel("bending moment [N m]")
ax_mu.set_title(r"Friction coefficient ($p_\mathrm{0}$ = 0.30 MPa)")
ax_p.set_title(r"Initial pressure $p_\mathrm{0}$ ($\mu$ = 0.2)")
ax_mu.set_ylabel(LABELS["moment_Nm"])
for axis in (ax_mu, ax_p):
axis.set_xlabel("curvature [1/m]")
axis.set_xlabel(LABELS["curvature"])
axis.set_xticks([-0.1, -0.05, 0.0, 0.05, 0.1])
axis.legend(loc="upper left")
fig.tight_layout()
fig.savefig(FIGURES / "tutorial_02_sensitivity.png", dpi=150)
fig.savefig(FIGURES / "tutorial_02_sensitivity.png", dpi=200)
print(f"wrote {(FIGURES / 'tutorial_02_sensitivity.png').name}")
29 changes: 18 additions & 11 deletions doc/tutorials/scripts/tutorial_03_global_to_fatigue.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
from cablexsec.analysis.fast_rainflow import fibre_fatigue
from cablexsec.analysis.fatigue import rainflow_cycles, wire_stress_field
from cablexsec.cable_adapters import cable_to_fatigue_layers
from cablexsec.plotting.style import COLORS, LABELS, apply_style

apply_style() # the MATLAB-style figures of every CableXSec plot
REPOSITORY = Path(__file__).resolve().parents[3]
FIGURES = (
Path(sys.argv[1])
Expand Down Expand Up @@ -208,29 +210,34 @@
for name, damage in fatigue.D_total_per_wire.items():
count = damage.size
ax.plot(360.0 * np.arange(count) / count, damage, label=name.replace("_", " "))
ax.axvline(fatigue.phi_critical_deg, color="0.5", linewidth=0.8, linestyle="--")
ax.set_xlabel("wire azimuth from e1 [deg]")
ax.set_ylabel("Miner damage over the record")
ax.axvline(
fatigue.phi_critical_deg, color=COLORS["GREY"], linewidth=1.0, linestyle="--"
)
ax.set_xlabel(r"Wire azimuth from $\mathbf{e}_\mathrm{1}$, $\varphi$ [$^\circ$]")
ax.set_ylabel(r"Miner damage over the record, $D$ [–]")
ax.set_xlim(0.0, 360.0)
ax.set_xticks(np.arange(0, 361, 45))
ax.set_ylim(bottom=0.0)
ax.ticklabel_format(axis="y", style="sci", scilimits=(0, 0))
ax.legend(frameon=False, loc="lower center")
fig.savefig(FIGURES / "tutorial_03_damage_circumference.png", dpi=150)
ax.legend(loc="lower center")
fig.savefig(FIGURES / "tutorial_03_damage_circumference.png", dpi=200)
plt.close(fig)
print("wrote tutorial_03_damage_circumference.png")

fig, ax = plt.subplots(figsize=(6.4, 3.0), layout="constrained")
window = series.time_s <= 120.0
ax.plot(series.time_s[window], stress[window] / 1e6, linewidth=0.9)
ax.set_xlabel("time [s]")
ax.set_ylabel("fibre stress [MPa]")
ax.plot(
series.time_s[window], stress[window] / 1e6, color=COLORS["BLUE"], linewidth=1.0
)
ax.set_xlabel(LABELS["time"])
ax.set_ylabel(r"Fibre stress $\sigma$ [MPa]")
ax.set_xlim(0.0, 120.0)
ax.set_title(
f"{fatigue.critical_layer.replace('_', ' ')}, wire at "
f"{fatigue.phi_critical_deg:.0f} deg, fibre {fatigue.fibre_critical_deg:.0f} deg",
rf"{fatigue.critical_layer.replace('_', ' ')}, wire at "
rf"{fatigue.phi_critical_deg:.0f}$^\circ$, "
rf"fibre {fatigue.fibre_critical_deg:.0f}$^\circ$",
fontsize=10,
)
fig.savefig(FIGURES / "tutorial_03_governing_fibre_stress.png", dpi=150)
fig.savefig(FIGURES / "tutorial_03_governing_fibre_stress.png", dpi=200)
plt.close(fig)
print("wrote tutorial_03_governing_fibre_stress.png")
39 changes: 28 additions & 11 deletions doc/tutorials/scripts/tutorial_04_contact_and_fretting.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
reduced_shear_modulus,
solve_contact,
)
from cablexsec.plotting.style import COLORS, LABELS, apply_style

FIGURES = (
Path(sys.argv[1])
Expand Down Expand Up @@ -274,8 +275,12 @@ def contact_cycle(x_over_a, z_over_b):
f"plane normal {tilt:.0f} deg from the wire axis"
)
# [step-figures]
apply_style() # the MATLAB-style figures of every CableXSec plot
fig, ax = plt.subplots(figsize=(6.4, 4.0), layout="constrained")
for name, colour in (("inner_armour", "C0"), ("outer_armour", "C1")):
for name, colour in (
("inner_armour", COLORS["BLUE"]),
("outer_armour", COLORS["ORANGE"]),
):
face_name = faces[name]
full = fretting.faces[face_name]
label = name.replace("_", " ")
Expand All @@ -288,24 +293,36 @@ def contact_cycle(x_over_a, z_over_b):
)
stations, amplitude = friction_slip[name]
ax.plot(stations, amplitude * 1e6, color=colour, label=f"{label}, friction law")
ax.set_xlabel("wire azimuth from e1 [deg]")
ax.set_ylabel("slip amplitude [µm]")
ax.set_xlabel(r"Wire azimuth from $\mathbf{e}_\mathrm{1}$, $\varphi$ [$^\circ$]")
ax.set_ylabel(LABELS["slip_um"])
ax.set_xlim(0.0, 360.0)
ax.set_xticks(np.arange(0, 361, 45))
ax.set_ylim(bottom=0.0)
fig.legend(frameon=False, fontsize=8, ncols=2, loc="outside lower center")
fig.savefig(FIGURES / "tutorial_04_slip_amplitude.png", dpi=150)
fig.legend(fontsize=8, ncols=2, loc="outside lower center")
fig.savefig(FIGURES / "tutorial_04_slip_amplitude.png", dpi=200)
plt.close(fig)
print("wrote tutorial_04_slip_amplitude.png")

fig, ax = plt.subplots(figsize=(6.4, 3.2), layout="constrained")
ax.plot(depths, np.array(profile) / 1e6, marker="o", label="next to the crossing")
ax.axhline(bulk_only / 1e6, color="0.4", linestyle="--", label="bulk cycle alone")
ax.set_xlabel("depth z / b at x = -1.1 a")
ax.set_ylabel("SWT indicator [MPa]")
ax.plot(
depths,
np.array(profile) / 1e6,
marker="o",
color=COLORS["BLUE"],
label="next to the crossing",
)
ax.axhline(
bulk_only / 1e6,
color=COLORS["GREY"],
linestyle="--",
linewidth=1.0,
label="bulk cycle alone",
)
ax.set_xlabel(r"Depth $z/b$ at $x = -1.1\,a$ [–]")
ax.set_ylabel(r"SWT indicator $\sigma_\mathrm{max}\,\varepsilon_\mathrm{a}$ [MPa]")
ax.set_xlim(0.0, 1.05)
ax.set_ylim(bottom=0.0)
ax.legend(frameon=False)
fig.savefig(FIGURES / "tutorial_04_swt_depth.png", dpi=150)
ax.legend()
fig.savefig(FIGURES / "tutorial_04_swt_depth.png", dpi=200)
plt.close(fig)
print("wrote tutorial_04_swt_depth.png")
23 changes: 23 additions & 0 deletions doc/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,29 @@ for screening.
`cablexsec.plotting.build_dashboard` writes a standalone HTML viewer of
stress, moment–curvature, capacity and fatigue results.

### 2.8 Figures

`cablexsec.plotting` draws the standard figures from result objects:

- `plot_mkappa` and `plot_mkappa_validation_suite`: moment–curvature loops;
- `plot_cross_section`: the section, by material or coloured by a stress component;
- `plot_stress_distribution` and `plot_stress_timeseries`: per-wire stress;
- `plot_damage_split` and `plot_fretting_polar`: fatigue;
- `plot_capacity_envelope` and `plot_temperature_gradient`: capacity and temperature.

Every figure uses one MATLAB-style look (`cablexsec.plotting.style`):

- MATLAB's default line colours, in MATLAB's order (`MATLAB_ORDER`; named in `COLORS`);
- a Helvetica or Arial face;
- a closed box with inward ticks and no grid;
- symbols with true Greek letters and sub- and superscripts, such as κ, EI_min and m⁻¹.

`style.LABELS` holds the standard axis labels, for example
`LABELS["curvature"]` and `LABELS["moment_kNm"]`. Use them in your own scripts
too. Apply the look to your own figures with `style.apply_style()`, or for
one block with `with style.use_style():`. The limitations of a result are
printed on its figure verbatim.

## 3. Reading results

- **{term}`Provenance <provenance>`.** Every result keeps its `provenance`: method, citations,
Expand Down
10 changes: 5 additions & 5 deletions examples/demo_02_mkappa_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from _console import configure_console

import cablexsec as cx
from cablexsec.plotting.style import COLORS, apply_style
from cablexsec.plotting.style import COLORS, LABELS, apply_style

configure_console()

Expand Down Expand Up @@ -48,10 +48,10 @@ def main() -> None:

apply_style()
fig, ax = plt.subplots(figsize=(5, 4))
ax.plot(mk.kappa_1_m * 1e3, mk.moment_Nm, color=COLORS["BLACK"], label="CableXSec")
ax.set_xlabel(r"curvature $\kappa$ [$10^{-3}$ m$^{-1}$]")
ax.set_ylabel("moment [N·m]")
ax.set_title("Ménard cable — M–κ loop (EI_min comparison, A11)")
ax.plot(mk.kappa_1_m * 1e3, mk.moment_Nm, color=COLORS["BLUE"], label="CableXSec")
ax.set_xlabel(LABELS["curvature_milli"])
ax.set_ylabel(LABELS["moment_Nm"])
ax.set_title(r"Ménard cable — $M$–$\kappa$ loop ($EI_\mathrm{min}$ check, A11)")
ax.legend()
fig.savefig(OUT / "demo_02_mkappa.png")
print(f"saved {OUT / 'demo_02_mkappa.png'}")
Expand Down
14 changes: 7 additions & 7 deletions examples/demo_03_stress_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from _console import configure_console

import cablexsec as cx
from cablexsec.plotting.style import COLORS, apply_style
from cablexsec.plotting.style import COLORS, LABELS, apply_style

configure_console()

Expand Down Expand Up @@ -51,14 +51,14 @@ def main() -> None:
phi = sr.phi_deg[name]
fig, ax = plt.subplots(figsize=(6, 4))
for comp, col, lab in [
(sr.sigma_A_Pa, COLORS["GREEN"], r"$\sigma_A$"),
(sr.sigma_B_Pa, COLORS["BLUE"], r"$\sigma_B$"),
(sr.sigma_f_Pa, COLORS["ORANGE"], r"$\sigma_f$"),
(sr.sigma_total_Pa, COLORS["BLACK"], r"$\sigma_{total}$"),
(sr.sigma_A_Pa, COLORS["BLUE"], r"$\sigma_\mathrm{A}$"),
(sr.sigma_B_Pa, COLORS["ORANGE"], r"$\sigma_\mathrm{B}$"),
(sr.sigma_f_Pa, COLORS["YELLOW"], r"$\sigma_\mathrm{f}$"),
(sr.sigma_total_Pa, COLORS["PURPLE"], r"$\sigma_\mathrm{total}$"),
]:
ax.plot(phi, comp[name] / mpa, color=col, label=lab)
ax.set_xlabel(r"wire azimuth $\varphi$ [deg]")
ax.set_ylabel("stress [MPa]")
ax.set_xlabel(LABELS["azimuth"])
ax.set_ylabel(LABELS["stress"])
ax.set_title(f"Per-wire stress — {name} (analytically verified)")
ax.legend(ncol=2)
fig.savefig(OUT / "demo_03_stress_distribution.png")
Expand Down
Loading
Loading