Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ All notable changes to CableDyn are recorded in this file. The format follows
at 0.109 1/m instead of 0.075 1/m, and the anchor tension stays at its static 1.23 kN, where
the coarse mesh showed stick-slip peaks up to 4.1 kN. The validation record and the tutorials
are updated.
- Faster tension-only (`EI = 0`) line steps. In every Newton evaluation the element kernels of
the line loads (axial damping, Morison drag, Froude-Krylov, buoyancy recovery, added mass) no
longer re-check, element by element, data the line model validates when it is set; the
Froude-Krylov and added-mass kernels check their section data once instead of three times;
the velocity Jacobians of the Froude-Krylov and buoyancy loads, which are zero, are no longer
added into the band; a step reuses the consistent-mass band of the previous one while the
lengths and masses are unchanged; and the Newton solve no longer rescans a matrix already
checked finite. With the release build, `examples/als_volturnus_line_break_time.dat` runs
13 % faster and `examples/spar_pinned_rods.dat` 13 %. Every input error is reported as
before. With gfortran the results are bit-identical. With the Intel compiler of the release
they can differ in the last printed digit, and by more where a deck amplifies round-off.

### Fixed

Expand Down Expand Up @@ -258,6 +269,17 @@ All notable changes to CableDyn are recorded in this file. The format follows
on the rounded surface. When the anchor walk of a finite-EI line over a non-planar bathymetry
reaches a state that is rejected, the failure no longer states that the line is too long for
its span to hang as a catenary, which is proven over a planar seabed only.
- Junction end tangent of a tension-only line step that ends right after a fresh tangent
evaluation. In the monolithic body and point coupling, a line step accepted within the
near-tolerance allowance at its Newton iteration limit (or converged on a freshly evaluated
tangent) still marked its last factorization as current, although the new tangent had
overwritten it. The condensed end tangent, and the warm start of a re-solve of the same step,
were then back-solved with the unfactored matrix: in a unit test the end tangent was wrong by
five orders of magnitude, which can slow or misdirect the outer junction iteration. The step
now clears the factorization flags whenever it overwrites the band without factoring it, so
the end query factors the current tangent (one more tangent assembly and factorization for
such a step of a junction solve). The outputs of the example decks and of the other tests
are unchanged.

## [0.1.1] - 2026-10-09

