diff --git a/CHANGELOG.md b/CHANGELOG.md index 678d4d7e..1093a611 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,8 +15,7 @@ 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. The coupled and mixed - routes refuse `Cl > 0` by name. + 5e-4 to 1e-2 s. 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 @@ -24,6 +23,12 @@ All notable changes to CableDyn are recorded in this file. The format follows 5e-4 to 1e-2 s without smoothing; a bending-stiff line matches the string of equal first-mode frequency in mode-1 lock-in and stays in mode 1 where that string jumps to mode 2. A finite-EI line with two moving ends, or beside bodies, rods or free points, refuses `Cl > 0`. +- Cross-flow VIV on the coupled routes: OpenFAST (`CompMooring = 5`), FAST.Farm and the + standalone runner of a mixed `EI = 0` / finite-EI deck carry the lift on both line kinds, with + the host's fluid field. The phases, running mean squares and averaging time are part of the + checkpoint state and of the correction rewind, so a restart continues bit for bit. A riser and + a cable in a 0.15 m/s host current lock in at A/D 0.665 and 0.292 Hz, MoorDyn-F's 0.662 and + 0.293 Hz. - Bend stiffeners (`STIFFENERS` table): a tapered polyurethane sleeve over an end of a finite-EI line, given as conical segments from the root outward (outer diameters, bore, modulus, density). Each element it covers takes the compliance average of the cable-plus-sleeve diff --git a/CMakeLists.txt b/CMakeLists.txt index db960784..58831b66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1180,6 +1180,11 @@ target_link_libraries(test_hermite_viv PRIVATE cabledyn_core) add_test(NAME hermite_viv COMMAND test_hermite_viv) set_tests_properties(hermite_viv PROPERTIES LABELS "fortran;dynamic;viv") +add_executable(test_viv_coupled tests/test_viv_coupled.f90) +target_link_libraries(test_viv_coupled PRIVATE cabledyn_core) +add_test(NAME viv_coupled COMMAND test_viv_coupled WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) +set_tests_properties(viv_coupled PROPERTIES LABELS "fortran;integration;dynamic;viv;openfast") + add_executable(test_hfmf_mirror tests/test_hfmf_mirror.f90) target_link_libraries(test_hfmf_mirror PRIVATE cabledyn_core) add_test(NAME hfmf_mirror COMMAND test_hfmf_mirror WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) diff --git a/doc/capabilities.rst b/doc/capabilities.rst index 68335dcb..c59c3e9c 100644 --- a/doc/capabilities.rst +++ b/doc/capabilities.rst @@ -114,12 +114,12 @@ Line and constitutive capability ``EI = 0`` lines, or all finite-EI lines on the Hermite route; flat seabed); a deck with torsion is rejected * - Cross-flow VIV (LINE TYPES ``Cl``, ``dF``, ``cF``) - - Standalone only + - Standalone and coupled - MoorDyn v2's synchronisation model on ``EI = 0`` lines and, as a distributed lift, on - finite-EI cables of the Hermite march (:ref:`theory-viv`); in-line VIV is not provided; - the coupled OpenFAST and FAST.Farm routes, mixed ``EI = 0`` / finite-EI decks, finite-EI - lines with two moving ends and finite-EI lines beside bodies, rods or free points refuse - ``Cl > 0`` by name + finite-EI cables of the Hermite march (:ref:`theory-viv`), with the host's fluid field + on the coupled routes and its state in the checkpoint; in-line VIV is not provided; + finite-EI lines with two moving ends and finite-EI lines beside bodies, rods or free + points refuse ``Cl > 0`` by name Loads and environment --------------------- diff --git a/doc/coupling.rst b/doc/coupling.rst index 8ec85665..f1184768 100644 --- a/doc/coupling.rst +++ b/doc/coupling.rst @@ -56,8 +56,7 @@ solve is mathematically incorrect; changing ``NumCrctn`` does not change that de - deck ``waves``/``wavetrain`` OPTIONS (the host SeaState supplies the waves), and a deck ``current`` except as a steady current on a single-turbine, pure ``EI = 0`` deck without Rigid6 bodies or rods in a SeaState without waves or current (a WaterKin ``CurrentMod 1`` - table remains available), - - cross-flow VIV (a LINE TYPES ``Cl > 0``), which runs in the standalone driver only, and + table remains available), and - fluid-source combinations that the nodewise SeaState field cannot separate without double counting. diff --git a/doc/migrating.rst b/doc/migrating.rst index ba7cf3f1..b14d72fb 100644 --- a/doc/migrating.rst +++ b/doc/migrating.rst @@ -93,7 +93,7 @@ Keyword map - same row; the native order is ``Cd_n Cd_t Ca_n Ca_t`` and the header decides which is meant. ``EI > 0`` switches the line to the bending element. * - ``LINE TYPES`` VIV columns ``Cl`` or ``Cl dF cF`` - - same columns and the same synchronisation model in the standalone driver, on ``EI = 0`` + - same columns and the same synchronisation model, standalone and coupled, on ``EI = 0`` types and as a distributed lift on finite-EI types (:ref:`theory-viv`); the running-RMS window is ``VIVrmsWindow`` seconds, by default 500 steps of ``dtM`` as MoorDyn's diff --git a/doc/options.rst b/doc/options.rst index 7acce5e1..0783b8a3 100644 --- a/doc/options.rst +++ b/doc/options.rst @@ -681,10 +681,10 @@ Ambient fluid and prescribed motion - ``0`` - finite, ≥ 0; the averaging time of the running RMS cross-flow velocity and acceleration of the VIV synchronisation model (:ref:`theory-viv`). ``0`` takes MoorDyn's 500 steps of - ``dtM`` (of the first step when the deck has no ``dtM``); set it to compare runs at + the deck ``dtM``, also where OpenFAST steps CableDyn at a ``dtM`` adjusted to its ``DT`` + (500 steps of the first step when the deck has no ``dtM``); set it to compare runs at different ``dtM`` with the same averaging time - - standalone lines (``EI = 0``, or finite-EI on the Hermite march) with a LINE TYPES - ``Cl > 0`` + - lines with a LINE TYPES ``Cl > 0``, on every route - ``0.25 VIVrmsWindow`` * - ``motionFile`` - path, or ``0``/``none`` diff --git a/doc/theory.rst b/doc/theory.rst index 215a53f8..3e6d8682 100644 --- a/doc/theory.rst +++ b/doc/theory.rst @@ -779,8 +779,12 @@ pump, and the response is the same from ``dtM`` 5e-4 to 1e-2 s. A finite-EI line carries it, including deck waves and current through its held fluid field; a finite-EI line with two moving ends, or beside bodies, rods or free points, refuses :math:`C_L > 0`. -VIV runs in the standalone driver; the coupled and mixed aggregate routes refuse a deck with -:math:`C_L > 0`. +VIV runs on every route that carries the line: the standalone driver, the coupled OpenFAST +and FAST.Farm routes and the standalone runner of a mixed ``EI = 0`` / finite-EI deck. On the +coupled routes the phase follows the host's fluid field (a SeaState current or waves), and the +phases, the running mean squares and the averaging time are part of the checkpoint state, so a +restart continues the uninterrupted run bit for bit. The OpenFAST correction iterations rewind +them with the rest of the state. Buoyancy and wetting ~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/troubleshooting.rst b/doc/troubleshooting.rst index 9fe01b00..330469fa 100644 --- a/doc/troubleshooting.rst +++ b/doc/troubleshooting.rst @@ -847,10 +847,6 @@ aborts with a CableDyn fatal error, check whether the deck uses one of these com - linearise a pinned-hang-off, uncontrolled variant of the deck; time-domain runs support both * - a ``Rigid`` end-connection direction reversed by exactly 180 degrees in one host update - drive the platform through intermediate orientations - * - VIV on the coupled or mixed route (``VIV (LINE TYPES Cl > 0) runs in the standalone driver - of an EI = 0 or finite-EI deck``) - - run the VIV study on a standalone ``EI = 0`` or finite-EI deck, or set ``Cl = 0`` for the - coupled run * - VIV on a finite-EI line with two moving ends (``needs its End B fixed``) or beside bodies, rods or free points (``does not run with bodies, rods or free points yet``) - fix End B of the line, or set ``Cl = 0`` for its line type diff --git a/python/cabledyn/deck_file.py b/python/cabledyn/deck_file.py index a3d1fe0d..7150a6a4 100644 --- a/python/cabledyn/deck_file.py +++ b/python/cabledyn/deck_file.py @@ -2611,9 +2611,8 @@ def numeric(token: str, row: DeckRecord, field: str) -> float: line_type_scales: dict[str, tuple[float, float]] = {} # name -> (BA, max Cd/Ca) line_type_meta: dict[str, tuple[float, float, float, float]] = {} line_type_gj: dict[str, float] = {} # name -> explicit GJ of a 14-column row, else 0 - # Cl > 0 on any LINE TYPES row (native CD_Init_Deck_Aggregate), and on an EI = 0 row - # (native init_one_model, which needs the line's Morison drag in water) - has_viv = False + # Cl > 0 on an EI = 0 row (native init_one_model, which needs the line's Morison drag in + # water) has_viv_ei0 = False viv_type_names: set[str] = set() for row in self.line_types: @@ -2703,7 +2702,6 @@ def numeric(token: str, row: DeckRecord, field: str) -> float: f"{self._at(row)}: VIV (Cl > 0) does not combine with the Syrope " "working-curve model" ) - has_viv = has_viv or cl > 0.0 has_viv_ei0 = has_viv_ei0 or (cl > 0.0 and not ei > 0.0) if cl > 0.0: viv_type_names.add(row.tokens[0].lower()) @@ -3490,12 +3488,6 @@ def end_key(token: str) -> str: ) if not line_ids: raise DeckFormatError(f"{self._label}: the coupled route needs at least one line") - if has_viv: - raise DeckFormatError( - f"{self._label}: VIV (LINE TYPES Cl > 0) runs in the standalone driver of an " - "EI = 0 or finite-EI deck; the coupled OpenFAST and FAST.Farm routes and mixed " - "EI = 0 / finite-EI decks do not carry it yet. Set Cl = 0 for this run" - ) if self.caller_driven: # native CD_Init_Deck_Aggregate: nothing on the coupled route evaluates deck # waves (the host SeaState supplies them). A deck current is a steady field on a @@ -3515,9 +3507,10 @@ def end_key(token: str) -> str: "single-turbine pure EI=0 deck without Rigid6 bodies or rods; remove the " "deck current OPTION (the host SeaState supplies the current)" ) - if has_viv_ei0 and deck_driver_route: + if has_viv_ei0 and not self.caller_driven: # native init_one_model: the lift acts with the line's Morison drag, which the - # deck switches on with water (a depth or bathymetry, a current, or waves) + # deck switches on with water (a depth or bathymetry, a current, or waves); on the + # coupled route the host supplies the water waterkin_option = option_by_key.get("waterkin") waterkin_text = "" if waterkin_option is None else waterkin_option.values[0] has_water = ( diff --git a/python/tests/test_deck_file.py b/python/tests/test_deck_file.py index c9fc05ed..bb4319ee 100644 --- a/python/tests/test_deck_file.py +++ b/python/tests/test_deck_file.py @@ -4603,11 +4603,12 @@ def test_line_type_viv_is_accepted_on_a_finite_ei_line_type(tmp_path): assert (line_type.ei, line_type.cl) == (1.0e4, 0.8) -def test_viv_is_refused_on_the_coupled_route(): +def test_viv_is_accepted_on_the_coupled_route(): text = _edit(_STATIC, (_VIV_ROW, _VIV_ROW + " 0.8")) DeckFile.from_text(text) - with pytest.raises(DeckFormatError, match="runs in the standalone driver"): - DeckFile.from_text(text, caller_driven=True) + DeckFile.from_text(text, caller_driven=True) + # the host supplies the water, so a deck without a depth is not refused there + DeckFile.from_text(_edit(text, ("50.0 WtrDpth\n", "")), caller_driven=True) def test_viv_needs_water_on_an_ei0_line(): diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index 5ddf4743..49f8f31f 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -3182,11 +3182,14 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, CALL fail(ErrStat, ErrMsg, 'finite-EI cable drag wiring failed: '//TRIM(em)); RETURN END IF ! Cross-flow VIV on the Cl > 0 sections, with the drag's diameters (CableDyn_VIV); an - ! OPTION VIVrmsWindow of 0 takes MoorDyn's 500 time steps. + ! OPTION VIVrmsWindow of 0 takes MoorDyn's 500 time steps of the deck dtM, as the EI = 0 + ! lines do (init_one_model), and of the coupling step dt where the deck gives none: a + ! 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)*dt, & + 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) IF (es /= CD_HCDYN_OK) THEN CALL fail(ErrStat, ErrMsg, 'finite-EI cable VIV wiring failed: '//TRIM(em)); RETURN @@ -6754,8 +6757,8 @@ SUBROUTINE CD_Init_Deck_HermiteCable(deck_path, dt, cable, coupled_node, ErrStat 'use the aggregate facade with its external SeaState field'); RETURN END IF IF (line_has_viv(lines(1), types, sections)) THEN - CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_HermiteCable: VIV (LINE TYPES Cl > 0) runs in the standalone '// & - 'deck driver; set Cl = 0 for this entry'); RETURN + CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_HermiteCable: VIV (LINE TYPES Cl > 0) acts with an ambient '// & + 'fluid field, which this single-cable entry does not apply; use the aggregate facade'); RETURN END IF IF (opts%has_bathymetry_file) THEN CALL load_bathymetry_file(path_join(deck_dir(deck_path), opts%bathymetry_file), bathymetry, ErrStat, ErrMsg, & @@ -6984,16 +6987,6 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi 'EI=0/finite-EI decks reject deck water kinematics)') RETURN END IF - ! Cross-flow VIV runs in the standalone driver (EI = 0 decks and finite-EI decks): the aggregate - ! route (OpenFAST, FAST.Farm, mixed EI = 0 / finite-EI decks) neither checkpoints its shedding - ! phase nor feeds it the host's fluid field yet. - IF (ANY(types%cl > CD_ZERO)) THEN - CALL fail(ErrStat, ErrMsg, 'VIV (LINE TYPES Cl > 0) runs in the standalone driver of an EI = 0 or '// & - 'finite-EI deck; '// & - 'the coupled OpenFAST and FAST.Farm routes and mixed EI = 0 / finite-EI decks do not carry it '// & - 'yet. Set Cl = 0 for this run') - RETURN - END IF IF (opts%waterkin_seastate) THEN IF (.NOT. PRESENT(external_fluid)) THEN @@ -7445,12 +7438,13 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi IF (opts%has_bathymetry_file) THEN CALL build_one_hermite_cable(lines(i), sections, types, points, opts, dt, agg%cables(c), cn, es, em, & bathymetry=bathymetry, fairlead_orientation=fairlead_dcm, & - init_note=agg%cable_note(c), & + init_note=agg%cable_note(c), install_viv=.TRUE., & fold_support=MERGE(FOLD_FRICTION_NONE, FOLD_FRICTION_FULL, & deck_has_dynamic_points(points))) ELSE CALL build_one_hermite_cable(lines(i), sections, types, points, opts, dt, agg%cables(c), cn, es, em, & fairlead_orientation=fairlead_dcm, init_note=agg%cable_note(c), & + install_viv=.TRUE., & fold_support=MERGE(FOLD_FRICTION_NONE, FOLD_FRICTION_FULL, & deck_has_dynamic_points(points))) END IF diff --git a/src/CableDyn_Model.f90 b/src/CableDyn_Model.f90 index 7f80f50b..adf6de6f 100644 --- a/src/CableDyn_Model.f90 +++ b/src/CableDyn_Model.f90 @@ -96,6 +96,7 @@ MODULE CableDyn_Model PUBLIC :: CD_Set_Model_Syrope_State PUBLIC :: CD_Set_Model_VIV PUBLIC :: CD_Latch_Model_VIV_Window + PUBLIC :: CD_Get_Model_VIV_State, CD_Set_Model_VIV_State, CD_Model_Has_VIV PUBLIC :: CD_Get_Model_Tension PUBLIC :: CD_Get_Model_EndForces PUBLIC :: CD_Get_Model_EndNodeMassDiag @@ -3991,6 +3992,82 @@ SUBROUTINE CD_Latch_Model_VIV_Window(model, dt) model%viv_tw = REAL(CD_VIV_NM, wp)*dt END SUBROUTINE CD_Latch_Model_VIV_Window + SUBROUTINE CD_Get_Model_VIV_State(model, phi, ms, t_window, ErrStat, ErrMsg) + !! Copy the committed VIV state for a checkpoint: the shedding phase per node (n_nodes), + !! the running mean squares of the cross-flow velocity and acceleration (2, n_nodes), and + !! the averaging time (0 while unlatched). A model without VIV returns zeros. + TYPE(CD_ModelType), INTENT(IN) :: model + REAL(wp), INTENT(OUT) :: phi(:), ms(:, :), t_window + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + phi = CD_ZERO + ms = CD_ZERO + t_window = CD_ZERO + ErrStat = CD_MODEL_OK + ErrMsg = '' + IF (.NOT. model%initialized) THEN + ErrStat = CD_MODEL_NOT_INITIALIZED + ErrMsg = 'CableDyn_Model: model is not initialized' + RETURN + END IF + IF (SIZE(phi) /= model%n_dof/3 .OR. SIZE(ms, 1) /= 2 .OR. SIZE(ms, 2) /= model%n_dof/3) THEN + CALL fail(ErrStat, ErrMsg, 'VIV state outputs must have shapes (n_nodes) and (2, n_nodes)') + RETURN + END IF + IF (.NOT. model%has_viv) RETURN + phi = model%viv_phi + ms = model%viv_ms + t_window = model%viv_tw + END SUBROUTINE CD_Get_Model_VIV_State + + SUBROUTINE CD_Set_Model_VIV_State(model, phi, ms, t_window, ErrStat, ErrMsg) + !! Overwrite the committed VIV state from a checkpoint (see CD_Get_Model_VIV_State). + !! Fails closed on a model without VIV, a shape mismatch, non-finite values, a negative + !! mean square or averaging time. + TYPE(CD_ModelType), INTENT(INOUT) :: model + REAL(wp), INTENT(IN) :: phi(:), ms(:, :), t_window + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + ErrStat = CD_MODEL_OK + ErrMsg = '' + IF (.NOT. model%initialized) THEN + ErrStat = CD_MODEL_NOT_INITIALIZED + ErrMsg = 'CableDyn_Model: model is not initialized' + RETURN + END IF + IF (.NOT. model%has_viv) THEN + CALL fail(ErrStat, ErrMsg, 'model carries no VIV state to set') + RETURN + END IF + IF (SIZE(phi) /= model%n_dof/3 .OR. SIZE(ms, 1) /= 2 .OR. SIZE(ms, 2) /= model%n_dof/3) THEN + CALL fail(ErrStat, ErrMsg, 'VIV state inputs must have shapes (n_nodes) and (2, n_nodes)') + RETURN + END IF + IF (.NOT. (CD_All_Finite(phi) .AND. CD_All_Finite(ms) .AND. CD_Is_Finite(t_window))) THEN + CALL fail(ErrStat, ErrMsg, 'VIV state mirror must be finite') + RETURN + END IF + IF (ANY(ms < CD_ZERO) .OR. t_window < CD_ZERO) THEN + CALL fail(ErrStat, ErrMsg, 'VIV mean squares and averaging time must be non-negative') + RETURN + END IF + model%viv_phi = phi + model%viv_ms = ms + model%viv_tw = t_window + ! the rollback and recovery twins follow (see CD_Set_Model_VE_Dl1) + model%viv_phi_rollback = phi + model%viv_ms_rollback = ms + model%recovery_viv_phi = phi + model%recovery_viv_ms = ms + model%viv_phi_eval = phi + END SUBROUTINE CD_Set_Model_VIV_State + + PURE LOGICAL FUNCTION CD_Model_Has_VIV(model) RESULT(has) + !! True if the model carries the cross-flow VIV phase state. + TYPE(CD_ModelType), INTENT(IN) :: model + has = model%has_viv + END FUNCTION CD_Model_Has_VIV + SUBROUTINE viv_node_coef(model, q, nd, coef, uu) !! Lift scale of interior node nd at positions q, sum over its two elements of !! (1/2 l0_e w_e)(1/2 rho D_e Cl_e) with w_e the wetted fraction under the drag waterline diff --git a/src/CableDyn_OpenFAST_HermiteFMF.f90 b/src/CableDyn_OpenFAST_HermiteFMF.f90 index 4ea5e7d3..5871b946 100644 --- a/src/CableDyn_OpenFAST_HermiteFMF.f90 +++ b/src/CableDyn_OpenFAST_HermiteFMF.f90 @@ -87,6 +87,7 @@ MODULE CableDyn_OpenFAST_HermiteFMF PUBLIC :: CD_HFMF_BoundaryMirrorSize PUBLIC :: CD_HFMF_ForceMirrorSize PUBLIC :: CD_HFMF_TorsionMirrorSize + PUBLIC :: CD_HFMF_VIVMirrorSize PUBLIC :: CD_HFMF_PackMirror PUBLIC :: CD_HFMF_UnpackMirror PUBLIC :: CD_HFMF_End @@ -1532,14 +1533,14 @@ INTEGER FUNCTION CD_HFMF_MirrorSize(self) RESULT(n) !! is re-derived by CD_Recompute_System_Acceleration) the cable reloads it exactly. !! A cable on a frictional seabed appends its stick-slip friction anchors, (x, y) per !! node (CD_HFMF_FrictionMirrorSize slots): they are committed state like q. Then come - !! the committed boundary (CD_HFMF_BoundaryMirrorSize), the force-blend state and the - !! torsion state. Zero if uninitialised. + !! the committed boundary (CD_HFMF_BoundaryMirrorSize), the force-blend state, the VIV + !! state and the torsion state. Zero if uninitialised. TYPE(CD_HFMF_ModuleType), INTENT(IN) :: self n = 0 IF (.NOT. self%initialized) RETURN IF (ALLOCATED(self%line%freemask)) n = 3*COUNT(self%line%freemask) n = n + CD_HFMF_FrictionMirrorSize(self) + CD_HFMF_BoundaryMirrorSize(self) + & - CD_HFMF_ForceMirrorSize(self) + CD_HFMF_TorsionMirrorSize(self) + CD_HFMF_ForceMirrorSize(self) + CD_HFMF_VIVMirrorSize(self) + CD_HFMF_TorsionMirrorSize(self) END FUNCTION CD_HFMF_MirrorSize INTEGER FUNCTION CD_HFMF_BoundaryMirrorSize(self) RESULT(n) @@ -1576,6 +1577,16 @@ INTEGER FUNCTION CD_HFMF_ForceMirrorSize(self) RESULT(n) IF (self%line%force_blend) n = 1 + self%line%ndof END FUNCTION CD_HFMF_ForceMirrorSize + INTEGER FUNCTION CD_HFMF_VIVMirrorSize(self) RESULT(n) + !! Mirror slots of the cross-flow VIV state, before the torsion block: the shedding phase + !! per node, the running mean squares of the cross-flow velocity and acceleration per node + !! (interleaved) and the averaging time (3 nn + 1 values); zero without VIV. + TYPE(CD_HFMF_ModuleType), INTENT(IN) :: self + n = 0 + IF (.NOT. self%initialized) RETURN + IF (self%line%has_viv) n = 3*self%line%nn + 1 + END FUNCTION CD_HFMF_VIVMirrorSize + INTEGER FUNCTION CD_HFMF_FrictionMirrorSize(self) RESULT(n) !! Mirror slots of the stick-slip friction anchors (2 per node), zero without friction. TYPE(CD_HFMF_ModuleType), INTENT(IN) :: self @@ -1586,7 +1597,7 @@ END FUNCTION CD_HFMF_FrictionMirrorSize SUBROUTINE CD_HFMF_PackMirror(self, buf, ErrStat, ErrMsg) !! Write the cable's continuous state into buf as [v_free; q_free; a_free], then the - !! friction, boundary, force-blend and torsion blocks -- the layout CD_HFMF_MirrorSize + !! friction, boundary, force-blend, VIV and torsion blocks -- the layout CD_HFMF_MirrorSize !! sizes. The mirror is written every mooring step and reloaded ONLY by a !! checkpoint-restart rebuild or the state-const CalcOutput restore !! (CD_HFMF_UnpackMirror); the module stays self-authoritative in normal marching. @@ -1644,6 +1655,12 @@ SUBROUTINE CD_HFMF_PackMirror(self, buf, ErrStat, ErrMsg) END IF k = k + 1 + self%line%ndof END IF + IF (self%line%has_viv) THEN + buf(k + 1:k + self%line%nn) = self%line%viv_phi + buf(k + self%line%nn + 1:k + 3*self%line%nn) = RESHAPE(self%line%viv_ms, [2*self%line%nn]) + buf(k + 3*self%line%nn + 1) = self%line%viv_tw + k = k + 3*self%line%nn + 1 + END IF IF (self%line%torsion%active) THEN buf(k + 1) = self%line%torsion%theta buf(k + 2) = self%line%torsion%phi @@ -1704,6 +1721,15 @@ SUBROUTINE CD_HFMF_UnpackMirror(self, buf, t, ErrStat, ErrMsg) ErrMsg = 'CD_HFMF_UnpackMirror: the parent orientation must be a proper orthogonal DCM' RETURN END IF + ! and the VIV block's mean squares and averaging time, which cannot be negative + IF (self%line%has_viv) THEN + kb = SIZE(buf) - CD_HFMF_TorsionMirrorSize(self) - CD_HFMF_VIVMirrorSize(self) + self%line%nn + IF (ANY(buf(kb + 1:kb + 2*self%line%nn + 1) < CD_ZERO)) THEN + ErrStat = CD_HFMF_BADINPUT + ErrMsg = 'CD_HFMF_UnpackMirror: the VIV mean squares and averaging time must be non-negative' + RETURN + END IF + END IF k = 0 DO i = 1, self%line%ndof IF (self%line%freemask(i)) THEN @@ -1757,6 +1783,17 @@ SUBROUTINE CD_HFMF_UnpackMirror(self, buf, t, ErrStat, ErrMsg) END IF k = k + 1 + self%line%ndof END IF + ! the VIV state, with the step-start copy of a recovering step and the in-step phase + IF (self%line%has_viv) THEN + self%line%viv_phi = buf(k + 1:k + self%line%nn) + self%line%viv_ms = RESHAPE(buf(k + self%line%nn + 1:k + 3*self%line%nn), [2, self%line%nn]) + self%line%viv_tw = buf(k + 3*self%line%nn + 1) + self%line%viv_phi_eval = self%line%viv_phi + self%line%viv_ms_next = self%line%viv_ms + self%line%ws_recovery_viv_phi = self%line%viv_phi + self%line%ws_recovery_viv_ms = self%line%viv_ms + k = k + 3*self%line%nn + 1 + END IF IF (self%line%torsion%active) THEN self%line%torsion%theta = buf(k + 1) self%line%torsion%phi = buf(k + 2) diff --git a/src/CableDyn_System.f90 b/src/CableDyn_System.f90 index 7a2cd623..e46ab3c6 100644 --- a/src/CableDyn_System.f90 +++ b/src/CableDyn_System.f90 @@ -17,6 +17,7 @@ MODULE CableDyn_System CD_Get_Model_State, CD_Get_Model_Tension, & CD_Model_Has_Viscoelastic, CD_Get_Model_VE_Dl1, CD_Set_Model_VE_Dl1, & CD_Model_Has_Syrope, CD_Get_Model_Syrope_State, CD_Set_Model_Syrope_State, & + CD_Model_Has_VIV, CD_Get_Model_VIV_State, CD_Set_Model_VIV_State, & CD_Model_Has_Friction, CD_Get_Model_Friction_Anchors, CD_Set_Model_Friction_Anchors, & CD_Latch_Model_VIV_Window, & CD_Get_Model_EndNodeMassDiag, CD_Get_Model_EndNodeAddedMass, & @@ -77,6 +78,7 @@ MODULE CableDyn_System PUBLIC :: CD_Get_System_Line_Friction_Anchors PUBLIC :: CD_Set_System_Line_Friction_Anchors PUBLIC :: CD_Get_System_Line_Syrope_State + PUBLIC :: CD_System_Line_VIV_MirrorSize, CD_Get_System_Line_VIV_State, CD_Set_System_Line_VIV_State PUBLIC :: CD_Set_System_Line_Syrope_State PUBLIC :: CD_Get_System_PointBlocks PUBLIC :: CD_Get_System_Point_State @@ -948,6 +950,80 @@ SUBROUTINE CD_Get_System_Line_Syrope_State(system, line_index, slow, tmax, ErrSt ErrMsg = '' END SUBROUTINE CD_Get_System_Line_Syrope_State + PURE INTEGER FUNCTION CD_System_Line_VIV_MirrorSize(system, line_index) RESULT(n) + !! Reals of one contained line's VIV checkpoint block (CD_Get_System_Line_VIV_State): + !! 3 per node plus the averaging time, or 0 for a line without VIV. + TYPE(CD_SystemType), INTENT(IN) :: system + INTEGER, INTENT(IN) :: line_index + n = 0 + IF (line_index < 1 .OR. line_index > system%n_lines) RETURN + IF (.NOT. CD_Model_Has_VIV(system%lines(line_index))) RETURN + n = 3*SIZE(system%lines(line_index)%viv_phi) + 1 + END FUNCTION CD_System_Line_VIV_MirrorSize + + SUBROUTINE CD_Get_System_Line_VIV_State(system, line_index, buf, ErrStat, ErrMsg) + !! One contained line's committed VIV state as a flat checkpoint block: the shedding + !! phases (n_nodes), the cross-flow velocity and acceleration mean squares interleaved + !! per node (2 n_nodes), then the averaging time. + TYPE(CD_SystemType), INTENT(IN) :: system + INTEGER, INTENT(IN) :: line_index + REAL(wp), INTENT(OUT) :: buf(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: nn, es + CHARACTER(160) :: em + REAL(wp), ALLOCATABLE :: phi(:), ms(:, :) + + buf = CD_ZERO + CALL validate_line_index(system, line_index, ErrStat, ErrMsg) + IF (ErrStat /= CD_SYSTEM_OK) RETURN + IF (SIZE(buf) /= CD_System_Line_VIV_MirrorSize(system, line_index) .OR. SIZE(buf) == 0) THEN + CALL fail(ErrStat, ErrMsg, 'line VIV state block has the wrong size') + RETURN + END IF + nn = (SIZE(buf) - 1)/3 + ALLOCATE (phi(nn), ms(2, nn)) + CALL CD_Get_Model_VIV_State(system%lines(line_index), phi, ms, buf(3*nn + 1), es, em) + IF (es /= CD_MODEL_OK) THEN + ErrStat = CD_SYSTEM_SOLVEFAIL + ErrMsg = 'CableDyn_System: line VIV state query failed: '//TRIM(em) + RETURN + END IF + buf(1:nn) = phi + buf(nn + 1:3*nn) = RESHAPE(ms, [2*nn]) + ErrStat = CD_SYSTEM_OK + ErrMsg = '' + END SUBROUTINE CD_Get_System_Line_VIV_State + + SUBROUTINE CD_Set_System_Line_VIV_State(system, line_index, buf, ErrStat, ErrMsg) + !! Overwrite one contained line's VIV state from a checkpoint block (see + !! CD_Get_System_Line_VIV_State). + TYPE(CD_SystemType), INTENT(INOUT) :: system + INTEGER, INTENT(IN) :: line_index + REAL(wp), INTENT(IN) :: buf(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: nn, es + CHARACTER(160) :: em + + CALL validate_line_index(system, line_index, ErrStat, ErrMsg) + IF (ErrStat /= CD_SYSTEM_OK) RETURN + IF (SIZE(buf) /= CD_System_Line_VIV_MirrorSize(system, line_index) .OR. SIZE(buf) == 0) THEN + CALL fail(ErrStat, ErrMsg, 'line VIV state block has the wrong size') + RETURN + END IF + nn = (SIZE(buf) - 1)/3 + CALL CD_Set_Model_VIV_State(system%lines(line_index), buf(1:nn), RESHAPE(buf(nn + 1:3*nn), [2, nn]), & + buf(3*nn + 1), es, em) + IF (es /= CD_MODEL_OK) THEN + ErrStat = CD_SYSTEM_SOLVEFAIL + ErrMsg = 'CableDyn_System: line VIV state reload failed: '//TRIM(em) + RETURN + END IF + ErrStat = CD_SYSTEM_OK + ErrMsg = '' + END SUBROUTINE CD_Set_System_Line_VIV_State + SUBROUTINE CD_Set_System_Line_Syrope_State(system, line_index, slow, tmax, ErrStat, ErrMsg) !! Overwrite one contained line's per-element Syrope states from a checkpoint mirror !! (the cross-process restart reload). diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index 8b26f507..a8a72f8f 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -93,7 +93,8 @@ MODULE CableDyn CD_AGG_WriteStaticProfile USE CableDyn_OpenFAST_HermiteFMF, ONLY: CD_HFMF_MirrorSize, CD_HFMF_PackMirror, CD_HFMF_UnpackMirror, & CD_HFMF_FrictionMirrorSize, CD_HFMF_BoundaryMirrorSize, & - CD_HFMF_ForceMirrorSize, CD_HFMF_TorsionMirrorSize, CD_HFMF_OK + CD_HFMF_ForceMirrorSize, CD_HFMF_TorsionMirrorSize, CD_HFMF_VIVMirrorSize, & + CD_HFMF_OK USE CableDyn_HermiteCableDynamic, ONLY: CD_HermiteCable_Dyn_Reset_Profile, & CD_HermiteCable_Dyn_Disable_Profile, & CD_HermiteCable_Dyn_Get_Profile, & @@ -112,6 +113,8 @@ MODULE CableDyn CD_Set_System_Line_VE_Dl1, & CD_System_Line_Has_Syrope, CD_Get_System_Line_Syrope_State, & CD_Set_System_Line_Syrope_State, & + CD_System_Line_VIV_MirrorSize, CD_Get_System_Line_VIV_State, & + CD_Set_System_Line_VIV_State, & CD_System_Line_Has_Friction, CD_Get_System_Line_Friction_Anchors, & CD_Set_System_Line_Friction_Anchors, & CD_Recompute_System_Acceleration, CD_SYSTEM_OK @@ -1089,6 +1092,9 @@ SUBROUTINE CD_Init(InitInp, u, p, x, xd, z, other, y, m, DTcoupling, InitOut, Er RETURN END IF END IF + ! a line with cross-flow VIV ends its span with the VIV state (the shedding phase and + ! the two running mean squares per node, then the averaging time) + nstates = nstates + CD_System_Line_VIV_MirrorSize( Inst(id)%agg%sys%fast%system, il ) m%LineStateIsN(il) = nstates END DO ! finite-EI cables append their free-DOF [v_free; q_free; a_free] mirror after the mooring block @@ -3326,6 +3332,26 @@ SUBROUTINE CD_InitVars(Vars, u, p, x, y, m, inst_, Linearize, ErrStat, ErrMsg) DEALLOCATE (CblLinVel) END DO + ! VIV states: the shedding phase and running mean squares per node and the averaging + ! time, the last block of a VIV line's span. Coverage-only, like the Syrope block. + DO il = 1, inst_%nlines + nve = CD_System_Line_VIV_MirrorSize( inst_%agg%sys%fast%system, il ) + IF (nve <= 0) CYCLE + LinStr = 'Line '//TRIM(Num2LStr(il)) + ALLOCATE (CblLinVel(nve), STAT=ErrStat2) + IF (ErrStat2 /= 0) THEN + CALL SetErrStat( ErrID_Fatal, 'Could not allocate line VIV lin-name work array.', & + ErrStat, ErrMsg, RoutineName ); RETURN + END IF + DO j = 1, nve + CblLinVel(j) = TRIM(LinStr)//' VIV state '//TRIM(Num2LStr(j)) + END DO + CALL MV_AddVar( Vars%x, TRIM(LinStr)//' VIV state', FieldScalar, DatLoc(CD_x_states), & + iAry=m%LineStateIsN(il) - nve + 1, Num=nve, Perturb=0.1_R8Ki, & + LinNames=CblLinVel ) + DEALLOCATE (CblLinVel) + END DO + ! finite-EI cable states: pack_state_mirror appends the free-DOF mirror ! [v_free; q_free] of each cable AFTER the EI=0 mooring block, at the x%states ! offset koff = LineStateIsN(nlines) (0 when there are no mooring lines). Register @@ -3342,10 +3368,11 @@ SUBROUTINE CD_InitVars(Vars, u, p, x, y, m, inst_, Linearize, ErrStat, ErrMsg) csz = CD_HFMF_MirrorSize( inst_%agg%cables(ic) ) IF (csz <= 0) CYCLE ! uninitialised cable contributes no states ! free DOFs; mirror = [v_free; q_free; a_free] then the friction anchors, the - ! committed boundary, the force-blend state and the torsion state (if any) + ! committed boundary, the force-blend state, the VIV state and the torsion state (if any) nf = (csz - CD_HFMF_FrictionMirrorSize( inst_%agg%cables(ic) ) - & CD_HFMF_BoundaryMirrorSize( inst_%agg%cables(ic) ) - & CD_HFMF_ForceMirrorSize( inst_%agg%cables(ic) ) - & + CD_HFMF_VIVMirrorSize( inst_%agg%cables(ic) ) - & CD_HFMF_TorsionMirrorSize( inst_%agg%cables(ic) ))/3 LinStr = 'Cable '//TRIM(Num2LStr(ic)) ! Build the per-DOF linearization names in an explicit pre-allocated loop, NOT an @@ -3379,8 +3406,8 @@ SUBROUTINE CD_InitVars(Vars, u, p, x, y, m, inst_, Linearize, ErrStat, ErrMsg) LinNames=CblLinAcc ) DEALLOCATE (CblLinVel, CblLinPos, CblLinAcc) ! stick-slip friction anchors (x, y per node), the force-blend committed force - ! (flag + force) and the torsion state (Theta, Phi, end frames) after the acceleration - ! block: coverage-only, like the acceleration block + ! (flag + force), the VIV state and the torsion state (Theta, Phi, end frames) after + ! the acceleration block: coverage-only, like the acceleration block IF (csz > 3*nf) THEN ALLOCATE (CblLinVel(csz - 3*nf), STAT=ErrStat2) IF (ErrStat2 /= 0) THEN @@ -3721,6 +3748,23 @@ SUBROUTINE reload_interiors_ary(inst_, m, states, t_clock, ErrStat, ErrMsg) END IF END BLOCK END IF + ! VIV state reload: the last block of the line's span (mirrors pack_state_mirror) + nve = CD_System_Line_VIV_MirrorSize( inst_%agg%sys%fast%system, il ) + IF (nve > 0) THEN + IF (m%LineStateIsN(il) > SIZE(states)) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: line '//TRIM(Num2LStr(il))// & + ' VIV state mirror extends past the state vector.', ErrStat, ErrMsg, RoutineName ) + RETURN + END IF + BLOCK + REAL(wp) :: vbuf(nve) + vbuf = REAL(states(m%LineStateIsN(il) - nve + 1:m%LineStateIsN(il)), wp) + CALL CD_Set_System_Line_VIV_State( inst_%agg%sys%fast%system, il, vbuf, es, em ) + IF (es /= CD_SYSTEM_OK) THEN + CALL SetErrStat( ErrID_Fatal, TRIM(em), ErrStat, ErrMsg, RoutineName ); RETURN + END IF + END BLOCK + END IF END DO CALL reload_cable_mirrors( inst_, m, states, t_clock, .FALSE., koff, ErrStat, ErrMsg ) IF (ErrStat >= AbortErrLev) RETURN @@ -4015,6 +4059,18 @@ SUBROUTINE pack_state_mirror_ary(inst_, m, states, ErrStat, ErrMsg) states(k + 3*nin + nve:k + 3*nin + 2*nve - 1) = REAL(tmx, DbKi) END BLOCK END IF + ! VIV state: the last block of the line's span + nve = CD_System_Line_VIV_MirrorSize( inst_%agg%sys%fast%system, il ) + IF (nve > 0) THEN + BLOCK + REAL(wp) :: vbuf(nve) + CALL CD_Get_System_Line_VIV_State( inst_%agg%sys%fast%system, il, vbuf, es, em ) + IF (es /= CD_SYSTEM_OK) THEN + CALL SetErrStat( ErrID_Fatal, TRIM(em), ErrStat, ErrMsg, RoutineName ); RETURN + END IF + states(m%LineStateIsN(il) - nve + 1:m%LineStateIsN(il)) = REAL(vbuf, DbKi) + END BLOCK + END IF END DO ! finite-EI cables: append per-cable free-DOF [v_free; q_free; a_free] after the mooring block koff = 0 diff --git a/tests/test_viv_coupled.f90 b/tests/test_viv_coupled.f90 new file mode 100644 index 00000000..99fc075e --- /dev/null +++ b/tests/test_viv_coupled.f90 @@ -0,0 +1,355 @@ +! File: tests/test_viv_coupled.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +PROGRAM test_viv_coupled + !! Cross-flow VIV on the coupled aggregate route (the OpenFAST and FAST.Farm shells and the + !! standalone mixed EI = 0 / finite-EI runner), on a deck with an EI = 0 riser and a finite-EI + !! cable (EI 1 N m^2) side by side: each 100 m long at 50 kN, D 0.1 m, 50 segments, ends held at + !! 50 m depth, Cl 0.8 with MoorDyn's band (dF 0.08, cF 0.18), in a uniform 0.15 m/s host current + !! across the lines (the deck of tests/test_viv_lockin.py). + !! + !! Gates: + !! * lock-in: over 60-120 s the mid-span cross-flow amplitude of both lines is MoorDyn-F's + !! A/D 0.662 within 0.03 and the response frequency its 0.293 Hz within 0.01 Hz; with Cl = 0 + !! the lines stay still (A/D below 0.01); + !! * checkpoint restart (the shell's rebuild recipe: a fresh instance takes the coupled + !! kinematics, each EI = 0 line's interior [v; q; a] and VIV block and each cable's mirror, + !! then the host field): the restarted run continues bit for bit, and a rebuild that skips the + !! VIV reload does not; + !! * correction rewind: a step taken after CD_AGG_Snapshot and repeated after CD_AGG_Restore + !! 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). + 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, & + CD_AGG_UpdateStates_Moving, CD_AGG_CalcOutput, CD_AGG_NFluidNodes, & + 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_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 + IMPLICIT NONE + + REAL(wp), PARAMETER :: DT = 0.01_wp, U = 0.15_wp, D = 0.1_wp + REAL(wp), PARAMETER :: MD_AD = 0.662_wp, MD_F = 0.293_wp + INTEGER, PARAMETER :: MID = 26 + INTEGER :: nfail + + nfail = 0 + CALL write_deck('viv_coupled.dat', 0.8_wp) + CALL write_deck('viv_coupled_nolift.dat', 0.0_wp) + CALL case_lockin() + CALL case_restart() + CALL case_rewind() + CALL case_window() + IF (nfail > 0) THEN + WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' coupled VIV check(s) failed' + ERROR STOP 1 + END IF + WRITE (*, '(A)') 'PASS: cross-flow VIV on the coupled aggregate route' + +CONTAINS + + SUBROUTINE case_lockin() + !! 120 s in the host current; the response statistics over 60-120 s. + INTEGER, PARAMETER :: NSTEP = 12000, NSKIP = 6000 + TYPE(CD_AGG_ModuleType) :: agg + REAL(wp) :: zs(NSTEP - NSKIP, 2), ad(2), f(2) + INTEGER :: pass, s, k + CHARACTER(16) :: what(2) = ['EI = 0 riser ', 'finite-EI cable '] + DO pass = 1, 2 + IF (.NOT. start(agg, MERGE('viv_coupled.dat ', 'viv_coupled_nolift.dat', pass == 1))) RETURN + DO s = 1, NSKIP + IF (.NOT. advance(agg)) RETURN + END DO + DO s = 1, NSTEP - NSKIP + IF (.NOT. advance(agg)) RETURN + zs(s, 1) = agg%sys%fast%system%lines(1)%q(3*MID) + zs(s, 2) = agg%cables(1)%line%q(6*(MID - 1) + 3) + END DO + CALL finish(agg) + DO k = 1, 2 + CALL response(zs(:, k), ad(k), f(k)) + IF (pass == 1) THEN + WRITE (*, '(2A,F7.4,A,F7.4,A)') ' ', what(k), ad(k), ' A/D at ', f(k), ' Hz (MoorDyn-F 0.662 at 0.293)' + CALL check(ABS(ad(k) - MD_AD) < 0.03_wp, TRIM(what(k))//' locks in at MoorDyn-F''s amplitude') + CALL check(ABS(f(k) - MD_F) < 0.01_wp, TRIM(what(k))//' locks in at MoorDyn-F''s frequency') + ELSE + WRITE (*, '(2A,ES10.3,A)') ' ', what(k), ad(k), ' A/D with Cl = 0' + CALL check(ad(k) < 0.01_wp, TRIM(what(k))//' stays still without the lift') + END IF + END DO + END DO + END SUBROUTINE case_lockin + + SUBROUTINE case_restart() + !! Checkpoint after 10 s, while the lock-in builds up; 50 steps on. + INTEGER, PARAMETER :: NPRE = 1000, NPOST = 50 + TYPE(CD_AGG_ModuleType) :: a, b, c + INTEGER :: s + LOGICAL :: same_b, same_c + IF (.NOT. start(a, 'viv_coupled.dat')) RETURN + DO s = 1, NPRE + IF (.NOT. advance(a)) RETURN + END DO + IF (.NOT. rebuild(a, b, .TRUE.)) RETURN + IF (.NOT. rebuild(a, c, .FALSE.)) RETURN + same_b = .TRUE. + same_c = .TRUE. + DO s = 1, NPOST + IF (.NOT. advance(a)) RETURN + IF (.NOT. advance(b)) RETURN + IF (.NOT. advance(c)) RETURN + same_b = same_b .AND. identical(a, b) + same_c = same_c .AND. identical(a, c) + END DO + CALL check(same_b, 'the restarted run continues bit for bit') + CALL check(.NOT. same_c, 'a restart without the VIV state does not') + CALL finish(a) + CALL finish(b) + CALL finish(c) + END SUBROUTINE case_restart + + SUBROUTINE case_rewind() + !! A correction iteration: snapshot, step, restore, the same step again. + TYPE(CD_AGG_ModuleType) :: a, b + INTEGER :: s, es + CHARACTER(512) :: em + IF (.NOT. start(a, 'viv_coupled.dat')) RETURN + IF (.NOT. start(b, 'viv_coupled.dat')) RETURN + DO s = 1, 500 + IF (.NOT. advance(a)) RETURN + IF (.NOT. advance(b)) RETURN + END DO + CALL CD_AGG_Snapshot(a, es, em) + CALL check(es == CD_AGG_OK, 'snapshot: '//TRIM(em)) + IF (.NOT. advance(a)) RETURN + CALL CD_AGG_Restore(a, es, em) + CALL check(es == CD_AGG_OK, 'restore: '//TRIM(em)) + DO s = 1, 20 + IF (.NOT. advance(a)) RETURN + IF (.NOT. advance(b)) RETURN + END DO + CALL check(identical(a, b), 'a rewound step repeats bit for bit') + CALL CD_AGG_End(a, es, em) + CALL CD_AGG_End(b, es, em) + END SUBROUTINE case_rewind + + SUBROUTINE case_window() + !! The default VIV averaging time of both line kinds, with and without a deck dtM. + TYPE(CD_AGG_ModuleType) :: agg + REAL(wp) :: tw_line, tw_cable + INTEGER :: pass + CALL write_deck('viv_coupled_dtm.dat', 0.8_wp, window=0.0_wp, dtm=0.001_wp) + CALL write_deck('viv_coupled_nodtm.dat', 0.8_wp, window=0.0_wp) + DO pass = 1, 2 + IF (.NOT. start(agg, MERGE('viv_coupled_dtm.dat ', 'viv_coupled_nodtm.dat', pass == 1))) RETURN + IF (.NOT. advance(agg)) RETURN + tw_line = agg%sys%fast%system%lines(1)%viv_tw + tw_cable = agg%cables(1)%line%viv_tw + WRITE (*, '(A,2F8.4,A)') ' averaging window (line, cable): ', tw_line, tw_cable, ' s' + IF (pass == 1) THEN + CALL check(ABS(tw_line - 0.5_wp) < 1.0e-12_wp .AND. ABS(tw_cable - 0.5_wp) < 1.0e-12_wp, & + 'both line kinds average over 500 steps of the deck dtM at a coarser coupling step') + ELSE + CALL check(ABS(tw_line - 5.0_wp) < 1.0e-12_wp .AND. ABS(tw_cable - 5.0_wp) < 1.0e-12_wp, & + 'both line kinds average over 500 coupling steps without a deck dtM') + END IF + CALL finish(agg) + END DO + END SUBROUTINE case_window + + LOGICAL FUNCTION start(agg, path) RESULT(ok) + !! A host-fluid build of the deck at dt. + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: agg + CHARACTER(*), INTENT(IN) :: path + INTEGER :: es + CHARACTER(512) :: em + CALL CD_AGG_Init_From_Deck(agg, TRIM(path), DT, es, em, external_fluid=.TRUE.) + ok = es == CD_AGG_OK + CALL check(ok, 'init '//TRIM(path)//': '//TRIM(em)) + IF (ok) ok = agg%ncable == 1 .AND. agg%has_sys + IF (ok) ok = SIZE(agg%sys%fast%system%lines(1)%q) == 3*(MID*2 - 1) + CALL check(ok, 'one EI = 0 line and one cable of 50 elements are built') + END FUNCTION start + + LOGICAL FUNCTION advance(agg) RESULT(ok) + !! One coupling step with the ends held, after the host samples its current. + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: agg + REAL(wp), ALLOCATABLE :: pos(:, :), vel(:, :), acc(:, :), load(:, :) + INTEGER :: es, npt, ni + LOGICAL :: cv, st + CHARACTER(512) :: em + CALL set_current(agg) + npt = CD_AGG_NMovingPoints(agg, es, em) + ALLOCATE (pos(3, npt), vel(3, npt), acc(3, npt), load(3, npt)) + CALL CD_AGG_GetMovingPointMesh(agg, pos, vel, acc, load, es, em) + vel = 0.0_wp + acc = 0.0_wp + CALL CD_AGG_Step_Moving(agg, DT, pos, vel, acc, cv, st, ni, es, em) + ok = es == CD_AGG_OK .AND. cv + IF (.NOT. ok) CALL check(.FALSE., 'step: '//TRIM(em)) + IF (ok) CALL CD_AGG_CalcOutput(agg, es, em) + END FUNCTION advance + + SUBROUTINE set_current(agg) + !! The host's uniform current U along +y over every fluid node, still surface at z = 0. + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: agg + REAL(wp), ALLOCATABLE :: fv(:, :), fa(:, :), wl(:) + INTEGER :: es, nfl + CHARACTER(512) :: em + nfl = CD_AGG_NFluidNodes(agg, es, em) + ALLOCATE (fv(3, nfl), fa(3, nfl), wl(nfl)) + fv = 0.0_wp + fv(2, :) = U + fa = 0.0_wp + wl = 0.0_wp + CALL CD_AGG_SetFluidFields(agg, fv, fa, wl, es, em) + IF (es /= CD_AGG_OK) CALL check(.FALSE., 'host current: '//TRIM(em)) + END SUBROUTINE set_current + + LOGICAL FUNCTION rebuild(a, b, with_viv) RESULT(ok) + !! The shell's checkpoint rebuild of a into a fresh b: the coupled kinematics, each EI = 0 + !! line's interior [v; q; a] and (with_viv) its VIV block, each cable's mirror (which + !! carries the cable's VIV block; zeroed to the build's state when not with_viv). + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: a, b + LOGICAL, INTENT(IN) :: with_viv + REAL(wp), ALLOCATABLE :: pos(:, :), vel(:, :), acc(:, :), load(:, :), qL(:), vL(:), aL(:), buf(:), & + fresh(:) + INTEGER :: es, npt, il, ndof, nv, nvc + CHARACTER(512) :: em + ok = start(b, 'viv_coupled.dat') + IF (.NOT. ok) RETURN + npt = CD_AGG_NMovingPoints(a, es, em) + ALLOCATE (pos(3, npt), vel(3, npt), acc(3, npt), load(3, npt)) + CALL CD_AGG_GetMovingPointMesh(a, pos, vel, acc, load, es, em) + CALL CD_AGG_UpdateStates_Moving(b, pos, vel, acc, es, em) + ok = es == CD_AGG_OK + DO il = 1, CD_System_NLines(a%sys%fast%system, es, em) + ndof = CD_System_Line_NDOF(a%sys%fast%system, il, es, em) + ALLOCATE (qL(ndof), vL(ndof), aL(ndof)) + CALL CD_Get_System_Line_State(a%sys%fast%system, il, qL, vL, aL, es, em) + CALL CD_Update_System_Line_Interior_State(b%sys%fast%system, il, qL(4:ndof - 3), vL(4:ndof - 3), es, em, & + a_interior=aL(4:ndof - 3)) + ok = ok .AND. es == CD_SYSTEM_OK + nv = CD_System_Line_VIV_MirrorSize(a%sys%fast%system, il) + ok = ok .AND. nv == 3*(ndof/3) + 1 + IF (with_viv .AND. nv > 0) THEN + ALLOCATE (buf(nv)) + CALL CD_Get_System_Line_VIV_State(a%sys%fast%system, il, buf, es, em) + CALL CD_Set_System_Line_VIV_State(b%sys%fast%system, il, buf, es, em) + ok = ok .AND. es == CD_SYSTEM_OK + DEALLOCATE (buf) + END IF + DEALLOCATE (qL, vL, aL) + END DO + ALLOCATE (buf(CD_HFMF_MirrorSize(a%cables(1))), fresh(CD_HFMF_MirrorSize(b%cables(1)))) + CALL CD_HFMF_PackMirror(a%cables(1), buf, es, em) + nvc = CD_HFMF_VIVMirrorSize(a%cables(1)) + ok = ok .AND. nvc == 3*a%cables(1)%line%nn + 1 + IF (.NOT. with_viv) THEN + ! the cable's VIV block as the fresh build has it (the torsion-free cable ends with it) + CALL CD_HFMF_PackMirror(b%cables(1), fresh, es, em) + buf(SIZE(buf) - nvc + 1:) = fresh(SIZE(fresh) - nvc + 1:) + END IF + CALL CD_HFMF_UnpackMirror(b%cables(1), buf, a%cables(1)%line%t, es, em) + ok = ok .AND. es == CD_HFMF_OK + CALL check(ok, 'checkpoint rebuild: '//TRIM(em)) + END FUNCTION rebuild + + LOGICAL FUNCTION identical(a, b) RESULT(same) + !! Both lines' state and shedding phases are the same bits. + TYPE(CD_AGG_ModuleType), INTENT(IN) :: a, b + same = MAXVAL(ABS(a%sys%fast%system%lines(1)%q - b%sys%fast%system%lines(1)%q)) <= 0.0_wp .AND. & + MAXVAL(ABS(a%sys%fast%system%lines(1)%viv_phi - b%sys%fast%system%lines(1)%viv_phi)) <= 0.0_wp .AND. & + MAXVAL(ABS(a%cables(1)%line%q - b%cables(1)%line%q)) <= 0.0_wp .AND. & + MAXVAL(ABS(a%cables(1)%line%viv_phi - b%cables(1)%line%viv_phi)) <= 0.0_wp + END FUNCTION identical + + SUBROUTINE response(z, ad, f) + !! Cross-flow amplitude A/D = sqrt(2) std(z)/D and the mean up-crossing frequency of z. + REAL(wp), INTENT(IN) :: z(:) + REAL(wp), INTENT(OUT) :: ad, f + REAL(wp) :: zm, t0, t1 + INTEGER :: i, n + zm = SUM(z)/SIZE(z) + ad = SQRT(2.0_wp*SUM((z - zm)**2)/SIZE(z))/D + n = 0 + t0 = 0.0_wp + t1 = 0.0_wp + DO i = 2, SIZE(z) + IF (z(i - 1) < zm .AND. z(i) >= zm) THEN + n = n + 1 + t1 = (REAL(i - 1, wp) + (zm - z(i - 1))/(z(i) - z(i - 1)))*DT + IF (n == 1) t0 = t1 + END IF + END DO + f = 0.0_wp + IF (n > 1) f = REAL(n - 1, wp)/(t1 - t0) + END SUBROUTINE response + + SUBROUTINE write_deck(path, cl, window, dtm) + !! 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 + INTEGER :: u + 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) + WRITE (cl_txt, '(F4.2)') cl + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') '--------------------- CableDyn Input File ---' + WRITE (u, '(A)') 'coupled VIV gate: taut riser and cable in a host cross current' + WRITE (u, '(A)') '--------------------- LINE TYPES ---' + WRITE (u, '(A)') 'TypeName Diam Mass/m EA BA/-zeta EI Cd Ca CdAx CaAx Cl dF cF' + WRITE (u, '(A)') '(name) (m) (kg/m) (N) (N-s/-) (-) (-) (-) (-) (-) (-) (-) (-)' + WRITE (u, '(A)') 'riser 0.10 10.0 5.0e7 -0.8 0.0 1.2 1.0 0.0 0.0 '//TRIM(cl_txt)//' 0.08 0.18' + WRITE (u, '(A)') 'cable 0.10 10.0 5.0e7 -0.8 1.0 1.2 1.0 0.0 0.0 '//TRIM(cl_txt)//' 0.08 0.18' + WRITE (u, '(A)') '--------------------- POINTS ---' + WRITE (u, '(A)') 'ID Attachment X Y Z M V CdA CA' + WRITE (u, '(A)') '(#) (-) (m) (m) (m) (kg) (m^3) (m^2) (-)' + WRITE (u, '(A)') '1 Coupled 0.0 0.0 -50.0 0 0 0 0' + WRITE (u, '(A)') '2 Fixed 100.0 0.0 -50.0 0 0 0 0' + WRITE (u, '(A)') '3 Coupled 0.0 20.0 -50.0 0 0 0 0' + WRITE (u, '(A)') '4 Fixed 100.0 20.0 -50.0 0 0 0 0' + 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 -' + WRITE (u, '(A)') '--------------------- OPTIONS ---' + WRITE (u, '(A)') '100.0 WtrDpth' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '9.80665 g' + tw = 0.25_wp + IF (PRESENT(window)) tw = window + IF (tw > 0.0_wp) WRITE (u, '(F6.3,A)') tw, ' VIVrmsWindow' + IF (PRESENT(dtm)) WRITE (u, '(ES12.5,A)') dtm, ' dtM' + WRITE (u, '(A)') '--------------------- need this line ---' + CLOSE (u) + END SUBROUTINE write_deck + + SUBROUTINE finish(agg) + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: agg + INTEGER :: es + CHARACTER(512) :: em + CALL CD_AGG_End(agg, es, em) + END SUBROUTINE finish + + SUBROUTINE check(ok, label) + LOGICAL, INTENT(IN) :: ok + CHARACTER(*), INTENT(IN) :: label + IF (ok) THEN + WRITE (*, '(2A)') ' ok ', label + ELSE + WRITE (*, '(2A)') ' FAIL ', label + nfail = nfail + 1 + END IF + END SUBROUTINE check + +END PROGRAM test_viv_coupled