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 @@ -529,6 +529,16 @@ All notable changes to CableXSec are recorded in this file. The format follows

### Fixed

- `read_cabledyn_sections` reads a section placed on a deck node from that node's channels
alone: `CurvX`/`CurvY` on the components route, and `Ten`, `Twist` and `Torq` on every route.
Before, every section needed the channels of both nodes of its element, so a station written
at one node (the usual OUTPUTS request) could not be read without the next node's channels;
where both are written, the values are unchanged. A section just off a node (a
rounded arc length a few micrometres away) still needs both, and the error now names the
node and its arc length. On the components route the twist and torque histories are kept
at every section whose nodes write them; before, one section without `Twist` channels (a
hang-off node, say) dropped the twist of all of them, and `checks["torsion"]` called the
read twist-free although CableDyn's axes carry the twist.
- A constant curvature cycles nothing in the distributed helix model. A sample that repeats the
last one under the Coulomb bound now keeps the state in both kernels: its outputs equal the
last sample's bit for bit and it takes no substep. Before, the compiled kernel started such a
Expand Down
16 changes: 11 additions & 5 deletions doc/global_local_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,13 @@ rotating plane, separators, a missing column). The station reader takes one
station's columns under the names above; a CableDyn `.out` file holds them as
`Ten<L>N<J>`, `CurvX<L>N<J>` and `CurvY<L>N<J>` for every requested node, so a
station is passed to `series_from_curvature_components` from its three
columns. `read_cabledyn_sections` does not read `CurvX`/`CurvY`.
columns. `read_cabledyn_sections(..., curvature_source="components")` reads
them at the deck nodes around each section (Section 2); a section placed on a
deck node, at the arc length `CableDynLine.node_arc_lengths()` gives it, needs
that node's `CurvX`, `CurvY` and `Ten` channels only (and its `Twist`/`Torq`,
recorded where written). A station given by a rounded arc length a few
micrometres off its node needs the next node's channels too; the error names
the node and its arc length.

## 3. Sea-state batch

Expand Down Expand Up @@ -535,10 +541,10 @@ law (`xsec_stiffness`, the backbone of `compute_mkappa`) returned to CableDyn
as an element constitutive law with history (biaxial stick–slip state per
element and Gauss point, consistent tangent for the implicit integrator,
state transfer between steps and restarts), followed by the local recovery
of this guide on the consistently bent histories. Also open: hang-off roll
about the cable axis (from the vessel attitude), wave dynamic pressure,
temperature histories from a coupled thermal run, and conductor fatigue in
the batch.
of this guide on the consistently bent histories. Also open: wave dynamic
pressure, temperature histories from a coupled thermal run, and conductor
fatigue in the batch. (The hang-off roll about the cable axis is read since
the `hang_off_rotation` input and `curvature_source="components"`, Section 2.)

Two findings shape stage 2:

Expand Down
168 changes: 120 additions & 48 deletions src/cablexsec/io/cabledyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@
cannot carry them and is refused on such a line.
``curvature_source="components"`` reads CableDyn's ``CurvX``/``CurvY`` at the
deck nodes bracketing a section instead (linear between them, as the
tension), exact on CableDyn's axes and needing no node positions or angles. A line
tension), exact on CableDyn's axes and needing no node positions or angles.
A section on a deck node (its arc length equal to the node's, as
:meth:`CableDynLine.node_arc_lengths` gives it) reads that node's channels
alone, with no channel at the neighbouring nodes; the twist and torque of
this route are recorded at every section whose nodes write them, since the
axes carry the twist already. A line
restrained in torsion at both ends without these channels is rejected, and so
is a dynamic run of a line restrained at one end whose torsion CableDyn solves
(:attr:`CableDynLine.torsion_solved`): the polar inertia carries torsional
Expand Down Expand Up @@ -2404,6 +2409,8 @@ class _Plan:
window: list[int] # 0-based nodes of the curvature spline (its grid)
probe: bool = False
node: int = -1 # 0-based deck node of a curvature probe
# 0-based deck nodes of the node channels, with their linear weights
deck_nodes: tuple[tuple[int, float], ...] = ()
data: dict[str, list[FloatArray]] = field(default_factory=dict)


