diff --git a/CMakeLists.txt b/CMakeLists.txt index 96dcf84c..8073e5a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1794,6 +1794,17 @@ if(Python3_Interpreter_FOUND) TIMEOUT 600 ENVIRONMENT "${_cabledyn_python_test_environment}") + # A heavily damped finite-EI line held at rest completes every step and stays at rest over + # a sweep of the axial damping coefficient and dtM (the damping's residual round-off floor). + add_test(NAME hermite_damped_rest + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_hermite_damped_rest.py + --exe $ + --output ${CMAKE_BINARY_DIR}/hermite_damped_rest) + set_tests_properties(hermite_damped_rest PROPERTIES + LABELS "python;hermite;dynamic;robustness" + TIMEOUT 300 + ENVIRONMENT "${_cabledyn_python_test_environment}") + # Range graphs (LINES flag r) and touchdown channels on every standalone route: envelopes # against the node channels, the analytic catenary TDP, quasi-static tracking under a # moving fairlead, and agreement with cabledyn.touchdown_history (needs numpy). diff --git a/doc/theory.rst b/doc/theory.rst index a16eb76b..c3988d09 100644 --- a/doc/theory.rst +++ b/doc/theory.rst @@ -2317,8 +2317,10 @@ residual decreases; its convergence norm divides each translational residual by frozen at the predictor and each tangent-DOF residual additionally by the nodal tributary length. The force scale is the largest inertial or residual entry, bounded below by 1 N, by the peak element weight, and by the round-off floor -:math:`16\,\epsilon\,\max(EA/L_0)\,x_\text{ref}/\text{tol}` of the axial forces -(:math:`x_\text{ref}` the largest coordinate magnitude or element length). The +:math:`16\,\epsilon\,\max\big((EA + BA\,\gamma/(\beta\,\Delta t))/L_0\big)\,x_\text{ref}/\text{tol}` +of the axial forces (:math:`x_\text{ref}` the largest coordinate magnitude or element length; +the axial damping takes the strain rate from the Newmark velocity, whose rounding is +:math:`\gamma/(\beta\,\Delta t)` times that of the coordinates). The deck defaults are relative tolerance :math:`10^{-8}`, absolute tolerance :math:`10^{-14}`, 30 iterations, and 12 backtracks (option ``dynamic_solver``). Option ``modified_newton`` reuses the factorised tangent within a step while each iterate reduces the residual to at most a quarter diff --git a/src/CableDyn_HermiteCableDynamic.f90 b/src/CableDyn_HermiteCableDynamic.f90 index 2a209e54..388856e4 100644 --- a/src/CableDyn_HermiteCableDynamic.f90 +++ b/src/CableDyn_HermiteCableDynamic.f90 @@ -4828,7 +4828,7 @@ SUBROUTINE eval_res(qcur, use_trial, rn, esx, emx) REAL(wp), POINTER :: Gout(:) INTEGER :: ii, nd INTEGER(INT64) :: ec0, ec1 - REAL(wp) :: xref, xd, xc, ea_r, kt, tw_round + REAL(wp) :: xref, xd, xc, ea_r, ka, kt, tw_round REAL(wp), PARAMETER :: RESID_ROUNDOFF = 16.0_wp REAL(wp), PARAMETER :: STATE_DIVERGED = 1.0e12_wp ec0 = 0_INT64 ! defined even with profiling off (see the step-entry note) @@ -4948,18 +4948,24 @@ SUBROUTINE eval_res(qcur, use_trial, rn, esx, emx) ! whose rounding is (K^2/GJ) eps |r|/l0, so the floor takes the whole axial stiffness ! EA - K^2/GJ + K^2/GJ of the line (without it the floor fell by 1 - K^2/(EA GJ): at ! K = 0.99 sqrt(EA GJ) to 2 % of the rounding it bounds, and a held line failed its step). + ! The axial damping force BA d(|r'|)/dt takes the strain rate from the Newmark velocity, + ! whose rounding is gamma/(beta dt) times that of the coordinates, so the floor adds + ! BA gamma/(beta dt) to the axial stiffness, as the twist floor below adds Bt: without it a + ! held line damped near its first axial mode (BA = 2 zeta EA/omega_1, which at small dt + ! puts the damping term well above EA) stagnated at a residual of a few times the + ! tolerance and failed its step. xref = MAXVAL(model%l0) DO ii = 1, ndof IF (MOD(ii - 1, 6) < 3) xref = MAX(xref, ABS(qcur(ii))) END DO - IF (model%torsion%active .AND. ALLOCATED(model%torsion%couple)) THEN - ea_r = CD_ZERO - DO ii = 1, SIZE(model%l0) - ea_r = MAX(ea_r, (ABS(model%EA(ii)) + model%torsion%couple(ii)**2*model%torsion%gj(ii))/model%l0(ii)) - END DO - ELSE - ea_r = MAXVAL(model%EA/model%l0) - END IF + ea_r = CD_ZERO + DO ii = 1, SIZE(model%l0) + ka = ABS(model%EA(ii)) + IF (model%torsion%active .AND. ALLOCATED(model%torsion%couple)) & + ka = ka + model%torsion%couple(ii)**2*model%torsion%gj(ii) + IF (model%has_axial_damping) ka = ka + ABS(model%BA(ii))*gm/(bt*dt) + ea_r = MAX(ea_r, ka/model%l0(ii)) + END DO fscale = MAX(fscale, RESID_ROUNDOFF*EPSILON(CD_ONE)*ea_r*xref/tol) ! Nodal twist: the torque scale of the angle rows, frozen with fscale and formed like it ! from the nodal loads (a node's torque imbalance, not the torque the line carries, diff --git a/tests/test_hermite_damped_rest.py b/tests/test_hermite_damped_rest.py new file mode 100644 index 00000000..3cd972cc --- /dev/null +++ b/tests/test_hermite_damped_rest.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +"""A heavily damped finite-EI line held at rest stays at rest on every time step. + +A taut 400 m wire (EA = 2.19e9 N, 111 elements) is held at both ends and started from its +static equilibrium. The axial damping coefficient BA is swept over 5e7 to 8e8 N s (2 zeta +EA/omega_1 with zeta from about 0.4 to 6 for its first axial mode, the damping that +``mode1 axialDampingRatio`` gives) and dtM over 0.002, 0.005 and 0.01 s. The damping force +takes the strain rate from the Newmark velocity, whose rounding is gamma/(beta dt) times +that of the coordinates, so at these BA and dtM the residual round-off of a step at rest +lies well above the tolerance on the undamped force scale. Every run must complete (exit +code 0) and keep its end tensions at their static values to 1e-6. + +usage: test_hermite_damped_rest.py --exe --output +""" + +from __future__ import annotations + +import argparse +import os +import subprocess +import sys +from pathlib import Path + +DECK = """--------------------- CableDyn Input File ------------------------------------ +Taut finite-EI line held at rest with a large axial damping coefficient +--------------------- LINE TYPES --------------------------------------- +TypeName Diam Mass EA BA EI Cd_n Cd_t Ca_n Ca_t +(-) (m) (kg/m) (N) (N-s) (N-m2) (-) (-) (-) (-) +wire 0.156 121.7 2.19e9 {ba} 963.0 1.2 0.008 1.0 0.0 +--------------------- POINTS ------------------------------------------- +ID Type X Y Z +(-) (-) (m) (m) (m) +1 Coupled 82.52 80.42 -8.60 +2 Fixed -117.94 395.14 -139.38 +--------------------- LINES -------------------------------------------- +ID NodeA NodeB Outputs +(-) (-) (-) (-) +1 1 2 - +--------------------- SECTIONS ----------------------------------------- +LineID LineType Length NumSegs +(-) (-) (m) (-) +1 wire 400.52 111 +--------------------- OPTIONS ------------------------------------------ +139.38 WtrDpth +2.9e6 kBot +{dt} dtM +{tmax} TMax +--------------------- OUTPUTS ------------------------------------------ +FairTen1 +AnchTen1 +--------------------- need this line ----------------------------------- +""" + +BA = ["5.0e7", "7.0e7", "1.0e8", "1.3e8", "1.6e8", "2.0e8", "3.0e8", "4.0e8", "6.0e8", "8.0e8"] +DT = ["0.002", "0.005", "0.01"] + + +def main() -> int: + ap = argparse.ArgumentParser() + ap.add_argument("--exe", required=True) + ap.add_argument("--output", required=True) + a = ap.parse_args() + out = Path(a.output) + out.mkdir(parents=True, exist_ok=True) + env = dict(os.environ) + env.setdefault("OPENBLAS_NUM_THREADS", "1") + failures = [] + for ba in BA: + for dt in DT: + name = "held_%s_%s" % (ba, dt) + deck = out / (name + ".dat") + deck.write_text(DECK.format(ba=ba, dt=dt, tmax=repr(round(40 * float(dt), 6))), encoding="utf-8", + newline="\n") + root = out / name + p = subprocess.run([a.exe, str(deck), str(root)], capture_output=True, text=True, env=env, + cwd=str(out)) + if p.returncode != 0: + failures.append("BA=%s dtM=%s: exit %d: %s" % (ba, dt, p.returncode, (p.stdout + p.stderr)[-300:])) + continue + rows = Path(str(root) + ".out").read_text(encoding="utf-8").splitlines() + names = rows[1].split() + vals = [[float(v) for v in r.split()] for r in rows[2:] if r.strip()] + if len(vals) != 41: + failures.append("BA=%s dtM=%s: %d output rows, expected 41" % (ba, dt, len(vals))) + continue + for ch in ("FairTen1", "AnchTen1"): + k = names.index(ch) + t0 = vals[0][k] + drift = max(abs(v[k] - t0) for v in vals) / abs(t0) + if drift > 1.0e-6: + failures.append("BA=%s dtM=%s: %s drifts by %.3e of its static value" % (ba, dt, ch, drift)) + print("held damped line: %d runs, %d failures" % (len(BA) * len(DT), len(failures))) + for f in failures: + print("FAIL:", f) + return 1 if failures else 0 + + +if __name__ == "__main__": + sys.exit(main())