diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bba0978..d449f5b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,15 @@ All notable changes to CableDyn are recorded in this file. The format follows are unchanged. With gfortran the results are bit-identical. With the Intel compiler of the release, which had computed the second cosine through a fused sine/cosine evaluation, they can differ in the last printed digit. +- Faster monolithic body steps with a finite-EI cable clamped or elastically connected to a + body or rod. The cable's finite-difference columns of the junction Jacobian, each of which + re-steps the whole cable, are now kept and reused across steps like the mooring lines' + condensed tangent. They are rebuilt when 20 steps old, after a step that needed more than two + outer iterations, when the step size changes, and from the third outer iteration of a step. + `examples/buoy_clamped_cable.dat` runs 66 % faster with the release build, with the same + outer iterations per step. The junction converges to the same tolerance, so results differ + only within it, and by no more than the tolerance already allowed against a tightly converged + run: tensions by about 2e-6 relative and the body position by under 1 µm. ### Fixed diff --git a/CMakeLists.txt b/CMakeLists.txt index 83eb7c1f..0f05fc1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1999,6 +1999,16 @@ add_test(NAME driver_clamped_buoyant_held -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/driver_clamped_buoyant_held -P ${CMAKE_CURRENT_SOURCE_DIR}/tests/check_driver_output.cmake) set_tests_properties(driver_clamped_buoyant_held PROPERTIES LABELS "fortran;driver;integration;static") +# A clamped finite-EI cable on a Rigid6 body that also holds a pinned rod: the body's junction +# group has nine coordinates, which the cable's kept Jacobian columns must span (the Debug +# build's bounds checks catch a cache sized for six). +add_test(NAME driver_clamped_cable_pinned_rod + COMMAND ${CMAKE_COMMAND} -DDRIVER=$ -DEXPECT_RC=0 + "-DARGS=${CMAKE_CURRENT_SOURCE_DIR}/tests/data/buoy_clamped_cable_pinned_rod.dat|pinned" + "-DONCE=converged run written" + -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/driver_clamped_cable_pinned_rod + -P ${CMAKE_CURRENT_SOURCE_DIR}/tests/check_driver_output.cmake) +set_tests_properties(driver_clamped_cable_pinned_rod PROPERTIES LABELS "fortran;driver;integration") if(WIN32 AND CABLEDYN_RUNTIME_DLLS) add_test( diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index fb5d855e..3fe730e6 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -805,6 +805,12 @@ MODULE CableDyn_DeckDriver INTEGER :: n_outer = 0, max_outer = 0, n_steps_imp = 0, n_subdiv = 0 ! condensed line tangent reuse: steps since the last refresh and the last step's outer count INTEGER :: tan_age = HUGE(1), last_outer = 0, n_refresh = 0 + ! clamped-cable Jacobian reuse: each clamped cable's finite-difference contribution to the + ! junction Jacobian over its object's group (cab_jac(1:n, 1:n, c), rows and columns from the + ! group's first coordinate), the steps since it was built and the step size it was built for + REAL(wp), ALLOCATABLE :: cab_jac(:, :, :) + INTEGER :: cab_age = HUGE(1) + REAL(wp) :: cab_dt = CD_ZERO INTEGER, ALLOCATABLE :: jb_off(:), jr_off(:), jp_off(:), g_kind(:), g_idx(:), g_lo(:), g_hi(:) LOGICAL, ALLOCATABLE :: jactive(:), is_rot(:) ! jobj: coupled DOFs driven by a body or rod (the objects' trapezoidal levels at the line @@ -16427,6 +16433,7 @@ SUBROUTINE write_multibody_dynamic_out(deck_path, out_root, channels, types, bod mb%cab_off(3, SIZE(cab_lines)), mb%cab_force(3, SIZE(cab_lines)), & mb%cab_clamp(SIZE(cab_lines)), mb%cab_moment(3, SIZE(cab_lines)), mb%cab_fend(3, SIZE(cab_lines)), & mb%cab_mend(3, SIZE(cab_lines)), mb%cab_f0(3, SIZE(cab_lines)), mb%cab_m0(3, SIZE(cab_lines))) + mb%cab_age = HUGE(1) mb%cab_kind = 0 mb%cab_obj = 0 mb%cab_off = CD_ZERO @@ -17672,6 +17679,16 @@ SUBROUTINE mb_junction_layout(mb, points) mb%is_rot(mb%jr_off(ir) + 4:mb%jr_off(ir) + 6) = .TRUE. END IF END DO + ! the clamped cables' kept Jacobian columns span a whole group: a body's six coordinates + ! and three for each rod pinned to it + IF (ALLOCATED(mb%cables)) THEN + IF (ALLOCATED(mb%cab_jac)) DEALLOCATE (mb%cab_jac) + k = 1 + IF (mb%ng > 0) k = MAX(k, MAXVAL(mb%g_hi(1:mb%ng) - mb%g_lo(1:mb%ng) + 1)) + ALLOCATE (mb%cab_jac(k, k, SIZE(mb%cables))) + mb%cab_jac = CD_ZERO + mb%cab_age = HUGE(1) + END IF CONTAINS SUBROUTINE add_group(kind, idx) INTEGER, INTENT(IN) :: kind, idx @@ -18112,8 +18129,8 @@ RECURSIVE SUBROUTINE mb_step_implicit(mb, points, opts, time, dt, converged, sta ! times the object length scale); the line reactions carry the inner tolerance REAL(wp), PARAMETER :: JUNCTION_TOL = 1.0e-6_wp, PREDICTOR_TOL = 1.0e-9_wp CHARACTER(24) :: tstr - INTEGER :: dep, it, g, c, ib, ir, p, o, es, lit, nj, gworst, it2 - LOGICAL :: lconv, lstall, first, ok, conv2, stall2, refresh, lines_stepped, tors_turn, lim + INTEGER :: dep, it, g, c, ib, ir, p, o, es, lit, nj, gworst, it2, gsz + LOGICAL :: lconv, lstall, first, ok, conv2, stall2, refresh, lines_stepped, tors_turn, lim, cab_refresh INTEGER, PARAMETER :: TAN_MAX_AGE = 20 REAL(wp) :: rho, am, af, beta_na, gam_na, t_af, h, fac, dth, worst, tol_it, am_p, gam_p, beta_p REAL(wp), ALLOCATABLE :: x(:), xp(:), r(:), rp(:), jac(:, :), dx(:), kg(:, :), ga(:, :), rscale(:) @@ -18194,6 +18211,7 @@ RECURSIVE SUBROUTINE mb_step_implicit(mb, points, opts, time, dt, converged, sta lines_stepped = .FALSE. ok = .FALSE. tors_turn = .FALSE. + cab_refresh = .FALSE. gworst = 0 DO it = 1, MAX_OUTER ! a body holding a line restrained in torsion turns by less than pi/2 per step: the line @@ -18284,6 +18302,7 @@ RECURSIVE SUBROUTINE mb_step_implicit(mb, points, opts, time, dt, converged, sta mb%max_outer = MAX(mb%max_outer, it) mb%last_outer = it IF (mb%tan_age < HUGE(1)) mb%tan_age = mb%tan_age + 1 + IF (mb%cab_age < HUGE(1)) mb%cab_age = mb%cab_age + 1 EXIT END IF IF (it == MAX_OUTER) EXIT @@ -18316,15 +18335,36 @@ RECURSIVE SUBROUTINE mb_step_implicit(mb, points, opts, time, dt, converged, sta ! clamped cables: their end force and moment follow the object motion within the step; the ! condensed dynamic end tangent (translations and rotations of the attachment) enters by ! finite differences of the cable step over the columns of the object's group, each - ! perturbing the end-of-step pose by CABLE_FD rad or m + ! perturbing the end-of-step pose by CABLE_FD rad or m. Each column re-steps the whole + ! cable, so the columns are kept and reused like the lines' condensed tangent: rebuilt on + ! the first Jacobian of a step when they are TAN_MAX_AGE steps old, the previous step + ! needed more than two outer iterations or the step size changed, and on every Jacobian + ! from the third outer iteration on. A Newton with reused columns converges to the same + ! junction tolerance. + IF (it == 1) THEN + cab_refresh = mb%cab_age >= TAN_MAX_AGE .OR. mb%last_outer > 2 .OR. ABS(dt - mb%cab_dt) > CD_ZERO + ELSE + cab_refresh = cab_refresh .OR. it >= 3 + END IF DO c = 1, SIZE(mb%cables) IF (.NOT. mb%cab_clamp(c)) CYCLE g = mb_cable_group(mb, c) IF (g == 0) CYCLE - CALL cable_columns(c, g) - IF (ErrStat /= CD_DECKDRV_OK) EXIT + IF (cab_refresh) THEN + CALL cable_columns(c, g) + IF (ErrStat /= CD_DECKDRV_OK) EXIT + ELSE + gsz = mb%g_hi(g) - mb%g_lo(g) + 1 + jac(mb%g_lo(g):mb%g_hi(g), mb%g_lo(g):mb%g_hi(g)) = & + jac(mb%g_lo(g):mb%g_hi(g), mb%g_lo(g):mb%g_hi(g)) + mb%cab_jac(1:gsz, 1:gsz, c) + END IF END DO IF (ErrStat /= CD_DECKDRV_OK) EXIT + IF (cab_refresh) THEN + mb%cab_age = 0 + mb%cab_dt = dt + cab_refresh = .FALSE. + END IF dx = -r CALL CD_Solve_Dense_As_Banded(jac, dx, es, em) IF (es /= CD_LINALG_OK .OR. .NOT. ALL(IEEE_IS_FINITE(dx))) EXIT @@ -18360,6 +18400,7 @@ RECURSIVE SUBROUTINE mb_step_implicit(mb, points, opts, time, dt, converged, sta CALL CD_HFMF_Restore(mb%cables(c), es, em) END DO mb%tan_age = HUGE(1) + mb%cab_age = HUGE(1) IF (dep >= MAX_DEPTH) THEN IF (ErrStat == CD_DECKDRV_OK .AND. tors_turn) THEN WRITE (tstr, '(ES12.5)') time @@ -18402,7 +18443,8 @@ RECURSIVE SUBROUTINE mb_step_implicit(mb, points, opts, time, dt, converged, sta SUBROUTINE cable_columns(cc, gg) !! Add clamped cable cc's end-load derivative to the Jacobian columns of its group gg: !! the cable re-stepped from the step entry with each column perturbed, the group residual - !! re-evaluated at the unperturbed objects with the perturbed cable loads. + !! re-evaluated at the unperturbed objects with the perturbed cable loads. The columns are + !! also kept in mb%cab_jac for reuse. INTEGER, INTENT(IN) :: cc, gg REAL(wp), PARAMETER :: CABLE_FD = 1.0e-5_wp INTEGER :: col, lo, hi @@ -18432,7 +18474,8 @@ SUBROUTINE cable_columns(cc, gg) mb%cab_force(:, cc) = fsave mb%cab_moment(:, cc) = msave IF (ErrStat /= CD_DECKDRV_OK) RETURN - jac(lo:hi, col) = jac(lo:hi, col) + (rp(lo:hi) - r(lo:hi))/hc + mb%cab_jac(1:hi - lo + 1, col - lo + 1, cc) = (rp(lo:hi) - r(lo:hi))/hc + jac(lo:hi, col) = jac(lo:hi, col) + mb%cab_jac(1:hi - lo + 1, col - lo + 1, cc) END DO END SUBROUTINE cable_columns END SUBROUTINE mb_step_implicit diff --git a/tests/data/buoy_clamped_cable_pinned_rod.dat b/tests/data/buoy_clamped_cable_pinned_rod.dat new file mode 100644 index 00000000..20976ff4 --- /dev/null +++ b/tests/data/buoy_clamped_cable_pinned_rod.dat @@ -0,0 +1,83 @@ +--------------------- CableDyn Input File ------------------------------------ +Rigid6 buoy with a clamped finite-EI cable and a rod pinned to the buoy (test deck) +-- examples/buoy_clamped_cable.dat with a 7.8 m arm rod pinned to Body1 (Body1Pinned) and a 6 s +-- run. The body's junction group then has nine coordinates (six of the body, three of the pin), +-- and the clamped cable's finite-difference Jacobian columns, kept across steps, span all nine. +--------------------- LINE TYPES --------------------------------------------- +TypeName Diam MassDenInAir EA BA/-zeta EI Cd_n Cd_t Ca_n Ca_t +(-) (m) (kg/m) (N) (N-s/-) (N-m^2) (-) (-) (-) (-) +poly 0.12 15.0 5.0e7 -1.0 0.0 1.2 0.2 1.0 0.0 +cable 0.20 60.0 5.0e8 -1.0 2.0e4 1.2 0.0 1.0 0.0 +--------------------- ROD TYPES ---------------------------------------- +Name Diam Mass Cd Ca CdEnd CaEnd +(-) (m) (kg/m) (-) (-) (-) (-) +arm 0.3 150.0 1.0 1.0 0.0 0.0 +--------------------- BODIES ------------------------------------------------- +ID Type X Y Z Roll Pitch Yaw Mass Vol C33 C44 C55 CdA Ca Ixx Iyy Izz +(-) (-) (m) (m) (m) (deg) (deg) (deg) (kg) (m3) (N/m) (Nm/rad) (Nm/rad) (m2) (-) (kgm2) (kgm2) (kgm2) +1 Rigid6 0.0 0.0 0.0 0.0 0.0 0.0 8.0e4 113.1 2.84e5 2.0e6 2.0e6 24.0 1.0 4.0e5 4.0e5 3.6e5 +--------------------- RODS --------------------------------------------- +ID RodType Attachment XA YA ZA XB YB ZB NumSegs Outputs +(-) (-) (-) (m) (m) (m) (m) (m) (m) (-) (-) +1 arm Body1Pinned 0.0 2.0 -4.0 0.0 8.0 -9.0 4 - +--------------------- POINTS ------------------------------------------------- +ID Type X Y Z Mass Vol CdA Ca +(-) (-) (m) (m) (m) (kg) (m^3) (m^2) (-) +1 Body1 3.0 0.0 -4.0 0 0 0 0 +2 Body1 -1.5 2.598 -4.0 0 0 0 0 +3 Body1 -1.5 -2.598 -4.0 0 0 0 0 +4 Body1 0.0 0.0 -4.0 0 0 0 0 +5 Fixed 60.0 0.0 -100.0 0 0 0 0 +6 Fixed -30.0 51.962 -100.0 0 0 0 0 +7 Fixed -30.0 -51.962 -100.0 0 0 0 0 +8 Fixed -60.0 0.0 -100.0 0 0 0 0 +--------------------- LINES -------------------------------------------------- +ID NodeA NodeB Outputs +(-) (-) (-) (-) +1 1 5 - +2 2 6 - +3 3 7 - +4 4 8 - +--------------------- SECTIONS ----------------------------------------------- +LineID LineType Length NumSegs +(-) (-) (m) (-) +1 poly 111.4 20 +2 poly 111.4 20 +3 poly 111.4 20 +4 cable 10.0 40 +4 cable 120.0 60 +--------------------- END CONNECTIONS ---------------------------------------- +LineID End Stiffness EzX EzY EzZ +(-) (-) (N-m/rad) (-) (-) (-) +4 A Rigid -0.5 0.0 -0.86603 +--------------------- OPTIONS ------------------------------------------------ +9.80665 g - Gravitational acceleration (m/s^2) [default: 9.80665] +1025.0 rhoW - Water density (kg/m^3) [default: 1025] +100.0 WtrDpth - Water depth (m) [default: absent standalone; host-owned OpenFAST] +1.0e5 kBot - Seabed penalty stiffness base (Pa/m) [default: 1.0e5] +1.0e4 cBot - Seabed normal damping base (Pa-s/m) [default: 1.0e4] +0.05 dtM - CableDyn internal time step (s) [default: omitted standalone; 0.1 s target OpenFAST] +6.0 TMax - Standalone simulation duration (s) [default: omitted standalone; host-owned OpenFAST] +static bodyIC - Free Rigid6 body / rod start {static=equilibrium; deck=deck pose} [default: static] +monolithic bodyScheme - Body time integration {monolithic; staggered}; a clamped End A needs monolithic [default: monolithic] +0.4 rhoInf - Generalised-alpha spectral radius {0<=rhoInf<=1} [default: 0.4] +False modified_newton - Tangent-reuse mode {False=full Newton; True=guarded reuse} [default: False] +False adaptive_mesh - Automatic finite-EI refinement {False; True} [default: False] +dynamic_solver 1.0e-8 1.0e-14 30 12 - Relative tolerance, absolute tolerance, max iterations, backtracks [defaults shown] +none frictionMu - Seabed friction coefficient {none; value>=0} [default: none] +none current - Current model and X/Y/Z velocity (m/s) {none; uniform; profile} [default: none] +airy 1.0 14.0 0.0 waves - Wave model, height, period, and direction (m, s, deg) {none; airy; jonswap} [default: none] +8.0 rampTime - Half-cosine start-up ramp of the wave amplitudes (s) [default: 0] +0 WaterKin - Water-kinematics source {0/none; file; SEASTATE coupled only} [default: no policy] +-- Complete option/default reference: cabledyn_options_reference.dat and doc/options.rst. +--------------------- OUTPUTS ------------------------------------------------ +"FairTen1" +"FairTen4" +"AnchTen4" +"Body1Px" +"Body1Pz" +"Body1Ry" +"Body1My" +"BendMom4N1" +"Curv4N1" +--------------------- need this line -----------------------------------------