Expand Down
33 changes: 29 additions & 4 deletions src/CableDyn_Damping.f90
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,27 @@ SUBROUTINE CD_Cable_Axial_Damping_Load(q, v, elem_conn, l0, ba, force, jac_q, ja
END DO
END SUBROUTINE CD_Cable_Axial_Damping_Load

SUBROUTINE CD_Axial_Damping_Element_Force(qa, qb, va, vb, l0, ba, force, ErrStat, ErrMsg, l0_dot)
SUBROUTINE CD_Axial_Damping_Element_Force(qa, qb, va, vb, l0, ba, force, ErrStat, ErrMsg, l0_dot, &
inputs_validated)
!! Two-node axial damping force kernel for model hot paths.
!! `inputs_validated` is an internal hot-path contract (as in CD_Component_Wave_Kinematics),
!! shared with CD_Axial_Damping_Element_Load: a caller that already guarantees a finite
!! state, a finite positive l0 and a finite resolved ba >= 0 skips the per-element input
!! scan. The default remains full validation for public/direct calls.
REAL(wp), INTENT(IN) :: qa(3), qb(3), va(3), vb(3), l0, ba
REAL(wp), INTENT(OUT) :: force(6)
REAL(wp), INTENT(IN), OPTIONAL :: l0_dot !! unstretched-length rate (see the cable-path routines)
INTEGER, INTENT(OUT) :: ErrStat
CHARACTER(*), INTENT(OUT) :: ErrMsg
LOGICAL, INTENT(IN), OPTIONAL :: inputs_validated
REAL(wp) :: chord(3), tang(3), rel(3), length, ldot, td_vec(3)

CALL validate_element_inputs(qa, qb, va, vb, l0, ba, ErrStat, ErrMsg)
IF (trusted(inputs_validated)) THEN
ErrStat = CD_DAMP_OK
ErrMsg = ''
ELSE
CALL validate_element_inputs(qa, qb, va, vb, l0, ba, ErrStat, ErrMsg)
END IF
force = CD_ZERO
IF (ErrStat /= CD_DAMP_OK) RETURN
IF (PRESENT(l0_dot)) THEN
Expand All @@ -285,18 +296,25 @@ SUBROUTINE CD_Axial_Damping_Element_Force(qa, qb, va, vb, l0, ba, force, ErrStat
force(4:6) = -td_vec
END SUBROUTINE CD_Axial_Damping_Element_Force

SUBROUTINE CD_Axial_Damping_Element_Load(qa, qb, va, vb, l0, ba, force, jac_q, jac_v, ErrStat, ErrMsg, l0_dot)
SUBROUTINE CD_Axial_Damping_Element_Load(qa, qb, va, vb, l0, ba, force, jac_q, jac_v, ErrStat, ErrMsg, l0_dot, &
inputs_validated)
!! Two-node axial damping force and residual-Jacobian kernel.
REAL(wp), INTENT(IN) :: qa(3), qb(3), va(3), vb(3), l0, ba
REAL(wp), INTENT(OUT) :: force(6), jac_q(6, 6), jac_v(6, 6)
REAL(wp), INTENT(IN), OPTIONAL :: l0_dot !! unstretched-length rate: the damped rate is ldot - (length/l0)*l0_dot
INTEGER, INTENT(OUT) :: ErrStat
CHARACTER(*), INTENT(OUT) :: ErrMsg
LOGICAL, INTENT(IN), OPTIONAL :: inputs_validated !! see CD_Axial_Damping_Element_Force
INTEGER :: i
REAL(wp) :: chord(3), tang(3), rel(3), length, ldot, k, td_vec(3)
REAL(wp) :: eye(3, 3), ktt(3, 3), m1(3, 3), m2(3, 3), dmat(3, 3)

CALL validate_element_inputs(qa, qb, va, vb, l0, ba, ErrStat, ErrMsg)
IF (trusted(inputs_validated)) THEN
ErrStat = CD_DAMP_OK
ErrMsg = ''
ELSE
CALL validate_element_inputs(qa, qb, va, vb, l0, ba, ErrStat, ErrMsg)
END IF
force = CD_ZERO
jac_q = CD_ZERO
jac_v = CD_ZERO
Expand Down Expand Up @@ -360,6 +378,13 @@ PURE FUNCTION outer(a, b) RESULT(m)
END DO
END FUNCTION outer

PURE LOGICAL FUNCTION trusted(inputs_validated) RESULT(trust)
!! The value of an optional inputs_validated flag (.FALSE. when absent).
LOGICAL, INTENT(IN), OPTIONAL :: inputs_validated
trust = .FALSE.
IF (PRESENT(inputs_validated)) trust = inputs_validated
END FUNCTION trusted

SUBROUTINE add_block(mat, node_i, node_j, blk)
!! Accumulate a 3x3 block into the (node_i, node_j) DOF positions of a global matrix.
REAL(wp), INTENT(INOUT) :: mat(:, :)
Expand Down
120 changes: 109 additions & 11 deletions src/CableDyn_Dynamic.f90
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ MODULE CableDyn_Dynamic
REAL(wp), ALLOCATABLE :: nodes_eval(:, :)
INTEGER :: topo_n_nodes = 0, bw_kl = 0, bw_ku = 0
LOGICAL :: topo_valid = .FALSE., bw_valid = .FALSE.
! M_band holds the element consistent mass band assembled for the remembered connectivity
! and free list (bw_free) from the lengths mb_l0 and masses per length mb_rho; a step whose
! inputs match reuses it instead of assembling the same band again. Every other writer of
! M_band clears mb_valid.
LOGICAL :: mb_valid = .FALSE.
REAL(wp), ALLOCATABLE :: mb_l0(:), mb_rho(:)
! TEST-ONLY diagnostic: the number of steps that reused the remembered mass band (saturating).
! Only the unit tests read it (to assert that the cache hit); no result depends on it.
INTEGER :: mb_hits = 0
INTEGER :: ad_kl = 0
INTEGER, ALLOCATABLE :: ad_finv(:), ad_ipiv(:), ad_fixed(:)
REAL(wp), ALLOCATABLE :: ad_full(:, :), ad_add(:, :), ad_ab(:, :), ad_x(:, :), ad_result(:, :)
Expand All @@ -164,7 +173,8 @@ MODULE CableDyn_Dynamic
LOGICAL :: end_valid = .FALSE.
! the factored effective band in eff_band/ipiv belongs to the current step (a junction solve
! of this step factored it): a warm re-solve of the same step starts with a chord iteration
! on it instead of assembling and factoring a new tangent
! on it instead of assembling and factoring a new tangent. Cleared whenever eff_band is
! overwritten by a tangent that is not factored.
LOGICAL :: step_factor = .FALSE.
! force scale of the junction solves (largest element tension of the last one): the
! residual gate of a warm-started junction solve is relative to it, not to its own
Expand Down Expand Up @@ -311,6 +321,10 @@ SUBROUTINE CD_Clear_GenAlpha_Workspace(work)
work%bw_ku = 0
work%topo_valid = .FALSE.
work%bw_valid = .FALSE.
work%mb_valid = .FALSE.
work%mb_hits = 0
IF (ALLOCATED(work%mb_l0)) DEALLOCATE (work%mb_l0)
IF (ALLOCATED(work%mb_rho)) DEALLOCATE (work%mb_rho)
IF (ALLOCATED(work%ad_finv)) DEALLOCATE (work%ad_finv)
IF (ALLOCATED(work%ad_ipiv)) DEALLOCATE (work%ad_ipiv)
IF (ALLOCATED(work%ad_fixed)) DEALLOCATE (work%ad_fixed)
Expand Down Expand Up @@ -536,6 +550,8 @@ SUBROUTINE CD_Cable_Initial_Acceleration(q, v, elem_conn, l0, ea, rho_a, tension
RETURN
END IF
END IF
! the band is factored in place below: not the step's reusable mass band
work%mb_valid = .FALSE.
IF (use_element_mass_band) THEN
CALL assemble_mass_band_free(elem_conn, l0, rho_a, work%dof_marker(1:n_dof), kl, ku, M_band, es, em)
ELSE
Expand Down Expand Up @@ -615,7 +631,7 @@ SUBROUTINE CD_Cable_Gen_Alpha_Step(q, v, a, elem_conn, l0, ea, rho_a, tension_on
REAL(wp), POINTER :: a_eval(:), a_alpha(:), q_alpha(:), v_eval(:), v_alpha(:), fint_eval(:)
! q_alpha viewed as (3, n_nodes) nodal coordinates, without a copy
REAL(wp), POINTER :: q_alpha_nodes(:, :)
LOGICAL :: topo_ok, bw_hit
LOGICAL :: topo_ok, bw_hit, mb_hit
INTEGER :: il, jl
REAL(wp), POINTER :: Kt_eval(:, :), tension_eval(:), load_eval(:), jac_q_eval(:, :), jac_v_eval(:, :)
REAL(wp), POINTER :: M_eff_eval(:, :), M_add_eval(:, :), dMa_a_dq_eval(:, :)
Expand Down Expand Up @@ -745,6 +761,7 @@ SUBROUTINE CD_Cable_Gen_Alpha_Step(q, v, a, elem_conn, l0, ea, rho_a, tension_on
direct_banded = .NOT. has_load_proc .AND. .NOT. has_added_mass_proc
use_element_mass_band = direct_banded .AND. .NOT. PRESENT(structural_mass)
CALL validate_topology_once(work, elem_conn, n_dof/3, topo_ok)
bw_hit = .FALSE.
IF (direct_banded) THEN
bw_hit = topo_ok .AND. work%bw_valid
IF (bw_hit) bw_hit = SIZE(work%bw_free) == n_free
Expand All @@ -753,6 +770,7 @@ SUBROUTINE CD_Cable_Gen_Alpha_Step(q, v, a, elem_conn, l0, ea, rho_a, tension_on
kl = work%bw_kl
ku = work%bw_ku
ELSE
work%mb_valid = .FALSE.
CALL CD_Cable_Free_Bandwidth(elem_conn, n_dof/3, free, kl, ku, es, em, topology_validated=topo_ok)
IF (es /= 0) THEN
CALL fail(ErrStat, ErrMsg, 'bandwidth analysis failed: '//TRIM(em))
Expand Down Expand Up @@ -907,9 +925,22 @@ SUBROUTINE CD_Cable_Gen_Alpha_Step(q, v, a, elem_conn, l0, ea, rho_a, tension_on
RETURN
END IF
END IF
es = 0
IF (use_element_mass_band) THEN
CALL assemble_mass_band_free(elem_conn, l0, rho_a, work%dof_marker(1:n_dof), kl, ku, M_band, es, em)
! The element mass band depends only on the connectivity, the free list, l0 and
! rho_a: a step with the inputs of the remembered band (bw_hit: same connectivity and
! free list) reuses it, which is the band the assembly would build again.
mb_hit = .FALSE.
IF (bw_hit) mb_hit = mass_band_matches(work, l0, rho_a)
IF (.NOT. mb_hit) THEN
work%mb_valid = .FALSE.
CALL assemble_mass_band_free(elem_conn, l0, rho_a, work%dof_marker(1:n_dof), kl, ku, M_band, es, em)
IF (es == 0 .AND. work%bw_valid) CALL remember_mass_band(work, l0, rho_a)
ELSE IF (work%mb_hits < HUGE(work%mb_hits)) THEN
work%mb_hits = work%mb_hits + 1
END IF
ELSE
work%mb_valid = .FALSE.
CALL pack_dense_free_band(M, free, kl, ku, CD_ONE, M_band, es, em)
END IF
IF (es /= 0) THEN
Expand Down Expand Up @@ -955,6 +986,13 @@ SUBROUTINE CD_Cable_Gen_Alpha_Step(q, v, a, elem_conn, l0, ea, rho_a, tension_on
IF (tangent_fresh) THEN
IF (direct_banded) THEN
CALL eval_dynamic(qk, R, es, em, effbandout=eff_band)
! factored_now and work%step_factor state that eff_band/ipiv hold the LU of the last
! factorization. eff_band now holds the unfactored tangent at qk, and they are set
! again only once it is factored below: an exit before that (convergence, or the
! near-tolerance allowance at the iteration limit) leaves the junction end query and
! a warm re-solve to factor it instead of back-solving with an unfactored band.
factored_now = .FALSE.
work%step_factor = .FALSE.
ELSE
CALL eval_dynamic(qk, R, es, em, effout=eff)
END IF
Expand Down Expand Up @@ -1017,7 +1055,10 @@ SUBROUTINE CD_Cable_Gen_Alpha_Step(q, v, a, elem_conn, l0, ea, rho_a, tension_on
eff_band_unfactored(il, jl) = eff_band(il, jl)
END DO
END DO
CALL CD_Factor_Banded(eff_band, kl, ku, ipiv, es, em)
! eval_dynamic has just checked this band finite when a banded load or added-mass
! callback contributes to it; the factorization then skips repeating that scan.
CALL CD_Factor_Banded(eff_band, kl, ku, ipiv, es, em, &
matrix_validated=has_load_band_proc .OR. has_added_mass_band_proc)
factored_now = es == 0
work%step_factor = factored_now .AND. work%end_request
IF (es /= 0) THEN
Expand All @@ -1031,7 +1072,9 @@ SUBROUTINE CD_Cable_Gen_Alpha_Step(q, v, a, elem_conn, l0, ea, rho_a, tension_on
op_norm = MAX(CD_ONE, dense_row_abs_sum_max(eff, free))
END IF
IF (direct_banded) THEN
CALL CD_Solve_Factored_Banded(eff_band, kl, ku, ipiv, dq, es, em)
! A tangent factored in this iteration is the finite LU CD_Factor_Banded returned; a
! reused one keeps the full check.
CALL CD_Solve_Factored_Banded(eff_band, kl, ku, ipiv, dq, es, em, factor_validated=tangent_fresh)
ELSE
eff_free = eff(free, free)
CALL CD_Solve_Dense_As_Banded(eff_free, dq, es, em)
Expand Down Expand Up @@ -1758,6 +1801,12 @@ SUBROUTINE ensure_step_workspace(work, n_dof, n_elem, n_free, ldab, need_band, n
CALL ensure_real_vector(work%load_eval, n_dof, ErrStat, ErrMsg)
IF (ErrStat /= CD_DYN_OK) RETURN
IF (need_band) THEN
! a reallocated mass band no longer holds the remembered one
IF (ALLOCATED(work%M_band)) THEN
IF (SIZE(work%M_band, 1) < ldab .OR. SIZE(work%M_band, 2) < n_free) work%mb_valid = .FALSE.
ELSE
work%mb_valid = .FALSE.
END IF
CALL ensure_real_matrix(work%M_band, ldab, n_free, ErrStat, ErrMsg)
IF (ErrStat /= CD_DYN_OK) RETURN
CALL ensure_real_vector(work%M_add_a_eval, n_dof, ErrStat, ErrMsg)
Expand Down Expand Up @@ -1863,6 +1912,56 @@ SUBROUTINE remember_bandwidth(work, free, kl, ku, topology_validated)
work%bw_valid = .TRUE.
END SUBROUTINE remember_bandwidth

LOGICAL FUNCTION mass_band_matches(work, l0, rho_a) RESULT(match)
!! work%M_band holds the element mass band of these l0 and rho_a (for the remembered
!! connectivity and free list). Equality is tested as <= and >= so that a NaN never matches.
TYPE(CD_CableGenAlphaWorkspace), INTENT(IN) :: work
REAL(wp), INTENT(IN) :: l0(:), rho_a(:)
INTEGER :: e

match = work%mb_valid
IF (match) match = SIZE(work%mb_l0) == SIZE(l0) .AND. SIZE(work%mb_rho) == SIZE(rho_a)
IF (.NOT. match) RETURN
DO e = 1, SIZE(l0)
IF (.NOT. (work%mb_l0(e) <= l0(e) .AND. work%mb_l0(e) >= l0(e))) THEN
match = .FALSE.
RETURN
END IF
END DO
DO e = 1, SIZE(rho_a)
IF (.NOT. (work%mb_rho(e) <= rho_a(e) .AND. work%mb_rho(e) >= rho_a(e))) THEN
match = .FALSE.
RETURN
END IF
END DO
END FUNCTION mass_band_matches

SUBROUTINE remember_mass_band(work, l0, rho_a)
!! Record the inputs of the element mass band just assembled into work%M_band.
TYPE(CD_CableGenAlphaWorkspace), INTENT(INOUT) :: work
REAL(wp), INTENT(IN) :: l0(:), rho_a(:)
INTEGER :: istat

work%mb_valid = .FALSE.
IF (ALLOCATED(work%mb_l0)) THEN
IF (SIZE(work%mb_l0) /= SIZE(l0)) DEALLOCATE (work%mb_l0)
END IF
IF (ALLOCATED(work%mb_rho)) THEN
IF (SIZE(work%mb_rho) /= SIZE(rho_a)) DEALLOCATE (work%mb_rho)
END IF
IF (.NOT. ALLOCATED(work%mb_l0)) THEN
ALLOCATE (work%mb_l0(SIZE(l0)), STAT=istat)
IF (istat /= 0) RETURN
END IF
IF (.NOT. ALLOCATED(work%mb_rho)) THEN
ALLOCATE (work%mb_rho(SIZE(rho_a)), STAT=istat)
IF (istat /= 0) RETURN
END IF
work%mb_l0 = l0
work%mb_rho = rho_a
work%mb_valid = .TRUE.
END SUBROUTINE remember_mass_band

SUBROUTINE partition_free_dofs_workspace(fixed_dofs, n_dof, free, n_free, fixed, marker, ErrStat, ErrMsg)
INTEGER, INTENT(IN) :: fixed_dofs(:), n_dof
INTEGER, INTENT(INOUT) :: free(:), fixed(:)
Expand Down Expand Up @@ -1907,14 +2006,15 @@ SUBROUTINE partition_free_dofs_workspace(fixed_dofs, n_dof, free, n_free, fixed,
END SUBROUTINE partition_free_dofs_workspace

SUBROUTINE ensure_int_vector(x, n, ErrStat, ErrMsg)
!! The ensure_* helpers run for every workspace array on every step: they write ErrMsg only
!! on failure, and their callers (ensure_dof_workspace, ensure_step_workspace) clear it.
INTEGER, ALLOCATABLE, INTENT(INOUT) :: x(:)
INTEGER, INTENT(IN) :: n
INTEGER, INTENT(OUT) :: ErrStat
CHARACTER(*), INTENT(OUT) :: ErrMsg
CHARACTER(*), INTENT(INOUT) :: ErrMsg
INTEGER :: istat

ErrStat = CD_DYN_OK
ErrMsg = ''
IF (n < 0) THEN
CALL fail(ErrStat, ErrMsg, 'internal workspace size must be non-negative')
RETURN
Expand All @@ -1931,11 +2031,10 @@ SUBROUTINE ensure_real_vector(x, n, ErrStat, ErrMsg)
REAL(wp), ALLOCATABLE, INTENT(INOUT) :: x(:)
INTEGER, INTENT(IN) :: n
INTEGER, INTENT(OUT) :: ErrStat
CHARACTER(*), INTENT(OUT) :: ErrMsg
CHARACTER(*), INTENT(INOUT) :: ErrMsg
INTEGER :: istat

ErrStat = CD_DYN_OK
ErrMsg = ''
IF (n < 0) THEN
CALL fail(ErrStat, ErrMsg, 'internal workspace size must be non-negative')
RETURN
Expand All @@ -1952,11 +2051,10 @@ SUBROUTINE ensure_real_matrix(x, n1, n2, ErrStat, ErrMsg)
REAL(wp), ALLOCATABLE, INTENT(INOUT) :: x(:, :)
INTEGER, INTENT(IN) :: n1, n2
INTEGER, INTENT(OUT) :: ErrStat
CHARACTER(*), INTENT(OUT) :: ErrMsg
CHARACTER(*), INTENT(INOUT) :: ErrMsg
INTEGER :: istat

ErrStat = CD_DYN_OK
ErrMsg = ''
IF (n1 < 0 .OR. n2 < 0) THEN
CALL fail(ErrStat, ErrMsg, 'internal workspace shape must be non-negative')
RETURN
Expand Down
Loading
Loading