Expand All @@ -2412,6 +2419,52 @@ def _element_of(arcs: FloatArray, arc: float) -> int:
return min(max(index, 0), int(arcs.size) - 2)


def _deck_weights(
arcs: FloatArray, element: int, arc: float
) -> tuple[tuple[int, float], ...]:
"""Deck nodes whose channels give a section's node values, with weights.

A section on a deck node reads that node alone; any other section is
linear between the two nodes of its element.
"""
if arc == arcs[element]:
return ((element, 1.0),)
if arc == arcs[element + 1]:
return ((element + 1, 1.0),)
weight = float((arc - arcs[element]) / (arcs[element + 1] - arcs[element]))
return ((element, 1.0 - weight), (element + 1, weight))


def _at_deck_nodes(
values: FloatArray,
slot: Mapping[tuple[str, int], int],
kind: str,
nodes: tuple[tuple[int, float], ...],
) -> FloatArray:
"""A node channel at a section: the node's own column, or linear between two."""
if len(nodes) == 1:
return np.array(values[:, slot[(kind, nodes[0][0])]])
(lower, w_lower), (upper, w_upper) = nodes
return np.asarray(
w_lower * values[:, slot[(kind, lower)]]
+ w_upper * values[:, slot[(kind, upper)]]
)


def _nearest_node_hint(arcs: FloatArray, element: int, arc: float) -> str:
"""A note for a section that lies just off a deck node."""
length = float(arcs[element + 1] - arcs[element])
for node in (element, element + 1):
gap = abs(arc - float(arcs[node]))
if 0.0 < gap <= 1e-3 * length:
return (
f"; it lies {gap:.3g} m from deck node {node + 1} "
f"(s = {float(arcs[node])!r} m): a section at that arc length reads "
"that node's channels alone"
)
return ""


def _window(element: int, n_nodes: int, half: int) -> list[int]:
lo = max(0, element - half + 1)
hi = min(n_nodes - 1, element + half)
Expand Down Expand Up @@ -3056,7 +3109,8 @@ def read_cabledyn_sections(
``"auto"`` uses the tangent channels when every section has them and
positions otherwise; the choice is recorded. ``"components"`` takes
CableDyn's ``CurvX<L>N<J>``/``CurvY<L>N<J>`` (finite-EI lines) on
CableDyn's section axes (module notes).
CableDyn's section axes (module notes); a section on a deck node
needs that node's channels only.
tangent_placement : {"auto", "chord"}
Where the ``Dec``/``Azi`` values sit along the line. ``"auto"``
(CableDyn 0.4.2 and later): at the node on a finite-EI line, at the
Expand Down Expand Up @@ -3394,10 +3448,11 @@ def has_components(node: int) -> bool:
)
plans: list[_Plan] = []
for name, arc_deck, arc_pos, elem_deck, elem_pos, node in specs:
deck_nodes = _deck_weights(deck_arcs, elem_deck, arc_deck)
window = (
_window(elem_deck, n_deck, window_nodes)
if source == "tangent"
else [elem_deck, elem_deck + 1]
else [j for j, _ in deck_nodes]
if source == "components"
else _window(elem_pos, n_pos, window_nodes)
)
Expand All @@ -3414,6 +3469,11 @@ def has_components(node: int) -> bool:
raise CableSchemaError(
f"section {name!r}: curvature from {source} needs {what} "
f"at nodes {missing}"
+ (
_nearest_node_hint(deck_arcs, elem_deck, arc_deck)
if source == "components"
else ""
)
)
if missing:
continue # a probe without its window is not checked
Expand All @@ -3426,6 +3486,7 @@ def has_components(node: int) -> bool:
window,
probe=node >= 0,
node=node,
deck_nodes=deck_nodes,
)
)
sections_plans = [plan for plan in plans if not plan.probe]
Expand All @@ -3442,13 +3503,24 @@ def has_components(node: int) -> bool:
else:
checks["tangent_placement"] = "chord mid-arc (EI = 0 line)"

