diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cac311..6ef04ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,15 @@ All notable changes to CableDyn are recorded in this file. The format follows the cable in at its first mode (A/D 0.58 against 0.10 uncoupled) and the drag and damping take out the wake lift's power within 0.3 %. Its state is in the step-recovery, snapshot and checkpoint state; the Python deck reader and builder take the section. +- Amplitude-dependent VIV coefficients: an optional `VIV AMPLITUDE` section, rows + `TypeName AD Cv [CdAmp]`, gives a line type a table over the cross-flow amplitude ratio of the + coefficient `Cv` that replaces its `Cl` and a factor `CdAmp` of its normal drag coefficient, read + at the amplitude estimate of Thorsen et al. (2016, Eq. 8 and 9) of each node, on `EI = 0` lines + and finite-EI cables, standalone and coupled. `VIVAmpN` writes the estimate. On the taut + example line it follows the steady response amplitude within 0.03 %, a falling `Cv` limits the + response inside its falling range, and a table with `Cv = Cl` and `CdAmp = 1` is the line + without it, bit for bit. The estimate is in the step-recovery, snapshot and checkpoint state; + the Python deck reader and builder take the section. - Load power channels `VIVPow`, `DragPow` and `DampPow` [W], and `N` per unit length about a node [W/m]: the power the VIV loads, the drag and the structural damping (`BA`, `Bb`) deliver to a line at the committed state, on `EI = 0` lines and finite-EI cables, diff --git a/CMakeLists.txt b/CMakeLists.txt index 6346dd5..1c134af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1330,6 +1330,20 @@ target_link_libraries(test_viv_wake_deck PRIVATE cabledyn_core) add_test(NAME viv_wake_deck COMMAND test_viv_wake_deck WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) set_tests_properties(viv_wake_deck PROPERTIES LABELS "fortran;integration;dynamic;viv" TIMEOUT 1200) +# VIV amplitude estimate (Thorsen et al. 2016, Eq. 8 and 9) and the amplitude tables. +add_executable(test_viv_amplitude_kernel tests/test_viv_amplitude_kernel.f90) +target_link_libraries(test_viv_amplitude_kernel PRIVATE cabledyn_core) +add_test(NAME viv_amplitude_kernel COMMAND test_viv_amplitude_kernel) +set_tests_properties(viv_amplitude_kernel PROPERTIES LABELS "fortran;unit;dynamic;viv") + +# Amplitude-dependent VIV coefficients on a deck (VIV AMPLITUDE section), both line kinds: the +# identity table, the amplitude channel against the response, self-limiting, drag amplification +# and the refusals. +add_executable(test_viv_amplitude_deck tests/test_viv_amplitude_deck.f90) +target_link_libraries(test_viv_amplitude_deck PRIVATE cabledyn_core) +add_test(NAME viv_amplitude_deck COMMAND test_viv_amplitude_deck WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) +set_tests_properties(viv_amplitude_deck PROPERTIES LABELS "fortran;integration;dynamic;viv" TIMEOUT 1200) + add_executable(test_hermite_viv tests/test_hermite_viv.f90) target_link_libraries(test_hermite_viv PRIVATE cabledyn_core) add_test(NAME hermite_viv COMMAND test_hermite_viv) diff --git a/doc/capabilities.rst b/doc/capabilities.rst index 16c9d3c..28b3690 100644 --- a/doc/capabilities.rst +++ b/doc/capabilities.rst @@ -155,6 +155,12 @@ Line and constitutive capability - the van der Pol wake oscillator of Facchinetti et al. (2004) with acceleration coupling, distributed along finite-EI cables in place of the synchronisation model (:ref:`theory-viv-wake`), its state in the checkpoint + * - Amplitude-dependent VIV coefficients (``VIV AMPLITUDE`` section ``AD``, ``Cv``, ``CdAmp``) + - Standalone and coupled + - a table over the cross-flow amplitude of the synchronisation coefficient and a drag + factor, read at the amplitude estimate of Thorsen et al. (2016) (``VIVAmp`` channel), on + ``EI = 0`` lines and finite-EI cables (:ref:`theory-viv-amplitude`), its state in the + checkpoint Loads and environment --------------------- diff --git a/doc/driver_format.md b/doc/driver_format.md index 919c972..97d81fb 100644 --- a/doc/driver_format.md +++ b/doc/driver_format.md @@ -298,7 +298,8 @@ the half-range and centre of its band in non-dimensional frequency (MoorDyn's `d `0 <= dF < cF`, and the line's drag in water. It acts in the dynamics on `EI = 0` lines and finite-EI cables (see [Cross-flow VIV](theory.rst)). The in-line force of a type is a [VIV](#viv-optional) section row; a [WAKE OSCILLATOR](#wake-oscillator-optional) row replaces the -lift by a wake oscillator. +lift by a wake oscillator, and a [VIV AMPLITUDE](#viv-amplitude-optional) table makes `Cl` (and +`Cd`) depend on the cross-flow amplitude. **Viscoelastic axial stiffness (MoorDyn `ElasticMod`).** The EA and BA columns accept bar-separated parts: @@ -1239,6 +1240,55 @@ Behaviour: type, or holds a value out of range; `CL0 > 0` fails on a type with `Cl > 0`. A line whose types mix the two models fails, and so does an `EI = 0` line with the wake oscillator. +### VIV AMPLITUDE (optional) + +Amplitude-dependent coefficients of the synchronisation model of a line type (Thorsen et al. +2016): a table over the cross-flow amplitude ratio A/D of the coefficient `Cv` that replaces the +type's LINE TYPES `Cl`, and of a factor `CdAmp` of its normal drag coefficient `Cd` (see +[Amplitude-dependent coefficients](theory.rst)). The rows of one type follow each other in +increasing A/D. + +```text +--------------------- VIV AMPLITUDE ------------------------------------ +TypeName AD Cv CdAmp +(-) (-) (-) (-) +riser 0.0 0.8 1.0 +riser 0.3 0.9 1.5 +riser 0.6 0.0 2.0 +``` + +| Column | Meaning | +|--------|---------| +| `TypeName` | an existing LINE TYPES name (case-insensitive) whose `Cl > 0` | +| `AD` | amplitude ratio A/D >= 0 of the row, strictly increasing over the type's rows | +| `Cv` | cross-flow coefficient >= 0 at that amplitude, in place of `Cl` | +| `CdAmp` | optional factor > 0 of the type's normal drag coefficient at that amplitude (default 1) | + +Behaviour: + +- Each node estimates its cross-flow amplitude as Thorsen et al. do (their Eq. 8 and 9): half the + travel of the node across the ambient flow between two zero crossings of its cross-flow + velocity, smoothed by a tenth of the difference at every time step. An element takes the mean of + its free nodes over its diameter as A/D (the one free node next to a fixed end or anchor), and + from its table `Cv` (for the lift) and `CdAmp` + (times `Cd`, for the normal Morison drag), linear between rows and held beyond the first and + last. The coefficients of a step use the estimate of the committed state. The estimate starts + at 0, and the static equilibrium takes the type's own `Cd`, so a table whose `CdAmp` at A/D 0 + is not 1 starts the run off that equilibrium. +- `VIVAmpN` (OUTPUTS) is the smoothed amplitude of node J [m]. +- A table whose `Cv` falls to zero above some A/D limits the response there (Thorsen et al. fit + such a curve to riser tests, their Fig. 7). `CdAmp` gives the drag amplification of a vibrating + cylinder, for example Chaplin et al. (2005, Eq. 4), `Cd/Cd0 = 1 + 2.3 s + 1.7 s^2` with the + r.m.s. cross-flow displacement `s = (A/D)/sqrt(2)` of a harmonic response. +- The estimate assumes a narrow-band response, as theirs does. With the in-line VIV of a `VIV` + section row, `ClX` and `Chh` stay constant. The estimate is part of the step-recovery, snapshot + and checkpoint state. A table with `Cv = Cl` and `CdAmp = 1` throughout runs as the type + without it. +- It acts on `EI = 0` lines and finite-EI cables, standalone and coupled. A row fails if it is not + `TypeName AD Cv [CdAmp]`, names an undefined type or one without the synchronisation lift + (`Cl = 0`, as a wake-oscillator type), holds a value out of range, does not increase in `AD`, + or has other columns than the type's earlier rows; a type takes 2 to 32 rows. + ### FAILURE (optional, EI = 0 decks) A FAILURE row detaches line ends from a point during a dynamic run, with MoorDyn's trigger rules. @@ -1713,6 +1763,7 @@ bending moment. None of these channels is mandatory. | `DragPow` | line L power of the Morison drag (and, on a finite-EI line, its ATTACHMENTS' drag) | W | | `DampPow` | line L power of the structural damping (`BA`, and `EI|Bb` on a finite-EI line); never positive | W | | `VIVPowN`, `DragPowN`, `DampPowN` | the same per unit unstretched length about node J (node J's share: half of each of its elements' power and its own node loads', over half their unstretched length) | W/m | +| `VIVAmpN` | line L smoothed cross-flow amplitude estimate at node J (Thorsen et al. 2016, Eq. 9), which a [VIV AMPLITUDE](#viv-amplitude-optional) table reads; only on a line with such a table; 0 at a node without VIV | m | - ``/`

` are deck LINE/POINT **ids**, not array positions. A channel that matches no supported form, names an unknown id, or carries trailing text (for example `Point2px_raw`) is a diff --git a/doc/outputs.rst b/doc/outputs.rst index 1e8fb1a..988ff65 100644 --- a/doc/outputs.rst +++ b/doc/outputs.rst @@ -918,6 +918,15 @@ three balance within 0.5 % of the VIV power, the line's loss of energy over the response settles, and as an ``EI = 0`` line the same. Integrating a channel over the output times gives the work of its load, :math:`W = \int P\,dt`; a static run reports 0. +VIV amplitude channel +~~~~~~~~~~~~~~~~~~~~~ + +``VIVAmpN`` [m] is the smoothed cross-flow amplitude estimate of node ``J`` of line ``L``, +the amplitude at which a ``VIV AMPLITUDE`` table reads the coefficients of the node's elements +(:ref:`theory-viv-amplitude`): half the node's travel across the ambient flow between two zero +crossings of its cross-flow velocity, smoothed over about ten time steps. It is requested only on +a line with such a table, and is 0 at a node without VIV and in a static run. + Point channels ~~~~~~~~~~~~~~ diff --git a/doc/theory.rst b/doc/theory.rst index bda864e..cff755e 100644 --- a/doc/theory.rst +++ b/doc/theory.rst @@ -1292,6 +1292,50 @@ steady mid-span A/D of 0.58; with :math:`A` = 0 the uncoupled wake drives it at 0.10, and over the lock-in the drag and damping take out the wake lift's power within 0.3 %. The wake oscillator acts on finite-EI cables, cross-flow only. +.. _theory-viv-amplitude: + +Amplitude-dependent coefficients +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +A ``VIV AMPLITUDE`` table makes the cross-flow coefficient of the synchronisation model and the +normal drag coefficient of a line type functions of the cross-flow amplitude, the form of +:ref:`Thorsen et al. (2016) `, who fit an excitation curve +:math:`C_v(y_0/D)` to riser tests. Each node estimates its amplitude as they do (their Eq. 8 and +9): + +.. math:: + + y_0 = \frac{1}{2}\int_{t_1}^{t_2} |\dot y|\,\mathrm{d}t, \qquad + \frac{\mathrm{d}y_0^*}{\mathrm{d}t} = k_a\,(y_0 - y_0^*), \quad k_a = \frac{0.1}{\Delta t}, + +with :math:`t_1, t_2` the last two zero crossings of :math:`\dot y` (a narrow-band response +travels :math:`2y_0` between them) and :math:`y_0^*` the smoothed amplitude, which moves a tenth +of the way to :math:`y_0` in each time step :math:`\Delta t`. :math:`\dot y` is the node's +velocity across the ambient flow normal to the line, :math:`\dot{\mathbf r}\cdot(\mathbf t\times +\mathbf u_n)/|\mathbf u_n|`: their :math:`y` is measured across the incoming flow, and the +cross-flow axis of the phase, across the relative flow, turns with the node's own velocity, which +at a response velocity comparable to the flow would shorten the projected velocity by +:math:`U/|\mathbf v_n|` (16 % at the A/D of 0.68 of the gate below). The travel is integrated by +the trapezoidal rule over each step, with a crossing inside a step placed by linear interpolation; +the error is that of the rule, :math:`(\omega\Delta t)^2/12` relative for a harmonic response. +The travel is carried signed, :math:`\int\dot y\,\mathrm{d}t` since the last crossing, whose sign +is that of the half cycle: a velocity that reverses through a sample at zero ends the half cycle +there, and one that touches zero without a sign change ends none. + +An element takes the mean :math:`y_0^*` of its free nodes (the VIV nodes; a fixed end node has +none) over its diameter as :math:`A/D` and reads its table there: :math:`C_v` in place of ``Cl`` in the lift, and a factor of ``Cd`` in the +normal Morison drag, linear between rows and held beyond the end ones. The coefficients of a step +use the estimate of the committed state, so the Jacobians only scale. The estimate is updated at +the end of each converged step from the committed one, so a repeated or rewound step updates it +once, and it is part of the step-recovery, snapshot and checkpoint state. + +On the taut line of the wake-oscillator gate (Cl 0.8, ``EI = 0`` and finite-EI alike) the +smoothed mid-span estimate follows the half peak-to-peak cross-flow displacement of the steady +response within 0.03 % at A/D 0.68; a table whose :math:`C_v` falls from 0.8 at A/D 0.1 to zero +at 0.3 holds the response at A/D 0.28; :math:`C_v = 0` with a drag factor 2 settles at the static +offset of ``Cd`` 2.4 to six digits; and a table with :math:`C_v` = ``Cl`` and factor 1 is the +line without it, bit for bit. + .. _theory-dry-buoyancy: Buoyancy and wetting diff --git a/python/cabledyn/builder.py b/python/cabledyn/builder.py index 8eb564e..518a3fa 100644 --- a/python/cabledyn/builder.py +++ b/python/cabledyn/builder.py @@ -114,7 +114,9 @@ ("line", re.compile(r"(tdp)([0-9]+)(s|x|y|z|lay|exc|grd)", re.IGNORECASE)), ( "line", - re.compile(r"(ten|curvx|curvy|curv|bendmom|stfmom|torq)([0-9]+)(n[0-9]+)", re.IGNORECASE), + re.compile( + r"(ten|curvx|curvy|curv|bendmom|stfmom|torq|vivamp)([0-9]+)(n[0-9]+)", re.IGNORECASE + ), ), ("line", re.compile(r"(twist)([0-9]+)(n[0-9]+|)", re.IGNORECASE)), ("line", re.compile(r"(vivpow|dragpow|damppow)([0-9]+)(n[0-9]+|)", re.IGNORECASE)), @@ -227,6 +229,13 @@ class LineType: synchronisation lift, so ``cl`` stays ``None`` or 0, and acts on finite-EI cables. ``None`` leaves a trailing value out of the row (the solver takes 0.2, 0.3 and 12); a value given writes the ones before it. + viv_amplitude : list of tuples | None + Optional amplitude-dependent VIV coefficients of a type (Thorsen et al. + 2016), the rows of a ``VIV AMPLITUDE`` section table ``Name AD Cv + [CdAmp]`` as ``(AD, Cv)`` or ``(AD, Cv, CdAmp)`` tuples, all of one + length, 2 to 32 of them in increasing amplitude ratio ``AD``: ``Cv`` + replaces ``cl`` at that amplitude (so ``cl`` must be set) and ``CdAmp`` + multiplies the normal drag coefficient ``cdn`` (1 when left out). """ name: str @@ -253,6 +262,7 @@ class LineType: wake_st: float | None = None wake_eps: float | None = None wake_a: float | None = None + viv_amplitude: list[tuple[float, ...]] | None = None @dataclass(eq=False) @@ -1676,6 +1686,7 @@ def add_line_type( wake_st: float | None = None, wake_eps: float | None = None, wake_a: float | None = None, + viv_amplitude: list[tuple[float, ...]] | None = None, ) -> LineType: """Add a ``LINE TYPES`` row; see :class:`LineType` for the fields. @@ -1716,6 +1727,7 @@ def add_line_type( wake_st, wake_eps, wake_a, + None if viv_amplitude is None else [tuple(row) for row in viv_amplitude], ) self._line_types.append(item) return item @@ -2608,6 +2620,7 @@ def to_text(self, *, validate: bool = True) -> str: _emit(out, "STIFFENERS", *self._stiffener_table()) _emit(out, "VIV", *self._viv_table()) _emit(out, "WAKE OSCILLATOR", *self._wake_table()) + _emit(out, "VIV AMPLITUDE", *self._viv_amp_table()) _emit(out, "FAILURE", *self._failure_table()) _emit(out, "CONTROL", *self._control_table()) _emit(out, "EXTERNAL LOADS", *self._external_load_table()) @@ -3008,6 +3021,26 @@ def _wake_table(self) -> tuple[str, str, list[list[str]]]: rows.append(row) return "Name CL0 St eps A", "(-) (-) (-) (-) (-)", rows + def _viv_amp_table(self) -> tuple[str, str, list[list[str]]]: + rows: list[list[str]] = [] + for item in self._line_types: + if item.viv_amplitude is None: + continue + what = f"line type {item.name!r}" + table = list(item.viv_amplitude) + if not table: + raise ValueError(f"{what}: viv_amplitude needs at least two rows") + widths = {len(row) for row in table} + if len(widths) != 1 or not widths <= {2, 3}: + raise ValueError( + f"{what}: viv_amplitude rows are (AD, Cv) or (AD, Cv, CdAmp), all of one length" + ) + if item.cl is None: + raise ValueError(f"{what}: viv_amplitude scales the synchronisation lift, set cl") + for row in table: + rows.append([_text(item.name, what), *(_num(value, what) for value in row)]) + return "Name AD Cv CdAmp", "(-) (-) (-) (-)", rows + def _syrope_table(self) -> tuple[str, str, list[list[str]]]: rows = [ [_line_list(row.lines), _num(row.tmax0, "SYROPE IC"), _num(row.tmean0, "SYROPE IC")] @@ -3219,6 +3252,12 @@ def load(self) -> None: item.wake_st = _f(t[2]) if len(t) >= 3 else None item.wake_eps = _f(t[3]) if len(t) >= 4 else None item.wake_a = _f(t[4]) if len(t) == 5 else None + for row in self.rows("VIV AMPLITUDE"): + t = row.tokens + item = model.line_types[t[0]] + if item.viv_amplitude is None: + item.viv_amplitude = [] + item.viv_amplitude.append(tuple(_f(token) for token in t[1:])) for row in self.rows("ATTACHMENTS"): t = row.tokens arc: float | tuple[float, float, float] diff --git a/python/cabledyn/deck_file.py b/python/cabledyn/deck_file.py index b8b165b..292cd91 100644 --- a/python/cabledyn/deck_file.py +++ b/python/cabledyn/deck_file.py @@ -82,6 +82,8 @@ "WAKE OSCILLATOR": "WAKE OSCILLATOR", "WAKE OSCILLATORS": "WAKE OSCILLATOR", "WAKE": "WAKE OSCILLATOR", + "VIV AMPLITUDE": "VIV AMPLITUDE", + "VIV AMPLITUDES": "VIV AMPLITUDE", } # Table sections whose rows the native reader takes through a Fortran # list-directed READ. Their descriptive and units rows are recognized by the @@ -104,7 +106,16 @@ # Table sections the native reader splits on whitespace and parses column by # column (their comma-separated line lists are valid there). _WHITESPACE_TABLE_SECTIONS = frozenset( - {"FAILURE", "CONTROL", "SYROPE IC", "ATTACHMENTS", "STIFFENERS", "VIV", "WAKE OSCILLATOR"} + { + "FAILURE", + "CONTROL", + "SYROPE IC", + "ATTACHMENTS", + "STIFFENERS", + "VIV", + "WAKE OSCILLATOR", + "VIV AMPLITUDE", + } ) _TABLE_SECTIONS = _LIST_DIRECTED_SECTIONS | _WHITESPACE_TABLE_SECTIONS _NATIVE_RECORD_LENGTH = 512 @@ -766,6 +777,7 @@ def _parse_line_node_channel(lowered: str) -> tuple[int, int, int, int]: ("curv", 5), ("bendmom", 6), ("stfmom", 12), + ("vivamp", 21), ): if lowered.startswith(keyword): prefix = len(keyword) @@ -840,7 +852,19 @@ def _channel_identity_key(channel: str) -> str: component = ("s", "x", "y", "z", "lay", "exc", "grd").index(touchdown.group(2)) + 1 return f"tdp:{int(touchdown.group(1))}:{component}" if lowered.startswith( - ("ten", "curv", "bendmom", "stfmom", "l", "torq", "twist", "vivpow", "dragpow", "damppow") + ( + "ten", + "curv", + "bendmom", + "stfmom", + "l", + "torq", + "twist", + "vivpow", + "dragpow", + "damppow", + "vivamp", + ) ): line_id, node_id, kind, component = _parse_line_node_channel(lowered) if line_id > 0 and node_id > 0 and kind > 0: @@ -3320,6 +3344,81 @@ def _check_wake_section(self, lift_type_names: set[str]) -> set[str]: wake.add(name) return wake + def _check_viv_amp_section(self, lift_type_names: set[str]) -> set[str]: + """Native ``apply_type_viv_amp`` for the VIV AMPLITUDE section; the types with a table. + + Rows ``TypeName AD Cv [CdAmp]`` build a line type's amplitude table: the rows of a type + in strictly increasing ``AD >= 0``, ``Cv >= 0`` replacing the type's LINE TYPES ``Cl`` + and ``CdAmp > 0`` (default 1) multiplying its normal drag coefficient, each at most + 1e15, all rows of a type with the same columns, 2 to 32 rows. The type needs the + synchronisation lift (LINE TYPES ``Cl > 0``). + """ + types = {row.tokens[0].lower(): row.tokens[0] for row in self.line_types} + rows_of: dict[str, int] = {} + cols_of: dict[str, int] = {} + last_ad: dict[str, float] = {} + for row in self._rows("VIV AMPLITUDE"): + where = self._at(row) + if not 3 <= len(row.tokens) <= 4: + raise DeckFormatError( + f"{where}: VIV AMPLITUDE rows must be: TypeName AD Cv [CdAmp]" + ) + name = row.tokens[0].lower() + if name not in types: + raise DeckFormatError( + f'{where}: VIV AMPLITUDE row names undefined LINE TYPE "{row.tokens[0]}"' + ) + label = types[name] + if name not in lift_type_names: + raise DeckFormatError( + f'{where}: VIV AMPLITUDE of LINE TYPE "{label}" scales its synchronisation ' + "lift: give the type LINE TYPES Cl > 0" + ) + if name in rows_of and len(row.tokens) != cols_of[name]: + raise DeckFormatError( + f'{where}: the VIV AMPLITUDE rows of LINE TYPE "{label}" must all have the ' + "same columns" + ) + if rows_of.get(name, 0) >= 32: + raise DeckFormatError( + f'{where}: VIV AMPLITUDE gives LINE TYPE "{label}" more than 32 rows' + ) + values = [0.0, 0.0, 1.0] + try: + for index, token in enumerate(row.tokens[1:]): + values[index] = _native_float(token) + except ValueError as exc: + raise DeckFormatError( + f"{where}: VIV AMPLITUDE AD, Cv and CdAmp must be plain numbers" + ) from exc + if not all(math.isfinite(value) for value in values): + raise DeckFormatError(f"{where}: VIV AMPLITUDE AD, Cv and CdAmp must be finite") + ad, cv, cd_amp = values + if not ( + 0.0 <= ad <= _NATIVE_MAX_COEFFICIENT + and 0.0 <= cv <= _NATIVE_MAX_COEFFICIENT + and 0.0 < cd_amp <= _NATIVE_MAX_COEFFICIENT + ): + raise DeckFormatError( + f"{where}: VIV AMPLITUDE needs AD >= 0, Cv >= 0 and CdAmp > 0, each at most " + "1e15" + ) + if name in last_ad and not ad > last_ad[name]: + raise DeckFormatError( + f'{where}: the VIV AMPLITUDE rows of LINE TYPE "{label}" must increase ' + "strictly in AD" + ) + rows_of[name] = rows_of.get(name, 0) + 1 + cols_of[name] = len(row.tokens) + last_ad[name] = ad + for name, count in rows_of.items(): + if count == 1: + raise DeckFormatError( + f'{self._label}: VIV AMPLITUDE gives LINE TYPE "{types[name]}" one row: a ' + "table needs at least two" + ) + return set(rows_of) + def _legacy_rod_type_columns(self, record: DeckRecord) -> bool: """Return whether ``record`` sits under a legacy CableDyn ROD TYPES header. @@ -4498,6 +4597,12 @@ def end_key(token: str) -> str: self._check_stiffeners(line_ids, section_types_by_line, line_type_meta, line_lengths) self._check_viv_section(line_type_meta, viv_type_names) wake_type_names = self._check_wake_section(viv_type_names) + amp_type_names = self._check_viv_amp_section(viv_type_names) + amp_lines = { + line_id + for line_id, section_types in section_types_by_line.items() + if {line_type.lower() for line_type in section_types} & amp_type_names + } # native build_one_hermite_cable and the EI = 0 line wiring: the wake oscillator acts # on finite-EI cables only, and a cable takes one VIV model for line_id, section_types in section_types_by_line.items(): @@ -5525,6 +5630,34 @@ def is_body_kind(kind: str, pinned: bool) -> bool: "restrained (END CONNECTIONS TorsStiffness), so it carries no torque" ) continue + if lowered.startswith("vivamp"): + # native: VIVAmpN, the smoothed VIV amplitude estimate (VIV AMPLITUDE) + line_number, node_id, kind, _ = _parse_line_node_channel(lowered) + line_id = str(line_number) + if ( + node_id == 0 + and line_id in line_ids + and re.search(r"[0-9]n0(?![0-9])", lowered) is not None + ): + raise DeckFormatError( + f"{self._label}: OUTPUT {channel!r}: node numbers start at 1 = End A " + "(MoorDyn numbers from N0)" + ) + if line_id not in line_ids or kind == 0 or node_id < 1: + raise DeckFormatError( + f"{self._label}: OUTPUT {channel!r}: bad VIV amplitude channel (use " + "VIVAmpN, with a known line id)" + ) + if node_id > line_nelems[line_id] + 1: + raise DeckFormatError( + f"{self._label}: OUTPUT {channel!r} node exceeds the line node count" + ) + if line_id not in amp_lines: + raise DeckFormatError( + f"{self._label}: OUTPUT {channel!r}: line {line_id} has no VIV AMPLITUDE " + "table, so no amplitude estimate" + ) + continue if lowered.startswith(("vivpow", "dragpow", "damppow")): # native: VIVPow/DragPow/DampPow and N, the load power channels line_number, node_id, kind, _ = _parse_line_node_channel(lowered) diff --git a/python/tests/test_builder.py b/python/tests/test_builder.py index 5c9e019..c46fb84 100644 --- a/python/tests/test_builder.py +++ b/python/tests/test_builder.py @@ -239,6 +239,48 @@ def test_wake_oscillator_rows_are_written_with_the_values_given(tmp_path: Path) model.to_text(validate=False) +def test_viv_amplitude_rows_are_written_with_the_values_given(tmp_path: Path) -> None: + model = _chain_model(tmp_path) + model.add_line_type( + "cable", + diam=0.1, + mass=10.0, + ea=5.0e7, + ei=1.0, + cdn=1.2, + can=1.0, + cl=0.8, + viv_amplitude=[(0.0, 0.8), (0.3, 0.0)], + ) + model.add_line_type( + "riser", + diam=0.1, + mass=10.0, + ea=5.0e7, + cdn=1.2, + can=1.0, + cl=0.8, + viv_amplitude=[(0.0, 0.8, 1.0), (0.5, 0.9, 1.6), (1.0, 0.0, 2.0)], + ) + deck = DeckFile.from_text(model.to_text(validate=False), path=tmp_path / "deck.dat") + rows = [row.tokens for row in deck._rows("VIV AMPLITUDE")] + assert [row[0] for row in rows] == ["cable", "cable", "riser", "riser", "riser"] + assert [[float(value) for value in row[1:]] for row in rows[2:]] == [ + [0.0, 0.8, 1.0], + [0.5, 0.9, 1.6], + [1.0, 0.0, 2.0], + ] + model.add_line_type( + "mixed", diam=0.1, mass=10.0, ea=5.0e7, cl=0.8, viv_amplitude=[(0.0, 0.8, 1.0), (1.0, 0.8)] + ) + with pytest.raises(ValueError, match="all of one length"): + model.to_text(validate=False) + model.line_types["mixed"].viv_amplitude = [(0.0, 0.8), (1.0, 0.8)] + model.line_types["mixed"].cl = None + with pytest.raises(ValueError, match="set cl"): + model.to_text(validate=False) + + def test_build_spread_mooring_with_multi_section_lines() -> None: import math diff --git a/python/tests/test_deck_file.py b/python/tests/test_deck_file.py index aa3ab40..346b105 100644 --- a/python/tests/test_deck_file.py +++ b/python/tests/test_deck_file.py @@ -4902,6 +4902,72 @@ def test_wake_oscillator_rows_follow_the_native_checks(base, rows, message): DeckFile.from_text(_with_section(text, "WAKE OSCILLATOR", *rows)) +_LIFT_ROW = "chain 0.252 390.0 1.674e9 -1.0 1.0e4 1.37 0.64 1.0 0.0" + + +@pytest.mark.parametrize( + "rows, expected", + [ + (("chain 0.0 0.8", "chain 0.5 0.0"), [(0.0, 0.8), (0.5, 0.0)]), + ( + ("TypeName AD Cv CdAmp", "chain 0.0 0.8 1.0", "chain 0.4 0.9 1.5", "chain 1.0 0.0 2.0"), + [(0.0, 0.8, 1.0), (0.4, 0.9, 1.5), (1.0, 0.0, 2.0)], + ), + ], +) +def test_viv_amplitude_rows_are_read_and_kept(tmp_path, rows, expected): + from cabledyn import DeckModel + + text = _with_section(_edit(_DYNAMIC, (_LIFT_ROW, _LIFT_ROW + " 0.8")), "VIV AMPLITUDE", *rows) + DeckFile.from_text(text) + path = tmp_path / "amp.dat" + path.write_text(text, encoding="utf-8") + assert DeckModel.load(path).line_types["chain"].viv_amplitude == expected + saved = tmp_path / "saved.dat" + DeckModel.load(path).save(saved) + assert DeckModel.load(saved).line_types["chain"].viv_amplitude == expected + + +@pytest.mark.parametrize( + "lift, rows, message", + [ + (True, ("chain 0.0 0.8 1.0 2.0",), "rows must be: TypeName AD Cv [CdAmp]"), + (True, ("chain 0.0",), "rows must be: TypeName AD Cv [CdAmp]"), + (True, ("chain 0.0 x", "chain 1.0 0.8"), "must be plain numbers"), + (True, ("cable 0.0 0.8", "cable 1.0 0.8"), 'undefined LINE TYPE "cable"'), + (False, ("chain 0.0 0.8", "chain 1.0 0.8"), "give the type LINE TYPES Cl > 0"), + (True, ("chain 0.0 0.8 1.0", "chain 1.0 0.8"), "must all have the same columns"), + (True, ("chain 0.5 0.8", "chain 0.5 0.6"), "must increase strictly in AD"), + (True, ("chain -0.1 0.8", "chain 1.0 0.8"), "AD >= 0, Cv >= 0 and CdAmp > 0"), + (True, ("chain 0.0 -0.8", "chain 1.0 0.8"), "AD >= 0, Cv >= 0 and CdAmp > 0"), + (True, ("chain 0.0 0.8 0.0", "chain 1.0 0.8 1.0"), "AD >= 0, Cv >= 0 and CdAmp > 0"), + (True, ("chain 0.0 0.8",), "a table needs at least two"), + (True, tuple(f"chain {0.01 * k:.2f} 0.8" for k in range(33)), "more than 32 rows"), + ], +) +def test_viv_amplitude_rows_follow_the_native_checks(lift, rows, message): + text = _edit(_DYNAMIC, (_LIFT_ROW, _LIFT_ROW + " 0.8")) if lift else _DYNAMIC + with pytest.raises(DeckFormatError, match=re.escape(message)): + DeckFile.from_text(_with_section(text, "VIV AMPLITUDE", *rows)) + + +def test_viv_amplitude_channel_needs_a_table(): + text = _edit(_DYNAMIC, (_LIFT_ROW, _LIFT_ROW + " 0.8")) + text = _edit(text, ("FairTen1\n", "FairTen1\nVIVAmp1N2\n")) + with pytest.raises(DeckFormatError, match="has no VIV AMPLITUDE table"): + DeckFile.from_text(text) + DeckFile.from_text(_with_section(text, "VIV AMPLITUDE", "chain 0.0 0.8", "chain 1.0 0.4")) + with pytest.raises(DeckFormatError, match="bad VIV amplitude channel"): + DeckFile.from_text( + _with_section( + _edit(text, ("VIVAmp1N2\n", "VIVAmp9N2\n")), + "VIV AMPLITUDE", + "chain 0.0 0.8", + "chain 1.0 0.4", + ) + ) + + def test_wake_oscillator_cl0_zero_is_off_and_needs_no_finite_line(): # CL0 0 switches nothing on, so it is accepted on an EI = 0 line and next to a lift type text = _edit(_DYNAMIC, ("1.674e9 -1.0 1.0e4 1.37", "1.674e9 -1.0 0.0 1.37")) diff --git a/python/tests/test_end_to_end.py b/python/tests/test_end_to_end.py index ad2548c..5ed655d 100644 --- a/python/tests/test_end_to_end.py +++ b/python/tests/test_end_to_end.py @@ -285,6 +285,61 @@ def test_generated_study_runs_on_the_real_driver(tmp_path): ] +_AMP_OPTIONS = "--------------------- OPTIONS -----" +_AMP_CHANNEL = ('"DampPow1"', '"DampPow1"\n"VIVAmp1N26"') + + +def _amp_table(*rows: str) -> tuple[str, str]: + """The edit that puts a VIV AMPLITUDE section with ``rows`` before OPTIONS.""" + block = "--------------------- VIV AMPLITUDE -----\n" + "".join(f"{row}\n" for row in rows) + return _AMP_OPTIONS, block + _AMP_OPTIONS + + +_AMP_PARITY = [ + ("amp-accepted", [_amp_table("riser 0.0 0.8 1.0", "riser 0.5 0.4 1.5")], True), + ("amp-channel", [_amp_table("riser 0.0 0.8", "riser 0.5 0.4"), _AMP_CHANNEL], True), + ("amp-channel-no-table", [_AMP_CHANNEL], False), + ("amp-one-row", [_amp_table("riser 0.0 0.8")], False), + ("amp-not-increasing", [_amp_table("riser 0.5 0.8", "riser 0.5 0.4")], False), + ( + "amp-no-lift", + [ + _WAKE_LIFT, + _WAKE_SECTION, + ("riser 0.85 0.15", "riser 0.3"), + _amp_table("riser 0.0 0.8", "riser 0.5 0.4"), + ], + False, + ), +] + + +@pytest.mark.parametrize( + ("label", "edits", "accepted"), _AMP_PARITY, ids=[item[0] for item in _AMP_PARITY] +) +def test_viv_amplitude_validator_agrees_with_the_native_reader( + driver, tmp_path, label, edits, accepted +): + text = (EXAMPLES / "viv_taut_cable_inline.dat").read_text(encoding="utf-8") + for old, new in edits: + assert old in text, old + text = text.replace(old, new, 1) + deck = tmp_path / f"{label}.dat" + deck.write_text(text.replace("90.0 TMax", "2.0 TMax"), encoding="utf-8") + try: + DeckFile.read(deck) + python_accepts = True + except DeckFormatError: + python_accepts = False + try: + driver.run(deck, label, timeout=300) + native_accepts = True + except DriverExecutionError as exc: + assert exc.returncode == 1, exc.stderr # a deck error, not a solve failure + native_accepts = False + assert python_accepts == native_accepts == accepted + + @pytest.mark.parametrize( ("label", "edits", "accepted"), _WAKE_PARITY, ids=[item[0] for item in _WAKE_PARITY] ) diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index 8e8dc73..fa58aca 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -59,7 +59,8 @@ MODULE CableDyn_DeckDriver CD_Get_Model_EndForces, & CD_Update_Model_CoupledMotion, CD_Update_Model_Hydro_Fields, & CD_Recompute_Model_Acceleration, CD_Step_Model, CD_Step_Model_Recovering, CD_MODEL_OK, & - CD_Audit_Model_Step, CD_Set_Model_VIV, CD_Get_Model_VIV_Lift, CD_Get_Model_Load_Power + CD_Audit_Model_Step, CD_Set_Model_VIV, CD_Get_Model_VIV_Lift, CD_Get_Model_Load_Power, & + CD_Get_Model_VIV_Amplitude USE CableDyn_System, ONLY: CD_SystemType, CD_SystemPointType, CD_LineEndpointBinding, & CD_Init_System_From_Points, CD_End_System, CD_System_Line_NDOF, & CD_System_Line_NElem, CD_Get_System_Point_State, CD_Get_System_Line_State, & @@ -97,6 +98,7 @@ MODULE CableDyn_DeckDriver CD_HC_COMPRESSION_STRICT USE CableDyn_HermiteCableDynamic, ONLY: CD_HCDYN_OK, CD_HCDYN_TENSILE_OFF, CD_HCDYN_TENSILE_WARN, & CD_HCDYN_TENSILE_ERROR, CD_HermiteCable_Dyn_Load_Power, & + CD_HermiteCable_Dyn_VIV_Amplitude, & CD_HermiteCable_Axial_Damping_Resultant, & CD_HermiteCable_Axial_Damping_Element, CD_HermiteCable_Dyn_End_Force, & CD_HermiteCable_Dyn_Node_Values, CD_HermiteCable_Dyn_Node_Recovery, & @@ -137,7 +139,7 @@ MODULE CableDyn_DeckDriver CD_HFMF_Set_Moving_End_B, CD_HFMF_GetEndBKinematics, & CD_HFMF_End, CD_HFMF_OK USE CableDyn_VIV, ONLY: CD_VIV_DEFAULT_DF, CD_VIV_DEFAULT_CF, CD_VIV_NM, CD_VIV_DEFAULT_IL_ALPHA, & - CD_VIV_WAKE_DEFAULT_ST, CD_VIV_WAKE_DEFAULT_EPS, CD_VIV_WAKE_DEFAULT_A + CD_VIV_WAKE_DEFAULT_ST, CD_VIV_WAKE_DEFAULT_EPS, CD_VIV_WAKE_DEFAULT_A, CD_VIV_AMP_MAXP USE CableDyn_Hydro, ONLY: CD_Airy_Wave_Kinematics_Precomputed, CD_Component_Wave_Kinematics, & CD_Current_Profile_Velocity, CD_CurrentGridType, CD_Current_Grid_Resample, & CD_Current_Grid_Velocity, & @@ -460,6 +462,11 @@ MODULE CableDyn_DeckDriver REAL(wp) :: wo_cl0 = CD_ZERO, wo_st = CD_VIV_WAKE_DEFAULT_ST, wo_eps = CD_VIV_WAKE_DEFAULT_EPS REAL(wp) :: wo_a = CD_VIV_WAKE_DEFAULT_A LOGICAL :: has_wake_row = .FALSE. + ! Amplitude-dependent VIV coefficients (the optional VIV AMPLITUDE section, rows TypeName AD Cv + ! [CdAmp]): amp_n rows of (A/D, C_v, drag factor) in amp_tab, A/D increasing; amp_cols the + ! token count of the type's rows (3 or 4, the drag factor 1 with 3). + INTEGER :: amp_n = 0, amp_cols = 0 + REAL(wp) :: amp_tab(3, CD_VIV_AMP_MAXP) = CD_ZERO ! Deck file line of the row (0 when not read from a file), for error messages. INTEGER :: deck_line = 0 END TYPE @@ -1893,6 +1900,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, REAL(wp), ALLOCATABLE :: q_sequence(:) REAL(wp), ALLOCATABLE :: curv(:), cdn(:), cdt(:), can(:), cat(:), catenary_pos(:) REAL(wp), ALLOCATABLE :: viv_cl(:), viv_cf(:), viv_df(:), viv_clx(:), viv_al(:), viv_hh(:) + REAL(wp), ALLOCATABLE :: viv_tix(:), viv_amp3(:, :, :) + INTEGER, ALLOCATABLE :: viv_ampn(:) REAL(wp), ALLOCATABLE :: wo_cl0(:), wo_st(:), wo_eps(:), wo_a(:) REAL(wp), ALLOCATABLE :: ba_raw(:), ba(:), dry_b(:), bb_el(:) REAL(wp) :: mode1_omega @@ -3294,7 +3303,10 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, CALL finite_viv_arrays(ln, sections, types, viv_cl, viv_cf, viv_df, viv_clx, viv_al, viv_hh) ALLOCATE (wo_cl0(SIZE(l0)), wo_st(SIZE(l0)), wo_eps(SIZE(l0)), wo_a(SIZE(l0))) CALL finite_wake_arrays(ln, sections, types, wo_cl0, wo_st, wo_eps, wo_a) + ALLOCATE (viv_tix(SIZE(l0))) + CALL viv_amp_type_index(ln, sections, types, viv_tix) IF (SIZE(l0_am) /= SIZE(l0)) THEN + CALL remap_elem_by_reference_arc(viv_tix, l0, l0_am) CALL remap_elem_by_reference_arc(wo_cl0, l0, l0_am) CALL remap_elem_by_reference_arc(wo_st, l0, l0_am) CALL remap_elem_by_reference_arc(wo_eps, l0, l0_am) @@ -3622,6 +3634,8 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, ELSE CALL CD_Deck_VIV_Phase_Seed(cable%line%l0, ln%ends_swapped, seed, zero=opts%viv_phase_zero) END IF + ! the VIV AMPLITUDE tables, left unallocated (absent below) on a line without one + CALL viv_amp_tables(types, viv_tix, viv_amp3, viv_ampn) ! with the in-line VIV of the VIV section where a type has ClX > 0 IF (ANY(wo_cl0 > CD_ZERO)) THEN ! the wake oscillator: cl is C_L0, the band unused @@ -3637,13 +3651,13 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, REAL(CD_VIV_NM, wp)*MERGE(opts%dtM, dt, opts%has_dtm), & opts%viv_rms_window > CD_ZERO), es, em, phase_seed=seed, & tangent_reversed=.NOT. ln%ends_swapped, clx=viv_clx, il_alpha=viv_al, & - chh=viv_hh) + chh=viv_hh, amp=viv_amp3, amp_n=viv_ampn) 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, phase_seed=seed, & - tangent_reversed=.NOT. ln%ends_swapped) + tangent_reversed=.NOT. ln%ends_swapped, amp=viv_amp3, amp_n=viv_ampn) END IF END BLOCK IF (es /= CD_HCDYN_OK) THEN @@ -10401,6 +10415,8 @@ RECURSIVE SUBROUTINE init_one_model(ln, sections, types, points, opts, model, Er REAL(wp), ALLOCATABLE :: hydro_diam(:), hydro_cdn(:), hydro_cdt(:), hydro_can(:), hydro_cat(:) REAL(wp), ALLOCATABLE :: ve_ead(:), ve_bas(:), ve_bad(:), ve_ambl(:), ve_vbet(:) REAL(wp), ALLOCATABLE :: viv_cl(:), viv_cf(:), viv_df(:), viv_clx(:), viv_al(:), viv_hh(:) + REAL(wp), ALLOCATABLE :: viv_tix(:), viv_amp3(:, :, :) + INTEGER, ALLOCATABLE :: viv_ampn(:) LOGICAL, ALLOCATABLE :: syr_el(:) REAL(wp) :: anchor(3), fairlead(3), mode1_omega REAL(wp), PARAMETER :: factors(4) = [0.25_wp, 0.5_wp, 0.75_wp, CD_ONE] @@ -10439,7 +10455,9 @@ RECURSIVE SUBROUTINE init_one_model(ln, sections, types, points, opts, model, Er ALLOCATE (ba(SIZE(l0)), hydro_diam(SIZE(l0)), hydro_cdn(SIZE(l0)), hydro_cdt(SIZE(l0)), & hydro_can(SIZE(l0)), hydro_cat(SIZE(l0)), ve_ead(SIZE(l0)), ve_bas(SIZE(l0)), & ve_bad(SIZE(l0)), ve_ambl(SIZE(l0)), ve_vbet(SIZE(l0)), viv_cl(SIZE(l0)), viv_cf(SIZE(l0)), & - viv_df(SIZE(l0)), syr_el(SIZE(l0)), viv_clx(SIZE(l0)), viv_al(SIZE(l0)), viv_hh(SIZE(l0))) + viv_df(SIZE(l0)), syr_el(SIZE(l0)), viv_clx(SIZE(l0)), viv_al(SIZE(l0)), viv_hh(SIZE(l0)), & + viv_tix(SIZE(l0))) + viv_tix = CD_ZERO viv_cl = CD_ZERO viv_cf = CD_ZERO viv_df = CD_ZERO @@ -10511,6 +10529,8 @@ RECURSIVE SUBROUTINE init_one_model(ln, sections, types, points, opts, model, Er viv_clx(e) = types(line_section_type(sections, ln%id, i))%clx viv_al(e) = types(line_section_type(sections, ln%id, i))%il_alpha viv_hh(e) = types(line_section_type(sections, ln%id, i))%chh + IF (types(line_section_type(sections, ln%id, i))%amp_n > 0) viv_tix(e) = REAL(line_section_type(sections, & + ln%id, i), wp) syr_el(e) = types(line_section_type(sections, ln%id, i))%is_syrope END DO END DO @@ -10521,6 +10541,7 @@ RECURSIVE SUBROUTINE init_one_model(ln, sections, types, points, opts, model, Er viv_clx = viv_clx(SIZE(viv_clx):1:-1) viv_al = viv_al(SIZE(viv_al):1:-1) viv_hh = viv_hh(SIZE(viv_hh):1:-1) + viv_tix = viv_tix(SIZE(viv_tix):1:-1) ba = ba(SIZE(ba):1:-1) ve_ead = ve_ead(SIZE(ve_ead):1:-1) ve_bas = ve_bas(SIZE(ve_bas):1:-1) @@ -10810,14 +10831,17 @@ RECURSIVE SUBROUTINE init_one_model(ln, sections, types, points, opts, model, Er BLOCK REAL(wp) :: seed(model%n_dof/3) CALL CD_Deck_VIV_Phase_Seed(model%l0, ln%ends_swapped, seed, zero=opts%viv_phase_zero) + ! the VIV AMPLITUDE tables, left unallocated (absent below) on a line without one + CALL viv_amp_tables(types, viv_tix, viv_amp3, viv_ampn) ! with the in-line VIV of the VIV section where a type has ClX > 0 IF (ANY(viv_clx > CD_ZERO)) THEN CALL CD_Set_Model_VIV(model, opts%rhoW, viv_cl, hydro_diam, viv_cf, viv_df, tw, es, em, & phase_seed=seed, tangent_reversed=.NOT. ln%ends_swapped, clx=viv_clx, & - il_alpha=viv_al, chh=viv_hh) + il_alpha=viv_al, chh=viv_hh, amp=viv_amp3, amp_n=viv_ampn) ELSE CALL CD_Set_Model_VIV(model, opts%rhoW, viv_cl, hydro_diam, viv_cf, viv_df, tw, es, em, & - phase_seed=seed, tangent_reversed=.NOT. ln%ends_swapped) + phase_seed=seed, tangent_reversed=.NOT. ln%ends_swapped, amp=viv_amp3, & + amp_n=viv_ampn) END IF END BLOCK IF (es == CD_MODEL_OK) CALL CD_Recompute_Model_Acceleration(model, es, em) @@ -11684,6 +11708,63 @@ SUBROUTINE finite_wake_arrays(ln, sections, types, cl0, st, eps, a) a = a(SIZE(a):1:-1) END SUBROUTINE finite_wake_arrays + SUBROUTINE viv_amp_type_index(ln, sections, types, tix) + !! The LINE TYPES index of every element of a line whose type has a VIV AMPLITUDE table (0 + !! elsewhere), as a real per-element field for remap_elem_by_reference_arc, in the element order + !! of finite_hydro_arrays (the deck order reversed). + TYPE(DeckLine), INTENT(IN) :: ln + TYPE(DeckSection), INTENT(IN) :: sections(:) + TYPE(DeckLineType), INTENT(IN) :: types(:) + REAL(wp), INTENT(OUT) :: tix(:) + INTEGER :: i, j, e, tidx + e = 0 + DO i = 1, SIZE(sections) + IF (sections(i)%line_id /= ln%id) CYCLE + tidx = sections(i)%ltype + DO j = 1, sections(i)%nsegs + e = e + 1 + tix(e) = CD_ZERO + IF (types(tidx)%amp_n > 0) tix(e) = REAL(tidx, wp) + END DO + END DO + tix = tix(SIZE(tix):1:-1) + END SUBROUTINE viv_amp_type_index + + SUBROUTINE viv_amp_tables(types, tix, amp, ampn) + !! Allocate and fill the per-element amplitude tables (CD_Set_Model_VIV and + !! CD_HermiteCable_Dyn_Set_VIV amp, amp_n) from the element type indices of + !! viv_amp_type_index; left unallocated (so absent in those calls) when no element has one. + TYPE(DeckLineType), INTENT(IN) :: types(:) + REAL(wp), INTENT(IN) :: tix(:) + REAL(wp), ALLOCATABLE, INTENT(OUT) :: amp(:, :, :) + INTEGER, ALLOCATABLE, INTENT(OUT) :: ampn(:) + INTEGER :: e, t + IF (.NOT. ANY(tix > 0.5_wp)) RETURN + ALLOCATE (amp(3, CD_VIV_AMP_MAXP, SIZE(tix)), ampn(SIZE(tix))) + amp = CD_ZERO + ampn = 0 + DO e = 1, SIZE(tix) + t = NINT(tix(e)) + IF (t < 1) CYCLE + ampn(e) = types(t)%amp_n + amp(:, :, e) = types(t)%amp_tab + END DO + END SUBROUTINE viv_amp_tables + + LOGICAL FUNCTION line_has_viv_amp(ln, types, sections) RESULT(has) + !! Whether a section of the line uses a line type with a VIV AMPLITUDE table. + TYPE(DeckLine), INTENT(IN) :: ln + TYPE(DeckLineType), INTENT(IN) :: types(:) + TYPE(DeckSection), INTENT(IN) :: sections(:) + INTEGER :: j + has = .FALSE. + DO j = 1, SIZE(sections) + IF (sections(j)%line_id /= ln%id) CYCLE + IF (sections(j)%ltype < 1 .OR. sections(j)%ltype > SIZE(types)) CYCLE + IF (types(sections(j)%ltype)%amp_n > 0) has = .TRUE. + END DO + END FUNCTION line_has_viv_amp + LOGICAL FUNCTION line_has_viv(ln, types, sections) RESULT(has) !! Whether a section of the line uses a line type with a VIV lift coefficient Cl > 0. TYPE(DeckLine), INTENT(IN) :: ln @@ -13802,6 +13883,9 @@ SUBROUTINE parse_deck(path, types, bodies, rod_types, rods, points, lines, secti CHARACTER(DECK_RECLEN), ALLOCATABLE :: wake_rows(:) INTEGER, ALLOCATABLE :: wake_lines(:) INTEGER :: n_wake + CHARACTER(DECK_RECLEN), ALLOCATABLE :: vamp_rows(:) + INTEGER, ALLOCATABLE :: vamp_lines(:) + INTEGER :: n_vamp CHARACTER(2*NAMELEN), ALLOCATABLE :: channel_keys(:) LOGICAL :: ext_march, types_stock_cols, rodtypes_legacy_cols, turb_ok, static_finite_ok, tors_marched INTEGER :: unit, ios, section, nt, nb, nrt, nr, np, nlin, nsec, neq, nch, nfl, nct, nec, lineno @@ -13819,7 +13903,7 @@ SUBROUTINE parse_deck(path, types, bodies, rod_types, rods, points, lines, secti SEC_SECTIONS = 5, SEC_OPTIONS = 6, SEC_OUTPUTS = 7, SEC_RODTYPES = 8, SEC_RODS = 9, & SEC_EQUIV = 10, SEC_FAILURE = 11, SEC_CONTROL = 12, SEC_SYROPE_IC = 13, & SEC_ENDCONN = 14, SEC_TURBINES = 15, SEC_EXTLOADS = 16, SEC_ATTACH = 17, & - SEC_STIFF = 18, SEC_VIV = 19, SEC_WAKE = 20 + SEC_STIFF = 18, SEC_VIV = 19, SEC_WAKE = 20, SEC_VIVAMP = 21 ErrStat = 0; ErrMsg = '' ext_march = .FALSE. @@ -13844,6 +13928,8 @@ SUBROUTINE parse_deck(path, types, bodies, rod_types, rods, points, lines, secti ALLOCATE (viv_rows(0), viv_lines(0)) n_viv = 0 ALLOCATE (wake_rows(0), wake_lines(0)) + ALLOCATE (vamp_rows(0), vamp_lines(0)) + n_vamp = 0 n_wake = 0 nt = 0; nb = 0; nrt = 0; nr = 0; np = 0; nlin = 0; nsec = 0; neq = 0; nch = 0; nfl = 0; nct = 0; nec = 0 section = SEC_NONE @@ -13988,6 +14074,15 @@ SUBROUTINE parse_deck(path, types, bodies, rod_types, rods, points, lines, secti END IF wake_rows(n_wake) = line(1:MIN(LEN(line), DECK_RECLEN)) wake_lines(n_wake) = lineno + CASE (SEC_VIVAMP) + IF (.NOT. has_numeric_token(line)) CYCLE + n_vamp = n_vamp + 1 + IF (n_vamp > SIZE(vamp_rows)) THEN + vamp_rows = [vamp_rows, [(REPEAT(' ', DECK_RECLEN), i_ch=1, 8)]] + vamp_lines = [vamp_lines, [(0, i_ch=1, 8)]] + END IF + vamp_rows(n_vamp) = line(1:MIN(LEN(line), DECK_RECLEN)) + vamp_lines(n_vamp) = lineno CASE (SEC_OPTIONS) CALL apply_option(line, opts, ErrStat, ErrMsg) CASE (SEC_OUTPUTS) @@ -14099,6 +14194,19 @@ SUBROUTINE parse_deck(path, types, bodies, rod_types, rods, points, lines, secti RETURN END IF END DO + DO i_ch = 1, n_vamp + CALL apply_type_viv_amp(vamp_rows(i_ch), types, ErrStat, ErrMsg) + IF (ErrStat /= 0) THEN + CALL add_row_context('deck', vamp_lines(i_ch), vamp_rows(i_ch), ErrMsg) + RETURN + END IF + END DO + DO i_ch = 1, SIZE(types) + IF (types(i_ch)%amp_n == 1) THEN + CALL fail(ErrStat, ErrMsg, 'VIV AMPLITUDE gives LINE TYPE "'//TRIM(types(i_ch)%name)//'" one row: a '// & + 'table needs at least two'); RETURN + END IF + END DO ! Caller-supplied environment overrides land HERE -- before equivalent-buoyancy ! conversion and validation -- so both run under the environment the model is @@ -15767,6 +15875,8 @@ SUBROUTINE set_section(secname, section, ErrStat, ErrMsg) section = 18 CASE ('VIV', 'VORTEX-INDUCED VIBRATION', 'VORTEX INDUCED VIBRATION') section = 19 + CASE ('VIV AMPLITUDE', 'VIV AMPLITUDES') + section = 21 CASE ('WAKE OSCILLATOR', 'WAKE OSCILLATORS', 'WAKE') section = 20 CASE DEFAULT @@ -17430,6 +17540,72 @@ SUBROUTINE apply_type_wake(row, types, ErrStat, ErrMsg) types(it)%has_wake_row = .TRUE. END SUBROUTINE apply_type_wake + SUBROUTINE apply_type_viv_amp(row, types, ErrStat, ErrMsg) + !! One VIV AMPLITUDE row: TypeName AD Cv [CdAmp] -- a row of a line type's amplitude table, the + !! rows of a type in increasing amplitude ratio AD = A/D >= 0, the cross-flow coefficient + !! Cv >= 0 that replaces the type's LINE TYPES Cl at that amplitude, and the factor CdAmp > 0 + !! (default 1) of its normal drag coefficient; the rows of one type have the same columns. The + !! type needs the synchronisation lift (LINE TYPES Cl > 0). At most CD_VIV_AMP_MAXP rows a type. + CHARACTER(*), INTENT(IN) :: row + TYPE(DeckLineType), INTENT(INOUT) :: types(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + CHARACTER(DECK_RECLEN) :: tok + INTEGER :: it, ntok, i, n + REAL(wp) :: v(3) + LOGICAL :: found, ok + + ErrStat = 0; ErrMsg = '' + ntok = count_tokens(row) + IF (ntok < 3 .OR. ntok > 4) THEN + CALL fail(ErrStat, ErrMsg, 'VIV AMPLITUDE rows must be: TypeName AD Cv [CdAmp]'); RETURN + END IF + CALL get_token(row, 1, tok, found) + it = find_type(types, TRIM(tok)) + IF (it == 0) THEN + CALL fail(ErrStat, ErrMsg, 'VIV AMPLITUDE row names undefined LINE TYPE "'//TRIM(tok)//'"'); RETURN + END IF + IF (.NOT. (types(it)%cl > CD_ZERO)) THEN + CALL fail(ErrStat, ErrMsg, 'VIV AMPLITUDE of LINE TYPE "'//TRIM(types(it)%name)//'" scales its '// & + 'synchronisation lift: give the type LINE TYPES Cl > 0'); RETURN + END IF + IF (types(it)%amp_n > 0 .AND. ntok /= types(it)%amp_cols) THEN + CALL fail(ErrStat, ErrMsg, 'the VIV AMPLITUDE rows of LINE TYPE "'//TRIM(types(it)%name)// & + '" must all have the same columns'); RETURN + END IF + IF (types(it)%amp_n >= CD_VIV_AMP_MAXP) THEN + CALL fail(ErrStat, ErrMsg, 'VIV AMPLITUDE gives LINE TYPE "'//TRIM(types(it)%name)//'" more than 32 '// & + 'rows'); RETURN + END IF + v = [CD_ZERO, CD_ZERO, CD_ONE] + ok = .TRUE. + DO i = 2, ntok + IF (.NOT. ok) EXIT + CALL get_token(row, i, tok, found) + CALL parse_real_token(tok, v(i - 1), ok) + END DO + IF (.NOT. ok) THEN + CALL fail(ErrStat, ErrMsg, 'VIV AMPLITUDE AD, Cv and CdAmp must be plain numbers'); RETURN + END IF + IF (.NOT. ALL(IEEE_IS_FINITE(v))) THEN + CALL fail(ErrStat, ErrMsg, 'VIV AMPLITUDE AD, Cv and CdAmp must be finite'); RETURN + END IF + IF (.NOT. (v(1) >= CD_ZERO .AND. v(1) <= MAX_COEFFICIENT .AND. v(2) >= CD_ZERO .AND. & + v(2) <= MAX_COEFFICIENT .AND. v(3) > CD_ZERO .AND. v(3) <= MAX_COEFFICIENT)) THEN + CALL fail(ErrStat, ErrMsg, 'VIV AMPLITUDE needs AD >= 0, Cv >= 0 and CdAmp > 0, each at most 1e15'); RETURN + END IF + n = types(it)%amp_n + IF (n > 0) THEN + IF (.NOT. (v(1) > types(it)%amp_tab(1, n))) THEN + CALL fail(ErrStat, ErrMsg, 'the VIV AMPLITUDE rows of LINE TYPE "'//TRIM(types(it)%name)// & + '" must increase strictly in AD'); RETURN + END IF + END IF + types(it)%amp_n = n + 1 + types(it)%amp_cols = ntok + types(it)%amp_tab(:, n + 1) = v + END SUBROUTINE apply_type_viv_amp + SUBROUTINE append_line_stiffener(row, lines, ErrStat, ErrMsg) !! One STIFFENERS row: LineID End Length RootOD TipOD InnerD E Density -- a conical segment of !! the bend stiffener sleeving End A or End B of a finite-EI line. The rows of one line end @@ -18755,7 +18931,7 @@ FUNCTION channel_identity_key(ch) RESULT(key) IF (a > 0 .AND. b > 0) key = 'point:'//TRIM(int_to_str(a))//':'//TRIM(int_to_str(b)) ELSE IF (starts_with(lo, 'ten') .OR. starts_with(lo, 'curv') .OR. starts_with(lo, 'bendmom') .OR. & starts_with(lo, 'stfmom') .OR. starts_with(lo, 'l') .OR. starts_with(lo, 'torq') .OR. & - starts_with(lo, 'twist') .OR. is_load_power_channel(lo)) THEN + starts_with(lo, 'twist') .OR. is_load_power_channel(lo) .OR. starts_with(lo, 'vivamp')) THEN CALL parse_line_node_channel(ch, a, b, c, d) IF (a > 0 .AND. b > 0 .AND. c > 0) key = 'node:'//TRIM(int_to_str(a))//':'//TRIM(int_to_str(b))// & ':'//TRIM(int_to_str(c))//':'//TRIM(int_to_str(d)) @@ -35214,7 +35390,8 @@ SUBROUTINE build_plan() END IF ELSE CALL parse_line_node_channel(channels(j), il, node, kind, comp) - IF (is_load_power_kind(kind)) CYCLE ! from the line model, channel-at-a-time (CH_LEGACY) + ! from the line model, channel-at-a-time (CH_LEGACY) + IF (is_load_power_kind(kind) .OR. kind == 21) CYCLE il = find_line(lines, il) IF (il < 1) CYCLE CALL line_sizes(il, sized, tension_sized) @@ -35481,6 +35658,19 @@ SUBROUTINE system_channel_value(ch, lines, points, system, work, val, ErrStat, E END BLOCK RETURN END IF + IF (kind == 21) THEN + BLOCK + REAL(wp) :: amp(nnode) + CALL CD_Get_Model_VIV_Amplitude(system%lines(li), amp, es, em) + IF (es /= CD_MODEL_OK) THEN + ErrStat = CD_DECKDRV_SOLVEFAIL + ErrMsg = 'CableDyn_DeckDriver: system line VIV amplitude recovery failed: '//TRIM(em) + RETURN + END IF + val = amp(inode) + END BLOCK + RETURN + END IF IF (kind == 3) THEN CALL ensure_model_output_workspace(work, 0, nnode - 1) CALL CD_Get_System_Line_Tension(system, li, work%tension(1:nnode - 1), es, em) @@ -35636,6 +35826,19 @@ SUBROUTINE model_channel_value(ch, lines, points, models, work, val, ErrStat, Er END BLOCK RETURN END IF + IF (kind == 21) THEN + BLOCK + REAL(wp) :: amp(nnode) + CALL CD_Get_Model_VIV_Amplitude(models(li), amp, es, em) + IF (es /= CD_MODEL_OK) THEN + ErrStat = CD_DECKDRV_SOLVEFAIL + ErrMsg = 'CableDyn_DeckDriver: dynamic line VIV amplitude recovery failed: '//TRIM(em) + RETURN + END IF + val = amp(inode) + END BLOCK + RETURN + END IF IF (kind == 3) THEN CALL ensure_model_output_workspace(work, 0, nnode - 1) CALL CD_Get_Model_Tension(models(li), work%tension(1:nnode - 1), es, em) @@ -37078,6 +37281,27 @@ SUBROUTINE check_channel(ch, lines, points, sections, ErrStat, ErrMsg, bodies, r CALL fail(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": line '//TRIM(int_to_str(line_id))//' is not '// & 'torsionally restrained (END CONNECTIONS TorsStiffness), so it carries no torque'); RETURN END IF + ELSE IF (starts_with(lo, 'vivamp')) THEN + CALL parse_line_node_channel(ch, line_id, node, kind, comp) + li = find_line(lines, line_id) + IF (li /= 0 .AND. node == 0 .AND. names_node_zero(lo)) THEN + CALL fail(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": node numbers start at 1 = End A (MoorDyn '// & + 'numbers from N0)'); RETURN + END IF + IF (li == 0 .OR. kind == 0 .OR. node < 1) THEN + CALL fail(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": bad VIV amplitude channel (use VIVAmpN, '// & + 'with a known line id)'); RETURN + END IF + nelem = line_nelem_from_sections(lines(li)%id, sections) + IF (node > nelem + 1) THEN + CALL fail(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": node index exceeds line node count'); RETURN + END IF + IF (PRESENT(types)) THEN + IF (.NOT. line_has_viv_amp(lines(li), types, sections)) THEN + CALL fail(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": line '//TRIM(int_to_str(line_id))//' has no '// & + 'VIV AMPLITUDE table, so no amplitude estimate'); RETURN + END IF + END IF ELSE IF (is_load_power_channel(lo)) THEN CALL parse_line_node_channel(ch, line_id, node, kind, comp) li = find_line(lines, line_id) @@ -37126,7 +37350,7 @@ SUBROUTINE check_channel(ch, lines, points, sections, ErrStat, ErrMsg, bodies, r 'Point

p{x,y,z} (alias Con

p{x,y,z}), Point

F{x,y,z,H}, '// & 'TenN, CurvN, CurvXN, CurvYN, BendMomN, StfMomN, '// & 'TorqN, TwistN, Twist, '// & - 'VIVPow, DragPow, DampPow (and N), '// & + 'VIVPow, DragPow, DampPow (and N), VIVAmpN, '// & 'LNp{x,y,z}, LNv{x,y,z}, LNa{x,y,z}, LNDec, LNAzi, '// & 'TDP{s,x,y,z,Lay,Exc,Grd}, or the Body/Rod channels)'); RETURN END IF @@ -37389,6 +37613,7 @@ SUBROUTINE parse_line_node_channel(ch, line_id, node_id, kind, comp) !! DragPowN -> kind=18, comp=0 the same per unit length about node J [W/m] !! DampPow -> kind=19, comp=0 power of the structural damping (node 1) [W] !! DampPowN -> kind=20, comp=0 the same per unit length about node J [W/m] + !! VIVAmpN -> kind=21, comp=0 smoothed VIV amplitude estimate (VIV AMPLITUDE) [m] CHARACTER(*), INTENT(IN) :: ch INTEGER, INTENT(OUT) :: line_id, node_id, kind, comp @@ -37441,6 +37666,10 @@ SUBROUTINE parse_line_node_channel(ch, line_id, node_id, kind, comp) CALL parse_keyword_line_node(lo, 6, last, line_id, node_id) IF (line_id > 0 .AND. node_id > 0) kind = 12 RETURN + ELSE IF (starts_with(lo, 'vivamp')) THEN + CALL parse_keyword_line_node(lo, 6, last, line_id, node_id) + IF (line_id > 0 .AND. node_id > 0) kind = 21 + RETURN ELSE IF (is_load_power_channel(lo)) THEN ! the load power channels: the line total (node 1, as Twist), or the power per ! unit length about a node N (the next kind) @@ -39360,6 +39589,17 @@ SUBROUTINE eval_system_line_channel(system, li, ch, val, ErrStat, ErrMsg) END BLOCK RETURN END IF + IF (kind == 21) THEN + BLOCK + REAL(wp) :: amp(nnode) + CALL CD_Get_Model_VIV_Amplitude(system%lines(li), amp, es, em) + IF (es /= CD_MODEL_OK) THEN + CALL sys_solvefail(ch, em, ErrStat, ErrMsg); RETURN + END IF + val = amp(inode) + END BLOCK + RETURN + END IF IF (kind == 3) THEN BLOCK REAL(wp) :: tension(nnode - 1) @@ -39514,6 +39754,16 @@ SUBROUTINE eval_cable_channel(cable, ch, val, ErrStat, ErrMsg, mesh_node) END IF val = load_power_value(kind, inode, pv, pd, pm, cable%line%l0) END BLOCK + CASE (21) ! the smoothed VIV amplitude estimate of the node (VIV AMPLITUDE) + BLOCK + REAL(wp) :: amp(nnode) + CALL CD_HermiteCable_Dyn_VIV_Amplitude(cable%line, amp, es, em) + IF (es /= CD_HCDYN_OK) THEN + CALL fail_solve(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": finite-EI VIV amplitude recovery failed: '// & + TRIM(em)); RETURN + END IF + val = amp(inode) + END BLOCK CASE (3, 5, 6) ! nodal tension, curvature, bend moment CALL cable_recovered_value(cable, kind, inode, ch, val, ErrStat, ErrMsg) CASE (1) ! position (cable-local state rotated to the deck's global frame) @@ -39986,7 +40236,7 @@ FUNCTION CD_Channel_Unit(ch) RESULT(unit) !! OrcaFlex-vocabulary output unit for a channel token, by kind: tension (FairTen/AnchTen/Ten) !! and anchor force (AnchFz/AnchFH) -> (N); curvature (Curv) -> (1/m); bend moment (BendMom) !! -> (N.m); endpoint orientation/Dec/Azi -> (deg); torque (Torq) -> (N.m); twist (Twist) -> (deg); position (Point/...p) -> (m); - !! load power (VIVPow/DragPow/DampPow) -> (W), per unit length about a node -> (W/m); + !! load power (VIVPow/DragPow/DampPow) -> (W), per unit length about a node -> (W/m); VIVAmp -> (m); !! velocity (...v) -> (m/s); !! acceleration (...a) -> (m/s2). CHARACTER(*), INTENT(IN) :: ch @@ -40027,7 +40277,7 @@ FUNCTION CD_Channel_Unit(ch) RESULT(unit) CASE (10, 11); unit = '(deg)' CASE (15, 17, 19); unit = '(W)' CASE (16, 18, 20); unit = '(W/m)' - CASE (1); unit = '(m)' + CASE (1, 21); unit = '(m)' CASE (2); unit = '(m/s)' CASE (4); unit = '(m/s2)' CASE DEFAULT; unit = '(-)' diff --git a/src/CableDyn_HermiteCableDynamic.f90 b/src/CableDyn_HermiteCableDynamic.f90 index 6d4ef5c..23e309c 100644 --- a/src/CableDyn_HermiteCableDynamic.f90 +++ b/src/CableDyn_HermiteCableDynamic.f90 @@ -67,7 +67,9 @@ MODULE CableDyn_HermiteCableDynamic USE CableDyn_Linalg, ONLY: CD_Factor_Banded, CD_Solve_Factored_Banded, CD_LINALG_OK USE CableDyn_VIV, ONLY: CD_VIV_Lift_Per_Length, CD_VIV_Crossflow_Along, CD_VIV_Phase_Rate, CD_VIV_Mean_Square, & CD_VIV_Wrap_Phase, CD_VIV_TWO_PI, CD_VIV_NM, CD_VIV_Inline_Per_Length, & - CD_VIV_Inline_Phase_Rate, CD_VIV_Wake_Advance + CD_VIV_Inline_Phase_Rate, CD_VIV_Wake_Advance, CD_VIV_NMS, CD_VIV_NMS_AMP, & + CD_VIV_AMP_MAXP, CD_VIV_Amplitude_Update, CD_VIV_Table, CD_VIV_Check_Amp_Table, & + CD_VIV_Ambient_Crossflow_Rate USE CableDyn_Hydro, ONLY: CD_Morison_Drag_Per_Length_Jac, CD_Airy_Wave_Kinematics_Precomputed, & CD_Component_Wave_Kinematics, CD_Solve_Dispersion_Wavenumber, CD_HYDRO_OK USE CableDyn_SeabedContact, ONLY: CD_Seabed_Normal_Law, CD_Seabed_Contact_Gate, CD_SEABED_CONTACT_BLEND, & @@ -129,6 +131,7 @@ MODULE CableDyn_HermiteCableDynamic PUBLIC :: CD_HermiteCable_Drag_Element PUBLIC :: CD_HermiteCable_VIV_Lift_Element PUBLIC :: CD_HermiteCable_Dyn_Load_Power + PUBLIC :: CD_HermiteCable_Dyn_VIV_Amplitude PUBLIC :: CD_HermiteCable_Axial_Damping_Element PUBLIC :: CD_HermiteCable_Axial_Damping_Resultant PUBLIC :: CD_HermiteCable_AddedMass_Element @@ -353,7 +356,16 @@ MODULE CableDyn_HermiteCableDynamic LOGICAL :: viv_wake = .FALSE. REAL(wp), ALLOCATABLE :: wo_st(:), wo_eps(:), wo_a(:), wo_s(:, :), wo_q_eval(:), wo_ydd0(:), wo_om0(:) REAL(wp), ALLOCATABLE :: ws_recovery_wo_s(:, :), snap_wo_s(:, :) - REAL(wp), ALLOCATABLE :: Mgb(:, :) ! constant global mass (band) + ! Amplitude-dependent VIV coefficients (Set_VIV amp, amp_n; VIV AMPLITUDE section): per element + ! a table of viv_amp_n rows (A/D, C_v, drag factor) in viv_amp(:, 1:n, e). With it viv_ms carries + ! CD_VIV_NMS_AMP rows per node, the amplitude estimate of Thorsen et al. (2016) after the mean + ! squares (CD_VIV_Amplitude_Update; row 5 the smoothed amplitude); an element takes C_v in place + ! of cl and the factor of its normal drag coefficient at the mean smoothed amplitude of its VIV + ! nodes over its diameter. + LOGICAL :: has_viv_amp = .FALSE. + REAL(wp), ALLOCATABLE :: viv_amp(:, :, :) + INTEGER, ALLOCATABLE :: viv_amp_n(:) + REAL(wp), ALLOCATABLE :: Mgb(:, :) ! constant global mass (band) LOGICAL, ALLOCATABLE :: freemask(:), solve_mask(:) INTEGER, ALLOCATABLE :: fmap(:) ! free -> global DOF index REAL(wp), ALLOCATABLE :: q(:), v(:), a(:) ! dynamic state @@ -1111,7 +1123,7 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Friction_Axial(model, mu_axial, ErrStat, ErrM END SUBROUTINE CD_HermiteCable_Dyn_Set_Friction_Axial SUBROUTINE CD_HermiteCable_Dyn_Set_VIV(model, cl, cf, df, t_window, ErrStat, ErrMsg, phase_seed, tangent_reversed, & - clx, il_alpha, chh, wake) + clx, il_alpha, chh, wake, amp, amp_n) !! 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 @@ -1140,6 +1152,13 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_VIV(model, cl, cf, df, t_window, ErrStat, Err !! q'' + eps om (q^2 - 1) q' + om^2 q = (A/D) y'' at each lifting node (om = 2 pi St U/D, y'' !! its cross-flow acceleration); q starts on its limit cycle at the phase seed, q = 2 cos(phi_0) !! and q' = 0. + !! + !! Amplitude-dependent coefficients (both or neither; not with the wake oscillator): amp (3, + !! CD_VIV_AMP_MAXP, ne) and amp_n (ne), per element a table of amp_n rows (0: none; only where + !! cl > 0) of the amplitude ratio A/D >= 0 (strictly increasing), the cross-flow coefficient + !! C_v >= 0 that replaces cl, and the factor > 0 of the element's normal drag coefficient, at + !! the smoothed amplitude estimate of Thorsen et al. (2016); piecewise linear, held beyond the + !! end rows. TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model REAL(wp), INTENT(IN) :: cl(:), cf(:), df(:), t_window INTEGER, INTENT(OUT) :: ErrStat @@ -1151,10 +1170,14 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_VIV(model, cl, cf, df, t_window, ErrStat, Err LOGICAL, INTENT(IN), OPTIONAL :: tangent_reversed REAL(wp), INTENT(IN), OPTIONAL :: clx(:), il_alpha(:), chh(:) REAL(wp), INTENT(IN), OPTIONAL :: wake(:, :) - INTEGER :: e, k, ne, nn, es + REAL(wp), INTENT(IN), OPTIONAL :: amp(:, :, :) + INTEGER, INTENT(IN), OPTIONAL :: amp_n(:) + INTEGER :: e, k, ne, nn, es, nms REAL(wp) :: wsum, tw_old, rest_old - LOGICAL :: had_viv, had_il, want_il, had_wake, want_wake, bad_band + LOGICAL :: had_viv, had_il, want_il, had_wake, want_wake, bad_band, had_amp, want_amp CHARACTER(LEN=1024) :: em + REAL(wp), ALLOCATABLE :: p_amp(:, :, :) + INTEGER, ALLOCATABLE :: p_ampn(:) REAL(wp), ALLOCATABLE :: a_old(:), o_cl(:), o_k(:), o_cf(:), o_df(:), o_dn(:), o_phi(:), o_phi_eval(:), & o_rate(:), o_ms(:, :), o_ms_next(:, :), o_rec_phi(:), o_rec_ms(:, :), & o_snap_phi(:), o_snap_ms(:, :) @@ -1266,10 +1289,28 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_VIV(model, cl, cf, df, t_window, ErrStat, Err 'higher-harmonic force runs at the cross-flow plus in-line phase)'; RETURN END IF END IF + IF (PRESENT(amp) .NEQV. PRESENT(amp_n)) THEN + ErrStat = CD_HCDYN_BADINPUT + ErrMsg = 'CD_HermiteCable_Dyn_Set_VIV: the amplitude tables amp and amp_n go together'; RETURN + END IF + want_amp = .FALSE. + IF (PRESENT(amp)) THEN + CALL CD_VIV_Check_Amp_Table(amp, amp_n, cl, em) + IF (LEN_TRIM(em) > 0) THEN + ErrStat = CD_HCDYN_BADINPUT; ErrMsg = 'CD_HermiteCable_Dyn_Set_VIV: '//TRIM(em); RETURN + END IF + want_amp = ANY(amp_n > 0) + IF (want_amp .AND. want_wake) THEN + ErrStat = CD_HCDYN_BADINPUT + ErrMsg = 'CD_HermiteCable_Dyn_Set_VIV: the amplitude tables act on the synchronisation model, not the '// & + 'wake oscillator'; RETURN + END IF + END IF ! the previous configuration and state, kept for a rollback had_viv = model%has_viv had_il = model%has_viv_il had_wake = model%viv_wake + had_amp = model%has_viv_amp tw_old = model%viv_tw rest_old = model%viv_phi_rest a_old = model%a @@ -1283,11 +1324,18 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_VIV(model, cl, cf, df, t_window, ErrStat, Err IF (had_viv) CALL refresh_acceleration() RETURN END IF + nms = MERGE(CD_VIV_NMS_AMP, CD_VIV_NMS, want_amp) ALLOCATE (model%viv_cl(ne), model%viv_k(ne), model%viv_cf(nn), model%viv_df(nn), model%viv_dn(nn), & model%viv_phi(nn), & - model%viv_phi_eval(nn), model%viv_rate(nn), model%viv_ms(2, nn), model%viv_ms_next(2, nn), & - model%ws_recovery_viv_phi(nn), model%ws_recovery_viv_ms(2, nn), model%snap_viv_phi(nn), & - model%snap_viv_ms(2, nn), model%viv_node(nn)) + model%viv_phi_eval(nn), model%viv_rate(nn), model%viv_ms(nms, nn), model%viv_ms_next(nms, nn), & + model%ws_recovery_viv_phi(nn), model%ws_recovery_viv_ms(nms, nn), model%snap_viv_phi(nn), & + model%snap_viv_ms(nms, nn), model%viv_node(nn)) + IF (want_amp) THEN + ALLOCATE (model%viv_amp(3, CD_VIV_AMP_MAXP, ne), model%viv_amp_n(ne)) + model%viv_amp = amp + model%viv_amp_n = amp_n + model%has_viv_amp = .TRUE. + END IF model%viv_cl = cl model%viv_cf = CD_ZERO model%viv_df = CD_ZERO @@ -1400,6 +1448,7 @@ SUBROUTINE refresh_acceleration() model%has_viv = had_viv model%has_viv_il = had_il model%viv_wake = had_wake + model%has_viv_amp = had_amp model%viv_tw = tw_old model%viv_phi_rest = rest_old model%a = a_old @@ -1432,6 +1481,7 @@ SUBROUTINE move_viv(back) CALL MOVE_ALLOC(w_qe, model%wo_q_eval); CALL MOVE_ALLOC(w_y0, model%wo_ydd0) CALL MOVE_ALLOC(w_om, model%wo_om0); CALL MOVE_ALLOC(w_rec, model%ws_recovery_wo_s) CALL MOVE_ALLOC(w_snap, model%snap_wo_s) + CALL MOVE_ALLOC(p_amp, model%viv_amp); CALL MOVE_ALLOC(p_ampn, model%viv_amp_n) ELSE CALL MOVE_ALLOC(model%viv_cl, o_cl); CALL MOVE_ALLOC(model%viv_k, o_k) CALL MOVE_ALLOC(model%viv_cf, o_cf); CALL MOVE_ALLOC(model%viv_df, o_df) @@ -1454,6 +1504,7 @@ SUBROUTINE move_viv(back) CALL MOVE_ALLOC(model%wo_q_eval, w_qe); CALL MOVE_ALLOC(model%wo_ydd0, w_y0) CALL MOVE_ALLOC(model%wo_om0, w_om); CALL MOVE_ALLOC(model%ws_recovery_wo_s, w_rec) CALL MOVE_ALLOC(model%snap_wo_s, w_snap) + CALL MOVE_ALLOC(model%viv_amp, p_amp); CALL MOVE_ALLOC(model%viv_amp_n, p_ampn) END IF END SUBROUTINE move_viv END SUBROUTINE CD_HermiteCable_Dyn_Set_VIV @@ -1474,6 +1525,9 @@ SUBROUTINE clear_viv(model) IF (ALLOCATED(model%vhh_k)) DEALLOCATE (model%vhh_cx, model%vhh_k) IF (ALLOCATED(model%wo_s)) DEALLOCATE (model%wo_st, model%wo_eps, model%wo_a, model%wo_s, model%wo_q_eval, & model%wo_ydd0, model%wo_om0, model%ws_recovery_wo_s, model%snap_wo_s) + IF (ALLOCATED(model%viv_amp)) DEALLOCATE (model%viv_amp) + IF (ALLOCATED(model%viv_amp_n)) DEALLOCATE (model%viv_amp_n) + model%has_viv_amp = .FALSE. model%has_viv = .FALSE. model%has_viv_il = .FALSE. model%viv_wake = .FALSE. @@ -1504,6 +1558,65 @@ SUBROUTINE viv_drag_terms(model) END DO END SUBROUTINE viv_drag_terms + PURE REAL(wp) FUNCTION viv_elem_amplitude(model, e) RESULT(y0) + !! The smoothed cross-flow amplitude of element e [m]: the mean over its VIV end nodes (zero + !! without amplitude tables). + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + INTEGER, INTENT(IN) :: e + INTEGER :: k, n + y0 = CD_ZERO + IF (.NOT. model%has_viv_amp) RETURN + n = 0 + DO k = e, e + 1 + IF (.NOT. model%viv_node(k)) CYCLE + y0 = y0 + model%viv_ms(5, k) + n = n + 1 + END DO + IF (n > 1) y0 = y0/REAL(n, wp) + END FUNCTION viv_elem_amplitude + + PURE REAL(wp) FUNCTION elem_viv_k(model, e) RESULT(k) + !! The lift scale of element e: viv_k = 1/2 rho D Cl, or with an amplitude table 1/2 rho D C_v + !! with the table's C_v at the element's smoothed amplitude over its diameter. + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + INTEGER, INTENT(IN) :: e + INTEGER :: n + k = model%viv_k(e) + IF (.NOT. model%has_viv_amp) RETURN + n = model%viv_amp_n(e) + IF (n == 0) RETURN + k = 0.5_wp*model%rho_w*model%diam(e)*CD_VIV_Table(viv_elem_amplitude(model, e)/model%diam(e), & + model%viv_amp(1, 1:n, e), model%viv_amp(2, 1:n, e)) + END FUNCTION elem_viv_k + + PURE REAL(wp) FUNCTION elem_cdn(model, e) RESULT(cdn) + !! The normal drag coefficient of element e: cdn, times the drag factor of its VIV amplitude + !! table at the element's smoothed amplitude where it has one. + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + INTEGER, INTENT(IN) :: e + INTEGER :: n + cdn = model%cdn(e) + IF (.NOT. model%has_viv_amp) RETURN + n = model%viv_amp_n(e) + IF (n == 0) RETURN + cdn = cdn*CD_VIV_Table(viv_elem_amplitude(model, e)/model%diam(e), model%viv_amp(1, 1:n, e), & + model%viv_amp(3, 1:n, e)) + END FUNCTION elem_cdn + + REAL(wp) FUNCTION viv_node_ambient_yd(model, k) RESULT(yd) + !! Cross-flow velocity of node k across the ambient flow (current plus a held field) normal to + !! its tangent (the slope DOFs) at the committed state, the y' of the amplitude estimate + !! (CD_VIV_Ambient_Crossflow_Rate). + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + INTEGER, INTENT(IN) :: k + REAL(wp) :: uu(3) + INTEGER :: i0 + i0 = 6*(k - 1) + uu = model%current + IF (model%has_held_field) uu = uu + model%hf_u(:, k) + yd = CD_VIV_Ambient_Crossflow_Rate(model%q(i0 + 4:i0 + 6), model%v(i0 + 1:i0 + 3), uu) + END FUNCTION viv_node_ambient_yd + REAL(wp) FUNCTION viv_node_ambient_speed(model, k) RESULT(ua) !! Speed of the ambient flow (current plus a held field) normal to node k's tangent (the slope !! DOFs) at the committed state; 0 for a degenerate tangent. @@ -1623,7 +1736,7 @@ SUBROUTINE viv_step_end(model, dt) TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model REAL(wp), INTENT(IN) :: dt INTEGER :: k - REAL(wp) :: w, yd, ydd, un, ms1, ms2, rate_end, xd, xdd, rate_end_x, sw(2) + REAL(wp) :: w, yd, ydd, un, ms1, ms2, rate_end, xd, xdd, rate_end_x, sw(2), st(4), yda LOGICAL :: ok, il IF (model%viv_wake) THEN ! the wake state over the step with the cross-flow acceleration linear from its step-start @@ -1655,6 +1768,15 @@ SUBROUTINE viv_step_end(model, dt) rate_end_x = CD_ZERO IF (il) rate_end_x = model%vil_rate(k) CALL viv_node_motion(model, k, yd, ydd, un, ok, xd, xdd) + IF (model%has_viv_amp) THEN + ! the amplitude estimate over the step on the cross-flow velocity across the ambient flow; + ! a non-finite one holds y' (no crossing) + st = model%viv_ms(3:6, k) + yda = viv_node_ambient_yd(model, k) + IF (.NOT. CD_Is_Finite(yda)) yda = st(4) + CALL CD_VIV_Amplitude_Update(st, yda, dt) + model%viv_ms_next(3:6, k) = st + END IF IF (ok) THEN ms1 = CD_VIV_Mean_Square(model%viv_ms_next(1, k), yd, w) ms2 = CD_VIV_Mean_Square(model%viv_ms_next(2, k), ydd, w) @@ -1712,7 +1834,7 @@ SUBROUTINE viv_element_lift(model, q_cfg, v_cfg, e, flift, ErrStat, ErrMsg, djq, IF (model%viv_wake) THEN kn = model%viv_k(e)*[model%wo_q_eval(e), model%wo_q_eval(e + 1)] ELSE - kn = model%viv_k(e)*[COS(model%viv_phi_eval(e)), COS(model%viv_phi_eval(e + 1))] + kn = elem_viv_k(model, e)*[COS(model%viv_phi_eval(e)), COS(model%viv_phi_eval(e + 1))] END IF il = .FALSE. IF (model%has_viv_il) il = model%vil_k(e) > CD_ZERO @@ -1750,7 +1872,7 @@ SUBROUTINE element_drag_load(model, e, qe, ve, l0, t_eval, fdrag, ErrStat, ErrMs INTEGER :: es IF (model%has_wave .AND. model%wv_ncomp > 0) THEN CALL CD_HermiteCable_Drag_Element(qe, ve, l0, model%current, model%waterline_z, & - model%rho_w, model%diam(e), model%cdn(e), model%cdt(e), & + model%rho_w, model%diam(e), elem_cdn(model, e), model%cdt(e), & fdrag, ErrStat=es, ErrMsg=ErrMsg, & wv_depth=model%wv_depth, wv_dir=model%wv_dir, wv_t=t_eval, & wvc_amp=model%wv_ampc, wvc_om=model%wv_omc, & @@ -1758,7 +1880,7 @@ SUBROUTINE element_drag_load(model, e, qe, ve, l0, t_eval, fdrag, ErrStat, ErrMs wvc_e2kd=model%wv_e2kd) ELSE IF (model%has_wave) THEN CALL CD_HermiteCable_Drag_Element(qe, ve, l0, model%current, model%waterline_z, & - model%rho_w, model%diam(e), model%cdn(e), model%cdt(e), & + model%rho_w, model%diam(e), elem_cdn(model, e), model%cdt(e), & fdrag, ErrStat=es, ErrMsg=ErrMsg, & wv_h=model%wv_h, wv_om=model%wv_om, wv_k=model%wv_k, & wv_depth=model%wv_depth, wv_dir=model%wv_dir, wv_t=t_eval) @@ -1766,11 +1888,11 @@ SUBROUTINE element_drag_load(model, e, qe, ve, l0, t_eval, fdrag, ErrStat, ErrMs CALL CD_HermiteCable_Drag_Element(qe, ve, l0, & model%current + 0.5_wp*(model%hf_u(:, e) + model%hf_u(:, e + 1)), & 0.5_wp*(model%hf_wl(e) + model%hf_wl(e + 1)), & - model%rho_w, model%diam(e), model%cdn(e), model%cdt(e), & + model%rho_w, model%diam(e), elem_cdn(model, e), model%cdt(e), & fdrag, ErrStat=es, ErrMsg=ErrMsg) ELSE CALL CD_HermiteCable_Drag_Element(qe, ve, l0, model%current, model%waterline_z, & - model%rho_w, model%diam(e), model%cdn(e), model%cdt(e), & + model%rho_w, model%diam(e), elem_cdn(model, e), model%cdt(e), & fdrag, ErrStat=es, ErrMsg=ErrMsg) END IF ErrStat = es @@ -1804,6 +1926,27 @@ SUBROUTINE CD_HermiteCable_Dyn_VIV_Node_Lift(model, lift, ErrStat, ErrMsg) END DO END SUBROUTINE CD_HermiteCable_Dyn_VIV_Node_Lift + SUBROUTINE CD_HermiteCable_Dyn_VIV_Amplitude(model, amp, ErrStat, ErrMsg) + !! The smoothed cross-flow amplitude estimate of every node at the committed state [m] (nn; + !! Thorsen et al. 2016, Eq. 9); zero on nodes without VIV and on a cable without amplitude + !! tables. + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + REAL(wp), INTENT(OUT) :: amp(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + amp = CD_ZERO + ErrStat = CD_HCDYN_OK; ErrMsg = '' + IF (.NOT. model%initialized) THEN + ErrStat = CD_HCDYN_BADINPUT; ErrMsg = 'CD_HermiteCable_Dyn_VIV_Amplitude: model not initialised'; RETURN + END IF + IF (SIZE(amp) /= model%nn) THEN + ErrStat = CD_HCDYN_BADINPUT; ErrMsg = 'CD_HermiteCable_Dyn_VIV_Amplitude: amp must have one value per node' + RETURN + END IF + IF (.NOT. model%has_viv_amp) RETURN + amp = MERGE(model%viv_ms(5, :), CD_ZERO, model%viv_node) + END SUBROUTINE CD_HermiteCable_Dyn_VIV_Amplitude + SUBROUTINE CD_HermiteCable_Dyn_Load_Power(model, p_viv, p_drag, p_damp, ErrStat, ErrMsg) !! The power [W] three loads deliver to the cable at the committed state, per node (nn): the !! VIV loads (cross-flow lift, and the in-line force where it is on), the hydrodynamic drag @@ -9498,7 +9641,7 @@ SUBROUTINE assemble_residual(model, q_cfg, v_cfg, t_eval, want_residual, want_ta IF (want_tangent) THEN IF (model%has_wave .AND. model%wv_ncomp > 0) THEN CALL CD_HermiteCable_Drag_Element(qe, ve, model%l0(e), model%current, model%waterline_z, & - model%rho_w, model%diam(e), model%cdn(e), model%cdt(e), & + model%rho_w, model%diam(e), elem_cdn(model, e), model%cdt(e), & fdrag, djq, djv, es, em_e, & wv_depth=model%wv_depth, wv_dir=model%wv_dir, wv_t=t_eval, & wvc_amp=model%wv_ampc, wvc_om=model%wv_omc, & @@ -9506,7 +9649,7 @@ SUBROUTINE assemble_residual(model, q_cfg, v_cfg, t_eval, want_residual, want_ta wvc_e2kd=model%wv_e2kd) ELSE IF (model%has_wave) THEN CALL CD_HermiteCable_Drag_Element(qe, ve, model%l0(e), model%current, model%waterline_z, & - model%rho_w, model%diam(e), model%cdn(e), model%cdt(e), & + model%rho_w, model%diam(e), elem_cdn(model, e), model%cdt(e), & fdrag, djq, djv, es, em_e, & wv_h=model%wv_h, wv_om=model%wv_om, wv_k=model%wv_k, & wv_depth=model%wv_depth, wv_dir=model%wv_dir, wv_t=t_eval) @@ -9517,11 +9660,11 @@ SUBROUTINE assemble_residual(model, q_cfg, v_cfg, t_eval, want_residual, want_ta CALL CD_HermiteCable_Drag_Element(qe, ve, model%l0(e), & model%current + 0.5_wp*(model%hf_u(:, e) + model%hf_u(:, e + 1)), & 0.5_wp*(model%hf_wl(e) + model%hf_wl(e + 1)), & - model%rho_w, model%diam(e), model%cdn(e), model%cdt(e), & + model%rho_w, model%diam(e), elem_cdn(model, e), model%cdt(e), & fdrag, djq, djv, es, em_e) ELSE CALL CD_HermiteCable_Drag_Element(qe, ve, model%l0(e), model%current, model%waterline_z, & - model%rho_w, model%diam(e), model%cdn(e), model%cdt(e), & + model%rho_w, model%diam(e), elem_cdn(model, e), model%cdt(e), & fdrag, djq, djv, es, em_e) END IF ELSE @@ -11043,14 +11186,14 @@ SUBROUTINE evaluate_tangent_element(model, e, q_cfg, v_cfg, t_eval, Kstruct, Kdr IF (model%has_drag) THEN IF (model%has_wave .AND. model%wv_ncomp > 0) THEN CALL CD_HermiteCable_Drag_Element(qe, ve, model%l0(e), model%current, model%waterline_z, & - model%rho_w, model%diam(e), model%cdn(e), model%cdt(e), & + model%rho_w, model%diam(e), elem_cdn(model, e), model%cdt(e), & fload, djq, djv, es, em, wv_depth=model%wv_depth, & wv_dir=model%wv_dir, wv_t=t_eval, wvc_amp=model%wv_ampc, & wvc_om=model%wv_omc, wvc_k=model%wv_kc, wvc_ph=model%wv_phc, & wvc_e2kd=model%wv_e2kd) ELSE IF (model%has_wave) THEN CALL CD_HermiteCable_Drag_Element(qe, ve, model%l0(e), model%current, model%waterline_z, & - model%rho_w, model%diam(e), model%cdn(e), model%cdt(e), & + model%rho_w, model%diam(e), elem_cdn(model, e), model%cdt(e), & fload, djq, djv, es, em, wv_h=model%wv_h, wv_om=model%wv_om, & wv_k=model%wv_k, wv_depth=model%wv_depth, wv_dir=model%wv_dir, & wv_t=t_eval) @@ -11058,10 +11201,10 @@ SUBROUTINE evaluate_tangent_element(model, e, q_cfg, v_cfg, t_eval, Kstruct, Kdr CALL CD_HermiteCable_Drag_Element(qe, ve, model%l0(e), & model%current + 0.5_wp*(model%hf_u(:, e) + model%hf_u(:, e + 1)), & 0.5_wp*(model%hf_wl(e) + model%hf_wl(e + 1)), model%rho_w, & - model%diam(e), model%cdn(e), model%cdt(e), fload, djq, djv, es, em) + model%diam(e), elem_cdn(model, e), model%cdt(e), fload, djq, djv, es, em) ELSE CALL CD_HermiteCable_Drag_Element(qe, ve, model%l0(e), model%current, model%waterline_z, & - model%rho_w, model%diam(e), model%cdn(e), model%cdt(e), & + model%rho_w, model%diam(e), elem_cdn(model, e), model%cdt(e), & fload, djq, djv, es, em) END IF IF (es /= CD_HCDYN_OK) THEN diff --git a/src/CableDyn_Model.f90 b/src/CableDyn_Model.f90 index c90536d..d12a277 100644 --- a/src/CableDyn_Model.f90 +++ b/src/CableDyn_Model.f90 @@ -57,7 +57,9 @@ MODULE CableDyn_Model CD_Added_Mass_Element, CD_Added_Mass_Element_Matrix, CD_Added_Mass_Element_Force, & CD_Submerged_Fraction USE CableDyn_VIV, ONLY: CD_VIV_Node_Lift, CD_VIV_Crossflow_Motion, CD_VIV_Phase_Rate, CD_VIV_Mean_Square, & - CD_VIV_Wrap_Phase, CD_VIV_NM, CD_VIV_TWO_PI, CD_VIV_Node_Inline, CD_VIV_Inline_Phase_Rate + CD_VIV_Wrap_Phase, CD_VIV_NM, CD_VIV_TWO_PI, CD_VIV_Node_Inline, CD_VIV_Inline_Phase_Rate, & + CD_VIV_NMS, CD_VIV_NMS_AMP, CD_VIV_AMP_MAXP, CD_VIV_Amplitude_Update, CD_VIV_Table, & + CD_VIV_Check_Amp_Table, CD_VIV_Ambient_Crossflow_Rate USE CableDyn_Dynamic, ONLY: GenAlphaConfig, CD_CableGenAlphaWorkspace, CD_Clear_GenAlpha_Workspace, & CD_Cable_Initial_Acceleration, CD_Cable_Gen_Alpha_Step, CD_Cable_Step_Loads, & CD_DYN_OK, CD_DYN_ALLOCFAIL, & @@ -97,7 +99,8 @@ 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, CD_Get_Model_VIV_Lift + PUBLIC :: CD_Get_Model_VIV_State, CD_Set_Model_VIV_State, CD_Model_Has_VIV, CD_Get_Model_VIV_Lift, & + CD_Model_VIV_NMS, CD_Get_Model_VIV_Amplitude PUBLIC :: CD_Model_Has_VIV_Inline PUBLIC :: CD_Get_Model_Load_Power PUBLIC :: CD_Get_Model_Tension @@ -426,6 +429,15 @@ MODULE CableDyn_Model REAL(wp), ALLOCATABLE :: vil_phi(:), vil_ms(:, :), vil_phi_rollback(:), vil_ms_rollback(:, :) REAL(wp), ALLOCATABLE :: recovery_vil_phi(:), recovery_vil_ms(:, :) REAL(wp), ALLOCATABLE :: vil_phi_eval(:), vil_rate(:), vil_ms_next(:, :), vil_phi_next(:) + ! Amplitude-dependent VIV coefficients (CD_Set_Model_VIV amp, amp_n; VIV AMPLITUDE section): + ! per element a table of amp_n rows (A/D, C_v, drag factor) in viv_amp(:, 1:amp_n, e) (amp_n 0 + ! = none). With it viv_ms carries CD_VIV_NMS_AMP rows: after the mean squares, the amplitude + ! estimate of Thorsen et al. (2016) per node (CD_VIV_Amplitude_Update, row 5 the smoothed + ! amplitude). An element takes C_v and the factor of its normal drag coefficient from its table + ! at the mean smoothed amplitude of its VIV nodes over its diameter. + LOGICAL :: has_viv_amp = .FALSE. + REAL(wp), ALLOCATABLE :: viv_amp(:, :, :) + INTEGER, ALLOCATABLE :: viv_amp_n(:) TYPE(GenAlphaConfig) :: cfg ! Run audit of the committed host steps (CD_Audit_Model_Step), diagnostics only: never part ! of the state, of a copy, or of a result. audit_t holds the segment tensions of the last two @@ -2272,6 +2284,7 @@ LOGICAL FUNCTION sub_alloc(model, has_pres) RESULT(ok) TYPE(CD_ModelType), INTENT(INOUT) :: model LOGICAL, INTENT(IN) :: has_pres INTEGER :: istat, k + LOGICAL :: reuse ok = .FALSE. istat = 0 DO k = 1, 2 @@ -2311,9 +2324,15 @@ LOGICAL FUNCTION sub_alloc(model, has_pres) RESULT(ok) END IF END IF IF (model%has_viv) THEN - IF (.NOT. sized(s%viv_phi, SIZE(model%viv_phi))) THEN - IF (ALLOCATED(s%viv_phi)) DEALLOCATE (s%viv_phi, s%viv_ms) - ALLOCATE (s%viv_phi(SIZE(model%viv_phi)), s%viv_ms(2, SIZE(model%viv_phi)), STAT=istat) + ! the motion statistics change rows with amplitude tables (CD_Model_VIV_NMS) on a line + ! whose VIV is set again after it has stepped: the slot follows both dimensions + reuse = sized(s%viv_phi, SIZE(model%viv_phi)) + IF (reuse) reuse = ALLOCATED(s%viv_ms) + IF (reuse) reuse = SIZE(s%viv_ms, 1) == SIZE(model%viv_ms, 1) .AND. SIZE(s%viv_ms, 2) == SIZE(model%viv_ms, 2) + IF (.NOT. reuse) THEN + IF (ALLOCATED(s%viv_phi)) DEALLOCATE (s%viv_phi) + IF (ALLOCATED(s%viv_ms)) DEALLOCATE (s%viv_ms) + ALLOCATE (s%viv_phi(SIZE(model%viv_phi)), s%viv_ms(SIZE(model%viv_ms, 1), SIZE(model%viv_phi)), STAT=istat) IF (istat /= 0) RETURN END IF END IF @@ -3928,7 +3947,7 @@ SUBROUTINE CD_Set_Model_Syrope_State(model, slow, tmax, ErrStat, ErrMsg) END SUBROUTINE CD_Set_Model_Syrope_State SUBROUTINE CD_Set_Model_VIV(model, rho, cl, diameter, cf, df, t_window, ErrStat, ErrMsg, phase_seed, & - tangent_reversed, clx, il_alpha, chh) + tangent_reversed, clx, il_alpha, chh, amp, amp_n) !! 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; @@ -3950,6 +3969,11 @@ SUBROUTINE CD_Set_Model_VIV(model, rho, cl, diameter, cf, df, t_window, ErrStat, !! twice its cross-flow phase. chh (optional, with clx), per element, the coefficient C_hh >= 0 !! of the higher-harmonic force of Ulveseter et al. (2019), the lift's form at the phase sum !! phi_y + phi_x (0: none; > 0 only where clx > 0). + !! Amplitude-dependent coefficients (both or neither): amp (3, CD_VIV_AMP_MAXP, n_elem) and + !! amp_n (n_elem), per element a table of amp_n rows (0: none; only where cl > 0) of the + !! amplitude ratio A/D >= 0 (strictly increasing), the cross-flow coefficient C_v >= 0 that + !! replaces cl, and the factor > 0 of the element's normal drag coefficient, at the smoothed + !! amplitude estimate of Thorsen et al. (2016); piecewise linear, held beyond the end rows. TYPE(CD_ModelType), INTENT(INOUT) :: model REAL(wp), INTENT(IN) :: rho, cl(:), diameter(:), cf(:), df(:), t_window INTEGER, INTENT(OUT) :: ErrStat @@ -3960,9 +3984,12 @@ SUBROUTINE CD_Set_Model_VIV(model, rho, cl, diameter, cf, df, t_window, ErrStat, !! .FALSE. on a line the reader turned around, whose tangent runs as MoorDyn's LOGICAL, INTENT(IN), OPTIONAL :: tangent_reversed REAL(wp), INTENT(IN), OPTIONAL :: clx(:), il_alpha(:), chh(:) - INTEGER :: n_nodes, n_elem, e, nd, istat, k + REAL(wp), INTENT(IN), OPTIONAL :: amp(:, :, :) + INTEGER, INTENT(IN), OPTIONAL :: amp_n(:) + INTEGER :: n_nodes, n_elem, e, nd, istat, k, nms REAL(wp) :: wsum - LOGICAL :: want_il + LOGICAL :: want_il, want_amp + CHARACTER(160) :: amsg ErrStat = CD_MODEL_OK ErrMsg = '' @@ -4036,6 +4063,19 @@ SUBROUTINE CD_Set_Model_VIV(model, rho, cl, diameter, cf, df, t_window, ErrStat, RETURN END IF END IF + IF (PRESENT(amp) .NEQV. PRESENT(amp_n)) THEN + CALL fail(ErrStat, ErrMsg, 'the VIV amplitude tables amp and amp_n go together') + RETURN + END IF + want_amp = .FALSE. + IF (PRESENT(amp)) THEN + CALL CD_VIV_Check_Amp_Table(amp, amp_n, cl, amsg) + IF (LEN_TRIM(amsg) > 0) THEN + CALL fail(ErrStat, ErrMsg, TRIM(amsg)) + RETURN + END IF + want_amp = ANY(amp_n > 0) + END IF CALL clear_viv(model) IF (.NOT. ANY(cl > CD_ZERO)) RETURN IF (.NOT. (CD_Is_Finite(rho) .AND. rho > CD_ZERO)) THEN @@ -4060,17 +4100,29 @@ SUBROUTINE CD_Set_Model_VIV(model, rho, cl, diameter, cf, df, t_window, ErrStat, RETURN END IF END DO + nms = MERGE(CD_VIV_NMS_AMP, CD_VIV_NMS, want_amp) ALLOCATE (model%viv_cl(n_elem), model%viv_d(n_elem), model%viv_node(n_nodes), model%viv_cf(n_nodes), & - model%viv_df(n_nodes), model%viv_dn(n_nodes), model%viv_phi(n_nodes), model%viv_ms(2, n_nodes), & - model%viv_phi_rollback(n_nodes), model%viv_ms_rollback(2, n_nodes), & - model%recovery_viv_phi(n_nodes), model%recovery_viv_ms(2, n_nodes), & - model%viv_phi_eval(n_nodes), model%viv_rate(n_nodes), model%viv_ms_next(2, n_nodes), & + model%viv_df(n_nodes), model%viv_dn(n_nodes), model%viv_phi(n_nodes), model%viv_ms(nms, n_nodes), & + model%viv_phi_rollback(n_nodes), model%viv_ms_rollback(nms, n_nodes), & + model%recovery_viv_phi(n_nodes), model%recovery_viv_ms(nms, n_nodes), & + model%viv_phi_eval(n_nodes), model%viv_rate(n_nodes), model%viv_ms_next(nms, n_nodes), & model%viv_phi_next(n_nodes), STAT=istat) IF (istat /= 0) THEN CALL clear_viv(model) CALL alloc_fail(ErrStat, ErrMsg, 'VIV storage allocation failed') RETURN END IF + IF (want_amp) THEN + ALLOCATE (model%viv_amp(3, CD_VIV_AMP_MAXP, n_elem), model%viv_amp_n(n_elem), STAT=istat) + IF (istat /= 0) THEN + CALL clear_viv(model) + CALL alloc_fail(ErrStat, ErrMsg, 'VIV amplitude table allocation failed') + RETURN + END IF + model%viv_amp = amp + model%viv_amp_n = amp_n + model%has_viv_amp = .TRUE. + END IF model%viv_rho = rho model%viv_tw = t_window model%viv_cl = MERGE(cl, CD_ZERO, cl > CD_ZERO) @@ -4190,8 +4242,8 @@ SUBROUTINE CD_Get_Model_VIV_State(model, phi, ms, t_window, ErrStat, ErrMsg, phi 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)') + IF (SIZE(phi) /= model%n_dof/3 .OR. SIZE(ms, 1) /= CD_Model_VIV_NMS(model) .OR. SIZE(ms, 2) /= model%n_dof/3) THEN + CALL fail(ErrStat, ErrMsg, 'VIV state outputs must have shapes (n_nodes) and (CD_Model_VIV_NMS, n_nodes)') RETURN END IF IF (PRESENT(phi_x) .NEQV. PRESENT(ms_x)) THEN @@ -4217,13 +4269,14 @@ END SUBROUTINE CD_Get_Model_VIV_State SUBROUTINE CD_Set_Model_VIV_State(model, phi, ms, t_window, ErrStat, ErrMsg, phi_x, ms_x) !! 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. A model with in-line VIV needs phi_x and ms_x, one without - !! refuses them. + !! mean square, amplitude or averaging time. A model with in-line VIV needs phi_x and ms_x, + !! one without refuses them. TYPE(CD_ModelType), INTENT(INOUT) :: model REAL(wp), INTENT(IN) :: phi(:), ms(:, :), t_window INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg REAL(wp), INTENT(IN), OPTIONAL :: phi_x(:), ms_x(:, :) + LOGICAL :: neg ErrStat = CD_MODEL_OK ErrMsg = '' IF (.NOT. model%initialized) THEN @@ -4235,16 +4288,20 @@ SUBROUTINE CD_Set_Model_VIV_State(model, phi, ms, t_window, ErrStat, ErrMsg, phi 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)') + IF (SIZE(phi) /= model%n_dof/3 .OR. SIZE(ms, 1) /= CD_Model_VIV_NMS(model) .OR. SIZE(ms, 2) /= model%n_dof/3) THEN + CALL fail(ErrStat, ErrMsg, 'VIV state inputs must have shapes (n_nodes) and (CD_Model_VIV_NMS, 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') + ! the mean squares (rows 1:2) and the amplitudes y0, y0s (rows 4:5) cannot be negative; the + ! travel and the last cross-flow velocity of the amplitude estimate (rows 3, 6) are signed + neg = ANY(ms(1:2, :) < CD_ZERO) + IF (SIZE(ms, 1) >= 5) neg = neg .OR. ANY(ms(4:5, :) < CD_ZERO) + IF (neg .OR. t_window < CD_ZERO) THEN + CALL fail(ErrStat, ErrMsg, 'VIV mean squares, amplitudes and averaging time must be non-negative') RETURN END IF IF (((PRESENT(phi_x) .AND. PRESENT(ms_x)) .NEQV. model%has_viv_il) .OR. (PRESENT(phi_x) .NEQV. PRESENT(ms_x))) THEN @@ -4355,7 +4412,7 @@ SUBROUTINE CD_Get_Model_Load_Power(model, p_viv, p_drag, p_damp, ErrStat, ErrMsg CALL extract_nodal_scalar(model%drag_waterline_z, model, e, wl2) CALL CD_Morison_Drag_Element_Force(q2(1:3), q2(4:6), v2(1:3), v2(4:6), model%l0(e), & fluid2(:, 1), fluid2(:, 2), wl2(1), wl2(2), model%drag_rho, & - model%drag_diameter_elem(e), model%drag_cdn_elem(e), & + model%drag_diameter_elem(e), elem_cdn(model, e), & model%drag_cdt_elem(e), f2, ErrStat, ErrMsg(1:lk), inputs_validated=.TRUE.) IF (ErrStat /= 0) RETURN CALL add_shares(p_drag) @@ -4464,6 +4521,82 @@ PURE LOGICAL FUNCTION CD_Model_Has_VIV(model) RESULT(has) has = model%has_viv END FUNCTION CD_Model_Has_VIV + PURE INTEGER FUNCTION CD_Model_VIV_NMS(model) RESULT(n) + !! Rows of the VIV motion statistics of a node in the VIV state (CD_Get_Model_VIV_State ms): + !! CD_VIV_NMS_AMP with amplitude tables (the amplitude estimate after the mean squares), + !! CD_VIV_NMS otherwise. + TYPE(CD_ModelType), INTENT(IN) :: model + n = MERGE(CD_VIV_NMS_AMP, CD_VIV_NMS, model%has_viv_amp) + END FUNCTION CD_Model_VIV_NMS + + SUBROUTINE CD_Get_Model_VIV_Amplitude(model, amp, ErrStat, ErrMsg) + !! The smoothed cross-flow amplitude estimate of every node at the committed state [m] + !! (n_nodes; Thorsen et al. 2016, Eq. 9); zero on nodes without VIV and on a model without + !! amplitude tables. + TYPE(CD_ModelType), INTENT(IN) :: model + REAL(wp), INTENT(OUT) :: amp(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + amp = 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(amp) /= model%n_dof/3) THEN + CALL fail(ErrStat, ErrMsg, 'VIV amplitude output must have shape (n_nodes)') + RETURN + END IF + IF (.NOT. model%has_viv_amp) RETURN + amp = MERGE(model%viv_ms(5, :), CD_ZERO, model%viv_node) + END SUBROUTINE CD_Get_Model_VIV_Amplitude + + PURE REAL(wp) FUNCTION viv_elem_amplitude(model, e) RESULT(y0) + !! The smoothed cross-flow amplitude of element e [m]: the mean over its VIV end nodes (zero + !! without amplitude tables or VIV nodes). + TYPE(CD_ModelType), INTENT(IN) :: model + INTEGER, INTENT(IN) :: e + INTEGER :: k, n + y0 = CD_ZERO + IF (.NOT. model%has_viv_amp) RETURN + n = 0 + DO k = e, e + 1 + IF (.NOT. model%viv_node(k)) CYCLE + y0 = y0 + model%viv_ms(5, k) + n = n + 1 + END DO + IF (n > 1) y0 = y0/REAL(n, wp) + END FUNCTION viv_elem_amplitude + + PURE REAL(wp) FUNCTION viv_elem_cl(model, e) RESULT(cl) + !! The cross-flow coefficient of element e: its LINE TYPES Cl, or with an amplitude table the + !! table's C_v at the element's smoothed amplitude over its diameter. + TYPE(CD_ModelType), INTENT(IN) :: model + INTEGER, INTENT(IN) :: e + INTEGER :: n + cl = model%viv_cl(e) + IF (.NOT. model%has_viv_amp) RETURN + n = model%viv_amp_n(e) + IF (n == 0) RETURN + cl = CD_VIV_Table(viv_elem_amplitude(model, e)/model%viv_d(e), model%viv_amp(1, 1:n, e), model%viv_amp(2, 1:n, e)) + END FUNCTION viv_elem_cl + + PURE REAL(wp) FUNCTION elem_cdn(model, e) RESULT(cdn) + !! The normal drag coefficient of element e: drag_cdn_elem, times the drag factor of its VIV + !! amplitude table at the element's smoothed amplitude where it has one. + TYPE(CD_ModelType), INTENT(IN) :: model + INTEGER, INTENT(IN) :: e + INTEGER :: n + cdn = model%drag_cdn_elem(e) + IF (.NOT. model%has_viv_amp) RETURN + n = model%viv_amp_n(e) + IF (n == 0) RETURN + cdn = cdn*CD_VIV_Table(viv_elem_amplitude(model, e)/model%viv_d(e), model%viv_amp(1, 1:n, e), & + model%viv_amp(3, 1:n, e)) + END FUNCTION elem_cdn + SUBROUTINE viv_node_coef(model, q, nd, coef, uu, coefx, coefh) !! 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 @@ -4489,7 +4622,7 @@ SUBROUTINE viv_node_coef(model, q, nd, coef, uu, coefx, coefh) wlb = model%drag_waterline_z(e + 1) END IF CALL CD_Submerged_Fraction(q(3*e) - wla, q(3*e + 3) - wlb, frac) - coef = coef + 0.25_wp*model%viv_rho*model%viv_d(e)*model%viv_cl(e)*model%l0(e)*frac + coef = coef + 0.25_wp*model%viv_rho*model%viv_d(e)*viv_elem_cl(model, e)*model%l0(e)*frac IF (PRESENT(coefx)) coefx = coefx + 0.25_wp*model%viv_rho*model%viv_d(e)*model%vil_cx(e)*model%l0(e)*frac IF (PRESENT(coefh)) coefh = coefh + 0.25_wp*model%viv_rho*model%viv_d(e)*model%vhh_cx(e)*model%l0(e)*frac END DO @@ -4561,7 +4694,7 @@ SUBROUTINE viv_step_end(model, dt, ErrStat, ErrMsg) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg INTEGER :: nd, ia - REAL(wp) :: w, yd, ydd, un, coef, uu(3), ms1, ms2, rate_end, xd, xdd, rate_end_x + REAL(wp) :: w, yd, ydd, un, coef, uu(3), ms1, ms2, rate_end, xd, xdd, rate_end_x, st(4) LOGICAL :: ok ErrStat = CD_MODEL_OK ErrMsg = '' @@ -4579,6 +4712,15 @@ SUBROUTINE viv_step_end(model, dt, ErrStat, ErrMsg) CALL fail(ErrStat, ErrMsg, 'VIV phase: the neighbours of a node coincide (no line tangent)') RETURN END IF + IF (model%has_viv_amp) THEN + ! the amplitude estimate over the step, from the committed one (repeatable), on the + ! cross-flow velocity across the ambient flow + st = model%viv_ms(3:6, nd) + CALL CD_VIV_Amplitude_Update(st, CD_VIV_Ambient_Crossflow_Rate(model%q_step(ia + 3:ia + 5) - & + model%q_step(ia - 3:ia - 1), & + smoothed(model%v_step, ia), uu), dt) + model%viv_ms_next(3:6, nd) = st + END IF ms1 = CD_VIV_Mean_Square(model%viv_ms_next(1, nd), yd, w) ms2 = CD_VIV_Mean_Square(model%viv_ms_next(2, nd), ydd, w) rate_end = CD_VIV_Phase_Rate(yd, ydd, ms1, ms2, model%viv_phi(nd) + dt*model%viv_rate(nd), un, & @@ -4652,6 +4794,9 @@ SUBROUTINE clear_viv(model) IF (ALLOCATED(model%vil_rate)) DEALLOCATE (model%vil_rate) IF (ALLOCATED(model%vil_ms_next)) DEALLOCATE (model%vil_ms_next) IF (ALLOCATED(model%vil_phi_next)) DEALLOCATE (model%vil_phi_next) + IF (ALLOCATED(model%viv_amp)) DEALLOCATE (model%viv_amp) + IF (ALLOCATED(model%viv_amp_n)) DEALLOCATE (model%viv_amp_n) + model%has_viv_amp = .FALSE. model%has_viv_il = .FALSE. model%has_viv = .FALSE. model%viv_rho = CD_ZERO @@ -7411,6 +7556,11 @@ SUBROUTINE CD_Copy_Model(src, dst, ErrStat, ErrMsg) IF (ErrStat /= CD_MODEL_OK) RETURN CALL copy_real1(src%viv_phi_next, work%viv_phi_next, 'viv_phi_next', ErrStat, ErrMsg) IF (ErrStat /= CD_MODEL_OK) RETURN + work%has_viv_amp = src%has_viv_amp + CALL copy_real3(src%viv_amp, work%viv_amp, 'viv_amp', ErrStat, ErrMsg) + IF (ErrStat /= CD_MODEL_OK) RETURN + CALL copy_int1(src%viv_amp_n, work%viv_amp_n, 'viv_amp_n', ErrStat, ErrMsg) + IF (ErrStat /= CD_MODEL_OK) RETURN work%has_viv_il = src%has_viv_il CALL copy_real1(src%vil_cx, work%vil_cx, 'vil_cx', ErrStat, ErrMsg) IF (ErrStat /= CD_MODEL_OK) RETURN @@ -7596,6 +7746,9 @@ SUBROUTINE commit_model_copy(from, to) CALL MOVE_ALLOC(from%viv_rate, to%viv_rate) CALL MOVE_ALLOC(from%viv_ms_next, to%viv_ms_next) CALL MOVE_ALLOC(from%viv_phi_next, to%viv_phi_next) + to%has_viv_amp = from%has_viv_amp + CALL MOVE_ALLOC(from%viv_amp, to%viv_amp) + CALL MOVE_ALLOC(from%viv_amp_n, to%viv_amp_n) to%has_viv_il = from%has_viv_il CALL MOVE_ALLOC(from%vil_cx, to%vil_cx) CALL MOVE_ALLOC(from%vhh_cx, to%vhh_cx) @@ -7740,6 +7893,22 @@ SUBROUTINE copy_real2(src, dst, label, ErrStat, ErrMsg) IF (istat /= 0) CALL copy_alloc_fail(label, ErrStat, ErrMsg) END SUBROUTINE copy_real2 + SUBROUTINE copy_real3(src, dst, label, ErrStat, ErrMsg) + REAL(wp), ALLOCATABLE, INTENT(IN) :: src(:, :, :) + REAL(wp), ALLOCATABLE, INTENT(INOUT) :: dst(:, :, :) + CHARACTER(*), INTENT(IN) :: label + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + + INTEGER :: istat + + ErrStat = CD_MODEL_OK + ErrMsg = '' + IF (.NOT. ALLOCATED(src)) RETURN + ALLOCATE (dst(SIZE(src, 1), SIZE(src, 2), SIZE(src, 3)), SOURCE=src, STAT=istat) + IF (istat /= 0) CALL copy_alloc_fail(label, ErrStat, ErrMsg) + END SUBROUTINE copy_real3 + SUBROUTINE copy_alloc_fail(label, ErrStat, ErrMsg) CHARACTER(*), INTENT(IN) :: label INTEGER, INTENT(OUT) :: ErrStat @@ -8528,7 +8697,7 @@ SUBROUTINE model_contributor_load_banded(model, q, v, free, kl, ku, force, jac_q CALL extract_nodal_scalar(model%drag_waterline_z, model, e, wl2) CALL CD_Morison_Drag_Element_Load(q2(1:3), q2(4:6), v2(1:3), v2(4:6), model%l0(e), & fluid2(:, 1), fluid2(:, 2), wl2(1), wl2(2), model%drag_rho, & - model%drag_diameter_elem(e), model%drag_cdn_elem(e), & + model%drag_diameter_elem(e), elem_cdn(model, e), & model%drag_cdt_elem(e), f2, jq2, jv2, ErrStat, ErrMsg(1:lk), & inputs_validated=.TRUE.) IF (ErrStat /= 0) RETURN @@ -8795,7 +8964,7 @@ SUBROUTINE model_contributor_force(model, q, v, force, ErrStat, ErrMsg, end_node CALL extract_nodal_scalar(model%drag_waterline_z, model, e, wl2) CALL CD_Morison_Drag_Element_Force(q2(1:3), q2(4:6), v2(1:3), v2(4:6), model%l0(e), & fluid2(:, 1), fluid2(:, 2), wl2(1), wl2(2), model%drag_rho, & - model%drag_diameter_elem(e), model%drag_cdn_elem(e), & + model%drag_diameter_elem(e), elem_cdn(model, e), & model%drag_cdt_elem(e), f2, ErrStat, ErrMsg(1:lk), inputs_validated=.TRUE.) IF (ErrStat /= 0) RETURN CALL scatter_element_vector(force, idx, f2) @@ -9362,7 +9531,7 @@ SUBROUTINE model_morison_drag_load(model, q, v, force, jac_q, jac_v, ErrStat, Er CALL extract_nodal_scalar(model%drag_waterline_z, model, e, wl2) l02(1) = model%l0(e) CALL CD_Cable_Morison_Drag_Load(q2, v2, conn1, l02, fluid2, wl2, model%drag_rho, & - model%drag_diameter_elem(e), model%drag_cdn_elem(e), & + model%drag_diameter_elem(e), elem_cdn(model, e), & model%drag_cdt_elem(e), f2, jq2, jv2, ErrStat, ErrMsg) IF (ErrStat /= 0) RETURN CALL scatter_element_vector(force, idx, f2) diff --git a/src/CableDyn_OpenFAST_HermiteFMF.f90 b/src/CableDyn_OpenFAST_HermiteFMF.f90 index 4de6294..bb28e17 100644 --- a/src/CableDyn_OpenFAST_HermiteFMF.f90 +++ b/src/CableDyn_OpenFAST_HermiteFMF.f90 @@ -2250,14 +2250,15 @@ END FUNCTION CD_HFMF_ForceMirrorSize INTEGER FUNCTION CD_HFMF_VIVMirrorSize(self) RESULT(n) !! Mirror slots of the VIV state, before the torsion block: the cross-flow 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); with in-line VIV then the in-line - !! phase and mean squares (3 nn more); with the wake oscillator its state (q, dq/dt) per node - !! (2 nn more); zero without VIV. + !! per node, the running mean squares of the cross-flow velocity and acceleration per node and, + !! with amplitude tables, the four values of the amplitude estimate after them (2 or 6 values a + !! node, interleaved), and the averaging time (3 nn + 1 values, 7 nn + 1 with amplitude tables); + !! with in-line VIV then the in-line phase and mean squares (3 nn more); with the wake + !! oscillator its state (q, dq/dt) per node (2 nn more); 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 + IF (self%line%has_viv) n = (1 + SIZE(self%line%viv_ms, 1))*self%line%nn + 1 IF (self%line%has_viv_il) n = n + 3*self%line%nn IF (self%line%viv_wake) n = n + 2*self%line%nn END FUNCTION CD_HFMF_VIVMirrorSize @@ -2280,7 +2281,7 @@ SUBROUTINE CD_HFMF_PackMirror(self, buf, ErrStat, ErrMsg) REAL(wp), INTENT(OUT) :: buf(:) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg - INTEGER :: i, nf, nh, k + INTEGER :: i, nf, nh, k, nv ErrStat = CD_HFMF_OK; ErrMsg = '' buf = CD_ZERO IF (.NOT. self%initialized) THEN @@ -2337,10 +2338,11 @@ SUBROUTINE CD_HFMF_PackMirror(self, buf, ErrStat, ErrMsg) k = k + 1 + self%line%ndof END IF IF (self%line%has_viv) THEN + nv = SIZE(self%line%viv_ms, 1) 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 + buf(k + self%line%nn + 1:k + (1 + nv)*self%line%nn) = RESHAPE(self%line%viv_ms, [nv*self%line%nn]) + buf(k + (1 + nv)*self%line%nn + 1) = self%line%viv_tw + k = k + (1 + nv)*self%line%nn + 1 END IF IF (self%line%has_viv_il) THEN buf(k + 1:k + self%line%nn) = self%line%vil_phi @@ -2374,7 +2376,8 @@ SUBROUTINE CD_HFMF_UnpackMirror(self, buf, t, ErrStat, ErrMsg) REAL(wp), INTENT(IN) :: t INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg - INTEGER :: i, nf, nh, k, kb, es + INTEGER :: i, nf, nh, k, kb, es, nv + LOGICAL :: bad_viv CHARACTER(1024) :: em ErrStat = CD_HFMF_OK; ErrMsg = '' IF (.NOT. self%initialized) THEN @@ -2431,12 +2434,23 @@ SUBROUTINE CD_HFMF_UnpackMirror(self, buf, t, ErrStat, ErrMsg) RETURN END IF END IF - ! and the VIV block's mean squares and averaging time, which cannot be negative + ! and the VIV block's mean squares, amplitudes and averaging time, which cannot be negative + ! (per node the rows of the motion statistics: the mean squares, rows 1:2, and the amplitudes + ! y0, y0s of the amplitude estimate, rows 4:5; its travel and last cross-flow velocity, rows + ! 3 and 6, are signed) IF (self%line%has_viv) THEN + nv = SIZE(self%line%viv_ms, 1) 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 + bad_viv = buf(kb + nv*self%line%nn + 1) < CD_ZERO + DO i = 1, self%line%nn + IF (ANY(buf(kb + (i - 1)*nv + 1:kb + (i - 1)*nv + 2) < CD_ZERO)) bad_viv = .TRUE. + IF (nv >= 5) THEN + IF (ANY(buf(kb + (i - 1)*nv + 4:kb + (i - 1)*nv + 5) < CD_ZERO)) bad_viv = .TRUE. + END IF + END DO + IF (bad_viv) THEN ErrStat = CD_HFMF_BADINPUT - ErrMsg = 'CD_HFMF_UnpackMirror: the VIV mean squares and averaging time must be non-negative' + ErrMsg = 'CD_HFMF_UnpackMirror: the VIV mean squares, amplitudes and averaging time must be non-negative' RETURN END IF END IF @@ -2510,13 +2524,14 @@ SUBROUTINE CD_HFMF_UnpackMirror(self, buf, t, ErrStat, ErrMsg) ! 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) + nv = SIZE(self%line%viv_ms, 1) + self%line%viv_ms = RESHAPE(buf(k + self%line%nn + 1:k + (1 + nv)*self%line%nn), [nv, self%line%nn]) + self%line%viv_tw = buf(k + (1 + nv)*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 + k = k + (1 + nv)*self%line%nn + 1 END IF IF (self%line%has_viv_il) THEN self%line%vil_phi = buf(k + 1:k + self%line%nn) diff --git a/src/CableDyn_System.f90 b/src/CableDyn_System.f90 index bb58dd1..f0416c4 100644 --- a/src/CableDyn_System.f90 +++ b/src/CableDyn_System.f90 @@ -18,7 +18,7 @@ MODULE CableDyn_System 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_Get_Model_VIV_Lift, & - CD_Model_Has_VIV_Inline, CD_Get_Model_Load_Power, & + CD_Model_Has_VIV_Inline, CD_Get_Model_Load_Power, CD_Model_VIV_NMS, & 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, & @@ -36,6 +36,7 @@ MODULE CableDyn_System CD_MODEL_OK, CD_MODEL_BADINPUT, & CD_MODEL_SOLVEFAIL, CD_MODEL_NOT_INITIALIZED, CD_MODEL_ALLOCFAIL, CD_Copy_Model USE CableDyn_Line, ONLY: CD_Nodal_Seabed_Stiffness + USE CableDyn_VIV, ONLY: CD_VIV_NMS !$ USE OMP_LIB, ONLY: omp_get_max_threads IMPLICIT NONE PRIVATE @@ -958,28 +959,32 @@ 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, 3 per node more with in-line VIV, or 0 for a line - !! without VIV. + !! 3 per node plus the averaging time, 3 per node more with in-line VIV, 4 per node more with + !! amplitude tables, or 0 for a line without VIV. TYPE(CD_SystemType), INTENT(IN) :: system INTEGER, INTENT(IN) :: line_index + INTEGER :: nn 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 - IF (CD_Model_Has_VIV_Inline(system%lines(line_index))) n = n + 3*SIZE(system%lines(line_index)%viv_phi) + nn = SIZE(system%lines(line_index)%viv_phi) + n = 3*nn + 1 + IF (CD_Model_Has_VIV_Inline(system%lines(line_index))) n = n + 3*nn + n = n + (CD_Model_VIV_NMS(system%lines(line_index)) - CD_VIV_NMS)*nn 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; with in-line VIV then the in-line phases - !! and mean squares the same way (3 n_nodes). + !! and mean squares the same way (3 n_nodes); with amplitude tables then the four values of + !! the amplitude estimate interleaved per node (4 n_nodes). 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 + INTEGER :: nn, es, nms, k CHARACTER(160) :: em REAL(wp), ALLOCATABLE :: phi(:), ms(:, :), phx(:), msx(:, :) @@ -991,7 +996,8 @@ SUBROUTINE CD_Get_System_Line_VIV_State(system, line_index, buf, ErrStat, ErrMsg RETURN END IF nn = SIZE(system%lines(line_index)%viv_phi) - ALLOCATE (phi(nn), ms(2, nn), phx(nn), msx(2, nn)) + nms = CD_Model_VIV_NMS(system%lines(line_index)) + ALLOCATE (phi(nn), ms(nms, nn), phx(nn), msx(2, nn)) CALL CD_Get_Model_VIV_State(system%lines(line_index), phi, ms, buf(3*nn + 1), es, em, phi_x=phx, ms_x=msx) IF (es /= CD_MODEL_OK) THEN ErrStat = CD_SYSTEM_SOLVEFAIL @@ -999,11 +1005,15 @@ SUBROUTINE CD_Get_System_Line_VIV_State(system, line_index, buf, ErrStat, ErrMsg RETURN END IF buf(1:nn) = phi - buf(nn + 1:3*nn) = RESHAPE(ms, [2*nn]) + buf(nn + 1:3*nn) = RESHAPE(ms(1:2, :), [2*nn]) + k = 3*nn + 1 IF (CD_Model_Has_VIV_Inline(system%lines(line_index))) THEN - buf(3*nn + 2:4*nn + 1) = phx - buf(4*nn + 2:6*nn + 1) = RESHAPE(msx, [2*nn]) + buf(k + 1:k + nn) = phx + buf(k + nn + 1:k + 3*nn) = RESHAPE(msx, [2*nn]) + k = k + 3*nn END IF + IF (nms > CD_VIV_NMS) buf(k + 1:k + (nms - CD_VIV_NMS)*nn) = RESHAPE(ms(CD_VIV_NMS + 1:nms, :), & + [(nms - CD_VIV_NMS)*nn]) ErrStat = CD_SYSTEM_OK ErrMsg = '' END SUBROUTINE CD_Get_System_Line_VIV_State @@ -1016,8 +1026,9 @@ SUBROUTINE CD_Set_System_Line_VIV_State(system, line_index, buf, ErrStat, ErrMsg REAL(wp), INTENT(IN) :: buf(:) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg - INTEGER :: nn, es + INTEGER :: nn, es, nms, k CHARACTER(160) :: em + REAL(wp), ALLOCATABLE :: ms(:, :) CALL validate_line_index(system, line_index, ErrStat, ErrMsg) IF (ErrStat /= CD_SYSTEM_OK) RETURN @@ -1026,13 +1037,19 @@ SUBROUTINE CD_Set_System_Line_VIV_State(system, line_index, buf, ErrStat, ErrMsg RETURN END IF nn = SIZE(system%lines(line_index)%viv_phi) + nms = CD_Model_VIV_NMS(system%lines(line_index)) + ALLOCATE (ms(nms, nn)) + ms(1:2, :) = RESHAPE(buf(nn + 1:3*nn), [2, nn]) + k = 3*nn + 1 + IF (CD_Model_Has_VIV_Inline(system%lines(line_index))) k = k + 3*nn + IF (nms > CD_VIV_NMS) ms(CD_VIV_NMS + 1:nms, :) = RESHAPE(buf(k + 1:k + (nms - CD_VIV_NMS)*nn), & + [nms - CD_VIV_NMS, nn]) IF (CD_Model_Has_VIV_Inline(system%lines(line_index))) THEN - CALL CD_Set_Model_VIV_State(system%lines(line_index), buf(1:nn), RESHAPE(buf(nn + 1:3*nn), [2, nn]), & + CALL CD_Set_Model_VIV_State(system%lines(line_index), buf(1:nn), ms, & buf(3*nn + 1), es, em, phi_x=buf(3*nn + 2:4*nn + 1), & ms_x=RESHAPE(buf(4*nn + 2:6*nn + 1), [2, nn])) ELSE - 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) + CALL CD_Set_Model_VIV_State(system%lines(line_index), buf(1:nn), ms, buf(3*nn + 1), es, em) END IF IF (es /= CD_MODEL_OK) THEN ErrStat = CD_SYSTEM_SOLVEFAIL @@ -1468,7 +1485,7 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, INTEGER, PARAMETER :: MAX_SUBDIV = 6 ! floor dt/64: resolves any benign line-search stall INTEGER :: i, j, lo, hi, nc, es, line_dof, sys_dof, depth, iter2, ntot, nve, nsy, lo_ve, lo_sy, ne, nfr, lo_fr - INTEGER :: n_team, nel, lo_el + INTEGER :: n_team, nel, lo_el, nvv, lo_vv LOGICAL :: conv2, stall2 CHARACTER(1024) :: em REAL(wp), ALLOCATABLE :: q0(:), v0(:), a0(:), qm(:), vm(:), am(:), qs(:), vs(:), as(:) @@ -1606,15 +1623,17 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, nsy = 0 nfr = 0 nel = 0 + nvv = 0 DO i = 1, system%n_lines ntot = ntot + SIZE(system%lines(i)%q) nel = nel + SIZE(system%lines(i)%l0_c) + nvv = nvv + viv_pack_size(system%lines(i)) IF (system%lines(i)%has_viscoelastic) nve = nve + SIZE(system%lines(i)%ve_dl_1) IF (system%lines(i)%has_syrope) nsy = nsy + SIZE(system%lines(i)%syrope_slow) IF (CD_Model_Has_Friction(system%lines(i))) nfr = nfr + SIZE(system%lines(i)%fr_anchor, 2) END DO ALLOCATE (qs(ntot), vs(ntot), as(ntot), dl1s(nve), slows(nsy), tmaxs(nsy), frs(2, nfr), & - hmaxs(system%n_lines), subs(system%n_lines), l0cs(nel), l0dcs(nel), vivs(ntot), vils(ntot)) + hmaxs(system%n_lines), subs(system%n_lines), l0cs(nel), l0dcs(nel), vivs(nvv), vils(ntot)) vivs = CD_ZERO vils = CD_ZERO lo = 1 @@ -1622,6 +1641,7 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, lo_sy = 1 lo_fr = 1 lo_el = 1 + lo_vv = 1 DO i = 1, system%n_lines hi = lo + SIZE(system%lines(i)%q) - 1 qs(lo:hi) = system%lines(i)%q @@ -1631,7 +1651,11 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, ! states, so the halves of a fallback that does not complete leave no trace hmaxs(i) = system%lines(i)%audit_hmax subs(i) = system%lines(i)%sub_stats - IF (system%lines(i)%has_viv) CALL pack_viv(system%lines(i), vivs(lo:hi)) + IF (system%lines(i)%has_viv) THEN + ne = viv_pack_size(system%lines(i)) + CALL pack_viv(system%lines(i), vivs(lo_vv:lo_vv + ne - 1)) + lo_vv = lo_vv + ne + END IF IF (system%lines(i)%has_viv_il) CALL pack_vil(system%lines(i), vils(lo:hi)) lo = hi + 1 ne = SIZE(system%lines(i)%l0_c) @@ -1675,6 +1699,7 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, lo_sy = 1 lo_fr = 1 lo_el = 1 + lo_vv = 1 DO i = 1, system%n_lines hi = lo + SIZE(system%lines(i)%q) - 1 system%lines(i)%q = qs(lo:hi) @@ -1682,7 +1707,11 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, system%lines(i)%a = as(lo:hi) system%lines(i)%audit_hmax = hmaxs(i) system%lines(i)%sub_stats = subs(i) - IF (system%lines(i)%has_viv) CALL unpack_viv(system%lines(i), vivs(lo:hi)) + IF (system%lines(i)%has_viv) THEN + ne = viv_pack_size(system%lines(i)) + CALL unpack_viv(system%lines(i), vivs(lo_vv:lo_vv + ne - 1)) + lo_vv = lo_vv + ne + END IF IF (system%lines(i)%has_viv_il) CALL unpack_vil(system%lines(i), vils(lo:hi)) lo = hi + 1 ne = SIZE(system%lines(i)%l0_c) @@ -3441,25 +3470,49 @@ SUBROUTINE restore_line_states(system) END DO END SUBROUTINE restore_line_states + PURE INTEGER FUNCTION viv_pack_offset(system, i) RESULT(lo) + !! First index of line i's packed VIV state in a system-wide VIV snapshot, the lines packed + !! in order (viv_pack_size each); i = n_lines + 1 gives the total plus one. + TYPE(CD_SystemType), INTENT(IN) :: system + INTEGER, INTENT(IN) :: i + INTEGER :: j + lo = 1 + DO j = 1, MIN(i - 1, system%n_lines) + lo = lo + viv_pack_size(system%lines(j)) + END DO + END FUNCTION viv_pack_offset + + PURE INTEGER FUNCTION viv_pack_size(line) RESULT(n) + !! Reals of a line's packed VIV state (pack_viv): per node the phase and the rows of the + !! motion statistics (CD_Model_VIV_NMS), 0 without VIV. + TYPE(CD_ModelType), INTENT(IN) :: line + n = 0 + IF (.NOT. line%has_viv) RETURN + n = (1 + SIZE(line%viv_ms, 1))*SIZE(line%viv_phi) + END FUNCTION viv_pack_size + PURE SUBROUTINE pack_viv(line, buf) - !! A line's committed VIV state as 3 reals per node: the phases, then the two mean - !! squares per node (the size of the line's q). + !! A line's committed VIV state (viv_pack_size reals): the phases, then the motion + !! statistics per node (the two mean squares, and the amplitude estimate with amplitude + !! tables). TYPE(CD_ModelType), INTENT(IN) :: line REAL(wp), INTENT(OUT) :: buf(:) - INTEGER :: nn + INTEGER :: nn, nms nn = SIZE(line%viv_phi) + nms = SIZE(line%viv_ms, 1) buf(1:nn) = line%viv_phi - buf(nn + 1:3*nn) = RESHAPE(line%viv_ms, [2*nn]) + buf(nn + 1:(1 + nms)*nn) = RESHAPE(line%viv_ms, [nms*nn]) END SUBROUTINE pack_viv PURE SUBROUTINE unpack_viv(line, buf) !! Inverse of pack_viv; the in-step phase returns to the committed one. TYPE(CD_ModelType), INTENT(INOUT) :: line REAL(wp), INTENT(IN) :: buf(:) - INTEGER :: nn + INTEGER :: nn, nms nn = SIZE(line%viv_phi) + nms = SIZE(line%viv_ms, 1) line%viv_phi = buf(1:nn) - line%viv_ms = RESHAPE(buf(nn + 1:3*nn), [2, nn]) + line%viv_ms = RESHAPE(buf(nn + 1:(1 + nms)*nn), [nms, nn]) line%viv_phi_eval = line%viv_phi END SUBROUTINE unpack_viv @@ -3583,10 +3636,17 @@ SUBROUTINE CD_System_Snapshot(system, ErrStat, ErrMsg) ALLOCATE (system%snap_l0(netot), system%snap_l0_dot(netot), system%snap_fbase(ntot), & system%snap_l0_c(netot), system%snap_l0_dot_c(netot), & system%snap_ve_dl_1(netot), system%snap_syrope_slow(netot), & - system%snap_syrope_tmax(netot), system%snap_fr_anchor(ntot), system%snap_viv(ntot), & + system%snap_syrope_tmax(netot), system%snap_fr_anchor(ntot), & + system%snap_viv(viv_pack_offset(system, system%n_lines + 1) - 1), & system%snap_vil(ntot)) END BLOCK END IF + ! The packed VIV state is sized by the lines' VIV configuration (viv_pack_size), which a line + ! may change after the first snapshot (amplitude tables add rows): follow it. + IF (SIZE(system%snap_viv) /= viv_pack_offset(system, system%n_lines + 1) - 1) THEN + DEALLOCATE (system%snap_viv) + ALLOCATE (system%snap_viv(viv_pack_offset(system, system%n_lines + 1) - 1)) + END IF lo = 1 DO i = 1, system%n_lines hi = lo + SIZE(system%lines(i)%q) - 1 @@ -3598,7 +3658,8 @@ SUBROUTINE CD_System_Snapshot(system, ErrStat, ErrMsg) IF (CD_Model_Has_Friction(system%lines(i))) & system%snap_fr_anchor(lo:lo + 2*SIZE(system%lines(i)%fr_anchor, 2) - 1) = & RESHAPE(system%lines(i)%fr_anchor, [2*SIZE(system%lines(i)%fr_anchor, 2)]) - IF (system%lines(i)%has_viv) CALL pack_viv(system%lines(i), system%snap_viv(lo:hi)) + IF (system%lines(i)%has_viv) CALL pack_viv(system%lines(i), system%snap_viv(viv_pack_offset(system, i): & + viv_pack_offset(system, i + 1) - 1)) IF (system%lines(i)%has_viv_il) CALL pack_vil(system%lines(i), system%snap_vil(lo:hi)) lo = hi + 1 END DO @@ -3659,6 +3720,11 @@ SUBROUTINE CD_System_Restore(system, ErrStat, ErrMsg) ErrMsg = 'CableDyn_System: restore has no valid snapshot' RETURN END IF + IF (SIZE(system%snap_viv) /= viv_pack_offset(system, system%n_lines + 1) - 1) THEN + ErrStat = CD_SYSTEM_BADINPUT + ErrMsg = 'CableDyn_System: restore: the VIV configuration of a line changed since the snapshot' + RETURN + END IF lo = 1 DO i = 1, system%n_lines hi = lo + SIZE(system%lines(i)%q) - 1 @@ -3669,7 +3735,8 @@ SUBROUTINE CD_System_Restore(system, ErrStat, ErrMsg) IF (CD_Model_Has_Friction(system%lines(i))) & system%lines(i)%fr_anchor = RESHAPE(system%snap_fr_anchor(lo:lo + 2*SIZE(system%lines(i)%fr_anchor, 2) - 1), & [2, SIZE(system%lines(i)%fr_anchor, 2)]) - IF (system%lines(i)%has_viv) CALL unpack_viv(system%lines(i), system%snap_viv(lo:hi)) + IF (system%lines(i)%has_viv) CALL unpack_viv(system%lines(i), system%snap_viv(viv_pack_offset(system, i): & + viv_pack_offset(system, i + 1) - 1)) IF (system%lines(i)%has_viv_il) CALL unpack_vil(system%lines(i), system%snap_vil(lo:hi)) lo = hi + 1 END DO diff --git a/src/CableDyn_VIV.f90 b/src/CableDyn_VIV.f90 index f2e1189..8029a5c 100644 --- a/src/CableDyn_VIV.f90 +++ b/src/CableDyn_VIV.f90 @@ -62,6 +62,10 @@ MODULE CableDyn_VIV PUBLIC :: CD_VIV_Inline_Per_Length PUBLIC :: CD_VIV_Inline_Phase_Rate PUBLIC :: CD_VIV_Wake_Advance + PUBLIC :: CD_VIV_Amplitude_Update + PUBLIC :: CD_VIV_Table + PUBLIC :: CD_VIV_Check_Amp_Table + PUBLIC :: CD_VIV_Ambient_Crossflow_Rate !> MoorDyn's running-RMS window in time steps (Line%n_m): each step updates the stored !> mean square as ((n_m - 1) old + new) / n_m. @@ -80,6 +84,15 @@ MODULE CableDyn_VIV REAL(wp), PARAMETER, PUBLIC :: CD_VIV_WAKE_DEFAULT_CL0 = 0.3_wp REAL(wp), PARAMETER, PUBLIC :: CD_VIV_WAKE_DEFAULT_EPS = 0.3_wp REAL(wp), PARAMETER, PUBLIC :: CD_VIV_WAKE_DEFAULT_A = 12.0_wp + !> Rows of the per-node VIV motion statistics: the running mean squares of the cross-flow + !> velocity and acceleration (CD_VIV_NMS), and with an amplitude table (VIV AMPLITUDE section) + !> the four values of the amplitude estimate after them (CD_VIV_NMS_AMP; CD_VIV_Amplitude_Update). + INTEGER, PARAMETER, PUBLIC :: CD_VIV_NMS = 2 + INTEGER, PARAMETER, PUBLIC :: CD_VIV_NMS_AMP = 6 + !> The smoothing of the amplitude estimate per time step, k_a dt of Thorsen et al. (2016, Eq. 9). + REAL(wp), PARAMETER, PUBLIC :: CD_VIV_AMP_KDT = 0.1_wp + !> The most rows of one line type's amplitude table. + INTEGER, PARAMETER, PUBLIC :: CD_VIV_AMP_MAXP = 32 !> Chord below which a node tangent is undefined (a collapsed pair of neighbours). REAL(wp), PARAMETER :: TINY_CHORD = 1.0e-12_wp @@ -504,6 +517,134 @@ PURE FUNCTION rhs(x, tau) RESULT(d) END FUNCTION rhs END SUBROUTINE CD_VIV_Wake_Advance + PURE SUBROUTINE CD_VIV_Amplitude_Update(st, yd, dt) + !! One time step dt of the cross-flow amplitude estimate of Thorsen, Saevik and Larsen + !! (J. Fluids Struct. 61, 2016, Eq. 8 and 9) at a node, with the cross-flow velocity yd at the + !! end of the step. st = (s, y0, y0s, yd_last): + !! + !! s the travel since the last zero crossing of y', signed: int y' dt (trapezoidal), + !! which is +-int |y'| dt as y' keeps its sign between crossings, and whose sign + !! is that of the half cycle + !! y0 the amplitude |s|/2 of the last half cycle, set at each zero crossing of y' (the + !! node travels 2 y0 between two crossings of a narrow-band response, Eq. 8) + !! y0s the smoothed amplitude, y0s + k_a dt (y0 - y0s) per step (Eq. 9, k_a = 0.1/dt) + !! yd_last y' at the start of the step + !! + !! A crossing is a change of sign of y' from that of the running half cycle: of yd_last, or + !! after samples at y' = 0 the sign of s, so a reversal through a sample at zero (+1, 0, -1) + !! ends the half cycle there and a touch (+1, 0, +1) does not. A crossing inside the step is + !! placed by linear interpolation of y', and the travel splits there between the half cycle + !! it ends and the next. + REAL(wp), INTENT(INOUT) :: st(4) + REAL(wp), INTENT(IN) :: yd, dt + REAL(wp) :: y_old, theta, p + IF (.NOT. (dt > CD_ZERO)) RETURN + y_old = st(4) + p = y_old + IF (.NOT. (p /= CD_ZERO)) p = st(1) + IF ((p > CD_ZERO .AND. yd < CD_ZERO) .OR. (p < CD_ZERO .AND. yd > CD_ZERO)) THEN + ! theta = 0 when the step starts on the sample at zero that ends the half cycle + theta = y_old/(y_old - yd) + st(1) = st(1) + 0.5_wp*y_old*theta*dt + st(2) = 0.5_wp*ABS(st(1)) + st(1) = 0.5_wp*yd*(CD_ONE - theta)*dt + ELSE + st(1) = st(1) + 0.5_wp*(y_old + yd)*dt + END IF + st(3) = st(3) + CD_VIV_AMP_KDT*(st(2) - st(3)) + st(4) = yd + END SUBROUTINE CD_VIV_Amplitude_Update + + PURE REAL(wp) FUNCTION CD_VIV_Ambient_Crossflow_Rate(tdir, rd, u) RESULT(yd) + !! The cross-flow velocity of a node across the AMBIENT flow, the y' of the amplitude estimate + !! (Thorsen et al. 2016, Fig. 1: y across the incoming flow): rd . (t x u_n)/|u_n|, with t the + !! unit line tangent along tdir and u_n the ambient velocity u normal to it; 0 without ambient + !! normal flow or with a degenerate tangent. Unlike the cross-flow axis of the phase (across the + !! relative flow), this axis does not turn with the node's own velocity, which at a response + !! velocity comparable to the flow would shorten the projected velocity by U/|v_n|. + REAL(wp), INTENT(IN) :: tdir(3), rd(3), u(3) + REAL(wp) :: t(3), un(3), s, e(3) + yd = CD_ZERO + s = SQRT(tdir(1)*tdir(1) + tdir(2)*tdir(2) + tdir(3)*tdir(3)) + IF (.NOT. (s > TINY_CHORD)) RETURN + t = tdir/s + un = u - (t(1)*u(1) + t(2)*u(2) + t(3)*u(3))*t + s = SQRT(un(1)*un(1) + un(2)*un(2) + un(3)*un(3)) + IF (.NOT. (s > CD_ZERO)) RETURN + e = cross3(t, un)/s + yd = rd(1)*e(1) + rd(2)*e(2) + rd(3)*e(3) + END FUNCTION CD_VIV_Ambient_Crossflow_Rate + + PURE SUBROUTINE CD_VIV_Check_Amp_Table(amp, amp_n, cl, msg) + !! Check the per-element amplitude tables of a line (CD_VIV_Amplitude_Update): amp (3, + !! CD_VIV_AMP_MAXP, n_elem) holds amp_n(e) rows (A/D, C_v, drag factor) of element e, cl the + !! element lift coefficients. msg is blank when the tables are valid: amp_n in [0, + !! CD_VIV_AMP_MAXP], > 0 only where cl > 0, the used rows finite with A/D >= 0 strictly + !! increasing, C_v >= 0 and the drag factor > 0, each at most 1e15. + REAL(wp), INTENT(IN) :: amp(:, :, :), cl(:) + INTEGER, INTENT(IN) :: amp_n(:) + CHARACTER(*), INTENT(OUT) :: msg + INTEGER :: e, n, i + REAL(wp), PARAMETER :: big = 1.0e15_wp + msg = '' + IF (SIZE(amp, 1) /= 3 .OR. SIZE(amp, 2) /= CD_VIV_AMP_MAXP .OR. SIZE(amp, 3) /= SIZE(cl) .OR. & + SIZE(amp_n) /= SIZE(cl)) THEN + msg = 'VIV amplitude tables must have shapes (3, 32, n_elem) and (n_elem)' + RETURN + END IF + DO e = 1, SIZE(cl) + n = amp_n(e) + IF (n < 0 .OR. n > CD_VIV_AMP_MAXP) THEN + msg = 'a VIV amplitude table holds 0 to 32 rows' + RETURN + END IF + IF (n == 0) CYCLE + IF (.NOT. (cl(e) > CD_ZERO)) THEN + msg = 'a VIV amplitude table needs the cross-flow lift (cl > 0) on its element' + RETURN + END IF + DO i = 1, n + IF (.NOT. (amp(1, i, e) >= CD_ZERO .AND. amp(1, i, e) <= big .AND. amp(2, i, e) >= CD_ZERO .AND. & + amp(2, i, e) <= big .AND. amp(3, i, e) > CD_ZERO .AND. amp(3, i, e) <= big)) THEN + msg = 'VIV amplitude table rows need finite A/D >= 0, C_v >= 0 and drag factor > 0, each at most 1e15' + RETURN + END IF + IF (i > 1) THEN + IF (.NOT. (amp(1, i, e) > amp(1, i - 1, e))) THEN + msg = 'the A/D of a VIV amplitude table must increase strictly' + RETURN + END IF + END IF + END DO + END DO + END SUBROUTINE CD_VIV_Check_Amp_Table + + PURE REAL(wp) FUNCTION CD_VIV_Table(x, xs, ys) RESULT(y) + !! Piecewise-linear interpolation of the table (xs, ys) at x, xs strictly increasing, held + !! at the end values outside [xs(1), xs(n)]; a one-row table is constant. + REAL(wp), INTENT(IN) :: x, xs(:), ys(:) + INTEGER :: n, i + n = SIZE(xs) + IF (n < 1) THEN + y = CD_ZERO + RETURN + END IF + IF (n == 1 .OR. x <= xs(1)) THEN + y = ys(1) + RETURN + END IF + IF (x >= xs(n)) THEN + y = ys(n) + RETURN + END IF + ! The search stops at the last segment (i = n) also for an x that compares false with + ! every row (NaN), which then propagates instead of indexing past the table. + DO i = 2, n - 1 + IF (x <= xs(i)) EXIT + END DO + y = ys(i - 1) + (ys(i) - ys(i - 1))*(x - xs(i - 1))/(xs(i) - xs(i - 1)) + END FUNCTION CD_VIV_Table + ELEMENTAL REAL(wp) FUNCTION CD_VIV_Wrap_Phase(phi) RESULT(wrapped) !! The phase mapped to [0, 2 pi); the model only uses cos(phi) and sin(. - phi). REAL(wp), INTENT(IN) :: phi diff --git a/tests/test_model.f90 b/tests/test_model.f90 index 35e48fe..e0dc7d2 100644 --- a/tests/test_model.f90 +++ b/tests/test_model.f90 @@ -9,6 +9,7 @@ PROGRAM test_model !! at rest, prescribed fairlead motion advances through the model boundary, and !! End releases the model cleanly. USE CableDyn_Precision, ONLY: wp + USE CableDyn_VIV, ONLY: CD_VIV_AMP_MAXP USE CableDyn_Bathymetry, ONLY: CD_BathymetryType, CD_Init_Bathymetry, CD_End_Bathymetry, CD_BATHY_OK USE CableDyn_Dynamic, ONLY: GenAlphaConfig, CD_EI0_SUBSTEPS_OFF USE CableDyn_SeabedContact, ONLY: CD_SEABED_CONTACT_BLEND @@ -1740,6 +1741,8 @@ SUBROUTINE case_substeps_restore_viv_state(inline) INTEGER :: conn(2, NE), fixed(6), es, k, n_iter REAL(wp) :: q0(3*NN), v0(3*NN), f_ext(3*NN), pq(3*NN), pv(3*NN), pa(3*NN), fluid(3, NN), wl(NN) REAL(wp) :: l0(NE), ea(NE), rho_a(NE), cl(NE), dia(NE), cf(NE), df(NE), phi0(NN), w, t, phx0(NN) + REAL(wp) :: tab(3, CD_VIV_AMP_MAXP, NE) + INTEGER :: tab_n(NE), ev0 LOGICAL :: conv, stalled, all_conv CHARACTER(200) :: em @@ -1825,6 +1828,37 @@ SUBROUTINE case_substeps_restore_viv_state(inline) CALL require(ALL(fb_m%vil_phi == off_m%vil_phi) .AND. ALL(fb_m%vil_ms == off_m%vil_ms), & 'substep-viv:in-line-fallback-is-the-plain-step') END IF + IF (.NOT. inline) THEN + ! amplitude tables set after the line has stepped grow its VIV motion statistics from 2 to 6 + ! rows per node at the same node count: the sub-step slots follow on the next sub-stepped steps + ! (100 more steps, to t = 3.2 s: the heave repeats the turning of the first 1.2 s) + tab = 0.0_wp + tab_n = 2 + DO k = 1, NE + tab(:, 1, k) = [0.0_wp, 0.8_wp, 1.0_wp] + tab(:, 2, k) = [0.5_wp, 0.4_wp, 1.5_wp] + END DO + ev0 = auto_m%sub_stats%events + CALL CD_Set_Model_VIV(auto_m, 1025.0_wp, cl, dia, cf, df, 0.25_wp, es, em, amp=tab, amp_n=tab_n) + CALL require(es == CD_MODEL_OK, 'substep-viv:tables-after-stepping: '//TRIM(em)) + all_conv = es == CD_MODEL_OK + DO k = NSTEP + 1, NSTEP + 100 + t = REAL(k, wp)*DT + pq = q0 + pv = 0.0_wp + pa = 0.0_wp + pq(3*NN) = q0(3*NN) + AMP*(1.0_wp - COS(w*t)) + pv(3*NN) = AMP*w*SIN(w*t) + pa(3*NN) = AMP*w*w*COS(w*t) + CALL CD_Step_Model(auto_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + END DO + WRITE (*, '(A,I0,A,L1)') ' sub-stepped steps with tables: ', auto_m%sub_stats%events - ev0, & + ', converged ', all_conv + CALL require(all_conv .AND. auto_m%sub_stats%events > ev0, 'substep-viv:tables-after-stepping-sub-steps') + CALL require(SIZE(auto_m%sub_slot(1)%viv_ms, 1) == 6 .AND. SIZE(auto_m%sub_slot(2)%viv_ms, 1) == 6, & + 'substep-viv:slots-follow-the-statistics-rows') + END IF CALL CD_End_Model(auto_m, es, em) CALL CD_End_Model(rep_m, es, em) CALL CD_End_Model(fb_m, es, em) diff --git a/tests/test_system.f90 b/tests/test_system.f90 index f9c35a1..b269dd1 100644 --- a/tests/test_system.f90 +++ b/tests/test_system.f90 @@ -9,7 +9,8 @@ PROGRAM test_system USE CableDyn_Precision, ONLY: wp USE CableDyn_Dynamic, ONLY: GenAlphaConfig USE CableDyn_Model, ONLY: CD_ModelType, CD_Init_Model, CD_End_Model, CD_MODEL_OK, & - CD_Get_Model_EndNodeMassDiag + CD_Get_Model_EndNodeMassDiag, CD_Set_Model_VIV, CD_Model_VIV_NMS + USE CableDyn_VIV, ONLY: CD_VIV_AMP_MAXP USE CableDyn_System, ONLY: CD_SystemType, CD_SystemPointType, CD_LineEndpointBinding, & CD_Init_System_From_Models, CD_Init_System_From_Points, CD_End_System, & CD_System_NLines, CD_System_NCoupledDOF, CD_System_Line_NDOF, & @@ -47,6 +48,7 @@ PROGRAM test_system CALL case_dynamic_free_point_zero_density_no_hydro() CALL case_zero_coupled_map() CALL case_system_fail_closed() + CALL case_viv_layout_snapshot() IF (nfail > 0) THEN WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' @@ -1113,6 +1115,77 @@ SUBROUTINE case_system_fail_closed() CALL require(es == CD_SYSTEM_OK, 'fail:end') END SUBROUTINE case_system_fail_closed + SUBROUTINE case_viv_layout_snapshot() + !! The packed VIV state of a line grows with amplitude tables (CD_Model_VIV_NMS rows per + !! node): a snapshot taken after a line gains them follows the new size, and a restore of a + !! snapshot taken before is refused, with nothing restored. + INTEGER, PARAMETER :: NN = 5, NE = 4 + TYPE(CD_ModelType) :: models(1) + TYPE(CD_SystemType) :: system + TYPE(GenAlphaConfig) :: cfg + INTEGER :: conn(2, NE), fixed(6), es, k, amp_n(NE) + REAL(wp) :: q0(3*NN), v0(3*NN), f_ext(3*NN), fluid(3, NN), wl(NN), q_moved(3*NN) + REAL(wp) :: l0(NE), ea(NE), rho_a(NE), cl(NE), dia(NE), cf(NE), df(NE), amp(3, CD_VIV_AMP_MAXP, NE) + CHARACTER(240) :: em + + DO k = 1, NE + conn(:, k) = [k, k + 1] + END DO + q0 = 0.0_wp + DO k = 1, NN + q0(3*k - 2) = REAL(k - 1, wp) + q0(3*k) = -5.0_wp + END DO + v0 = 0.0_wp + f_ext = 0.0_wp + fixed = [1, 2, 3, 3*NN - 2, 3*NN - 1, 3*NN] + l0 = 0.99_wp + ea = 1.0e6_wp + rho_a = 10.0_wp + fluid = 0.0_wp + fluid(2, :) = 0.5_wp + wl = 0.0_wp + cl = 0.8_wp + dia = 0.1_wp + cf = 0.18_wp + df = 0.08_wp + amp = 0.0_wp + amp_n = 2 + DO k = 1, NE + amp(:, 1, k) = [0.0_wp, 0.8_wp, 1.0_wp] + amp(:, 2, k) = [0.5_wp, 0.4_wp, 1.5_wp] + END DO + CALL CD_Init_Model(models(1), q0, v0, conn, l0, ea, rho_a, .TRUE., f_ext, fixed, cfg, es, em, & + fluid_velocity=fluid, drag_waterline_z=wl, drag_rho=1025.0_wp, & + drag_diameter=0.1_wp, drag_cdn=1.2_wp, drag_cdt=0.0_wp) + CALL require(es == CD_MODEL_OK, 'viv-layout:init-line: '//TRIM(em)) + CALL CD_Set_Model_VIV(models(1), 1025.0_wp, cl, dia, cf, df, 0.25_wp, es, em) + CALL require(es == CD_MODEL_OK, 'viv-layout:viv: '//TRIM(em)) + CALL CD_Init_System_From_Models(system, models, es, em) + CALL require(es == CD_SYSTEM_OK, 'viv-layout:init-system: '//TRIM(em)) + CALL CD_End_Model(models(1), es, em) + IF (.NOT. CD_System_Is_Initialized(system)) RETURN + + CALL CD_System_Snapshot(system, es, em) + CALL require(es == CD_SYSTEM_OK, 'viv-layout:snapshot-without-tables: '//TRIM(em)) + CALL CD_Set_Model_VIV(system%lines(1), 1025.0_wp, cl, dia, cf, df, 0.25_wp, es, em, amp=amp, amp_n=amp_n) + CALL require(es == CD_MODEL_OK .AND. CD_Model_VIV_NMS(system%lines(1)) == 6, 'viv-layout:tables: '//TRIM(em)) + q_moved = system%lines(1)%q + q_moved(8) = q_moved(8) + 0.01_wp + system%lines(1)%q = q_moved + CALL CD_System_Restore(system, es, em) + CALL require(es == CD_SYSTEM_BADINPUT .AND. INDEX(em, 'VIV configuration') > 0, & + 'viv-layout:restore-across-layouts-refused: '//TRIM(em)) + CALL require(ALL(system%lines(1)%q == q_moved), 'viv-layout:nothing-restored') + CALL CD_System_Snapshot(system, es, em) + CALL require(es == CD_SYSTEM_OK .AND. SIZE(system%snap_viv) == 7*NN, 'viv-layout:snapshot-resized: '//TRIM(em)) + system%lines(1)%viv_ms(5, 3) = 0.25_wp + CALL CD_System_Restore(system, es, em) + CALL require(es == CD_SYSTEM_OK .AND. system%lines(1)%viv_ms(5, 3) == 0.0_wp, & + 'viv-layout:restore-with-tables: '//TRIM(em)) + CALL CD_End_System(system, es, em) + END SUBROUTINE case_viv_layout_snapshot + SUBROUTINE require(cond, label) LOGICAL, INTENT(IN) :: cond CHARACTER(*), INTENT(IN) :: label diff --git a/tests/test_viv_amplitude_deck.f90 b/tests/test_viv_amplitude_deck.f90 new file mode 100644 index 0000000..6f2af92 --- /dev/null +++ b/tests/test_viv_amplitude_deck.f90 @@ -0,0 +1,300 @@ +! File: tests/test_viv_amplitude_deck.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +PROGRAM test_viv_amplitude_deck + !! Amplitude-dependent VIV coefficients on a deck (the optional VIV AMPLITUDE section, rows + !! TypeName AD Cv [CdAmp]; the amplitude estimate of Thorsen et al. 2016, Eq. 8 and 9): the taut + !! cable of the wake-oscillator gate (100 m, D 0.1 m, 50 kN, pinned at 50 m depth, 50 elements) + !! with the synchronisation lift Cl 0.8 in a uniform 0.15 m/s current along y, as a finite-EI + !! cable (EI 1 N m^2) and as an EI = 0 line, each run checked on both line kinds: + !! A1 a table that gives Cv = Cl and CdAmp = 1 at every amplitude is the deck without the + !! section, to the printed digits; + !! A2 the amplitude channel VIVAmp1N26 at mid-span follows the half peak-to-peak cross-flow + !! displacement of the steady response there within 1 % (it projects the velocity across + !! the ambient flow, as Thorsen et al.: across the relative flow, which turns with the + !! response velocity, it read 16 % low at this A/D of 0.68); + !! A3 a table whose Cv falls from Cl at A/D 0.1 to zero at A/D AD_ZERO, below the free response + !! of the constant-Cl deck, holds the steady response between those two amplitudes; + !! A4 a table with Cv 0 and CdAmp 2 at every amplitude (no lift, twice the drag) settles at the + !! static in-line mid-span offset of the deck with Cd 2.4, within 0.5 %, at rest; + !! A5 refusals by name: a malformed or non-numeric row, an unknown type, a type without the + !! synchronisation lift, rows of different columns, A/D not increasing, values out of range, + !! a one-row table, more than 32 rows, and the VIVAmp channel on a line without a table. + USE CableDyn_Precision, ONLY: wp + USE CableDyn_DeckDriver, ONLY: CD_Run_Deck_Driver, CD_DECKDRV_OK + IMPLICIT NONE + REAL(wp), PARAMETER :: D = 0.1_wp, AD_ZERO = 0.3_wp + INTEGER :: nfail = 0 + + CALL write_current('vad_current.dat') + CALL check_kind('1.0', 'finite-EI') + CALL check_kind('0.0', 'EI = 0') + CALL check_refusals() + IF (nfail > 0) THEN + WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' + ERROR STOP 1 + END IF + WRITE (*, '(A)') 'PASS: VIV amplitude deck gates' + +CONTAINS + + SUBROUTINE require(cond, label) + LOGICAL, INTENT(IN) :: cond + CHARACTER(*), INTENT(IN) :: label + IF (cond) RETURN + nfail = nfail + 1 + WRITE (*, '(A)') 'FAIL: '//TRIM(label) + END SUBROUTINE require + + SUBROUTINE write_current(path) + CHARACTER(*), INTENT(IN) :: path + INTEGER :: u + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'MoorDyn v2 water kinematics file' + WRITE (u, '(A)') 'uniform current along y for the VIV amplitude deck gate' + WRITE (u, '(A)') '--------------------------- WAVES -------------------------------------' + WRITE (u, '(A)') '0 WaveKinMod - type of wave input' + WRITE (u, '(A)') '"" WaveKinFile - file containing wave elevation time series' + WRITE (u, '(A)') '0.000000E+00 dtWave - time step to use in setting up wave kinematics grid (s)' + WRITE (u, '(A)') '0 WaveDir - wave heading (deg)' + WRITE (u, '(A)') '2 - X wave input type' + WRITE (u, '(A)') '-10, 110, 2 - X wave grid point data' + WRITE (u, '(A)') '2 - Y wave input type' + WRITE (u, '(A)') '-10, 10, 2 - Y wave grid point data' + WRITE (u, '(A)') '2 - Z wave input type' + WRITE (u, '(A)') '-100, 0, 2 - Z wave grid point data' + WRITE (u, '(A)') '--------------------------- CURRENT -------------------------------------' + WRITE (u, '(A)') '1 CurrentMod - type of current input' + WRITE (u, '(A)') 'z-depth x-current y-current' + WRITE (u, '(A)') '(m) (m/s) (m/s)' + WRITE (u, '(A)') '0.0 0.0 0.15' + WRITE (u, '(A)') '-100.0 0.0 0.15' + WRITE (u, '(A)') '--------------------- need this line ------------------' + CLOSE (u) + END SUBROUTINE write_current + + SUBROUTINE write_deck(path, amp_rows, tmax, ei, cl, amp_channel, cd) + !! amp_rows: the VIV AMPLITUDE section's data rows, ';'-separated ('' for no section); ei the + !! type's EI, cl its LINE TYPES Cl (default 0.8), cd its Cd (default 1.2); amp_channel adds + !! VIVAmp1N26 to the outputs (default: with a section). + CHARACTER(*), INTENT(IN) :: path, amp_rows, ei + REAL(wp), INTENT(IN) :: tmax + CHARACTER(*), INTENT(IN), OPTIONAL :: cl, cd + LOGICAL, INTENT(IN), OPTIONAL :: amp_channel + CHARACTER(32) :: cl_col, cd_col + INTEGER :: u, i0, i1 + LOGICAL :: with_amp + cl_col = '0.8' + IF (PRESENT(cl)) cl_col = cl + cd_col = '1.2' + IF (PRESENT(cd)) cd_col = cd + with_amp = LEN_TRIM(amp_rows) > 0 + IF (PRESENT(amp_channel)) with_amp = amp_channel + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') '--------------------- CableDyn Input File ---------------------------------' + WRITE (u, '(A)') 'VIV amplitude deck gate: taut cable in a uniform 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)') 'riser 0.10 10.0 5.0e7 -0.8 '//TRIM(ei)//' '//TRIM(cd_col)// & + ' 1.0 0.0 0.0 '//TRIM(cl_col)//' 0.08 0.18' + WRITE (u, '(A)') '----------------------- POINTS ----------------------------------------------' + WRITE (u, '(A)') 'ID Attachment X Y Z M V CdA CA' + 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)') '----------------------- LINES -----------------------------------------------' + WRITE (u, '(A)') 'ID NodeA NodeB Outputs' + WRITE (u, '(A)') '1 1 2 -' + WRITE (u, '(A)') '----------------------- SECTIONS --------------------------------------------' + WRITE (u, '(A)') 'LineID LineType Length NumSegs' + WRITE (u, '(A)') '1 riser 99.900100 50' + IF (LEN_TRIM(amp_rows) > 0) THEN + WRITE (u, '(A)') '----------------------- VIV AMPLITUDE ---------------------------------------' + WRITE (u, '(A)') 'TypeName AD Cv CdAmp' + WRITE (u, '(A)') '(-) (-) (-) (-)' + i0 = 1 + DO + i1 = INDEX(amp_rows(i0:), ';') + IF (i1 == 0) THEN + WRITE (u, '(A)') TRIM(amp_rows(i0:)) + EXIT + END IF + WRITE (u, '(A)') amp_rows(i0:i0 + i1 - 2) + i0 = i0 + i1 + END DO + END IF + WRITE (u, '(A)') '---------------------- OPTIONS ----------------------------------------------' + WRITE (u, '(A)') '0.01 dtM' + WRITE (u, '(A)') '100.0 WtrDpth' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') 'vad_current.dat WaterKin' + WRITE (u, '(A,F8.3,A)') ' ', tmax, ' TMax' + WRITE (u, '(A)') '---------------------- OUTPUTS -----------------------------------------------' + WRITE (u, '(A)') 'L1N26PZ' + WRITE (u, '(A)') 'L1N26PY' + IF (with_amp) WRITE (u, '(A)') 'VIVAmp1N26' + WRITE (u, '(A)') 'END' + WRITE (u, '(A)') '------------------------- need this line --------------------------------------' + CLOSE (u) + END SUBROUTINE write_deck + + SUBROUTINE run(deck, root, ok, msg) + CHARACTER(*), INTENT(IN) :: deck, root + LOGICAL, INTENT(OUT) :: ok + CHARACTER(*), INTENT(OUT) :: msg + LOGICAL :: conv + INTEGER :: es + CALL CD_Run_Deck_Driver(deck, root, conv, es, msg) + ok = es == CD_DECKDRV_OK .AND. conv + END SUBROUTINE run + + SUBROUTINE read_out(path, ncol, tab, n) + !! The rows (time and ncol - 1 channels) of a deck's main output file. + CHARACTER(*), INTENT(IN) :: path + INTEGER, INTENT(IN) :: ncol + REAL(wp), ALLOCATABLE, INTENT(OUT) :: tab(:, :) + INTEGER, INTENT(OUT) :: n + CHARACTER(1024) :: rec + INTEGER :: u, ios + ALLOCATE (tab(ncol, 20000)) + n = 0 + OPEN (NEWUNIT=u, FILE=path, STATUS='OLD', ACTION='READ', IOSTAT=ios) + IF (ios /= 0) RETURN + READ (u, '(A)') rec + READ (u, '(A)') rec + DO + READ (u, '(A)', IOSTAT=ios) rec + IF (ios /= 0) EXIT + IF (LEN_TRIM(rec) == 0) CYCLE + IF (n == SIZE(tab, 2)) EXIT + n = n + 1 + READ (rec, *) tab(:, n) + END DO + CLOSE (u) + END SUBROUTINE read_out + + REAL(wp) FUNCTION window_mean(tab, n, row, t0) RESULT(m) + REAL(wp), INTENT(IN) :: tab(:, :), t0 + INTEGER, INTENT(IN) :: n, row + LOGICAL :: keep(n) + keep = tab(1, 1:n) >= t0 + m = SUM(PACK(tab(row, 1:n), keep))/REAL(MAX(1, COUNT(keep)), wp) + END FUNCTION window_mean + + REAL(wp) FUNCTION window_ad(tab, n, t0) RESULT(ad) + !! Half peak-to-peak mid-span cross-flow displacement over D from t0 on. + REAL(wp), INTENT(IN) :: tab(:, :), t0 + INTEGER, INTENT(IN) :: n + LOGICAL :: keep(n) + REAL(wp), ALLOCATABLE :: z(:) + keep = tab(1, 1:n) >= t0 + z = PACK(tab(2, 1:n), keep) + ad = 0.5_wp*(MAXVAL(z) - MINVAL(z))/D + END FUNCTION window_ad + + SUBROUTINE check_kind(ei, label) + CHARACTER(*), INTENT(IN) :: ei, label + CHARACTER(16) :: tag + REAL(wp), ALLOCATABLE :: tn(:, :), ti(:, :), tl(:, :), tg(:, :), tc(:, :) + INTEGER :: nn, ni, nl, ng, nc + REAL(wp) :: ad_n, ad_i, amp_i, ad_l, amp_l, y_g, y_static, amp_g + LOGICAL :: ok + CHARACTER(1024) :: msg + tag = MERGE('fe', 'e0', ei /= '0.0') + CALL write_deck('vad_'//TRIM(tag)//'_none.dat', '', 100.0_wp, ei) + CALL run('vad_'//TRIM(tag)//'_none.dat', 'vad_'//TRIM(tag)//'_none', ok, msg) + CALL require(ok, 'A1 ('//label//'): the deck without the section runs: '//TRIM(msg)) + CALL write_deck('vad_'//TRIM(tag)//'_ident.dat', 'riser 0.0 0.8 1.0;riser 1.0 0.8 1.0', 100.0_wp, ei) + CALL run('vad_'//TRIM(tag)//'_ident.dat', 'vad_'//TRIM(tag)//'_ident', ok, msg) + CALL require(ok, 'A1 ('//label//'): the identity-table deck runs: '//TRIM(msg)) + CALL write_deck('vad_'//TRIM(tag)//'_limit.dat', 'riser 0.0 0.8;riser 0.1 0.8;riser 0.3 0.0', 100.0_wp, ei) + CALL run('vad_'//TRIM(tag)//'_limit.dat', 'vad_'//TRIM(tag)//'_limit', ok, msg) + CALL require(ok, 'A3 ('//label//'): the falling-Cv deck runs: '//TRIM(msg)) + CALL write_deck('vad_'//TRIM(tag)//'_drag.dat', 'riser 0.0 0.0 2.0;riser 1.0 0.0 2.0', 100.0_wp, ei) + CALL run('vad_'//TRIM(tag)//'_drag.dat', 'vad_'//TRIM(tag)//'_drag', ok, msg) + CALL require(ok, 'A4 ('//label//'): the Cv 0, CdAmp 2 deck runs: '//TRIM(msg)) + CALL write_deck('vad_'//TRIM(tag)//'_cd24.dat', '', 0.1_wp, ei, cd='2.4') + CALL run('vad_'//TRIM(tag)//'_cd24.dat', 'vad_'//TRIM(tag)//'_cd24', ok, msg) + CALL require(ok, 'A4 ('//label//'): the Cd 2.4 deck runs: '//TRIM(msg)) + CALL read_out('vad_'//TRIM(tag)//'_cd24.out', 3, tc, nc) + CALL read_out('vad_'//TRIM(tag)//'_none.out', 3, tn, nn) + CALL read_out('vad_'//TRIM(tag)//'_ident.out', 4, ti, ni) + CALL read_out('vad_'//TRIM(tag)//'_limit.out', 4, tl, nl) + CALL read_out('vad_'//TRIM(tag)//'_drag.out', 4, tg, ng) + CALL require(nn > 5000 .AND. ni == nn .AND. nl == nn .AND. ng == nn, 'A1 ('//label//'): the runs wrote '// & + 'matching rows') + IF (.NOT. (nn > 5000 .AND. ni == nn .AND. nl == nn .AND. ng == nn)) RETURN + ! A1: the identity table + CALL require(ALL(ti(1:3, 1:ni) == tn(1:3, 1:nn)), 'A1 ('//label//'): Cv = Cl and CdAmp 1 is the deck '// & + 'without the section') + ! A2: the amplitude estimate against the response + ad_n = window_ad(tn, nn, 60.0_wp) + ad_i = window_ad(ti, ni, 60.0_wp) + amp_i = window_mean(ti, ni, 4, 60.0_wp)/D + WRITE (*, '(A,3F8.4)') 'A2 ('//label//'): A/D constant Cl, identity table, its VIVAmp/D: ', ad_n, ad_i, amp_i + CALL require(ad_i > 0.05_wp .AND. ABS(amp_i/ad_i - 1.0_wp) <= 0.01_wp, 'A2 ('//label//'): VIVAmp follows '// & + 'the response amplitude within 1 %') + ! A3: self-limiting + ad_l = window_ad(tl, nl, 60.0_wp) + amp_l = window_mean(tl, nl, 4, 60.0_wp)/D + WRITE (*, '(A,2F8.4)') 'A3 ('//label//'): falling-Cv A/D and VIVAmp/D: ', ad_l, amp_l + CALL require(ad_n > AD_ZERO, 'A3 ('//label//'): the constant-Cl response exceeds the zero of the table') + CALL require(ABS(amp_l/ad_l - 1.0_wp) <= 0.01_wp, 'A3 ('//label//'): VIVAmp follows it within 1 %') + CALL require(ad_l > 0.1_wp .AND. ad_l < AD_ZERO, 'A3 ('//label//'): the falling Cv holds the response '// & + 'inside its falling range') + ! A4: the drag factor, on the mid-span in-line offset from the line between the ends (y = 0) + CALL require(nc >= 1, 'A4 ('//label//'): the Cd 2.4 deck wrote its static row') + IF (nc < 1) RETURN + y_static = tc(3, 1) + y_g = window_mean(tg, ng, 3, 80.0_wp) + amp_g = window_mean(tg, ng, 4, 80.0_wp)/D + WRITE (*, '(A,2F10.6,ES11.3)') 'A4 ('//label//'): Cd 2.4 static, Cv 0 CdAmp 2 final offsets [m], '// & + 'VIVAmp/D: ', y_static, y_g, amp_g + CALL require(y_static > 0.0_wp .AND. ABS(y_g/y_static - 1.0_wp) <= 0.005_wp, 'A4 ('//label//'): CdAmp 2 '// & + 'settles at the offset of Cd 2.4') + CALL require(window_ad(tg, ng, 80.0_wp) < 1.0e-3_wp .AND. amp_g < 1.0e-2_wp, 'A4 ('//label//'): at rest, '// & + 'without lift') + END SUBROUTINE check_kind + + SUBROUTINE check_refusals() + CHARACTER(2048) :: many + INTEGER :: k + CALL refused('riser 0.0 0.8 1.0 2.0', 'TypeName AD Cv [CdAmp]', 'a row of five columns') + CALL refused('riser 0.0;riser 1.0', 'TypeName AD Cv [CdAmp]', 'a row of two columns') + CALL refused('riser 0.0 x;riser 1.0 0.8', 'plain numbers', 'a non-numeric Cv') + CALL refused('cable 0.0 0.8;cable 1.0 0.8', 'undefined LINE TYPE', 'an unknown type') + CALL refused('riser 0.0 0.8;riser 1.0 0.8', 'give the type LINE TYPES Cl > 0', 'a type without lift', & + cl='0.0') + CALL refused('riser 0.0 0.8 1.0;riser 1.0 0.8', 'same columns', 'rows of different columns') + CALL refused('riser 0.5 0.8;riser 0.5 0.6', 'increase strictly in AD', 'a repeated AD') + CALL refused('riser -0.1 0.8;riser 1.0 0.8', 'AD >= 0, Cv >= 0 and CdAmp > 0', 'a negative AD') + CALL refused('riser 0.0 -0.8;riser 1.0 0.8', 'AD >= 0, Cv >= 0 and CdAmp > 0', 'a negative Cv') + CALL refused('riser 0.0 0.8 0.0;riser 1.0 0.8 1.0', 'AD >= 0, Cv >= 0 and CdAmp > 0', 'a zero CdAmp') + CALL refused('riser 0.0 0.8', 'at least two', 'a one-row table') + many = '' + DO k = 0, 32 + WRITE (many(LEN_TRIM(many) + 1:), '(A,F5.2,A)') 'riser ', 0.01_wp*REAL(k, wp), ' 0.8;' + END DO + many(LEN_TRIM(many):LEN_TRIM(many)) = ' ' + CALL refused(TRIM(many), 'more than 32', 'a table of 33 rows') + CALL refused('', 'has no VIV AMPLITUDE table', 'VIVAmp on a line without a table', amp_channel=.TRUE.) + END SUBROUTINE check_refusals + + SUBROUTINE refused(rows, needle, what, cl, amp_channel) + CHARACTER(*), INTENT(IN) :: rows, needle, what + CHARACTER(*), INTENT(IN), OPTIONAL :: cl + LOGICAL, INTENT(IN), OPTIONAL :: amp_channel + LOGICAL :: ok + CHARACTER(1024) :: msg + IF (PRESENT(cl)) THEN + CALL write_deck('vad_bad.dat', rows, 1.0_wp, '1.0', cl=cl) + ELSE IF (PRESENT(amp_channel)) THEN + CALL write_deck('vad_bad.dat', rows, 1.0_wp, '1.0', amp_channel=amp_channel) + ELSE + CALL write_deck('vad_bad.dat', rows, 1.0_wp, '1.0') + END IF + CALL run('vad_bad.dat', 'vad_bad', ok, msg) + CALL require(.NOT. ok .AND. INDEX(msg, needle) > 0, 'A5: '//what//' is refused: '//TRIM(msg)) + END SUBROUTINE refused + +END PROGRAM test_viv_amplitude_deck diff --git a/tests/test_viv_amplitude_kernel.f90 b/tests/test_viv_amplitude_kernel.f90 new file mode 100644 index 0000000..385b60c --- /dev/null +++ b/tests/test_viv_amplitude_kernel.f90 @@ -0,0 +1,241 @@ +! File: tests/test_viv_amplitude_kernel.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +PROGRAM test_viv_amplitude_kernel + !! The cross-flow amplitude estimate of Thorsen et al. (2016, Eq. 8 and 9; CD_VIV_Amplitude_Update) + !! and the amplitude tables (CD_VIV_Table, CD_VIV_Check_Amp_Table): + !! K1 a sinusoidal cross-flow velocity y' = om y0 cos(om t + p) with a step that does not divide + !! the period: after the first half cycle the half-cycle amplitude is y0 within 3e-6 relative + !! (the trapezoidal (om dt)^2/12 is 1.9e-6), + !! halving the step cuts the error about four times (trapezoidal travel, interpolated + !! crossings), and the smoothed amplitude follows Eq. 9 (within 1e-9 of y0 after 400 steps); + !! K2 a velocity that touches zero without changing sign ends no half cycle, a velocity that + !! changes sign does, also through a sample at exactly zero (the travel is signed); + !! K3 a growing oscillation y0(t) = a t: each half-cycle value is the mean amplitude of its half + !! cycle (within 0.1 % from the sixth period, the extremes then within that of a t); + !! K4 the table interpolates linearly and holds its end values; a one-row table is constant; + !! a NaN argument stays inside the table (NaN back, or the one row); + !! K5 the table check refuses each bad table by name and accepts a good one. + USE, INTRINSIC :: IEEE_ARITHMETIC, ONLY: IEEE_VALUE, IEEE_QUIET_NAN, IEEE_IS_NAN + USE CableDyn_Precision, ONLY: wp + USE CableDyn_VIV, ONLY: CD_VIV_Amplitude_Update, CD_VIV_Table, CD_VIV_Check_Amp_Table, CD_VIV_AMP_MAXP, & + CD_VIV_AMP_KDT + IMPLICIT NONE + REAL(wp), PARAMETER :: PI = 3.14159265358979323846_wp + INTEGER :: nfail = 0 + + CALL check_sinusoid() + CALL check_touch() + CALL check_growth() + CALL check_table() + CALL check_tables_validated() + IF (nfail > 0) THEN + WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' + ERROR STOP 1 + END IF + WRITE (*, '(A)') 'PASS: VIV amplitude estimate and tables' + +CONTAINS + + SUBROUTINE require(cond, label) + LOGICAL, INTENT(IN) :: cond + CHARACTER(*), INTENT(IN) :: label + IF (cond) RETURN + nfail = nfail + 1 + WRITE (*, '(A)') 'FAIL: '//TRIM(label) + END SUBROUTINE require + + SUBROUTINE run_sinusoid(dt, nstep, y0, err, smooth_err) + !! The largest relative error of the half-cycle amplitude over the run after the first two + !! crossings, and the final error of the smoothed one. + REAL(wp), INTENT(IN) :: dt, y0 + INTEGER, INTENT(IN) :: nstep + REAL(wp), INTENT(OUT) :: err, smooth_err + REAL(wp), PARAMETER :: om = 2.0_wp*PI/1.3_wp, ph = 0.4_wp + REAL(wp) :: st(4), y_half + INTEGER :: i, ncross + st = 0.0_wp + st(4) = om*y0*COS(ph) + err = 0.0_wp + ncross = 0 + y_half = 0.0_wp + DO i = 1, nstep + CALL CD_VIV_Amplitude_Update(st, om*y0*COS(om*REAL(i, wp)*dt + ph), dt) + IF (st(2) /= y_half) THEN + ncross = ncross + 1 + y_half = st(2) + IF (ncross > 1) err = MAX(err, ABS(st(2)/y0 - 1.0_wp)) + END IF + END DO + smooth_err = ABS(st(3)/y0 - 1.0_wp) + CALL require(ncross > 10, 'K1: the sinusoid crosses zero') + END SUBROUTINE run_sinusoid + + SUBROUTINE check_sinusoid() + REAL(wp) :: e1, e2, s1, s2 + CALL run_sinusoid(1.0e-3_wp, 13000, 0.07_wp, e1, s1) + CALL run_sinusoid(0.5e-3_wp, 26000, 0.07_wp, e2, s2) + WRITE (*, '(A,2ES11.3,A,F6.2)') 'K1: half-cycle error at dt, dt/2: ', e1, e2, '; ratio ', e1/e2 + CALL require(e1 <= 3.0e-6_wp, 'K1: the half-cycle amplitude is y0 within 3e-6') + CALL require(e1/e2 > 3.0_wp .AND. e1/e2 < 5.0_wp, 'K1: the error is second order in the step') + CALL require(s1 <= 1.0e-5_wp .AND. s2 <= 1.0e-5_wp, 'K1: the smoothed amplitude settles on y0') + CALL check_smoothing() + END SUBROUTINE check_sinusoid + + SUBROUTINE check_smoothing() + !! Eq. 9 per step: y0s_n+1 = y0s_n + k_a dt (y0 - y0s_n) with the half-cycle amplitude held. + REAL(wp) :: st(4), expect + INTEGER :: i + st = [0.0_wp, 0.5_wp, 0.0_wp, 1.0_wp] + expect = 0.0_wp + DO i = 1, 400 + CALL CD_VIV_Amplitude_Update(st, 1.0_wp, 1.0e-3_wp) + expect = expect + CD_VIV_AMP_KDT*(0.5_wp - expect) + END DO + CALL require(st(3) == expect, 'K1: the smoothing is Eq. 9 step by step') + CALL require(ABS(st(3) - 0.5_wp) <= 1.0e-9_wp, 'K1: and reaches the held amplitude') + CALL require(st(2) == 0.5_wp, 'K1: no crossing, the half-cycle amplitude is held') + END SUBROUTINE check_smoothing + + SUBROUTINE check_touch() + REAL(wp) :: st(4) + st = [0.0_wp, 0.25_wp, 0.25_wp, 1.0_wp] + CALL CD_VIV_Amplitude_Update(st, 0.0_wp, 0.1_wp) + CALL CD_VIV_Amplitude_Update(st, 1.0_wp, 0.1_wp) + CALL require(st(2) == 0.25_wp, 'K2: touching zero without a sign change ends no half cycle') + CALL require(ABS(st(1) - 0.1_wp) <= 1.0e-15_wp, 'K2: the travel keeps accumulating') + CALL CD_VIV_Amplitude_Update(st, -1.0_wp, 0.1_wp) + ! the crossing halfway through the step: travel 0.1 + 0.025 before it, half of it the amplitude + CALL require(ABS(st(2) - 0.0625_wp) <= 1.0e-15_wp, 'K2: a sign change ends the half cycle at the crossing') + CALL require(ABS(st(1) + 0.025_wp) <= 1.0e-15_wp, 'K2: the rest of the step starts the next one, signed') + CALL check_zero_samples() + END SUBROUTINE check_touch + + SUBROUTINE check_zero_samples() + !! A triangular velocity sampled on its zeros, 0 1 2 1 0 -1 -2 -1 0 ... with dt 0.5: every + !! reversal passes through a sample at zero, and each half cycle travels 2 (exact for the + !! trapezoidal rule on a piecewise-linear velocity), so y0 = 1; a touch (1 0 1) ends none. + REAL(wp), PARAMETER :: wave(8) = [1.0_wp, 2.0_wp, 1.0_wp, 0.0_wp, -1.0_wp, -2.0_wp, -1.0_wp, 0.0_wp] + REAL(wp) :: st(4), s_before + INTEGER :: i, n_half + LOGICAL :: all_one + st = 0.0_wp + n_half = 0 + all_one = .TRUE. + DO i = 1, 8*5 + s_before = st(1) + CALL CD_VIV_Amplitude_Update(st, wave(MOD(i - 1, 8) + 1), 0.5_wp) + ! a half cycle ends where the signed travel changes sign + IF (s_before*st(1) < 0.0_wp) THEN + n_half = n_half + 1 + all_one = all_one .AND. st(2) == 1.0_wp + END IF + END DO + CALL require(n_half == 9 .AND. all_one, 'K2: each reversal through a sample at zero ends a half cycle, y0 = 1') + CALL require(st(1) == -2.0_wp .AND. st(4) == 0.0_wp, 'K2: the run ends on a zero sample, its half cycle open') + st = [0.75_wp, 0.5_wp, 0.5_wp, 0.0_wp] + CALL CD_VIV_Amplitude_Update(st, 1.0_wp, 0.5_wp) + CALL require(st(2) == 0.5_wp .AND. st(1) == 1.0_wp, 'K2: a touch through a zero sample (+, 0, +) ends none') + st = [0.75_wp, 0.5_wp, 0.5_wp, 0.0_wp] + CALL CD_VIV_Amplitude_Update(st, -1.0_wp, 0.5_wp) + CALL require(st(2) == 0.375_wp .AND. st(1) == -0.25_wp, 'K2: a reversal through it (+, 0, -) ends one there') + END SUBROUTINE check_zero_samples + + SUBROUTINE check_growth() + !! y = a t sin(om t): y' = a sin(om t) + a t om cos(om t). Between crossings of y' the travel + !! is |y(t2) - y(t1)|, half of which is the mean of the two extreme amplitudes. + REAL(wp), PARAMETER :: om = 2.0_wp*PI, a = 0.01_wp, dt = 1.0e-4_wp + REAL(wp) :: st(4), y_half, t, yd, t_prev_cross, y_prev_ext, err + INTEGER :: i, ncross + st = 0.0_wp + st(4) = 0.0_wp + y_half = 0.0_wp + ncross = 0 + err = 0.0_wp + t_prev_cross = 0.0_wp + y_prev_ext = 0.0_wp + DO i = 1, 100000 + t = REAL(i, wp)*dt + yd = a*SIN(om*t) + a*t*om*COS(om*t) + CALL CD_VIV_Amplitude_Update(st, yd, dt) + IF (st(2) /= y_half) THEN + ncross = ncross + 1 + y_half = st(2) + ! the extreme just passed is at about the crossing time; its |y| = a t + IF (ncross > 10) err = MAX(err, ABS(st(2)/(0.5_wp*(a*t + y_prev_ext)) - 1.0_wp)) + y_prev_ext = a*t + END IF + END DO + WRITE (*, '(A,ES11.3)') 'K3: growing oscillation, largest error of the half-cycle mean amplitude: ', err + CALL require(ncross > 15 .AND. err <= 1.0e-3_wp, & + 'K3: each half-cycle value is the mean amplitude of the half cycle') + END SUBROUTINE check_growth + + SUBROUTINE check_table() + REAL(wp) :: xs(3), ys(3), nan, y + xs = [0.0_wp, 0.4_wp, 0.8_wp] + ys = [0.5_wp, 1.0_wp, 0.0_wp] + CALL require(CD_VIV_Table(-1.0_wp, xs, ys) == 0.5_wp, 'K4: held below the first row') + CALL require(CD_VIV_Table(0.0_wp, xs, ys) == 0.5_wp, 'K4: the first row') + CALL require(ABS(CD_VIV_Table(0.2_wp, xs, ys) - 0.75_wp) <= 1.0e-15_wp, 'K4: linear between rows') + CALL require(CD_VIV_Table(0.4_wp, xs, ys) == 1.0_wp, 'K4: an interior row') + CALL require(ABS(CD_VIV_Table(0.7_wp, xs, ys) - 0.25_wp) <= 1.0e-15_wp, 'K4: linear on the falling side') + CALL require(CD_VIV_Table(5.0_wp, xs, ys) == 0.0_wp, 'K4: held beyond the last row') + CALL require(CD_VIV_Table(3.0_wp, xs(1:1), ys(1:1)) == 0.5_wp, 'K4: a one-row table is constant') + ! A NaN amplitude (a diverged run) stays inside the table: NaN back, or the one row. + nan = IEEE_VALUE(nan, IEEE_QUIET_NAN) + y = CD_VIV_Table(nan, xs, ys) + CALL require(IEEE_IS_NAN(y), 'K4: a NaN amplitude gives NaN') + CALL require(CD_VIV_Table(nan, xs(1:1), ys(1:1)) == 0.5_wp, 'K4: a one-row table is constant at NaN') + END SUBROUTINE check_table + + SUBROUTINE check_tables_validated() + REAL(wp) :: amp(3, CD_VIV_AMP_MAXP, 2), cl(2) + INTEGER :: n(2) + CHARACTER(160) :: msg + CALL good(amp, n, cl) + CALL CD_VIV_Check_Amp_Table(amp, n, cl, msg) + CALL require(LEN_TRIM(msg) == 0, 'K5: a good table passes: '//TRIM(msg)) + CALL good(amp, n, cl) + amp(1, 2, 1) = 0.0_wp + CALL bad(amp, n, cl, 'increase strictly', 'a repeated A/D') + CALL good(amp, n, cl) + amp(1, 1, 1) = -0.1_wp + CALL bad(amp, n, cl, 'A/D >= 0', 'a negative A/D') + CALL good(amp, n, cl) + amp(2, 2, 1) = -0.1_wp + CALL bad(amp, n, cl, 'C_v >= 0', 'a negative C_v') + CALL good(amp, n, cl) + amp(3, 1, 1) = 0.0_wp + CALL bad(amp, n, cl, 'drag factor > 0', 'a zero drag factor') + CALL good(amp, n, cl) + cl(1) = 0.0_wp + CALL bad(amp, n, cl, 'needs the cross-flow lift', 'a table on an element without lift') + CALL good(amp, n, cl) + n(1) = CD_VIV_AMP_MAXP + 1 + CALL bad(amp, n, cl, '0 to 32 rows', 'too many rows') + CALL good(amp, n, cl) + CALL CD_VIV_Check_Amp_Table(amp(:, 1:4, :), n, cl, msg) + CALL require(INDEX(msg, 'shapes') > 0, 'K5: a table of the wrong shape is refused: '//TRIM(msg)) + END SUBROUTINE check_tables_validated + + SUBROUTINE good(amp, n, cl) + REAL(wp), INTENT(OUT) :: amp(:, :, :), cl(:) + INTEGER, INTENT(OUT) :: n(:) + amp = 0.0_wp + amp(:, 1, 1) = [0.0_wp, 0.8_wp, 1.0_wp] + amp(:, 2, 1) = [0.5_wp, 0.0_wp, 2.0_wp] + n = [2, 0] + cl = [0.8_wp, 0.0_wp] + END SUBROUTINE good + + SUBROUTINE bad(amp, n, cl, needle, what) + REAL(wp), INTENT(IN) :: amp(:, :, :), cl(:) + INTEGER, INTENT(IN) :: n(:) + CHARACTER(*), INTENT(IN) :: needle, what + CHARACTER(160) :: msg + CALL CD_VIV_Check_Amp_Table(amp, n, cl, msg) + CALL require(INDEX(msg, needle) > 0, 'K5: '//what//' is refused: '//TRIM(msg)) + END SUBROUTINE bad + +END PROGRAM test_viv_amplitude_kernel diff --git a/tests/test_viv_coupled.f90 b/tests/test_viv_coupled.f90 index bc07883..81320a6 100644 --- a/tests/test_viv_coupled.f90 +++ b/tests/test_viv_coupled.f90 @@ -33,7 +33,11 @@ PROGRAM test_viv_coupled !! * wake oscillator (a WAKE OSCILLATOR row, C_L0 0.3, on the cable, whose type has Cl 0; the !! EI = 0 riser keeps its synchronisation lift): the cable's checkpoint block grows by the wake !! state (2 per node), the restarted run continues bit for bit with it, a rebuild without the - !! VIV state does not, and a rewound step repeats. + !! VIV state does not, and a rewound step repeats; + !! * amplitude tables (a VIV AMPLITUDE table on both types, Cv falling from 0.8 at A/D 0 to 0.4 at + !! 1, CdAmp from 1 to 1.5): both checkpoint blocks grow by the amplitude estimate (4 per node), + !! the restarted run continues bit for bit with it, a rebuild without the VIV state does not, + !! and a rewound step repeats. 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, & @@ -53,13 +57,14 @@ PROGRAM test_viv_coupled INTEGER :: nfail ! the deck of the restart and rewind cases, and whether its lines carry in-line VIV CHARACTER(32) :: deck_name = 'viv_coupled.dat' - LOGICAL :: il_case = .FALSE., wake_case = .FALSE. + LOGICAL :: il_case = .FALSE., wake_case = .FALSE., amp_case = .FALSE. nfail = 0 CALL write_deck('viv_coupled.dat', 0.8_wp) CALL write_deck('viv_coupled_nolift.dat', 0.0_wp) CALL write_deck('viv_coupled_il.dat', 0.8_wp, inline=.TRUE.) CALL write_deck('viv_coupled_wake.dat', 0.8_wp, wake=.TRUE.) + CALL write_deck('viv_coupled_amp.dat', 0.8_wp, amp=.TRUE.) CALL case_lockin() CALL case_restart() CALL case_rewind() @@ -74,6 +79,11 @@ PROGRAM test_viv_coupled wake_case = .TRUE. CALL case_restart() CALL case_rewind() + deck_name = 'viv_coupled_amp.dat' + wake_case = .FALSE. + amp_case = .TRUE. + CALL case_restart() + CALL case_rewind() IF (nfail > 0) THEN WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' coupled VIV check(s) failed' ERROR STOP 1 @@ -361,7 +371,7 @@ LOGICAL FUNCTION rebuild(a, b, with_viv) RESULT(ok) 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 == MERGE(6, 3, il_case)*(ndof/3) + 1 + ok = ok .AND. nv == (MERGE(6, 3, il_case) + MERGE(4, 0, amp_case))*(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) @@ -374,7 +384,8 @@ LOGICAL FUNCTION rebuild(a, b, with_viv) RESULT(ok) 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 == (MERGE(6, 3, il_case) + MERGE(2, 0, wake_case))*a%cables(1)%line%nn + 1 + ok = ok .AND. nvc == (MERGE(6, 3, il_case) + MERGE(2, 0, wake_case) + MERGE(4, 0, amp_case))* & + 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) @@ -394,6 +405,13 @@ LOGICAL FUNCTION identical(a, b) RESULT(same) MAXVAL(ABS(a%cables(1)%line%viv_phi - b%cables(1)%line%viv_phi)) <= 0.0_wp IF (same .AND. wake_case) same = a%cables(1)%line%viv_wake .AND. & MAXVAL(ABS(a%cables(1)%line%wo_s - b%cables(1)%line%wo_s)) <= 0.0_wp + IF (same .AND. amp_case) THEN + ! the motion statistics with the amplitude estimate (rows 3-6) on both lines + same = a%sys%fast%system%lines(1)%has_viv_amp .AND. a%cables(1)%line%has_viv_amp .AND. & + SIZE(a%cables(1)%line%viv_ms, 1) == 6 .AND. & + MAXVAL(ABS(a%sys%fast%system%lines(1)%viv_ms - b%sys%fast%system%lines(1)%viv_ms)) <= 0.0_wp .AND. & + MAXVAL(ABS(a%cables(1)%line%viv_ms - b%cables(1)%line%viv_ms)) <= 0.0_wp + END IF IF (.NOT. (same .AND. il_case)) RETURN same = a%sys%fast%system%lines(1)%has_viv_il .AND. a%cables(1)%line%has_viv_il .AND. & MAXVAL(ABS(a%sys%fast%system%lines(1)%vil_phi - b%sys%fast%system%lines(1)%vil_phi)) <= 0.0_wp .AND. & @@ -422,15 +440,16 @@ 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, anchor_first, inline, wake) + SUBROUTINE write_deck(path, cl, window, dtm, anchor_first, inline, wake, amp) !! 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; !! inline adds the in-line VIV of both types (a VIV section, ClX 0.85); wake gives the cable - !! the wake oscillator instead of its lift (Cl 0 and a WAKE OSCILLATOR row, C_L0 0.3). + !! the wake oscillator instead of its lift (Cl 0 and a WAKE OSCILLATOR row, C_L0 0.3); amp a VIV + !! AMPLITUDE table on both types. CHARACTER(*), INTENT(IN) :: path REAL(wp), INTENT(IN) :: cl REAL(wp), INTENT(IN), OPTIONAL :: window, dtm - LOGICAL, INTENT(IN), OPTIONAL :: anchor_first, inline, wake + LOGICAL, INTENT(IN), OPTIONAL :: anchor_first, inline, wake, amp INTEGER :: u LOGICAL :: stock, wo REAL(wp) :: tw @@ -483,6 +502,16 @@ SUBROUTINE write_deck(path, cl, window, dtm, anchor_first, inline, wake) WRITE (u, '(A)') 'TypeName CL0 St eps A' WRITE (u, '(A)') 'cable 0.3 0.2 0.3 12' END IF + IF (PRESENT(amp)) THEN + IF (amp) THEN + WRITE (u, '(A)') '--------------------- VIV AMPLITUDE ---' + WRITE (u, '(A)') 'TypeName AD Cv CdAmp' + WRITE (u, '(A)') 'riser 0.0 0.8 1.0' + WRITE (u, '(A)') 'riser 1.0 0.4 1.5' + WRITE (u, '(A)') 'cable 0.0 0.8 1.0' + WRITE (u, '(A)') 'cable 1.0 0.4 1.5' + END IF + END IF WRITE (u, '(A)') '--------------------- OPTIONS ---' WRITE (u, '(A)') '100.0 WtrDpth' WRITE (u, '(A)') '1025.0 rhoW'