Skip to content

perf: evaluate each directional-sea phase and depth profile once - #9

Merged
SMI-Lab-Inha merged 1 commit into
devfrom
perf/sea-kinematics
Oct 14, 2026
Merged

SMI-Lab-Inha merged 1 commit into
devfrom
perf/sea-kinematics

Conversation

@SMI-Lab-Inha

Copy link
Copy Markdown
Owner

Summary

Speeds up the directional and multi-train sea kinematics (CD_Sea_Kinematics: wavetrain rows, spectral waves rows, WaveSpreading).

On the release-equivalent build, these kinematics take 80 % of examples/chain_two_train_sea.dat. For every node, step and component, the routine computed:

  • the phase cosine twice: once for the surface elevation and again for the kinematics;
  • two exponentials for the depth profile.

Changes:

  • The elevation pass keeps its cosines for the kinematics pass, for up to 4096 components; any further ones are recomputed. They are computed in the same 256-component chunks as before.
  • The depth profile uses EXP(-k (z + 2h)) = e2kd / EXP(k z) with the table's e2kd = EXP(-2 k h), as the JONSWAP component path CD_Component_Wave_Kinematics already does.
  • The two-exponential form is kept wherever the shortcut would not be exact:
    • a component whose EXP(k z) or e2kd underflows;
    • a call at another depth than the synthesis. CD_SeaType now records its synthesis depth for this test.

Speed (IFX 2025.3.2 release-mirror build, one thread, median of 3, isolated runs):

Deck Before After
chain_two_train_sea 1.89 s 1.57 s (−17 %)
Decks without a directional sea (multibody, lazy-wave RAO, line break, buoy, static) — unchanged within noise

Results. The formulas are unchanged; the evaluation is reorganised.

  • gfortran: the outputs of both directional-sea examples are bit-identical.
  • IFX: the release compiler had computed the second-pass cosine through a fused sin/cos evaluation, which can differ from the first-pass cosine in the last bit.
Deck (IFX) Channels differing Maximum difference
chain_two_train_sea none 0 (bit-identical)
chain_torsethaugen_spread AnchTen1 only, isolated rows from row 1813 one unit in the 8th printed digit (1.2e-8 relative)

Tests

  • New case_kinematics_reference in tests/test_wave_spectra.f90. It compares CD_Sea_Kinematics (elevation, velocity, acceleration, dynamic pressure) against a direct per-component sum of the original formulas, to 1e-11 relative. It covers four seas:

    1. 9 × 200 components, all cosines kept;
    2. 31 × 200 components, past the kept length;
    3. a short sea in 1000 m, where both exponentials underflow for many components (the test asserts the underflow is reached);
    4. a call at another depth than the synthesis.

    The sampled points are below the surface, near the seabed, and one above the surface.

  • Full suite, Windows, gfortran 16.2, Release, slow tier included: 245/245 pass.

  • pre-commit run --all-files passes.

Checklist

  • pre-commit run --all-files passes
  • ctest --test-dir build --output-on-failure passes
  • python -m pytest tests python/tests passes (if Python or validation records changed) — not applicable
  • VALIDATION.md updated if a validation result changed — no validation result changes
  • CHANGELOG.md updated under [Unreleased] (heading added if missing) for user-visible changes
  • Documentation in doc/ updated for changed inputs, options, or outputs — not applicable, no inputs or outputs changed
  • Conventional Commit title (feat:, fix:, docs:, ...)
  • Commits are signed off (git commit -s) under the
    Developer Certificate of Origin

Profiling the release build showed the directional-sea kinematics
(CD_Sea_Kinematics, the deck's wavetrain rows and spectral seas) taking
80 % of a chain run in a two-train sea. For every node, step and
component it computed the phase cosine twice (for the elevation and
again for the kinematics) and two exponentials for the depth profile.

The cosines of the elevation pass are now kept for the kinematics pass
(up to 4096 components; any further ones are recomputed), and the
depth profile uses EXP(-k (z + 2h)) = e2kd / EXP(k z) with the table's
e2kd = EXP(-2 k h), as the JONSWAP component path does. A component
whose EXP(k z) or e2kd underflows, or a call at another depth than the
synthesis, takes the second exponential instead; the sea now records
the depth of its synthesis for that test. With the release build the
two-train chain example runs in 1.57 s instead of 1.89 s (-17 %).

The formulas are unchanged. With gfortran the outputs of the two
directional-sea examples are bit-identical; with IFX the reuse removes
a fused sin/cos evaluation of the second pass, and one channel of
chain_torsethaugen_spread.dat differs by one unit in its eighth printed
digit at isolated rows. A new unit test checks the kinematics against a
direct per-component sum, with all cosines kept, with cosines past the
kept length, with underflowing exponentials, and at another depth.

Signed-off-by: Jae Hoon Seo <jaehoon.seo@inha.ac.kr>
@SMI-Lab-Inha

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T10:13:48.709546Z 07c0b9e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 CableDyn | 🛠️ Build #35139256 | 📁 Comparing 07c0b9e against latest (f27c5e3)

  🔍 Preview build  

2 files changed
± changelog.html
± development.html

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 07c0b9e5c9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@SMI-Lab-Inha
SMI-Lab-Inha merged commit 69cbe6a into dev Oct 14, 2026
15 checks passed
@SMI-Lab-Inha
SMI-Lab-Inha deleted the perf/sea-kinematics branch October 14, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant