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
17 changes: 12 additions & 5 deletions src/CableDyn_HermiteCableDynamic.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_hermite_cable_control.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading