From a3d29a927828d1c11ba00897fd7e9732a35f03aa Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Fri, 16 Oct 2026 12:45:42 +0900 Subject: [PATCH 1/7] fix(statics): refine locally; robust attachment polish - A finite-EI static solve whose resolution check failed refined the whole line uniformly, up to 16x, even when one region was coarse: two decks went from 462 to 7392 elements and took 6-13 s. AutoMesh now refines locally (option local_refinement, on for every deck route): only the elements whose curvature resolution, bending length, boundary layer or contact change requires it are split into 2-16 equal children, graded so neighbours differ by at most a factor of two. The pass starts under exactly the old conditions, the caps and audits are unchanged. R6: 6.6 s / 7392 elements -> 0.30 s / 492 (end tensions within 3.5e-7, nodes 0.7 mm); the statics matrix refining decks 76 -> 31 s CPU, results within 0.21 % of peak end tension of the uniform refinement. Decks that do not refine are byte-identical. - The attachment polish of a lazy wave with 25 discrete buoyancy modules on a refined mesh in a 0.3 m/s cross current failed at load fraction 0.125 (seabed friction: the first Newton update raised the residual 300-fold). A failed step is now retried from the last converged state with pseudo-transient continuation, the merit line search and halved load steps down to 1/1024; the case solves within 0.04 % (fairlead) / 0.2 % (anchor) of its smeared twin. Decks whose steps converge take the unchanged path. Tests: attachment_cross_current (four discrete-module decks against smeared twins), local-mode AutoMesh cases. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 40 ++++ CMakeLists.txt | 13 ++ doc/theory.rst | 34 ++- doc/troubleshooting.rst | 15 ++ src/CableDyn_DeckDriver.f90 | 224 ++++++++++++------ src/CableDyn_HermiteCableStatic.f90 | 312 +++++++++++++++++++++++-- tests/test_attachment_cross_current.py | 113 +++++++++ tests/test_deck_hermite_cable.f90 | 29 ++- tests/test_hermite_automesh.f90 | 196 ++++++++++++++++ 9 files changed, 872 insertions(+), 104 deletions(-) create mode 100644 tests/test_attachment_cross_current.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d3639aa..b3f711a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -675,6 +675,46 @@ All notable changes to CableDyn are recorded in this file. The format follows `clump_weight_free_point.dat`, whose clump now rests 4.7 cm deep instead of 6.6 cm and whose anchor tension falls from 186 kN to 92 kN; decks whose points stay clear of the seabed give identical output. See the manual's theory page (Seabed contact). +- A finite-EI deck mesh that cannot resolve the curvature of its static equilibrium (an + element folded beyond `L0*kappa = 0.7`), and a fragile mesh under `adaptive_mesh True`, are + now refined locally instead of as a whole. The static solve had multiplied every element by + the power of two that the worst one needed, up to 16, even when only one section was coarse: + a 462-element lazy wave whose 180 m top section had two elements was solved on 7392 elements + in 6.6 s, and a 410-element lazy wave with a rigid horizontal hang-off on 6560 elements in + 6.0 s. A refinement pass now splits into 2, 4, 8 or 16 equal elements only the elements whose + `L0*kappa` exceeds 0.12 (or the stricter `adaptive_mesh` target), that are longer than half + their bending length `(EI/|w|)^(1/3)`, or, at a line end, longer than the boundary layer + `sqrt(EI/T)`, and the elements about an isolated seabed-contact change, and grades the mesh + into the neighbouring elements (no element more than twice as long as the next, unless the + deck mesh has a larger ratio there). The cap of 16 per deck element, the element limit, the + acceptance checks and the fail-closed messages are unchanged. The two decks above now solve + on 492 and 436 elements in 0.30 s and 0.27 s, with end tensions within 4e-7 and 2e-6 of the + whole-line refinement and nodes within 0.7 mm and 4 mm. In the finite-EI statics matrix 61 + of the 123 decks refine: their CPU time falls from 76 s to 34 s, the end tensions change by + at most 0.21 % of the line's peak end tension (a 58 m line on 2 m end elements, whose + hang-off tension moves from 1157.5 N to 1155.1 N; 1157.5 N on a mesh 16 times finer) and the + nodes by at most 6.4e-4 of the line length. In a 761-deck statics robustness campaign 57 + decks refine: they solve in 18 s instead of 63 s, with the same outcomes and notes (two no + longer need the static residual floor note), end tensions within 1e-5 of the peak end tension and nodes within 3.2e-5 of the line length. + Decks that do not refine, including every shipped example, give identical output. On a + deck that refines, the dynamics run on the new mesh, and node output channels (`LN`) + name its nodes. +- A finite-EI line with discrete buoyancy modules (`ATTACHMENTS`) in a cross current on a + frictional seabed no longer fails its static solve. The lazy wave of + `tests/data/lazy_wave_touchdown_planar_refined_att.dat` (25 modules on 2 m elements) in a + 0.3 m/s current across its plane stopped with `finite-EI static solve with discrete + ATTACHMENTS failed at load fraction 0.125 (relative residual 1.304E+02)`. The homotopy from + the smeared to the lumped modules adds the module drag, which the smeared equilibrium does + not carry, and on the frictional seabed the damped Newton update for it overshot and + diverged from the first step, even in steps of 1/64 of the load; the seed and the step size + were not the cause. A step whose damped Newton solve does not converge is now repeated from + the last converged state with pseudo-transient continuation and then with a residual-merit + line search, and halved (down to 1/1024) when neither converges. The deck now solves in + 1.8 s, its fairlead and anchor tensions within 0.04 % and 0.2 % of the deck with the + equivalent smeared buoyancy section; in 0.6 m/s, and on the coarse mesh, it solved before + and its results are unchanged. A polish whose Newton steps all converge takes the same + solves as before, so every other deck is unchanged. A new test (`attachment_cross_current`) + checks the four cases against their smeared twins. - The development environment (`environment.yml`) excludes OpenBLAS 0.3.34, which caused the access violation in the modal analysis tests listed under Known issues for 0.1.1. On AMD Zen 4 and Zen 5 CPUs that expose AVX-512, OpenBLAS 0.3.34 enlarges the GEMM blocking, diff --git a/CMakeLists.txt b/CMakeLists.txt index e86a8a0b..e602d2ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1458,6 +1458,19 @@ if(Python3_Interpreter_FOUND) TIMEOUT 600 ENVIRONMENT "${_cabledyn_python_test_environment}") + # Discrete buoyancy modules on a lazy wave in a cross current (the attachment polish falls + # back from diverging Newton steps on the frictional seabed): the static solve converges and + # its end tensions match the equivalent smeared section. + add_test(NAME attachment_cross_current + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_attachment_cross_current.py + --exe $ + --data ${CMAKE_CURRENT_SOURCE_DIR}/tests/data + --output ${CMAKE_BINARY_DIR}/attachment_cross_current) + set_tests_properties(attachment_cross_current PROPERTIES + LABELS "python;hermite;static;robustness;attachments" + TIMEOUT 600 + ENVIRONMENT "${_cabledyn_python_test_environment}") + # Finite-EI generalised-alpha blends: force-blend dtM convergence under prescribed surge. add_test(NAME hermite_force_blend_dt COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_hermite_force_blend_dt.py diff --git a/doc/theory.rst b/doc/theory.rst index a75319ba..f0b3d49b 100644 --- a/doc/theory.rst +++ b/doc/theory.rst @@ -1276,9 +1276,26 @@ mesh-sequenced route described below first and this route as its fallback): does not converge is restarted at full ``EI``. 3. **Polish and diagnosis** on the deck mesh at the static tolerance. A residual floor above it is accepted at :math:`10^{-6}` (or, for a line on the seabed, :math:`10^{-5}`, nodes - alternating across the 1 µm contact blend) and reported. A deck mesh too coarse for the - bending length (continuation or polish failing, or an element folded beyond - :math:`L_0\kappa = 0.7`) repeats the route on a mesh refined until the elements are at most + alternating across the 1 µm contact blend) and reported. An element folded beyond + :math:`L_0\kappa = 0.7` on the deck mesh is refined locally, from the polished state, until + no element exceeds :math:`L_0\kappa = 0.35`; ``adaptive_mesh`` refines the same way, to its + own target. A refinement pass splits into :math:`2^k` equal elements every element whose + sampled :math:`L_0\kappa` exceeds 0.12 (or the requested target, when stricter), that is + longer than half its bending length :math:`(EI/|w|)^{1/3}`, or, at a line end, longer than + its boundary layer :math:`\sqrt{EI/T}`, and the elements about a node whose seabed contact + differs from both neighbours; :math:`k` is the smallest that meets the criterion, at most 4 + (16 elements per deck element). The neighbours are then split until no element is more than + twice as long as the next one (or than the ratio the deck mesh already has there) and none + is left longer than both of its neighbours with fewer splits than either (a single coarser + element between finer ones carries a spurious axial oscillation), the state is carried to + the new mesh by the Hermite interpolant of each element and polished, and the pass is + repeated on the polished state while the target is not met and an element can still be + split, within 8192 elements. Elements the criteria leave alone keep their deck length, so + a single coarse section costs only its own refinement (a 462-element lazy + wave whose 180 m top section has two elements: 492 elements, where refining the whole line + by the factor of its worst element gave 7392). A deck mesh too coarse for the bending length + whose continuation or polish fails, or whose folded element the local refinement does not + resolve, repeats the route on a mesh refined until the elements are at most half the bending length (when the continuation on that mesh runs out of its iteration budget, on the coarser powers of two down to twice the deck mesh); a rotationally restrained end whose boundary layer :math:`\sqrt{EI/T}` is shorter than its element, which @@ -2311,7 +2328,16 @@ the nodal tangent :math:`\mathbf{m}_j/\lvert\mathbf{m}_j\rvert` (the line's Mori and, through :math:`\mathbf{m}_j`, the position tangent exactly. The statics start from the equilibrium with the net weight smeared over the node's two elements and continue to the lumped load in warm-started Newton solves; in a deck current the drag at rest is added and the final -solve is repeated with the drag of its own solution until the nodes stop moving. As the pitch :math:`p` of identical modules shrinks, the discrete equilibrium +solve is repeated with the drag of its own solution until the nodes stop moving. The load moves +in eighths; a step whose damped Newton solve does not converge is repeated from the last +converged state with pseudo-transient continuation and then with a residual-merit line search, +and is halved (down to 1/1024) when neither converges. The smeared state carries no +attachment drag, and on a frictional seabed, whose regularised friction force turns from its +sticking stiffness to its sliding capacity over a short slip, the Newton update for a +cross-flow drag can overshoot and diverge from the first step (a lazy wave with 25 modules in a +0.3 m/s cross current on 2 m elements, even in steps of 1/64), which the pseudo-transient +regularisation avoids. +As the pitch :math:`p` of identical modules shrinks, the discrete equilibrium converges to the smeared section at :math:`O(p^2)`. **Line failure.** A ``FAILURE`` row detaches a line end from its point at a prescribed time or diff --git a/doc/troubleshooting.rst b/doc/troubleshooting.rst index 587f693f..32fdc397 100644 --- a/doc/troubleshooting.rst +++ b/doc/troubleshooting.rst @@ -576,6 +576,13 @@ but a few geometries are genuinely hard: the mesh-sequenced state is prolongated and polished there. If the message names that refined mesh as well (``still unstable on the refined mesh``), the instability is physical: check the layout, the line length and the buoyancy. +- **Discrete buoyancy modules.** ``finite-EI static solve with discrete ATTACHMENTS failed at + load fraction ...`` means the homotopy from the smeared modules to the lumped ones (see + *Discrete attachments* in :doc:`theory`) did not reach the discrete equilibrium: the damped + Newton solve of a load step did not converge, nor did its pseudo-transient and line-search + repetitions, down to steps of 1/1024 of the module loads. The message names the load fraction + of the first failed solve. Check that the deck with the modules replaced by the equivalent + smeared buoyancy section solves; if it does, the discrete layout itself is the difficulty. - **A cold start at full load.** The static solve continues the load in stages; if you have hand-tuned a case into a bad basin, remove the tuning and let the default continuation run from the catenary/arch seed. @@ -754,6 +761,14 @@ Warnings and notes that do not stop a run :math:`(EI/|w|)^{1/3}` (see :doc:`modeling`, step 5). The run uses the refined mesh, statics and dynamics alike, and its outputs have that many segments. Mesh the touchdown and section changes to that rule to keep the deck mesh. + * - ``Note: line ...: the deck mesh (... elements) could not resolve the curvature of the + equilibrium; refined to ... elements`` + - an element of the deck mesh folded beyond :math:`L_0\kappa = 0.7` (a bend shorter than the + element). The static solve refined the mesh locally where the bend is, and where elements + are longer than half the bending length, at most 16-fold per deck element and graded into + the neighbouring elements (see :doc:`theory`, Static equilibrium); the run uses that mesh, + statics and dynamics alike, and its outputs have that many segments. Mesh the reported + section finer to keep the deck mesh. * - ``Note: line ... starts the dynamics from a static state solved in its vertical plane that is unstable out of that plane on its mesh of ... elements, the coarsest ... m long where half the bending length (EI/|w|)^(1/3) is ... m; ...`` diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index 9a71baeb..0d3aab0c 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -2094,8 +2094,9 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, ! n_cont = 8 load steps and damping = 0.7. When the deck opts in to ! adaptive_mesh AND CD_HermiteCable_Resolution_Metrics flags the mesh FRAGILE (an ! under-resolved arch/touchdown that would stall the coupled dynamic Newton), AutoMesh - ! refines by WARM-STARTED cubic-Hermite prolongation of the converged IC - ! (CD_HermiteCable_Refine_Mesh) up to CD_HC_REFINE_CAP. Prolongation -- not a + ! refines by WARM-STARTED cubic-Hermite prolongation of the converged IC, element by + ! element where the resolution screens fail (local_refinement), up to CD_HC_REFINE_CAP + ! bisection factor per deck element. Prolongation -- not a ! cold re-solve at the finer mesh -- is essential: a cold fine solve kinks (mesh-sequencing is ! the documented practice). inherit_dofs [2,5] carries the planar out-of-plane hold (y ! position + y tangent) onto inserted nodes. max_scale = 1 (adaptive_mesh off, the DEFAULT) @@ -2319,7 +2320,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, & waterline_z=CD_ZERO, dry_buoyancy=dry_b, & - water_weight=opts%rhoW*opts%g, current=cur_obj) + water_weight=opts%rhoW*opts%g, current=cur_obj, & + local_refinement=.TRUE.) ELSE IF (contact_enabled) THEN CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, ea, ei, w, q_sequence, fixed_dofs, & contact_z, CD_ZERO, 8, 80, static_tol, 0.7_wp, & @@ -2340,7 +2342,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, & waterline_z=CD_ZERO, dry_buoyancy=dry_b, & - water_weight=opts%rhoW*opts%g, current=cur_obj) + water_weight=opts%rhoW*opts%g, current=cur_obj, & + local_refinement=.TRUE.) ELSE CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, ea, ei, w, q_sequence, fixed_dofs, & contact_z, CD_ZERO, 8, 80, static_tol, 0.7_wp, & @@ -2360,7 +2363,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, & waterline_z=CD_ZERO, dry_buoyancy=dry_b, & - water_weight=opts%rhoW*opts%g, current=cur_obj) + water_weight=opts%rhoW*opts%g, current=cur_obj, & + local_refinement=.TRUE.) END IF iters = sequence_total + adaptive_iters ELSE @@ -2389,7 +2393,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, & waterline_z=CD_ZERO, dry_buoyancy=dry_b, & - water_weight=opts%rhoW*opts%g, current=cur_obj) + water_weight=opts%rhoW*opts%g, current=cur_obj, & + local_refinement=.TRUE.) ELSE IF (contact_enabled) THEN CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, ea, ei, w, q0, fixed_dofs, contact_z, CD_ZERO, & 8, 80, static_tol, 0.7_wp, CD_HC_HKAPPA_TARGET, CD_ZERO, & @@ -2409,7 +2414,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, & waterline_z=CD_ZERO, dry_buoyancy=dry_b, & - water_weight=opts%rhoW*opts%g, current=cur_obj) + water_weight=opts%rhoW*opts%g, current=cur_obj, & + local_refinement=.TRUE.) ELSE CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, ea, ei, w, q0, fixed_dofs, -2000.0_wp, CD_ZERO, & 8, 80, static_tol, 0.7_wp, CD_HC_HKAPPA_TARGET, CD_ZERO, & @@ -2427,7 +2433,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, & waterline_z=CD_ZERO, dry_buoyancy=dry_b, & - water_weight=opts%rhoW*opts%g, current=cur_obj) + water_weight=opts%rhoW*opts%g, current=cur_obj, & + local_refinement=.TRUE.) END IF IF (es == CD_HCSTAT_OK .OR. es == CD_HCSTAT_BADINPUT) EXIT static_attempt IF (static_tol >= COUPLED_STATIC_TOL) EXIT static_attempt @@ -2469,7 +2476,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, & waterline_z=CD_ZERO, dry_buoyancy=dry_b, & - water_weight=opts%rhoW*opts%g, current=cur_obj) + water_weight=opts%rhoW*opts%g, current=cur_obj, & + local_refinement=.TRUE.) ELSE IF (contact_enabled) THEN CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, ea, ei, w, q_coupled_tol, fixed_dofs, & contact_z, CD_ZERO, 8, 80, static_tol_target, 0.7_wp, & @@ -2488,7 +2496,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, & waterline_z=CD_ZERO, dry_buoyancy=dry_b, & - water_weight=opts%rhoW*opts%g, current=cur_obj) + water_weight=opts%rhoW*opts%g, current=cur_obj, & + local_refinement=.TRUE.) ELSE CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, ea, ei, w, q_coupled_tol, fixed_dofs, & -2000.0_wp, CD_ZERO, 8, 80, static_tol_target, 0.7_wp, & @@ -2506,7 +2515,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, & waterline_z=CD_ZERO, dry_buoyancy=dry_b, & - water_weight=opts%rhoW*opts%g, current=cur_obj) + water_weight=opts%rhoW*opts%g, current=cur_obj, & + local_refinement=.TRUE.) END IF iters = iters + polish_iters END IF @@ -3337,7 +3347,8 @@ SUBROUTINE sequenced_refined_polish(done, why) refine_non_axial=opts%adaptive_mesh, & endconn_stiffness=endconn_k, endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, waterline_z=CD_ZERO, & - dry_buoyancy=dry_r, water_weight=opts%rhoW*opts%g, current=cur_obj) + dry_buoyancy=dry_r, water_weight=opts%rhoW*opts%g, & + current=cur_obj, local_refinement=.TRUE.) ELSE IF (contact_enabled) THEN CALL CD_HermiteCable_Static_Solve_AutoMesh(l0_r, ea_r, ei_r, w_r, q_r, fixed_r, contact_z, CD_ZERO, & 8, 80, tol_r(k_tol), 0.7_wp, CD_HC_HKAPPA_TARGET, CD_ZERO, & @@ -3353,7 +3364,8 @@ SUBROUTINE sequenced_refined_polish(done, why) refine_non_axial=opts%adaptive_mesh, & endconn_stiffness=endconn_k, endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, waterline_z=CD_ZERO, & - dry_buoyancy=dry_r, water_weight=opts%rhoW*opts%g, current=cur_obj) + dry_buoyancy=dry_r, water_weight=opts%rhoW*opts%g, & + current=cur_obj, local_refinement=.TRUE.) ELSE CALL CD_HermiteCable_Static_Solve_AutoMesh(l0_r, ea_r, ei_r, w_r, q_r, fixed_r, contact_z, CD_ZERO, & 8, 80, tol_r(k_tol), 0.7_wp, CD_HC_HKAPPA_TARGET, CD_ZERO, & @@ -3368,7 +3380,8 @@ SUBROUTINE sequenced_refined_polish(done, why) refine_non_axial=opts%adaptive_mesh, & endconn_stiffness=endconn_k, endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, waterline_z=CD_ZERO, & - dry_buoyancy=dry_r, water_weight=opts%rhoW*opts%g, current=cur_obj) + dry_buoyancy=dry_r, water_weight=opts%rhoW*opts%g, & + current=cur_obj, local_refinement=.TRUE.) END IF iters = iters + it_r IF (es_r == CD_HCSTAT_OK) THEN @@ -3601,7 +3614,8 @@ SUBROUTINE symmetric_current_polish(done) endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, waterline_z=CD_ZERO, & dry_buoyancy=dry_s, water_weight=opts%rhoW*opts%g, & - current=cur_obj) + current=cur_obj, & + local_refinement=.TRUE.) ELSE CALL CD_HermiteCable_Static_Solve_AutoMesh(l0_s, ea_s, ei_s, w_s, q_s, fixed_s, -2000.0_wp, CD_ZERO, & 8, 80, tol_s(k_tol), 0.7_wp, h_t, & @@ -3616,7 +3630,8 @@ SUBROUTINE symmetric_current_polish(done) endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, waterline_z=CD_ZERO, & dry_buoyancy=dry_s, water_weight=opts%rhoW*opts%g, & - current=cur_obj) + current=cur_obj, & + local_refinement=.TRUE.) END IF iters = iters + it_s IF (es_s == CD_HCSTAT_OK) THEN @@ -3922,7 +3937,8 @@ SUBROUTINE coarse_current_first(done, fail_msg) endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, waterline_z=CD_ZERO, & dry_buoyancy=dry_b, water_weight=opts%rhoW*opts%g, & - current=cur_obj) + current=cur_obj, & + local_refinement=.TRUE.) ELSE CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, ea, ei, w, q_p, fixed_3d, -2000.0_wp, CD_ZERO, & 8, 80, tol_c(k_tol), 0.7_wp, h_t, & @@ -3939,7 +3955,8 @@ SUBROUTINE coarse_current_first(done, fail_msg) endconn_direction=endconn_d0_local, & endconn_mode=endconn_mode, waterline_z=CD_ZERO, & dry_buoyancy=dry_b, water_weight=opts%rhoW*opts%g, & - current=cur_obj) + current=cur_obj, & + local_refinement=.TRUE.) END IF iters = iters + it_c IF (esc == CD_HCSTAT_OK) THEN @@ -4340,13 +4357,25 @@ END SUBROUTINE smear_attachments SUBROUTINE attachment_static_polish(l0, ea, ei, w_bare, w_smear, diam, node, att, q, fixed_dofs, & contact_enabled, contact_z, frame_cs, endconn_k, endconn_d0, endconn_mode, & opts, tol, ErrStat, ErrMsg, bathymetry, cur_obj) - !! Homotopy from the smeared-attachment equilibrium q to the discrete one: in NSTEP - !! warm-started Newton solves the element weights move from w_smear to w_bare while the - !! lumped nodal forces -(m - rho V) g e_z and, in a deck current, the attachment current - !! drag grow from zero to full, with the contact, dry-buoyancy, end-connection and line - !! current terms of the builder's static problem. The drag depends on the node's depth - !! (profile current) and line tangent, so the full-load solve is repeated with the drag - !! of the last solution until the solution stops moving (fixed point). + !! Homotopy from the smeared-attachment equilibrium q to the discrete one: in warm-started + !! Newton solves the element weights move from w_smear to w_bare while the lumped nodal + !! forces -(m - rho V) g e_z and, in a deck current, the attachment current drag grow from + !! zero to full, with the contact, dry-buoyancy, end-connection and line current terms of + !! the builder's static problem. The drag depends on the node's depth (profile current) + !! and line tangent, so the full-load solve is repeated with the drag of the last solution + !! until the solution stops moving (fixed point). + !! + !! The load fraction advances in steps of 1/NSTEP. A step whose damped Newton solve does + !! not converge is repeated from the last converged state with pseudo-transient + !! continuation and then with a residual-merit line search; when neither converges, the + !! step is halved (down to MIN_STEP), and it grows back to 1/NSTEP after converged steps. + !! The smeared state carries no attachment drag, and on a frictional seabed, whose + !! regularised friction force turns from its sticking stiffness to its sliding capacity + !! over a short slip, the Newton update for a cross-flow drag can overshoot far from the + !! equilibrium and diverge (even in load steps of 1/64), which the pseudo-transient + !! regularisation avoids. Once a damped Newton solve has failed, the + !! later ones get NEWTON_RETRY_ITER iterations before the fallbacks take over. A polish + !! whose damped Newton solves all converge takes exactly the solves it took before. REAL(wp), INTENT(IN) :: l0(:), ea(:), ei(:), w_bare(:), w_smear(:), diam(:), att(:, :) INTEGER, INTENT(IN) :: node(:), fixed_dofs(:), endconn_mode(2) REAL(wp), INTENT(INOUT) :: q(:) @@ -4358,13 +4387,21 @@ SUBROUTINE attachment_static_polish(l0, ea, ei, w_bare, w_smear, diam, node, att TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry TYPE(CD_HermiteStaticCurrentType), INTENT(IN), OPTIONAL :: cur_obj INTEGER, PARAMETER :: NSTEP = 8, MAX_FIXED_POINT = 60 + ! Smallest load-fraction step: 1/NSTEP halved seven times. Newton budget once a damped + ! Newton solve of this polish has failed (a converging one takes well under it). + REAL(wp), PARAMETER :: MIN_STEP = 1.0_wp/1024.0_wp + INTEGER, PARAMETER :: NEWTON_RETRY_ITER = 40 REAL(wp), PARAMETER :: FIXED_POINT_TOL = 1.0e-9_wp ! m REAL(wp), ALLOCATABLE :: f_att(:), f_drag(:), dry(:), knnode(:), wl(:), q_out(:), curv(:) - REAL(wp) :: lam, res, change - INTEGER :: i, k, ne, step, fp - LOGICAL :: has_drag + REAL(wp) :: lam, lam_done, dlam, res, change + INTEGER :: i, k, ne, fp + LOGICAL :: has_drag, converged, newton_failed + CHARACTER(1024) :: fail_msg + CHARACTER(48) :: step_buf ErrStat = CD_DECKDRV_OK; ErrMsg = '' + fail_msg = '' + newton_failed = .FALSE. ne = SIZE(l0) ALLOCATE (f_att(6*(ne + 1)), f_drag(6*(ne + 1)), dry(ne), q_out(SIZE(q)), curv(ne + 1)) f_att = CD_ZERO @@ -4381,29 +4418,54 @@ SUBROUTINE attachment_static_polish(l0, ea, ei, w_bare, w_smear, diam, node, att knnode(i + 1) = knnode(i + 1) + 0.5_wp*opts%kbot*diam(i)*l0(i) END DO END IF - DO step = 1, NSTEP - lam = REAL(step, wp)/REAL(NSTEP, wp) + lam_done = CD_ZERO + dlam = CD_ONE/REAL(NSTEP, wp) + DO WHILE (lam_done < CD_ONE) + lam = MIN(CD_ONE, lam_done + dlam) wl = w_bare + (CD_ONE - lam)*(w_smear - w_bare) - CALL solve_with(lam) + CALL solve_with(lam, converged) IF (ErrStat /= CD_DECKDRV_OK) RETURN + IF (converged) THEN + lam_done = lam + dlam = MIN(2.0_wp*dlam, CD_ONE/REAL(NSTEP, wp)) + ELSE + dlam = 0.5_wp*dlam + IF (dlam < MIN_STEP) THEN + WRITE (step_buf, '(ES9.2)') MIN_STEP + CALL fail_solve(ErrStat, ErrMsg, TRIM(fail_msg)//'; load-fraction steps down to '// & + TRIM(ADJUSTL(step_buf))//' did not converge either') + RETURN + END IF + END IF END DO IF (.NOT. has_drag) RETURN DO fp = 1, MAX_FIXED_POINT - CALL solve_with(CD_ONE, change) + CALL solve_with(CD_ONE, converged, change) IF (ErrStat /= CD_DECKDRV_OK) RETURN + IF (.NOT. converged) THEN + CALL fail_solve(ErrStat, ErrMsg, TRIM(fail_msg)//' (attachment current drag fixed point)'); RETURN + END IF IF (change <= FIXED_POINT_TOL) RETURN END DO CALL fail_solve(ErrStat, ErrMsg, 'finite-EI static solve with discrete ATTACHMENTS: the attachment '// & 'current drag did not settle to a fixed point') CONTAINS - SUBROUTINE solve_with(scale, dq_max) - !! One warm-started Newton solve at load fraction scale, with the attachment current - !! drag evaluated on the incoming state; dq_max is the resulting largest DOF change. + SUBROUTINE solve_with(scale, ok, dq_max) + !! One warm-started solve at load fraction scale, with the attachment current drag + !! evaluated on the incoming state: the damped Newton iteration and, when it does not + !! converge, the pseudo-transient continuation and the residual-merit line search, each + !! from the incoming state. ok reports convergence; q is updated only then, and dq_max + !! is the resulting largest DOF change. Otherwise fail_msg names the load fraction and + !! the damped Newton failure. A failed drag evaluation or a rejected input sets ErrStat. REAL(wp), INTENT(IN) :: scale + LOGICAL, INTENT(OUT) :: ok REAL(wp), INTENT(OUT), OPTIONAL :: dq_max - INTEGER :: it, es + INTEGER, PARAMETER :: NEWTON = 1, PSEUDO_TRANSIENT = 2, MERIT = 3 + INTEGER :: it, es, mode, max_it(3) CHARACTER(1024) :: em CHARACTER(48) :: num_buf + ok = .FALSE. + max_it = [MERGE(NEWTON_RETRY_ITER, 200, newton_failed), 200, 200] f_drag = CD_ZERO IF (has_drag) THEN CALL attachment_static_drag(q, node, att, opts, frame_cs, f_drag, es, em) @@ -4411,35 +4473,49 @@ SUBROUTINE solve_with(scale, dq_max) CALL fail_solve(ErrStat, ErrMsg, 'finite-EI static attachment drag failed: '//TRIM(em)); RETURN END IF END IF - IF (contact_enabled) THEN - CALL CD_HermiteCable_Static_Solve(l0, ea, ei, wl, q, fixed_dofs, contact_z, CD_ZERO, 1, 200, & - tol, 0.7_wp, q_out, curv, res, it, es, em, & - f_nodal=scale*(f_att + f_drag), n_buoy_steps=1, contact_kn=knnode, & - bathymetry=bathymetry, contact_frame_cs=frame_cs, & - axial_quadrature_order=opts%axial_quadrature_order, & - bending_quadrature_order=opts%bending_quadrature_order, & - 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) - ELSE - CALL CD_HermiteCable_Static_Solve(l0, ea, ei, wl, q, fixed_dofs, contact_z, CD_ZERO, 1, 200, & - tol, 0.7_wp, q_out, curv, res, it, es, em, & - f_nodal=scale*(f_att + f_drag), n_buoy_steps=1, & - axial_quadrature_order=opts%axial_quadrature_order, & - bending_quadrature_order=opts%bending_quadrature_order, & - 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) - END IF - IF (es /= CD_HCSTAT_OK .OR. .NOT. (res <= tol)) THEN - ! numbers into a local buffer: an internal WRITE into the caller's ErrMsg would abort - ! on a short buffer - WRITE (num_buf, '(F5.3,A,ES10.3)') scale, ' (relative residual ', res - ErrMsg = 'CableDyn_DeckDriver: finite-EI static solve with discrete ATTACHMENTS failed at load '// & - 'fraction '//TRIM(num_buf)//'): '//TRIM(em) - ErrStat = CD_DECKDRV_SOLVEFAIL - RETURN - END IF + DO mode = NEWTON, MERIT + IF (contact_enabled) THEN + CALL CD_HermiteCable_Static_Solve(l0, ea, ei, wl, q, fixed_dofs, contact_z, CD_ZERO, 1, max_it(mode), & + tol, 0.7_wp, q_out, curv, res, it, es, em, & + f_nodal=scale*(f_att + f_drag), n_buoy_steps=1, contact_kn=knnode, & + bathymetry=bathymetry, contact_frame_cs=frame_cs, & + axial_quadrature_order=opts%axial_quadrature_order, & + bending_quadrature_order=opts%bending_quadrature_order, & + 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, & + backtracking=mode == MERIT, merit_line_search=mode == MERIT, & + pseudo_transient=mode == PSEUDO_TRANSIENT) + ELSE + CALL CD_HermiteCable_Static_Solve(l0, ea, ei, wl, q, fixed_dofs, contact_z, CD_ZERO, 1, max_it(mode), & + tol, 0.7_wp, q_out, curv, res, it, es, em, & + f_nodal=scale*(f_att + f_drag), n_buoy_steps=1, & + axial_quadrature_order=opts%axial_quadrature_order, & + bending_quadrature_order=opts%bending_quadrature_order, & + 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, & + backtracking=mode == MERIT, merit_line_search=mode == MERIT, & + pseudo_transient=mode == PSEUDO_TRANSIENT) + END IF + IF (es == CD_HCSTAT_OK .AND. res <= tol) THEN + ok = .TRUE. + EXIT + END IF + IF (mode == NEWTON) THEN + ! numbers into a local buffer: an internal WRITE into the caller's ErrMsg would abort + ! on a short buffer + WRITE (num_buf, '(F5.3,A,ES10.3)') scale, ' (relative residual ', res + fail_msg = 'finite-EI static solve with discrete ATTACHMENTS failed at load '// & + 'fraction '//TRIM(num_buf)//'): '//TRIM(em) + newton_failed = .TRUE. + END IF + ! A rejected input is rejected by every update rule. + IF (es == CD_HCSTAT_BADINPUT) THEN + CALL fail_solve(ErrStat, ErrMsg, TRIM(fail_msg)); RETURN + END IF + END DO + IF (.NOT. ok) RETURN IF (PRESENT(dq_max)) dq_max = MAXVAL(ABS(q_out - q)) q = q_out END SUBROUTINE solve_with @@ -4975,7 +5051,7 @@ RECURSIVE SUBROUTINE hermite_static_primary(anchor, fairlead, l0, ea, ei, w, dia END IF END IF - ! 3. caller-mesh polish, diagnosis and opt-in refinement (adaptive_mesh: uniform + ! 3. caller-mesh polish, diagnosis and opt-in refinement (adaptive_mesh: local ! refinement of a fragile resolution screen). A coarse mesh whose axial resultant ! oscillates is kept and reported by the audit. With tensile_safety True ! compression beyond the tighter of the strain band and the tension-relative band is @@ -4987,9 +5063,10 @@ RECURSIVE SUBROUTINE hermite_static_primary(anchor, fairlead, l0, ea, ei, w, dia refine_all = opts%adaptive_mesh CALL polish_with_floor() ! Safety-driven refinement: an element-localized fold on the deck mesh means the - ! mesh cannot represent the bends of this equilibrium. Refine globally (power of two, - ! capped) until max(h*kappa) is half the kink limit, whatever adaptive_mesh says; the - ! alternative is no result at all. The caller reports the refined mesh. + ! mesh cannot represent the bends of this equilibrium. Refine locally (power-of-two + ! splits of the elements that fail the resolution screens, graded into their + ! neighbours, capped) until max(h*kappa) is half the kink limit, whatever adaptive_mesh + ! says; the alternative is no result at all. The caller reports the refined mesh. IF (ErrStat == CD_HCSTAT_NOCONVERGE .AND. INDEX(ErrMsg, 'unresolved/kinked') > 0) THEN h_target = 0.5_wp*CD_HC_KINK_LIMIT @@ -5626,7 +5703,8 @@ SUBROUTINE polish(tol_polish) refine_non_axial=refine_all, & endconn_stiffness=endconn_k, endconn_direction=endconn_d0, & endconn_mode=endconn_mode, waterline_z=CD_ZERO, dry_buoyancy=dry_b, & - water_weight=opts%rhoW*opts%g, current=cur_obj) + water_weight=opts%rhoW*opts%g, current=cur_obj, & + local_refinement=.TRUE.) ELSE IF (contact_enabled) THEN CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, ea, ei, w, q_cont, fixed_dofs, contact_z, CD_ZERO, & 8, 200, tol_polish, 0.7_wp, h_target, CD_ZERO, & @@ -5644,7 +5722,8 @@ SUBROUTINE polish(tol_polish) refine_non_axial=refine_all, & endconn_stiffness=endconn_k, endconn_direction=endconn_d0, & endconn_mode=endconn_mode, waterline_z=CD_ZERO, dry_buoyancy=dry_b, & - water_weight=opts%rhoW*opts%g, current=cur_obj) + water_weight=opts%rhoW*opts%g, current=cur_obj, & + local_refinement=.TRUE.) ELSE CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, ea, ei, w, q_cont, fixed_dofs, contact_z, CD_ZERO, & 8, 200, tol_polish, 0.7_wp, h_target, CD_ZERO, & @@ -5660,7 +5739,8 @@ SUBROUTINE polish(tol_polish) refine_non_axial=refine_all, & endconn_stiffness=endconn_k, endconn_direction=endconn_d0, & endconn_mode=endconn_mode, waterline_z=CD_ZERO, dry_buoyancy=dry_b, & - water_weight=opts%rhoW*opts%g, current=cur_obj) + water_weight=opts%rhoW*opts%g, current=cur_obj, & + local_refinement=.TRUE.) END IF iters = iters + polish_iters END SUBROUTINE polish diff --git a/src/CableDyn_HermiteCableStatic.f90 b/src/CableDyn_HermiteCableStatic.f90 index 88829029..f81c099f 100644 --- a/src/CableDyn_HermiteCableStatic.f90 +++ b/src/CableDyn_HermiteCableStatic.f90 @@ -5104,7 +5104,8 @@ END SUBROUTINE reject_unresolved_sequence 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) + bathymetry, contact_frame_cs, EA, EI, compression_mode, & + elem_h_kappa, chatter_node) !! Diagnose the mesh resolution of a converged finite-EI static IC and recommend a global !! refinement factor. This is the preflight trigger for the adaptive mesh policy: a lazy-wave !! arch or touchdown transition resolved with too few elements carries a large h*kappa and @@ -5126,6 +5127,10 @@ SUBROUTINE CD_HermiteCable_Resolution_Metrics(l0, q, seabed_z, contact_band, & !! element force tolerance of diag%axial_compression (see the constants). !! STRICT judges the three-element mean of the element-mean axial force !! (smoothed_element_means) instead of the pointwise resultant. + !! elem_h_kappa(ne) (optional out): l0(e) * peak |kappa| of every element, the field whose + !! maximum is h_kappa_peak (the local refinement of AutoMesh marks from it). + !! chatter_node(ne+1) (optional out): every interior node whose contact state differs from + !! both of its neighbours (the nodes behind diag%contact_chatter). REAL(wp), INTENT(IN) :: l0(:), q(:), seabed_z, contact_band, h_kappa_target TYPE(CD_HermiteResolutionType), INTENT(OUT) :: diag INTEGER, INTENT(OUT) :: ErrStat @@ -5134,6 +5139,8 @@ SUBROUTINE CD_HermiteCable_Resolution_Metrics(l0, q, seabed_z, contact_band, & REAL(wp), INTENT(IN), OPTIONAL :: contact_frame_cs(2) REAL(wp), INTENT(IN), OPTIONAL :: EA(:), EI(:) INTEGER, INTENT(IN), OPTIONAL :: compression_mode + REAL(wp), INTENT(OUT), OPTIONAL :: elem_h_kappa(:) + LOGICAL, INTENT(OUT), OPTIONAL :: chatter_node(:) INTEGER :: ne, nn, e, a, es3, mode REAL(wp) :: qe(12), ke, ke_prev, hk, u_peak, z, z_floor, xg, yg, contact_cs(2), & @@ -5166,6 +5173,20 @@ SUBROUTINE CD_HermiteCable_Resolution_Metrics(l0, q, seabed_z, contact_band, & ErrStat = CD_HCSTAT_BADINPUT ErrMsg = 'CD_HermiteCable_Resolution_Metrics: q must be 6*(ne+1)'; RETURN END IF + IF (PRESENT(elem_h_kappa)) THEN + IF (SIZE(elem_h_kappa) /= ne) THEN + ErrStat = CD_HCSTAT_BADINPUT + ErrMsg = 'CD_HermiteCable_Resolution_Metrics: elem_h_kappa must have length ne'; RETURN + END IF + elem_h_kappa = CD_ZERO + END IF + IF (PRESENT(chatter_node)) THEN + IF (SIZE(chatter_node) /= nn) THEN + ErrStat = CD_HCSTAT_BADINPUT + ErrMsg = 'CD_HermiteCable_Resolution_Metrics: chatter_node must have length ne+1'; RETURN + END IF + chatter_node = .FALSE. + END IF IF (PRESENT(EA)) THEN IF (SIZE(EA) /= ne .OR. .NOT. CD_All_Finite(EA) .OR. ANY(EA < CD_ZERO)) THEN ErrStat = CD_HCSTAT_BADINPUT @@ -5248,6 +5269,7 @@ SUBROUTINE CD_HermiteCable_Resolution_Metrics(l0, q, seabed_z, contact_band, & END IF diag%kappa_peak = MAX(diag%kappa_peak, ke) hk = l0(e)*ke + IF (PRESENT(elem_h_kappa)) elem_h_kappa(e) = hk IF (hk > diag%h_kappa_peak) THEN diag%h_kappa_peak = hk diag%h_kappa_elem = e @@ -5399,6 +5421,12 @@ SUBROUTINE CD_HermiteCable_Resolution_Metrics(l0, q, seabed_z, contact_band, & EXIT END IF END DO + IF (PRESENT(chatter_node)) THEN + DO a = 2, nn - 1 + chatter_node(a) = (contact_node(a) .NEQV. contact_node(a - 1)) .AND. & + (contact_node(a) .NEQV. contact_node(a + 1)) + END DO + END IF ! Recommended global refinement: the smallest power-of-two factor that brings h_kappa_peak ! at or below the target, capped so a pathological IC cannot ask for an unbounded mesh. @@ -6129,7 +6157,7 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs require_tensile, refine_non_axial, endconn_stiffness, & endconn_direction, endconn_mode, waterline_z, dry_buoyancy, & compression_mode, energy_polish_in, tensile_advisory, water_weight, & - current) + current, local_refinement) !! Solve the finite-EI static equilibrium and AUTOMATICALLY select the minimum safe mesh: the !! metric-gated mesh-economics entry. Solve at the caller's (coarse) mesh; if !! CD_HermiteCable_Resolution_Metrics flags it fragile, refine by the recommended power-of-two @@ -6166,6 +6194,21 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs !! energy_polish_in (optional, default false): polish the initial state and every !! prolongated refinement with the trust-region energy minimization of !! CD_HermiteCable_Static_Solve instead of the damped Newton update. + !! local_refinement (optional, default false): refine for the curvature, end boundary-layer + !! and contact-topology screens element by element instead of globally. A + !! pass runs when the same screens fail as for the global refinement; it + !! splits into the power-of-two number of equal children that meets its + !! criterion every element whose h*kappa exceeds min(h_kappa_target, + !! CD_HC_HKAPPA_TARGET), every element longer than half its bending length + !! (EI/|w|)^(1/3), each end element for its boundary-layer ratio, and the + !! elements about an isolated contact or gap node once (local_resolution_mesh); + !! the neighbours are then split until the mesh is graded (grade). Every + !! element keeps the cumulative cap max_scale relative to its caller element, + !! the mesh keeps the element limit of the global refinement, and the split + !! elements are cubic-Hermite prolongated exactly as there. The pass repeats + !! on the re-solved state while a screen fails and an element can still be + !! split. applied_scale then reports the largest factor of any element. The + !! axial (tensile) refinement is local in either mode and unchanged. REAL(wp), INTENT(IN) :: l0(:), EA(:), EI(:), w(:), seed(:) INTEGER, INTENT(IN) :: fixed_dofs(:) REAL(wp), INTENT(IN) :: seabed_z, kn, tol, damping, h_kappa_target, contact_band @@ -6187,11 +6230,20 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs REAL(wp), INTENT(IN), OPTIONAL :: waterline_z, dry_buoyancy(:), water_weight TYPE(CD_HermiteStaticCurrentType), INTENT(IN), OPTIONAL :: current INTEGER, INTENT(IN), OPTIONAL :: compression_mode - LOGICAL, INTENT(IN), OPTIONAL :: energy_polish_in, tensile_advisory + LOGICAL, INTENT(IN), OPTIONAL :: energy_polish_in, tensile_advisory, local_refinement INTEGER :: ne, nn, it, scale, parent, j, es, axial_order, bending_order, local_passes, cmode LOGICAL :: energy_polish, advisory INTEGER, PARAMETER :: MAX_LOCAL_AXIAL_PASSES = 16 + ! Local resolution refinement (local_refinement): passes, the per-element level cap + ! (log2 of max_scale), every element's number of bisections from its caller element, + ! and the per-element h*kappa and isolated contact/gap nodes of the last diagnosis. + INTEGER, PARAMETER :: MAX_LOCAL_RESOLUTION_PASSES = 12 + LOGICAL :: local_mode, nothing_to_split + INTEGER :: kcap, local_res_passes + INTEGER, ALLOCATABLE :: level_out(:), level_r(:) + REAL(wp), ALLOCATABLE :: elem_hk(:) + LOGICAL, ALLOCATABLE :: chatter_nodes(:) REAL(wp), ALLOCATABLE :: l0r(:), qr(:), EAr(:), EIr(:), wr(:), qnew(:), curvnew(:) REAL(wp), ALLOCATABLE :: contact_diam_out(:), contact_diam_r(:) ! Current-mesh dry buoyancy; unallocated (an absent optional) without a free surface. @@ -6246,6 +6298,9 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs max_axial_stall_passes = MERGE(4, 2, cmode == CD_HC_COMPRESSION_STRICT) energy_polish = .FALSE. IF (PRESENT(energy_polish_in)) energy_polish = energy_polish_in + local_mode = .FALSE. + IF (PRESENT(local_refinement)) local_mode = local_refinement + local_res_passes = 0 IF (max_scale < 1) THEN ErrStat = CD_HCSTAT_BADINPUT; ErrMsg = 'CD_HermiteCable_Static_Solve_AutoMesh: max_scale >= 1 required'; RETURN @@ -6281,6 +6336,12 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs ErrStat = CD_HCSTAT_BADINPUT ErrMsg = 'CD_HermiteCable_Static_Solve_AutoMesh: l0/EA/EI/w/seed sizes inconsistent'; RETURN END IF + kcap = 0 + DO WHILE (2_I8**(kcap + 1) <= INT(max_scale, I8)) + kcap = kcap + 1 + END DO + ALLOCATE (level_out(ne)) + level_out = 0 axial_budget = MAX(max_scale, CD_HC_REFINE_CAP) IF (axial_budget > HUGE(axial_budget)/ne) THEN axial_budget = HUGE(axial_budget) @@ -6324,15 +6385,7 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs END IF ! Diagnose; refine and re-solve while fragile and under the cap. - IF (PRESENT(bathymetry)) THEN - CALL CD_HermiteCable_Resolution_Metrics(l0_out, q_out, seabed_z, contact_band, h_kappa_target, & - diag_out, es, ErrMsg, bathymetry=bathymetry, & - contact_frame_cs=contact_cs, EA=EA_out, EI=EI_out, & - compression_mode=cmode) - ELSE - CALL CD_HermiteCable_Resolution_Metrics(l0_out, q_out, seabed_z, contact_band, h_kappa_target, & - diag_out, es, ErrMsg, EA=EA_out, EI=EI_out, compression_mode=cmode) - END IF + CALL diagnose(es) IF (es /= CD_HCSTAT_OK) THEN ErrStat = es; RETURN END IF @@ -6346,8 +6399,12 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs (diag_out%axial_strain_min_elem == SIZE(l0_out) .AND. & diag_out%axial_strain_min_xi >= CD_ONE - 1.0e-6_wp)) end_res_prev = diag_out%axial_strain_min_resultant + ! A local resolution pass runs while an element can still be split (local_resolution_mesh + ! says when none can); the global and axial passes keep their cumulative-factor bound. DO WHILE (needs_refinement .AND. & - (applied_scale < max_scale .OR. (local_axial .AND. local_passes < MAX_LOCAL_AXIAL_PASSES))) + (applied_scale < max_scale .OR. (local_axial .AND. local_passes < MAX_LOCAL_AXIAL_PASSES) .OR. & + (local_mode .AND. .NOT. local_axial .AND. kcap > 0 .AND. & + local_res_passes < MAX_LOCAL_RESOLUTION_PASSES))) ! A signed axial oscillation is local, usually at a section interface or the ! touchdown transition. Split every offending element and its immediate ! neighbours rather than multiplying the whole installed line. Curvature or @@ -6370,6 +6427,18 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs END IF END IF scale = 2 + IF (es == CD_HCSTAT_OK) THEN + ALLOCATE (level_r(SIZE(l0r))) + DO j = 1, SIZE(l0r) + level_r(j) = level_out(parent_map(j)) + MERGE(1, 0, axial_marks(parent_map(j))) + END DO + END IF + ELSE IF (local_mode) THEN + ! Split the elements whose screen fails, graded into their neighbours. + local_res_passes = local_res_passes + 1 + CALL local_resolution_mesh(nothing_to_split, es, emloc) + IF (es == CD_HCSTAT_OK .AND. nothing_to_split) EXIT + scale = 2 ELSE ! Mesh-scale contact chatter can report rec_scale = 1 (a topology signal), so ! force at least one doubling; never exceed the cumulative cap. @@ -6381,9 +6450,10 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs CALL CD_HermiteCable_Refine_Mesh(l0_out, q_out, fixed_out, scale, l0r, qr, fixedr, es, emloc, & inherit_dofs=inherit_dofs) IF (es == CD_HCSTAT_OK) THEN - ALLOCATE (parent_map(SIZE(l0r))) + ALLOCATE (parent_map(SIZE(l0r)), level_r(SIZE(l0r))) DO j = 1, SIZE(l0r) parent_map(j) = (j - 1)/scale + 1 + level_r(j) = level_out(parent_map(j)) + NINT(LOG(REAL(scale, wp))/LOG(2.0_wp)) END DO END IF END IF @@ -6453,21 +6523,17 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs CALL MOVE_ALLOC(qnew, q_out) CALL MOVE_ALLOC(curvnew, curv_out) DEALLOCATE (qr) + CALL MOVE_ALLOC(level_r, level_out) IF (local_axial) THEN applied_scale = MIN(max_scale, applied_scale*scale) + ELSE IF (local_mode) THEN + ! The largest factor of any element (its level is at most kcap here). + applied_scale = MAX(applied_scale, MIN(max_scale, 2**MIN(MAXVAL(level_out), 30))) ELSE applied_scale = applied_scale*scale END IF - IF (PRESENT(bathymetry)) THEN - CALL CD_HermiteCable_Resolution_Metrics(l0_out, q_out, seabed_z, contact_band, h_kappa_target, & - diag_out, es, ErrMsg, bathymetry=bathymetry, & - contact_frame_cs=contact_cs, EA=EA_out, EI=EI_out, & - compression_mode=cmode) - ELSE - CALL CD_HermiteCable_Resolution_Metrics(l0_out, q_out, seabed_z, contact_band, h_kappa_target, & - diag_out, es, ErrMsg, EA=EA_out, EI=EI_out, compression_mode=cmode) - END IF + CALL diagnose(es) IF (es /= CD_HCSTAT_OK) THEN ErrStat = es; RETURN END IF @@ -6634,11 +6700,211 @@ LOGICAL FUNCTION refinable(dg) !! topology, and for an unresolved end boundary layer only while the remaining !! refinement cap can still bring h/sqrt(EI/T) to its target. TYPE(CD_HermiteResolutionType), INTENT(IN) :: dg + IF (local_mode) THEN + ! As below, with the factor still open to the end element of the larger ratio (on + ! the caller mesh exactly the global test, so the same meshes refine). + refinable = dg%h_kappa_peak > h_kappa_target .OR. dg%contact_chatter .OR. & + (dg%boundary_unresolved .AND. & + dg%boundary_ratio_peak <= CD_HC_BOUNDARY_TARGET*REAL(max_scale, wp)/ & + 2.0_wp**MERGE(level_out(1), level_out(SIZE(level_out)), & + dg%hop_boundary_ratio >= dg%end_boundary_ratio)) + RETURN + END IF refinable = dg%h_kappa_peak > h_kappa_target .OR. dg%contact_chatter .OR. & (dg%boundary_unresolved .AND. & dg%boundary_ratio_peak <= CD_HC_BOUNDARY_TARGET*REAL(max_scale, wp)/REAL(applied_scale, wp)) END FUNCTION refinable + INTEGER FUNCTION end_layer_levels(ratio, level) RESULT(k) + !! Bisections of an end element (at level bisections from its caller element) that bring + !! its boundary-layer ratio h/sqrt(EI/T) to CD_HC_BOUNDARY_TARGET, within the cap; zero + !! when the ratio is met. A layer the cap cannot reach is an accuracy limit (reported by + !! diag%boundary_unresolved) that does not by itself start a pass (refinable), but a + !! pass that runs refines it as far as the cap allows -- as the global factor rec_scale + !! does. + REAL(wp), INTENT(IN) :: ratio + INTEGER, INTENT(IN) :: level + k = 0 + IF (.NOT. (ratio > CD_HC_BOUNDARY_TARGET*(CD_ONE + 1.0e-10_wp))) RETURN + DO WHILE (ratio > CD_HC_BOUNDARY_TARGET*2.0_wp**k*(CD_ONE + 1.0e-10_wp) .AND. level + k < kcap) + k = k + 1 + END DO + END FUNCTION end_layer_levels + + SUBROUTINE diagnose(esx) + !! Resolution diagnosis of the current mesh and state (diag_out); in local mode also the + !! per-element h*kappa and the isolated contact/gap nodes the local refinement marks from. + INTEGER, INTENT(OUT) :: esx + IF (local_mode) THEN + IF (ALLOCATED(elem_hk)) DEALLOCATE (elem_hk, chatter_nodes) + ALLOCATE (elem_hk(SIZE(l0_out)), chatter_nodes(SIZE(l0_out) + 1)) + IF (PRESENT(bathymetry)) THEN + CALL CD_HermiteCable_Resolution_Metrics(l0_out, q_out, seabed_z, contact_band, h_kappa_target, & + diag_out, esx, ErrMsg, bathymetry=bathymetry, & + contact_frame_cs=contact_cs, EA=EA_out, EI=EI_out, & + compression_mode=cmode, elem_h_kappa=elem_hk, & + chatter_node=chatter_nodes) + ELSE + CALL CD_HermiteCable_Resolution_Metrics(l0_out, q_out, seabed_z, contact_band, h_kappa_target, & + diag_out, esx, ErrMsg, EA=EA_out, EI=EI_out, & + compression_mode=cmode, elem_h_kappa=elem_hk, & + chatter_node=chatter_nodes) + END IF + ELSE IF (PRESENT(bathymetry)) THEN + CALL CD_HermiteCable_Resolution_Metrics(l0_out, q_out, seabed_z, contact_band, h_kappa_target, & + diag_out, esx, ErrMsg, bathymetry=bathymetry, & + contact_frame_cs=contact_cs, EA=EA_out, EI=EI_out, & + compression_mode=cmode) + ELSE + CALL CD_HermiteCable_Resolution_Metrics(l0_out, q_out, seabed_z, contact_band, h_kappa_target, & + diag_out, esx, ErrMsg, EA=EA_out, EI=EI_out, compression_mode=cmode) + END IF + END SUBROUTINE diagnose + + SUBROUTINE local_resolution_mesh(none, esx, emx) + !! The locally refined mesh of a local resolution pass, in l0r/qr/fixedr with parent_map + !! (the current element each new one lies in) and level_r. Levels needed per element: + !! h*kappa -- the smallest k with h*kappa / 2^k <= min(h_kappa_target, + !! CD_HC_HKAPPA_TARGET). A pass runs only while the caller's target fails, + !! but it refines every element to the accuracy target (a looser caller + !! target, such as the safety-driven half kink limit, would leave the bends + !! of a locally refined line at a much coarser resolution than the global + !! factor, which refines every element by the factor of the worst one); + !! bending -- the smallest k with h / 2^k <= half the bending length (EI/|w|)^(1/3), + !! the element-length rule of the finite-EI meshing guide: an element longer + !! than that cannot follow a bend (a grounded run over an uneven bed, a + !! touchdown) whose curvature it therefore does not show, and on such a mesh + !! a planar state can read as unstable out of its plane; + !! end layer -- end_layer_levels of each end element (as far as the cap allows); + !! contact -- one level on the two elements at an isolated contact or gap node and + !! one more on each side; + !! each limited to kcap bisections from the caller element. The levels are then graded: + !! an element is split further while it is longer than max(2, its length ratio to the + !! neighbour before the pass) times that neighbour's new length. A pass that would exceed + !! the element limit AUTO_MAX_ELEMENTS takes one level less everywhere, as the global + !! refinement halves its factor. none is set when no element can be split. + LOGICAL, INTENT(OUT) :: none + INTEGER, INTENT(OUT) :: esx + CHARACTER(*), INTENT(OUT) :: emx + INTEGER, ALLOCATABLE :: base(:), need(:), need_n(:), lev_c(:), lev_n(:), par_c(:), par_n(:) + INTEGER, ALLOCATABLE :: fix_c(:), fix_n(:) + REAL(wp), ALLOCATABLE :: l0_c(:), q_c(:), l0_n(:), q_n(:) + LOGICAL, ALLOCATABLE :: split(:) + INTEGER :: nec, e, a, k, red + INTEGER(I8) :: n_new + REAL(wp) :: hk_local, half_bend + none = .TRUE. + esx = CD_HCSTAT_OK + emx = '' + nec = SIZE(l0_out) + ALLOCATE (base(nec), need(nec)) + hk_local = MIN(h_kappa_target, CD_HC_HKAPPA_TARGET) + base = 0 + DO e = 1, nec + IF (.NOT. (elem_hk(e) > hk_local)) CYCLE + k = 0 + DO WHILE (elem_hk(e) > hk_local*2.0_wp**k .AND. level_out(e) + k < kcap) + k = k + 1 + END DO + base(e) = MAX(base(e), k) + END DO + DO e = 1, nec + IF (.NOT. (EI_out(e) > CD_ZERO .AND. ABS(w_out(e)) > CD_ZERO)) CYCLE + half_bend = 0.5_wp*(EI_out(e)/ABS(w_out(e)))**(CD_ONE/3.0_wp) + k = 0 + DO WHILE (l0_out(e) > half_bend*2.0_wp**k*(CD_ONE + 1.0e-12_wp) .AND. level_out(e) + k < kcap) + k = k + 1 + END DO + base(e) = MAX(base(e), k) + END DO + base(1) = MAX(base(1), end_layer_levels(diag_out%hop_boundary_ratio, level_out(1))) + base(nec) = MAX(base(nec), end_layer_levels(diag_out%end_boundary_ratio, level_out(nec))) + DO a = 2, nec + IF (.NOT. chatter_nodes(a)) CYCLE + DO e = MAX(1, a - 2), MIN(nec, a + 1) + IF (level_out(e) < kcap) base(e) = MAX(base(e), 1) + END DO + END DO + IF (ALL(base == 0)) RETURN + DO red = 0, MAXVAL(base) + need = MAX(base - red, 0) + CALL grade(need) + n_new = SUM(2_I8**need) + IF (n_new <= INT(AUTO_MAX_ELEMENTS, I8)) EXIT + END DO + IF (n_new > INT(AUTO_MAX_ELEMENTS, I8) .OR. ALL(need == 0)) RETURN + none = .FALSE. + + ! Bisect level by level: the children of a split cubic-Hermite element carry the same + ! cubic, so k bisections are the 2^k-fold uniform prolongation of the element. + l0_c = l0_out + q_c = q_out + fix_c = fixed_out + lev_c = level_out + ALLOCATE (par_c(nec)) + par_c = [(e, e=1, nec)] + DO WHILE (ANY(need > 0)) + split = need > 0 + CALL refine_marked_elements(l0_c, q_c, fix_c, split, l0_n, q_n, fix_n, par_n, esx, emx, inherit_dofs) + IF (esx /= CD_HCSTAT_OK) RETURN + ALLOCATE (need_n(SIZE(l0_n)), lev_n(SIZE(l0_n))) + DO e = 1, SIZE(l0_n) + need_n(e) = need(par_n(e)) - MERGE(1, 0, split(par_n(e))) + lev_n(e) = lev_c(par_n(e)) + MERGE(1, 0, split(par_n(e))) + par_n(e) = par_c(par_n(e)) + END DO + CALL MOVE_ALLOC(l0_n, l0_c) + CALL MOVE_ALLOC(q_n, q_c) + CALL MOVE_ALLOC(fix_n, fix_c) + CALL MOVE_ALLOC(par_n, par_c) + CALL MOVE_ALLOC(need_n, need) + CALL MOVE_ALLOC(lev_n, lev_c) + END DO + CALL MOVE_ALLOC(l0_c, l0r) + CALL MOVE_ALLOC(q_c, qr) + CALL MOVE_ALLOC(fix_c, fixedr) + CALL MOVE_ALLOC(par_c, parent_map) + CALL MOVE_ALLOC(lev_c, level_r) + END SUBROUTINE local_resolution_mesh + + SUBROUTINE grade(need) + !! Raise need until no element of the refined mesh is longer than max(2, its length + !! ratio to the neighbour on the current mesh) times that neighbour's refined length, + !! within the per-element cap, and no element left longer than both of its neighbours + !! is split fewer times (from its caller element) than both: such an element is split + !! until it is no longer than the longer neighbour or as often as the less split one. + !! (A single coarser element between finer ones carries a spurious axial oscillation + !! and can read as a compressed stretch.) + INTEGER, INTENT(INOUT) :: need(:) + LOGICAL :: changed + INTEGER :: e, side, f, g, lm + REAL(wp) :: allow, lnb + changed = .TRUE. + DO WHILE (changed) + changed = .FALSE. + DO e = 2, SIZE(need) - 1 + lm = MIN(level_out(e - 1) + need(e - 1), level_out(e + 1) + need(e + 1), kcap) + lnb = MAX(l0_out(e - 1)/2.0_wp**need(e - 1), l0_out(e + 1)/2.0_wp**need(e + 1)) + DO WHILE (l0_out(e)/2.0_wp**need(e) > lnb*(CD_ONE + 1.0e-12_wp) .AND. level_out(e) + need(e) < lm) + need(e) = need(e) + 1 + changed = .TRUE. + END DO + END DO + DO e = 1, SIZE(need) - 1 + DO side = 0, 1 + f = e + side + g = e + 1 - side + allow = MAX(2.0_wp, l0_out(f)/l0_out(g))*(CD_ONE + 1.0e-12_wp) + DO WHILE (l0_out(f)/2.0_wp**need(f) > allow*l0_out(g)/2.0_wp**need(g) .AND. & + level_out(f) + need(f) < kcap) + need(f) = need(f) + 1 + changed = .TRUE. + END DO + END DO + END DO + END DO + END SUBROUTINE grade + SUBROUTINE solve_level(l0x, EAx, EIx, wx, seedx, fixedx, diamx, dryx, qx, curvx, resx, itx, esx, emx, polish) REAL(wp), INTENT(IN) :: l0x(:), EAx(:), EIx(:), wx(:), seedx(:) INTEGER, INTENT(IN) :: fixedx(:) diff --git a/tests/test_attachment_cross_current.py b/tests/test_attachment_cross_current.py new file mode 100644 index 00000000..188ebf98 --- /dev/null +++ b/tests/test_attachment_cross_current.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +"""Discrete buoyancy modules on a lazy wave in a cross current, against the smeared section. + +The lazy-wave power cable of ``tests/data/lazy_wave_touchdown_planar_{refined,coarse}_att.dat`` +(25 discrete buoyancy modules at a 4 m pitch, rigid end connections, seabed friction 0.35) is +put in a uniform current across its vertical plane. The static solve reaches the discrete +equilibrium from the smeared one by a homotopy in the module loads and drag; on the refined +mesh in 0.3 m/s its damped Newton steps diverge on the frictional seabed, and the polish must +fall back to its regularised solves rather than fail. + +Every deck must solve (exit 0), and its line-end tensions must agree with the deck that +replaces the modules by the equivalent smeared section (the same submerged weight, displaced +volume and normal drag per metre over the stretch the modules cover): FairTen within 1 % and +AnchTen within 2 % of the smeared values. + +usage: test_attachment_cross_current.py --exe --data --output +""" + +from __future__ import annotations + +import argparse +import math +import re +import subprocess +import sys +from pathlib import Path + +# 25 modules at a 4 m pitch from 80 m to 176 m: the smeared stretch runs from 78 m to 178 m. +MODULES, PITCH, M_MOD, V_MOD, CDA_MOD = 25, 4.0, 91.32, 0.18378, 1.392 +BARE_D, BARE_M, BARE_CDN, BARE_CDT = 0.16, 36.70, 1.2, 0.1 +FAIR_TOL, ANCH_TOL = 0.01, 0.02 +CASES = [("refined", 0.3), ("refined", 0.6), ("coarse", 0.3), ("coarse", 0.6)] + + +def with_current(text: str, speed: float) -> str: + """The deck in a uniform current of the given speed across its plane, with AnchTen output.""" + text = re.sub(r"^(0\.0 TMax)$", r"\1\nuniform 0.0 %g 0.0 current" % speed, text, count=1, flags=re.M) + return re.sub(r"^FairTen4$", "FairTen4\nAnchTen4", text, count=1, flags=re.M) + + +def smeared(text: str) -> str: + """The deck with the modules replaced by the equivalent smeared section over 78-178 m.""" + span = MODULES * PITCH + area = math.pi / 4.0 * BARE_D**2 + MODULES * V_MOD / span + d_eq = math.sqrt(4.0 * area / math.pi) + m_eq = BARE_M + MODULES * M_MOD / span + cdn = (BARE_CDN * BARE_D + MODULES * CDA_MOD / span) / d_eq + cdt = BARE_CDT * BARE_D / d_eq + text = re.sub(r"^-+ ATTACHMENTS -+\n(?:(?!-{10}).*\n)*", "", text, count=1, flags=re.M) + bare = re.search(r"^bare .*$", text, re.M).group(0) + f = bare.split() + buoy = " ".join(["buoy", "%.6f" % d_eq, "%.4f" % m_eq] + f[3:10] + ["%.6f" % cdn, "%.6f" % cdt] + f[12:]) + text = text.replace(bare, bare + "\n" + buoy, 1) + rows = re.findall(r"^4 bare \S+ \d+$", text, re.M) + h = [float(r.split()[2]) / int(r.split()[3]) for r in rows] + new = ["4 bare 78.0 %d" % round(78.0 / h[0]), "4 buoy 100.0 %d" % round(100.0 / h[1]), + "4 bare 422.0 %d" % round(422.0 / h[2])] + for old, row in zip(rows, new): + text = text.replace(old, row, 1) + return text + + +def run(exe: str, deck: Path) -> tuple[int, dict, str]: + p = subprocess.run([exe, deck.name, "o"], cwd=deck.parent, capture_output=True, text=True, timeout=600) + row = {} + out = deck.parent / "o.out" + if p.returncode == 0 and out.exists(): + lines = [ln for ln in out.read_text().splitlines() if not ln.startswith("#")] + row = dict(zip(lines[0].split(), (float(v) for v in lines[1].split()))) + return p.returncode, row, p.stdout + p.stderr + + +def main() -> int: + ap = argparse.ArgumentParser() + ap.add_argument("--exe", required=True) + ap.add_argument("--data", required=True) + ap.add_argument("--output", required=True) + a = ap.parse_args() + exe = str(Path(a.exe).resolve()) + failures = [] + for mesh, speed in CASES: + base = (Path(a.data) / ("lazy_wave_touchdown_planar_%s_att.dat" % mesh)).read_text() + name = "%s_%g" % (mesh, speed) + results = {} + for kind, text in (("discrete", with_current(base, speed)), ("smeared", smeared(with_current(base, speed)))): + d = Path(a.output) / name / kind + d.mkdir(parents=True, exist_ok=True) + (d / "deck.dat").write_text(text) + rc, row, log = run(exe, d / "deck.dat") + if rc != 0 or "FairTen4" not in row: + failures.append("%s %s: exit %d\n%s" % (name, kind, rc, log[-2000:])) + results[kind] = row + if all("FairTen4" in r for r in results.values()): + disc, smr = results["discrete"], results["smeared"] + dfair = abs(disc["FairTen4"] - smr["FairTen4"]) / smr["FairTen4"] + danch = abs(disc["AnchTen4"] - smr["AnchTen4"]) / smr["AnchTen4"] + print("%-12s FairTen %10.1f / %10.1f N (%.2e) AnchTen %8.1f / %8.1f N (%.2e)" % + (name, disc["FairTen4"], smr["FairTen4"], dfair, disc["AnchTen4"], smr["AnchTen4"], danch)) + if dfair > FAIR_TOL or danch > ANCH_TOL: + failures.append("%s: discrete and smeared tensions differ by %.2e (FairTen) / %.2e (AnchTen)" % + (name, dfair, danch)) + for f in failures: + print("FAIL: " + f) + if failures: + return 1 + print("PASS: discrete buoyancy modules in a cross current match the smeared section") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/test_deck_hermite_cable.f90 b/tests/test_deck_hermite_cable.f90 index 652e30f0..9860d77d 100644 --- a/tests/test_deck_hermite_cable.f90 +++ b/tests/test_deck_hermite_cable.f90 @@ -129,8 +129,9 @@ SUBROUTINE case_adaptive_mesh_refines() !! h*kappa target; adaptive_mesh true lets the coupled builder refine it (warm-started !! cubic-Hermite prolongation of the converged IC) before the dynamic run. Gate: (a) OFF keeps !! the deck's mesh EXACTLY (the default, so every other deck stays bit-for-bit); (b) ON yields - !! MORE nodes, a whole element multiple (uniform refinement -- the replicated hydro/property - !! arrays stay aligned with the refined solution); (c) the coupled node still tracks the + !! MORE nodes, every declared element split into a power of two of equal children (local + !! refinement keeps the declared element partition, so the hydro/property arrays mapped by + !! reference arc stay aligned with the refined solution); (c) the coupled node still tracks the !! refined fairlead; (d) the refined cable steps stably with smooth, bounded curvature (the !! prolongation produced a valid finer equilibrium, not a kink). TYPE(CD_HFMF_ModuleType), ALLOCATABLE :: plain, adapt ! see DEVELOPMENT.md (gfortran 16 -Wuninitialized) @@ -141,7 +142,10 @@ SUBROUTINE case_adaptive_mesh_refines() REAL(wp), PARAMETER :: DT = 0.05_wp, AMP = 1.0_wp, PER = 12.0_wp REAL(wp), PARAMETER :: PI = 3.141592653589793_wp INTEGER, PARAMETER :: NSTEP = 30 - LOGICAL :: stepped_ok + LOGICAL :: stepped_ok, nested + REAL(wp), ALLOCATABLE :: l_deck(:) + REAL(wp) :: acc, ratio + INTEGER :: i, j, k ALLOCATE (plain, adapt) CALL write_cable_deck('hcab_deck_hc_plain.dat') @@ -149,6 +153,7 @@ SUBROUTINE case_adaptive_mesh_refines() CALL require(es == CD_DECKDRV_OK, 'adaptive-mesh: plain deck init: '//TRIM(em)) IF (es /= CD_DECKDRV_OK) RETURN nn_plain = SIZE(plain%line%q)/6 + l_deck = plain%line%l0 CALL CD_HFMF_End(plain) CALL write_cable_deck('hcab_deck_hc_adapt.dat', extra_option='true adaptive_mesh', ba_value=-0.005_wp) @@ -158,8 +163,22 @@ SUBROUTINE case_adaptive_mesh_refines() nn_adapt = SIZE(adapt%line%q)/6 CALL require(nn_adapt > nn_plain, 'adaptive-mesh: accuracy policy refines the declared mesh') - CALL require(MOD(nn_adapt - 1, nn_plain - 1) == 0, & - 'adaptive-mesh: uniform refinement preserves the declared element partition') + ! Every declared element is tiled by refined elements of its length / 2^k (k <= 4). + nested = .TRUE. + j = 1 + DO i = 1, SIZE(l_deck) + acc = 0.0_wp + DO WHILE (acc < l_deck(i)*(1.0_wp - 1.0e-12_wp) .AND. j <= SIZE(adapt%line%l0)) + ratio = l_deck(i)/adapt%line%l0(j) + k = NINT(LOG(ratio)/LOG(2.0_wp)) + IF (k < 0 .OR. k > 4 .OR. ABS(ratio - 2.0_wp**k) > 1.0e-9_wp*ratio) nested = .FALSE. + acc = acc + adapt%line%l0(j) + j = j + 1 + END DO + IF (ABS(acc - l_deck(i)) > 1.0e-9_wp*l_deck(i)) nested = .FALSE. + END DO + IF (j /= SIZE(adapt%line%l0) + 1) nested = .FALSE. + CALL require(nested, 'adaptive-mesh: refinement preserves the declared element partition') CALL require(cn == nn_adapt, 'adaptive-mesh: coupled node tracks the refined fairlead') CALL require(adapt%line%has_axial_damping .AND. ALLOCATED(adapt%line%BA), & 'adaptive-mesh: deck BA is installed on the finite-EI dynamic cable') diff --git a/tests/test_hermite_automesh.f90 b/tests/test_hermite_automesh.f90 index ed825f7c..8c4a275e 100644 --- a/tests/test_hermite_automesh.f90 +++ b/tests/test_hermite_automesh.f90 @@ -19,6 +19,10 @@ PROGRAM test_hermite_automesh !! 5. Physical multi-island contact is accepted at the refinement cap. !! 6. Tension-controlled end layers trigger refinement through the EI-aware diagnosis. !! 7. FAIL-CLOSED: max_scale < 1 is rejected. + !! 8. LOCAL refinement (local_refinement): a line with one coarse section is refined where its + !! h*kappa fails, graded into the fine section, within the per-element cap, and agrees with + !! the global refinement; a resolved mesh, max_scale = 1 and the end-layer rig behave as + !! in the global mode; the per-element diagnosis outputs are consistent. USE CableDyn_Precision, ONLY: wp USE CableDyn_HermiteCableStatic, ONLY: CD_HermiteCable_Static_Solve, & CD_HermiteCable_Static_Solve_AutoMesh, & @@ -41,6 +45,10 @@ PROGRAM test_hermite_automesh CALL case_required_resolution_cap() CALL case_resolved_multi_island_cap() CALL case_fail_closed() + CALL case_local_refinement() + CALL case_local_unchanged() + CALL case_local_boundary_layer() + CALL case_metrics_element_outputs() IF (nfail > 0) THEN WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' @@ -345,6 +353,194 @@ SUBROUTINE case_fail_closed() CALL check(es == CD_HCSTAT_BADINPUT, 'fail: EA size /= SIZE(l0) rejected (no OOB copy)') END SUBROUTINE case_fail_closed + !> The rig of build_rig on a two-section mesh: NC coarse elements over the first 30 m and NF + !> fine 1 m elements over the remaining 70 m (the deck mesh of a line with one coarse section). + SUBROUTINE build_two_section_rig(nc, l0, EA, EI, w, seed, fixed, nfix, seabed_z) + INTEGER, INTENT(IN) :: nc + REAL(wp), ALLOCATABLE, INTENT(OUT) :: l0(:), EA(:), EI(:), w(:), seed(:) + INTEGER, ALLOCATABLE, INTENT(OUT) :: fixed(:) + INTEGER, INTENT(OUT) :: nfix + REAL(wp), INTENT(OUT) :: seabed_z + INTEGER, PARAMETER :: NF = 70 + INTEGER :: ne + CALL build_rig(nc + NF, l0, EA, EI, w, seed, fixed, nfix, seabed_z) + ne = nc + NF + l0(1:nc) = 30.0_wp/REAL(nc, wp) + l0(nc + 1:ne) = 1.0_wp + BLOCK + INTEGER :: es + CHARACTER(160) :: em + CALL CD_HermiteCable_Trivial_Seed([0.0_wp, 0.0_wp, 0.0_wp], [90.0_wp, 0.0_wp, 0.0_wp], l0, seabed_z, & + seed, es, em) + IF (es /= CD_HCSTAT_OK) WRITE (*, '(A)') ' (seed error) '//TRIM(em) + END BLOCK + END SUBROUTINE build_two_section_rig + + SUBROUTINE case_local_refinement() + !! Three coarse 10 m elements beside seventy 1 m elements. The local mode refines the coarse + !! section (and grades into the fine one) instead of multiplying the whole line, keeps every + !! element a power-of-two child of its caller element within the cap, meets the target, and + !! reaches the equilibrium of the global refinement. + REAL(wp), ALLOCATABLE :: l0(:), EA(:), EI(:), w(:), seed(:) + REAL(wp), ALLOCATABLE :: l0o(:), EAo(:), EIo(:), wo(:), qo(:), curvo(:) + REAL(wp), ALLOCATABLE :: l0g(:), EAg(:), EIg(:), wg(:), qg(:), curvg(:), sg(:), so(:) + INTEGER, ALLOCATABLE :: fixed(:), fixo(:), fixg(:) + TYPE(CD_HermiteResolutionType) :: dg, dgg + INTEGER :: nfix, scale, scaleg, its, es, e, k, ng, no + REAL(wp) :: seabed_z, res, ratio, dmax, xg + LOGICAL :: dyadic + CHARACTER(240) :: em + CALL build_two_section_rig(3, l0, EA, EI, w, seed, fixed, nfix, seabed_z) + CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed(1:nfix), seabed_z, 0.0_wp, & + 8, 120, 1.0e-8_wp, 0.7_wp, 0.12_wp, 0.0_wp, 16, [2, 5], & + l0o, EAo, EIo, wo, qo, curvo, fixo, scale, dg, res, its, es, em, & + local_refinement=.TRUE.) + IF (es /= CD_HCSTAT_OK) WRITE (*, '(A)') ' (local automesh error) '//TRIM(em) + CALL check(es == CD_HCSTAT_OK, 'local: solve ok') + IF (es /= CD_HCSTAT_OK) RETURN + CALL check(scale > 1, 'local: refined') + CALL check(dg%h_kappa_peak <= 0.12_wp, 'local: h*kappa target met') + CALL check(ABS(SUM(l0o) - SUM(l0)) <= 1.0e-12_wp*SUM(l0), 'local: rest length preserved') + ! Every element is a 2^-k child (k <= 4) of the caller element that contains it. + dyadic = .TRUE. + xg = 0.0_wp + DO e = 1, SIZE(l0o) + ratio = MERGE(10.0_wp, 1.0_wp, xg + 0.5_wp*l0o(e) < 30.0_wp)/l0o(e) + k = NINT(LOG(ratio)/LOG(2.0_wp)) + IF (k < 0 .OR. k > 4 .OR. ABS(ratio - 2.0_wp**k) > 1.0e-9_wp*ratio) dyadic = .FALSE. + xg = xg + l0o(e) + END DO + CALL check(dyadic, 'local: elements are power-of-two children within the cap') + ! Graded: neighbours differ by at most twice, except across the deck's own 10:1 jump. + ratio = 0.0_wp + DO e = 1, SIZE(l0o) - 1 + ratio = MAX(ratio, MAX(l0o(e)/l0o(e + 1), l0o(e + 1)/l0o(e))) + END DO + CALL check(ratio <= 10.0_wp*(1.0_wp + 1.0e-12_wp), 'local: no new size jump beyond the deck one') + ! The far end of the fine section is not touched. + CALL check(ALL(ABS(l0o(SIZE(l0o) - 19:) - 1.0_wp) < 1.0e-12_wp), 'local: resolved fine section unchanged') + ! Same equilibrium as the global refinement, on far fewer elements. + CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed(1:nfix), seabed_z, 0.0_wp, & + 8, 120, 1.0e-8_wp, 0.7_wp, 0.12_wp, 0.0_wp, 16, [2, 5], & + l0g, EAg, EIg, wg, qg, curvg, fixg, scaleg, dgg, res, its, es, em) + CALL check(es == CD_HCSTAT_OK, 'local: global reference ok') + IF (es /= CD_HCSTAT_OK) RETURN + CALL check(SIZE(l0o) < SIZE(l0g), 'local: fewer elements than the global refinement') + ng = SIZE(l0g) + 1 + no = SIZE(l0o) + 1 + ALLOCATE (sg(ng), so(no)) + sg(1) = 0.0_wp + DO e = 2, ng + sg(e) = sg(e - 1) + l0g(e - 1) + END DO + so(1) = 0.0_wp + DO e = 2, no + so(e) = so(e - 1) + l0o(e - 1) + END DO + dmax = 0.0_wp + DO e = 1, no + DO k = 1, 3, 2 + dmax = MAX(dmax, ABS(qo(6*(e - 1) + k) - interp(so(e), sg, qg(k::6)))) + END DO + END DO + CALL check(dmax < 1.0e-3_wp*SUM(l0), 'local: equilibrium within 1e-3 of the line length of the global one') + END SUBROUTINE case_local_refinement + + REAL(wp) FUNCTION interp(x, xs, ys) + !! Piecewise-linear interpolation of ys(xs) at x (xs ascending). + REAL(wp), INTENT(IN) :: x, xs(:), ys(:) + INTEGER :: i + interp = ys(SIZE(ys)) + DO i = 2, SIZE(xs) + IF (x <= xs(i)) THEN + interp = ys(i - 1) + (ys(i) - ys(i - 1))*(x - xs(i - 1))/(xs(i) - xs(i - 1)) + RETURN + END IF + END DO + END FUNCTION interp + + SUBROUTINE case_local_unchanged() + !! The local mode changes nothing when no refinement runs: a resolved mesh is returned + !! bit-identical to the global mode, and max_scale = 1 disables the local passes too. + REAL(wp), ALLOCATABLE :: l0(:), EA(:), EI(:), w(:), seed(:) + REAL(wp), ALLOCATABLE :: l0o(:), EAo(:), EIo(:), wo(:), qo(:), curvo(:) + REAL(wp), ALLOCATABLE :: l0g(:), EAg(:), EIg(:), wg(:), qg(:), curvg(:) + INTEGER, ALLOCATABLE :: fixed(:), fixo(:), fixg(:) + TYPE(CD_HermiteResolutionType) :: dg + INTEGER :: nfix, scale, its, es + REAL(wp) :: seabed_z, res + CHARACTER(200) :: em + CALL build_rig(64, l0, EA, EI, w, seed, fixed, nfix, seabed_z) + EI = 1.0e6_wp + CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed(1:nfix), seabed_z, 0.0_wp, & + 8, 120, 1.0e-8_wp, 0.7_wp, 0.2_wp, 0.5_wp, 8, [2, 5], & + l0o, EAo, EIo, wo, qo, curvo, fixo, scale, dg, res, its, es, em, & + local_refinement=.TRUE.) + CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed(1:nfix), seabed_z, 0.0_wp, & + 8, 120, 1.0e-8_wp, 0.7_wp, 0.2_wp, 0.5_wp, 8, [2, 5], & + l0g, EAg, EIg, wg, qg, curvg, fixg, scale, dg, res, its, es, em) + CALL check(es == CD_HCSTAT_OK .AND. scale == 1 .AND. SIZE(qo) == SIZE(qg), 'local unchanged: resolved mesh kept') + IF (SIZE(qo) == SIZE(qg)) & + CALL check(nan_max_abs(qo - qg) <= 0.0_wp, 'local unchanged: bit-identical to the global mode') + CALL build_rig(10, l0, EA, EI, w, seed, fixed, nfix, seabed_z) + CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed(1:nfix), seabed_z, 0.0_wp, & + 8, 120, 1.0e-8_wp, 0.7_wp, 0.05_wp, 0.5_wp, 1, [2, 5], & + l0o, EAo, EIo, wo, qo, curvo, fixo, scale, dg, res, its, es, em, & + local_refinement=.TRUE.) + CALL check(es == CD_HCSTAT_OK .AND. scale == 1 .AND. SIZE(l0o) == 10, & + 'local unchanged: no refinement with max_scale = 1') + END SUBROUTINE case_local_unchanged + + SUBROUTINE case_local_boundary_layer() + !! The end-layer rig of case_boundary_layer_refinement in the local mode: the single + !! element is split once and the layer is resolved. + INTEGER, PARAMETER :: NE = 1, NN = 2, NDOF = 6*NN + REAL(wp) :: l0(NE), EA(NE), EI(NE), w(NE), seed(NDOF) + REAL(wp), ALLOCATABLE :: l0o(:), EAo(:), EIo(:), wo(:), qo(:), curvo(:) + INTEGER :: fixed(NDOF), i, scale, its, es + INTEGER, ALLOCATABLE :: fixo(:) + TYPE(CD_HermiteResolutionType) :: dg + REAL(wp) :: res + CHARACTER(240) :: em + l0 = 2.0_wp; EA = 1.0e6_wp; EI = 1.21e4_wp; w = 0.0_wp + seed = 0.0_wp + seed(4) = 1.01_wp; seed(7) = 2.02_wp; seed(10) = 1.01_wp + DO i = 1, NDOF + fixed(i) = i + END DO + CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed, -1.0e4_wp, 0.0_wp, & + 1, 5, 1.0e-10_wp, 1.0_wp, 1.0_wp, 0.0_wp, 2, & + [1, 2, 3, 4, 5, 6], & + l0o, EAo, EIo, wo, qo, curvo, fixo, scale, dg, & + res, its, es, em, require_resolved=.TRUE., local_refinement=.TRUE.) + CALL check(es == CD_HCSTAT_OK .AND. scale == 2 .AND. SIZE(l0o) == 2, 'local boundary: end layer split once') + CALL check(.NOT. dg%boundary_unresolved, 'local boundary: end layer resolved') + END SUBROUTINE case_local_boundary_layer + + SUBROUTINE case_metrics_element_outputs() + !! The per-element outputs of the resolution diagnosis: the h*kappa field peaks at + !! h_kappa_peak, and its length is checked. + REAL(wp), ALLOCATABLE :: l0(:), EA(:), EI(:), w(:), seed(:), q(:), curv(:), hk(:) + INTEGER, ALLOCATABLE :: fixed(:) + LOGICAL, ALLOCATABLE :: chat(:) + TYPE(CD_HermiteResolutionType) :: dg + INTEGER :: nfix, its, es + REAL(wp) :: seabed_z, res + CHARACTER(200) :: em + CALL build_rig(10, l0, EA, EI, w, seed, fixed, nfix, seabed_z) + ALLOCATE (q(SIZE(seed)), curv(11), hk(10), chat(11)) + CALL CD_HermiteCable_Static_Solve(l0, EA, EI, w, seed, fixed(1:nfix), seabed_z, 0.0_wp, & + 8, 120, 1.0e-8_wp, 0.7_wp, q, curv, res, its, es, em) + CALL CD_HermiteCable_Resolution_Metrics(l0, q, seabed_z, 0.5_wp, 0.12_wp, dg, es, em, EA=EA, EI=EI, & + elem_h_kappa=hk, chatter_node=chat) + CALL check(es == CD_HCSTAT_OK, 'metrics outputs: ok') + CALL check(ABS(MAXVAL(hk) - dg%h_kappa_peak) <= 0.0_wp .AND. MAXLOC(hk, 1) == dg%h_kappa_elem, & + 'metrics outputs: element h*kappa peaks at h_kappa_peak') + CALL check(.NOT. ANY(chat) .AND. .NOT. dg%contact_chatter, 'metrics outputs: no chatter off the seabed') + CALL CD_HermiteCable_Resolution_Metrics(l0, q, seabed_z, 0.5_wp, 0.12_wp, dg, es, em, elem_h_kappa=hk(1:9)) + CALL check(es == CD_HCSTAT_BADINPUT, 'metrics outputs: short elem_h_kappa rejected') + END SUBROUTINE case_metrics_element_outputs + SUBROUTINE check(cond, label) LOGICAL, INTENT(IN) :: cond CHARACTER(*), INTENT(IN) :: label From 61a8fa82011fd4aa672ed9eb55cfbdf07a618d77 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Fri, 16 Oct 2026 18:16:36 +0900 Subject: [PATCH 2/7] fix(statics): check fallback attachment states; bound local refinement A discrete attachment equilibrium that the damped Newton solves did not reach alone (pseudo-transient continuation, line search or smaller load steps) is now put through the checks the smeared state passed: the kink limit, the tensile contract under tensile_safety True, the physical-branch audit and the stability test with the static constraints. The solve fails closed naming the failed check. A polish whose Newton solves all converge is not checked again, so its output is unchanged. The attachment polish allows at most 32 failed load steps in all; a step that converged at one size and failed at twice it could otherwise cycle about a thousand times. Its failure message names the load fraction of the first failed solve and the load fraction the homotopy reached; a failure of the drag fixed point names that solve. Local refinement: where a pass would exceed the element limit, the bending-length levels give way first (a level at a time, graded), then the grading, and only then the h*kappa, end-layer and contact needs. The pass cap of 12 now bounds the local resolution passes (the cumulative factor no longer keeps them going), and in the local mode an axial pass is bounded by its own pass cap. applied_scale in the local mode is the largest factor of any element after axial passes too, so the "adaptive refinement stopped at Nx" note is truthful. Documentation: node output channels on a refined line number the nodes of the refined mesh while names are validated against the deck node count, and .static.out or .elements.out give the node arc positions; the "refined to ... elements" note also follows the uniform refinement of a coarse deck mesh whose continuation or polish failed; the attachment failure message and its checks are described. Tests: the local refinement case checks that new neighbour length jumps stay within 2x (the deck's own jump excepted), and a new case checks that the element limit keeps the h*kappa levels and gives up a bending-length level (it fails with the former uniform reduction). Decks that do not refine, and attachment decks whose polish converges without its fallbacks, give identical output. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 9 +- doc/theory.rst | 8 +- doc/troubleshooting.rst | 26 ++++-- src/CableDyn_DeckDriver.f90 | 134 ++++++++++++++++++++++++---- src/CableDyn_HermiteCableStatic.f90 | 53 +++++++---- tests/test_hermite_automesh.f90 | 55 ++++++++++-- 6 files changed, 233 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3f711a8..bcca7895 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -687,7 +687,9 @@ All notable changes to CableDyn are recorded in this file. The format follows `sqrt(EI/T)`, and the elements about an isolated seabed-contact change, and grades the mesh into the neighbouring elements (no element more than twice as long as the next, unless the deck mesh has a larger ratio there). The cap of 16 per deck element, the element limit, the - acceptance checks and the fail-closed messages are unchanged. The two decks above now solve + acceptance checks and the fail-closed messages are unchanged; where a pass would exceed the + element limit, the bending-length splits give way first, then the grading, and only then the + curvature, end-layer and contact splits. The two decks above now solve on 492 and 436 elements in 0.30 s and 0.27 s, with end tensions within 4e-7 and 2e-6 of the whole-line refinement and nodes within 0.7 mm and 4 mm. In the finite-EI statics matrix 61 of the 123 decks refine: their CPU time falls from 76 s to 34 s, the end tensions change by @@ -709,7 +711,10 @@ All notable changes to CableDyn are recorded in this file. The format follows diverged from the first step, even in steps of 1/64 of the load; the seed and the step size were not the cause. A step whose damped Newton solve does not converge is now repeated from the last converged state with pseudo-transient continuation and then with a residual-merit - line search, and halved (down to 1/1024) when neither converges. The deck now solves in + line search, and halved (down to 1/1024, with at most 32 failed steps in all) when neither + converges. A discrete state reached this way must pass the checks the smeared state passed + (the kink limit, the tensile contract under `tensile_safety True`, the physical-branch audit + and the stability test), or the solve fails closed naming the check. The deck now solves in 1.8 s, its fairlead and anchor tensions within 0.04 % and 0.2 % of the deck with the equivalent smeared buoyancy section; in 0.6 m/s, and on the coarse mesh, it solved before and its results are unchanged. A polish whose Newton steps all converge takes the same diff --git a/doc/theory.rst b/doc/theory.rst index f0b3d49b..57f0e69f 100644 --- a/doc/theory.rst +++ b/doc/theory.rst @@ -1290,7 +1290,9 @@ mesh-sequenced route described below first and this route as its fallback): element between finer ones carries a spurious axial oscillation), the state is carried to the new mesh by the Hermite interpolant of each element and polished, and the pass is repeated on the polished state while the target is not met and an element can still be - split, within 8192 elements. Elements the criteria leave alone keep their deck length, so + split (at most 12 passes), within 8192 elements: a pass that would exceed them gives up the + bending-length splits first, then the grading, and only then the curvature, end-layer and + contact splits. Elements the criteria leave alone keep their deck length, so a single coarse section costs only its own refinement (a 462-element lazy wave whose 180 m top section has two elements: 492 elements, where refining the whole line by the factor of its worst element gave 7392). A deck mesh too coarse for the bending length @@ -2331,7 +2333,9 @@ load in warm-started Newton solves; in a deck current the drag at rest is added solve is repeated with the drag of its own solution until the nodes stop moving. The load moves in eighths; a step whose damped Newton solve does not converge is repeated from the last converged state with pseudo-transient continuation and then with a residual-merit line search, -and is halved (down to 1/1024) when neither converges. The smeared state carries no +and is halved (down to 1/1024, with at most 32 failed steps in all) when neither converges; a +discrete state reached this way passes the kink, tensile, physical-branch and stability checks +of the smeared state before it is accepted. The smeared state carries no attachment drag, and on a frictional seabed, whose regularised friction force turns from its sticking stiffness to its sliding capacity over a short slip, the Newton update for a cross-flow drag can overshoot and diverge from the first step (a lazy wave with 25 modules in a diff --git a/doc/troubleshooting.rst b/doc/troubleshooting.rst index 32fdc397..8bfc8aac 100644 --- a/doc/troubleshooting.rst +++ b/doc/troubleshooting.rst @@ -580,8 +580,12 @@ but a few geometries are genuinely hard: load fraction ...`` means the homotopy from the smeared modules to the lumped ones (see *Discrete attachments* in :doc:`theory`) did not reach the discrete equilibrium: the damped Newton solve of a load step did not converge, nor did its pseudo-transient and line-search - repetitions, down to steps of 1/1024 of the module loads. The message names the load fraction - of the first failed solve. Check that the deck with the modules replaced by the equivalent + repetitions, down to steps of 1/1024 of the module loads (or 32 load steps failed in all). + The message names the load fraction of the first failed solve and the load fraction the + homotopy reached. A discrete state reached by those repetitions or smaller steps is checked as + the smeared one was; ``... the discrete equilibrium reached after a failed Newton solve ...`` + names the check it failed (the kink limit, the tensile contract, the physical-branch audit + or the stability test). Check that the deck with the modules replaced by the equivalent smeared buoyancy section solves; if it does, the discrete layout itself is the difficulty. - **A cold start at full load.** The static solve continues the load in stages; if you have hand-tuned a case into a bad basin, remove the tuning and let the default continuation run @@ -763,12 +767,18 @@ Warnings and notes that do not stop a run Mesh the touchdown and section changes to that rule to keep the deck mesh. * - ``Note: line ...: the deck mesh (... elements) could not resolve the curvature of the equilibrium; refined to ... elements`` - - an element of the deck mesh folded beyond :math:`L_0\kappa = 0.7` (a bend shorter than the - element). The static solve refined the mesh locally where the bend is, and where elements - are longer than half the bending length, at most 16-fold per deck element and graded into - the neighbouring elements (see :doc:`theory`, Static equilibrium); the run uses that mesh, - statics and dynamics alike, and its outputs have that many segments. Mesh the reported - section finer to keep the deck mesh. + - the deck mesh is too coarse for the bends of the static state. Either an element folded + beyond :math:`L_0\kappa = 0.7` (a bend shorter than the element), and the static solve + refined the mesh locally where the bend is, and where elements are longer than half the + bending length, at most 16-fold per deck element and graded into the neighbouring + elements; or the continuation or polish failed on a deck mesh with elements longer than + half the bending length :math:`(EI/|w|)^{1/3}`, and the route was repeated on the whole + line refined uniformly by a power of two, up to the factor at which every element meets + that length (or, at a rotationally + restrained end, on end elements halved toward the end down to its boundary layer). See + :doc:`theory`, Static equilibrium. The run uses the refined mesh, statics and dynamics + alike, and its outputs have that many segments (node channels number its nodes, see + :doc:`outputs`). Mesh the line to the bending-length rule to keep the deck mesh. * - ``Note: line ... starts the dynamics from a static state solved in its vertical plane that is unstable out of that plane on its mesh of ... elements, the coarsest ... m long where half the bending length (EI/|w|)^(1/3) is ... m; ...`` diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index 0d3aab0c..3255f018 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -1670,6 +1670,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, INTEGER, PARAMETER :: FALLBACK_SEQUENCE_BUDGET = 2000 LOGICAL :: standalone_mode, contact_enabled, used_trivial_seed, anchor_on_flat_bed, allow_extra_sequence LOGICAL :: polish_ready + ! 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 ! 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(:) @@ -2949,8 +2951,18 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, END IF CALL attachment_static_polish(l0, ea, ei, w_bare, w, diam, att_node, ln%att, q_static, fixed_dofs, & contact_enabled, contact_z, frame_cs, endconn_k, endconn_d0_local, & - endconn_mode, opts, static_tol, ErrStat, ErrMsg, bathymetry, cur_obj) + endconn_mode, opts, static_tol, ErrStat, ErrMsg, bathymetry, cur_obj, & + fell_back=att_fell_back) IF (ErrStat /= CD_DECKDRV_OK) RETURN + ! A discrete state the damped Newton solves did not reach alone (pseudo-transient + ! continuation, line search or smaller load steps) passes the acceptance checks the + ! smeared state passed above: the kink limit, the tensile contract, the physical-branch + ! audit and the stability test. A polish whose Newton solves all converge is a small + ! warm-started correction of an accepted state and is not checked again. + IF (att_fell_back) THEN + CALL attachment_fallback_checks() + IF (ErrStat /= CD_DECKDRV_OK) RETURN + END IF ! On the final mesh, with the bare weights the polished state carries; the bending-length ! rule of the note uses the smeared section weights w. CALL handoff_lateral_note(l0, l0, ea, ei, w_bare, w, diam, opts%rhoW*opts%g*QUARTER_PI*diam**2, fixed_dofs, & @@ -3805,6 +3817,70 @@ SUBROUTINE handoff_lateral_note(l0_ref, l0_n, ea_n, ei_n, w_n, w_rule, diam_ref, CALL report_note(text_h) END SUBROUTINE handoff_lateral_note + SUBROUTINE attachment_fallback_checks() + !! Acceptance of a discrete attachment equilibrium the polish reached with its fallbacks + !! (attachment_static_polish, fell_back), on the final mesh: the kink limit and, under + !! tensile_safety True, the tensile contract of the mesh safety diagnosis, the + !! physical-branch audit and the stability test with the static constraints, as for the + !! smeared state. The tangent takes the bare weights (the lumped attachment loads are + !! dead loads); the audit's compression allowance takes the section weights w smeared + !! over the attachments, as for the smeared state. Fails closed naming the check. + CHARACTER(*), PARAMETER :: WHAT = 'finite-EI static solve with discrete ATTACHMENTS: the discrete '// & + 'equilibrium reached after a failed Newton solve (pseudo-transient '// & + 'continuation, line search or smaller load steps) ' + TYPE(CD_HermiteResolutionType) :: diag_f + LOGICAL :: ok_f + INTEGER :: es_f + CHARACTER(1024) :: em_f + IF (PRESENT(bathymetry) .AND. .NOT. bathymetry_flat) THEN + CALL CD_HermiteCable_Resolution_Metrics(l0, q_static, contact_z, CD_ZERO, CD_HC_KINK_LIMIT, diag_f, es_f, & + em_f, bathymetry=bathymetry, contact_frame_cs=frame_cs, EA=ea, EI=ei, & + compression_mode=CD_HC_COMPRESSION_STRICT) + ELSE + CALL CD_HermiteCable_Resolution_Metrics(l0, q_static, contact_z, CD_ZERO, CD_HC_KINK_LIMIT, diag_f, es_f, & + em_f, EA=ea, EI=ei, compression_mode=CD_HC_COMPRESSION_STRICT) + END IF + IF (es_f /= CD_HCSTAT_OK) THEN + CALL fail_solve(ErrStat, ErrMsg, WHAT//'could not be diagnosed: '//TRIM(em_f)); RETURN + END IF + IF (diag_f%h_kappa_peak > CD_HC_KINK_LIMIT) THEN + WRITE (em_f, '(A,ES12.5,A,ES12.5,A,I0)') 'is unresolved/kinked: max(h*kappa)=', diag_f%h_kappa_peak, & + ' > safety limit=', CD_HC_KINK_LIMIT, ' at element ', diag_f%h_kappa_elem + CALL fail_solve(ErrStat, ErrMsg, WHAT//TRIM(em_f)); RETURN + END IF + IF (opts%tensile_mode == CD_HCDYN_TENSILE_ERROR .AND. diag_f%axial_compression) THEN + WRITE (em_f, '(A,ES12.5,A,ES12.5,A,I0,A,F8.5,A,ES12.5)') & + 'carries axial compression under tensile_safety True: element-mean axial force=', & + diag_f%axial_strain_min_resultant, ' N below tolerance=', diag_f%axial_tolerance, ' N at element ', & + diag_f%axial_strain_min_elem, ', xi=', diag_f%axial_strain_min_xi, ', strain=', diag_f%axial_strain_min + CALL fail_solve(ErrStat, ErrMsg, WHAT//TRIM(em_f)); RETURN + END IF + CALL audit_hermite_static(l0, q_static, ea, ei, w, diam, endconn_mode, ok_f, em_f) + IF (.NOT. ok_f) THEN + CALL fail_solve(ErrStat, ErrMsg, WHAT//'is rejected: '//TRIM(em_f)); RETURN + 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, & + contact_enabled, contact_z, frame_cs, endconn_k, endconn_d0_local, endconn_mode, & + opts, ok_f, ErrStat, ErrMsg, bathymetry=bathymetry, cur_obj=cur_obj) + ELSE + CALL hermite_static_stable(l0, l0, ea, ei, w_bare, diam, dry_b_final(), q_static, fixed_dofs, & + contact_enabled, contact_z, frame_cs, endconn_k, endconn_d0_local, endconn_mode, & + opts, ok_f, ErrStat, ErrMsg, cur_obj=cur_obj) + END IF + IF (ErrStat /= CD_DECKDRV_OK) RETURN + IF (.NOT. ok_f) THEN + CALL fail_solve(ErrStat, ErrMsg, WHAT//'is an unstable equilibrium (tangent stiffness not positive '// & + 'definite)'); RETURN + END IF + END SUBROUTINE attachment_fallback_checks + + FUNCTION dry_b_final() RESULT(dry) + !! Dry buoyancy per length on the final mesh (as dry_b on the deck mesh). + REAL(wp), ALLOCATABLE :: dry(:) + dry = opts%rhoW*opts%g*QUARTER_PI*diam**2 + END FUNCTION dry_b_final + LOGICAL FUNCTION coarse_current_eligible() RESULT(ok) !! coarse_current_first applies to an in-plane current (in_plane_current) without !! seabed friction or attachments, on a deck build that is not itself the coarse one, @@ -4356,7 +4432,7 @@ END SUBROUTINE smear_attachments SUBROUTINE attachment_static_polish(l0, ea, ei, w_bare, w_smear, diam, node, att, q, fixed_dofs, & contact_enabled, contact_z, frame_cs, endconn_k, endconn_d0, endconn_mode, & - opts, tol, ErrStat, ErrMsg, bathymetry, cur_obj) + opts, tol, ErrStat, ErrMsg, bathymetry, cur_obj, fell_back) !! Homotopy from the smeared-attachment equilibrium q to the discrete one: in warm-started !! Newton solves the element weights move from w_smear to w_bare while the lumped nodal !! forces -(m - rho V) g e_z and, in a deck current, the attachment current drag grow from @@ -4369,6 +4445,8 @@ SUBROUTINE attachment_static_polish(l0, ea, ei, w_bare, w_smear, diam, node, att !! not converge is repeated from the last converged state with pseudo-transient !! continuation and then with a residual-merit line search; when neither converges, the !! step is halved (down to MIN_STEP), and it grows back to 1/NSTEP after converged steps. + !! At most MAX_FAILED_STEPS load steps may fail in all (a step that converges at one size + !! and fails at twice it, over and over, would otherwise take about a thousand cycles). !! The smeared state carries no attachment drag, and on a frictional seabed, whose !! regularised friction force turns from its sticking stiffness to its sliding capacity !! over a short slip, the Newton update for a cross-flow drag can overshoot far from the @@ -4376,6 +4454,10 @@ SUBROUTINE attachment_static_polish(l0, ea, ei, w_bare, w_smear, diam, node, att !! regularisation avoids. Once a damped Newton solve has failed, the !! later ones get NEWTON_RETRY_ITER iterations before the fallbacks take over. A polish !! whose damped Newton solves all converge takes exactly the solves it took before. + !! fell_back (optional out) reports that a damped Newton solve failed, so that the state + !! was reached with the fallbacks (and the caller re-runs its acceptance checks on it). + !! A failure names the load fraction of the first failed solve and, when the homotopy + !! stops, the load fraction it reached. REAL(wp), INTENT(IN) :: l0(:), ea(:), ei(:), w_bare(:), w_smear(:), diam(:), att(:, :) INTEGER, INTENT(IN) :: node(:), fixed_dofs(:), endconn_mode(2) REAL(wp), INTENT(INOUT) :: q(:) @@ -4386,22 +4468,28 @@ SUBROUTINE attachment_static_polish(l0, ea, ei, w_bare, w_smear, diam, node, att CHARACTER(*), INTENT(OUT) :: ErrMsg TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry TYPE(CD_HermiteStaticCurrentType), INTENT(IN), OPTIONAL :: cur_obj + LOGICAL, INTENT(OUT), OPTIONAL :: fell_back INTEGER, PARAMETER :: NSTEP = 8, MAX_FIXED_POINT = 60 ! Smallest load-fraction step: 1/NSTEP halved seven times. Newton budget once a damped - ! Newton solve of this polish has failed (a converging one takes well under it). + ! Newton solve of this polish has failed (a converging one takes well under it). Budget + ! of failed load steps (each at most NEWTON_RETRY_ITER + 400 Newton iterations). REAL(wp), PARAMETER :: MIN_STEP = 1.0_wp/1024.0_wp - INTEGER, PARAMETER :: NEWTON_RETRY_ITER = 40 + INTEGER, PARAMETER :: NEWTON_RETRY_ITER = 40, MAX_FAILED_STEPS = 32 REAL(wp), PARAMETER :: FIXED_POINT_TOL = 1.0e-9_wp ! m REAL(wp), ALLOCATABLE :: f_att(:), f_drag(:), dry(:), knnode(:), wl(:), q_out(:), curv(:) REAL(wp) :: lam, lam_done, dlam, res, change - INTEGER :: i, k, ne, fp + INTEGER :: i, k, ne, fp, n_failed LOGICAL :: has_drag, converged, newton_failed - CHARACTER(1024) :: fail_msg - CHARACTER(48) :: step_buf + ! The damped Newton failure of the first failed solve, and of the last one. + CHARACTER(1024) :: first_msg, last_msg + CHARACTER(48) :: step_buf, lam_buf ErrStat = CD_DECKDRV_OK; ErrMsg = '' - fail_msg = '' + IF (PRESENT(fell_back)) fell_back = .FALSE. + first_msg = '' + last_msg = '' newton_failed = .FALSE. + n_failed = 0 ne = SIZE(l0) ALLOCATE (f_att(6*(ne + 1)), f_drag(6*(ne + 1)), dry(ne), q_out(SIZE(q)), curv(ne + 1)) f_att = CD_ZERO @@ -4429,11 +4517,20 @@ SUBROUTINE attachment_static_polish(l0, ea, ei, w_bare, w_smear, diam, node, att lam_done = lam dlam = MIN(2.0_wp*dlam, CD_ONE/REAL(NSTEP, wp)) ELSE + n_failed = n_failed + 1 dlam = 0.5_wp*dlam - IF (dlam < MIN_STEP) THEN - WRITE (step_buf, '(ES9.2)') MIN_STEP - CALL fail_solve(ErrStat, ErrMsg, TRIM(fail_msg)//'; load-fraction steps down to '// & - TRIM(ADJUSTL(step_buf))//' did not converge either') + IF (dlam < MIN_STEP .OR. n_failed >= MAX_FAILED_STEPS) THEN + WRITE (lam_buf, '(F8.6)') lam_done + IF (dlam < MIN_STEP) THEN + WRITE (step_buf, '(ES9.2)') MIN_STEP + CALL fail_solve(ErrStat, ErrMsg, TRIM(first_msg)//'; the homotopy stopped at load fraction '// & + TRIM(ADJUSTL(lam_buf))//', where load steps down to '//TRIM(ADJUSTL(step_buf))// & + ' did not converge either') + ELSE + WRITE (step_buf, '(I0)') MAX_FAILED_STEPS + CALL fail_solve(ErrStat, ErrMsg, TRIM(first_msg)//'; the homotopy stopped at load fraction '// & + TRIM(ADJUSTL(lam_buf))//' after '//TRIM(step_buf)//' load steps had failed') + END IF RETURN END IF END IF @@ -4443,7 +4540,7 @@ SUBROUTINE attachment_static_polish(l0, ea, ei, w_bare, w_smear, diam, node, att CALL solve_with(CD_ONE, converged, change) IF (ErrStat /= CD_DECKDRV_OK) RETURN IF (.NOT. converged) THEN - CALL fail_solve(ErrStat, ErrMsg, TRIM(fail_msg)//' (attachment current drag fixed point)'); RETURN + CALL fail_solve(ErrStat, ErrMsg, TRIM(last_msg)//' (attachment current drag fixed point)'); RETURN END IF IF (change <= FIXED_POINT_TOL) RETURN END DO @@ -4455,8 +4552,9 @@ SUBROUTINE solve_with(scale, ok, dq_max) !! evaluated on the incoming state: the damped Newton iteration and, when it does not !! converge, the pseudo-transient continuation and the residual-merit line search, each !! from the incoming state. ok reports convergence; q is updated only then, and dq_max - !! is the resulting largest DOF change. Otherwise fail_msg names the load fraction and - !! the damped Newton failure. A failed drag evaluation or a rejected input sets ErrStat. + !! is the resulting largest DOF change. Otherwise last_msg (and, the first time, + !! first_msg) names the load fraction and the damped Newton failure. A failed drag + !! evaluation or a rejected input sets ErrStat. REAL(wp), INTENT(IN) :: scale LOGICAL, INTENT(OUT) :: ok REAL(wp), INTENT(OUT), OPTIONAL :: dq_max @@ -4506,13 +4604,15 @@ SUBROUTINE solve_with(scale, ok, dq_max) ! numbers into a local buffer: an internal WRITE into the caller's ErrMsg would abort ! on a short buffer WRITE (num_buf, '(F5.3,A,ES10.3)') scale, ' (relative residual ', res - fail_msg = 'finite-EI static solve with discrete ATTACHMENTS failed at load '// & + last_msg = 'finite-EI static solve with discrete ATTACHMENTS failed at load '// & 'fraction '//TRIM(num_buf)//'): '//TRIM(em) + IF (.NOT. newton_failed) first_msg = last_msg newton_failed = .TRUE. + IF (PRESENT(fell_back)) fell_back = .TRUE. END IF ! A rejected input is rejected by every update rule. IF (es == CD_HCSTAT_BADINPUT) THEN - CALL fail_solve(ErrStat, ErrMsg, TRIM(fail_msg)); RETURN + CALL fail_solve(ErrStat, ErrMsg, TRIM(last_msg)); RETURN END IF END DO IF (.NOT. ok) RETURN diff --git a/src/CableDyn_HermiteCableStatic.f90 b/src/CableDyn_HermiteCableStatic.f90 index f81c099f..ec1b21c6 100644 --- a/src/CableDyn_HermiteCableStatic.f90 +++ b/src/CableDyn_HermiteCableStatic.f90 @@ -6400,10 +6400,14 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs diag_out%axial_strain_min_xi >= CD_ONE - 1.0e-6_wp)) end_res_prev = diag_out%axial_strain_min_resultant ! A local resolution pass runs while an element can still be split (local_resolution_mesh - ! says when none can); the global and axial passes keep their cumulative-factor bound. + ! says when none can), at most MAX_LOCAL_RESOLUTION_PASSES times, and in the local mode an + ! axial pass at most MAX_LOCAL_AXIAL_PASSES times (applied_scale, the largest factor of + ! any element there, need not grow with every pass); the global passes, and the axial + ! passes of the global mode, keep their cumulative-factor bound. DO WHILE (needs_refinement .AND. & - (applied_scale < max_scale .OR. (local_axial .AND. local_passes < MAX_LOCAL_AXIAL_PASSES) .OR. & - (local_mode .AND. .NOT. local_axial .AND. kcap > 0 .AND. & + ((local_axial .AND. local_passes < MAX_LOCAL_AXIAL_PASSES) .OR. & + (.NOT. local_mode .AND. applied_scale < max_scale) .OR. & + (.NOT. local_axial .AND. local_mode .AND. kcap > 0 .AND. & local_res_passes < MAX_LOCAL_RESOLUTION_PASSES))) ! A signed axial oscillation is local, usually at a section interface or the ! touchdown transition. Split every offending element and its immediate @@ -6524,11 +6528,12 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs CALL MOVE_ALLOC(curvnew, curv_out) DEALLOCATE (qr) CALL MOVE_ALLOC(level_r, level_out) - IF (local_axial) THEN - applied_scale = MIN(max_scale, applied_scale*scale) - ELSE IF (local_mode) THEN - ! The largest factor of any element (its level is at most kcap here). + IF (local_mode) THEN + ! The largest factor of any element from its caller element (an axial pass splits + ! only the marked elements, so it raises the factor of those alone). applied_scale = MAX(applied_scale, MIN(max_scale, 2**MIN(MAXVAL(level_out), 30))) + ELSE IF (local_axial) THEN + applied_scale = MIN(max_scale, applied_scale*scale) ELSE applied_scale = applied_scale*scale END IF @@ -6781,25 +6786,31 @@ SUBROUTINE local_resolution_mesh(none, esx, emx) !! each limited to kcap bisections from the caller element. The levels are then graded: !! an element is split further while it is longer than max(2, its length ratio to the !! neighbour before the pass) times that neighbour's new length. A pass that would exceed - !! the element limit AUTO_MAX_ELEMENTS takes one level less everywhere, as the global - !! refinement halves its factor. none is set when no element can be split. + !! the element limit AUTO_MAX_ELEMENTS gives up first the bending-length levels (one + !! level at a time, graded), then the grading, and only then takes one level less of the + !! h*kappa, end-layer and contact needs at a time: those name a bend or a boundary layer + !! the state shows, where the bending-length rule is a mesh-quality rule. none is set + !! when no element can be split. LOGICAL, INTENT(OUT) :: none INTEGER, INTENT(OUT) :: esx CHARACTER(*), INTENT(OUT) :: emx - INTEGER, ALLOCATABLE :: base(:), need(:), need_n(:), lev_c(:), lev_n(:), par_c(:), par_n(:) + INTEGER, ALLOCATABLE :: base(:), bend(:), need(:), need_n(:), lev_c(:), lev_n(:), par_c(:), par_n(:) INTEGER, ALLOCATABLE :: fix_c(:), fix_n(:) REAL(wp), ALLOCATABLE :: l0_c(:), q_c(:), l0_n(:), q_n(:) LOGICAL, ALLOCATABLE :: split(:) INTEGER :: nec, e, a, k, red INTEGER(I8) :: n_new REAL(wp) :: hk_local, half_bend + LOGICAL :: fits none = .TRUE. esx = CD_HCSTAT_OK emx = '' nec = SIZE(l0_out) - ALLOCATE (base(nec), need(nec)) + ! base: the h*kappa, end-layer and contact needs; bend: the bending-length needs. + ALLOCATE (base(nec), bend(nec), need(nec)) hk_local = MIN(h_kappa_target, CD_HC_HKAPPA_TARGET) base = 0 + bend = 0 DO e = 1, nec IF (.NOT. (elem_hk(e) > hk_local)) CYCLE k = 0 @@ -6815,7 +6826,7 @@ SUBROUTINE local_resolution_mesh(none, esx, emx) DO WHILE (l0_out(e) > half_bend*2.0_wp**k*(CD_ONE + 1.0e-12_wp) .AND. level_out(e) + k < kcap) k = k + 1 END DO - base(e) = MAX(base(e), k) + bend(e) = k END DO base(1) = MAX(base(1), end_layer_levels(diag_out%hop_boundary_ratio, level_out(1))) base(nec) = MAX(base(nec), end_layer_levels(diag_out%end_boundary_ratio, level_out(nec))) @@ -6825,14 +6836,24 @@ SUBROUTINE local_resolution_mesh(none, esx, emx) IF (level_out(e) < kcap) base(e) = MAX(base(e), 1) END DO END DO - IF (ALL(base == 0)) RETURN + IF (ALL(base == 0) .AND. ALL(bend == 0)) RETURN + ! Within the element limit: the bending-length levels go first, then the grading, then + ! the other needs a level at a time (the first try is the whole graded need). + fits = .FALSE. + DO red = 0, MAXVAL(bend) + need = MAX(base, bend - red) + CALL grade(need) + n_new = SUM(2_I8**need) + fits = n_new <= INT(AUTO_MAX_ELEMENTS, I8) + IF (fits) EXIT + END DO DO red = 0, MAXVAL(base) + IF (fits) EXIT need = MAX(base - red, 0) - CALL grade(need) n_new = SUM(2_I8**need) - IF (n_new <= INT(AUTO_MAX_ELEMENTS, I8)) EXIT + fits = n_new <= INT(AUTO_MAX_ELEMENTS, I8) END DO - IF (n_new > INT(AUTO_MAX_ELEMENTS, I8) .OR. ALL(need == 0)) RETURN + IF (.NOT. fits .OR. ALL(need == 0)) RETURN none = .FALSE. ! Bisect level by level: the children of a split cubic-Hermite element carry the same diff --git a/tests/test_hermite_automesh.f90 b/tests/test_hermite_automesh.f90 index 8c4a275e..04c46353 100644 --- a/tests/test_hermite_automesh.f90 +++ b/tests/test_hermite_automesh.f90 @@ -22,7 +22,8 @@ PROGRAM test_hermite_automesh !! 8. LOCAL refinement (local_refinement): a line with one coarse section is refined where its !! h*kappa fails, graded into the fine section, within the per-element cap, and agrees with !! the global refinement; a resolved mesh, max_scale = 1 and the end-layer rig behave as - !! in the global mode; the per-element diagnosis outputs are consistent. + !! in the global mode; the element limit takes bending-length levels before h*kappa + !! levels; the per-element diagnosis outputs are consistent. USE CableDyn_Precision, ONLY: wp USE CableDyn_HermiteCableStatic, ONLY: CD_HermiteCable_Static_Solve, & CD_HermiteCable_Static_Solve_AutoMesh, & @@ -48,6 +49,7 @@ PROGRAM test_hermite_automesh CALL case_local_refinement() CALL case_local_unchanged() CALL case_local_boundary_layer() + CALL case_local_element_limit() CALL case_metrics_element_outputs() IF (nfail > 0) THEN @@ -387,8 +389,8 @@ SUBROUTINE case_local_refinement() INTEGER, ALLOCATABLE :: fixed(:), fixo(:), fixg(:) TYPE(CD_HermiteResolutionType) :: dg, dgg INTEGER :: nfix, scale, scaleg, its, es, e, k, ng, no - REAL(wp) :: seabed_z, res, ratio, dmax, xg - LOGICAL :: dyadic + REAL(wp) :: seabed_z, res, ratio, dmax, xg, deck_ratio + LOGICAL :: dyadic, graded CHARACTER(240) :: em CALL build_two_section_rig(3, l0, EA, EI, w, seed, fixed, nfix, seabed_z) CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed(1:nfix), seabed_z, 0.0_wp, & @@ -411,12 +413,17 @@ SUBROUTINE case_local_refinement() xg = xg + l0o(e) END DO CALL check(dyadic, 'local: elements are power-of-two children within the cap') - ! Graded: neighbours differ by at most twice, except across the deck's own 10:1 jump. - ratio = 0.0_wp + ! Graded: neighbours differ by at most twice, except across the deck's own 10:1 jump + ! (the node at 30 m between a 10 m and a 1 m caller element), where the jump is at most it. + graded = .TRUE. + xg = 0.0_wp DO e = 1, SIZE(l0o) - 1 - ratio = MAX(ratio, MAX(l0o(e)/l0o(e + 1), l0o(e + 1)/l0o(e))) + ratio = MAX(l0o(e)/l0o(e + 1), l0o(e + 1)/l0o(e)) + xg = xg + l0o(e) + deck_ratio = MERGE(10.0_wp, 1.0_wp, ABS(xg - 30.0_wp) < 1.0e-9_wp) + IF (ratio > MAX(2.0_wp, deck_ratio)*(1.0_wp + 1.0e-12_wp)) graded = .FALSE. END DO - CALL check(ratio <= 10.0_wp*(1.0_wp + 1.0e-12_wp), 'local: no new size jump beyond the deck one') + CALL check(graded, 'local: new neighbour length jumps at most 2x (the deck jump excepted)') ! The far end of the fine section is not touched. CALL check(ALL(ABS(l0o(SIZE(l0o) - 19:) - 1.0_wp) < 1.0e-12_wp), 'local: resolved fine section unchanged') ! Same equilibrium as the global refinement, on far fewer elements. @@ -517,6 +524,40 @@ SUBROUTINE case_local_boundary_layer() CALL check(.NOT. dg%boundary_unresolved, 'local boundary: end layer resolved') END SUBROUTINE case_local_boundary_layer + SUBROUTINE case_local_element_limit() + !! A pass that would exceed the element limit (8192) gives up bending-length levels before + !! h*kappa levels. 520 elements of 0.19 m with EI = 1e-2 (half the bending length is + !! 2.3 cm) all ask for 16 children by the bending-length rule (8320 elements), and with the + !! h*kappa target 3e-4 the elements about the sag ask for 16 by h*kappa as well. Taking one + !! level less everywhere (8x) would leave the sag at h*kappa about 4e-4 with no pass able to + !! split it further within the limit; keeping its h*kappa levels and giving the + !! bending-length rule one level meets the target in one pass. (The tolerance is the + !! round-off floor of the 6000-element polish.) + INTEGER, PARAMETER :: NE = 520 + REAL(wp), PARAMETER :: TARGET = 3.0e-4_wp + REAL(wp), ALLOCATABLE :: l0(:), EA(:), EI(:), w(:), seed(:) + REAL(wp), ALLOCATABLE :: l0o(:), EAo(:), EIo(:), wo(:), qo(:), curvo(:) + INTEGER, ALLOCATABLE :: fixed(:), fixo(:) + TYPE(CD_HermiteResolutionType) :: dg + INTEGER :: nfix, scale, its, es + REAL(wp) :: seabed_z, res, h + CHARACTER(240) :: em + CALL build_rig(NE, l0, EA, EI, w, seed, fixed, nfix, seabed_z) + EI = 1.0e-2_wp + h = l0(1) + CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed(1:nfix), seabed_z, 0.0_wp, & + 8, 120, 1.0e-6_wp, 0.7_wp, TARGET, 0.0_wp, 16, [2, 5], & + l0o, EAo, EIo, wo, qo, curvo, fixo, scale, dg, res, its, es, em, & + local_refinement=.TRUE.) + IF (es /= CD_HCSTAT_OK) WRITE (*, '(A)') ' (local limit automesh error) '//TRIM(em) + CALL check(es == CD_HCSTAT_OK, 'local limit: solve ok') + IF (es /= CD_HCSTAT_OK) RETURN + CALL check(SIZE(l0o) <= 8192 .AND. SIZE(l0o) > 8*NE, 'local limit: within the limit, beyond 8x') + CALL check(ABS(MINVAL(l0o) - h/16.0_wp) <= 1.0e-12_wp*h, 'local limit: h*kappa needs keep 16 children') + CALL check(ABS(MAXVAL(l0o) - h/8.0_wp) <= 1.0e-12_wp*h, 'local limit: bending-length needs give a level') + CALL check(dg%h_kappa_peak <= TARGET, 'local limit: h*kappa target met') + END SUBROUTINE case_local_element_limit + SUBROUTINE case_metrics_element_outputs() !! The per-element outputs of the resolution diagnosis: the h*kappa field peaks at !! h_kappa_peak, and its length is checked. From 79eacadfd052bdd3abb136f23a9dfce7fd9772d9 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Fri, 16 Oct 2026 21:15:57 +0900 Subject: [PATCH 3/7] fix(statics): judge fallback attachment kinks away from the modules The acceptance checks of a discrete attachment state reached with the polish fallbacks applied the kink limit to every element. A lumped load turns the line by a slope jump at its node, which the C1 elements beside the node carry as h*kappa of about twice the jump at any mesh size, so a heavy module on a slack stretch failed closed on the fallback path while the same equilibrium was accepted when Newton converged plainly. The kink limit now applies away from the attachment nodes; the tensile contract, the fold, loop and self-contact audit (its own kink test left to that check) and the stability test are unchanged. The checks moved into CD_Attachment_Discrete_Verdict, public for its unit test, and a state that passes them is reported in a note. The polish step controller doubled a halved step after a single converged step, so a homotopy converging steadily at 1/32 or 1/64 of the load ran into the 32-failure budget at a load fraction of 0.94 or 0.45. A halved step now doubles after two consecutive converged steps of its size, and each time a doubled step fails the number of converged steps a doubling waits for doubles; such a homotopy keeps advancing and tries the larger size about ten times at most. At most 64 load steps may fail in all, a backstop with at most 1024 converged steps. In the local mode, a refinement that stops short of its target names what stopped it (the element limit, the 12-pass or 16-axial-pass limit) instead of "refinement cap exhausted", which remains for the per-element cap. Documentation: the node channels note in outputs.rst names the silent refinements (adaptive_mesh, torsion, the axial passes of tensile_safety True), gives the End B node by ReferenceArcEnd, and says that node counts and arc positions follow the static state (for example an OpenFAST start with PtfmInit against the deck positions). The iteration budget comment of the polish counts the first failed step correctly, and the comment on the friction pull test names the arcs of N26 and N28 in the 1-based channel convention. Tests: a unit case of the verdict (a slope jump beside the module accepted; the same bend away from it, a compressed state under tensile_safety and an unstable state rejected by name), and the cross-current test requires the fallback note on its fallback case. Decks that do not refine and attachment decks whose polish converges without its fallbacks give identical output. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 16 +- doc/theory.rst | 12 +- doc/troubleshooting.rst | 8 +- src/CableDyn_DeckDriver.f90 | 207 ++++++++++++++++++------- src/CableDyn_HermiteCableStatic.f90 | 44 +++++- tests/test_attachment_cross_current.py | 8 +- tests/test_line_attachments.f90 | 56 ++++++- 7 files changed, 274 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcca7895..84218a75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -689,7 +689,9 @@ All notable changes to CableDyn are recorded in this file. The format follows deck mesh has a larger ratio there). The cap of 16 per deck element, the element limit, the acceptance checks and the fail-closed messages are unchanged; where a pass would exceed the element limit, the bending-length splits give way first, then the grading, and only then the - curvature, end-layer and contact splits. The two decks above now solve + curvature, end-layer and contact splits, and a refinement that stops short of its target + names what stopped it (the cap, the element limit or the limit of 12 passes, 16 for the + axial passes). The two decks above now solve on 492 and 436 elements in 0.30 s and 0.27 s, with end tensions within 4e-7 and 2e-6 of the whole-line refinement and nodes within 0.7 mm and 4 mm. In the finite-EI statics matrix 61 of the 123 decks refine: their CPU time falls from 76 s to 34 s, the end tensions change by @@ -711,10 +713,14 @@ All notable changes to CableDyn are recorded in this file. The format follows diverged from the first step, even in steps of 1/64 of the load; the seed and the step size were not the cause. A step whose damped Newton solve does not converge is now repeated from the last converged state with pseudo-transient continuation and then with a residual-merit - line search, and halved (down to 1/1024, with at most 32 failed steps in all) when neither - converges. A discrete state reached this way must pass the checks the smeared state passed - (the kink limit, the tensile contract under `tensile_safety True`, the physical-branch audit - and the stability test), or the solve fails closed naming the check. The deck now solves in + line search, and halved (down to 1/1024) when neither converges. A halved step doubles + again (up to 1/8) after two consecutive converged steps of its size, and each time a + doubled step fails, the number of converged steps a doubling waits for doubles; at most 64 + load steps may fail in all. A discrete state reached this way must pass the checks the + smeared state passed (the kink limit, except on the elements beside an attachment node, + which carry its slope jump as curvature at any mesh size; the tensile contract under + `tensile_safety True`; the physical-branch audit; the stability test), or the solve fails + closed naming the check; a state that passes them is reported in a note. The deck now solves in 1.8 s, its fairlead and anchor tensions within 0.04 % and 0.2 % of the deck with the equivalent smeared buoyancy section; in 0.6 m/s, and on the coarse mesh, it solved before and its results are unchanged. A polish whose Newton steps all converge takes the same diff --git a/doc/theory.rst b/doc/theory.rst index 57f0e69f..b696d11b 100644 --- a/doc/theory.rst +++ b/doc/theory.rst @@ -2333,9 +2333,15 @@ load in warm-started Newton solves; in a deck current the drag at rest is added solve is repeated with the drag of its own solution until the nodes stop moving. The load moves in eighths; a step whose damped Newton solve does not converge is repeated from the last converged state with pseudo-transient continuation and then with a residual-merit line search, -and is halved (down to 1/1024, with at most 32 failed steps in all) when neither converges; a -discrete state reached this way passes the kink, tensile, physical-branch and stability checks -of the smeared state before it is accepted. The smeared state carries no +and is halved (down to 1/1024) when neither converges. A halved step doubles again (up to 1/8) +after two consecutive converged steps of its size; each time a doubled step fails, the number +of converged steps a doubling waits for doubles, so a homotopy that converges steadily at one +size and fails at twice it keeps advancing and tries the larger size about ten times at most. +At most 64 load steps may fail in all. A discrete state reached this way passes the kink, +tensile, physical-branch and stability checks of the smeared state before it is accepted, the +kink limit :math:`L_0\kappa \le 0.7` applied away from the attachment nodes: a lumped load +turns the line by a slope jump :math:`\theta` at its node, which the :math:`C^1` elements +beside the node carry as :math:`L_0\kappa \approx 2\theta` at any mesh size. The smeared state carries no attachment drag, and on a frictional seabed, whose regularised friction force turns from its sticking stiffness to its sliding capacity over a short slip, the Newton update for a cross-flow drag can overshoot and diverge from the first step (a lazy wave with 25 modules in a diff --git a/doc/troubleshooting.rst b/doc/troubleshooting.rst index 8bfc8aac..09aa905b 100644 --- a/doc/troubleshooting.rst +++ b/doc/troubleshooting.rst @@ -580,12 +580,14 @@ but a few geometries are genuinely hard: load fraction ...`` means the homotopy from the smeared modules to the lumped ones (see *Discrete attachments* in :doc:`theory`) did not reach the discrete equilibrium: the damped Newton solve of a load step did not converge, nor did its pseudo-transient and line-search - repetitions, down to steps of 1/1024 of the module loads (or 32 load steps failed in all). + repetitions, down to steps of 1/1024 of the module loads (or 64 load steps failed in all). The message names the load fraction of the first failed solve and the load fraction the homotopy reached. A discrete state reached by those repetitions or smaller steps is checked as the smeared one was; ``... the discrete equilibrium reached after a failed Newton solve ...`` - names the check it failed (the kink limit, the tensile contract, the physical-branch audit - or the stability test). Check that the deck with the modules replaced by the equivalent + names the check it failed (the kink limit away from the attachment nodes, the tensile + contract, the physical-branch audit or the stability test), and a state that passes them is + reported in the note ``... was reached after a failed Newton solve ... and passed the + acceptance checks of the smeared state``. Check that the deck with the modules replaced by the equivalent smeared buoyancy section solves; if it does, the discrete layout itself is the difficulty. - **A cold start at full load.** The static solve continues the load in stages; if you have hand-tuned a case into a bad basin, remove the tuning and let the default continuation run diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index 3255f018..77732441 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -209,6 +209,8 @@ MODULE CableDyn_DeckDriver PUBLIC :: CD_Rigid6_Get_States, CD_Rigid6_Set_States PUBLIC :: DeckFailure, DeckLine, DeckPoint PUBLIC :: CD_Fire_Deck_Failures + ! Acceptance of a fallback attachment equilibrium (public for its unit test). + PUBLIC :: CD_Attachment_Discrete_Verdict PUBLIC :: CD_Check_System_Plausibility PUBLIC :: CD_Replay_Deck_Failures PUBLIC :: CD_Classify_Dynamic_Completion @@ -2956,12 +2958,17 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, IF (ErrStat /= CD_DECKDRV_OK) RETURN ! A discrete state the damped Newton solves did not reach alone (pseudo-transient ! continuation, line search or smaller load steps) passes the acceptance checks the - ! smeared state passed above: the kink limit, the tensile contract, the physical-branch - ! audit and the stability test. A polish whose Newton solves all converge is a small - ! warm-started correction of an accepted state and is not checked again. + ! smeared state passed above: the kink limit (away from the attachment nodes, whose + ! slope jump the elements beside them carry as curvature), the tensile contract, the + ! physical-branch audit and the stability test (CD_Attachment_Discrete_Verdict). A + ! polish whose Newton solves all converge is a small warm-started correction of an + ! accepted state and is not checked again. IF (att_fell_back) THEN CALL attachment_fallback_checks() IF (ErrStat /= CD_DECKDRV_OK) RETURN + CALL report_note('line '//TRIM(int_to_str(ln%id))//': the discrete attachment equilibrium was reached '// & + 'after a failed Newton solve (pseudo-transient continuation, line search or smaller '// & + 'load steps) and passed the acceptance checks of the smeared state') END IF ! On the final mesh, with the bare weights the polished state carries; the bending-length ! rule of the note uses the smeared section weights w. @@ -3819,59 +3826,30 @@ END SUBROUTINE handoff_lateral_note SUBROUTINE attachment_fallback_checks() !! Acceptance of a discrete attachment equilibrium the polish reached with its fallbacks - !! (attachment_static_polish, fell_back), on the final mesh: the kink limit and, under - !! tensile_safety True, the tensile contract of the mesh safety diagnosis, the - !! physical-branch audit and the stability test with the static constraints, as for the - !! smeared state. The tangent takes the bare weights (the lumped attachment loads are - !! dead loads); the audit's compression allowance takes the section weights w smeared - !! over the attachments, as for the smeared state. Fails closed naming the check. - CHARACTER(*), PARAMETER :: WHAT = 'finite-EI static solve with discrete ATTACHMENTS: the discrete '// & - 'equilibrium reached after a failed Newton solve (pseudo-transient '// & - 'continuation, line search or smaller load steps) ' - TYPE(CD_HermiteResolutionType) :: diag_f - LOGICAL :: ok_f - INTEGER :: es_f - CHARACTER(1024) :: em_f - IF (PRESENT(bathymetry) .AND. .NOT. bathymetry_flat) THEN - CALL CD_HermiteCable_Resolution_Metrics(l0, q_static, contact_z, CD_ZERO, CD_HC_KINK_LIMIT, diag_f, es_f, & - em_f, bathymetry=bathymetry, contact_frame_cs=frame_cs, EA=ea, EI=ei, & - compression_mode=CD_HC_COMPRESSION_STRICT) - ELSE - CALL CD_HermiteCable_Resolution_Metrics(l0, q_static, contact_z, CD_ZERO, CD_HC_KINK_LIMIT, diag_f, es_f, & - em_f, EA=ea, EI=ei, compression_mode=CD_HC_COMPRESSION_STRICT) - END IF - IF (es_f /= CD_HCSTAT_OK) THEN - CALL fail_solve(ErrStat, ErrMsg, WHAT//'could not be diagnosed: '//TRIM(em_f)); RETURN - END IF - IF (diag_f%h_kappa_peak > CD_HC_KINK_LIMIT) THEN - WRITE (em_f, '(A,ES12.5,A,ES12.5,A,I0)') 'is unresolved/kinked: max(h*kappa)=', diag_f%h_kappa_peak, & - ' > safety limit=', CD_HC_KINK_LIMIT, ' at element ', diag_f%h_kappa_elem - CALL fail_solve(ErrStat, ErrMsg, WHAT//TRIM(em_f)); RETURN - END IF - IF (opts%tensile_mode == CD_HCDYN_TENSILE_ERROR .AND. diag_f%axial_compression) THEN - WRITE (em_f, '(A,ES12.5,A,ES12.5,A,I0,A,F8.5,A,ES12.5)') & - 'carries axial compression under tensile_safety True: element-mean axial force=', & - diag_f%axial_strain_min_resultant, ' N below tolerance=', diag_f%axial_tolerance, ' N at element ', & - diag_f%axial_strain_min_elem, ', xi=', diag_f%axial_strain_min_xi, ', strain=', diag_f%axial_strain_min - CALL fail_solve(ErrStat, ErrMsg, WHAT//TRIM(em_f)); RETURN - END IF - CALL audit_hermite_static(l0, q_static, ea, ei, w, diam, endconn_mode, ok_f, em_f) - IF (.NOT. ok_f) THEN - CALL fail_solve(ErrStat, ErrMsg, WHAT//'is rejected: '//TRIM(em_f)); RETURN - END IF + !! (attachment_static_polish, fell_back), on the final mesh, by + !! CD_Attachment_Discrete_Verdict: the stability test with the static constraints is + !! evaluated here (the tangent takes the bare weights; the lumped attachment loads are + !! dead loads), the rest there. Fails closed with the verdict's message. + LOGICAL :: stable_f, accepted_f + CHARACTER(1024) :: msg_f 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, & contact_enabled, contact_z, frame_cs, endconn_k, endconn_d0_local, endconn_mode, & - opts, ok_f, ErrStat, ErrMsg, bathymetry=bathymetry, cur_obj=cur_obj) + opts, stable_f, ErrStat, ErrMsg, bathymetry=bathymetry, cur_obj=cur_obj) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + CALL CD_Attachment_Discrete_Verdict(l0, q_static, ea, ei, w, diam, endconn_mode, att_node, contact_z, & + 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, & contact_enabled, contact_z, frame_cs, endconn_k, endconn_d0_local, endconn_mode, & - opts, ok_f, ErrStat, ErrMsg, cur_obj=cur_obj) + opts, stable_f, ErrStat, ErrMsg, cur_obj=cur_obj) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + CALL CD_Attachment_Discrete_Verdict(l0, q_static, ea, ei, w, diam, endconn_mode, att_node, contact_z, & + opts%tensile_mode == CD_HCDYN_TENSILE_ERROR, stable_f, accepted_f, msg_f) END IF - IF (ErrStat /= CD_DECKDRV_OK) RETURN - IF (.NOT. ok_f) THEN - CALL fail_solve(ErrStat, ErrMsg, WHAT//'is an unstable equilibrium (tangent stiffness not positive '// & - 'definite)'); RETURN + IF (.NOT. accepted_f) THEN + CALL fail_solve(ErrStat, ErrMsg, TRIM(msg_f)); RETURN END IF END SUBROUTINE attachment_fallback_checks @@ -4444,9 +4422,13 @@ SUBROUTINE attachment_static_polish(l0, ea, ei, w_bare, w_smear, diam, node, att !! The load fraction advances in steps of 1/NSTEP. A step whose damped Newton solve does !! not converge is repeated from the last converged state with pseudo-transient !! continuation and then with a residual-merit line search; when neither converges, the - !! step is halved (down to MIN_STEP), and it grows back to 1/NSTEP after converged steps. - !! At most MAX_FAILED_STEPS load steps may fail in all (a step that converges at one size - !! and fails at twice it, over and over, would otherwise take about a thousand cycles). + !! step is halved (down to MIN_STEP). A step doubles again (up to 1/NSTEP) once grow_after + !! consecutive steps of its size have converged; grow_after starts at 2 and doubles each + !! time a doubled step fails, so a homotopy that converges steadily at one size and fails + !! at twice it tries the larger size ever more rarely (about log2(1/MIN_STEP) times in all) + !! and still advances at the smaller size. At most MAX_FAILED_STEPS load steps may fail in + !! all, a backstop that a steady homotopy does not reach (16 failures at worst, at + !! MIN_STEP); with at most 1/MIN_STEP converged steps this bounds the polish. !! The smeared state carries no attachment drag, and on a frictional seabed, whose !! regularised friction force turns from its sticking stiffness to its sliding capacity !! over a short slip, the Newton update for a cross-flow drag can overshoot far from the @@ -4472,14 +4454,15 @@ SUBROUTINE attachment_static_polish(l0, ea, ei, w_bare, w_smear, diam, node, att INTEGER, PARAMETER :: NSTEP = 8, MAX_FIXED_POINT = 60 ! Smallest load-fraction step: 1/NSTEP halved seven times. Newton budget once a damped ! Newton solve of this polish has failed (a converging one takes well under it). Budget - ! of failed load steps (each at most NEWTON_RETRY_ITER + 400 Newton iterations). + ! of failed load steps: each takes at most NEWTON_RETRY_ITER + 400 Newton iterations + ! (the first failed solve 600, its damped Newton solve having the full 200). REAL(wp), PARAMETER :: MIN_STEP = 1.0_wp/1024.0_wp - INTEGER, PARAMETER :: NEWTON_RETRY_ITER = 40, MAX_FAILED_STEPS = 32 + INTEGER, PARAMETER :: NEWTON_RETRY_ITER = 40, MAX_FAILED_STEPS = 64 REAL(wp), PARAMETER :: FIXED_POINT_TOL = 1.0e-9_wp ! m REAL(wp), ALLOCATABLE :: f_att(:), f_drag(:), dry(:), knnode(:), wl(:), q_out(:), curv(:) REAL(wp) :: lam, lam_done, dlam, res, change - INTEGER :: i, k, ne, fp, n_failed - LOGICAL :: has_drag, converged, newton_failed + INTEGER :: i, k, ne, fp, n_failed, n_ok, grow_after + LOGICAL :: has_drag, converged, newton_failed, grown ! The damped Newton failure of the first failed solve, and of the last one. CHARACTER(1024) :: first_msg, last_msg CHARACTER(48) :: step_buf, lam_buf @@ -4508,6 +4491,9 @@ SUBROUTINE attachment_static_polish(l0, ea, ei, w_bare, w_smear, diam, node, att END IF lam_done = CD_ZERO dlam = CD_ONE/REAL(NSTEP, wp) + n_ok = 0 + grow_after = 2 + grown = .FALSE. DO WHILE (lam_done < CD_ONE) lam = MIN(CD_ONE, lam_done + dlam) wl = w_bare + (CD_ONE - lam)*(w_smear - w_bare) @@ -4515,9 +4501,20 @@ SUBROUTINE attachment_static_polish(l0, ea, ei, w_bare, w_smear, diam, node, att IF (ErrStat /= CD_DECKDRV_OK) RETURN IF (converged) THEN lam_done = lam - dlam = MIN(2.0_wp*dlam, CD_ONE/REAL(NSTEP, wp)) + grown = .FALSE. + n_ok = n_ok + 1 + IF (dlam < CD_ONE/REAL(NSTEP, wp) .AND. n_ok >= grow_after) THEN + dlam = MIN(2.0_wp*dlam, CD_ONE/REAL(NSTEP, wp)) + n_ok = 0 + grown = .TRUE. + END IF ELSE n_failed = n_failed + 1 + ! A doubled step that fails was premature: wait twice as long before the next. + ! (Capped past the 1/MIN_STEP steps a homotopy can take.) + IF (grown) grow_after = MIN(2*grow_after, 2*NINT(CD_ONE/MIN_STEP)) + grown = .FALSE. + n_ok = 0 dlam = 0.5_wp*dlam IF (dlam < MIN_STEP .OR. n_failed >= MAX_FAILED_STEPS) THEN WRITE (lam_buf, '(F8.6)') lam_done @@ -6014,8 +6011,97 @@ SUBROUTINE hermite_static_torsion(l0_deck, l0, ea, ei, w, diam_deck, dry_deck, q q = q_out END SUBROUTINE hermite_static_torsion - SUBROUTINE audit_hermite_static(l0, q, ea, ei, w, diam, endconn_mode, physical, message, compression_note) + SUBROUTINE CD_Attachment_Discrete_Verdict(l0, q, ea, ei, w, diam, endconn_mode, att_node, contact_z, & + tensile_error, stable, accepted, message, bathymetry, frame_cs) + !! Acceptance of a discrete attachment equilibrium that the attachment polish reached + !! with its fallbacks (pseudo-transient continuation, line search or smaller load steps), + !! on its mesh l0 with state q: the checks the smeared state passed before the polish. + !! 1. The kink limit (h*kappa <= CD_HC_KINK_LIMIT), except on the elements beside an + !! attachment node att_node: the lumped load turns the line there by a slope jump, + !! which the C1 Hermite elements beside the node carry as curvature (h*kappa of about + !! twice the jump) at any mesh size; a polish whose Newton solves converge accepts it. + !! 2. With tensile_error (tensile_safety True), no axial compression in the mesh safety + !! diagnosis (the strict, smoothed compression mode of the smeared-state check). + !! 3. The physical-branch audit (audit_hermite_static: no fold, loop or self-contact), + !! with its kink test left to 1. + !! 4. stable: the stability test with the static constraints, evaluated by the caller. + !! accepted is false when a check fails, and message names it in full. w are the section + !! weights (smeared over the attachments) of the audit's compression allowance, diam the + !! element diameters on l0. Public for its unit test. + REAL(wp), INTENT(IN) :: l0(:), q(:), ea(:), ei(:), w(:), diam(:), contact_z + INTEGER, INTENT(IN) :: endconn_mode(2), att_node(:) + LOGICAL, INTENT(IN) :: tensile_error, stable + LOGICAL, INTENT(OUT) :: accepted + CHARACTER(*), INTENT(OUT) :: message + TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry + REAL(wp), INTENT(IN), OPTIONAL :: frame_cs(2) + CHARACTER(*), PARAMETER :: WHAT = 'finite-EI static solve with discrete ATTACHMENTS: the discrete '// & + 'equilibrium reached after a failed Newton solve (pseudo-transient '// & + 'continuation, line search or smaller load steps) ' + TYPE(CD_HermiteResolutionType) :: diag + REAL(wp), ALLOCATABLE :: hk(:) + LOGICAL, ALLOCATABLE :: beside(:) + REAL(wp) :: hk_peak + INTEGER :: ne, e, k, es, e_peak + LOGICAL :: physical + CHARACTER(1024) :: em + accepted = .FALSE. + message = '' + ne = SIZE(l0) + ALLOCATE (hk(ne), beside(ne)) + IF (PRESENT(bathymetry) .AND. PRESENT(frame_cs)) THEN + CALL CD_HermiteCable_Resolution_Metrics(l0, q, contact_z, CD_ZERO, CD_HC_KINK_LIMIT, diag, es, em, & + bathymetry=bathymetry, contact_frame_cs=frame_cs, EA=ea, EI=ei, & + compression_mode=CD_HC_COMPRESSION_STRICT, elem_h_kappa=hk) + ELSE + CALL CD_HermiteCable_Resolution_Metrics(l0, q, contact_z, CD_ZERO, CD_HC_KINK_LIMIT, diag, es, em, & + EA=ea, EI=ei, compression_mode=CD_HC_COMPRESSION_STRICT, elem_h_kappa=hk) + END IF + IF (es /= CD_HCSTAT_OK) THEN + message = WHAT//'could not be diagnosed: '//TRIM(em); RETURN + END IF + beside = .FALSE. + DO k = 1, SIZE(att_node) + DO e = att_node(k) - 1, att_node(k) + IF (e >= 1 .AND. e <= ne) beside(e) = .TRUE. + END DO + END DO + hk_peak = CD_ZERO + e_peak = 0 + DO e = 1, ne + IF (beside(e)) CYCLE + IF (hk(e) > hk_peak) THEN + hk_peak = hk(e) + e_peak = e + END IF + END DO + 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)' + message = WHAT//TRIM(em); RETURN + END IF + IF (tensile_error .AND. diag%axial_compression) THEN + WRITE (em, '(A,ES12.5,A,ES12.5,A,I0,A,F8.5,A,ES12.5)') & + 'carries axial compression under tensile_safety True: element-mean axial force=', & + diag%axial_strain_min_resultant, ' N below tolerance=', diag%axial_tolerance, ' N at element ', & + diag%axial_strain_min_elem, ', xi=', diag%axial_strain_min_xi, ', strain=', diag%axial_strain_min + message = WHAT//TRIM(em); RETURN + END IF + CALL audit_hermite_static(l0, q, ea, ei, w, diam, endconn_mode, physical, em, ignore_kink=.TRUE.) + IF (.NOT. physical) THEN + message = WHAT//'is rejected: '//TRIM(em); RETURN + END IF + IF (.NOT. stable) THEN + message = WHAT//'is an unstable equilibrium (tangent stiffness not positive definite)'; RETURN + END IF + accepted = .TRUE. + END SUBROUTINE CD_Attachment_Discrete_Verdict + + SUBROUTINE audit_hermite_static(l0, q, ea, ei, w, diam, endconn_mode, physical, message, compression_note, & + ignore_kink) !! Physical-branch audit of a converged deck cable (CD_HermiteCable_Branch_Audit). + !! ignore_kink (optional, default false): accept a state that fails only the audit's kink + !! test (the last it applies), for a caller that judges the kink limit itself. !! A rotationally restrained end (Finite/Rigid connection) may turn the centreline !! against the chord heading inside its bending boundary layer, of length !! sqrt(EI/T) at the end tension; five such lengths (at most a quarter of the line) @@ -6028,6 +6114,7 @@ SUBROUTINE audit_hermite_static(l0, q, ea, ei, w, diam, endconn_mode, physical, LOGICAL, INTENT(OUT) :: physical CHARACTER(*), INTENT(OUT) :: message CHARACTER(*), INTENT(OUT), OPTIONAL :: compression_note + LOGICAL, INTENT(IN), OPTIONAL :: ignore_kink TYPE(CD_HermiteBranchAuditType) :: audit REAL(wp) :: zone(2), qe(12), t_end, total, allowance, hl_max, excess, denom LOGICAL :: report_c @@ -6061,6 +6148,9 @@ SUBROUTINE audit_hermite_static(l0, q, ea, ei, w, diam, endconn_mode, physical, RETURN END IF physical = audit%physical + IF (PRESENT(ignore_kink)) THEN + IF (ignore_kink .AND. audit%failed_check == CD_HC_AUDIT_KINK) physical = .TRUE. + END IF IF (PRESENT(compression_note)) THEN ! Mesh adequacy: a cubic-Hermite element longer than the bending length ! lambda = (EI/|w|)^(1/3) cannot follow the bends of the line (touchdown, arch, @@ -6115,6 +6205,7 @@ SUBROUTINE audit_hermite_static(l0, q, ea, ei, w, diam, endconn_mode, physical, 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 END SELECT + IF (physical) message = '' END SUBROUTINE audit_hermite_static FUNCTION diam_on(l0_deck, l0, diam_deck) RESULT(diam) diff --git a/src/CableDyn_HermiteCableStatic.f90 b/src/CableDyn_HermiteCableStatic.f90 index ec1b21c6..2f21774b 100644 --- a/src/CableDyn_HermiteCableStatic.f90 +++ b/src/CableDyn_HermiteCableStatic.f90 @@ -6241,6 +6241,8 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs INTEGER, PARAMETER :: MAX_LOCAL_RESOLUTION_PASSES = 12 LOGICAL :: local_mode, nothing_to_split INTEGER :: kcap, local_res_passes + ! What stopped the local refinement short of its targets, other than the per-element cap. + CHARACTER(160) :: local_stop INTEGER, ALLOCATABLE :: level_out(:), level_r(:) REAL(wp), ALLOCATABLE :: elem_hk(:) LOGICAL, ALLOCATABLE :: chatter_nodes(:) @@ -6301,6 +6303,7 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs local_mode = .FALSE. IF (PRESENT(local_refinement)) local_mode = local_refinement local_res_passes = 0 + local_stop = '' IF (max_scale < 1) THEN ErrStat = CD_HCSTAT_BADINPUT; ErrMsg = 'CD_HermiteCable_Static_Solve_AutoMesh: max_scale >= 1 required'; RETURN @@ -6575,6 +6578,14 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs EXIT END IF END DO + ! In the local mode, name a pass limit that stopped the refinement (the element limit is + ! named by local_resolution_mesh; a refinement that stops at the per-element cap keeps + ! the cap wording below). + IF (local_mode .AND. LEN_TRIM(local_stop) == 0 .AND. local_res_passes >= MAX_LOCAL_RESOLUTION_PASSES) & + WRITE (local_stop, '(A,I0,A)', IOSTAT=wios) 'the limit of ', MAX_LOCAL_RESOLUTION_PASSES, & + ' refinement passes was reached' + IF (local_mode .AND. LEN_TRIM(axial_stop) == 0 .AND. local_passes >= MAX_LOCAL_AXIAL_PASSES) & + WRITE (axial_stop, '(A,I0,A)', IOSTAT=wios) 'the limit of ', MAX_LOCAL_AXIAL_PASSES, ' passes was reached' ! A residual-converged, element-localized fold is not a usable equilibrium. ! Enforce this numerical-safety bound for every AutoMesh caller, including @@ -6589,6 +6600,7 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs 'CD_HermiteCable_Static_Solve_AutoMesh: unresolved/kinked equilibrium: max(h*kappa)=', & 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)//')' ErrMsg = wbuf RETURN END IF @@ -6606,6 +6618,13 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs ' N below tolerance=', diag_out%axial_tolerance, ' N at element ', & diag_out%axial_strain_min_elem, ', xi=', diag_out%axial_strain_min_xi, & ', strain=', diag_out%axial_strain_min + ELSE IF (LEN_TRIM(local_stop) > 0) THEN + WRITE (wbuf, '(A,ES12.5,A,ES12.5,A,I0,A,F8.5,A,ES12.5)', IOSTAT=wios) & + 'CD_HermiteCable_Static_Solve_AutoMesh: local refinement stopped ('//TRIM(local_stop)// & + ') with compressive axial resultant=', diag_out%axial_strain_min_resultant, & + ' N below tolerance=', diag_out%axial_tolerance, ' N at element ', & + diag_out%axial_strain_min_elem, ', xi=', diag_out%axial_strain_min_xi, & + ', strain=', diag_out%axial_strain_min ELSE WRITE (wbuf, '(A,I0,A,ES12.5,A,ES12.5,A,I0,A,F8.5,A,ES12.5)', IOSTAT=wios) & 'CD_HermiteCable_Static_Solve_AutoMesh: refinement cap ', max_scale, & @@ -6635,11 +6654,19 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs (diag_out%h_kappa_peak > h_kappa_target .OR. diag_out%contact_chatter)) THEN ErrStat = CD_HCSTAT_NOCONVERGE wbuf = '' - WRITE (wbuf, '(A,I0,A,ES12.5,A,ES12.5,A,L1,A,I0)', IOSTAT=wios) & - 'CD_HermiteCable_Static_Solve_AutoMesh: refinement cap ', max_scale, & - ' exhausted with unresolved h*kappa=', diag_out%h_kappa_peak, ' (target ', h_kappa_target, & - '), contact chatter=', diag_out%contact_chatter, & - ', contact islands=', diag_out%n_islands + IF (LEN_TRIM(local_stop) > 0) THEN + WRITE (wbuf, '(A,ES12.5,A,ES12.5,A,L1,A,I0)', IOSTAT=wios) & + 'CD_HermiteCable_Static_Solve_AutoMesh: local refinement stopped ('//TRIM(local_stop)// & + ') with unresolved h*kappa=', diag_out%h_kappa_peak, ' (target ', h_kappa_target, & + '), contact chatter=', diag_out%contact_chatter, & + ', contact islands=', diag_out%n_islands + ELSE + WRITE (wbuf, '(A,I0,A,ES12.5,A,ES12.5,A,L1,A,I0)', IOSTAT=wios) & + 'CD_HermiteCable_Static_Solve_AutoMesh: refinement cap ', max_scale, & + ' exhausted with unresolved h*kappa=', diag_out%h_kappa_peak, ' (target ', h_kappa_target, & + '), contact chatter=', diag_out%contact_chatter, & + ', contact islands=', diag_out%n_islands + END IF ErrMsg = wbuf RETURN END IF @@ -6853,7 +6880,12 @@ SUBROUTINE local_resolution_mesh(none, esx, emx) n_new = SUM(2_I8**need) fits = n_new <= INT(AUTO_MAX_ELEMENTS, I8) END DO - IF (.NOT. fits .OR. ALL(need == 0)) RETURN + IF (.NOT. fits .OR. ALL(need == 0)) THEN + ! A need was given up to the limit (with no need at all the early return above names + ! the per-element cap). + WRITE (local_stop, '(A,I0,A)') 'the element limit ', AUTO_MAX_ELEMENTS, ' was reached' + RETURN + END IF none = .FALSE. ! Bisect level by level: the children of a split cubic-Hermite element carry the same diff --git a/tests/test_attachment_cross_current.py b/tests/test_attachment_cross_current.py index 188ebf98..29305eee 100644 --- a/tests/test_attachment_cross_current.py +++ b/tests/test_attachment_cross_current.py @@ -8,7 +8,7 @@ put in a uniform current across its vertical plane. The static solve reaches the discrete equilibrium from the smeared one by a homotopy in the module loads and drag; on the refined mesh in 0.3 m/s its damped Newton steps diverge on the frictional seabed, and the polish must -fall back to its regularised solves rather than fail. +fall back to its regularised solves rather than fail (its note naming that path is required). Every deck must solve (exit 0), and its line-end tensions must agree with the deck that replaces the modules by the equivalent smeared section (the same submerged weight, displaced @@ -32,6 +32,10 @@ BARE_D, BARE_M, BARE_CDN, BARE_CDT = 0.16, 36.70, 1.2, 0.1 FAIR_TOL, ANCH_TOL = 0.01, 0.02 CASES = [("refined", 0.3), ("refined", 0.6), ("coarse", 0.3), ("coarse", 0.6)] +# The case whose polish takes the fallback path; its note says so (and that the state passed +# the acceptance checks of the smeared state). +FALLBACK_CASE = "refined_0.3" +FALLBACK_NOTE = "was reached after a failed Newton solve" def with_current(text: str, speed: float) -> str: @@ -91,6 +95,8 @@ def main() -> int: rc, row, log = run(exe, d / "deck.dat") if rc != 0 or "FairTen4" not in row: failures.append("%s %s: exit %d\n%s" % (name, kind, rc, log[-2000:])) + if kind == "discrete" and name == FALLBACK_CASE and FALLBACK_NOTE not in log: + failures.append("%s: the polish did not report its fallback path" % name) results[kind] = row if all("FairTen4" in r for r in results.values()): disc, smr = results["discrete"], results["smeared"] diff --git a/tests/test_line_attachments.f90 b/tests/test_line_attachments.f90 index b67b30b0..9795d5ea 100644 --- a/tests/test_line_attachments.f90 +++ b/tests/test_line_attachments.f90 @@ -17,8 +17,12 @@ PROGRAM test_line_attachments !! 5. Deck current (uniform, profile): convergence to EQUIVALENT BUOYANCY and no drift at rest. !! 6. Coupled route (the OpenFAST aggregate): held SeaState-style kinematics at the !! attachment nodes, and a bit-identical checkpoint restart. + !! 7. Acceptance of a fallback attachment state (CD_Attachment_Discrete_Verdict): a slope + !! jump beside an attachment node passes the kink limit; the same bend away from it, a + !! compressed state under tensile_safety and an unstable state fail closed by name. USE CableDyn_Precision, ONLY: wp - USE CableDyn_DeckDriver, ONLY: CD_Run_Deck_Driver, CD_DECKDRV_OK + USE CableDyn_DeckDriver, ONLY: CD_Run_Deck_Driver, CD_DECKDRV_OK, CD_Attachment_Discrete_Verdict + USE CableDyn_EndConnection, ONLY: CD_ENDCONN_PINNED USE CableDyn_OpenFAST_Aggregate, ONLY: CD_AGG_ModuleType, CD_AGG_Init_From_Deck, CD_AGG_GetMovingPointMesh, & CD_AGG_UpdateStates_Moving, CD_AGG_Step_Moving, CD_AGG_CalcOutput, & CD_AGG_End, CD_AGG_NFluidNodes, CD_AGG_GetFluidNodePositions, & @@ -42,6 +46,7 @@ PROGRAM test_line_attachments CALL case_current('profile', 'profile -60.0 0.2 0.3 0.0 0.0 0.5 0.4 0.0 current') CALL case_grammar() CALL case_coupled() + CALL case_fallback_verdict() IF (nfail > 0) THEN WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' @@ -53,6 +58,55 @@ PROGRAM test_line_attachments INCLUDE 'nan_max_abs.inc' + SUBROUTINE case_fallback_verdict() + !! A straight 10 m line on 1 m elements whose tangent at node 6 is turned by 0.6 rad: the + !! two elements beside node 6 carry h*kappa of about 2.3, beyond the kink limit 0.7, as the + !! elements beside a lumped attachment load carry its slope jump. With the attachment at + !! node 6 the verdict accepts the state; with it at node 3 it rejects the kink; a uniformly + !! compressed straight line is rejected under tensile_safety True; and an unstable state + !! (the caller's stability test) is rejected. + INTEGER, PARAMETER :: NE = 10 + REAL(wp), PARAMETER :: THETA = 0.6_wp + REAL(wp) :: l0(NE), ea(NE), ei(NE), w(NE), diam(NE), q(6*(NE + 1)), qc(6*(NE + 1)) + INTEGER :: i + LOGICAL :: accepted + CHARACTER(1024) :: msg + l0 = 1.0_wp + ea = 1.0e8_wp + ei = 1.0e4_wp + w = 100.0_wp + diam = 0.1_wp + q = 0.0_wp + qc = 0.0_wp + DO i = 1, NE + 1 + q(6*(i - 1) + 1:6*(i - 1) + 3) = [REAL(i - 1, wp), 0.0_wp, -50.0_wp] + q(6*(i - 1) + 4:6*(i - 1) + 6) = [1.0_wp, 0.0_wp, 0.0_wp] + qc(6*(i - 1) + 1:6*(i - 1) + 3) = [0.99_wp*REAL(i - 1, wp), 0.0_wp, -50.0_wp] + qc(6*(i - 1) + 4:6*(i - 1) + 6) = [0.99_wp, 0.0_wp, 0.0_wp] + END DO + q(6*5 + 4:6*5 + 6) = [COS(THETA), 0.0_wp, SIN(THETA)] + CALL CD_Attachment_Discrete_Verdict(l0, q, ea, ei, w, diam, [CD_ENDCONN_PINNED, CD_ENDCONN_PINNED], [6], & + -1000.0_wp, .FALSE., .TRUE., accepted, msg) + CALL require(accepted, 'fallback verdict: a slope jump beside the attachment node is accepted ('// & + TRIM(msg)//')') + CALL CD_Attachment_Discrete_Verdict(l0, q, ea, ei, w, diam, [CD_ENDCONN_PINNED, CD_ENDCONN_PINNED], [3], & + -1000.0_wp, .FALSE., .TRUE., accepted, msg) + CALL require(.NOT. accepted .AND. INDEX(msg, 'discrete ATTACHMENTS') > 0 .AND. & + INDEX(msg, 'is unresolved/kinked') > 0 .AND. INDEX(msg, 'away from the attachment nodes') > 0, & + 'fallback verdict: the bend away from the attachment fails the kink limit ('//TRIM(msg)//')') + CALL CD_Attachment_Discrete_Verdict(l0, qc, ea, ei, w, diam, [CD_ENDCONN_PINNED, CD_ENDCONN_PINNED], [6], & + -1000.0_wp, .TRUE., .TRUE., accepted, msg) + CALL require(.NOT. accepted .AND. INDEX(msg, 'carries axial compression under tensile_safety True') > 0, & + 'fallback verdict: a compressed state fails the tensile contract ('//TRIM(msg)//')') + CALL CD_Attachment_Discrete_Verdict(l0, qc, ea, ei, w, diam, [CD_ENDCONN_PINNED, CD_ENDCONN_PINNED], [6], & + -1000.0_wp, .FALSE., .TRUE., accepted, msg) + CALL require(accepted, 'fallback verdict: compression alone passes without tensile_safety ('//TRIM(msg)//')') + CALL CD_Attachment_Discrete_Verdict(l0, q, ea, ei, w, diam, [CD_ENDCONN_PINNED, CD_ENDCONN_PINNED], [6], & + -1000.0_wp, .FALSE., .FALSE., accepted, msg) + CALL require(.NOT. accepted .AND. INDEX(msg, 'is an unstable equilibrium') > 0, & + 'fallback verdict: an unstable state is rejected ('//TRIM(msg)//')') + END SUBROUTINE case_fallback_verdict + SUBROUTINE require(cond, msg) LOGICAL, INTENT(IN) :: cond CHARACTER(*), INTENT(IN) :: msg From 79f4d04810bf079996501f1eb8e628b71621b98b Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Sat, 17 Oct 2026 21:50:02 +0900 Subject: [PATCH 4/7] docs(statics): node channels name deck nodes on locally refined lines After the rebase onto the deck-node channel mapping, the local refinement keeps every deck node (it only bisects deck elements), so the node channels still name deck nodes. The CHANGELOG and the troubleshooting note said they number the refined nodes; they now point to the node-channel section instead, which names both refinement kinds. Re-measured on the rebased build: the two headline decks take 10.0 s and 9.2 s with whole-line refinement and 0.33 s and 0.28 s now; the statics matrix CPU time of its 61 refining decks falls from 65 s to 33 s (the accuracy figures are unchanged). The lazy wave of the node-channel entry now refines to 269 elements instead of 1136, its node tensions within 0.9 N of the same line on 1560 elements. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 22 +++++++++++++--------- doc/outputs.rst | 6 +++--- doc/troubleshooting.rst | 6 ++++-- src/CableDyn_DeckDriver.f90 | 3 ++- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84218a75..ffcd8df7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -680,8 +680,8 @@ All notable changes to CableDyn are recorded in this file. The format follows now refined locally instead of as a whole. The static solve had multiplied every element by the power of two that the worst one needed, up to 16, even when only one section was coarse: a 462-element lazy wave whose 180 m top section had two elements was solved on 7392 elements - in 6.6 s, and a 410-element lazy wave with a rigid horizontal hang-off on 6560 elements in - 6.0 s. A refinement pass now splits into 2, 4, 8 or 16 equal elements only the elements whose + in 10.0 s, and a 410-element lazy wave with a rigid horizontal hang-off on 6560 elements in + 9.2 s. A refinement pass now splits into 2, 4, 8 or 16 equal elements only the elements whose `L0*kappa` exceeds 0.12 (or the stricter `adaptive_mesh` target), that are longer than half their bending length `(EI/|w|)^(1/3)`, or, at a line end, longer than the boundary layer `sqrt(EI/T)`, and the elements about an isolated seabed-contact change, and grades the mesh @@ -691,18 +691,22 @@ All notable changes to CableDyn are recorded in this file. The format follows element limit, the bending-length splits give way first, then the grading, and only then the curvature, end-layer and contact splits, and a refinement that stops short of its target names what stopped it (the cap, the element limit or the limit of 12 passes, 16 for the - axial passes). The two decks above now solve - on 492 and 436 elements in 0.30 s and 0.27 s, with end tensions within 4e-7 and 2e-6 of the - whole-line refinement and nodes within 0.7 mm and 4 mm. In the finite-EI statics matrix 61 - of the 123 decks refine: their CPU time falls from 76 s to 34 s, the end tensions change by + axial passes). The two decks above now solve on 492 and 436 elements in 0.33 s and 0.28 s, + with end tensions within 4e-7 and 2e-6 of the whole-line refinement and nodes within 0.7 mm + and 4 mm. The lazy wave of the node-channel entry above (its top section on 4 elements) now + refines to 269 elements instead of 1136, with node tensions within 0.9 N (of 1.2 to 12 kN) + of the same line on 1560 elements of 0.25 to 0.5 m. In the finite-EI statics matrix 61 + of the 123 decks refine: their CPU time falls from 65 s to 33 s, the end tensions change by at most 0.21 % of the line's peak end tension (a 58 m line on 2 m end elements, whose hang-off tension moves from 1157.5 N to 1155.1 N; 1157.5 N on a mesh 16 times finer) and the nodes by at most 6.4e-4 of the line length. In a 761-deck statics robustness campaign 57 decks refine: they solve in 18 s instead of 63 s, with the same outcomes and notes (two no - longer need the static residual floor note), end tensions within 1e-5 of the peak end tension and nodes within 3.2e-5 of the line length. + longer need the static residual floor note), end tensions within 1e-5 of the peak end + tension and nodes within 3.2e-5 of the line length. Decks that do not refine, including every shipped example, give identical output. On a - deck that refines, the dynamics run on the new mesh, and node output channels (`LN`) - name its nodes. + deck that refines, the dynamics run on the new mesh; the local refinement only splits deck + elements, so every deck node is a node of the new mesh and the node output channels still + name deck nodes (see the node-channel entry above). - A finite-EI line with discrete buoyancy modules (`ATTACHMENTS`) in a cross current on a frictional seabed no longer fails its static solve. The lazy wave of `tests/data/lazy_wave_touchdown_planar_refined_att.dat` (25 modules on 2 m elements) in a diff --git a/doc/outputs.rst b/doc/outputs.rst index eedcd047..989ed591 100644 --- a/doc/outputs.rst +++ b/doc/outputs.rst @@ -485,9 +485,9 @@ Node channels on a refined line ```` is always a node of the **deck** mesh. The static solve of a finite-EI line can refine its mesh (``OPTIONS adaptive_mesh``, or the automatic refinement after a failed stability test or an unresolved curvature, which a note of the initialization report names). A refinement splits -deck elements, so each deck node is a node of the refined mesh at the same unstretched arc length -from End A, and ``TenN``, ``CurvN``, ``BendMomN``, ``LN…``, -``TorqN`` and ``TwistN`` report deck node ``J`` there, on every route (standalone, +deck elements (along the whole line or only where the state needs it), so each deck node is a +node of the refined mesh at the same unstretched arc length from End A, and ``TenN``, +``CurvN``, ``BendMomN``, ``LN…``, ``TorqN`` and ``TwistN`` report deck node ``J`` there, on every route (standalone, mixed, multibody, OpenFAST and the C API ``CableDyn_EvalChannel``). ``.static.out``, the range graphs, the per-line files and the C API ``CableDyn_GetLineValues`` list every node of the refined mesh instead, and ``.elements.out`` every element. To find deck node ``J`` among them, diff --git a/doc/troubleshooting.rst b/doc/troubleshooting.rst index 09aa905b..ab6092ed 100644 --- a/doc/troubleshooting.rst +++ b/doc/troubleshooting.rst @@ -779,8 +779,10 @@ Warnings and notes that do not stop a run that length (or, at a rotationally restrained end, on end elements halved toward the end down to its boundary layer). See :doc:`theory`, Static equilibrium. The run uses the refined mesh, statics and dynamics - alike, and its outputs have that many segments (node channels number its nodes, see - :doc:`outputs`). Mesh the line to the bending-length rule to keep the deck mesh. + alike, and its profile and per-line outputs have that many segments; the refinement + only splits deck elements, so the node channels still name deck nodes (see + :ref:`outputs-refined-nodes`). Mesh the line to the bending-length rule to keep the deck + mesh. * - ``Note: line ... starts the dynamics from a static state solved in its vertical plane that is unstable out of that plane on its mesh of ... elements, the coarsest ... m long where half the bending length (EI/|w|)^(1/3) is ... m; ...`` diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index 77732441..926b7a53 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -2877,7 +2877,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, IF (.NOT. has_att) CALL handoff_lateral_note(l0, l0_am, ea_am, ei_am, w_am, w_am, diam, dry_b, fixed_am, .FALSE.) ! Build the coarse Morison arrays, then map every per-element quantity onto the ! refined reference-arc mesh. This covers both global refinement and the local - ! axial-oscillation refinement used by tensile safety. Every child inherits the + ! refinements (the resolution screens, and the axial-oscillation refinement used by + ! tensile safety). Every child inherits the ! property of the original element containing its reference-arc midpoint. ALLOCATE (cdn(SIZE(l0)), cdt(SIZE(l0)), can(SIZE(l0)), cat(SIZE(l0))) CALL finite_hydro_arrays(ln, sections, types, diam, cdn, cdt, can, cat) From d66c256d0049d6102d9dec065e97995b90638be7 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Tue, 20 Oct 2026 09:55:18 +0900 Subject: [PATCH 5/7] test: control span on a locally refined cable The active-tension test of a refined cable, merged from dev, assumed that static refinement splits every deck segment into the same number of cable elements. With local refinement the fairlead-side segment of the test deck becomes 2 of 100 elements, so the count check failed although the span was right. The test now checks that the span is the trailing elements that make up the 40/13 m segment and that it stops at that segment. Signed-off-by: Jae Hoon Seo --- tests/test_openfast_aggregate.f90 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_openfast_aggregate.f90 b/tests/test_openfast_aggregate.f90 index 67e5db9a..5dd249bc 100644 --- a/tests/test_openfast_aggregate.f90 +++ b/tests/test_openfast_aggregate.f90 @@ -3694,8 +3694,12 @@ SUBROUTINE case_aggregate_cable_control() fr = aggr%ctrl_elem(1) WRITE (*, '(A,I0,A,I0,A)') ' cable control span on the refined mesh: ', ner - fr + 1, ' of ', ner, & ' elements' - CALL require(ner > 47 .AND. MOD(ner, 47) == 0 .AND. ner - fr + 1 == ner/47, & + ! static refinement is local, so the children of a segment are not a fixed count: the + ! span is the trailing elements that make up the fairlead-side segment and no more + CALL require(ner > 47 .AND. fr > 1 .AND. fr <= ner, & 'cablectrl: the span is the children of the refined fairlead-side segment') + IF (fr > 1) CALL require(SUM(aggr%cables(1)%line%l0(fr - 1:ner)) > 40.0_wp/13.0_wp*(1.0_wp + 1.0e-9_wp), & + 'cablectrl: the span stops at the fairlead-side segment') CALL require(ABS(SUM(aggr%cables(1)%line%l0(fr:ner)) - 40.0_wp/13.0_wp) <= 1.0e-12_wp*40.0_wp, & 'cablectrl: the refined span is the 40/13 m segment') base = aggr%cables(1)%line%l0 From 84f9096832c10e745c211dc14fbfd518ebc0de9e Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Tue, 20 Oct 2026 16:44:21 +0900 Subject: [PATCH 6/7] test: give the element-limit refinement case room to converge The local-refinement case at the element limit polishes a near-cable line (EI = 1e-2) on about 7000 elements. It converged in 106 Newton iterations on Windows but not within the cap of 120 on the Linux Release runner (residual 3.6). The case checks how the refinement levels are allocated at the limit, not the iteration count, so the cap is now 400, and the test prints the element count, the iterations and the residual of the solve. Signed-off-by: Jae Hoon Seo --- tests/test_hermite_automesh.f90 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_hermite_automesh.f90 b/tests/test_hermite_automesh.f90 index 04c46353..16a1a7e0 100644 --- a/tests/test_hermite_automesh.f90 +++ b/tests/test_hermite_automesh.f90 @@ -532,7 +532,9 @@ SUBROUTINE case_local_element_limit() !! level less everywhere (8x) would leave the sag at h*kappa about 4e-4 with no pass able to !! split it further within the limit; keeping its h*kappa levels and giving the !! bending-length rule one level meets the target in one pass. (The tolerance is the - !! round-off floor of the 6000-element polish.) + !! round-off floor of the 6000-element polish. The near-cable line, EI = 1e-2 on 7000 + !! elements, takes about 106 Newton iterations on one platform and ran past a cap of 120 on + !! another, so the cap is 400: the case checks the level allocation, not the iteration count.) INTEGER, PARAMETER :: NE = 520 REAL(wp), PARAMETER :: TARGET = 3.0e-4_wp REAL(wp), ALLOCATABLE :: l0(:), EA(:), EI(:), w(:), seed(:) @@ -546,10 +548,11 @@ SUBROUTINE case_local_element_limit() EI = 1.0e-2_wp h = l0(1) CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed(1:nfix), seabed_z, 0.0_wp, & - 8, 120, 1.0e-6_wp, 0.7_wp, TARGET, 0.0_wp, 16, [2, 5], & + 8, 400, 1.0e-6_wp, 0.7_wp, TARGET, 0.0_wp, 16, [2, 5], & l0o, EAo, EIo, wo, qo, curvo, fixo, scale, dg, res, its, es, em, & local_refinement=.TRUE.) IF (es /= CD_HCSTAT_OK) WRITE (*, '(A)') ' (local limit automesh error) '//TRIM(em) + WRITE (*, '(A,I0,A,I0,A,ES10.3)') ' local limit: ', SIZE(l0o), ' elements, ', its, ' Newton iterations, |R| ', res CALL check(es == CD_HCSTAT_OK, 'local limit: solve ok') IF (es /= CD_HCSTAT_OK) RETURN CALL check(SIZE(l0o) <= 8192 .AND. SIZE(l0o) > 8*NE, 'local limit: within the limit, beyond 8x') From 01d6411b00ea593f7959b15fc3002771365acb7a Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Tue, 20 Oct 2026 17:18:23 +0900 Subject: [PATCH 7/7] test: reach the refinement element limit on a well-conditioned line The element-limit case of the local refinement needed a string-like line (EI = 1e-2) on about 7000 elements to reach the limit of 8192. Its polish has nearly free folding modes, so the equilibrium it settles on depends on round-off: Windows found the smooth one in 106 Newton iterations, while the Linux Release runner first ran past the cap and, with a larger cap, settled on a folded state that the kink check correctly rejected. CD_HermiteCable_Static_Solve_AutoMesh takes an optional max_elements, a lower element limit than 8192 (the default and every caller are unchanged). The case now refines 60 elements of 1.67 m with EI = 5 under a limit of 900: the bending-length rule asks for 16 children everywhere (960 elements), the elements about the sag keep their 16 by h*kappa and the rest take 8, giving 768 elements in 85 Newton iterations against a cap of 300. Signed-off-by: Jae Hoon Seo --- src/CableDyn_HermiteCableStatic.f90 | 22 +++++++++++++------- tests/test_hermite_automesh.f90 | 32 ++++++++++++++--------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/CableDyn_HermiteCableStatic.f90 b/src/CableDyn_HermiteCableStatic.f90 index 2f21774b..22b34085 100644 --- a/src/CableDyn_HermiteCableStatic.f90 +++ b/src/CableDyn_HermiteCableStatic.f90 @@ -6157,7 +6157,7 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs require_tensile, refine_non_axial, endconn_stiffness, & endconn_direction, endconn_mode, waterline_z, dry_buoyancy, & compression_mode, energy_polish_in, tensile_advisory, water_weight, & - current, local_refinement) + current, local_refinement, max_elements) !! Solve the finite-EI static equilibrium and AUTOMATICALLY select the minimum safe mesh: the !! metric-gated mesh-economics entry. Solve at the caller's (coarse) mesh; if !! CD_HermiteCable_Resolution_Metrics flags it fragile, refine by the recommended power-of-two @@ -6194,6 +6194,9 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs !! energy_polish_in (optional, default false): polish the initial state and every !! prolongated refinement with the trust-region energy minimization of !! CD_HermiteCable_Static_Solve instead of the damped Newton update. + !! max_elements (optional): a lower element limit than AUTO_MAX_ELEMENTS (8192), the most + !! elements a refinement may produce; values outside [1, 8192] use 8192. It lets + !! a test reach the limit on a small, well-conditioned line. !! local_refinement (optional, default false): refine for the curvature, end boundary-layer !! and contact-topology screens element by element instead of globally. A !! pass runs when the same screens fail as for the global refinement; it @@ -6231,6 +6234,7 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs TYPE(CD_HermiteStaticCurrentType), INTENT(IN), OPTIONAL :: current INTEGER, INTENT(IN), OPTIONAL :: compression_mode LOGICAL, INTENT(IN), OPTIONAL :: energy_polish_in, tensile_advisory, local_refinement + INTEGER, INTENT(IN), OPTIONAL :: max_elements INTEGER :: ne, nn, it, scale, parent, j, es, axial_order, bending_order, local_passes, cmode LOGICAL :: energy_polish, advisory @@ -6240,7 +6244,7 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs ! and the per-element h*kappa and isolated contact/gap nodes of the last diagnosis. INTEGER, PARAMETER :: MAX_LOCAL_RESOLUTION_PASSES = 12 LOGICAL :: local_mode, nothing_to_split - INTEGER :: kcap, local_res_passes + INTEGER :: kcap, local_res_passes, element_limit ! What stopped the local refinement short of its targets, other than the per-element cap. CHARACTER(160) :: local_stop INTEGER, ALLOCATABLE :: level_out(:), level_r(:) @@ -6302,6 +6306,10 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs IF (PRESENT(energy_polish_in)) energy_polish = energy_polish_in local_mode = .FALSE. IF (PRESENT(local_refinement)) local_mode = local_refinement + element_limit = AUTO_MAX_ELEMENTS + IF (PRESENT(max_elements)) THEN + IF (max_elements >= 1 .AND. max_elements < AUTO_MAX_ELEMENTS) element_limit = max_elements + END IF local_res_passes = 0 local_stop = '' @@ -6450,7 +6458,7 @@ SUBROUTINE CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed_dofs ! Mesh-scale contact chatter can report rec_scale = 1 (a topology signal), so ! force at least one doubling; never exceed the cumulative cap. scale = MAX(2, diag_out%rec_scale) - DO WHILE ((applied_scale*scale > max_scale .OR. SIZE(l0_out)*scale > AUTO_MAX_ELEMENTS) .AND. scale > 1) + DO WHILE ((applied_scale*scale > max_scale .OR. SIZE(l0_out)*scale > element_limit) .AND. scale > 1) scale = scale/2 END DO IF (scale < 2) EXIT @@ -6813,7 +6821,7 @@ SUBROUTINE local_resolution_mesh(none, esx, emx) !! each limited to kcap bisections from the caller element. The levels are then graded: !! an element is split further while it is longer than max(2, its length ratio to the !! neighbour before the pass) times that neighbour's new length. A pass that would exceed - !! the element limit AUTO_MAX_ELEMENTS gives up first the bending-length levels (one + !! the element limit (element_limit) gives up first the bending-length levels (one !! level at a time, graded), then the grading, and only then takes one level less of the !! h*kappa, end-layer and contact needs at a time: those name a bend or a boundary layer !! the state shows, where the bending-length rule is a mesh-quality rule. none is set @@ -6871,19 +6879,19 @@ SUBROUTINE local_resolution_mesh(none, esx, emx) need = MAX(base, bend - red) CALL grade(need) n_new = SUM(2_I8**need) - fits = n_new <= INT(AUTO_MAX_ELEMENTS, I8) + fits = n_new <= INT(element_limit, I8) IF (fits) EXIT END DO DO red = 0, MAXVAL(base) IF (fits) EXIT need = MAX(base - red, 0) n_new = SUM(2_I8**need) - fits = n_new <= INT(AUTO_MAX_ELEMENTS, I8) + fits = n_new <= INT(element_limit, I8) END DO IF (.NOT. fits .OR. ALL(need == 0)) THEN ! A need was given up to the limit (with no need at all the early return above names ! the per-element cap). - WRITE (local_stop, '(A,I0,A)') 'the element limit ', AUTO_MAX_ELEMENTS, ' was reached' + WRITE (local_stop, '(A,I0,A)') 'the element limit ', element_limit, ' was reached' RETURN END IF none = .FALSE. diff --git a/tests/test_hermite_automesh.f90 b/tests/test_hermite_automesh.f90 index 16a1a7e0..2f2fa6f2 100644 --- a/tests/test_hermite_automesh.f90 +++ b/tests/test_hermite_automesh.f90 @@ -525,18 +525,18 @@ SUBROUTINE case_local_boundary_layer() END SUBROUTINE case_local_boundary_layer SUBROUTINE case_local_element_limit() - !! A pass that would exceed the element limit (8192) gives up bending-length levels before - !! h*kappa levels. 520 elements of 0.19 m with EI = 1e-2 (half the bending length is - !! 2.3 cm) all ask for 16 children by the bending-length rule (8320 elements), and with the - !! h*kappa target 3e-4 the elements about the sag ask for 16 by h*kappa as well. Taking one - !! level less everywhere (8x) would leave the sag at h*kappa about 4e-4 with no pass able to - !! split it further within the limit; keeping its h*kappa levels and giving the - !! bending-length rule one level meets the target in one pass. (The tolerance is the - !! round-off floor of the 6000-element polish. The near-cable line, EI = 1e-2 on 7000 - !! elements, takes about 106 Newton iterations on one platform and ran past a cap of 120 on - !! another, so the cap is 400: the case checks the level allocation, not the iteration count.) - INTEGER, PARAMETER :: NE = 520 - REAL(wp), PARAMETER :: TARGET = 3.0e-4_wp + !! A pass that would exceed the element limit gives up bending-length levels before h*kappa + !! levels. The limit is lowered to 900 (max_elements) so that a small, well-conditioned line + !! reaches it: 60 elements of 1.67 m with EI = 5 (half the bending length is 18 cm) all ask + !! for 16 children by the bending-length rule (960 elements), and with the h*kappa target + !! 3e-3 the elements about the sag ask for 16 by h*kappa as well. Taking one level less + !! everywhere (8x) would leave the sag above the target with no pass able to split it + !! further within the limit; keeping its h*kappa levels and giving the bending-length rule + !! one level meets the target in one pass. (At the default limit of 8192 the same test needs + !! a string-like line on about 7000 elements, whose polish can settle on a folded + !! equilibrium depending on round-off.) + INTEGER, PARAMETER :: NE = 60, LIMIT = 900 + REAL(wp), PARAMETER :: TARGET = 3.0e-3_wp REAL(wp), ALLOCATABLE :: l0(:), EA(:), EI(:), w(:), seed(:) REAL(wp), ALLOCATABLE :: l0o(:), EAo(:), EIo(:), wo(:), qo(:), curvo(:) INTEGER, ALLOCATABLE :: fixed(:), fixo(:) @@ -545,17 +545,17 @@ SUBROUTINE case_local_element_limit() REAL(wp) :: seabed_z, res, h CHARACTER(240) :: em CALL build_rig(NE, l0, EA, EI, w, seed, fixed, nfix, seabed_z) - EI = 1.0e-2_wp + EI = 5.0_wp h = l0(1) CALL CD_HermiteCable_Static_Solve_AutoMesh(l0, EA, EI, w, seed, fixed(1:nfix), seabed_z, 0.0_wp, & - 8, 400, 1.0e-6_wp, 0.7_wp, TARGET, 0.0_wp, 16, [2, 5], & + 8, 300, 1.0e-8_wp, 0.7_wp, TARGET, 0.0_wp, 16, [2, 5], & l0o, EAo, EIo, wo, qo, curvo, fixo, scale, dg, res, its, es, em, & - local_refinement=.TRUE.) + local_refinement=.TRUE., max_elements=LIMIT) IF (es /= CD_HCSTAT_OK) WRITE (*, '(A)') ' (local limit automesh error) '//TRIM(em) WRITE (*, '(A,I0,A,I0,A,ES10.3)') ' local limit: ', SIZE(l0o), ' elements, ', its, ' Newton iterations, |R| ', res CALL check(es == CD_HCSTAT_OK, 'local limit: solve ok') IF (es /= CD_HCSTAT_OK) RETURN - CALL check(SIZE(l0o) <= 8192 .AND. SIZE(l0o) > 8*NE, 'local limit: within the limit, beyond 8x') + CALL check(SIZE(l0o) <= LIMIT .AND. SIZE(l0o) > 8*NE, 'local limit: within the limit, beyond 8x') CALL check(ABS(MINVAL(l0o) - h/16.0_wp) <= 1.0e-12_wp*h, 'local limit: h*kappa needs keep 16 children') CALL check(ABS(MAXVAL(l0o) - h/8.0_wp) <= 1.0e-12_wp*h, 'local limit: bending-length needs give a level') CALL check(dg%h_kappa_peak <= TARGET, 'local limit: h*kappa target met')