From 99d77a5b1ddd59c4d89c18045a66a2edcf5068ed Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Wed, 21 Oct 2026 17:52:20 +0900 Subject: [PATCH] feat(openfast): extrapolate the coupled loads between dtM solves With dtM larger than the glue DT, CableDyn solves once per nsuper glue steps and held its loads between solves, so the platform received them on average dtM/2 late: a first-order lag that acts as negative damping of about the mooring stiffness times dtM/2. This is why 0.2.0 defaults to dtM = DT, at four times the mooring cost of dtM = 0.1 s. Between solves the loads are now extrapolated from the last two committed solves, F = F_c + tau (F_c - F_p) with tau the fraction of the mooring step elapsed, clamped to [0, 1]; the error is second order in dtM. The extrapolation is used only between consecutive commits, so the first step keeps the held loads. CD_UpdateStates shifts the served loads into the previous ones when a mooring step starts (not on a correction re-entry over the same step), keeping CalcOutput state-const, and mirrors them into the OtherState (pred_t, pred_loads), so a restart continues the extrapolation. The output channels and the .CD.out keep the committed samples. The deck OPTION predictLoads (default True) switches it; False keeps the hold. The arithmetic lives in CableDyn_LoadPredictor and is unit-tested. IEA-15 MW VolturnUS-S, turbulent 600 s DLC-1.6, dtM = 0.1 s against dtM = DT = 0.025 s: the platform surge, sway, roll and pitch differ by at most 0.12 % of their standard deviation (0.42 % held), on the chain and on the chain and power-cable mooring; the chain-only run takes a fifth less time (116 s against 141 s). Runs at dtM = DT are byte-identical, and with predictLoads False the outputs equal the held runs byte for byte. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 7 ++ CMakeLists.txt | 8 +++ doc/faq.rst | 3 +- doc/modeling.rst | 5 +- doc/openfast.rst | 38 +++++++--- doc/options.rst | 9 +++ src/CableDyn_DeckDriver.f90 | 9 +++ src/CableDyn_LoadPredictor.f90 | 45 ++++++++++++ src/CableDyn_OpenFAST_Aggregate.f90 | 4 ++ src/openfast/CableDyn_OF.f90 | 105 +++++++++++++++++++++++++--- src/openfast/CableDyn_Registry.txt | 2 + src/openfast/CableDyn_Types.f90 | 27 +++++++ tests/test_load_predictor.f90 | 77 ++++++++++++++++++++ 13 files changed, 315 insertions(+), 24 deletions(-) create mode 100644 src/CableDyn_LoadPredictor.f90 create mode 100644 tests/test_load_predictor.f90 diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a8f1286..83346b62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,13 @@ All notable changes to CableDyn are recorded in this file. The format follows `sqrt(EA/m)`) the time step `dtM` resolves in fewer than six steps gets a note with the period and a `dtM` that resolves it, on the standalone, mixed and OpenFAST routes. Results do not change. +- OpenFAST with `dtM` larger than `DT`: between CableDyn solves the coupled loads are + extrapolated from the last two solves instead of held (deck `OPTIONS predictLoads`, default + `True`; `False` keeps the hold). The error drops from first to second order in `dtM`: on the + IEA-15 MW VolturnUS-S at `dtM = 0.1 s` and `DT = 0.025 s` the platform motions differ from a + `dtM = DT` run by at most 0.12 % of their standard deviation, against 0.42 % held. Runs at + `dtM = DT` (the default) do not change; the previous solve's loads are checkpointed, so a restart + continues the extrapolation. ### Changed diff --git a/CMakeLists.txt b/CMakeLists.txt index e52727c8..d82c7420 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -333,6 +333,7 @@ add_library(cabledyn_obj OBJECT src/CableDyn_Precision.f90 src/CableDyn_FatalReport.f90 src/CableDyn_Profile.f90 + src/CableDyn_LoadPredictor.f90 src/CableDyn_PathIO.f90 src/CableDyn_Banner.f90 src/CableDyn_Linalg.f90 @@ -1103,6 +1104,13 @@ add_test(NAME dtm_advisor COMMAND test_dtm_advisor ${CMAKE_SOURCE_DIR}/examples/iea15mw_umaine_mixed_cabledyn.dat) set_tests_properties(dtm_advisor PROPERTIES LABELS "fortran;unit;openfast") +# The load predictor between supercycled OpenFAST solves: used only between consecutive commits, +# exact at the commit and for loads linear in time, second order otherwise. +add_executable(test_load_predictor tests/test_load_predictor.f90) +target_link_libraries(test_load_predictor PRIVATE cabledyn_core) +add_test(NAME load_predictor COMMAND test_load_predictor) +set_tests_properties(load_predictor PROPERTIES LABELS "fortran;unit;openfast") + # The same deck initialises without a static compression/mesh note: the touchdown # contact kink is element-local, the smoothed element-mean axial force is tensile. add_executable(test_flagship_compression_note tests/test_flagship_compression_note.f90) diff --git a/doc/faq.rst b/doc/faq.rst index 8a5af7e3..a554942d 100644 --- a/doc/faq.rst +++ b/doc/faq.rst @@ -84,7 +84,8 @@ OpenFAST coupling :class: note CableDyn solves on ``dtM`` (the glue ``DT`` unless the deck sets a larger ``dtM``) and, with a - larger ``dtM``, holds its committed loads/channels between solves on the faster glue clock of + larger ``dtM``, holds its committed channels between solves (its coupled loads are + extrapolated from the last two solves) on the faster glue clock of OpenFAST (maintained by NLR, the National Laboratory of the Rockies, formerly NREL). A smaller ``DT_Out`` records more copies of the held value; it does not add physical bandwidth. Plot ``.CD.out`` for the solver-native record containing one row per genuine CableDyn diff --git a/doc/modeling.rst b/doc/modeling.rst index 267b99dd..25eb2eb9 100644 --- a/doc/modeling.rst +++ b/doc/modeling.rst @@ -200,8 +200,9 @@ performance comparisons keep the default. Choose ``dtM`` by convergence of peaks, phase, rainflow ranges, and accumulated damage—not only by solver success. Numerical stability at a large implicit step is not evidence of fatigue accuracy. In OpenFAST the default is ``dtM = DT`` (a solve every glue step); with a larger deck ``dtM``, -loads and assembled OpenFAST channels are zero-order-held between CableDyn solves, which delays -the loads by about ``dtM/2`` (see :doc:`openfast`). The separate ``.CD.out`` contains only genuine committed +the coupled loads are extrapolated from the last two CableDyn solves (or held, with +``predictLoads False``, which delays them by about ``dtM/2``) and the assembled OpenFAST channels +are held between solves (see :doc:`openfast`). The separate ``.CD.out`` contains only genuine committed ``dtM`` samples, while ``DT_Out`` changes the assembled OpenFAST recording cadence only. Neither file convention substitutes for a time-step convergence study, which should cover the forcing bandwidth, the shortest element transit time, contact switching, and constitutive relaxation diff --git a/doc/openfast.rst b/doc/openfast.rst index 69e0ee92..1ebeed5d 100644 --- a/doc/openfast.rst +++ b/doc/openfast.rst @@ -77,8 +77,10 @@ Time step ``DT`` is the OpenFAST glue step; ``dtM`` is CableDyn's committed step. With no deck ``dtM``, CableDyn solves every glue step (``dtM = DT``). A deck ``dtM`` that is a whole multiple of ``DT`` -solves once per that many glue steps and holds its loads (zero-order hold) between commits, which -is faster but delays the loads (see the note below). The console reports the result, for +solves once per that many glue steps, which is faster. Between commits the coupled loads are +extrapolated from the last two commits (deck ``OPTIONS predictLoads``, the default) or, with +``predictLoads False``, held at the last commit, which delays them (see the note below). The +console reports the result, for example ``CableDyn time step dtM = 2.50000E-02 s (1 x glue DT; deck dtM)``. A deck ``dtM`` larger than ``DT`` but not a whole multiple of it is never coarsened: CableDyn uses the largest multiple of ``DT`` that does not exceed it and reports a warning with both values (``dtM = 0.025`` @@ -92,15 +94,29 @@ peaks, and damage. If CableDyn needs a smaller step than the glue step, reduce ` .. note:: - With ``dtM`` larger than ``DT``, CableDyn holds its loads between commits, so the platform - receives the mooring load on average half a ``dtM`` late. A spring force delayed this way - acts on the platform as a negative damping of about the mooring stiffness times ``dtM/2``. For a catenary mooring this - is small: in the three-seed DLC-1.1 comparison of :doc:`validation` the platform motions with - ``dtM`` above ``DT`` agree with MoorDyn within 0.6 % in mean and standard deviation, but the - fairlead tension's standard deviation differs by about 3 % from CableDyn's own solution at - every glue step. For stiff taut, semi-taut or tension-leg moorings the lag can be comparable - to the system's own damping. Check such systems, and any fatigue or tension-range result, at - a smaller ``dtM`` (down to ``dtM = DT``) before relying on them. + With ``dtM`` larger than ``DT``, the loads CableDyn returns at a glue step a fraction + :math:`\tau = (t - t_c)/\mathrm{dtM}` past its last commit :math:`t_c` are extrapolated from + that commit and the one before, :math:`F = F_c + \tau\,(F_c - F_p)`. Their error is of + second order in ``dtM`` (:math:`\tau(1+\tau)\,\mathrm{dtM}^2 \ddot F/2`). Held instead + (``predictLoads False``), the platform receives the mooring load on average half a ``dtM`` + late, and a spring force delayed this way acts on the platform as a negative damping of about + the mooring stiffness times ``dtM/2``. + + On the IEA-15 MW VolturnUS-S in a turbulent 600 s DLC-1.6 environment at ``dtM = 0.1 s`` + (four glue steps of 0.025 s), the platform surge, sway, roll and pitch time series differ from + the ``dtM = DT`` run by at most 0.12 % of their standard deviation with the extrapolation, on + the chain mooring as on the chain and power-cable mooring, where the held loads give up to + 0.42 %. The chain-only run took a fifth less time (116 s against 141 s for ``dtM = DT`` + on the same machine). In the three-seed DLC-1.1 comparison + of :doc:`validation`, made with held loads, the platform motions with ``dtM`` above ``DT`` + agree with MoorDyn within 0.6 % in mean and standard deviation, but the fairlead tension's + standard deviation differs by about 3 % from CableDyn's own solution at every glue step. + + The extrapolation does not change how the lines themselves are integrated: each line still + steps on ``dtM``, so its own resolution (see the ``dtM`` advisory in :doc:`modeling`) decides + its tension accuracy, and the output channels and the ``.CD.out`` record the committed + samples. For stiff taut, semi-taut or tension-leg moorings, and for any fatigue or + tension-range result, check a smaller ``dtM`` (down to ``dtM = DT``) before relying on it. Fluid source ~~~~~~~~~~~~ diff --git a/doc/options.rst b/doc/options.rst index cfa29341..fd1f4a39 100644 --- a/doc/options.rst +++ b/doc/options.rst @@ -527,6 +527,15 @@ Finite-EI cable controls controlled one-way comparison, not a physical operating configuration - OpenFAST (coupled finite-EI cables) - ``True cable_load_feedback`` + * - ``predictLoads`` / ``predict_loads`` + - logical + - ``True`` + - with ``dtM`` larger than the glue ``DT``: ``True`` extrapolates the coupled loads between + CableDyn solves from the last two, ``False`` holds the last solve's loads (about ``dtM/2`` + late). No effect at ``dtM = DT``; the output channels hold the committed samples either way + (see :doc:`openfast`) + - OpenFAST + - ``False predictLoads`` Ambient fluid and prescribed motion ----------------------------------- diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index d4efa545..ce6604eb 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -634,6 +634,9 @@ MODULE CableDyn_DeckDriver ! channels remain available; FALSE suppresses only its reaction at the host ! moving-point boundary. The default preserves ordinary two-way coupling. LOGICAL :: cable_load_feedback = .TRUE. + ! OpenFAST supercycling (dtM > DT): extrapolate the coupled loads between dtM solves from the + ! last two (CableDyn_LoadPredictor); FALSE holds the last solve's loads + LOGICAL :: predict_loads = .TRUE. ! Opt-in adaptive mesh for COUPLED finite-EI cables: when set, a cable whose static IC is ! diagnosed under-resolved (CD_HermiteCable_Resolution_Metrics fragile) is refined by ! warm-started cubic-Hermite prolongation before the coupled dynamic run. Default FALSE keeps @@ -1018,6 +1021,8 @@ MODULE CableDyn_DeckDriver LOGICAL :: host_wave_enabled = .FALSE. LOGICAL :: host_current_enabled = .FALSE. LOGICAL :: cable_load_feedback = .TRUE. + ! Deck OPTION predictLoads (the OpenFAST shell; see CD_AGG_ModuleType%predict_loads) + LOGICAL :: predict_loads = .TRUE. ! OPTION maxStrain, for the per-step plausibility guard of the coupled EI=0 lines. REAL(wp) :: max_strain = 0.5_wp REAL(wp), ALLOCATABLE :: host_current_profile_z(:) @@ -6540,6 +6545,7 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi END IF agg%n_turbines = nturb agg%cable_load_feedback = opts%cable_load_feedback + agg%predict_loads = opts%predict_loads agg%max_strain = opts%max_strain ! The standalone driver retains DeckOptions and evaluates a WaveKinMod-1 Fourier @@ -7636,6 +7642,7 @@ SUBROUTINE CD_End_Deck_Aggregate(agg) agg%host_wave_enabled = .FALSE. agg%host_current_enabled = .FALSE. agg%cable_load_feedback = .TRUE. + agg%predict_loads = .TRUE. agg%max_strain = 0.5_wp IF (ALLOCATED(agg%host_current_profile_z)) DEALLOCATE (agg%host_current_profile_z) IF (ALLOCATED(agg%host_current_profile_velocity)) DEALLOCATE (agg%host_current_profile_velocity) @@ -14244,6 +14251,8 @@ SUBROUTINE apply_option(line, opts, ErrStat, ErrMsg) END SELECT CASE ('cable_load_feedback', 'cableloadfeedback') CALL rd_bool(val, opts%cable_load_feedback, ErrStat, ErrMsg) + CASE ('predict_loads', 'predictloads') + CALL rd_bool(val, opts%predict_loads, ErrStat, ErrMsg) CASE ('tensile_safety', 'tensilesafety') CALL rd_tensile_mode(val, opts%tensile_mode, ErrStat, ErrMsg) CASE ('tensile_strain_tolerance', 'tensilestraintolerance') diff --git a/src/CableDyn_LoadPredictor.f90 b/src/CableDyn_LoadPredictor.f90 new file mode 100644 index 00000000..2638fed4 --- /dev/null +++ b/src/CableDyn_LoadPredictor.f90 @@ -0,0 +1,45 @@ +! File: src/CableDyn_LoadPredictor.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +MODULE CableDyn_LoadPredictor + !! Coupled loads between supercycled mooring solves. When the mooring steps on dtM, a whole + !! number of host steps, the host still asks for the loads at every one of its steps. Held at + !! the last committed solve they lag the platform by up to dtM; extrapolated linearly from + !! the last two committed solves, + !! + !! F(t) = F_c + tau (F_c - F_p), tau = (t - t_c)/dtM in [0, 1], + !! + !! they follow it to second order: the error is of order dtM^2 F'' instead of dtM F'. The + !! extrapolation is used only when the two solves are exactly one dtM apart (consecutive + !! commits), so the first interval of a run, or after a gap, keeps the held loads. + USE CableDyn_Precision, ONLY: wp + IMPLICIT NONE + PRIVATE + PUBLIC :: CD_Predictor_Ready, CD_Predictor_Fraction, CD_Predict_Loads + +CONTAINS + + PURE LOGICAL FUNCTION CD_Predictor_Ready(t_commit, t_prev, dt) RESULT(ready) + !! The previous committed solve (time t_prev; negative when there is none) is the one + !! immediately before the last (time t_commit): exactly dt earlier, within 1e-6 dt. + REAL(wp), INTENT(IN) :: t_commit, t_prev, dt + ready = .FALSE. + IF (.NOT. (dt > 0.0_wp .AND. t_prev >= 0.0_wp)) RETURN + ready = ABS((t_commit - t_prev) - dt) <= 1.0e-6_wp*dt + END FUNCTION CD_Predictor_Ready + + PURE REAL(wp) FUNCTION CD_Predictor_Fraction(t, t_commit, dt) RESULT(tau) + !! The fraction of the mooring step elapsed since the last committed solve, clamped to + !! [0, 1] (no extrapolation beyond one step, none backwards). + REAL(wp), INTENT(IN) :: t, t_commit, dt + tau = MAX(0.0_wp, MIN(1.0_wp, (t - t_commit)/dt)) + END FUNCTION CD_Predictor_Fraction + + PURE SUBROUTINE CD_Predict_Loads(f_last, f_prev, tau, f) + !! F = F_c + tau (F_c - F_p), element by element. + REAL(wp), INTENT(IN) :: f_last(:, :), f_prev(:, :), tau + REAL(wp), INTENT(OUT) :: f(:, :) + f = f_last + tau*(f_last - f_prev) + END SUBROUTINE CD_Predict_Loads + +END MODULE CableDyn_LoadPredictor diff --git a/src/CableDyn_OpenFAST_Aggregate.f90 b/src/CableDyn_OpenFAST_Aggregate.f90 index 7b4e7dc2..c0d6f785 100644 --- a/src/CableDyn_OpenFAST_Aggregate.f90 +++ b/src/CableDyn_OpenFAST_Aggregate.f90 @@ -141,6 +141,9 @@ MODULE CableDyn_OpenFAST_Aggregate ! cable march, environmental loading, and output channels active but zeros ! its moving-point load and moment for a controlled one-way comparison. LOGICAL :: cable_load_feedback = .TRUE. + ! Deck OPTION predictLoads: the OpenFAST shell extrapolates the coupled loads between + ! supercycled solves (TRUE) or holds the last solve's (FALSE) + LOGICAL :: predict_loads = .TRUE. ! Deck OPTION maxStrain: the per-step plausibility bound on the EI=0 system lines. REAL(wp) :: max_strain = 0.5_wp INTEGER :: ncp_sys = 0 ! moving points owned by sys @@ -330,6 +333,7 @@ SUBROUTINE CD_AGG_Init_From_Deck(self, deck_path, dt, ErrStat, ErrMsg, env_gravi candidate%host_wave_enabled = parts%host_wave_enabled candidate%host_current_enabled = parts%host_current_enabled candidate%cable_load_feedback = parts%cable_load_feedback + candidate%predict_loads = parts%predict_loads candidate%max_strain = parts%max_strain IF (ALLOCATED(parts%host_current_profile_z)) THEN candidate%host_current_profile_z = parts%host_current_profile_z diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index 241a6914..0a29426c 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -98,6 +98,7 @@ MODULE CableDyn CD_HermiteCable_Dyn_Get_Assembly_Profile, HC_ASM_NSEC, HC_ASM_KEYS, & CD_HermiteCable_Dyn_Recovery_Count, & CD_HermiteCable_Dyn_Recovery_Reset + USE CableDyn_LoadPredictor, ONLY: CD_Predictor_Ready, CD_Predictor_Fraction, CD_Predict_Loads USE CableDyn_Profile, ONLY: CD_Profile_Arm, CD_Profile_Disarm, CD_Profile_Kernels, CD_PROF_K_RESIDUAL, & CD_PROF_K_TANGENT, CD_PROF_K_FACTOR, CD_PROF_K_SOLVE, CD_PROF_NKERNEL USE CableDyn_System, ONLY: CD_System_NLines, CD_System_Line_NDOF, CD_System_Line_NElem, & @@ -136,9 +137,10 @@ MODULE CableDyn ! dt_moor = nsuper * (glue DT), ONE step per nsuper glue steps, instead of being ! chained to the turbine's small DT. The deck's OPTIONS dtM sets it (clamped to at ! least the glue DT); absent a deck dtM the mooring solves every glue step. Between - ! mooring solves CD_CalcOutput returns the last - ! committed load state as a zero-order hold; feeding instantaneous endpoints into a - ! lagged mooring interior creates artificial stiff-EA load chatter. + ! mooring solves CD_CalcOutput returns the last committed load state, extrapolated from + ! the solve before it (deck OPTION predictLoads, the default) or held; feeding + ! instantaneous endpoints into a lagged mooring interior creates artificial stiff-EA + ! load chatter. INTEGER(IntKi) :: nsuper = 1 ! glue steps per mooring step REAL(wp) :: dt_moor = 0.0_wp ! the mooring step frozen into the aggregate LOGICAL :: active = .FALSE. @@ -157,6 +159,12 @@ MODULE CableDyn LOGICAL :: loads_cached = .FALSE. INTEGER(IntKi) :: loads_at_n = -1 REAL(wp), ALLOCATABLE :: ws_chan(:) + ! Load predictor (nsuper > 1 with predictLoads; CableDyn_LoadPredictor): the coupled + ! loads and moments of the committed solve before the last and its time (pred_t < 0: + ! none), shifted in by CD_UpdateStates when a mooring step starts and mirrored into the + ! OtherState for restarts; ws_pfld/ws_pmom hold the extrapolated loads CalcOutput serves. + REAL(wp), ALLOCATABLE :: pred_fld(:,:), pred_mom(:,:), ws_pfld(:,:), ws_pmom(:,:) + REAL(DbKi) :: pred_t = -1.0_DbKi ! Persistent interpolated-input container: CD_UpdateStates interpolates the coupled ! kinematics to the mooring interval end; the mesh copy is built ONCE and reused ! (ExtrapInterp overwrites the fields in place), never created/destroyed per step. @@ -640,13 +648,6 @@ SUBROUTINE CD_Init(InitInp, u, p, x, xd, z, other, y, m, DTcoupling, InitOut, Er dt_moor = REAL(nsuper, wp)*dtC CALL WrScr( ' CableDyn time step dtM = '//TRIM(Num2LStr(dt_moor))//' s ('//TRIM(Num2LStr(nsuper))// & ' x glue DT'//TRIM(MERGE('; deck dtM ', '; the default', has_dtm))//')' ) - IF (nsuper > 1_IntKi) THEN - CALL WrScr( ' CableDyn: coupled loads are held between dtM solves and reach the platform about dtM/2 '// & - 'late, which matters for stiff (taut or tension-leg) moorings and for tension statistics; '// & - 'the separate .CD.out records committed CableDyn samples only. Verify dtM convergence for '// & - 'fatigue, snap, contact, or local cable-response calculations; omit dtM or set it to DT for '// & - 'glue-rate solves.' ) - END IF ! The run must END on a mooring boundary: with supercycling, a trailing partial ! interval would take only skipped glue steps, leaving the committed mooring state -- ! and the held (zero-order-hold) loads -- up to dtM stale at TMax, silently. Fail @@ -793,6 +794,20 @@ SUBROUTINE CD_Init(InitInp, u, p, x, xd, z, other, y, m, DTcoupling, InitOut, Er Inst(id)%nsuper = nsuper Inst(id)%dt_moor = dt_moor Inst(id)%use_extfluid = use_extf + IF (nsuper > 1_IntKi) THEN + IF (Inst(id)%agg%predict_loads) THEN + CALL WrScr( ' CableDyn: between dtM solves the coupled loads are extrapolated from the last two '// & + 'solves (OPTIONS predictLoads); the output channels and the .CD.out record the committed '// & + 'samples. Verify dtM convergence for fatigue, snap, contact, or local cable-response '// & + 'calculations; omit dtM or set it to DT for glue-rate solves.' ) + ELSE + CALL WrScr( ' CableDyn: coupled loads are held between dtM solves (OPTIONS predictLoads False) and '// & + 'reach the platform about dtM/2 late, which matters for stiff (taut or tension-leg) '// & + 'moorings and for tension statistics; the separate .CD.out records committed CableDyn '// & + 'samples only. Verify dtM convergence for fatigue, snap, contact, or local cable-response '// & + 'calculations; omit dtM or set it to DT for glue-rate solves.' ) + END IF + END IF ! CableDyn-owned result files. Single-turbine names use p%RootName = ! .CD; FAST.Farm preserves its established FarmCD root. IF (nT > 0) THEN @@ -1118,6 +1133,7 @@ SUBROUTINE CD_Init(InitInp, u, p, x, xd, z, other, y, m, DTcoupling, InitOut, Er Inst(id)%t_commit = 0.0_DbKi ! committed at the static IC (t = 0) other%restart_serial = g_serial other%t_commit = Inst(id)%t_commit + other%pred_t = -1.0_DbKi ! no previous commit yet (load predictor) ! ------------------------------------------------------------------------------ ! Output channels: the deck OUTPUTS list in the OrcaFlex vocabulary, emitted through @@ -1529,6 +1545,20 @@ 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. + ! the load predictor's previous commit (shift_predictor_loads) + Inst(id)%pred_t = other%pred_t + IF (Inst(id)%pred_t >= 0.0_DbKi) THEN + IF (ALLOCATED(other%pred_loads)) THEN + IF (SIZE(other%pred_loads) == 6*ncp) THEN + Inst(id)%pred_fld = RESHAPE(REAL(other%pred_loads(1:3*ncp), wp), [3, ncp]) + Inst(id)%pred_mom = RESHAPE(REAL(other%pred_loads(3*ncp + 1:6*ncp), wp), [3, ncp]) + ELSE + Inst(id)%pred_t = -1.0_DbKi + END IF + ELSE + Inst(id)%pred_t = -1.0_DbKi + END IF + END IF m%CDInst = id CALL WrScr( ' CableDyn: rebuilt the solver instance from the checkpoint at t = '// & TRIM(Num2LStr(t))//' s ('//TRIM(Num2LStr(ncp))//' coupled points, '// & @@ -1645,6 +1675,10 @@ SUBROUTINE CD_UpdateStates( t, n, u, t_array, p, x, xd, z, other, m, ErrStat, Er END IF CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) IF (ErrStat < AbortErrLev) THEN + ! Load predictor: a new mooring step (not a correction re-entry over the same n) + ! makes the loads served since the last commit the previous ones. + IF (Inst(id)%nsuper > 1_IntKi .AND. Inst(id)%agg%predict_loads .AND. & + Inst(id)%last_solve_n /= n) CALL shift_predictor_loads( Inst(id), other ) ! Snapshot the step-start state before advancing: a later correction re-entry ! over this same n restores it and re-advances. Idempotent (buffers reused), ! and on the corrected re-advance it re-captures the SAME restored state. @@ -2170,6 +2204,7 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) CHARACTER(ErrMsgLen) :: ErrMsg2 CHARACTER(ErrMsgLen) :: em REAL(wp) :: cval + REAL(wp) :: tau_pred ! load predictor: fraction of the mooring step elapsed LOGICAL :: fresh, state_overlaid ! Report this call's OWN status: clear at entry (ErrStat is INTENT(INOUT) and @@ -2403,6 +2438,31 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) y%CoupledLoads(1)%Moment(:, i) = REAL(Inst(id)%ws_moment(:, i), ReKi) END DO END IF + ! Load predictor (supercycled, predictLoads): the committed loads extrapolated from the + ! solve before, at the fraction of the mooring step elapsed (CableDyn_LoadPredictor). The + ! output channels keep the committed samples. + IF (Inst(id)%nsuper > 1_IntKi .AND. Inst(id)%agg%predict_loads) THEN + IF (CD_Predictor_Ready(REAL(Inst(id)%t_commit, wp), REAL(Inst(id)%pred_t, wp), Inst(id)%dt_moor)) THEN + IF (.NOT. ALLOCATED(Inst(id)%ws_pfld)) & + ALLOCATE (Inst(id)%ws_pfld(3, Inst(id)%ncp), Inst(id)%ws_pmom(3, Inst(id)%ncp)) + tau_pred = CD_Predictor_Fraction(REAL(t, wp), REAL(Inst(id)%t_commit, wp), Inst(id)%dt_moor) + CALL CD_Predict_Loads(Inst(id)%ws_fld, Inst(id)%pred_fld, tau_pred, Inst(id)%ws_pfld) + CALL CD_Predict_Loads(Inst(id)%ws_moment, Inst(id)%pred_mom, tau_pred, Inst(id)%ws_pmom) + IF (Inst(id)%nT > 0) THEN + DO i = 1, Inst(id)%ncp + y%CoupledLoads(Inst(id)%tmap(i))%Force(:, Inst(id)%node_of_slot(i)) = & + REAL(Inst(id)%ws_pfld(:, i), ReKi) + y%CoupledLoads(Inst(id)%tmap(i))%Moment(:, Inst(id)%node_of_slot(i)) = & + REAL(Inst(id)%ws_pmom(:, i), ReKi) + END DO + ELSE + DO i = 1, Inst(id)%ncp + y%CoupledLoads(1)%Force(:, i) = REAL(Inst(id)%ws_pfld(:, i), ReKi) + y%CoupledLoads(1)%Moment(:, i) = REAL(Inst(id)%ws_pmom(:, i), ReKi) + END DO + END IF + END IF + END IF DO i = 1, p%NumOuts y%WriteOutput(i) = REAL(Inst(id)%ws_chan(i), ReKi) END DO @@ -2416,6 +2476,31 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) END SUBROUTINE CD_CalcOutput !---------------------------------------------------------------------------------------------------------------------------------- + SUBROUTINE shift_predictor_loads( inst_e, other ) + !! The load predictor's previous commit when a new mooring step starts: the loads served + !! since the last commit, when CalcOutput evaluated them there (its committed loads), and + !! that commit's time; none otherwise. Mirrored into the OtherState, so a restart + !! continues the extrapolation from the same two commits. + TYPE(CD_OF_Instance), INTENT(INOUT) :: inst_e + TYPE(CD_OtherStateType), INTENT(INOUT) :: other + INTEGER(IntKi) :: nl + IF (inst_e%loads_cached .AND. inst_e%loads_at_n == inst_e%last_solve_n) THEN + inst_e%pred_fld = inst_e%ws_fld + inst_e%pred_mom = inst_e%ws_moment + inst_e%pred_t = inst_e%t_commit + nl = 3_IntKi*inst_e%ncp + IF (ALLOCATED(other%pred_loads)) THEN + IF (SIZE(other%pred_loads) /= 2*nl) DEALLOCATE (other%pred_loads) + END IF + IF (.NOT. ALLOCATED(other%pred_loads)) ALLOCATE (other%pred_loads(2*nl)) + other%pred_loads(1:nl) = RESHAPE(REAL(inst_e%ws_fld, DbKi), [nl]) + other%pred_loads(nl + 1:2*nl) = RESHAPE(REAL(inst_e%ws_moment, DbKi), [nl]) + ELSE + inst_e%pred_t = -1.0_DbKi + END IF + other%pred_t = inst_e%pred_t + END SUBROUTINE shift_predictor_loads + SUBROUTINE restore_calcoutput_probe( inst_e, m, ErrStat, ErrMsg ) !! Restore every state surface after the output-probe !! overlay. This is used on both success and every post-overlay error exit. diff --git a/src/openfast/CableDyn_Registry.txt b/src/openfast/CableDyn_Registry.txt index 45180fc9..78e960e0 100644 --- a/src/openfast/CableDyn_Registry.txt +++ b/src/openfast/CableDyn_Registry.txt @@ -359,6 +359,8 @@ typedef ^ ConstraintStateType SiKi dummy - ## ============================== Define Other states here: ===================================================================================================================================== typedef ^ OtherStateType IntKi restart_serial - -1 - "instance-generation stamp minted at Init/rebuild; a restored OtherState whose stamp does not match the live instance's (a fresh process) triggers the checkpoint rebuild from p + the x state mirror" - typedef ^ ^ DbKi t_commit - -1 - "time of the last committed mooring advance; a live instance whose committed clock is AHEAD of a restored OtherState's (a same-process checkpoint rewind) also triggers the rebuild" - +typedef ^ ^ DbKi pred_t - -1 - "load predictor: time of the committed solve before the last (negative: none), from which the coupled loads between supercycled solves are extrapolated" - +typedef ^ ^ DbKi pred_loads {:} - - "load predictor: the coupled forces (3 x ncp) and then moments (3 x ncp) of that solve" - ## ============================== Parameters ============================================================================================================================================ typedef ^ ParameterType IntKi nLineTypes - 0 - "number of line types" "" diff --git a/src/openfast/CableDyn_Types.f90 b/src/openfast/CableDyn_Types.f90 index 25ec971d..c88607f7 100644 --- a/src/openfast/CableDyn_Types.f90 +++ b/src/openfast/CableDyn_Types.f90 @@ -393,6 +393,8 @@ MODULE CableDyn_Types TYPE, PUBLIC :: CD_OtherStateType INTEGER(IntKi) :: restart_serial = -1 !< instance-generation stamp minted at Init/rebuild; a restored OtherState whose stamp does not match the live instance's (a fresh process) triggers the checkpoint rebuild from p + the x state mirror [-] REAL(DbKi) :: t_commit = -1 !< time of the last committed mooring advance; a live instance whose committed clock is AHEAD of a restored OtherState's (a same-process checkpoint rewind) also triggers the rebuild [-] + REAL(DbKi) :: pred_t = -1 !< load predictor: time of the committed solve before the last (negative: none), from which the coupled loads between supercycled solves are extrapolated [-] + REAL(DbKi) , DIMENSION(:), ALLOCATABLE :: pred_loads !< load predictor: the coupled forces (3 x ncp) and then moments (3 x ncp) of that solve [-] END TYPE CD_OtherStateType ! ======================= ! ========= CD_ParameterType ======= @@ -2969,11 +2971,26 @@ subroutine CD_CopyOtherState(SrcOtherStateData, DstOtherStateData, CtrlCode, Err integer(IntKi), intent(in ) :: CtrlCode integer(IntKi), intent( out) :: ErrStat character(*), intent( out) :: ErrMsg + integer(B4Ki) :: LB(1), UB(1) + integer(IntKi) :: ErrStat2 character(*), parameter :: RoutineName = 'CD_CopyOtherState' ErrStat = ErrID_None ErrMsg = '' DstOtherStateData%restart_serial = SrcOtherStateData%restart_serial DstOtherStateData%t_commit = SrcOtherStateData%t_commit + DstOtherStateData%pred_t = SrcOtherStateData%pred_t + if (allocated(SrcOtherStateData%pred_loads)) then + LB(1:1) = lbound(SrcOtherStateData%pred_loads) + UB(1:1) = ubound(SrcOtherStateData%pred_loads) + if (.not. allocated(DstOtherStateData%pred_loads)) then + allocate(DstOtherStateData%pred_loads(LB(1):UB(1)), stat=ErrStat2) + if (ErrStat2 /= 0) then + call SetErrStat(ErrID_Fatal, 'Error allocating DstOtherStateData%pred_loads.', ErrStat, ErrMsg, RoutineName) + return + end if + end if + DstOtherStateData%pred_loads = SrcOtherStateData%pred_loads + end if end subroutine subroutine CD_DestroyOtherState(OtherStateData, ErrStat, ErrMsg) @@ -2983,6 +3000,9 @@ subroutine CD_DestroyOtherState(OtherStateData, ErrStat, ErrMsg) character(*), parameter :: RoutineName = 'CD_DestroyOtherState' ErrStat = ErrID_None ErrMsg = '' + if (allocated(OtherStateData%pred_loads)) then + deallocate(OtherStateData%pred_loads) + end if end subroutine subroutine CD_PackOtherState(RF, Indata) @@ -2992,6 +3012,8 @@ subroutine CD_PackOtherState(RF, Indata) if (RF%ErrStat >= AbortErrLev) return call RegPack(RF, InData%restart_serial) call RegPack(RF, InData%t_commit) + call RegPack(RF, InData%pred_t) + call RegPackAlloc(RF, InData%pred_loads) if (RegCheckErr(RF, RoutineName)) return end subroutine @@ -2999,9 +3021,14 @@ subroutine CD_UnPackOtherState(RF, OutData) type(RegFile), intent(inout) :: RF type(CD_OtherStateType), intent(inout) :: OutData character(*), parameter :: RoutineName = 'CD_UnPackOtherState' + integer(B4Ki) :: LB(1), UB(1) + integer(IntKi) :: stat + logical :: IsAllocAssoc if (RF%ErrStat /= ErrID_None) return call RegUnpack(RF, OutData%restart_serial); if (RegCheckErr(RF, RoutineName)) return call RegUnpack(RF, OutData%t_commit); if (RegCheckErr(RF, RoutineName)) return + call RegUnpack(RF, OutData%pred_t); if (RegCheckErr(RF, RoutineName)) return + call RegUnpackAlloc(RF, OutData%pred_loads); if (RegCheckErr(RF, RoutineName)) return end subroutine subroutine CD_CopyParam(SrcParamData, DstParamData, CtrlCode, ErrStat, ErrMsg) diff --git a/tests/test_load_predictor.f90 b/tests/test_load_predictor.f90 new file mode 100644 index 00000000..906bfebf --- /dev/null +++ b/tests/test_load_predictor.f90 @@ -0,0 +1,77 @@ +! File: tests/test_load_predictor.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +PROGRAM test_load_predictor + !! The load predictor between supercycled solves (CableDyn_LoadPredictor): + !! * it is used only between consecutive commits (exactly one dtM apart, within 1e-6 dtM), + !! never without a previous commit or with a non-positive dtM; + !! * the elapsed fraction is clamped to [0, 1]; + !! * at the commit (tau = 0) the served loads are the committed ones bit for bit; + !! * a load linear in time is reproduced, and a quadratic one t^2 is in error by exactly + !! tau (1 + tau) dtM^2 (second order; the hold is first order). + USE CableDyn_Precision, ONLY: wp + USE CableDyn_LoadPredictor, ONLY: CD_Predictor_Ready, CD_Predictor_Fraction, CD_Predict_Loads + IMPLICIT NONE + + REAL(wp), PARAMETER :: DT = 0.1_wp, TC = 37.3_wp + REAL(wp) :: f_last(3, 2), f_prev(3, 2), f(3, 2), tau, t, expect + INTEGER :: nfail, k + + nfail = 0 + + CALL require(CD_Predictor_Ready(TC, TC - DT, DT), 'consecutive commits are ready') + CALL require(CD_Predictor_Ready(TC, TC - DT*(1.0_wp + 0.5e-6_wp), DT), 'within 1e-6 dtM is ready') + CALL require(.NOT. CD_Predictor_Ready(TC, TC - DT*(1.0_wp + 2.0e-6_wp), DT), 'beyond 1e-6 dtM is not ready') + CALL require(.NOT. CD_Predictor_Ready(TC, TC - 2.0_wp*DT, DT), 'a skipped commit is not ready') + CALL require(.NOT. CD_Predictor_Ready(TC, -1.0_wp, DT), 'no previous commit is not ready') + CALL require(CD_Predictor_Ready(DT, 0.0_wp, DT), 'the static state at t = 0 is a previous commit') + CALL require(.NOT. CD_Predictor_Ready(TC, TC - DT, 0.0_wp), 'a zero dtM is not ready') + + CALL require(CD_Predictor_Fraction(TC - 0.01_wp, TC, DT) == 0.0_wp, 'the fraction is not negative') + CALL require(CD_Predictor_Fraction(TC + 2.0_wp*DT, TC, DT) == 1.0_wp, 'the fraction is at most one') + CALL require(ABS(CD_Predictor_Fraction(TC + 0.075_wp, TC, DT) - 0.75_wp) <= 1.0e-12_wp, 'three quarters') + + ! a load linear in time, a + b t, sampled at the two commits + DO k = 1, 2 + f_prev(:, k) = [1.0e6_wp, -2.5e5_wp, 3.0e4_wp]*REAL(k, wp) + [4.0e5_wp, 1.0e3_wp, -7.0e4_wp]*(TC - DT) + f_last(:, k) = [1.0e6_wp, -2.5e5_wp, 3.0e4_wp]*REAL(k, wp) + [4.0e5_wp, 1.0e3_wp, -7.0e4_wp]*TC + END DO + CALL CD_Predict_Loads(f_last, f_prev, 0.0_wp, f) + CALL require(ALL(f == f_last), 'at the commit the committed loads are served bit for bit') + DO k = 1, 3 + tau = 0.25_wp*REAL(k, wp) + t = TC + tau*DT + CALL CD_Predict_Loads(f_last, f_prev, tau, f) + CALL require(ALL(ABS(f(:, 2) - ([2.0e6_wp, -5.0e5_wp, 6.0e4_wp] + [4.0e5_wp, 1.0e3_wp, -7.0e4_wp]*t)) <= & + 1.0e-9_wp*MAXVAL(ABS(f_last))), 'a linear load is reproduced') + END DO + + ! a quadratic load t^2: error tau (1 + tau) dtM^2 + f_prev = (TC - DT)**2 + f_last = TC**2 + DO k = 1, 3 + tau = 0.25_wp*REAL(k, wp) + t = TC + tau*DT + CALL CD_Predict_Loads(f_last, f_prev, tau, f) + expect = tau*(1.0_wp + tau)*DT**2 + CALL require(ABS((t**2 - f(1, 1)) - expect) <= 1.0e-9_wp*expect, 'the quadratic error is tau (1 + tau) dtM^2') + END DO + + IF (nfail > 0) THEN + WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' + ERROR STOP 1 + END IF + WRITE (*, '(A)') 'PASS: load predictor (readiness, fraction, extrapolation order)' + +CONTAINS + + SUBROUTINE require(cond, msg) + LOGICAL, INTENT(IN) :: cond + CHARACTER(*), INTENT(IN) :: msg + IF (.NOT. cond) THEN + WRITE (*, '(A)') 'FAIL: '//TRIM(msg) + nfail = nfail + 1 + END IF + END SUBROUTINE require + +END PROGRAM test_load_predictor