From cbbd61a7874ccc8cd37941e5ce993f9f848d2d40 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Wed, 2 Dec 2026 22:55:22 +0900 Subject: [PATCH 1/3] fix(openfast): sample the SeaState grid where the nodes are at the sample time CD_UpdateStates samples the wave field at the end of the mooring interval (t + DT), but the positions it reads are those of the last commit, the interval's start, so the grid route took every node's kinematics one CableDyn step behind it: a phase error of k v dtM. The node-wise route already advanced its nodes from the time the positions belong to (f852696). The grid route now does the same. advance_sample_positions keeps each node's positions at the last two distinct commit times and samples SeaState at the committed position advanced to the sample time by that velocity (CD_WaveGrid_Advance); a retry or rewind restarts the history, and the first sample, without one, takes the positions as read. The history travels in the checkpoint with the held fields, so a restarted run continues bit for bit. The wave-grid guard still checks the committed positions, and the provenance record is unchanged. Grid-route results change at the level of the lag, by design: - r-test chain mooring of the OpenFAST tutorial (Hs 6 m, Tp 12 s, 60 s, dtM 0.025 s): fairlead-tension std within 0.001 %, largest tension difference 196 N (0.001 to 0.002 std); - the wave-grid guard cases (1 s; 60 s mid-run case): std within 0.01 %, largest fairlead-tension difference 184 N on a std of 840 kN; - a chain and lazy-wave cable mooring at dtM 0.0125 s, 300 s: the std of fairlead tension, cable tension, curvature, twist and torque within 0.001 %, the largest differences at the last printed digit (5 N of fairlead tension, 1e-7 1/m of curvature). test_wave_grid checks that positions read at one time and sampled at another are advanced exactly for nodes at constant velocity. The guard script's byte-for-byte comparison now needs a reference build with the same sampling; an earlier build differs by design. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 12 ++ doc/openfast.rst | 4 +- src/CableDyn_WaveGrid.f90 | 16 ++- src/openfast/CableDyn_OF.f90 | 134 ++++++++++++++---- tests/test_wave_grid.f90 | 17 ++- .../scripts/openfast_wave_grid_guard.py | 10 +- 6 files changed, 160 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7ec671d..fb17be5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,18 @@ All notable changes to CableDyn are recorded in this file. The format follows until its grid is enlarged as the tutorial describes. Runs that pass the checks give the same results, 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, advanced from their committed positions + by their velocity (from their last two committed positions), where they took them at the committed + positions of the step's start: one CableDyn step behind, a phase error of k v dtM. Grid-route results + change at that level, by design: on the r-test chain mooring of the OpenFAST tutorial (Hs 6 m, + Tp 12 s, 60 s, dtM 0.025 s) the fairlead-tension standard deviations move by less than 0.001 % and + the tensions by at most 200 N (0.002 standard deviations); on a chain and lazy-wave cable mooring at + dtM 0.0125 s over 300 s the standard deviations of tension, curvature and twist move by less than + 0.001 % and the largest differences are at the last printed digit. The wave-grid guard and the + provenance record are unchanged; a checkpoint carries the position history, so a restarted run + continues bit for bit. The node-wise route (`SEASTATE_SPECTRAL`) advanced its nodes so from the start. + ### Fixed - A Syrope rope at its running maximum had a band of slow strains, up to 9e-7 wide on the shipped table, diff --git a/doc/openfast.rst b/doc/openfast.rst index 7d665448..4a4c534c 100644 --- a/doc/openfast.rst +++ b/doc/openfast.rst @@ -126,7 +126,9 @@ Fluid source ~~~~~~~~~~~~ With no WaterKin policy (``0 WaterKin``, the default), CableDyn samples the complete enabled -SeaState wave and current field at its line nodes and refreshes it every CableDyn step. A +SeaState wave and current field at its line nodes and refreshes it every CableDyn step, at the +end of the step and at the nodes' positions then: their positions at the last committed step +advanced by their velocity (from their last two committed positions). A WaterKin file can select file waves, a file depth-dependent current, host waves, or host current independently where the field is separable. Unsupported or double-counted combinations fail during initialisation. The selector matrix is in :doc:`options` and :doc:`driver_format`. diff --git a/src/CableDyn_WaveGrid.f90 b/src/CableDyn_WaveGrid.f90 index 43534e50..106a59da 100644 --- a/src/CableDyn_WaveGrid.f90 +++ b/src/CableDyn_WaveGrid.f90 @@ -32,7 +32,7 @@ MODULE CableDyn_WaveGrid IMPLICIT NONE PRIVATE - PUBLIC :: CD_WaveGrid_Along_Axis, CD_WaveGrid_Coarse_Axes, CD_WaveGrid_Field_Varies + PUBLIC :: CD_WaveGrid_Along_Axis, CD_WaveGrid_Coarse_Axes, CD_WaveGrid_Field_Varies, CD_WaveGrid_Advance !> the tolerance on a wave direction taken as along a grid axis (deg) REAL(wp), PARAMETER, PUBLIC :: CD_WAVEGRID_DIR_TOL = 1.0E-4_wp @@ -140,4 +140,18 @@ PURE LOGICAL FUNCTION CD_WaveGrid_Field_Varies(f, axis, rtol) RESULT(varies) END DO END FUNCTION CD_WaveGrid_Field_Varies + PURE FUNCTION CD_WaveGrid_Advance(x, x_last, t, t_last, t_target) RESULT(xs) + !! The positions x of time t advanced to t_target by the velocity (x - x_last)/(t - t_last) of + !! the positions x_last of the earlier time t_last: where the wave field is sampled for a + !! sample time other than the time of the positions. x itself without a history (t_last not + !! before t) or at its own time. + REAL(wp), INTENT(IN) :: x(:, :), x_last(:, :), t, t_last, t_target + REAL(wp) :: xs(SIZE(x, 1), SIZE(x, 2)) + IF (t > t_last .AND. ABS(t_target - t) > 0.0_wp) THEN + xs = x + (x - x_last)/(t - t_last)*(t_target - t) + ELSE + xs = x + END IF + END FUNCTION CD_WaveGrid_Advance + END MODULE CableDyn_WaveGrid diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index 142fdd3f..87a8f282 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -137,7 +137,8 @@ MODULE CableDyn CD_Recompute_System_Acceleration, CD_SYSTEM_OK USE SeaSt_WaveField, ONLY: WaveField_GetNodeWaveKin USE SeaSt_WaveField_Types, ONLY: WaveMod_None, WaveMod_ExtFull - USE CableDyn_WaveGrid, ONLY: CD_WaveGrid_Coarse_Axes, CD_WaveGrid_Field_Varies, CD_WAVEGRID_DIR_TOL, & + USE CableDyn_WaveGrid, ONLY: CD_WaveGrid_Coarse_Axes, CD_WaveGrid_Field_Varies, CD_WaveGrid_Advance, & + CD_WAVEGRID_DIR_TOL, & CD_WAVEGRID_COARSE_HALF_NODES, CD_WAVEGRID_FIELD_RTOL USE IfW_FlowField_Types, ONLY: Grid3D_FieldType USE IfW_FlowField, ONLY: IfW_FlowField_GetVelAcc @@ -280,6 +281,12 @@ END FUNCTION cd_cpu_guard_armed ! as sampled at each node, and the nodes it flags REAL(wp), ALLOCATABLE :: fx_zeta(:) LOGICAL, ALLOCATABLE :: fx_flag(:) + ! the grid route samples SeaState at the nodes' positions advanced to the sample time (fx_smp): + ! the positions read (fx_xyz) are those of the last commit, the start of the mooring interval + ! whose end is sampled; the advance takes each node's velocity from its positions at the last + ! two distinct commit times (smp_x at smp_t, smp_xl at smp_tl), carried through a checkpoint + REAL(wp), ALLOCATABLE :: fx_smp(:,:), smp_x(:,:), smp_xl(:,:) + REAL(DbKi) :: smp_t = -1.0_DbKi, smp_tl = -1.0_DbKi ! TRUE once the warning that sampling nodes lie outside the SeaState wave-kinematics grid has ! been issued (OPTION waveGridCheck warn): one warning per run (check_wavefield_grid). LOGICAL :: grid_warned = .FALSE. @@ -1077,7 +1084,8 @@ SUBROUTINE CD_Init(InitInp, u, p, x, xd, z, other, y, m, DTcoupling, InitOut, Er ALLOCATE (Inst(id)%fx_xyz(3, Inst(id)%nfluid), Inst(id)%fx_vel(3, Inst(id)%nfluid), & Inst(id)%fx_acc(3, Inst(id)%nfluid), Inst(id)%fx_wl(Inst(id)%nfluid), & Inst(id)%fx_pd(Inst(id)%nfluid), Inst(id)%fx_zeta(Inst(id)%nfluid), & - Inst(id)%fx_flag(Inst(id)%nfluid), STAT=ErrStat2) + Inst(id)%fx_flag(Inst(id)%nfluid), Inst(id)%fx_smp(3, Inst(id)%nfluid), & + Inst(id)%smp_x(3, Inst(id)%nfluid), Inst(id)%smp_xl(3, Inst(id)%nfluid), STAT=ErrStat2) IF (ErrStat2 /= 0) THEN CALL SetErrStat( ErrID_Fatal, 'Could not allocate the ambient-fluid sampling workspace.', & ErrStat, ErrMsg, RoutineName ) @@ -1796,7 +1804,8 @@ SUBROUTINE rebuild_from_checkpoint( t, u1, p, x, other, m, ErrStat, ErrMsg ) ALLOCATE (Inst(id)%fx_xyz(3, Inst(id)%nfluid), Inst(id)%fx_vel(3, Inst(id)%nfluid), & Inst(id)%fx_acc(3, Inst(id)%nfluid), Inst(id)%fx_wl(Inst(id)%nfluid), & Inst(id)%fx_pd(Inst(id)%nfluid), Inst(id)%fx_zeta(Inst(id)%nfluid), & - Inst(id)%fx_flag(Inst(id)%nfluid), STAT=ErrStat2) + Inst(id)%fx_flag(Inst(id)%nfluid), Inst(id)%fx_smp(3, Inst(id)%nfluid), & + Inst(id)%smp_x(3, Inst(id)%nfluid), Inst(id)%smp_xl(3, Inst(id)%nfluid), STAT=ErrStat2) IF (ErrStat2 /= 0) THEN CALL SetErrStat( ErrID_Fatal, 'Could not allocate the ambient-fluid workspace (rebuild).', & ErrStat, ErrMsg, RoutineName ) @@ -2136,19 +2145,19 @@ SUBROUTINE CD_UpdateStates( t, n, u, t_array, p, x, xd, z, other, m, ErrStat, Er TRIM(em), ErrStat, ErrMsg, RoutineName ) RETURN END IF - ! SeaState ambient fluid: sample the WaveField at the line nodes' committed - ! positions, at the END of this mooring interval (where the implicit step - ! prescribes the boundary), and hold the fields over the step. The advance - ! runs on the LAST glue substep of the interval, so the interval end is + ! SeaState ambient fluid: sample the WaveField at the line nodes' positions at the + ! END of this mooring interval (where the implicit step prescribes the boundary), + ! advanced there from their committed positions, and hold the fields over the step. + ! The advance runs on the LAST glue substep of the interval, so the interval end is ! t + p%dtCoupling -- the SAME time the coupled-kinematics interpolation ! above uses (t + dt_moor from here would sit almost a full mooring step in ! the future under supercycling, phase-shifting the wave kinematics). ! Runs AFTER the snapshot: a correction re-entry restores the step-start - ! state and re-samples at the same committed positions. + ! state and re-samples from the same committed positions. IF (Inst(id)%use_extfluid) THEN IF (Inst(id)%prof_enabled) CALL SYSTEM_CLOCK(prof_phase0) - ! (the positions are those of the interval start, the last commit; the node-wise route - ! advances them from there, the grid route samples them as they are) + ! (the positions read are those of the interval start, the last commit; both routes + ! advance them from there to the sample time) CALL sample_wavefield( Inst(id), p, m, t + p%dtCoupling, ErrStat2, ErrMsg2, & t_positions=Inst(id)%t_commit ) IF (ErrStat2 < AbortErrLev) CALL save_held_fluid( Inst(id), other ) @@ -2236,7 +2245,8 @@ END SUBROUTINE CD_UpdateStates !---------------------------------------------------------------------------------------------------------------------------------- SUBROUTINE sample_wavefield( inst_e, p, m, t_sample, ErrStat, ErrMsg, at_init, t_positions ) - !! Sample the SeaState WaveField at every mooring line node's committed position -- + !! Sample the SeaState WaveField at every mooring line node -- at its committed position + !! advanced to t_sample (advance_sample_positions) -- !! fluid velocity (waves + current), fluid acceleration, and the local free-surface !! elevation -- and prescribe them to the aggregate for the coming advance. Nodes !! are forced in-water for kinematics (forceNodeInWater = .TRUE., the MoorDyn @@ -2332,6 +2342,10 @@ SUBROUTINE sample_wavefield( inst_e, p, m, t_sample, ErrStat, ErrMsg, at_init, t CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: '//TRIM(em), ErrStat, ErrMsg, RoutineName ) RETURN END IF + ! the grid route samples at the positions advanced to the sample time (fx_smp) + t_pos = t_sample + IF (PRESENT(t_positions)) t_pos = t_positions + CALL advance_sample_positions( inst_e, t_sample, t_pos ) check_grid = .TRUE. IF (timed) CALL SYSTEM_CLOCK(prof_c0, prof_rate) DO i = 1, inst_e%nfluid @@ -2344,7 +2358,7 @@ SUBROUTINE sample_wavefield( inst_e, p, m, t_sample, ErrStat, ErrMsg, at_init, t nodeInWater = 0_IntKi ELSE CALL WaveField_GetNodeWaveKin( p%WaveField, m%WaveField_m, t_sample, & - REAL(inst_e%fx_xyz(:, i), ReKi), .TRUE., & + REAL(inst_e%fx_smp(:, i), ReKi), .TRUE., & inst_e%agg%host_current_enabled, nodeInWater, & zeta1, zeta2, zeta, pdyn, fv, fa, famcf, ErrStat2, ErrMsg2 ) CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) @@ -2362,7 +2376,7 @@ SUBROUTINE sample_wavefield( inst_e, p, m, t_sample, ErrStat, ErrMsg, at_init, t ! Below SWL and for Wheeler stretching, retain the same four ! vertical grid nodes and interpolation weights as the sampler. n_current_nodes = 4 - IF (p%WaveField%WaveStMod < 3_IntKi .AND. inst_e%fx_xyz(3, i) > 0.0_wp) & + IF (p%WaveField%WaveStMod < 3_IntKi .AND. inst_e%fx_smp(3, i) > 0.0_wp) & n_current_nodes = 1 DO l = 1, n_current_nodes IF (n_current_nodes == 1) THEN @@ -2397,7 +2411,7 @@ SUBROUTINE sample_wavefield( inst_e, p, m, t_sample, ErrStat, ErrMsg, at_init, t ! subtract both, then restore the analytically reconstructed steady ! current. The remainder from the first sample is dynamic current. CALL WaveField_GetNodeWaveKin( p%WaveField, m%WaveField_m, t_sample, & - REAL(inst_e%fx_xyz(:, i), ReKi), .TRUE., .FALSE., nodeInWater, & + REAL(inst_e%fx_smp(:, i), ReKi), .TRUE., .FALSE., nodeInWater, & wave_zeta1, wave_zeta2, wave_zeta, wave_pdyn, wave_fv, wave_fa, & wave_famcf, ErrStat2, ErrMsg2 ) CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) @@ -2410,7 +2424,7 @@ SUBROUTINE sample_wavefield( inst_e, p, m, t_sample, ErrStat, ErrMsg, at_init, t fv = fv - steady_fv END IF IF (ALLOCATED(inst_e%agg%host_current_profile_z)) THEN - CALL CD_Current_Profile_Velocity(REAL(inst_e%fx_xyz(3, i), wp), & + CALL CD_Current_Profile_Velocity(REAL(inst_e%fx_smp(3, i), wp), & inst_e%agg%host_current_profile_z, & inst_e%agg%host_current_profile_velocity, & profile_fv, es, em) @@ -2434,8 +2448,8 @@ SUBROUTINE sample_wavefield( inst_e, p, m, t_sample, ErrStat, ErrMsg, at_init, t inst_e%prof_t_wave_kin = inst_e%prof_t_wave_kin + REAL(prof_c1 - prof_c0, wp)/REAL(prof_rate, wp) prof_c0 = prof_c1 END IF - ! Grid coverage: checked on the positions just sampled (with their free-surface - ! elevations), at Init (the static equilibrium) and then every mooring step: to the end of + ! Grid coverage: checked on the committed positions (within a mooring step's motion of those + ! just sampled, with the free-surface elevations sampled there), at Init (the static equilibrium) and then every mooring step: to the end of ! the run, which it stops at the first node outside (OPTION waveGridCheck error, the ! default), or warning once and then silently noting the nodes outside in the provenance ! record (waveGridCheck warn), which is written at once when the check reports. @@ -2465,6 +2479,67 @@ SUBROUTINE sample_wavefield( inst_e, p, m, t_sample, ErrStat, ErrMsg, at_init, t END SUBROUTINE sample_wavefield !---------------------------------------------------------------------------------------------------------------------------------- + SUBROUTINE advance_sample_positions( inst_e, t_sample, t_pos ) + !! The grid route's sample positions (fx_smp): the committed positions just read (fx_xyz), + !! which belong to t_pos (the last commit, the start of the mooring interval), advanced to + !! t_sample (its end) by each node's velocity, the difference of its positions at the last + !! two distinct position times (smp_x at smp_t, smp_xl at smp_tl). Without that history (the + !! first sample, or positions of an earlier time: a retry or a rewind, which restart it) and + !! when t_sample is t_pos, the positions are sampled as read. The node-wise route advances its + !! evaluation points the same way (sample_nodewise). + TYPE(CD_OF_Instance), INTENT(INOUT) :: inst_e + REAL(DbKi), INTENT(IN ) :: t_sample, t_pos + IF (t_pos > inst_e%smp_t) THEN + IF (inst_e%smp_t >= 0.0_DbKi) THEN + inst_e%smp_xl = inst_e%smp_x + inst_e%smp_tl = inst_e%smp_t + ELSE + inst_e%smp_xl = inst_e%fx_xyz + inst_e%smp_tl = t_pos + END IF + inst_e%smp_x = inst_e%fx_xyz + inst_e%smp_t = t_pos + ELSE IF (t_pos < inst_e%smp_t) THEN + inst_e%smp_x = inst_e%fx_xyz + inst_e%smp_xl = inst_e%fx_xyz + inst_e%smp_t = t_pos + inst_e%smp_tl = t_pos + END IF + ! smp_x holds the positions just read (fx_xyz) at smp_t = t_pos + inst_e%fx_smp = CD_WaveGrid_Advance( inst_e%smp_x, inst_e%smp_xl, REAL(inst_e%smp_t, wp), & + REAL(inst_e%smp_tl, wp), REAL(t_sample, wp) ) + END SUBROUTINE advance_sample_positions + + PURE INTEGER(IntKi) FUNCTION smp_mirror_size( inst_e ) RESULT(n) + !! The grid route's position history (advance_sample_positions) carried in the OtherState after + !! the node-wise cache: per node its last two positions, then the two times. + TYPE(CD_OF_Instance), INTENT(IN) :: inst_e + n = 0_IntKi + IF (ALLOCATED(inst_e%smp_x) .AND. .NOT. inst_e%nwk_on) n = 6_IntKi*inst_e%nfluid + 2_IntKi + END FUNCTION smp_mirror_size + + SUBROUTINE smp_pack( inst_e, buf ) + TYPE(CD_OF_Instance), INTENT(IN ) :: inst_e + REAL(DbKi), INTENT(INOUT) :: buf(:) + INTEGER(IntKi) :: nf + nf = inst_e%nfluid + buf(1:3*nf) = RESHAPE(REAL(inst_e%smp_x, DbKi), [3*nf]) + buf(3*nf + 1:6*nf) = RESHAPE(REAL(inst_e%smp_xl, DbKi), [3*nf]) + buf(6*nf + 1) = inst_e%smp_t + buf(6*nf + 2) = inst_e%smp_tl + END SUBROUTINE smp_pack + + SUBROUTINE smp_unpack( inst_e, buf ) + TYPE(CD_OF_Instance), INTENT(INOUT) :: inst_e + REAL(DbKi), INTENT(IN ) :: buf(:) + INTEGER(IntKi) :: nf + nf = inst_e%nfluid + inst_e%smp_x = RESHAPE(REAL(buf(1:3*nf), wp), [3, nf]) + inst_e%smp_xl = RESHAPE(REAL(buf(3*nf + 1:6*nf), wp), [3, nf]) + inst_e%smp_t = buf(6*nf + 1) + inst_e%smp_tl = buf(6*nf + 2) + END SUBROUTINE smp_unpack + SUBROUTINE check_wavefield_grid( inst_e, wf, t_sample, at_init, ErrStat, ErrMsg ) !! The wave-grid guard on coverage: sampling nodes in the water that lie outside the SeaState !! wave-kinematics grid. The volume grid spans X_HalfWidth and Y_HalfWidth about the origin @@ -3959,11 +4034,12 @@ SUBROUTINE save_held_fluid( inst_e, other ) !! restart serves its loads from the same fields (restore_held_fluid). TYPE(CD_OF_Instance), INTENT(IN ) :: inst_e TYPE(CD_OtherStateType), INTENT(INOUT) :: other - INTEGER(IntKi) :: nf, nn, np + INTEGER(IntKi) :: nf, nn, np, ng nf = inst_e%nfluid - ! the node-wise route (WaterKin SEASTATE_SPECTRAL) appends its cache, then the provenance - ! record its run state - nn = nwk_mirror_size( inst_e ) + ! the node-wise route (WaterKin SEASTATE_SPECTRAL) appends its cache, the grid route its + ! position history, then the provenance record its run state + ng = smp_mirror_size( inst_e ) + nn = nwk_mirror_size( inst_e ) + ng np = prov_mirror_size( inst_e ) IF (ALLOCATED(other%fluid_held)) THEN IF (SIZE(other%fluid_held) /= 8*nf + nn + np) DEALLOCATE (other%fluid_held) @@ -3973,7 +4049,8 @@ SUBROUTINE save_held_fluid( inst_e, other ) other%fluid_held(3*nf + 1:6*nf) = RESHAPE(REAL(inst_e%fx_acc, DbKi), [3*nf]) other%fluid_held(6*nf + 1:7*nf) = REAL(inst_e%fx_wl, DbKi) other%fluid_held(7*nf + 1:8*nf) = REAL(inst_e%fx_pd, DbKi) - IF (nn > 0_IntKi) CALL nwk_pack( inst_e, other%fluid_held(8*nf + 1:8*nf + nn) ) + IF (nn > ng) CALL nwk_pack( inst_e, other%fluid_held(8*nf + 1:8*nf + nn - ng) ) + IF (ng > 0_IntKi) CALL smp_pack( inst_e, other%fluid_held(8*nf + nn - ng + 1:8*nf + nn) ) CALL prov_pack( inst_e, other%fluid_held(8*nf + nn + 1:8*nf + nn + np) ) END SUBROUTINE save_held_fluid @@ -3986,17 +4063,19 @@ SUBROUTINE restore_held_fluid( inst_e, other, restored, ErrStat, ErrMsg ) LOGICAL, INTENT( OUT) :: restored INTEGER(IntKi), INTENT( OUT) :: ErrStat CHARACTER(*), INTENT( OUT) :: ErrMsg - INTEGER(IntKi) :: nf, es, nn, np + INTEGER(IntKi) :: nf, es, nn, np, ng CHARACTER(ErrMsgLen) :: em ErrStat = ErrID_None ErrMsg = '' restored = .FALSE. nf = inst_e%nfluid - nn = nwk_mirror_size( inst_e ) + ng = smp_mirror_size( inst_e ) + nn = nwk_mirror_size( inst_e ) + ng np = prov_mirror_size( inst_e ) IF (.NOT. ALLOCATED(other%fluid_held)) RETURN IF (SIZE(other%fluid_held) /= 8*nf + nn + np) RETURN - IF (nn > 0_IntKi) CALL nwk_unpack( inst_e, other%fluid_held(8*nf + 1:8*nf + nn) ) + IF (nn > ng) CALL nwk_unpack( inst_e, other%fluid_held(8*nf + 1:8*nf + nn - ng) ) + IF (ng > 0_IntKi) CALL smp_unpack( inst_e, other%fluid_held(8*nf + nn - ng + 1:8*nf + nn) ) CALL prov_unpack( inst_e, other%fluid_held(8*nf + nn + 1:8*nf + nn + np) ) inst_e%fx_vel = RESHAPE(REAL(other%fluid_held(1:3*nf), wp), [3, nf]) inst_e%fx_acc = RESHAPE(REAL(other%fluid_held(3*nf + 1:6*nf), wp), [3, nf]) @@ -6588,7 +6667,10 @@ SUBROUTINE release_instance( k, ErrStat, ErrMsg ) Inst(k)%u_interp_ready = .FALSE. END IF IF (ALLOCATED(Inst(k)%fx_xyz)) DEALLOCATE (Inst(k)%fx_xyz, Inst(k)%fx_vel, Inst(k)%fx_acc, & - Inst(k)%fx_wl, Inst(k)%fx_pd, Inst(k)%fx_zeta, Inst(k)%fx_flag) + Inst(k)%fx_wl, Inst(k)%fx_pd, Inst(k)%fx_zeta, Inst(k)%fx_flag, & + Inst(k)%fx_smp, Inst(k)%smp_x, Inst(k)%smp_xl) + Inst(k)%smp_t = -1.0_DbKi + Inst(k)%smp_tl = -1.0_DbKi IF (ALLOCATED(Inst(k)%nwk_step)) DEALLOCATE (Inst(k)%nwk_step, Inst(k)%nwk_p, Inst(k)%nwk_val, & Inst(k)%nwk_der, Inst(k)%nwk_x, Inst(k)%nwk_xl, Inst(k)%nwk_pos, & Inst(k)%nwk_dcv, Inst(k)%nwk_dca) diff --git a/tests/test_wave_grid.f90 b/tests/test_wave_grid.f90 index 6bd1a382..b1803c6e 100644 --- a/tests/test_wave_grid.f90 +++ b/tests/test_wave_grid.f90 @@ -8,12 +8,13 @@ PROGRAM test_wave_grid !! * NY = 2 is coarse for every long-crested sea not along x (30, 60 and 90 deg) and for a !! short-crested sea; NX = 2 for every sea not along y; an aligned sea (NY = 2 at 0 or !! 180 deg, NX = 2 at 90 or 270 deg) and a finer grid (NX = NY = 3) are never coarse; + !! * positions read at one time and sampled at another are advanced by their velocity; !! * OPTION waveGridCheck reaches the coupled aggregate (the mixed IEA-15 MW example deck, the !! first argument): error by default and as written, warn as written, any other value is !! refused by name. USE CableDyn_Precision, ONLY: wp USE CableDyn_WaveGrid, ONLY: CD_WaveGrid_Along_Axis, CD_WaveGrid_Coarse_Axes, CD_WaveGrid_Field_Varies, & - CD_WAVEGRID_DIR_TOL, CD_WAVEGRID_FIELD_RTOL + CD_WAVEGRID_DIR_TOL, CD_WAVEGRID_FIELD_RTOL, CD_WaveGrid_Advance USE CableDyn_OpenFAST_Aggregate, ONLY: CD_AGG_ModuleType, CD_AGG_Init_From_Deck, CD_AGG_End, CD_AGG_OK USE, INTRINSIC :: IEEE_ARITHMETIC, ONLY: IEEE_VALUE, IEEE_QUIET_NAN USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: REAL32 @@ -113,6 +114,20 @@ PROGRAM test_wave_grid 'a single point along the axis does not vary') CALL require(.NOT. CD_WaveGrid_Field_Varies(field, 3, CD_WAVEGRID_FIELD_RTOL), 'there is no third axis') + ! the sample positions: nodes moving at a constant velocity, read at the start of a mooring + ! step and sampled at its end, are sampled where they are at that time + BLOCK + REAL(wp) :: x0(3, 2), u(3, 2), xs(3, 2) + x0 = RESHAPE([10.0_wp, -4.0_wp, -30.0_wp, 60.0_wp, 2.0_wp, -14.0_wp], [3, 2]) + u = RESHAPE([0.8_wp, -0.3_wp, 0.5_wp, -1.2_wp, 0.0_wp, 2.0_wp], [3, 2]) + xs = CD_WaveGrid_Advance(x0 + u*1.025_wp, x0 + u*1.0_wp, 1.025_wp, 1.0_wp, 1.05_wp) + CALL require(MAXVAL(ABS(xs - (x0 + u*1.05_wp))) < 1.0e-12_wp, 'a sample position belongs to the sample time') + xs = CD_WaveGrid_Advance(x0, x0, 1.0_wp, 1.0_wp, 1.05_wp) + CALL require(.NOT. ANY(ABS(xs - x0) > 0.0_wp), 'without a history the positions are sampled as read') + xs = CD_WaveGrid_Advance(x0 + u, x0, 1.0_wp, 0.5_wp, 1.0_wp) + CALL require(.NOT. ANY(ABS(xs - (x0 + u)) > 0.0_wp), 'at their own time the positions are sampled as read') + END BLOCK + ! the deck option, through the aggregate the OpenFAST shell reads it from IF (COMMAND_ARGUMENT_COUNT() < 1) THEN WRITE (*, '(A)') 'FAIL: the mixed example deck path argument is required' diff --git a/validation/scripts/openfast_wave_grid_guard.py b/validation/scripts/openfast_wave_grid_guard.py index 2cc8ed31..8134be93 100644 --- a/validation/scripts/openfast_wave_grid_guard.py +++ b/validation/scripts/openfast_wave_grid_guard.py @@ -30,10 +30,12 @@ ext_along_x the covering grid with NY = 2 under supplied kinematics of a wave at 0 deg. Each stopping case's message must name the time, a line, the node count, the deepest and the -shallowest node, and the option that downgrades it. With ``--base-exe`` (an openfast.exe built -with the CableDyn sources before the guard), the two running cases and the ``outside`` and -``ny2_oblique`` cases under ``warn`` (which the earlier build only warned about, or did not check) -must give the same ``.out`` and ``.CD.out`` data rows as that build, byte for byte. +shallowest node, and the option that downgrades it. With ``--base-exe`` (a reference openfast.exe +with the same grid sampling: a build at or after the commit that samples the grid at the positions +of the sample time; an earlier build samples a mooring step behind and differs by design), the two +running cases and the ``outside`` and ``ny2_oblique`` cases under ``warn`` must give the same +``.out`` and ``.CD.out`` data rows as that build, byte for byte: the guard and its record do not +change a result. usage: openfast_wave_grid_guard.py --exe --case-dir --work [--base-exe ] From 57da2f3bf23f917d386eed58d52fec85e5747093 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Thu, 3 Dec 2026 03:50:28 +0900 Subject: [PATCH 2/3] fix(openfast): check the wave grid at the positions sampled The grid route now samples SeaState at the nodes' positions advanced to the sample time, but the coverage guard, its message and the provenance record still read the committed positions of the step's start. A node that a step's motion carried out of the grid was sampled there without a finding. The guard, the resolution check, the per-line report and the out-of-grid record now use the positions sampled; the node-wise route reports the positions read, as before. On the guard cases the running and warned runs give the same data rows, bit for bit, as the build before this change; the mid-run case stops at 4.15 s, one mooring step earlier than at 4.175 s, the step whose sample position is the first outside the grid. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 3 ++- src/openfast/CableDyn_OF.f90 | 46 ++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb17be5d..136e6e32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,7 +74,8 @@ All notable changes to CableDyn are recorded in this file. The format follows the tensions by at most 200 N (0.002 standard deviations); on a chain and lazy-wave cable mooring at dtM 0.0125 s over 300 s the standard deviations of tension, curvature and twist move by less than 0.001 % and the largest differences are at the last printed digit. The wave-grid guard and the - provenance record are unchanged; a checkpoint carries the position history, so a restarted run + provenance record check and report the positions sampled, so a node that a step's motion carries + out of the grid is found at that step; a checkpoint carries the position history, so a restarted run continues bit for bit. The node-wise route (`SEASTATE_SPECTRAL`) advanced its nodes so from the start. ### Fixed diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index 87a8f282..33db20a3 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -2298,6 +2298,10 @@ SUBROUTINE sample_wavefield( inst_e, p, m, t_sample, ErrStat, ErrMsg, at_init, t CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: '//TRIM(em), ErrStat, ErrMsg, RoutineName ) RETURN END IF + ! the positions the guard and the provenance record check and report (fx_smp): on the grid + ! route those SeaState is asked at, the positions read advanced to the sample time below; on + ! the node-wise route the positions read + inst_e%fx_smp = inst_e%fx_xyz ! SeaState measures its wave field and grid from the still-water level, and its node ! queries take SWL-relative positions; the mooring samples it at positions relative to the ! mean sea level, which coincide only for MSL2SWL = 0. Checked here, where the deck's @@ -2448,8 +2452,8 @@ SUBROUTINE sample_wavefield( inst_e, p, m, t_sample, ErrStat, ErrMsg, at_init, t inst_e%prof_t_wave_kin = inst_e%prof_t_wave_kin + REAL(prof_c1 - prof_c0, wp)/REAL(prof_rate, wp) prof_c0 = prof_c1 END IF - ! Grid coverage: checked on the committed positions (within a mooring step's motion of those - ! just sampled, with the free-surface elevations sampled there), at Init (the static equilibrium) and then every mooring step: to the end of + ! Grid coverage: checked on the positions just sampled (fx_smp, with the free-surface + ! elevations sampled there), at Init (the static equilibrium) and then every mooring step: to the end of ! the run, which it stops at the first node outside (OPTION waveGridCheck error, the ! default), or warning once and then silently noting the nodes outside in the provenance ! record (waveGridCheck warn), which is written at once when the check reports. @@ -2618,17 +2622,17 @@ SUBROUTINE check_wavefield_grid( inst_e, wf, t_sample, at_init, ErrStat, ErrMsg ! nodes above the free surface carry no fluid load (see above) surface = inst_e%fx_wl(i) IF (wf%WaveStMod == 0_IntKi) surface = MIN(surface, 0.0_wp) - IF (inst_e%fx_xyz(3, i) > surface) CYCLE + IF (inst_e%fx_smp(3, i) > surface) CYCLE nwet = nwet + 1_IntKi outside = .FALSE. DO k = 1, 2 IF (.NOT. check_xy(k)) CYCLE - ex = MAX(lo(k) - inst_e%fx_xyz(k, i), inst_e%fx_xyz(k, i) - hi(k)) + ex = MAX(lo(k) - inst_e%fx_smp(k, i), inst_e%fx_smp(k, i) - hi(k)) IF (ex > tol(k)) THEN outside = .TRUE. IF (ex > ex_max(k)) THEN ex_max(k) = ex - at_max(k) = inst_e%fx_xyz(k, i) + at_max(k) = inst_e%fx_smp(k, i) END IF END IF END DO @@ -2637,7 +2641,7 @@ SUBROUTINE check_wavefield_grid( inst_e, wf, t_sample, at_init, ErrStat, ErrMsg ! the depth mapped linearly from [-EffWtrDpth, wave elevation] to [-EffWtrDpth, 0] with ! the elevation it sampled -- also for the current of a current-only host mode, whose ! fx_wl is the still-water level - zq = inst_e%fx_xyz(3, i) + zq = inst_e%fx_smp(3, i) IF (wf%WaveMod /= WaveMod_None .AND. wf%WaveStMod == 3_IntKi) THEN dep = REAL(wf%EffWtrDpth, wp) IF (dep + inst_e%fx_zeta(i) > 0.0_wp) & @@ -2648,7 +2652,7 @@ SUBROUTINE check_wavefield_grid( inst_e, wf, t_sample, at_init, ErrStat, ErrMsg outside = .TRUE. IF (ex > ex_max(3)) THEN ex_max(3) = ex - at_max(3) = inst_e%fx_xyz(3, i) + at_max(3) = inst_e%fx_smp(3, i) END IF END IF END IF @@ -2826,7 +2830,7 @@ SUBROUTINE check_wavefield_resolution( inst_e, wf, ErrStat, ErrMsg ) inst_e%fx_flag(i) = .FALSE. surface = inst_e%fx_wl(i) IF (wf%WaveStMod == 0_IntKi) surface = MIN(surface, 0.0_wp) - IF (inst_e%fx_xyz(3, i) > surface) CYCLE + IF (inst_e%fx_smp(3, i) > surface) CYCLE nwet = nwet + 1_IntKi inst_e%fx_flag(i) = .TRUE. END DO @@ -2908,8 +2912,8 @@ SUBROUTINE flagged_nodes_by_line( inst_e, budget, report, with_ratio ) ideep = i ishal = i END IF - IF (inst_e%fx_xyz(3, i) < inst_e%fx_xyz(3, ideep)) ideep = i - IF (inst_e%fx_xyz(3, i) > inst_e%fx_xyz(3, ishal)) ishal = i + IF (inst_e%fx_smp(3, i) < inst_e%fx_smp(3, ideep)) ideep = i + IF (inst_e%fx_smp(3, i) > inst_e%fx_smp(3, ishal)) ishal = i END DO IF (n == 0_IntKi) CYCLE IF (n == 1_IntKi) THEN @@ -2919,9 +2923,9 @@ SUBROUTINE flagged_nodes_by_line( inst_e, budget, report, with_ratio ) node_position(ideep)//', shallowest at '//node_position(ishal) END IF IF (PRESENT(with_ratio)) THEN - IF (with_ratio .AND. vel_ratio( inst_e, REAL(inst_e%fx_xyz(3, ishal), wp) ) >= 0.0_wp) & + IF (with_ratio .AND. vel_ratio( inst_e, REAL(inst_e%fx_smp(3, ishal), wp) ) >= 0.0_wp) & item = item//', weighted velocity ratio '//ratio_text( vel_ratio( inst_e, & - REAL(inst_e%fx_xyz(3, ishal), wp) ) )// & + REAL(inst_e%fx_smp(3, ishal), wp) ) )// & TRIM(MERGE(' at the shallowest node', ' at the node ', n > 1_IntKi)) END IF IF (LEN(report) + LEN(item) + 2 > budget) THEN @@ -2954,8 +2958,8 @@ END FUNCTION ratio_text FUNCTION node_position(i) RESULT(s) INTEGER(IntKi), INTENT(IN) :: i CHARACTER(:), ALLOCATABLE :: s - s = '(x, y, z) = ('//TRIM(Num2LStr(inst_e%fx_xyz(1, i)))//', '//TRIM(Num2LStr(inst_e%fx_xyz(2, i)))// & - ', '//TRIM(Num2LStr(inst_e%fx_xyz(3, i)))//') m' + s = '(x, y, z) = ('//TRIM(Num2LStr(inst_e%fx_smp(1, i)))//', '//TRIM(Num2LStr(inst_e%fx_smp(2, i)))// & + ', '//TRIM(Num2LStr(inst_e%fx_smp(3, i)))//') m' END FUNCTION node_position END SUBROUTINE flagged_nodes_by_line @@ -3518,11 +3522,11 @@ SUBROUTINE prov_note( inst_e, kind, t_event, write_now, stopping ) IF (.NOT. ln%has_oog) THEN ln%has_oog = .TRUE. ln%oog_first_time = REAL(t_event, wp) - ln%oog_deepest = inst_e%fx_xyz(:, i) - ln%oog_shallowest = inst_e%fx_xyz(:, i) + ln%oog_deepest = inst_e%fx_smp(:, i) + ln%oog_shallowest = inst_e%fx_smp(:, i) END IF - IF (inst_e%fx_xyz(3, i) < ln%oog_deepest(3)) ln%oog_deepest = inst_e%fx_xyz(:, i) - IF (inst_e%fx_xyz(3, i) > ln%oog_shallowest(3)) ln%oog_shallowest = inst_e%fx_xyz(:, i) + IF (inst_e%fx_smp(3, i) < ln%oog_deepest(3)) ln%oog_deepest = inst_e%fx_smp(:, i) + IF (inst_e%fx_smp(3, i) > ln%oog_shallowest(3)) ln%oog_shallowest = inst_e%fx_smp(:, i) END IF END DO ! the weighted velocity ratio grows toward the surface: its largest value over the line's @@ -3653,7 +3657,7 @@ SUBROUTINE note_seastate_deep_interval( inst_e, wf ) interval = depth*SIN(REAL(wf%VolGridParams%delta(4), wp)) IF (depth < REAL(wf%EffWtrDpth, wp) - 0.01_wp*interval) RETURN IF (interval <= SEASTATE_DEEP_INTERVAL*depth) RETURN - nodes = COUNT(inst_e%fx_xyz(3, 1:inst_e%nfluid) < interval - depth) + nodes = COUNT(inst_e%fx_smp(3, 1:inst_e%nfluid) < interval - depth) IF (nodes == 0_IntKi) RETURN CALL WrScr( ' Note: the deepest interval of the SeaState depth grid is '//TRIM(Num2LStr(interval))// & ' m (NZ = '//TRIM(Num2LStr(nz))//', Z_Depth = '//TRIM(Num2LStr(depth))//' m), over '// & @@ -3692,8 +3696,8 @@ SUBROUTINE check_current_field_grid( inst_e, wf, t_sample ) ey = 0.0_wp DO i = 1, inst_e%nfluid surface = MIN(inst_e%fx_wl(i), 0.0_wp) - IF (inst_e%fx_xyz(3, i) > MAX(inst_e%fx_wl(i), surface)) CYCLE - pos = [inst_e%fx_xyz(1, i), inst_e%fx_xyz(2, i), inst_e%fx_xyz(3, i) + dep] + IF (inst_e%fx_smp(3, i) > MAX(inst_e%fx_wl(i), surface)) CYCLE + pos = [inst_e%fx_smp(1, i), inst_e%fx_smp(2, i), inst_e%fx_smp(3, i) + dep] IF (wf%CurrField%RotateWindBox) THEN rel = MATMUL(REAL(wf%CurrField%RotToWind, wp), pos - REAL(wf%CurrField%RefPosition, wp)) + & REAL(wf%CurrField%RefPosition, wp) From 00fa62e39a4a4da9b44b8613f6dccfbe81684b0f Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Thu, 3 Dec 2026 05:51:46 +0900 Subject: [PATCH 3/3] docs: word the grid-lag changelog entry plainly Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 136e6e32..f3cd4ae7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,17 +66,18 @@ All notable changes to CableDyn are recorded in this file. The format follows 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, advanced from their committed positions - by their velocity (from their last two committed positions), where they took them at the committed - positions of the step's start: one CableDyn step behind, a phase error of k v dtM. Grid-route results - change at that level, by design: on the r-test chain mooring of the OpenFAST tutorial (Hs 6 m, - Tp 12 s, 60 s, dtM 0.025 s) the fairlead-tension standard deviations move by less than 0.001 % and - the tensions by at most 200 N (0.002 standard deviations); on a chain and lazy-wave cable mooring at - dtM 0.0125 s over 300 s the standard deviations of tension, curvature and twist move by less than - 0.001 % and the largest differences are at the last printed digit. The wave-grid guard and the - provenance record check and report the positions sampled, so a node that a step's motion carries - out of the grid is found at that step; a checkpoint carries the position history, so a restarted run - continues bit for bit. The node-wise route (`SEASTATE_SPECTRAL`) advanced its nodes so from the start. + positions at the sample time (the end of the CableDyn step): their committed positions advanced by + their velocity, taken from their last two committed positions. Before, they took them at the + committed positions of the step's start, one CableDyn step behind (a phase error of k v dtM). + Grid-route results change at that level, by design: on the r-test chain mooring of the OpenFAST + tutorial (Hs 6 m, Tp 12 s, 60 s, dtM 0.025 s) the fairlead-tension standard deviations move by less + than 0.001 % and the tensions by at most 200 N (0.002 standard deviations); on a chain and lazy-wave + cable mooring at dtM 0.0125 s over 300 s the standard deviations of tension, curvature and twist + move by less than 0.001 % and the largest differences are at the last printed digit. The wave-grid + guard and the provenance record check and report the positions sampled, so a node that a step's + motion carries out of the grid is found at that step. A checkpoint carries the position history, so + a restarted run continues bit for bit. The node-wise route (`SEASTATE_SPECTRAL`) has advanced its + nodes this way from the start. ### Fixed