From 35b0c8f16201ff346c0da530a3fc0d27c6603948 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Wed, 2 Dec 2026 15:31:17 +0900 Subject: [PATCH 1/3] fix: stop a coupled run whose SeaState grid misses its line nodes In OpenFAST, the line nodes take their wave and current kinematics from the SeaState grid. A node outside the grid gets the kinematics of the nearest boundary point, out of phase beyond a half-width and too strong below Z_Depth, and CableDyn only warned once and ran on. A grid with NX = 2 or NY = 2 (three points across that axis) under waves that vary along the axis passed silently, although SeaState then interpolates across a large part of a wavelength: under waves along y, a grid with NY = 2 and a half-width near half a wavelength gives the lines between its points nearly the kinematics of y = 0. Both now stop the run by default. The coverage check runs at the static start and at every CableDyn step, and its message gives the time and, line by line, the number of nodes outside with the deepest and the shallowest of them. The resolution check runs at the start: it reads the directions of SeaState's wave components (the spread of WaveDirMod 1, the component directions of WaveMod 7, WaveDir for WaveMod 6), takes a direction as along an axis within 1e-4 deg, and stops when line nodes in the water lie between the grid points across a coarse axis. NY = 2 under waves along x and NX = 2 under waves along y still run. OPTIONS waveGridCheck warn turns both into warnings; error is the default. The rules live in a new core module, CableDyn_WaveGrid, tested without OpenFAST (test_wave_grid, which also checks that the option reaches the coupled aggregate). The coupled cases, which stop by default and run with warn, and the bit-identity of runs that pass, are checked by validation/scripts/openfast_wave_grid_guard.py against an OpenFAST build. The release smoke case on the platform-only MD_Shared grid sets waveGridCheck warn and requires the warning. The grid check now uses a workspace sized at initialisation instead of allocating every step. Runs that pass the checks give the same results, bit for bit. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 16 + CMakeLists.txt | 11 + DEVELOPMENT.md | 7 + doc/openfast.rst | 59 ++- doc/options.rst | 11 + doc/troubleshooting.rst | 28 +- doc/tutorial_openfast.rst | 13 +- examples/cabledyn_options_reference.dat | 1 + examples/openfast/README.md | 3 +- python/cabledyn/deck_file.py | 4 + python/tests/test_deck_file.py | 4 + release/build_static_windows.ps1 | 16 + src/CableDyn_DeckDriver.f90 | 16 + src/CableDyn_OpenFAST_Aggregate.f90 | 6 + src/CableDyn_WaveGrid.f90 | 94 +++++ src/openfast/CableDyn_OF.f90 | 381 +++++++++++++++--- tests/test_wave_grid.f90 | 176 ++++++++ .../scripts/openfast_wave_grid_guard.py | 224 ++++++++++ 18 files changed, 990 insertions(+), 80 deletions(-) create mode 100644 src/CableDyn_WaveGrid.f90 create mode 100644 tests/test_wave_grid.f90 create mode 100644 validation/scripts/openfast_wave_grid_guard.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 43950899..8f8131ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,22 @@ All notable changes to CableDyn are recorded in this file. The format follows ## [Unreleased] +### Changed + +- In OpenFAST, a coupled run whose lines take their wave or current kinematics from the SeaState grid now + stops when the grid cannot give them those kinematics, where it warned once and ran on. It stops at the + static start or at the first CableDyn step at which a line node in the water lies outside the grid, + where SeaState gives it the kinematics of the grid boundary; the message gives the time and, line by + line, the number of such nodes and the deepest and shallowest of them. It also stops at the start when + the grid has `NX = 2` or `NY = 2` (three points across that axis) under waves that vary along the axis + (a long-crested sea not along the other axis, within 1e-4 deg, or a short-crested sea) and line nodes in + the water lie between the grid points, where SeaState interpolates across a large part of a wavelength. + A grid with `NY = 2` under waves along x, or `NX = 2` under waves along y, still runs. The new + `OPTIONS waveGridCheck warn` turns both checks into the former warnings (`error`, the default, stops). + The r-test `MD_Shared` SeaState file of the OpenFAST tutorial, which covers only the platform, now stops + until its grid is enlarged as the tutorial describes. Runs that pass the checks give the same results, + bit for bit. + ### Fixed - A Syrope rope at its running maximum had a band of slow strains, up to 9e-7 wide on the shipped table, diff --git a/CMakeLists.txt b/CMakeLists.txt index ddbfa291..998a1eca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -419,6 +419,7 @@ add_library(cabledyn_obj OBJECT src/CableDyn_FatalReport.f90 src/CableDyn_Profile.f90 src/CableDyn_LoadPredictor.f90 + src/CableDyn_WaveGrid.f90 src/CableDyn_PathIO.f90 src/CableDyn_Banner.f90 src/CableDyn_Linalg.f90 @@ -1294,6 +1295,16 @@ target_link_libraries(test_load_predictor PRIVATE cabledyn_core) add_test(NAME load_predictor COMMAND test_load_predictor) set_tests_properties(load_predictor PROPERTIES LABELS "fortran;unit;openfast") +# The rules of the coupled wave-grid guard (OPTION waveGridCheck): which wave directions a +# SeaState grid with NX or NY = 2 represents, and which nodes lie between its points; the option +# reaches the coupled aggregate from the mixed example deck. +add_executable(test_wave_grid tests/test_wave_grid.f90) +target_link_libraries(test_wave_grid PRIVATE cabledyn_core) +file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/wave_grid) +add_test(NAME wave_grid COMMAND test_wave_grid ${CMAKE_SOURCE_DIR}/examples/iea15mw_umaine_mixed_cabledyn.dat + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/wave_grid) +set_tests_properties(wave_grid PROPERTIES LABELS "fortran;unit;openfast") + # The same deck initialises without a static compression/mesh note: the touchdown # contact kink is element-local, the smoothed element-mean axial force is tensile. add_executable(test_flagship_compression_note tests/test_flagship_compression_note.f90) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 6cc9d3d4..efceefae 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -258,6 +258,13 @@ stack overflow while ElastoDyn initialises. checks that the CableDyn banner appears in the log, that the executable names itself `OpenFAST--CableDyn-`, and that the output is finite. +The SeaState wave-grid checks of the OpenFAST module (`OPTIONS waveGridCheck`) run only inside +OpenFAST. `validation/scripts/openfast_wave_grid_guard.py --exe --case-dir +--work ` runs the IEA-15 MW model of the OpenFAST tutorial (the r-test `MD_Shared` turbine-1 +files in ``) under grids that must stop the run by default and run with `waveGridCheck warn`, +and under grids that must run; with `--base-exe` (an `openfast.exe` built from the previous CableDyn +sources) it also requires the same output as that build where the run passes. + An `openfast.exe` built this way through CMake does not embed the UTF-8 active-code-page manifest (`app/utf8_code_page.manifest`), so on Windows it may not open input files in folders whose names the system code page cannot spell. The diff --git a/doc/openfast.rst b/doc/openfast.rst index 780e37cd..cc2a4483 100644 --- a/doc/openfast.rst +++ b/doc/openfast.rst @@ -161,7 +161,9 @@ only the platform. The r-test ``MD_Shared`` file used in :doc:`tutorial_openfast grid; and * ``NX``, ``NY`` and ``NZ`` raised with the extents to keep the grid spacing: a horizontal spacing of about a tenth of the peak wavelength or less. A long-crested sea (``WaveDirMod = - 0``) that travels along x does not vary in y, so ``NY = 2`` is enough for it. + 0``) that travels along x (``WaveDir`` 0° or 180°) does not vary in y, so ``NY = 2`` is enough + for it, and ``NX = 2`` for one along y (90° or 270°). Any other sea, a long-crested one at + another heading or a short-crested one, varies along both axes and needs both resolved. SeaState holds the whole time history of the grid in memory, so memory and initialisation time grow with (2 ``NX`` − 1)(2 ``NY`` − 1) ``NZ`` ``WaveTMax`` / ``WaveDT``. For the @@ -172,18 +174,55 @@ or using ``NZ = 16`` changes the 10–70 s platform and fairlead-tension statist 0.1 %. The ``MD_Shared`` grid gives a line-1 fairlead tension standard deviation 18 % too high (0.136 MN instead of 0.115 MN). -CableDyn compares its nodes with the grid at the static equilibrium and at every CableDyn step. -At the first node found outside it prints one warning and continues: +CableDyn compares its nodes with the grid at the static equilibrium and at every CableDyn step, +and by default (``OPTIONS waveGridCheck error``) stops the run at the first step that finds a +node outside it, at initialisation for the ``MD_Shared`` grid: .. code-block:: text - WARNING: CableDyn mooring module: 147 of the 153 CableDyn sampling nodes in the water lie - outside the SeaState wave-kinematics grid at t = 0 s (warned once). SeaState clamps them to - the grid boundary, so their fluid kinematics and loads are not physical. Farthest: x = -837.6 - m (grid |x| <= X_HalfWidth = 100 m); y = 725.38 m (grid |y| <= Y_HalfWidth = 100 m); z = - -200.01 m (grid z >= -Z_Depth = -40 m). In the SeaState input file enlarge X_HalfWidth, - Y_HalfWidth and Z_Depth (Z_Depth at most WtrDpth + MSL2SWL, its default) to cover the lines - with margin for their motion, and raise NX, NY and NZ to keep the grid spacing. + CableDyn mooring module: 147 of the 153 CableDyn sampling nodes in the water lie outside the + SeaState wave-kinematics grid at t = 0 s, where SeaState would give them the kinematics of the + grid boundary, which are not physical there. By line: line 1, 49 nodes, deepest at (x, y, z) = + (-735.56, 0, -200.01) m, shallowest at (x, y, z) = (-77.518, 0, -41.866) m; line 2, 49 nodes, + deepest at (x, y, z) = (367.78, 637.01, -200.01) m, shallowest at (x, y, z) = (38.759, 67.132, + -41.866) m; line 3, ... . Farthest: x = -837.6 m (grid |x| <= X_HalfWidth = 100 m); y = 725.38 + m (grid |y| <= Y_HalfWidth = 100 m); z = -200.01 m (grid z >= -Z_Depth = -40 m). In the SeaState + input file enlarge X_HalfWidth, Y_HalfWidth and Z_Depth (Z_Depth at most WtrDpth + MSL2SWL, its + default) to cover the lines with margin for their motion, and raise NX, NY and NZ to keep the + grid spacing. To run on with those kinematics, set waveGridCheck warn in the OPTIONS of the + CableDyn deck. + +The message gives the time and, line by line, the number of nodes outside the grid with the +deepest and the shallowest of them. A node that leaves the grid during the run, as a line swings +out with the platform, stops the run at that step. With ``waveGridCheck warn`` the message is a +warning, given once per run (also after a restart), and the run continues with the boundary +kinematics at those nodes. + +At initialisation CableDyn also checks the grid against the directions of the sea. A grid with +``NX = 2`` or ``NY = 2`` has three points along that axis, ``X_HalfWidth`` (or ``Y_HalfWidth``) +apart, and SeaState interpolates the kinematics across the axis between them. That is exact only +for waves that do not vary along the axis: ``NY = 2`` for a long-crested sea along x and +``NX = 2`` for one along y, each within 1e-4°. Under any other sea, with line nodes in the water +between the grid points across that axis, the run stops by default: + +.. code-block:: text + + CableDyn mooring module: the SeaState wave-kinematics grid has NY = 2 (3 points 900 m apart in y) + under long-crested waves at 30 deg, which vary along that axis: SeaState interpolates them + between the three grid points, over distances that are a large part of a wavelength or more, + and 102 of the 153 CableDyn sampling nodes in the water lie between grid points there. By line: + line 2, 51 nodes, deepest at (x, y, z) = (367.78, 637.01, -200.01) m, shallowest at (x, y, z) = + (29, 50.229, -14) m; line 3, ... . A grid with NY = 2 represents only waves along x (0 or 180 deg) + and one with NX = 2 only waves along y (90 or 270 deg), within 1e-4 deg; in the SeaState input + file raise the count so that the spacing resolves the shortest wavelength that matters at the + lines (a tenth of it or finer). To run on with the interpolated kinematics, set waveGridCheck + warn in the OPTIONS of the CableDyn deck. + + +The directions are those of SeaState's wave components (the spread of ``WaveDirMod = 1``, the +component directions of ``WaveMod = 7``), or ``WaveDir`` for ``WaveMod = 6``; a node on a grid +line across the coarse axis, such as a line at ``y = 0``, takes the grid values there exactly and +is not counted. ``waveGridCheck warn`` turns this check into a warning too. Only nodes in the water are checked: a node above the free surface carries no fluid load, whatever kinematics SeaState would give it, so a suspended cable or jumper above the water may diff --git a/doc/options.rst b/doc/options.rst index 915adc9f..e0c4e645 100644 --- a/doc/options.rst +++ b/doc/options.rst @@ -573,6 +573,17 @@ Finite-EI cable controls (see :doc:`openfast`) - OpenFAST - ``False predictLoads`` + * - ``waveGridCheck`` / ``wave_grid_check`` + - mode + - ``error`` + - ``error`` or ``warn`` (case-insensitive). The checks of the SeaState grid the lines take their + wave and current kinematics from: a line node in the water outside the grid (at the static + start or at any CableDyn step), and ``NX = 2`` or ``NY = 2`` under waves that vary along that + axis with line nodes in the water between the grid points (at the start). ``error`` stops the + run with a message that gives the time and, by line, the nodes concerned; ``warn`` warns once + and runs on with SeaState's kinematics there (see :ref:`openfast:SeaState grid`) + - OpenFAST (a run that samples SeaState); accepted and unused elsewhere + - ``warn waveGridCheck`` * - ``CDOutDt`` / ``cd_out_dt`` - real, s - ``0`` diff --git a/doc/troubleshooting.rst b/doc/troubleshooting.rst index 7fc78a5a..4fa695e9 100644 --- a/doc/troubleshooting.rst +++ b/doc/troubleshooting.rst @@ -698,17 +698,27 @@ Warnings and notes that do not stop a run line takes up by its shape; the torque follows from it. A non-zero descent count means the straight or untwisted branch was unstable at the imposed twist and the solve moved to a buckled shape; check the shape and the ``Twist`` channel. - * - ``WARNING: CableDyn mooring module: of the CableDyn sampling nodes in the water - lie outside the SeaState wave-kinematics grid at t = ... s (warned once)`` (OpenFAST) + * - ``CableDyn mooring module: of the CableDyn sampling nodes in the water lie outside + the SeaState wave-kinematics grid at t = ... s`` (OpenFAST; an error, or with + ``waveGridCheck warn`` a warning given once) - the SeaState grid (``X_HalfWidth``, ``Y_HalfWidth``, ``Z_Depth``) does not cover the lines in the water (nodes above the free surface carry no fluid load and are not - counted), and SeaState gives the nodes outside it the kinematics of the grid boundary: waves - out of phase beyond a half-width, kinematics that are too strong below ``Z_Depth``. The - message names the farthest node in each direction. Enlarge the listed inputs in the - SeaState file past the farthest anchor (``Z_Depth`` to the water depth, its default) and - raise ``NX``, ``NY``, ``NZ`` to keep the spacing. A SeaState file written for the - platform alone, such as the r-test ``MD_Shared`` file, triggers it. See - :ref:`openfast:SeaState grid` for sizes and memory. + counted), and SeaState would give the nodes outside it the kinematics of the grid boundary: + waves out of phase beyond a half-width, kinematics that are too strong below ``Z_Depth``. + The message lists the nodes outside by line, with the deepest and shallowest of them, and + the farthest node in each direction. Enlarge the listed inputs in the SeaState file past + the farthest anchor (``Z_Depth`` to the water depth, its default) and raise ``NX``, ``NY``, + ``NZ`` to keep the spacing. A SeaState file written for the platform alone, such as the + r-test ``MD_Shared`` file, triggers it. ``OPTIONS waveGridCheck warn`` runs on with the + boundary kinematics. See :ref:`openfast:SeaState grid` for sizes and memory. + * - ``CableDyn mooring module: the SeaState wave-kinematics grid has NY = 2 (3 points ... m apart + in y) under ...`` (OpenFAST; an error, or with ``waveGridCheck warn`` a warning) + - the grid has three points across an axis along which the waves vary: ``NY = 2`` under a + sea not along x, or ``NX = 2`` under a sea not along y (a long-crested sea at another + heading, or a short-crested sea), and line nodes in the water lie between the grid points, + where SeaState interpolates across a large part of a wavelength. Raise ``NY`` (or ``NX``) so + that the spacing resolves the shortest wavelength that matters at the lines. See + :ref:`openfast:SeaState grid`. * - ``Note: LINE is stretched to a static strain of ... % at the fairlead`` - the fairlead tension over the EA of the End A section exceeds ``maxStrain`` (when the OPTION is given and positive) or 10 % (when it is not given or is ``0``, which disables diff --git a/doc/tutorial_openfast.rst b/doc/tutorial_openfast.rst index 726b26fa..c3c2b71d 100644 --- a/doc/tutorial_openfast.rst +++ b/doc/tutorial_openfast.rst @@ -119,10 +119,11 @@ outside the grid the kinematics of the grid boundary. Enlarge the grid to cover This sets ``X_HalfWidth`` and ``Y_HalfWidth`` to 900 m, ``Z_Depth`` to the water depth, 37 grid points along each half of x (25 m spacing) and 11 in depth. ``NY`` stays 2 because the long-crested sea travels along x and does not vary in y. SeaState then needs about 4.6 GB of -memory and several seconds to generate the grid. Without this step the run still completes, but -CableDyn warns that 147 of its 153 line nodes lie outside the SeaState wave-kinematics grid, and -the line-1 fairlead tension standard deviation comes out 18 % too high. Grid sizing is -described in :ref:`openfast:SeaState grid`. +memory and several seconds to generate the grid. Without this step CableDyn stops at +initialisation: 147 of its 153 line nodes lie outside the SeaState wave-kinematics grid. With +``waveGridCheck warn`` in the deck's OPTIONS it runs on with the boundary kinematics, and the +line-1 fairlead tension standard deviation comes out 18 % too high. Grid sizing is described in +:ref:`openfast:SeaState grid`. 4. How CableDyn is wired in --------------------------- @@ -201,8 +202,8 @@ Check, in order: #. ``Running CableDyn (`` — the CableDyn-enabled executable is in use. A stock OpenFAST rejects ``CompMooring = 5`` during input validation. -#. The line inventory (3 lines, 6 points) and ``dtM``, and no ``WARNING: CableDyn mooring module: - ... lie outside the SeaState wave-kinematics grid`` line (step 3). +#. The line inventory (3 lines, 6 points) and ``dtM``. A SeaState grid that does not cover the + lines stops the run at initialisation (step 3). #. The initial fairlead tensions: 2.437 MN per line, with the line tangent 55.7° below horizontal, as in the standalone ``spread_3line_chain.dat`` of :doc:`tutorial_spread`. The tension is the magnitude of the line-end force, which includes the fairlead node's share of diff --git a/examples/cabledyn_options_reference.dat b/examples/cabledyn_options_reference.dat index b8038759..17d14a0a 100644 --- a/examples/cabledyn_options_reference.dat +++ b/examples/cabledyn_options_reference.dat @@ -98,6 +98,7 @@ none waves - Wave model and parameters (m, s, deg) {none; airy; -- 0 WriteLog - MoorDyn logging compatibility only; accepted and ignored -- 0.1 dtOut - MoorDyn output-cadence compatibility only; accepted and ignored -- 0.1 CDOutDt - OpenFAST/FAST.Farm: .CD.out row interval, a whole multiple of the CableDyn step [default: 0 = every step] +-- warn waveGridCheck - OpenFAST: a SeaState grid that misses or under-resolves the line nodes {error=stop; warn} [default: error] -- 0 Currents - MoorDyn-C current mode {0=none; 1=current_profile.txt} [default: 0] -- 0.25 dtWave - MoorDyn-C WaveKin 3 resampling step (s) [default: 0.25] -- 3.14159 WvHiCOff - High cut-off of an elevation record, WaveKinMod 1 or WaveKin 3 (rad/s) {value; none} [default: 3.14159] diff --git a/examples/openfast/README.md b/examples/openfast/README.md index 7dac9f6d..1590671a 100644 --- a/examples/openfast/README.md +++ b/examples/openfast/README.md @@ -49,7 +49,8 @@ The initial CableDyn fairlead tensions are then the ~2.4 MN chain pretension. The `MD_Shared` `SeaState.dat` computes the wave kinematics on a grid that covers only the platform (`X_HalfWidth = Y_HalfWidth = 100 m`, `Z_Depth = 40 m`), while the anchors lie 838 m away on the 200 m seabed. SeaState gives every line node outside the grid the kinematics of the -grid boundary, and CableDyn warns about it. Enlarge the grid: +grid boundary, and CableDyn stops at initialisation (`OPTIONS waveGridCheck warn` runs on with +a warning instead). Enlarge the grid: ```powershell $ss = 'SeaState.dat' diff --git a/python/cabledyn/deck_file.py b/python/cabledyn/deck_file.py index 14be1592..d3446bb9 100644 --- a/python/cabledyn/deck_file.py +++ b/python/cabledyn/deck_file.py @@ -262,6 +262,8 @@ "cd_out_dt": "cd_out_dt", "vivphaseseed": "viv_phase_seed", "viv_phase_seed": "viv_phase_seed", + "wavegridcheck": "wave_grid_check", + "wave_grid_check": "wave_grid_check", "rangestart": "range_start", "range_start": "range_start", "waveseed": "wave_seed", @@ -1414,6 +1416,8 @@ def _scalar_option_value_error(keyword: str, value: str) -> str | None: ) if key == "viv_phase_seed": return None if value.lower() in {"spread", "zero"} else "must be spread or zero" + if key == "wave_grid_check": + return None if value.lower() in {"error", "warn"} else "must be error or warn" if key == "cable_statics": return ( None diff --git a/python/tests/test_deck_file.py b/python/tests/test_deck_file.py index 10493675..b1c8a74d 100644 --- a/python/tests/test_deck_file.py +++ b/python/tests/test_deck_file.py @@ -674,6 +674,8 @@ def test_unknown_scalar_option_keyword_fails_closed(tmp_path): ("relaxed", "cable_statics", "continuation or sequenced"), ("random", "VIVphaseSeed", "spread or zero"), ("0", "viv_phase_seed", "spread or zero"), + ("strict", "waveGridCheck", "error or warn"), + ("1", "wave_grid_check", "error or warn"), ("nodal", "OutputRecovery", "equilibrium or element"), ("mode2", "axialDampingRatio", "segment or mode1"), ("element", "axial_damping_ratio", "segment or mode1"), @@ -762,6 +764,8 @@ def test_zero_e_exponent_waterkin_mode_is_accepted(tmp_path): "sequenced cableStatics", "spread VIVphaseSeed", "ZERO viv_phase_seed", + "warn waveGridCheck", + "ERROR wave_grid_check", "equilibrium OutputRecovery", "element output_recovery", "segment axialDampingRatio", diff --git a/release/build_static_windows.ps1 b/release/build_static_windows.ps1 index a9fa02d1..12807d28 100644 --- a/release/build_static_windows.ps1 +++ b/release/build_static_windows.ps1 @@ -419,6 +419,19 @@ try { Copy-Item -LiteralPath (Join-Path $CableDynRoot 'examples\openfast\IEA-15-UMaine_CompMooring5_CableDyn.fst') ` -Destination $fst Copy-Item -LiteralPath (Join-Path $CableDynRoot 'examples\openfast\CableDyn_UMaine.dat') -Destination $smokeDir + # The MD_Shared SeaState grid covers the platform only, so the wave-grid check would stop the + # run at initialisation. This 1 s smoke case checks the executable, not the line loads: it keeps + # the light grid and turns the check into its warning (OPTIONS waveGridCheck warn), which the + # log must then show. + $smokeDeck = Join-Path $smokeDir 'CableDyn_UMaine.dat' + $deckLines = Get-Content -LiteralPath $smokeDeck + $dtmHits = @($deckLines | Where-Object { $_ -match '^\s*\S+\s+dtM\b' }).Count + if ($dtmHits -ne 1) { throw "expected one dtM row in the smoke deck CableDyn_UMaine.dat; found $dtmHits" } + $deckLines = foreach ($line in $deckLines) { + $line + if ($line -match '^\s*\S+\s+dtM\b') { 'warn waveGridCheck - smoke case on the platform-only MD_Shared grid' } + } + $deckLines | Set-Content -LiteralPath $smokeDeck -Encoding ascii $fstLines = Get-Content -LiteralPath $fst $replaced = 0 $fstLines = foreach ($line in $fstLines) { @@ -437,6 +450,9 @@ try { $runLog = $run.Text Write-Host $runLog if ($run.ExitCode -ne 0) { throw "openfast.exe smoke case failed`n$runLog" } + if ($runLog -notmatch 'lie outside the SeaState wave-kinematics grid at t = 0 s \(warned once\)') { + throw "openfast.exe did not report the platform-only SeaState grid of the smoke case`n$runLog" + } if ($runLog -notmatch 'Running CableDyn \(' -or $runLog -notmatch 'OpenFAST terminated normally') { throw "openfast.exe did not prove CableDyn identity and normal termination`n$runLog" } diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index e2b547a8..607e6da0 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -831,6 +831,9 @@ MODULE CableDyn_DeckDriver ! OpenFAST supercycling (dtM > DT): extrapolate the coupled loads between dtM solves from the ! last two (CableDyn_LoadPredictor); FALSE holds the last solve's loads LOGICAL :: predict_loads = .TRUE. + ! OPTION waveGridCheck: TRUE (warn) downgrades the coupled wave-grid guard of the OpenFAST shell + ! from a fatal error (error, the default) to a warning + LOGICAL :: wave_grid_warn = .FALSE. ! OPTION CDOutDt [s]: the interval of the coupled .CD.out rows, a whole multiple of the ! CableDyn step; 0 (the default) writes a row after every committed step REAL(wp) :: cd_out_dt = CD_ZERO @@ -1316,6 +1319,8 @@ MODULE CableDyn_DeckDriver LOGICAL :: cable_load_feedback = .TRUE. ! Deck OPTION predictLoads (the OpenFAST shell; see CD_AGG_ModuleType%predict_loads) LOGICAL :: predict_loads = .TRUE. + ! Deck OPTION waveGridCheck (the OpenFAST shell; see CD_AGG_ModuleType%wave_grid_warn) + LOGICAL :: wave_grid_warn = .FALSE. ! Deck OPTION CDOutDt (the OpenFAST shell; see CD_AGG_ModuleType%cd_out_dt) REAL(wp) :: cd_out_dt = CD_ZERO ! OPTION maxStrain, for the per-step plausibility guard of the coupled EI=0 lines. @@ -8390,6 +8395,7 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi agg%n_turbines = nturb agg%cable_load_feedback = opts%cable_load_feedback agg%predict_loads = opts%predict_loads + agg%wave_grid_warn = opts%wave_grid_warn agg%cd_out_dt = opts%cd_out_dt agg%max_strain = opts%max_strain @@ -9676,6 +9682,7 @@ SUBROUTINE CD_End_Deck_Aggregate(agg) agg%host_current_enabled = .FALSE. agg%cable_load_feedback = .TRUE. agg%predict_loads = .TRUE. + agg%wave_grid_warn = .FALSE. agg%cd_out_dt = CD_ZERO agg%max_strain = 0.5_wp IF (ALLOCATED(agg%host_current_profile_z)) DEALLOCATE (agg%host_current_profile_z) @@ -19122,6 +19129,15 @@ SUBROUTINE apply_option(line, opts, ErrStat, ErrMsg) CALL rd_bool(val, opts%cable_load_feedback, ErrStat, ErrMsg) CASE ('predict_loads', 'predictloads') CALL rd_bool(val, opts%predict_loads, ErrStat, ErrMsg) + CASE ('wavegridcheck', 'wave_grid_check') + SELECT CASE (TRIM(to_lower(val))) + CASE ('error') + opts%wave_grid_warn = .FALSE. + CASE ('warn') + opts%wave_grid_warn = .TRUE. + CASE DEFAULT + CALL fail(ErrStat, ErrMsg, 'OPTION waveGridCheck "'//TRIM(val)//'" must be error or warn') + END SELECT CASE ('tensile_safety', 'tensilesafety') CALL rd_tensile_mode(val, opts%tensile_mode, ErrStat, ErrMsg) CASE ('tensile_strain_tolerance', 'tensilestraintolerance') diff --git a/src/CableDyn_OpenFAST_Aggregate.f90 b/src/CableDyn_OpenFAST_Aggregate.f90 index d7384dc6..80e7ddf3 100644 --- a/src/CableDyn_OpenFAST_Aggregate.f90 +++ b/src/CableDyn_OpenFAST_Aggregate.f90 @@ -166,6 +166,11 @@ MODULE CableDyn_OpenFAST_Aggregate ! Deck OPTION predictLoads: the OpenFAST shell extrapolates the coupled loads between ! supercycled solves (TRUE) or holds the last solve's (FALSE) LOGICAL :: predict_loads = .TRUE. + ! Deck OPTION waveGridCheck: the OpenFAST shell stops (FALSE, the default) or warns (TRUE) when + ! the SeaState grid it samples the line kinematics from does not cover the nodes in the water or + ! has too few points across an oblique or short-crested sea (check_wavefield_grid, + ! check_wavefield_resolution) + LOGICAL :: wave_grid_warn = .FALSE. ! Deck OPTION CDOutDt [s]: the OpenFAST shell writes a .CD.out row at every whole multiple ! of it (a whole multiple of the CableDyn step); 0 writes one after every committed step REAL(wp) :: cd_out_dt = CD_ZERO @@ -418,6 +423,7 @@ SUBROUTINE CD_AGG_Init_From_Deck(self, deck_path, dt, ErrStat, ErrMsg, env_gravi candidate%host_current_enabled = parts%host_current_enabled candidate%cable_load_feedback = parts%cable_load_feedback candidate%predict_loads = parts%predict_loads + candidate%wave_grid_warn = parts%wave_grid_warn candidate%cd_out_dt = parts%cd_out_dt candidate%max_strain = parts%max_strain IF (ALLOCATED(parts%host_current_profile_z)) THEN diff --git a/src/CableDyn_WaveGrid.f90 b/src/CableDyn_WaveGrid.f90 new file mode 100644 index 00000000..cf39ecea --- /dev/null +++ b/src/CableDyn_WaveGrid.f90 @@ -0,0 +1,94 @@ +! File: src/CableDyn_WaveGrid.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +MODULE CableDyn_WaveGrid + !! The rules by which the coupled route judges a gridded wave field (the OpenFAST SeaState + !! grid) against the sea it carries and the nodes that sample it: the wave-grid guard of the + !! OpenFAST shell (check_wavefield_grid and check_wavefield_resolution in + !! src/openfast/CableDyn_OF.f90, OPTION waveGridCheck). Pure functions of plain numbers, so + !! the rules are tested without OpenFAST (tests/test_wave_grid.f90). + !! + !! SeaState's horizontal grid has NX points on each half of [-X_HalfWidth, X_HalfWidth] (its + !! input NX; 2 NX - 1 points in all, spaced X_HalfWidth/(NX - 1)), and likewise in y. With + !! NX = 2 there are three points, at -X_HalfWidth, 0 and X_HalfWidth, and a node between two of + !! them gets an interpolation of their kinematics across a whole half-width (SeaState's + !! GridInterp takes the quadratic through the three points). That is exact only for a field + !! constant along x: a long-crested sea travelling along y. A sea whose components travel in + !! any other direction varies along x, and the interpolation across the half-width, often a + !! large part of a wavelength, is wrong in amplitude and phase. The same holds for NY = 2 + !! unless every component travels along x. + !! + !! A direction is along x when it is a multiple of 180 deg and along y when it is 90 deg plus + !! a multiple of 180 deg, each within CD_WAVEGRID_DIR_TOL. At 1e-4 deg, a direction that is + !! taken as aligned changes the phase across a half-width h by at most k h sin(1e-4 deg), less + !! than 2e-6 k h: 1e-5 rad over half a wavelength. + USE CableDyn_Precision, ONLY: wp + IMPLICIT NONE + PRIVATE + + PUBLIC :: CD_WaveGrid_Along_Axis, CD_WaveGrid_Coarse_Axes, CD_WaveGrid_Off_Vertex + + !> the tolerance on a wave direction taken as along a grid axis (deg) + REAL(wp), PARAMETER, PUBLIC :: CD_WAVEGRID_DIR_TOL = 1.0E-4_wp + !> the largest SeaState NX or NY (points on each half of the axis) that the guard calls coarse + INTEGER, PARAMETER, PUBLIC :: CD_WAVEGRID_COARSE_HALF_NODES = 2 + +CONTAINS + + PURE LOGICAL FUNCTION CD_WaveGrid_Along_Axis(direction, axis) RESULT(along) + !! Whether a wave direction (deg, from +x toward +y, the direction of travel) is along the + !! grid axis `axis` (1: x, 2: y) within CD_WAVEGRID_DIR_TOL. Either sense counts: 0 and + !! 180 deg are along x, 90 and 270 deg along y. A non-finite direction is along neither. + REAL(wp), INTENT(IN) :: direction + INTEGER, INTENT(IN) :: axis + REAL(wp) :: d + + along = .FALSE. + IF (.NOT. (ABS(direction) <= HUGE(direction))) RETURN + d = MODULO(direction, 180.0_wp) + IF (axis == 1) THEN + along = d <= CD_WAVEGRID_DIR_TOL .OR. d >= 180.0_wp - CD_WAVEGRID_DIR_TOL + ELSE IF (axis == 2) THEN + along = ABS(d - 90.0_wp) <= CD_WAVEGRID_DIR_TOL + END IF + END FUNCTION CD_WaveGrid_Along_Axis + + PURE SUBROUTINE CD_WaveGrid_Coarse_Axes(half_nodes, directions, coarse) + !! The grid axes too coarse for the sea: coarse(1) when the grid has + !! CD_WAVEGRID_COARSE_HALF_NODES or fewer points on each half of x (SeaState NX) and a + !! component travels in a direction other than along y; coarse(2) likewise for y (NY) and + !! a direction other than along x. `directions` holds the direction (deg) of every component + !! the sea carries: one for a long-crested sea, the spread of a short-crested one. With no + !! direction (a still sea) no axis is coarse. + INTEGER, INTENT(IN) :: half_nodes(2) + REAL(wp), INTENT(IN) :: directions(:) + LOGICAL, INTENT(OUT) :: coarse(2) + INTEGER :: i + + coarse = .FALSE. + DO i = 1, SIZE(directions) + IF (half_nodes(1) <= CD_WAVEGRID_COARSE_HALF_NODES .AND. .NOT. CD_WaveGrid_Along_Axis(directions(i), 2)) & + coarse(1) = .TRUE. + IF (half_nodes(2) <= CD_WAVEGRID_COARSE_HALF_NODES .AND. .NOT. CD_WaveGrid_Along_Axis(directions(i), 1)) & + coarse(2) = .TRUE. + END DO + END SUBROUTINE CD_WaveGrid_Coarse_Axes + + PURE LOGICAL FUNCTION CD_WaveGrid_Off_Vertex(c, lo, delta, npts, tol) RESULT(off) + !! Whether the coordinate c lies inside the grid axis of npts points lo + k delta + !! (k = 0 .. npts - 1) but more than tol from every point, so that the grid interpolates + !! there. A coordinate outside the axis by more than tol is not off a vertex: the grid gives it + !! the boundary point's kinematics, which the out-of-grid check reports. + REAL(wp), INTENT(IN) :: c, lo, delta, tol + INTEGER, INTENT(IN) :: npts + REAL(wp) :: s, hi + + off = .FALSE. + IF (npts < 2 .OR. .NOT. (delta > 0.0_wp)) RETURN + hi = lo + REAL(npts - 1, wp)*delta + IF (c < lo - tol .OR. c > hi + tol) RETURN + s = (c - lo)/delta + off = ABS(s - ANINT(s))*delta > tol + END FUNCTION CD_WaveGrid_Off_Vertex + +END MODULE CableDyn_WaveGrid diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index 51d158d7..a5dfdab0 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -136,7 +136,9 @@ MODULE CableDyn CD_Set_System_Line_Friction_Anchors, & CD_Recompute_System_Acceleration, CD_SYSTEM_OK USE SeaSt_WaveField, ONLY: WaveField_GetNodeWaveKin - USE SeaSt_WaveField_Types, ONLY: WaveMod_None + USE SeaSt_WaveField_Types, ONLY: WaveMod_None, WaveMod_ExtFull + USE CableDyn_WaveGrid, ONLY: CD_WaveGrid_Coarse_Axes, CD_WaveGrid_Off_Vertex, CD_WAVEGRID_DIR_TOL, & + CD_WAVEGRID_COARSE_HALF_NODES USE IfW_FlowField_Types, ONLY: Grid3D_FieldType IMPLICIT NONE @@ -266,8 +268,12 @@ END FUNCTION cd_cpu_guard_armed LOGICAL :: use_extfluid = .FALSE. INTEGER(IntKi) :: nfluid = 0 REAL(wp), ALLOCATABLE :: fx_xyz(:,:), fx_vel(:,:), fx_acc(:,:), fx_wl(:), fx_pd(:) - ! TRUE once the warning that sampling nodes lie outside the SeaState wave-kinematics - ! grid has been issued: one warning per run (check_wavefield_grid). + ! the wave-grid guard's workspace (check_wavefield_grid): the SeaState free-surface elevation + ! as sampled at each node, and the nodes it flags + REAL(wp), ALLOCATABLE :: fx_zeta(:) + LOGICAL, ALLOCATABLE :: fx_flag(:) + ! TRUE once the warning that sampling nodes lie outside the SeaState wave-kinematics grid has + ! been issued (OPTION waveGridCheck warn): one warning per run (check_wavefield_grid). LOGICAL :: grid_warned = .FALSE. LOGICAL :: curr_grid_warned = .FALSE. !< the dynamic current-field grid check has warned ! CHECKPOINT-RESTART identity: serial is the generation stamp minted at @@ -1033,7 +1039,8 @@ SUBROUTINE CD_Init(InitInp, u, p, x, xd, z, other, y, m, DTcoupling, InitOut, Er END IF ALLOCATE (Inst(id)%fx_xyz(3, Inst(id)%nfluid), Inst(id)%fx_vel(3, Inst(id)%nfluid), & Inst(id)%fx_acc(3, Inst(id)%nfluid), Inst(id)%fx_wl(Inst(id)%nfluid), & - Inst(id)%fx_pd(Inst(id)%nfluid), STAT=ErrStat2) + Inst(id)%fx_pd(Inst(id)%nfluid), Inst(id)%fx_zeta(Inst(id)%nfluid), & + Inst(id)%fx_flag(Inst(id)%nfluid), STAT=ErrStat2) IF (ErrStat2 /= 0) THEN CALL SetErrStat( ErrID_Fatal, 'Could not allocate the ambient-fluid sampling workspace.', & ErrStat, ErrMsg, RoutineName ) @@ -1075,6 +1082,11 @@ SUBROUTINE CD_Init(InitInp, u, p, x, xd, z, other, y, m, DTcoupling, InitOut, Er IF (ErrStat2 < AbortErrLev) CALL save_held_fluid( Inst(id), other ) CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) IF (ErrStat >= AbortErrLev) RETURN + ! the grid's resolution across the waves, on the static positions just sampled (the + ! coverage is checked in sample_wavefield, here and at every mooring step) + CALL check_wavefield_resolution( Inst(id), InitInp%WaveField, ErrStat2, ErrMsg2 ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) RETURN CALL note_seastate_deep_interval( Inst(id), InitInp%WaveField ) END IF @@ -1719,7 +1731,8 @@ SUBROUTINE rebuild_from_checkpoint( t, u1, p, x, other, m, ErrStat, ErrMsg ) Inst(id)%nfluid = CD_AGG_NFluidNodes( Inst(id)%agg, es, em ) ALLOCATE (Inst(id)%fx_xyz(3, Inst(id)%nfluid), Inst(id)%fx_vel(3, Inst(id)%nfluid), & Inst(id)%fx_acc(3, Inst(id)%nfluid), Inst(id)%fx_wl(Inst(id)%nfluid), & - Inst(id)%fx_pd(Inst(id)%nfluid), STAT=ErrStat2) + Inst(id)%fx_pd(Inst(id)%nfluid), Inst(id)%fx_zeta(Inst(id)%nfluid), & + Inst(id)%fx_flag(Inst(id)%nfluid), STAT=ErrStat2) IF (ErrStat2 /= 0) THEN CALL SetErrStat( ErrID_Fatal, 'Could not allocate the ambient-fluid workspace (rebuild).', & ErrStat, ErrMsg, RoutineName ) @@ -2160,11 +2173,12 @@ SUBROUTINE sample_wavefield( inst_e, p, m, t_sample, ErrStat, ErrMsg, at_init ) REAL(SiKi) :: wave_fv(3), wave_fa(3), wave_famcf(3) REAL(wp) :: profile_fv(3), steady_fv_wp(3), grid_z REAL(SiKi) :: steady_fv(3), grid_fv(3), grid_weight - ! the SeaState free-surface elevation as sampled at each node (kept also when the host - ! waves are off and fx_wl takes the still-water level): SeaState's Wheeler stretching - ! interpolates the current at the depth mapped with it. Only the grid check reads it, so - ! it exists only until that check has warned. - REAL(wp), ALLOCATABLE :: wl_sampled(:) + ! check_grid: the grid check runs on this sample (always under OPTION waveGridCheck error, the + ! default; until its one warning under warn). It reads the SeaState free-surface elevation + ! as sampled at each node (inst_e%fx_zeta, kept also when the host waves are off and fx_wl + ! takes the still-water level): SeaState's Wheeler stretching interpolates the current at + ! the depth mapped with it. + LOGICAL :: check_grid CHARACTER(ErrMsgLen) :: em INTEGER(IntKi) :: ErrStat2 CHARACTER(ErrMsgLen) :: ErrMsg2 @@ -2206,7 +2220,7 @@ SUBROUTINE sample_wavefield( inst_e, p, m, t_sample, ErrStat, ErrMsg, at_init ) ErrStat, ErrMsg, RoutineName ) RETURN END IF - IF (.NOT. inst_e%grid_warned) ALLOCATE (wl_sampled(inst_e%nfluid)) + check_grid = .NOT. inst_e%grid_warned IF (timed) CALL SYSTEM_CLOCK(prof_c0, prof_rate) DO i = 1, inst_e%nfluid IF (.NOT. inst_e%agg%host_wave_enabled .AND. .NOT. inst_e%agg%host_current_enabled) THEN @@ -2224,7 +2238,7 @@ SUBROUTINE sample_wavefield( inst_e, p, m, t_sample, ErrStat, ErrMsg, at_init ) CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) IF (ErrStat >= AbortErrLev) RETURN END IF - IF (ALLOCATED(wl_sampled)) wl_sampled(i) = REAL(zeta, wp) + IF (check_grid) inst_e%fx_zeta(i) = REAL(zeta, wp) steady_fv = 0.0_SiKi IF (nodeInWater /= 0_IntKi .AND. & (.NOT. inst_e%agg%host_wave_enabled .OR. .NOT. inst_e%agg%host_current_enabled)) THEN @@ -2309,11 +2323,13 @@ SUBROUTINE sample_wavefield( inst_e, p, m, t_sample, ErrStat, ErrMsg, at_init ) prof_c0 = prof_c1 END IF ! Grid coverage: checked on the positions just sampled (with their free-surface - ! elevations), at Init (the static equilibrium) and then every mooring step until the one - ! warning has been issued. - IF (.NOT. inst_e%grid_warned) THEN - CALL check_wavefield_grid( inst_e, p%WaveField, t_sample, init_call, wl_sampled, ErrStat2, ErrMsg2 ) + ! elevations), at Init (the static equilibrium) and then every mooring step: to the end of + ! the run, which it stops at the first node outside (OPTION waveGridCheck error, the + ! default), or until its one warning (waveGridCheck warn). + IF (check_grid) THEN + CALL check_wavefield_grid( inst_e, p%WaveField, t_sample, init_call, ErrStat2, ErrMsg2 ) CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) RETURN END IF IF (.NOT. inst_e%curr_grid_warned) CALL check_current_field_grid( inst_e, p%WaveField, t_sample ) IF (timed) THEN @@ -2333,21 +2349,28 @@ SUBROUTINE sample_wavefield( inst_e, p, m, t_sample, ErrStat, ErrMsg, at_init ) END SUBROUTINE sample_wavefield !---------------------------------------------------------------------------------------------------------------------------------- - SUBROUTINE check_wavefield_grid( inst_e, wf, t_sample, at_init, wl_sampled, ErrStat, ErrMsg ) - !! Warn, once per run, when sampling nodes lie outside the SeaState wave-kinematics grid. - !! The volume grid spans X_HalfWidth and Y_HalfWidth about the origin of the global frame - !! the nodes are sampled in (FAST.Farm runs in still water and never samples) and Z_Depth - !! below the SWL. Beyond it SeaState clamps the position to the grid boundary (GridInterp - !! SetIndex horizontally, the depth mapping of WaveField_Interp_Setup4D vertically), so - !! the node receives the kinematics of the nearest boundary point -- out of phase - !! horizontally, too strong below Z_Depth. SeaState's own clamping notice is generic, names - !! no node, and is issued once, at the Init sample, where the glue drops it. The extents are - !! read from the WaveField's volume-grid parameters, i.e. exactly the grid the sampler - !! interpolates. Excursions below 1 % of the boundary grid spacing are ignored. Below a - !! grid that reaches the seabed (Z_Depth = WtrDpth + MSL2SWL, the SeaState maximum) a node - !! is in the seabed and the seabed kinematics are the right ones. SeaState's current is + SUBROUTINE check_wavefield_grid( inst_e, wf, t_sample, at_init, ErrStat, ErrMsg ) + !! The wave-grid guard on coverage: sampling nodes in the water that lie outside the SeaState + !! wave-kinematics grid. The volume grid spans X_HalfWidth and Y_HalfWidth about the origin + !! of the global frame the nodes are sampled in (FAST.Farm runs in still water and never + !! samples) and Z_Depth below the SWL. Beyond it SeaState clamps the position to the grid + !! boundary (GridInterp SetIndex horizontally, the depth mapping of WaveField_Interp_Setup4D + !! vertically), so the node receives the kinematics of the nearest boundary point -- out of + !! phase horizontally, too strong below Z_Depth. SeaState's own clamping notice is generic, + !! names no node, and is issued once, at the Init sample, where the glue drops it. The + !! extents are read from the WaveField's volume-grid parameters, i.e. exactly the grid the + !! sampler interpolates. Excursions below 1 % of the boundary grid spacing are ignored. + !! Below a grid that reaches the seabed (Z_Depth = WtrDpth + MSL2SWL, the SeaState maximum) a + !! node is in the seabed and the seabed kinematics are the right ones. SeaState's current is !! uniform in x and y, so the horizontal check applies to waves only. !! + !! Under OPTION waveGridCheck error (the default) a node outside is a fatal error, at Init + !! (the static equilibrium, t = 0) or at the first mooring step whose sample finds one: the + !! run stops there, and the message gives the time. Under waveGridCheck warn it is a + !! warning, given once per run, and the nodes keep the boundary kinematics. The message + !! lists, by line (or body, rod, buoy point), the nodes outside with the deepest and the + !! shallowest of them. + !! !! Only nodes in the water are checked: a node above the free surface carries no fluid !! load whatever kinematics it is given, so a suspended cable or jumper above the water !! outside the grid is no error. A node is in the water at or below the free-surface @@ -2355,28 +2378,27 @@ SUBROUTINE check_wavefield_grid( inst_e, wf, t_sample, at_init, wl_sampled, ErrS !! off), which decides its wetting in CableDyn, and, without wave stretching !! (WaveStMod = 0), at or below the still-water level too, above which SeaState gives a !! node zero kinematics without reading the grid. Called after the nodes' sampling, on the - !! positions just sampled. Cost: a few comparisons per node per mooring step until the - !! warning. at_init marks the Init call, at the static equilibrium (t = 0). + !! positions just sampled, with the SeaState elevations sampled there (fx_zeta). Cost: a few + !! comparisons per node per mooring step. !! - !! The message states first that it is given once, so that a caller's message buffer that - !! cuts its tail keeps that; the farthest-node details are left out if the message would not - !! fit the remaining length of ErrMsg. + !! The message is built to fit the room left in ErrMsg: the option that downgrades the error + !! is always in it, the per-line list is cut short ('and N more') before it would overflow, + !! and the farthest-node details are left out if they would not fit. TYPE(CD_OF_Instance), INTENT(INOUT) :: inst_e TYPE(SeaSt_WaveFieldType), INTENT(IN ) :: wf REAL(DbKi), INTENT(IN ) :: t_sample LOGICAL, INTENT(IN ) :: at_init - REAL(wp), INTENT(IN ) :: wl_sampled(:) !< SeaState elevation as sampled per node INTEGER(IntKi), INTENT( OUT) :: ErrStat CHARACTER(*), INTENT( OUT) :: ErrMsg character(*), parameter :: RoutineName = 'check_wavefield_grid' - LOGICAL :: waves, grid_current, check_xy(2), check_z, outside + LOGICAL :: waves, grid_current, check_xy(2), check_z, outside, fatal INTEGER(IntKi) :: i, k, nout, nin, nwet, room REAL(wp) :: lo(2), hi(2), tol(2), zbot, tol_z, ex, ex_max(3), at_max(3), surface REAL(wp) :: zq, dep CHARACTER(11) :: inp(3), res(3) CHARACTER(1024) :: farthest, enlarge, refine - CHARACTER(:), ALLOCATABLE :: head, msg + CHARACTER(:), ALLOCATABLE :: head, fix, option, by_line, msg ErrStat = ErrID_None ErrMsg = '' @@ -2401,6 +2423,7 @@ SUBROUTINE check_wavefield_grid( inst_e, wf, t_sample, at_init, wl_sampled, ErrS ex_max = 0.0_wp at_max = 0.0_wp DO i = 1, inst_e%nfluid + inst_e%fx_flag(i) = .FALSE. ! nodes above the free surface carry no fluid load (see above) surface = inst_e%fx_wl(i) IF (wf%WaveStMod == 0_IntKi) surface = MIN(surface, 0.0_wp) @@ -2426,7 +2449,8 @@ SUBROUTINE check_wavefield_grid( inst_e, wf, t_sample, at_init, wl_sampled, ErrS zq = inst_e%fx_xyz(3, i) IF (wf%WaveMod /= WaveMod_None .AND. wf%WaveStMod == 3_IntKi) THEN dep = REAL(wf%EffWtrDpth, wp) - IF (dep + wl_sampled(i) > 0.0_wp) zq = MIN(dep*(dep + zq)/(dep + wl_sampled(i)) - dep, 0.0_wp) + IF (dep + inst_e%fx_zeta(i) > 0.0_wp) & + zq = MIN(dep*(dep + zq)/(dep + inst_e%fx_zeta(i)) - dep, 0.0_wp) END IF ex = zbot - zq IF (ex > tol_z) THEN @@ -2437,7 +2461,10 @@ SUBROUTINE check_wavefield_grid( inst_e, wf, t_sample, at_init, wl_sampled, ErrS END IF END IF END IF - IF (outside) nout = nout + 1_IntKi + IF (outside) THEN + nout = nout + 1_IntKi + inst_e%fx_flag(i) = .TRUE. + END IF END DO IF (nout == 0_IntKi) RETURN @@ -2478,25 +2505,271 @@ SUBROUTINE check_wavefield_grid( inst_e, wf, t_sample, at_init, wl_sampled, ErrS END DO IF (ex_max(3) > 0.0_wp) enlarge = TRIM(enlarge)//' (Z_Depth at most WtrDpth + MSL2SWL, its default)' - inst_e%grid_warned = .TRUE. + fatal = .NOT. inst_e%agg%wave_grid_warn head = 'CableDyn mooring module: '//TRIM(Num2LStr(nout))//' of the '//TRIM(Num2LStr(nwet))// & ' CableDyn sampling nodes in the water lie outside the SeaState wave-kinematics grid at t = '// & - TRIM(Num2LStr(t_sample))//' s (warned once). SeaState clamps them to the grid boundary, so '// & - 'their fluid kinematics and loads are not physical.' - msg = head//' Farthest: '//TRIM(farthest(3:))//'. In the SeaState input file enlarge '//TRIM(enlarge)// & - ' to cover the lines with margin for their motion, and raise '//TRIM(refine)// & - ' to keep the grid spacing.' + TRIM(Num2LStr(t_sample))//' s' + IF (fatal) THEN + head = head//', where SeaState would give them the kinematics of the grid boundary, which are not '// & + 'physical there.' + option = ' To run on with those kinematics, set waveGridCheck warn in the OPTIONS of the CableDyn deck.' + ELSE + inst_e%grid_warned = .TRUE. + head = head//' (warned once). SeaState clamps them to the grid boundary, so their fluid kinematics '// & + 'and loads are not physical.' + option = ' (OPTIONS waveGridCheck warn; the default, error, stops the run here.)' + END IF + fix = ' In the SeaState input file enlarge '//TRIM(enlarge)//' to cover the lines with margin for '// & + 'their motion, and raise '//TRIM(refine)//' to keep the grid spacing.' ! SetErrStat appends the message to ErrMsg after a line break and the routine name - room = LEN(ErrMsg) - LEN_TRIM(ErrMsg) - LEN(RoutineName) - 2 - IF (LEN(msg) > room) msg = head//' Enlarge '//TRIM(enlarge)//' in the SeaState input file.' - CALL SetErrStat( ErrID_Warn, msg, ErrStat, ErrMsg, RoutineName ) - ! The OpenFAST glue does not print module initialization warnings (FAST_InitializeAll_T - ! passes its status on to FAST_InitMappings, which resets it), so the Init check also - ! writes the warning to the screen, as the deck dtM warning does. A warning raised - ! during the time march reaches the screen through the glue's error check. - IF (at_init) CALL WrScr( ' WARNING: '//msg ) + room = LEN(ErrMsg) - LEN(RoutineName) - 2 - LEN(head) - LEN(option) - LEN(fix) + CALL flagged_nodes_by_line( inst_e, room - 16, by_line ) + msg = head + IF (LEN(by_line) > 0) msg = msg//' By line: '//by_line//'.' + IF (LEN(msg) + LEN(fix) + LEN(option) + 12 + LEN_TRIM(farthest) <= LEN(ErrMsg) - LEN(RoutineName) - 2) & + msg = msg//' Farthest: '//TRIM(farthest(3:))//'.' + msg = msg//fix//option + IF (fatal) THEN + CALL SetErrStat( ErrID_Fatal, msg, ErrStat, ErrMsg, RoutineName ) + ELSE + CALL SetErrStat( ErrID_Warn, msg, ErrStat, ErrMsg, RoutineName ) + ! The OpenFAST glue does not print module initialization warnings (FAST_InitializeAll_T + ! passes its status on to FAST_InitMappings, which resets it), so the Init check also + ! writes the warning to the screen, as the deck dtM warning does. A warning raised + ! during the time march reaches the screen through the glue's error check. + IF (at_init) CALL WrScr( ' WARNING: '//msg ) + END IF END SUBROUTINE check_wavefield_grid + SUBROUTINE check_wavefield_resolution( inst_e, wf, ErrStat, ErrMsg ) + !! The wave-grid guard on resolution across the waves, at initialisation (once per run: a + !! checkpoint restart, whose run passed it, rebuilds without it). A SeaState grid with NX = 2 + !! has three points along x (-X_HalfWidth, 0, X_HalfWidth), and SeaState's GridInterp + !! interpolates the kinematics between them with the quadratic through the three + !! (CableDyn_WaveGrid). That is exact only for waves that do not vary along x, a long-crested + !! sea travelling along y; likewise NY = 2 only for a sea along x. Under any other sea -- a + !! long-crested one in another direction, a short-crested one, or components in several + !! directions -- the sampling nodes in the water between grid points across that axis receive + !! an interpolation over a large part of a wavelength, wrong in amplitude and phase. + !! + !! The sea's directions are those of its first-order components with a nonzero amplitude + !! (WaveDirArr where WaveElevC0 is nonzero: one direction for a long-crested sea, the spread + !! of WaveDirMod 1, the component directions of WaveMod 7), or WaveDir where SeaState keeps no + !! components (WaveMod 6 reads the kinematics themselves). A direction is along an axis + !! within CD_WAVEGRID_DIR_TOL (1e-4 deg). Checked on the static positions just sampled, with + !! the wet-node rule of check_wavefield_grid; nodes outside the grid are left to that check. + !! A node on a grid line across the coarse axis (within 1 % of the spacing) is exact there + !! and not flagged. + !! + !! Under OPTION waveGridCheck error (the default) a flagged node is a fatal error; under warn + !! a warning, written to the screen too (the glue drops Init warnings). Only the waves are + !! concerned: SeaState's current is uniform in x and y. + TYPE(CD_OF_Instance), INTENT(INOUT) :: inst_e + TYPE(SeaSt_WaveFieldType), INTENT(IN ) :: wf + INTEGER(IntKi), INTENT( OUT) :: ErrStat + CHARACTER(*), INTENT( OUT) :: ErrMsg + + character(*), parameter :: RoutineName = 'check_wavefield_resolution' + CHARACTER(1), PARAMETER :: AXIS_NAME(2) = ['x', 'y'], AXIS_UPPER(2) = ['X', 'Y'] + LOGICAL :: coarse(2), fatal, inside + INTEGER(IntKi) :: i, k, i0, i1, ndir, nflag, nwet, room, half(2) + REAL(wp) :: lo(2), delta(2), tol(2), surface, dmin, dmax + REAL(wp), ALLOCATABLE :: dirs(:) + CHARACTER(:), ALLOCATABLE :: head, sea, grid, fix, option, by_line, msg + + ErrStat = ErrID_None + ErrMsg = '' + IF (.NOT. (inst_e%agg%host_wave_enabled .AND. wf%WaveMod /= WaveMod_None)) RETURN + DO k = 1, 2 + half(k) = (wf%VolGridParams%n(k + 1) + 1_IntKi)/2_IntKi + lo(k) = REAL(wf%VolGridParams%pZero(k + 1), wp) + delta(k) = REAL(wf%VolGridParams%delta(k + 1), wp) + tol(k) = 0.01_wp*delta(k) + END DO + IF (ALL(half > CD_WAVEGRID_COARSE_HALF_NODES)) RETURN + + ! the directions of the components the sea carries + ndir = 0_IntKi + IF (wf%WaveMod /= WaveMod_ExtFull .AND. ALLOCATED(wf%WaveDirArr) .AND. ALLOCATED(wf%WaveElevC0)) THEN + i0 = MAX(LBOUND(wf%WaveDirArr, 1), LBOUND(wf%WaveElevC0, 2)) + i1 = MIN(UBOUND(wf%WaveDirArr, 1), UBOUND(wf%WaveElevC0, 2)) + ALLOCATE (dirs(MAX(1_IntKi, i1 - i0 + 1_IntKi))) + DO i = i0, i1 + IF (wf%WaveElevC0(1, i) == 0.0_SiKi .AND. wf%WaveElevC0(2, i) == 0.0_SiKi) CYCLE + ndir = ndir + 1_IntKi + dirs(ndir) = REAL(wf%WaveDirArr(i), wp) + END DO + ELSE + ALLOCATE (dirs(1)) + END IF + IF (ndir == 0_IntKi) THEN + ndir = 1_IntKi + dirs(1) = REAL(wf%WaveDir, wp) + END IF + CALL CD_WaveGrid_Coarse_Axes( half, dirs(1:ndir), coarse ) + IF (.NOT. ANY(coarse)) RETURN + + ! the nodes in the water between grid points across a coarse axis + nflag = 0_IntKi + nwet = 0_IntKi + DO i = 1, inst_e%nfluid + inst_e%fx_flag(i) = .FALSE. + surface = inst_e%fx_wl(i) + IF (wf%WaveStMod == 0_IntKi) surface = MIN(surface, 0.0_wp) + IF (inst_e%fx_xyz(3, i) > surface) CYCLE + nwet = nwet + 1_IntKi + inside = .FALSE. + DO k = 1, 2 + IF (coarse(k)) inside = inside .OR. CD_WaveGrid_Off_Vertex( inst_e%fx_xyz(k, i), lo(k), delta(k), & + wf%VolGridParams%n(k + 1), tol(k) ) + END DO + IF (inside) THEN + nflag = nflag + 1_IntKi + inst_e%fx_flag(i) = .TRUE. + END IF + END DO + IF (nflag == 0_IntKi) RETURN + + dmin = MINVAL(dirs(1:ndir)) + dmax = MAXVAL(dirs(1:ndir)) + IF (wf%WaveMultiDir) THEN + sea = 'a short-crested sea (directions '//TRIM(Num2LStr(dmin))//' to '//TRIM(Num2LStr(dmax))//' deg)' + ELSE IF (dmax - dmin <= CD_WAVEGRID_DIR_TOL) THEN + sea = 'long-crested waves at '//TRIM(Num2LStr(dmin))//' deg' + ELSE + sea = 'wave components in directions from '//TRIM(Num2LStr(dmin))//' to '//TRIM(Num2LStr(dmax))//' deg' + END IF + grid = '' + DO k = 1, 2 + IF (.NOT. coarse(k)) CYCLE + IF (LEN(grid) > 0) grid = grid//' and ' + grid = grid//'N'//AXIS_UPPER(k)//' = '//TRIM(Num2LStr(half(k)))//' (3 points '// & + TRIM(Num2LStr(delta(k)))//' m apart in '//AXIS_NAME(k)//')' + END DO + fatal = .NOT. inst_e%agg%wave_grid_warn + head = 'CableDyn mooring module: the SeaState wave-kinematics grid has '//grid//' under '//sea// & + ', which vary along that axis: SeaState interpolates them between the three grid points, '// & + 'over distances that are a large part of a wavelength or more, and '//TRIM(Num2LStr(nflag))//' of the '// & + TRIM(Num2LStr(nwet))//' CableDyn sampling nodes in the water lie between grid points there.' + fix = ' A grid with NY = 2 represents only waves along x (0 or 180 deg) and one with NX = 2 only '// & + 'waves along y (90 or 270 deg), within 1e-4 deg; in the SeaState input file raise the count so '// & + 'that the spacing resolves the shortest wavelength that matters at the lines (a tenth of it '// & + 'or finer).' + IF (fatal) THEN + option = ' To run on with the interpolated kinematics, set waveGridCheck warn in the OPTIONS of '// & + 'the CableDyn deck.' + ELSE + option = ' (OPTIONS waveGridCheck warn; the default, error, stops the run here.)' + END IF + room = LEN(ErrMsg) - LEN(RoutineName) - 2 - LEN(head) - LEN(option) - LEN(fix) + CALL flagged_nodes_by_line( inst_e, room - 16, by_line ) + msg = head + IF (LEN(by_line) > 0) msg = msg//' By line: '//by_line//'.' + msg = msg//fix//option + IF (fatal) THEN + CALL SetErrStat( ErrID_Fatal, msg, ErrStat, ErrMsg, RoutineName ) + ELSE + CALL SetErrStat( ErrID_Warn, msg, ErrStat, ErrMsg, RoutineName ) + CALL WrScr( ' WARNING: '//msg ) + END IF + + END SUBROUTINE check_wavefield_resolution + + SUBROUTINE flagged_nodes_by_line( inst_e, budget, report ) + !! The sampling nodes flagged in inst_e%fx_flag, by line, in the order of the fluid blocks + !! (CD_AGG_GetFluidNodePositions: the EI = 0 lines, the finite-EI cables, then the Rigid6 + !! body reference points, the rod stations and the buoy points): per line the count and the + !! positions of the deepest and the shallowest flagged node, '; '-separated. An item that + !! would take the report past `budget` characters is left out and counted in a closing + !! 'and N more'. + TYPE(CD_OF_Instance), INTENT(IN ) :: inst_e + INTEGER(IntKi), INTENT(IN ) :: budget + CHARACTER(:), ALLOCATABLE, INTENT(OUT) :: report + INTEGER(IntKi) :: b, i, n, ideep, ishal, nskip + CHARACTER(:), ALLOCATABLE :: item + + report = '' + nskip = 0_IntKi + IF (.NOT. ALLOCATED(inst_e%agg%fl_off)) RETURN + DO b = 1, SIZE(inst_e%agg%fl_off) - 1 + n = 0_IntKi + ideep = 0_IntKi + ishal = 0_IntKi + DO i = inst_e%agg%fl_off(b) + 1, MIN(inst_e%agg%fl_off(b + 1), inst_e%nfluid) + IF (.NOT. inst_e%fx_flag(i)) CYCLE + n = n + 1_IntKi + IF (ideep == 0_IntKi) THEN + ideep = i + ishal = i + END IF + IF (inst_e%fx_xyz(3, i) < inst_e%fx_xyz(3, ideep)) ideep = i + IF (inst_e%fx_xyz(3, i) > inst_e%fx_xyz(3, ishal)) ishal = i + END DO + IF (n == 0_IntKi) CYCLE + IF (n == 1_IntKi) THEN + item = TRIM(fluid_block_label(inst_e%agg, b))//', 1 node, at '//node_position(ideep) + ELSE + item = TRIM(fluid_block_label(inst_e%agg, b))//', '//TRIM(Num2LStr(n))//' nodes, deepest at '// & + node_position(ideep)//', shallowest at '//node_position(ishal) + END IF + IF (LEN(report) + LEN(item) + 2 > budget) THEN + nskip = nskip + 1_IntKi + CYCLE + END IF + IF (LEN(report) > 0) report = report//'; ' + report = report//item + END DO + IF (nskip > 0_IntKi) report = report//'; and '//TRIM(Num2LStr(nskip))//' more' + + CONTAINS + + FUNCTION node_position(i) RESULT(s) + INTEGER(IntKi), INTENT(IN) :: i + CHARACTER(:), ALLOCATABLE :: s + s = '(x, y, z) = ('//TRIM(Num2LStr(inst_e%fx_xyz(1, i)))//', '//TRIM(Num2LStr(inst_e%fx_xyz(2, i)))// & + ', '//TRIM(Num2LStr(inst_e%fx_xyz(3, i)))//') m' + END FUNCTION node_position + + END SUBROUTINE flagged_nodes_by_line + + FUNCTION fluid_block_label( agg, b ) RESULT(label) + !! The name of fluid block b of the aggregate (CD_AGG_GetFluidNodePositions): 'line ' with + !! the deck's LINES id for an EI = 0 line or a finite-EI cable, else the body, rod or buoy + !! point with its position among those of the deck. + TYPE(CD_AGG_ModuleType), INTENT(IN) :: agg + INTEGER(IntKi), INTENT(IN) :: b + CHARACTER(64) :: label + INTEGER(IntKi) :: k, obj + LOGICAL :: cable + + label = '' + IF (b <= agg%fl_nlines + agg%ncable) THEN + cable = b > agg%fl_nlines + obj = b + IF (cable) obj = b - agg%fl_nlines + IF (ALLOCATED(agg%line_obj_index) .AND. ALLOCATED(agg%line_is_cable)) THEN + DO k = 1, SIZE(agg%line_obj_index) + IF (agg%line_obj_index(k) == obj .AND. (agg%line_is_cable(k) .EQV. cable)) THEN + label = 'line '//TRIM(Num2LStr(k)) + RETURN + END IF + END DO + END IF + IF (cable) THEN + label = 'finite-EI cable '//TRIM(Num2LStr(obj))//' of the deck' + ELSE + label = 'EI = 0 line '//TRIM(Num2LStr(obj))//' of the deck' + END IF + ELSE IF (b <= agg%fl_nlines + agg%ncable + agg%fl_nbody) THEN + label = 'Rigid6 body '//TRIM(Num2LStr(b - agg%fl_nlines - agg%ncable))//' of the deck' + ELSE IF (b <= agg%fl_nlines + agg%ncable + agg%fl_nbody + agg%fl_nrod) THEN + label = 'rod '//TRIM(Num2LStr(b - agg%fl_nlines - agg%ncable - agg%fl_nbody))//' of the deck' + ELSE + label = 'buoy point '//TRIM(Num2LStr(b - agg%fl_nlines - agg%ncable - agg%fl_nbody - agg%fl_nrod))// & + ' of the deck' + END IF + END FUNCTION fluid_block_label + SUBROUTINE note_seastate_deep_interval( inst_e, wf ) !! Say at initialisation, once per run (a restart rebuilds without passing here), when the !! deepest interval of the SeaState depth grid is coarse and a line lies in it. The levels @@ -5518,7 +5791,7 @@ SUBROUTINE release_instance( k, ErrStat, ErrMsg ) Inst(k)%u_interp_ready = .FALSE. END IF IF (ALLOCATED(Inst(k)%fx_xyz)) DEALLOCATE (Inst(k)%fx_xyz, Inst(k)%fx_vel, Inst(k)%fx_acc, & - Inst(k)%fx_wl, Inst(k)%fx_pd) + Inst(k)%fx_wl, Inst(k)%fx_pd, Inst(k)%fx_zeta, Inst(k)%fx_flag) Inst(k)%use_extfluid = .FALSE. Inst(k)%nfluid = 0 Inst(k)%grid_warned = .FALSE. diff --git a/tests/test_wave_grid.f90 b/tests/test_wave_grid.f90 new file mode 100644 index 00000000..11f6a0c5 --- /dev/null +++ b/tests/test_wave_grid.f90 @@ -0,0 +1,176 @@ +! File: tests/test_wave_grid.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +PROGRAM test_wave_grid + !! The rules of the coupled wave-grid guard (CableDyn_WaveGrid): + !! * a direction is along x at multiples of 180 deg and along y at 90 deg plus multiples of + !! 180 deg, within 1e-4 deg, in either sense and for negative angles; + !! * NY = 2 is coarse for every long-crested sea not along x (30, 60 and 90 deg) and for a + !! short-crested sea; NX = 2 for every sea not along y; an aligned sea (NY = 2 at 0 or + !! 180 deg, NX = 2 at 90 or 270 deg) and a finer grid (NX = NY = 3) are never coarse; + !! * a coordinate is off a vertex only inside the axis and more than the tolerance from every + !! grid point; + !! * OPTION waveGridCheck reaches the coupled aggregate (the mixed IEA-15 MW example deck, the + !! first argument): error by default and as written, warn as written, any other value is + !! refused by name. + USE CableDyn_Precision, ONLY: wp + USE CableDyn_WaveGrid, ONLY: CD_WaveGrid_Along_Axis, CD_WaveGrid_Coarse_Axes, CD_WaveGrid_Off_Vertex, & + CD_WAVEGRID_DIR_TOL + USE CableDyn_OpenFAST_Aggregate, ONLY: CD_AGG_ModuleType, CD_AGG_Init_From_Deck, CD_AGG_End, CD_AGG_OK + USE, INTRINSIC :: IEEE_ARITHMETIC, ONLY: IEEE_VALUE, IEEE_QUIET_NAN + IMPLICIT NONE + + INTEGER :: nfail, k + CHARACTER(1024) :: deck + LOGICAL :: coarse(2) + REAL(wp) :: spread(7), nan + + nfail = 0 + + ! directions along an axis + CALL require(CD_WaveGrid_Along_Axis(0.0_wp, 1), '0 deg is along x') + CALL require(CD_WaveGrid_Along_Axis(180.0_wp, 1), '180 deg is along x') + CALL require(CD_WaveGrid_Along_Axis(-180.0_wp, 1), '-180 deg is along x') + CALL require(CD_WaveGrid_Along_Axis(360.0_wp, 1), '360 deg is along x') + CALL require(CD_WaveGrid_Along_Axis(0.5_wp*CD_WAVEGRID_DIR_TOL, 1), 'half the tolerance is along x') + CALL require(CD_WaveGrid_Along_Axis(180.0_wp - 0.5_wp*CD_WAVEGRID_DIR_TOL, 1), & + '180 deg less half the tolerance is along x') + CALL require(.NOT. CD_WaveGrid_Along_Axis(2.0_wp*CD_WAVEGRID_DIR_TOL, 1), 'twice the tolerance is not along x') + CALL require(.NOT. CD_WaveGrid_Along_Axis(30.0_wp, 1), '30 deg is not along x') + CALL require(.NOT. CD_WaveGrid_Along_Axis(90.0_wp, 1), '90 deg is not along x') + CALL require(CD_WaveGrid_Along_Axis(90.0_wp, 2), '90 deg is along y') + CALL require(CD_WaveGrid_Along_Axis(270.0_wp, 2), '270 deg is along y') + CALL require(CD_WaveGrid_Along_Axis(-90.0_wp, 2), '-90 deg is along y') + CALL require(.NOT. CD_WaveGrid_Along_Axis(90.0_wp + 2.0_wp*CD_WAVEGRID_DIR_TOL, 2), & + '90 deg plus twice the tolerance is not along y') + CALL require(.NOT. CD_WaveGrid_Along_Axis(0.0_wp, 2), '0 deg is not along y') + CALL require(.NOT. CD_WaveGrid_Along_Axis(60.0_wp, 2), '60 deg is not along y') + nan = IEEE_VALUE(nan, IEEE_QUIET_NAN) + CALL require(.NOT. (CD_WaveGrid_Along_Axis(nan, 1) .OR. CD_WaveGrid_Along_Axis(nan, 2)), & + 'a NaN direction is along neither axis') + CALL require(.NOT. CD_WaveGrid_Along_Axis(0.0_wp, 3), 'there is no third axis') + + ! long-crested seas: NY = 2 across the waves + CALL CD_WaveGrid_Coarse_Axes([37, 2], [0.0_wp], coarse) + CALL require(.NOT. ANY(coarse), 'NY = 2 at 0 deg is not coarse') + CALL CD_WaveGrid_Coarse_Axes([37, 2], [180.0_wp], coarse) + CALL require(.NOT. ANY(coarse), 'NY = 2 at 180 deg is not coarse') + CALL CD_WaveGrid_Coarse_Axes([37, 2], [30.0_wp], coarse) + CALL require(coarse(2) .AND. .NOT. coarse(1), 'NY = 2 at 30 deg is coarse in y only') + CALL CD_WaveGrid_Coarse_Axes([37, 2], [60.0_wp], coarse) + CALL require(coarse(2) .AND. .NOT. coarse(1), 'NY = 2 at 60 deg is coarse in y only') + CALL CD_WaveGrid_Coarse_Axes([37, 2], [90.0_wp], coarse) + CALL require(coarse(2) .AND. .NOT. coarse(1), 'NY = 2 at 90 deg is coarse in y') + ! NX = 2 + CALL CD_WaveGrid_Coarse_Axes([2, 73], [90.0_wp], coarse) + CALL require(.NOT. ANY(coarse), 'NX = 2 at 90 deg is not coarse') + CALL CD_WaveGrid_Coarse_Axes([2, 73], [270.0_wp], coarse) + CALL require(.NOT. ANY(coarse), 'NX = 2 at 270 deg is not coarse') + CALL CD_WaveGrid_Coarse_Axes([2, 73], [0.0_wp], coarse) + CALL require(coarse(1) .AND. .NOT. coarse(2), 'NX = 2 at 0 deg is coarse in x only') + CALL CD_WaveGrid_Coarse_Axes([2, 73], [45.0_wp], coarse) + CALL require(coarse(1) .AND. .NOT. coarse(2), 'NX = 2 at 45 deg is coarse in x only') + CALL CD_WaveGrid_Coarse_Axes([2, 2], [45.0_wp], coarse) + CALL require(ALL(coarse), 'NX = NY = 2 at 45 deg is coarse in both') + CALL CD_WaveGrid_Coarse_Axes([3, 3], [45.0_wp], coarse) + CALL require(.NOT. ANY(coarse), 'NX = NY = 3 is never coarse') + + ! short-crested seas: a spread of directions about 0 deg (WaveDirMod 1) or 90 deg + spread = [(-30.0_wp + 10.0_wp*REAL(k, wp), k=0, 6)] + CALL CD_WaveGrid_Coarse_Axes([37, 2], spread, coarse) + CALL require(coarse(2) .AND. .NOT. coarse(1), 'NY = 2 under a short-crested sea about 0 deg is coarse in y') + CALL CD_WaveGrid_Coarse_Axes([2, 37], spread, coarse) + CALL require(coarse(1) .AND. .NOT. coarse(2), 'NX = 2 under a short-crested sea about 0 deg is coarse in x') + CALL CD_WaveGrid_Coarse_Axes([2, 37], spread + 90.0_wp, coarse) + CALL require(coarse(1), 'NX = 2 under a short-crested sea about 90 deg is coarse in x') + CALL CD_WaveGrid_Coarse_Axes([37, 37], spread, coarse) + CALL require(.NOT. ANY(coarse), 'a fine grid under a short-crested sea is not coarse') + CALL CD_WaveGrid_Coarse_Axes([2, 2], spread(1:0), coarse) + CALL require(.NOT. ANY(coarse), 'a sea with no component is never coarse') + + ! nodes between grid points: the axis -45, 0, 45 m (NY = 2, Y_HalfWidth = 45 m), tolerance 0.45 m + CALL require(.NOT. CD_WaveGrid_Off_Vertex(0.0_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), 'y = 0 is a vertex') + CALL require(.NOT. CD_WaveGrid_Off_Vertex(-45.0_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), 'y = -45 m is a vertex') + CALL require(.NOT. CD_WaveGrid_Off_Vertex(44.6_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), & + 'y = 44.6 m is within the tolerance of a vertex') + CALL require(CD_WaveGrid_Off_Vertex(44.5_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), 'y = 44.5 m is off the vertices') + CALL require(CD_WaveGrid_Off_Vertex(20.0_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), 'y = 20 m is off the vertices') + CALL require(CD_WaveGrid_Off_Vertex(-22.5_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), 'y = -22.5 m is off the vertices') + CALL require(.NOT. CD_WaveGrid_Off_Vertex(45.3_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), & + 'y = 45.3 m is within the tolerance of the edge') + CALL require(.NOT. CD_WaveGrid_Off_Vertex(60.0_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), & + 'y = 60 m is outside the grid, not off a vertex') + CALL require(.NOT. CD_WaveGrid_Off_Vertex(20.0_wp, -45.0_wp, 45.0_wp, 1, 0.45_wp), 'a one-point axis has no interior') + CALL require(.NOT. CD_WaveGrid_Off_Vertex(20.0_wp, -45.0_wp, 0.0_wp, 3, 0.45_wp), 'a zero spacing has no interior') + + ! the deck option, through the aggregate the OpenFAST shell reads it from + IF (COMMAND_ARGUMENT_COUNT() < 1) THEN + WRITE (*, '(A)') 'FAIL: the mixed example deck path argument is required' + ERROR STOP 1 + END IF + CALL GET_COMMAND_ARGUMENT(1, deck) + CALL check_option('', .TRUE., .FALSE., '') + CALL check_option('error waveGridCheck', .TRUE., .FALSE., '') + CALL check_option('warn waveGridCheck', .TRUE., .TRUE., '') + CALL check_option('WARN wave_grid_check - downgraded', .TRUE., .TRUE., '') + CALL check_option('strict waveGridCheck', .FALSE., .FALSE., 'OPTION waveGridCheck "strict" must be error or warn') + + IF (nfail > 0) THEN + WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' + ERROR STOP 1 + END IF + WRITE (*, '(A)') 'PASS: the wave-grid guard rules (directions along the axes, coarse axes, off-vertex nodes) '// & + 'and OPTION waveGridCheck' + +CONTAINS + + SUBROUTINE check_option(row, accepted, warn, message) + !! A copy of the deck with `row` after its dtM row (none for an empty row), in the working + !! directory: initialised as the coupled aggregate, it is accepted or refused with `message`, + !! and an accepted deck carries wave_grid_warn = warn. + CHARACTER(*), INTENT(IN) :: row, message + LOGICAL, INTENT(IN) :: accepted, warn + CHARACTER(*), PARAMETER :: COPY = 'wave_grid_option.dat' + TYPE(CD_AGG_ModuleType), ALLOCATABLE :: agg + CHARACTER(4096) :: line + CHARACTER(1024) :: em + INTEGER :: uin, uout, ios, es + + OPEN (NEWUNIT=uin, FILE=TRIM(deck), STATUS='OLD', ACTION='READ', IOSTAT=ios) + CALL require(ios == 0, 'the deck opens: '//TRIM(deck)) + IF (ios /= 0) RETURN + OPEN (NEWUNIT=uout, FILE=COPY, STATUS='REPLACE', ACTION='WRITE', IOSTAT=ios) + CALL require(ios == 0, 'the deck copy opens') + IF (ios /= 0) THEN + CLOSE (uin) + RETURN + END IF + DO + READ (uin, '(A)', IOSTAT=ios) line + IF (ios /= 0) EXIT + WRITE (uout, '(A)') TRIM(line) + IF (INDEX(line, ' dtM ') > 0 .AND. LEN(row) > 0) WRITE (uout, '(A)') row + END DO + CLOSE (uin) + CLOSE (uout) + ALLOCATE (agg) + CALL CD_AGG_Init_From_Deck(agg, COPY, 0.025_wp, es, em) + IF (accepted) THEN + CALL require(es == CD_AGG_OK, '"'//row//'" is accepted: '//TRIM(em)) + IF (es == CD_AGG_OK) CALL require(agg%wave_grid_warn .EQV. warn, '"'//row//'" sets waveGridCheck') + ELSE + CALL require(es /= CD_AGG_OK .AND. INDEX(em, message) > 0, '"'//row//'" is refused by name: '//TRIM(em)) + END IF + CALL CD_AGG_End(agg, es, em) + END SUBROUTINE check_option + + SUBROUTINE require(ok, what) + LOGICAL, INTENT(IN) :: ok + CHARACTER(*), INTENT(IN) :: what + IF (.NOT. ok) THEN + nfail = nfail + 1 + WRITE (*, '(A)') 'FAIL: '//what + END IF + END SUBROUTINE require + +END PROGRAM test_wave_grid diff --git a/validation/scripts/openfast_wave_grid_guard.py b/validation/scripts/openfast_wave_grid_guard.py new file mode 100644 index 00000000..a410b710 --- /dev/null +++ b/validation/scripts/openfast_wave_grid_guard.py @@ -0,0 +1,224 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +"""Coupled check of the SeaState wave-grid guard (OPTIONS waveGridCheck) in OpenFAST. + +The IEA-15 MW UMaine model of the OpenFAST tutorial (the r-test ``MD_Shared`` turbine-1 files, +pose reset as in doc/tutorial_openfast.rst) runs with ``examples/openfast/CableDyn_UMaine.dat`` +under SeaState grids that do and do not serve its lines. Every case is short (``TMax`` 1 s, the +mid-run case 60 s) and its grid small (``WaveTMax`` 200 s), so the whole set needs well under +1 GB. + +Cases that must STOP by default (``waveGridCheck error``) and RUN with ``waveGridCheck warn``: + + outside the MD_Shared grid (100 m half-widths, 40 m deep): nodes outside at t = 0; + ny2_oblique a grid covering the lines with NY = 2 under long-crested waves at 30 deg; + ny2_short the same grid under a short-crested sea (WaveDirMod 1, 5 directions over 60 deg); + midrun one 178 m chain from a platform point at x = 58 m to an anchor 176 m below and + 18 m inboard, the platform's only line, on a grid 2 m wider in x than that point: + the platform drifts down-wave (+x, about 8 m in 60 s) and carries nodes out during + the run, which stops at t > 0. + +Cases that must RUN by default, with no guard message: + + ny2_along_x the covering grid with NY = 2 under waves at 0 deg (the tutorial grid); + nx2_along_y NX = 2, NY = 37 under waves at 90 deg. + +Each stopping case's message must name the time, a line, the node count, the deepest and the +shallowest node, and the option that downgrades it. With ``--base-exe`` (an openfast.exe built +with the CableDyn sources before the guard), the two running cases and the ``outside`` and +``ny2_oblique`` cases under ``warn`` (which the earlier build only warned about, or did not check) +must give the same ``.out`` and ``.CD.out`` data rows as that build, byte for byte. + +usage: openfast_wave_grid_guard.py --exe --case-dir + --work [--base-exe ] +""" + +from __future__ import annotations + +import argparse +import re +import shutil +import subprocess +import sys +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +ED = "IEA-15-240-RWT-UMaineSemi_ElastoDynT1.dat" +HD = "IEA-15-240-RWT-UMaineSemi_HydroDynT1.dat" +SS = "SeaState.dat" +FST = "case.fst" +DECK = "CableDyn_UMaine.dat" + +COVER = {"X_HalfWidth": "900", "Y_HalfWidth": "900", "Z_Depth": '"default"', "NX": "37", "NY": "2", "NZ": "11"} +LIGHT = {"WaveTMax": "200"} + +HANGING_DECK = """--------------------- CableDyn Input File ------------------------------------ +One chain from a point of the IEA-15 MW UMaine platform at x = 58 m to an anchor below it (wave-grid guard) +--------------------------- LINE TYPES ---------------------------------------- +Name Diam Mass EA BA EI Cdn Cdt Can Cat +(-) (m) (kg/m) (N) (-) (Nm2) (-) (-) (-) (-) +main 0.333 685.00 3.27e9 -1.0 0.0 2.0 0.4 0.82 0.27 +--------------------------- POINTS -------------------------------------------- +ID Type X Y Z +(-) (-) (m) (m) (m) +1 Coupled 58.000 0.000 -14.000 +2 Fixed 40.000 0.000 -190.000 +--------------------------- LINES --------------------------------------------- +ID NodeA NodeB Outputs +(-) (-) (-) (-) +1 1 2 - +--------------------------- SECTIONS ------------------------------------------ +LineID LineType Length NumSegs +(-) (-) (m) (-) +1 main 178.0 30 +--------------------------- OPTIONS ------------------------------------------- +3.0e6 kBot - Seabed penalty stiffness base (Pa/m) +3.0e5 cBot - Seabed normal damping base (Pa-s/m) +0.025 dtM - CableDyn internal time step (s) +--------------------------- OUTPUTS ------------------------------------------- +"FairTen1" +END +--------------------------- need this line ------------------------------------ +""" + +# case: (SeaState edits, deck, TMax, stops by default) +CASES = { + "outside": ({**LIGHT}, DECK, 1.0, True), + "ny2_oblique": ({**COVER, **LIGHT, "WaveDir": "30"}, DECK, 1.0, True), + "ny2_short": ( + {**COVER, **LIGHT, "WaveDirMod": "1", "WaveDirSpread": "1", "WaveNDir": "5", "WaveDirRange": "60"}, + DECK, + 1.0, + True, + ), + "midrun": ( + {**LIGHT, "X_HalfWidth": "60", "Y_HalfWidth": "60", "Z_Depth": '"default"', "NX": "7", "NY": "7", "NZ": "11"}, + "hanging.dat", + 60.0, + True, + ), + "ny2_along_x": ({**COVER, **LIGHT}, DECK, 1.0, False), + "nx2_along_y": ({**COVER, **LIGHT, "NX": "2", "NY": "37", "WaveDir": "90"}, DECK, 1.0, False), +} +BIT_IDENTICAL = [("ny2_along_x", "error"), ("nx2_along_y", "error"), ("outside", "warn"), ("ny2_oblique", "warn")] + + +def set_value(path: Path, key: str, value: str) -> None: + """Replace the value of the one row `` ...`` of an OpenFAST input file.""" + lines = path.read_text(encoding="latin-1").splitlines() # byte for byte + pattern = re.compile(rf"^(\s*)(\S+)(\s+{re.escape(key)}\b)") + hits = [i for i, line in enumerate(lines) if pattern.match(line)] + if len(hits) != 1: + raise SystemExit(f"{path.name}: expected one {key} row, found {len(hits)}") + lines[hits[0]] = pattern.sub(lambda m: f"{m.group(1)}{value}{m.group(3)}", lines[hits[0]]) + path.write_text("\n".join(lines) + "\n", encoding="latin-1") + + +def prepare(case_dir: Path, work: Path, name: str, mode: str) -> Path: + """A case folder: the turbine files with the pose reset, the SeaState edits and the deck.""" + edits, deck, tmax, _ = CASES[name] + folder = work / f"{name}_{mode}" + if folder.exists(): + shutil.rmtree(folder) + shutil.copytree(case_dir, folder) + for key in ("PtfmSurge", "PtfmSway", "PtfmHeave", "PtfmRoll", "PtfmPitch", "PtfmYaw"): + set_value(folder / ED, key, "0") + set_value(folder / HD, "PtfmRefY", "0") + for key, value in edits.items(): + set_value(folder / SS, key, value) + shutil.copy(ROOT / "examples/openfast/IEA-15-UMaine_CompMooring5_CableDyn.fst", folder / FST) + set_value(folder / FST, "TMax", str(tmax)) + if deck == DECK: + text = (ROOT / "examples/openfast" / DECK).read_text(encoding="utf-8") + else: + text = HANGING_DECK + set_value(folder / FST, "MooringFile", f'"{deck}"') + if mode == "warn": + text = re.sub(r"(?m)^(\S+\s+dtM\b.*)$", r"\1\nwarn waveGridCheck - downgrade the wave-grid guard", text, count=1) + (folder / deck).write_text(text, encoding="ascii") + return folder + + +def run(exe: Path, folder: Path) -> tuple[int, str]: + proc = subprocess.run([str(exe), FST], cwd=folder, capture_output=True, text=True, errors="replace") + return proc.returncode, proc.stdout + proc.stderr + + +def data_rows(path: Path) -> list[str]: + """The rows of an output table from its 'Time' header on (the preamble names the build).""" + lines = path.read_text(encoding="utf-8", errors="replace").splitlines() + start = next((i for i, line in enumerate(lines) if line.split()[:1] == ["Time"]), 0) + return lines[start:] + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) + parser.add_argument("--exe", type=Path, required=True) + parser.add_argument("--case-dir", type=Path, required=True) + parser.add_argument("--work", type=Path, required=True) + parser.add_argument("--base-exe", type=Path) + args = parser.parse_args() + args.work.mkdir(parents=True, exist_ok=True) + failures: list[str] = [] + + for name, (_, deck, _, stops) in CASES.items(): + for mode in ("error", "warn") if stops else ("error",): + folder = prepare(args.case_dir, args.work, name, mode) + code, log = run(args.exe, folder) + (folder / "run.log").write_text(log, encoding="utf-8") + log = " ".join(log.split()) # OpenFAST wraps the messages + guard = re.search(r"CableDyn mooring module: (\d+ of the \d+ CableDyn sampling nodes|the SeaState wave-kin)", log) + tag = f"{name} [{mode}]" + if stops and mode == "error": + ok = code != 0 and guard is not None and "waveGridCheck warn" in log + ok = ok and re.search(r"line \d+, \d+ nodes?, (deepest at|at) \(x, y, z\)", log) is not None + if name != "midrun" and "lie outside" in log: + ok = ok and "at t = 0 s" in log + if name == "midrun": + times = [float(t) for t in re.findall(r"wave-kinematics grid at t = ([0-9.Ee+-]+) s", log)] + ok = ok and bool(times) and times[0] > 0.0 + if name.startswith("ny2"): + ok = ok and "NY = 2 (3 points" in log + if name == "outside": + ok = ok and "shallowest at" in log + print(f"{tag:22s} exit {code}: {'stops as required' if ok else 'FAIL'}") + elif stops: + ok = code == 0 and "OpenFAST terminated normally" in log and guard is not None + print(f"{tag:22s} exit {code}: {'runs with the warning' if ok else 'FAIL'}") + else: + ok = code == 0 and "OpenFAST terminated normally" in log and guard is None + print(f"{tag:22s} exit {code}: {'runs, no guard message' if ok else 'FAIL'}") + if not ok: + failures.append(tag) + print(" ..." + log[-2000:]) + + if args.base_exe: + for name, mode in BIT_IDENTICAL: + new = args.work / f"{name}_{mode}" + base = prepare(args.case_dir, args.work, name, f"{mode}_base") + if mode == "warn": # the earlier build knows no waveGridCheck: run it without the row + deck_path = base / CASES[name][1] + deck_path.write_text( + re.sub(r"(?m)^warn\s+waveGridCheck.*\n", "", deck_path.read_text(encoding="ascii")), encoding="ascii" + ) + code, log = run(args.base_exe, base) + (base / "run.log").write_text(log, encoding="utf-8") + same = code == 0 + for suffix in (".out", ".CD.out"): + a, b = new / f"case{suffix}", base / f"case{suffix}" + same = same and a.exists() and b.exists() and data_rows(a) == data_rows(b) + tag = f"{name} [{mode}] vs base" + print(f"{tag:22s} {'bit-identical data rows' if same else 'FAIL: differs'}") + if not same: + failures.append(tag) + + if failures: + print("FAIL: " + ", ".join(failures)) + return 1 + print("PASS: the wave-grid guard stops, warns and passes as required") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) From c09e755522f451cac57893efa1cb1512c95d3910 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Wed, 2 Dec 2026 16:07:55 +0900 Subject: [PATCH 2/3] fix: stop on NX or NY = 2 under a crossing sea wherever the lines lie The resolution check exempted a node in the water within 1 % of the grid spacing of a grid line across the coarse axis. On a coarse axis that spacing is the half-width, so the exemption could reach several metres: under an oblique sea a node 9 m off y = 0 is already wrong in phase by k 9 sin(beta), which the grid cannot represent, and the check ran only at the start, while the sea sways the lines off the grid line during the run. The hull's Morison members read the same grid and are interpolated across the axis too, which CableDyn cannot see node by node. The check now stops the run (one warning under waveGridCheck warn) whenever the grid has NX = 2 or NY = 2 under waves that vary along that axis and the lines sample the grid in the water at all, and its message lists those nodes by line. CD_WaveGrid_Off_Vertex, which only this exemption used, is removed with its tests. The coupled check requires that a line along y = 0 is now reported with the others. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 5 ++- doc/openfast.rst | 27 ++++++------ doc/options.rst | 2 +- doc/troubleshooting.rst | 5 ++- src/CableDyn_WaveGrid.f90 | 21 +-------- src/openfast/CableDyn_OF.f90 | 44 +++++++------------ tests/test_wave_grid.f90 | 22 +--------- .../scripts/openfast_wave_grid_guard.py | 6 ++- 8 files changed, 46 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f8131ad..ea3371ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,8 +16,9 @@ All notable changes to CableDyn are recorded in this file. The format follows where SeaState gives it the kinematics of the grid boundary; the message gives the time and, line by line, the number of such nodes and the deepest and shallowest of them. It also stops at the start when the grid has `NX = 2` or `NY = 2` (three points across that axis) under waves that vary along the axis - (a long-crested sea not along the other axis, within 1e-4 deg, or a short-crested sea) and line nodes in - the water lie between the grid points, where SeaState interpolates across a large part of a wavelength. + (a long-crested sea not along the other axis, within 1e-4 deg, or a short-crested sea) while the lines + sample the grid in the water: SeaState then interpolates across a large part of a wavelength for every + line node and hull member, also near a grid line, from which the sea sways the lines. A grid with `NY = 2` under waves along x, or `NX = 2` under waves along y, still runs. The new `OPTIONS waveGridCheck warn` turns both checks into the former warnings (`error`, the default, stops). The r-test `MD_Shared` SeaState file of the OpenFAST tutorial, which covers only the platform, now stops diff --git a/doc/openfast.rst b/doc/openfast.rst index cc2a4483..438588ce 100644 --- a/doc/openfast.rst +++ b/doc/openfast.rst @@ -202,27 +202,28 @@ At initialisation CableDyn also checks the grid against the directions of the se ``NX = 2`` or ``NY = 2`` has three points along that axis, ``X_HalfWidth`` (or ``Y_HalfWidth``) apart, and SeaState interpolates the kinematics across the axis between them. That is exact only for waves that do not vary along the axis: ``NY = 2`` for a long-crested sea along x and -``NX = 2`` for one along y, each within 1e-4°. Under any other sea, with line nodes in the water -between the grid points across that axis, the run stops by default: +``NX = 2`` for one along y, each within 1e-4°. Under any other sea, when the lines sample the grid +in the water at all, the run stops by default: .. code-block:: text CableDyn mooring module: the SeaState wave-kinematics grid has NY = 2 (3 points 900 m apart in y) under long-crested waves at 30 deg, which vary along that axis: SeaState interpolates them between the three grid points, over distances that are a large part of a wavelength or more, - and 102 of the 153 CableDyn sampling nodes in the water lie between grid points there. By line: - line 2, 51 nodes, deepest at (x, y, z) = (367.78, 637.01, -200.01) m, shallowest at (x, y, z) = - (29, 50.229, -14) m; line 3, ... . A grid with NY = 2 represents only waves along x (0 or 180 deg) - and one with NX = 2 only waves along y (90 or 270 deg), within 1e-4 deg; in the SeaState input - file raise the count so that the spacing resolves the shortest wavelength that matters at the - lines (a tenth of it or finer). To run on with the interpolated kinematics, set waveGridCheck - warn in the OPTIONS of the CableDyn deck. - + for the hull members and for the lines, which sample the grid in the water at 153 CableDyn + nodes. By line: line 1, 51 nodes, deepest at (x, y, z) = (-735.56, 0, -200.01) m, shallowest at + (x, y, z) = (-58, 0, -14) m; line 2, ... ; line 3, ... . A grid with NY = 2 represents only + waves along x (0 or 180 deg) and one with NX = 2 only waves along y (90 or 270 deg), within + 1e-4 deg; in the SeaState input file raise the count so that the spacing resolves the shortest + wavelength that matters at the lines (a tenth of it or finer). To run on with the interpolated + kinematics, set waveGridCheck warn in the OPTIONS of the CableDyn deck. The directions are those of SeaState's wave components (the spread of ``WaveDirMod = 1``, the -component directions of ``WaveMod = 7``), or ``WaveDir`` for ``WaveMod = 6``; a node on a grid -line across the coarse axis, such as a line at ``y = 0``, takes the grid values there exactly and -is not counted. ``waveGridCheck warn`` turns this check into a warning too. +component directions of ``WaveMod = 7``), or ``WaveDir`` for ``WaveMod = 6``. A line lying on a +grid line across the coarse axis, such as one along ``y = 0``, is no exception: a node off it by a +small part of the half-width is already wrong in phase, and the sea sways the line off it. The +hull's Morison members read the same grid, so their kinematics are interpolated across the axis +too. ``waveGridCheck warn`` turns this check into a warning. Only nodes in the water are checked: a node above the free surface carries no fluid load, whatever kinematics SeaState would give it, so a suspended cable or jumper above the water may diff --git a/doc/options.rst b/doc/options.rst index e0c4e645..0c05450a 100644 --- a/doc/options.rst +++ b/doc/options.rst @@ -579,7 +579,7 @@ Finite-EI cable controls - ``error`` or ``warn`` (case-insensitive). The checks of the SeaState grid the lines take their wave and current kinematics from: a line node in the water outside the grid (at the static start or at any CableDyn step), and ``NX = 2`` or ``NY = 2`` under waves that vary along that - axis with line nodes in the water between the grid points (at the start). ``error`` stops the + axis while the lines sample the grid in the water (at the start). ``error`` stops the run with a message that gives the time and, by line, the nodes concerned; ``warn`` warns once and runs on with SeaState's kinematics there (see :ref:`openfast:SeaState grid`) - OpenFAST (a run that samples SeaState); accepted and unused elsewhere diff --git a/doc/troubleshooting.rst b/doc/troubleshooting.rst index 4fa695e9..4c815711 100644 --- a/doc/troubleshooting.rst +++ b/doc/troubleshooting.rst @@ -715,8 +715,9 @@ Warnings and notes that do not stop a run in y) under ...`` (OpenFAST; an error, or with ``waveGridCheck warn`` a warning) - the grid has three points across an axis along which the waves vary: ``NY = 2`` under a sea not along x, or ``NX = 2`` under a sea not along y (a long-crested sea at another - heading, or a short-crested sea), and line nodes in the water lie between the grid points, - where SeaState interpolates across a large part of a wavelength. Raise ``NY`` (or ``NX``) so + heading, or a short-crested sea), while the lines sample the grid in the water. SeaState + interpolates across a large part of a wavelength for every line node and hull member, also + near a grid line, from which the sea sways the lines. Raise ``NY`` (or ``NX``) so that the spacing resolves the shortest wavelength that matters at the lines. See :ref:`openfast:SeaState grid`. * - ``Note: LINE is stretched to a static strain of ... % at the fairlead`` diff --git a/src/CableDyn_WaveGrid.f90 b/src/CableDyn_WaveGrid.f90 index cf39ecea..9c117c27 100644 --- a/src/CableDyn_WaveGrid.f90 +++ b/src/CableDyn_WaveGrid.f90 @@ -3,7 +3,7 @@ ! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University MODULE CableDyn_WaveGrid !! The rules by which the coupled route judges a gridded wave field (the OpenFAST SeaState - !! grid) against the sea it carries and the nodes that sample it: the wave-grid guard of the + !! grid) against the sea it carries: the wave-grid guard of the !! OpenFAST shell (check_wavefield_grid and check_wavefield_resolution in !! src/openfast/CableDyn_OF.f90, OPTION waveGridCheck). Pure functions of plain numbers, so !! the rules are tested without OpenFAST (tests/test_wave_grid.f90). @@ -26,7 +26,7 @@ MODULE CableDyn_WaveGrid IMPLICIT NONE PRIVATE - PUBLIC :: CD_WaveGrid_Along_Axis, CD_WaveGrid_Coarse_Axes, CD_WaveGrid_Off_Vertex + PUBLIC :: CD_WaveGrid_Along_Axis, CD_WaveGrid_Coarse_Axes !> the tolerance on a wave direction taken as along a grid axis (deg) REAL(wp), PARAMETER, PUBLIC :: CD_WAVEGRID_DIR_TOL = 1.0E-4_wp @@ -74,21 +74,4 @@ PURE SUBROUTINE CD_WaveGrid_Coarse_Axes(half_nodes, directions, coarse) END DO END SUBROUTINE CD_WaveGrid_Coarse_Axes - PURE LOGICAL FUNCTION CD_WaveGrid_Off_Vertex(c, lo, delta, npts, tol) RESULT(off) - !! Whether the coordinate c lies inside the grid axis of npts points lo + k delta - !! (k = 0 .. npts - 1) but more than tol from every point, so that the grid interpolates - !! there. A coordinate outside the axis by more than tol is not off a vertex: the grid gives it - !! the boundary point's kinematics, which the out-of-grid check reports. - REAL(wp), INTENT(IN) :: c, lo, delta, tol - INTEGER, INTENT(IN) :: npts - REAL(wp) :: s, hi - - off = .FALSE. - IF (npts < 2 .OR. .NOT. (delta > 0.0_wp)) RETURN - hi = lo + REAL(npts - 1, wp)*delta - IF (c < lo - tol .OR. c > hi + tol) RETURN - s = (c - lo)/delta - off = ABS(s - ANINT(s))*delta > tol - END FUNCTION CD_WaveGrid_Off_Vertex - END MODULE CableDyn_WaveGrid diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index a5dfdab0..50cd46a4 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -137,7 +137,7 @@ MODULE CableDyn CD_Recompute_System_Acceleration, CD_SYSTEM_OK USE SeaSt_WaveField, ONLY: WaveField_GetNodeWaveKin USE SeaSt_WaveField_Types, ONLY: WaveMod_None, WaveMod_ExtFull - USE CableDyn_WaveGrid, ONLY: CD_WaveGrid_Coarse_Axes, CD_WaveGrid_Off_Vertex, CD_WAVEGRID_DIR_TOL, & + USE CableDyn_WaveGrid, ONLY: CD_WaveGrid_Coarse_Axes, CD_WAVEGRID_DIR_TOL, & CD_WAVEGRID_COARSE_HALF_NODES USE IfW_FlowField_Types, ONLY: Grid3D_FieldType @@ -2549,19 +2549,20 @@ SUBROUTINE check_wavefield_resolution( inst_e, wf, ErrStat, ErrMsg ) !! (CableDyn_WaveGrid). That is exact only for waves that do not vary along x, a long-crested !! sea travelling along y; likewise NY = 2 only for a sea along x. Under any other sea -- a !! long-crested one in another direction, a short-crested one, or components in several - !! directions -- the sampling nodes in the water between grid points across that axis receive - !! an interpolation over a large part of a wavelength, wrong in amplitude and phase. + !! directions -- every point interpolated across that axis, the line nodes and the hull's Morison + !! members alike, receives an interpolation over a large part of a wavelength, wrong in + !! amplitude and phase. A node near a grid line at Init is no exception: one off it by a small + !! part of the half-width is already wrong in phase, and the sea sways the lines off it. !! !! The sea's directions are those of its first-order components with a nonzero amplitude !! (WaveDirArr where WaveElevC0 is nonzero: one direction for a long-crested sea, the spread !! of WaveDirMod 1, the component directions of WaveMod 7), or WaveDir where SeaState keeps no !! components (WaveMod 6 reads the kinematics themselves). A direction is along an axis - !! within CD_WAVEGRID_DIR_TOL (1e-4 deg). Checked on the static positions just sampled, with - !! the wet-node rule of check_wavefield_grid; nodes outside the grid are left to that check. - !! A node on a grid line across the coarse axis (within 1 % of the spacing) is exact there - !! and not flagged. + !! within CD_WAVEGRID_DIR_TOL (1e-4 deg). It applies when the lines sample the grid in the + !! water, by the wet-node rule of check_wavefield_grid on the static positions just sampled; + !! the message lists those nodes by line. !! - !! Under OPTION waveGridCheck error (the default) a flagged node is a fatal error; under warn + !! Under OPTION waveGridCheck error (the default) it is a fatal error; under warn !! a warning, written to the screen too (the glue drops Init warnings). Only the waves are !! concerned: SeaState's current is uniform in x and y. TYPE(CD_OF_Instance), INTENT(INOUT) :: inst_e @@ -2571,9 +2572,9 @@ SUBROUTINE check_wavefield_resolution( inst_e, wf, ErrStat, ErrMsg ) character(*), parameter :: RoutineName = 'check_wavefield_resolution' CHARACTER(1), PARAMETER :: AXIS_NAME(2) = ['x', 'y'], AXIS_UPPER(2) = ['X', 'Y'] - LOGICAL :: coarse(2), fatal, inside - INTEGER(IntKi) :: i, k, i0, i1, ndir, nflag, nwet, room, half(2) - REAL(wp) :: lo(2), delta(2), tol(2), surface, dmin, dmax + LOGICAL :: coarse(2), fatal + INTEGER(IntKi) :: i, k, i0, i1, ndir, nwet, room, half(2) + REAL(wp) :: delta(2), surface, dmin, dmax REAL(wp), ALLOCATABLE :: dirs(:) CHARACTER(:), ALLOCATABLE :: head, sea, grid, fix, option, by_line, msg @@ -2582,9 +2583,7 @@ SUBROUTINE check_wavefield_resolution( inst_e, wf, ErrStat, ErrMsg ) IF (.NOT. (inst_e%agg%host_wave_enabled .AND. wf%WaveMod /= WaveMod_None)) RETURN DO k = 1, 2 half(k) = (wf%VolGridParams%n(k + 1) + 1_IntKi)/2_IntKi - lo(k) = REAL(wf%VolGridParams%pZero(k + 1), wp) delta(k) = REAL(wf%VolGridParams%delta(k + 1), wp) - tol(k) = 0.01_wp*delta(k) END DO IF (ALL(half > CD_WAVEGRID_COARSE_HALF_NODES)) RETURN @@ -2609,8 +2608,7 @@ SUBROUTINE check_wavefield_resolution( inst_e, wf, ErrStat, ErrMsg ) CALL CD_WaveGrid_Coarse_Axes( half, dirs(1:ndir), coarse ) IF (.NOT. ANY(coarse)) RETURN - ! the nodes in the water between grid points across a coarse axis - nflag = 0_IntKi + ! the nodes that sample the grid in the water nwet = 0_IntKi DO i = 1, inst_e%nfluid inst_e%fx_flag(i) = .FALSE. @@ -2618,17 +2616,9 @@ SUBROUTINE check_wavefield_resolution( inst_e, wf, ErrStat, ErrMsg ) IF (wf%WaveStMod == 0_IntKi) surface = MIN(surface, 0.0_wp) IF (inst_e%fx_xyz(3, i) > surface) CYCLE nwet = nwet + 1_IntKi - inside = .FALSE. - DO k = 1, 2 - IF (coarse(k)) inside = inside .OR. CD_WaveGrid_Off_Vertex( inst_e%fx_xyz(k, i), lo(k), delta(k), & - wf%VolGridParams%n(k + 1), tol(k) ) - END DO - IF (inside) THEN - nflag = nflag + 1_IntKi - inst_e%fx_flag(i) = .TRUE. - END IF + inst_e%fx_flag(i) = .TRUE. END DO - IF (nflag == 0_IntKi) RETURN + IF (nwet == 0_IntKi) RETURN dmin = MINVAL(dirs(1:ndir)) dmax = MAXVAL(dirs(1:ndir)) @@ -2649,8 +2639,8 @@ SUBROUTINE check_wavefield_resolution( inst_e, wf, ErrStat, ErrMsg ) fatal = .NOT. inst_e%agg%wave_grid_warn head = 'CableDyn mooring module: the SeaState wave-kinematics grid has '//grid//' under '//sea// & ', which vary along that axis: SeaState interpolates them between the three grid points, '// & - 'over distances that are a large part of a wavelength or more, and '//TRIM(Num2LStr(nflag))//' of the '// & - TRIM(Num2LStr(nwet))//' CableDyn sampling nodes in the water lie between grid points there.' + 'over distances that are a large part of a wavelength or more, for the hull members and for '// & + 'the lines, which sample the grid in the water at '//TRIM(Num2LStr(nwet))//' CableDyn nodes.' fix = ' A grid with NY = 2 represents only waves along x (0 or 180 deg) and one with NX = 2 only '// & 'waves along y (90 or 270 deg), within 1e-4 deg; in the SeaState input file raise the count so '// & 'that the spacing resolves the shortest wavelength that matters at the lines (a tenth of it '// & diff --git a/tests/test_wave_grid.f90 b/tests/test_wave_grid.f90 index 11f6a0c5..9cefa941 100644 --- a/tests/test_wave_grid.f90 +++ b/tests/test_wave_grid.f90 @@ -8,14 +8,11 @@ PROGRAM test_wave_grid !! * NY = 2 is coarse for every long-crested sea not along x (30, 60 and 90 deg) and for a !! short-crested sea; NX = 2 for every sea not along y; an aligned sea (NY = 2 at 0 or !! 180 deg, NX = 2 at 90 or 270 deg) and a finer grid (NX = NY = 3) are never coarse; - !! * a coordinate is off a vertex only inside the axis and more than the tolerance from every - !! grid point; !! * OPTION waveGridCheck reaches the coupled aggregate (the mixed IEA-15 MW example deck, the !! first argument): error by default and as written, warn as written, any other value is !! refused by name. USE CableDyn_Precision, ONLY: wp - USE CableDyn_WaveGrid, ONLY: CD_WaveGrid_Along_Axis, CD_WaveGrid_Coarse_Axes, CD_WaveGrid_Off_Vertex, & - CD_WAVEGRID_DIR_TOL + USE CableDyn_WaveGrid, ONLY: CD_WaveGrid_Along_Axis, CD_WaveGrid_Coarse_Axes, CD_WAVEGRID_DIR_TOL USE CableDyn_OpenFAST_Aggregate, ONLY: CD_AGG_ModuleType, CD_AGG_Init_From_Deck, CD_AGG_End, CD_AGG_OK USE, INTRINSIC :: IEEE_ARITHMETIC, ONLY: IEEE_VALUE, IEEE_QUIET_NAN IMPLICIT NONE @@ -88,21 +85,6 @@ PROGRAM test_wave_grid CALL CD_WaveGrid_Coarse_Axes([2, 2], spread(1:0), coarse) CALL require(.NOT. ANY(coarse), 'a sea with no component is never coarse') - ! nodes between grid points: the axis -45, 0, 45 m (NY = 2, Y_HalfWidth = 45 m), tolerance 0.45 m - CALL require(.NOT. CD_WaveGrid_Off_Vertex(0.0_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), 'y = 0 is a vertex') - CALL require(.NOT. CD_WaveGrid_Off_Vertex(-45.0_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), 'y = -45 m is a vertex') - CALL require(.NOT. CD_WaveGrid_Off_Vertex(44.6_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), & - 'y = 44.6 m is within the tolerance of a vertex') - CALL require(CD_WaveGrid_Off_Vertex(44.5_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), 'y = 44.5 m is off the vertices') - CALL require(CD_WaveGrid_Off_Vertex(20.0_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), 'y = 20 m is off the vertices') - CALL require(CD_WaveGrid_Off_Vertex(-22.5_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), 'y = -22.5 m is off the vertices') - CALL require(.NOT. CD_WaveGrid_Off_Vertex(45.3_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), & - 'y = 45.3 m is within the tolerance of the edge') - CALL require(.NOT. CD_WaveGrid_Off_Vertex(60.0_wp, -45.0_wp, 45.0_wp, 3, 0.45_wp), & - 'y = 60 m is outside the grid, not off a vertex') - CALL require(.NOT. CD_WaveGrid_Off_Vertex(20.0_wp, -45.0_wp, 45.0_wp, 1, 0.45_wp), 'a one-point axis has no interior') - CALL require(.NOT. CD_WaveGrid_Off_Vertex(20.0_wp, -45.0_wp, 0.0_wp, 3, 0.45_wp), 'a zero spacing has no interior') - ! the deck option, through the aggregate the OpenFAST shell reads it from IF (COMMAND_ARGUMENT_COUNT() < 1) THEN WRITE (*, '(A)') 'FAIL: the mixed example deck path argument is required' @@ -119,7 +101,7 @@ PROGRAM test_wave_grid WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' ERROR STOP 1 END IF - WRITE (*, '(A)') 'PASS: the wave-grid guard rules (directions along the axes, coarse axes, off-vertex nodes) '// & + WRITE (*, '(A)') 'PASS: the wave-grid guard rules (directions along the axes, coarse axes) '// & 'and OPTION waveGridCheck' CONTAINS diff --git a/validation/scripts/openfast_wave_grid_guard.py b/validation/scripts/openfast_wave_grid_guard.py index a410b710..6a7804ea 100644 --- a/validation/scripts/openfast_wave_grid_guard.py +++ b/validation/scripts/openfast_wave_grid_guard.py @@ -12,7 +12,8 @@ Cases that must STOP by default (``waveGridCheck error``) and RUN with ``waveGridCheck warn``: outside the MD_Shared grid (100 m half-widths, 40 m deep): nodes outside at t = 0; - ny2_oblique a grid covering the lines with NY = 2 under long-crested waves at 30 deg; + ny2_oblique a grid covering the lines with NY = 2 under long-crested waves at 30 deg (line 1, which + lies along y = 0, is reported with the others); ny2_short the same grid under a short-crested sea (WaveDirMod 1, 5 directions over 60 deg); midrun one 178 m chain from a platform point at x = 58 m to an anchor 176 m below and 18 m inboard, the platform's only line, on a grid 2 m wider in x than that point: @@ -179,7 +180,8 @@ def main() -> int: times = [float(t) for t in re.findall(r"wave-kinematics grid at t = ([0-9.Ee+-]+) s", log)] ok = ok and bool(times) and times[0] > 0.0 if name.startswith("ny2"): - ok = ok and "NY = 2 (3 points" in log + # every line sampling the grid in the water counts, line 1 along y = 0 too + ok = ok and "NY = 2 (3 points" in log and "line 1, 51 nodes" in log if name == "outside": ok = ok and "shallowest at" in log print(f"{tag:22s} exit {code}: {'stops as required' if ok else 'FAIL'}") From d5df27290bc1d5ce60d87e3086446e7ad3702c0b Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Wed, 2 Dec 2026 16:49:03 +0900 Subject: [PATCH 3/3] fix: judge supplied WaveMod 6 kinematics on a coarse grid from the data For externally supplied wave kinematics (SeaState WaveMod 6) the guard took the sea's direction from WaveDir, which SeaState does not use in that mode: the heading lives in the supplied grid data. A valid field travelling along y on an NX = 2 grid then stopped at initialisation because the unused WaveDir was 0, and a crossing field could pass on an unrelated WaveDir. With WaveMod 6 a coarse axis (NX or NY = 2) is now judged from the supplied WaveVel and WaveAcc themselves: the run stops when they differ between the three grid points across that axis by more than 1e-5 of their largest magnitude, and a field that is the same along the axis passes. A non-finite value counts as differing. The rule is a pure function in CableDyn_WaveGrid (CD_WaveGrid_Field_Varies) with unit tests, and the coupled guard script gains two WaveMod 6 cases written from an Airy wave with WaveDir left at 0: at 30 deg on NY = 2 it stops by default and runs with waveGridCheck warn, at 0 deg it runs. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 3 +- doc/openfast.rst | 6 +- src/CableDyn_WaveGrid.f90 | 68 +++++++++++++++- src/openfast/CableDyn_OF.f90 | 36 +++++++-- tests/test_wave_grid.f90 | 53 ++++++++++++- .../scripts/openfast_wave_grid_guard.py | 79 ++++++++++++++++++- 6 files changed, 231 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea3371ce..cdbd2171 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,8 @@ All notable changes to CableDyn are recorded in this file. The format follows where SeaState gives it the kinematics of the grid boundary; the message gives the time and, line by line, the number of such nodes and the deepest and shallowest of them. It also stops at the start when the grid has `NX = 2` or `NY = 2` (three points across that axis) under waves that vary along the axis - (a long-crested sea not along the other axis, within 1e-4 deg, or a short-crested sea) while the lines + (a long-crested sea not along the other axis, within 1e-4 deg, a short-crested sea, or supplied + `WaveMod 6` kinematics that differ across the axis, judged from the data) while the lines sample the grid in the water: SeaState then interpolates across a large part of a wavelength for every line node and hull member, also near a grid line, from which the sea sways the lines. A grid with `NY = 2` under waves along x, or `NX = 2` under waves along y, still runs. The new diff --git a/doc/openfast.rst b/doc/openfast.rst index 438588ce..3aa63b8c 100644 --- a/doc/openfast.rst +++ b/doc/openfast.rst @@ -219,7 +219,11 @@ in the water at all, the run stops by default: kinematics, set waveGridCheck warn in the OPTIONS of the CableDyn deck. The directions are those of SeaState's wave components (the spread of ``WaveDirMod = 1``, the -component directions of ``WaveMod = 7``), or ``WaveDir`` for ``WaveMod = 6``. A line lying on a +component directions of ``WaveMod = 7``). Externally supplied kinematics (``WaveMod = 6``) have no +components, and SeaState does not use ``WaveDir`` in that mode, so there the supplied ``WaveVel`` +and ``WaveAcc`` are compared across the three grid points of the coarse axis: the check stops the +run when they differ by more than 1e-5 of their largest magnitude, and passes a field that is the +same at every point along that axis (waves along the other axis). A line lying on a grid line across the coarse axis, such as one along ``y = 0``, is no exception: a node off it by a small part of the half-width is already wrong in phase, and the sea sways the line off it. The hull's Morison members read the same grid, so their kinematics are interpolated across the axis diff --git a/src/CableDyn_WaveGrid.f90 b/src/CableDyn_WaveGrid.f90 index 9c117c27..43534e50 100644 --- a/src/CableDyn_WaveGrid.f90 +++ b/src/CableDyn_WaveGrid.f90 @@ -22,14 +22,23 @@ MODULE CableDyn_WaveGrid !! a multiple of 180 deg, each within CD_WAVEGRID_DIR_TOL. At 1e-4 deg, a direction that is !! taken as aligned changes the phase across a half-width h by at most k h sin(1e-4 deg), less !! than 2e-6 k h: 1e-5 rad over half a wavelength. + !! + !! Externally supplied kinematics (SeaState WaveMod 6) carry no component directions, and + !! SeaState does not use WaveDir in that mode: the grid data are the sea. A coarse axis is then + !! judged from the data themselves (CD_WaveGrid_Field_Varies): the field must be the same at + !! every grid point along that axis, within CD_WAVEGRID_FIELD_RTOL of its largest magnitude. USE CableDyn_Precision, ONLY: wp + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: REAL32 IMPLICIT NONE PRIVATE - PUBLIC :: CD_WaveGrid_Along_Axis, CD_WaveGrid_Coarse_Axes + PUBLIC :: CD_WaveGrid_Along_Axis, CD_WaveGrid_Coarse_Axes, CD_WaveGrid_Field_Varies !> the tolerance on a wave direction taken as along a grid axis (deg) REAL(wp), PARAMETER, PUBLIC :: CD_WAVEGRID_DIR_TOL = 1.0E-4_wp + !> the tolerance, relative to the field's largest magnitude, within which supplied grid + !> kinematics count as the same along an axis (single-precision data written as text) + REAL(wp), PARAMETER, PUBLIC :: CD_WAVEGRID_FIELD_RTOL = 1.0E-5_wp !> the largest SeaState NX or NY (points on each half of the axis) that the guard calls coarse INTEGER, PARAMETER, PUBLIC :: CD_WAVEGRID_COARSE_HALF_NODES = 2 @@ -74,4 +83,61 @@ PURE SUBROUTINE CD_WaveGrid_Coarse_Axes(half_nodes, directions, coarse) END DO END SUBROUTINE CD_WaveGrid_Coarse_Axes + PURE LOGICAL FUNCTION CD_WaveGrid_Field_Varies(f, axis, rtol) RESULT(varies) + !! Whether a gridded field f(time, x, y, z, component) -- SeaState's WaveVel or WaveAcc layout + !! -- differs along the grid axis `axis` (1: x, 2: y) by more than rtol times its largest + !! magnitude at any time, point or component. A field that is zero everywhere, or with a single + !! point along the axis, does not vary; nor does any field for an axis other than 1 or 2. A + !! non-finite value along the axis counts as varying. + REAL(REAL32), INTENT(IN) :: f(:, :, :, :, :) + INTEGER, INTENT(IN) :: axis + REAL(wp), INTENT(IN) :: rtol + INTEGER :: it, ix, iy, iz, ic + REAL(wp) :: tol, a, b + + varies = .FALSE. + IF (axis /= 1 .AND. axis /= 2) RETURN + IF (SIZE(f, axis + 1) < 2) RETURN + tol = 0.0_wp + DO ic = 1, SIZE(f, 5) + DO iz = 1, SIZE(f, 4) + DO iy = 1, SIZE(f, 3) + DO ix = 1, SIZE(f, 2) + DO it = 1, SIZE(f, 1) + a = REAL(f(it, ix, iy, iz, ic), wp) + IF (.NOT. (ABS(a) <= HUGE(a))) THEN + varies = .TRUE. + RETURN + END IF + tol = MAX(tol, ABS(a)) + END DO + END DO + END DO + END DO + END DO + tol = rtol*tol + DO ic = 1, SIZE(f, 5) + DO iz = 1, SIZE(f, 4) + DO iy = 1, SIZE(f, 3) + DO ix = 1, SIZE(f, 2) + IF (axis == 1 .AND. ix == 1) CYCLE + IF (axis == 2 .AND. iy == 1) CYCLE + DO it = 1, SIZE(f, 1) + a = REAL(f(it, ix, iy, iz, ic), wp) + IF (axis == 1) THEN + b = REAL(f(it, 1, iy, iz, ic), wp) + ELSE + b = REAL(f(it, ix, 1, iz, ic), wp) + END IF + IF (ABS(a - b) > tol) THEN + varies = .TRUE. + RETURN + END IF + END DO + END DO + END DO + END DO + END DO + END FUNCTION CD_WaveGrid_Field_Varies + END MODULE CableDyn_WaveGrid diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index 50cd46a4..3a58f22e 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -137,8 +137,8 @@ MODULE CableDyn CD_Recompute_System_Acceleration, CD_SYSTEM_OK USE SeaSt_WaveField, ONLY: WaveField_GetNodeWaveKin USE SeaSt_WaveField_Types, ONLY: WaveMod_None, WaveMod_ExtFull - USE CableDyn_WaveGrid, ONLY: CD_WaveGrid_Coarse_Axes, CD_WAVEGRID_DIR_TOL, & - CD_WAVEGRID_COARSE_HALF_NODES + USE CableDyn_WaveGrid, ONLY: CD_WaveGrid_Coarse_Axes, CD_WaveGrid_Field_Varies, CD_WAVEGRID_DIR_TOL, & + CD_WAVEGRID_COARSE_HALF_NODES, CD_WAVEGRID_FIELD_RTOL USE IfW_FlowField_Types, ONLY: Grid3D_FieldType IMPLICIT NONE @@ -2556,9 +2556,12 @@ SUBROUTINE check_wavefield_resolution( inst_e, wf, ErrStat, ErrMsg ) !! !! The sea's directions are those of its first-order components with a nonzero amplitude !! (WaveDirArr where WaveElevC0 is nonzero: one direction for a long-crested sea, the spread - !! of WaveDirMod 1, the component directions of WaveMod 7), or WaveDir where SeaState keeps no - !! components (WaveMod 6 reads the kinematics themselves). A direction is along an axis - !! within CD_WAVEGRID_DIR_TOL (1e-4 deg). It applies when the lines sample the grid in the + !! of WaveDirMod 1, the component directions of WaveMod 7), or WaveDir if no component has an + !! amplitude. A direction is along an axis within CD_WAVEGRID_DIR_TOL (1e-4 deg). Externally + !! supplied kinematics (WaveMod 6) have no components, and SeaState does not use WaveDir in + !! that mode: a coarse axis is then judged from the supplied WaveVel and WaveAcc themselves, + !! which must be the same at the three grid points across it (CD_WaveGrid_Field_Varies, + !! within CD_WAVEGRID_FIELD_RTOL of their largest magnitude). It applies when the lines sample the grid in the !! water, by the wet-node rule of check_wavefield_grid on the static positions just sampled; !! the message lists those nodes by line. !! @@ -2587,6 +2590,19 @@ SUBROUTINE check_wavefield_resolution( inst_e, wf, ErrStat, ErrMsg ) END DO IF (ALL(half > CD_WAVEGRID_COARSE_HALF_NODES)) RETURN + ! externally supplied kinematics (WaveMod 6): no component directions, and SeaState does not + ! use WaveDir in that mode, so a coarse axis is judged from the supplied grid data + IF (wf%WaveMod == WaveMod_ExtFull) THEN + coarse = .FALSE. + DO k = 1, 2 + IF (half(k) > CD_WAVEGRID_COARSE_HALF_NODES) CYCLE + IF (ALLOCATED(wf%WaveVel)) coarse(k) = CD_WaveGrid_Field_Varies( wf%WaveVel, k, CD_WAVEGRID_FIELD_RTOL ) + IF (.NOT. coarse(k) .AND. ALLOCATED(wf%WaveAcc)) & + coarse(k) = CD_WaveGrid_Field_Varies( wf%WaveAcc, k, CD_WAVEGRID_FIELD_RTOL ) + END DO + IF (.NOT. ANY(coarse)) RETURN + END IF + ! the directions of the components the sea carries ndir = 0_IntKi IF (wf%WaveMod /= WaveMod_ExtFull .AND. ALLOCATED(wf%WaveDirArr) .AND. ALLOCATED(wf%WaveElevC0)) THEN @@ -2605,8 +2621,10 @@ SUBROUTINE check_wavefield_resolution( inst_e, wf, ErrStat, ErrMsg ) ndir = 1_IntKi dirs(1) = REAL(wf%WaveDir, wp) END IF - CALL CD_WaveGrid_Coarse_Axes( half, dirs(1:ndir), coarse ) - IF (.NOT. ANY(coarse)) RETURN + IF (wf%WaveMod /= WaveMod_ExtFull) THEN + CALL CD_WaveGrid_Coarse_Axes( half, dirs(1:ndir), coarse ) + IF (.NOT. ANY(coarse)) RETURN + END IF ! the nodes that sample the grid in the water nwet = 0_IntKi @@ -2622,7 +2640,9 @@ SUBROUTINE check_wavefield_resolution( inst_e, wf, ErrStat, ErrMsg ) dmin = MINVAL(dirs(1:ndir)) dmax = MAXVAL(dirs(1:ndir)) - IF (wf%WaveMultiDir) THEN + IF (wf%WaveMod == WaveMod_ExtFull) THEN + sea = 'externally supplied wave kinematics (WaveMod 6) that differ between the grid points across it' + ELSE IF (wf%WaveMultiDir) THEN sea = 'a short-crested sea (directions '//TRIM(Num2LStr(dmin))//' to '//TRIM(Num2LStr(dmax))//' deg)' ELSE IF (dmax - dmin <= CD_WAVEGRID_DIR_TOL) THEN sea = 'long-crested waves at '//TRIM(Num2LStr(dmin))//' deg' diff --git a/tests/test_wave_grid.f90 b/tests/test_wave_grid.f90 index 9cefa941..6bd1a382 100644 --- a/tests/test_wave_grid.f90 +++ b/tests/test_wave_grid.f90 @@ -12,15 +12,18 @@ PROGRAM test_wave_grid !! first argument): error by default and as written, warn as written, any other value is !! refused by name. USE CableDyn_Precision, ONLY: wp - USE CableDyn_WaveGrid, ONLY: CD_WaveGrid_Along_Axis, CD_WaveGrid_Coarse_Axes, CD_WAVEGRID_DIR_TOL + USE CableDyn_WaveGrid, ONLY: CD_WaveGrid_Along_Axis, CD_WaveGrid_Coarse_Axes, CD_WaveGrid_Field_Varies, & + CD_WAVEGRID_DIR_TOL, CD_WAVEGRID_FIELD_RTOL USE CableDyn_OpenFAST_Aggregate, ONLY: CD_AGG_ModuleType, CD_AGG_Init_From_Deck, CD_AGG_End, CD_AGG_OK USE, INTRINSIC :: IEEE_ARITHMETIC, ONLY: IEEE_VALUE, IEEE_QUIET_NAN + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: REAL32 IMPLICIT NONE INTEGER :: nfail, k CHARACTER(1024) :: deck LOGICAL :: coarse(2) REAL(wp) :: spread(7), nan + REAL(REAL32), ALLOCATABLE :: field(:, :, :, :, :) nfail = 0 @@ -85,6 +88,31 @@ PROGRAM test_wave_grid CALL CD_WaveGrid_Coarse_Axes([2, 2], spread(1:0), coarse) CALL require(.NOT. ANY(coarse), 'a sea with no component is never coarse') + ! supplied kinematics (WaveMod 6), judged from the data: f(time, x, y, z, component) on a 3 x 3 x 2 + ! grid, a wave along y (the same at every x), along x, and the same with round-off and a NaN + ALLOCATE (field(4, 3, 3, 2, 3)) + field = 0.0_REAL32 + CALL require(.NOT. (CD_WaveGrid_Field_Varies(field, 1, CD_WAVEGRID_FIELD_RTOL) .OR. & + CD_WaveGrid_Field_Varies(field, 2, CD_WAVEGRID_FIELD_RTOL)), 'a zero field varies along no axis') + CALL wave_along(field, 2) + CALL require(.NOT. CD_WaveGrid_Field_Varies(field, 1, CD_WAVEGRID_FIELD_RTOL), 'a wave along y does not vary along x') + CALL require(CD_WaveGrid_Field_Varies(field, 2, CD_WAVEGRID_FIELD_RTOL), 'a wave along y varies along y') + CALL wave_along(field, 1) + CALL require(CD_WaveGrid_Field_Varies(field, 1, CD_WAVEGRID_FIELD_RTOL), 'a wave along x varies along x') + CALL require(.NOT. CD_WaveGrid_Field_Varies(field, 2, CD_WAVEGRID_FIELD_RTOL), 'a wave along x does not vary along y') + field(2, 1, 3, 1, 1) = field(2, 1, 3, 1, 1)*(1.0_REAL32 + 1.0E-6_REAL32) + CALL require(.NOT. CD_WaveGrid_Field_Varies(field, 2, CD_WAVEGRID_FIELD_RTOL), & + 'a difference below the tolerance does not vary') + field(2, 1, 3, 1, 1) = field(2, 1, 3, 1, 1) + 1.0E-3_REAL32*MAXVAL(ABS(field)) + CALL require(CD_WaveGrid_Field_Varies(field, 2, CD_WAVEGRID_FIELD_RTOL), 'a difference above the tolerance varies') + CALL wave_along(field, 1) + field(3, 2, 2, 2, 2) = REAL(nan, REAL32) + CALL require(CD_WaveGrid_Field_Varies(field, 2, CD_WAVEGRID_FIELD_RTOL), 'a NaN in the field counts as varying') + CALL wave_along(field, 1) + CALL require(.NOT. CD_WaveGrid_Field_Varies(field(:, :, 1:1, :, :), 2, CD_WAVEGRID_FIELD_RTOL), & + 'a single point along the axis does not vary') + CALL require(.NOT. CD_WaveGrid_Field_Varies(field, 3, CD_WAVEGRID_FIELD_RTOL), 'there is no third axis') + ! the deck option, through the aggregate the OpenFAST shell reads it from IF (COMMAND_ARGUMENT_COUNT() < 1) THEN WRITE (*, '(A)') 'FAIL: the mixed example deck path argument is required' @@ -146,6 +174,29 @@ SUBROUTINE check_option(row, accepted, warn, message) CALL CD_AGG_End(agg, es, em) END SUBROUTINE check_option + SUBROUTINE wave_along(f, axis) + !! A long-crested wave travelling along grid axis `axis` (1: x, 2: y), with a different + !! amplitude per component and depth, sampled at four times on a grid 30 m apart. + REAL(REAL32), INTENT(OUT) :: f(:, :, :, :, :) + INTEGER, INTENT(IN) :: axis + INTEGER :: it, ix, iy, iz, ic + REAL(wp) :: s + + DO ic = 1, SIZE(f, 5) + DO iz = 1, SIZE(f, 4) + DO iy = 1, SIZE(f, 3) + DO ix = 1, SIZE(f, 2) + DO it = 1, SIZE(f, 1) + s = 30.0_wp*REAL(MERGE(ix, iy, axis == 1), wp) + f(it, ix, iy, iz, ic) = REAL(REAL(ic, wp)*EXP(-0.1_wp*REAL(iz, wp))* & + COS(0.069_wp*s - 0.8_wp*REAL(it, wp)), REAL32) + END DO + END DO + END DO + END DO + END DO + END SUBROUTINE wave_along + SUBROUTINE require(ok, what) LOGICAL, INTENT(IN) :: ok CHARACTER(*), INTENT(IN) :: what diff --git a/validation/scripts/openfast_wave_grid_guard.py b/validation/scripts/openfast_wave_grid_guard.py index 6a7804ea..40fd89aa 100644 --- a/validation/scripts/openfast_wave_grid_guard.py +++ b/validation/scripts/openfast_wave_grid_guard.py @@ -20,10 +20,14 @@ the platform drifts down-wave (+x, about 8 m in 60 s) and carries nodes out during the run, which stops at t > 0. + ext_oblique the covering grid with NY = 2 under supplied kinematics (WaveMod 6, HydroDyn PotMod 0) + of a wave at 30 deg, with WaveDir left at 0 (unused in that mode): judged from the data. + Cases that must RUN by default, with no guard message: ny2_along_x the covering grid with NY = 2 under waves at 0 deg (the tutorial grid); - nx2_along_y NX = 2, NY = 37 under waves at 90 deg. + nx2_along_y NX = 2, NY = 37 under waves at 90 deg; + ext_along_x the covering grid with NY = 2 under supplied kinematics of a wave at 0 deg. Each stopping case's message must name the time, a line, the node count, the deepest and the shallowest node, and the option that downgrades it. With ``--base-exe`` (an openfast.exe built @@ -38,6 +42,7 @@ from __future__ import annotations import argparse +import math import re import shutil import subprocess @@ -53,6 +58,8 @@ COVER = {"X_HalfWidth": "900", "Y_HalfWidth": "900", "Z_Depth": '"default"', "NX": "37", "NY": "2", "NZ": "11"} LIGHT = {"WaveTMax": "200"} +# WaveMod 6 reads WaveTMax/WaveDT + 1 records of the whole grid from text files; keep them small +EXTERNAL = {"WaveMod": "6", "WaveTMax": "20", "WaveDT": "0.25", "WvKinFile": '"ext/wave"'} HANGING_DECK = """--------------------- CableDyn Input File ------------------------------------ One chain from a point of the IEA-15 MW UMaine platform at x = 58 m to an anchor below it (wave-grid guard) @@ -101,7 +108,13 @@ ), "ny2_along_x": ({**COVER, **LIGHT}, DECK, 1.0, False), "nx2_along_y": ({**COVER, **LIGHT, "NX": "2", "NY": "37", "WaveDir": "90"}, DECK, 1.0, False), + # supplied kinematics (WaveMod 6, written by write_external): SeaState does not use WaveDir in + # this mode, so the guard judges the grid from the data; WaveDir is left at 0 on purpose + "ext_oblique": ({**COVER, **EXTERNAL}, DECK, 1.0, True), + "ext_along_x": ({**COVER, **EXTERNAL}, DECK, 1.0, False), } +# the direction (deg) of the long-crested wave written into each WaveMod 6 case's files +EXTERNAL_DIR = {"ext_oblique": 30.0, "ext_along_x": 0.0} BIT_IDENTICAL = [("ny2_along_x", "error"), ("nx2_along_y", "error"), ("outside", "warn"), ("ny2_oblique", "warn")] @@ -116,6 +129,63 @@ def set_value(path: Path, key: str, value: str) -> None: path.write_text("\n".join(lines) + "\n", encoding="latin-1") +def write_external(folder: Path, direction_deg: float) -> None: + """The WaveMod 6 files of a long-crested Airy wave (1 m amplitude, 10 s, travelling at + ``direction_deg``) on the COVER grid, in SeaState's layout: 13 header lines, then for every + time step, depth level (z = (cos(k dtheta) - 1) Z_Depth) and y, one row of the x values.""" + depth, half = 200.0, 900.0 + nx, ny, nz = int(COVER["NX"]), int(COVER["NY"]), int(COVER["NZ"]) + tmax, dt = float(EXTERNAL["WaveTMax"]), float(EXTERNAL["WaveDT"]) + xs = [-half + i * half / (nx - 1) for i in range(2 * nx - 1)] + ys = [-half + j * half / (ny - 1) for j in range(2 * ny - 1)] + dth = math.pi / (2 * (nz - 1)) + zs = [(math.cos(k * dth) - 1.0) * depth for k in range(nz)] + omega = 2.0 * math.pi / 10.0 + k_wave = omega**2 / 9.80665 # omega^2 = g k tanh(k h), by fixed point + for _ in range(50): + k_wave = omega**2 / (9.80665 * math.tanh(k_wave * depth)) + cb, sb = math.cos(math.radians(direction_deg)), math.sin(math.radians(direction_deg)) + steps = round(tmax / dt) + out = folder / "ext" + out.mkdir() + header = [f"wave-grid guard test: Airy wave at {direction_deg} deg"] + ["-"] * 12 + + def phase(t: float, x: float, y: float) -> float: + return omega * t - k_wave * (x * cb + y * sb) + + def rows(name: str) -> list[str]: + lines = [] + for m in range(steps + 1): + for z in zs: + ch = math.cosh(k_wave * (z + depth)) / math.sinh(k_wave * depth) + sh = math.sinh(k_wave * (z + depth)) / math.sinh(k_wave * depth) + cp = 1025.0 * 9.80665 * math.cosh(k_wave * (z + depth)) / math.cosh(k_wave * depth) + for y in ys: + values = [] + for x in xs: + p = phase(m * dt, x, y) + # u = omega ch cos p (along the heading), w = omega sh sin p + value = { + "Vxi": omega * ch * math.cos(p) * cb, + "Vyi": omega * ch * math.cos(p) * sb, + "Vzi": omega * sh * math.sin(p), + "Axi": -(omega**2) * ch * math.sin(p) * cb, + "Ayi": -(omega**2) * ch * math.sin(p) * sb, + "Azi": omega**2 * sh * math.cos(p), + "DynP": cp * math.cos(p), + }[name] + values.append(f"{value:.7e}") + lines.append(" ".join(values)) + return lines + + for name in ("Vxi", "Vyi", "Vzi", "Axi", "Ayi", "Azi", "DynP"): + (out / f"wave.{name}").write_text("\n".join(header + rows(name)) + "\n", encoding="ascii") + elev = [ + " ".join(f"{math.cos(phase(m * dt, x, y)):.7e}" for x in xs) for m in range(steps + 1) for y in ys + ] + (out / "wave.Elev").write_text("\n".join(header + elev) + "\n", encoding="ascii") + + def prepare(case_dir: Path, work: Path, name: str, mode: str) -> Path: """A case folder: the turbine files with the pose reset, the SeaState edits and the deck.""" edits, deck, tmax, _ = CASES[name] @@ -128,6 +198,9 @@ def prepare(case_dir: Path, work: Path, name: str, mode: str) -> Path: set_value(folder / HD, "PtfmRefY", "0") for key, value in edits.items(): set_value(folder / SS, key, value) + if name in EXTERNAL_DIR: # SeaState refuses WaveMod 6 with potential flow + set_value(folder / HD, "PotMod", "0") + write_external(folder, EXTERNAL_DIR[name]) shutil.copy(ROOT / "examples/openfast/IEA-15-UMaine_CompMooring5_CableDyn.fst", folder / FST) set_value(folder / FST, "TMax", str(tmax)) if deck == DECK: @@ -179,9 +252,11 @@ def main() -> int: if name == "midrun": times = [float(t) for t in re.findall(r"wave-kinematics grid at t = ([0-9.Ee+-]+) s", log)] ok = ok and bool(times) and times[0] > 0.0 - if name.startswith("ny2"): + if name.startswith("ny2") or name == "ext_oblique": # every line sampling the grid in the water counts, line 1 along y = 0 too ok = ok and "NY = 2 (3 points" in log and "line 1, 51 nodes" in log + if name == "ext_oblique": + ok = ok and "externally supplied wave kinematics (WaveMod 6)" in log if name == "outside": ok = ok and "shallowest at" in log print(f"{tag:22s} exit {code}: {'stops as required' if ok else 'FAIL'}")