diff --git a/CHANGELOG.md b/CHANGELOG.md index f3cd4ae7..261c0569 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,20 @@ All notable changes to CableDyn are recorded in this file. The format follows The r-test `MD_Shared` SeaState file of the OpenFAST tutorial, which covers only the platform, now stops until its grid is enlarged as the tutorial describes. Runs that pass the checks give the same results, bit for bit. +- In OpenFAST, CableDyn evaluates its output channels only at the steps OpenFAST writes (`DT_Out`, from + `TStart`) and when it linearizes, as AeroDyn and BeamDyn can, where it evaluated them at every output + call of every step (two to four per step in the tightly coupled solver). The loads are evaluated as + before. On the IEA-15 MW lazy-wave cable deck with 17 stations and torsion channels at DT = 0.025 s, + `DT_Out` = 0.05 s, the channels cost 12.6 s where they cost 53.1 s and the run 10 % less CPU time; the + `.out` and `.CD.out` are the same as before, bit for bit, also with the mooring supercycled and after a + restart from a checkpoint. This needs the OpenFAST integration patches of this release. +- The nodal twist of a finite-EI line costs less. Its residual no longer forms the Hessian of the + torque-tension coupling term, which only the tangent uses. An element's reference twist is taken + from the last evaluation when every input it reads is the same, bit for bit; in OpenFAST every output + call moves only the fairlead end, so all elements but the end ones are taken over. On the IEA-15 MW + lazy-wave cable deck (237 elements, torsion, DT = 0.0125 s, 400 s, operating rotor) the run takes + 9.00 min of CPU time where it took 9.79 min after the change above (11.23 min before both); the + `.out` and `.CD.out` are the same, bit for bit. - In OpenFAST, the lines on the SeaState grid route take the wave and current kinematics at their positions at the sample time (the end of the CableDyn step): their committed positions advanced by diff --git a/integration/openfast/patches/0009-fast-funcs.patch b/integration/openfast/patches/0009-fast-funcs.patch index 6c844044..5ee1ee23 100644 --- a/integration/openfast/patches/0009-fast-funcs.patch +++ b/integration/openfast/patches/0009-fast-funcs.patch @@ -1,5 +1,5 @@ diff --git a/modules/openfast-library/src/FAST_Funcs.f90 b/modules/openfast-library/src/FAST_Funcs.f90 -index ff46ce942..46e7a09e1 100644 +index ff46ce942..323baf77c 100644 --- a/modules/openfast-library/src/FAST_Funcs.f90 +++ b/modules/openfast-library/src/FAST_Funcs.f90 @@ -104,6 +104,13 @@ use MoorDyn, only: MD_JacobianPInput, & @@ -60,19 +60,22 @@ index ff46ce942..46e7a09e1 100644 case (Module_Orca) call FAST_CopyStates(ModData, T, STATE_CURR, STATE_PRED, MESH_UPDATECOPY, ErrStat2, ErrMsg2) if (Failed()) return -@@ -827,6 +857,11 @@ subroutine FAST_CalcOutput(ModData, Mappings, ThisTime, iInput, iState, T, ErrSt +@@ -827,6 +857,14 @@ subroutine FAST_CalcOutput(ModData, Mappings, ThisTime, iInput, iState, T, ErrSt T%MD%x(iState), T%MD%xd(iState), T%MD%z(iState), T%MD%OtherSt(iState), & T%MD%y, T%MD%m, ErrStat2, ErrMsg2) + case (Module_CD) ++ ! CableDyn evaluates its deck channels only when this step's outputs are written (or the ++ ! glue linearizes); its loads are evaluated on every call. + call CD_CalcOutput(ThisTime, T%CD%Input(iInput), T%CD%p, & + T%CD%x(iState), T%CD%xd(iState), T%CD%z(iState), T%CD%OtherSt(iState), & -+ T%CD%y, T%CD%m, ErrStat2, ErrMsg2) ++ T%CD%y, T%CD%m, ErrStat2, ErrMsg2, & ++ CalcWriteOutput=CalcWriteOutputLoc .and. (T%y_FAST%WriteThisStep .or. T%p_FAST%Linearize)) + case (Module_Orca) call Orca_CalcOutput(ThisTime, T%Orca%Input(iInput), T%Orca%p, & T%Orca%x(iState), T%Orca%xd(iState), T%Orca%z(iState), T%Orca%OtherSt(iState), & -@@ -937,6 +972,8 @@ subroutine FAST_GetOP(ModData, ThisTime, iInput, iState, T, ErrStat, ErrMsg, & +@@ -937,6 +975,8 @@ subroutine FAST_GetOP(ModData, ThisTime, iInput, iState, T, ErrStat, ErrMsg, & call MAP_VarsPackInput(ModData%Vars, T%MAP%Input(iInput), u_op) case (Module_MD) call MD_VarsPackInput(ModData%Vars, T%MD%Input(iInput), u_op) @@ -81,7 +84,7 @@ index ff46ce942..46e7a09e1 100644 case (Module_ExtInfw) ! call ExtInfw_VarsPackInput(ModData%Vars, T%ExtInfw%Input(iIndex), u_op) case (Module_Orca) -@@ -994,6 +1031,8 @@ subroutine FAST_GetOP(ModData, ThisTime, iInput, iState, T, ErrStat, ErrMsg, & +@@ -994,6 +1034,8 @@ subroutine FAST_GetOP(ModData, ThisTime, iInput, iState, T, ErrStat, ErrMsg, & call MAP_VarsPackOutput(ModData%Vars, T%MAP%y, y_op) case (Module_MD) call MD_VarsPackOutput(ModData%Vars, T%MD%y, y_op) @@ -90,7 +93,7 @@ index ff46ce942..46e7a09e1 100644 case (Module_ExtInfw) call ExtInfw_VarsPackOutput(ModData%Vars, T%ExtInfw%y, y_op) case (Module_Orca) -@@ -1050,6 +1089,8 @@ subroutine FAST_GetOP(ModData, ThisTime, iInput, iState, T, ErrStat, ErrMsg, & +@@ -1050,6 +1092,8 @@ subroutine FAST_GetOP(ModData, ThisTime, iInput, iState, T, ErrStat, ErrMsg, & call MAP_VarsPackContState(ModData%Vars, T%MAP%x(iState), x_op) case (Module_MD) call MD_VarsPackContState(ModData%Vars, T%MD%x(iState), x_op) @@ -99,7 +102,7 @@ index ff46ce942..46e7a09e1 100644 case (Module_ExtInfw) ! call ExtInfw_VarsPackContState(ModData%Vars, T%ExtInfw%x(StateIndex), x_op) case (Module_Orca) -@@ -1181,6 +1222,13 @@ subroutine FAST_GetOP(ModData, ThisTime, iInput, iState, T, ErrStat, ErrMsg, & +@@ -1181,6 +1225,13 @@ subroutine FAST_GetOP(ModData, ThisTime, iInput, iState, T, ErrStat, ErrMsg, & if (Failed()) return call MD_VarsPackContStateDeriv(ModData%Vars, T%MD%m%dxdt_lin, dx_op) @@ -113,7 +116,7 @@ index ff46ce942..46e7a09e1 100644 ! case (Module_ExtInfw) ! call ExtInfw_VarsPackContStateDeriv(ModData%Vars, T%ExtInfw%x(StateIndex), dx_op) -@@ -1274,6 +1322,8 @@ subroutine FAST_SetOP(ModData, iInput, iState, T, ErrStat, ErrMsg, & +@@ -1274,6 +1325,8 @@ subroutine FAST_SetOP(ModData, iInput, iState, T, ErrStat, ErrMsg, & call MAP_VarsUnpackInput(ModData%Vars, u_op, T%MAP%Input(iInput)) case (Module_MD) call MD_VarsUnpackInput(ModData%Vars, u_op, T%MD%Input(iInput)) @@ -122,7 +125,7 @@ index ff46ce942..46e7a09e1 100644 case (Module_ExtInfw) ! call ExtInfw_VarsUnpackInput(ModData%Vu_op, ars, T%ExtInfw%Input(InputIndex)) case (Module_Orca) -@@ -1325,6 +1375,8 @@ subroutine FAST_SetOP(ModData, iInput, iState, T, ErrStat, ErrMsg, & +@@ -1325,6 +1378,8 @@ subroutine FAST_SetOP(ModData, iInput, iState, T, ErrStat, ErrMsg, & call MAP_VarsUnpackContState(ModData%Vars, x_op, T%MAP%x(iState)) case (Module_MD) call MD_VarsUnpackContState(ModData%Vars, x_op, T%MD%x(iState)) @@ -131,7 +134,7 @@ index ff46ce942..46e7a09e1 100644 case (Module_ExtInfw) ! call ExtInfw_VarsUnpackContState(ModData%Vars, x_op, T%ExtInfw%x(StateIndex)) case (Module_Orca) -@@ -1426,6 +1478,11 @@ subroutine FAST_JacobianPInput(ModData, ThisTime, iInput, iState, T, ErrStat, Er +@@ -1426,6 +1481,11 @@ subroutine FAST_JacobianPInput(ModData, ThisTime, iInput, iState, T, ErrStat, Er T%MD%z(iState), T%MD%OtherSt(iState), T%MD%y, T%MD%m, ErrStat2, ErrMsg2, & dYdu=dYdu, dXdu=dXdu) @@ -143,7 +146,7 @@ index ff46ce942..46e7a09e1 100644 case (Module_SD) call SD_JacobianPInput(ModData%Vars, ThisTime, T%SD%Input(iInput), T%SD%p, T%SD%x(iState), T%SD%xd(iState), & T%SD%z(iState), T%SD%OtherSt(iState), T%SD%y, T%SD%m, ErrStat2, ErrMsg2, & -@@ -1545,6 +1602,13 @@ subroutine FAST_JacobianPContState(ModData, ThisTime, iInput, iState, T, ErrStat +@@ -1545,6 +1605,13 @@ subroutine FAST_JacobianPContState(ModData, ThisTime, iInput, iState, T, ErrStat T%MD%y, T%MD%m, ErrStat2, ErrMsg2, & dYdx=dYdx, dXdx=dXdx) @@ -157,7 +160,7 @@ index ff46ce942..46e7a09e1 100644 case (Module_SD) call SD_JacobianPContState(ModData%Vars, ThisTime, T%SD%Input(iInput), T%SD%p, & T%SD%x(iState), T%SD%xd(iState), & -@@ -1715,6 +1779,13 @@ subroutine FAST_CopyStates(ModData, T, iSrc, iDst, CtrlCode, ErrStat, ErrMsg) +@@ -1715,6 +1782,13 @@ subroutine FAST_CopyStates(ModData, T, iSrc, iDst, CtrlCode, ErrStat, ErrMsg) call MD_CopyConstrState(T%MD%z(iSrc), T%MD%z(iDst), CtrlCode, ErrStat2, ErrMsg2); if (Failed()) return call MD_CopyOtherState(T%MD%OtherSt(iSrc), T%MD%OtherSt(iDst), CtrlCode, ErrStat2, ErrMsg2); if (Failed()) return @@ -171,7 +174,7 @@ index ff46ce942..46e7a09e1 100644 case (Module_Orca) call Orca_CopyContState(T%Orca%x(iSrc), T%Orca%x(iDst), CtrlCode, ErrStat2, ErrMsg2); if (Failed()) return -@@ -1842,6 +1913,9 @@ subroutine FAST_CopyInput(ModData, T, iSrc, iDst, CtrlCode, ErrStat, ErrMsg) +@@ -1842,6 +1916,9 @@ subroutine FAST_CopyInput(ModData, T, iSrc, iDst, CtrlCode, ErrStat, ErrMsg) case (Module_MD) call MD_CopyInput(T%MD%Input(iSrc), T%MD%Input(iDst), CtrlCode, ErrStat2, ErrMsg2) @@ -181,7 +184,7 @@ index ff46ce942..46e7a09e1 100644 ! case (Module_ExtInfw) case (Module_Orca) -@@ -2004,6 +2078,10 @@ subroutine FAST_ModEnd(Mods, T, ErrStat, ErrMsg) +@@ -2004,6 +2081,10 @@ subroutine FAST_ModEnd(Mods, T, ErrStat, ErrMsg) call MD_End(T%MD%Input(1), T%MD%p, T%MD%x(STATE_CURR), T%MD%xd(STATE_CURR), T%MD%z(STATE_CURR), & T%MD%OtherSt(STATE_CURR), T%MD%y, T%MD%m, ErrStat2, ErrMsg2) @@ -192,4 +195,3 @@ index ff46ce942..46e7a09e1 100644 case (Module_Orca) call Orca_End(T%Orca%Input(1), T%Orca%p, T%Orca%x(STATE_CURR), T%Orca%xd(STATE_CURR), & T%Orca%z(STATE_CURR), T%Orca%OtherSt(STATE_CURR), T%Orca%y, T%Orca%m, ErrStat2, ErrMsg2) - diff --git a/src/CableDyn_HermiteCableDynamic.f90 b/src/CableDyn_HermiteCableDynamic.f90 index 50c8a607..103ba248 100644 --- a/src/CableDyn_HermiteCableDynamic.f90 +++ b/src/CableDyn_HermiteCableDynamic.f90 @@ -195,6 +195,9 @@ MODULE CableDyn_HermiteCableDynamic INTEGER, PARAMETER :: KL_D = 11, KU_D = 11 ! Half-bandwidth of the nodal-twist tangent in 7-DOF-per-node order ([r, m, phi] per node). INTEGER, PARAMETER :: KB7 = 13 + ! Inputs of the twist_reference memo per element (tw_mk): 12 DOFs, 2 unit tangents, tw_beta, + ! l0 and the coupling. + INTEGER, PARAMETER :: TW_MEMO_KEY = 21 INTEGER, PARAMETER :: LDAB_D = 2*KL_D + KU_D + 1 ! First row of the stored band. Rows 1..KL_D are the factorization's fill-in space: every ! band array is allocated with them zero and only an LU factor (ws_Keffb) ever writes them, @@ -652,6 +655,16 @@ MODULE CableDyn_HermiteCableDynamic ! 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. + ! A memo of twist_reference without the Hessian at an element away from a rigid end, for + ! assemble_twist: tw_mk(:, e) the inputs it reads there (the element's 12 DOFs, the reference + ! unit tangents of its two nodes, tw_beta, l0, the coupling), tw_mqo(e) the quadrature order, + ! tw_mv(:, e) the results (rho, beta, g). An assembly takes the results only when every input + ! is bitwise the memo's (tw_mo), so it can never be stale. A host's frame-only transfer + ! (CD_HermiteCable_Dyn_Set_Torsion_Frames, every OpenFAST output call) assembles every element + ! at the committed shape; all but the elements at the moved end nodes then hit. + REAL(wp), ALLOCATABLE :: tw_mk(:, :), tw_mv(:, :) + INTEGER, ALLOCATABLE :: tw_mqo(:) + LOGICAL, ALLOCATABLE :: tw_mo(:) ! 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. @@ -11115,7 +11128,8 @@ SUBROUTINE twist_reference(model, e, q_cfg, ends, want_hess, rho, beta, g, h, Er cpl = CD_ZERO IF (ALLOCATED(model%torsion%couple)) cpl = model%torsion%couple(e) IF (ABS(cpl) > CD_ZERO) THEN - CALL CD_HermiteTorsion_Stretch_Derivatives(qe, model%l0(e), ls, gs, hs, model%torsion%quadrature_order) + CALL CD_HermiteTorsion_Stretch_Derivatives(qe, model%l0(e), ls, gs, hs, model%torsion%quadrature_order, & + want_hess=want_hess) rho = rho + cpl*(ls - model%l0(e)) g = g + cpl*gs IF (want_hess) h = h + cpl*hs @@ -11252,7 +11266,8 @@ SUBROUTINE assemble_twist(model, q_cfg, v_cfg, want_residual, want_tangent, R, K ! length-rate share of the damping (active line control): l0_dot/l0, the element's tangent ! handles (m in the 12-DOF layout, the r slots zero) and the angle stiffness it leaves REAL(wp) :: rr, mv(12), gmv(12), kel_t, cpl - LOGICAL :: ctrl_rate, one_node + LOGICAL :: ctrl_rate, one_node, memo + REAL(wp) :: key(TW_MEMO_KEY) INTEGER :: e, iend, node, b, i, j, es, e_lo, e_hi CHARACTER(1024) :: em @@ -11288,8 +11303,31 @@ SUBROUTINE assemble_twist(model, q_cfg, v_cfg, want_residual, want_tangent, R, K ! an element at a rigid end twists through rho as its end frame turns: its damping rate ! takes d rho/dw . omega of the frames (the tangent keeps the rate's q-dependence through ! g only, as the frame's share of it is of order omega dt) + memo = .NOT. want_tangent .AND. ALLOCATED(model%tw_mo) .AND. & + .NOT. ((e == 1 .AND. model%tw_rigid(1)) .OR. (e == model%ne .AND. model%tw_rigid(2))) IF (turning .AND. kd > CD_ZERO .AND. (e == 1 .OR. e == model%ne)) THEN CALL twist_reference(model, e, q_cfg, ends, want_tangent, rho, beta, g, h, es, em, end_w=ew) + ELSE IF (memo) THEN + ! (twist_reference reads, away from a rigid end, exactly the inputs of the key) + CALL tw_memo_inputs(model, e, q_cfg, key) + IF (model%tw_mo(e) .AND. model%tw_mqo(e) == model%torsion%quadrature_order .AND. & + ALL(bits_equal(key, model%tw_mk(:, e)))) THEN + rho = model%tw_mv(1, e) + beta = model%tw_mv(2, e) + g = model%tw_mv(3:14, e) + es = CD_HCDYN_OK + ELSE + CALL twist_reference(model, e, q_cfg, ends, .FALSE., rho, beta, g, h, es, em) + model%tw_mo(e) = es == CD_HCDYN_OK + IF (model%tw_mo(e)) THEN + model%tw_mk(:, e) = key + model%tw_mqo(e) = model%torsion%quadrature_order + model%tw_mv(1, e) = rho + model%tw_mv(2, e) = beta + model%tw_mv(3:14, e) = g + END IF + END IF + ew = CD_ZERO ELSE CALL twist_reference(model, e, q_cfg, ends, want_tangent, rho, beta, g, h, es, em) ew = CD_ZERO @@ -11573,8 +11611,10 @@ SUBROUTINE tw_init(model, mt, ErrStat, ErrMsg) 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), model%tw_sq(6*nn), model%tw_rq(6*nn)) + ALLOCATE (model%tw_mk(TW_MEMO_KEY, ne), model%tw_mv(14, ne), model%tw_mqo(ne), model%tw_mo(ne)) ALLOCATE (model%ws_recovery_tw(tw_pack_size(model))) END IF + model%tw_mo = .FALSE. model%tw_pn = CD_ZERO; model%tw_wn = CD_ZERO; model%tw_an = CD_ZERO; model%tw_pk = CD_ZERO model%tw_wk = CD_ZERO; model%tw_ak = CD_ZERO; model%tw_ptrial = CD_ZERO; model%tw_dp = CD_ZERO model%tw_G = CD_ZERO; model%tw_Gt = CD_ZERO; model%tw_Rk = CD_ZERO; model%tw_Rt = CD_ZERO @@ -11730,12 +11770,30 @@ SUBROUTINE tw_release(model) 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) + IF (ALLOCATED(model%tw_mk)) DEALLOCATE (model%tw_mk, model%tw_mv, model%tw_mqo, model%tw_mo) 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) END SUBROUTINE tw_release + PURE SUBROUTINE tw_memo_inputs(model, e, q_cfg, key) + !! The inputs twist_reference reads at an element e away from a rigid end (see tw_mk): the + !! element's 12 DOFs of q_cfg, the reference unit tangents of its nodes, tw_beta(e), l0(e) + !! and the coupling (zero when there is none, as twist_reference takes it). + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + INTEGER, INTENT(IN) :: e + REAL(wp), INTENT(IN) :: q_cfg(:) + REAL(wp), INTENT(OUT) :: key(TW_MEMO_KEY) + key(1:12) = q_cfg(6*e - 5:6*e + 6) + key(13:15) = model%tw_tn(:, e) + key(16:18) = model%tw_tn(:, e + 1) + key(19) = model%tw_beta(e) + key(20) = model%l0(e) + key(21) = CD_ZERO + IF (ALLOCATED(model%torsion%couple)) key(21) = model%torsion%couple(e) + END SUBROUTINE tw_memo_inputs + SUBROUTINE tw_advance_reference(model, q_new, ends_new, ErrStat, ErrMsg) !! The twist reference at q_new with the frames ends_new, into the commit scratch: the !! reference twists and end-frame references (the step's own formulas, so the committed diff --git a/src/CableDyn_HermiteTorsion.f90 b/src/CableDyn_HermiteTorsion.f90 index 8929f748..ebfbf82a 100644 --- a/src/CableDyn_HermiteTorsion.f90 +++ b/src/CableDyn_HermiteTorsion.f90 @@ -1641,15 +1641,21 @@ PURE REAL(wp) FUNCTION CD_HermiteTorsion_Element_Stretch(qe, L, quadrature_order CALL element_stretch(qe, L, order, .FALSE., ls, g, h) END FUNCTION CD_HermiteTorsion_Element_Stretch - PURE SUBROUTINE CD_HermiteTorsion_Stretch_Derivatives(qe, L, ls, grad, hess, quadrature_order) + PURE SUBROUTINE CD_HermiteTorsion_Stretch_Derivatives(qe, L, ls, grad, hess, quadrature_order, want_hess) !! CD_HermiteTorsion_Element_Stretch with its gradient and Hessian over the 12 DOFs. + !! want_hess = .FALSE. leaves the Hessian zero (the residual needs the gradient alone); ls and + !! grad are the same either way. REAL(wp), INTENT(IN) :: qe(12), L REAL(wp), INTENT(OUT) :: ls, grad(12), hess(12, 12) INTEGER, INTENT(IN), OPTIONAL :: quadrature_order + LOGICAL, INTENT(IN), OPTIONAL :: want_hess INTEGER :: order + LOGICAL :: hs order = NG_DEFAULT IF (PRESENT(quadrature_order)) order = quadrature_order - CALL element_stretch(qe, L, order, .TRUE., ls, grad, hess) + hs = .TRUE. + IF (PRESENT(want_hess)) hs = want_hess + CALL element_stretch(qe, L, order, hs, ls, grad, hess) END SUBROUTINE CD_HermiteTorsion_Stretch_Derivatives PURE SUBROUTINE element_stretch(qe, L, order, want_hess, ls, grad, hess) diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index 33db20a3..a0cc3daa 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -212,6 +212,9 @@ END FUNCTION cd_cpu_guard_armed ! change, so held loads/channels are recomputed only after a new solve commit. LOGICAL :: loads_cached = .FALSE. INTEGER(IntKi) :: loads_at_n = -1 + ! ws_chan holds the channels of the cached loads' state (a call that skipped them, or + ! loads served without them, leaves it .FALSE.; cleared with loads_cached) + LOGICAL :: chan_cached = .FALSE. REAL(wp), ALLOCATABLE :: ws_chan(:) ! the committed-step row of the .CD.out when it evaluates its own channels (CD_CalcOutput) REAL(wp), ALLOCATABLE :: ws_rowchan(:) @@ -1997,6 +2000,7 @@ SUBROUTINE rebuild_from_checkpoint( t, u1, p, x, other, m, ErrStat, ErrMsg ) Inst(id)%last_n = -1_IntKi Inst(id)%last_solve_n = -1_IntKi Inst(id)%loads_cached = .FALSE. + Inst(id)%chan_cached = .FALSE. Inst(id)%restored_unserved = Inst(id)%nsuper > 1_IntKi ! the load predictor's previous commit (shift_predictor_loads) Inst(id)%pred_t = other%pred_t @@ -2206,6 +2210,7 @@ SUBROUTINE CD_UpdateStates( t, n, u, t_array, p, x, xd, z, other, m, ErrStat, Er ! cache is invalidated on every successful advance (bit-identical for the ! normal path -- last_solve_n moved anyway -- and correct for corrections). Inst(id)%loads_cached = .FALSE. + Inst(id)%chan_cached = .FALSE. ! (a row at every native_every-th glue step: OPTIONS CDOutDt) Inst(id)%native_pending = Inst(id)%native_un > 0_IntKi .AND. & MOD(n + 1_IntKi, Inst(id)%native_every) == 0_IntKi @@ -3724,7 +3729,7 @@ SUBROUTINE check_current_field_grid( inst_e, wf, t_sample ) END SUBROUTINE check_current_field_grid !---------------------------------------------------------------------------------------------------------------------------------- - SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) + SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg, CalcWriteOutput ) REAL(DbKi) , INTENT(IN ) :: t TYPE( CD_InputType ) , INTENT(IN ) :: u TYPE( CD_ParameterType ) , INTENT(IN ) :: p @@ -3736,6 +3741,10 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) TYPE(CD_MiscVarType) , INTENT(INOUT) :: m INTEGER(IntKi) , INTENT(INOUT) :: ErrStat CHARACTER(*) , INTENT(INOUT) :: ErrMsg + !> .FALSE. when the caller will not write y%WriteOutput from this call (the OpenFAST glue passes + !! its WriteThisStep, as for AeroDyn and BeamDyn): the deck channels are then not evaluated and + !! y%WriteOutput keeps its last values. Absent: evaluated on every call. The loads are unaffected. + LOGICAL, OPTIONAL , INTENT(IN ) :: CalcWriteOutput character(*), parameter :: RoutineName = 'CD_CalcOutput' INTEGER(IntKi) :: ErrStat2, es, id, i, n_chan @@ -3746,6 +3755,7 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) LOGICAL :: fresh, state_overlaid ! the channels this call evaluated are those of the committed state as it stands LOGICAL :: chan_committed + LOGICAL :: want_chan ! evaluate the deck channels in this call ! Report this call's OWN status: clear at entry (ErrStat is INTENT(INOUT) and ! every SetErrStat below only ACCUMULATES, so on the all-success path an @@ -3773,6 +3783,8 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) END IF state_overlaid = .FALSE. chan_committed = .FALSE. + want_chan = .TRUE. + IF (PRESENT(CalcWriteOutput)) want_chan = CalcWriteOutput ! Evaluate the loads the mooring exerts on the coupling points. At nsuper = 1 (the ! mooring stepping at the glue rate) the CURRENT coupled kinematics are transferred @@ -3842,7 +3854,9 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) ! Supercycled: the committed state changes only when a mooring step completes, so the ! held loads/channels are re-evaluated only then (serving the cache is bit-identical ! to re-evaluating the unchanged state, at 1/nsuper of the evaluations). - fresh = (.NOT. Inst(id)%loads_cached) .OR. (Inst(id)%loads_at_n /= Inst(id)%last_solve_n) + ! A call that wants the channels re-evaluates when the cached loads were taken without them. + fresh = (.NOT. Inst(id)%loads_cached) .OR. (Inst(id)%loads_at_n /= Inst(id)%last_solve_n) .OR. & + (want_chan .AND. p%NumOuts > 0 .AND. .NOT. Inst(id)%chan_cached) END IF IF (fresh) THEN @@ -3890,7 +3904,7 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) ! one row: the line-wide values several of a cable's channels read (its element twists, ! node torques, ...) are evaluated once for the row (CD_AGG_EvalChannels). IF (Inst(id)%prof_enabled) CALL SYSTEM_CLOCK(prof_phase0) - IF (p%NumOuts > 0) THEN + IF (p%NumOuts > 0 .AND. want_chan) THEN CALL CD_AGG_EvalChannels( Inst(id)%agg, Inst(id)%ws_chan, n_chan, es, em ) IF (es /= CD_AGG_OK) THEN CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: output channel evaluation failed: '// & @@ -3902,14 +3916,16 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) RETURN END IF END IF - ! supercycled, the state evaluated is the committed one itself (no overlay) - chan_committed = .NOT. state_overlaid + ! supercycled, the state evaluated is the committed one itself (no overlay); channels + ! skipped in this call leave ws_chan stale, so a row due now evaluates its own + chan_committed = .NOT. state_overlaid .AND. want_chan IF (Inst(id)%prof_enabled) THEN CALL SYSTEM_CLOCK(prof_c1) Inst(id)%prof_t_channels = Inst(id)%prof_t_channels + & REAL(prof_c1 - prof_phase0, wp)/REAL(prof_rate, wp) END IF Inst(id)%loads_cached = .TRUE. + Inst(id)%chan_cached = want_chan Inst(id)%loads_at_n = Inst(id)%last_solve_n Inst(id)%restored_unserved = .FALSE. END IF @@ -4019,9 +4035,11 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) END IF END IF END IF - DO i = 1, p%NumOuts - y%WriteOutput(i) = REAL(Inst(id)%ws_chan(i), ReKi) - END DO + IF (want_chan) THEN + DO i = 1, p%NumOuts + y%WriteOutput(i) = REAL(Inst(id)%ws_chan(i), ReKi) + END DO + END IF IF (Inst(id)%prof_enabled) THEN CALL SYSTEM_CLOCK(prof_c1) @@ -4266,6 +4284,7 @@ SUBROUTINE serve_committed_loads( inst_e, ErrStat, ErrMsg ) RETURN END IF inst_e%loads_cached = .TRUE. + inst_e%chan_cached = .FALSE. ! loads only (see above) inst_e%loads_at_n = inst_e%last_solve_n inst_e%restored_unserved = .FALSE. END SUBROUTINE serve_committed_loads @@ -4672,6 +4691,7 @@ SUBROUTINE restore() CALL reload_interiors_ary( Inst(id), m, Inst(id)%ws_lsave, t_clock, ErrStat2, ErrMsg2 ) CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) Inst(id)%loads_cached = .FALSE. + Inst(id)%chan_cached = .FALSE. END SUBROUTINE restore END SUBROUTINE lin_eval