From 18e6ecf30da17223539c16c85546ab26cd85b2e7 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Tue, 20 Oct 2026 20:42:47 +0900 Subject: [PATCH] fix: accept seabed recompute inputs equal to rounding The deck driver stores the seabed recompute inputs of every finite-EI cable with seabed contact (kBot, the contact diameters and cBot/kBot), so that active line control can rebuild the nodal contact coefficients after a length change, and CD_HermiteCable_Dyn_Set_Control_Seabed checked that the inputs reproduce the installed coefficients bit for bit. The deck computes the damping as kn*(cBot/kBot) and the check computes the same product, but the optimised Intel build of the release evaluates the two with different rounding: the release driver stopped examples/buoy_clamped_cable.dat with "the inputs do not reproduce the installed nodal contact damping". The gfortran builds of the test suite round both the same way and did not show it. The check now accepts coefficients within 8 units in the last place, which still rejects inputs that do not belong to the installed coefficients. Built with the release flags (Intel Fortran 2025.3.2, /Qipo, reference LAPACK), the driver of dev stops on that deck and the fixed driver runs it and every other shipped example (51 decks). Signed-off-by: Jae Hoon Seo --- src/CableDyn_HermiteCableDynamic.f90 | 17 ++++++++++++----- tests/test_hermite_cable_control.f90 | 9 +++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/CableDyn_HermiteCableDynamic.f90 b/src/CableDyn_HermiteCableDynamic.f90 index fd7c555b..87878b61 100644 --- a/src/CableDyn_HermiteCableDynamic.f90 +++ b/src/CableDyn_HermiteCableDynamic.f90 @@ -1377,9 +1377,11 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Control_Seabed(model, kbot, diameter_elem, cn !! per-area penalty kbot [N/m^3], the per-element contact diameter [m] and the ratio !! cn/kn, the inputs from which the deck built the installed nodal coefficients with !! CD_Nodal_Seabed_Stiffness. Call after CD_HermiteCable_Dyn_Set_Contact. The inputs - !! must reproduce the installed contact_kn and contact_cn bit for bit at the present - !! lengths, so a length change rebuilds exactly the coefficients a model built with the - !! new lengths would carry; otherwise the call fails and changes nothing. + !! must reproduce the installed contact_kn and contact_cn at the present lengths to within + !! a few units in the last place, so a length change rebuilds the coefficients a model + !! built with the new lengths would carry; otherwise the call fails and changes nothing. + !! (Not bit for bit: an optimising compiler may evaluate the caller's kn*(cBot/kBot) and + !! the same product here with different rounding, as the Intel release build does.) TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model REAL(wp), INTENT(IN) :: kbot, diameter_elem(:), cn_over_kn INTEGER, INTENT(OUT) :: ErrStat @@ -1405,10 +1407,10 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Control_Seabed(model, kbot, diameter_elem, cn IF (es /= CD_LINE_OK) THEN CALL fail(TRIM(em)); RETURN END IF - IF (.NOT. ALL(bits_equal(kn_check, model%contact_kn))) THEN + IF (.NOT. ALL(within_ulps(kn_check, model%contact_kn))) THEN CALL fail('the inputs do not reproduce the installed nodal contact stiffness'); RETURN END IF - IF (.NOT. ALL(bits_equal(kn_check*cn_over_kn, model%contact_cn))) THEN + IF (.NOT. ALL(within_ulps(kn_check*cn_over_kn, model%contact_cn))) THEN CALL fail('the inputs do not reproduce the installed nodal contact damping'); RETURN END IF model%seabed_kbot = kbot @@ -1422,6 +1424,11 @@ SUBROUTINE fail(msg) ErrStat = CD_HCDYN_BADINPUT ErrMsg = 'CD_HermiteCable_Dyn_Set_Control_Seabed: '//msg END SUBROUTINE fail + ELEMENTAL LOGICAL FUNCTION within_ulps(x, y) RESULT(close) + !! |x - y| within 8 units in the last place of the larger magnitude (false for a NaN). + REAL(wp), INTENT(IN) :: x, y + close = ABS(x - y) <= 8.0_wp*SPACING(MAX(ABS(x), ABS(y))) + END FUNCTION within_ulps END SUBROUTINE CD_HermiteCable_Dyn_Set_Control_Seabed SUBROUTINE rebuild_length_caches(model, l0_new, ErrStat, ErrMsg) diff --git a/tests/test_hermite_cable_control.f90 b/tests/test_hermite_cable_control.f90 index 1f05ac03..ba874047 100644 --- a/tests/test_hermite_cable_control.f90 +++ b/tests/test_hermite_cable_control.f90 @@ -221,6 +221,15 @@ SUBROUTINE check_model_contract() CALL CD_HermiteCable_Dyn_Set_Control_Seabed(a, 2.0_wp*KBOT, diam, CBOT/KBOT, es, em) CALL require(es /= CD_HCDYN_OK .AND. INDEX(em, 'do not reproduce') > 0 .AND. a%seabed_kbot == KBOT, & 'A: seabed recompute inputs that do not reproduce the installed coefficients fail') + ! a ratio that differs only by rounding (an optimising compiler may evaluate the deck's + ! kn*(cBot/kBot) differently) is accepted; one that differs by 1e-9 is not + CALL CD_HermiteCable_Dyn_Set_Control_Seabed(a, KBOT, diam, NEAREST(CBOT/KBOT, 1.0_wp), es, em) + CALL require(es == CD_HCDYN_OK, 'A: seabed recompute inputs equal to rounding are accepted: '//TRIM(em)) + CALL CD_HermiteCable_Dyn_Set_Control_Seabed(a, KBOT, diam, CBOT/KBOT, es, em) + CALL require(es == CD_HCDYN_OK .AND. a%seabed_cn_over_kn == CBOT/KBOT, 'A: the exact inputs are set again') + CALL CD_HermiteCable_Dyn_Set_Control_Seabed(a, KBOT, diam, (CBOT/KBOT)*(1.0_wp + 1.0e-9_wp), es, em) + CALL require(es /= CD_HCDYN_OK .AND. INDEX(em, 'contact damping') > 0, & + 'A: a damping ratio off by 1e-9 does not reproduce the installed coefficients') ! snapshot/restore: a later command and step roll back exactly, caches included ref = a