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
new SpectralWaves(options?): SpectralWaves;Defined in: packages/marine/src/waves/SpectralWaves.ts:160
Parameters
| Parameter | Type |
|---|---|
options? | SpectralWavesOptions |
Returns
SpectralWaves
Properties
| Property | Modifier | Type | Default value | Description | Defined in |
|---|---|---|---|---|---|
gravity | readonly | number | undefined | - | packages/marine/src/waves/SpectralWaves.ts:122 |
gustPatches | readonly | number | undefined | Patches as small as this or smaller gust. | packages/marine/src/waves/SpectralWaves.ts:134 |
gusts | readonly | readonly object[] | undefined | The gusts' pattern: a few long sines, each (kx, kz, phase), summed. | packages/marine/src/waves/SpectralWaves.ts:132 |
inversionIterations | readonly | number | undefined | - | packages/marine/src/waves/SpectralWaves.ts:121 |
lastGridPoint | readonly | object | ... | The undisplaced grid point the last heightAt or heightFrom found. | packages/marine/src/waves/SpectralWaves.ts:124 |
lastGridPoint.x | public | number | 0 | - | packages/marine/src/waves/SpectralWaves.ts:124 |
lastGridPoint.z | public | number | 0 | - | packages/marine/src/waves/SpectralWaves.ts:124 |
loopPeriod | readonly | number | undefined | - | packages/marine/src/waves/SpectralWaves.ts:120 |
patches | readonly | readonly WavePatch[] | undefined | - | packages/marine/src/waves/SpectralWaves.ts:117 |
physicsResolution | readonly | number | undefined | - | packages/marine/src/waves/SpectralWaves.ts:123 |
swell | readonly | readonly SwellWave[] | undefined | The swell's long waves, as their amplitude is for the sea's swellHeight now. | packages/marine/src/waves/SpectralWaves.ts:126 |
timeOffset | readonly | number | undefined | - | packages/marine/src/waves/SpectralWaves.ts:119 |
timeScale | readonly | number | undefined | - | packages/marine/src/waves/SpectralWaves.ts:118 |
version | public | number | 0 | Counts the changes setSea has made, for those drawing the waves to notice. | packages/marine/src/waves/SpectralWaves.ts:138 |
workerStatistics | readonly | object | ... | Evaluations the worker had ready, and those it didn't and the main thread did instead. | packages/marine/src/waves/SpectralWaves.ts:136 |
workerStatistics.missed | public | number | 0 | - | packages/marine/src/waves/SpectralWaves.ts:136 |
workerStatistics.ready | public | number | 0 | - | packages/marine/src/waves/SpectralWaves.ts:136 |
Accessors
choppiness
Get Signature
get choppiness(): number;Defined in: packages/marine/src/waves/SpectralWaves.ts:210
Returns
number
sea
Get Signature
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
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()
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
| Parameter | Type |
|---|---|
gridX | number |
gridZ | number |
Returns
number
heightAt()
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
| Parameter | Type |
|---|---|
worldX | number |
worldZ | number |
time | number |
Returns
number
Implementation of
heightFrom()
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
| Parameter | Type |
|---|---|
worldX | number |
worldZ | number |
time | number |
startGridX | number |
startGridZ | number |
iterations | number |
Returns
number
Implementation of
normalAt()
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
| Parameter | Type |
|---|---|
worldX | number |
worldZ | number |
time | number |
target? | Vector3 |
Returns
Vector3
Implementation of
phaseTime()
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
| Parameter | Type |
|---|---|
time | number |
Returns
number
prefetch()
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
| Parameter | Type |
|---|---|
time | number |
Returns
void
Implementation of
riseRate()
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
| Parameter | Type |
|---|---|
gridX | number |
gridZ | number |
time | number |
Returns
number
Implementation of
setSea()
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
| Parameter | Type |
|---|---|
changes | Partial<SeaSettings> |
Returns
void
surfacePoint()
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
| Parameter | Type |
|---|---|
gridX | number |
gridZ | number |
time | number |
target? | Vector3 |
Returns
Vector3
Implementation of
swellPhasesAt()
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
| Parameter | Type |
|---|---|
time | number |
target | Float64Array |
Returns
Float64Array
useWorker()
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
| Parameter | Type |
|---|---|
port | SpectralPort |
Returns
void
