From 84ea3db9b07b7ecc3def9de6605191638d64a1a7 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Sun, 8 Nov 2026 23:46:16 +0900 Subject: [PATCH 1/3] fix(options): an overridden waves or current row leaves no bound behind The last waves row and the last current row are the ones in effect, and the reader checks the magnitude bounds of a regular, stream or JONSWAP waves row (height, period, gamma) and of a current row (speed, profile depth) once OPTIONS is read, on that row alone. Two values of an overridden row survived into that check: - an Airy or stream waves row kept the gamma of an earlier JONSWAP row, so "jonswap 3 10 2000 0 waves" followed by "airy 2 8 0 waves" was refused for a gamma above 1e3 that the Airy wave does not have; - a profile current row kept the velocity of an earlier uniform row, so "uniform 2000 0 0 current" followed by a profile row was refused for a speed above 1e3 m/s. Both rows now reset what the earlier row set. The physics is unchanged: a regular wave never reads gamma and a profile current never reads the uniform velocity. The Python deck validator applied those magnitude bounds to every row as it read it, and so refused a deck whose out-of-range row a later row overrides (for example "airy 2000 8 0 waves" followed by "none waves"), which the solver runs. It now checks the row rules (positive height and period, gamma >= 1, distinct profile depths, every spectral and wavetrain row) on every row and the magnitude bounds on the waves and current rows in effect, as the native reader does. Editing a waves or current row keeps the full check. Tests: test_deck_driver runs four overridden-row decks and refuses an out-of-range effective row; the parity tests check twenty override cases against the validator and, with the driver, against the native verdict. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 6 ++++ python/cabledyn/deck_file.py | 31 ++++++++++++++--- python/tests/test_deck_native_parity.py | 44 +++++++++++++++++++++++++ src/CableDyn_DeckDriver.f90 | 4 +++ tests/test_deck_driver.f90 | 36 ++++++++++++++++++++ 5 files changed, 116 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3549554..9d36b74f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,12 @@ All notable changes to CableDyn are recorded in this file. The format follows The touchdown element now takes the reaction of its grounded stretch, from the grounded node to the touchdown point located from the two nodes' clearances: the error falls at the second order (2.1, 0.7, 0.2 N) and the outputs vary continuously. +- A `waves` or `current` row overridden by a later one no longer leaves a bound behind: an Airy + or stream `waves` row after a JONSWAP row was refused for that row's gamma above 1e3, and a + `profile` current row after a `uniform` one for that row's velocity above 1e3 m/s. The Python + deck validator now applies the magnitude bounds of these rows (wave height and period, JONSWAP + gamma, current speed and depth) to the row in effect only, as the solver does, instead of + refusing a deck for an out-of-range row a later row overrides. ## [0.4.1] - 2026-11-08 diff --git a/python/cabledyn/deck_file.py b/python/cabledyn/deck_file.py index c9e957f1..24f38edb 100644 --- a/python/cabledyn/deck_file.py +++ b/python/cabledyn/deck_file.py @@ -1018,8 +1018,15 @@ def _positional_numbers_are_finite(tokens: list[str]) -> bool: return False -def _positional_range_error(tokens: list[str]) -> str | None: - """Return a native-finalizer range error for a parsed positional option.""" +def _positional_range_error(tokens: list[str], *, effective: bool = True) -> str | None: + """Return a native range error for a parsed positional option. + + The native reader checks some rules on every row as it reads it (positive wave + height and period, distinct profile depths, every spectral and wavetrain row) and + the magnitude bounds of a regular or JONSWAP ``waves`` row and of a ``current`` row + only on the row in effect once OPTIONS is read: the last one. ``effective=False`` + returns the per-row rules alone, for a row a later row may override. + """ mode = tokens[0].lower() if mode == "profile": # The native two-point parser accepts either input direction and @@ -1028,7 +1035,7 @@ def _positional_range_error(tokens: list[str]) -> str | None: if abs(_native_float(tokens[5]) - _native_float(tokens[1])) <= 100.0 * math.ulp(1.0): return "current profile depths must be strictly increasing" values = [_native_float(token) for token in tokens[1:9]] - if ( + if effective and ( abs(values[0]) > _NATIVE_MAX_COORDINATE or abs(values[4]) > _NATIVE_MAX_COORDINATE or any(abs(value) > _NATIVE_MAX_FLUID_SPEED for value in values[1:4] + values[5:8]) @@ -1038,7 +1045,9 @@ def _positional_range_error(tokens: list[str]) -> str | None: "in magnitude" ) elif mode == "uniform": - if any(abs(_native_float(token)) > _NATIVE_MAX_FLUID_SPEED for token in tokens[1:4]): + if effective and any( + abs(_native_float(token)) > _NATIVE_MAX_FLUID_SPEED for token in tokens[1:4] + ): return "OPTION current velocity components must be at most 1e3 m/s" elif ( mode in {"airy", "jonswap", "stream", "dean"} @@ -1049,6 +1058,8 @@ def _positional_range_error(tokens: list[str]) -> str | None: gamma = _native_float(tokens[3]) if mode == "jonswap" else 1.0 if height <= 0.0 or period <= 0.0 or gamma < 1.0: return "waves require positive height/period and JONSWAP gamma >= 1" + if not effective: + return None low, high = _NATIVE_WAVE_PERIOD_RANGE if height > _NATIVE_MAX_WAVE_HEIGHT or not low <= period <= high: return "waves need height <= 1e3 m and period in [0.1, 1e5] s" @@ -3255,7 +3266,8 @@ def _option_row(self, index: int) -> OptionRecord | None: raise DeckFormatError( f"{where}: positional option values must be finite plain numbers" ) - if error := _positional_range_error(tokens): + # the magnitude bounds apply to the row in effect only (``_validate``) + if error := _positional_range_error(tokens, effective=False): raise DeckFormatError(f"{where}: {error}") _raise_option_defect(where, tokens) return OptionRecord(index, tokens[-1], tuple(tokens[:-1]), description) @@ -3380,6 +3392,15 @@ def _validate(self) -> None: options = self.options channels = self.outputs option_by_key = {_option_key(option.keyword): option for option in options} + # native finalize_checks: the magnitude bounds of the waves and current rows in + # effect (the last of each); a row a later row overrides takes its row rules only + for key in ("waves", "current"): + record = option_by_key.get(key) + if record is None or record.keyword_first: + continue + tokens = [*record.values, record.keyword] + if _is_positional_option(tokens) and (error := _positional_range_error(tokens)): + raise DeckFormatError(f"{self._label}:{record.index + 1}: {error}") has_depth = "water_depth" in option_by_key has_bathymetry = "bathymetry" in option_by_key if has_depth and has_bathymetry: diff --git a/python/tests/test_deck_native_parity.py b/python/tests/test_deck_native_parity.py index df4b1368..7d1ee333 100644 --- a/python/tests/test_deck_native_parity.py +++ b/python/tests/test_deck_native_parity.py @@ -584,12 +584,41 @@ def _carries_waves(name: str) -> bool: if _carries_waves(name) for variant in ("spelled", "upper") ] +_PROFILE_ROW = "profile -30 0.2 0 0 0 0.5 0 0 current" +# (rows, message): the last waves or current row is the one in effect; the native reader +# checks the magnitude bounds on that row alone and the row rules on every row +_OVERRIDDEN_ROW_CASES = [ + (("airy 2000 8 0 waves", "none waves"), None), + (("airy 2 0.01 0 waves", "airy 2 8 0 waves"), None), + (("stream 2 2e5 0 waves", "pm 3 10 0 waves"), None), + (("jonswap 3 10 40 0 waves", "airy 2 8 0 waves"), None), + (("jonswap 3 10 2000 0 waves", "airy 2 8 0 waves"), None), + (("jonswap 3 10 2000 0 waves", "stream 2 8 0 waves"), None), + (("jonswap 3000 10 3.3 0 waves", "none waves"), None), + (("uniform 2000 0 0 current", "none current"), None), + (("uniform 2000 0 0 current", _PROFILE_ROW), None), + (("profile -2e6 0.2 0 0 0 0.5 0 0 current", "uniform 0.1 0 0 current"), None), + (("profile -30 2000 0 0 0 0.5 0 0 current", _PROFILE_ROW), None), + (("airy 2 8 0 waves", "airy 2000 8 0 waves"), r"waves need height <= 1e3 m"), + (("none waves", "jonswap 3 10 40 0 waves"), r"JONSWAP gamma must be in \[1, 32\.6\)"), + (("airy 2 8 0 waves", "jonswap 3 10 2000 0 waves"), r"JONSWAP gamma must be in \[1, 32\.6\)"), + ((_PROFILE_ROW, "uniform 2000 0 0 current"), r"at most 1e3 m/s"), + (("uniform 0.1 0 0 current", "profile -2e6 0.2 0 0 0 0.5 0 0 current"), r"at most 1e6 m"), + # the row rules hold on an overridden row too + (("airy 0 8 0 waves", "none waves"), r"positive height/period"), + (("jonswap 3 10 0.5 0 waves", "airy 2 8 0 waves"), r"JONSWAP gamma >= 1"), + (("profile -30 0.2 0 0 -30 0.5 0 0 current", "none current"), r"strictly increasing"), + (("pm 3000 10 0 waves", "none waves"), r"a wave train needs height <= 1e3 m"), +] + + _ALL_FILE_CASES = [ *[("held", rows, files) for rows, files in _WAVE_RECORD_CASES], *_ANCILLARY_CASES, *_SPELLED_CASES, *_STATIC_CASES, *_SHIPPED_CASES, + *[("held", rows, {}) for rows, _ in _OVERRIDDEN_ROW_CASES], ] @@ -827,6 +856,21 @@ def test_jonswap_gamma_limit_applies_on_every_path(rows): _rejects(_options(_HELD, *rows), r"JONSWAP gamma must be in \[1, 32\.6\)") +@pytest.mark.parametrize(("rows", "message"), _OVERRIDDEN_ROW_CASES) +def test_magnitude_bounds_apply_to_the_waves_and_current_rows_in_effect(rows, message): + text = _options(_HELD, *rows) + if message is None: + DeckFile.from_text(text) + else: + _rejects(text, message) + + +def test_an_edited_waves_row_takes_the_magnitude_bounds(): + deck = DeckFile.from_text(_options(_HELD, "airy 2000 8 0 waves", "airy 2 8 0 waves")) + with pytest.raises(ValueError, match="waves need height <= 1e3 m"): + deck.set_option("waves", ("airy", 2000.0, 8.0, 0.0)) + + def test_spread_jonswap_row_is_validated_as_a_wave_train(): DeckFile.from_text(_options(_HELD, "jonswap 2 8 3.3 2e6 waves")) _rejects( diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index 6aa49a46..33dea36d 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -17093,6 +17093,8 @@ SUBROUTINE apply_option(line, opts, ErrStat, ErrMsg) opts%current_profile_velocity(:, 1) = [x6, x7, x8] opts%current_profile_velocity(:, 2) = [x2, x3, x4] END IF + ! last row wins: an earlier uniform row leaves no velocity behind + opts%current_velocity = CD_ZERO opts%has_current = .TRUE. opts%has_current_profile = .TRUE. RETURN @@ -17148,6 +17150,8 @@ SUBROUTINE apply_option(line, opts, ErrStat, ErrMsg) opts%wave_height = x1 opts%wave_period = x2 opts%wave_direction = x3 + ! last row wins: a regular wave has no gamma, so an earlier JONSWAP row leaves none + opts%wave_gamma = CD_ONE opts%has_wave = .TRUE. opts%wave_kind = WAVE_AIRY IF (to_lower(TRIM(mode)) /= 'airy') opts%wave_kind = WAVE_STREAM diff --git a/tests/test_deck_driver.f90 b/tests/test_deck_driver.f90 index 78f0d38a..96adb521 100644 --- a/tests/test_deck_driver.f90 +++ b/tests/test_deck_driver.f90 @@ -2197,6 +2197,42 @@ SUBROUTINE check_parser_hardening() 'LINE 1 combines EI=0 and finite-EI sections') END IF END BLOCK + + ! The last waves or current row sets the sea: a row it overrides leaves nothing behind + ! that the bounds of the effective row are checked against (a JONSWAP gamma under an + ! Airy row, a uniform velocity under a profile row), while the effective row is checked. + BLOCK + CHARACTER(1) :: nl + CHARACTER(*), PARAMETER :: CLOCK = '0.1 dtM'//NEW_LINE('a')//'0.2 TMax' + CHARACTER(64), PARAMETER :: OVERRIDDEN(4) = [CHARACTER(64) :: & + 'jonswap 3.0 10.0 2000.0 0.0 waves', & + 'jonswap 3.0 10.0 2000.0 0.0 waves', & + 'uniform 2000.0 0.0 0.0 current', & + 'airy 2000.0 8.0 0.0 waves'] + CHARACTER(64), PARAMETER :: EFFECTIVE(4) = [CHARACTER(64) :: & + 'airy 2.0 8.0 0.0 waves', 'stream 2.0 8.0 0.0 waves', & + 'profile -30 0.2 0 0 0 0.5 0 0 current', 'none waves'] + INTEGER :: k + nl = NEW_LINE('a') + DO k = 1, SIZE(OVERRIDDEN) + CALL write_text_file('deck_hard_overridden.dat', hardening_deck(ANCHOR, SECTION, CLOCK//nl// & + TRIM(OVERRIDDEN(k))//nl//TRIM(EFFECTIVE(k)), & + 'FairTen1')) + CALL CD_Run_Deck_Driver('deck_hard_overridden.dat', 'deck_hard_overridden', conv_l, es_l, em_l) + CALL require(es_l == CD_DECKDRV_OK .AND. conv_l, '"'//TRIM(OVERRIDDEN(k))//'" overridden by "'// & + TRIM(EFFECTIVE(k))//'" leaves no stale bound: '//TRIM(em_l)) + END DO + CALL expect_badinput('deck_hard_effective_gamma.dat', hardening_deck(ANCHOR, SECTION, CLOCK//nl// & + 'airy 2.0 8.0 0.0 waves'//nl// & + 'jonswap 3.0 10.0 2000.0 0.0 waves', & + 'FairTen1'), & + 'an out-of-range JONSWAP gamma on the effective row', 'gamma <= 1e3') + CALL expect_badinput('deck_hard_effective_current.dat', hardening_deck(ANCHOR, SECTION, CLOCK//nl// & + 'profile -30 0.2 0 0 0 0.5 0 0 current'// & + nl//'uniform 2000.0 0.0 0.0 current', & + 'FairTen1'), & + 'an out-of-range uniform current on the effective row', 'at most 1e3 m/s') + END BLOCK END SUBROUTINE check_parser_hardening FUNCTION rigid6_failure_deck(failure_rows, extra_point) RESULT(body) From 841914d095107a1fcc31143dfc4afc287174e287 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Mon, 9 Nov 2026 00:29:50 +0900 Subject: [PATCH 2/3] chore(changelog): the entry moves to the batch changelog change The [Unreleased] entries of the open changes are added together in one change, so that they do not conflict with each other. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d36b74f..e3549554 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,12 +18,6 @@ All notable changes to CableDyn are recorded in this file. The format follows The touchdown element now takes the reaction of its grounded stretch, from the grounded node to the touchdown point located from the two nodes' clearances: the error falls at the second order (2.1, 0.7, 0.2 N) and the outputs vary continuously. -- A `waves` or `current` row overridden by a later one no longer leaves a bound behind: an Airy - or stream `waves` row after a JONSWAP row was refused for that row's gamma above 1e3, and a - `profile` current row after a `uniform` one for that row's velocity above 1e3 m/s. The Python - deck validator now applies the magnitude bounds of these rows (wave height and period, JONSWAP - gamma, current speed and depth) to the row in effect only, as the solver does, instead of - refusing a deck for an out-of-range row a later row overrides. ## [0.4.1] - 2026-11-08 From 99c850001d9d8a8ab84b53f8e4d0ded35100ac41 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Mon, 9 Nov 2026 02:35:49 +0900 Subject: [PATCH 3/3] fix(python): the waves/current override loop takes its own variable name mypy (strict) refused the loop variable key, which the END CONNECTIONS check of the same function uses as a tuple. Signed-off-by: Jae Hoon Seo --- python/cabledyn/deck_file.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/cabledyn/deck_file.py b/python/cabledyn/deck_file.py index 24f38edb..1df28e8a 100644 --- a/python/cabledyn/deck_file.py +++ b/python/cabledyn/deck_file.py @@ -3394,8 +3394,8 @@ def _validate(self) -> None: option_by_key = {_option_key(option.keyword): option for option in options} # native finalize_checks: the magnitude bounds of the waves and current rows in # effect (the last of each); a row a later row overrides takes its row rules only - for key in ("waves", "current"): - record = option_by_key.get(key) + for overridden_kind in ("waves", "current"): + record = option_by_key.get(overridden_kind) if record is None or record.keyword_first: continue tokens = [*record.values, record.keyword]