From 58cf4e546f327e616cac68bee6e628feb504adb0 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Tue, 3 Nov 2026 07:34:15 +0900 Subject: [PATCH 1/3] fix(torsion): coupled held lines step, body passes converge, a lazy wave in current starts Three torsion defects of the 0.4.0 robustness campaign (all on dev): - Strong torque-tension coupling: with K >= 0.85 sqrt(EA GJ) (and -0.8 with one end free) a held line in exact static equilibrium failed its dynamic step ("||G|| = 2.4e-8 > tol = 1e-8"): the round-off floor of the convergence norm took only the kernel's EA - K^2/GJ. It now takes the coupling's share of the axial force and of the element torque (whose twist is formed from coordinates). Gate torsion_coupling_still: K up to 0.99 sqrt(EA GJ), either sense, one end free; fails on the old code. - Static body passes of a cable restrained in torsion between two Rigid6 bodies stalled near 2e-9 at 360 deg (Rigid) and 300 deg (Pinned): the 1e-10 pass tolerance sat below the resolution of the core's body balance. The passes now stop at that resolution (four times the core's residual load), and the failure advice no longer suggests bodyIC deck. Gate torsion_body_passes: the pretwist sweep converges (Rigid 360 deg in 6 passes, torque 4886.24 N m); fails on the old code. - A lazy wave with 25 modules restrained in torsion in a 0.5 m/s in-plane current was refused by the torsion stage ("stalled at Phi = 0") although the twist added no negative stiffness mode to its untwisted state, which is unstable out of its plane and accepted by the deck without torsion. A twisted state with no more negative modes than its untwisted one is now kept and named as such. Gate torsion_current_start (pretwist 0 and 360 deg); fails on the old code. Also: the "unresolved/kinked equilibrium" refusal names the factor to refine the section's NumSegs by. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 24 ++++ CMakeLists.txt | 25 ++++ doc/troubleshooting.rst | 30 ++++- src/CableDyn_DeckDriver.f90 | 135 ++++++++++++++++--- src/CableDyn_HermiteCableDynamic.f90 | 41 +++++- src/CableDyn_HermiteCableStatic.f90 | 124 ++++++++++++++++- src/CableDyn_HermiteTorsion.f90 | 11 ++ tests/test_torsion_body_passes.f90 | 169 +++++++++++++++++++++++ tests/test_torsion_coupling_still.f90 | 186 ++++++++++++++++++++++++++ tests/test_torsion_current_start.py | 96 +++++++++++++ 10 files changed, 806 insertions(+), 35 deletions(-) create mode 100644 tests/test_torsion_body_passes.f90 create mode 100644 tests/test_torsion_coupling_still.f90 create mode 100644 tests/test_torsion_current_start.py diff --git a/CHANGELOG.md b/CHANGELOG.md index ba47391b..389a799a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -451,6 +451,30 @@ All notable changes to CableDyn are recorded in this file. The format follows the IEA-15 MW mixed example in a 60 s platform motion changes by 1.6e-6 of its cable tension. Cost: a coupled cable step takes about 2.0 tangent factorisations instead of 1.1, and the aggregate step of that example (chains included) 38 % more CPU time (the D03 deck: 19 %). +- A held line under strong torque-tension coupling stays still in its dynamics. With + `K >= 0.85 sqrt(EA GJ)` (and at `-0.8` with one end free in torsion) a line in exact static + equilibrium failed its step within 0.05-0.9 s ("Newton did not converge, ||G|| = 2.4e-8 > + tol = 1e-8"): the round-off floor of the step's convergence norm took only the kernel's + `EA - K^2/GJ`, not the coupling's share of the axial force and of the torque. It now takes + both; at `K` up to `0.99 sqrt(EA GJ)` in either sense the held line holds at the default `dtM` + and tolerance (`torsion_coupling_still`), and lines with `|K| <= 0.8 sqrt(EA GJ)` step as before. +- The static passes of a finite-EI cable restrained in torsion between two Rigid6 bodies + converge at every pretwist. They compared the change of the cable's end loads with 1e-10 of + their scale, below the resolution of the core's body balance (1e-9 of the bodies' net weight), + so at 360 deg (Rigid ends) and 300 deg (Pinned) they stalled near 2e-9 and the deck stopped, + with advice (`bodyIC deck`) that was not the remedy. They now stop at the resolution the core + leaves: the Rigid 360 deg case converges in 6 passes (torque 4886.24 N m), and the + pretwist sweep 120-720 deg of both end kinds converges (`torsion_body_passes`). +- A lazy wave restrained in torsion starts in an in-plane current. In a 0.5 m/s current its + untwisted static state, solved in its vertical plane, is unstable out of that plane on its mesh + (one negative stiffness mode), which the deck without torsion accepts with a note; the torsion + stage refused the twisted state as unstable although the twist added no negative mode ("torsion + continuation stalled at Phi = 0 (target 0)" at pretwist 0, an unstable equilibrium after a + failed Newton solve at 360 deg). A twisted state with no more negative modes than its untwisted + one is now kept, and the note names the instability as the untwisted state's + (`torsion_current_start`). +- The "unresolved/kinked equilibrium" refusal names the element and the factor to refine its + section's `NumSegs` by. - A rod numbered as a body no longer joins the body's attachment points. A `RodA/B` end point keeps its rod's id where a `Body` point keeps its body's, and the body's point list took every point with its id: a rod end POINT row listed before the body's points became the body's diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e462550..1c1b9cc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1803,6 +1803,18 @@ if(Python3_Interpreter_FOUND) # A rod numbered as a body is not one of the body's points: a Rod1B end POINT listed before # the Body1 points gives the run of the same deck with the rod renumbered, bit for bit. + # A lazy wave restrained in torsion starts in an in-plane current (its untwisted state's + # out-of-plane instability is kept, not refused by the torsion stage). + add_test(NAME torsion_current_start + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_torsion_current_start.py + --exe $ + --data ${CMAKE_CURRENT_SOURCE_DIR}/tests/data + --output ${CMAKE_BINARY_DIR}/torsion_current_start) + set_tests_properties(torsion_current_start PROPERTIES + LABELS "python;driver;integration;static" + TIMEOUT 600 + ENVIRONMENT "${_cabledyn_python_test_environment}") + add_test(NAME body_rod_numbering COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_body_rod_numbering.py --exe $ @@ -2321,6 +2333,12 @@ add_executable(test_cable_between_bodies tests/test_cable_between_bodies.f90) target_link_libraries(test_cable_between_bodies PRIVATE cabledyn_core) add_test(NAME cable_between_bodies COMMAND test_cable_between_bodies) set_tests_properties(cable_between_bodies PROPERTIES LABELS "fortran;driver;integration;dynamic;static") +# The static passes of a cable restrained in torsion between two moored bodies converge at every +# pretwist (they stop at the resolution of the core's balance): the mirror-symmetric start, held. +add_executable(test_torsion_body_passes tests/test_torsion_body_passes.f90) +target_link_libraries(test_torsion_body_passes PRIVATE cabledyn_core) +add_test(NAME torsion_body_passes COMMAND test_torsion_body_passes) +set_tests_properties(torsion_body_passes PROPERTIES LABELS "fortran;driver;integration;dynamic;static") add_executable(test_pinned_cable_light_object tests/test_pinned_cable_light_object.f90) target_link_libraries(test_pinned_cable_light_object PRIVATE cabledyn_core) @@ -2355,6 +2373,13 @@ add_executable(test_torsion_coupling tests/test_torsion_coupling.f90) target_link_libraries(test_torsion_coupling PRIVATE cabledyn_core) add_test(NAME torsion_coupling COMMAND test_torsion_coupling) set_tests_properties(torsion_coupling PROPERTIES LABELS "fortran;unit;driver;integration;static") +# A held line under strong torque-tension coupling (K up to 0.99 sqrt(EA GJ), either sense, one +# end free in torsion) stays still at the default dtM and dynamic tolerance: the round-off floor of +# the step's convergence norm carries the coupling's share of the axial force and of the torque. +add_executable(test_torsion_coupling_still tests/test_torsion_coupling_still.f90) +target_link_libraries(test_torsion_coupling_still PRIVATE cabledyn_core) +add_test(NAME torsion_coupling_still COMMAND test_torsion_coupling_still) +set_tests_properties(torsion_coupling_still PROPERTIES LABELS "fortran;driver;integration;dynamic") # Torsion and prescribed motion on the standalone mixed EI = 0 + finite-EI route (the driver # executable marches the aggregate): route equivalence with the cubic-Hermite route under vessel diff --git a/doc/troubleshooting.rst b/doc/troubleshooting.rst index 8322bfe9..fdefde91 100644 --- a/doc/troubleshooting.rst +++ b/doc/troubleshooting.rst @@ -281,11 +281,17 @@ Model data supported in a deck marched as one multibody system. End the cable on a Fixed point, a body or a rod end, or run the cable and the lines it joins as separate decks. * - ``static body/rod equilibrium with the bending end loads of finite-EI LINE (its End A|B, - on a body or rod) did not converge after 60 passes`` + on a body or rod) did not converge after 60 passes (relative end-load change ..., + tolerance ...)`` - the static passes that balance a finite-EI line between two objects on its cubic-Hermite end loads (Anderson-accelerated) did not settle; the line's bending couples the objects - more strongly than their own restoring holds them. Check the connection directions and - the mooring, or start from the deck pose (``deck bodyIC``). + more strongly than their own restoring holds them. The passes stop at a change of 1e-7 of + the end-load scale (1e-10 with torsion), or at the resolution each pass's balance of the + objects leaves (four times its residual load) where that is larger, so a change above the + reported tolerance is not round-off. Restrain the object more stiffly (its moorings or + ``C44``/``C55``) or soften the connection (a finite ``Stiffness``, a ``Pinned`` end or a + finite ``TorsStiffness``); ``OPTION bodyIC deck`` skips the balance and starts the objects + out of equilibrium at their deck poses. * - ``finite-EI LINE : a Coupled/Vessel End B (POINT ) would need motionFile coupling to drive it`` - the multibody march takes no ``motionFile``, so it has nothing to drive a ``Coupled``/ @@ -546,9 +552,14 @@ but a few geometries are genuinely hard: - **A residual-converged folded branch.** CableDyn checks the element rotation measure after every finite-EI sequence attempt, every final deck-built equilibrium, and the public automatic-mesh route. ``max(h*kappa) > 0.7`` is rejected by name even if Newton's residual is small. This is a - mesh/branch safety failure, not permission to relax the tolerance. Increase resolution in the - reported high-curvature section and inspect the static profile. The check samples element - interiors adaptively, so a cubic-element fold cannot hide between output nodes. + mesh/branch safety failure, not permission to relax the tolerance. The refusal names the + element and the factor to refine ``NumSegs`` by there (``refine NumSegs at least x about + element ...``): on a resolved bend the curvature does not change with the mesh, so ``h*kappa`` + falls with the element length and ``n`` is ``max(h*kappa)/0.7`` rounded up, times the + refinement the solve already applied to the deck element. Refine the reported section by it + and inspect the static profile; a fold that stays kinked on the finer mesh is a non-physical + branch, not a resolution limit. The check samples element interiors adaptively, so a + cubic-element fold cannot hide between output nodes. - **Odd, prime, or section-wise nonuniform meshes.** These are supported; do not change ``NumSegs`` merely to make the total divisible by two. The nested hierarchy retains physical section interfaces and interpolates at the true cumulative rest-length coordinate. Its @@ -595,7 +606,12 @@ but a few geometries are genuinely hard: equilibrium on the path, typically because a loop is forming (hockling), which needs a dynamic analysis and is not resolved as self-contact. ``finite-EI torsion static solve ended on an unstable equilibrium`` means the descent from a buckled (unstable) twisted state did not - find a stable one. ``the twist moved more than pi/2 from its committed value in one step`` + find a stable one. The twist stages refuse, or descend from, only an instability the twist + adds: a twisted state with no more negative stiffness modes than its untwisted state (a + planar state that is unstable out of its plane, which a line without torsion starts from with + a note) starts with the note ``the twisted static state keeps the instability of its untwisted + state``. Where such a state cannot be kept, ``torsion stage failed: the untwisted equilibrium + it starts from is itself unstable`` names the untwisted state, not the twist, as the cause. ``the twist moved more than pi/2 from its committed value in one step`` stops a dynamic step that would change the twist by more than a quarter turn (the unwrapping of the twist cannot be trusted beyond it): reduce ``dtM`` or slow the imposed roll. ``tangent turns by more than 120 degrees`` names an element or node pair where the twist of diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index 79e3d75a..8f93c500 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -78,8 +78,8 @@ MODULE CableDyn_DeckDriver CD_HermiteCable_Axial_Resultant_Range, CD_HermiteCable_Element, CD_HCABLE_OK, & CD_HermiteCable_Gauss_Rule USE CableDyn_HermiteCableStatic, ONLY: CD_HermiteCable_Static_Solve_AutoMesh, CD_HermiteCable_Static_Solve, & - CD_HermiteCable_Prolong_Arc, & - CD_HC_OSCILLATION_REL_TOL, & + CD_HermiteCable_Prolong_Arc, CD_HermiteCable_Kink_Advice, & + CD_HermiteCable_Element_Ratio, CD_HC_OSCILLATION_REL_TOL, & CD_HermiteCable_Static_Solve_Sequenced, CD_HCSTAT_OK, & CD_HCSTAT_BADINPUT, & CD_HermiteCable_Sequence_Coarse_Max_Length, & @@ -1667,6 +1667,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, ! Set when the attachment polish needed its fallbacks (attachment_fallback_checks). LOGICAL :: att_fell_back LOGICAL :: bathymetry_flat, require_3d_static, sym_broken, planar_unstable, saddle_kept + ! whether the line would be solved in 3D without its torsion (a twisted line always is) + LOGICAL :: require_3d_untwisted ! A planar equilibrium in a current that is a saddle out of its plane (see route_pass). REAL(wp), ALLOCATABLE :: l0_saddle(:), ea_saddle(:), ei_saddle(:), w_saddle(:), q_saddle(:), curv_saddle(:) INTEGER, ALLOCATABLE :: fixed_saddle(:) @@ -1897,7 +1899,6 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, ! torsional line is solved in 3D from the start; a line free in torsion at one end carries no ! static torque, so its statics are those of the line without torsion. tors_line = line_torsion_active(ln) - IF (tors_line .AND. ln%tors_free_end == 0) require_3d_static = .TRUE. ! A current with a component across the vertical plane of the chord pushes the line out ! of that plane, which the dynamics (endpoints held, every other DOF free) follow: the ! static equilibrium is then solved in 3D as well. @@ -1934,6 +1935,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, ! reference, and the friction it holds, out of that plane: solved in 3D as well. This is ! decided here, before the held (planar) DOFs below are chosen. IF (as_laid_off_plane()) require_3d_static = .TRUE. + require_3d_untwisted = require_3d_static + IF (tors_line .AND. ln%tors_free_end == 0) require_3d_static = .TRUE. CALL build_finite_section_mesh(ln, sections, types, conn, l0, ea, mpl, diam, ei, & gas_in, gj_in, i_rt_in, i_rn_in, ErrStat, ErrMsg, ktt=ktt_in, bt=bt_in) @@ -2959,6 +2962,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, WRITE (em, '(A,ES12.5,A,ES12.5,A,I0)') & 'unresolved/kinked finite-EI equilibrium: max(h*kappa)=', diag%h_kappa_peak, & ' > safety limit=', CD_HC_KINK_LIMIT, ' at element ', diag%h_kappa_elem + em = TRIM(em)//TRIM(CD_HermiteCable_Kink_Advice(diag%h_kappa_peak, diag%h_kappa_elem, SIZE(l0_am), & + CD_HermiteCable_Element_Ratio(l0, l0_am, diag%h_kappa_elem))) CALL fail_solve(ErrStat, ErrMsg, TRIM(em)); RETURN END IF IF (opts%tensile_mode == CD_HCDYN_TENSILE_ERROR .AND. diag%axial_compression) THEN @@ -3348,6 +3353,14 @@ SUBROUTINE torsion_stage(est, emt, f_nodal) tors = CD_HermiteTorsionType() tors%active = .TRUE. tors%quadrature_order = opts%bending_quadrature_order + ! The untwisted state was accepted by the checks of a line without torsion, which start a + ! state that is unstable out of its vertical plane with a note (handoff_lateral_note, a + ! kept planar saddle): the stage refuses, or descends from, only an instability the twist + ! adds, and keeps the untwisted state's own (torsion_note names it). A lazy wave with 25 + ! modules in an in-plane 0.5 m/s current, whose discrete planar equilibrium has one + ! out-of-plane negative mode with or without torsion, was refused at Phi = 0 ("the twisted + ! equilibrium is unstable", with no twist to impose). + tors%keep_untwisted_instability = .TRUE. tors%gj = gj_in IF (SIZE(lf) /= SIZE(ld)) CALL remap_elem_by_reference_arc(tors%gj, ld, lf) ! torque-tension coupling: K/GJ per element (left unallocated without coupling) @@ -3468,6 +3481,12 @@ SUBROUTINE torsion_note() tors%phi*45.0_wp/QUARTER_PI, ' deg, torque ', tors%torque, ' N m (', tors%ramp_steps, & ' twist stage(s), ', tors%descents, ' buckling descent(s))' CALL report_note(tnote) + IF (tors%untwisted_instability) THEN + WRITE (tnote, '(A,I0,A,I0,A)') 'line ', ln%id, ': the twisted static state keeps the instability of '// & + 'its untwisted state (', tors%n_negative, ' negative stiffness mode(s), none added by the twist), '// & + 'which a line without torsion starts from as well; a disturbance can move the line away from it' + CALL report_note(tnote) + END IF END SUBROUTINE torsion_note SUBROUTINE torsion_after_attachments(est, emt) @@ -3559,11 +3578,12 @@ SUBROUTINE twisted_attachment_checks(est, emt) IF (PRESENT(bathymetry) .AND. .NOT. bathymetry_flat) THEN CALL attachment_mesh_checks(l0, q_static, ea, ei, att_node, contact_z, & opts%tensile_mode == CD_HCDYN_TENSILE_ERROR, TWISTED_WHAT, accepted_t, msg_t, & - bathymetry=bathymetry, frame_cs=frame_cs, axial_offset=tors_axial_offset) + bathymetry=bathymetry, frame_cs=frame_cs, axial_offset=tors_axial_offset, & + l0_deck=l0_deck_att) ELSE CALL attachment_mesh_checks(l0, q_static, ea, ei, att_node, contact_z, & opts%tensile_mode == CD_HCDYN_TENSILE_ERROR, TWISTED_WHAT, accepted_t, msg_t, & - axial_offset=tors_axial_offset) + axial_offset=tors_axial_offset, l0_deck=l0_deck_att) END IF IF (.NOT. accepted_t) THEN est = CD_DECKDRV_SOLVEFAIL @@ -4483,8 +4503,30 @@ SUBROUTINE attachment_fallback_checks() !! dead loads), the rest there. Fails closed with the verdict's message. LOGICAL :: stable_f, accepted_f CHARACTER(1024) :: msg_f + INTEGER, ALLOCATABLE :: fixed_f(:) + INTEGER :: nn_f, i_f + ! A line restrained in torsion is solved in 3D, but where the same line free in torsion is + ! solved in its vertical plane, its untwisted discrete state is tested as that line's is, with + ! the out-of-plane DOFs held: the torsion stage that follows tests the twisted state in 3D and + ! keeps only an instability its untwisted state has (a planar state unstable out of its plane, + ! which the line free in torsion starts from with a note). Without it the lazy wave with 25 + ! modules restrained in torsion, Pretwist 360 deg, in an in-plane 0.5 m/s current, whose polish + ! needed its fallbacks, was refused for its out-of-plane mode before any twist. + fixed_f = fixed_dofs + IF (tors_line .AND. ln%tors_free_end == 0 .AND. .NOT. require_3d_untwisted) THEN + IF (.NOT. as_laid_cross_slope()) THEN + nn_f = SIZE(l0) + 1 + fixed_f = [1, 2, 3, 6*nn_f - 5, 6*nn_f - 4, 6*nn_f - 3] + DO i_f = 1, nn_f + fixed_f = [fixed_f, 6*(i_f - 1) + 2] + IF ((i_f == 1 .AND. endconn_mode(1) == CD_ENDCONN_RIGID) .OR. & + (i_f == nn_f .AND. endconn_mode(2) == CD_ENDCONN_RIGID)) CYCLE + fixed_f = [fixed_f, 6*(i_f - 1) + 5] + END DO + END IF + END IF IF (PRESENT(bathymetry) .AND. .NOT. bathymetry_flat) THEN - CALL hermite_static_stable(l0, l0, ea, ei, w_bare, diam, dry_b_final(), q_static, fixed_dofs, & + CALL hermite_static_stable(l0, l0, ea, ei, w_bare, diam, dry_b_final(), q_static, fixed_f, & contact_enabled, contact_z, frame_cs, endconn_k, endconn_d0_local, endconn_mode, & opts, stable_f, ErrStat, ErrMsg, bathymetry=bathymetry, cur_obj=cur_obj) IF (ErrStat /= CD_DECKDRV_OK) RETURN @@ -4492,7 +4534,7 @@ SUBROUTINE attachment_fallback_checks() opts%tensile_mode == CD_HCDYN_TENSILE_ERROR, stable_f, accepted_f, msg_f, & bathymetry=bathymetry, frame_cs=frame_cs) ELSE - CALL hermite_static_stable(l0, l0, ea, ei, w_bare, diam, dry_b_final(), q_static, fixed_dofs, & + CALL hermite_static_stable(l0, l0, ea, ei, w_bare, diam, dry_b_final(), q_static, fixed_f, & contact_enabled, contact_z, frame_cs, endconn_k, endconn_d0_local, endconn_mode, & opts, stable_f, ErrStat, ErrMsg, cur_obj=cur_obj) IF (ErrStat /= CD_DECKDRV_OK) RETURN @@ -6896,7 +6938,7 @@ SUBROUTINE hermite_static_torsion(l0_deck, l0, ea, ei, w, diam_deck, dry_deck, q ELSE IF (es /= CD_HCSTAT_OK) THEN CALL fail_solve(ErrStat, ErrMsg, 'finite-EI torsion static solve failed: '//TRIM(em)); RETURN END IF - IF (.NOT. tors%stable) THEN + IF (.NOT. tors%stable .AND. .NOT. tors%untwisted_instability) THEN CALL fail_solve(ErrStat, ErrMsg, 'finite-EI torsion static solve ended on an unstable equilibrium'); RETURN END IF q = q_out @@ -6951,7 +6993,7 @@ SUBROUTINE CD_Attachment_Discrete_Verdict(l0, q, ea, ei, w, diam, endconn_mode, END SUBROUTINE CD_Attachment_Discrete_Verdict SUBROUTINE attachment_mesh_checks(l0, q, ea, ei, att_node, contact_z, tensile_error, what, accepted, message, & - bathymetry, frame_cs, axial_offset) + bathymetry, frame_cs, axial_offset, l0_deck) !! The mesh safety checks of a discrete attachment equilibrium on its mesh l0 with state q: !! 1. the kink limit (h*kappa <= CD_HC_KINK_LIMIT), except on the elements beside an !! attachment node att_node, where the lumped load turns the line by a slope jump that the @@ -6970,6 +7012,8 @@ SUBROUTINE attachment_mesh_checks(l0, q, ea, ei, att_node, contact_z, tensile_er TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry REAL(wp), INTENT(IN), OPTIONAL :: frame_cs(2) REAL(wp), INTENT(IN), OPTIONAL :: axial_offset(:) + ! the deck mesh l0 refines (the kink advice names the factor for its NumSegs) + REAL(wp), INTENT(IN), OPTIONAL :: l0_deck(:) TYPE(CD_HermiteResolutionType) :: diag REAL(wp), ALLOCATABLE :: hk(:) LOGICAL, ALLOCATABLE :: beside(:) @@ -7011,6 +7055,12 @@ SUBROUTINE attachment_mesh_checks(l0, q, ea, ei, att_node, contact_z, tensile_er IF (hk_peak > CD_HC_KINK_LIMIT) THEN WRITE (em, '(A,ES12.5,A,ES12.5,A,I0,A)') 'is unresolved/kinked: max(h*kappa)=', hk_peak, & ' > safety limit=', CD_HC_KINK_LIMIT, ' at element ', e_peak, ' (away from the attachment nodes)' + IF (PRESENT(l0_deck)) THEN + em = TRIM(em)//TRIM(CD_HermiteCable_Kink_Advice(hk_peak, e_peak, ne, & + CD_HermiteCable_Element_Ratio(l0_deck, l0, e_peak))) + ELSE + em = TRIM(em)//TRIM(CD_HermiteCable_Kink_Advice(hk_peak, e_peak, ne)) + END IF message = what//TRIM(em); RETURN END IF IF (tensile_error .AND. diag%axial_compression) THEN @@ -7130,6 +7180,7 @@ SUBROUTINE audit_hermite_static(l0, q, ea, ei, w, diam, endconn_mode, physical, CASE (CD_HC_AUDIT_KINK) WRITE (message, '(A,ES10.3,A,ES10.3,A,I0)') 'unresolved/kinked equilibrium: max(h*kappa)=', & audit%h_kappa_peak, ' > safety limit=', CD_HC_KINK_LIMIT, ' at element ', audit%h_kappa_elem + message = TRIM(message)//TRIM(CD_HermiteCable_Kink_Advice(audit%h_kappa_peak, audit%h_kappa_elem, SIZE(l0))) END SELECT IF (physical) message = '' END SUBROUTINE audit_hermite_static @@ -26238,7 +26289,7 @@ END SUBROUTINE rigid6_rod_loads SUBROUTINE solve_body_equilibrium_core(types, bodies, rod_types, rods, points, lines, sections, opts, ErrStat, & ErrMsg, bathymetry, points_only, jac_check_err, ext_pt, ext_fm, & - end_force_a, quiet, skipped, ext_km, ext_rot, end_force_b) + end_force_a, quiet, skipped, ext_km, ext_rot, end_force_b, res_left) !! Static equilibrium of the free objects of a deck: free Rigid6 bodies (six DOFs: position !! and a rotation-vector increment on SO(3); a CoupledPinned body holds its position at its !! host node and balances its moment about it), free rods (position and the two rotations @@ -26321,6 +26372,10 @@ SUBROUTINE solve_body_equilibrium_core(types, bodies, rod_types, rods, points, l ! skipped: the objects were held at their deck poses (a moving line has no moving-end ! static solve), so nothing was balanced LOGICAL, INTENT(OUT), OPTIONAL :: skipped + ! res_left: the net load the solve leaves on the objects, the largest force [N] or moment + ! [N m] of an object at the returned poses (zero when nothing was balanced): the resolution of + ! the balance, which the passes of solve_body_equilibrium cannot refine + REAL(wp), INTENT(OUT), OPTIONAL :: res_left TYPE :: LineStaticCache !! A moving line's mesh and loads (fixed) and its last converged shape (the warm seed). @@ -26365,6 +26420,7 @@ SUBROUTINE solve_body_equilibrium_core(types, bodies, rod_types, rods, points, l silent = .FALSE. IF (PRESENT(quiet)) silent = quiet IF (PRESENT(skipped)) skipped = .FALSE. + IF (PRESENT(res_left)) res_left = CD_ZERO IF (.NOT. (only_points .OR. opts%body_ic_static)) RETURN ! the objects that move: free Rigid6 bodies and free rods with a line, then Free/Connect points ALLOCATE (okind(SIZE(bodies) + SIZE(rods) + SIZE(points)), idx(SIZE(bodies) + SIZE(rods) + SIZE(points))) @@ -26693,6 +26749,18 @@ SUBROUTINE solve_body_equilibrium_core(types, bodies, rod_types, rods, points, l END IF EXIT END DO + IF (PRESENT(res_left)) THEN + ! the force rows of r are in N, the moment rows scaled by the object length lsc + res_left = CD_ZERO + DO k = 1, nobj + IF (okind(k) == OBJ_PIN) THEN + res_left = MAX(res_left, MAXVAL(ABS(r(off(k) + 1:off(k) + ndof(k))))*lsc(k)) + ELSE + res_left = MAX(res_left, MAXVAL(ABS(r(off(k) + 1:off(k) + MIN(3, ndof(k)))))) + IF (ndof(k) > 3) res_left = MAX(res_left, MAXVAL(ABS(r(off(k) + 4:off(k) + ndof(k))))*lsc(k)) + END IF + END DO + END IF IF (unstable) THEN IF (only_points) THEN CALL fail_solve(ErrStat, ErrMsg, 'static point equilibrium found is unstable: '// & @@ -27911,13 +27979,22 @@ SUBROUTINE solve_body_equilibrium(types, bodies, rod_types, rods, points, lines, !! Hermite connection moment, both evaluated at the previous pass's equilibrium. The passes !! repeat from the deck state until these loads change by at most 1e-7 of the force scale !! (moments of the force scale times 1 m), so the converged pose balances the Hermite cable - !! exactly: at the fixed point the core's surrogate end force cancels. A deck without such a + !! exactly: at the fixed point the core's surrogate end force cancels. A change is resolved + !! only down to the net load each pass's core solve leaves on the objects (res_left, its + !! tolerance 1e-9 of the core's own force scale, the largest net weight or line end force, or + !! its round-off): the end loads are those of poses balanced to that load, so two passes + !! differ by up to twice it (the end stiffness at most the stiffness that balances the + !! objects), and the passes stop on a change of at most PASS_RES_FACTOR times the larger of + !! the last two passes' res_left when that is above the tolerance. A deck without such a !! line is the core solve unchanged. A line with condensed torsion also returns its torque, !! which depends on the object's rotation as strongly as GJ/L: each pass then also gives the !! core the torque's moment stiffness (1/C) a a^T about the previous pass's pose (a = dTheta/dw !! of the cable at that pose, its shape held; C the line torsional compliance), so the passes !! converge whatever the ratio of the object's own restoring stiffness to GJ/L (the passes - !! alone would need it far above GJ/L), to 1e-10 of the force scale. A finite-EI line between + !! alone would need it far above GJ/L), to 1e-10 of the force scale (two moored 20 t bodies, + !! whose net weights set the core's scale to 13 times the line's end force, leave a res_left + !! of up to 5e-9 of that end force: their passes stalled at a change of 1-4e-9 for 60 passes, + !! the torque settled to six digits from the fourth). A finite-EI line between !! two objects (End B on a body point or a rod end) takes the same corrections at both ends, !! whatever its connections (the passes balance both objects on the cubic-Hermite cable); the !! torque's stiffness at each end is about that end's object with the other's held, the @@ -27942,6 +28019,8 @@ SUBROUTINE solve_body_equilibrium(types, bodies, rod_types, rods, points, lines, REAL(wp), INTENT(OUT), OPTIONAL :: jac_check_err INTEGER, PARAMETER :: MAX_PASS = 60, ANDERSON_DEPTH = 6 REAL(wp), PARAMETER :: PASS_TOL = 1.0e-7_wp, PASS_TOL_TORSION = 1.0e-10_wp, ANDERSON_DROP = 1.0e-6_wp + ! twice the res_left of a pass (two passes, each off by its own) and a margin of 2 + REAL(wp), PARAMETER :: PASS_RES_FACTOR = 4.0_wp TYPE(DeckBody), ALLOCATABLE :: bodies0(:) TYPE(DeckRod), ALLOCATABLE :: rods0(:) TYPE(DeckPoint), ALLOCATABLE :: points0(:) @@ -27961,8 +28040,17 @@ SUBROUTINE solve_body_equilibrium(types, bodies, rod_types, rods, points, lines, TYPE(DeckLine), ALLOCATABLE :: lines_core(:) INTEGER :: attempt, n_attempt, first_stat CHARACTER(1024) :: first_msg - REAL(wp) :: scale, change, pass_tol_eff - CHARACTER(24) :: b1 + REAL(wp) :: scale, change, pass_tol_eff, res_core, res_core_prev, pass_floor + CHARACTER(24) :: b1, b2 + ! the failure's advice: the passes balance each object against the line's end loads at the + ! last pose, so they settle only where the object's own restoring stiffness and its other + ! lines hold it against the change of those loads with its pose + CHARACTER(*), PARAMETER :: PASS_REMEDY = 'the end loads of the line change with the pose of its object(s) '// & + 'faster than the object''s restoring stiffness and its other lines settle them; '// & + 'restrain the object more stiffly (its moorings or C44/C55) or soften the '// & + 'connection (a finite Stiffness, a Pinned end or a finite TorsStiffness); OPTION '// & + 'bodyIC deck skips this balance and starts the objects out of equilibrium at their '// & + 'deck poses' ErrStat = CD_DECKDRV_OK ErrMsg = '' @@ -28077,6 +28165,8 @@ SUBROUTINE solve_body_equilibrium(types, bodies, rod_types, rods, points, lines, ext_fm = CD_ZERO ext_km = CD_ZERO ext_rot = CD_ZERO + res_core = CD_ZERO + pass_floor = CD_ZERO DO e = 1, ne ext_rot(1, 1, e) = CD_ONE ext_rot(2, 2, e) = CD_ONE @@ -28086,17 +28176,19 @@ SUBROUTINE solve_body_equilibrium(types, bodies, rod_types, rods, points, lines, bodies = bodies0 rods = rods0 points = points0 + res_core_prev = res_core ! the torque stiffness only with torsion: without it the core's arithmetic is exactly that ! of a deck before torsion existed (no zero-stiffness correction, signed zeros kept) IF (pass_tol_eff < PASS_TOL) THEN CALL solve_body_equilibrium_core(types, bodies, rod_types, rods, points, lines_core, sections, opts, & ErrStat, ErrMsg, bathymetry, ext_pt=ext_pt, ext_fm=ext_fm, & end_force_a=fs, quiet=pass > 1, skipped=held, ext_km=ext_km, & - ext_rot=ext_rot, end_force_b=fsb) + ext_rot=ext_rot, end_force_b=fsb, res_left=res_core) ELSE CALL solve_body_equilibrium_core(types, bodies, rod_types, rods, points, lines_core, sections, opts, & ErrStat, ErrMsg, bathymetry, ext_pt=ext_pt, ext_fm=ext_fm, & - end_force_a=fs, quiet=pass > 1, skipped=held, end_force_b=fsb) + end_force_a=fs, quiet=pass > 1, skipped=held, end_force_b=fsb, & + res_left=res_core) END IF IF (ErrStat /= CD_DECKDRV_OK) EXIT ! the objects stay at their deck poses (the core has already said why): nothing to balance @@ -28122,7 +28214,9 @@ SUBROUTINE solve_body_equilibrium(types, bodies, rod_types, rods, points, lines, eworst = MAXLOC(MAXVAL(ABS(new_fm - ext_fm), DIM=1), DIM=1) ext_km = new_km ext_rot = new_rot - IF (change <= pass_tol_eff*scale) THEN + ! the resolution of the passes: the net load the last two core solves left + pass_floor = PASS_RES_FACTOR*MAX(res_core, MERGE(res_core_prev, res_core, pass > 1)) + IF (change <= MAX(pass_tol_eff*scale, pass_floor)) THEN ext_fm = new_fm EXIT END IF @@ -28133,20 +28227,21 @@ SUBROUTINE solve_body_equilibrium(types, bodies, rod_types, rods, points, lines, END IF END DO IF (ErrStat == CD_DECKDRV_OK) THEN - IF (change <= pass_tol_eff*scale) EXIT + IF (change <= MAX(pass_tol_eff*scale, pass_floor)) EXIT WRITE (b1, '(ES10.3)') change/scale + WRITE (b2, '(ES10.3)') MAX(pass_tol_eff*scale, pass_floor)/scale IF (nb == 0) THEN CALL fail_solve(ErrStat, ErrMsg, 'static body/rod equilibrium with the END CONNECTION or ATTACHMENTS '// & 'of finite-EI LINE '//TRIM(int_to_str(lines(eline(eworst))%id))// & ' did not converge after '//TRIM(int_to_str(max_pass_eff))//' passes (relative end-load '// & - 'change '//TRIM(ADJUSTL(b1))//'); OPTION bodyIC deck starts from the deck pose instead') + 'change '//TRIM(ADJUSTL(b1))//', tolerance '//TRIM(ADJUSTL(b2))//'): '//PASS_REMEDY) ELSE ! the worst entry may be the End B of a line between two objects, connected or pinned CALL fail_solve(ErrStat, ErrMsg, 'static body/rod equilibrium with the bending end loads of finite-EI '// & 'LINE '//TRIM(int_to_str(lines(eline(eworst))%id))//' (its End '// & MERGE('B', 'A', eworst > ncl)//', on a body or rod) did not converge after '// & TRIM(int_to_str(max_pass_eff))//' passes (relative end-load change '//TRIM(ADJUSTL(b1))// & - '); OPTION bodyIC deck starts from the deck pose instead') + ', tolerance '//TRIM(ADJUSTL(b2))//'): '//PASS_REMEDY) END IF END IF IF (attempt == n_attempt) THEN diff --git a/src/CableDyn_HermiteCableDynamic.f90 b/src/CableDyn_HermiteCableDynamic.f90 index 10e0bf21..6c030390 100644 --- a/src/CableDyn_HermiteCableDynamic.f90 +++ b/src/CableDyn_HermiteCableDynamic.f90 @@ -4761,7 +4761,7 @@ SUBROUTINE eval_res(qcur, use_trial, rn, esx, emx) REAL(wp), POINTER :: Gout(:) INTEGER :: ii, nd INTEGER(INT64) :: ec0, ec1 - REAL(wp) :: xref, xd + REAL(wp) :: xref, xd, xc, ea_r, kt, tw_round REAL(wp), PARAMETER :: RESID_ROUNDOFF = 16.0_wp REAL(wp), PARAMETER :: STATE_DIVERGED = 1.0e12_wp ec0 = 0_INT64 ! defined even with profiling off (see the step-entry note) @@ -4875,18 +4875,37 @@ SUBROUTINE eval_res(qcur, use_trial, rn, esx, emx) ! so its rounding error is about eps*|r|/l0*EA per element. On a finely meshed, stiff, ! long cable at rest (e.g. 1024 elements, EA ~ 5e8 N, coordinates ~ 1e3 m) that exceeds ! tol*|w|*l0 and a held step stagnates at the floor forever. Raise fscale so tol*fscale - ! is never below RESID_ROUNDOFF times that error; the floor binds only there. + ! is never below RESID_ROUNDOFF times that error; the floor binds only there. With the + ! torque-tension coupling K the kernel carries EA - K^2/GJ and the torque the rest: the + ! coupling force (K/GJ) M_t takes the stretch through M_t = (GJ/l0)(... - (K/GJ)(l - l0)), + ! whose rounding is (K^2/GJ) eps |r|/l0, so the floor takes the whole axial stiffness + ! EA - K^2/GJ + K^2/GJ of the line (without it the floor fell by 1 - K^2/(EA GJ): at + ! K = 0.99 sqrt(EA GJ) to 2 % of the rounding it bounds, and a held line failed its step). xref = MAXVAL(model%l0) DO ii = 1, ndof IF (MOD(ii - 1, 6) < 3) xref = MAX(xref, ABS(qcur(ii))) END DO - fscale = MAX(fscale, RESID_ROUNDOFF*EPSILON(CD_ONE)*MAXVAL(model%EA/model%l0)*xref/tol) + IF (model%torsion%active .AND. ALLOCATED(model%torsion%couple)) THEN + ea_r = CD_ZERO + DO ii = 1, SIZE(model%l0) + ea_r = MAX(ea_r, (ABS(model%EA(ii)) + model%torsion%couple(ii)**2*model%torsion%gj(ii))/model%l0(ii)) + END DO + ELSE + ea_r = MAXVAL(model%EA/model%l0) + END IF + fscale = MAX(fscale, RESID_ROUNDOFF*EPSILON(CD_ONE)*ea_r*xref/tol) ! Nodal twist: the torque scale of the angle rows, frozen with fscale and formed like it ! from the nodal loads (a node's torque imbalance, not the torque the line carries, ! which accumulates the imbalances along the line as the tension does the force's): the ! inertial torques and the predictor's imbalance, at least 1 N m, and the round-off ! floor of an element twist, (GJ/l0 + Bt/l0 gamma/(beta dt)) eps (max|phi| + max|x|/l0) - ! (the damping takes the twist rate, whose Newmark rate amplifies the rounding). + ! (the damping takes the twist rate, whose Newmark rate amplifies the rounding). With the + ! torque-tension coupling the twist tau also takes -(K/GJ)(l - l0), the element length l + ! formed from coordinates with the rounding eps max|x|, so the floor adds + ! (GJ/l0 + Bt/l0 gamma/(beta dt)) |K/GJ| eps max|x| = |K| eps max|x|/l0 (static share): + ! K/l0 exceeds GJ/l0^2 by K l0/GJ (165 on a 2 m mesh at K = 0.85 sqrt(EA GJ), EA/GJ = + ! 9.4e3 m^-2), and without it a held line's rounding of 2.4e-8 N m stood above the + ! tolerance of its 1 N m scale and the step failed. IF (model%tw_active) THEN model%tw_tscale = CD_ONE DO ii = 1, model%nn @@ -4897,8 +4916,18 @@ SUBROUTINE eval_res(qcur, use_trial, rn, esx, emx) END DO xd = MAXVAL(model%torsion%gj/model%l0) IF (ALLOCATED(model%torsion%bt)) xd = xd + MAXVAL(model%torsion%bt/model%l0)*gm/(bt*dt) - model%tw_tscale = MAX(model%tw_tscale, RESID_ROUNDOFF*EPSILON(CD_ONE)*xd* & - (MAX(CD_ONE, MAXVAL(ABS(model%tw_pe))) + xref/MINVAL(model%l0))/tol) + xc = CD_ZERO + IF (ALLOCATED(model%torsion%couple)) THEN + DO ii = 1, SIZE(model%l0) + kt = model%torsion%gj(ii)/model%l0(ii) + IF (ALLOCATED(model%torsion%bt)) kt = kt + model%torsion%bt(ii)/model%l0(ii)*gm/(bt*dt) + xc = MAX(xc, ABS(model%torsion%couple(ii))*kt) + END DO + END IF + tw_round = MAX(CD_ONE, MAXVAL(ABS(model%tw_pe))) + xref/MINVAL(model%l0) + model%tw_tscale = MAX(model%tw_tscale, RESID_ROUNDOFF*EPSILON(CD_ONE)*xd*tw_round/tol) + IF (xc > CD_ZERO) & + model%tw_tscale = MAX(model%tw_tscale, RESID_ROUNDOFF*EPSILON(CD_ONE)*(xd*tw_round + xc*xref)/tol) END IF scale_set = .TRUE. END IF diff --git a/src/CableDyn_HermiteCableStatic.f90 b/src/CableDyn_HermiteCableStatic.f90 index 40b1dd63..d2ef016b 100644 --- a/src/CableDyn_HermiteCableStatic.f90 +++ b/src/CableDyn_HermiteCableStatic.f90 @@ -75,6 +75,7 @@ MODULE CableDyn_HermiteCableStatic PUBLIC :: CD_HermiteCable_Current_Load PUBLIC :: CD_HermiteCable_Friction_Anchors, CD_HermiteCable_Friction_Reference, CD_HermiteCable_As_Laid_Offsets PUBLIC :: CD_HermiteCable_Mean_Axial_Extremes + PUBLIC :: CD_HermiteCable_Kink_Advice, CD_HermiteCable_Element_Ratio PUBLIC :: CD_Arclength_Dot, CD_Arclength_Unit_Tangent, CD_Arclength_Bordered_Update INTEGER, PARAMETER, PUBLIC :: CD_HCSTAT_OK = 0, CD_HCSTAT_BADINPUT = 1, CD_HCSTAT_NOCONVERGE = 2 @@ -516,6 +517,10 @@ SUBROUTINE CD_HermiteCable_Static_Solve(l0, EA, EI, w, seed, fixed_dofs, seabed_ REAL(wp), ALLOCATABLE :: tors_g(:), tors_gr(:), tors_h(:, :), tors_v(:), tors_rhs(:), tors_q(:), tors_gs(:) REAL(wp), ALLOCATABLE :: tors_grs(:), tors_gt(:) REAL(wp), ALLOCATABLE :: tors_rhs2(:, :) + ! the untwisted equilibrium the twist starts from (its state, accepted Theta and Phi = Theta_0), + ! whose inertia an unstable twist stage is compared with (untwisted_inertia) + REAL(wp), ALLOCATABLE :: tors_q_untw(:) + REAL(wp) :: tors_th_untw, tors_phi_untw REAL(wp) :: contact_cs(2), end_support(3, 2), end_floor(3), end_g(2), end_sfac ! Floor-carried end moments in the potential: the end element shares of the last ! evaluation, and the shares held (end_share_held) by an energy line search or the caller. @@ -1091,6 +1096,10 @@ SUBROUTINE CD_HermiteCable_Static_Solve(l0, EA, EI, w, seed, fixed_dofs, seabed_ ELSE torsion%stable = stable END IF + ! an unstable state kept as the untwisted equilibrium's own instability (torsion_stage) + torsion%untwisted_instability = torsion%keep_untwisted_instability .AND. .NOT. torsion%stable .AND. & + torsion%n_negative_untwisted > 0 .AND. & + torsion%n_negative <= torsion%n_negative_untwisted END IF IF (res_out >= tol) THEN @@ -1879,6 +1888,8 @@ SUBROUTINE torsion_continuation(ecs, ecm) torsion%stable = .FALSE. torsion%n_negative = 0 torsion%lambda_min = CD_ZERO + torsion%n_negative_untwisted = -1 + torsion%untwisted_instability = .FALSE. CALL CD_HermiteTorsion_Line(q, l0, torsion%ends, raw, tors_g, ks, km, & couple=torsion%couple, quadrature_order=torsion%quadrature_order) IF (ks /= CD_HTORS_OK) THEN @@ -1908,6 +1919,9 @@ SUBROUTINE torsion_continuation(ecs, ecm) phi0 = tors_theta_acc total = torsion%phi - phi0 tors_on = .TRUE. + tors_q_untw = q + tors_th_untw = tors_theta_acc + tors_phi_untw = phi0 ! |total| <= 4000 pi (Phi and Theta_0 within 1000 turns of zero, Theta_0 within pi of its ! start): at most 16000 stages, so the integer stage count cannot overflow dlam_max = CD_ONE/REAL(MAX(1, CEILING(MIN(ABS(total), 2.0_wp*CD_HTORS_MAX_TWIST + CD_HTORS_PI)/ & @@ -1947,6 +1961,16 @@ SUBROUTINE torsion_continuation(ecs, ecm) ecm = wbuf RETURN END IF + IF (lam <= CD_ZERO .AND. torsion%n_negative_untwisted > 0) THEN + ! the first stage failed on an instability the untwisted state already has: not a + ! loop of the twist (with no twist to impose, not a twist at all) + WRITE (wbuf, '(A,I0,A,ES12.5,A,ES12.5,A)', IOSTAT=wios) & + 'CD_HermiteCable_Static_Solve: torsion stage failed: the untwisted equilibrium it starts '// & + 'from is itself unstable (', torsion%n_negative_untwisted, ' negative stiffness mode(s) at '// & + 'Phi = Theta_0 = ', phi0, ' rad, target Phi ', torsion%phi, ' rad): '//TRIM(why) + ecm = wbuf + RETURN + END IF WRITE (wbuf, '(A,ES12.5,A,ES12.5,A)', IOSTAT=wios) & 'CD_HermiteCable_Static_Solve: torsion continuation stalled at Phi = ', tors_phi_cur, & ' rad (target ', torsion%phi, ' rad): '//TRIM(why)// & @@ -2009,10 +2033,54 @@ SUBROUTINE torsion_stage(ok, why) RETURN END IF torsion%stable = st - IF (st .OR. .NOT. torsion%descend) RETURN + IF (st) RETURN + ! An unstable stage: is the instability the twist's? The untwisted state's negative count + ! (once, at the start of the twist) tells; a stage with no more negative eigenvalues than + ! it is kept under keep_untwisted_instability (a descent would leave an instability the + ! twist did not bring, and with current drag cannot run at all). + IF (torsion%keep_untwisted_instability .OR. torsion%descend) THEN + CALL untwisted_inertia(ks, km) + IF (ks /= CD_HCSTAT_OK) THEN + ok = .FALSE. + why = km + RETURN + END IF + END IF + IF (torsion%keep_untwisted_instability .AND. torsion%n_negative_untwisted >= 0 .AND. & + torsion%n_negative <= torsion%n_negative_untwisted) RETURN + IF (.NOT. torsion%descend) RETURN CALL torsion_descent(ok, why) END SUBROUTINE torsion_stage + SUBROUTINE untwisted_inertia(ecs, ecm) + !! torsion%n_negative_untwisted, once: the stability test of the untwisted equilibrium the + !! twist started from (tors_q_untw at Phi = Theta_0, no torque); the current state, its + !! accepted Theta and Phi are then restored and tested again, which restores its report + !! and the lowest mode the descent takes. + INTEGER, INTENT(OUT) :: ecs + CHARACTER(*), INTENT(OUT) :: ecm + REAL(wp), ALLOCATABLE :: q_now(:) + REAL(wp) :: th_now, phi_now + LOGICAL :: st0 + ecs = CD_HCSTAT_OK + ecm = '' + IF (torsion%n_negative_untwisted >= 0 .OR. .NOT. ALLOCATED(tors_q_untw)) RETURN + q_now = q + th_now = tors_theta_acc + phi_now = tors_phi_cur + q = tors_q_untw + tors_theta_acc = tors_th_untw + tors_phi_cur = tors_phi_untw + CALL torsion_stability(st0, ecs, ecm) + q = q_now + tors_theta_acc = th_now + tors_phi_cur = phi_now + IF (ecs /= CD_HCSTAT_OK) RETURN + torsion%n_negative_untwisted = MERGE(0, MAX(1, torsion%n_negative), st0) + CALL torsion_stability(st0, ecs, ecm) + torsion%stable = st0 + END SUBROUTINE untwisted_inertia + SUBROUTINE torsion_stability(st, ecs, ecm) !! Stability of the state q with torsion: the inertia of the symmetric tangent !! B + g g^T / C on the free DOFs (CD_HermiteTorsion_Inertia). A negative (or unreliable) @@ -5199,11 +5267,57 @@ SUBROUTINE reject_unresolved_sequence(l0, q, ErrStat, ErrMsg) WRITE (wbuf, '(A,ES12.5,A,ES12.5,A,I0)', IOSTAT=wios) & 'mesh-sequenced equilibrium is unresolved/kinked: max(h*kappa)=', diag%h_kappa_peak, & ' > safety limit=', CD_HC_KINK_LIMIT, ' at element ', diag%h_kappa_elem - ErrMsg = wbuf + ErrMsg = TRIM(wbuf)//TRIM(CD_HermiteCable_Kink_Advice(diag%h_kappa_peak, diag%h_kappa_elem, SIZE(l0))) END BLOCK END IF END SUBROUTINE reject_unresolved_sequence + PURE FUNCTION CD_HermiteCable_Kink_Advice(h_kappa, elem, n_elem, deck_ratio) RESULT(advice) + !! The remedy of an unresolved/kinked refusal (max(h*kappa) = h_kappa above CD_HC_KINK_LIMIT + !! at element elem of n_elem): on a resolved bend the curvature kappa does not change with the + !! mesh, so h*kappa falls in proportion to the element length and a mesh n times finer there + !! clears the limit for n >= h_kappa/CD_HC_KINK_LIMIT; deck_ratio (default 1) is the deck + !! element's length over the solve element's (an automatically refined mesh), which the + !! factor for NumSegs takes. A fold that stays kinked on the finer mesh is a non-physical + !! branch, not a resolution limit. Starts with '; '. + REAL(wp), INTENT(IN) :: h_kappa + INTEGER, INTENT(IN) :: elem, n_elem + REAL(wp), INTENT(IN), OPTIONAL :: deck_ratio + CHARACTER(320) :: advice + REAL(wp) :: f + INTEGER :: n, ios + f = h_kappa/CD_HC_KINK_LIMIT + IF (PRESENT(deck_ratio)) f = f*MAX(CD_ONE, deck_ratio) + IF (.NOT. (f < 1.0e6_wp)) f = 1.0e6_wp + n = MAX(2, CEILING(f)) + advice = '' + WRITE (advice, '(A,I0,A,I0,A,I0,A)', IOSTAT=ios) '; refine NumSegs at least ', n, 'x about element ', elem, & + ' (of ', n_elem, ' in the solve): h*kappa falls in proportion to the element length on a resolved bend '// & + '(a fold that stays kinked on the finer mesh is a non-physical branch)' + END FUNCTION CD_HermiteCable_Kink_Advice + + PURE REAL(wp) FUNCTION CD_HermiteCable_Element_Ratio(l0_ref, l0_fin, elem) RESULT(ratio) + !! The length of the element of the mesh l0_ref (the deck's) that holds the rest-arc midpoint + !! of element elem of the mesh l0_fin (a refinement of it) over that element's length: the + !! refinement already applied there (1 outside the meshes or for one mesh). + REAL(wp), INTENT(IN) :: l0_ref(:), l0_fin(:) + INTEGER, INTENT(IN) :: elem + REAL(wp) :: s_mid, s_acc + INTEGER :: k + ratio = CD_ONE + IF (elem < 1 .OR. elem > SIZE(l0_fin) .OR. SIZE(l0_ref) < 1) RETURN + IF (.NOT. (l0_fin(elem) > CD_ZERO)) RETURN + s_mid = SUM(l0_fin(1:elem - 1)) + 0.5_wp*l0_fin(elem) + s_acc = CD_ZERO + DO k = 1, SIZE(l0_ref) + s_acc = s_acc + l0_ref(k) + IF (s_mid <= s_acc .OR. k == SIZE(l0_ref)) THEN + ratio = MAX(CD_ONE, l0_ref(k)/l0_fin(elem)) + RETURN + END IF + END DO + END FUNCTION CD_HermiteCable_Element_Ratio + SUBROUTINE CD_HermiteCable_Resolution_Metrics(l0, q, seabed_z, contact_band, & h_kappa_target, diag, ErrStat, ErrMsg, & bathymetry, contact_frame_cs, EA, EI, compression_mode, & @@ -6733,6 +6847,12 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs diag_out%h_kappa_peak, ' > safety limit=', CD_HC_KINK_LIMIT, & ' at element ', diag_out%h_kappa_elem IF (LEN_TRIM(local_stop) > 0) wbuf = TRIM(wbuf)//' (local refinement stopped: '//TRIM(local_stop)//')' + BLOCK + REAL(wp) :: deck_ratio + deck_ratio = CD_HermiteCable_Element_Ratio(l0, l0_out, diag_out%h_kappa_elem) + wbuf = TRIM(wbuf)//TRIM(CD_HermiteCable_Kink_Advice(diag_out%h_kappa_peak, diag_out%h_kappa_elem, & + SIZE(l0_out), deck_ratio)) + END BLOCK ErrMsg = wbuf RETURN END IF diff --git a/src/CableDyn_HermiteTorsion.f90 b/src/CableDyn_HermiteTorsion.f90 index 6f97c2f3..752b5586 100644 --- a/src/CableDyn_HermiteTorsion.f90 +++ b/src/CableDyn_HermiteTorsion.f90 @@ -146,11 +146,22 @@ MODULE CableDyn_HermiteTorsion LOGICAL :: check_stability = .TRUE. LOGICAL :: descend = .TRUE. LOGICAL :: zero_mode_allowed = .FALSE. + !! keep_untwisted_instability: a twist stage that is unstable with no more negative + !! eigenvalues than the untwisted equilibrium it starts from (the twist adds no instability: + !! the untwisted state's own, which its caller accepted, a planar state unstable out of its + !! plane for example) is kept as it is, not descended from or refused; the report then sets + !! untwisted_instability. + LOGICAL :: keep_untwisted_instability = .FALSE. !! Static report at the returned state: stability, negative-eigenvalue count of the tangent !! on the free DOFs, the lowest Jacobi-scaled eigenvalue when it was computed (0 otherwise), !! the total potential energy, the twist-continuation stage count and the descents taken. LOGICAL :: stable = .FALSE. INTEGER :: n_negative = 0 + !! The negative-eigenvalue count of the untwisted equilibrium the twist starts from (-1: not + !! evaluated, which it is only once a twist stage is unstable), and whether the returned + !! unstable state was kept under keep_untwisted_instability (its count at most that one). + INTEGER :: n_negative_untwisted = -1 + LOGICAL :: untwisted_instability = .FALSE. REAL(wp) :: lambda_min = CD_ZERO REAL(wp) :: energy = CD_ZERO INTEGER :: ramp_steps = 0 diff --git a/tests/test_torsion_body_passes.f90 b/tests/test_torsion_body_passes.f90 new file mode 100644 index 00000000..10208cb6 --- /dev/null +++ b/tests/test_torsion_body_passes.f90 @@ -0,0 +1,169 @@ +! File: tests/test_torsion_body_passes.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +PROGRAM test_torsion_body_passes + !! The static passes of a finite-EI cable restrained in torsion between two moored Rigid6 bodies + !! (bodyIC static) converge at every pretwist. The bodies (20 t, three mooring legs each) are each + !! other turned 180 deg about the vertical axis between them; the cable (64 m, 40 + !! elements, EA 5e8 N, EI 2e4 N m2, GJ 5e4 N m2) is clamped (Rigid) or bending-pinned at both + !! ends and Rigid in torsion, with the pretwist at End B. The passes compare the change of the + !! cable's end loads with 1e-10 of their scale, but each pass balances the bodies only to the + !! core solve's tolerance, 1e-9 of its own scale (the bodies' net weight, 13 times the cable end + !! force here): the change could not fall below 1-4e-9 and the passes stopped after 60 at 360 + !! deg (Rigid) and 300 deg (Pinned), the torque settled to six digits from the fourth pass. The + !! passes now stop at the resolution the core leaves (four times its residual load). + !! 1. Rigid ends, 360 deg, and Pinned ends, 300 deg (both failed): the static start is + !! found; + !! 2. it is the symmetric equilibrium (the deck's symmetry, which the passes do not impose): + !! body 2's pose is body 1's turned 180 deg about the vertical axis, to 1e-6 m and deg, and + !! the end tensions are equal to 1e-6; + !! 3. a still run of 0.5 s holds it: the poses within 2e-6 m and deg, the torque within 1e-6 of + !! its start. + USE CableDyn_Precision, ONLY: wp + USE CableDyn_DeckDriver, ONLY: CD_Run_Deck_Driver, CD_DECKDRV_OK + IMPLICIT NONE + + INTEGER :: nfail = 0 + + CALL pair_case('tbp_rigid_360', 'Rigid', 360) + CALL pair_case('tbp_pinned_300', 'Pinned', 300) + IF (nfail > 0) THEN + PRINT '(I0,A)', nfail, ' assertion(s) failed' + ERROR STOP 1 + END IF + PRINT '(A)', 'all torsion body-pass checks passed' + +CONTAINS + + SUBROUTINE pair_case(root, conn, pretwist) + !! Run the pair, then the symmetry and stillness gates on its .out (Body1/Body2 P/R, FairTen7, + !! AnchTen7, Torq7N1). + CHARACTER(*), INTENT(IN) :: root, conn + INTEGER, INTENT(IN) :: pretwist + REAL(wp) :: row(16), first(16), drift(16), sym + INTEGER :: u, ios, es, nrow + LOGICAL :: conv + CHARACTER(512) :: em + CHARACTER(4096) :: buf + CALL write_pair(root//'.dat', conn, pretwist) + CALL CD_Run_Deck_Driver(root//'.dat', root, conv, es, em) + CALL require(es == CD_DECKDRV_OK .AND. conv, root//': the static passes converge and the run ends: '//TRIM(em)) + IF (es /= CD_DECKDRV_OK) RETURN + OPEN (NEWUNIT=u, FILE=root//'.out', STATUS='OLD', ACTION='READ', IOSTAT=ios) + READ (u, '(A)') buf + READ (u, '(A)') buf + nrow = 0 + drift = 0.0_wp + DO + READ (u, *, IOSTAT=ios) row + IF (ios /= 0) EXIT + nrow = nrow + 1 + IF (nrow == 1) first = row + drift = MAX(drift, ABS(row - first)) + END DO + CLOSE (u) + ! body 2 = body 1 turned 180 deg about z: (x, y, z) -> (-x, -y, z), rotations (rx, ry, rz) -> + ! (-rx, -ry, rz) + sym = MAXVAL(ABS([first(2) + first(8), first(3) + first(9), first(4) - first(10), first(5) + first(11), & + first(6) + first(12), first(7) - first(13)])) + PRINT '(A,ES10.3,A,ES10.3,A,ES10.3,A,ES14.7,A)', ' '//root//': symmetry ', sym, ', pose drift ', & + MAXVAL(drift(2:13)), ', torque drift ', drift(16), ' (torque ', first(16), ' N m)' + CALL require(sym <= 1.0e-6_wp, root//': the start is the mirror-symmetric equilibrium') + CALL require(ABS(first(14) - first(15)) <= 1.0e-6_wp*first(14), root//': equal end tensions') + CALL require(ABS(row(1) - 0.5_wp) < 1.0e-9_wp .AND. MAXVAL(drift(2:13)) <= 2.0e-6_wp, & + root//': the still run holds the poses') + CALL require(drift(16) <= 1.0e-6_wp*ABS(first(16)), root//': the still run holds the torque') + END SUBROUTINE pair_case + + SUBROUTINE write_pair(path, conn, pretwist) + !! The two moored bodies at x = -30 and 30 m, the cable between their points 13 and 14. + CHARACTER(*), INTENT(IN) :: path, conn + INTEGER, INTENT(IN) :: pretwist + INTEGER :: u, k + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'torsion body passes' + WRITE (u, '(A)') '--- LINE TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass EA BA EI GAs GJ Irt Irn Cdn Cdt Can Cat' + WRITE (u, '(A)') '(-) (m) (kg/m) (N) (-) (Nm2) (N) (Nm2) (kgm) (kgm) (-) (-) (-) (-)' + WRITE (u, '(A)') 'poly 0.12 15.0 5.0e7 -1.0 0.0 0 0 0 0 1.2 0.2 1.0 0.0' + WRITE (u, '(A)') 'cab 0.2 60 500000000 -1 20000 100000000 50000 1 0.3 1.2 0 1 0' + WRITE (u, '(A)') '--- BODIES ---' + WRITE (u, '(A)') 'ID Type X Y Z Roll Pitch Yaw Mass Vol C33 C44 C55 CdA Ca Ixx Iyy Izz' + WRITE (u, '(A)') '(-) (-) (m) (m) (m) (deg) (deg) (deg) (kg) (m3) (N/m) (Nm) (Nm) (m2) (-) (kgm2) (kgm2) (kgm2)' + WRITE (u, '(A)') '1 Rigid6 -30 0 -20 0 0 0 20000 40 0 2000000 2000000 8 0.5 35000 35000 35000' + WRITE (u, '(A)') '2 Rigid6 30 0 -20 0 0 0 20000 40 0 2000000 2000000 8 0.5 35000 35000 35000' + 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 Body1 -1.5 0.0 -2.0 0 0 0 0' + WRITE (u, '(A)') '2 Body1 0.75 1.299 -2.0 0 0 0 0' + WRITE (u, '(A)') '3 Body1 0.75 -1.299 -2.0 0 0 0 0' + WRITE (u, '(A)') '4 Fixed -70.0 0.0 -100.0 0 0 0 0' + WRITE (u, '(A)') '5 Fixed -10.0 34.641 -100.0 0 0 0 0' + WRITE (u, '(A)') '6 Fixed -10.0 -34.641 -100.0 0 0 0 0' + WRITE (u, '(A)') '7 Body2 1.5 0.0 -2.0 0 0 0 0' + WRITE (u, '(A)') '8 Body2 -0.75 1.299 -2.0 0 0 0 0' + WRITE (u, '(A)') '9 Body2 -0.75 -1.299 -2.0 0 0 0 0' + WRITE (u, '(A)') '10 Fixed 70.0 0.0 -100.0 0 0 0 0' + WRITE (u, '(A)') '11 Fixed 10.0 34.641 -100.0 0 0 0 0' + WRITE (u, '(A)') '12 Fixed 10.0 -34.641 -100.0 0 0 0 0' + WRITE (u, '(A)') '13 Body1 0.0 0.0 -3.0 0 0 0 0' + WRITE (u, '(A)') '14 Body2 0.0 0.0 -3.0 0 0 0 0' + WRITE (u, '(A)') '--- LINES ---' + WRITE (u, '(A)') 'ID NodeA NodeB Outputs' + WRITE (u, '(A)') '(-) (-) (-) (-)' + DO k = 1, 3 + WRITE (u, '(I0,A,I0,A,I0,A)') k, ' ', k, ' ', k + 3, ' -' + END DO + DO k = 4, 6 + WRITE (u, '(I0,A,I0,A,I0,A)') k, ' ', k + 3, ' ', k + 6, ' -' + END DO + WRITE (u, '(A)') '7 13 14 -' + WRITE (u, '(A)') '--- SECTIONS ---' + WRITE (u, '(A)') 'LineID LineType Length NumSegs' + WRITE (u, '(A)') '(-) (-) (m) (-)' + DO k = 1, 6 + WRITE (u, '(I0,A)') k, ' poly 86.85 20' + END DO + WRITE (u, '(A)') '7 cab 64 40' + WRITE (u, '(A)') '--- END CONNECTIONS ---' + WRITE (u, '(A)') 'LineID End Stiffness EzX EzY EzZ TorsStiffness NxX NxY NxZ Pretwist' + WRITE (u, '(A)') '(-) (-) (N-m/rad) (-) (-) (-) (N-m/rad) (-) (-) (-) (deg)' + WRITE (u, '(A)') '7 A '//conn//' 0.7071067811865476 0.0 -0.7071067811865476 Rigid 0 1 0 0' + WRITE (u, '(A,I0)') '7 B '//conn//' 0.7071067811865476 0.0 0.7071067811865476 Rigid 0 1 0 ', pretwist + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '100.0 WtrDpth' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '1.0e5 kBot' + WRITE (u, '(A)') '1.0e4 cBot' + WRITE (u, '(A)') '0.05 dtM' + WRITE (u, '(A)') '0.5 TMax' + WRITE (u, '(A)') 'static bodyIC' + WRITE (u, '(A)') '--- OUTPUTS ---' + DO k = 1, 2 + WRITE (u, '(A,I0,A)') 'Body', k, 'Px' + WRITE (u, '(A,I0,A)') 'Body', k, 'Py' + WRITE (u, '(A,I0,A)') 'Body', k, 'Pz' + WRITE (u, '(A,I0,A)') 'Body', k, 'Rx' + WRITE (u, '(A,I0,A)') 'Body', k, 'Ry' + WRITE (u, '(A,I0,A)') 'Body', k, 'Rz' + END DO + WRITE (u, '(A)') 'FairTen7' + WRITE (u, '(A)') 'AnchTen7' + WRITE (u, '(A)') 'Torq7N1' + WRITE (u, '(A)') '--- END ---' + CLOSE (u) + END SUBROUTINE write_pair + + SUBROUTINE require(ok, what) + LOGICAL, INTENT(IN) :: ok + CHARACTER(*), INTENT(IN) :: what + IF (ok) THEN + PRINT '(A)', 'PASS: '//what + ELSE + PRINT '(A)', 'FAIL: '//what + nfail = nfail + 1 + END IF + END SUBROUTINE require +END PROGRAM test_torsion_body_passes diff --git a/tests/test_torsion_coupling_still.f90 b/tests/test_torsion_coupling_still.f90 new file mode 100644 index 00000000..1b2dc95e --- /dev/null +++ b/tests/test_torsion_coupling_still.f90 @@ -0,0 +1,186 @@ +! File: tests/test_torsion_coupling_still.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +PROGRAM test_torsion_coupling_still + !! A held line under strong torque-tension coupling stays still in its dynamics at the default + !! dtM (0.05 s) and dynamic tolerance (1e-8). The line: 50 m neutral cable, EA 4.69e8 N, GJ 5e4 + !! N m2, Irn 0.1174 kg m (the nodal twist), 25 elements, stretched by eps = 1.07e-4 between a + !! held Coupled End A and a Fixed End B, the coupling K = r sqrt(EA GJ). Its static start is exact, + !! so a step of the held line is a residual at the round-off of its forces: the convergence norm + !! must place its floor at the rounding of the axial force of the whole axial stiffness (the + !! kernel's EA - K^2/GJ plus the coupling's K^2/GJ) and of the element torque, whose coupling + !! share (K/GJ)(l - l0) is formed from coordinates (|K| eps max|x|/l0). Before, at |r| >= 0.85 + !! (and at -0.8 with one end free) a step failed, "Newton did not converge, ||G|| = 2.4e-8 > + !! tol = 1e-8", within 0.05-0.9 s. + !! 1. Both ends Rigid in torsion, Pretwist 90 deg, r = 0.85, 0.9, 0.95, 0.99: the run of 2 s + !! holds, and its start is the section law T = EA eps + K Phi/L0, M = GJ Phi/L0 + K eps + !! (relative 1e-6). + !! 2. Both ends Rigid, r = -0.8, -0.9: the opposite-sense coupling compresses the line, which + !! buckles into a twisted bow; the run of 2 s holds its start. + !! 3. End B Free in torsion, r = -0.8, -0.9: the stretch twists the line, so T = (EA - + !! K^2/GJ) eps and M = 0; the run of 10 s holds. + !! Holding: every tension and torque channel stays within 1e-6 of the scale of its parts (EA eps + + !! |K| Phi/L0 for a tension, GJ Phi/L0 + |K| eps for a torque) of its start. + USE CableDyn_Precision, ONLY: wp + USE CableDyn_DeckDriver, ONLY: CD_Run_Deck_Driver, CD_DECKDRV_OK + IMPLICIT NONE + + REAL(wp), PARAMETER :: PI = 3.14159265358979323846_wp + REAL(wp), PARAMETER :: EA = 4.69e8_wp, GJ = 5.0e4_wp, SPAN = 50.0_wp, L0 = 49.9946700778_wp + REAL(wp), PARAMETER :: PHI = 0.5_wp*PI + INTEGER :: nfail = 0 + + CALL still_case('tcst_p085', 0.85_wp, .FALSE., .TRUE.) + CALL still_case('tcst_p090', 0.90_wp, .FALSE., .TRUE.) + CALL still_case('tcst_p095', 0.95_wp, .FALSE., .TRUE.) + CALL still_case('tcst_p099', 0.99_wp, .FALSE., .TRUE.) + CALL still_case('tcst_m080', -0.80_wp, .FALSE., .FALSE.) + CALL still_case('tcst_m090', -0.90_wp, .FALSE., .FALSE.) + CALL still_case('tcst_fm080', -0.80_wp, .TRUE., .TRUE.) + CALL still_case('tcst_fm090', -0.90_wp, .TRUE., .TRUE.) + IF (nfail > 0) THEN + PRINT '(I0,A)', nfail, ' assertion(s) failed' + ERROR STOP 1 + END IF + PRINT '(A)', 'all held coupled-line checks passed' + +CONTAINS + + SUBROUTINE still_case(root, r, free_b, straight) + !! Run the case, check the start against the section law (straight) and the run's stillness. + CHARACTER(*), INTENT(IN) :: root + REAL(wp), INTENT(IN) :: r + LOGICAL, INTENT(IN) :: free_b, straight + REAL(wp) :: k, eps, t_ref, m_ref, t_sc, m_sc, row(5), first(5), dev(4) + INTEGER :: u, ios, es, nrow + LOGICAL :: conv + CHARACTER(512) :: em + CHARACTER(4096) :: buf + CHARACTER(160) :: what + k = r*SQRT(EA*GJ) + eps = SPAN/L0 - 1.0_wp + CALL write_case(root//'.dat', k, free_b) + CALL CD_Run_Deck_Driver(root//'.dat', root, conv, es, em) + IF (free_b) THEN + WRITE (what, '(A,F6.2,A)') root//' (K/sqrt(EA GJ) = ', r, ', End B free)' + ELSE + WRITE (what, '(A,F6.2,A)') root//' (K/sqrt(EA GJ) = ', r, ', both Rigid)' + END IF + CALL require(es == CD_DECKDRV_OK .AND. conv, TRIM(what)//' runs: '//TRIM(em)) + IF (es /= CD_DECKDRV_OK) RETURN + IF (free_b) THEN + t_ref = (EA - k*k/GJ)*eps + m_ref = 0.0_wp + t_sc = EA*eps + m_sc = ABS(k)*eps + ELSE + t_ref = EA*eps + k*PHI/L0 + m_ref = GJ*PHI/L0 + k*eps + t_sc = EA*eps + ABS(k)*PHI/L0 + m_sc = GJ*PHI/L0 + ABS(k)*eps + END IF + OPEN (NEWUNIT=u, FILE=root//'.out', STATUS='OLD', ACTION='READ', IOSTAT=ios) + READ (u, '(A)') buf + READ (u, '(A)') buf + nrow = 0 + dev = 0.0_wp + first = 0.0_wp + DO + READ (u, *, IOSTAT=ios) row + IF (ios /= 0) EXIT + nrow = nrow + 1 + IF (nrow == 1) first = row + dev = MAX(dev, ABS(row(2:5) - first(2:5))) + END DO + CLOSE (u) + PRINT '(A,ES11.3,A,4ES12.4)', ' '//root//': t_end ', row(1), ' s, max |change| T_A T_B M_A M_B ', dev + CALL require(ABS(row(1) - MERGE(10.0_wp, 2.0_wp, free_b)) < 1.0e-9_wp, TRIM(what)//' reaches TMax') + CALL require(MAXVAL(dev(1:2)) <= 1.0e-6_wp*t_sc .AND. MAXVAL(dev(3:4)) <= 1.0e-6_wp*m_sc, & + TRIM(what)//' holds its start') + IF (straight) THEN + PRINT '(A,4ES16.8)', ' start T, M and the section law ', first(2), first(4), t_ref, m_ref + CALL require(ABS(first(2) - t_ref) <= 1.0e-6_wp*t_sc .AND. ABS(first(3) - t_ref) <= 1.0e-6_wp*t_sc, & + TRIM(what)//' starts at the section tension') + CALL require(ABS(first(4) - m_ref) <= 1.0e-6_wp*m_sc .AND. ABS(first(5) - m_ref) <= 1.0e-6_wp*m_sc, & + TRIM(what)//' starts at the section torque') + END IF + END SUBROUTINE still_case + + SUBROUTINE write_case(path, k, free_b) + !! The held line: End A Coupled at the origin (no motion), End B Fixed 50 m along +x, both + !! ends clamped along x; torsion Rigid at End A and Rigid (Pretwist 90 deg) or Free at End B. + CHARACTER(*), INTENT(IN) :: path + REAL(wp), INTENT(IN) :: k + LOGICAL, INTENT(IN) :: free_b + INTEGER :: u + CHARACTER(64) :: gjcol + WRITE (gjcol, '(ES12.5,A,ES17.10)') GJ, '|', k + gjcol = remove_blanks(gjcol) + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'held line under torque-tension coupling' + WRITE (u, '(A)') '--- LINE TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass EA BA EI GAs GJ Irt Irn Cdn Cdt Can Cat' + WRITE (u, '(A)') '(-) (m) (kg/m) (N) (-) (Nm2) (N) (Nm2) (kgm) (kgm) (-) (-) (-) (-)' + WRITE (u, '(A)') 'cab 0.16 20.6088478075 469000000 -0.8 20000 90000000 '//TRIM(gjcol)// & + ' 0.0587 0.1174 1.2 0.1 1 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 Coupled 0 0 -50 0 0 0 0' + WRITE (u, '(A)') '2 Fixed 50 0 -50 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 cab 49.9946700778 25' + WRITE (u, '(A)') '--- END CONNECTIONS ---' + WRITE (u, '(A)') 'LineID End Stiffness EzX EzY EzZ TorsStiffness NxX NxY NxZ Pretwist' + WRITE (u, '(A)') '(-) (-) (N-m/rad) (-) (-) (-) (N-m/rad) (-) (-) (-) (deg)' + WRITE (u, '(A)') '1 A Rigid 1 0 0 Rigid 0 1 0 0' + IF (free_b) THEN + WRITE (u, '(A)') '1 B Rigid 1 0 0 Free 0 1 0 0' + ELSE + WRITE (u, '(A)') '1 B Rigid 1 0 0 Rigid 0 1 0 90' + END IF + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '0.05 dtM' + WRITE (u, '(A)') MERGE('10 TMax', ' 2 TMax', free_b) + WRITE (u, '(A)') '--- OUTPUTS ---' + WRITE (u, '(A)') 'FairTen1' + WRITE (u, '(A)') 'AnchTen1' + WRITE (u, '(A)') 'Torq1N1' + WRITE (u, '(A)') 'Torq1N26' + WRITE (u, '(A)') '--- END ---' + CLOSE (u) + END SUBROUTINE write_case + + PURE FUNCTION remove_blanks(s) RESULT(r) + CHARACTER(*), INTENT(IN) :: s + CHARACTER(LEN(s)) :: r + INTEGER :: i, k + r = '' + k = 0 + DO i = 1, LEN(s) + IF (s(i:i) /= ' ') THEN + k = k + 1 + r(k:k) = s(i:i) + END IF + END DO + END FUNCTION remove_blanks + + SUBROUTINE require(ok, what) + LOGICAL, INTENT(IN) :: ok + CHARACTER(*), INTENT(IN) :: what + IF (ok) THEN + PRINT '(A)', 'PASS: '//what + ELSE + PRINT '(A)', 'FAIL: '//what + nfail = nfail + 1 + END IF + END SUBROUTINE require +END PROGRAM test_torsion_coupling_still diff --git a/tests/test_torsion_current_start.py b/tests/test_torsion_current_start.py new file mode 100644 index 00000000..0f047b25 --- /dev/null +++ b/tests/test_torsion_current_start.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +"""A lazy wave restrained in torsion starts in an in-plane current. + +The lazy wave of ``tests/data/lazy_wave_torsion_attachments.dat`` (25 buoyancy modules, Rigid in +torsion at both ends) in a 0.5 m/s current along its plane: its untwisted static state, solved in +the vertical plane, is unstable out of that plane on its mesh (one negative stiffness mode), which +the same deck without torsion accepts with a note. The twist stage added no instability, yet the +torsion stage refused it: at pretwist 0 "torsion continuation stalled at Phi = 0 (target 0): the +twisted equilibrium is unstable", at 360 deg an unstable equilibrium after a failed Newton solve. + +Gate, on the driver's own output: at pretwist 0 and 360 deg the deck starts and runs (it stopped +before), the torsion note reports the twist solved, and the instability is named as the untwisted +state's own. + +usage: test_torsion_current_start.py --exe --data --output +""" + +from __future__ import annotations + +import argparse +import subprocess +import sys +from pathlib import Path + + +def deck_text(base: str, pretwist: str) -> str: + lines = base.split("\n") + out = [] + for line in lines: + f = line.split() + if f and f[0] == "bare" and len(f) == 14: + f[9] = "0.12" + line = " ".join(f) + elif f[:3] == ["4", "B", "Rigid"]: + line = " ".join(f[:-1] + [pretwist]) + elif f[1:] == ["dtM"]: + line = "0.05 dtM" + elif f[1:] == ["TMax"]: + line = "0.5 TMax\nuniform 0.5 0 0 current" + out.append(line) + return "\n".join(out) + + +def main() -> int: + ap = argparse.ArgumentParser() + ap.add_argument("--exe", required=True) + ap.add_argument("--data", required=True) + ap.add_argument("--output", required=True) + args = ap.parse_args() + out = Path(args.output) + out.mkdir(parents=True, exist_ok=True) + base = (Path(args.data) / "lazy_wave_torsion_attachments.dat").read_text( + encoding="utf-8" + ) + failures = [] + for pretwist in ("0", "360"): + deck = out / f"lw_current_twist{pretwist}.dat" + deck.write_text(deck_text(base, pretwist), encoding="utf-8", newline="\n") + if "uniform 0.5 0 0 current" not in deck.read_text(encoding="utf-8"): + failures.append("the deck edit did not place the current") + continue + p = subprocess.run( + [args.exe, str(deck), str(out / f"lw_current_twist{pretwist}")], + capture_output=True, + text=True, + check=False, + ) + log = p.stdout + p.stderr + solved = "torsion solved" in log + named = "keeps the instability of its untwisted state" in log + print( + f"pretwist {pretwist}: exit {p.returncode}, solved {solved}, untwisted instability named {named}" + ) + if p.returncode != 0: + failures.append(f"pretwist {pretwist}: the deck stopped: {log[-400:]}") + if not solved: + failures.append(f"pretwist {pretwist}: no 'torsion solved' note") + if not named: + failures.append( + f"pretwist {pretwist}: the untwisted state's instability is not named" + ) + if "stalled" in log: + failures.append( + f"pretwist {pretwist}: a stalled torsion continuation is reported" + ) + for f in failures: + print("FAIL: " + f) + if not failures: + print("PASS: a lazy wave restrained in torsion starts in an in-plane current") + return 1 if failures else 0 + + +if __name__ == "__main__": + sys.exit(main()) From 1bdbb754e46111f3b9537267b25f5c49152b75c3 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Tue, 3 Nov 2026 13:37:46 +0900 Subject: [PATCH 2/3] fix(torsion): a lazy wave in current starts at any pretwist on every BLAS kernel The start of the lazy wave restrained in torsion in an in-plane current depended on the pretwist and on the round-off of the BLAS kernel: - The static helper builds (coarse branch selection, auxiliary-weight seed, friction reference, no-current diagnosis) ran the torsion stage, and the twisted coarse state seeded the untwisted solve on the deck mesh. Pretwist 180 deg stopped in the attachment polish; 360 deg needed the polish's fallbacks and stopped with OPENBLAS_CORETYPE=Prescott. Helper builds now solve the untwisted line. - Each pass of the attachment fixed point after the first applied the drag of the last twisted shape in full at the untwisted start, which pushed the out-of-plane-unstable untwisted state away before any twist (270 deg and more). The load change is now ramped with the imposed twist (f_nodal_twist of CD_HermiteCable_Static_Solve). Pretwists 0 to 720 deg now start without fallbacks, with the same torques on the Haswell and Prescott kernels, proportional to the pretwist. torsion_current_start sweeps 0/180/360/720 deg and checks both. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 10 +++++- src/CableDyn_DeckDriver.f90 | 56 ++++++++++++++++++++--------- src/CableDyn_HermiteCableStatic.f90 | 41 ++++++++++++++++++++- tests/test_torsion_current_start.py | 34 +++++++++++++++--- 4 files changed, 118 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 389a799a..339d5a95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -472,7 +472,15 @@ All notable changes to CableDyn are recorded in this file. The format follows continuation stalled at Phi = 0 (target 0)" at pretwist 0, an unstable equilibrium after a failed Newton solve at 360 deg). A twisted state with no more negative modes than its untwisted one is now kept, and the note names the instability as the untwisted state's - (`torsion_current_start`). + (`torsion_current_start`). Its start also depended on the pretwist and on the round-off of the + BLAS kernel: the coarse branch-selection build of a line restrained in torsion twisted it, and + that twisted state seeded the untwisted solve on the deck mesh (pretwist 180 deg stopped in the + attachment polish, 360 deg needed the polish's fallbacks and stopped with + `OPENBLAS_CORETYPE=Prescott`); and each pass of the attachment fixed point after the first + applied the drag of the last twisted shape in full at the untwisted start (270 deg and more + stopped before any twist). The static helper builds now solve the untwisted line, and the + change of the attachment loads is ramped with the imposed twist: pretwists from 0 to 720 deg + start with the same torques on every kernel, proportional to the pretwist. - The "unresolved/kinked equilibrium" refusal names the element and the factor to refine its section's `NumSegs` by. - A rod numbered as a body no longer joins the body's attachment points. A `RodA/B` end point diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index 8f93c500..467f8277 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -1720,6 +1720,13 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, ! static load stage on the final mesh, then installed in the cable; a line restrained at one ! end only (ln%tors_free_end) has no static torque and installs its free end. LOGICAL :: tors_line + ! whether this build twists the line: not in a static helper build (standalone_controls + ! .FALSE.: the coarse branch selection, the auxiliary-weight seed, the friction reference and + ! the no-current diagnosis), whose callers take the untwisted equilibrium. A coarse state + ! twisted by the line's pretwist seeded the untwisted solve on the deck mesh, which then + ! depended on the pretwist (a lazy wave restrained in torsion in an in-plane current stopped + ! at 180 deg). + LOGICAL :: twist_here TYPE(CD_HermiteTorsionType) :: tors ! the residual tolerance the accepted torsion stage met (torsion_note) REAL(wp) :: tors_tol_used @@ -1899,6 +1906,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, ! torsional line is solved in 3D from the start; a line free in torsion at one end carries no ! static torque, so its statics are those of the line without torsion. tors_line = line_torsion_active(ln) + twist_here = tors_line + IF (PRESENT(standalone_controls)) twist_here = tors_line .AND. standalone_controls ! A current with a component across the vertical plane of the chord pushes the line out ! of that plane, which the dynamics (endpoints held, every other DOF free) follow: the ! static equilibrium is then solved in 3D as well. @@ -2928,7 +2937,7 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, END IF ! A line with ATTACHMENTS takes its torsion stage on the discrete equilibrium, after the ! attachment polish (torsion_after_attachments). - IF (tors_line .AND. .NOT. has_att) THEN + IF (twist_here .AND. .NOT. has_att) THEN CALL torsion_stage(es, em) IF (es /= CD_DECKDRV_OK) THEN ErrStat = es @@ -3086,7 +3095,7 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, IF (.NOT. tors_line) & CALL handoff_lateral_note(l0, l0, ea, ei, w_bare, w, diam, opts%rhoW*opts%g*QUARTER_PI*diam**2, & fixed_dofs, .TRUE.) - IF (tors_line) THEN + IF (twist_here) THEN CALL torsion_after_attachments(es, em) IF (es == CD_DECKDRV_OK) CALL twisted_attachment_checks(es, em) IF (es /= CD_DECKDRV_OK) THEN @@ -3154,13 +3163,13 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, CALL fail(ErrStat, ErrMsg, 'finite-EI cable end-connection wiring failed: '//TRIM(em)); RETURN END IF END IF - IF (tors_line .AND. ln%tors_free_end == 1) THEN + IF (twist_here .AND. ln%tors_free_end == 1) THEN ! a free End A: its torsion frame is a gauge, which no parent turns CALL CD_HFMF_Set_Torsion(cable, tors, es, em) IF (es /= CD_HFMF_OK) THEN CALL fail(ErrStat, ErrMsg, 'finite-EI cable torsion wiring failed: '//TRIM(em)); RETURN END IF - ELSE IF (tors_line) THEN + ELSE IF (twist_here) THEN ! The End A torsion frame (director -Ez, reference normal Nx, in the frame of Ez) is held ! by End A's parent and turns with it in the dynamics, whatever the bending connection; a ! moving End B's frame (director -Ez, normal Nx of End B) is held by End B's parent likewise. @@ -3316,7 +3325,7 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, END IF CONTAINS - SUBROUTINE torsion_stage(est, emt, f_nodal) + SUBROUTINE torsion_stage(est, emt, f_nodal, f_twist) !! The condensed-torsion load stage of a line restrained in torsion at both ends: from the !! converged untwisted state on the final mesh (l0_am), CD_HermiteCable_Static_Solve ramps !! the imposed twist Phi = Pretwist(End B) - Pretwist(End A) with the same loads, contact, @@ -3325,7 +3334,8 @@ SUBROUTINE torsion_stage(est, emt, f_nodal) !! is deck End B (global axes), end 2 deck End A (its parent's axes, turned with it). !! f_nodal: the stage of a line with ATTACHMENTS, after the attachment polish (the final !! mesh then is l0, with the bare weights w_bare and the deck mesh l0_deck_att), with the - !! attachments' lumped loads. + !! attachments' lumped loads; f_twist, with f_nodal, a change of those loads ramped with + !! the imposed twist (torsion_after_attachments). !! A line restrained at one end only (ln%tors_free_end) carries no static torque: the !! untwisted state is its static state, Theta is evaluated there, and the free end's frame !! is a gauge (end_free): the end's connection direction, or its static tangent at a @@ -3333,6 +3343,7 @@ SUBROUTINE torsion_stage(est, emt, f_nodal) INTEGER, INTENT(OUT) :: est CHARACTER(*), INTENT(OUT) :: emt REAL(wp), INTENT(IN), OPTIONAL :: f_nodal(:) + REAL(wp), INTENT(IN), OPTIONAL :: f_twist(:) REAL(wp) :: nvec(3), dvec(3), tol_t INTEGER :: k, attempt, kf LOGICAL :: nodal_loads @@ -3441,12 +3452,14 @@ SUBROUTINE torsion_stage(est, emt, f_nodal) CALL hermite_static_torsion(l0, l0, ea, ei, w_bare, diam, opts%rhoW*opts%g*QUARTER_PI*diam**2, & q_static, curv, fixed_dofs, contact_enabled, contact_z, frame_cs, & endconn_k, endconn_d0_local, endconn_mode, opts, tol_t, tors, est, emt, & - bathymetry=bathymetry, cur_obj=cur_obj, f_nodal=f_nodal) + bathymetry=bathymetry, cur_obj=cur_obj, f_nodal=f_nodal, & + f_nodal_twist=f_twist) ELSE CALL hermite_static_torsion(l0, l0, ea, ei, w_bare, diam, opts%rhoW*opts%g*QUARTER_PI*diam**2, & q_static, curv, fixed_dofs, contact_enabled, contact_z, frame_cs, & endconn_k, endconn_d0_local, endconn_mode, opts, tol_t, tors, est, emt, & - cur_obj=cur_obj, f_nodal=f_nodal) + cur_obj=cur_obj, f_nodal=f_nodal, & + f_nodal_twist=f_twist) END IF ELSE IF (PRESENT(bathymetry) .AND. .NOT. bathymetry_flat) THEN CALL hermite_static_torsion(l0, l0_am, ea_am, ei_am, w_am, diam, dry_b, q_static, curv, fixed_am, & @@ -3497,12 +3510,16 @@ SUBROUTINE torsion_after_attachments(est, emt) !! line tangent, and the weight on the side of the surface, so the stage is repeated, each !! time a fresh torsion solve from the last state, with the loads of the last solution until !! the solution stops moving and no attachment changes side (fixed point, as in - !! attachment_static_polish). + !! attachment_static_polish). Every pass starts from the polished state, in equilibrium + !! under the loads at that state: the change to the loads of the last solution is ramped + !! with the imposed twist, in full at the target. Taken in full from the untwisted start, the + !! drag of a twisted shape pushed a lazy wave whose untwisted state is unstable out of its + !! plane off that state before any twist (pretwist 270 deg and more in a 0.5 m/s current). INTEGER, INTENT(OUT) :: est CHARACTER(*), INTENT(OUT) :: emt INTEGER, PARAMETER :: MAX_FIXED_POINT = 60 REAL(wp), PARAMETER :: FIXED_POINT_TOL = 1.0e-9_wp ! m - REAL(wp), ALLOCATABLE :: f_att(:), f_drag(:), q_prev(:), q_polished(:) + REAL(wp), ALLOCATABLE :: f_att(:), f_drag(:), q_prev(:), q_polished(:), f_untwisted(:) LOGICAL, ALLOCATABLE :: att_dry(:), att_dry_now(:) LOGICAL :: has_drag INTEGER :: fp, k_cross @@ -3532,7 +3549,12 @@ SUBROUTINE torsion_after_attachments(est, emt) END IF q_prev = q_static q_static = q_polished - CALL torsion_stage(est, emt, f_att + f_drag) + IF (fp == 1) THEN + f_untwisted = f_att + f_drag + CALL torsion_stage(est, emt, f_untwisted) + ELSE + CALL torsion_stage(est, emt, f_untwisted, f_att + f_drag - f_untwisted) + END IF IF (est /= CD_DECKDRV_OK) THEN IF (k_cross > 0) emt = TRIM(cause)//'; '//TRIM(emt) RETURN @@ -4510,8 +4532,8 @@ SUBROUTINE attachment_fallback_checks() ! the out-of-plane DOFs held: the torsion stage that follows tests the twisted state in 3D and ! keeps only an instability its untwisted state has (a planar state unstable out of its plane, ! which the line free in torsion starts from with a note). Without it the lazy wave with 25 - ! modules restrained in torsion, Pretwist 360 deg, in an in-plane 0.5 m/s current, whose polish - ! needed its fallbacks, was refused for its out-of-plane mode before any twist. + ! modules restrained in torsion, Pretwist 360 deg, in an in-plane 0.5 m/s current, was refused + ! for its out-of-plane mode before any twist whenever its polish needed its fallbacks. fixed_f = fixed_dofs IF (tors_line .AND. ln%tors_free_end == 0 .AND. .NOT. require_3d_untwisted) THEN IF (.NOT. as_laid_cross_slope()) THEN @@ -6872,7 +6894,7 @@ END SUBROUTINE hermite_static_stable SUBROUTINE hermite_static_torsion(l0_deck, l0, ea, ei, w, diam_deck, dry_deck, q, curv, fixed_dofs, & contact_enabled, contact_z, frame_cs, endconn_k, endconn_d0, endconn_mode, opts, & - tol, tors, ErrStat, ErrMsg, bathymetry, cur_obj, f_nodal) + tol, tors, ErrStat, ErrMsg, bathymetry, cur_obj, f_nodal, f_nodal_twist) !! Torsion stage of a deck cable on its final mesh l0: CD_HermiteCable_Static_Solve from the !! converged untwisted state q (one EI and buoyancy stage, a polish) with the torsion !! description tors, under the same contact, dry-buoyancy, end-connection and current terms @@ -6892,6 +6914,8 @@ SUBROUTINE hermite_static_torsion(l0_deck, l0, ea, ei, w, diam_deck, dry_deck, q TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry TYPE(CD_HermiteStaticCurrentType), INTENT(IN), OPTIONAL :: cur_obj REAL(wp), INTENT(IN), OPTIONAL :: f_nodal(:) + ! with f_nodal: its change ramped with the imposed twist (CD_HermiteCable_Static_Solve) + REAL(wp), INTENT(IN), OPTIONAL :: f_nodal_twist(:) REAL(wp), ALLOCATABLE :: diam(:), dry(:), knnode(:), q_out(:) REAL(wp) :: res INTEGER :: i, ne, it, es @@ -6922,7 +6946,7 @@ SUBROUTINE hermite_static_torsion(l0_deck, l0, ea, ei, w, diam_deck, dry_deck, q endconn_stiffness=endconn_k, endconn_direction=endconn_d0, & endconn_mode=endconn_mode, waterline_z=CD_ZERO, dry_buoyancy=dry, & water_weight=opts%rhoW*opts%g, current=cur_obj, torsion=tors, & - f_nodal=f_nodal) + f_nodal=f_nodal, f_nodal_twist=f_nodal_twist) ELSE CALL CD_HermiteCable_Static_Solve(l0, ea, ei, w, q, fixed_dofs, contact_z, CD_ZERO, 1, 200, & tol, 0.7_wp, q_out, curv, res, it, es, em, n_buoy_steps=1, & @@ -6931,7 +6955,7 @@ SUBROUTINE hermite_static_torsion(l0_deck, l0, ea, ei, w, diam_deck, dry_deck, q endconn_stiffness=endconn_k, endconn_direction=endconn_d0, & endconn_mode=endconn_mode, waterline_z=CD_ZERO, dry_buoyancy=dry, & water_weight=opts%rhoW*opts%g, current=cur_obj, torsion=tors, & - f_nodal=f_nodal) + f_nodal=f_nodal, f_nodal_twist=f_nodal_twist) END IF IF (es == CD_HCSTAT_BADINPUT) THEN CALL fail(ErrStat, ErrMsg, 'finite-EI torsion static solve rejected the input: '//TRIM(em)); RETURN diff --git a/src/CableDyn_HermiteCableStatic.f90 b/src/CableDyn_HermiteCableStatic.f90 index d2ef016b..4aa6374b 100644 --- a/src/CableDyn_HermiteCableStatic.f90 +++ b/src/CableDyn_HermiteCableStatic.f90 @@ -302,7 +302,7 @@ SUBROUTINE CD_HermiteCable_Static_Solve(l0, EA, EI, w, seed, fixed_dofs, seabed_ waterline_z, dry_buoyancy, merit_line_search, pseudo_transient, & energy_minimization, stable, water_weight, current, residual_out, & tangent_out, friction, residual_unmet, torsion, energy_out, & - end_share_hold) + end_share_hold, f_nodal_twist) !! Solve the finite-EI static equilibrium of a Hermite bending-cable line. !! !! l0(ne), EA(ne), EI(ne), w(ne) : per-element rest length, axial/bending stiffness, @@ -436,6 +436,14 @@ SUBROUTINE CD_HermiteCable_Static_Solve(l0, EA, EI, w, seed, fixed_dofs, seabed_ !! resting on the seabed; the residual keeps the shares of !! each iterate (CD_Seabed_End_Element_Share). Omitted, an !! energy line search holds the shares of its start. + !! f_nodal_twist (optional, 6*nn) : with torsion, generalized nodal loads (as f_nodal) + !! ramped with the imposed twist: none at the untwisted + !! state, the fraction of the twist continuation at each + !! stage, in full at the target Phi. The change of a load + !! that follows the line's shape (the drag of discrete + !! attachments in a current, evaluated at a twisted state) + !! then leaves the untwisted state in equilibrium under + !! f_nodal alone. REAL(wp), INTENT(IN) :: l0(:), EA(:), EI(:), w(:), seed(:) INTEGER, INTENT(IN) :: fixed_dofs(:) REAL(wp), INTENT(IN) :: seabed_z, kn, tol, damping @@ -473,6 +481,7 @@ SUBROUTINE CD_HermiteCable_Static_Solve(l0, EA, EI, w, seed, fixed_dofs, seabed_ REAL(wp), INTENT(OUT), OPTIONAL :: energy_out REAL(wp), INTENT(IN), OPTIONAL :: end_share_hold(2) TYPE(CD_HermiteTorsionType), INTENT(INOUT), OPTIONAL :: torsion + REAL(wp), INTENT(IN), OPTIONAL :: f_nodal_twist(:) INTEGER :: ne, nn, ndof, c, it, es, i, b, nci, n_buoy, omp_threads, axial_order, bending_order REAL(wp) :: eifac, rnorm, fscale, bfac, rmerit, ptc_tau, ptc_rprev, pi_total, pi_abs, lm_mu, chord @@ -514,6 +523,8 @@ SUBROUTINE CD_HermiteCable_Static_Solve(l0, EA, EI, w, seed, fixed_dofs, seabed_ ! tors_v the lowest mode of an unstable tangent (descent direction). LOGICAL :: use_tors, tors_on, tors_have_mode, tors_descending REAL(wp) :: tors_c, tors_phi_cur, tors_theta_acc, tors_theta_eval, tors_mt, tors_lambda + ! the share of f_nodal_twist the residual takes: the twist continuation's fraction + REAL(wp) :: tors_load_frac REAL(wp), ALLOCATABLE :: tors_g(:), tors_gr(:), tors_h(:, :), tors_v(:), tors_rhs(:), tors_q(:), tors_gs(:) REAL(wp), ALLOCATABLE :: tors_grs(:), tors_gt(:) REAL(wp), ALLOCATABLE :: tors_rhs2(:, :) @@ -627,6 +638,17 @@ SUBROUTINE CD_HermiteCable_Static_Solve(l0, EA, EI, w, seed, fixed_dofs, seabed_ CALL fail('f_nodal must be finite'); RETURN END IF END IF + IF (PRESENT(f_nodal_twist)) THEN + IF (.NOT. PRESENT(torsion)) THEN + CALL fail('f_nodal_twist needs torsion'); RETURN + END IF + IF (SIZE(f_nodal_twist) /= ndof) THEN + CALL fail('f_nodal_twist must be 6*(ne+1)'); RETURN + END IF + IF (.NOT. CD_All_Finite(f_nodal_twist)) THEN + CALL fail('f_nodal_twist must be finite'); RETURN + END IF + END IF IF (use_nodal_contact) THEN IF (SIZE(contact_kn) /= nn .OR. .NOT. CD_All_Finite(contact_kn) .OR. ANY(contact_kn <= CD_ZERO)) THEN CALL fail('contact_kn must be finite, positive, and have length n_nodes'); RETURN @@ -739,6 +761,7 @@ SUBROUTINE CD_HermiteCable_Static_Solve(l0, EA, EI, w, seed, fixed_dofs, seabed_ tors_descending = .FALSE. tors_c = CD_ZERO tors_phi_cur = CD_ZERO + tors_load_frac = CD_ZERO tors_theta_acc = CD_ZERO tors_theta_eval = CD_ZERO tors_mt = CD_ZERO @@ -909,6 +932,12 @@ SUBROUTINE CD_HermiteCable_Static_Solve(l0, EA, EI, w, seed, fixed_dofs, seabed_ fscale = MAX(fscale, MAXVAL(ABS(f_nodal(6*(i - 1) + 4:6*(i - 1) + 6)))/trib(i)) END DO END IF + IF (PRESENT(f_nodal_twist)) THEN + DO i = 1, nn + fscale = MAX(fscale, MAXVAL(ABS(f_nodal_twist(6*(i - 1) + 1:6*(i - 1) + 3)))) + fscale = MAX(fscale, MAXVAL(ABS(f_nodal_twist(6*(i - 1) + 4:6*(i - 1) + 6)))/trib(i)) + END DO + END IF ! The tension a taut line must carry: with its ends farther apart than its length L, a line ! is stretched by at least chord/L - 1 over its series axial stiffness, so it carries at ! least that force whatever its weight. A line that carries little weight for its tension @@ -1274,6 +1303,14 @@ RECURSIVE SUBROUTINE newton_step(rnorm, es, em, do_update) pi_total = pi_total - e_term pi_abs = pi_abs + ABS(e_term) END IF + IF (PRESENT(f_nodal_twist)) THEN + IF (tors_load_frac > CD_ZERO) THEN + R = R - eifac*tors_load_frac*f_nodal_twist + e_term = eifac*tors_load_frac*DOT_PRODUCT(f_nodal_twist, q) + pi_total = pi_total - e_term + pi_abs = pi_abs + ABS(e_term) + END IF + END IF ! ---- optional rotational line-end connections ---- ! Ramped with the same factor as EI: a stiff connection introduced at full strength @@ -1934,8 +1971,10 @@ SUBROUTINE torsion_continuation(ecs, ecm) lam_try = MIN(CD_ONE, lam + dlam) IF (lam_try >= CD_ONE) THEN tors_phi_cur = torsion%phi + tors_load_frac = CD_ONE ELSE tors_phi_cur = phi0 + lam_try*total + tors_load_frac = lam_try END IF q_keep = q th_keep = tors_theta_acc diff --git a/tests/test_torsion_current_start.py b/tests/test_torsion_current_start.py index 0f047b25..e6984755 100644 --- a/tests/test_torsion_current_start.py +++ b/tests/test_torsion_current_start.py @@ -9,10 +9,17 @@ the same deck without torsion accepts with a note. The twist stage added no instability, yet the torsion stage refused it: at pretwist 0 "torsion continuation stalled at Phi = 0 (target 0): the twisted equilibrium is unstable", at 360 deg an unstable equilibrium after a failed Newton solve. +Two causes made the start depend on the pretwist and on the round-off of the BLAS kernel: the +coarse branch-selection build twisted its line, and that twisted state seeded the untwisted solve +on the deck mesh (180 deg stopped in the attachment polish; 360 deg needed its fallbacks, and +stopped under OPENBLAS_CORETYPE=Prescott); and every pass of the attachment fixed point after the +first applied the drag of the last twisted shape in full at the untwisted start (270 deg and more +stopped before any twist). -Gate, on the driver's own output: at pretwist 0 and 360 deg the deck starts and runs (it stopped -before), the torsion note reports the twist solved, and the instability is named as the untwisted -state's own. +Gate, on the driver's own output: at pretwist 0, 180, 360 and 720 deg the deck starts and runs, +the torsion note reports the twist solved, the instability is named as the untwisted state's own, +the attachment polish converges without its fallbacks, and the end torque is proportional to the +pretwist (to 1 % of the torque at 720 deg). usage: test_torsion_current_start.py --exe --data --output """ @@ -20,6 +27,7 @@ from __future__ import annotations import argparse +import re import subprocess import sys from pathlib import Path @@ -55,7 +63,8 @@ def main() -> int: encoding="utf-8" ) failures = [] - for pretwist in ("0", "360"): + torques = {} + for pretwist in ("0", "180", "360", "720"): deck = out / f"lw_current_twist{pretwist}.dat" deck.write_text(deck_text(base, pretwist), encoding="utf-8", newline="\n") if "uniform 0.5 0 0 current" not in deck.read_text(encoding="utf-8"): @@ -70,9 +79,16 @@ def main() -> int: log = p.stdout + p.stderr solved = "torsion solved" in log named = "keeps the instability of its untwisted state" in log + fell_back = "reached after a failed Newton solve" in log + m = re.search(r"torsion solved, imposed twist\s+\S+ deg, torque\s+(\S+) N m", log) + if m: + torques[pretwist] = float(m.group(1)) print( - f"pretwist {pretwist}: exit {p.returncode}, solved {solved}, untwisted instability named {named}" + f"pretwist {pretwist}: exit {p.returncode}, solved {solved}, untwisted instability named {named}, " + f"polish fallbacks {fell_back}, torque {torques.get(pretwist)}" ) + if fell_back: + failures.append(f"pretwist {pretwist}: the attachment polish needed its fallbacks") if p.returncode != 0: failures.append(f"pretwist {pretwist}: the deck stopped: {log[-400:]}") if not solved: @@ -85,6 +101,14 @@ def main() -> int: failures.append( f"pretwist {pretwist}: a stalled torsion continuation is reported" ) + if len(torques) == 4: + rate = torques["720"] / 720.0 + for pt, tq in torques.items(): + if abs(tq - rate * float(pt)) > 0.01 * abs(torques["720"]): + failures.append( + f"pretwist {pt}: torque {tq} N m not proportional to the pretwist " + f"({rate * float(pt)} N m from 720 deg)" + ) for f in failures: print("FAIL: " + f) if not failures: From 9d0971bf64afbc72a1d118f2ca4f5309a7d573e6 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Tue, 3 Nov 2026 15:40:23 +0900 Subject: [PATCH 3/3] test(torsion): run the four torsion_current_start decks concurrently The pretwist sweep runs four independent decks; one after another they took 322 s in a local Debug build and passed the 600 s test timeout on the CI Debug runners. They now run concurrently (158 s locally in Debug, 26 s in Release), and the timeout is 900 s, as for the other long driver tests. Signed-off-by: Jae Hoon Seo --- CMakeLists.txt | 2 +- tests/test_torsion_current_start.py | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c1b9cc6..9521cb50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1812,7 +1812,7 @@ if(Python3_Interpreter_FOUND) --output ${CMAKE_BINARY_DIR}/torsion_current_start) set_tests_properties(torsion_current_start PROPERTIES LABELS "python;driver;integration;static" - TIMEOUT 600 + TIMEOUT 900 ENVIRONMENT "${_cabledyn_python_test_environment}") add_test(NAME body_rod_numbering diff --git a/tests/test_torsion_current_start.py b/tests/test_torsion_current_start.py index e6984755..edcc1ce1 100644 --- a/tests/test_torsion_current_start.py +++ b/tests/test_torsion_current_start.py @@ -30,6 +30,7 @@ import re import subprocess import sys +from concurrent.futures import ThreadPoolExecutor from pathlib import Path @@ -64,18 +65,27 @@ def main() -> int: ) failures = [] torques = {} - for pretwist in ("0", "180", "360", "720"): + pretwists = ("0", "180", "360", "720") + for pretwist in pretwists: deck = out / f"lw_current_twist{pretwist}.dat" deck.write_text(deck_text(base, pretwist), encoding="utf-8", newline="\n") if "uniform 0.5 0 0 current" not in deck.read_text(encoding="utf-8"): - failures.append("the deck edit did not place the current") - continue - p = subprocess.run( - [args.exe, str(deck), str(out / f"lw_current_twist{pretwist}")], + print("FAIL: the deck edit did not place the current") + return 1 + + def run(pretwist: str) -> subprocess.CompletedProcess[str]: + return subprocess.run( + [args.exe, str(out / f"lw_current_twist{pretwist}.dat"), str(out / f"lw_current_twist{pretwist}")], capture_output=True, text=True, check=False, ) + + # the four runs are independent: concurrently, so a Debug build stays within the test's timeout + with ThreadPoolExecutor(max_workers=len(pretwists)) as pool: + runs = dict(zip(pretwists, pool.map(run, pretwists))) + for pretwist in pretwists: + p = runs[pretwist] log = p.stdout + p.stderr solved = "torsion solved" in log named = "keeps the instability of its untwisted state" in log