From 64b724a4ed2556cb2fb9dc81a66d7efb60dac962 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Wed, 28 Oct 2026 00:58:43 +0900 Subject: [PATCH] fix(viv): seed the shedding phase from the deck's End A; MoorDyn-C's riser MoorDyn seeds the phase at 2 pi i/N with node i counted from the line's AttachA. CableDyn counted from its own End A, which on a line written anchor first (the common MoorDyn row order, turned around by the reader) is MoorDyn's node N, and on a finite-EI mesh the static solve refined the node index no longer named the deck nodes. CD_Deck_VIV_Phase_Seed now gives MoorDyn's seed node by node: counted from the deck's End A, kept at the deck nodes of a refined mesh, interpolated in arc length at the nodes the refinement added. Both line kinds take it (an optional phase_seed of their VIV setters). Lines written fairlead first on the deck mesh are unchanged. MoorDyn-C's VIV test, the catenary riser of Thorsen et al. in a uniform 0.2 m/s current (written anchor first), joins the validation set (viv_riser): over 20-40 s at dtM 1e-3 s the fairlead tension averages 69.92 N against MoorDyn-C's 69.93 N, ranges 3.73 N against 3.72 N, and oscillates with a period of 0.4853 s against the measured 0.4808 s and MoorDyn-C's 0.4811 s, converging with dtM (0.4829 s at 2.5e-4 s). VALIDATION records it and the coupled VIV, which it listed as unsupported. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 6 +- CMakeLists.txt | 9 +++ VALIDATION.md | 3 +- doc/theory.rst | 5 +- src/CableDyn_DeckDriver.f90 | 77 ++++++++++++++++-- src/CableDyn_HermiteCableDynamic.f90 | 14 +++- src/CableDyn_Model.f90 | 14 +++- tests/test_viv_coupled.f90 | 62 ++++++++++++++- tests/test_viv_riser.py | 115 +++++++++++++++++++++++++++ 9 files changed, 289 insertions(+), 16 deletions(-) create mode 100644 tests/test_viv_riser.py diff --git a/CHANGELOG.md b/CHANGELOG.md index ca12e8f3..6af9ee14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,11 @@ All notable changes to CableDyn are recorded in this file. The format follows with the same phase start and running-RMS window (`VIVrmsWindow`, default 500 steps of `dtM`). On a taut 100 m line in a uniform current it follows MoorDyn-F's lock-in amplitude and frequency to two to three digits through mode-1 and mode-3 lock-in, at any `dtM` from - 5e-4 to 1e-2 s. The Python deck tools read and keep the columns. + 5e-4 to 1e-2 s. The phases start from the deck's End A as MoorDyn's do, also on a line + written anchor first, which the reader turns around, and at the deck nodes of a refined + finite-EI mesh. MoorDyn-C's own VIV case, the catenary riser of Thorsen et al., reproduces + its mean tension and tension range and the measured lock-in frequency (period within 1 %). + The Python deck tools read and keep the columns. - Cross-flow VIV of finite-EI cables in the standalone driver: the same LINE TYPES columns on an `EI > 0` type give a distributed lift, Gauss-integrated over each cubic-Hermite element with exact tangents, and a shedding phase at each node driven along the node's own tangent. A taut diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c3b79d0..163a0b51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1649,6 +1649,15 @@ if(Python3_Interpreter_FOUND) PROCESSORS 4 TIMEOUT ${_viv_lockin_timeout} ENVIRONMENT "${_cabledyn_python_test_environment}") + # MoorDyn-C's VIV test case: the catenary riser of Thorsen et al. in a uniform current + add_test(NAME viv_riser + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_viv_riser.py + --exe $ + --output ${CMAKE_BINARY_DIR}/viv_riser) + set_tests_properties(viv_riser PROPERTIES + LABELS "python;integration;dynamic;viv;validation" + TIMEOUT ${_viv_lockin_timeout} + ENVIRONMENT "${_cabledyn_python_test_environment}") else() message(STATUS "viv_lockin: skipped (numpy not importable in ${Python3_EXECUTABLE})") endif() diff --git a/VALIDATION.md b/VALIDATION.md index a025c0a3..8414bb19 100644 --- a/VALIDATION.md +++ b/VALIDATION.md @@ -63,6 +63,7 @@ article's methods, are compared in | **L2-80** | Lozon 80 m all-chain mooring | catenary (H) / MoorDyn-F (fairlead) | 0.03% / 1.8% | <2% / <5% | Pass | | **L2-arb** | Closed-form catenary reference check | OrcaFlex VolturnUS-S ref | 0.69% | <2% | Pass | | **L2-VIV** | Cross-flow VIV lock-in of a taut 100 m line, U = 0.06–0.42 m/s | MoorDyn-F (OpenFAST v5 `moordyn_driver`, `dtM` 5e-4 s) | mode-1 and mode-3 lock-in (U ≤ 0.18 and ≥ 0.36 m/s): mid-span A/D within 1.2%, frequency within one spectral bin; same response at `dtM` 5e-4 to 1e-2 s; at 0.21–0.33 m/s the codes settle on different modes (MoorDyn-F mode 1, CableDyn mode 2) | A/D <3%, frequency within one spectral bin (`viv_lockin`) | Pass scoped | +| **L2-VIV-riser** | Catenary riser of Thorsen et al. in a uniform 0.2 m/s current (MoorDyn-C's VIV test: D 0.024 m, EI 10.5 N m², 100 segments, `Cl` 0.7), deck written anchor first | measured cross-flow frequency 1.04 Hz; MoorDyn-C v2.7.2 (RK4, `dtM` 1e-4 s) | over 20–40 s at `dtM` 1e-3 s: mean fairlead tension 69.92 N against 69.93 N, range 3.73 N against 3.72 N, tension period 0.4853 s against the measured 0.4808 s and MoorDyn-C's 0.4811 s (0.4843 / 0.4829 s at `dtM` 5e-4 / 2.5e-4 s) | mean 0.2%, range 10%, period 1.5% (`viv_riser`) | Pass | | **L2-VIV-EI** | Cross-flow VIV of a finite-EI cable: the L2-VIV line with EI = 1 N m², and a bending-stiff line (EA 5e9 N, EI 5e7 N m², β = π²EI/(TL²) ≈ 1, neutrally buoyant) against the EI = 0 string of equal first-mode frequency, U = 0.10–0.36 m/s | CableDyn `EI = 0` line (verification) | EI = 1: mid/quarter A/D 0.662/0.421 against 0.663/0.421, same frequency, at `dtM` 5e-4 to 1e-2 s; stiff line: mode-1 lock-in A/D within 2.5% of the string's at the same frequency for U ≤ 0.24 m/s; for U ≥ 0.27 m/s the string jumps to mode 2 while the stiff line stays in mode 1 (bending raises f₂/f₁ to 3.15) | EI = 1: A/D within 1% at `dtM` 0.01 and 0.002 s (5e-4 s run once over 200 s); stiff line at U 0.21 m/s: A/D within 3%; frequency within one spectral bin; at U 0.30 m/s stiff line A/D > 0.6, string < 0.15 (`viv_lockin`, `hermite_viv`) | Pass | | **L3-1** | WD0050 static | OrcaFlex | 0.15 / 0.85% | <2% | Pass | | **L3-2** | Regular-wave dynamic | OrcaFlex (pinned, dt-converged) | mean 0.30%, swing 8.4% | <2% / <15% | Pass | @@ -793,7 +794,7 @@ stop with a named error. | Coupled finite-EI touchdown/contact | Pass verified | flat `WtrDpth` and equivalent constant structured bathymetry initialise and step with matching loads; friction and checkpoint restore are tested. The IEA-15 mixed example (its power cable on 248 elements, each at most half the bending length) has 149 grounded nodes and completes a 20 s aggregate trajectory at `dtM=0.025 s` with 2 m surge, 1 m heave, and 0.5 m/s host current, without fallback or stall recovery, at most 12 Newton iterations. A full-turbine run of the same model (one hour after a 200 s transient; TurbSim normal turbulence, 10.6 m/s, 17 % TI; JONSWAP Hs 8 m, Tp 12 s, aligned with the wind and the cable; AeroDyn with the rotor held at 7.55 rpm, no controller, rigid blades and tower; SeaState grid covering the lines) completes without recoveries or non-finite values. The cable's hang-off tension is 11.5 ± 1.1 kN (static 11.9 kN, maximum 17.9 kN). The 149 nodes grounded at the static state stay grounded, joined by one more once the platform has drifted (the touchdown moves 2.5 m toward the platform). The peak curvature is 0.156 1/m at the sag bend, 72 m from the hang-off, and 0.109 1/m at the touchdown. On the former 87-element mesh (10 m elements along the laid section) the peak was 0.160 1/m and the touchdown curvature 0.075 1/m, under-resolved by about 30 %. These curvatures were recorded before the `Curv` channels took the curvature recovered from nodal equilibrium: they are the geometric curvature of the centreline (the larger one-sided trace at a node), which `OutputRecovery element` reproduces. The chain-only twin of the run matches stock MoorDyn over 1200 s to 0.3 % in platform motion and fairlead tension statistics. The anchor tension of the laid cable stays at its static 1.23 kN (maximum 1.24 kN): the seabed friction of the 370 m laid section holds the tension changes at the touchdown. On the former mesh it read 1.39 kN (median) with wave-frequency stick-slip peaks up to 4.1 kN lasting under 1 s, which the resolved mesh does not show, and before the anchor-end correction of this release it locked at about 2.75 kN for the whole run. The run takes 27.1 min of wall time (18.8 min on the former mesh) | | `WaterKin` from file | Pass verified | See [WaterKin and SeaState modes](#waterkin-and-seastate-modes) | | Syrope polyester (`SYROPE:` syntax; [Falkenberg et al., 2017](https://cabledyn.readthedocs.io/en/latest/references.html#ref-falkenberg2017)) | Pass verified | MoorDyn-F/C `BA_s|BA_d` rate and force equations; analytic position/velocity tangents with finite-difference checks; projected, bracketed backward-Euler slow-state update with a strong-unloading boundary test; OWC running maximum; `SYROPE IC` `Tmax0/Tmean0` history with range/order checks; both states carried through every lifecycle stage and the coupled checkpoint. `BA_s` is kept separate from line axial damping (`BA`) and tested against double counting. Composite, hydrodynamic, finite-EI, current, and wave combinations stop with a named error | -| VIV (`compVIV`) | Not supported | outside CableDyn's scope | +| Cross-flow VIV (LINE TYPES `Cl`) | Pass verified | `EI = 0` lines and finite-EI cables on the aggregate with the host's fluid field: an `EI = 0` riser and a cable (EI 1 N m²) in a 0.15 m/s host current lock in at A/D 0.6645 / 0.6646 and 0.292 Hz (MoorDyn-F 0.662 at 0.293 Hz; standalone 0.665); the phases, running mean squares and averaging time ride in the checkpoint state and the correction rewind: a rebuild from the checkpoint continues bit for bit, one without the VIV reload does not (`viv_coupled`). OpenFAST (IEA-15 UMaine mixed deck, `Cl` 0.8 on the lazy-wave cable, SeaState 0.5 m/s current, 60 s): `openfast -restart` at 30 s reproduces every later CableDyn and OpenFAST output row bit for bit | **Standalone mixed aggregate.** `CableDyn_driver.exe` partitions and steps the same aggregate used by OpenFAST. The IEA-15 three-chain + touchdown-cable deck diff --git a/doc/theory.rst b/doc/theory.rst index 8cf279c6..11c57108 100644 --- a/doc/theory.rst +++ b/doc/theory.rst @@ -746,7 +746,10 @@ along :math:`\mathbf{e} = \mathbf{q}\times\mathbf{v}_n/U`: so the shedding frequency locks onto the cross-flow motion inside the band :math:`c_F \pm d_F` (MoorDyn's defaults 0.18 and 0.08). The running RMS values average over ``VIVrmsWindow`` seconds, by default 500 steps of ``dtM`` as in MoorDyn, and the phases start at -:math:`2\pi i/N` along the line from End A. The static equilibrium carries no lift. +:math:`2\pi i/N` at node :math:`i` counted from the deck's End A (MoorDyn's ``AttachA``), also on +a line written anchor first, which the reader turns around. On a finite-EI mesh the static solve +refined, the deck nodes keep that seed and the nodes it added take the seed interpolated in +arc length. The static equilibrium carries no lift. In the implicit step the phase is explicit: the step's lift takes the phase predicted at :math:`t_{n+1}` from the step-start rate (the generalised-α level under the configuration blend), diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index e07937c8..a60b4dc4 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -193,6 +193,7 @@ MODULE CableDyn_DeckDriver PUBLIC :: CD_Init_Deck_Models PUBLIC :: CD_Init_Deck_System PUBLIC :: CD_Init_Deck_HermiteCable + PUBLIC :: CD_Deck_VIV_Phase_Seed PUBLIC :: CD_Stiffener_Overlay PUBLIC :: CD_Init_Deck_Aggregate PUBLIC :: CD_Deck_Query_dtM @@ -3189,10 +3190,27 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, ! coupled host may step the cable at a dt adjusted from the deck dtM. IF (PRESENT(install_viv)) THEN IF (install_viv .AND. ANY(viv_cl > CD_ZERO)) THEN - CALL CD_HermiteCable_Dyn_Set_VIV(cable%line, viv_cl, viv_cf, viv_df, & - MERGE(opts%viv_rms_window, & - REAL(CD_VIV_NM, wp)*MERGE(opts%dtM, dt, opts%has_dtm), & - opts%viv_rms_window > CD_ZERO), es, em) + ! MoorDyn's phase seed counts the deck nodes from the deck's End A: a line the reader turned + ! around, or a mesh the static solve refined, takes it node by node (CD_Deck_VIV_Phase_Seed) + IF (ln%ends_swapped .OR. ALLOCATED(cable%deck_node)) THEN + BLOCK + REAL(wp) :: seed(cable%line%nn) + IF (ALLOCATED(cable%deck_node)) THEN + CALL CD_Deck_VIV_Phase_Seed(cable%line%l0, ln%ends_swapped, seed, deck_map=cable%deck_node) + ELSE + CALL CD_Deck_VIV_Phase_Seed(cable%line%l0, ln%ends_swapped, seed) + END IF + CALL CD_HermiteCable_Dyn_Set_VIV(cable%line, viv_cl, viv_cf, viv_df, & + MERGE(opts%viv_rms_window, & + REAL(CD_VIV_NM, wp)*MERGE(opts%dtM, dt, opts%has_dtm), & + opts%viv_rms_window > CD_ZERO), es, em, phase_seed=seed) + END BLOCK + ELSE + CALL CD_HermiteCable_Dyn_Set_VIV(cable%line, viv_cl, viv_cf, viv_df, & + MERGE(opts%viv_rms_window, & + REAL(CD_VIV_NM, wp)*MERGE(opts%dtM, dt, opts%has_dtm), & + opts%viv_rms_window > CD_ZERO), es, em) + END IF IF (es /= CD_HCDYN_OK) THEN CALL fail(ErrStat, ErrMsg, 'finite-EI cable VIV wiring failed: '//TRIM(em)); RETURN END IF @@ -9043,7 +9061,17 @@ SUBROUTINE init_one_model(ln, sections, types, points, opts, model, ErrStat, Err END IF tw = opts%viv_rms_window IF (.NOT. (tw > CD_ZERO) .AND. opts%has_dtm) tw = REAL(CD_VIV_NM, wp)*opts%dtM - CALL CD_Set_Model_VIV(model, opts%rhoW, viv_cl, hydro_diam, viv_cf, viv_df, tw, es, em) + IF (ln%ends_swapped) THEN + ! MoorDyn counts the phase seed from the deck's End A, which the reader turned around + BLOCK + REAL(wp) :: seed(model%n_dof/3) + CALL CD_Deck_VIV_Phase_Seed(model%l0, .TRUE., seed) + CALL CD_Set_Model_VIV(model, opts%rhoW, viv_cl, hydro_diam, viv_cf, viv_df, tw, es, em, & + phase_seed=seed) + END BLOCK + ELSE + CALL CD_Set_Model_VIV(model, opts%rhoW, viv_cl, hydro_diam, viv_cf, viv_df, tw, es, em) + END IF IF (es == CD_MODEL_OK) CALL CD_Recompute_Model_Acceleration(model, es, em) IF (es /= CD_MODEL_OK) THEN ErrStat = CD_DECKDRV_BADINPUT @@ -34966,6 +34994,45 @@ PURE FUNCTION cable_frame_is_identity(cable) RESULT(is_id) is_id = .NOT. (ABS(cable%frame_s) > CD_ZERO .OR. ABS(cable%frame_c - CD_ONE) > CD_ZERO) END FUNCTION cable_frame_is_identity + PURE SUBROUTINE CD_Deck_VIV_Phase_Seed(l0, swapped, seed, deck_map) + !! MoorDyn's VIV phase seed i/N (phase 2 pi i/N at node i = 0 .. N counted from the deck's + !! End A, N the deck's segment count) at every node of a line, in the model's internal node + !! order (node 1 = End B; element e of length l0(e) joins nodes e and e + 1). swapped: the + !! reader turned the line's ends around, so the deck's End A is the model's End B. deck_map: + !! the mesh node (public order, End A = 1) of each deck node, on a mesh the static solve + !! refined; a node it added takes the seed interpolated linearly in unstretched arc length + !! between its two deck nodes. Without deck_map the mesh is the deck's. + REAL(wp), INTENT(IN) :: l0(:) + LOGICAL, INTENT(IN) :: swapped + REAL(wp), INTENT(OUT) :: seed(:) + INTEGER, INTENT(IN), OPTIONAL :: deck_map(:) + REAL(wp) :: s(SIZE(l0) + 1), f + INTEGER :: ne, nn, p, j, nd + ne = SIZE(l0) + nn = ne + 1 + ! unstretched arc length from End A at public node p (internal element ne + 1 - p follows it) + s(1) = CD_ZERO + DO p = 1, ne + s(p + 1) = s(p) + l0(ne + 1 - p) + END DO + DO p = 1, nn + IF (PRESENT(deck_map)) THEN + nd = SIZE(deck_map) - 1 + f = CD_ONE + DO j = 1, nd + IF (p >= deck_map(j) .AND. p <= deck_map(j + 1)) THEN + f = (REAL(j - 1, wp) + (s(p) - s(deck_map(j)))/(s(deck_map(j + 1)) - s(deck_map(j))))/REAL(nd, wp) + EXIT + END IF + END DO + ELSE + f = REAL(p - 1, wp)/REAL(ne, wp) + END IF + IF (swapped) f = CD_ONE - f + seed(nn + 1 - p) = f + END DO + END SUBROUTINE CD_Deck_VIV_Phase_Seed + PURE INTEGER FUNCTION CD_Cable_Deck_Node(cable, node) RESULT(deck_node) !! The deck node at public node `node` (End A = 1) of a finite-EI cable's final mesh: the !! node itself when the mesh is the deck mesh, 0 for a node the refinement added (the diff --git a/src/CableDyn_HermiteCableDynamic.f90 b/src/CableDyn_HermiteCableDynamic.f90 index 89d7fb44..b303cb3d 100644 --- a/src/CableDyn_HermiteCableDynamic.f90 +++ b/src/CableDyn_HermiteCableDynamic.f90 @@ -966,13 +966,15 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Friction_Axial(model, mu_axial, ErrStat, ErrM model%tr_valid = .FALSE. END SUBROUTINE CD_HermiteCable_Dyn_Set_Friction_Axial - SUBROUTINE CD_HermiteCable_Dyn_Set_VIV(model, cl, cf, df, t_window, ErrStat, ErrMsg) + SUBROUTINE CD_HermiteCable_Dyn_Set_VIV(model, cl, cf, df, t_window, ErrStat, ErrMsg, phase_seed) !! Install the cross-flow VIV synchronisation model (CableDyn_VIV) on a cable with drag: !! per element the lift coefficient cl (0: no lift) and the band df/cf, and the running-RMS !! averaging time t_window (s; 0 takes 500 steps of the first step). The lift acts on the !! wetted Gauss points of every element with cl > 0, its phase lives on the nodes of those !! elements; the phases start at 2 pi i/N with node i counted from End A (the model's last - !! node), as MoorDyn's. The phase follows the drag's current and a held host field (which + !! node), as MoorDyn's; phase_seed, per node, gives i/N instead (a line whose deck End A the + !! reader turned around, or a mesh refined from the deck's). The phase follows the drag's + !! current and a held host field (which !! carries any waves); the internal wave families (Set_Waves) are refused with VIV. The !! committed acceleration is refreshed with the new lift; if that fails, the previous VIV !! configuration, its state and the acceleration are restored. @@ -980,6 +982,7 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_VIV(model, cl, cf, df, t_window, ErrStat, Err REAL(wp), INTENT(IN) :: cl(:), cf(:), df(:), t_window INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), INTENT(IN), OPTIONAL :: phase_seed(:) INTEGER :: e, k, ne, nn, es REAL(wp) :: wsum, tw_old LOGICAL :: had_viv @@ -1013,6 +1016,12 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_VIV(model, cl, cf, df, t_window, ErrStat, Err ErrStat = CD_HCDYN_BADINPUT ErrMsg = 'CD_HermiteCable_Dyn_Set_VIV: VIV needs the cable''s drag in water (set the drag first)'; RETURN END IF + IF (PRESENT(phase_seed)) THEN + IF (SIZE(phase_seed) /= nn .OR. .NOT. CD_All_Finite(phase_seed)) THEN + ErrStat = CD_HCDYN_BADINPUT + ErrMsg = 'CD_HermiteCable_Dyn_Set_VIV: the phase seed must be finite with one value per node'; RETURN + END IF + END IF IF (model%has_wave) THEN ErrStat = CD_HCDYN_BADINPUT ErrMsg = 'CD_HermiteCable_Dyn_Set_VIV: internal waves are configured; VIV takes waves as a held '// & @@ -1057,6 +1066,7 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_VIV(model, cl, cf, df, t_window, ErrStat, Err model%viv_cf(k) = model%viv_cf(k)/wsum model%viv_df(k) = model%viv_df(k)/wsum model%viv_phi(k) = CD_VIV_TWO_PI*REAL(nn - k, wp)/REAL(ne, wp) + IF (PRESENT(phase_seed)) model%viv_phi(k) = CD_VIV_TWO_PI*phase_seed(k) END DO CALL viv_drag_terms(model) model%viv_phi_eval = model%viv_phi diff --git a/src/CableDyn_Model.f90 b/src/CableDyn_Model.f90 index b7f1d3ae..3c864f75 100644 --- a/src/CableDyn_Model.f90 +++ b/src/CableDyn_Model.f90 @@ -3861,14 +3861,16 @@ SUBROUTINE CD_Set_Model_Syrope_State(model, slow, tmax, ErrStat, ErrMsg) model%recovery_syrope_tmax = tmax END SUBROUTINE CD_Set_Model_Syrope_State - SUBROUTINE CD_Set_Model_VIV(model, rho, cl, diameter, cf, df, t_window, ErrStat, ErrMsg) + SUBROUTINE CD_Set_Model_VIV(model, rho, cl, diameter, cf, df, t_window, ErrStat, ErrMsg, phase_seed) !! Install the cross-flow VIV model (CableDyn_VIV) on an initialised line. Per element: !! the lift coefficient cl (0 = no lift on that element), hydrodynamic diameter, and the !! synchronisation centre cf and half-range df of the non-dimensional shedding frequency; !! rho is the water density. t_window is the averaging time of the running cross-flow mean !! squares [s]; 0 selects MoorDyn's 500 time steps, latched at the first step. Every !! interior free node next to a cl > 0 element carries a lift and a shedding phase; the - !! phases start spread over [0, 2 pi) along the line (MoorDyn-C), the mean squares at 0. + !! phases start spread over [0, 2 pi) along the line (MoorDyn-C: 2 pi i/N at node i from + !! End A; phase_seed, per node, gives i/N instead, for a line whose deck End A the reader + !! turned around), the mean squares at 0. !! An all-zero cl leaves the model without VIV. The mesh must be the single chain the !! line builder makes (element e joins nodes e and e+1). The caller recomputes the !! acceleration if the lift should enter the initial state (CD_Recompute_Model_Acceleration). @@ -3876,6 +3878,7 @@ SUBROUTINE CD_Set_Model_VIV(model, rho, cl, diameter, cf, df, t_window, ErrStat, REAL(wp), INTENT(IN) :: rho, cl(:), diameter(:), cf(:), df(:), t_window INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), INTENT(IN), OPTIONAL :: phase_seed(:) INTEGER :: n_nodes, n_elem, e, nd, istat, k REAL(wp) :: wsum @@ -3905,6 +3908,12 @@ SUBROUTINE CD_Set_Model_VIV(model, rho, cl, diameter, cf, df, t_window, ErrStat, CALL fail(ErrStat, ErrMsg, 'VIV averaging time must be finite and non-negative') RETURN END IF + IF (PRESENT(phase_seed)) THEN + IF (SIZE(phase_seed) /= n_nodes .OR. .NOT. CD_All_Finite(phase_seed)) THEN + CALL fail(ErrStat, ErrMsg, 'VIV phase seed must be finite with shape (n_nodes)') + RETURN + END IF + END IF CALL clear_viv(model) IF (.NOT. ANY(cl > CD_ZERO)) RETURN IF (.NOT. (CD_Is_Finite(rho) .AND. rho > CD_ZERO)) THEN @@ -3968,6 +3977,7 @@ SUBROUTINE CD_Set_Model_VIV(model, rho, cl, diameter, cf, df, t_window, ErrStat, ! MoorDyn: phi_i = 2 pi i/N at node i = 0..N counted from End A; the model numbers its ! nodes from End B, so node nd is MoorDyn's node n_nodes - nd model%viv_phi(nd) = CD_VIV_TWO_PI*REAL(n_nodes - nd, wp)/REAL(n_elem, wp) + IF (PRESENT(phase_seed)) model%viv_phi(nd) = CD_VIV_TWO_PI*phase_seed(nd) END DO model%viv_phi_rollback = model%viv_phi model%viv_ms_rollback = model%viv_ms diff --git a/tests/test_viv_coupled.f90 b/tests/test_viv_coupled.f90 index 99fc075e..9272a1bd 100644 --- a/tests/test_viv_coupled.f90 +++ b/tests/test_viv_coupled.f90 @@ -20,7 +20,10 @@ PROGRAM test_viv_coupled !! lands on the same state, phases included, bit for bit; !! * averaging window: without VIVrmsWindow both line kinds average over MoorDyn's 500 steps !! of the deck dtM, also when the coupling step differs from it (dtM 0.001 s at a 0.01 s - !! step: 0.5 s), and over 500 coupling steps when the deck has no dtM (5 s). + !! step: 0.5 s), and over 500 coupling steps when the deck has no dtM (5 s); + !! * phase seed: MoorDyn's 2 pi i/N with node i counted from the deck's End A, also on a deck + !! written anchor first (which the reader turns around) and, through CD_Deck_VIV_Phase_Seed, + !! at the deck nodes of a refined mesh (added nodes interpolated in arc length). USE CableDyn_Precision, ONLY: wp USE CableDyn_OpenFAST_Aggregate, ONLY: CD_AGG_ModuleType, CD_AGG_Init_From_Deck, CD_AGG_End, CD_AGG_OK, & CD_AGG_NMovingPoints, CD_AGG_GetMovingPointMesh, CD_AGG_Step_Moving, & @@ -28,6 +31,7 @@ PROGRAM test_viv_coupled CD_AGG_SetFluidFields, CD_AGG_Snapshot, CD_AGG_Restore USE CableDyn_OpenFAST_HermiteFMF, ONLY: CD_HFMF_MirrorSize, CD_HFMF_VIVMirrorSize, CD_HFMF_PackMirror, & CD_HFMF_UnpackMirror, CD_HFMF_OK + USE CableDyn_DeckDriver, ONLY: CD_Deck_VIV_Phase_Seed USE CableDyn_System, ONLY: CD_System_NLines, CD_System_Line_NDOF, CD_Get_System_Line_State, & CD_Update_System_Line_Interior_State, CD_System_Line_VIV_MirrorSize, & CD_Get_System_Line_VIV_State, CD_Set_System_Line_VIV_State, CD_SYSTEM_OK @@ -45,6 +49,7 @@ PROGRAM test_viv_coupled CALL case_restart() CALL case_rewind() CALL case_window() + CALL case_seed() IF (nfail > 0) THEN WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' coupled VIV check(s) failed' ERROR STOP 1 @@ -162,6 +167,45 @@ SUBROUTINE case_window() END DO END SUBROUTINE case_window + SUBROUTINE case_seed() + !! MoorDyn's phase seed on a refined mesh and on an anchor-first deck. + REAL(wp), PARAMETER :: TWO_PI = 8.0_wp*ATAN(1.0_wp) + TYPE(CD_AGG_ModuleType) :: agg + REAL(wp) :: seed(5), want(5), worst_line, worst_cable + INTEGER :: k, pass, nn + ! four mesh elements (internal order, End B first) over two deck segments: deck nodes at public + ! nodes 1, 3 and 5, so public node 4 lies 3/4 of the way along the second deck segment + CALL CD_Deck_VIV_Phase_Seed([1.0_wp, 3.0_wp, 2.0_wp, 2.0_wp], .FALSE., seed, deck_map=[1, 3, 5]) + want = [1.0_wp, 0.875_wp, 0.5_wp, 0.25_wp, 0.0_wp] + CALL check(MAXVAL(ABS(seed - want)) < 1.0e-14_wp, 'refined mesh: deck nodes keep i/N, added nodes interpolate') + CALL CD_Deck_VIV_Phase_Seed([1.0_wp, 3.0_wp, 2.0_wp, 2.0_wp], .TRUE., seed, deck_map=[1, 3, 5]) + CALL check(MAXVAL(ABS(seed - (1.0_wp - want))) < 1.0e-14_wp, 'a turned-around line counts from its End B') + CALL CD_Deck_VIV_Phase_Seed([1.0_wp, 3.0_wp, 2.0_wp, 2.0_wp], .FALSE., seed) + CALL check(MAXVAL(ABS(seed - [4.0_wp, 3.0_wp, 2.0_wp, 1.0_wp, 0.0_wp]/4.0_wp)) < 1.0e-14_wp, & + 'the deck mesh keeps the node index') + CALL write_deck('viv_coupled_stock.dat', 0.8_wp, anchor_first=.TRUE.) + DO pass = 1, 2 + IF (.NOT. start(agg, MERGE('viv_coupled.dat ', 'viv_coupled_stock.dat', pass == 1))) RETURN + nn = SIZE(agg%sys%fast%system%lines(1)%viv_phi) + worst_line = 0.0_wp + worst_cable = 0.0_wp + DO k = 2, nn - 1 + ! internal node k (k = 1 at the anchor); MoorDyn's node from the deck's End A + IF (pass == 1) THEN + worst_line = MAX(worst_line, ABS(agg%sys%fast%system%lines(1)%viv_phi(k) - TWO_PI*REAL(nn - k, wp)/50.0_wp)) + worst_cable = MAX(worst_cable, ABS(agg%cables(1)%line%viv_phi(k) - TWO_PI*REAL(nn - k, wp)/50.0_wp)) + ELSE + worst_line = MAX(worst_line, ABS(agg%sys%fast%system%lines(1)%viv_phi(k) - TWO_PI*REAL(k - 1, wp)/50.0_wp)) + worst_cable = MAX(worst_cable, ABS(agg%cables(1)%line%viv_phi(k) - TWO_PI*REAL(k - 1, wp)/50.0_wp)) + END IF + END DO + CALL check(worst_line < 1.0e-12_wp .AND. worst_cable < 1.0e-12_wp, & + MERGE('fairlead-first deck: the seed counts from the fairlead', & + 'anchor-first deck: the seed counts from the anchor ', pass == 1)) + CALL finish(agg) + END DO + END SUBROUTINE case_seed + LOGICAL FUNCTION start(agg, path) RESULT(ok) !! A host-fluid build of the deck at dt. TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: agg @@ -291,13 +335,15 @@ SUBROUTINE response(z, ad, f) IF (n > 1) f = REAL(n - 1, wp)/(t1 - t0) END SUBROUTINE response - SUBROUTINE write_deck(path, cl, window, dtm) + SUBROUTINE write_deck(path, cl, window, dtm, anchor_first) !! The EI = 0 riser (line 1) and the finite-EI cable (line 2), 20 m apart across the current; !! VIVrmsWindow 0.25 s unless window is given (0: none), and a deck dtM when dtm is given. CHARACTER(*), INTENT(IN) :: path REAL(wp), INTENT(IN) :: cl REAL(wp), INTENT(IN), OPTIONAL :: window, dtm + LOGICAL, INTENT(IN), OPTIONAL :: anchor_first INTEGER :: u + LOGICAL :: stock REAL(wp) :: tw CHARACTER(32) :: len_txt, cl_txt WRITE (len_txt, '(F12.6)') 100.0_wp/(1.0_wp + 5.0e4_wp/5.0e7_wp) @@ -320,8 +366,16 @@ SUBROUTINE write_deck(path, cl, window, dtm) WRITE (u, '(A)') '--------------------- LINES ---' WRITE (u, '(A)') 'ID LineType AttachA AttachB UnstrLen NumSegs Outputs' WRITE (u, '(A)') '(#) (name) (#) (#) (m) (-) (-)' - WRITE (u, '(A)') '1 riser 1 2 '//TRIM(ADJUSTL(len_txt))//' 50 -' - WRITE (u, '(A)') '2 cable 3 4 '//TRIM(ADJUSTL(len_txt))//' 50 -' + stock = .FALSE. + IF (PRESENT(anchor_first)) stock = anchor_first + IF (stock) THEN + ! MoorDyn's common row order, AttachA the anchor: the reader turns the lines around + WRITE (u, '(A)') '1 riser 2 1 '//TRIM(ADJUSTL(len_txt))//' 50 -' + WRITE (u, '(A)') '2 cable 4 3 '//TRIM(ADJUSTL(len_txt))//' 50 -' + ELSE + WRITE (u, '(A)') '1 riser 1 2 '//TRIM(ADJUSTL(len_txt))//' 50 -' + WRITE (u, '(A)') '2 cable 3 4 '//TRIM(ADJUSTL(len_txt))//' 50 -' + END IF WRITE (u, '(A)') '--------------------- OPTIONS ---' WRITE (u, '(A)') '100.0 WtrDpth' WRITE (u, '(A)') '1025.0 rhoW' diff --git a/tests/test_viv_riser.py b/tests/test_viv_riser.py new file mode 100644 index 00000000..0c10f071 --- /dev/null +++ b/tests/test_viv_riser.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +"""Cross-flow VIV of the catenary riser of Thorsen et al., MoorDyn-C's VIV test case. + +MoorDyn-C (tests/Mooring/viv/viv.txt): a 23.71 m riser model (D 0.024 m, 0.69 kg/m, EA 6.66e5 N, +EI 10.5 N m^2, 100 segments) from the seabed at 10 m depth to 1 m below the surface, in a uniform +0.2 m/s current in its plane, Cl 0.7 with MoorDyn's band. The cross-flow response, out of the +plane, locks in at the measured 1.04 Hz, so the fairlead tension oscillates at twice that: a +period of 1/(2 x 1.04 Hz) = 0.4808 s. The deck is written anchor first, as MoorDyn's, so it also +exercises the phase seed counted from the deck's End A on a line the reader turns around. + +MoorDyn-C v2.7.2 (RK4, dtM 1e-4 s) over 20-40 s: mean fairlead tension 69.93 N, peak-to-peak +3.72 N, period 0.4811 s. Gates on CableDyn at dtM 1e-3 s over the same window: + +* mean tension within 0.2 % of MoorDyn-C's; +* tension range (peak to peak) within 10 % of MoorDyn-C's; +* mean period within 1.5 % of the measured target and of MoorDyn-C's (the period converges to + MoorDyn-C's with dtM: 0.4853, 0.4843, 0.4829 s at 1e-3, 5e-4, 2.5e-4 s). + +usage: test_viv_riser.py --exe --output +""" + +from __future__ import annotations + +import argparse +import os +import shutil +import subprocess +import sys +from pathlib import Path + +import numpy as np + +TARGET = 1.0 / (2.0 * 1.04) +MDC_MEAN, MDC_RANGE, MDC_PERIOD = 69.93, 3.72, 0.4811 +FAILURES: list[str] = [] + +DECK = """--------------------- CableDyn Input File --- +Thorsen et al. catenary riser in a uniform 0.2 m/s current (MoorDyn-C tests/Mooring/viv/viv.txt) +--------------------- LINE TYPES --- +LineType Diam MassDenInAir EA cIntDamp EI Cd Ca CdAx CaAx Cl +(-) (m) (kg/m) (N) (Pa-s) (N-m^2) (-) (-) (-) (-) (-) +cable 0.024 0.69 6.66e5 -1 10.5 1.2 2.0 0.08 0.08 0.7 +--------------------- POINTS --- +Node Type X Y Z M V CdA Ca +(-) (-) (m) (m) (m) (kg) (m^3) (m2) () +1 Fixed -21.0425 0 -10 0 0 0 0 +2 Coupled 0 0 -1 0 0 0 0 +--------------------- LINES --- +Line LineType NodeA NodeB UnstrLen NumSegs Outputs +(-) (-) (-) (-) (m) (-) (-) +1 cable 1 2 23.71 100 - +--------------------- OPTIONS --- +1000.0 rhoW +9.80665 g +10.0 WtrDpth +1.5e5 kBot +1.0e4 cBot +0.5 frictionMu +uniform 0.2 0 0 current +0.001 dtM +40.0 TMax +--------------------- OUTPUTS --- +FairTen1 +END +--------------------- need this line --- +""" + + +def check(ok: bool, message: str) -> None: + print(("PASS: " if ok else "FAIL: ") + message) + if not ok: + FAILURES.append(message) + + +def main() -> int: + ap = argparse.ArgumentParser() + ap.add_argument("--exe", required=True) + ap.add_argument("--output", required=True) + args = ap.parse_args() + out = Path(args.output) + if out.exists(): + shutil.rmtree(out) + out.mkdir(parents=True) + (out / "riser.dat").write_text(DECK, encoding="utf-8", newline="\n") + proc = subprocess.run([args.exe, "riser.dat", "riser"], cwd=out, capture_output=True, text=True, + env=dict(os.environ, OMP_NUM_THREADS="1")) + check(proc.returncode == 0, f"the riser run completes (exit {proc.returncode})") + if proc.returncode != 0: + print(proc.stdout[-2000:], proc.stderr[-2000:]) + return 1 + lines = (out / "riser.out").read_text().splitlines() + head = next(i for i, line in enumerate(lines) if line.split() and line.split()[0].startswith("Time")) + data = np.array([[float(v) for v in line.split()] for line in lines[head + 1:] + if line.strip() and not line.lstrip().startswith("(")]) + t, ten = data[:, 0], data[:, lines[head].split().index("FairTen1")] + w = (t > 20.0) & (t <= 40.0) + tt, x = t[w], ten[w] - ten[w].mean() + peaks = [i for i in range(1, len(x) - 1) if x[i] > x[i - 1] and x[i] >= x[i + 1] and x[i] > 0.0] + period = float(np.mean(np.diff(tt[peaks]))) + mean, span = float(ten[w].mean()), float(np.ptp(ten[w])) + check(abs(mean - MDC_MEAN) <= 0.002 * MDC_MEAN, + f"mean fairlead tension {mean:.2f} N, MoorDyn-C {MDC_MEAN} N (within 0.2 %)") + check(abs(span - MDC_RANGE) <= 0.10 * MDC_RANGE, + f"tension range {span:.2f} N, MoorDyn-C {MDC_RANGE} N (within 10 %)") + check(abs(period - TARGET) <= 0.015 * TARGET and abs(period - MDC_PERIOD) <= 0.015 * MDC_PERIOD, + f"tension period {period:.4f} s: measured 1/(2 x 1.04 Hz) = {TARGET:.4f} s, MoorDyn-C " + f"{MDC_PERIOD} s (within 1.5 %)") + print(f"{len(FAILURES)} failure(s)") + return 1 if FAILURES else 0 + + +if __name__ == "__main__": + sys.exit(main())