diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d2d71f9..5692dfef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1781,6 +1781,21 @@ if(Python3_Interpreter_FOUND) TIMEOUT 900 ENVIRONMENT "${_cabledyn_python_test_environment}") + # A lazy wave on a strongly graded deck mesh (4 m and 10 m elements beside a refined buoyant + # section) in oblique and cross currents: the route is repeated on the mesh refined element by + # element to the bending length, and agrees with the deck on 2 m elements. PROCESSORS reserves + # the four driver processes the test runs at once. + add_test(NAME graded_mesh_statics + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_graded_mesh_statics.py + --exe $ + --data ${CMAKE_CURRENT_SOURCE_DIR}/tests/data + --output ${CMAKE_BINARY_DIR}/graded_mesh_statics) + set_tests_properties(graded_mesh_statics PROPERTIES + LABELS "python;hermite;static;robustness;attachments" + PROCESSORS 4 + TIMEOUT 1500 + 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 61129c2c..7d5c8966 100644 --- a/doc/theory.rst +++ b/doc/theory.rst @@ -1815,7 +1815,13 @@ mesh-sequenced route described below first and this route as its fallback): 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 + budget, on the coarser powers of two down to twice the deck mesh) and, when that fails too, + on the deck mesh with each element split only into the power of two (at most 16) that brings + it to half the bending length. A uniform refinement keeps a graded deck's ratios and refines + its short elements with the long ones: a lazy wave meshed 4 m at its sag bend, 0.9 m over its + buoyant section and 10 m at its touchdown failed in an oblique current on the deck mesh and on + the 8x refined one, and solves on the mesh refined element by element (within 1.2e-3 of its + fairlead tension of the same deck on 2 m elements); a rotationally restrained end whose boundary layer :math:`\sqrt{EI/T}` is shorter than its element, which shows as a polish that does not converge or a compression at that end, repeats it on a mesh graded geometrically toward that end. The refined mesh is reported. diff --git a/doc/troubleshooting.rst b/doc/troubleshooting.rst index 78388c12..203f9e76 100644 --- a/doc/troubleshooting.rst +++ b/doc/troubleshooting.rst @@ -857,7 +857,8 @@ Warnings and notes that do not stop a run 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 + that length, and then on the deck mesh with only its long elements split to 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 profile and per-line outputs have that many segments; the refinement diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index 6aa49a46..cf262c7b 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -1900,6 +1900,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, LOGICAL :: tensile_error CHARACTER(1024) :: note_text CHARACTER(1024) :: limit_text + ! the still-water diagnosis read its compression on elements longer than half the bending length + LOGICAL :: coarse_sw ! The geometric cause of a line with no admissible planar equilibrium clear of the seabed: ! too long to hang as a catenary (net-heavy), or weightless (no catenary exists at all). LOGICAL :: weightless_line @@ -3102,8 +3104,13 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, ! route diagnostics below are bounded and would cut it. A line already compressed ! without the current is named before that: the current starts from that layout. limit_text = '' - IF (opts%has_current) CALL still_water_compression(limit_text) - IF (LEN_TRIM(limit_text) > 0) THEN + IF (opts%has_current) CALL still_water_compression(limit_text, coarse_sw) + IF (LEN_TRIM(limit_text) > 0 .AND. coarse_sw) THEN + CALL fail_solve(ErrStat, ErrMsg, 'finite-EI cable static solve failed in the current: '// & + TRIM(limit_text)//'. Catenary-continuation route: '// & + TRIM(short_message(primary_msg, 360))//'. Mesh-sequenced route: '// & + TRIM(short_message(sequence_msg, 360))); RETURN + ELSE IF (LEN_TRIM(limit_text) > 0) THEN CALL fail_solve(ErrStat, ErrMsg, 'finite-EI cable has no static equilibrium in the current: '// & TRIM(limit_text)//'. Catenary-continuation route: '// & TRIM(short_message(primary_msg, 360))//'. Mesh-sequenced route: '// & @@ -4204,18 +4211,25 @@ SUBROUTINE audit_refined_state(done, why) END IF END SUBROUTINE audit_refined_state - SUBROUTINE still_water_compression(text) + SUBROUTINE still_water_compression(text, coarse) !! On a failed solve in a current: whether the same line without the current is !! already in axial compression (an element-mean force below -1e-3 of the peak !! tension, held only by the bending stiffness). Returns the diagnosis, or blank. + !! coarse: the still-water state is on elements longer than half the bending length + !! (EI/|w|)^(1/3), where the element-mean axial force of a stiff line oscillates and can + !! read a compression the line does not carry; the diagnosis then says so instead of + !! naming the layout (a lazy wave on 4 m and 10 m elements beside 0.9 m ones read + !! -2.8 kN where it carries about +1 kN, and solves on a mesh that resolves its bends). CHARACTER(*), INTENT(OUT) :: text + LOGICAL, INTENT(OUT) :: coarse TYPE(DeckOptions) :: opts_sw TYPE(CD_HFMF_ModuleType) :: sw_cable INTEGER :: sw_node, esw, e_min, wios - REAL(wp) :: t_min, t_max, s_min + REAL(wp) :: t_min, t_max, s_min, need CHARACTER(1024) :: emw CHARACTER(2048) :: sw_note text = '' + coarse = .FALSE. opts_sw = opts opts_sw%has_current = .FALSE. opts_sw%has_current_profile = .FALSE. @@ -4235,10 +4249,21 @@ SUBROUTINE still_water_compression(text) CALL CD_HermiteCable_Mean_Axial_Extremes(sw_cable%line%l0, sw_cable%line%EA, sw_cable%line%q, t_min, & t_max, e_min, s_min, esw, emw) IF (esw == CD_HCSTAT_OK .AND. t_min < -1.0e-3_wp*t_max) THEN - WRITE (text, '(A,ES10.3,A,F10.2,A,ES10.3,A)', IOSTAT=wios) 'the line is already in axial '// & - 'compression without the current (element mean ', t_min, ' N at unstretched arc length ', & - s_min, ' m from the anchor, peak tension ', t_max, ' N), a layout that only its bending '// & - 'stiffness holds; the current pushes that layout further and no equilibrium follows it' + need = bending_refine_need(sw_cable%line%l0, sw_cable%line%EI, sw_cable%line%w) + coarse = need > CD_ONE + IF (coarse) THEN + WRITE (text, '(A,ES10.3,A,F10.2,A,ES10.3,A,F6.2,A)', IOSTAT=wios) 'without the current the line '// & + 'reads an element-mean axial compression (', t_min, ' N at unstretched arc length ', s_min, & + ' m from the anchor, peak tension ', t_max, ' N) on elements up to ', need, ' times half the '// & + 'bending length (EI/|w|)^(1/3), where the element-mean axial force of a stiff line oscillates '// & + 'and can read a compression the line does not carry; refine those elements (NumSegs) to half '// & + 'the bending length or less' + ELSE + WRITE (text, '(A,ES10.3,A,F10.2,A,ES10.3,A)', IOSTAT=wios) 'the line is already in axial '// & + 'compression without the current (element mean ', t_min, ' N at unstretched arc length ', & + s_min, ' m from the anchor, peak tension ', t_max, ' N), a layout that only its bending '// & + 'stiffness holds; the current pushes that layout further and no equilibrium follows it' + END IF END IF END IF CALL CD_HFMF_End(sw_cable) @@ -6997,9 +7022,119 @@ RECURSIVE SUBROUTINE graded_restart() END SUBROUTINE graded_restart RECURSIVE SUBROUTINE refined_restart() - !! Repeat the route on a uniformly refined mesh (power of two, capped) when the - !! deck mesh is longer than half the bending length (EI/|w|)^(1/3) somewhere. The + !! Repeat the route on a refined mesh when the deck mesh is longer than half the bending + !! length (EI/|w|)^(1/3) somewhere: uniformly refined (uniform_restart), then, when that + !! fails, with each element split only as far as the rule asks of it (rule_restart). The !! refined equilibrium is returned in the *_am outputs like an adaptive refinement. + CALL uniform_restart() + IF (ErrStat /= CD_HCSTAT_OK .AND. .NOT. inadmissible) CALL rule_restart() + END SUBROUTINE refined_restart + + RECURSIVE SUBROUTINE rule_restart() + !! Repeat the route on the deck mesh with every element split into the power of two + !! (capped) that brings it to half its bending length (EI/|w|)^(1/3), the elements that + !! meet the rule kept. A uniform refinement by the largest factor keeps the deck's grading + !! and refines the short elements beside the long ones as well: on a lazy wave meshed + !! 4 m / 0.9 m / 10 m (the buoyant section refined, the sag bend and the touchdown + !! coarse) the long elements' axial force oscillated into compression beside the short + !! ones, the 8x refined mesh stalled at the start of its stiffness continuation, and the + !! deck failed in an oblique current although the same layout solves on 2 m elements. + !! Not run when the rule asks the same factor of every element (the uniform refinement + !! was that mesh) or more than REFINED_MAX_ELEMENTS elements. + INTEGER, PARAMETER :: REFINED_MAX_ELEMENTS = 4096 + REAL(wp), ALLOCATABLE :: l0_g(:), ea_g(:), ei_g(:), w_g(:), diam_g(:), dry_g(:) + INTEGER, ALLOCATABLE :: fixed_g(:), parent_g(:), node_of(:), split(:) + LOGICAL, ALLOCATABLE :: fixed_map(:, :) + LOGICAL :: planar, inadm_g, walked_sub + INTEGER :: k, j, n_g, nf, es_g, slot, piece + REAL(wp) :: need + CHARACTER(1024) :: em_g + IF (PRESENT(refined_pass) .OR. fold) RETURN + ALLOCATE (split(ne)) + split = 1 + DO k = 1, ne + IF (.NOT. (ei(k) > CD_ZERO .AND. ABS(w(k)) > CD_ZERO)) CYCLE + need = l0(k)/(0.5_wp*(ei(k)/ABS(w(k)))**(CD_ONE/3.0_wp)) + DO WHILE (REAL(split(k), wp) < need .AND. split(k) < CD_HC_REFINE_CAP) + split(k) = 2*split(k) + END DO + END DO + IF (ALL(split == 1)) RETURN + IF (ALL(split == MAXVAL(split))) RETURN + n_g = SUM(split) + IF (n_g > REFINED_MAX_ELEMENTS) RETURN + ALLOCATE (l0_g(n_g), parent_g(n_g), node_of(nnode)) + j = 0 + node_of(1) = 1 + DO k = 1, ne + DO piece = 1, split(k) + j = j + 1 + l0_g(j) = l0(k)/REAL(split(k), wp) + parent_g(j) = k + END DO + node_of(k + 1) = j + 1 + END DO + ALLOCATE (ea_g(n_g), ei_g(n_g), w_g(n_g), diam_g(n_g), dry_g(n_g)) + ea_g = ea(parent_g); ei_g = ei(parent_g); w_g = w(parent_g) + diam_g = diam(parent_g); dry_g = dry_b(parent_g) + ! Held DOFs: the deck nodes keep theirs; inserted nodes take the out-of-plane reduction + ! (y, m_y) when the deck holds it on every node (as graded_restart). + ALLOCATE (fixed_map(6, nnode)) + fixed_map = .FALSE. + DO k = 1, SIZE(fixed_dofs) + fixed_map(MOD(fixed_dofs(k) - 1, 6) + 1, (fixed_dofs(k) - 1)/6 + 1) = .TRUE. + END DO + planar = ALL(fixed_map(2, :)) + ALLOCATE (fixed_g(6*(n_g + 1))) + nf = 0 + k = 1 + DO j = 1, n_g + 1 + IF (k <= nnode) THEN + IF (node_of(k) == j) THEN + DO slot = 1, 6 + IF (fixed_map(slot, k)) THEN + nf = nf + 1; fixed_g(nf) = 6*(j - 1) + slot + END IF + END DO + k = k + 1 + CYCLE + END IF + END IF + IF (planar) THEN + nf = nf + 1; fixed_g(nf) = 6*(j - 1) + 2 + nf = nf + 1; fixed_g(nf) = 6*(j - 1) + 5 + END IF + END DO + IF (PRESENT(bathymetry)) THEN + CALL hermite_static_primary(anchor, fairlead, l0_g, ea_g, ei_g, w_g, diam_g, dry_g, fixed_g(1:nf), & + contact_enabled, contact_z, frame_cs, endconn_k, endconn_d0, endconn_mode, & + opts, static_tol, l0_am, ea_am, ei_am, w_am, q_static, curv, fixed_am, & + applied_scale, diag, res, iters, es_g, em_g, inadm_g, tolerance_note, & + kink_refined, bathymetry=bathymetry, refined_pass=.TRUE., cur_obj=cur_obj, & + walked=walked_sub, fold_walk=fold) + ELSE + CALL hermite_static_primary(anchor, fairlead, l0_g, ea_g, ei_g, w_g, diam_g, dry_g, fixed_g(1:nf), & + contact_enabled, contact_z, frame_cs, endconn_k, endconn_d0, endconn_mode, & + opts, static_tol, l0_am, ea_am, ei_am, w_am, q_static, curv, fixed_am, & + applied_scale, diag, res, iters, es_g, em_g, inadm_g, tolerance_note, & + kink_refined, refined_pass=.TRUE., cur_obj=cur_obj, walked=walked_sub, & + fold_walk=fold) + END IF + IF (es_g == CD_HCSTAT_OK) THEN + ErrStat = CD_HCSTAT_OK + ErrMsg = '' + kink_refined = .TRUE. + inadmissible = .FALSE. + IF (PRESENT(walked)) walked = walked_sub + ELSE + ErrMsg = TRIM(ErrMsg)//'; on the mesh refined element by element to the bending length: '//TRIM(em_g) + IF (inadm_g) inadmissible = .TRUE. + END IF + END SUBROUTINE rule_restart + + RECURSIVE SUBROUTINE uniform_restart() + !! The route on a uniformly refined mesh (power of two, capped) when the deck mesh is + !! longer than half the bending length somewhere (refined_restart). REAL(wp), ALLOCATABLE :: l0_r(:), q_r(:), q_ref_r(:), ea_r(:), ei_r(:), w_r(:), diam_r(:), dry_r(:) INTEGER, ALLOCATABLE :: fixed_r(:) INTEGER :: scale, scale_need, k, es_r, parent @@ -7065,7 +7200,7 @@ RECURSIVE SUBROUTINE refined_restart() IF (INDEX(em_r, 'iteration budget') == 0) RETURN scale = scale/2 END DO - END SUBROUTINE refined_restart + END SUBROUTINE uniform_restart SUBROUTINE polish_with_floor() !! Polish at the tight tolerance; accept the coupled static tolerance when the diff --git a/tests/test_graded_mesh_statics.py b/tests/test_graded_mesh_statics.py new file mode 100644 index 00000000..7c59b4fc --- /dev/null +++ b/tests/test_graded_mesh_statics.py @@ -0,0 +1,137 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +"""A finite-EI lazy wave on a strongly graded deck mesh solves in an oblique or cross current. + +The frictional lazy wave of ``tests/data/lazy_wave_touchdown_planar_coarse_att.dat`` keeps the +deck's 4 m elements at its sag bend and 10 m elements at its touchdown, longer than half its +bending length (EI/|w|)^(1/3) = 2.5 m, while its buoyant section (10 or 25 modules over 96 m) is +refined r times. With r = 4 (0.9 m and 1 m elements beside the 4 m and 10 m ones) the static solve +in 0.2 to 0.5 m/s at 45 or 90 deg to the line's plane failed with "the line is already in axial +compression without the current": every route stopped on the deck mesh, and its uniform refinement +by the largest factor (8x, which keeps the grading and refines the short elements as well) stalled +at the start of its stiffness continuation, although the same layout solves on 2 m elements. The +route is now repeated on the mesh refined element by element to the bending-length rule. + +Gates, on the driver's own output: every deck (grading ratios from r = 2 to r = 8, the six r = 4 +decks that failed) exits 0 without a fallback note ("reached after a failed Newton solve", +"stalled", "looser tolerance"), its mean out-of-plane offset has the sign of the current's cross +component, and two of the r = 4 decks agree with the same deck on 2 m elements throughout to +2e-3 of the fairlead tension in every end-force channel. + +usage: test_graded_mesh_statics.py --exe --data --output +""" + +from __future__ import annotations + +import argparse +import math +import re +import subprocess +import sys +from concurrent.futures import ThreadPoolExecutor +from pathlib import Path + +FALLBACK_NOTES = ("reached after a failed Newton solve", "stalled", "looser tolerance") +REFERENCE_TOL = 2.0e-3 +# (speed m/s, heading deg from the line's plane, modules, buoyant-section refinement) +CASES = [ + (0.2, 45, 10, 4), + (0.3, 45, 10, 4), + (0.2, 90, 10, 4), + (0.5, 45, 10, 4), + (0.2, 45, 25, 4), + (0.3, 45, 25, 4), + (0.3, 45, 10, 2), + (0.3, 45, 10, 8), +] +# cases compared with the same deck on 2 m elements throughout +REFERENCED = [(0.3, 45, 10, 4), (0.2, 45, 25, 4)] + + +def deck(data: Path, speed: float, heading: float, n_mod: int, refine: int, fine: bool) -> str: + """The frictional lazy wave with n_mod modules over 80-176 m (the deck's totals).""" + text = (data / "lazy_wave_touchdown_planar_coarse_att.dat").read_text() + pitch = 96.0 / (n_mod - 1) + per_pitch = max(1, round(pitch / 4.0)) + g = 2 if fine else 1 + rows = "4 bare 80.0 %d\n4 bare 96.0 %d\n4 bare 424.0 %d\n" % ( + 20 * g, (n_mod - 1) * per_pitch * refine * g, 170 if fine else 42) + text = re.sub(r"(-+ SECTIONS -+\n.*\n.*\n)(?:4 .*\n)+", lambda m: m.group(1) + rows, text) + s = 25.0 / n_mod + att = "4 80.0:%.10g:176.0 %.6g %.6g %.6g 1.0 0.0\n" % (pitch, 91.32 * s, 0.18378 * s, 1.392 * s) + text = re.sub(r"(-+ ATTACHMENTS -+\n.*\n.*\n)(?:4 .*\n)+", lambda m: m.group(1) + att, text) + th = math.radians(heading) + ux, uy = round(speed * math.cos(th), 12) + 0.0, round(speed * math.sin(th), 12) + 0.0 + text = re.sub(r"^(0\.0 TMax)$", lambda m: m.group(1) + "\nuniform %.12g %.12g 0.0 current" % (ux, uy), + text, count=1, flags=re.M) + text = text.replace("FairTen4\n", "FairTen4\nAnchTen4\n" + "".join( + "Point%d%s\n" % (p, c) for p in (7, 8) for c in ("Fx", "Fy", "Fz"))) + return text + + +def run(exe: str, d: Path, text: str) -> tuple[int, str, dict, float]: + d.mkdir(parents=True, exist_ok=True) + (d / "deck.dat").write_text(text, newline="\n") + p = subprocess.run([exe, "deck.dat", "o"], cwd=d, capture_output=True, text=True, timeout=1800) + row, y = {}, float("nan") + if p.returncode == 0: + lines = [ln for ln in (d / "o.out").read_text().splitlines() if not ln.startswith("#")] + row = dict(zip(lines[0].split(), (float(v) for v in lines[1].split()))) + prof = (d / "o.static.out").read_text().splitlines()[3:] + ys = [float(ln.split()[4]) for ln in prof if ln.strip()] + y = sum(ys) / len(ys) + return p.returncode, p.stdout + p.stderr, row, y + + +def main() -> int: + ap = argparse.ArgumentParser() + ap.add_argument("--exe", required=True) + ap.add_argument("--data", required=True) + ap.add_argument("--output", required=True) + ap.add_argument("--jobs", type=int, default=4) + a = ap.parse_args() + exe = str(Path(a.exe).resolve()) + data, out = Path(a.data), Path(a.output) + jobs = [(c, False) for c in CASES] + [(c, True) for c in REFERENCED] + + def one(job): + (speed, heading, n_mod, refine), fine = job + name = "%s_U%.1f_h%d_N%d_r%d" % (("fine" if fine else "graded"), speed, heading, n_mod, refine) + return job, name, run(exe, out / name, deck(data, speed, heading, n_mod, refine, fine)) + + with ThreadPoolExecutor(a.jobs) as pool: + results = list(pool.map(one, jobs)) + rows = {} + failures = [] + for (case, fine), name, (rc, log, row, y) in results: + notes = [n for n in FALLBACK_NOTES if n in log] + print("%-24s exit %d fallback notes %s FairTen %s mean y %+.4f m" % + (name, rc, notes or "none", "%.1f N" % row["FairTen4"] if row else "-", y)) + rows[(case, fine)] = row + if rc != 0: + failures.append("%s: exit %d\n%s" % (name, rc, log[-1500:])) + elif notes: + failures.append("%s: the static solve needed a fallback (%s)" % (name, ", ".join(notes))) + elif not y > 0.0: + failures.append("%s: mean out-of-plane offset %.3e m against the cross current" % (name, y)) + for case in REFERENCED: + g, f = rows.get((case, False)), rows.get((case, True)) + if not g or not f: + continue + err = max(abs(g[c] - f[c]) for c in f if c != "Time(s)") / f["FairTen4"] + print("U %.1f h %d N %d r %d: graded against 2 m mesh, largest end-force difference %.2e of FairTen" % + (case + (err,))) + if not err <= REFERENCE_TOL: + failures.append("U %.1f h %d N %d r %d: the graded deck misses the 2 m mesh by %.2e of FairTen" % + (case + (err,))) + for f in failures: + print("FAIL: " + f) + if failures: + return 1 + print("PASS: the lazy wave on a graded deck mesh solves in oblique and cross currents") + return 0 + + +if __name__ == "__main__": + sys.exit(main())