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
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,13 @@ add_test(NAME aggregate_step_atomicity COMMAND test_aggregate_step_atomicity
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_tests_properties(aggregate_step_atomicity PROPERTIES LABELS "fortran;unit;dynamic;capi")

add_executable(test_line_values tests/test_line_values.f90)
target_link_libraries(test_line_values PRIVATE cabledyn_core)
add_test(NAME line_values_match_channels
COMMAND test_line_values ${CMAKE_CURRENT_SOURCE_DIR}/tests/data/lazy_wave_touchdown_planar_coarse.dat
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_tests_properties(line_values_match_channels PROPERTIES LABELS "fortran;unit;dynamic;capi")

add_executable(test_core_input_guards tests/test_core_input_guards.f90)
target_link_libraries(test_core_input_guards PRIVATE cabledyn_core)
add_test(NAME core_input_guards COMMAND test_core_input_guards WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
Expand Down
10 changes: 8 additions & 2 deletions doc/capi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1879,8 +1879,9 @@ handle numbers its lines 1..n).
one value per node; ``_SEGMENT_TENSION`` (9), one value per segment;
``_DECK_NODE`` (10), one value per node: the deck node ``J`` of the node (the ``<J>``
of the node channels), 0 for a node a mesh refinement added, ``1 … n_nodes`` on a line
meshed as the deck. ``n_out`` must equal the value count. A library without code 10
rejects it with ``CD_C_BAD_INPUT``.
meshed as the deck; ``_SECTION_CURVATURE`` (11), two values per node, ``CurvX`` and
``CurvY`` interleaved, on a finite-EI line. ``n_out`` must equal the value count. A library
without code 10 or 11 rejects it with ``CD_C_BAD_INPUT``.
* - ``CableDyn_GetPointState``
- position, velocity and the resultant force of the attached lines (``Point<P>F``),
3 doubles each
Expand All @@ -1902,6 +1903,11 @@ On a finite-EI line whose mesh the static solve refined, ``n_nodes`` and the
(:ref:`outputs-refined-nodes`); ``CD_C_LINE_DECK_NODE`` locates it: the array row whose value is
5.

``CableDyn_GetLineValues`` evaluates a whole line in one call, with no text token per node, and
each value is bit for bit the node channel's. It is the cheap way to read many nodes at every
step. Reading the tension, curvature and bend moment of a line after a step shares one evaluation
of its elements.

A ``NULL`` output pointer skips that output, except for the ``out`` array of
``CableDyn_GetLineValues`` and the ``value`` of ``CableDyn_EvalChannel``; the latter is not
checked and must point to valid storage. An index out of range, a wrongly sized buffer, an
Expand Down
3 changes: 2 additions & 1 deletion doc/outputs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,8 @@ chord from End A to End B, at the deck positions, heads within 45° of +X, and i
every other line. The cut of a line's range then lies at least 45° from its heading: a line
swaying about its heading reads continuously, where a line along +X would otherwise jump
between 0 and 360 as it moves a fraction of a degree to either side. The range is fixed for
the run, so the motion of the line cannot switch it. A round-off component across the cut
the run, so the motion of the line cannot switch it, and the same on every route: the standalone
driver, the C API and Python, and OpenFAST. A round-off component across the cut
reads on its included side (0, or 180 in the signed range), and one across +X reads exactly 0.
A line a host builds through the C interface without a deck reports [0, 360).

Expand Down
1 change: 1 addition & 0 deletions doc/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ state at the time of the call through the same evaluator as the deck ``OUTPUTS``
line = model.line(1)
xyz = line.node_positions() # (n_nodes, 3), End A first
seg = line.segment_tensions() # (n_segments,)
axes = line.section_curvature() # (n_nodes, 2): CurvX, CurvY of a finite-EI line
kappa = line.curvature() # (n_nodes,); bend_moment() on finite-EI lines
buf = np.empty_like(xyz)
for _ in range(100):
Expand Down
17 changes: 15 additions & 2 deletions python/cabledyn/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"declination",
"azimuth",
"segment_tension",
"section_curvature",
]
_LINE_QUANTITIES: dict[str, tuple[int, int]] = {
"position": (1, 3),
Expand All @@ -65,6 +66,7 @@
"declination": (7, 1),
"azimuth": (8, 1),
"segment_tension": (9, 1),
"section_curvature": (11, 2),
}

#: C ABI code of the deck node of each mesh node (``CD_C_LINE_DECK_NODE``).
Expand Down Expand Up @@ -219,7 +221,7 @@ def values(self, quantity: LineQuantity, out: FloatArray | None = None) -> Float
)
code, width = _LINE_QUANTITIES[quantity]
count = self.n_segments if quantity == "segment_tension" else self.n_nodes
shape = (count, 3) if width == 3 else (count,)
shape = (count, width) if width > 1 else (count,)
buf = _buffer(out, shape)
with self._model._lock:
handle = self._handle()
Expand Down Expand Up @@ -258,6 +260,14 @@ def curvature(self, out: FloatArray | None = None) -> FloatArray:
"""Curvature at each node ``(n_nodes,)`` [1/m] (``Curv<L>N<k>``)."""
return self.values("curvature", out)

def section_curvature(self, out: FloatArray | None = None) -> FloatArray:
"""Curvature on the section axes at each node ``(n_nodes, 2)`` [1/m].

Columns ``CurvX<L>N<k>`` and ``CurvY<L>N<k>``, on a finite-EI line; one evaluation
for the whole line, so it is much cheaper than a channel per node.
"""
return self.values("section_curvature", out)

def bend_moment(self, out: FloatArray | None = None) -> FloatArray:
"""Bend moment magnitude at each node ``(n_nodes,)`` [N-m]; zero when EI = 0."""
return self.values("bend_moment", out)
Expand All @@ -267,7 +277,10 @@ def declination(self, out: FloatArray | None = None) -> FloatArray:
return self.values("declination", out)

def azimuth(self, out: FloatArray | None = None) -> FloatArray:
"""Azimuth at each node ``(n_nodes,)`` [deg] (``L<L>N<k>Azi``)."""
"""Azimuth at each node ``(n_nodes,)`` [deg] (``L<L>N<k>Azi``), in the line's range.

(-180, 180] on a line whose deck chord heads within 45 deg of +X, otherwise [0, 360).
"""
return self.values("azimuth", out)

def arc_length(self) -> FloatArray:
Expand Down
21 changes: 21 additions & 0 deletions python/tests/test_host_fluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,24 @@ def test_the_stepping_example_runs():
tensions = runpy.run_path(str(example))["main"](duration=2.0)
assert len(tensions) == 40
assert all(math.isfinite(value) and value > 0.0 for value in tensions)


def test_section_curvature_of_a_line_matches_its_channels(tmp_path):
deck = _deck(tmp_path, "library", "", STIFFENER)
with CableDyn() as model:
model.init_deck_rotating(deck)
model.calc_output()
line = model.lines[0]
values = line.section_curvature()
assert values.shape == (line.n_nodes, 2)
tokens = [f"Curv{axis}1N{j}" for j in range(1, line.n_nodes + 1) for axis in "XY"]
expected = model.channels(tokens).reshape(-1, 2)
np.testing.assert_array_equal(values, expected)
assert np.abs(values).max() > 0.0
np.testing.assert_allclose(np.hypot(*values.T), line.curvature(), rtol=1e-9, atol=1e-12)


def test_section_curvature_needs_a_finite_ei_line(tmp_path):
with CableDyn(_deck(tmp_path, "library", "", template=EI0_DECK)) as model:
with pytest.raises(CableDynError, match="finite-EI"):
model.lines[0].section_curvature()
92 changes: 92 additions & 0 deletions python/tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from __future__ import annotations

import math
import os
import re
from pathlib import Path
Expand Down Expand Up @@ -270,6 +271,97 @@ def test_body_and_rod_decks_match_driver_outputs_at_the_initial_state(tmp_path):
_check_row(model, result, 0.0)


def _heading_deck(cables: bool) -> tuple[str, dict[int, float]]:
"""Lines on headings on both sides of +x, and the azimuth each must report at End A.

Line ``2 k`` runs in its vertical plane from its own coupled point to its own anchor. Within
45 deg of +x the range is (-180, 180], otherwise [0, 360). With ``cables`` every second line
is finite-EI, which puts the deck on the mixed route.
"""
headings = [-46.0, -44.0, -30.0, -10.0, -1.0, 1.0, 10.0, 30.0, 44.0, 46.0, 180.0, 270.0]
points, lines, sections, outputs, expected = [], [], [], [], {}
for k, heading in enumerate(headings, start=1):
cable = cables and k % 2 == 0
reach = 70.0 if cable else 240.0
cx, sy = math.cos(math.radians(heading)), math.sin(math.radians(heading))
points.append(f"{2 * k - 1} Coupled {5.0 * cx:.15e} {5.0 * sy:.15e} -10.0")
points.append(f"{2 * k} Fixed {(5.0 + reach) * cx:.15e} {(5.0 + reach) * sy:.15e} -60.0")
lines.append(f"{2 * k} {2 * k - 1} {2 * k} -")
sections.append(f"{2 * k} {'cable 100.0 20' if cable else 'chain 260.0 13'}")
outputs.append(f"L{2 * k}N1Azi")
expected[2 * k] = heading if abs(heading) < 45.0 else heading % 360.0
text = "\n".join(
[
"Lines on both sides of +x",
"--- LINE TYPES ---",
"Name Diam Mass EA BA EI Cdn Cdt Can Cat",
"(-) (m) (kg/m) (N) (-) (Nm2) (-) (-) (-) (-)",
"cable 0.16 36.7 4.69e8 -1.0 1.99e4 1.2 0.1 1.0 0.0",
"chain 0.10 150.0 8.0e8 -1.0 0.0 1.2 0.4 1.0 0.5",
"--- POINTS ---",
"ID Type X Y Z",
"(-) (-) (m) (m) (m)",
*points,
"--- LINES ---",
"ID NodeA NodeB Outputs",
"(-) (-) (-) (-)",
*lines,
"--- SECTIONS ---",
"LineID LineType Length NumSegs",
"(-) (-) (m) (-)",
*sections,
"--- OPTIONS ---",
"9.80665 g",
"1025.0 rhoW",
"60.0 WtrDpth",
"1.0e6 kBot",
"1.0e5 cBot",
"0.02 dtM",
"0.04 TMax",
"--- OUTPUTS ---",
*outputs,
"--- need this line ---",
"",
]
)
return text, expected


@needs_driver
@pytest.mark.parametrize("cables", [False, True], ids=["ei0", "mixed"])
def test_azimuth_range_is_the_same_on_every_route(tmp_path, cables):
text, expected = _heading_deck(cables)
deck = _write(tmp_path, "headings.dat", text)
result = _driver_run(deck, tmp_path)
main = result.read_main()
# a run without dtM and TMax stops at the static solution, which an EI = 0 deck writes out
static_text = text.replace("0.02 dtM\n", "").replace("0.04 TMax\n", "")
static_deck = _write(tmp_path, "headings_static.dat", static_text)
static = _driver_run(static_deck, tmp_path).read_static()
with CableDyn(deck) as model:
for line_id, azimuth in expected.items():
token = f"L{line_id}N1Azi"
driver = float(main.values[0, list(main.channels).index(token)])
assert driver == pytest.approx(azimuth, abs=1.0e-5), f"driver {token}"
assert model.channel(token) == pytest.approx(azimuth, abs=1.0e-6), f"library {token}"
line = model.line(line_id)
np.testing.assert_allclose(line.azimuth(), azimuth, rtol=0.0, atol=1.0e-6)
profile = static.line(line_id).column("Azimuth")
np.testing.assert_allclose(profile, azimuth, rtol=0.0, atol=1.0e-5)


@needs_driver
def test_azimuth_range_of_a_line_on_a_body(tmp_path):
text = _BODY_DECK.replace("4 Fixed 40.0 0.0 -100.0", "4 Fixed 40.0 -10.0 -100.0")
text = text.replace('"FairTen1"\n', '"FairTen1"\n"L1N1Azi"\n')
deck = _write(tmp_path, "body_heading.dat", text)
main = _driver_run(deck, tmp_path).read_main()
driver = float(main.values[0, list(main.channels).index("L1N1Azi")])
with CableDyn(deck) as model:
assert model.channel("L1N1Azi") == pytest.approx(driver, abs=1.0e-5)
assert -45.0 < driver < 0.0


# --- library-only gates --------------------------------------------------------


Expand Down
Loading
Loading