FERRETGame engine over Babylon.js
Ferret

@ferret/physics-links

Links that close loops between capabilities: a fire heats a pot, steam turns a turbine, a generator lights a lamp.

Links between capabilities: the places where one capability's output is another's input, so a world closes its loops (a fire heats a pot, steam turns a turbine, the turbine a generator, the generator lights a lamp; a screw pushes a ship and loads its engine). Each capability stays ignorant of the others; a link is a small object that reads one side and writes the other once a step, after the capabilities have stepped, and keeps the energy it moves so a scene can account for it.

The link reads and writes through the plain fields and methods of the objects it joins (a heat part, a chemical vessel, a gas volume, a shaft, a reactor, a thruster, a kernel body), so this package imports none of their packages.

36 exports · source in packages/physics-links/src

Functions

arcFlash function

function arcFlash(world: WorldLike, o: { circuit: string; at: Vec3; voltage: number; arcVoltage?: number; blastShare?: number; maxTime?: number; detonate: (d: { at: Vec3; energy: number; burst: 'air' }) => unknown }): Link & { dispose(): void }

An arc fault: from the first circuit:short until the circuit is cleared (circuit:trip or circuit:blown, or maxTime), the arc dissipates V_arc · I · t; a share of that goes into a blast at at (the rest is light and heat), handed to X as joules. One blast per fault.

packages/physics-links/src/index.ts:228

armatureOf function

function armatureOf(coil: { gap: number; force: number }, body: Body, pole: Vec3, kernel: KernelLike, reach = 0): Link

