diff --git a/CHANGELOG.md b/CHANGELOG.md index 838c3f59..7eec942a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,15 @@ All notable changes to CableDyn are recorded in this file. The format follows ## [Unreleased] +### Fixed + +- A Syrope line whose rest tension is a small part of its past one (a `SYROPE IC` `Tmax0` well above the + installed tension, as of a polyester mooring line after a storm that loaded it) failed to start when its + static secants, far below the working curve's tangent along the whole line, did not settle in 50 + iterations. From the thirtieth iteration on, the static start combines the stored solves of the whole line + (Anderson acceleration); a 644 m rope that stopped at a residual of 1.2e-10 after 50 iterations starts in + fewer than 40, with the same tensions. Lines that settled in fewer iterations start as before, bit for bit. + ## [0.4.3] - 2026-11-20 ### Added diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index 7e54eab4..a3ae1deb 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -11126,6 +11126,8 @@ RECURSIVE SUBROUTINE init_one_syrope_model(types, ln, sections, points, l0, opts TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry INTEGER, PARAMETER :: MAX_ITER_COMPOSITE = 50 + ! the line-wide step replaces the element steps from this iteration on, over this many stored solves + INTEGER, PARAMETER :: ITER_LINE_STEP = 30, N_STORED = 6 ! per section in deck order (End A first): its line type, element count and, for a Syrope ! section, its constitutive data; per element (internal order, anchor first): its section, ! whether it is a Syrope element and its static secant EA @@ -11133,10 +11135,10 @@ RECURSIVE SUBROUTINE init_one_syrope_model(types, ln, sections, points, l0, opts INTEGER, ALLOCATABLE :: sec_type(:), sec_nseg(:), el_sec(:) LOGICAL, ALLOCATABLE :: sec_syr(:), sis(:) REAL(wp), ALLOCATABLE :: sec_el(:), cand_el(:), sslow(:), stmax(:), t_static(:), eps_prev(:), t_prev(:), & - step_prev(:) + step_prev(:), map_el(:), x_hist(:, :), g_hist(:, :), x_line(:) REAL(wp) :: anchor(3), fairlead(3), eps0, t_ref, total_l0, t_hist, t_mean_static REAL(wp) :: eps_e, change, secant, eps_now, d_eps, d_t, eps_r, t_r, acc - LOGICAL :: have_acc + LOGICAL :: have_acc, have_line INTEGER :: ne, e, es, n_owc, iter, nsec, j, k, isec, st LOGICAL :: composite, converged CHARACTER(1024) :: em @@ -11209,12 +11211,14 @@ RECURSIVE SUBROUTINE init_one_syrope_model(types, ln, sections, points, l0, opts t_hist = CD_ZERO IF (ln%has_syrope_ic) t_hist = ln%syrope_tmax0 ALLOCATE (sec_el(ne), cand_el(ne), stype(ne), sis(ne), sslow(ne), stmax(ne), t_static(ne), eps_prev(ne), & - t_prev(ne), step_prev(ne)) + t_prev(ne), step_prev(ne), map_el(ne), x_hist(ne, N_STORED), g_hist(ne, N_STORED), x_line(ne)) sis = .FALSE. sslow = CD_ZERO stmax = CD_ZERO step_prev = CD_ZERO sec_el = CD_ZERO + x_hist = CD_ZERO + g_hist = CD_ZERO DO e = 1, ne IF (.NOT. sec_syr(el_sec(e))) CYCLE sis(e) = .TRUE. @@ -11278,6 +11282,7 @@ RECURSIVE SUBROUTINE init_one_syrope_model(types, ln, sections, points, l0, opts ! each Syrope element: the curve's strain at its tension change = CD_ZERO cand_el = sec_el + map_el = sec_el DO e = 1, ne IF (.NOT. sis(e)) CYCLE isec = el_sec(e) @@ -11305,6 +11310,7 @@ RECURSIVE SUBROUTINE init_one_syrope_model(types, ln, sections, points, l0, opts ELSE cand_el(e) = t_static(e)/eps_e END IF + map_el(e) = cand_el(e) ! the residual: how far the element's (strain, tension) sits off its curve change = MAX(change, ABS(cand_el(e) - sec_el(e))/sec_el(e)) ! The tension update contracts by 1 - (secant / tangent) of the curve, slowly where the @@ -11356,6 +11362,25 @@ RECURSIVE SUBROUTINE init_one_syrope_model(types, ln, sections, points, l0, opts converged = .TRUE. EXIT END IF + ! The element steps are slow where the secant is far below the tangent along the whole + ! line (a low rest tension on a working curve of a high Tmax0): the elements share the + ! line's strain, which no element step sees. From ITER_LINE_STEP on, the next secants + ! are the combination of the stored solves (secants in, tension update out) that + ! minimises the relative residual (Anderson acceleration); else the element steps stand. + DO k = N_STORED, 2, -1 + x_hist(:, k) = x_hist(:, k - 1) + g_hist(:, k) = g_hist(:, k - 1) + END DO + x_hist(:, 1) = sec_el + g_hist(:, 1) = map_el + have_line = .FALSE. + IF (iter >= ITER_LINE_STEP) CALL line_step(MIN(iter, N_STORED), x_line, have_line) + IF (have_line) THEN + DO e = 1, ne + IF (sis(e)) step_prev(e) = x_line(e) - sec_el(e) + END DO + cand_el = x_line + END IF sec_el = cand_el END BLOCK END DO @@ -11533,6 +11558,68 @@ SUBROUTINE response_root(isec_, eps_k, t_k, d_eps_, d_t_, eps_out, t_out) IF (es_c /= CD_SYROPE_OK) eps_out = -CD_ONE END SUBROUTINE response_root + SUBROUTINE line_step(n_hist, x_new, ok) + !! The secants that minimise the relative residual of the tension update over the affine + !! combinations of the newest n_hist solves (x_hist, g_hist, newest first): least squares by + !! modified Gram-Schmidt on the residual differences, a difference dependent on the earlier + !! ones left out. ok = .FALSE. where no difference is left or a secant would fall outside + !! half to twice the newest one. + INTEGER, INTENT(IN) :: n_hist + REAL(wp), INTENT(OUT) :: x_new(:) + LOGICAL, INTENT(OUT) :: ok + REAL(wp) :: f_new(SIZE(x_new)), q(SIZE(x_new), N_STORED), dg(SIZE(x_new), N_STORED) + REAL(wp) :: r(N_STORED, N_STORED), rhs(N_STORED), coef(N_STORED), w, nrm0, nrm + INTEGER :: i, j, m_, el + ok = .FALSE. + x_new = x_hist(:, 1) + f_new = CD_ZERO + DO el = 1, SIZE(x_new) + IF (sis(el)) f_new(el) = (g_hist(el, 1) - x_hist(el, 1))/x_hist(el, 1) + END DO + m_ = 0 + r = CD_ZERO + DO j = 2, n_hist + m_ = m_ + 1 + q(:, m_) = CD_ZERO + dg(:, m_) = CD_ZERO + DO el = 1, SIZE(x_new) + IF (.NOT. sis(el)) CYCLE + w = (g_hist(el, j) - x_hist(el, j))/x_hist(el, 1) + q(el, m_) = f_new(el) - w + dg(el, m_) = g_hist(el, 1) - g_hist(el, j) + END DO + nrm0 = NORM2(q(:, m_)) + DO i = 1, m_ - 1 + r(i, m_) = DOT_PRODUCT(q(:, i), q(:, m_)) + q(:, m_) = q(:, m_) - r(i, m_)*q(:, i) + END DO + nrm = NORM2(q(:, m_)) + IF (.NOT. (nrm > 1.0e-6_wp*nrm0)) THEN + m_ = m_ - 1 + CYCLE + END IF + r(m_, m_) = nrm + q(:, m_) = q(:, m_)/nrm + END DO + IF (m_ < 1) RETURN + DO i = 1, m_ + rhs(i) = DOT_PRODUCT(q(:, i), f_new) + END DO + DO i = m_, 1, -1 + coef(i) = rhs(i) + DO j = i + 1, m_ + coef(i) = coef(i) - r(i, j)*coef(j) + END DO + coef(i) = coef(i)/r(i, i) + END DO + DO el = 1, SIZE(x_new) + IF (.NOT. sis(el)) CYCLE + x_new(el) = g_hist(el, 1) - DOT_PRODUCT(coef(1:m_), dg(el, 1:m_)) + IF (.NOT. (x_new(el) >= 0.5_wp*x_hist(el, 1) .AND. x_new(el) <= 2.0_wp*x_hist(el, 1))) RETURN + END DO + ok = .TRUE. + END SUBROUTINE line_step + LOGICAL FUNCTION strain_in_table(isec_, eps) RESULT(ok) !! Whether strain eps lies in section isec_'s OWC table (the interpolation clamps at its end !! rows, so a strain outside would start the line silently mis-tensioned); fails otherwise. diff --git a/tests/test_syrope_composite.f90 b/tests/test_syrope_composite.f90 index 92ded4e3..d948f02a 100644 --- a/tests/test_syrope_composite.f90 +++ b/tests/test_syrope_composite.f90 @@ -25,11 +25,14 @@ PROGRAM test_syrope_composite !! 8. A lightly loaded SYROPE IC rope near its working curve's zero-tension strain, where the !! plain secant update contracts slowly: the accelerated update lands every element on the !! Tmax0 working curve. + !! 9. A long inclined single-section rope (60 elements, 644 m) whose rest tension is a small part + !! of its past one on a linear working curve: the secants are a fifth and less of the + !! tangent along the whole line, where the element steps alone ran out of iterations. USE CableDyn_Precision, ONLY: wp USE CableDyn_DeckDriver, ONLY: CD_Init_Deck_Models, CD_Run_Deck_Driver, CD_DECKDRV_OK USE CableDyn_Model, ONLY: CD_ModelType, CD_End_Model, CD_Get_Model_Tension USE CableDyn_Syrope, ONLY: CD_SyropeType, CD_Syrope_Init, CD_Syrope_End, CD_Syrope_Static_Tension, & - CD_SYROPE_WC_EXP, CD_SYROPE_OK + CD_SYROPE_WC_EXP, CD_SYROPE_WC_LINEAR, CD_SYROPE_OK IMPLICIT NONE INTEGER, PARAMETER :: NOWC = 30, NE_A = 25, NE_P = 40, NE_F = 12 @@ -134,6 +137,13 @@ PROGRAM test_syrope_composite ! zero-tension strain (about 53 kN), where the plain secant update contracts slowly CALL taut_rope(20.2_wp, '16.70', 'a lightly loaded preconditioned rope', tmax0=2.5e6_wp) + ! 9. the slow case of the whole line (with the element steps alone 2.60, 2.83 and 2.89 MN ran out of + ! iterations) + CALL long_rope(2.60e6_wp) + CALL long_rope(2.83e6_wp) + CALL long_rope(2.86e6_wp) + CALL long_rope(2.89e6_wp) + CALL finish() CONTAINS @@ -245,6 +255,88 @@ SUBROUTINE taut_rope(span, mass, what, tmax0) IF (PRESENT(tmax0)) CALL CD_Syrope_End(td) END SUBROUTINE taut_rope + SUBROUTINE long_rope(tmax0) + !! A 643.77 m polyester rope between an anchor at 700 m and a fairlead at 58 m radius in 150 m of + !! water, on the linear working curve (slope 156 MN) of a past tension tmax0: every element + !! lands on that curve. + REAL(wp), INTENT(IN) :: tmax0 + INTEGER, PARAMETER :: NR = 4, NE = 60 + ! an original working curve of 12 MN breaking strength (strain, tension) + REAL(wp), PARAMETER :: R_EPS(NR) = [0.0_wp, 0.010_wp, 0.037_wp, 0.080_wp] + REAL(wp), PARAMETER :: R_TEN(NR) = [0.0_wp, 0.9e6_wp, 2.83e6_wp, 6.5e6_wp] + TYPE(CD_ModelType), ALLOCATABLE :: ml(:) + TYPE(CD_SyropeType) :: td + REAL(wp) :: ten(NE), eps_k, wst, tcurve + INTEGER :: u, k + CHARACTER(32) :: s_tmax0 + OPEN (NEWUNIT=u, FILE='csyr_long_owc.dat', STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'Strain Tension' + WRITE (u, '(A)') '(-) (N)' + DO k = 1, NR + WRITE (u, '(ES14.6,1X,ES14.6)') R_EPS(k), R_TEN(k) + END DO + CLOSE (u) + OPEN (NEWUNIT=u, FILE='csyr_long_settings.dat', STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'csyr_long_owc.dat OWC - Original working-curve table file' + WRITE (u, '(A)') 'LINEAR WCType - Working-curve formulation' + WRITE (u, '(A)') '1.56e8 k1 - Working-curve slope (N)' + WRITE (u, '(A)') '0.0 k2 - unused' + CLOSE (u) + WRITE (s_tmax0, '(ES23.16)') tmax0 + OPEN (NEWUNIT=u, FILE='csyr_long.dat', STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'long single-section Syrope test deck' + WRITE (u, '(A)') '--- LINE TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass EA BA EI Cdn Cdt Can Cat' + WRITE (u, '(A)') '(-) (m) (kg/m) (N) (-) (Nm2) (-) (-) (-) (-)' + WRITE (u, '(A)') 'rope 0.145 23.0 "SYROPE:csyr_long_settings.dat|2.22e8|33.0" 2.952e9|1.0e5 0.0 1.2 0.2 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) (m3) (m2) (-)' + WRITE (u, '(A)') '1 Fixed -700.0 0.0 -150.0 0 0 0 0' + WRITE (u, '(A)') '2 Vessel -58.0 0.0 -14.0 0 0 0 0' + WRITE (u, '(A)') '--- LINES ---' + WRITE (u, '(A)') 'ID NodeA NodeB Outputs' + WRITE (u, '(A)') '(-) (-) (-) (-)' + WRITE (u, '(A)') '1 2 1 -' + WRITE (u, '(A)') '--- SYROPE IC ---' + WRITE (u, '(A)') 'Line(s) Tmax0 Tmean0' + WRITE (u, '(A)') '(-) (N) (N)' + WRITE (u, '(A)') '1 '//TRIM(ADJUSTL(s_tmax0))//' 6.0e5' + WRITE (u, '(A)') '--- SECTIONS ---' + WRITE (u, '(A)') 'LineID LineType Length NumSegs' + WRITE (u, '(A)') '(-) (-) (m) (-)' + WRITE (u, '(A)') '1 rope 643.7681 60' + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '150.0 WtrDpth' + WRITE (u, '(A)') '--- OUTPUTS ---' + WRITE (u, '(A)') 'FairTen1' + WRITE (u, '(A)') '--- end ---' + CLOSE (u) + CALL CD_Init_Deck_Models('csyr_long.dat', ml, es, em) + CALL require(es == CD_DECKDRV_OK, 'the long rope of Tmax0 '//TRIM(ADJUSTL(s_tmax0))//' N builds: '//TRIM(em)) + IF (es /= CD_DECKDRV_OK) RETURN + CALL CD_Syrope_Init(td, R_EPS, R_TEN, CD_SYROPE_WC_LINEAR, 1.56e8_wp, 0.0_wp, 2.22e8_wp, 33.0_wp, & + 2.952e9_wp, 1.0e5_wp, es, em) + CALL require(es == CD_SYROPE_OK, 'reference linear working curve: '//TRIM(em)) + ASSOCIATE (md => ml(1)) + CALL CD_Get_Model_Tension(md, ten, es, em) + wst = 0.0_wp + DO k = 1, md%n_elem + eps_k = NORM2(md%q(3*md%elem_conn(2, k) - 2:3*md%elem_conn(2, k)) - & + md%q(3*md%elem_conn(1, k) - 2:3*md%elem_conn(1, k)))/md%l0(k) - 1.0_wp + CALL CD_Syrope_Static_Tension(td, tmax0, eps_k, tcurve, es, em) + wst = MAX(wst, ABS(tcurve - ten(k))/ten(k)) + END DO + PRINT '(A,ES10.3,A,ES12.5,A,ES12.5,A,ES10.3)', ' long rope, Tmax0 ', tmax0, ': tensions ', MINVAL(ten), & + ' to ', MAXVAL(ten), ' N, elements off their rest curve by at most ', wst + CALL require(wst <= 1.0e-8_wp, 'every element of the long rope sits on its Tmax0 working curve') + END ASSOCIATE + CALL CD_End_Model(ml(1), es, em) + CALL CD_Syrope_End(td) + END SUBROUTINE long_rope + SUBROUTINE tmax0_curve() !! SYROPE IC Tmax0 = 2.5 MN: the polyester's mean tension is the Tmax0 working curve's at its !! mean strain.