torsion_nodes = [(plan.elem_deck, plan.elem_deck + 1) for plan in sections_plans]
twist_available = all(
("twist", line_id, n + 1) in channels for pair in torsion_nodes for n in pair
)
torque_available = all(
("torq", line_id, n + 1) in channels for pair in torsion_nodes for n in pair
)
# Twist and torque channels at each section's nodes. The reconstructed
# frame needs the twist at every section; CableDyn's components carry it
# in their axes, so that route records them where they are written.
twist_at = {
plan.name: all(
("twist", line_id, n + 1) in channels for n, _ in plan.deck_nodes
)
for plan in sections_plans
}
torque_at = {
plan.name: all(("torq", line_id, n + 1) in channels for n, _ in plan.deck_nodes)
for plan in sections_plans
}
twist_available = all(twist_at.values())
torque_available = all(torque_at.values())
if source != "components":
twist_at = dict.fromkeys(twist_at, twist_available)
torque_at = dict.fromkeys(torque_at, torque_available)
if line.torsion_restrained and not twist_available and source != "components":
raise CableSchemaError(
f"line {line_id} is restrained in torsion; the material frame needs "
Expand Down Expand Up @@ -3494,7 +3566,18 @@ def has_components(node: int) -> bool:
"restrained_ends": sorted(line.torsion_restrained_ends),
"solved": line.torsion_solved,
"not_solved_because": line.torsion_note,
"material_twist": "Twist channels" if twist_available else "none (twist-free)",
"material_twist": (
"Twist channels"
if twist_available
else "in CableDyn's section axes (CurvX/CurvY); Twist channels at "
+ (
", ".join(repr(name) for name, ok in twist_at.items() if ok)
if any(twist_at.values())
else "no section"
)
if source == "components" and line.torsion_solved
else "none (twist-free)"
),
}

# How End A's material frame turns in time (module notes, hang-off).
Expand Down Expand Up @@ -3562,11 +3645,12 @@ def has_components(node: int) -> bool:
)
if not use_segments:
for plan in sections_plans:
for node in (plan.elem_deck, plan.elem_deck + 1):
for node, _ in plan.deck_nodes:
if ("ten", line_id, node + 1) not in channels:
raise CableSchemaError(
f"section {plan.name!r}: tension needs .Line{line_id}.t.out "
f"or Ten{line_id}N{node + 1} in the main output"
+ _nearest_node_hint(deck_arcs, plan.elem_deck, plan.arc)
)
# Main-table column plan.
main_cols: list[int] = [0]
Expand All @@ -3590,18 +3674,15 @@ def want(kind: str, node: int) -> None:
for node in pos_order:
for kind in ("px", "py", "pz"):
want(kind, node)
if not use_segments:
for plan in sections_plans:
want("ten", plan.elem_deck)
want("ten", plan.elem_deck + 1)
if twist_available:
for plan in sections_plans:
want("twist", plan.elem_deck)
want("twist", plan.elem_deck + 1)
if torque_available:
for plan in sections_plans:
want("torq", plan.elem_deck)
want("torq", plan.elem_deck + 1)
for plan in sections_plans:
for kind, wanted in (
("ten", not use_segments),
("twist", twist_at[plan.name]),
("torq", torque_at[plan.name]),
):
if wanted:
for node, _ in plan.deck_nodes:
want(kind, node)
probe_nodes = [plan.node for plan in plans if plan.probe]
for node in probe_nodes:
want("curv", node)
Expand Down Expand Up @@ -3668,7 +3749,6 @@ def want(kind: str, node: int) -> None:
_chunks(tensions_table, [0] + [1 + e for e in elements], chunk_rows)
)

deck_l0 = np.diff(deck_arcs)
# Arc length of each Dec/Azi value: the node's own tangent of a finite-EI
# line (CableDyn 0.4.2+) at the node; a chord (central, one-sided at the
# ends) at its mid-arc, the point of a smooth arc whose tangent it is. On a
Expand Down Expand Up @@ -3870,11 +3950,9 @@ def append(plan: _Plan, key: str, values: FloatArray) -> None:
e1 = _transport(e1, chords[:, k - 1], chords[:, k])
arc_e1[k] = e1
for plan in plans:
# Linear weights between the bracketing deck nodes (node
# channels) and position-grid nodes (positions).
weight = (plan.arc - deck_arcs[plan.elem_deck]) / deck_l0[
plan.elem_deck
]
# Linear weights between the bracketing position-grid nodes;
# the node channels take plan.deck_nodes (the node alone for
# a section on a deck node).
weight_pos = (plan.arc - pos_arcs[plan.elem_pos]) / pos_l0[
plan.elem_pos
]
Expand All @@ -3883,28 +3961,23 @@ def append(plan: _Plan, key: str, values: FloatArray) -> None:
# curvature) on its section axes (x, y): the rotation
# curvature on the same axes is (-CurvY, CurvX).
curv_x, curv_y = (
(1 - weight) * values[:, slot[(kind, plan.elem_deck)]]
+ weight * values[:, slot[(kind, plan.elem_deck + 1)]]
_at_deck_nodes(values, slot, kind, plan.deck_nodes)
for kind in ("curvx", "curvy")
)
append(plan, "norm", np.hypot(curv_x, curv_y))
if twist_available:
if twist_at[plan.name]:
append(
plan,
"twist",
np.radians(
(1 - weight)
* values[:, slot[("twist", plan.elem_deck)]]
+ weight
* values[:, slot[("twist", plan.elem_deck + 1)]]
_at_deck_nodes(values, slot, "twist", plan.deck_nodes)
),
)
if torque_available:
if torque_at[plan.name]:
append(
plan,
"torque",
(1 - weight) * values[:, slot[("torq", plan.elem_deck)]]
+ weight * values[:, slot[("torq", plan.elem_deck + 1)]],
_at_deck_nodes(values, slot, "torq", plan.deck_nodes),
)
append(plan, "kx", -curv_y)
append(plan, "ky", curv_x)
Expand Down Expand Up @@ -3964,8 +4037,7 @@ def append(plan: _Plan, key: str, values: FloatArray) -> None:
axis2 = np.cross(tangent, axis1)
if twist_available:
twist = np.radians(
(1 - weight) * values[:, slot[("twist", plan.elem_deck)]]
+ weight * values[:, slot[("twist", plan.elem_deck + 1)]]
_at_deck_nodes(values, slot, "twist", plan.deck_nodes)
)
cos, sin = np.cos(twist)[:, None], np.sin(twist)[:, None]
axis1, axis2 = (
Expand All @@ -3977,8 +4049,7 @@ def append(plan: _Plan, key: str, values: FloatArray) -> None:
append(
plan,
"torque",
(1 - weight) * values[:, slot[("torq", plan.elem_deck)]]
+ weight * values[:, slot[("torq", plan.elem_deck + 1)]],
_at_deck_nodes(values, slot, "torq", plan.deck_nodes),
)
append(plan, "kx", np.sum(kappa * axis1, axis=-1))
append(plan, "ky", np.sum(kappa * axis2, axis=-1))
Expand Down Expand Up @@ -4010,9 +4081,7 @@ def append(plan: _Plan, key: str, values: FloatArray) -> None:
:, ten_slot[lower + 1]
]
else:
ten = (1 - weight) * values[
:, slot[("ten", plan.elem_deck)]
] + weight * values[:, slot[("ten", plan.elem_deck + 1)]]
ten = _at_deck_nodes(values, slot, "ten", plan.deck_nodes)
append(plan, "tension", ten)
append(plans[0], "time", time)
n_rows += nt
Expand Down Expand Up @@ -4243,7 +4312,10 @@ def share(item: dict[str, Any]) -> float:
"in time by minimal rotation)"
),
"material twist from Twist channels"
if twist_available
if twist_at[plan.name]
else "material twist in CableDyn's section axes (no Twist "
"channels at the section)"
if source == "components" and line.torsion_solved
else "no material twist (line not restrained in torsion)",
"hydrostatic external pressure only (no wave dynamic pressure)"
if pressure == "hydrostatic"
Expand Down
Loading
Loading