@ferret/flow
wind, fronts, vortices, jets, shelters and channels as one field of moving air and water, without physics.
Read the guide: how to use it →
Classes
FlowField class
class FlowFieldreadonly sources: Map<string, FlowSourceDef> | |
evaluated: number | how many sources were evaluated by the last at (the reach culling is visible to tests and the budget) |
maxSources: number | the most sources the field takes; none by default |
add(def: FlowSourceDef): void | |
remove(name: string) | |
set(name: string, patch: Partial<FlowSourceDef>) | |
list(): FlowSourceDef[] | the sources of the level (those published by code, with a publisher, are left out: they are not data) |
centreOf(s: FlowSourceDef, t: number): V3 | where a source is centred at time t (its first reference point, moved along its path) |
at(p: V3, t: number, medium: Medium = 'air', skipPublisher?: string, onlyPublisher?: string): FlowSample | The flow at a point and time, per medium: the sum of the sources, then the shelters reduce it. |
packages/flow/src/index.ts:142
FlowService class
class FlowService implements ServiceThe field as a world service: the clock is the world's, and the commands of the plan section 5 are registered.
readonly name: "flow" | |
readonly field: FlowField | |
world: World | |
init(world: World) | |
unload(): void | The sources a level's block added go with the level. |
load(list: unknown): void | Flow sources of a level's physics.flow list. |
packages/flow/src/index.ts:302
Functions
advectClouds function
function advectClouds(field: FlowField, clouds: V3[], t: number, dt: number): V3[]Move clouds by the wind at their own place for dt; returns the new positions (the input is left alone).
packages/flow/src/view.ts:26
cloudVelocity function
function cloudVelocity(field: FlowField, at: V3, t: number): [number, number]The horizontal velocity at the height of a cloud layer; a cloud drifts with the wind there, a front brings its clouds with it.
packages/flow/src/view.ts:21
dropVelocity function
function dropVelocity(field: FlowField, at: V3, t: number, fall: number): V3The slant of rain or snow: the velocity of a drop falling at fall m/s through the wind there (unit direction and speed).
packages/flow/src/view.ts:37
erf function
function erf(x: number): numbererf, Abramowitz and Stegun 7.1.26 (error below 1.5e-7)
packages/flow/src/jets.ts:49
exitVelocity function
function exitVelocity(thrust: number, exitArea: number, rho = AIR_DENSITY): numberthe exit velocity of a ducted fan or a nozzle that gives thrust through the area exitArea: v_e = sqrt(T / (rho A_e))
packages/flow/src/jets.ts:17
flowGrid function
function flowGrid(field: FlowField, centre: V3, half: number, step: number, t: number, medium: Medium = 'air'): FlowArrow[]A grid of samples round a centre for the inspector's arrows: half metres each way (x and z) at height centre[1], every step metres.
packages/flow/src/view.ts:78
flowReaches function
function flowReaches(field: FlowField, t: number): FlowReach[]Where each source is now, how far it reaches and (for a vortex) its core: what the inspector draws as rings.
packages/flow/src/view.ts:93
funnels function
function funnels(field: FlowField, t: number): Funnel[]packages/flow/src/view.ts:44
groundEffectRatio function
function groundEffectRatio(radius: number, height: number): numberthe thrust of a ground-effect rotor over the same rotor out of ground effect (Cheeseman and Bennett): 1 / (1 - (R / 4z)^2), z the height of the disc over the ground
packages/flow/src/jets.ts:21
gustAt function
function gustAt(t: number, g: Gust): numberA deterministic gust, −1..1 in time (the one of physics-media).
packages/flow/src/index.ts:77
netFlow function
function netFlow(field: FlowField, net: FlowNetLike, opts: NetFlowOptions): NetFlowpackages/flow/src/net.ts:33
patchWind function
function patchWind(field: FlowField, centre: V3, t: number, o: { calm?: number; full?: number } = {}): PatchWindpackages/flow/src/view.ts:14
pathAt function
function pathAt(path: V3[], speed: number, start: number, t: number): V3The point of a path at time t (moving at speed from start); the last point after the end.
packages/flow/src/index.ts:103
plumeLean function
function plumeLean(field: FlowField, base: V3, t: number, riseSpeed: number): [number, number]How far a plume of smoke or steam leans: the horizontal offset per metre of rise, for a rise speed (wind speed over rise speed).
packages/flow/src/view.ts:31
rotorInducedVelocity function
function rotorInducedVelocity(thrust: number, discArea: number, rho = AIR_DENSITY): numberthe induced velocity at the disc of an open rotor: v_i = sqrt(T / (2 rho A)); the far wake runs at twice that (momentum theory)
packages/flow/src/jets.ts:13
roundJetAt function
function roundJetAt(ue: number, D: number, x: number, r: number): numberthe velocity of a round free jet at distance x along the axis and r from it; 0 where it is below 0.2 % of the centreline
packages/flow/src/jets.ts:36
roundJetCentreline function
function roundJetCentreline(ue: number, D: number, x: number): numberthe centreline velocity of a round free jet of exit velocity ue and diameter D at distance x from the nozzle
packages/flow/src/jets.ts:31
turbulenceNoise function
function turbulenceNoise(seed: number, p: V3, t: number): numberSeeded turbulence for the picture only (D9): a smooth value noise of position and time, in -1..1, the same everywhere for one seed. The physics never reads it; the render adds amplitude * noise to the flow it draws, so a gale looks ragged without peers disagreeing.
packages/flow/src/view.ts:57
validateFlowSource function
function validateFlowSource(d: unknown, path = 'flow'): string[]packages/flow/src/index.ts:116
wallJetAt function
function wallJetAt(uj: number, D: number, r: number, z: number): numberthe wall jet's speed at radius r and height z; 0 beyond 40 diameters or above 8 half-thicknesses
packages/flow/src/jets.ts:71
wallJetMax function
function wallJetMax(uj: number, D: number, r: number): numberthe maximum velocity of the wall jet at radius r from the stagnation point: a linear rise inside 1.2 D, Poreh beyond; uj the velocity of the jet at the surface, D its diameter there
packages/flow/src/jets.ts:58
wallJetProfile function
function wallJetProfile(z: number, half: number): numberthe Glauert vertical profile u / u_m at height z over the surface for a wall jet of half-thickness half (0 at the wall, 1 at its maximum)
packages/flow/src/jets.ts:65
wallJetThickness function
function wallJetThickness: (D: number, r: number) => numberthe half-thickness of the wall jet at radius r (the height where the velocity is half the maximum), with a floor that is the jet's own scale
packages/flow/src/jets.ts:63
waterCurrent function
function waterCurrent(field: FlowField, y = 0, t = 0): (x: number, z: number) => [number, number]A current for a liquid surface (SurfaceDef.current) taken from the water flow at height y and time t.
packages/flow/src/index.ts:333
Interfaces
ChannelSource interface
interface ChannelSource extends BaseA flow along a polyline (a river, a mill race, a canyon wind) with a parabolic cross profile of half-width width.
kind: 'channel' | |
points: V3[] | |
velocity: number | |
width: number |
packages/flow/src/index.ts:63
CurveSource interface
interface CurveSource extends BaseA sampled field (baked from a tool): size cells of cell metres from origin, data holds vx, vy, vz per cell (x fastest, then y, then z); trilinear inside, nothing outside.
kind: 'curve' | |
origin: V3 | |
cell: number | |
size: [number, number, number] | |
data: number[] |
packages/flow/src/index.ts:65
FlowArrow interface
interface FlowArrowpackages/flow/src/view.ts:76
FlowNetLike interface
interface FlowNetLikeThe weather over the net. The flow field is a pure function of position and time, so only its changes travel:
the authority of the level (one machine) sends each change with an effect time now() + delay, and every machine, the authority included,
applies it when the shared clock reaches that time. Nothing else is replicated, so a storm costs a message per change, not per step.
send(name: string, data: unknown): void | |
on(name: string, fn: (data: any, from: string) => void): () => void |
packages/flow/src/net.ts:9
FlowReach interface
interface FlowReachname: string | |
kind: FlowSourceDef['kind'] | |
on: boolean | |
centre: V3 | |
reach?: number | |
core?: number |
packages/flow/src/view.ts:91
FlowSample interface
interface FlowSamplevelocity: V3 | |
updraft?: number | |
turbulence?: number | |
temperature?: number |
packages/flow/src/index.ts:13
FrontSource interface
interface FrontSource extends BaseA plane that travels along direction (horizontal) at speed; behind it the flow goes from before to after over width.
packages/flow/src/index.ts:39
Funnel interface
interface FunnelA funnel to draw: the vortices of the field with their core, height and where they are now.
name: string | |
centre: V3 | |
core: number | |
height: number | |
updraft: number | |
circulation: number |
packages/flow/src/view.ts:43
Gust interface
interface Gustamplitude: number | |
period: number | |
seed?: number |
packages/flow/src/index.ts:36
ImpingingSource interface
interface ImpingingSource extends BaseA jet that strikes a surface turns into a radial wall jet: centre is the stagnation point on the surface, normal points out of the surface, velocity the speed of the jet where it arrives and diameter its width there. The flow is along the surface away from the centre, thickest at the wall's height of 0.098 r (Poreh, Glauert), with Glauert's vertical profile. Published by a propulsor whose jet meets the ground, the water or a body.
packages/flow/src/index.ts:59
JetSource interface
interface JetSource extends BaseA cone of flow from a point (a fan, a vent, the wash of a propeller) with exponential decay over distance.
kind: 'jet' | |
origin: V3 | |
direction: V3 | |
velocity: number | |
halfAngle?: number | |
decay?: number | |
profile?: 'round' | round: the round turbulent free jet of a propulsor: velocity is the exit velocity and diameter the nozzle's, a potential core of six diameters and a centreline decay of 6.2 D / x after it, a Gaussian cross profile 0.0965 x wide (halfAngle and decay are not used). Without it the cone with the exponential decay below, as before. |
diameter?: number | |
temperature?: number | the temperature excess at the exit, K (a hot exhaust): the field reports it, scaled down with the velocity |
packages/flow/src/index.ts:43
LevelCurve interface
interface LevelCurveA level of a source in time: keys [[t, v], ...] (linear, held at the ends); loop repeats over the last key.
curve: Array<[number, number]> | |
loop?: boolean |
packages/flow/src/index.ts:16
NetFlow interface
interface NetFlowadd(def: FlowSourceDef): void | |
set(name: string, patch: Partial<FlowSourceDef>): void | |
remove(name: string): void | |
step(): void | call every fixed step |
pending(): number | |
dispose(): void |
packages/flow/src/net.ts:23
NetFlowOptions interface
interface NetFlowOptionsauthority: boolean | is this machine the authority of the level's weather (default false: it only receives) |
authorityPeer?: string | the peer id of the authority, when known (otherwise the first sender is taken for it) |
now: () => number | |
delay?: number |
packages/flow/src/net.ts:13
PatchWind interface
interface PatchWindOne wind uniform for a patch of grass or trees: the direction (unit, horizontal), the speed and a 0..1 sway amount.
dir: [number, number] | |
speed: number | |
sway: number | |
gust: number |
packages/flow/src/view.ts:13
ShelterSource interface
interface ShelterSource extends BaseA sphere in the lee of an obstacle where the flow of the other sources is reduced by strength (0..1) and made turbulent.
kind: 'shelter' | |
centre: V3 | |
radius: number | |
strength: number |
packages/flow/src/index.ts:61
SolvedSource interface
interface SolvedSource extends BaseA region where the flow is solved (a flow box, @ferret/flow-solver): inside it the solver's field replaces the analytic sum, blended over a margin. Code only (it has a function); the box publishes it and the readers see the wake without any change on their side. sampler gets the point, the time and the analytic velocity there and returns the replaced velocity and its weight 0..1, or null outside the region (or while the box sleeps).
packages/flow/src/index.ts:71
UniformSource interface
interface UniformSource extends Basekind: 'uniform' | |
velocity: V3 | |
profile?: { power: number; refHeight: number; seaLevel?: number } | |
gust?: Gust |
packages/flow/src/index.ts:37
VortexSource interface
interface VortexSource extends BaseA Rankine vortex about a vertical axis: solid rotation inside core, Γ/(2πr) outside; inflow near the ground, an updraft in the core.
kind: 'vortex' | |
centre: V3 | |
core: number | |
circulation: number | |
inflow?: number | |
updraft?: number | |
height?: number |
packages/flow/src/index.ts:41
Types
FlowSourceDef type
type FlowSourceDef = SolvedSource | CurveSource | UniformSource | FrontSource | VortexSource | JetSource | ImpingingSource | ShelterSource | ChannelSourcepackages/flow/src/index.ts:72
Medium type
type Medium = 'air' | 'water'packages/flow/src/index.ts:12
V3 type
type V3 = [number, number, number]Flow sources: wind, fronts, vortices, jets, shelters and channels add up to one field flowAt(position, time, medium) that bodies, vessels, the character and the render all read. No physics and no Babylon here: every source is a pure function of (position, time), so every peer computes the same field and a game without physics can use it.
packages/flow/src/index.ts:11
Constants
AIR_DENSITY const
const AIR_DENSITY: 1.225packages/flow/src/jets.ts:9
ROUND_CORE const
const ROUND_CORE: 6packages/flow/src/jets.ts:26
ROUND_DECAY const
const ROUND_DECAY: 6.2packages/flow/src/jets.ts:27
ROUND_HALF_ANGLE const
const ROUND_HALF_ANGLE: numberthe half-angle (rad) of the spreading cone of a round jet: atan of the half-width over the distance, 0.0965
packages/flow/src/jets.ts:46
ROUND_SPREAD const
const ROUND_SPREAD: 0.0965packages/flow/src/jets.ts:28
WALL_JET_A const
const WALL_JET_A: 1.03packages/flow/src/jets.ts:55
WALL_JET_N const
const WALL_JET_N: -1.12packages/flow/src/jets.ts:55
WALL_JET_THICKNESS const
const WALL_JET_THICKNESS: 0.098packages/flow/src/jets.ts:55
WATER_DENSITY const
const WATER_DENSITY: 1000packages/flow/src/jets.ts:10