From 3d42c12386e16d4bffb342f528515d8be91281d3 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Sun, 8 Nov 2026 17:36:11 +0900 Subject: [PATCH 1/2] fix(outputs): the tangent outputs of a finite-EI line take its tangent DOF The declination and azimuth of a finite-EI node were taken from a difference of node positions (central inside, one-sided at an end), the direction of a chord. A finite-EI node has its own tangent, the Hermite DOF m = dr/ds. Where the line bends within an element the two differ: at an end clamped by an END CONNECTIONS Rigid row the end tangent read 171.15 deg for a vertical (180 deg) clamp, 163.83 deg for 165 deg and 148.87 deg for 135 deg, up to 14 deg off; with a current the vertical clamp of a cable read 167.08 deg. line_geom_value and line_geom_values now take the angles of a finite-EI node (stride-6 state) from its tangent DOF, normalised and oriented End A -> End B (cable_node_tangent), and the range graph's declination of a cable reads the same. This is the shared evaluator of every finite-EI route, so LNDec/Azi, FairDecl/AnchDecl, FairIncl/ AnchIncl and FairAngle/AnchAngle, the Declination, Inclination and Azimuth columns of .static.out, the range graph and the line tangent of the initialisation reports change together on the standalone, mixed and multibody routes, through the C API (CableDyn_GetLineValues, channels, notes) and in the OpenFAST shell, which reads them from the aggregate. EI = 0 lines, whose segments are straight, keep the difference of node positions. outputs.rst defines the node tangent of both. Tests: end_tangent_channels clamps a cable at End A at declinations of 120 to 180 deg and azimuths of 0 and 20 deg and pins End B. At the clamp the channels equal the clamp's angles to 1.4e-14 deg (14.1 deg off before), at the pinned end and every other node the angle of the solution's tangent DOF to 2.8e-14 deg (5.4 deg off before). driver_end_tangent_channels checks the channels, the static profile, the range graph and the reports of the standalone and mixed routes, and test_end_tangent.py the C API line values. Examples: the finite-EI tangent outputs change, by up to 3.1 deg in the line tangent report of buoy_clamped_cable.dat (now the clamp direction turned with its buoy), 1.8 deg in the static Declination of lozon_gomex80_power_cable_motion.dat, 1.4 deg in that of iea15mw_umaine_mixed_cabledyn.dat, 0.63 deg in the FairIncl1 history of lazy_wave_vessel_motion.dat and 0.49 deg in the range graph of torsion_lazy_wave_hangoff_twist.dat; 0.2 deg or less elsewhere. Positions, forces, tensions, curvatures and every EI = 0 example are bit-identical. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 17 +++ CMakeLists.txt | 15 +++ doc/outputs.rst | 24 +++- doc/tutorial_openfast.rst | 2 +- python/tests/test_end_tangent.py | 69 ++++++++++++ src/CableDyn_DeckDriver.f90 | 68 ++++++++++-- tests/check_end_tangent_channels.py | 135 +++++++++++++++++++++++ tests/test_driver_channels.f90 | 35 +++++- tests/test_end_tangent_channels.f90 | 163 ++++++++++++++++++++++++++++ tests/test_openfast_aggregate.f90 | 10 +- 10 files changed, 517 insertions(+), 21 deletions(-) create mode 100644 python/tests/test_end_tangent.py create mode 100644 tests/check_end_tangent_channels.py create mode 100644 tests/test_end_tangent_channels.f90 diff --git a/CHANGELOG.md b/CHANGELOG.md index e3549554..5e111d30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,23 @@ All notable changes to CableDyn are recorded in this file. The format follows The touchdown element now takes the reaction of its grounded stretch, from the grounded node to the touchdown point located from the two nodes' clearances: the error falls at the second order (2.1, 0.7, 0.2 N) and the outputs vary continuously. +- The tangent outputs of a finite-EI line take the line's tangent, the node's Hermite tangent + DOF, instead of a difference of node positions. At an end clamped by an `END CONNECTIONS` + `Rigid` row they now give the direction the clamp holds: a cable clamped 15 deg off the + vertical read 163.8 deg for a 165 deg clamp, and up to 14 deg off where the line bends within + its first element. + +### Upgrading + +- On finite-EI lines `LNDec` and `LNAzi`, `FairDecl`/`AnchDecl`, `FairIncl`/`AnchIncl` + and `FairAngle`/`AnchAngle`, the `Declination`, `Inclination` and `Azimuth` columns of + `.static.out`, the `Declination` envelope of the range graph and the `line tangent` of the + initialisation reports (driver, mixed route, C API notes and OpenFAST) change: by up to 3.1 deg + at the clamped end of `buoy_clamped_cable.dat`, 1.8 deg in the static profile of + `lozon_gomex80_power_cable_motion.dat` (1.4 deg in `iea15mw_umaine_mixed_cabledyn.dat`, 0.5 deg + in `torsion_lazy_wave_hangoff_twist.dat`) and 0.6 deg in the `FairIncl1` history of + `lazy_wave_vessel_motion.dat`, and by 0.2 deg or less on the other finite-EI examples. + Positions, forces, tensions, curvatures and every `EI = 0` line are unchanged. ## [0.4.1] - 2026-11-08 diff --git a/CMakeLists.txt b/CMakeLists.txt index b2b4b1fb..96dcf84c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1284,6 +1284,12 @@ add_executable(test_static_dry_weight tests/test_static_dry_weight.f90) target_link_libraries(test_static_dry_weight PRIVATE cabledyn_core) add_test(NAME static_dry_weight COMMAND test_static_dry_weight WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) set_tests_properties(static_dry_weight PROPERTIES LABELS "fortran;integration;static;openfast") +# The tangent channels of a finite-EI line read its tangent DOF: at a clamped end the clamp's +# angles, at a pinned end and every other node the solution's tangent. +add_executable(test_end_tangent_channels tests/test_end_tangent_channels.f90) +target_link_libraries(test_end_tangent_channels PRIVATE cabledyn_core) +add_test(NAME end_tangent_channels COMMAND test_end_tangent_channels WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) +set_tests_properties(end_tangent_channels PROPERTIES LABELS "fortran;integration;static;outputs" TIMEOUT 600) add_executable(test_viv_kernels tests/test_viv_kernels.f90) target_link_libraries(test_viv_kernels PRIVATE cabledyn_core) @@ -2816,6 +2822,15 @@ if(Python3_Interpreter_FOUND) LABELS "python;driver;integration;static;validation" SKIP_RETURN_CODE 77 ENVIRONMENT "${_cabledyn_python_test_environment}") + # The end tangent outputs of a clamped finite-EI line (channels, static profile, range graph, + # initialisation reports on the finite-EI and mixed routes) are the clamp's angles. + add_test(NAME driver_end_tangent_channels + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/check_end_tangent_channels.py + $) + set_tests_properties(driver_end_tangent_channels PROPERTIES + LABELS "python;driver;integration;static;outputs" + TIMEOUT 600 + ENVIRONMENT "${_cabledyn_python_test_environment}") endif() # The scan of the round-off CI job: it must flag a fallback note, a failed run and a forced # BLAS kernel that did not take effect, or a clean scan would prove nothing. diff --git a/doc/outputs.rst b/doc/outputs.rst index f2b132e1..b8e57daa 100644 --- a/doc/outputs.rst +++ b/doc/outputs.rst @@ -218,7 +218,8 @@ finite-EI line of the run: stiffener); written as 0 by the ``EI = 0`` static route * - ``Declination`` - ``(deg)`` - - axial-tangent angle from +Z (0 = up, 90 = horizontal, 180 = down) + - axial-tangent angle from +Z (0 = up, 90 = horizontal, 180 = down); the + :ref:`node tangent ` * - ``Inclination`` - ``(deg)`` - signed inclination below horizontal, ``Declination āˆ’ 90`` @@ -608,7 +609,8 @@ Line-end channels availability; for an anchor that holds one line it equals ``Point

