Skip to content

Faster hydrodynamic kernels: convolutions, wave set-up and nonlinear mesh loops - #25

Merged
dav-og merged 12 commits into
devfrom
perf/numerical-kernels
Dec 3, 2026
Merged

dav-og merged 12 commits into
devfrom
perf/numerical-kernels

Conversation

@dav-og

@dav-og dav-og commented Dec 2, 2026

Copy link
Copy Markdown
Member

Summary

[IMPROVEMENT] Restructures the numerical kernels that dominate a SEA-Stack run. The
physics, numerical methods, defaults, YAML inputs and results-file layout are unchanged:
each kernel computes the same sum as before in a different order or with a different data
layout, so results agree with v1.2.0 to rounding.

Area Change
Radiation convolution One dot product per non-zero kernel against a contiguous velocity record (new VelocityHistory); trapezoid weights folded into the stored kernel; recorded samples used directly when they fall on the lag grid; single-threaded
Excitation, IRF convolution Lag sum carried out once for component waves (closed form); start-up ramp handled with partial sums stored along the lag grid
Excitation, frequency domain Components of equal frequency summed once, so a spreading sea costs one cosine and sine per frequency instead of per component
Wave set-up Eta-file transform takes its cosines and sines from a table; incident elevation series summed per frequency
Nonlinear hydrostatics and Froude-Krylov Mesh loops and vertex transform on plain doubles; regular waves evaluated with one array operation over all vertices
Headless runs [BUG FIX] Chrono no longer regenerates spring visual shapes at every step when there is no viewer

Also adds bench_hydro_kernels (force-component timing without Chrono) and separate
"Mooring" and "Damping + External" lines in run_seastack --profile.

Effect

Measured on a 16-core Windows desktop over the 43 demo cases:

  • Complete runs of the cases that use these kernels are 1.5 to 6 times faster (median
    about 2.2x); the two crane cases and the state-space and constant-coefficient cases are
    essentially unchanged.
  • A run uses one core where it used most of the machine, so CPU time falls by a far
    larger factor and concurrent runs (campaigns) no longer compete for threads.
  • Results no longer depend on OMP_NUM_THREADS: runs with 1, 8 and 32 threads are
    bit-identical. This removes the limitation "Joint reaction loads and thread count" of
    the v1.2.0 release notes.
  • Driven body motions differ from v1.2.0 at rounding level; in cases that use an
    iterative linear solver the difference is of the size v1.2.0 itself shows between two
    thread counts.

Compatibility

[COMPATIBILITY]

  • RadiationRirfConvolution::ComputeForces(callback, kernel) is replaced by
    SetKernel() (once) and ComputeForces(). The header is installed; code that uses
    this class directly must be adapted. RadiationComponent and the YAML interface are
    unchanged.
  • The radiation lag grid must be non-negative and strictly increasing; the constructor
    throws otherwise.
  • A time earlier than the newest velocity sample (a repeated integrator step) discards
    the samples at or after it and logs one warning. An equal time still throws.
  • run_seastack --profile: "Chrono Solver" no longer includes mooring and damping time.
  • WaveBase::ComputeElevationTimeSeries() is now virtual. New public interface:
    VelocityHistory, AmplitudeEnvelope::IsConstantOver(),
    TriangleMesh::TransformVertices(), RemoveLinkVisualShapes().
  • IRF excitation with a start-up ramp stores partial sums of up to 64 MB.
  • Nonlinear hydrostatics results differ from v1.2.0 in the last digits.

Testing

  • Windows: unit (78), regression (48), demo regression (36 comparisons), verification
    (15), comparison (30) and external-module (3) suites pass. No reference data was
    regenerated and no tolerance was changed.
  • New unit tests compare each rewritten kernel with a term-by-term evaluation of the
    same sum: test_radiation_component, test_excitation_irf_closed_form,
    test_excitation_frequency_sums, test_eta_file_components,
    test_elevation_time_series; test_radiation_rirf_convolution,
    test_amplitude_envelope, test_wave_pressure and test_viz_extractor are extended.
  • Not yet built or run on Linux or macOS: this pull request's CI run is the first. It
    carries the full-tests label so that verification and comparison run on every
    platform.

Suggested release-note entries

  • Faster simulations: the radiation and excitation convolutions, wave set-up and the
    nonlinear hydrostatics and Froude-Krylov mesh loops were restructured. Typical runs are
    about twice as fast and use a single core; results agree with v1.2.0 to rounding.
  • Results no longer depend on the OpenMP thread count (limitation of v1.2.0 removed).
  • Headless runs no longer update spring visual shapes at every step.
  • run_seastack --profile lists mooring and damping time separately.
  • Interface change: RadiationRirfConvolution takes its kernel through SetKernel() and
    ComputeForces() has no arguments.
  • The radiation lag grid of a BEM file must be non-negative and strictly increasing.

@dav-og dav-og added full-tests Run the full test suites on all platforms in CI and removed full-tests Run the full test suites on all platforms in CI labels Dec 2, 2026
@dav-og
dav-og force-pushed the perf/numerical-kernels branch from ccd7341 to 1169769 Compare December 3, 2026 14:27
dav-og added 12 commits December 3, 2026 18:53
RadiationRirfConvolution had no unit test. test_radiation_rirf_convolution checks it on synthetic kernels against a term-by-term evaluation of F_i = sum_j sum_k K_ij(tau_k) w_k v_j(t - tau_k): time steps equal to, an integer fraction of and not commensurate with the lag spacing, a variable step, a non-uniform lag grid, start-up, two bodies, a truncated kernel and rejected inputs. test_radiation_component checks RadiationComponent on the bundled sphere and RM3 kernels, as stored, smoothed, truncated and with a yawed body.
Builds a HydroModel from each demo BEM file with HydroModelBuilder and times radiation, excitation and hydrostatics / nonlinear Froude-Krylov through HydroForces' profiling counters, with a prescribed body motion. Prints microseconds per evaluation as CSV. Run by hand; not a CTest test.
The 'Chrono Solver' line was the loop time minus hydrostatics, radiation and excitation, so it also held MoorDyn and the damping and external components. HydroForces now times damping and external components as well, the profile lists 'Mooring' and 'Damping + External' when present, and 'Chrono Solver' excludes them.
Chrono regenerates the geometry of every point-to-point visual shape on a link at each time step, drawn or not; a SPRING coil is rebuilt point by point with heap allocation. With --nogui this took 10% of the loop for RM3 (one PTO spring) and 22% for 5SA regular waves (16 ram springs). RemoveLinkVisualShapes() clears the link shapes; run_seastack calls it for headless runs once the replay scene is written, and the 5SA demos and benchmark call it when no viewer is requested. VizExtractor reads a link's shape once and afterwards uses only its end points, so replay data is unchanged. Results are bit-identical.
…velocity record.

The convolution term of the Cummins equation is now computed with one dot product per non-zero kernel K_ij against the lagged velocity of degree of freedom j. Trapezoid weights are folded into the stored kernel, identically zero kernels and degrees of freedom that have not moved are skipped, and the velocity record (new class VelocityHistory) is a contiguous array in time order. When the recorded samples coincide with the lag grid the lagged velocities are read directly from the record; otherwise they are interpolated linearly as before. The quadrature is unchanged; results differ from the previous implementation by rounding only. The kernel runs on one thread and gives the same result for any OMP_NUM_THREADS.

Interface: RadiationRirfConvolution::ComputeForces(callback, kernel) is replaced by SetKernel() and ComputeForces(). The lag grid must be non-negative and strictly increasing. A time earlier than the newest sample (a repeated integrator step) discards the samples at or after it, with a warning reported once; an equal time still throws.
For a wave made of components the sum over the kernel lags is carried out once, giving per-component coefficients C_i and S_i, so that F(t) = sum_i A_i [C_i cos(theta_i) - S_i sin(theta_i)] with theta_i = phi_i - omega_i t. The lags still inside the start-up ramp are corrected with a direct sum over those lags only. This is the same quadrature in another order; results differ from the direct sum by rounding.

The direct sum is kept for eta-table waves, while every lag is inside the ramp, while a change of wave height is inside the kernel window, and for live period or direction changes. AmplitudeEnvelope::IsConstantOver() identifies the intervals on which the wave-height factor is constant, so a schedule that leaves the wave height unchanged stays bit-identical to a run without one.
Components of equal frequency are added together when the component is built, giving F(t) = sum_m [P_m cos(omega_m t) + Q_m sin(omega_m t)] over the distinct frequencies. A sea with directional spreading has n_omega x n_theta components but n_omega frequencies, so each time step needs n_theta times fewer cosines and sines. The terms are those of the sum over components in another order; results differ by rounding.

The sum over components is kept during and after a live change of wave period or direction.
…d count.

The coefficients were formed with one matrix-matrix product, which Eigen splits between the OpenMP threads; the rounding then depended on the number of threads (differences of 1e-11 in the excitation force). They are now formed with one matrix-vector product per wave component, which runs on one thread. Results are bit-identical for any OMP_NUM_THREADS.
…ation series.

BuildFromEtaFile: every angle of the transform at the Fourier frequencies is a multiple of 2 pi / N, so the cosines and sines are taken from a table of N values in place of two library calls per term, and the frequencies are summed in parallel (one thread per frequency, so the result does not depend on the thread count). Component amplitudes and phases differ from the previous values by rounding.

ComputeElevationTimeSeries is now virtual. LinearDirectionalWaveField adds the components of equal frequency into one cosine before the time loop: a sea with directional spreading needs one cosine per frequency and time instead of one per component. For a long-crested sea the series is identical to the previous one.
…e-Krylov.

The submerged-volume and pressure integrals and the vertex transform now work on plain doubles (internal type Vec3). The same formulas written with Eigen::Vector3d took about ten times as long per mesh face in the Windows release build. The per-face heap allocations of the waterline clipping are gone. Results differ from the previous ones by rounding.

LinearDirectionalWaveField::GetElevationAndPressureHead works through the points one component at a time for a regular wave or up to 8 components, so each cosine and exponential is one array operation over all mesh vertices. Seas with more components keep the point-by-point loop. TriangleMesh gains TransformVertices().
…ows.

A regular wave now costs about 0.1 ms per time step for the 8064-face sphere mesh, and the wave evaluation runs in parallel only for more than 8 wave components.
… over the lags.

While some lags still look back into the start-up ramp, the excitation convolution was corrected with a direct sum over all of those lags at every step. The ramp factor r(t - tau) of the linear and cosine ramps is a sum of a few products of a function of t and a function of tau, so the contribution of the ramping lags is a combination of sums over ranges of lags. These are now taken from partial sums stored at every 16th lag (or a larger spacing, to keep the tables below 64 MB); only the lags between a range end and the nearest stored sum are summed directly. The result is the same sum in another order and differs by rounding. After the ramp window the evaluation is unchanged.

The case in which every lag is still inside the ramp, which used the direct sum, is evaluated in the same way.
@dav-og
dav-og force-pushed the perf/numerical-kernels branch from 1169769 to 5434c88 Compare December 3, 2026 18:57
@dav-og
dav-og marked this pull request as ready for review December 3, 2026 20:11
@dav-og
dav-og merged commit 46cc14b into dev Dec 3, 2026
8 checks passed
@dav-og
dav-og deleted the perf/numerical-kernels branch December 4, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-tests Run the full test suites on all platforms in CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant