Skip to content

eulerjs API / @eulerjs/marine / SpectralWaves

SpectralWaves ​

Defined in: packages/marine/src/waves/SpectralWaves.ts:116

An ocean of hundreds of thousands of waves, drawn from the JONSWAP spectrum of a wind sea and summed by inverse FFT (Tessendorf's "Simulating Ocean Water"): linear waves, sharpened at the crests by moving the surface's points sideways toward them.

The sea is a few square patches of different sizes, tiled, each holding its own band of wavelengths. The water mesh sums every wave of every patch on the GPU; the physics sums, on the CPU, the longest of them, those of the largest patches up to physicsResolution waves across: the waves a hull rides on, the same in both. Its FFT runs once a time step, and a height is then a few lookups in its grids.

Implements ​

Constructors ​

Constructor ​

ts
new SpectralWaves(options?): SpectralWaves;

Defined in: packages/marine/src/waves/SpectralWaves.ts:160

Parameters ​

ParameterType
options?SpectralWavesOptions

Returns ​

SpectralWaves

Properties ​

PropertyModifierTypeDefault valueDescriptionDefined in
gravityreadonlynumberundefined-packages/marine/src/waves/SpectralWaves.ts:122
gustPatchesreadonlynumberundefinedPatches as small as this or smaller gust.packages/marine/src/waves/SpectralWaves.ts:134
gustsreadonlyreadonly object[]undefinedThe gusts' pattern: a few long sines, each (kx, kz, phase), summed.packages/marine/src/waves/SpectralWaves.ts:132
inversionIterationsreadonlynumberundefined-packages/marine/src/waves/SpectralWaves.ts:121
lastGridPointreadonlyobject...The undisplaced grid point the last heightAt or heightFrom found.packages/marine/src/waves/SpectralWaves.ts:124
lastGridPoint.xpublicnumber0-packages/marine/src/waves/SpectralWaves.ts:124
lastGridPoint.zpublicnumber0-packages/marine/src/waves/SpectralWaves.ts:124
loopPeriodreadonlynumberundefined-packages/marine/src/waves/SpectralWaves.ts:120
patchesreadonlyreadonly WavePatch[]undefined-packages/marine/src/waves/SpectralWaves.ts:117
physicsResolutionreadonlynumberundefined-packages/marine/src/waves/SpectralWaves.ts:123
swellreadonlyreadonly SwellWave[]undefinedThe swell's long waves, as their amplitude is for the sea's swellHeight now.packages/marine/src/waves/SpectralWaves.ts:126
timeOffsetreadonlynumberundefined-packages/marine/src/waves/SpectralWaves.ts:119
timeScalereadonlynumberundefined-packages/marine/src/waves/SpectralWaves.ts:118
versionpublicnumber0Counts the changes setSea has made, for those drawing the waves to notice.packages/marine/src/waves/SpectralWaves.ts:138
workerStatisticsreadonlyobject...Evaluations the worker had ready, and those it didn't and the main thread did instead.packages/marine/src/waves/SpectralWaves.ts:136
workerStatistics.missedpublicnumber0-packages/marine/src/waves/SpectralWaves.ts:136
workerStatistics.readypublicnumber0-packages/marine/src/waves/SpectralWaves.ts:136

Accessors ​

choppiness ​

Get Signature ​

ts
get choppiness(): number;

Defined in: packages/marine/src/waves/SpectralWaves.ts:210

Returns ​

number


sea ​

Get Signature ​

ts
get sea(): Readonly<SeaSettings>;

Defined in: packages/marine/src/waves/SpectralWaves.ts:206

The wind and waves the sea is made of now.

Returns ​

Readonly<SeaSettings>


significantWaveHeight ​

Get Signature ​

ts
get significantWaveHeight(): number;

Defined in: packages/marine/src/waves/SpectralWaves.ts:237

The significant wave height, Hs: four times the standard deviation of the surface's height, about the mean height of the highest third of the waves, as a sea state is given in.

Returns ​

number

Methods ​

gustAt() ​

ts
gustAt(gridX, gridZ): number;

Defined in: packages/marine/src/waves/SpectralWaves.ts:447

How much the gusting patches' waves are scaled by at the undisplaced grid point: one, plus the gustiness times the gusts' pattern, about as often above as below and seldom past two.

Parameters ​

ParameterType
gridXnumber
gridZnumber

Returns ​

number


heightAt() ​

ts
heightAt(
   worldX, 
   worldZ, 
   time
): number;

Defined in: packages/marine/src/waves/SpectralWaves.ts:295

Height of the surface directly above or below the world position (worldX, worldZ) at time.

Parameters ​

ParameterType
worldXnumber
worldZnumber
timenumber

Returns ​

number

Implementation of ​

WaveSurface.heightAt


heightFrom() ​

ts
heightFrom(
   worldX, 
   worldZ, 
   time, 
   startGridX, 
   startGridZ, 
   iterations
): number;

Defined in: packages/marine/src/waves/SpectralWaves.ts:299

Like heightAt, but starts the search for the undisplaced grid point at (startGridX, startGridZ) and runs iterations steps; a good start needs one. The grid point found is left in lastGridPoint.

Parameters ​

ParameterType
worldXnumber
worldZnumber
timenumber
startGridXnumber
startGridZnumber
iterationsnumber

Returns ​

number

Implementation of ​

WaveSurface.heightFrom


normalAt() ​

ts
normalAt(
   worldX, 
   worldZ, 
   time, 
   target?
): Vector3;

Defined in: packages/marine/src/waves/SpectralWaves.ts:369

Upward unit normal of the surface at the world position (worldX, worldZ).

Parameters ​

ParameterType
worldXnumber
worldZnumber
timenumber
target?Vector3

Returns ​

Vector3

Implementation of ​

WaveSurface.normalAt


phaseTime() ​

ts
phaseTime(time): number;

Defined in: packages/marine/src/waves/SpectralWaves.ts:252

Time the waves are evaluated at for a given simulation time: scaled, offset, and wrapped round the loop period.

Parameters ​

ParameterType
timenumber

Returns ​

number


prefetch() ​

ts
prefetch(time): void;

Defined in: packages/marine/src/waves/SpectralWaves.ts:286

Asks the worker, if there is one, to evaluate the waves at time before they are needed.

Parameters ​

ParameterType
timenumber

Returns ​

void

Implementation of ​

WaveSurface.prefetch


riseRate() ​

ts
riseRate(
   gridX, 
   gridZ, 
   time
): number;

Defined in: packages/marine/src/waves/SpectralWaves.ts:322

How fast the surface point that started at grid position (gridX, gridZ) rises at time, in m/s: the water's own vertical velocity there, which is slower than the surface rises at a fixed place as a steep crest passes it. For floating bodies to move with the water. A surface without it, Buoyancy damps against the surface's rise at the place instead.

Parameters ​

ParameterType
gridXnumber
gridZnumber
timenumber

Returns ​

number

Implementation of ​

WaveSurface.riseRate


setSea() ​

ts
setSea(changes): void;

Defined in: packages/marine/src/waves/SpectralWaves.ts:219

Changes the wind, or the waves' height or choppiness, while the sea runs. Each wave keeps the random draw it was made with, so the sea changes into the new one smoothly, swell by swell, rather than starting another; the physics, the worker and the water drawn all follow.

Parameters ​

ParameterType
changesPartial<SeaSettings>

Returns ​

void


surfacePoint() ​

ts
surfacePoint(
   gridX, 
   gridZ, 
   time, 
   target?
): Vector3;

Defined in: packages/marine/src/waves/SpectralWaves.ts:315

Where the surface point that started at grid position (gridX, gridZ) is at time, displaced sideways as well as up.

Parameters ​

ParameterType
gridXnumber
gridZnumber
timenumber
target?Vector3

Returns ​

Vector3

Implementation of ​

WaveSurface.surfacePoint


swellPhasesAt() ​

ts
swellPhasesAt(time, target): Float64Array;

Defined in: packages/marine/src/waves/SpectralWaves.ts:334

Each swell wave's phase at time, into target: its own, less how far it has turned, worked out in double precision and wrapped into a turn, so that it is as exact on the GPU.

Parameters ​

ParameterType
timenumber
targetFloat64Array

Returns ​

Float64Array


useWorker() ​

ts
useWorker(port): void;

Defined in: packages/marine/src/waves/SpectralWaves.ts:264

Evaluates the physics' waves in a worker from now on, for the times prefetch asks for ahead (Buoyancy asks for the next few steps'); any other time, or one the worker hasn't finished, is still evaluated here. port is a Worker running @eulerjs/marine/spectral-worker.

Parameters ​

ParameterType
portSpectralPort

Returns ​

void

Released under the MIT License.