FH`` - N * - ``FairIncl`` / ``AnchIncl`` - - signed inclination of the End-A / End-B tangent below horizontal + - signed inclination of the End-A / End-B tangent (:ref:`node tangent `) + below horizontal (``Decl āˆ’ 90``: 0 = horizontal, +90 = pointing down, āˆ’90 = pointing up) - deg * - ``FairDecl`` / ``AnchDecl`` @@ -751,7 +753,8 @@ Line-node channels - node acceleration component (0 on a static run) - m/s² * - ``LNDec`` - - declination of the node's axial tangent from +Z (0 = up, 90 = horizontal, 180 = down) + - declination of the node's axial tangent from +Z (0 = up, 90 = horizontal, 180 = down); + the :ref:`node tangent ` - deg * - ``LNAzi`` - azimuth of the node's axial tangent from +X toward +Y, in the line's range @@ -944,6 +947,21 @@ The axial tangent of every orientation channel points from End A toward End B (O ``Ez`` axis). Curvature, declination and azimuth are evaluated from the solved geometry on every route (static, ``EI = 0`` dynamic, finite-EI dynamic, rod and Rigid6 decks). +.. _outputs-node-tangent: + +The tangent of a node is the line's own direction there. On a finite-EI line it is the node's +tangent degree of freedom :math:`\mathbf r_{,s}` of the cubic-Hermite centreline, normalised: at +an end clamped by an ``END CONNECTIONS`` ``Rigid`` row it is the direction the connection holds, +at an end on a rotational spring the direction the spring lets the line take, and at every other +node the tangent of the solution, continuous through the node. On an ``EI = 0`` line, whose segments are straight, it is the direction from +the previous to the next node (from the end node to its neighbour at an end). The +``LNDec``/``Azi`` channels, ``FairDecl``/``AnchDecl``, ``FairIncl``/``AnchIncl`` and +their aliases, the ``Declination``, ``Inclination`` and ``Azimuth`` columns of ``.static.out``, +the ``Declination`` envelope of the range graph and the ``line tangent`` of the initialisation +reports all take it, on every route (the standalone driver, the mixed and multibody routes, the +C API and Python, and OpenFAST). :func:`cabledyn.line_geometry` is a post-processing estimate from +the node positions alone. + Validation of channel names ~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/tutorial_openfast.rst b/doc/tutorial_openfast.rst index 684bd368..b89d9b1a 100644 --- a/doc/tutorial_openfast.rst +++ b/doc/tutorial_openfast.rst @@ -339,7 +339,7 @@ seabed. Copy it into the case folder and point a copy of the ``.fst`` at it: ... Line 4 fairlead effective tension: 11922 N force [Fx, Fy, Fz]: [1230, 0, -11858] N, inclination=84.078 deg - line tangent: inclination=83.943 deg, declination=173.94 deg, azimuth=0 deg + line tangent: inclination=83.973 deg, declination=173.97 deg, azimuth=0 deg ... Curv4N38 = 9.01822E-02 (1/m) BendMom4N38 = 1794.6 (N.m) diff --git a/python/tests/test_end_tangent.py b/python/tests/test_end_tangent.py new file mode 100644 index 00000000..54dd89d7 --- /dev/null +++ b/python/tests/test_end_tangent.py @@ -0,0 +1,69 @@ +# SPDX-License-Identifier: Apache-2.0 +"""The tangent of a finite-EI line in process: at an end clamped by END CONNECTIONS Rigid the +declination and azimuth the C API returns are the clamp's, and the line values match the +channels (aggregate route).""" + +from __future__ import annotations + +import math +from pathlib import Path + +import pytest + +try: + import cabledyn._lib # noqa: F401 (loads the shared library) +except (ImportError, OSError) as exc: # a missing library raises OSError + pytest.skip(f"CableDyn shared library not available: {exc}", allow_module_level=True) + +from cabledyn.model import CableDyn + +_BAR = "-" * 21 + + +def _deck(path: Path, declination: float, azimuth: float) -> Path: + d, a = math.radians(declination), math.radians(azimuth) + ez = (math.sin(d) * math.cos(a), math.sin(d) * math.sin(a), math.cos(d)) + path.write_text( + f"""{_BAR} CableDyn Input File {_BAR} +a cable clamped at End A +{_BAR} LINE TYPES {_BAR} +Name Diam Mass EA BA EI Cdn Cdt Can Cat +cable 0.2 60.0 1.0e8 -1.0 1.0e4 1.2 0.008 1.0 0.0 +{_BAR} POINTS {_BAR} +ID Type X Y Z Mass Vol CdA Ca +1 Coupled 0.0 0.0 -10.0 0 0 0 0 +2 Fixed 80.0 0.0 -80.0 0 0 0 0 +{_BAR} LINES {_BAR} +ID NodeA NodeB Outputs +1 1 2 - +{_BAR} SECTIONS {_BAR} +LineID LineType Length NumSegs +1 cable 125.0 100 +{_BAR} END CONNECTIONS {_BAR} +LineID End Stiffness EzX EzY EzZ +1 A Rigid {ez[0]:.17g} {ez[1]:.17g} {ez[2]:.17g} +{_BAR} OPTIONS {_BAR} +9.80665 g +1025.0 rhoW +0.05 dtM +1.0 TMax +{_BAR} OUTPUTS {_BAR} +FairDecl1 +{_BAR} need this line {_BAR} +""", + encoding="utf-8", + ) + return path + + +@pytest.mark.parametrize(("declination", "azimuth"), [(165.0, 0.0), (135.0, 20.0)]) +def test_the_clamped_end_reads_the_clamp(tmp_path, declination, azimuth): + with CableDyn(_deck(tmp_path / "clamp.dat", declination, azimuth)) as model: + line = model.line(1) + dec, azi = line.declination(), line.azimuth() + assert dec[0] == pytest.approx(declination, abs=1.0e-9) + assert azi[0] == pytest.approx(azimuth, abs=1.0e-9) + assert model.channel("FairDecl1") == pytest.approx(declination, abs=1.0e-9) + # the ends of the line's mesh (refined at the clamp) are its deck end nodes + assert dec[0] == model.channel("L1N1Dec") and azi[0] == model.channel("L1N1Azi") + assert dec[-1] == model.channel("AnchDecl1") diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index bb3317d5..0e6abd55 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -36621,12 +36621,28 @@ END FUNCTION wrap_azimuth_deg PURE REAL(wp) FUNCTION line_geom_value(kind, deck_node, nnode, q_flat, stride, signed) RESULT(v) !! Shared evaluator for the GEOMETRIC output channels so every writer computes them - !! identically. `q_flat` holds the line node positions in INTERNAL order - !! (anchor->fairlead) with `stride` reals per node (3 for EI=0, 6 for finite-EI). + !! identically. `q_flat` holds the line node states in INTERNAL order + !! (anchor->fairlead) with `stride` reals per node (3 for EI=0: the position; 6 for + !! finite-EI: the position and the tangent DOF m = dr/ds). !! kind: 5 curvature, 7 declination, 8 azimuth. Bend moment is NOT geometric -- it is !! the MATERIAL moment EI*(kappa - kappa_0), computed per path (zero on EI=0 lines; !! eval_cable_channel and range_sample_cable on finite-EI lines), so it is not handled here and - !! kind = 6 returns 0. signed: the line's azimuth range (DeckLine%azi_signed). + !! kind = 6 returns 0. signed: the line's azimuth range (DeckLine%azi_signed). The + !! declination and azimuth of a finite-EI node are those of its tangent DOF + !! (cable_node_tangent), of an EI = 0 node those of the difference of node positions + !! (deck_node_tangent). + INTEGER, INTENT(IN) :: kind, deck_node, nnode, stride + REAL(wp), INTENT(IN) :: q_flat(:) + LOGICAL, INTENT(IN), OPTIONAL :: signed + IF (stride >= 6 .AND. (kind == 7 .OR. kind == 8)) THEN + v = cable_tangent_angle(kind, cable_node_tangent(q_flat, stride, nnode, deck_node), signed) + ELSE + v = position_geom_value(kind, deck_node, nnode, q_flat, stride, signed) + END IF + END FUNCTION line_geom_value + + PURE REAL(wp) FUNCTION position_geom_value(kind, deck_node, nnode, q_flat, stride, signed) RESULT(v) + !! line_geom_value from the node positions alone (line_geom_from_r), q_flat as there. INTEGER, INTENT(IN) :: kind, deck_node, nnode, stride REAL(wp), INTENT(IN) :: q_flat(:) LOGICAL, INTENT(IN), OPTIONAL :: signed @@ -36638,21 +36654,56 @@ PURE REAL(wp) FUNCTION line_geom_value(kind, deck_node, nnode, q_flat, stride, s r(:, j) = q_flat(base + 1:base + 3) END DO v = line_geom_from_r(kind, r, nnode, deck_node, signed) - END FUNCTION line_geom_value + END FUNCTION position_geom_value PURE SUBROUTINE line_geom_values(kind, nnode, stride, q, signed, values) !! line_geom_value at every deck node of a line. q(:, n) is internal node n's state, its first - !! three entries the position; the deck-ordered positions are read in place, not copied. + !! three entries the position (and on a finite-EI line, stride 6, the next three its tangent + !! DOF); the deck-ordered positions are read in place, not copied. INTEGER, INTENT(IN) :: kind, nnode, stride REAL(wp), INTENT(IN) :: q(stride, nnode) LOGICAL, INTENT(IN) :: signed REAL(wp), INTENT(OUT) :: values(nnode) INTEGER :: j + IF (stride >= 6 .AND. (kind == 7 .OR. kind == 8)) THEN + DO j = 1, nnode + ! deck node j is internal node nnode + 1 - j, whose tangent runs End B -> End A + values(j) = cable_tangent_angle(kind, -q(4:6, nnode + 1 - j), signed) + END DO + RETURN + END IF DO j = 1, nnode values(j) = line_geom_from_r(kind, q(1:3, nnode:1:-1), nnode, j, signed) END DO END SUBROUTINE line_geom_values + PURE FUNCTION cable_node_tangent(q_flat, stride, nnode, deck_node) RESULT(t) + !! The axial tangent of a finite-EI line at a deck node, oriented End A -> End B: its tangent + !! DOF m = dr/ds (q_flat in internal order, anchor -> fairlead, stride reals per node, the + !! position then m), reversed, as the internal arc length runs from End B. It is the line's + !! own direction at the node: the direction an END CONNECTIONS row holds at a restrained + !! end, continuous through the node, where a difference of node positions is the direction + !! of a chord. + REAL(wp), INTENT(IN) :: q_flat(:) + INTEGER, INTENT(IN) :: stride, nnode, deck_node + REAL(wp) :: t(3) + INTEGER :: base + base = stride*(nnode - MIN(MAX(deck_node, 1), nnode)) + t = -q_flat(base + 4:base + 6) + END FUNCTION cable_node_tangent + + PURE REAL(wp) FUNCTION cable_tangent_angle(kind, t, signed) RESULT(v) + !! kind 7: the declination [deg] of the tangent t; 8: its azimuth, in the line's range. + INTEGER, INTENT(IN) :: kind + REAL(wp), INTENT(IN) :: t(3) + LOGICAL, INTENT(IN), OPTIONAL :: signed + IF (kind == 7) THEN + v = tangent_declination_deg(t) + ELSE + v = tangent_azimuth_deg(t, signed) + END IF + END FUNCTION cable_tangent_angle + PURE REAL(wp) FUNCTION line_geom_from_r(kind, r, nnode, deck_node, signed) RESULT(v) !! Geometric channel value (kind: 5 curvature, 7 declination, 8 azimuth) from the !! deck-ordered node positions r(3, nnode). Factored out of line_geom_value so a caller @@ -37222,13 +37273,10 @@ SUBROUTINE range_sample_cable(cable, rl, ErrStat, ErrMsg) IF (cable%line%nn /= nn .OR. cable%line%ne /= ne .OR. SIZE(cable%line%q) < 6*nn) THEN CALL fail_solve(ErrStat, ErrMsg, 'range-graph sample: cable state not available'); RETURN END IF - DO j = 1, nn - inode = nn + 1 - j - rl%r(:, j) = cable%line%q(6*(inode - 1) + 1:6*(inode - 1) + 3) - END DO IF (rl%want_range) THEN + ! the declination of each node's tangent DOF (cable_node_tangent), as LNDec DO j = 1, nn - rl%val(CD_RQ_DECLINATION, j) = line_geom_from_r(7, rl%r, nn, j) + rl%val(CD_RQ_DECLINATION, j) = cable_tangent_angle(7, cable_node_tangent(cable%line%q, 6, nn, j)) END DO END IF DO j = 1, nn diff --git a/tests/check_end_tangent_channels.py b/tests/check_end_tangent_channels.py new file mode 100644 index 00000000..8121a280 --- /dev/null +++ b/tests/check_end_tangent_channels.py @@ -0,0 +1,135 @@ +# SPDX-License-Identifier: Apache-2.0 +"""The tangent outputs of a finite-EI line clamped at End A, through the standalone driver +(driver_end_tangent_channels in CMakeLists.txt). + +A cable is clamped at End A (END CONNECTIONS Rigid) along a set direction, swept over +declinations of 120 to 180 deg and azimuths of 0 and 20 deg, and pinned at End B. Every output +of the end tangent must equal the clamp's angles to round-off (1e-6 deg, the printed digits +allowing): the FairDecl, FairIncl, L1N1Dec and L1N1Azi channels, the first row of +the static profile (Declination, Inclination, Azimuth), the range graph's DeclinationMin and +DeclinationMax at node 1 over a short held march, and the ``line tangent`` line of the +initialisation report. The line bends within its first element at the clamp, where a +difference of node positions reads several degrees off. The same deck with an EI = 0 chain +beside the cable runs on the mixed route, whose fairlead report must give the clamp too. + +Usage: check_end_tangent_channels.py +""" + +import math +import pathlib +import re +import subprocess +import sys +import tempfile + +DECLINATIONS = (180.0, 165.0, 150.0, 135.0, 120.0) +AZIMUTHS = (0.0, 20.0) +TOL = 1.0e-6 +CHANNELS = ("FairDecl1", "FairIncl1", "L1N1Dec", "L1N1Azi") + + +def deck(dec: float, azi: float, mixed: bool) -> str: + d, a = math.radians(dec), math.radians(azi) + ez = (math.sin(d) * math.cos(a), math.sin(d) * math.sin(a), math.cos(d)) + types = "cable 0.2 60.0 1.0e8 -1.0 1.0e4 1.2 0.008 1.0 0.0\n" + points = "1 Coupled 0.0 0.0 -10.0 0 0 0 0\n2 Fixed 80.0 0.0 -80.0 0 0 0 0\n" + lines = "1 1 2 r\n" + sections = "1 cable 125.0 100\n" + if mixed: + types += "chain 0.1 20.0 5.0e8 -1.0 0.0 1.2 0.4 1.0 0.0\n" + points += "3 Coupled 0.0 50.0 -10.0 0 0 0 0\n4 Fixed 80.0 50.0 -80.0 0 0 0 0\n" + lines = "1 1 2 -\n2 3 4 -\n" + sections += "2 chain 125.0 40\n" + outputs = "".join(f'"{c}"\n' for c in CHANNELS) + return f"""--------------------- CableDyn Input File ------------------------------------ +tangent outputs of a cable clamped at End A +--------------------- LINE TYPES --------------------------------------------- +TypeName Diam MassDenInAir EA BA/-zeta EI Cd_n Cd_t Ca_n Ca_t +(-) (m) (kg/m) (N) (N-s/-) (N-m^2) (-) (-) (-) (-) +{types}--------------------- POINTS ------------------------------------------------- +ID Type X Y Z Mass Vol CdA Ca +(-) (-) (m) (m) (m) (kg) (m^3) (m^2) (-) +{points}--------------------- LINES -------------------------------------------------- +ID NodeA NodeB Outputs +(-) (-) (-) (-) +{lines}--------------------- SECTIONS ----------------------------------------------- +LineID LineType Length NumSegs +(-) (-) (m) (-) +{sections}--------------------- END CONNECTIONS ---------------------------------------- +LineID End Stiffness EzX EzY EzZ +(-) (-) (N-m/rad) (-) (-) (-) +1 A Rigid {ez[0]:.17g} {ez[1]:.17g} {ez[2]:.17g} +--------------------- OPTIONS ------------------------------------------------ +9.80665 g +1025.0 rhoW +0.05 dtM +{0.0 if mixed else 0.1} TMax +--------------------- OUTPUTS ------------------------------------------------ +{outputs}END +""" + + +def table(path: pathlib.Path, skip: int) -> tuple[list[str], list[list[float]]]: + rows = path.read_text().splitlines() + names = [n.split("(")[0] for n in rows[1].split()] + return names, [[float(v) for v in r.split()] for r in rows[skip:] if r.strip()] + + +def main() -> int: + exe = sys.argv[1] + failures = [] + + def check(ok: bool, what: str, got: float, want: float) -> None: + print(("ok " if ok else "FAIL ") + f"{what}: {got:.9f} deg (clamp {want:.9f})") + if not ok: + failures.append(what) + + with tempfile.TemporaryDirectory() as folder: + tmp = pathlib.Path(folder) + for dec in DECLINATIONS: + for azi in AZIMUTHS if dec < 180.0 else (0.0,): + tag = f"d{dec:g}_a{azi:g}" + want = {"FairDecl1": dec, "FairIncl1": dec - 90.0, "L1N1Dec": dec, + "L1N1Azi": azi} + for mixed in (False, True): + name = tag + ("_mixed" if mixed else "") + (tmp / f"{name}.dat").write_text(deck(dec, azi, mixed)) + proc = subprocess.run([exe, f"{name}.dat", name], cwd=tmp, capture_output=True, text=True) + if proc.returncode != 0: + failures.append(f"{name}: the driver failed") + print(f"FAIL {name}: the driver failed:\n{(proc.stdout + proc.stderr)[-1500:]}") + continue + log = proc.stdout + proc.stderr + if mixed: + match = re.search(r"Line 1: FairTen=\s*\S+ N, tangent inclination=\s*(\S+) deg", log) + got = float(match.group(1)) if match else math.nan + check(abs(got - (dec - 90.0)) <= 1.0e-3, f"{name} mixed report inclination", got, dec - 90.0) + continue + names, rows = table(tmp / f"{name}.out", 2) + for ch in CHANNELS: + if ch == "L1N1Azi" and dec == 180.0: + continue + got = rows[0][names.index(ch)] + check(abs(got - want[ch]) <= TOL, f"{name} {ch} at t = 0", got, want[ch]) + names, rows = table(tmp / f"{name}.static.out", 3) + first = rows[0] + check(abs(first[names.index("Declination")] - dec) <= TOL, f"{name} static Declination", + first[names.index("Declination")], dec) + check(abs(first[names.index("Inclination")] - (dec - 90.0)) <= TOL, + f"{name} static Inclination", first[names.index("Inclination")], dec - 90.0) + if dec < 180.0: + check(abs(first[names.index("Azimuth")] - azi) <= TOL, f"{name} static Azimuth", + first[names.index("Azimuth")], azi) + names, rows = table(tmp / f"{name}.Line1.range.out", 3) + for col in ("DeclinationMin", "DeclinationMax"): + got = rows[0][names.index(col)] + check(abs(got - dec) <= TOL, f"{name} range {col}", got, dec) + match = re.search(r"line tangent: inclination=\s*(\S+) deg, declination=\s*(\S+) deg", log) + got = float(match.group(2)) if match else math.nan + check(abs(got - dec) <= 1.0e-3, f"{name} report declination", got, dec) + print("PASS" if not failures else f"FAIL: {len(failures)} check(s)") + return 0 if not failures else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/test_driver_channels.f90 b/tests/test_driver_channels.f90 index a5758b3e..e8bde6f8 100644 --- a/tests/test_driver_channels.f90 +++ b/tests/test_driver_channels.f90 @@ -323,8 +323,12 @@ SUBROUTINE test_finite_dynamic_channels() ! of every node of the initial state is tensile. CALL require(min_static_tension('chan_fin.static.out') > 0.0_wp, & 'opt-in tensile safety leaves a tensile element-mean state before initialisation') - ! declination channel matches the reported tangent. - CALL require(ABS(v(18) - ref_dec(n4 - n2)) < 1.0e-3_wp, 'finite-EI L1N3Dec matches tangent') + ! The declination channel is the cable's tangent at the node (its tangent DOF), the + ! Declination of the static profile; the chord of the neighbouring nodes is only close to it + ! on this 20-element arch (1.2 deg off). + CALL require(ABS(v(18) - static_declination('chan_fin.static.out', 3)) < 1.0e-5_wp, & + 'finite-EI L1N3Dec is the static profile tangent') + CALL require(ABS(v(18) - ref_dec(n4 - n2)) < 2.0_wp, 'finite-EI L1N3Dec is close to the chord') ! acceleration channel is finite on a dynamic run. CALL require(IEEE_IS_FINITE(v(15)) .AND. IEEE_IS_FINITE(v(16)) .AND. IEEE_IS_FINITE(v(17)), & 'finite-EI acceleration channel is finite') @@ -382,6 +386,33 @@ SUBROUTINE test_finite_straight_bendmom() CALL require(ABS(v(3)) <= 1.0e-6_wp*2.0e5_wp, 'reference-relative BendMom = 0 when the shape equals its reference') END SUBROUTINE test_finite_straight_bendmom + REAL(wp) FUNCTION static_declination(path, want_node) RESULT(dec) + !! The Declination of node want_node of line 1 in a static.out profile; HUGE when unreadable. + CHARACTER(*), INTENT(IN) :: path + INTEGER, INTENT(IN) :: want_node + INTEGER :: u, ios, lineid, node + REAL(wp) :: s, x, y, z, tn, curv, bend, d + CHARACTER(2048) :: buf + dec = HUGE(1.0_wp) + OPEN (NEWUNIT=u, FILE=path, STATUS='OLD', ACTION='READ', IOSTAT=ios) + IF (ios /= 0) RETURN + DO node = 1, 3 + READ (u, '(A)', IOSTAT=ios) buf + END DO + DO + READ (u, '(A)', IOSTAT=ios) buf + IF (ios /= 0) EXIT + IF (LEN_TRIM(buf) == 0) CYCLE + READ (buf, *, IOSTAT=ios) lineid, node, s, x, y, z, tn, curv, bend, d + IF (ios /= 0) EXIT + IF (lineid == 1 .AND. node == want_node) THEN + dec = d + EXIT + END IF + END DO + CLOSE (u) + END FUNCTION static_declination + REAL(wp) FUNCTION min_static_tension(path) RESULT(tmin) !! Smallest node Tension (segment tension) of a static.out profile; -HUGE when unreadable. CHARACTER(*), INTENT(IN) :: path diff --git a/tests/test_end_tangent_channels.f90 b/tests/test_end_tangent_channels.f90 new file mode 100644 index 00000000..7c5594c7 --- /dev/null +++ b/tests/test_end_tangent_channels.f90 @@ -0,0 +1,163 @@ +! File: tests/test_end_tangent_channels.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +PROGRAM test_end_tangent_channels + !! The tangent channels of a finite-EI line read its tangent, the Hermite tangent DOF m = dr/ds + !! of every node (normalised, End A -> End B), not a difference of node positions. A cable is + !! clamped at End A (END CONNECTIONS Rigid) along a set direction, swept over declinations of + !! 120 to 180 deg and azimuths of 0 and 20 deg (a clamp out of the vertical plane of the + !! ends), and pinned (bending-free) at End B. At the clamp FairDecl, FairAngle, FairIncl, + !! L1N1Dec and L1N1Azi equal the clamp's angles to round-off, though the line bends sharply + !! within its first element there; at the pinned end AnchDecl, AnchIncl and the last node's + !! Dec, and at every interior node Dec, equal the angle of the solution's own tangent. On the + !! aggregate route, which the C API and the OpenFAST shell share; the standalone outputs use + !! the same evaluator (check_end_tangent_channels.py). + USE CableDyn_Precision, ONLY: wp + USE CableDyn_OpenFAST_Aggregate, ONLY: CD_AGG_ModuleType, CD_AGG_Init_From_Deck, CD_AGG_End, CD_AGG_OK + USE CableDyn_DeckDriver, ONLY: CD_Eval_Aggregate_Channel + IMPLICIT NONE + + REAL(wp), PARAMETER :: PI = 3.14159265358979323846_wp + REAL(wp), PARAMETER :: TOL_DEG = 1.0e-9_wp + REAL(wp), PARAMETER :: DECLINATIONS(5) = [180.0_wp, 165.0_wp, 150.0_wp, 135.0_wp, 120.0_wp] + REAL(wp), PARAMETER :: AZIMUTHS(2) = [0.0_wp, 20.0_wp] + INTEGER :: nfail, id, ia + REAL(wp) :: worst_clamp, worst_node, worst_chord + ! the case under way + TYPE(CD_AGG_ModuleType) :: agg + CHARACTER(96) :: label + + nfail = 0 + worst_clamp = 0.0_wp + worst_node = 0.0_wp + worst_chord = 0.0_wp + DO id = 1, SIZE(DECLINATIONS) + DO ia = 1, SIZE(AZIMUTHS) + IF (id == 1 .AND. ia > 1) CYCLE ! a vertical clamp has no azimuth + CALL run_case(DECLINATIONS(id), AZIMUTHS(ia)) + END DO + END DO + WRITE (*, '(A,ES10.3,A,ES10.3,A)') 'largest channel error at the clamp ', worst_clamp, & + ' deg, at the other nodes ', worst_node, ' deg' + WRITE (*, '(A,F8.3,A)') 'the node-position difference at the clamp is off by up to ', worst_chord, ' deg' + IF (nfail > 0) THEN + WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' check(s) failed' + ERROR STOP 1 + END IF + WRITE (*, '(A)') 'PASS' + +CONTAINS + + SUBROUTINE run_case(dec_clamp, azi_clamp) + REAL(wp), INTENT(IN) :: dec_clamp, azi_clamp + CHARACTER(512) :: em + CHARACTER(64) :: path, ch + REAL(wp) :: ez(3), t(3), dec_m, chord(3) + INTEGER :: es, nn, j, inode + + ez = [SIN(dec_clamp*PI/180.0_wp)*COS(azi_clamp*PI/180.0_wp), & + SIN(dec_clamp*PI/180.0_wp)*SIN(azi_clamp*PI/180.0_wp), COS(dec_clamp*PI/180.0_wp)] + path = 'end_tangent_channels.dat' + CALL write_deck(path, ez) + WRITE (label, '(A,F6.1,A,F5.1,A)') 'clamp declination ', dec_clamp, ' deg, azimuth ', azi_clamp, ' deg' + CALL CD_AGG_Init_From_Deck(agg, TRIM(path), 0.05_wp, es, em) + IF (es /= CD_AGG_OK) THEN + CALL check(.FALSE., TRIM(label)//': init: '//TRIM(em)) + CALL CD_AGG_End(agg, es, em) + RETURN + END IF + ! the clamped End A (the line's last internal node) + CALL expect('FairDecl1', dec_clamp, worst_clamp) + CALL expect('FairAngle1', dec_clamp, worst_clamp) + CALL expect('FairIncl1', dec_clamp - 90.0_wp, worst_clamp) + CALL expect('L1N1Dec', dec_clamp, worst_clamp) + IF (ABS(ez(3)) < 1.0_wp - 1.0e-12_wp) CALL expect('L1N1Azi', azi_clamp, worst_clamp) + nn = agg%cables(1)%line%nn + ! what a difference of node positions gives at the clamp + chord = agg%cables(1)%line%q(6*(nn - 2) + 1:6*(nn - 2) + 3) - agg%cables(1)%line%q(6*(nn - 1) + 1:6*(nn - 1) + 3) + worst_chord = MAX(worst_chord, ABS(ACOS(chord(3)/NORM2(chord))*180.0_wp/PI - dec_clamp)) + ! every other node, the pinned End B included: the angle of the solution's tangent DOF + DO j = 2, nn + inode = nn + 1 - j + t = -agg%cables(1)%line%q(6*(inode - 1) + 4:6*(inode - 1) + 6) + dec_m = ACOS(MAX(-1.0_wp, MIN(1.0_wp, t(3)/NORM2(t))))*180.0_wp/PI + WRITE (ch, '(A,I0,A)') 'L1N', j, 'Dec' + CALL expect(TRIM(ch), dec_m, worst_node, mesh=.TRUE.) + END DO + CALL expect('AnchDecl1', dec_m, worst_node) + CALL expect('AnchIncl1', dec_m - 90.0_wp, worst_node) + CALL CD_AGG_End(agg, es, em) + END SUBROUTINE run_case + + SUBROUTINE expect(name, want, worst, mesh) + !! The channel name of the case's line equals want [deg] to TOL_DEG; worst: the largest error. + CHARACTER(*), INTENT(IN) :: name + REAL(wp), INTENT(IN) :: want + REAL(wp), INTENT(INOUT) :: worst + LOGICAL, INTENT(IN), OPTIONAL :: mesh + REAL(wp) :: v + INTEGER :: ese + CHARACTER(512) :: eme + IF (PRESENT(mesh)) THEN + CALL CD_Eval_Aggregate_Channel(name, agg%has_sys, agg%sys%fast%system, agg%cables, agg%line_is_cable, & + agg%line_obj_index, v, ese, eme, mesh_node=mesh) + ELSE + CALL CD_Eval_Aggregate_Channel(name, agg%has_sys, agg%sys%fast%system, agg%cables, agg%line_is_cable, & + agg%line_obj_index, v, ese, eme) + END IF + IF (ese /= 0) THEN + CALL check(.FALSE., TRIM(label)//': '//name//': '//TRIM(eme)) + RETURN + END IF + worst = MAX(worst, ABS(v - want)) + IF (ABS(v - want) > TOL_DEG) THEN + WRITE (*, '(4A,F14.9,A,F14.9)') ' ', TRIM(label), ': ', name, v, ' deg, the tangent gives ', want + CALL check(.FALSE., TRIM(label)//': '//name//' is the angle of the line tangent') + END IF + END SUBROUTINE expect + + SUBROUTINE write_deck(path, ez) + CHARACTER(*), INTENT(IN) :: path + REAL(wp), INTENT(IN) :: ez(3) + INTEGER :: u + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') '--------------------- CableDyn Input File ------------------------------------' + WRITE (u, '(A)') 'tangent channels of a cable clamped at End A' + WRITE (u, '(A)') '--------------------- LINE TYPES ---------------------------------------------' + WRITE (u, '(A)') 'TypeName Diam MassDenInAir EA BA/-zeta EI Cd_n Cd_t Ca_n Ca_t' + WRITE (u, '(A)') '(-) (m) (kg/m) (N) (N-s/-) (N-m^2) (-) (-) (-) (-)' + WRITE (u, '(A)') 'cable 0.2 60.0 1.0e8 -1.0 1.0e4 1.2 0.008 1.0 0.0' + WRITE (u, '(A)') '--------------------- POINTS -------------------------------------------------' + WRITE (u, '(A)') 'ID Type X Y Z Mass Vol CdA Ca' + WRITE (u, '(A)') '(-) (-) (m) (m) (m) (kg) (m^3) (m^2) (-)' + WRITE (u, '(A)') '1 Coupled 0.0 0.0 -10.0 0 0 0 0' + WRITE (u, '(A)') '2 Fixed 80.0 0.0 -80.0 0 0 0 0' + WRITE (u, '(A)') '--------------------- LINES --------------------------------------------------' + WRITE (u, '(A)') 'ID NodeA NodeB Outputs' + WRITE (u, '(A)') '(-) (-) (-) (-)' + WRITE (u, '(A)') '1 1 2 -' + WRITE (u, '(A)') '--------------------- SECTIONS -----------------------------------------------' + WRITE (u, '(A)') 'LineID LineType Length NumSegs' + WRITE (u, '(A)') '(-) (-) (m) (-)' + WRITE (u, '(A)') '1 cable 125.0 100' + WRITE (u, '(A)') '--------------------- END CONNECTIONS ----------------------------------------' + WRITE (u, '(A)') 'LineID End Stiffness EzX EzY EzZ' + WRITE (u, '(A)') '(-) (-) (N-m/rad) (-) (-) (-)' + WRITE (u, '(A,3(1X,ES23.16))') '1 A Rigid', ez + WRITE (u, '(A)') '--------------------- OPTIONS ------------------------------------------------' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '--------------------- OUTPUTS ------------------------------------------------' + WRITE (u, '(A)') 'END' + CLOSE (u) + END SUBROUTINE write_deck + + SUBROUTINE check(ok, label) + LOGICAL, INTENT(IN) :: ok + CHARACTER(*), INTENT(IN) :: label + IF (ok) RETURN + nfail = nfail + 1 + WRITE (*, '(2A)') ' FAIL ', TRIM(label) + END SUBROUTINE check + +END PROGRAM test_end_tangent_channels diff --git a/tests/test_openfast_aggregate.f90 b/tests/test_openfast_aggregate.f90 index 89809f58..ab9d75f8 100644 --- a/tests/test_openfast_aggregate.f90 +++ b/tests/test_openfast_aggregate.f90 @@ -758,7 +758,7 @@ SUBROUTINE case_output_channels() REAL(wp), PARAMETER :: DT = 0.05_wp, EI_BARE = 1.99e4_wp REAL(wp) :: vFairTen2, vAnchTen2, vCurv1N5, vFairAngle1, vBendMom1N5, vTen1N10 REAL(wp) :: vFairDecl1, vFairIncl1 - REAL(wp) :: r1(3), r2(3), kexp, decexp + REAL(wp) :: kexp, decexp REAL(wp), ALLOCATABLE :: tension(:), exact_curvature(:) CALL write_mixed_channels_deck('agg_channels.dat') @@ -859,10 +859,10 @@ SUBROUTINE case_output_channels() END BLOCK CALL CD_HermiteCable_Dyn_Set_Output_Recovery(agg%cables(1)%line, .FALSE.) - ! (c) cable FairAngle1 == declination of the End-A one-sided tangent (deck nodes 1,2). - base = 6*(nnode - 1); r1 = agg%cables(1)%line%q(base + 1:base + 3) - base = 6*(nnode - 2); r2 = agg%cables(1)%line%q(base + 1:base + 3) - decexp = tangent_declination_deg(r2 - r1) + ! (c) cable FairAngle1 == declination of the End-A tangent: the tangent DOF of deck node 1 + ! (internal node nnode), reversed to point End A -> End B. + base = 6*(nnode - 1) + decexp = tangent_declination_deg(-agg%cables(1)%line%q(base + 4:base + 6)) CALL require(ABS(vFairAngle1 - decexp) <= 1.0e-9_wp + 1.0e-6_wp*ABS(decexp), 'chan:FairAngle1-matches-driver') CALL require(vFairDecl1 >= 0.0_wp .AND. vFairDecl1 <= 180.0_wp, 'chan:AnchDecl1-declination-range') CALL require(ABS(vFairIncl1 - (decexp - 90.0_wp)) <= 1.0e-9_wp + 1.0e-6_wp*ABS(decexp), & From 0b0ba7240b92351ad7c7f67519c268d2860c515c Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Sun, 8 Nov 2026 19:34:25 +0900 Subject: [PATCH 2/2] chore(changelog): the entry moves to the batch changelog change The [Unreleased] entries of the open changes are added together in one change, so that they do not conflict with each other. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e111d30..e3549554 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,23 +18,6 @@ All notable changes to CableDyn are recorded in this file. The format follows The touchdown element now takes the reaction of its grounded stretch, from the grounded node to the touchdown point located from the two nodes' clearances: the error falls at the second order (2.1, 0.7, 0.2 N) and the outputs vary continuously. -- The tangent outputs of a finite-EI line take the line's tangent, the node's Hermite tangent - DOF, instead of a difference of node positions. At an end clamped by an `END CONNECTIONS` - `Rigid` row they now give the direction the clamp holds: a cable clamped 15 deg off the - vertical read 163.8 deg for a 165 deg clamp, and up to 14 deg off where the line bends within - its first element. - -### Upgrading - -- On finite-EI lines `LNDec` and `LNAzi`, `FairDecl`/`AnchDecl`, `FairIncl`/`AnchIncl` - and `FairAngle`/`AnchAngle`, the `Declination`, `Inclination` and `Azimuth` columns of - `.static.out`, the `Declination` envelope of the range graph and the `line tangent` of the - initialisation reports (driver, mixed route, C API notes and OpenFAST) change: by up to 3.1 deg - at the clamped end of `buoy_clamped_cable.dat`, 1.8 deg in the static profile of - `lozon_gomex80_power_cable_motion.dat` (1.4 deg in `iea15mw_umaine_mixed_cabledyn.dat`, 0.5 deg - in `torsion_lazy_wave_hangoff_twist.dat`) and 0.6 deg in the `FairIncl1` history of - `lazy_wave_vessel_motion.dat`, and by 0.2 deg or less on the other finite-EI examples. - Positions, forces, tensions, curvatures and every `EI = 0` line are unchanged. ## [0.4.1] - 2026-11-08