diff --git a/CHANGELOG.md b/CHANGELOG.md index 08fa1f6a..aceb1c69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,17 @@ All notable changes to CableDyn are recorded in this file. The format follows ### Added +- Deck currents on the standalone mixed `EI = 0` + finite-EI deck: a `current` OPTION (uniform or + profile), a WaterKin `CurrentMod 1` table and MoorDyn-C `Currents 1`/`2`/`5`, which the mixed + route refused, are taken in the static start of the chains and cables and sampled at every node + before each step with the single-line routes' updaters. Against the single-line routes on a + chain and a cable in a cross current: the static start agrees exactly for the chain and to + 4.9e-6 of the range for the cable (the coupled build's static polish), the march with the + same Newton controls to 4.9e-6 (cable) and 2.1e-5 (chain); a `Currents 2` table wrapping past + its last sample equals the unrolled table bit for bit; a uniform `Currents 1` profile and a + uniform `Currents 5` grid equal `uniform` to round-off (at most 3.9e-8); a correction rewind repeats the + step bit for bit; the march allocates nothing per step. Deck waves stay refused; the coupled + route keeps taking the host's field. - Finite-EI lines with two moving ends on the cubic-Hermite route: a line whose End B is a `Coupled`/`Vessel` point (a cable shared by two floaters, a FAST.Farm shared line) is driven at both ends standalone, in OpenFAST, FAST.Farm and the C API (End B on a moving column of its diff --git a/CMakeLists.txt b/CMakeLists.txt index 869b3af8..84066a67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1459,6 +1459,10 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_ID STREQUAL "GN set_tests_properties(step_allocations_motion_roll PROPERTIES LABELS "fortran;dynamic;memory") add_test(NAME step_allocations_motion_vessel COMMAND test_step_allocations motion_vessel) set_tests_properties(step_allocations_motion_vessel PROPERTIES LABELS "fortran;dynamic;memory") + # And with the deck's own current on that march (a Currents 5 grid that varies in time). + add_test(NAME step_allocations_mixed_current COMMAND test_step_allocations mixed_current) + file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/step_alloc_mixed_current) + set_tests_properties(step_allocations_mixed_current PROPERTIES LABELS "fortran;dynamic;memory") # And with the nodal twist of a line free in torsion at one end. add_test(NAME step_allocations_torsion_one_end COMMAND test_step_allocations free) set_tests_properties(step_allocations_torsion_one_end PROPERTIES LABELS "fortran;dynamic;memory") @@ -2256,6 +2260,19 @@ target_link_libraries(test_mixed_route_torsion PRIVATE cabledyn_core) add_test(NAME mixed_route_torsion COMMAND test_mixed_route_torsion $) set_tests_properties(mixed_route_torsion PROPERTIES LABELS "fortran;driver;integration;dynamic") +# Deck currents on the standalone mixed route (the aggregate samples the deck current at every +# node before each step): OPTION uniform and profile and MoorDyn-C Currents 1/2/5 against the +# single-line routes, the wrap of a time-varying table, uniform writings of one field, snapshot +# and restore, and the refusals that remain (deck waves, double counting, no dtM). +add_executable(test_mixed_route_currents tests/test_mixed_route_currents.f90) +target_link_libraries(test_mixed_route_currents PRIVATE cabledyn_core) +add_test(NAME mixed_route_currents COMMAND test_mixed_route_currents $ + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/mixed_route_currents_work) +set_tests_properties(mixed_route_currents PROPERTIES LABELS "fortran;driver;integration;dynamic") +foreach(_mrc_case uni prof still wav c1 c2 c2u c2h c2d c5 c1u c5u) + file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/mixed_route_currents_work/${_mrc_case}) +endforeach() + add_executable(test_coupled_torsion tests/test_coupled_torsion.f90) target_link_libraries(test_coupled_torsion PRIVATE cabledyn_core) add_test(NAME coupled_torsion COMMAND test_coupled_torsion WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) @@ -2741,8 +2758,13 @@ cabledyn_msg_test(shared_line_finite_ei msg_shared_line_finite_ei.dat 1 cabledyn_msg_test(pliant_connect_end_b msg_pliant_connect_end_b.dat 1 "finite-EI LINE 1 in a mixed-topology deck: End B is POINT 2 .connect.;is not supported on the multibody march;End the cable on a Fixed point" "") -cabledyn_msg_test(mixed_current msg_mixed_current.dat 1 - "the deck current OPTION is not supported for a standalone mixed EI=0/finite-EI deck;runs the mooring in STILL WATER;couple the deck to OpenFAST .CompMooring = 5. with SeaState" +# The standalone mixed route takes a deck current (here the static start of the lazy-wave deck) +# and refuses deck waves by name. +cabledyn_msg_test(mixed_current msg_mixed_current.dat 0 + "CableDyn mixed standalone aggregate: 3 line.s. .2 EI=0, 1 finite-EI." + "STILL WATER") +cabledyn_msg_test(mixed_waves msg_mixed_waves.dat 1 + "the deck waves OPTION is not supported for a standalone mixed EI=0/finite-EI deck;takes the deck current but evaluates no deck waves;couple the deck to OpenFAST .CompMooring = 5. with SeaState" "this coupled mode;the C API;FAST.Farm") cabledyn_msg_test(mixed_connect_coupled_cable msg_mixed_connect_coupled_cable.dat 1 "finite-EI LINE 3: a Coupled/Vessel End A .POINT 1. would need motionFile coupling to drive it;remove the Connect/Free points;held still .that route takes no motionFile either." diff --git a/VALIDATION.md b/VALIDATION.md index f0ce65de..4143f3a5 100644 --- a/VALIDATION.md +++ b/VALIDATION.md @@ -863,10 +863,23 @@ stop with a named error. **Standalone mixed aggregate.** `CableDyn_driver.exe` partitions and steps the same aggregate used by OpenFAST. The IEA-15 three-chain + touchdown-cable deck writes all four static profiles and a one-step `dtM=0.025 s` dynamic test with -progress/ETA. On this held-end mixed route (mixed lines without bodies, rods or -free points), `motionFile` and deck-owned waves/current stop with an error. Mixed -decks that also contain bodies, rods or free points run on the multibody march, +progress/ETA. On this mixed route (mixed lines without bodies, rods or free points) +the deck's prescribed motion (`motionFile`, `vesselMotion`; `mixed_route_torsion`) and +its current (`mixed_route_currents`, below) are marched; deck waves stop with an error. +Mixed decks that also contain bodies, rods or free points run on the multibody march, which accepts deck waves and current (`mixed_body_rods_points.dat`). +`mixed_route_currents` runs a cable (100 m, 40 elements) and a chain (110 m) surging 1 m from +rest in cross currents (OPTION `uniform` and `profile`, MoorDyn-C `Currents 1`, `2` and `5`) on +the mixed route and on their single-line routes: the static start agrees exactly for the chain +and to 4.9e-6 of each channel's range for the cable (its out-of-plane offset, 4 um of 0.55 m, at +the stopping point of the coupled build's static polish; exactly in still water); the march +differs by 1.1e-3 for the cable on the coupled Newton controls (1.2e-3 in still water too) and +keeps the static start's 4.9e-6 with the deck's; the chain agrees to 2.1e-5 (exactly in a sheared +current; the row-1 transfer, 5.4e-5 in still water). A `Currents 2` table wrapping past its last +sample equals the unrolled table bit for bit and departs from the held one by 0.39 of the chain +tension range; a uniform `Currents 1` profile equals `uniform` to round-off (0 on Windows, +3.9e-8 on Linux), a uniform `Currents 5` grid to 3.9e-8; ten correction rewinds repeat their steps bit for bit; the march of a mixed deck +in a `Currents 5` grid makes no heap allocation per step (`step_allocations_mixed_current`). ### WaterKin and SeaState modes diff --git a/app/cabledyn.f90 b/app/cabledyn.f90 index 9676692b..9accf8a1 100644 --- a/app/cabledyn.f90 +++ b/app/cabledyn.f90 @@ -459,8 +459,10 @@ SUBROUTINE run_mixed_held_deck(deck, root, dt, has_dt, run_time, has_run_time, h !! motion as the standalone cubic-Hermite route does: the point rows' translations, the !! vessel's rotation (the orientation and angular rates the fairlead end connection and !! torsion frames turn with) and the motionFile roll column (the imposed twist of a line - !! restrained in torsion). Deck-owned ambient fields require separate updaters and - !! therefore remain an explicit fail-closed boundary. + !! restrained in torsion). The deck's own current (a current OPTION, a WaterKin CurrentMod 1 + !! table, MoorDyn-C Currents 1/2/5) is the aggregate's deck_current: its static solves take + !! it and every step samples it at the nodes. Deck waves remain an explicit fail-closed + !! boundary. CHARACTER(*), INTENT(IN) :: deck, root REAL(wp), INTENT(IN) :: dt, run_time LOGICAL, INTENT(IN) :: has_dt, has_run_time, has_motion, line_outputs @@ -527,13 +529,14 @@ SUBROUTINE run_mixed_held_deck(deck, root, dt, has_dt, run_time, has_run_time, h run_msg = 'CableDyn_driver: cannot allocate the mixed aggregate' EXIT mixed_run END IF - ! The aggregate is caller-driven and cannot refresh standalone wave/current - ! OPTIONS. Reject such decks by name instead of silently holding zero fluid. The driver - ! holds the line end frames or turns them with the deck's vesselMotion table + ! The aggregate is caller-driven and evaluates no deck waves: a waves OPTION is refused by + ! name instead of silently holding zero fluid. The deck's own current is the aggregate's + ! (deck_current), sampled at the nodes before every step at the step's t_committed. The + ! driver holds the line end frames or turns them with the deck's vesselMotion table ! (host_orientation), and marches the deck's prescribed motion (prescribed_motion). CALL CD_AGG_Init_From_Deck(aggregate, deck, step_dt, es, em, forbid_deck_ambient=.TRUE., & run_tmax=MAX(CD_ZERO, run_time), range_files=.TRUE., host_orientation=.TRUE., & - prescribed_motion=has_motion, static_run=nstep == 0) + prescribed_motion=has_motion, static_run=nstep == 0, deck_current=.TRUE.) IF (es /= CD_AGG_OK) THEN CALL set_aggregate_error(es, em, run_stat, run_msg) EXIT mixed_run @@ -633,7 +636,7 @@ SUBROUTINE run_mixed_held_deck(deck, root, dt, has_dt, run_time, has_run_time, h max_consecutive_miss = 0 first_miss_time = CD_ZERO last_miss_time = CD_ZERO - ! the march (no fluid sampled by the driver on this route) or, without one, finalisation + ! the march (the aggregate samples the deck current itself) or, without one, finalisation CALL CD_Profile_Enter(MERGE(CD_PROF_SOLVE, CD_PROF_FINAL, nstep > 0)) IF (nstep > 0) CALL start_standalone_progress(progress, nstep, step_dt) DO step = 1, nstep diff --git a/doc/capabilities.rst b/doc/capabilities.rst index 7493bdf7..793046d3 100644 --- a/doc/capabilities.rst +++ b/doc/capabilities.rst @@ -72,8 +72,10 @@ Line and constitutive capability - Supported with route limits - a mixed deck of lines between held or coupled points only (no bodies, rods, or ``Free``/``Connect`` points) runs in OpenFAST and standalone as a static run or a dynamic - run with held ends or a ``motionFile``/``vesselMotion`` prescription, and rejects deck - waves standalone (so ``vesselRAO`` too); a mixed deck with bodies, rods, or + run with held ends or a ``motionFile``/``vesselMotion`` prescription; standalone it takes + the deck current (``current`` OPTION, WaterKin ``CurrentMod 1``, MoorDyn-C ``Currents`` + ``1``/``2``/``5``) as the single-line routes do and rejects deck waves (so ``vesselRAO`` + too); a mixed deck with bodies, rods, or ``Free``/``Connect`` points runs standalone on the multibody march, with moving objects and deck waves/current, but not with a ``motionFile`` * - Viscoelastic rope (MoorDyn ``ElasticMod`` 2/3) @@ -173,7 +175,8 @@ Loads and environment * - MoorDyn-C currents in time and space (``Currents 2``, ``Currents 5``) - Standalone only - ``current_profile_dynamic.txt`` and ``current_profile_4d.txt``, interpolated as MoorDyn-C - v2.7.1 does at every node's position and time, the static start included; see + v2.7.1 does at every node's position and time, the static start included, on every + standalone route (the mixed ``EI = 0`` + finite-EI deck too); see :ref:`moordyn-c-wavekin` * - Airy and JONSWAP waves - Supported diff --git a/doc/driver_format.md b/doc/driver_format.md index fba25861..1512b826 100644 --- a/doc/driver_format.md +++ b/doc/driver_format.md @@ -356,8 +356,14 @@ first steps differ from that route's. A static run (`TMax = 0`) of a line restra takes `False alpha_force_blend`, as on the single-line route. The run writes the common `.out` and the all-line `.static.out` tables, plus the range graph of every line with the `r` flag. -Mixed decks reject, by name, deck wave/current OPTIONS (so `vesselRAO`), WaterKin `WaveKinMod 1`, -MoorDyn-C `WaveKin 3`/`7` and `Currents 1`/`2`/`5`, and per-line `p`/`t` flags. +A mixed deck takes every deck current the single-line routes take: a `current` OPTION (uniform or +profile), a WaterKin `CurrentMod 1` table and MoorDyn-C `Currents 1`/`2`/`5`. The static start of +its `EI = 0` lines and finite-EI cables is solved in the current at `t = 0`, and before every step +the current at the step's end time is sampled at every node of the step-start state and held +over the step, as on the single-line routes and with the same field evaluation (a `Currents 2`/`5` +table that varies in time repeats past its last sample there too). Mixed decks reject, by name, +deck waves (so `vesselRAO`), WaterKin `WaveKinMod 1`, MoorDyn-C `WaveKin 3`/`7`, and per-line +`p`/`t` flags. (multibody-march)= **Multibody march** (bodies, rods, `Connect`/`Free` points, EI = 0 lines and finite-EI cables in diff --git a/doc/standalone_driver.rst b/doc/standalone_driver.rst index d608a667..3ca77654 100644 --- a/doc/standalone_driver.rst +++ b/doc/standalone_driver.rst @@ -109,9 +109,11 @@ to march held-end dynamics. A static-only mixed deck with no dynamic-only option both ``dtM`` and ``TMax``; the time-step option becomes mandatory when a positive-duration march is requested. -A mixed deck rejects deck-owned wave/current OPTIONS by name, and with them ``vesselRAO``, -which needs deck waves. A ``vesselMotion`` record moves every ``Coupled``/``Vessel`` point -rigidly with the vessel (translation and rotation of each hang-off); a ``motionFile`` gives the +A mixed deck takes the deck current (a ``current`` OPTION, a WaterKin ``CurrentMod 1`` table or +MoorDyn-C ``Currents 1``/``2``/``5``) in its static start and its march, as the single-line +routes do. It rejects deck waves by name, and with them ``vesselRAO``, which needs deck waves. +A ``vesselMotion`` record moves every ``Coupled``/``Vessel`` point rigidly with the vessel +(translation and rotation of each hang-off); a ``motionFile`` gives the rows of each point. Row 1 is installed before ``t = 0``, also with ``TMax = 0``, after the ``.static.out`` of the static solve is written. On the ``EI = 0`` lines that transfer re-derives the interior accelerations, which the ``EI = 0``-only route does not, so with row 1 off the deck diff --git a/doc/troubleshooting.rst b/doc/troubleshooting.rst index 8c590c8b..8322bfe9 100644 --- a/doc/troubleshooting.rst +++ b/doc/troubleshooting.rst @@ -299,13 +299,13 @@ Model data deck (the ``EI = 0`` lines on the Coupled point directly): a host (OpenFAST ``CompMooring = 5`` or the C API) drives its Coupled points, and the standalone driver runs it with them held still (that route takes no ``motionFile`` either). - * - ``the deck current OPTION is not supported for a standalone mixed EI=0/finite-EI deck`` / - ``the deck waves OPTION ...`` - - the standalone driver runs a mixed ``EI = 0``/finite-EI deck in still water: no ambient - fluid field covers its span. Remove the ``waves``/``current`` OPTION, run a deck whose - lines are all ``EI = 0`` or all finite-EI (those standalone routes evaluate the deck waves - and current), or couple the deck to OpenFAST (``CompMooring = 5``) with SeaState, which - supplies them. + * - ``the deck waves OPTION is not supported for a standalone mixed EI=0/finite-EI deck`` / + ``the MoorDyn-C WaveKin waves are not supported for a standalone mixed EI=0/finite-EI + deck`` + - the standalone driver marches the deck current of a mixed ``EI = 0``/finite-EI deck but no + deck waves. Remove the ``waves`` OPTION (or ``WaveKin``), run a deck whose lines are all + ``EI = 0`` or all finite-EI (those standalone routes evaluate the deck waves), or couple + the deck to OpenFAST (``CompMooring = 5``) with SeaState, which supplies them. * - ``the deck current OPTION is not supported in FAST.Farm`` / ``the deck waves OPTION ...`` - the shared mooring of a FAST.Farm farm runs in still water (no fluid field spans the farm). Remove the ``waves``/``current`` OPTION. diff --git a/python/cabledyn/deck_file.py b/python/cabledyn/deck_file.py index 8065c46a..9fb70d1a 100644 --- a/python/cabledyn/deck_file.py +++ b/python/cabledyn/deck_file.py @@ -3756,18 +3756,20 @@ def end_key(token: str) -> str: f"{self._label}: OPTION nModes is not supported for mixed EI=0/finite-EI " "decks; remove it or set it to 0" ) - # native run_mixed_held_deck: the standalone mixed deck runs on the aggregate in - # still water and writes the main OUTPUTS only - if ( - has_waves - or trains - or mdc_wave_kin - or (current is not None and current.values[0].lower() != "none") - or mdc_currents - ): + # native run_mixed_held_deck: the standalone mixed deck runs on the aggregate, which + # marches the deck current (a current OPTION or Currents 1/2/5, deck_current) but + # evaluates no deck waves, and writes the main OUTPUTS only + if mdc_wave_kin: + raise DeckFormatError( + f"{self._label}: the MoorDyn-C WaveKin {mdc_wave_kin} waves are not supported " + "for a standalone mixed EI=0/finite-EI deck (it takes a deck current but no " + "deck waves)" + ) + if has_waves or trains: raise DeckFormatError( - f"{self._label}: a mixed EI=0/finite-EI deck runs in still water; remove " - "the deck waves and current" + f"{self._label}: the deck waves OPTION is not supported for a standalone mixed " + "EI=0/finite-EI deck: this route takes the deck current but evaluates no deck " + "waves" ) if series_lines: raise DeckFormatError( diff --git a/python/tests/test_deck_file.py b/python/tests/test_deck_file.py index 62254259..49d0dda6 100644 --- a/python/tests/test_deck_file.py +++ b/python/tests/test_deck_file.py @@ -940,9 +940,8 @@ def test_attachments_accept_an_axial_drag_area_and_a_deck_current(tmp_path): # all finite-EI lines: the deck driver takes a deck current path.write_text(text.replace("1.0e8 0.0 0.0 1.2", "1.0e8 0.0 1.0e3 1.2"), encoding="utf-8") DeckFile.read(path) - # a mixed EI=0/finite-EI deck runs on the aggregate in still water - with pytest.raises(DeckFormatError, match="runs in still water"): - DeckFile.from_text(text) + # a mixed EI=0/finite-EI deck runs on the aggregate in its current too + DeckFile.from_text(text) def test_viv_lift_flag_is_upper_case_and_standalone(): diff --git a/python/tests/test_deck_native_parity.py b/python/tests/test_deck_native_parity.py index 2abb9c5e..55f4d6a0 100644 --- a/python/tests/test_deck_native_parity.py +++ b/python/tests/test_deck_native_parity.py @@ -842,17 +842,27 @@ def test_quoted_syrope_paths_reject_what_a_quote_cannot_hold(path, message): ) -def test_standalone_mixed_deck_runs_on_the_still_water_aggregate(): +def test_standalone_mixed_deck_runs_on_the_aggregate_in_its_current(): DeckFile.from_text(_MIXED) DeckFile.from_text(_edit(_MIXED, ("2 2 3 -", "2 2 3 r"))) - _rejects(_options(_MIXED, "uniform 0.5 0 0 current"), "runs in still water") - _rejects(_options(_MIXED, "airy 2 8 0 waves"), "runs in still water") + # the aggregate marches the deck current (deck_current) but evaluates no deck waves + DeckFile.from_text(_options(_MIXED, "uniform 0.5 0 0 current")) + DeckFile.from_text(_options(_MIXED, "profile -50 0.1 0 0 0 0.5 0.2 0 current")) + for mode in (1, 2, 5): + DeckFile.from_text(_options(_MIXED, f"{mode} Currents")) + _rejects(_options(_MIXED, "airy 2 8 0 waves"), "evaluates no deck waves") + _rejects(_options(_MIXED, "7 WaveKin"), "WaveKin 7 waves are not supported") + _rejects(_options(_MIXED, "uniform 0.5 0 0 current", "2 Currents"), "double-counting") + _rejects( + _edit(_options(_MIXED, "uniform 0.5 0 0 current"), ("0.1 dtM\n10.0 TMax\n", "")), + "standalone OPTION current requires dtM and TMax", + ) _rejects(_edit(_MIXED, ("2 2 3 -", "2 2 3 pt")), "writes no per-line files") # the driver marches the deck's motionFile or vesselMotion; vesselRAO needs deck waves DeckFile.from_text(_options(_MIXED, "m.txt motionFile")) DeckFile.from_text(_options(_MIXED, "v.txt vesselMotion", "0|0|0 vesselRef")) _rejects(_options(_MIXED, "r.txt vesselRAO"), "vesselRAO needs deck waves") - _rejects(_options(_MIXED, "r.txt vesselRAO", "airy 2 8 0 waves"), "runs in still water") + _rejects(_options(_MIXED, "r.txt vesselRAO", "airy 2 8 0 waves"), "evaluates no deck waves") def test_coupled_route_takes_no_motion_file_and_needs_a_line(): @@ -1710,3 +1720,75 @@ def test_model_round_trips_the_torsion_columns(): ) assert added.torsion_stiffness == 1.0e4 assert "TorsStiffness" in plain.to_text() + + +# MoorDyn-C current files of the mixed-route parity decks (written beside the deck) +_MIXED_CURRENT_FILES = { + 1: ("current_profile.txt", "steady\nz ux uy uz\n-50.0 0.1 0.05 0.0\n0.0 0.4 0.2 0.0\n"), + 2: ( + "current_profile_dynamic.txt", + "dynamic\n\n\n\n-50.0 0.0\nt ux... uy...\n0.0 0.1 0.3 0.0 0.1\n1.0 0.2 0.4 0.05 0.15\n", + ), + 5: ( + "current_profile_4d.txt", + "2 2 2 2\n-500.0 500.0\n-50.0 50.0\n-60.0 0.0\n0.0 1.0\nx y z t ux uy uz\n" + + "".join( + f"{x} {y} {z} {t} {0.1 + 0.1 * t} 0.05 0.0\n" + for t in (0.0, 1.0) + for z in (-60.0, 0.0) + for y in (-50.0, 50.0) + for x in (-500.0, 500.0) + ), + ), +} + + +@pytest.mark.skipif( + not _PARITY_DRIVER or not Path(_PARITY_DRIVER).is_file(), + reason="set CABLEDYN_TEST_DRIVER to a built native driver to run the native mixed-route parity", +) +@pytest.mark.parametrize( + "rows", + [ + ("uniform 0.5 0 0 current",), + ("profile -50 0.1 0 0 0 0.5 0.2 0 current",), + ("1 Currents",), + ("2 Currents",), + ("5 Currents",), + ("2 Currents", "uniform 0.5 0 0 current"), + ("3 Currents",), + ("airy 2 8 0 waves",), + ("7 WaveKin",), + ("no dtM", "uniform 0.5 0 0 current"), + ], +) +def test_mixed_route_currents_get_the_native_verdict(rows, tmp_path): + # the deck currents of the single-line routes run on the mixed route too; deck waves do not + text = _edit(_MIXED, ("0.1 dtM\n10.0 TMax\n", "0.1 dtM\n0.2 TMax\n")) + if rows[0] == "no dtM": + text = _edit(text, ("0.1 dtM\n0.2 TMax\n", "")) + rows = rows[1:] + text = _options(text, *rows) + for row in rows: + if row.endswith("Currents") and int(row.split()[0]) in _MIXED_CURRENT_FILES: + name, content = _MIXED_CURRENT_FILES[int(row.split()[0])] + (tmp_path / name).write_text(content, encoding="utf-8") + try: + DeckFile.from_text(text) + python_accepts = True + except DeckFormatError: + python_accepts = False + deck = tmp_path / "mixed.dat" + deck.write_text(text, encoding="utf-8") + completed = subprocess.run( + [_PARITY_DRIVER, str(deck), str(tmp_path / "mixed")], + capture_output=True, + text=True, + cwd=tmp_path, + timeout=600, + check=False, + ) + # exit code 1 is an input refusal; 0 a run and 2 a solve failure after validation + assert python_accepts == (completed.returncode != 1), completed.stdout + completed.stderr + if python_accepts: + assert "mixed standalone aggregate" in completed.stdout, completed.stdout diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index ec80fc40..d914afda 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -219,6 +219,11 @@ MODULE CableDyn_DeckDriver PUBLIC :: CD_MotionRuntimeType PUBLIC :: CD_Motion_Active, CD_Motion_NColumns, CD_Motion_Has_Rotation, CD_Motion_Has_Roll PUBLIC :: CD_Motion_Kinematics, CD_Motion_Deck_Positions, CD_Motion_End + ! Deck current of a standalone mixed deck: the aggregate samples it at every node before each + ! step with the updaters of the single-line routes (opaque; DeckOptions stays private). + PUBLIC :: CD_DeckCurrentRuntimeType + PUBLIC :: CD_Deck_Current_Active, CD_Deck_Current_Sample_System, CD_Deck_Current_Sample_Cables + PUBLIC :: CD_Deck_Current_End PUBLIC :: CD_Init_Deck_Aggregate_Rod, CD_Step_Aggregate_Rod PUBLIC :: CD_Rod_NRods, CD_Rod_Snapshot, CD_Rod_Restore, CD_Rod_End PUBLIC :: CD_Rod_MirrorSize, CD_Rod_Get_States, CD_Rod_Set_States, CD_Rod_Apply_States @@ -791,6 +796,8 @@ MODULE CableDyn_DeckDriver TYPE :: HydroUpdateWorkspace REAL(wp), ALLOCATABLE :: q(:), v(:), a(:) REAL(wp), ALLOCATABLE :: fluid_velocity(:, :), fluid_acceleration(:, :), waterline(:) + ! node positions of a finite-EI cable (update_hermite_deck_fluid with a workspace) + REAL(wp), ALLOCATABLE :: node_pos(:, :) END TYPE TYPE :: ModelOutputWorkspace @@ -1092,6 +1099,22 @@ MODULE CableDyn_DeckDriver LOGICAL, ALLOCATABLE :: col_roll(:) END TYPE + !> Opaque deck current of a standalone mixed deck, which the standalone driver marches on the + !> coupled aggregate (CD_Init_Deck_Aggregate with deck_current): the deck's current OPTION + !> (uniform or profile), WaterKin CurrentMod 1 table or MoorDyn-C Currents 1/2/5 field, as the + !> deck options that carry it, and the workspace of its samples. Before every step the + !> aggregate samples it at time t + dt at every node of the step-start state and holds it over + !> the step (CD_Deck_Current_Sample_System on the EI = 0 lines, CD_Deck_Current_Sample_Cables + !> on the finite-EI cables), with the updaters of the single-line EI = 0 and cubic-Hermite + !> routes (update_wave_models' system twin update_system_line_hydro, update_hermite_deck_fluid), + !> so every route evaluates the same field the same way (deck_current_velocity). + TYPE :: CD_DeckCurrentRuntimeType + PRIVATE + LOGICAL :: active = .FALSE. + TYPE(DeckOptions) :: opts + TYPE(HydroUpdateWorkspace) :: work + END TYPE + TYPE :: CD_LineInitSummary !! Engineering quantities at the converged static initial condition. The !! fairlead force is the force exerted by the line on public End A and the @@ -1209,6 +1232,9 @@ MODULE CableDyn_DeckDriver ! The deck's own prescribed motion (prescribed_motion: the standalone driver), in the ! aggregate moving-set order; inactive otherwise. TYPE(CD_MotionRuntimeType) :: motion + ! The deck's own current (deck_current: the standalone driver), sampled by the facade at + ! every node before each step; inactive otherwise. + TYPE(CD_DeckCurrentRuntimeType) :: current END TYPE CONTAINS @@ -7248,7 +7274,7 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi ptfm_init, external_fluid, coupled_positions, & n_turbines, turbine_ref_pos, farm_ptfm_init, forbid_deck_ambient, run_tmax, & range_files, host_orientation, static_current, prescribed_motion, & - static_run) + static_run, deck_current) !! Parse a MIXED deck ONCE and partition its lines into {EI=0 mooring} and !! {finite-EI cable}, returning the raw parts the OpenFAST aggregate facade wraps: !! the EI=0 mooring SYSTEM built from the mooring subset (over ALL deck points, the @@ -7267,6 +7293,8 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi !! a deck with a finite-EI cable, a Rigid6 body or a rod, under a host fluid field, or in !! FAST.Farm mode; a deck with a finite-EI cable that also carries Free/Connect dynamic !! points. A deck current on any other deck is a steady field applied through the lines. + !! With deck_current (the standalone driver) a deck current of every kind the standalone + !! routes take is the deck's own, on the EI = 0 lines and the finite-EI cables alike. !! Coupled finite-EI flat/structured contact and friction use the same production !! Hermite residual as the standalone route. !! ptfm_init (optional, 6): initial platform displacement [surge, sway, heave, @@ -7338,9 +7366,17 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi ! restrained in torsion needs no force-blended step, as on the single-line standalone route; ! a coupled host always marches. LOGICAL, INTENT(IN), OPTIONAL :: static_run + ! deck_current: the caller marches the deck's own current (the standalone driver on a mixed + ! deck of lines between Fixed/Coupled/Vessel points): a current OPTION (uniform or profile), a + ! WaterKin CurrentMod 1 table or a MoorDyn-C Currents 1/2/5 field is taken instead of refused. + ! The static solves of the EI = 0 lines and of the finite-EI cables take it at t = 0, as on + ! the single-line routes, and agg%current carries it for the facade, which samples it at + ! every node before each step (CD_Deck_Current_Sample_System/_Cables). A coupled host keeps + ! supplying its own field and passes no deck_current. + LOGICAL, INTENT(IN), OPTIONAL :: deck_current INTEGER :: nturb - LOGICAL :: host_turns, own_motion, dynamic_points, static_only + LOGICAL :: host_turns, own_motion, dynamic_points, static_only, own_current TYPE(DeckLineType), ALLOCATABLE :: types(:) TYPE(DeckBody), ALLOCATABLE :: bodies(:) TYPE(DeckRodType), ALLOCATABLE :: rod_types(:) @@ -7478,12 +7514,49 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi 'coupled aggregate runs must use WaveKinMod 2/SEASTATE through external_fluid') RETURN END IF - IF (opts%mdc_wave_kin > 0 .OR. opts%mdc_currents > 0) THEN + own_current = .FALSE. + IF (PRESENT(deck_current)) own_current = deck_current + IF (opts%mdc_wave_kin > 0 .AND. own_current) THEN + CALL fail(ErrStat, ErrMsg, 'the MoorDyn-C WaveKin '//TRIM(int_to_str(opts%mdc_wave_kin))//' waves are '// & + 'not supported for a standalone mixed EI=0/finite-EI deck (it takes a deck current but no '// & + 'deck waves): remove WaveKin, run a deck whose lines are all EI=0 or all finite-EI, or '// & + 'couple the deck to OpenFAST (CompMooring = 5) with SeaState, which supplies the waves') + RETURN + END IF + IF ((opts%mdc_wave_kin > 0 .OR. opts%mdc_currents > 0) .AND. .NOT. own_current) THEN CALL fail(ErrStat, ErrMsg, 'the MoorDyn-C WaveKin 3/7 and Currents 1/2/5 files are not supported on the '// & - 'aggregate route (coupled runs take water kinematics from the host; standalone mixed '// & - 'EI=0/finite-EI decks reject deck water kinematics)') + 'aggregate route (coupled runs take water kinematics from the host)') RETURN END IF + ! The deck's own current (deck_current) is marched by the standalone driver over lines between + ! Fixed/Coupled/Vessel points held or moved by the deck's motion, from the deck pose: no host + ! field, placement or farm, and no body, rod or Connect/Free point (those decks run on the + ! standalone multibody or point-system march, which take the current themselves). + IF (own_current .AND. (opts%has_current .OR. opts%has_current_profile)) THEN + IF (PRESENT(external_fluid)) THEN + IF (external_fluid) THEN + CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: a deck-owned current (deck_current) and a '// & + 'host fluid field (external_fluid) would double-count the current'); RETURN + END IF + END IF + IF (nturb > 0 .OR. PRESENT(ptfm_init) .OR. PRESENT(coupled_positions) .OR. PRESENT(static_current)) THEN + CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: a deck-owned current (deck_current) is marched '// & + 'from the deck pose of a standalone deck (no host placement, farm or host current)'); RETURN + END IF + IF (deck_has_dynamic_points(points) .OR. SIZE(bodies) > 0 .OR. SIZE(rods) > 0) THEN + CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: a deck-owned current (deck_current) drives lines '// & + 'between Fixed/Coupled/Vessel points only (bodies, rods and Connect/Free points take it on '// & + 'the standalone multibody or point-system march)'); RETURN + END IF + ! the standalone routes' clock: the current is a dynamic-deck option + IF (.NOT. opts%has_dtm) THEN + IF (opts%mdc_currents > 0) THEN + CALL fail(ErrStat, ErrMsg, 'standalone Currents '//TRIM(int_to_str(opts%mdc_currents))// & + ' requires dtM and TMax'); RETURN + END IF + CALL fail(ErrStat, ErrMsg, 'standalone OPTION current requires dtM and TMax'); RETURN + END IF + END IF IF (opts%waterkin_seastate) THEN IF (.NOT. PRESENT(external_fluid)) THEN @@ -7529,6 +7602,8 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi IF (forbid_deck_ambient) THEN ! The two callers that forbid deck ambient fluid: the FAST.Farm shell (n_turbines >= 1) and ! the standalone runner of a mixed EI=0/finite-EI deck. Each gets the advice of its route. + ! The standalone runner marches the deck current itself (deck_current), so only a caller + ! without it is refused one. IF (opts%has_wave) THEN IF (nturb > 0) THEN CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: the deck waves OPTION is not supported in '// & @@ -7536,22 +7611,21 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi 'farm). Remove the waves OPTION'); RETURN END IF CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: the deck waves OPTION is not supported for a '// & - 'standalone mixed EI=0/finite-EI deck: this route runs the mooring in STILL WATER, because '// & - 'no ambient fluid field covers its span. Remove the waves OPTION, run a deck whose lines are '// & + 'standalone mixed EI=0/finite-EI deck: this route takes the deck current but evaluates no '// & + 'deck waves. Remove the waves OPTION, run a deck whose lines are '// & 'all EI=0 or all finite-EI (those standalone routes evaluate the deck waves), or couple the '// & 'deck to OpenFAST (CompMooring = 5) with SeaState, which supplies the waves'); RETURN END IF - IF (opts%has_current .OR. opts%has_current_profile) THEN + IF ((opts%has_current .OR. opts%has_current_profile) .AND. .NOT. own_current) THEN IF (nturb > 0) THEN CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: the deck current OPTION is not supported in '// & 'FAST.Farm: the shared mooring of a farm runs in STILL WATER (no fluid field spans the '// & 'farm). Remove the current OPTION'); RETURN END IF - CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: the deck current OPTION is not supported for a '// & - 'standalone mixed EI=0/finite-EI deck: this route runs the mooring in STILL WATER, because '// & - 'no ambient fluid field covers its span. Remove the current OPTION, run a deck whose lines are '// & - 'all EI=0 or all finite-EI (those standalone routes evaluate the deck current), or couple the '// & - 'deck to OpenFAST (CompMooring = 5) with SeaState, which supplies the current'); RETURN + ! (the standalone mixed route passes deck_current; this is a library caller without it) + CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: the deck current OPTION is not marched by a '// & + 'caller that forbids deck ambient fluid without deck_current; remove the current OPTION, '// & + 'or pass deck_current to march the deck''s own current'); RETURN END IF END IF END IF @@ -7786,7 +7860,8 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi ! closed rather than silently drop the physics. A PURE mooring deck (n_fin == 0) keeps ! the full EI=0 feature set so it composes to the plain CD_FMF_Init_From_Deck system. IF (n_fin > 0) THEN - IF (opts%has_current .OR. opts%has_current_profile) THEN + ! (a deck-owned current, deck_current, reaches the cables through their held field) + IF ((opts%has_current .OR. opts%has_current_profile) .AND. .NOT. own_current) THEN CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: ambient current on a deck with a finite-EI '// & 'cable is not supported (the cable does not receive a deck-owned current)'); RETURN END IF @@ -8088,6 +8163,12 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi IF (ErrStat /= CD_DECKDRV_OK) THEN CALL CD_End_Deck_Aggregate(agg); RETURN END IF + ! The deck's own current, sampled by the facade at every node before each step (the + ! static solves above took it at t = 0 through opts). + IF (own_current .AND. opts%has_current) THEN + agg%current%active = .TRUE. + agg%current%opts = opts + END IF ! The deck's own prescribed motion over the same moving-set order. IF (own_motion) THEN CALL build_aggregate_motion(points, lines, is_fin, opts, agg%motion, ErrStat, ErrMsg) @@ -8676,6 +8757,7 @@ SUBROUTINE CD_End_Deck_Aggregate(agg) agg%has_point3 = .FALSE. CALL CD_Range_End(agg%ranges) CALL CD_Motion_End(agg%motion) + CALL CD_Deck_Current_End(agg%current) agg%gravity = CD_ZERO agg%rho_water = CD_ZERO END SUBROUTINE CD_End_Deck_Aggregate @@ -8881,6 +8963,61 @@ SUBROUTINE CD_Motion_End(rt) rt%active = .FALSE. END SUBROUTINE CD_Motion_End + LOGICAL FUNCTION CD_Deck_Current_Active(rt) RESULT(active) + !! The aggregate carries the deck's own current (CD_Init_Deck_Aggregate deck_current). + TYPE(CD_DeckCurrentRuntimeType), INTENT(IN) :: rt + active = rt%active + END FUNCTION CD_Deck_Current_Active + + SUBROUTINE CD_Deck_Current_Sample_System(rt, system, time, ErrStat, ErrMsg, initial_condition) + !! The deck current u(x_j, time) at every node x_j of the EI = 0 system's lines, held over the + !! coming step as the drag's fluid velocity (update_system_line_hydro, the updater of the + !! standalone point-system march): before a step from t to t + dt the caller passes time = + !! t + dt and the step-start node positions, as the single-line EI = 0 march does. With + !! initial_condition (the t = 0 sample at the start state) a line whose field changed + !! re-derives its acceleration; a march-step sample keeps the committed generalised-alpha + !! acceleration. A no-op without a deck current. + TYPE(CD_DeckCurrentRuntimeType), INTENT(INOUT) :: rt + TYPE(CD_SystemType), INTENT(INOUT) :: system + REAL(wp), INTENT(IN) :: time + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + LOGICAL, INTENT(IN), OPTIONAL :: initial_condition + ErrStat = CD_DECKDRV_OK + ErrMsg = '' + IF (.NOT. rt%active) RETURN + CALL update_system_line_hydro(system, rt%opts, time, rt%work, ErrStat, ErrMsg, & + initial_condition=initial_condition) + END SUBROUTINE CD_Deck_Current_Sample_System + + SUBROUTINE CD_Deck_Current_Sample_Cables(rt, cables, time, ErrStat, ErrMsg) + !! The deck current u(x_j, time) at every node x_j of each finite-EI cable, installed as its + !! held fluid field over the coming step (update_hermite_deck_fluid, the updater of the + !! standalone cubic-Hermite march; time = t + dt at the step-start nodes). The first held + !! field of a cable completes its dynamic initialisation (the consistent start acceleration + !! in the current); a later one keeps the committed acceleration. A no-op without a deck + !! current. + TYPE(CD_DeckCurrentRuntimeType), INTENT(INOUT) :: rt + TYPE(CD_HFMF_ModuleType), INTENT(INOUT) :: cables(:) + REAL(wp), INTENT(IN) :: time + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + ErrStat = CD_DECKDRV_OK + ErrMsg = '' + IF (.NOT. rt%active) RETURN + CALL update_hermite_deck_fluid(cables, rt%opts, time, ErrStat, ErrMsg, work=rt%work) + END SUBROUTINE CD_Deck_Current_Sample_Cables + + SUBROUTINE CD_Deck_Current_End(rt) + !! Release the deck current. Idempotent. + TYPE(CD_DeckCurrentRuntimeType), INTENT(INOUT) :: rt + TYPE(DeckOptions) :: none + TYPE(HydroUpdateWorkspace) :: empty + rt%opts = none + rt%work = empty + rt%active = .FALSE. + END SUBROUTINE CD_Deck_Current_End + SUBROUTINE CD_Run_Deck_Driver(deck_path, out_root, converged, ErrStat, ErrMsg) !! Parse a MoorDyn-style deck, run static IC and optional held-end dynamic march, !! write `.out`. @@ -31381,49 +31518,75 @@ SUBROUTINE apply_motion_to_hermite_cables(cables, lines, points, motion, time_in END DO END SUBROUTINE apply_motion_to_hermite_cables - SUBROUTINE update_hermite_deck_fluid(cables, opts, time, ErrStat, ErrMsg) + SUBROUTINE update_hermite_deck_fluid(cables, opts, time, ErrStat, ErrMsg, work) + !! The deck current and waves at time at every node of each cable, installed as its held + !! fluid field (CD_HFMF_Set_Held_Fluid). work (optional): the scratch of the samples, sized at + !! the first call, so a march that passes it makes no heap allocation per step. TYPE(CD_HFMF_ModuleType), INTENT(INOUT) :: cables(:) TYPE(DeckOptions), INTENT(IN) :: opts REAL(wp), INTENT(IN) :: time INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg - INTEGER :: i, j, nn, es - REAL(wp) :: eta, wv(3), wa(3) - CHARACTER(1024) :: em - CHARACTER(200) :: em_k ! a per-node current or wave kinematics message (at most 160 characters) + TYPE(HydroUpdateWorkspace), INTENT(INOUT), OPTIONAL :: work + INTEGER :: i, nn + LOGICAL :: grow ErrStat = CD_DECKDRV_OK; ErrMsg = '' IF (.NOT. (opts%has_current .OR. opts%has_wave)) RETURN DO i = 1, SIZE(cables) nn = CD_HFMF_NNodes(cables(i)) - BLOCK - REAL(wp) :: xyz(3, nn), fv(3, nn), fa(3, nn), wl(nn) - CALL CD_HFMF_GetNodePositions(cables(i), xyz, es, em) - IF (es /= CD_HFMF_OK) THEN - CALL hermite_fluid_fail('node-position query', em); RETURN - END IF - fv = CD_ZERO; fa = CD_ZERO; wl = CD_ZERO - DO j = 1, nn - IF (opts%has_current) THEN - fv(:, j) = deck_current_velocity(opts, xyz(:, j), time, es, em_k) - IF (es /= CD_HYDRO_OK) THEN - CALL hermite_fluid_fail('current profile', em_k); RETURN - END IF + IF (PRESENT(work)) THEN + CALL ensure_hydro_workspace(work, 0, nn) + grow = .NOT. ALLOCATED(work%node_pos) + IF (.NOT. grow) grow = SIZE(work%node_pos, 2) < nn + IF (grow) THEN + IF (ALLOCATED(work%node_pos)) DEALLOCATE (work%node_pos) + ALLOCATE (work%node_pos(3, nn)) + END IF + CALL hermite_cable_fluid(cables(i), nn, work%node_pos(:, 1:nn), work%fluid_velocity(:, 1:nn), & + work%fluid_acceleration(:, 1:nn), work%waterline(1:nn)) + ELSE + BLOCK + REAL(wp) :: xyz(3, nn), fv(3, nn), fa(3, nn), wl(nn) + CALL hermite_cable_fluid(cables(i), nn, xyz, fv, fa, wl) + END BLOCK + END IF + IF (ErrStat /= CD_DECKDRV_OK) RETURN + END DO + CONTAINS + SUBROUTINE hermite_cable_fluid(cable, n, xyz, fv, fa, wl) + !! One cable's sample: u(x_j, time) (current plus wave velocity), the wave acceleration and + !! elevation at its node positions x_j, held as its fluid field. + TYPE(CD_HFMF_ModuleType), INTENT(INOUT) :: cable + INTEGER, INTENT(IN) :: n + REAL(wp), INTENT(OUT) :: xyz(3, n), fv(3, n), fa(3, n), wl(n) + INTEGER :: j, es + REAL(wp) :: eta, wv(3), wa(3) + CHARACTER(1024) :: em + CHARACTER(200) :: em_k ! a per-node current or wave kinematics message (at most 160 characters) + CALL CD_HFMF_GetNodePositions(cable, xyz, es, em) + IF (es /= CD_HFMF_OK) THEN + CALL hermite_fluid_fail('node-position query', em); RETURN + END IF + fv = CD_ZERO; fa = CD_ZERO; wl = CD_ZERO + DO j = 1, n + IF (opts%has_current) THEN + fv(:, j) = deck_current_velocity(opts, xyz(:, j), time, es, em_k) + IF (es /= CD_HYDRO_OK) THEN + CALL hermite_fluid_fail('current profile', em_k); RETURN END IF - IF (opts%has_wave) THEN - CALL deck_wave_kinematics(opts, xyz(1, j), xyz(2, j), xyz(3, j), time, eta, wv, wa, es, em_k) - IF (es /= CD_HYDRO_OK) THEN - CALL hermite_fluid_fail('wave kinematics', em_k); RETURN - END IF - fv(:, j) = fv(:, j) + wv; fa(:, j) = wa; wl(j) = eta + END IF + IF (opts%has_wave) THEN + CALL deck_wave_kinematics(opts, xyz(1, j), xyz(2, j), xyz(3, j), time, eta, wv, wa, es, em_k) + IF (es /= CD_HYDRO_OK) THEN + CALL hermite_fluid_fail('wave kinematics', em_k); RETURN END IF - END DO - CALL CD_HFMF_Set_Held_Fluid(cables(i), fv, fa, wl, es, em) - IF (es /= CD_HFMF_OK) THEN - CALL hermite_fluid_fail('held-field update', em); RETURN + fv(:, j) = fv(:, j) + wv; fa(:, j) = wa; wl(j) = eta END IF - END BLOCK - END DO - CONTAINS + END DO + CALL CD_HFMF_Set_Held_Fluid(cable, fv, fa, wl, es, em) + IF (es /= CD_HFMF_OK) CALL hermite_fluid_fail('held-field update', em) + END SUBROUTINE hermite_cable_fluid + SUBROUTINE hermite_fluid_fail(where, msg) CHARACTER(*), INTENT(IN) :: where, msg ErrStat = CD_DECKDRV_SOLVEFAIL diff --git a/src/CableDyn_OpenFAST_Aggregate.f90 b/src/CableDyn_OpenFAST_Aggregate.f90 index e8e75e9e..62d59dcb 100644 --- a/src/CableDyn_OpenFAST_Aggregate.f90 +++ b/src/CableDyn_OpenFAST_Aggregate.f90 @@ -86,7 +86,10 @@ MODULE CableDyn_OpenFAST_Aggregate CD_Deck_Range_Sample_Aggregate, CD_Deck_Range_Write, & CD_MotionRuntimeType, CD_Motion_Active, CD_Motion_NColumns, & CD_Motion_Has_Rotation, CD_Motion_Has_Roll, CD_Motion_Kinematics, & - CD_Motion_Deck_Positions, CD_Motion_End + CD_Motion_Deck_Positions, CD_Motion_End, & + CD_DeckCurrentRuntimeType, CD_Deck_Current_Active, & + CD_Deck_Current_Sample_System, CD_Deck_Current_Sample_Cables, & + CD_Deck_Current_End USE CableDyn_RangeOutput, ONLY: CD_RangeSet, CD_Range_End USE CableDyn_System, ONLY: CD_Get_System_Substep_Counts, CD_System_NLines, CD_System_Line_NDOF, & CD_Get_System_Line_State, & @@ -181,6 +184,11 @@ MODULE CableDyn_OpenFAST_Aggregate REAL(wp), ALLOCATABLE :: cable_phi0(:) ! The deck's own prescribed motion (standalone mixed route; inactive for a coupled host). TYPE(CD_MotionRuntimeType) :: motion + ! The deck's own current (standalone mixed route, Init deck_current; inactive for a coupled + ! host, which supplies its field through CD_AGG_SetFluidFields): sampled at every node of the + ! EI = 0 lines and the cables at t = 0 by Init and CD_AGG_Refresh_Accelerations, and at + ! t_committed before every step (sample_deck_current). + TYPE(CD_DeckCurrentRuntimeType) :: current ! Per-cable status staging lets independent finite-EI cables advance concurrently while ! preserving deterministic, cable-order error reporting after the parallel region. INTEGER, ALLOCATABLE :: cable_stat(:) @@ -280,7 +288,8 @@ MODULE CableDyn_OpenFAST_Aggregate SUBROUTINE CD_AGG_Init_From_Deck(self, deck_path, dt, ErrStat, ErrMsg, env_gravity, env_rho_water, env_wtrdpth, & ptfm_init, external_fluid, coupled_positions, & n_turbines, turbine_ref_pos, farm_ptfm_init, forbid_deck_ambient, run_tmax, & - range_files, host_orientation, static_current, prescribed_motion, static_run) + range_files, host_orientation, static_current, prescribed_motion, static_run, & + deck_current) !! Build the aggregate from ONE mixed deck: partition its lines into {EI=0 mooring} !! and {finite-EI cable}, wrap the mooring subset into a CD_FMF, and own one CD_HFMF !! per cable. Same signature philosophy as CD_FMF_Init_From_Deck (host environment @@ -311,8 +320,8 @@ SUBROUTINE CD_AGG_Init_From_Deck(self, deck_path, dt, ErrStat, ErrMsg, env_gravi INTEGER, INTENT(IN), OPTIONAL :: n_turbines REAL(wp), INTENT(IN), OPTIONAL :: turbine_ref_pos(:, :) REAL(wp), INTENT(IN), OPTIONAL :: farm_ptfm_init(:, :) - ! forbid_deck_ambient: the caller's documented scope is still water, so reject a - ! deck that declares its own waves/current OPTIONS (see CD_Init_Deck_Aggregate). + ! forbid_deck_ambient: the caller evaluates no deck waves (and, without deck_current, no + ! deck current), so reject a deck that declares them (see CD_Init_Deck_Aggregate). LOGICAL, INTENT(IN), OPTIONAL :: forbid_deck_ambient ! range_files: the caller writes the range graphs of the LINES flag r (CD_AGG_Range_*) LOGICAL, INTENT(IN), OPTIONAL :: range_files @@ -328,6 +337,9 @@ SUBROUTINE CD_AGG_Init_From_Deck(self, deck_path, dt, ErrStat, ErrMsg, env_gravi ! static_run: the caller marches no step (the standalone TMax = 0 run; see ! CD_Init_Deck_Aggregate) LOGICAL, INTENT(IN), OPTIONAL :: static_run + ! deck_current: the caller marches the deck's own current (the standalone driver; see + ! CD_Init_Deck_Aggregate): every step samples it at the nodes, at its t_committed + LOGICAL, INTENT(IN), OPTIONAL :: deck_current ! Both bundles (about 70 KB together) are built on the heap: initialisation runs on the ! thread of the calling host, whose stack size CableDyn does not choose. @@ -368,7 +380,7 @@ SUBROUTINE CD_AGG_Init_From_Deck(self, deck_path, dt, ErrStat, ErrMsg, env_gravi forbid_deck_ambient=forbid_deck_ambient, run_tmax=run_tmax, & range_files=range_files, host_orientation=host_orientation, & static_current=static_current, prescribed_motion=prescribed_motion, & - static_run=static_run) + static_run=static_run, deck_current=deck_current) IF (PRESENT(external_fluid)) THEN candidate%built_extfluid = external_fluid END IF @@ -503,6 +515,7 @@ SUBROUTINE CD_AGG_Init_From_Deck(self, deck_path, dt, ErrStat, ErrMsg, env_gravi IF (ALLOCATED(parts%line_obj_index)) CALL MOVE_ALLOC(parts%line_obj_index, candidate%line_obj_index) candidate%ranges = parts%ranges candidate%motion = parts%motion + candidate%current = parts%current IF (ALLOCATED(parts%cable_points)) THEN CALL MOVE_ALLOC(parts%cable_points, candidate%cable_points) ELSE @@ -587,6 +600,16 @@ SUBROUTINE CD_AGG_Init_From_Deck(self, deck_path, dt, ErrStat, ErrMsg, env_gravi CALL CD_AGG_End(candidate, es, em) RETURN END IF + ! the deck's own current at t = 0 at the static state: the EI = 0 lines re-derive their start + ! accelerations in it and the cables take it as their first held field, as the single-line + ! routes' t = 0 samples do before their march + IF (CD_Deck_Current_Active(candidate%current)) THEN + CALL sample_deck_current(candidate, CD_ZERO, .TRUE., ErrStat, ErrMsg) + IF (ErrStat /= CD_AGG_OK) THEN + CALL CD_AGG_End(candidate, es, em) + RETURN + END IF + END IF candidate%dt = dt ! freeze the coupling step for the fixed-dt Step_Moving guard candidate%initialized = .TRUE. IF (CD_Motion_Active(candidate%motion)) THEN @@ -1087,6 +1110,13 @@ SUBROUTINE CD_AGG_Step_Moving(self, dt, position, velocity, acceleration, conver 'threaded into every step' RETURN END IF + ! a deck-owned current is sampled at the end-of-step time + IF (CD_Deck_Current_Active(self%current) .AND. .NOT. PRESENT(t_committed)) THEN + ErrStat = CD_AGG_BADINPUT + ErrMsg = 'CableDyn_OpenFAST_Aggregate: a deck-owned current requires the committed time (t_committed) '// & + 'threaded into every step' + RETURN + END IF IF (.NOT. (moving_cols_ok(position, self) .AND. moving_cols_ok(velocity, self) .AND. & moving_cols_ok(acceleration, self))) THEN ErrStat = CD_AGG_BADINPUT @@ -1149,6 +1179,15 @@ SUBROUTINE CD_AGG_Step_Moving(self, dt, position, velocity, acceleration, conver END IF self%mv_roll = CD_ZERO IF (use_roll) self%mv_roll = roll + ! The deck's own current over this step: u(x_j, t + dt) at every node x_j of the step-start + ! state, held over the step on the EI = 0 lines and the cables, as the single-line EI = 0 + ! and cubic-Hermite marches sample it before their steps. It is an input of the step (a + ! function of the committed state and the clock), so a rewound or restored step samples + ! the same field again. + IF (CD_Deck_Current_Active(self%current)) THEN + CALL sample_deck_current(self, t_committed, .FALSE., ErrStat, ErrMsg) + IF (ErrStat /= CD_AGG_OK) RETURN + END IF ! stage: snapshot every sub-object before any of them steps (multi-object only; a ! single sub-object is already atomic -- the hot mooring-only path skips this). ! A Rigid6 deck is single-subobject (ncable == 0) yet still needs staging: its branch @@ -1503,13 +1542,21 @@ SUBROUTINE CD_AGG_Refresh_Accelerations(self, ErrStat, ErrMsg) !! committed state, keeping the coupled node's prescribed acceleration !! (CD_HFMF_Refresh_Acceleration): after CD_AGG_UpdateStates_Moving installs the first row !! of a prescribed motion, so the first step does not start from the static acceleration - !! (the standalone cubic-Hermite route's row-1 station). The EI = 0 system is unchanged. + !! (the standalone cubic-Hermite route's row-1 station). The EI = 0 system is unchanged, + !! except under a deck-owned current: the row-1 station is t = 0, so the current is sampled + !! again at t = 0 at the installed row (as the single-line routes sample it after installing + !! row 1), an EI = 0 line whose field changed re-deriving its acceleration in it, before the + !! cables' refresh. TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: self INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg INTEGER :: c, es CHARACTER(1024) :: em IF (.NOT. require_initialized(self, ErrStat, ErrMsg)) RETURN + IF (CD_Deck_Current_Active(self%current)) THEN + CALL sample_deck_current(self, CD_ZERO, .TRUE., ErrStat, ErrMsg) + IF (ErrStat /= CD_AGG_OK) RETURN + END IF DO c = 1, self%ncable CALL CD_HFMF_Refresh_Acceleration(self%cables(c), es, em) IF (es /= CD_HFMF_OK) THEN @@ -1521,6 +1568,33 @@ SUBROUTINE CD_AGG_Refresh_Accelerations(self, ErrStat, ErrMsg) ErrMsg = '' END SUBROUTINE CD_AGG_Refresh_Accelerations + SUBROUTINE sample_deck_current(self, time, initial_condition, ErrStat, ErrMsg) + !! The deck's own current at time over every node: the EI = 0 system's lines + !! (CD_Deck_Current_Sample_System; initial_condition re-derives the acceleration of a line + !! whose field changed) and the finite-EI cables (CD_Deck_Current_Sample_Cables). + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: self + REAL(wp), INTENT(IN) :: time + LOGICAL, INTENT(IN) :: initial_condition + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: es + CHARACTER(1024) :: em + ErrStat = CD_AGG_OK + ErrMsg = '' + IF (self%has_sys) THEN + CALL CD_Deck_Current_Sample_System(self%current, self%sys%fast%system, time, es, em, & + initial_condition=initial_condition) + IF (es /= CD_DECKDRV_OK) THEN + CALL map_deck_status(es, em, ErrStat, ErrMsg) + RETURN + END IF + END IF + IF (self%ncable > 0) THEN + CALL CD_Deck_Current_Sample_Cables(self%current, self%cables, time, es, em) + IF (es /= CD_DECKDRV_OK) CALL map_deck_status(es, em, ErrStat, ErrMsg) + END IF + END SUBROUTINE sample_deck_current + SUBROUTINE check_motion_columns(self, ErrStat, ErrMsg) !! The prescribed-motion columns match the moving surface: one column per moving point, and !! each column's driving point at that moving point's static position (a column map that @@ -2310,6 +2384,7 @@ SUBROUTINE CD_AGG_End(self, ErrStat, ErrMsg) IF (ALLOCATED(self%mv_roll)) DEALLOCATE (self%mv_roll) IF (ALLOCATED(self%cable_phi0)) DEALLOCATE (self%cable_phi0) CALL CD_Motion_End(self%motion) + CALL CD_Deck_Current_End(self%current) IF (ALLOCATED(self%cable_stat)) DEALLOCATE (self%cable_stat) IF (ALLOCATED(self%cable_msg)) DEALLOCATE (self%cable_msg) IF (ALLOCATED(self%channels)) DEALLOCATE (self%channels) diff --git a/tests/data/msg_mixed_waves.dat b/tests/data/msg_mixed_waves.dat new file mode 100644 index 00000000..2e42b975 --- /dev/null +++ b/tests/data/msg_mixed_waves.dat @@ -0,0 +1,58 @@ +--------------------- CableDyn Input File --- +msg_mixed_waves +--------------------- LINE TYPES --- +TypeName Diam MassDenInAir EA BA EI Cd_n Cd_t Ca_n Ca_t +(-) (m) (kg/m) (N) (-) (Nm2) (-) (-) (-) (-) +chain 0.216 286.56 1229760000 -1 0 1.37 0.64 1 0 +pc 0.16 36.7 469000000 -1 19900 1.2 0.1 1 0 +buoy 0.5 170.666793 469000000 -1 19900 1.2 0.1 1 0 +--------------------- POINTS --- +ID Type X Y Z Mass Vol CdA Ca +(-) (-) (m) (m) (m) (kg) (m3) (m2) (-) +1 Coupled 0 0 -14 0 0 0 0 +2 Fixed 830 0 -200 0 0 0 0 +3 Fixed -415 719 -200 0 0 0 0 +4 Fixed -300 -50 -200 0 0 0 0 +--------------------- LINES --- +ID NodeA NodeB Outputs +(-) (-) (-) (-) +1 1 2 - +2 1 3 - +3 1 4 - +--------------------- SECTIONS --- +LineID LineType Length NumSegs +(-) (-) (m) (-) +1 chain 850 85 +2 chain 850 85 +3 pc 180 180 +3 buoy 80 80 +3 pc 150 150 +--------------------- OPTIONS --- +9.80665 g +1025.0 rhoW +200.0 WtrDpth +100000.0 kBot +1.0e4 cBot +0.05 dtM +0.0 TMax +airy 2 8 0 waves +--------------------- OUTPUTS --- +"FairTen1" +"AnchTen1" +"FairTen2" +"AnchTen2" +"FairTen3" +"AnchTen3" +"Point1Fx" +"Point1Fy" +"Point1Fz" +"Point2Fx" +"Point2Fy" +"Point2Fz" +"Point3Fx" +"Point3Fy" +"Point3Fz" +"Point4Fx" +"Point4Fy" +"Point4Fz" +--------------------- need this line --- diff --git a/tests/test_mixed_route_currents.f90 b/tests/test_mixed_route_currents.f90 new file mode 100644 index 00000000..8e60d849 --- /dev/null +++ b/tests/test_mixed_route_currents.f90 @@ -0,0 +1,798 @@ +! File: tests/test_mixed_route_currents.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +!> Deck currents on the standalone mixed route: a deck that mixes an EI = 0 chain and a finite-EI +!> cable (on separate points, without bodies, rods or Free/Connect points) runs on the coupled +!> aggregate, marched by the standalone driver (the executable given as the first argument), and +!> takes every deck current the single-line routes take. Each deck is run three ways: the cable +!> alone (the standalone cubic-Hermite route), the chain alone (the EI = 0 route) and both together +!> (the mixed route); both Coupled fairleads surge 1 m from rest (motionFile) over 10 s. +!> 1. A uniform current (0.4, 0.3, 0) m/s and a sheared profile, both across the two lines (the +!> cable along x, the chain along y), in the static start and the march: the mixed route +!> against the single-line routes, each channel to a fraction of its range, beside the same +!> comparison in still water (the route difference without a current). The static start agrees +!> within STATIC_TOL: the chain exactly, the cable to the stopping point of the coupled cable +!> build's static polish (its out-of-plane offset, the softest coordinate, by 4 um of 0.55 m; +!> in still water exactly). In the march the cable steps with the coupled Newton controls on +!> the mixed route (relative tolerance 5e-3, a fresh factor) and with the deck's on its own +!> (1e-8, a carried factor), which differ by about 1.2e-3 of the range in still water too +!> (DRIVER_CABLE_TOL); with the deck's controls given to the aggregate cable (the library +!> march of the driver's loop) the march keeps the static start's difference +!> (LIBRARY_CABLE_TOL). The chain agrees within CHAIN_TOL (exactly in a sheared current; its +!> row-1 transfer re-derives its interior accelerations on the mixed route, by 5e-5 in still +!> water). The current is felt: both mid nodes leave the vertical plane of their chord, and +!> the chain's fairlead tension history differs from the still-water run's. +!> 2. MoorDyn-C Currents 1 (a sheared current_profile.txt), Currents 2 (a sheared +!> current_profile_dynamic.txt that varies in time) and Currents 5 (a current_profile_4d.txt +!> grid that varies in x, y, z and time): the gate 1 agreement of the mixed route with the +!> single-line routes given the same file. +!> 3. The wrap of a Currents 2 table past its last sample in the march: three samples (0, 2, 4 s, +!> the first and last equal) run to 10 s repeat with period 6 s. The mixed route matches the +!> mixed route given the table unrolled to 12 s (round-off: 1e-9 of each channel's range) and +!> departs from the same table held after its last sample (beyond 6 s, by more than 1 % of the +!> chain's tension range): the march samples the wrapped field at every step. +!> 4. A uniform field written as a Currents 1 profile equals the OPTION uniform current on the +!> mixed route to GRID_TOL of each channel's range (the profile's linear interpolation between +!> equal levels is exact on some platforms and one ulp off on others, which the march carries: +!> 0 on Windows, 3.9e-8 on Linux gfortran); written as a Currents 5 grid (constant in space and time), its static +!> start bit for bit and its march to GRID_TOL of each channel's range (the round-off of the +!> grid's trilinear weights). +!> 5. The correction rewind of the aggregate (CD_AGG_Snapshot, a step, CD_AGG_Restore, the step +!> again) every 20th step, in still water and in the Currents 2 field: the repeated step samples +!> the current again from the restored state, and every channel of every step equals the march +!> without rewinds bit for bit. +!> 6. The mixed route still refuses deck waves by name, and like the single-line routes a current +!> OPTION beside Currents 2 (double-counting) and a current without dtM. +PROGRAM test_mixed_route_currents + USE CableDyn_Precision, ONLY: wp + USE CableDyn_OpenFAST_Aggregate, ONLY: CD_AGG_ModuleType, CD_AGG_Init_From_Deck, CD_AGG_NMovingPoints, & + CD_AGG_GetMovingPointMesh, CD_AGG_UpdateStates_Moving, & + CD_AGG_Step_Moving, CD_AGG_CalcOutput, CD_AGG_EvalChannel, & + CD_AGG_NumChannels, CD_AGG_End, CD_AGG_MotionKinematics, & + CD_AGG_Refresh_Accelerations, CD_AGG_Snapshot, CD_AGG_Restore, CD_AGG_OK + USE, INTRINSIC :: IEEE_ARITHMETIC, ONLY: IEEE_IS_FINITE + IMPLICIT NONE + + REAL(wp), PARAMETER :: PI = 3.14159265358979323846_wp + REAL(wp), PARAMETER :: DT = 0.05_wp, TMAX = 10.0_wp, PERIOD = 10.0_wp + INTEGER, PARAMETER :: NSTEP = 200, MAXCOL = 16, MAXROW = 400 + CHARACTER(*), PARAMETER :: CAB_T = 'cab 0.2 60.0 4.0e8 0.0 1.0e4 1.2 0.1 1.0 0.0' + CHARACTER(*), PARAMETER :: CHAIN_T = 'chain 0.1 50.0 1.0e9 -1.0 0.0 1.37 0.64 1.0 0.0' + ! the mixed deck's channels: the cable (line 1) then the chain (line 2) + CHARACTER(16), PARAMETER :: MIXED_OUTS(10) = [CHARACTER(16) :: 'FairTen1', 'AnchTen1', 'L1N21px', 'L1N21py', & + 'L1N21pz', 'FairTen2', 'AnchTen2', 'L2N11px', 'L2N11py', 'L2N11pz'] + CHARACTER(16), PARAMETER :: CABLE_OUTS(5) = [CHARACTER(16) :: 'FairTen1', 'AnchTen1', 'L1N21px', 'L1N21py', & + 'L1N21pz'] + CHARACTER(16), PARAMETER :: CHAIN_OUTS(5) = [CHARACTER(16) :: 'FairTen1', 'AnchTen1', 'L1N11px', 'L1N11py', & + 'L1N11pz'] + ! differences of the mixed route from the single-line routes, of each channel's range (gate 1): the + ! static start; the cable stepped with the coupled Newton controls, and with the deck's; the chain + REAL(wp), PARAMETER :: STATIC_TOL = 1.0e-5_wp, DRIVER_CABLE_TOL = 2.0e-3_wp, LIBRARY_CABLE_TOL = 1.0e-5_wp + REAL(wp), PARAMETER :: CHAIN_TOL = 1.0e-4_wp + ! round-off between two writings of one field (gates 3 and 4), of each channel's range, and of a + ! uniform field interpolated on a grid (gate 4) + REAL(wp), PARAMETER :: SAME_TOL = 1.0e-9_wp, GRID_TOL = 1.0e-7_wp + CHARACTER(1024) :: driver + INTEGER :: n_fail = 0 + + IF (COMMAND_ARGUMENT_COUNT() < 1) ERROR STOP 'usage: test_mixed_route_currents ' + CALL GET_COMMAND_ARGUMENT(1, driver) + + CALL check_option_currents() + CALL check_moordyn_c_currents() + CALL check_wrap() + CALL check_uniform_writings() + CALL check_snapshot('still/mixed.dat', '5 still water') + CALL check_snapshot('c2/mixed.dat', '5 Currents 2') + CALL check_refusals() + IF (n_fail > 0) THEN + WRITE (*, '(A,I0,A)') 'FAIL: ', n_fail, ' mixed-route current gate(s) failed' + ERROR STOP 1 + END IF + WRITE (*, '(A)') 'PASS: deck currents on the standalone mixed route' + +CONTAINS + + SUBROUTINE require(cond, msg) + LOGICAL, INTENT(IN) :: cond + CHARACTER(*), INTENT(IN) :: msg + IF (.NOT. cond) THEN + n_fail = n_fail + 1 + WRITE (*, '(A,A)') 'FAILED: ', msg + END IF + END SUBROUTINE require + + PURE SUBROUTINE smooth(amplitude, t, f, df, d2f) + !! f = F (1 - cos w t) / 2 and its rates, w = 2 pi / PERIOD: a motion from rest. + REAL(wp), INTENT(IN) :: amplitude, t + REAL(wp), INTENT(OUT) :: f, df, d2f + REAL(wp) :: w + w = 2.0_wp*PI/PERIOD + f = 0.5_wp*amplitude*(1.0_wp - COS(w*t)) + df = 0.5_wp*amplitude*w*SIN(w*t) + d2f = 0.5_wp*amplitude*w*w*COS(w*t) + END SUBROUTINE smooth + + SUBROUTINE write_motion(path, ids, ys) + !! motionFile rows of the Coupled points ids at (0, ys, -50), each surging 1 m from rest. + CHARACTER(*), INTENT(IN) :: path + INTEGER, INTENT(IN) :: ids(:) + REAL(wp), INTENT(IN) :: ys(:) + REAL(wp) :: t, x, vx, ax + INTEGER :: u, k, j + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + DO k = 0, NSTEP + t = DT*k + CALL smooth(1.0_wp, t, x, vx, ax) + DO j = 1, SIZE(ids) + WRITE (u, '(F8.3,1X,I0,3ES25.16E3,A,ES25.16E3,A,ES25.16E3,A)') t, ids(j), x, ys(j), -50.0_wp, ' ', vx, & + ' 0 0 ', ax, ' 0 0' + END DO + END DO + CLOSE (u) + END SUBROUTINE write_motion + + SUBROUTINE write_deck(path, types, points, lines, sections, options, outs) + CHARACTER(*), INTENT(IN) :: path, types(:), points(:), lines(:), sections(:), options(:), outs(:) + INTEGER :: u, i + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'mixed-route current gate' + WRITE (u, '(A)') '--- LINE TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass EA BA EI Cdn Cdt Can Cat' + WRITE (u, '(A)') '(-) (m) (kg/m) (N) (-) (Nm2) (-) (-) (-) (-)' + DO i = 1, SIZE(types) + WRITE (u, '(A)') TRIM(types(i)) + END DO + WRITE (u, '(A)') '--- POINTS ---' + WRITE (u, '(A)') 'ID Type X Y Z Mass Vol CdA Ca' + WRITE (u, '(A)') '(-) (-) (m) (m) (m) (kg) (m3) (m2) (-)' + DO i = 1, SIZE(points) + WRITE (u, '(A)') TRIM(points(i)) + END DO + WRITE (u, '(A)') '--- LINES ---' + WRITE (u, '(A)') 'ID NodeA NodeB Outputs' + WRITE (u, '(A)') '(-) (-) (-) (-)' + DO i = 1, SIZE(lines) + WRITE (u, '(A)') TRIM(lines(i)) + END DO + WRITE (u, '(A)') '--- SECTIONS ---' + WRITE (u, '(A)') 'LineID LineType Length NumSegs' + WRITE (u, '(A)') '(-) (-) (m) (-)' + DO i = 1, SIZE(sections) + WRITE (u, '(A)') TRIM(sections(i)) + END DO + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '200.0 WtrDpth' + DO i = 1, SIZE(options) + WRITE (u, '(A)') TRIM(options(i)) + END DO + WRITE (u, '(A)') '--- OUTPUTS ---' + DO i = 1, SIZE(outs) + WRITE (u, '(A)') TRIM(outs(i)) + END DO + WRITE (u, '(A)') '--- END ---' + CLOSE (u) + END SUBROUTINE write_deck + + SUBROUTINE write_case(dir, current) + !! The three decks of a case in folder dir (ending in '/', or empty): cable.dat, a 100 m + !! finite-EI line (40 elements) from End A on the Coupled point (0, 0, -50) to a Fixed End B + !! at (95, 0, -60); chain.dat, a 110 m chain (20 segments) from (0, 20, -50) to a Fixed + !! (0, 110, -100); and mixed.dat, both on their own points. current: the deck's current rows. + CHARACTER(*), INTENT(IN) :: dir, current(:) + CHARACTER(48) :: opts(SIZE(current) + 3) + INTEGER :: i + opts(1) = '0.05 dtM' + opts(2) = '10.0 TMax' + DO i = 1, SIZE(current) + opts(2 + i) = current(i) + END DO + opts(SIZE(opts)) = 'cable_m.txt motionFile' + CALL write_motion(dir//'cable_m.txt', [1], [0.0_wp]) + CALL write_deck(dir//'cable.dat', [CHARACTER(64) :: CAB_T], & + [CHARACTER(40) :: '1 Coupled 0.0 0.0 -50.0 0 0 0 0', '2 Fixed 95.0 0.0 -60.0 0 0 0 0'], & + [CHARACTER(16) :: '1 1 2 -'], [CHARACTER(24) :: '1 cab 100.0 40'], opts, CABLE_OUTS) + opts(SIZE(opts)) = 'chain_m.txt motionFile' + CALL write_motion(dir//'chain_m.txt', [1], [20.0_wp]) + CALL write_deck(dir//'chain.dat', [CHARACTER(64) :: CHAIN_T], & + [CHARACTER(40) :: '1 Coupled 0.0 20.0 -50.0 0 0 0 0', '2 Fixed 0.0 110.0 -100.0 0 0 0 0'], & + [CHARACTER(16) :: '1 1 2 -'], [CHARACTER(24) :: '1 chain 110.0 20'], opts, CHAIN_OUTS) + opts(SIZE(opts)) = 'mixed_m.txt motionFile' + CALL write_motion(dir//'mixed_m.txt', [1, 3], [0.0_wp, 20.0_wp]) + CALL write_deck(dir//'mixed.dat', [CHARACTER(64) :: CAB_T, CHAIN_T], & + [CHARACTER(40) :: '1 Coupled 0.0 0.0 -50.0 0 0 0 0', '2 Fixed 95.0 0.0 -60.0 0 0 0 0', & + '3 Coupled 0.0 20.0 -50.0 0 0 0 0', '4 Fixed 0.0 110.0 -100.0 0 0 0 0'], & + [CHARACTER(16) :: '1 1 2 -', '2 3 4 -'], [CHARACTER(24) :: '1 cab 100.0 40', '2 chain 110.0 20'], & + opts, MIXED_OUTS) + END SUBROUTINE write_case + + SUBROUTINE write_text(path, lines) + CHARACTER(*), INTENT(IN) :: path, lines(:) + INTEGER :: u, i + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + DO i = 1, SIZE(lines) + WRITE (u, '(A)') TRIM(lines(i)) + END DO + CLOSE (u) + END SUBROUTINE write_text + + SUBROUTINE run_driver(deck, root, ok) + !! Run the driver executable on a deck, its stdout and stderr to .log. + CHARACTER(*), INTENT(IN) :: deck, root + LOGICAL, INTENT(OUT) :: ok + INTEGER :: ex, cs + CALL EXECUTE_COMMAND_LINE('"'//TRIM(driver)//'" '//deck//' '//root//' > '//root//'.log 2>&1', & + WAIT=.TRUE., EXITSTAT=ex, CMDSTAT=cs) + ok = cs == 0 .AND. ex == 0 + END SUBROUTINE run_driver + + INTEGER FUNCTION driver_exit(deck, root) RESULT(ex) + CHARACTER(*), INTENT(IN) :: deck, root + INTEGER :: cs + CALL EXECUTE_COMMAND_LINE('"'//TRIM(driver)//'" '//deck//' '//root//' > '//root//'.log 2>&1', & + WAIT=.TRUE., EXITSTAT=ex, CMDSTAT=cs) + IF (cs /= 0) ex = -1 + END FUNCTION driver_exit + + LOGICAL FUNCTION log_has(root, text) RESULT(found) + CHARACTER(*), INTENT(IN) :: root, text + CHARACTER(4096) :: line + INTEGER :: u, ios + found = .FALSE. + OPEN (NEWUNIT=u, FILE=root//'.log', STATUS='OLD', ACTION='READ', IOSTAT=ios) + IF (ios /= 0) RETURN + DO + READ (u, '(A)', IOSTAT=ios) line + IF (ios /= 0) EXIT + IF (INDEX(line, text) > 0) found = .TRUE. + END DO + CLOSE (u) + END FUNCTION log_has + + SUBROUTINE read_out(path, names, vals, nrow) + !! The channel names and rows of a driver .out file (Time first). + CHARACTER(*), INTENT(IN) :: path + CHARACTER(32), INTENT(OUT) :: names(MAXCOL) + REAL(wp), INTENT(OUT) :: vals(MAXROW, MAXCOL) + INTEGER, INTENT(OUT) :: nrow + CHARACTER(4096) :: buf + INTEGER :: u, ios, ncol, k + names = '' + vals = 0.0_wp + nrow = 0 + OPEN (NEWUNIT=u, FILE=path, STATUS='OLD', ACTION='READ', IOSTAT=ios) + IF (ios /= 0) RETURN + READ (u, '(A)', IOSTAT=ios) buf + READ (u, '(A)', IOSTAT=ios) buf + READ (buf, *, IOSTAT=ios) names + ncol = 0 + DO k = 1, MAXCOL + IF (LEN_TRIM(names(k)) > 0) ncol = k + END DO + DO + IF (nrow == MAXROW) EXIT + READ (u, *, IOSTAT=ios) vals(nrow + 1, 1:ncol) + IF (ios /= 0) EXIT + nrow = nrow + 1 + END DO + CLOSE (u) + END SUBROUTINE read_out + + INTEGER FUNCTION col_of(names, name) RESULT(c) + CHARACTER(32), INTENT(IN) :: names(:) + CHARACTER(*), INTENT(IN) :: name + INTEGER :: k + c = 0 + DO k = 1, SIZE(names) + IF (TRIM(names(k)) == TRIM(name)) c = k + END DO + END FUNCTION col_of + + REAL(wp) FUNCTION range_error(a, b, n) RESULT(e) + !! max |b - a| over the rows, relative to the range max |a|. + REAL(wp), INTENT(IN) :: a(:), b(:) + INTEGER, INTENT(IN) :: n + e = MAXVAL(ABS(b(1:n) - a(1:n)))/MAX(MAXVAL(ABS(a(1:n))), TINY(1.0_wp)) + IF (.NOT. IEEE_IS_FINITE(e)) e = HUGE(1.0_wp) + END FUNCTION range_error + + SUBROUTINE run_case(dir, label, ok) + !! Run the three decks of a case (write_case) on the driver. + CHARACTER(*), INTENT(IN) :: dir, label + LOGICAL, INTENT(OUT) :: ok + LOGICAL :: ok_a, ok_b, ok_c + CALL run_driver(dir//'cable.dat', dir//'cable', ok_a) + CALL require(ok_a, label//': the cable alone runs on the standalone cubic-Hermite route') + CALL run_driver(dir//'chain.dat', dir//'chain', ok_b) + CALL require(ok_b, label//': the chain alone runs on the EI = 0 route') + CALL run_driver(dir//'mixed.dat', dir//'mixed', ok_c) + CALL require(ok_c, label//': the mixed deck runs in the current') + IF (ok_c) CALL require(log_has(dir//'mixed', 'mixed standalone aggregate'), & + label//': the mixed deck runs on the aggregate') + ok = ok_a .AND. ok_b .AND. ok_c + END SUBROUTINE run_case + + SUBROUTINE line_errors(nm, vm, nl, vl, first, outs_l, e_static, e_march) + !! The mixed route's channels MIXED_OUTS(first + 1:first + 5) against a single-line route's + !! outs_l: the largest difference at t = 0 (the static start) and over every row, each + !! relative to the channel's range max |a| on the single-line route. + CHARACTER(32), INTENT(IN) :: nm(:), nl(:) + REAL(wp), INTENT(IN) :: vm(:, :), vl(:, :) + INTEGER, INTENT(IN) :: first + CHARACTER(16), INTENT(IN) :: outs_l(5) + REAL(wp), INTENT(OUT) :: e_static, e_march + INTEGER :: k, cm, cl + REAL(wp) :: scale + e_static = 0.0_wp + e_march = 0.0_wp + DO k = 1, 5 + cm = col_of(nm, MIXED_OUTS(first + k)) + cl = col_of(nl, outs_l(k)) + IF (cm == 0 .OR. cl == 0) THEN + e_static = HUGE(1.0_wp) + e_march = HUGE(1.0_wp) + RETURN + END IF + scale = MAX(MAXVAL(ABS(vl(1:NSTEP + 1, cl))), TINY(1.0_wp)) + e_static = MAX(e_static, ABS(vm(1, cm) - vl(1, cl))/scale) + e_march = MAX(e_march, MAXVAL(ABS(vm(1:NSTEP + 1, cm) - vl(1:NSTEP + 1, cl)))/scale) + END DO + END SUBROUTINE line_errors + + SUBROUTINE compare_case(dir, label, still) + !! The mixed route (mixed.out) against the cable alone (cable.out) and the chain alone + !! (chain.out): the static row (t = 0) and every row of the march. still: a still-water case + !! (the baseline of the route difference; no out-of-plane offset to check). + CHARACTER(*), INTENT(IN) :: dir, label + LOGICAL, INTENT(IN), OPTIONAL :: still + CHARACTER(32) :: nm(MAXCOL), na(MAXCOL), nc(MAXCOL) + REAL(wp), ALLOCATABLE :: vm(:, :), va(:, :), vc(:, :) + INTEGER :: rm, ra, rc, cm, cs + REAL(wp) :: e_cable_static, e_cable, e_chain_static, e_chain + ALLOCATE (vm(MAXROW, MAXCOL), va(MAXROW, MAXCOL), vc(MAXROW, MAXCOL)) + CALL read_out(dir//'mixed.out', nm, vm, rm) + CALL read_out(dir//'cable.out', na, va, ra) + CALL read_out(dir//'chain.out', nc, vc, rc) + CALL require(rm == NSTEP + 1 .AND. ra == NSTEP + 1 .AND. rc == NSTEP + 1, label//': every route writes every row') + IF (rm /= NSTEP + 1 .OR. ra /= NSTEP + 1 .OR. rc /= NSTEP + 1) RETURN + CALL line_errors(nm, vm, na, va, 0, CABLE_OUTS, e_cable_static, e_cable) + CALL line_errors(nm, vm, nc, vc, 5, CHAIN_OUTS, e_chain_static, e_chain) + WRITE (*, '(A,A,2ES10.3,A,2ES10.3,A)') ' ', label//': driver, mixed route against single-line routes: cable ', & + e_cable_static, e_cable, ', chain ', e_chain_static, e_chain, ' (static start, march; of each channel''s range)' + CALL require(e_cable_static <= STATIC_TOL .AND. e_chain_static <= STATIC_TOL, & + label//': the static start agrees within the static tolerance') + CALL require(e_cable <= DRIVER_CABLE_TOL, label//': the cable agrees within the coupled Newton tolerance') + CALL require(e_chain <= CHAIN_TOL, label//': the chain agrees within the row-1 transfer') + ! the current is felt: both mid nodes leave the vertical plane of their chord + IF (PRESENT(still)) THEN + IF (still) RETURN + END IF + cm = col_of(nm, 'L1N21py') + cs = col_of(nm, 'L2N11px') + IF (cm > 0 .AND. cs > 0) THEN + WRITE (*, '(A,A,F8.4,A,F8.4,A)') ' ', label//': static out-of-plane offset of the mid nodes: cable ', & + vm(1, cm), ' m, chain ', vm(1, cs), ' m' + CALL require(ABS(vm(1, cm)) > 0.02_wp .AND. ABS(vm(1, cs)) > 0.02_wp, & + label//': the current pushes both lines out of the plane of their chord') + END IF + END SUBROUTINE compare_case + + SUBROUTINE march_library(dir, label) + !! The driver's march of the mixed deck (CableDyn_driver run_mixed_held_deck) through the + !! aggregate library, with the cable given the standalone route's Newton controls (the deck's + !! dynamic tolerance 1e-8, 30 iterations, the carried factor): every channel of both lines is + !! compared at every step with the single-line routes' outputs. + CHARACTER(*), INTENT(IN) :: dir, label + TYPE(CD_AGG_ModuleType), ALLOCATABLE :: agg + REAL(wp), ALLOCATABLE :: got(:, :), va(:, :), vc(:, :) + CHARACTER(32) :: na(MAXCOL), nc(MAXCOL), ng(MAXCOL) + CHARACTER(2048) :: em + INTEGER :: c, ra, rc, nch, es + REAL(wp) :: e_cable_static, e_cable, e_chain_static, e_chain + LOGICAL :: ok + ALLOCATE (agg, va(MAXROW, MAXCOL), vc(MAXROW, MAXCOL)) + CALL init_mixed(agg, dir//'mixed.dat', label, ok) + IF (.NOT. ok) RETURN + DO c = 1, agg%ncable + agg%cables(c)%tol = 1.0e-8_wp + agg%cables(c)%max_iter = 30 + agg%cables(c)%line%tangent_reuse = .TRUE. + END DO + nch = CD_AGG_NumChannels(agg) + ALLOCATE (got(MAXROW, MAXCOL)) + got = 0.0_wp + CALL march(agg, 0, NSTEP, got(1:NSTEP + 1, 1:nch), label, ok) + CALL CD_AGG_End(agg, es, em) + IF (.NOT. ok) RETURN + CALL read_out(dir//'cable.out', na, va, ra) + CALL read_out(dir//'chain.out', nc, vc, rc) + CALL require(ra == NSTEP + 1 .AND. rc == NSTEP + 1, label//': the single-line outputs are complete') + IF (ra /= NSTEP + 1 .OR. rc /= NSTEP + 1) RETURN + ng = '' + ng(1:SIZE(MIXED_OUTS)) = MIXED_OUTS + CALL line_errors(ng, got, na, va, 0, CABLE_OUTS, e_cable_static, e_cable) + CALL line_errors(ng, got, nc, vc, 5, CHAIN_OUTS, e_chain_static, e_chain) + WRITE (*, '(A,A,2ES10.3,A,2ES10.3,A)') ' ', label//': library, the standalone Newton controls: cable ', & + e_cable_static, e_cable, ', chain ', e_chain_static, e_chain, ' (static start, march; of each channel''s range)' + CALL require(e_cable <= LIBRARY_CABLE_TOL, label//': with the same Newton controls the cable reproduces the '// & + 'single-line route') + CALL require(e_chain <= CHAIN_TOL, label//': the chain reproduces the EI = 0 route') + END SUBROUTINE march_library + SUBROUTINE init_mixed(agg, deck, label, ok) + !! The aggregate as the driver's mixed route builds it, with the motion's first row installed. + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: agg + CHARACTER(*), INTENT(IN) :: deck, label + LOGICAL, INTENT(OUT) :: ok + REAL(wp), ALLOCATABLE :: pos(:, :), vel(:, :), acc(:, :), load(:, :), orient(:, :, :), omega(:, :), alpha(:, :) + REAL(wp), ALLOCATABLE :: roll(:) + CHARACTER(2048) :: em + INTEGER :: es, n + LOGICAL :: turns, rolls + CALL CD_AGG_Init_From_Deck(agg, deck, DT, es, em, forbid_deck_ambient=.TRUE., run_tmax=TMAX, & + range_files=.TRUE., host_orientation=.TRUE., prescribed_motion=.TRUE., & + deck_current=.TRUE.) + ok = es == CD_AGG_OK + CALL require(ok, label//': the aggregate takes the deck current: '//TRIM(em)) + IF (.NOT. ok) RETURN + n = CD_AGG_NMovingPoints(agg, es, em) + ALLOCATE (pos(3, n), vel(3, n), acc(3, n), load(3, n), orient(3, 3, n), omega(3, n), alpha(3, n), roll(n)) + CALL CD_AGG_GetMovingPointMesh(agg, pos, vel, acc, load, es, em) + IF (es == CD_AGG_OK) CALL CD_AGG_MotionKinematics(agg, 1, pos, vel, acc, orient, omega, alpha, roll, turns, & + rolls, es, em) + IF (es == CD_AGG_OK) CALL CD_AGG_UpdateStates_Moving(agg, pos, vel, acc, es, em) + IF (es == CD_AGG_OK) CALL CD_AGG_Refresh_Accelerations(agg, es, em) + ok = es == CD_AGG_OK + CALL require(ok, label//': the first motion row installs: '//TRIM(em)) + END SUBROUTINE init_mixed + + SUBROUTINE march(agg, first, last, got, label, ok) + !! Steps first + 1 .. last of the driver's loop (step 0: the outputs only), every channel + !! of every step into got(step + 1, :). + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: agg + INTEGER, INTENT(IN) :: first, last + REAL(wp), INTENT(INOUT) :: got(:, :) + CHARACTER(*), INTENT(IN) :: label + LOGICAL, INTENT(OUT) :: ok + REAL(wp), ALLOCATABLE :: pos(:, :), vel(:, :), acc(:, :), orient(:, :, :), omega(:, :), alpha(:, :), roll(:) + CHARACTER(2048) :: em + INTEGER :: es, n, step, k, n_iter + LOGICAL :: turns, rolls, conv, stalled + REAL(wp) :: v + n = CD_AGG_NMovingPoints(agg, es, em) + ALLOCATE (pos(3, n), vel(3, n), acc(3, n), orient(3, 3, n), omega(3, n), alpha(3, n), roll(n)) + ok = .TRUE. + DO step = first, last + IF (step > first) THEN + CALL CD_AGG_MotionKinematics(agg, step + 1, pos, vel, acc, orient, omega, alpha, roll, turns, rolls, es, em) + IF (es == CD_AGG_OK) CALL CD_AGG_Step_Moving(agg, DT, pos, vel, acc, conv, stalled, n_iter, es, em, & + t_committed=DT*step) + IF (es /= CD_AGG_OK .OR. .NOT. conv) THEN + CALL require(.FALSE., label//': library march step: '//TRIM(em)) + ok = .FALSE. + RETURN + END IF + ELSE IF (step > 0) THEN + ! the state of step first, recorded by the march that reached it + CYCLE + END IF + CALL CD_AGG_CalcOutput(agg, es, em) + DO k = 1, SIZE(got, 2) + CALL CD_AGG_EvalChannel(agg, k, v, es, em) + got(step + 1, k) = v + END DO + END DO + END SUBROUTINE march + + SUBROUTINE check_option_currents() + !! Gate 1. + LOGICAL :: ok + CHARACTER(32) :: nu(MAXCOL), ns(MAXCOL) + REAL(wp), ALLOCATABLE :: vu(:, :), vs(:, :) + INTEGER :: ru, rs + REAL(wp) :: change + CALL write_case('uni/', [CHARACTER(48) :: 'uniform 0.4 0.3 0 current']) + CALL run_case('uni/', '1 uniform', ok) + IF (ok) THEN + CALL compare_case('uni/', '1 uniform') + CALL march_library('uni/', '1 uniform') + END IF + CALL write_case('prof/', [CHARACTER(48) :: 'profile -200 0.1 0.05 0 0 0.6 0.4 0 current']) + CALL run_case('prof/', '1 profile', ok) + IF (ok) THEN + CALL compare_case('prof/', '1 profile') + CALL march_library('prof/', '1 profile') + END IF + ! the same mixed deck in still water: the current changes the chain's tension history + CALL write_case('still/', [CHARACTER(48) :: 'none current']) + CALL run_case('still/', '1 still water', ok) + IF (ok) THEN + CALL compare_case('still/', '1 still water', still=.TRUE.) + CALL march_library('still/', '1 still water') + END IF + ALLOCATE (vu(MAXROW, MAXCOL), vs(MAXROW, MAXCOL)) + CALL read_out('uni/mixed.out', nu, vu, ru) + CALL read_out('still/mixed.out', ns, vs, rs) + IF (ru == NSTEP + 1 .AND. rs == NSTEP + 1) THEN + change = range_error(vs(:, col_of(ns, 'FairTen2')), vu(:, col_of(nu, 'FairTen2')), rs) + WRITE (*, '(A,ES10.3,A)') ' 1 still water: the uniform current changes the chain fairlead tension by ', change, & + ' of its range' + CALL require(change > 1.0e-3_wp, '1: the mixed route applies the current to the chain') + change = MAXVAL(ABS(vs(1:rs, col_of(ns, 'L1N21py')))) + CALL require(change < 1.0e-9_wp, '1: in still water the cable stays in its plane') + ELSE + CALL require(.FALSE., '1: the still-water and uniform-current outputs are complete') + END IF + END SUBROUTINE check_option_currents + + SUBROUTINE write_c1(dir, uniform) + !! current_profile.txt: a sheared profile across both lines, or the uniform (0.4, 0.3, 0). + CHARACTER(*), INTENT(IN) :: dir + LOGICAL, INTENT(IN) :: uniform + IF (uniform) THEN + CALL write_text(dir//'current_profile.txt', [CHARACTER(40) :: 'uniform current', 'z ux uy uz', & + '-200.0 0.4 0.3 0.0', '0.0 0.4 0.3 0.0']) + ELSE + CALL write_text(dir//'current_profile.txt', [CHARACTER(40) :: 'sheared current', 'z ux uy uz', & + '-200.0 0.05 0.02 0.0', '-80.0 0.3 0.2 0.01', & + '-40.0 0.5 0.35 0.0', '0.0 0.7 0.5 0.0']) + END IF + END SUBROUTINE write_c1 + + SUBROUTINE write_c2(dir, kind) + !! current_profile_dynamic.txt at the depths -200, -80, -40, 0 m: kind 1 the three samples + !! 0, 2, 4 s (the first and last equal, so the field repeats with period 6 s past 4 s), + !! kind 2 the same table unrolled to 12 s, kind 3 the same table held from 4 s to 12 s. + CHARACTER(*), INTENT(IN) :: dir + INTEGER, INTENT(IN) :: kind + CHARACTER(*), PARAMETER :: A = ' 0.10 0.15 0.20 0.25 0.05 0.08 0.10 0.12', & + B = ' 0.40 0.50 0.60 0.70 0.30 0.35 0.40 0.45' + CHARACTER(96) :: rows(7) + INTEGER :: n + SELECT CASE (kind) + CASE (1) + rows(1:3) = [CHARACTER(96) :: '0.0'//A, '2.0'//B, '4.0'//A] + n = 3 + CASE (2) + rows = [CHARACTER(96) :: '0.0'//A, '2.0'//B, '4.0'//A, '6.0'//A, '8.0'//B, '10.0'//A, '12.0'//A] + n = 7 + CASE DEFAULT + rows(1:4) = [CHARACTER(96) :: '0.0'//A, '2.0'//B, '4.0'//A, '12.0'//A] + n = 4 + END SELECT + CALL write_text(dir//'current_profile_dynamic.txt', [CHARACTER(96) :: 'time-varying sheared current', & + 'across both lines', '', '', '-200.0 -80.0 -40.0 0.0', 't ux... uy...', rows(1:n)]) + END SUBROUTINE write_c2 + + SUBROUTINE write_c5(dir, uniform) + !! current_profile_4d.txt: x in {-10, 110}, y in {-10, 120}, z in {-210, -100, 0} and t in + !! {0, 3, 6} with u varying in each (sheared, turning across the lines and past its last + !! sample: the march to 10 s wraps it), or the uniform (0.4, 0.3, 0) at t = 0 and 1. + CHARACTER(*), INTENT(IN) :: dir + LOGICAL, INTENT(IN) :: uniform + REAL(wp), PARAMETER :: XS(2) = [-10.0_wp, 110.0_wp], YS(2) = [-10.0_wp, 120.0_wp], & + ZS(3) = [-210.0_wp, -100.0_wp, 0.0_wp], TS(3) = [0.0_wp, 3.0_wp, 6.0_wp] + INTEGER :: u, ix, iy, iz, it, nt + REAL(wp) :: ux, uy, s + OPEN (NEWUNIT=u, FILE=dir//'current_profile_4d.txt', STATUS='REPLACE', ACTION='WRITE') + nt = MERGE(2, 3, uniform) + WRITE (u, '(A,I0)') '2 2 3 ', nt + WRITE (u, '(A)') '-10.0 110.0' + WRITE (u, '(A)') '-10.0 120.0' + WRITE (u, '(A)') '-210.0 -100.0 0.0' + IF (uniform) THEN + WRITE (u, '(A)') '0.0 1.0' + ELSE + WRITE (u, '(A)') '0.0 3.0 6.0' + END IF + WRITE (u, '(A)') 'x y z t ux uy uz' + DO it = 1, nt + DO iz = 1, 3 + DO iy = 1, 2 + DO ix = 1, 2 + IF (uniform) THEN + ux = 0.4_wp + uy = 0.3_wp + ELSE + s = 1.0_wp + ZS(iz)/250.0_wp + ux = s*(0.3_wp + 0.002_wp*XS(ix) + 0.001_wp*YS(iy))*MERGE(1.0_wp, 1.6_wp, it /= 2) + uy = s*(0.2_wp + 0.001_wp*XS(ix) - 0.001_wp*YS(iy) + 0.1_wp*(it - 1)) + END IF + WRITE (u, '(4F10.3,3F12.6)') XS(ix), YS(iy), ZS(iz), MERGE(REAL(it - 1, wp), TS(it), uniform), ux, uy, & + MERGE(0.0_wp, 0.01_wp*s, uniform) + END DO + END DO + END DO + END DO + CLOSE (u) + END SUBROUTINE write_c5 + + SUBROUTINE check_moordyn_c_currents() + !! Gate 2. + LOGICAL :: ok + CALL write_case('c1/', [CHARACTER(48) :: '1 Currents']) + CALL write_c1('c1/', .FALSE.) + CALL run_case('c1/', '2 Currents 1', ok) + IF (ok) CALL compare_case('c1/', '2 Currents 1') + CALL write_case('c2/', [CHARACTER(48) :: '2 Currents']) + CALL write_c2('c2/', 1) + CALL run_case('c2/', '2 Currents 2', ok) + IF (ok) THEN + CALL compare_case('c2/', '2 Currents 2') + CALL march_library('c2/', '2 Currents 2') + END IF + CALL write_case('c5/', [CHARACTER(48) :: '5 Currents']) + CALL write_c5('c5/', .FALSE.) + CALL run_case('c5/', '2 Currents 5', ok) + IF (ok) THEN + CALL compare_case('c5/', '2 Currents 5') + CALL march_library('c5/', '2 Currents 5') + END IF + END SUBROUTINE check_moordyn_c_currents + + REAL(wp) FUNCTION outs_difference(root_a, root_b, from_row, to_row) RESULT(e) + !! max over the mixed channels and the rows from_row..to_row of |b - a| relative to each + !! channel's range in a (HUGE when an output is incomplete). + CHARACTER(*), INTENT(IN) :: root_a, root_b + INTEGER, INTENT(IN) :: from_row, to_row + CHARACTER(32) :: na(MAXCOL), nb(MAXCOL) + REAL(wp), ALLOCATABLE :: va(:, :), vb(:, :) + INTEGER :: ra, rb, k, ca, cb + REAL(wp) :: scale + ALLOCATE (va(MAXROW, MAXCOL), vb(MAXROW, MAXCOL)) + CALL read_out(root_a//'.out', na, va, ra) + CALL read_out(root_b//'.out', nb, vb, rb) + e = HUGE(1.0_wp) + IF (ra /= NSTEP + 1 .OR. rb /= NSTEP + 1) RETURN + e = 0.0_wp + DO k = 1, SIZE(MIXED_OUTS) + ca = col_of(na, MIXED_OUTS(k)) + cb = col_of(nb, MIXED_OUTS(k)) + IF (ca == 0 .OR. cb == 0) THEN + e = HUGE(1.0_wp) + RETURN + END IF + scale = MAXVAL(ABS(va(1:ra, ca))) + e = MAX(e, MAXVAL(ABS(vb(from_row:to_row, cb) - va(from_row:to_row, ca)))/MAX(scale, TINY(1.0_wp))) + END DO + END FUNCTION outs_difference + + SUBROUTINE check_wrap() + !! Gate 3: the Currents 2 table of gate 2 (c2/) against it unrolled (c2u/) and held (c2h/). + LOGICAL :: ok + REAL(wp) :: e_unrolled, e_held, e_early + CHARACTER(32) :: na(MAXCOL), nb(MAXCOL) + REAL(wp), ALLOCATABLE :: va(:, :), vb(:, :) + INTEGER :: ra, rb, c + CALL write_case('c2u/', [CHARACTER(48) :: '2 Currents']) + CALL write_c2('c2u/', 2) + CALL run_driver('c2u/mixed.dat', 'c2u/mixed', ok) + CALL require(ok, '3: the mixed deck runs with the unrolled table') + CALL write_case('c2h/', [CHARACTER(48) :: '2 Currents']) + CALL write_c2('c2h/', 3) + CALL run_driver('c2h/mixed.dat', 'c2h/mixed', ok) + CALL require(ok, '3: the mixed deck runs with the held table') + e_unrolled = outs_difference('c2/mixed', 'c2u/mixed', 1, NSTEP + 1) + ALLOCATE (va(MAXROW, MAXCOL), vb(MAXROW, MAXCOL)) + CALL read_out('c2/mixed.out', na, va, ra) + CALL read_out('c2h/mixed.out', nb, vb, rb) + e_held = 0.0_wp + e_early = HUGE(1.0_wp) + IF (ra == NSTEP + 1 .AND. rb == NSTEP + 1) THEN + c = col_of(na, 'FairTen2') + e_early = MAXVAL(ABS(vb(1:121, c) - va(1:121, c)))/(MAXVAL(va(1:ra, c)) - MINVAL(va(1:ra, c))) + e_held = MAXVAL(ABS(vb(122:rb, c) - va(122:ra, c)))/(MAXVAL(va(1:ra, c)) - MINVAL(va(1:ra, c))) + END IF + WRITE (*, '(A,ES10.3,A)') ' 3 wrap: the wrapped and the unrolled table differ by ', e_unrolled, & + ' of each channel''s range' + WRITE (*, '(A,ES10.3,A,ES10.3,A)') ' 3 wrap: the held table differs from the wrapped one by ', e_early, & + ' up to 6 s and by ', e_held, ' after it (chain tension, of its range)' + CALL require(e_unrolled <= SAME_TOL, '3: past its last sample the march takes the table repeated') + CALL require(e_early <= SAME_TOL, '3: the held table is the same field up to 6 s') + CALL require(e_held > 0.01_wp, '3: the wrap changes the march after 6 s') + END SUBROUTINE check_wrap + + SUBROUTINE check_uniform_writings() + !! Gate 4: a uniform Currents 5 grid and a uniform Currents 1 profile against OPTION uniform. + LOGICAL :: ok + REAL(wp) :: e5, e1, e5_static + CALL write_case('c5u/', [CHARACTER(48) :: '5 Currents']) + CALL write_c5('c5u/', .TRUE.) + CALL run_driver('c5u/mixed.dat', 'c5u/mixed', ok) + CALL require(ok, '4: the mixed deck runs in a uniform Currents 5 grid') + CALL write_case('c1u/', [CHARACTER(48) :: '1 Currents']) + CALL write_c1('c1u/', .TRUE.) + CALL run_driver('c1u/mixed.dat', 'c1u/mixed', ok) + CALL require(ok, '4: the mixed deck runs in a uniform Currents 1 profile') + e5 = outs_difference('uni/mixed', 'c5u/mixed', 1, NSTEP + 1) + e5_static = outs_difference('uni/mixed', 'c5u/mixed', 1, 1) + e1 = outs_difference('uni/mixed', 'c1u/mixed', 1, NSTEP + 1) + WRITE (*, '(A,ES10.3,A,ES10.3,A,ES10.3,A)') ' 4 uniform field: Currents 5 grid ', e5, ' (static start ', & + e5_static, '), Currents 1 profile ', e1, ' of each channel''s range from OPTION uniform' + ! the grid's trilinear weights and the profile's linear ones reproduce the uniform field to + ! round-off, which the march carries + CALL require(e5_static == 0.0_wp .AND. e5 <= GRID_TOL, '4: a uniform Currents 5 grid is OPTION uniform') + CALL require(e1 <= GRID_TOL, '4: a uniform Currents 1 profile is OPTION uniform') + END SUBROUTINE check_uniform_writings + + SUBROUTINE check_snapshot(deck, label) + !! Gate 5 on a mixed deck (the Newton controls of the coupled route): the correction rewind of + !! the OpenFAST shell (CD_AGG_Snapshot at the start of a step, the step, CD_AGG_Restore, the + !! step again) every 20th step of the march, against the march without rewinds. + CHARACTER(*), INTENT(IN) :: deck, label + TYPE(CD_AGG_ModuleType), ALLOCATABLE :: a, b + REAL(wp), ALLOCATABLE :: ga(:, :), gb(:, :), gp(:, :) + INTEGER, PARAMETER :: EVERY = 20 + INTEGER :: es, nch, step, n_rewind + CHARACTER(2048) :: em + LOGICAL :: ok + REAL(wp) :: e_pre, e_post + ALLOCATE (a, b) + CALL init_mixed(a, deck, label//' uninterrupted', ok) + IF (.NOT. ok) RETURN + nch = CD_AGG_NumChannels(a) + ALLOCATE (ga(NSTEP + 1, nch), gb(NSTEP + 1, nch), gp(NSTEP + 1, nch)) + ga = 0.0_wp + gb = 0.0_wp + gp = 0.0_wp + CALL march(a, 0, NSTEP, ga, label//' uninterrupted', ok) + CALL CD_AGG_End(a, es, em) + IF (.NOT. ok) RETURN + CALL init_mixed(b, deck, label//' rewound', ok) + IF (.NOT. ok) RETURN + CALL march(b, 0, 0, gb, label//' rewound', ok) + n_rewind = 0 + DO step = 1, NSTEP + IF (MOD(step, EVERY) == 0) THEN + CALL CD_AGG_Snapshot(b, es, em) + CALL require(es == CD_AGG_OK, label//': snapshot: '//TRIM(em)) + CALL march(b, step - 1, step, gp, label//' before the rewind', ok) + IF (.NOT. ok) EXIT + CALL CD_AGG_Restore(b, es, em) + CALL require(es == CD_AGG_OK, label//': restore: '//TRIM(em)) + n_rewind = n_rewind + 1 + END IF + CALL march(b, step - 1, step, gb, label//' rewound', ok) + IF (.NOT. ok) EXIT + END DO + CALL CD_AGG_End(b, es, em) + IF (.NOT. ok) RETURN + e_pre = 0.0_wp + DO step = EVERY, NSTEP, EVERY + e_pre = MAX(e_pre, MAXVAL(ABS(gp(step + 1, :) - ga(step + 1, :)))) + END DO + e_post = MAXVAL(ABS(gb - ga)) + WRITE (*, '(A,I0,A,ES10.3,A,ES10.3)') ' '//label//': ', n_rewind, ' rewinds; largest difference from the '// & + 'march without them: the rewound steps ', e_pre, ', the march after them ', e_post + CALL require(n_rewind == NSTEP/EVERY .AND. e_pre == 0.0_wp .AND. e_post == 0.0_wp, & + label//': a step repeated after a restore is the uninterrupted march, bit for bit') + END SUBROUTINE check_snapshot + + SUBROUTINE check_refusals() + !! Gate 6. + INTEGER :: ex + LOGICAL :: named + CALL write_case('wav/', [CHARACTER(48) :: 'airy 2 8 0 waves']) + ex = driver_exit('wav/mixed.dat', 'wav/mixed') + named = log_has('wav/mixed', 'the deck waves OPTION is not supported for a standalone mixed') + CALL require(ex == 1 .AND. named, & + '6: deck waves on the mixed deck are refused by name') + CALL write_case('c2d/', [CHARACTER(48) :: '2 Currents', 'uniform 0.4 0.3 0 current']) + CALL write_c2('c2d/', 1) + ex = driver_exit('c2d/mixed.dat', 'c2d/mixed') + named = log_has('c2d/mixed', 'double-counting') + CALL require(ex == 1 .AND. named, & + '6: a current OPTION beside Currents 2 is refused as double counting') + CALL write_deck('nodt_mixed.dat', [CHARACTER(64) :: CAB_T, CHAIN_T], & + [CHARACTER(40) :: '1 Coupled 0.0 0.0 -50.0 0 0 0 0', '2 Fixed 95.0 0.0 -60.0 0 0 0 0', & + '3 Coupled 0.0 20.0 -50.0 0 0 0 0', '4 Fixed 0.0 110.0 -100.0 0 0 0 0'], & + [CHARACTER(16) :: '1 1 2 -', '2 3 4 -'], [CHARACTER(24) :: '1 cab 100.0 40', '2 chain 110.0 20'], & + [CHARACTER(48) :: 'uniform 0.4 0.3 0 current'], MIXED_OUTS) + ex = driver_exit('nodt_mixed.dat', 'nodt_mixed') + named = log_has('nodt_mixed', 'standalone OPTION current requires dtM and TMax') + CALL require(ex == 1 .AND. named, & + '6: a current without dtM is refused as on the single-line routes') + END SUBROUTINE check_refusals + +END PROGRAM test_mixed_route_currents diff --git a/tests/test_step_allocations.f90 b/tests/test_step_allocations.f90 index c20dade2..f101c1eb 100644 --- a/tests/test_step_allocations.f90 +++ b/tests/test_step_allocations.f90 @@ -36,8 +36,13 @@ PROGRAM test_step_allocations !! CD_AGG_Step_Moving with the roll column or with the vessel orientation and rates): a straight !! line restrained in torsion whose End A rolls about its axis, beside an EI = 0 chain. !! + !! With "mixed_current" the same march of a mixed deck takes the deck's own current + !! (deck_current): a MoorDyn-C Currents 5 grid that varies in space and time, sampled at every + !! node of the chain and of the finite-EI cable before each step, past its last sample too. + !! !! Usage: test_step_allocations [ranges] - !! test_step_allocations torsion | nodal | free | current_grid | motion_roll | motion_vessel + !! test_step_allocations torsion | nodal | free | current_grid | motion_roll | motion_vessel | + !! mixed_current USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT, C_LONG_LONG USE CableDyn_Precision, ONLY: wp USE CableDyn_EndConnection, ONLY: CD_ENDCONN_RIGID @@ -88,9 +93,11 @@ END SUBROUTINE cd_test_allocation_counting CALL current_grid_gate() CASE ('motion_roll', 'motion_vessel') CALL motion_gate(TRIM(arg) == 'motion_vessel') + CASE ('mixed_current') + CALL mixed_current_gate() CASE DEFAULT - ERROR STOP 'a single argument must be "torsion", "nodal", "free", "current_grid", "motion_roll" or '// & - '"motion_vessel"' + ERROR STOP 'a single argument must be "torsion", "nodal", "free", "current_grid", "motion_roll", '// & + '"motion_vessel" or "mixed_current"' END SELECT STOP END IF @@ -468,6 +475,124 @@ SUBROUTINE motion_gate(vessel) PRINT '(A)', 'PASS: no heap allocation in the prescribed-motion march of a mixed deck after warm-up' END SUBROUTINE motion_gate + SUBROUTINE mixed_current_gate() + !! Zero heap allocation in the standalone driver's per-step march of a mixed deck in its own + !! current: a sagging finite-EI line beside a chain, both fairleads surging (motionFile), in + !! a Currents 5 grid (x, y, z, t) whose last sample (6 s) the 10 s march passes. + INTEGER, PARAMETER :: N_WARM = 40, N_COUNT = 160, NT = N_WARM + N_COUNT + REAL(wp), PARAMETER :: DTM = 0.05_wp, PI = 3.14159265358979323846_wp + REAL(wp), PARAMETER :: XS(2) = [-10.0_wp, 110.0_wp], YS(2) = [-10.0_wp, 120.0_wp], & + ZS(3) = [-210.0_wp, -100.0_wp, 0.0_wp], TS(3) = [0.0_wp, 3.0_wp, 6.0_wp] + CHARACTER(*), PARAMETER :: DIR = 'step_alloc_mixed_current/' + TYPE(CD_AGG_ModuleType), ALLOCATABLE :: mag + REAL(wp), ALLOCATABLE :: p(:, :), v(:, :), a(:, :), ld(:, :), o(:, :, :), w(:, :), al(:, :), roll(:) + REAL(wp) :: t, x, vx, ax, om + INTEGER :: u, k, n, n_it, ix, iy, iz, it + INTEGER(C_LONG_LONG) :: c0, n_alloc + LOGICAL :: turns, rolls, converged, stalled + om = 2.0_wp*PI/10.0_wp + OPEN (NEWUNIT=u, FILE=DIR//'motion.txt', STATUS='REPLACE', ACTION='WRITE') + DO k = 0, NT + t = DTM*k + x = 0.5_wp*(1.0_wp - COS(om*t)) + vx = 0.5_wp*om*SIN(om*t) + ax = 0.5_wp*om*om*COS(om*t) + WRITE (u, '(F8.3,A,ES25.16E3,A,ES25.16E3,A,ES25.16E3,A)') t, ' 1 ', x, ' 0 -50 ', vx, ' 0 0 ', ax, ' 0 0' + WRITE (u, '(F8.3,A,ES25.16E3,A,ES25.16E3,A,ES25.16E3,A)') t, ' 3 ', x, ' 20 -50 ', vx, ' 0 0 ', ax, ' 0 0' + END DO + CLOSE (u) + OPEN (NEWUNIT=u, FILE=DIR//'current_profile_4d.txt', STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') '2 2 3 3' + WRITE (u, '(A)') '-10.0 110.0' + WRITE (u, '(A)') '-10.0 120.0' + WRITE (u, '(A)') '-210.0 -100.0 0.0' + WRITE (u, '(A)') '0.0 3.0 6.0' + WRITE (u, '(A)') 'x y z t ux uy uz' + DO it = 1, 3 + DO iz = 1, 3 + DO iy = 1, 2 + DO ix = 1, 2 + WRITE (u, '(4F10.3,3F12.6)') XS(ix), YS(iy), ZS(iz), TS(it), & + (1.0_wp + ZS(iz)/250.0_wp)*(0.3_wp + 0.002_wp*XS(ix) + 0.1_wp*(it - 1)), & + (1.0_wp + ZS(iz)/250.0_wp)*(0.2_wp - 0.001_wp*YS(iy)), 0.0_wp + END DO + END DO + END DO + END DO + CLOSE (u) + OPEN (NEWUNIT=u, FILE=DIR//'deck.dat', STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'step allocation gate: mixed deck in its own current' + WRITE (u, '(A)') '--- LINE TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass EA BA EI Cdn Cdt Can Cat' + WRITE (u, '(A)') '(-) (m) (kg/m) (N) (-) (Nm2) (-) (-) (-) (-)' + WRITE (u, '(A)') 'cab 0.2 60.0 4.0e8 0.0 1.0e4 1.2 0.1 1.0 0.0' + WRITE (u, '(A)') 'chain 0.1 50.0 1.0e9 -1.0 0.0 1.37 0.64 1.0 0.0' + WRITE (u, '(A)') '--- POINTS ---' + WRITE (u, '(A)') 'ID Type X Y Z Mass Vol CdA Ca' + WRITE (u, '(A)') '(-) (-) (m) (m) (m) (kg) (m3) (m2) (-)' + WRITE (u, '(A)') '1 Coupled 0.0 0.0 -50.0 0 0 0 0' + WRITE (u, '(A)') '2 Fixed 95.0 0.0 -60.0 0 0 0 0' + WRITE (u, '(A)') '3 Coupled 0.0 20.0 -50.0 0 0 0 0' + WRITE (u, '(A)') '4 Fixed 0.0 110.0 -100.0 0 0 0 0' + WRITE (u, '(A)') '--- LINES ---' + WRITE (u, '(A)') 'ID NodeA NodeB Outputs' + WRITE (u, '(A)') '(-) (-) (-) (-)' + WRITE (u, '(A)') '1 1 2 -' + WRITE (u, '(A)') '2 3 4 -' + WRITE (u, '(A)') '--- SECTIONS ---' + WRITE (u, '(A)') 'LineID LineType Length NumSegs' + WRITE (u, '(A)') '(-) (-) (m) (-)' + WRITE (u, '(A)') '1 cab 100.0 40' + WRITE (u, '(A)') '2 chain 110.0 20' + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '200.0 WtrDpth' + WRITE (u, '(A)') '0.05 dtM' + WRITE (u, '(A)') '10.0 TMax' + WRITE (u, '(A)') '5 Currents' + WRITE (u, '(A)') 'motion.txt motionFile' + WRITE (u, '(A)') '--- OUTPUTS ---' + WRITE (u, '(A)') 'FairTen1' + WRITE (u, '(A)') '--- END ---' + CLOSE (u) + ALLOCATE (mag) + CALL CD_AGG_Init_From_Deck(mag, DIR//'deck.dat', DTM, es, em, forbid_deck_ambient=.TRUE., & + run_tmax=10.0_wp, host_orientation=.TRUE., prescribed_motion=.TRUE., & + deck_current=.TRUE.) + CALL check('current deck initialization') + n = CD_AGG_NMovingPoints(mag, es, em) + CALL check('current moving-point count') + ALLOCATE (p(3, n), v(3, n), a(3, n), ld(3, n), o(3, 3, n), w(3, n), al(3, n), roll(n)) + CALL CD_AGG_GetMovingPointMesh(mag, p, v, a, ld, es, em) + CALL check('current initial mesh') + CALL CD_AGG_MotionKinematics(mag, 1, p, v, a, o, w, al, roll, turns, rolls, es, em) + CALL check('current row 1') + CALL CD_AGG_UpdateStates_Moving(mag, p, v, a, es, em) + CALL check('current row 1 transfer') + CALL CD_AGG_Refresh_Accelerations(mag, es, em) + CALL check('current row 1 accelerations') + n_alloc = 0 + DO k = 1, NT + c0 = cd_test_allocation_count() + IF (k > N_WARM) CALL cd_test_allocation_counting(1_C_INT) + CALL CD_AGG_MotionKinematics(mag, k + 1, p, v, a, o, w, al, roll, turns, rolls, es, em) + IF (es == 0) CALL CD_AGG_Step_Moving(mag, DTM, p, v, a, converged, stalled, n_it, es, em, t_committed=DTM*k) + CALL cd_test_allocation_counting(0_C_INT) + CALL check('current step') + IF (.NOT. converged .OR. stalled) ERROR STOP 'current step did not converge' + n_alloc = n_alloc + (cd_test_allocation_count() - c0) + END DO + CALL CD_AGG_End(mag, es, em) + PRINT '(A,I0,A,I0,A)', 'mixed deck in a Currents 5 grid: ', N_COUNT, ' counted steps, ', n_alloc, & + ' heap allocations in the steps' + IF (n_alloc /= 0) THEN + PRINT '(A)', 'FAIL: the march of a mixed deck in its own current allocated after warm-up' + ERROR STOP 1 + END IF + PRINT '(A)', 'PASS: no heap allocation in the march of a mixed deck in its own current after warm-up' + END SUBROUTINE mixed_current_gate + SUBROUTINE check(stage) CHARACTER(*), INTENT(IN) :: stage