From 0c09e692f770837fe1d5ae8bbb570573f4bfad2c Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Sat, 7 Nov 2026 20:59:34 +0900 Subject: [PATCH 1/3] feat(openfast): range graphs in coupled single-turbine runs The LINES Outputs flag r and RangeStart now work in OpenFAST as on the standalone routes: .CD.Line.range.out holds the minimum, maximum and mean at every node over the rows of .CD.out in the window. The module samples the aggregate once per committed mooring step, at t = 0 and in CD_UpdateStates after the commit, so an intermediate supercycle call, a CalcOutput probe and an abandoned step add nothing. A retried step takes its sample back: CD_AGG_Snapshot/Restore carry the accumulators, and on the glue's state copy the rebuild reloads them from the OtherState. The accumulators are double precision on every host build and ride the checkpoint (OtherState range_state), so a restart writes the file of an uninterrupted run. This changes the checkpoint format. The file is written at the end of a run that reaches TMax. A run that stops earlier says so and writes none, and the file of an earlier run goes at initialisation, so nothing stale stands in for the result. A range file that cannot be completed is now removed on every route. RangeStart is held against the host's run time: a coupled deck needs no TMax, and a deck TMax neither clamps nor bounds the window there. A FAST.Farm shared mooring and the C API refuse the flag by name, the C API now also on an EI = 0 deck, which it accepted without writing a file. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 18 +++ doc/capabilities.rst | 9 +- doc/capi.rst | 2 + doc/driver_format.md | 4 +- doc/index.rst | 2 +- doc/openfast.rst | 10 +- doc/options.rst | 6 +- doc/outputs.rst | 15 +- doc/tutorial_openfast.rst | 2 +- python/cabledyn/deck_file.py | 31 ++-- python/tests/test_deck_file.py | 23 +++ src/CableDyn_DeckDriver.f90 | 73 +++++++--- src/CableDyn_OpenFAST_Aggregate.f90 | 95 ++++++++++++- src/CableDyn_RangeOutput.f90 | 136 +++++++++++++++++- src/openfast/CableDyn_OF.f90 | 121 +++++++++++++++- src/openfast/CableDyn_Registry.txt | 1 + src/openfast/CableDyn_Types.f90 | 18 +++ tests/test_c_api.f90 | 37 ++++- tests/test_openfast_aggregate.f90 | 213 +++++++++++++++++++++++++++- 19 files changed, 743 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 345466ad..3cbf9029 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,24 @@ All notable changes to CableDyn are recorded in this file. The format follows ## [Unreleased] +### Added + +- Range graphs in coupled OpenFAST runs: the `LINES` `Outputs` flag `r` and `RangeStart` now write + `.CD.Line.range.out` in a single-turbine run, from the committed `dtM` steps of + `.CD.out`, once per step when OpenFAST retries a step, and across a checkpoint restart. The + file appears when the run reaches `TMax`. A FAST.Farm shared mooring and the C API reject the + flag by name. + +### Changed + +- OpenFAST checkpoints carry the accumulated range graphs: a checkpoint written by an earlier + CableDyn cannot be restarted with this one. +- The C API refuses the flag `r` on `EI = 0` decks too, which it accepted without writing a file. + +### Fixed + +- A range-graph file that cannot be written completely is removed instead of left behind. + ## [0.4.0] - 2026-11-04 ### Added diff --git a/doc/capabilities.rst b/doc/capabilities.rst index cfba7e1d..4d2334ab 100644 --- a/doc/capabilities.rst +++ b/doc/capabilities.rst @@ -108,7 +108,7 @@ Line and constitutive capability the platform, ``PtfmInit``, checkpoints, linearisation with the twist angles as states; see :doc:`openfast`) and through the C API with the host's rotations (``CableDyn_InitDeckRotating``, :doc:`capi`), active line control (``CONTROL``) of the - fairlead segment on the coupled route; ``Torq``/``Twist`` channels and standalone range + fairlead segment on the coupled route; ``Torq``/``Twist`` channels and range graphs. Stopped by name: ``CableDyn_InitDeck``/``InitDeckAt`` (which move the line ends by translation only), ends of free and pinned rods (axisymmetric, no roll angle) and of ``Coupled``/``Vessel`` rods, bodies other than Rigid6 and ``False alpha_force_blend``. @@ -193,9 +193,10 @@ Loads and environment - a 6-DOF vessel record, or the RAO response to the deck waves, moves every ``Coupled``/``Vessel`` point of a line deck; see :doc:`options` * - Range graphs (``r`` line output flag, ``RangeStart``) - - Standalone only - - minimum, maximum, and mean along each line over the run; a coupled OpenFAST deck rejects - the flag + - Standalone and OpenFAST + - minimum, maximum, and mean along each line over the run, from the committed steps; a run + restarted from a checkpoint keeps them. A FAST.Farm shared mooring and the C API reject + the flag by name * - WaterKin CurrentMod-1 file table - Supported - bit-identical to the equivalent inline depth profile diff --git a/doc/capi.rst b/doc/capi.rst index 5fac1f83..87d9a04a 100644 --- a/doc/capi.rst +++ b/doc/capi.rst @@ -937,6 +937,8 @@ The deck is validated under the standalone-deck rules: - the standalone driver (prescribe motion through ``CableDyn_Step`` instead) * - a ``FAILURE`` section (line failures) - the standalone driver; the OpenFAST module + * - the ``LINES`` ``Outputs`` flag ``r`` (range graph) + - the standalone driver; the OpenFAST module in a single-turbine run * - a ``CONTROL`` section (active line control) - the OpenFAST module * - ``WaveKinMod 2`` / ``SEASTATE`` wave kinematics diff --git a/doc/driver_format.md b/doc/driver_format.md index 8da2e336..922859b0 100644 --- a/doc/driver_format.md +++ b/doc/driver_format.md @@ -740,7 +740,7 @@ never both: a `SECTIONS` row for a 7-column line is an error naming the line. |--------|---------| | `ID` | unique line id ≥ 1 | | `NodeA`, `NodeB` | End A / End B POINT ids (distinct). **End A is the fairlead (top) end and End B the anchor (lower) end**, as in OrcaFlex. | -| `Outputs` | per-line file flags. `-` = none. `p` (node positions) and `t` (segment tensions) write `.Line.p.out` / `.t.out`, End A first. Static EI = 0 decks write node/segment tables; independent EI = 0, point-system EI = 0, independent finite-EI, rod, and Rigid6 dynamic decks write time series (one row per output time). `r` writes the range graph `.Line.range.out`: the minimum, maximum and mean over the run (from `RangeStart`) of the node tension, curvature, bend moment, declination and seabed clearance (and torque and twist on a line with torsion), on every standalone route; a coupled OpenFAST deck rejects it. Line-node channels in the main `.out` file are requested in `OUTPUTS`. | +| `Outputs` | per-line file flags. `-` = none. `p` (node positions) and `t` (segment tensions) write `.Line.p.out` / `.t.out`, End A first. Static EI = 0 decks write node/segment tables; independent EI = 0, point-system EI = 0, independent finite-EI, rod, and Rigid6 dynamic decks write time series (one row per output time). `r` writes the range graph `.Line.range.out`: the minimum, maximum and mean over the run (from `RangeStart`) of the node tension, curvature, bend moment, declination and seabed clearance (and torque and twist on a line with torsion), on every standalone route and in a single-turbine OpenFAST run (`.CD.Line.range.out`); a FAST.Farm shared mooring and the C API reject it. Line-node channels in the main `.out` file are requested in `OUTPUTS`. | **Automatic anchor-first swap.** Stock MoorDyn decks list lines anchor first. When a line's `NodeA` is a `Fixed` point and its `NodeB` is a `Coupled`, `Vessel`, `Body`, `Free`, or @@ -1264,7 +1264,7 @@ syntax form. The most frequently edited keywords are: | `TMax` | dynamic end time [s]; an integer multiple of `dtM` | — | | `rhoInf` | generalised-α spectral radius | 0.4 | | `maxStrain` | plausibility bound on `EI = 0` element strain, checked after every committed dynamic step; a non-finite state or a larger strain stops the run with exit code 2. `0` disables it | 0.5 | -| `RangeStart` / `range_start` | first output time [s] in the range graphs of the `LINES` `Outputs` flag `r`; earlier rows (a start-up transient) are left out. ≥ 0 and ≤ `TMax`; needs `TMax` and a line with the `r` flag | 0 | +| `RangeStart` / `range_start` | first output time [s] in the range graphs of the `LINES` `Outputs` flag `r`; earlier rows (a start-up transient) are left out. ≥ 0 and ≤ `TMax` (the host's in OpenFAST); needs a line with the `r` flag and, standalone, `TMax` | 0 | | `modified_newton` | `True`/`False`: reuse the tangent within a step on every dynamic solver the deck builds (the EI = 0 system and each coupled finite-EI cable): one effective-tangent factorization per step, contraction-checked with a refresh when the direction goes stale. Committed states meet the same Newton tolerance either way | `False` | | `cable_load_feedback` | coupled finite-EI cable reaction switch. `True` returns cable force and moment to the host. `False` marches the cable with the same moving boundary and host fluid field and keeps its output channels, but returns zero force and moment; use it for a one-way comparison, not as a physical model | `True` | | `adaptive_mesh` | `True`/`False`; allow finite-EI mesh refinement when the static resolution check is fragile | `False` | diff --git a/doc/index.rst b/doc/index.rst index 121a98d7..d3a05cb5 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -113,7 +113,7 @@ What CableDyn does - yes * - Modal analysis (``nModes``), range graphs, discrete ``ATTACHMENTS`` - yes - - ``ATTACHMENTS`` only + - range graphs and ``ATTACHMENTS`` * - Checkpoint/restart, linearisation, FAST.Farm, active tensioning - — - yes (:doc:`openfast`) diff --git a/doc/openfast.rst b/doc/openfast.rst index 9fd39544..4aefbca4 100644 --- a/doc/openfast.rst +++ b/doc/openfast.rst @@ -268,7 +268,11 @@ channels ``AnchFz``, ``AnchFH`` and ``TDPGrd``) and units are in :doc:` * - ``.CD.static.out`` - CableDyn-owned, always written: the static-equilibrium profile of every line, one row per node (arc length, coordinates, effective tension, curvature, bend moment, declination, - inclination, azimuth) — the coupled range graph, at the state of the printed line summary + inclination, azimuth), at the state of the printed line summary + * - ``.CD.Line.range.out`` + - CableDyn-owned, for a line with the ``LINES`` ``Outputs`` flag ``r``: the range graph, the + minimum, maximum and mean at every node over the committed steps from ``RangeStart``, + written when the run reaches ``TMax`` (:doc:`outputs`) * - ``.CD.rst.dat`` - temporary CableDyn-owned copy of the deck, written in the ``MooringFile`` folder only when a run restarts from a checkpoint (see *Lifecycle features*), and removed after use @@ -380,7 +384,9 @@ without an auxiliary process: * **Checkpoint/restart** serialises the committed line, constitutive, connection, body, and rod state needed to continue the trajectory, with the SeaState fields the committed step holds and, with ``dtM`` larger than ``DT``, the loads of the solve before it (the load predictor), so a - restart continues the run bit for bit at any ``dtM``. A checkpoint is accepted only on a committed CableDyn + restart continues the run bit for bit at any ``dtM``. The accumulated range graphs (``LINES`` + flag ``r``) are part of it, so a restarted run writes the range files of an uninterrupted one. A + checkpoint is accepted only on a committed CableDyn step, so choose ``ChkptTime`` as a whole multiple of ``dtM``; a checkpoint written between two commits stops the restart with a message that says so. On restart the module writes a temporary deck copy, ``.CD.rst.dat``, beside the ``MooringFile``, rebuilds the model diff --git a/doc/options.rst b/doc/options.rst index cc59b65b..b06a8d45 100644 --- a/doc/options.rst +++ b/doc/options.rst @@ -282,8 +282,10 @@ Clock and initial condition - finite, ≥ 0 and ≤ ``TMax`` (any value at ``TMax = 0``, where the graphs hold the ``t = 0`` row). First output time accumulated into the range graphs (``.Line.range.out``, ``LINES`` ``Outputs`` flag ``r``), so a start-up - transient is left out. Needs ``TMax`` and at least one line with the ``r`` flag - - standalone only + transient is left out. Needs at least one line with the ``r`` flag and, standalone, + ``TMax`` + - both; OpenFAST holds it against the host ``TMax``. A FAST.Farm shared mooring rejects the + ``r`` flag - ``100.0 RangeStart`` Nonlinear solver diff --git a/doc/outputs.rst b/doc/outputs.rst index 3229e994..758d4358 100644 --- a/doc/outputs.rst +++ b/doc/outputs.rst @@ -384,6 +384,16 @@ every node: the minimum and maximum equal those of the channel time histories exactly, and the mean is their arithmetic mean. The file is written when the run completes; a run that stops early leaves none. +A single-turbine OpenFAST run writes the same file as ``.CD.Line.range.out``. Its +samples are the rows of ``.CD.out``: the state at ``t = 0`` and every committed ``dtM`` +step, once each whatever ``DT``, ``DT_Out`` and the correction iterations are; a step OpenFAST +corrects counts once, with its corrected state. The accumulators are double precision on every +OpenFAST build and travel in the checkpoint, so a restart continues them. The file is written at +the end of a run that reaches ``TMax``; the run removes one left by an earlier run when it starts, +and one that stops before ``TMax`` says so and leaves none. An OpenFAST run stopped early on +purpose (``CalcSteady`` once steady) counts as stopping early. A FAST.Farm shared mooring and the +C API write no range file and reject the flag by name. + Layout: title line, header row, **units row**, then one row per node, End A first. The title reads ``CableDyn range graph (line ; samples from t = s to t = s; public node order End A -> End B)``. @@ -1018,8 +1028,9 @@ a run and intact after a crash. Select CableDyn channels in the ``OUTPUTS`` section of the CableDyn ``MooringFile``; they are not members of the top-level ``.fst`` ``OutList``. The ``TDP`` channels are evaluated from the -coupled state against the touchdown reference of the converged initialisation; the range files of -the ``LINES`` flag ``r`` are a standalone output, and a coupled deck with that flag is rejected. For +coupled state against the touchdown reference of the converged initialisation. The ``LINES`` flag +``r`` adds ``.CD.Line.range.out`` (see above) to a single-turbine run; a FAST.Farm +shared-mooring deck with that flag is rejected. For a single-turbine run the module also prints every selected channel's static value to the screen after initialisation. A deck with no ``OUTPUTS`` section is valid but publishes no channels. diff --git a/doc/tutorial_openfast.rst b/doc/tutorial_openfast.rst index b0a0ea9f..57b7b5a8 100644 --- a/doc/tutorial_openfast.rst +++ b/doc/tutorial_openfast.rst @@ -232,7 +232,7 @@ Check, in order: CableDyn step (every ``dtM``), with a units row * - ``IEA-15-UMaine_CompMooring5_CableDyn.CD.static.out`` - the initial nodal equilibrium of every line (arc length, coordinates, tension, curvature, - bend moment, declination, inclination, azimuth) — the coupled range graph + bend moment, declination, inclination, azimuth) * - ``*.ED.sum``, ``*.HD.sum`` - the usual OpenFAST module summaries diff --git a/python/cabledyn/deck_file.py b/python/cabledyn/deck_file.py index 7ea1388a..9f79bdef 100644 --- a/python/cabledyn/deck_file.py +++ b/python/cabledyn/deck_file.py @@ -1623,8 +1623,11 @@ class DeckFile: current is kept as a steady field when SeaState carries no waves or current and is rejected otherwise. The native C API (:class:`cabledyn.CableDyn`) reads decks with the standalone rules, so it rejects the ``CoupledPinned``/``VesselPinned`` bodies and rods - that ``caller_driven=True`` accepts; FAST.Farm, in turn, refuses bodies and rods when it - initialises the module. A coupled deck carries bodies or rods, not both (a rod fixed to a + that ``caller_driven=True`` accepts; a FAST.Farm shared mooring, in turn, refuses bodies and + rods and the ``LINES`` range-graph flag ``r`` when it initialises the module, and the C API + refuses the flag. ``RangeStart`` is held + against the host's ``TMax`` when OpenFAST initialises the module, not against a deck + ``TMax``. A coupled deck carries bodies or rods, not both (a rod fixed to a body counts as a rod): ``caller_driven=True`` rejects a deck with both, as the coupled route and the C API do, while the standalone driver's multibody march takes them. """ @@ -4125,17 +4128,19 @@ def is_body_kind(kind: str, pinned: bool) -> bool: f"{self._label}: OPTION RangeStart needs a line with the LINES Outputs " "flag r (range graph)" ) - if not has_tmax: - raise DeckFormatError( - f"{self._label}: OPTION RangeStart needs a dynamic deck (TMax)" - ) - tmax_value = _native_float(option_by_key["tmax"].values[0]) - # at TMax = 0 (a dynamic deck's static start) the range graphs hold the t = 0 row - if _native_float(range_start.values[0]) > tmax_value and tmax_value > 0.0: - raise DeckFormatError( - f"{self._label}: OPTION RangeStart exceeds TMax: the range window would hold " - "no output time" - ) + # a coupled host owns the run time: the native init holds the window against it + if not self.caller_driven: + if not has_tmax: + raise DeckFormatError( + f"{self._label}: OPTION RangeStart needs a dynamic deck (TMax)" + ) + tmax_value = _native_float(option_by_key["tmax"].values[0]) + # at TMax = 0 (a dynamic deck's static start) the range graphs hold the t = 0 row + if _native_float(range_start.values[0]) > tmax_value and tmax_value > 0.0: + raise DeckFormatError( + f"{self._label}: OPTION RangeStart exceeds TMax: the range window would " + "hold no output time" + ) # Native check_channel: ids are digit strings compared by value, so leading zeros # are accepted (FairTen01 is FairTen1). diff --git a/python/tests/test_deck_file.py b/python/tests/test_deck_file.py index bac4331f..5ac38630 100644 --- a/python/tests/test_deck_file.py +++ b/python/tests/test_deck_file.py @@ -2547,6 +2547,29 @@ def test_range_flag_and_range_start_follow_native_rules(): assert DeckFile.from_text(_edit(_STATIC, ("1 2 1 -\n", "1 2 1 r\n"))).lines[0].tokens[3] == "r" +def test_coupled_range_flag_and_range_start_take_the_host_clock(): + # the host owns the run time: no deck TMax is needed, and one is not a bound on RangeStart + no_tmax = _edit( + _STATIC, + ("1 2 1 -\n", "1 2 1 r\n"), + ("50.0 WtrDpth\n", "50.0 WtrDpth\n100.0 RangeStart\n"), + ) + deck = DeckFile.from_text(no_tmax, caller_driven=True) + assert deck.option("RangeStart").values == ("100.0",) + assert deck.lines[0].tokens[3] == "r" + deck_tmax = _edit( + _DYNAMIC, ("1 2 1 -\n", "1 2 1 r\n"), ("10.0 TMax\n", "10.0 TMax\n12.0 RangeStart\n") + ) + with pytest.raises(DeckFormatError, match="exceeds TMax"): + DeckFile.from_text(deck_tmax) + assert DeckFile.from_text(deck_tmax, caller_driven=True).option("RangeStart").values == ( + "12.0", + ) + # the flag is still what RangeStart needs + with pytest.raises(DeckFormatError, match="needs a line with the LINES Outputs flag r"): + DeckFile.from_text(_edit(no_tmax, ("1 2 1 r\n", "1 2 1 -\n")), caller_driven=True) + + def test_fixtures_are_valid_decks(): static = DeckFile.from_text(_STATIC) dynamic = DeckFile.from_text(_DYNAMIC) diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index c86ee353..68121a32 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -258,7 +258,12 @@ MODULE CableDyn_DeckDriver ! In-process object queries of the C API (CableDyn_CAPI): segment tensions in the .t.out ! convention, and the body/rod inventories the Body/Rod channels resolve on. PUBLIC :: CD_Eval_Aggregate_Segment_Tensions, CD_Rigid6_Inventory, CD_Rod_Inventory, CD_Channel_Token_Parses - ! Range graphs of an aggregate run (the standalone mixed route samples and writes them). + ! The refusal of the LINES flag r on a route that writes no range file. + CHARACTER(*), PARAMETER :: RANGE_FLAG_REFUSED = 'the LINES Outputs flag r (range graph) is written by the '// & + 'standalone driver and a single-turbine OpenFAST run; a FAST.Farm shared '// & + 'mooring or a C API run reports TDP and node channels instead' + ! Range graphs of an aggregate run (the standalone mixed route and the OpenFAST module sample + ! and write them). PUBLIC :: CD_Deck_Range_Sample_Aggregate, CD_Deck_Range_Write ! Diagnostic probe of the multibody march (verification tests): CD_Multibody_Probe_Arm makes ! the next multibody run start body 1 with the given velocity and angular velocity and record @@ -1230,7 +1235,7 @@ MODULE CableDyn_DeckDriver TYPE(CD_RodRuntimeType) :: rod ! Point3 buoys: stepped as Free points of the EI=0 system, but not placed by the static solve LOGICAL :: has_point3 = .FALSE. - ! Range graphs (LINES flag r, standalone only) and the touchdown references of the + ! Range graphs (LINES flag r) and the touchdown references of the ! TDP channels, keyed by deck line id and fixed at the converged initial state. TYPE(CD_RangeSet) :: ranges ! The deck's own prescribed motion (prescribed_motion: the standalone driver), in the @@ -1347,6 +1352,7 @@ SUBROUTINE CD_Init_Deck_System(deck_path, system, dtM, gravity, rho_water, ErrSt CHARACTER(NAMELEN), ALLOCATABLE :: channels(:) TYPE(CD_BathymetryType) :: bathymetry LOGICAL :: ext_march + INTEGER :: i ErrStat = CD_DECKDRV_OK ErrMsg = '' dtM = CD_ZERO @@ -1361,6 +1367,10 @@ SUBROUTINE CD_Init_Deck_System(deck_path, system, dtM, gravity, rho_water, ErrSt ErrStat, ErrMsg, caller_driven=ext_march, env_gravity=env_gravity, & env_rho_water=env_rho_water, env_wtrdpth=env_wtrdpth) IF (ErrStat /= CD_DECKDRV_OK) RETURN + ! the caller steps the system and writes no file: the flag does not pass silently + IF (ANY([(line_output_has_flag(lines(i)%outputs, 'r'), i=1, SIZE(lines))])) THEN + CALL fail(ErrStat, ErrMsg, RANGE_FLAG_REFUSED); RETURN + END IF IF (opts%waterkin_seastate) THEN CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_System cannot consume WaveKinMod 2/SEASTATE; use the '// & 'OpenFAST aggregate with its external SeaState field') @@ -7442,8 +7452,9 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi ! self-drive ambient forcing against that scope. Independent of external_fluid ! (which rejects the same options for the opposite reason: double-counting). LOGICAL, INTENT(IN), OPTIONAL :: forbid_deck_ambient - ! range_files: the caller writes the range graphs of the LINES flag r (the standalone - ! mixed route); a coupled host does not, so the flag fails closed there. + ! range_files: the caller samples and writes the range graphs of the LINES flag r (the + ! standalone mixed route, the single-turbine OpenFAST module); a host that does not (a FAST.Farm + ! shared mooring, the C API) leaves it out, and the flag fails closed there. LOGICAL, INTENT(IN), OPTIONAL :: range_files ! host_orientation: the caller passes each moving point's orientation with every update ! (the OpenFAST and FAST.Farm shells, and the standalone mixed route, which holds the frame @@ -8268,7 +8279,7 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi END IF ! A static strain above the note level is named in the line's initialisation note (every route that ! prints the notes of this summary shows it), and the standalone mixed route -- the caller that - ! asks for the range graphs -- also warns about coarse sections, as the single-topology driver does. + ! takes the deck's own current -- also warns about coarse sections, as the single-topology driver does. BLOCK INTEGER :: il CHARACTER(1024) :: strain_note @@ -8279,9 +8290,7 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi CALL axial_period_note(agg%init_lines(il)%line_id, dt, sections, types, strain_note) IF (LEN_TRIM(strain_note) > 0) CALL append_note_line(agg%init_lines(il)%note, strain_note) END DO - IF (PRESENT(range_files)) THEN - IF (range_files) CALL warn_coarse_sections(lines, sections) - END IF + IF (own_current) CALL warn_coarse_sections(lines, sections) END BLOCK ! Per moving slot, the driving turbine (0 outside farm mode) -- the SAME @@ -8316,10 +8325,17 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi wants_range = ANY([(line_output_has_flag(lines(i)%outputs, 'r'), i=1, SIZE(lines))]) wants_tdp = ANY([(CD_Is_TDP_Channel(to_lower(channels(i))), i=1, SIZE(channels))]) IF (wants_range .AND. .NOT. files_ok) THEN - CALL fail(ErrStat, ErrMsg, 'the LINES Outputs flag r (range graph) is written by the standalone driver; '// & - 'a coupled run reports TDP and node channels instead') + CALL fail(ErrStat, ErrMsg, RANGE_FLAG_REFUSED) CALL CD_End_Deck_Aggregate(agg); RETURN END IF + ! the run time of a coupled host is known here, not at the deck's own checks; the host's TMax + ! can have passed through single precision + IF (wants_range .AND. opts%has_range_start .AND. PRESENT(run_tmax)) THEN + IF (opts%range_start > run_tmax*(CD_ONE + 1.0e-6_wp) .AND. run_tmax > CD_ZERO) THEN + CALL fail(ErrStat, ErrMsg, 'OPTION RangeStart exceeds TMax: the range window would hold no output time') + CALL CD_End_Deck_Aggregate(agg); RETURN + END IF + END IF IF (wants_range .OR. wants_tdp) THEN IF (opts%has_bathymetry_file) THEN CALL load_bathymetry_file(path_join(deck_dir(deck_path), opts%bathymetry_file), bathymetry, ErrStat, & @@ -8330,10 +8346,10 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi END IF IF (ALLOCATED(agg%cables)) THEN CALL range_setup_aggregate(agg%ranges, lines, channels, opts, agg%has_sys, agg%sys, agg%cables, & - agg%line_is_cable, agg%line_obj_index, ErrStat, ErrMsg, bathymetry) + agg%line_is_cable, agg%line_obj_index, ErrStat, ErrMsg, bathymetry, run_tmax) ELSE CALL range_setup_aggregate(agg%ranges, lines, channels, opts, agg%has_sys, agg%sys, no_cables, & - agg%line_is_cable, agg%line_obj_index, ErrStat, ErrMsg, bathymetry) + agg%line_is_cable, agg%line_obj_index, ErrStat, ErrMsg, bathymetry, run_tmax) END IF IF (opts%has_bathymetry_file) CALL CD_End_Bathymetry(bathymetry) IF (ErrStat /= CD_DECKDRV_OK) THEN @@ -17547,13 +17563,16 @@ SUBROUTINE finalize_checks(types, bodies, rod_types, rods, points, lines, sectio CALL fail(ErrStat, ErrMsg, 'OPTION RangeStart needs a line with the LINES Outputs flag r (range graph)') RETURN END IF - IF (.NOT. opts%has_tmax) THEN - CALL fail(ErrStat, ErrMsg, 'OPTION RangeStart needs a dynamic deck (TMax)'); RETURN - END IF - ! at TMax = 0 (a dynamic deck's static start) the range graphs hold the t = 0 row - IF (opts%range_start > opts%tmax .AND. opts%tmax > CD_ZERO) THEN - CALL fail(ErrStat, ErrMsg, 'OPTION RangeStart exceeds TMax: the range window would hold no output time') - RETURN + ! a coupled host owns the run time: CD_Init_Deck_Aggregate holds the window against it + IF (.NOT. caller_driven) THEN + IF (.NOT. opts%has_tmax) THEN + CALL fail(ErrStat, ErrMsg, 'OPTION RangeStart needs a dynamic deck (TMax)'); RETURN + END IF + ! at TMax = 0 (a dynamic deck's static start) the range graphs hold the t = 0 row + IF (opts%range_start > opts%tmax .AND. opts%tmax > CD_ZERO) THEN + CALL fail(ErrStat, ErrMsg, 'OPTION RangeStart exceeds TMax: the range window would hold no output time') + RETURN + END IF END IF END IF @@ -36365,10 +36384,12 @@ SUBROUTINE range_status(es, em, ErrStat, ErrMsg) ErrMsg = 'CableDyn_DeckDriver: '//TRIM(em) END SUBROUTINE range_status - SUBROUTINE range_setup(rset, lines, channels, opts, nnodes, by_id, ErrStat, ErrMsg, bathymetry) + SUBROUTINE range_setup(rset, lines, channels, opts, nnodes, by_id, ErrStat, ErrMsg, bathymetry, run_tmax) !! Size the range set of a run from the LINES flag r and the TDP channels. by_id: !! rset%lines(k) is deck line id k (the aggregate line map) and nnodes is indexed by !! id; otherwise rset%lines(i) is lines(i) and nnodes follows the deck line order. + !! run_tmax: the run time of the aggregate's caller, which replaces a deck TMax (a coupled + !! deck's TMax is the standalone one). TYPE(CD_RangeSet), INTENT(INOUT) :: rset TYPE(DeckLine), INTENT(IN) :: lines(:) CHARACTER(*), INTENT(IN) :: channels(:) @@ -36378,6 +36399,7 @@ SUBROUTINE range_setup(rset, lines, channels, opts, nnodes, by_id, ErrStat, ErrM INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry + REAL(wp), INTENT(IN), OPTIONAL :: run_tmax INTEGER, ALLOCATABLE :: ids(:) LOGICAL, ALLOCATABLE :: want_r(:), want_t(:) INTEGER :: i, k, n, line_id, comp, es @@ -36407,7 +36429,11 @@ SUBROUTINE range_setup(rset, lines, channels, opts, nnodes, by_id, ErrStat, ErrM END DO ! TMax = 0 (a static start check) puts the t = 0 row in the range graphs whatever RangeStart says t_start = opts%range_start - IF (opts%has_tmax) t_start = MIN(t_start, opts%tmax) + IF (PRESENT(run_tmax)) THEN + t_start = MIN(t_start, run_tmax) + ELSE IF (opts%has_tmax) THEN + t_start = MIN(t_start, opts%tmax) + END IF CALL CD_Range_Setup(rset, ids, nnodes, want_r, want_t, t_start, opts%has_wtrdpth, -opts%wtrdpth, & es, em, bathymetry=bathymetry) CALL range_status(es, em, ErrStat, ErrMsg) @@ -36720,7 +36746,7 @@ SUBROUTINE aggregate_line_positions(system, cables, line_is_cable, line_obj_inde END SUBROUTINE aggregate_line_positions SUBROUTINE range_setup_aggregate(rset, lines, channels, opts, has_sys, system, cables, line_is_cable, & - line_obj_index, ErrStat, ErrMsg, bathymetry) + line_obj_index, ErrStat, ErrMsg, bathymetry, run_tmax) !! Range set of an aggregate (EI=0 system + Hermite cables), keyed by deck line id, with !! the touchdown references fixed at the current (initial) state. TYPE(CD_RangeSet), INTENT(INOUT) :: rset @@ -36735,6 +36761,7 @@ SUBROUTINE range_setup_aggregate(rset, lines, channels, opts, has_sys, system, c INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry + REAL(wp), INTENT(IN), OPTIONAL :: run_tmax INTEGER, ALLOCATABLE :: nnodes(:) INTEGER :: k, obj, es CHARACTER(1024) :: em @@ -36755,7 +36782,7 @@ SUBROUTINE range_setup_aggregate(rset, lines, channels, opts, has_sys, system, c END IF END IF END DO - CALL range_setup(rset, lines, channels, opts, nnodes, .TRUE., ErrStat, ErrMsg, bathymetry) + CALL range_setup(rset, lines, channels, opts, nnodes, .TRUE., ErrStat, ErrMsg, bathymetry, run_tmax) IF (ErrStat /= CD_DECKDRV_OK .OR. .NOT. rset%active) RETURN DO k = 1, SIZE(rset%lines) IF (.NOT. rset%lines(k)%want_tdp) CYCLE diff --git a/src/CableDyn_OpenFAST_Aggregate.f90 b/src/CableDyn_OpenFAST_Aggregate.f90 index be68b088..7c07c150 100644 --- a/src/CableDyn_OpenFAST_Aggregate.f90 +++ b/src/CableDyn_OpenFAST_Aggregate.f90 @@ -91,7 +91,8 @@ MODULE CableDyn_OpenFAST_Aggregate CD_DeckCurrentRuntimeType, CD_Deck_Current_Active, & CD_Deck_Current_Sample_System, CD_Deck_Current_Sample_Cables, & CD_Deck_Current_End - USE CableDyn_RangeOutput, ONLY: CD_RangeSet, CD_Range_End + USE CableDyn_RangeOutput, ONLY: CD_RangeSet, CD_Range_End, CD_Range_Has_Graph, CD_Range_Mirror_Size, & + CD_Range_Get_State, CD_Range_Set_State, CD_Range_Discard_Files, CD_RANGE_OK USE CableDyn_System, ONLY: CD_Get_System_Substep_Counts, CD_System_NLines, CD_System_Line_NDOF, & CD_System_Fallback_Count, CD_System_Fallback_Reset, & CD_Get_System_Line_State, & @@ -139,8 +140,10 @@ MODULE CableDyn_OpenFAST_Aggregate PUBLIC :: CD_AGG_ChannelHeader PUBLIC :: CD_AGG_EvalChannel PUBLIC :: CD_AGG_WriteStaticProfile - ! Range graphs of the LINES flag r on the standalone mixed route (not a coupled-host surface) - PUBLIC :: CD_AGG_Range_Sample, CD_AGG_Range_Write + ! Range graphs of the LINES flag r: the standalone mixed route and the single-turbine OpenFAST + ! module sample and write them; the accumulated state rides a host's checkpoint + PUBLIC :: CD_AGG_Range_Sample, CD_AGG_Range_Write, CD_AGG_Range_Discard, CD_AGG_Range_Graphs, & + CD_AGG_Range_MirrorSize, CD_AGG_Range_Get_State, CD_AGG_Range_Set_State PUBLIC :: CD_AGG_GetInitMetadata, CD_AGG_GetInitLine ! Status space mirrors CD_FMF_* (and the CD_HFMF_* / CD_DECKDRV_* subsets) so the facade @@ -263,10 +266,11 @@ MODULE CableDyn_OpenFAST_Aggregate ! branch (mutually exclusive with has_rigid6); its snapshot buffer joins the aggregate snapshot. LOGICAL :: has_rod = .FALSE. TYPE(CD_RodRuntimeType) :: rod - ! Range graphs (standalone mixed route) and the touchdown references of the TDP + ! Range graphs (standalone mixed route, OpenFAST module) and the touchdown references of the TDP ! channels, keyed by deck line id. The references are fixed at the converged initial ! state (a checkpoint rebuild re-derives the same state), so they carry no step state. TYPE(CD_RangeSet) :: ranges + REAL(wp), ALLOCATABLE :: snap_range(:) ! the accumulated range graphs at the last CD_AGG_Snapshot ! Coupled/Vessel and CoupledPinned rods: the trailing host nodes of the moving surface, and ! the full EI=0 coupled-block scratch (3, n_system_coupled_dof/3) their RodA/B points are ! overlaid on. @@ -326,7 +330,7 @@ SUBROUTINE CD_AGG_Init_From_Deck(self, deck_path, dt, ErrStat, ErrMsg, env_gravi ! forbid_deck_ambient: the caller evaluates no deck waves (and, without deck_current, no ! deck current), so reject a deck that declares them (see CD_Init_Deck_Aggregate). LOGICAL, INTENT(IN), OPTIONAL :: forbid_deck_ambient - ! range_files: the caller writes the range graphs of the LINES flag r (CD_AGG_Range_*) + ! range_files: the caller samples and writes the range graphs of the LINES flag r (CD_AGG_Range_*) LOGICAL, INTENT(IN), OPTIONAL :: range_files ! host_orientation: the caller passes the moving-point orientations with every update, ! which a finite-EI line restrained in torsion requires (see CD_Init_Deck_Aggregate) @@ -1693,6 +1697,11 @@ SUBROUTINE CD_AGG_Snapshot(self, ErrStat, ErrMsg) ! a rewind to a state before the first step takes the start accelerations open again (new ! fluid fields re-solve them) self%snap_objects_committed = self%objects_committed + ! the range graphs as of the step start: a rewind takes back the sample of the abandoned step + IF (CD_Range_Has_Graph(self%ranges)) THEN + IF (.NOT. ALLOCATED(self%snap_range)) ALLOCATE (self%snap_range(CD_Range_Mirror_Size(self%ranges))) + CALL CD_Range_Get_State(self%ranges, self%snap_range) + END IF ErrStat = CD_AGG_OK ErrMsg = '' END SUBROUTINE CD_AGG_Snapshot @@ -1728,6 +1737,14 @@ SUBROUTINE CD_AGG_Restore(self, ErrStat, ErrMsg) IF (self%has_rigid6) CALL CD_Rigid6_Restore(self%rigid6) IF (self%has_rod) CALL CD_Rod_Restore(self%rod) self%objects_committed = self%snap_objects_committed + IF (ALLOCATED(self%snap_range)) THEN + CALL CD_Range_Set_State(self%ranges, self%snap_range, es, em) + IF (es /= CD_RANGE_OK) THEN + ErrStat = CD_AGG_BADINPUT + ErrMsg = 'CableDyn_OpenFAST_Aggregate: '//TRIM(em) + RETURN + END IF + END IF ErrStat = CD_AGG_OK ErrMsg = '' END SUBROUTINE CD_AGG_Restore @@ -2468,6 +2485,7 @@ SUBROUTINE CD_AGG_End(self, ErrStat, ErrMsg) self%has_rod = .FALSE. self%has_point3 = .FALSE. CALL CD_Range_End(self%ranges) + IF (ALLOCATED(self%snap_range)) DEALLOCATE (self%snap_range) self%nhost_rod = 0 self%nhost_body = 0 IF (ALLOCATED(self%hf_mask)) DEALLOCATE (self%hf_mask) @@ -2633,8 +2651,8 @@ SUBROUTINE CD_AGG_EvalChannel(self, i, value, ErrStat, ErrMsg) END SUBROUTINE CD_AGG_EvalChannel SUBROUTINE CD_AGG_Range_Sample(self, time, ErrStat, ErrMsg) - !! Accumulate the range graphs (LINES flag r) at a committed output time. The standalone - !! mixed route calls it once per written row; a coupled host never does. + !! Accumulate the range graphs (LINES flag r) at a committed output time: once per written + !! row on the standalone mixed route, once per committed mooring step in the OpenFAST module. TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: self REAL(wp), INTENT(IN) :: time INTEGER, INTENT(OUT) :: ErrStat @@ -2671,6 +2689,69 @@ SUBROUTINE CD_AGG_Range_Write(self, root, ErrStat, ErrMsg) CALL map_deck_status(es, em, ErrStat, ErrMsg) END SUBROUTINE CD_AGG_Range_Write + SUBROUTINE CD_AGG_Range_Discard(self, root, ErrStat, ErrMsg) + !! Remove the .Line.range.out files an earlier run left (CD_Range_Discard_Files). + TYPE(CD_AGG_ModuleType), INTENT(IN) :: self + CHARACTER(*), INTENT(IN) :: root + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: es + CHARACTER(1024) :: em + + IF (.NOT. require_initialized(self, ErrStat, ErrMsg)) RETURN + CALL CD_Range_Discard_Files(self%ranges, root, es, em) + IF (es /= CD_RANGE_OK) THEN + ErrStat = CD_AGG_BADINPUT + ErrMsg = 'CableDyn_OpenFAST_Aggregate: '//TRIM(em) + END IF + END SUBROUTINE CD_AGG_Range_Discard + + LOGICAL FUNCTION CD_AGG_Range_Graphs(self) RESULT(yes) + !! True when a line of the deck carries the LINES flag r; touchdown channels alone need no + !! sampling, they are evaluated from the state. + TYPE(CD_AGG_ModuleType), INTENT(IN) :: self + yes = CD_Range_Has_Graph(self%ranges) + END FUNCTION CD_AGG_Range_Graphs + + INTEGER FUNCTION CD_AGG_Range_MirrorSize(self) RESULT(n) + !! Reals of the accumulated range graphs (checkpoint pack surface; 0 without a LINES flag r). + TYPE(CD_AGG_ModuleType), INTENT(IN) :: self + n = CD_Range_Mirror_Size(self%ranges) + END FUNCTION CD_AGG_Range_MirrorSize + + SUBROUTINE CD_AGG_Range_Get_State(self, state, ErrStat, ErrMsg) + !! The accumulated range graphs, CD_AGG_Range_MirrorSize reals (checkpoint pack surface). + TYPE(CD_AGG_ModuleType), INTENT(IN) :: self + REAL(wp), INTENT(OUT) :: state(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + + IF (.NOT. require_initialized(self, ErrStat, ErrMsg)) RETURN + IF (SIZE(state) /= CD_Range_Mirror_Size(self%ranges)) THEN + ErrStat = CD_AGG_BADINPUT + ErrMsg = 'CableDyn_OpenFAST_Aggregate: range-graph query needs CD_AGG_Range_MirrorSize slots' + RETURN + END IF + CALL CD_Range_Get_State(self%ranges, state) + END SUBROUTINE CD_AGG_Range_Get_State + + SUBROUTINE CD_AGG_Range_Set_State(self, state, ErrStat, ErrMsg) + !! Reload the accumulated range graphs of CD_AGG_Range_Get_State (checkpoint restore surface). + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: self + REAL(wp), INTENT(IN) :: state(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: es + CHARACTER(1024) :: em + + IF (.NOT. require_initialized(self, ErrStat, ErrMsg)) RETURN + CALL CD_Range_Set_State(self%ranges, state, es, em) + IF (es /= CD_RANGE_OK) THEN + ErrStat = CD_AGG_BADINPUT + ErrMsg = 'CableDyn_OpenFAST_Aggregate: '//TRIM(em) + END IF + END SUBROUTINE CD_AGG_Range_Set_State + SUBROUTINE CD_AGG_WriteStaticProfile(self, path, ErrStat, ErrMsg) !! Write the converged coupled initialization as an OrcaFlex-statics-style range table. !! This file is independent of the deck OUTPUTS selection: every line and every node is diff --git a/src/CableDyn_RangeOutput.f90 b/src/CableDyn_RangeOutput.f90 index 7680cfa5..f43cbf8b 100644 --- a/src/CableDyn_RangeOutput.f90 +++ b/src/CableDyn_RangeOutput.f90 @@ -27,7 +27,7 @@ MODULE CableDyn_RangeOutput !! length the deformed chord length from the grounded end to the TDP (0 while no node !! beyond the grounded end node is grounded). USE CableDyn_Precision, ONLY: wp, CD_ZERO, CD_ONE - USE CableDyn_PathIO, ONLY: CD_Open_Write + USE CableDyn_PathIO, ONLY: CD_Open_Write, CD_Path_Openable USE CableDyn_Bathymetry, ONLY: CD_BathymetryType, CD_Bathymetry_Floor, CD_Bathymetry_Is_Initialized, & CD_BATHY_OK USE CableDyn_SeabedContact, ONLY: CD_SEABED_CONTACT_BLEND @@ -38,7 +38,8 @@ MODULE CableDyn_RangeOutput PUBLIC :: CD_RangeLine, CD_RangeSet PUBLIC :: CD_Range_Setup, CD_Range_End, CD_Range_Needs_Sample, CD_Range_Commit_Sample PUBLIC :: CD_Range_Clearance, CD_Range_TDP_Evaluate, CD_Range_TDP_Reference - PUBLIC :: CD_Range_Write_Files + PUBLIC :: CD_Range_Write_Files, CD_Range_Discard_Files + PUBLIC :: CD_Range_Has_Graph, CD_Range_Mirror_Size, CD_Range_Get_State, CD_Range_Set_State PUBLIC :: CD_Is_TDP_Channel, CD_Parse_TDP_Channel INTEGER, PARAMETER, PUBLIC :: CD_RANGE_OK = 0, CD_RANGE_BADINPUT = 1, CD_RANGE_SOLVEFAIL = 2 @@ -50,6 +51,9 @@ MODULE CableDyn_RangeOutput INTEGER, PARAMETER, PUBLIC :: CD_TDP_S = 1, CD_TDP_X = 2, CD_TDP_Y = 3, CD_TDP_Z = 4, CD_TDP_LAY = 5, & CD_TDP_EXC = 6, CD_TDP_GRD = 7, CD_TDP_N = 7 + ! Leading reals of a line in CD_Range_Get_State: sample count, t_first, t_last, arc-ready flag. + INTEGER, PARAMETER :: RANGE_MIRROR_HEAD = 4 + TYPE :: CD_RangeLine INTEGER :: line_id = 0 INTEGER :: nn = 0 @@ -196,6 +200,96 @@ PURE LOGICAL FUNCTION CD_Range_Needs_Sample(set, il) RESULT(yes) yes = set%lines(il)%want_range .OR. set%lines(il)%want_tdp END FUNCTION CD_Range_Needs_Sample + PURE LOGICAL FUNCTION CD_Range_Has_Graph(set) RESULT(yes) + !! True when some line of the set accumulates a range graph (LINES flag r), not only + !! touchdown channels. + TYPE(CD_RangeSet), INTENT(IN) :: set + INTEGER :: il + yes = .FALSE. + IF (.NOT. set%active) RETURN + DO il = 1, SIZE(set%lines) + IF (set%lines(il)%want_range) yes = .TRUE. + END DO + END FUNCTION CD_Range_Has_Graph + + PURE INTEGER FUNCTION CD_Range_Mirror_Size(set) RESULT(n) + !! Reals of the accumulated range graphs (CD_Range_Get_State): per line with a range file, + !! the sample count, the first and last sample times, the arc-ready flag, the arc stations + !! and the three envelopes. + TYPE(CD_RangeSet), INTENT(IN) :: set + INTEGER :: il + n = 0 + IF (.NOT. set%active) RETURN + DO il = 1, SIZE(set%lines) + IF (set%lines(il)%want_range) n = n + RANGE_MIRROR_HEAD + (1 + 3*CD_RQ_N)*set%lines(il)%nn + END DO + END FUNCTION CD_Range_Mirror_Size + + PURE SUBROUTINE CD_Range_Get_State(set, state) + !! Copy the accumulated range graphs into state (CD_Range_Mirror_Size reals, every one + !! double precision whatever the host's output precision). The touchdown references and + !! the sample scratch are not part of it: a route rebuilds them. + TYPE(CD_RangeSet), INTENT(IN) :: set + REAL(wp), INTENT(OUT) :: state(:) + INTEGER :: il, j, k, nn + + k = 0 + IF (.NOT. set%active) RETURN + DO il = 1, SIZE(set%lines) + IF (.NOT. set%lines(il)%want_range) CYCLE + nn = set%lines(il)%nn + state(k + 1) = REAL(set%lines(il)%nsample, wp) + state(k + 2) = set%lines(il)%t_first + state(k + 3) = set%lines(il)%t_last + state(k + 4) = MERGE(CD_ONE, CD_ZERO, set%lines(il)%arc_ready) + k = k + RANGE_MIRROR_HEAD + state(k + 1:k + nn) = set%lines(il)%arc + k = k + nn + DO j = 1, nn + state(k + 1:k + CD_RQ_N) = set%lines(il)%vmin(:, j) + state(k + CD_RQ_N + 1:k + 2*CD_RQ_N) = set%lines(il)%vmax(:, j) + state(k + 2*CD_RQ_N + 1:k + 3*CD_RQ_N) = set%lines(il)%vsum(:, j) + k = k + 3*CD_RQ_N + END DO + END DO + END SUBROUTINE CD_Range_Get_State + + SUBROUTINE CD_Range_Set_State(set, state, ErrStat, ErrMsg) + !! Reload the accumulated range graphs of CD_Range_Get_State, of a set sized alike. + TYPE(CD_RangeSet), INTENT(INOUT) :: set + REAL(wp), INTENT(IN) :: state(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: il, j, k, nn + + ErrStat = CD_RANGE_OK + ErrMsg = '' + IF (SIZE(state) /= CD_Range_Mirror_Size(set)) THEN + ErrStat = CD_RANGE_BADINPUT + ErrMsg = 'CableDyn_RangeOutput: the saved range graphs do not match the lines of this run' + RETURN + END IF + k = 0 + IF (.NOT. set%active) RETURN + DO il = 1, SIZE(set%lines) + IF (.NOT. set%lines(il)%want_range) CYCLE + nn = set%lines(il)%nn + set%lines(il)%nsample = NINT(state(k + 1)) + set%lines(il)%t_first = state(k + 2) + set%lines(il)%t_last = state(k + 3) + set%lines(il)%arc_ready = state(k + 4) > CD_ZERO + k = k + RANGE_MIRROR_HEAD + set%lines(il)%arc = state(k + 1:k + nn) + k = k + nn + DO j = 1, nn + set%lines(il)%vmin(:, j) = state(k + 1:k + CD_RQ_N) + set%lines(il)%vmax(:, j) = state(k + CD_RQ_N + 1:k + 2*CD_RQ_N) + set%lines(il)%vsum(:, j) = state(k + 2*CD_RQ_N + 1:k + 3*CD_RQ_N) + k = k + 3*CD_RQ_N + END DO + END DO + END SUBROUTINE CD_Range_Set_State + SUBROUTINE CD_Range_Clearance(set, r, clearance, ErrStat, ErrMsg) !! Vertical centreline clearance above the seabed, z - z_floor(x, y), per node. TYPE(CD_RangeSet), INTENT(IN) :: set @@ -560,14 +654,50 @@ SUBROUTINE CD_Range_Write_Files(set, out_root, ErrStat, ErrMsg) WRITE (unit, '(A)', IOSTAT=ios) '' IF (ios /= 0) GOTO 910 END DO + FLUSH (unit, IOSTAT=ios) + IF (ios /= 0) GOTO 910 CLOSE (unit) END DO RETURN + ! a file that could not be completed does not stay behind looking like a finished graph 910 ErrStat = CD_RANGE_BADINPUT ErrMsg = 'CableDyn_RangeOutput: cannot write range-graph output file: '//TRIM(path) - CLOSE (unit) + CLOSE (unit, STATUS='DELETE', IOSTAT=ios) END SUBROUTINE CD_Range_Write_Files + SUBROUTINE CD_Range_Discard_Files(set, out_root, ErrStat, ErrMsg) + !! Remove the .Line.range.out files of an earlier run, so a run that ends + !! before writing its own leaves none behind to be taken for its result. A file that + !! cannot be removed fails here, at the start of the run, not after it. + TYPE(CD_RangeSet), INTENT(IN) :: set + CHARACTER(*), INTENT(IN) :: out_root + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: il, unit, ios + CHARACTER(LEN(out_root) + 32) :: path + CHARACTER(16) :: id_text + + ErrStat = CD_RANGE_OK + ErrMsg = '' + IF (.NOT. set%active) RETURN + DO il = 1, SIZE(set%lines) + IF (.NOT. set%lines(il)%want_range) CYCLE + WRITE (id_text, '(I0)') set%lines(il)%line_id + path = TRIM(out_root)//'.Line'//TRIM(id_text)//'.range.out' + IF (.NOT. CD_Path_Openable(TRIM(path), .FALSE.)) CYCLE ! no such file + CALL CD_Open_Write(unit, TRIM(path), ios, status='OLD') + IF (ios == 0) CLOSE (unit, STATUS='DELETE', IOSTAT=ios) + IF (ios == 0) THEN + IF (CD_Path_Openable(TRIM(path), .FALSE.)) ios = 1 + END IF + IF (ios /= 0) THEN + ErrStat = CD_RANGE_BADINPUT + ErrMsg = 'CableDyn_RangeOutput: cannot replace the range-graph output file of an earlier run: '//TRIM(path) + RETURN + END IF + END DO + END SUBROUTINE CD_Range_Discard_Files + PURE LOGICAL FUNCTION CD_Is_TDP_Channel(lo) RESULT(yes) !! True for a name of the TDP family (lower case), valid or not: "tdp" then a digit. CHARACTER(*), INTENT(IN) :: lo diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index 14bb6997..9b517ac3 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -51,7 +51,9 @@ MODULE CableDyn !! (PtfmInit), the module's own mooring step (supercycling + zero-order-hold loads), !! glue correction iterations (NumCrctn > 0: snapshot-rewind re-advance), SeaState !! wave/current kinematics sampled at the line nodes (single-turbine only; see the - !! farm scope at the use_extf guard), checkpoint restart (rebuild from the packed + !! farm scope at the use_extf guard), range graphs of the LINES flag r (single-turbine + !! only: .Line.range.out, sampled at every committed mooring step, written when + !! the run reaches TMax), checkpoint restart (rebuild from the packed !! deck + state mirror, accepted on committed mooring-interval boundaries), !! linearization with the line dynamics (as MoorDyn-F: the continuous states are the !! EI=0 lines' interior-node positions and the finite-EI cables' free DOFs, positions @@ -98,7 +100,9 @@ MODULE CableDyn CD_AGG_NFluidNodes, CD_AGG_GetFluidNodePositions, CD_AGG_SetFluidFields, & CD_AGG_NumChannels, CD_AGG_ChannelHeader, CD_AGG_EvalChannel, & CD_AGG_GetInitMetadata, CD_AGG_GetInitLine, & - CD_AGG_WriteStaticProfile + CD_AGG_WriteStaticProfile, CD_AGG_Range_Graphs, CD_AGG_Range_Sample, & + CD_AGG_Range_Write, CD_AGG_Range_Discard, CD_AGG_Range_MirrorSize, & + CD_AGG_Range_Get_State, CD_AGG_Range_Set_State USE CableDyn_OpenFAST_HermiteFMF, ONLY: CD_HFMF_MirrorSize, CD_HFMF_PackMirror, CD_HFMF_UnpackMirror, & CD_HFMF_FrictionMirrorSize, CD_HFMF_BoundaryMirrorSize, & CD_HFMF_ForceMirrorSize, CD_HFMF_TorsionMirrorSize, CD_HFMF_VIVMirrorSize, & @@ -238,6 +242,11 @@ END FUNCTION cd_cpu_guard_armed REAL(DbKi) :: native_wrote_t = 0.0_DbKi LOGICAL :: native_pending = .FALSE. CHARACTER(1024) :: native_root = '' + ! Range graphs (LINES flag r): sampled by the aggregate once per committed mooring step + ! (sample_range); ws_range is the double-precision transfer buffer to the OtherState + ! mirror, which a checkpoint packs and a correction iteration's state copy rewinds. + LOGICAL :: range_on = .FALSE. + REAL(wp), ALLOCATABLE :: ws_range(:) ! SeaState ambient-fluid sampling (host-driven wave/current kinematics): when the ! glue's WaveField declares waves or a current, the aggregate is built wave-capable ! (external_fluid) and every mooring advance samples the field at the line nodes' @@ -816,7 +825,7 @@ SUBROUTINE CD_Init(InitInp, u, p, x, xd, z, other, y, m, DTcoupling, InitOut, Er env_gravity=REAL(InitInp%g, wp), env_rho_water=REAL(InitInp%rhoW, wp), & env_wtrdpth=REAL(InitInp%WtrDepth, wp), ptfm_init=REAL(ptfm6, wp), & external_fluid=use_extf, run_tmax=REAL(InitInp%Tmax, wp), & - host_orientation=.TRUE., static_current=static_cur ) + host_orientation=.TRUE., static_current=static_cur, range_files=.TRUE. ) END IF IF (es /= CD_AGG_OK) THEN ! The slot stays inactive (it is activated only after full success, below), so this and @@ -1330,6 +1339,20 @@ SUBROUTINE CD_Init(InitInp, u, p, x, xd, z, other, y, m, DTcoupling, InitOut, Er CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) IF (ErrStat >= AbortErrLev) RETURN + ! Range graphs (LINES flag r): the first sample is the state of the t = 0 output row. The + ! files of an earlier run go now: this run writes its own only when it reaches TMax. + Inst(id)%range_on = CD_AGG_Range_Graphs( Inst(id)%agg ) + IF (Inst(id)%range_on) THEN + CALL CD_AGG_Range_Discard( Inst(id)%agg, TRIM(native_root), es, em ) + IF (es /= CD_AGG_OK) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: '//TRIM(em), ErrStat, ErrMsg, RoutineName ) + RETURN + END IF + CALL sample_range( Inst(id), other, 0.0_DbKi, ErrStat2, ErrMsg2 ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) RETURN + END IF + IF (profile_requested) THEN CALL SYSTEM_CLOCK(prof_c1) CALL reset_instance_profile( id, .TRUE., & @@ -1536,7 +1559,7 @@ SUBROUTINE rebuild_from_checkpoint( t, u1, p, x, other, m, ErrStat, ErrMsg ) env_gravity=REAL(p%g, wp), env_rho_water=REAL(p%rhoW, wp), & env_wtrdpth=REAL(p%WtrDpth, wp), external_fluid=use_extf, & ptfm_init=REAL(p%PtfmInit, wp), run_tmax=REAL(p%Tmax, wp), & - host_orientation=.TRUE., static_current=static_cur ) + host_orientation=.TRUE., static_current=static_cur, range_files=.TRUE. ) CALL delete_file( rst_deck ) IF (es /= CD_AGG_OK) THEN CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: checkpoint rebuild: '//TRIM(em), & @@ -1669,6 +1692,18 @@ SUBROUTINE rebuild_from_checkpoint( t, u1, p, x, other, m, ErrStat, ErrMsg ) RETURN END IF END IF + ! The range graphs continue from the checkpoint: the rebuild sized them, the restored + ! OtherState holds them through other%t_commit (a same-process rewind drops the samples + ! of the abandoned steps with it). + Inst(id)%range_on = CD_AGG_Range_Graphs( Inst(id)%agg ) + IF (Inst(id)%range_on) THEN + CALL restore_range_state( Inst(id), other, ErrStat2, ErrMsg2 ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) THEN + CALL release_instance( id ) + RETURN + END IF + END IF ! A fresh-process restart first passes through CD_Init, whose provisional instance ! owns the output stream of the same root; the checkpointed m%CDInst need not be ! that slot. Find it so its stream is released and the slot freed with old_id. @@ -1918,6 +1953,14 @@ SUBROUTINE CD_UpdateStates( t, n, u, t_array, p, x, xd, z, other, m, ErrStat, Er other%t_commit = Inst(id)%t_commit CALL pack_state_mirror( Inst(id), m, x, ErrStat2, ErrMsg2 ) CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + ! one range-graph sample per commit, here where the OtherState can carry it: a + ! correction re-advance takes the sample back with the step (CD_AGG_Restore, or + ! the glue's state copy and the rebuild), an intermediate supercycle call never + ! gets here, and CalcOutput's probes of off-step inputs are not commits + IF (Inst(id)%range_on .AND. ErrStat < AbortErrLev) THEN + CALL sample_range( Inst(id), other, Inst(id)%t_commit, ErrStat2, ErrMsg2 ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + END IF END IF END IF @@ -2688,6 +2731,60 @@ SUBROUTINE restore_held_fluid( inst_e, other, restored, ErrStat, ErrMsg ) restored = .TRUE. END SUBROUTINE restore_held_fluid + SUBROUTINE sample_range( inst_e, other, t_sample, ErrStat, ErrMsg ) + !! Add the committed state at t_sample to the range graphs and mirror them into the + !! OtherState, so a checkpoint carries them. The samples are the aggregate's own double + !! precision node values, whatever the precision of the host's outputs (ReKi). + TYPE(CD_OF_Instance), INTENT(INOUT) :: inst_e + TYPE(CD_OtherStateType), INTENT(INOUT) :: other + REAL(DbKi), INTENT(IN ) :: t_sample + INTEGER(IntKi), INTENT( OUT) :: ErrStat + CHARACTER(*), INTENT( OUT) :: ErrMsg + INTEGER(IntKi) :: es, nr + CHARACTER(ErrMsgLen) :: em + ErrStat = ErrID_None + ErrMsg = '' + CALL CD_AGG_Range_Sample( inst_e%agg, REAL(t_sample, wp), es, em ) + nr = CD_AGG_Range_MirrorSize( inst_e%agg ) + IF (.NOT. ALLOCATED(inst_e%ws_range)) ALLOCATE (inst_e%ws_range(nr)) + IF (es == CD_AGG_OK) CALL CD_AGG_Range_Get_State( inst_e%agg, inst_e%ws_range, es, em ) + IF (es /= CD_AGG_OK) THEN + ErrStat = ErrID_Fatal + ErrMsg = 'CableDyn mooring module: range-graph sample at t = '//TRIM(Num2LStr(t_sample))//' s: '//TRIM(em) + RETURN + END IF + IF (ALLOCATED(other%range_state)) THEN + IF (SIZE(other%range_state) /= nr) DEALLOCATE (other%range_state) + END IF + IF (.NOT. ALLOCATED(other%range_state)) ALLOCATE (other%range_state(nr)) + other%range_state = REAL(inst_e%ws_range, DbKi) + END SUBROUTINE sample_range + + SUBROUTINE restore_range_state( inst_e, other, ErrStat, ErrMsg ) + !! Hand the range graphs of a checkpoint (sample_range) back to the rebuilt aggregate. A + !! checkpoint without them for these lines fails by name: continuing would write a range + !! graph that silently misses the run before the restart. + TYPE(CD_OF_Instance), INTENT(INOUT) :: inst_e + TYPE(CD_OtherStateType), INTENT(IN ) :: other + INTEGER(IntKi), INTENT( OUT) :: ErrStat + CHARACTER(*), INTENT( OUT) :: ErrMsg + INTEGER(IntKi) :: es + CHARACTER(ErrMsgLen) :: em + ErrStat = ErrID_None + ErrMsg = '' + es = CD_AGG_OK + IF (ALLOCATED(other%range_state)) THEN + CALL CD_AGG_Range_Set_State( inst_e%agg, REAL(other%range_state, wp), es, em ) + ELSE + es = ErrID_Fatal + em = 'the checkpoint carries no range graphs' + END IF + IF (es /= CD_AGG_OK) THEN + ErrStat = ErrID_Fatal + ErrMsg = 'CableDyn mooring module: checkpoint rebuild of the range graphs (LINES flag r): '//TRIM(em) + END IF + END SUBROUTINE restore_range_state + SUBROUTINE shift_predictor_loads( inst_e, other ) !! The load predictor's previous commit when a new mooring step starts: the loads served !! since the last commit, when CalcOutput evaluated them there (its committed loads), and @@ -3169,6 +3266,8 @@ SUBROUTINE CD_End(u, p, x, xd, z, other, y, m, ErrStat , ErrMsg) CHARACTER(:), ALLOCATABLE :: asm_txt INTEGER :: k_i INTEGER :: sb_max, sb_ios + INTEGER(IntKi) :: range_es + CHARACTER(ErrMsgLen) :: range_em CHARACTER(24) :: sb_txt(5) REAL(wp) :: ht_step, ht_resid, ht_eff, ht_solve, ht_am, ht_tan CHARACTER(ErrMsgLen) :: ErrMsg2 @@ -3179,6 +3278,20 @@ SUBROUTINE CD_End(u, p, x, xd, z, other, y, m, ErrStat , ErrMsg) IF (ALLOCATED(Inst)) THEN IF (m%CDInst >= 1 .AND. m%CDInst <= SIZE(Inst)) THEN IF (Inst(m%CDInst)%active) THEN + ! The range graphs cover the whole run, so only a run that reached TMax writes them + ! (as the standalone driver, which writes them on completion); the glue also comes + ! here after an abort. TMax passes through ReKi, so the test allows its rounding. + IF (Inst(m%CDInst)%range_on) THEN + IF (Inst(m%CDInst)%t_commit >= p%Tmax - 1.0E-6_DbKi*p%dtM0 - & + 2.0_DbKi*REAL(EPSILON(1.0_ReKi), DbKi)*ABS(p%Tmax)) THEN + CALL CD_AGG_Range_Write( Inst(m%CDInst)%agg, TRIM(p%RootName), range_es, range_em ) + IF (range_es /= CD_AGG_OK) CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: '// & + TRIM(range_em), ErrStat, ErrMsg, RoutineName ) + ELSE + CALL WrScr( ' CableDyn: the run ended at t = '//TRIM(Num2LStr(Inst(m%CDInst)%t_commit))// & + ' s, before TMax = '//TRIM(Num2LStr(p%Tmax))//' s: no range graph is written.' ) + END IF + END IF ! the rotation- and snap-resolved sub-steps of the EI=0 lines (ei0_substeps), as the ! standalone driver reports them CALL CD_AGG_Get_Substep_Counts( Inst(m%CDInst)%agg, sb_calls, sb_events, sb_max, sb_capped, & diff --git a/src/openfast/CableDyn_Registry.txt b/src/openfast/CableDyn_Registry.txt index a4c32cf2..11194c8d 100644 --- a/src/openfast/CableDyn_Registry.txt +++ b/src/openfast/CableDyn_Registry.txt @@ -362,6 +362,7 @@ typedef ^ ^ DbKi t_commit - typedef ^ ^ DbKi pred_t - -1 - "load predictor: time of the committed solve before the last (negative: none), from which the coupled loads between supercycled solves are extrapolated" - typedef ^ ^ DbKi pred_loads {:} - - "load predictor: the coupled forces (3 x ncp) and then moments (3 x ncp) of that solve" - typedef ^ ^ DbKi fluid_held {:} - - "the held ambient-fluid fields of the last committed mooring step (velocity, acceleration, free-surface elevation, dynamic pressure at the line nodes), restored at a restart instead of re-sampled" - +typedef ^ ^ DbKi range_state {:} - - "the accumulated range graphs (LINES flag r) through the last committed mooring step, in double precision, restored at a restart" - ## ============================== Parameters ============================================================================================================================================ typedef ^ ParameterType IntKi nLineTypes - 0 - "number of line types" "" diff --git a/src/openfast/CableDyn_Types.f90 b/src/openfast/CableDyn_Types.f90 index e654f304..0cb3b4ce 100644 --- a/src/openfast/CableDyn_Types.f90 +++ b/src/openfast/CableDyn_Types.f90 @@ -396,6 +396,7 @@ MODULE CableDyn_Types REAL(DbKi) :: pred_t = -1 !< load predictor: time of the committed solve before the last (negative: none), from which the coupled loads between supercycled solves are extrapolated [-] REAL(DbKi) , DIMENSION(:), ALLOCATABLE :: pred_loads !< load predictor: the coupled forces (3 x ncp) and then moments (3 x ncp) of that solve [-] REAL(DbKi) , DIMENSION(:), ALLOCATABLE :: fluid_held !< the held ambient-fluid fields of the last committed mooring step (velocity, acceleration, free-surface elevation, dynamic pressure at the line nodes), restored at a restart instead of re-sampled [-] + REAL(DbKi) , DIMENSION(:), ALLOCATABLE :: range_state !< the accumulated range graphs (LINES flag r) through the last committed mooring step, in double precision, restored at a restart [-] END TYPE CD_OtherStateType ! ======================= ! ========= CD_ParameterType ======= @@ -3004,6 +3005,18 @@ subroutine CD_CopyOtherState(SrcOtherStateData, DstOtherStateData, CtrlCode, Err end if DstOtherStateData%fluid_held = SrcOtherStateData%fluid_held end if + if (allocated(SrcOtherStateData%range_state)) then + LB(1:1) = lbound(SrcOtherStateData%range_state) + UB(1:1) = ubound(SrcOtherStateData%range_state) + if (.not. allocated(DstOtherStateData%range_state)) then + allocate(DstOtherStateData%range_state(LB(1):UB(1)), stat=ErrStat2) + if (ErrStat2 /= 0) then + call SetErrStat(ErrID_Fatal, 'Error allocating DstOtherStateData%range_state.', ErrStat, ErrMsg, RoutineName) + return + end if + end if + DstOtherStateData%range_state = SrcOtherStateData%range_state + end if end subroutine subroutine CD_DestroyOtherState(OtherStateData, ErrStat, ErrMsg) @@ -3019,6 +3032,9 @@ subroutine CD_DestroyOtherState(OtherStateData, ErrStat, ErrMsg) if (allocated(OtherStateData%fluid_held)) then deallocate(OtherStateData%fluid_held) end if + if (allocated(OtherStateData%range_state)) then + deallocate(OtherStateData%range_state) + end if end subroutine subroutine CD_PackOtherState(RF, Indata) @@ -3031,6 +3047,7 @@ subroutine CD_PackOtherState(RF, Indata) call RegPack(RF, InData%pred_t) call RegPackAlloc(RF, InData%pred_loads) call RegPackAlloc(RF, InData%fluid_held) + call RegPackAlloc(RF, InData%range_state) if (RegCheckErr(RF, RoutineName)) return end subroutine @@ -3047,6 +3064,7 @@ subroutine CD_UnPackOtherState(RF, OutData) call RegUnpack(RF, OutData%pred_t); if (RegCheckErr(RF, RoutineName)) return call RegUnpackAlloc(RF, OutData%pred_loads); if (RegCheckErr(RF, RoutineName)) return call RegUnpackAlloc(RF, OutData%fluid_held); if (RegCheckErr(RF, RoutineName)) return + call RegUnpackAlloc(RF, OutData%range_state); if (RegCheckErr(RF, RoutineName)) return end subroutine subroutine CD_CopyParam(SrcParamData, DstParamData, CtrlCode, ErrStat, ErrMsg) diff --git a/tests/test_c_api.f90 b/tests/test_c_api.f90 index 03decc8b..78e49634 100644 --- a/tests/test_c_api.f90 +++ b/tests/test_c_api.f90 @@ -27,6 +27,7 @@ PROGRAM test_c_api CALL case_deck_init() CALL case_deck_dynamic_point_fluid() CALL case_deck_current_in_time() + CALL case_deck_range_flag() CALL case_deck_bodies_rods() CALL case_init_update_output_step() CALL case_multiline_shared_map() @@ -233,11 +234,41 @@ SUBROUTINE case_deck_current_in_time() CALL require(es == 0_C_INT .AND. .NOT. C_ASSOCIATED(handle), 'c-api-currents2:close') END SUBROUTINE case_deck_current_in_time - SUBROUTINE write_capi_currents_deck(path, row_later) + SUBROUTINE case_deck_range_flag() + !! The C ABI writes no result files: the LINES range-graph flag is refused by name, not + !! accepted and left without a file. + CHARACTER(*), PARAMETER :: DECK_PATH = 'capi_range_flag_deck.dat' + CHARACTER(KIND=C_CHAR), TARGET :: c_path(LEN(DECK_PATH)) + CHARACTER(KIND=C_CHAR), TARGET :: msg(300) + TYPE(C_PTR) :: handle + INTEGER(C_INT) :: es + INTEGER :: i + + DO i = 1, LEN(DECK_PATH) + c_path(i) = DECK_PATH(i:i) + END DO + CALL write_capi_currents_deck(DECK_PATH, '0.1 0.1 0.0 0.0', line_outputs='r') + CALL CableDyn_Create(handle, es) + CALL require(es == 0_C_INT .AND. C_ASSOCIATED(handle), 'c-api-range-flag:create') + CALL CableDyn_InitDeck(handle, C_LOC(c_path), INT(LEN(DECK_PATH), C_INT), es) + CALL require(es == 3_C_INT, 'c-api-range-flag:rejected') + CALL CableDyn_GetLastError(handle, C_LOC(msg), INT(SIZE(msg), C_INT)) + CALL require(INDEX(c_text(msg), 'flag r') > 0 .AND. INDEX(c_text(msg), 'C API') > 0, 'c-api-range-flag:message') + CALL CableDyn_Close(handle, es) + CALL require(es == 0_C_INT .AND. .NOT. C_ASSOCIATED(handle), 'c-api-range-flag:close') + END SUBROUTINE case_deck_range_flag + + SUBROUTINE write_capi_currents_deck(path, row_later, line_outputs) !! The smoke deck with Currents 2 and its current_profile_dynamic.txt: x velocities - !! 0.1 m/s at the two depths at t = 0 and the given row at t = 5 s. + !! 0.1 m/s at the two depths at t = 0 and the given row at t = 5 s. line_outputs gives the + !! LINES Outputs flags. CHARACTER(*), INTENT(IN) :: path, row_later + CHARACTER(*), INTENT(IN), OPTIONAL :: line_outputs INTEGER :: u, ios + CHARACTER(8) :: flags + + flags = '-' + IF (PRESENT(line_outputs)) flags = line_outputs OPEN (NEWUNIT=u, FILE='current_profile_dynamic.txt', STATUS='REPLACE', ACTION='WRITE', IOSTAT=ios) CALL require(ios == 0, 'c-api-currents2:create-table') @@ -267,7 +298,7 @@ SUBROUTINE write_capi_currents_deck(path, row_later) WRITE (u, '(A)') '--- LINES ---' WRITE (u, '(A)') 'ID NodeA NodeB Outputs' WRITE (u, '(A)') '(-) (-) (-) (-)' - WRITE (u, '(A)') '1 2 1 -' + WRITE (u, '(A)') '1 2 1 '//TRIM(flags) WRITE (u, '(A)') '--- SECTIONS ---' WRITE (u, '(A)') 'LineID LineType Length NumSegs' WRITE (u, '(A)') '(-) (-) (m) (-)' diff --git a/tests/test_openfast_aggregate.f90 b/tests/test_openfast_aggregate.f90 index 90d71e7a..04546052 100644 --- a/tests/test_openfast_aggregate.f90 +++ b/tests/test_openfast_aggregate.f90 @@ -39,7 +39,11 @@ PROGRAM test_openfast_aggregate CD_AGG_Refresh_PointMesh, CD_AGG_HasRigid6, CD_AGG_HasRod, & CD_AGG_Rigid6_MirrorSize, CD_AGG_Get_Rigid6_States, & CD_AGG_Set_Rigid6_States, CD_AGG_Rod_MirrorSize, & - CD_AGG_Get_Rod_States, CD_AGG_Set_Rod_States + CD_AGG_Get_Rod_States, CD_AGG_Set_Rod_States, & + CD_AGG_Range_Sample, CD_AGG_Range_Write, CD_AGG_Range_Discard, & + CD_AGG_Range_Graphs, CD_AGG_Range_MirrorSize, CD_AGG_Range_Get_State, & + CD_AGG_Range_Set_State + USE CableDyn_RangeOutput, ONLY: CD_RQ_TENSION, CD_RQ_CURVATURE, CD_RQ_BEND, CD_RQ_DECLINATION USE CableDyn_OpenFAST_FMF, ONLY: CD_FMF_ModuleType, CD_FMF_Init_From_Deck, CD_FMF_NMovingPoints, & CD_FMF_GetMovingPointMesh, CD_FMF_Step_Moving, CD_FMF_CalcOutput, & CD_FMF_End, CD_FMF_OK @@ -131,6 +135,7 @@ PROGRAM test_openfast_aggregate CALL case_touchdown_cable_end_tension() CALL case_anchor_uplift_channels() CALL case_output_channels() + CALL case_range_graph_host() CALL case_pure_cable_deck() CALL case_cable_load_feedback() CALL case_end_connection_orientation_and_moment() @@ -935,6 +940,196 @@ SUBROUTINE case_output_channels() IF (es == CD_AGG_OK) CALL CD_AGG_End(agg, es, em) END SUBROUTINE case_output_channels + SUBROUTINE case_range_graph_host() + !! The range graphs (LINES flag r) as the OpenFAST module drives them: one sample per committed + !! step from RangeStart, against the run's own node channels; a correction rewind that takes + !! the sample of the abandoned step back; the state mirror a checkpoint carries; the files of + !! a completed run, and the removal of an earlier run's; the refusal on a host that writes no + !! file; RangeStart against the host's run time, not the deck's standalone TMax. + INTEGER, PARAMETER :: NSTEP = 6, NCH = 9, CHK = 3 + REAL(wp), PARAMETER :: DT = 0.05_wp, RUN_T = NSTEP*DT, T_START = 0.1_wp + CHARACTER(*), PARAMETER :: ROW = 'Ten1N1 Ten1N10 Curv1N5 BendMom1N5 L1N5Dec Ten2N1 Ten2N5 Curv2N5 L2N5Dec' + ! the channels above: deck line, public node, range-graph row + INTEGER, PARAMETER :: CH_LINE(NCH) = [1, 1, 1, 1, 1, 2, 2, 2, 2], CH_NODE(NCH) = [1, 10, 5, 5, 5, 1, 5, 5, 5] + INTEGER, PARAMETER :: CH_ROW(NCH) = [CD_RQ_TENSION, CD_RQ_TENSION, CD_RQ_CURVATURE, CD_RQ_BEND, & + CD_RQ_DECLINATION, CD_RQ_TENSION, CD_RQ_TENSION, CD_RQ_CURVATURE, & + CD_RQ_DECLINATION] + TYPE(CD_AGG_ModuleType) :: agg, whole, back, plain + REAL(wp) :: r0(3, 2), vel(3, 2), acc(3, 2), lds(3, 2), cval, lo(NCH), hi(NCH), total(NCH), t + REAL(wp), ALLOCATABLE :: state(:), other(:), saved(:) + INTEGER :: es, ic, s, nsamp, u, ios, n + LOGICAL :: there + CHARACTER(512) :: em + CHARACTER(256) :: title + + ! a host that writes no file refuses the flag by name + CALL write_mixed_channels_deck('agg_range.dat', outputs_row=ROW, line_outputs='r', extra_option='0.0 TMax', & + extra_option2='0.1 RangeStart') + CALL CD_AGG_Init_From_Deck(agg, 'agg_range.dat', DT, es, em, run_tmax=RUN_T) + CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'flag r') > 0 .AND. INDEX(em, 'FAST.Farm') > 0 .AND. & + INDEX(em, 'C API') > 0, & + 'range:host-without-files-refused: '//TRIM(em)) + + ! RangeStart holds against the host's run time, and the deck's own TMax = 0 does not clamp it + CALL CD_AGG_Init_From_Deck(agg, 'agg_range.dat', DT, es, em, run_tmax=0.05_wp, range_files=.TRUE.) + CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'RangeStart exceeds TMax') > 0, & + 'range:window-beyond-host-run-refused: '//TRIM(em)) + CALL CD_AGG_Init_From_Deck(agg, 'agg_range.dat', DT, es, em, run_tmax=RUN_T, range_files=.TRUE.) + CALL require(es == CD_AGG_OK, 'range:init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL require(ABS(agg%ranges%t_start - T_START) <= 0.0_wp, 'range:host-window-start') + CALL require(CD_AGG_Range_Graphs(agg), 'range:graphs-requested') + CALL CD_AGG_Init_From_Deck(whole, 'agg_range.dat', DT, es, em, run_tmax=RUN_T, range_files=.TRUE.) + CALL require(es == CD_AGG_OK, 'range:whole-init: '//TRIM(em)) + CALL CD_AGG_Init_From_Deck(back, 'agg_range.dat', DT, es, em, run_tmax=RUN_T, range_files=.TRUE.) + CALL require(es == CD_AGG_OK, 'range:restart-init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + + n = CD_AGG_Range_MirrorSize(agg) + ! four head reals, the arc and three seven-row envelopes per node, per line + CALL require(n == 2*4 + 22*(agg%ranges%lines(1)%nn + agg%ranges%lines(2)%nn), 'range:mirror-size') + ALLOCATE (state(n), other(n), saved(n)) + + CALL CD_AGG_GetMovingPointMesh(agg, r0, vel, acc, lds, es, em) + CALL require(es == CD_AGG_OK, 'range:mesh0: '//TRIM(em)) + lo = HUGE(1.0_wp) + hi = -HUGE(1.0_wp) + total = 0.0_wp + nsamp = 0 + CALL CD_AGG_Range_Sample(agg, 0.0_wp, es, em) + CALL require(es == CD_AGG_OK, 'range:sample0: '//TRIM(em)) + CALL CD_AGG_Range_Sample(whole, 0.0_wp, es, em) + CALL require(es == CD_AGG_OK, 'range:whole-sample0: '//TRIM(em)) + DO s = 1, NSTEP + t = REAL(s, wp)*DT + IF (s == CHK) THEN + ! a correction: an abandoned advance with other motion, sampled, then rewound + CALL CD_AGG_Snapshot(agg, es, em) + CALL require(es == CD_AGG_OK, 'range:snapshot: '//TRIM(em)) + CALL range_march(agg, r0, DT, s, 40.0_wp, 'range:abandoned-step') + CALL CD_AGG_Range_Sample(agg, t, es, em) + CALL require(es == CD_AGG_OK, 'range:abandoned-sample: '//TRIM(em)) + CALL CD_AGG_Range_Get_State(agg, state, es, em) + CALL CD_AGG_Range_Get_State(whole, other, es, em) + CALL require(nan_max_abs(state - other) > 0.0_wp, 'range:abandoned-sample-counts') + CALL CD_AGG_Restore(agg, es, em) + CALL require(es == CD_AGG_OK, 'range:restore: '//TRIM(em)) + CALL CD_AGG_Range_Get_State(agg, state, es, em) + CALL require(nan_max_abs(state - other) <= 0.0_wp, 'range:rewind-takes-the-sample-back') + END IF + CALL range_march(agg, r0, DT, s, 1.0_wp, 'range:step') + CALL CD_AGG_Range_Sample(agg, t, es, em) + CALL require(es == CD_AGG_OK, 'range:sample: '//TRIM(em)) + CALL range_march(whole, r0, DT, s, 1.0_wp, 'range:whole-step') + CALL CD_AGG_Range_Sample(whole, t, es, em) + CALL require(es == CD_AGG_OK, 'range:whole-sample: '//TRIM(em)) + IF (s <= CHK) CALL range_march(back, r0, DT, s, 1.0_wp, 'range:restart-step') + IF (s == CHK) THEN + CALL CD_AGG_Range_Get_State(whole, saved, es, em) + CALL require(es == CD_AGG_OK, 'range:mirror-get: '//TRIM(em)) + CALL CD_AGG_Range_Set_State(back, saved, es, em) + CALL require(es == CD_AGG_OK, 'range:mirror-set: '//TRIM(em)) + ELSE IF (s > CHK) THEN + CALL range_march(back, r0, DT, s, 1.0_wp, 'range:restart-step') + CALL CD_AGG_Range_Sample(back, t, es, em) + CALL require(es == CD_AGG_OK, 'range:restart-sample: '//TRIM(em)) + END IF + IF (t < T_START - 1.0e-9_wp) CYCLE + nsamp = nsamp + 1 + DO ic = 1, NCH + CALL CD_AGG_EvalChannel(agg, ic, cval, es, em) + CALL require(es == CD_AGG_OK, 'range:channel: '//TRIM(em)) + lo(ic) = MIN(lo(ic), cval) + hi(ic) = MAX(hi(ic), cval) + total(ic) = total(ic) + cval + END DO + END DO + + ! the envelopes are the node channels' own extremes and mean over the window + DO ic = 1, NCH + ASSOCIATE (rl => agg%ranges%lines(CH_LINE(ic))) + CALL require(rl%nsample == nsamp, 'range:one-sample-per-committed-step-in-the-window') + CALL require(ABS(rl%vmin(CH_ROW(ic), CH_NODE(ic)) - lo(ic)) <= 1.0e-12_wp*MAX(ABS(lo(ic)), 1.0e-12_wp), & + 'range:min-equals-channel') + CALL require(ABS(rl%vmax(CH_ROW(ic), CH_NODE(ic)) - hi(ic)) <= 1.0e-12_wp*MAX(ABS(hi(ic)), 1.0e-12_wp), & + 'range:max-equals-channel') + CALL require(ABS(rl%vsum(CH_ROW(ic), CH_NODE(ic)) - total(ic)) <= 1.0e-12_wp*MAX(ABS(total(ic)), 1.0e-12_wp), & + 'range:mean-equals-channel') + CALL require(ABS(rl%t_first - T_START) <= 1.0e-12_wp .AND. ABS(rl%t_last - RUN_T) <= 1.0e-12_wp, & + 'range:window-times') + END ASSOCIATE + END DO + CALL require(hi(2) > lo(2), 'range:channel-moved') + ! the rewound and the restored runs match the uninterrupted one bit for bit + CALL CD_AGG_Range_Get_State(agg, state, es, em) + CALL CD_AGG_Range_Get_State(whole, other, es, em) + CALL require(nan_max_abs(state - other) <= 0.0_wp, 'range:corrected-equals-uninterrupted') + CALL CD_AGG_Range_Get_State(back, state, es, em) + CALL require(nan_max_abs(state - other) <= 0.0_wp, 'range:restored-equals-uninterrupted') + CALL CD_AGG_Range_Set_State(back, saved(1:n - 1), es, em) + CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'do not match') > 0, & + 'range:mirror-of-another-deck-refused: '//TRIM(em)) + + ! a file of an earlier run goes at the start of the run; the completed run writes its own + OPEN (NEWUNIT=u, FILE='agg_range.Line2.range.out', STATUS='REPLACE', ACTION='WRITE', IOSTAT=ios) + WRITE (u, '(A)') 'stale' + CLOSE (u) + CALL CD_AGG_Range_Discard(agg, 'agg_range', es, em) + CALL require(es == CD_AGG_OK, 'range:discard: '//TRIM(em)) + INQUIRE (FILE='agg_range.Line2.range.out', EXIST=there) + CALL require(.NOT. there, 'range:earlier-file-removed') + CALL CD_AGG_Range_Discard(agg, 'agg_range', es, em) + CALL require(es == CD_AGG_OK, 'range:discard-without-a-file: '//TRIM(em)) + CALL CD_AGG_Range_Write(agg, 'agg_range', es, em) + CALL require(es == CD_AGG_OK, 'range:write: '//TRIM(em)) + OPEN (NEWUNIT=u, FILE='agg_range.Line2.range.out', STATUS='OLD', ACTION='READ', IOSTAT=ios) + CALL require(ios == 0, 'range:file-at-root') + IF (ios == 0) THEN + READ (u, '(A)', IOSTAT=ios) title + CLOSE (u) + CALL require(ios == 0 .AND. INDEX(title, 'line 2; 5 samples') > 0, 'range:file-title: '//TRIM(title)) + END IF + CALL CD_AGG_End(agg, es, em) + CALL CD_AGG_End(whole, es, em) + CALL CD_AGG_End(back, es, em) + + ! a deck without the flag has nothing to sample or mirror, also with range_files + CALL write_mixed_channels_deck('agg_range_none.dat', outputs_row=ROW) + CALL CD_AGG_Init_From_Deck(plain, 'agg_range_none.dat', DT, es, em, run_tmax=RUN_T, range_files=.TRUE.) + CALL require(es == CD_AGG_OK, 'range:plain-init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL require(.NOT. CD_AGG_Range_Graphs(plain) .AND. CD_AGG_Range_MirrorSize(plain) == 0, 'range:plain-empty') + CALL CD_AGG_End(plain, es, em) + END SUBROUTINE case_range_graph_host + + SUBROUTINE range_march(a, r0, dt, step, amplitude, label) + !! Advance to step's committed time with a small surge and heave of the fairleads about r0, + !! scaled by amplitude: the same motion for every instance at amplitude 1. + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: a + REAL(wp), INTENT(IN) :: r0(3, 2), dt, amplitude + INTEGER, INTENT(IN) :: step + CHARACTER(*), INTENT(IN) :: label + REAL(wp), PARAMETER :: OMEGA = 2.0_wp*PI/1.2_wp + REAL(wp) :: tc, tgt(3, 2), v(3, 2), ac(3, 2), wave + INTEGER :: ni, es + LOGICAL :: cv, st + CHARACTER(512) :: em + + tc = REAL(step, wp)*dt + wave = 0.2_wp*amplitude + tgt = r0 + tgt(1, :) = r0(1, :) + wave*SIN(OMEGA*tc) + tgt(3, :) = r0(3, :) + 0.5_wp*wave*SIN(OMEGA*tc) + v = 0.0_wp + v(1, :) = wave*OMEGA*COS(OMEGA*tc) + v(3, :) = 0.5_wp*wave*OMEGA*COS(OMEGA*tc) + ac = 0.0_wp + ac(1, :) = -wave*OMEGA**2*SIN(OMEGA*tc) + ac(3, :) = -0.5_wp*wave*OMEGA**2*SIN(OMEGA*tc) + CALL CD_AGG_Step_Moving(a, dt, tgt, v, ac, cv, st, ni, es, em, t_committed=tc) + CALL require(es == CD_AGG_OK .AND. cv, label//': '//TRIM(em)) + END SUBROUTINE range_march + SUBROUTINE check_static_profile(path, expected_rows) CHARACTER(*), INTENT(IN) :: path INTEGER, INTENT(IN) :: expected_rows @@ -5422,18 +5617,22 @@ SUBROUTINE write_control_section(u, rows) END DO END SUBROUTINE write_control_section - SUBROUTINE write_mixed_channels_deck(path, point_channel_id, outputs_row) + SUBROUTINE write_mixed_channels_deck(path, point_channel_id, outputs_row, line_outputs, extra_option, extra_option2) !! The write_mixed_deck geometry (cable = line 1, mooring chain = line 2) plus an OUTPUTS !! section exercising both objects and multiple channel kinds: FairTen/AnchTen on the mooring, !! and curvature / fairlead-angle / bend-moment / nodal-tension on the cable. outputs_row - !! replaces the default OUTPUTS row. + !! replaces the default OUTPUTS row, line_outputs the LINES Outputs flags of both lines; + !! extra_option and extra_option2 add OPTIONS rows. CHARACTER(*), INTENT(IN) :: path INTEGER, INTENT(IN), OPTIONAL :: point_channel_id - CHARACTER(*), INTENT(IN), OPTIONAL :: outputs_row + CHARACTER(*), INTENT(IN), OPTIONAL :: outputs_row, line_outputs, extra_option, extra_option2 INTEGER :: u, ios INTEGER :: point_id + CHARACTER(8) :: flags point_id = 0 IF (PRESENT(point_channel_id)) point_id = point_channel_id + flags = '-' + IF (PRESENT(line_outputs)) flags = line_outputs OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE', IOSTAT=ios) WRITE (u, '(A)') 'MIXED deck with OUTPUTS: EI=0 chain mooring + finite-EI lazy-wave cable' WRITE (u, '(A)') '--- LINE TYPES ---' @@ -5453,8 +5652,8 @@ SUBROUTINE write_mixed_channels_deck(path, point_channel_id, outputs_row) WRITE (u, '(A)') '--- LINES ---' WRITE (u, '(A)') 'ID NodeA NodeB Outputs' WRITE (u, '(A)') '(-) (-) (-) (-)' - WRITE (u, '(A)') '1 1 2 -' - WRITE (u, '(A)') '2 3 4 -' + WRITE (u, '(A)') '1 1 2 '//TRIM(flags) + WRITE (u, '(A)') '2 3 4 '//TRIM(flags) WRITE (u, '(A)') '--- SECTIONS ---' WRITE (u, '(A)') 'LineID LineType Length NumSegs' WRITE (u, '(A)') '(-) (-) (m) (-)' @@ -5469,6 +5668,8 @@ SUBROUTINE write_mixed_channels_deck(path, point_channel_id, outputs_row) WRITE (u, '(A)') '3.0e6 kBot' WRITE (u, '(A)') '3.0e5 cBot' WRITE (u, '(A)') '0.5 rhoInf' + IF (PRESENT(extra_option)) WRITE (u, '(A)') extra_option + IF (PRESENT(extra_option2)) WRITE (u, '(A)') extra_option2 WRITE (u, '(A)') '--- OUTPUTS ---' IF (point_id > 0) THEN WRITE (u, '(A,I0,A)') 'Point', point_id, 'px' From e9354fca4e834f1e27e0a092af3c0a492b7cd151 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Sat, 7 Nov 2026 21:04:55 +0900 Subject: [PATCH 2/3] feat(openfast): note a coarse deepest interval of the SeaState depth grid SeaState's depth levels are cosine-spaced, so the grid is coarsest at the bottom: the deepest interval is Z_Depth*sin(pi/(2*(NZ - 1))), about 22 m at 200 m depth with NZ = 15, and the field is linear across it down to the seabed, unlike a deck depth table. The OpenFAST module now says so at initialisation when that interval exceeds 5 % of the depth (NZ below 33) and a line lies in it, with the interval, the nodes in it and the NZ that brings it under 5 %. For the 1/7-power current the linear ramp is up to 62 % low whatever the interval is, so the interval alone sets how much of the column carries the difference: the depth integral lacks 3/7*(H/D)^(8/7), 1.4 % at the threshold and 3.5 % at NZ = 15. The note applies only when waves or a current come from SeaState and the grid reaches the seabed; a shorter grid has the out-of-grid warning. It is printed once, at initialisation, and changes no result. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 2 ++ doc/openfast.rst | 6 +++++ src/openfast/CableDyn_OF.f90 | 44 ++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cbf9029..5a3ac26d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ All notable changes to CableDyn are recorded in this file. The format follows `.CD.out`, once per step when OpenFAST retries a step, and across a checkpoint restart. The file appears when the run reaches `TMax`. A FAST.Farm shared mooring and the C API reject the flag by name. +- An OpenFAST initialisation note when the deepest interval of the SeaState depth grid exceeds 5 % + of the depth and a line lies in it: the field is linear there, unlike a deck depth table. ### Changed diff --git a/doc/openfast.rst b/doc/openfast.rst index 4aefbca4..e22d65a1 100644 --- a/doc/openfast.rst +++ b/doc/openfast.rst @@ -207,6 +207,12 @@ the seabed (``Z_Depth = WtrDpth + MSL2SWL``): they are in the seabed, where the grid bottom are the right ones. FAST.Farm runs, which use still water, and SeaState fields without waves or current are not checked. +SeaState's cosine depth grid is coarsest at the bottom: its deepest interval is +``Z_Depth*sin(pi/(2*(NZ - 1)))``, about 22 m at 200 m depth with ``NZ = 15``, and the field falls +linearly across it to the seabed, so near the seabed it differs from a deck depth table; when that +interval exceeds 5 % of the depth (``NZ`` below 33) and a line lies in it, an initialisation note +states the interval and the ``NZ`` that would bring it under 5 %. + Run and confirm --------------- diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index 9b517ac3..66d91374 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -142,6 +142,10 @@ MODULE CableDyn PRIVATE + ! Depth fraction above which the deepest interval of the SeaState grid is noted at initialisation + ! (note_seastate_deep_interval). + REAL(wp), PARAMETER :: SEASTATE_DEEP_INTERVAL = 0.05_wp + ! the kinds of first-order linearization state (lin_state_map) INTEGER(IntKi), PARAMETER :: LIN1_VE = 1, LIN1_SYROPE = 2 @@ -997,6 +1001,7 @@ 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 + CALL note_seastate_deep_interval( Inst(id), InitInp%WaveField ) END IF ! The coupling mesh carries ONLY the host-prescribed (Coupled/Vessel) points. @@ -2336,6 +2341,45 @@ SUBROUTINE check_wavefield_grid( inst_e, wf, t_sample, at_init, wl_sampled, ErrS IF (at_init) CALL WrScr( ' WARNING: '//msg ) END SUBROUTINE check_wavefield_grid + 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 + !! are z_k = Z_Depth*(sin(k*delta) - 1) with delta = pi/(2*(NZ - 1)): the grid is finest at + !! the surface and coarsest at the bottom, where the interval H = Z_Depth*sin(delta) is + !! pi/2 times the uniform spacing. Inside H the field is interpolated linearly down to the + !! seabed. For the 1/7-power current of CurrMod 1 that is up to 62 % of the value at the top + !! of the interval low, whatever H is, so H alone sets how much of the column carries the + !! difference: the depth integral of the current lacks 3/7*(H/D)^(8/7) of its value, 1.4 % + !! at the threshold H = 5 % of the depth (NZ >= 33 stays below it) and 3.5 % at NZ = 15. A + !! grid short of the seabed has the out-of-grid warning of check_wavefield_grid instead. + !! Reads the grid and the node positions and writes to the screen only. + TYPE(CD_OF_Instance), INTENT(IN) :: inst_e + TYPE(SeaSt_WaveFieldType), INTENT(IN) :: wf + REAL(wp), PARAMETER :: HALF_PI = 2.0_wp*ATAN(1.0_wp) + LOGICAL :: waves, grid_current + INTEGER(IntKi) :: nz, nodes + REAL(wp) :: depth, interval + + waves = inst_e%agg%host_wave_enabled .AND. wf%WaveMod /= WaveMod_None + grid_current = inst_e%agg%host_current_enabled .AND. wf%Current_InitInput%CurrMod /= 0_IntKi + nz = wf%VolGridParams%n(4) + IF (.NOT. (waves .OR. grid_current) .OR. nz < 2_IntKi) RETURN + depth = REAL(wf%GridDepth, wp) + interval = depth*SIN(REAL(wf%VolGridParams%delta(4), wp)) + IF (depth < REAL(wf%EffWtrDpth, wp) - 0.01_wp*interval) RETURN + IF (interval <= SEASTATE_DEEP_INTERVAL*depth) RETURN + nodes = COUNT(inst_e%fx_xyz(3, 1:inst_e%nfluid) < interval - depth) + IF (nodes == 0_IntKi) RETURN + CALL WrScr( ' Note: the deepest interval of the SeaState depth grid is '//TRIM(Num2LStr(interval))// & + ' m (NZ = '//TRIM(Num2LStr(nz))//', Z_Depth = '//TRIM(Num2LStr(depth))//' m), over '// & + TRIM(Num2LStr(NINT(100.0_wp*SEASTATE_DEEP_INTERVAL)))//' % of the depth, and '// & + TRIM(Num2LStr(nodes))//' of the '//TRIM(Num2LStr(inst_e%nfluid))// & + ' CableDyn sampling nodes lie in it. The field is linear there, so near the seabed '// & + 'it differs from a deck depth table. More depth levels refine it: NZ = '// & + TRIM(Num2LStr(1_IntKi + CEILING(HALF_PI/ASIN(SEASTATE_DEEP_INTERVAL), IntKi)))// & + ' or more in the SeaState input file.' ) + END SUBROUTINE note_seastate_deep_interval + SUBROUTINE check_current_field_grid( inst_e, wf, t_sample ) !! A dynamically populated current field (an InflowWind-driven MHK current, hasCurrField) is !! not read on the SeaState grid: InflowWind reads it on its own field at the node position From eee5d765d9195dedd022f1385c83c81c53dc15bc Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Sat, 7 Nov 2026 21:14:24 +0900 Subject: [PATCH 3/3] chore: keep the changelog entry for the release batch Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a3ac26d..345466ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,26 +8,6 @@ All notable changes to CableDyn are recorded in this file. The format follows ## [Unreleased] -### Added - -- Range graphs in coupled OpenFAST runs: the `LINES` `Outputs` flag `r` and `RangeStart` now write - `.CD.Line.range.out` in a single-turbine run, from the committed `dtM` steps of - `.CD.out`, once per step when OpenFAST retries a step, and across a checkpoint restart. The - file appears when the run reaches `TMax`. A FAST.Farm shared mooring and the C API reject the - flag by name. -- An OpenFAST initialisation note when the deepest interval of the SeaState depth grid exceeds 5 % - of the depth and a line lies in it: the field is linear there, unlike a deck depth table. - -### Changed - -- OpenFAST checkpoints carry the accumulated range graphs: a checkpoint written by an earlier - CableDyn cannot be restarted with this one. -- The C API refuses the flag `r` on `EI = 0` decks too, which it accepted without writing a file. - -### Fixed - -- A range-graph file that cannot be written completely is removed instead of left behind. - ## [0.4.0] - 2026-11-04 ### Added