diff --git a/CHANGELOG.md b/CHANGELOG.md index c78ca02..617e8ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -257,6 +257,16 @@ All notable changes to CableDyn are recorded in this file. The format follows evaluation. Results are unchanged to the bit; the Delta Flume case 9 deck of `validation/experiments/delta_flume` (64 elements, 80 000 steps) runs in 58.6 s instead of 73.2 s. +- The nodal twist of a finite-EI cable (torsion with polar inertia `Irn`) is cheaper to + evaluate. Its reference-twist and holonomy Hessians no longer call the run-time library for + small outer products and skew matrices, and they form only the solid-angle and intermediate + blocks that are read. A frame-only twist transfer (the OpenFAST output probe on every + `CalcOutput`, the checkpoint rebuild, linearization) re-bases only the elements at a rigid end + or at a turned node; the others keep their reference twist, which the evaluation would return + unchanged. Outputs, `.CD.out` and restarts are unchanged to the bit. On the IEA-15MW + VolturnUS-S with three chains and a lazy-wave power cable restrained in torsion (one thread), + simulation CPU per simulated hour fell from 36.5 to 32.5 min (241 elements, `DT = 0.02 s`) + and from 35.0 to 30.6 min (291 elements, `DT = 0.025 s`). ### Fixed diff --git a/src/CableDyn_HermiteCableDynamic.f90 b/src/CableDyn_HermiteCableDynamic.f90 index ed77b53..efe473f 100644 --- a/src/CableDyn_HermiteCableDynamic.f90 +++ b/src/CableDyn_HermiteCableDynamic.f90 @@ -640,6 +640,13 @@ MODULE CableDyn_HermiteCableDynamic ! the step's residual norm. REAL(wp) :: tw_tsum = CD_ZERO, tw_spsi(2) = CD_ZERO, tw_tscale = CD_ONE REAL(wp), ALLOCATABLE :: tw_su(:, :), tw_stn(:, :), tw_sbeta(:) + ! tw_sq: the configuration tw_advance_reference re-based at; tw_rq: the configuration of the + ! last committed step (tw_commit_reference after a step, not a frame-only transfer), at which + ! every element passed every check of twist_reference; valid while tw_rq_ok (none before the + ! first step, after tw_init or a change of the lengths). An element whose DOFs are tw_rq's + ! and whose unit node tangents are the reference's, bit for bit, keeps its reference twist. + REAL(wp), ALLOCATABLE :: tw_sq(:), tw_rq(:) + LOGICAL :: tw_rq_ok = .FALSE. ! tw_som(:, k): the angular velocity of end frame k over the running step, log(R_{n+1} ! R_n^T)/dt (R = [d n d x n]); tw_om: that of the committed step. A turning frame twists ! the element at a rigid end through rho, and the torsional damping takes that rate. @@ -3335,6 +3342,8 @@ SUBROUTINE rebuild_length_caches(model, l0_new, ErrStat, ErrMsg) cn_new = kn_new*model%seabed_cn_over_kn END IF model%l0 = l0_new + ! (the element checks of the nodal twist's recorded configuration hold for the old lengths) + model%tw_rq_ok = .FALSE. CALL MOVE_ALLOC(mgb_new, model%Mgb) CALL MOVE_ALLOC(trib_new, model%trib) IF (model%has_contact) THEN @@ -5154,7 +5163,7 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Torsion_Frames(model, ends, ErrStat, ErrMsg, IF (PRESENT(q_check)) RETURN ! a frame turn within one step of the end-frame constants (the wrapped change is unique) model%tors_drive_set = .FALSE. - CALL tw_commit_reference(model) + CALL tw_commit_reference(model, frames_only=.TRUE.) model%torsion%ends = ends model%tors_use_step = .FALSE. CALL assemble_twist(model, model%q, model%v, .TRUE., .FALSE., model%ws_R, model%ws_Kb, model%ws_Kvb, & @@ -10900,6 +10909,8 @@ PURE SUBROUTINE tw_unpack(model, buf) model%tw_psi = buf(9*nn + 2*ne + 1:9*nn + 2*ne + 2) model%tw_om = RESHAPE(buf(9*nn + 2*ne + 3:9*nn + 2*ne + 8), [3, 2]) model%tw_oal = RESHAPE(buf(9*nn + 2*ne + 9:9*nn + 2*ne + 14), [3, 2]) + ! (tw_rq stays: it is a configuration this model evaluated, and a reloaded reference is used + ! there only where its tangents are those of tw_rq, see tw_advance_reference) END SUBROUTINE tw_unpack ELEMENTAL REAL(wp) FUNCTION tw_wrap(x) RESULT(y) @@ -11519,7 +11530,7 @@ SUBROUTINE tw_init(model, mt, ErrStat, ErrMsg) model%tw_we(nn)) ALLOCATE (model%tw_eg(12, ne), model%tw_ehv(12, ne), model%tw_ek(ne), model%tw_ed(ne), model%tw_me(ne)) ALLOCATE (model%tw_K7(3*KB7 + 1, 7*nn), model%tw_x7(7*nn), model%tw_ipiv(7*nn)) - ALLOCATE (model%tw_su(3, nn), model%tw_stn(3, nn), model%tw_sbeta(ne)) + ALLOCATE (model%tw_su(3, nn), model%tw_stn(3, nn), model%tw_sbeta(ne), model%tw_sq(6*nn), model%tw_rq(6*nn)) ALLOCATE (model%ws_recovery_tw(tw_pack_size(model))) END IF model%tw_pn = CD_ZERO; model%tw_wn = CD_ZERO; model%tw_an = CD_ZERO; model%tw_pk = CD_ZERO @@ -11615,6 +11626,7 @@ SUBROUTINE tw_init(model, mt, ErrStat, ErrMsg) model%tw_w = CD_ZERO model%tw_al = CD_ZERO model%tw_mt = mt + model%tw_rq_ok = .FALSE. model%tw_active = .TRUE. CONTAINS PURE FUNCTION unit_perp(x, ax) RESULT(y) @@ -11675,6 +11687,8 @@ SUBROUTINE tw_release(model) IF (ALLOCATED(model%tw_eg)) DEALLOCATE (model%tw_eg, model%tw_ehv, model%tw_ek, model%tw_ed, model%tw_me) IF (ALLOCATED(model%tw_K7)) DEALLOCATE (model%tw_K7, model%tw_x7, model%tw_ipiv) IF (ALLOCATED(model%tw_su)) DEALLOCATE (model%tw_su, model%tw_stn, model%tw_sbeta) + IF (ALLOCATED(model%tw_sq)) DEALLOCATE (model%tw_sq, model%tw_rq) + model%tw_rq_ok = .FALSE. IF (ALLOCATED(model%ws_recovery_tw)) DEALLOCATE (model%ws_recovery_tw) IF (ALLOCATED(model%snap_tw)) DEALLOCATE (model%snap_tw) IF (ALLOCATED(model%snap_tw_fcR)) DEALLOCATE (model%snap_tw_fcR) @@ -11685,18 +11699,47 @@ SUBROUTINE tw_advance_reference(model, q_new, ends_new, ErrStat, ErrMsg) !! reference twists and end-frame references (the step's own formulas, so the committed !! state reproduces the converged iterate bit for bit), the unit tangents and the directors !! carried over by the smallest rotation (a rigid end's: its end frame's normal carried). + !! + !! An interior element (not at a rigid end) whose 12 DOFs are those of the last committed step + !! (tw_rq) and whose unit node tangents are those of the reference, bit for bit, keeps its + !! reference twist: its transport solid angles are those of the reference terms they are + !! differenced against, so twist_reference returns tw_beta(e) + tw_wrap(0) + 0, which is + !! formed here without the evaluation; and it passed every check of twist_reference (the + !! element's fold and handle checks) at that very shape. A frame-only transfer between steps + !! (CD_HermiteCable_Dyn_Set_Torsion_Frames at the committed shape, where a host writes only + !! the end nodes) so evaluates only the elements at a rigid end or at a node the host moved; + !! the commit of a step evaluates every element that moved. TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model REAL(wp), INTENT(IN) :: q_new(:), ends_new(3, 4) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg INTEGER :: e, i, iend - REAL(wp) :: rho, beta, g(12), h(12, 12), psi, gl(3), hl(3, 3), u(3), t(3) + REAL(wp) :: rho, beta, g(12), h(12, 12), psi, gl(3), hl(3, 3), u(3), t(3), rn + LOGICAL :: kept_prev, kept_i ErrStat = CD_HCDYN_OK ErrMsg = '' + ! the unit tangents at q_new first: an element whose two tangents are the reference's keeps + ! its reference twist + ! (a zero handle keeps a zero tangent here, so its elements are evaluated and report it) + DO i = 1, model%nn + rn = NORM2(q_new(6*i - 2:6*i)) + model%tw_stn(:, i) = CD_ZERO + IF (rn > CD_ZERO) model%tw_stn(:, i) = q_new(6*i - 2:6*i)/rn + END DO + model%tw_sq = q_new + kept_prev = .FALSE. DO e = 1, model%ne - CALL twist_reference(model, e, q_new, ends_new, .FALSE., rho, beta, g, h, ErrStat, ErrMsg) - IF (ErrStat /= CD_HCDYN_OK) RETURN - model%tw_sbeta(e) = beta + kept_i = node_kept(e + 1) + IF (e == 1) kept_prev = node_kept(1) + IF (kept_prev .AND. kept_i .AND. .NOT. ((e == 1 .AND. model%tw_rigid(1)) .OR. & + (e == model%ne .AND. model%tw_rigid(2)))) THEN + model%tw_sbeta(e) = model%tw_beta(e) + tw_wrap(CD_ZERO) + CD_ZERO + ELSE + CALL twist_reference(model, e, q_new, ends_new, .FALSE., rho, beta, g, h, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) RETURN + model%tw_sbeta(e) = beta + END IF + kept_prev = kept_i END DO model%tw_spsi = model%tw_psi DO iend = 1, 2 @@ -11706,8 +11749,7 @@ SUBROUTINE tw_advance_reference(model, q_new, ends_new, ErrStat, ErrMsg) model%tw_spsi(iend) = psi END DO DO i = 1, model%nn - t = q_new(6*i - 2:6*i)/NORM2(q_new(6*i - 2:6*i)) - model%tw_stn(:, i) = t + t = model%tw_stn(:, i) IF (i == 1 .AND. model%tw_rigid(1)) THEN u = CD_HermiteTwist_Carry(ends_new(:, 1), t, ends_new(:, 2)) ELSE IF (i == model%nn .AND. model%tw_rigid(2)) THEN @@ -11718,6 +11760,22 @@ SUBROUTINE tw_advance_reference(model, q_new, ends_new, ErrStat, ErrMsg) u = u - DOT_PRODUCT(u, t)*t model%tw_su(:, i) = u/NORM2(u) END DO + CONTAINS + LOGICAL FUNCTION node_kept(k) RESULT(kept) + !! Node k's six DOFs are those of the committed reference configuration and its unit + !! tangent the reference tangent, bit for bit. + INTEGER, INTENT(IN) :: k + INTEGER :: jj + kept = model%tw_rq_ok + DO jj = 6*k - 5, 6*k + IF (.NOT. kept) RETURN + kept = bits_equal(q_new(jj), model%tw_rq(jj)) + END DO + DO jj = 1, 3 + IF (.NOT. kept) RETURN + kept = bits_equal(model%tw_stn(jj, k), model%tw_tn(jj, k)) + END DO + END FUNCTION node_kept END SUBROUTINE tw_advance_reference SUBROUTINE tw_frame_rates(model, dt) @@ -11739,12 +11797,22 @@ SUBROUTINE tw_frame_rates(model, dt) END DO END SUBROUTINE tw_frame_rates - SUBROUTINE tw_commit_reference(model) - !! Make the reference state of tw_advance_reference the committed one. + SUBROUTINE tw_commit_reference(model, frames_only) + !! Make the reference state of tw_advance_reference the committed one. After a step it also + !! records the step's configuration as tw_rq; a frame-only transfer (frames_only) keeps the + !! tw_rq of the last step, as it moves no element DOF but the end nodes'. TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + LOGICAL, INTENT(IN), OPTIONAL :: frames_only + LOGICAL :: record + record = .TRUE. + IF (PRESENT(frames_only)) record = .NOT. frames_only model%tw_beta = model%tw_sbeta model%tw_psi = model%tw_spsi model%tw_tn = model%tw_stn + IF (record) THEN + model%tw_rq = model%tw_sq + model%tw_rq_ok = .TRUE. + END IF model%tw_u = model%tw_su END SUBROUTINE tw_commit_reference diff --git a/src/CableDyn_HermiteTorsion.f90 b/src/CableDyn_HermiteTorsion.f90 index 752b558..8929f74 100644 --- a/src/CableDyn_HermiteTorsion.f90 +++ b/src/CableDyn_HermiteTorsion.f90 @@ -1396,7 +1396,7 @@ PURE SUBROUTINE CD_HermiteTwist_Reference(qe, L, tri, tslot, tsign, value, grad, LOGICAL, INTENT(IN), OPTIONAL :: holonomy INTEGER, INTENT(IN), OPTIONAL :: quadrature_order INTEGER :: order, k, j, i, ntri, si, sj - LOGICAL :: want_hess, with_h, need(2), finite + LOGICAL :: want_hess, with_h, need(2), finite, free(3) REAL(wp) :: node_t(3, 2), proj(3, 3, 2), x(3, 3), om, g9(9), h9(9, 9), gt(3, 2), htt(3, 3, 2, 2) REAL(wp) :: he, ge(12), hk(12, 12), dmy, blk(3, 3), blk2(3, 3) CHARACTER(200) :: em @@ -1433,13 +1433,8 @@ PURE SUBROUTINE CD_HermiteTwist_Reference(qe, L, tri, tslot, tsign, value, grad, END IF need(1) = ANY(tslot == 1) .OR. with_h need(2) = ANY(tslot == 2) .OR. with_h - ! (column by column: a reshaped copy of the assumed-shape tri would be a heap temporary) - finite = CD_All_Finite(qe) .AND. CD_Is_Finite(L) .AND. CD_All_Finite(tsign) - DO k = 1, ntri - DO j = 1, 3 - finite = finite .AND. CD_All_Finite(tri(:, j, k)) - END DO - END DO + ! (the rank-3 test reads tri in place: a reshaped copy would be a heap temporary) + finite = CD_All_Finite(qe) .AND. CD_Is_Finite(L) .AND. CD_All_Finite(tsign) .AND. CD_All_Finite(tri) IF (.NOT. finite) THEN ErrStat = CD_HTORS_NONFINITE ErrMsg = 'CD_HermiteTwist_Reference: non-finite input' @@ -1488,7 +1483,11 @@ PURE SUBROUTINE CD_HermiteTwist_Reference(qe, L, tri, tslot, tsign, value, grad, RETURN END IF END DO - CALL solid_angle(x(:, 1), x(:, 2), x(:, 3), want_hess, om, g9, h9) + ! (a local mask: the expression tslot(:, k) /= 0 as the argument is a heap temporary) + DO j = 1, 3 + free(j) = tslot(j, k) /= 0 + END DO + CALL solid_angle(x(:, 1), x(:, 2), x(:, 3), want_hess, om, g9, h9, free=free) value = value + tsign(k)*om DO j = 1, 3 si = tslot(j, k) @@ -1544,11 +1543,7 @@ PURE SUBROUTINE CD_HermiteTwist_Reference(qe, L, tri, tslot, tsign, value, grad, RETURN END IF IF (want_hess) THEN - finite = .TRUE. - DO j = 1, 12 - finite = finite .AND. CD_All_Finite(hess(:, j)) - END DO - IF (.NOT. finite) THEN + IF (.NOT. CD_All_Finite(hess)) THEN ErrStat = CD_HTORS_NONFINITE ErrMsg = 'CD_HermiteTwist_Reference: non-finite twist Hessian' value = CD_ZERO @@ -1727,8 +1722,14 @@ PURE SUBROUTINE element_holonomy(qe, L, order, want_hess, h, grad, hess, margin, margin = HUGE(CD_ONE) CALL CD_HermiteCable_Gauss_Rule(order, gp, gw) DO ig = 1, order + ! (element_ab, on the shape derivatives at hand) CALL shape_derivatives(L, gp(ig), dh, ddh) - CALL element_ab(qe, L, gp(ig), a, b) + a = CD_ZERO + b = CD_ZERO + DO i = 1, 4 + a = a + dh(i)*qe(3*i - 2:3*i) + b = b + ddh(i)*qe(3*i - 2:3*i) + END DO s2 = DOT_PRODUCT(a, a) sp = SQRT(s2) IF (sp <= GEOM_TOL) THEN @@ -1771,7 +1772,12 @@ PURE SUBROUTINE element_holonomy(qe, L, order, want_hess, h, grad, hess, margin, hd(1:3, 1:3) = 2.0_wp*eye + ta*(eye/sp - outer(a, a)/(sp*s2)) + (outer(a, t) + outer(t, a))/sp hd(1:3, 7:9) = outer(a, a)/sp + sp*eye hd(7:9, 1:3) = TRANSPOSE(hd(1:3, 7:9)) - hf = (hn - f*hd - outer9(gf, gd) - outer9(gd, gf))/den + ! (the blocks read below: rows 7:9 only against columns 7:9) + DO j = 1, 9 + DO i = 1, MERGE(9, 6, j > 6) + hf(i, j) = (hn(i, j) - f*hd(i, j) - gf(i)*gd(j) - gd(i)*gf(j))/den + END DO + END DO DO j = 1, 4 DO i = 1, 4 blk = dh(i)*dh(j)*hf(1:3, 1:3) + dh(i)*ddh(j)*hf(1:3, 4:6) + ddh(i)*dh(j)*hf(4:6, 1:3) & @@ -1871,14 +1877,18 @@ PURE FUNCTION smallest_rotation(a, b, v) RESULT(r) r = c*v + cross(w, v) + w*DOT_PRODUCT(w, v)/(CD_ONE + c) END FUNCTION smallest_rotation - PURE SUBROUTINE solid_angle(x, y, z, want_hess, om, g, h) + PURE SUBROUTINE solid_angle(x, y, z, want_hess, om, g, h, free) !! Omega = 2 atan2(N, D), N = x.(y x z), D = 1 + x.y + y.z + z.x (signed solid angle of the !! geodesic triangle x, y, z), with gradient g and Hessian h in the raw vectors (x, y, z). - !! Under the fold guard every triangle used here has D >= 1.5. + !! Under the fold guard every triangle used here has D >= 1.5. With free, only the Hessian + !! blocks between two free vertices (free(j): vertex j is a variable of the caller) are + !! formed, each entry as the full Hessian forms it; the others are zero. REAL(wp), INTENT(IN) :: x(3), y(3), z(3) LOGICAL, INTENT(IN) :: want_hess REAL(wp), INTENT(OUT) :: om, g(9), h(9, 9) - REAL(wp) :: nv, dv, r2, gn(9), gd(9), eye(3, 3) + LOGICAL, INTENT(IN), OPTIONAL :: free(3) + REAL(wp) :: nv, dv, r2, gn(9), gd(9), eye(3, 3), h0(3, 3), c1, c2, s(3, 3) + INTEGER :: bi, bj, i, j, ii, jj nv = DOT_PRODUCT(x, cross(y, z)) dv = CD_ONE + DOT_PRODUCT(x, y) + DOT_PRODUCT(y, z) + DOT_PRODUCT(z, x) @@ -1894,6 +1904,42 @@ PURE SUBROUTINE solid_angle(x, y, z, want_hess, om, g, h) h = CD_ZERO IF (.NOT. want_hess) RETURN eye = identity3() + IF (PRESENT(free)) THEN + c1 = nv*nv - dv*dv + c2 = 2.0_wp*dv*nv + DO bj = 1, 3 + IF (.NOT. free(bj)) CYCLE + DO bi = 1, 3 + IF (.NOT. free(bi)) CYCLE + ! the block (bi, bj) of d2N and d2D before the scaling below + IF (bi == bj) THEN + h0 = CD_ZERO + ELSE + IF (bi + bj == 3) THEN + s = skew(z) + ELSE IF (bi + bj == 5) THEN + s = skew(x) + ELSE + s = skew(y) + END IF + IF (bj == MOD(bi, 3) + 1) THEN + h0 = -dv*s - nv*eye + ELSE + h0 = dv*s - nv*eye + END IF + END IF + DO j = 1, 3 + jj = 3*(bj - 1) + j + DO i = 1, 3 + ii = 3*(bi - 1) + i + h(ii, jj) = 2.0_wp*(h0(i, j)/r2 + (c1*(gn(ii)*gd(jj) + gd(ii)*gn(jj)) & + - c2*(gn(ii)*gn(jj) - gd(ii)*gd(jj)))/(r2*r2)) + END DO + END DO + END DO + END DO + RETURN + END IF ! d2N: (x,y) = -S(z), (y,z) = -S(x), (z,x) = -S(y); d2D: identity off-diagonal blocks h(1:3, 4:6) = -dv*skew(z) - nv*eye h(4:6, 1:3) = dv*skew(z) - nv*eye @@ -1959,28 +2005,52 @@ PURE FUNCTION cross(a, b) RESULT(c) c = [a(2)*b(3) - a(3)*b(2), a(3)*b(1) - a(1)*b(3), a(1)*b(2) - a(2)*b(1)] END FUNCTION cross + ! (element by element: the RESHAPE and SPREAD forms of these are run-time library calls on the + ! torsion kernels' hot path; the entries are the same products) + PURE FUNCTION skew(v) RESULT(s) !! S(v) w = v x w. REAL(wp), INTENT(IN) :: v(3) REAL(wp) :: s(3, 3) - s = RESHAPE([CD_ZERO, v(3), -v(2), -v(3), CD_ZERO, v(1), v(2), -v(1), CD_ZERO], [3, 3]) + s(1, 1) = CD_ZERO + s(2, 1) = v(3) + s(3, 1) = -v(2) + s(1, 2) = -v(3) + s(2, 2) = CD_ZERO + s(3, 2) = v(1) + s(1, 3) = v(2) + s(2, 3) = -v(1) + s(3, 3) = CD_ZERO END FUNCTION skew PURE FUNCTION outer(a, b) RESULT(m) REAL(wp), INTENT(IN) :: a(3), b(3) REAL(wp) :: m(3, 3) - m = SPREAD(a, 2, 3)*SPREAD(b, 1, 3) + INTEGER :: i, j + DO j = 1, 3 + DO i = 1, 3 + m(i, j) = a(i)*b(j) + END DO + END DO END FUNCTION outer PURE FUNCTION outer9(a, b) RESULT(m) REAL(wp), INTENT(IN) :: a(9), b(9) REAL(wp) :: m(9, 9) - m = SPREAD(a, 2, 9)*SPREAD(b, 1, 9) + INTEGER :: i, j + DO j = 1, 9 + DO i = 1, 9 + m(i, j) = a(i)*b(j) + END DO + END DO END FUNCTION outer9 PURE FUNCTION identity3() RESULT(m) REAL(wp) :: m(3, 3) - m = RESHAPE([CD_ONE, CD_ZERO, CD_ZERO, CD_ZERO, CD_ONE, CD_ZERO, CD_ZERO, CD_ZERO, CD_ONE], [3, 3]) + m = CD_ZERO + m(1, 1) = CD_ONE + m(2, 2) = CD_ONE + m(3, 3) = CD_ONE END FUNCTION identity3 END MODULE CableDyn_HermiteTorsion diff --git a/tests/test_nodal_twist_dynamic.f90 b/tests/test_nodal_twist_dynamic.f90 index 0a6bcf0..c447791 100644 --- a/tests/test_nodal_twist_dynamic.f90 +++ b/tests/test_nodal_twist_dynamic.f90 @@ -28,7 +28,12 @@ PROGRAM test_nodal_twist_dynamic !! carries at most 4e-6 of the peak kinetic energy with an extreme Irn = 1 kg m (6e-8 at !! 0.02 kg m), below the step's own energy band; !! R restart: a rolling, torsionally damped run restored from a snapshot, and one rebuilt - !! from the checkpoint mirror, continue bit-identically. + !! from the checkpoint mirror, continue bit-identically; + !! F a coupled write that folds the end element (the coupled end, elastic in torsion and + !! pinned in bending, translated past its neighbour with its tangent unchanged) is refused + !! before anything is written, after a march and after a frame-only transfer (whose + !! re-basing keeps the elements at the committed shape); a length change drops the + !! configuration the shortcut of the re-basing keeps elements at, and the next step records it. USE CableDyn_Precision, ONLY: wp USE CableDyn_EndConnection, ONLY: CD_ENDCONN_RIGID USE CableDyn_HermiteTorsion, ONLY: CD_HermiteTorsionType, CD_HermiteTorsion_Line, CD_HermiteTorsion_Unwrap, & @@ -37,11 +42,13 @@ PROGRAM test_nodal_twist_dynamic CD_HermiteCable_Dyn_Step, CD_HermiteCable_Dyn_Energy, & CD_HermiteCable_Dyn_End, CD_HermiteCable_Dyn_Set_EndConnection, & CD_HermiteCable_Dyn_Set_Torsion, CD_HermiteCable_Dyn_Torsion_State, & - CD_HermiteCable_Dyn_Node_Torque, CD_HCDYN_OK + CD_HermiteCable_Dyn_Node_Torque, CD_HermiteCable_Dyn_Set_SegmentLength, & + CD_HCDYN_OK USE CableDyn_OpenFAST_HermiteFMF, ONLY: CD_HFMF_ModuleType, CD_HFMF_Init, CD_HFMF_Set_EndConnection, & CD_HFMF_Set_Torsion, CD_HFMF_UpdateStates, CD_HFMF_CalcOutput, & CD_HFMF_Snapshot, CD_HFMF_Restore, CD_HFMF_MirrorSize, & - CD_HFMF_PackMirror, CD_HFMF_UnpackMirror, CD_HFMF_End, CD_HFMF_OK + CD_HFMF_PackMirror, CD_HFMF_UnpackMirror, CD_HFMF_End, CD_HFMF_OK, & + CD_HFMF_SetCoupledKinematics IMPLICIT NONE REAL(wp), PARAMETER :: PI = 3.14159265358979323846_wp @@ -61,6 +68,7 @@ PROGRAM test_nodal_twist_dynamic CALL check_frame_energy() CALL check_pinned_energy() CALL check_restart() + CALL check_fold_refused() IF (nfail > 0) THEN WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' @@ -266,6 +274,58 @@ SUBROUTINE check_quasi_static(label, pinned, compliance) CALL CD_HFMF_End(cn) END SUBROUTINE check_quasi_static + ! ------------------------------------------------------------------------------------------ + SUBROUTINE check_fold_refused() + !! F: march a bending-pinned line, elastic in torsion, then write the coupled end 0.8 m back + !! along the line, past its neighbour 0.5 m away, with the end tangent unchanged: the end + !! element folds, and the write is refused with the state untouched. The same after a + !! frame-only transfer of the march's last pose. + TYPE(CD_HFMF_ModuleType), ALLOCATABLE :: cab + REAL(wp) :: q(NDOF), x(3), v(3), a(3), dcm(3, 3), w(3), al(3), phi + REAL(wp), ALLOCATABLE :: q0(:), u0(:, :), b0(:) + INTEGER :: es, pass + LOGICAL :: ok + CHARACTER(300) :: em + ALLOCATE (cab) + CALL line_seed(0.0_wp, 0.0_wp, q) + CALL build_cable(cab, q, 1.0_wp, 0.01_wp, 1.0e-10_wp, 0.8_wp, .TRUE., 1.0e-9_wp, 0.05_wp) + CALL require(cab%line%tw_active, 'F: the nodal twist is active') + CALL march(cab, 0, 20, ok) + CALL require(ok, 'F: the march steps') + IF (.NOT. ok) RETURN + DO pass = 1, 2 + CALL drive(20, x, v, a, dcm, w, al, phi) + IF (pass == 2) THEN + ! a frame-only transfer of the committed pose first: it re-bases the reference + x = cab%line%q(NDOF - 5:NDOF - 3) + CALL CD_HFMF_SetCoupledKinematics(cab, x, v, a, es, em, u_orientation=dcm, & + u_angular_velocity=w, u_angular_acceleration=al) + CALL require(es == CD_HFMF_OK, 'F: a frame-only transfer of the committed pose: '//TRIM(em)) + END IF + q0 = cab%line%q + u0 = cab%line%tw_u + b0 = cab%line%tw_beta + ! (the coupled node's committed position, node NN; the cable frame is the global one) + x = cab%line%q(NDOF - 5:NDOF - 3) - [0.8_wp, 0.0_wp, 0.0_wp] + CALL CD_HFMF_SetCoupledKinematics(cab, x, v, a, es, em, u_orientation=dcm, u_angular_velocity=w, & + u_angular_acceleration=al) + WRITE (*, '(A,I0,A)') 'F fold through the coupled end (pass ', pass, '): '//TRIM(em) + CALL require(es /= CD_HFMF_OK, 'F: a write that folds the end element is refused') + CALL require(nan_max_abs(cab%line%q - q0) <= 0.0_wp .AND. nan_max_abs(cab%line%tw_beta - b0) <= 0.0_wp & + .AND. nan_max_abs(RESHAPE(cab%line%tw_u - u0, [3*NN])) <= 0.0_wp, & + 'F: the refused write leaves the line and its twist reference unchanged') + END DO + ! a length change: the element shapes are no longer those the checks passed at, so the + ! recorded configuration is dropped (every element is evaluated) until the next step + CALL require(cab%line%tw_rq_ok, 'F: a committed step records its configuration') + CALL CD_HermiteCable_Dyn_Set_SegmentLength(cab%line, [NE/2], [0.55_wp], [0.0_wp], es, em) + CALL require(es == CD_HCDYN_OK .AND. .NOT. cab%line%tw_rq_ok, & + 'F: a length change drops the recorded configuration: '//TRIM(em)) + CALL march(cab, 20, 21, ok) + CALL require(ok .AND. cab%line%tw_rq_ok, 'F: the next step records it again') + CALL CD_HFMF_End(cab) + END SUBROUTINE check_fold_refused + ! ------------------------------------------------------------------------------------------ SUBROUTINE check_waves() !! W: a roll A sin(Omega t) of the coupled end (amplitude ramped in over the first eight