A coil element (W's Coil) and an armature body: the gap follows the distance of the body from the pole, the coil's pull acts on the body along the line to the pole, and the work it does is counted (the coil's own energy account takes the other side). Plain fields only: gap is written, force is read.

packages/physics-links/src/index.ts:138

boilerFed function

function boilerFed(boiler: FeedableBoiler, tank: { volume: number }, o: { setpoint: number; rate: number; density?: number; T?: () => number }): Link & { fed: number }

A feed pump between an L1 reservoir and a boiler: while the drum holds less water than setpoint (kg), it moves at most rate m³/s of the tank's liquid into it, never more than the tank has and never past the setpoint, at the tank's temperature T (the boiler cools by exactly what the cold water costs to heat). An empty tank starves the boiler.

packages/physics-links/src/index.ts:400

coilPulls function

function coilPulls(current: () => number, body: Body, pole: Vec3, kernel: KernelLike, force: (I: number, gap: number) => number, reach = 0): Link

packages/physics-links/src/index.ts:152

engineOnBoiler function

function engineOnBoiler(boiler: BoilerLike, shaft: ShaftLike, o: { area: number; exhaust: number; work: (p1: number, p2: number) => number; maxTorque: number; throttle?: () => number }): Link

A steam engine or turbine on a boiler: steam flows through the throttle (throttle() 0..1 of area) to the exhaust pressure, the boiler loses it with its enthalpy, and work(p1, p2) per kilogram (K's steamWork) turns the shaft, as power / ω.

packages/physics-links/src/index.ts:99

gasInPart function

function gasInPart(gas: GasLike, part: HeatPartLike, net: HeatNetLike, G: number, at: 'volume' | 'pressure' = 'volume'): Link

A gas volume and a heat part exchange heat through a conductance G (W/K): a hot wall warms a tank's gas and raises its pressure.

packages/physics-links/src/index.ts:58

mudOver function

function mudOver(terrain: TerrainLike, mediaCap: MediaLike, o: { box: [number, number, number, number]; name?: string; viscosity?: number; threshold?: number; depth?: number; every?: number }): Link & { present: boolean }

Wet ground is a medium: in a rectangle of the terrain the columns that are wet (moisture at least threshold) make a mud medium of the soil's wet density, its top at the mean surface of those columns and its box their extent, so bodies in it feel buoyancy and the viscous drag of D. When the ground dries, or the pit is dug away, the medium goes. It follows the terrain every every seconds.

packages/physics-links/src/index.ts:332

plasticHeats function

function plasticHeats(link: PlasticLike, part: HeatPartLike, net: HeatNetLike, share = 0.9): Link

Plastic work of an E link becomes heat in a part: the force it carried times the plastic length it added, a Taylor-Quinney share (0.9) of it.

packages/physics-links/src/index.ts:306

reactorHeatsPart function

function reactorHeatsPart(reactor: ReactorFuel, part: HeatPartLike, net: HeatNetLike, conductance: number): Link

The fuel of a reactor conducts heat to a part of H (the vessel, the containment, a pool) through a conductance, W/K. What leaves the fuel enters the part, so after a scram the decay heat that the coolant no longer carries warms the structure instead of vanishing.

packages/physics-links/src/index.ts:208

reservoirInPart function

function reservoirInPart(res: ReservoirLike, part: HeatPartLike, net: HeatNetLike, o: { G: number; density: number; cp: number; T0?: number }): Link & { T: number; mass(): number }

The liquid of an L1 reservoir takes the part's temperature slowly: heat flows through a conductance G (W/K) into the mass the reservoir holds now (volume x density x cp), so a tank that is filled warms to the wall, a drained one has nothing to warm, and the part is cooled by exactly what the liquid took. T is the liquid's temperature; liquid poured in mixes at inT by the energy balance.

packages/physics-links/src/index.ts:268

screwOnShaft function

function screwOnShaft(thruster: ThrusterLike, shaft: ShaftLike, o: { diameter: number; kt: number; kq: number; rho?: number }): Link

A screw on a shaft drives a vessel's thruster: thrust k_T·ρ·n²·D⁴ from the shaft's speed, and the torque k_Q·ρ·n²·D⁵ the water takes back as a load on the shaft (n in revolutions per second). The vessel's speed through the water is not in this law (a bollard pull).

packages/physics-links/src/index.ts:119

slipHeats function

function slipHeats(coupling: CouplingLike, part: HeatPartLike, net: HeatNetLike): Link

What a coupling loses (a slipping belt or clutch, a brake) heats a part.

packages/physics-links/src/index.ts:70

stagnationHeats function

function stagnationHeats(part: HeatPartLike, net: HeatNetLike, o: { speed: () => number; ambient: () => number; G: (v: number) => number; cp?: number; recovery?: number }): Link

Stagnation heating (D into H): a body moving at speed v through air at T warms toward its recovery temperature T + r v^2 / (2 cp) (r = 0.85 for a laminar and 0.89 for a turbulent boundary layer), through a heat-transfer conductance G (W/K) that the caller derives from its speed (h A).

packages/physics-links/src/index.ts:292

turbineOnReactor function

function turbineOnReactor(reactor: ReactorLike, shaft: ShaftLike, o: { efficiency: number; maxTorque: number }): Link

A steam turbine on a reactor's heat sink: of the heat the coolant gives up, efficiency becomes shaft work (as a torque on the shaft, power / ω, capped at maxTorque at standstill). The rest is the condenser's.

packages/physics-links/src/index.ts:82

vesselInPart function

function vesselInPart(vessel: ChemVesselLike, part: HeatPartLike, net: HeatNetLike): Link

The chemical vessel sits in a heat part: the part is its surroundings, and what the vessel loses goes into the part.

packages/physics-links/src/index.ts:43

wireFire function

function wireFire(world: WorldLike, o: { circuit: string; element: string; target: { ignite(): unknown } | (() => void) }): Link & { dispose(): void; lit: boolean }

A wire that overheats past its insulation sets fire to what it lies in (a chamber of K, or any object with ignite()), once.

packages/physics-links/src/index.ts:251

Interfaces

BoilerLike interface

interface BoilerLike

A boiler (K): steam through an area, taken out with its enthalpy.

pressure: number
flowThrough(area: number, outside?: number): number
take(kg: number): number

packages/physics-links/src/index.ts:36

ChemVesselLike interface

interface ChemVesselLike

A chemical vessel (Q): its surroundings' temperature and the heat it has lost to them.

Tenv: number
lost: number
hA: number
entity?: string

packages/physics-links/src/index.ts:26

CouplingLike interface

interface CouplingLike

A drivetrain coupling (M) with the energy it has turned into heat (slip, a brake).

loss: number

packages/physics-links/src/index.ts:30

EnergyTerm interface

interface EnergyTerm

One entry in a scene's energy account: a name and how much it holds or has taken, J.

name: string
joules: () => number

packages/physics-links/src/index.ts:167

FeedableBoiler interface

interface FeedableBoiler
readonly water: number
feed(kg: number, T?: number): void

packages/physics-links/src/index.ts:394

GasLike interface

interface GasLike

A bounded gas (D): heated at constant volume or pressure.

temperature: number
heat(joules: number, at?: 'volume' | 'pressure'): unknown

packages/physics-links/src/index.ts:28

HeatNetLike interface

interface HeatNetLike

What adds heat to a part: HeatNetwork.add.

add(p: HeatPartLike, joules: number): void

packages/physics-links/src/index.ts:24

HeatPartLike interface

interface HeatPartLike

A part of the heat network (H).

T: number
fixed: boolean
entity?: string

packages/physics-links/src/index.ts:22

KernelLike interface

interface KernelLike

A kernel that applies forces.

applyForce(b: Body, f: Vec3, at?: Vec3): void

packages/physics-links/src/index.ts:40

LinksCapability interface

interface LinksCapability extends Capability
readonly links: Link[]
add<L extends Link>(l: L): L
readonly terms: EnergyTerm[]Terms of the scene's energy account: stores (kinetic, heat, chemical, electric) and sinks (losses, the condenser).
account(t: EnergyTerm): void
energy(): { total: number; terms: Record<string, number> }The sum of every term, J: in a closed scene it stays where it started (links.energy).

packages/physics-links/src/index.ts:169

MediaLike interface

interface MediaLike
addMedium(m: { name: string; density: number; viscosity: number; surface?: number; bounds?: { min: Vec3; max: Vec3 } }): void
removeMedium(name: string): void

packages/physics-links/src/index.ts:326

PlasticLike interface

interface PlasticLike
k: number
L0: number
alpha: number
force: number

packages/physics-links/src/index.ts:304

ReactorLike interface

interface ReactorLike

A reactor (N): its coolant temperature, flow and the inlet the heat sink returns it at.

Tc: number
flow: number
spec: { inlet: number }

packages/physics-links/src/index.ts:34

ReservoirLike interface

interface ReservoirLike
volume: number

packages/physics-links/src/index.ts:262

ShaftLike interface

interface ShaftLike

A drivetrain shaft (M) and the torques acting on it.

omega: number
sources: Array<(omega: number, theta: number, t: number) => number>

packages/physics-links/src/index.ts:32

TerrainLike interface

interface TerrainLike
readonly nx: number
readonly nz: number
x(i: number): number
z(j: number): number
height(i: number, j: number): number
moistureAt(i: number, j: number): number
topSoil(i: number, j: number): { soil: { density: number; wet?: { density?: number } } }

packages/physics-links/src/index.ts:321

ThrusterLike interface

interface ThrusterLike

A thruster of a vessel (V) that takes its thrust from a source.

source?: (u: number) => number

packages/physics-links/src/index.ts:38