From b8d1e2f5252b20c4af8eae83f8e2b34df96c378a Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Sun, 8 Nov 2026 15:56:41 +0900 Subject: [PATCH] fix(recovery): spread the touchdown node's floor reaction over its grounded stretch The equilibrium recovery of the finite-EI node outputs spreads each nodal seabed reaction over the grounded half-elements beside the node. The touchdown element, on the floor at one end only, took none of the first grounded node's reaction, wherever the touchdown point lay in it. The node tension next to touchdown then carried a local error that depended on that position and fell only at the first order with the element length: at most 4.3, 1.9, 1.0 and 0.42 N at 1.6, 0.8, 0.4 and 0.2 m elements on a lazy-wave cable at 270 N. The share also switched when a node grounded, so the node outputs stepped by up to about 1 N in a quasi-static march as the touchdown point crossed a node. The touchdown element is now grounded from its grounded node to the touchdown point, where the clearance interpolated linearly between its two nodes reaches the contact onset height (at most its half), and takes the reaction of that stretch: a node's reaction is spread uniformly over the grounded part of its two half-elements and shared by that length. The stretch reaches the half-element as the suspended node reaches the floor and vanishes with the reaction as the grounded node lifts off, so the outputs vary continuously. The local error now falls at the second order (2.1, 0.7, 0.2, 0.05 N). The solution, the end forces and the touchdown channels are unchanged. driver_touchdown_convergence sweeps nine meshes at each of three element sizes so that the touchdown point falls at every position in its element, and requires the local error to fall by at least 2.5 from 0.8 to 0.4 m elements and to stay below 0.35 N there; it fails on the previous recovery (ratio 1.89, 1.0 N). Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 11 ++ CMakeLists.txt | 13 ++- doc/outputs.rst | 13 +++ doc/theory.rst | 21 +++- src/CableDyn_HermiteCableDynamic.f90 | 113 +++++++++++++------- tests/check_touchdown_convergence.py | 149 +++++++++++++++++++++++++++ 6 files changed, 278 insertions(+), 42 deletions(-) create mode 100644 tests/check_touchdown_convergence.py diff --git a/CHANGELOG.md b/CHANGELOG.md index b6df6ab8..e3549554 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,17 @@ All notable changes to CableDyn are recorded in this file. The format follows ## [Unreleased] +### Fixed + +- Finite-EI node tension, curvature and bend moment next to the touchdown point: the floor + reaction of the first grounded node was spread over its grounded half-element alone, wherever + the touchdown point lay in the touchdown element. The local tension error there fell only at + the first order with the element length (4.3, 1.9, 1.0 N at 1.6, 0.8, 0.4 m elements on a + lazy-wave cable at 270 N) and the node outputs stepped as each node grounded or lifted off. + The touchdown element now takes the reaction of its grounded stretch, from the grounded node + to the touchdown point located from the two nodes' clearances: the error falls at the second + order (2.1, 0.7, 0.2 N) and the outputs vary continuously. + ## [0.4.1] - 2026-11-08 ### Added diff --git a/CMakeLists.txt b/CMakeLists.txt index aebdc15a..b2b4b1fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2779,13 +2779,24 @@ if(Python3_Interpreter_FOUND) ENVIRONMENT "${_cabledyn_python_test_environment}") # Node tension through touchdown on a coarse mesh (10 m grounded elements) follows a four # times finer reference within 3.5 %: the touchdown element, grounded at one end only, takes - # no share of its grounded node's floor reaction. + # the floor reaction of its grounded stretch alone, not half an element's. add_test(NAME driver_touchdown_recovery COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/check_touchdown_recovery.py $) set_tests_properties(driver_touchdown_recovery PROPERTIES LABELS "python;driver;integration;static" ENVIRONMENT "${_cabledyn_python_test_environment}") + # Node tension at touchdown converges at second order wherever the touchdown point falls in + # its element: the local error over a sweep of meshes at 1.6, 0.8 and 0.4 m elements falls + # by at least 2.5 from 0.8 to 0.4 m and stays below 0.35 N there (the touchdown element takes + # the floor reaction of its grounded stretch). + add_test(NAME driver_touchdown_convergence + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/check_touchdown_convergence.py + $) + set_tests_properties(driver_touchdown_convergence PROPERTIES + LABELS "python;driver;integration;static" + TIMEOUT 600 + ENVIRONMENT "${_cabledyn_python_test_environment}") # A hang-off through a tapered bend stiffener follows the planar elastica (scipy solve_bvp) # within 2 % of the root moment and 1 cm, and node by node on a sweep of element sizes within # 0.5 % of the local curvature on 0.1 m elements; skipped where scipy is not installed. diff --git a/doc/outputs.rst b/doc/outputs.rst index 0cb33a4d..f2b132e1 100644 --- a/doc/outputs.rst +++ b/doc/outputs.rst @@ -841,6 +841,19 @@ the channels report that end node (and ``TDPGrd`` reads 0); when the whole li seabed, the suspended end node. ``TDPGrd`` is the grounded length of the `Anchor uplift`_ check. +The seabed carries the line at its nodes, so the mesh at touchdown sets how finely the touchdown +point and the tension around it are resolved: a node lands on the floor at once, and in a +dynamic run its landing shakes the line. The node tension near touchdown converges at the second +order in the element length there. On the lazy-wave cable of +``lozon_gomex80_power_cable_motion.dat`` (bending length :math:`\sqrt{EI/T}` = 3.9 m at +touchdown, tension 1.3 to 1.9 kN) it departs from a 1024-element solution by at most 140, 55, +19 and 5.8 N with 3.3, 1.6, 0.8 and 0.4 m elements at touchdown over the heave cycle (time step +0.0125 s), and by 4.6, 1.0 and 0.25 N in the static state with 3.3, 1.6 and 0.8 m elements; on +the 3.3 m mesh ``TDPs`` moves at up to 4 m/s while a node lands (0.7 m/s converged) and its +lowest value differs from the converged one by 0.6 m. Elements no longer than about a fifth of +:math:`\sqrt{EI/T}` at touchdown keep the node tension there within about 1.5 % of the +converged value through the motion, and a tenth within 0.5 %. + Point channels ~~~~~~~~~~~~~~ diff --git a/doc/theory.rst b/doc/theory.rst index 7b45a636..6db8e69f 100644 --- a/doc/theory.rst +++ b/doc/theory.rst @@ -314,11 +314,22 @@ end residual holds only the element's own distributed loads: consistent submerged weight, the buoyancy lost above the free surface, drag, Froude-Krylov force, structural and added-mass inertia, and the -seabed reaction of its end nodes, each nodal reaction spread uniformly over the node's tributary -length (the distributed floor reaction it stands for; without it a line resting on the floor -would report the fixed-end moment :math:`w L_0^2/12` of its own weight; at a held line end whose -end element lies on the floor, the reaction of the end half is the floor-support share of the -weight, the share that the static and dynamic residuals carry on the end tangent rows). +seabed reaction of its end nodes, each nodal reaction spread uniformly over the grounded part of +the node's tributary length (the distributed floor reaction it stands for; without it a line +resting on the floor would report the fixed-end moment :math:`w L_0^2/12` of its own weight; at a +held line end whose end element lies on the floor, the reaction of the end half is the +floor-support share of the weight, the share that the static and dynamic residuals carry on the +end tangent rows). A half-element whose far node is on the floor is grounded whole; the +touchdown element, on the floor at one end only, is grounded from that end to the touchdown +point, where the clearance interpolated linearly between its two nodes reaches the contact onset +height (at most its half). The grounded stretch reaches the half-element as the suspended node +reaches the floor, and vanishes with the reaction as the grounded node lifts off, so the node +outputs vary continuously as nodes ground and lift off. With the reaction of the first grounded +node spread over its grounded half-element alone, the tension near touchdown carried a local +error that depended on where the touchdown point fell in its element and fell only at the first +order (at most 4.3, 1.9 and 1.0 N at 1.6, 0.8 and 0.4 m elements on the lazy-wave cable of +``lazy_wave_buoyancy_smeared.dat``, line tension 270 N there; 2.1, 0.7 and 0.2 N with the +grounded stretch), and it stepped as each node grounded. :math:`\mathbf{g}_e` is the generalised force the two end nodes exert on the element: its position rows at the End-B side of the internal arc are the section force :math:`\mathbf{F}_j^-` just before node diff --git a/src/CableDyn_HermiteCableDynamic.f90 b/src/CableDyn_HermiteCableDynamic.f90 index c711a155..fb32e362 100644 --- a/src/CableDyn_HermiteCableDynamic.f90 +++ b/src/CableDyn_HermiteCableDynamic.f90 @@ -7257,15 +7257,18 @@ PURE FUNCTION unit_tangent(model, node) RESULT(t) END IF END FUNCTION unit_tangent - SUBROUTINE node_contact_normal(model, node, fc, ErrStat, ErrMsg) + SUBROUTINE node_contact_normal(model, node, fc, ErrStat, ErrMsg, clearance) !! Frictionless seabed contact force on a node at the committed state, exactly as !! assemble_contact applies it: the normal force with its damping and, in a rounded crease !! of the bathymetry, the elastic increment of the penalty potential (crease_contact_increment). + !! clearance is the node's normal distance above the height at which the contact law engages: + !! negative on the floor, positive above it. TYPE(CD_HermiteCableDynType), INTENT(IN) :: model INTEGER, INTENT(IN) :: node REAL(wp), INTENT(OUT) :: fc(3) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), INTENT(OUT), OPTIONAL :: clearance REAL(wp) :: z_floor, gx, gy, xg, yg, gxg, gyg, sfac, nvec(3), gap, normal, normal_gap, vn, gate, gate_gap REAL(wp) :: curv_g(3), fcrease(3), kcrease(3, 3) INTEGER :: iz, es @@ -7273,6 +7276,7 @@ SUBROUTINE node_contact_normal(model, node, fc, ErrStat, ErrMsg) CHARACTER(200) :: em2 ErrStat = CD_HCDYN_OK; ErrMsg = '' fc = CD_ZERO + IF (PRESENT(clearance)) clearance = HUGE(CD_ONE) iz = 6*(node - 1) + 3 IF (model%has_contact) THEN z_floor = model%seabed_z @@ -7293,6 +7297,7 @@ SUBROUTINE node_contact_normal(model, node, fc, ErrStat, ErrMsg) sfac = SQRT(CD_ONE + gx*gx + gy*gy) nvec = [-gx, -gy, CD_ONE]/sfac gap = (z_floor - model%q(iz))/sfac + IF (PRESENT(clearance)) clearance = -gap - CD_SEABED_CONTACT_BLEND CALL CD_Seabed_Normal_Law(gap, model%contact_kn(node), normal, normal_gap) CALL CD_Seabed_Contact_Gate(gap, gate, gate_gap) IF (normal <= CD_ZERO .AND. gate <= CD_ZERO) RETURN @@ -7308,6 +7313,7 @@ SUBROUTINE node_contact_normal(model, node, fc, ErrStat, ErrMsg) END IF ELSE IF (model%kn > CD_ZERO) THEN gap = model%seabed_z - model%q(iz) + IF (PRESENT(clearance)) clearance = -gap IF (gap > CD_ZERO) fc(3) = model%kn*gap*model%trib(node) END IF END SUBROUTINE node_contact_normal @@ -7364,7 +7370,7 @@ SUBROUTINE element_end_residual(model, e, g, ErrStat, ErrMsg) INTEGER, PARAMETER :: ZS(4) = [3, 6, 9, 12] REAL(wp) :: qe(12), ve(12), ae(12), fe(12), fx(12), energy, fdry(4), kdry(4, 4) REAL(wp) :: dry_wl, dry_b, dry_r, hf_mid(3), l0, fca(3), fcb(3), c, a4(4), m4(4, 4) - REAL(wp) :: support(3), dsupport(3), nin(3) + REAL(wp) :: support(3), dsupport(3), nin(3), xa, xb, ca(4), cb(4) INTEGER :: es, k, inode LOGICAL :: dry CHARACTER(200) :: em2 @@ -7465,20 +7471,22 @@ SUBROUTINE element_end_residual(model, e, g, ErrStat, ErrMsg) ! Seabed contact acts at the nodes; spread over the grounded line next to each node it is the ! distributed floor reaction it stands for. Its consistent share is taken out of the element, ! so a line resting on the floor carries no fixed-end moment of its own weight. A node's - ! reaction is shared by the half-elements beside it whose far node is on the floor as well - ! (grounded elements), by length. The touchdown element, on the floor at one end only, is - ! mostly suspended and takes none of it; spreading the reaction onto it understated the - ! tension of the last suspended node by the floor reaction of half an element (5 % on a - ! 10 m lazy-wave mesh). A node with no grounded element beside it (a node just touching - ! down, or an isolated contact) shares its reaction by tributary length. + ! reaction is spread uniformly over the grounded part of its two half-elements and shared + ! between them by that length (grounded_share). The touchdown element, on the floor at one + ! end only, is grounded from that end to the touchdown point, located on it from the two + ! nodes' clearances; it takes the reaction of that stretch alone (spreading the reaction over + ! its half understated the tension of the last suspended node by the floor reaction of half + ! an element, 5 % on a 10 m lazy-wave mesh). The grounded stretch grows to the half-element + ! as the suspended node reaches the floor, so the spread, and the node outputs, change + ! continuously as nodes ground and lift off. IF (model%has_contact .OR. model%kn > CD_ZERO) THEN CALL node_contact_normal(model, e, fca, es, em2) IF (es /= CD_HCDYN_OK) GOTO 900 CALL node_contact_normal(model, e + 1, fcb, es, em2) IF (es /= CD_HCDYN_OK) GOTO 900 - CALL grounded_share(e, e, fca, es) + CALL grounded_share(e, e, fca, xa, es) IF (es /= CD_HCDYN_OK) GOTO 900 - CALL grounded_share(e + 1, e, fcb, es) + CALL grounded_share(e + 1, e, fcb, xb, es) IF (es /= CD_HCDYN_OK) GOTO 900 ! A held end whose end element lies on the floor (assemble_residual): the seabed carries the ! element's weight with its consistent end moment, which the held end node's own contact @@ -7486,18 +7494,23 @@ SUBROUTINE element_end_residual(model, e, g, ErrStat, ErrMsg) ! end half of that element is the support share of its weight, uniform with the reaction ! of the neighbouring node, so that a laid end element carries no fixed-end moment. IF (e == 1) THEN - IF (held_end_floor_support(model, model%q, 1, support, dsupport, inode, nin)) & - fca = (model%w(1)*l0)*support + IF (held_end_floor_support(model, model%q, 1, support, dsupport, inode, nin)) THEN + fca = (0.5_wp*model%w(1)*l0)*support; xa = 0.5_wp + END IF END IF IF (e == model%ne) THEN - IF (held_end_floor_support(model, model%q, 2, support, dsupport, inode, nin)) & - fcb = (model%w(e)*l0)*support + IF (held_end_floor_support(model, model%q, 2, support, dsupport, inode, nin)) THEN + fcb = (0.5_wp*model%w(e)*l0)*support; xb = 0.5_wp + END IF END IF - ! integrals of the four shapes over xi in [0, 1/2] (fca) and [1/2, 1] (fcb) - g(1:3) = g(1:3) - (0.40625_wp*fca + 0.09375_wp*fcb) - g(4:6) = g(4:6) - l0*(0.0572916666666666667_wp*fca + 0.0260416666666666667_wp*fcb) - g(7:9) = g(7:9) - (0.09375_wp*fca + 0.40625_wp*fcb) - g(10:12) = g(10:12) + l0*(0.0260416666666666667_wp*fca + 0.0572916666666666667_wp*fcb) + ! the loads fca and fcb spread uniformly over xi in [0, xa] and [1 - xb, 1]: the integrals + ! of the four shapes over those stretches per unit length of xi (spread_shapes) + ca = spread_shapes(xa) + cb = spread_shapes(xb) + g(1:3) = g(1:3) - (ca(1)*fca + cb(3)*fcb) + g(4:6) = g(4:6) - l0*(ca(2)*fca - cb(4)*fcb) + g(7:9) = g(7:9) - (ca(3)*fca + cb(1)*fcb) + g(10:12) = g(10:12) - l0*(ca(4)*fca - cb(2)*fcb) END IF ae(1:6) = model%a(6*(e - 1) + 1:6*e); ae(7:12) = model%a(6*e + 1:6*(e + 1)) IF (ANY(ABS(ae) > CD_ZERO)) THEN @@ -7529,40 +7542,68 @@ SUBROUTINE element_end_residual(model, e, g, ErrStat, ErrMsg) CONTAINS - SUBROUTINE grounded_share(node, el, fc, esx) - !! Scale the floor reaction fc of node (an end of element el) to el's share of it, as the - !! factor l0(el)/(grounded length beside the node) that the half-element shape integrals - !! below expect: zero when el is not grounded but another element beside the node is, the - !! tributary-length share when no element beside the node is grounded. + SUBROUTINE grounded_share(node, el, fc, x, esx) + !! Element el's share of the floor reaction fc of node (an end of el), and the grounded + !! stretch x of el's half beside the node (a fraction of el, at most 1/2) that it is + !! spread over. Each half-element beside the node is grounded over x = 1/2 when its far + !! node is on the floor as well, and otherwise up to the touchdown point, where the + !! clearance interpolated linearly between the node (on the floor) and the far node (above + !! it) reaches the contact onset; the reaction is shared between the two halves by the + !! grounded length x l0. The touchdown point reaches the far node as that node reaches + !! the floor and the node itself as it lifts off (its reaction then vanishing), so the + !! share and the stretch are continuous in the configuration. A node off the floor with a + !! reaction (a held end the floor supports) keeps the tributary-length share over the + !! half-element. INTEGER, INTENT(IN) :: node, el REAL(wp), INTENT(INOUT) :: fc(3) + REAL(wp), INTENT(OUT) :: x INTEGER, INTENT(OUT) :: esx - REAL(wp) :: grounded_len - LOGICAL :: on_el, grounded - INTEGER :: k + REAL(wp) :: ext, ext_el, grounded_len, c_node, c_far, fdum(3) + LOGICAL :: grounded + INTEGER :: k, far esx = CD_HCDYN_OK + x = 0.5_wp IF (.NOT. ANY(ABS(fc) > CD_ZERO)) RETURN + CALL node_contact_normal(model, node, fdum, esx, em2, clearance=c_node) + IF (esx /= CD_HCDYN_OK) RETURN grounded_len = CD_ZERO - on_el = .FALSE. + ext_el = CD_ZERO DO k = MAX(1, node - 1), MIN(model%ne, node) CALL element_on_floor(k, grounded, esx) IF (esx /= CD_HCDYN_OK) RETURN IF (grounded) THEN - grounded_len = grounded_len + 0.5_wp*model%l0(k) - IF (k == el) on_el = .TRUE. + ext = 0.5_wp + ELSE + far = MERGE(k, k + 1, k == node - 1) + CALL node_contact_normal(model, far, fdum, esx, em2, clearance=c_far) + IF (esx /= CD_HCDYN_OK) RETURN + ext = CD_ZERO + IF (c_node < CD_ZERO .AND. c_far > c_node) ext = MIN(0.5_wp, -c_node/(c_far - c_node)) END IF + grounded_len = grounded_len + ext*model%l0(k) + IF (k == el) ext_el = ext END DO IF (grounded_len > CD_ZERO) THEN - IF (on_el) THEN - fc = fc*model%l0(el)/grounded_len - ELSE - fc = CD_ZERO - END IF + fc = fc*(ext_el*model%l0(el)/grounded_len) + x = ext_el ELSE IF (model%trib(node) > CD_ZERO) THEN - fc = fc*model%l0(el)/model%trib(node) + fc = fc*(0.5_wp*model%l0(el)/model%trib(node)) END IF END SUBROUTINE grounded_share + PURE FUNCTION spread_shapes(xs) RESULT(cs) + !! Integrals of the cubic Hermite shapes H1, H2/l0, H3, H4/l0 over xi in [0, xs], divided + !! by xs: the consistent loads of a unit load spread uniformly over that stretch (a point + !! load at xi = 0 as xs goes to zero). A stretch [1 - xs, 1] at the other end takes + !! [cs(3), -cs(4), cs(1), -cs(2)]. + REAL(wp), INTENT(IN) :: xs + REAL(wp) :: cs(4) + cs(1) = CD_ONE - xs*xs + 0.5_wp*xs**3 + cs(2) = 0.5_wp*xs - 2.0_wp*xs*xs/3.0_wp + 0.25_wp*xs**3 + cs(3) = xs*xs - 0.5_wp*xs**3 + cs(4) = -xs*xs/3.0_wp + 0.25_wp*xs**3 + END FUNCTION spread_shapes + SUBROUTINE element_on_floor(k, grounded, esx) !! Element k is grounded when both its nodes are on the floor (node_on_floor). INTEGER, INTENT(IN) :: k diff --git a/tests/check_touchdown_convergence.py b/tests/check_touchdown_convergence.py new file mode 100644 index 00000000..1ef2f4dd --- /dev/null +++ b/tests/check_touchdown_convergence.py @@ -0,0 +1,149 @@ +# SPDX-License-Identifier: Apache-2.0 +"""Node tension at touchdown converges at the element's order (driver_touchdown_convergence). + +A lazy-wave cable in a current is solved statically on three element sizes at touchdown +(about 1.6, 0.8 and 0.4 m), each on nine meshes that differ by a few elements in the section +that holds the touchdown point, so that the touchdown point falls at every position within its +element. A mesh 32 times finer than the 64-element base is the reference; nodes are compared at +the same unstretched arc length. The local error at touchdown is the largest departure of the +node tension error at the last suspended node, the first grounded node and the next node from +the error three nodes either side (the smooth discretisation error of the profile). Its largest +value over the nine meshes must fall at least by RATE when the elements are halved from 0.8 to +0.4 m, and stay below LIMIT on the 0.4 m meshes. + +The floor reaction of the first grounded node used to be spread over its grounded half-element +alone, whatever the position of the touchdown point in the touchdown element: the local error +then fell at the first order (4.3, 1.9, 1.0 N on the three sizes, against a line tension of +about 270 N there). + +Usage: check_touchdown_convergence.py +""" + +import bisect +import pathlib +import subprocess +import sys +import tempfile + +FLOOR_Z = -80.0 +LENGTHS = (68.114, 50.0, 52.101) +BASE = (28, 20, 16) # elements per section of the 64-element base mesh +LEVELS = (2, 4, 8) # multipliers of the base mesh +SHIFTS = range(-4, 5) # elements added to the touchdown section of each level +REFERENCE = 32 +RATE = 2.5 +LIMIT = 0.35 # N, on the 0.4 m meshes + +DECK = """--------------------- CableDyn Input File ------------------------------------ +Touchdown convergence check: lazy-wave cable in a current, static +--------------------- LINE TYPES --------------------------------------------- +TypeName Diam MassDenInAir EA BA EI Cd_n Cd_t Ca_n Ca_t +(-) (m) (kg/m) (N) (-) (N-m2) (-) (-) (-) (-) +bare 0.160 36.70 4.69e8 0.0 1.99e4 1.2 0.1 1.0 0.0 +buoy 0.290 0.0 4.69e8 0.0 1.99e4 1.2 0.1 1.0 0.0 +--------------------- POINTS ------------------------------------------------ +ID Type X Y Z +(-) (-) (m) (m) (m) +1 Coupled 5.0 0.0 -14.0 +2 Fixed 125.0 0.0 -80.0 +--------------------- LINES ------------------------------------------------- +ID NodeA NodeB Outputs +(-) (-) (-) (-) +1 1 2 - +--------------------- SECTIONS ---------------------------------------------- +LineID LineType Length NumSegs +(-) (-) (m) (-) +1 bare 68.114 {n1} +1 buoy 50.000 {n2} +1 bare 52.101 {n3} +--------------------- EQUIVALENT BUOYANCY ----------------------------------- +LineType Diam SubmergedWeightNpm +(-) (m) (N/m) +buoy 0.290 -80.15 +--------------------- OPTIONS ----------------------------------------------- +9.80665 g +1025.0 rhoW +80.0 WtrDpth +1.0e5 kBot +1.0e4 cBot +0.05 dtM +0.0 TMax +uniform 0.5 0.0 0.0 current +--------------------- OUTPUTS ----------------------------------------------- +"FairTen1" +--------------------- need this line ---------------------------------------- +""" + + +def static_profile(exe, work, counts): + """Unstretched arc length, height and node tension of every node of the static state.""" + name = "m_" + "_".join(str(n) for n in counts) + deck = work / f"{name}.dat" + deck.write_text(DECK.format(n1=counts[0], n2=counts[1], n3=counts[2]), encoding="utf-8") + run = subprocess.run([exe, str(deck), str(work / name)], capture_output=True, text=True, check=False) + if run.returncode != 0: + raise SystemExit(f"FAIL: the {name} deck did not solve (exit {run.returncode}):\n{run.stdout}{run.stderr}") + lines = (work / f"{name}.static.out").read_text(encoding="utf-8").splitlines() + header = lines[1].split() + if "DeckNode" in header: + raise SystemExit(f"FAIL: the static solve refined the {name} mesh") + iz, it = header.index("Z"), header.index("Tension") + rows = [line.split() for line in lines[3:] if line.strip()] + arc = [0.0] + start = 0.0 + for length, n in zip(LENGTHS, counts): + arc += [start + length * k / n for k in range(1, n + 1)] + start += length + if len(rows) != len(arc): + raise SystemExit(f"FAIL: {len(rows)} rows in {name}.static.out, expected {len(arc)}") + return arc, [float(r[iz]) for r in rows], [float(r[it]) for r in rows] + + +def interpolate(xs, ys, x): + k = min(max(bisect.bisect_left(xs, x), 1), len(xs) - 1) + f = (x - xs[k - 1]) / (xs[k] - xs[k - 1]) + return ys[k - 1] + f * (ys[k] - ys[k - 1]) + + +def local_error(exe, work, counts, reference): + """Largest local tension error at touchdown, and the element size there.""" + arc, z, t = static_profile(exe, work, counts) + first = next(j for j in range(1, len(z)) if z[j] <= FLOOR_Z + 1e-6 and z[j - 1] > FLOOR_Z + 1e-6) + err = [t[j] - interpolate(reference[0], reference[1], arc[j]) for j in range(len(arc))] + background = 0.5 * (err[first - 3] + err[first + 3]) + return max(abs(err[j] - background) for j in range(first - 1, first + 2)), arc[first] - arc[first - 1] + + +def main(): + if len(sys.argv) != 2: + raise SystemExit(__doc__) + exe = sys.argv[1] + worst = [] + with tempfile.TemporaryDirectory() as tmp: + work = pathlib.Path(tmp) + r_arc, _, r_t = static_profile(exe, work, tuple(REFERENCE * n for n in BASE)) + for m in LEVELS: + values = [] + for shift in SHIFTS: + counts = (BASE[0] * m, BASE[1] * m, BASE[2] * m + shift) + e, h = local_error(exe, work, counts, (r_arc, r_t)) + values.append(e) + worst.append(max(values)) + listed = " ".join(f"{v:.3f}" for v in values) + print(f" {BASE[2] * m + SHIFTS[0]}-{BASE[2] * m + SHIFTS[-1]} elements in the touchdown section " + f"(about {h:.2f} m): local error {listed} N; largest {worst[-1]:.3f} N") + rate = worst[-2] / max(worst[-1], 1e-12) + print(f" largest local error {worst[-2]:.3f} N -> {worst[-1]:.3f} N when the elements are halved: " + f"ratio {rate:.2f} (at least {RATE}; second order 4)") + failures = [] + if rate < RATE: + failures.append(f"the local error fell by {rate:.2f} per halving of the elements (at least {RATE})") + if worst[-1] > LIMIT: + failures.append(f"local error {worst[-1]:.3f} N on the 0.4 m meshes (limit {LIMIT} N)") + if failures: + raise SystemExit("FAIL: node tension at touchdown does not converge at second order: " + "; ".join(failures)) + print("PASS: node tension at touchdown converges at second order wherever the touchdown point falls") + + +if __name__ == "__main__": + main()